Просмотр исходного кода

docs(core): Improve docs on EntityIdStrategy

Relates to #460
Michael Bromley 5 лет назад
Родитель
Сommit
82fcd075db

+ 9 - 0
docs/content/docs/developer-guide/deployment.md

@@ -23,6 +23,15 @@ For a production Vendure server, there are a few security-related points to cons
 * Set the [Superadmin credentials]({{< relref "auth-options" >}}#superadmincredentials) to something other than the default.
 * Consider taking steps to harden your GraphQL APIs against DOS attacks. Use the [ApiOptions]({{< relref "api-options" >}}) to set up appropriate Express middleware for things like [request timeouts](https://github.com/expressjs/express/issues/3330) and [rate limits](https://www.npmjs.com/package/express-rate-limit). A tool such as [graphql-query-complexity](https://github.com/slicknode/graphql-query-complexity) can be used to mitigate resource-intensive GraphQL queries. 
 * You may wish to restrict the Admin API to only be accessed from trusted IPs. This could be achieved for instance by configuring an nginx reverse proxy that sits in front of the Vendure server.
+* By default, Vendure uses auto-increment integer IDs as entity primary keys. While easier to work with in development, sequential primary keys can leak information such as the number of orders or customers in the system. For this reason you should consider using the [UuidIdStrategy]({{< relref "entity-id-strategy" >}}#uuididstrategy) for production.
+  ```TypeScript
+  import { UuidIdStrategy, VendureConfig } from '@vendure/core';
+  
+  export const config: VendureConfig = {
+    entityIdStrategy: new UuidIdStrategy(),
+    // ...
+  }
+  ```
 
 ## Health/Readiness Checks
 

+ 5 - 1
packages/core/src/config/entity-id-strategy/auto-increment-id-strategy.ts

@@ -1,8 +1,12 @@
 import { EntityIdStrategy } from './entity-id-strategy';
 
 /**
+ * @description
  * An id strategy which uses auto-increment integers as primary keys
- * for all entities.
+ * for all entities. This is the default strategy used by Vendure.
+ *
+ * @docsCategory configuration
+ * @docsPage EntityIdStrategy
  */
 export class AutoIncrementIdStrategy implements EntityIdStrategy<'increment'> {
     readonly primaryKeyType = 'increment';

+ 7 - 3
packages/core/src/config/entity-id-strategy/entity-id-strategy.ts

@@ -6,10 +6,14 @@ export type PrimaryKeyType<T> = T extends 'uuid' ? string : T extends 'increment
  * @description
  * The EntityIdStrategy determines how entity IDs are generated and stored in the
  * database, as well as how they are transformed when being passed from the API to the
- * service layer.
+ * service layer and vice versa.
  *
- * @docsCategory entities
- * @docsPage Entity Configuration
+ * Vendure ships with two strategies: {@link AutoIncrementIdStrategy} and {@link UuidIdStrategy},
+ * but custom strategies can be used, e.g. to apply some custom encoding to the ID before exposing
+ * it in the GraphQL API.
+ *
+ * @docsCategory configuration
+ * @docsPage EntityIdStrategy
  * */
 export interface EntityIdStrategy<T extends 'increment' | 'uuid'> extends InjectableStrategy {
     /**

+ 16 - 1
packages/core/src/config/entity-id-strategy/uuid-id-strategy.ts

@@ -1,8 +1,23 @@
 import { EntityIdStrategy } from './entity-id-strategy';
 
 /**
+ * @description
  * An id strategy which uses string uuids as primary keys
- * for all entities.
+ * for all entities. This strategy can be configured with the
+ * `entityIdStrategy` property of the {@link VendureConfig}.
+ *
+ * @example
+ * ```TypeScript
+ * import { UuidIdStrategy, VendureConfig } from '\@vendure/core';
+ *
+ * export const config: VendureConfig = {
+ *   entityIdStrategy: new UuidIdStrategy(),
+ *   // ...
+ * }
+ * ```
+ *
+ * @docsCategory configuration
+ * @docsPage EntityIdStrategy
  */
 export class UuidIdStrategy implements EntityIdStrategy<'uuid'> {
     readonly primaryKeyType = 'uuid';

+ 1 - 1
packages/core/src/config/vendure-config.ts

@@ -730,7 +730,7 @@ export interface VendureConfig {
      * entities via the API. The default uses a simple auto-increment integer
      * strategy.
      *
-     * @default new AutoIncrementIdStrategy()
+     * @default AutoIncrementIdStrategy
      */
     entityIdStrategy?: EntityIdStrategy<any>;
     /**