Procházet zdrojové kódy

docs(docs): Add some developer guides

Michael Bromley před 6 roky
rodič
revize
54078d0059

+ 1 - 5
admin-ui/src/app/common/generated-types.ts

@@ -1932,11 +1932,7 @@ export type OrderLine = Node & {
   totalPrice: Scalars['Int'],
   adjustments: Array<Adjustment>,
   order: Order,
-  customFields?: Maybe<OrderLineCustomFields>,
-};
-
-export type OrderLineCustomFields = {
-  message?: Maybe<Scalars['String']>,
+  customFields?: Maybe<Scalars['JSON']>,
 };
 
 export type OrderList = PaginatedList & {

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

@@ -0,0 +1,9 @@
+---
+title: "Developer Guide"
+weight: 1
+showtoc: false
+---
+ 
+# Developer Guide
+
+This section contains guides for developers building applications which consume the Vendure API. The primary focus is on the use of the Shop API, since the Admin API functions are covered by the admin-ui-plugin.

+ 60 - 0
docs/content/docs/developer-guide/authentication-and-sessions.md

@@ -0,0 +1,60 @@
+---
+title: "Authentication & Sessions"
+weight: 0
+showtoc: true
+---
+ 
+# Authentication & Sessions
+
+Vendure supports two ways to manage user sessions: cookies and bearer token. The method you choose depends on your requirements, and is specified by the [`authOptions.tokenMethod` property]({{< relref "auth-options" >}}#tokenmethod) of the VendureConfig.
+
+## Cookie-based sessions (default)
+
+Using cookies is the simpler approach for browser-based applications, since the browser will manage the cookies for you automatically. 
+
+When using cookie-based sessions, you should set the [`authOptions.sessionSecret` property]({{< relref "auth-options" >}}#sessionsecret) to some secret string which will be used to sign the cookies sent to clients to prevent tampering. This string could be hard-coded in your config file, or (better) reside in an environment variable:
+
+```TypeScript
+const config = {
+    // ...
+    authOptions: {
+        tokenMethod: 'cookie',
+        sessionSecret: process.env.COOKIE_SESSION_SECRET
+    }
+}
+```
+
+## Bearer-token sessions
+
+In environments when cookies cannot be easily used (e.g. in some server environments), then the bearer-token method can be used.
+
+Using bearer tokens involes a bit more work on your part: you'll need to manually read response headers to get the token, and once you have it you'll have to manually add it to the headers of each request. Here's a simplified example of how that would look:
+
+```TypeScript
+const config = {
+    // ...
+    authOptions: {
+        tokenMethod: 'bearer',
+    }
+}
+```
+
+```TypeScript
+let token: string;
+
+export async function request(query: string, variables: any) {
+     // If we already know the token, set the Authorization header.
+     const headers = token ? { Authorization: `Bearer ${token}` } : {};
+     
+     const response = await someGraphQlClient(query, variables, headers);
+    
+     // Check the response headers to see if Vendure has set the 
+     // auth token. The header key "vendure-auth-token" may be set to
+     // a custom value with the authOptions.authTokenHeaderKey config option.
+     const authToken = response.headers.get('vendure-auth-token');
+     if (authToken != null) {
+         token = authToken;
+     }
+     return response.data;
+}
+```

+ 37 - 0
docs/content/docs/developer-guide/customizing-models.md

@@ -0,0 +1,37 @@
+---
+title: "Customizing Models"
+weight: 0
+showtoc: true
+---
+ 
+# Customizing Models with custom fields
+
+Custom fields allow you to add your own custom data properties to many of the Vendure entities. The entities which may be have custom fields defined are listed in the [CustomFields documentation]({{< relref "/docs/typescript-api/custom-fields" >}})
+
+They are specified in the VendureConfig:
+
+```TypeScript
+const config = {
+    // ...
+    dbConnectionOptions: {
+         // ...
+         synchronize: true,  
+    },
+    customFields: {
+        Product: [
+                { name: 'infoUrl', type: 'string' },
+                { name: 'downloadable', type: 'boolean' },
+                { name: 'shortName', type: 'localeString' },
+            ],
+            User: [
+                { name: 'socialLoginToken', type: 'string' },
+            ],
+        },
+}
+```
+
+With the example config above, the following will occur:
+
+1. The database schema will be altered and a column will be added for each custom field. Note: this step requires the [TypeORM synchronize option](https://typeorm.io/#/connection-options/common-connection-options) to be set to `true` as above.
+2. The GraphQL APIs will be modified on bootstrap to add the custom fields to the `Product` and `User` types respectively.
+3. If you are using the [admin-ui-plugin]({{< relref "docs/plugins/admin-ui-plugin" >}}), the Admin UI detail pages will now contain form inputs to allow the custom field data to be added or edited.

+ 1 - 11
packages/common/src/generated-shop-types.ts

@@ -1159,7 +1159,6 @@ export type Mutation = {
 export type MutationAddItemToOrderArgs = {
     productVariantId: Scalars['ID'];
     quantity: Scalars['Int'];
-    customFields?: Maybe<OrderLineCustomFieldsInput>;
 };
 
 export type MutationRemoveOrderLineArgs = {
@@ -1169,7 +1168,6 @@ export type MutationRemoveOrderLineArgs = {
 export type MutationAdjustOrderLineArgs = {
     orderLineId: Scalars['ID'];
     quantity?: Maybe<Scalars['Int']>;
-    customFields?: Maybe<OrderLineCustomFieldsInput>;
 };
 
 export type MutationTransitionOrderToStateArgs = {
@@ -1343,15 +1341,7 @@ export type OrderLine = Node & {
     totalPrice: Scalars['Int'];
     adjustments: Array<Adjustment>;
     order: Order;
-    customFields?: Maybe<OrderLineCustomFields>;
-};
-
-export type OrderLineCustomFields = {
-    message?: Maybe<Scalars['String']>;
-};
-
-export type OrderLineCustomFieldsInput = {
-    message?: Maybe<Scalars['String']>;
+    customFields?: Maybe<Scalars['JSON']>;
 };
 
 export type OrderList = PaginatedList & {

+ 1 - 5
packages/common/src/generated-types.ts

@@ -1911,11 +1911,7 @@ export type OrderLine = Node & {
   totalPrice: Scalars['Int'],
   adjustments: Array<Adjustment>,
   order: Order,
-  customFields?: Maybe<OrderLineCustomFields>,
-};
-
-export type OrderLineCustomFields = {
-  message?: Maybe<Scalars['String']>,
+  customFields?: Maybe<Scalars['JSON']>,
 };
 
 export type OrderList = PaginatedList & {

+ 1 - 5
packages/core/e2e/graphql/generated-e2e-admin-types.ts

@@ -1851,11 +1851,7 @@ export type OrderLine = Node & {
     totalPrice: Scalars['Int'];
     adjustments: Array<Adjustment>;
     order: Order;
-    customFields?: Maybe<OrderLineCustomFields>;
-};
-
-export type OrderLineCustomFields = {
-    message?: Maybe<Scalars['String']>;
+    customFields?: Maybe<Scalars['JSON']>;
 };
 
 export type OrderList = PaginatedList & {

+ 1 - 11
packages/core/e2e/graphql/generated-e2e-shop-types.ts

@@ -1159,7 +1159,6 @@ export type Mutation = {
 export type MutationAddItemToOrderArgs = {
     productVariantId: Scalars['ID'];
     quantity: Scalars['Int'];
-    customFields?: Maybe<OrderLineCustomFieldsInput>;
 };
 
 export type MutationRemoveOrderLineArgs = {
@@ -1169,7 +1168,6 @@ export type MutationRemoveOrderLineArgs = {
 export type MutationAdjustOrderLineArgs = {
     orderLineId: Scalars['ID'];
     quantity?: Maybe<Scalars['Int']>;
-    customFields?: Maybe<OrderLineCustomFieldsInput>;
 };
 
 export type MutationTransitionOrderToStateArgs = {
@@ -1343,15 +1341,7 @@ export type OrderLine = Node & {
     totalPrice: Scalars['Int'];
     adjustments: Array<Adjustment>;
     order: Order;
-    customFields?: Maybe<OrderLineCustomFields>;
-};
-
-export type OrderLineCustomFields = {
-    message?: Maybe<Scalars['String']>;
-};
-
-export type OrderLineCustomFieldsInput = {
-    message?: Maybe<Scalars['String']>;
+    customFields?: Maybe<Scalars['JSON']>;
 };
 
 export type OrderList = PaginatedList & {

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
schema-admin.json


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
schema-shop.json


Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů