New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@labdigital/commercetools-utilities

Package Overview
Dependencies
Maintainers
5
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@labdigital/commercetools-utilities

## CommercetoolsClient

  • 0.8.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
262
decreased by-1.5%
Maintainers
5
Weekly downloads
 
Created
Source

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.

FAQs

Package last updated on 22 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc