From a510f90b13ccdbe169af36935adbe95ee40cd5d8 Mon Sep 17 00:00:00 2001 From: Baroshem Date: Fri, 19 Mar 2021 15:52:19 +0100 Subject: [PATCH] doc: correct ct config docs --- .../core/docs/commercetools/configuration.md | 187 ++++-------------- 1 file changed, 38 insertions(+), 149 deletions(-) diff --git a/packages/core/docs/commercetools/configuration.md b/packages/core/docs/commercetools/configuration.md index 1a2009a0c43..9ff188a08d7 100644 --- a/packages/core/docs/commercetools/configuration.md +++ b/packages/core/docs/commercetools/configuration.md @@ -9,8 +9,8 @@ Commercetools configuration is located in two places: ## Nuxt Commercetools configuration - ```js +// nuxt.config.js ['@vue-storefront/commercetools/nuxt', { i18n: { useNuxtI18nConfig: true @@ -18,163 +18,52 @@ Commercetools configuration is located in two places: }] ``` -## Middleware Commercetools configuration - - -```js -// middleware.config.js -ct: { - location: '@vue-storefront/commercetools-api/server', - configuration: { - api: { - /* your api configuration object */ - } - } -} -``` - -Minimal configuration object: - -```js -ct: { - location: '@vue-storefront/commercetools-api/server', - configuration: { - api: { - uri: 'https://.com//graphql', - authHost: 'https://auth.sphere.io', - projectKey: '', - clientId: '', - clientSecret: '', - scopes: [ - 'manage_products:', - /* other scope rules */ - ] - }, - currency: 'USD', - country: 'US' - } -} -``` +- `useNuxtI18nConfig` - when this variable is set to true, `@vue-storefront/commercetools/nuxt` package will use i18n config object provided in nuxt.config.js. When set to false, i18n config should be declared directly inside this package configuration. -### uri +If you do not have this package installed locally, please run: -Link to your Commercetools GraphQL API instance. It should look like this: -`https://.com//graphql` - -### authHost - -Link to Commercetools Authentication Server. It is used to request an access token from commercetools OAuth 2.0 service. To choose the nearest service, please visit [Commercetools hosts list](https://docs.commercetools.com/api/authorization) - -### projectKey - -i.e. `my-awesome-vsf-project` - -### clientId - -Unique Commercetools Client ID. Visit [Commercetools documentation](https://docs.commercetools.com/tutorials/getting-started#creating-an-api-client) for more details about creating an API Client - -### clientSecret - -Commercetools secret API key. Visit [Commercetools documentation](https://docs.commercetools.com/tutorials/getting-started#creating-an-api-client) for more details about creating an API Client - -### scopes - -The scope constrains the endpoints to which a client has access, and whether a client has read or write access to an endpoint. Visit [Commercetools documentation](https://docs.commercetools.com/api/scopes#top) for more details about Scopes. - - -Full configuration: - -```js -interface Config { - client?: ApolloClient; - api: ApiConfig; - customOptions?: ApolloClientOptions; - currency: string; - locale: string; - country: string; - countries: LocaleItem[]; - currencies: LocaleItem[]; - locales: LocaleItem[]; - languageMap: Record; - acceptLanguage: string[]; - cookies: CookiesConfig; - auth?: Auth; - forceToken?: boolean; - handleIsTokenUserSession: (token: Token) => boolean; -} +```sh +yarn add @vue-storefront/commercetools ``` -#### `client` - -Connection to the Commercetools client. `SdkAuth` and `TokenProvider` are imported from `@commercetools/sdk-auth` - -```js -interface ClientInstance extends ApolloClient { - sdkAuth?: SdkAuth; - tokenProvider?: TokenProvider; -} -``` - -#### `api` - -Commercetools API configuration from `middleware.config.js` - -```js -interface ApiConfig { - uri: string; - authHost: string; - projectKey: string; - clientId: string; - clientSecret: string; - scopes: string[]; -} -``` - -#### `countries`, `currencies`, `locales` - -Array of accepted items - -```js -interface LocaleItem { - name: string; - label: string; -} -``` - -#### `cookies` +## Middleware Commercetools configuration -Cookie names for `currency`, `country`, and `locale` +You can read more about middleware configuration in Vue Storefront [here](../advanced/server-middleware.md#configuration) ```js -interface CookiesConfig { - currencyCookieName: string; - countryCookieName: string; - localeCookieName: string; -} +// middleware.config.js +module.exports = { + integrations: { + ct: { + location: '@vue-storefront/commercetools-api/server', + configuration: { + api: { + uri: 'https://.com//graphql', + authHost: 'https://auth.sphere.io', + projectKey: '', + clientId: '', + clientSecret: '', + scopes: [ + 'manage_products:', + /* other scope rules */ + ] + }, + currency: 'USD', + country: 'US' + } + } + } +}; ``` -#### `auth` - -Token Authentication object. Later extended with custom extension `tokenExtension` - -```js -interface Auth { - onTokenChange?: (token: Token) => void; - onTokenRead?: () => string; - onTokenRemove?: () => void; -} - -interface Token { - access_token: string; - expires_at: number; - expires_in: number; - scope: string; - token_type: string; - refresh_token: string; -} -``` +- `uri` - link to your Commercetools GraphQL API instance. +- `authHost` - link to Commercetools Authentication Server. It is used to request an access token from commercetools OAuth 2.0 service. To choose the nearest service, please visit [Commercetools hosts list](https://docs.commercetools.com/api/authorization) +- `projectKey` - name of your Commercetools project, i.e. `my-awesome-vsf-project` +- `clientId` - unique Commercetools Client ID. Visit [Commercetools documentation](https://docs.commercetools.com/tutorials/getting-started#creating-an-api-client) for more details about creating an API Client +- `clientSecret` - Commercetools secret API key. Visit [Commercetools documentation](https://docs.commercetools.com/tutorials/getting-started#creating-an-api-client) for more details about creating an API Client +- `scopes` - The scope constrains the endpoints to which a client has access, and whether a client has read or write access to an endpoint. Visit [Commercetools documentation](https://docs.commercetools.com/api/scopes#top) for more details about Scopes. -#### `acceptLanguage` +### `acceptLanguage` Commercetools supports querying localised fields via an array of accepted languages - `acceptLanguage`. @@ -182,7 +71,7 @@ Commercetools supports querying localised fields via an array of accepted langua acceptLanguage: ['en-gb', 'en-us'] ``` -#### `languageMap` +### `languageMap` If you supply a `languageMap` during setup this will be used to map a locale to the accepted languages.