0.8.3 • Published 11 months ago
@labdigital/commercetools-utilities v0.8.3
Lab Digital Commercetools Utilities
CommercetoolsClient
This is a more straight-forward helper to create a commercetools client for interacting with Commercetools.
const client = CommercetoolsClient({
host: 'https://api.europe-west1.gcp.commercetools.com/',
projectKey: 'my-project',
auth: {
host: 'https://auth.europe-west1.gcp.commercetools.com/',
credentials: {
clientId: 'my-client-id',
clientSecret: 'my-client-secret',
},
scopes: ['view_orders:my-project', 'view_products:my-project'],
},
});
const projectApi = await client.getProjectApi();
projectApi.products().get().execute()
When the options are not passed it will read it from the ENV vars:
CT_PROJECT_KEY
CT_API_URL
CT_AUTH_URL
CT_CLIENT_ID
CT_CLIENT_SECRET
CT_SCOPES
const client = CommercetoolsClient();
client.getProjectApi();
You can also pass a callable to auth
which returns a token to be used.
const client = createClient({
host: process.env.CT_API_URL,
projectKey,
auth: async () => {
return 'mytoken';
},
});
client.getProjectApi();
Note that the ApiRoot object is cached on the client instance for 900 seconds
Pass custom middleware to the Commercetools client
const client = CommercetoolsClient({
host: 'https://api.europe-west1.gcp.commercetools.com/',
projectKey: 'my-project',
auth: {
host: 'https://auth.europe-west1.gcp.commercetools.com/',
credentials: {
clientId: 'my-client-id',
clientSecret: 'my-client-secret',
},
scopes: ['view_orders:my-project', 'view_products:my-project'],
},
middlewares: [yourMiddleware]
});
See the commercetools sdk docs for an example of custom middleware or check the tests in client.test.ts
.
0.8.3
11 months ago
0.7.3
2 years ago
0.7.2
2 years ago
0.7.1
2 years ago
0.7.0
2 years ago
0.6.1
3 years ago
0.5.4
3 years ago
0.5.3
3 years ago
0.5.2
3 years ago
0.5.0
3 years ago
0.5.1
3 years ago
0.4.1
3 years ago
0.4.0
3 years ago
0.3.4
3 years ago
0.3.3
3 years ago
0.3.2
3 years ago
0.3.1
3 years ago
0.3.0
3 years ago
0.2.1
3 years ago
0.1.2
3 years ago
0.2.0
3 years ago
0.1.3
3 years ago
0.1.1
3 years ago
0.1.0
3 years ago