Skip to content

Commit

Permalink
Merge a510f90 into 36304ce
Browse files Browse the repository at this point in the history
  • Loading branch information
Baroshem committed Mar 19, 2021
2 parents 36304ce + a510f90 commit 45f71da
Showing 1 changed file with 38 additions and 149 deletions.
187 changes: 38 additions & 149 deletions packages/core/docs/commercetools/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,180 +9,69 @@ Commercetools configuration is located in two places:

## Nuxt Commercetools configuration


```js
// nuxt.config.js
['@vue-storefront/commercetools/nuxt', {
i18n: {
useNuxtI18nConfig: true
}
}]
```

## 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://<DOMAIN_NAME>.com/<PROJECT_KEY>/graphql',
authHost: 'https://auth.sphere.io',
projectKey: '<PROJECT_KEY>',
clientId: '<CLIENT_ID>',
clientSecret: '<CLIENT_SECRET>',
scopes: [
'manage_products:<PROJECT_KEY>',
/* 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://<DOMAIN_NAME>.com/<PROJECT_KEY>/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<T = any> {
client?: ApolloClient<T>;
api: ApiConfig;
customOptions?: ApolloClientOptions<any>;
currency: string;
locale: string;
country: string;
countries: LocaleItem[];
currencies: LocaleItem[];
locales: LocaleItem[];
languageMap: Record<string, any>;
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<any> {
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://<DOMAIN_NAME>.com/<PROJECT_KEY>/graphql',
authHost: 'https://auth.sphere.io',
projectKey: '<PROJECT_KEY>',
clientId: '<CLIENT_ID>',
clientSecret: '<CLIENT_SECRET>',
scopes: [
'manage_products:<PROJECT_KEY>',
/* 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`.

```js
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.

Expand Down

0 comments on commit 45f71da

Please sign in to comment.