How to use @commercetools/sdk-client - 9 common examples

To help you get started, we’ve selected a few @commercetools/sdk-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github commercetools / nodejs / integration-tests / ts-sdk / ts-sdk.it.js View on Github external
it('create an anonymous session and a cart tied to the session', () => {
      const authConfig = {
        ...apiConfig,
        ...{ scopes: [`manage_project:${projectKey}`] },
        ...{
          credentials: {
            clientId: apiConfig.credentials.clientId,
            clientSecret: apiConfig.credentials.clientSecret,
          },
        },
        fetch,
      }
      const client = createClient({
        middlewares: [
          createAuthMiddlewareForClientCredentialsFlow(authConfig),
          httpMiddleware,
        ],
      })

      const apiRoot = createApiBuilderFromCtpClient(client)

      return apiRoot
        .withProjectKey({
          projectKey,
        })
        .get()
        .execute()
        .then(res => {
          expect(res.body.key).toEqual(projectKey)
github commercetools / nodejs / integration-tests / cli / resource-deleter.it.js View on Github external
function getResource(resource) {
    const client = createClient({
      middlewares: [
        createAuthMiddlewareForClientCredentialsFlow({ ...apiConfig, fetch }),
        createHttpMiddleware({ host: apiConfig.apiUrl, fetch }),
      ],
    })

    const service = createRequestBuilder({
      projectKey: apiConfig.projectKey,
    })[resource]

    const request = {
      uri: service.build(),
      method: 'GET',
    }

    return client.execute(request)
github commercetools / nodejs / packages / customer-groups-exporter / src / main.js View on Github external
constructor(options: ExporterOptions) {
    if (!options.apiConfig)
      throw new Error('The constructor must be passed an `apiConfig` object')
    this.apiConfig = options.apiConfig
    this.client = createClient({
      middlewares: [
        createAuthMiddlewareWithExistingToken(
          options.accessToken ? `Bearer ${options.accessToken}` : ''
        ),
        createAuthMiddlewareForClientCredentialsFlow({
          ...this.apiConfig,
          fetch,
        }),
        createUserAgentMiddleware({
          libraryName: pkg.name,
          libraryVersion: pkg.version,
        }),
        createHttpMiddleware({
          host: this.apiConfig.apiUrl,
          enableRetry: true,
          fetch,
github commercetools / nodejs / packages / category-exporter / src / main.js View on Github external
constructor(options: CategoryExporterOptions) {
    if (!options.apiConfig)
      throw new Error('The constructor must be passed an `apiConfig` object')
    this.apiConfig = options.apiConfig
    this.client = createClient({
      middlewares: [
        createAuthMiddlewareWithExistingToken(
          options.accessToken ? `Bearer ${options.accessToken}` : ''
        ),
        createAuthMiddlewareForClientCredentialsFlow({
          ...this.apiConfig,
          fetch,
        }),
        createUserAgentMiddleware({
          libraryName: pkg.name,
          libraryVersion: pkg.version,
        }),
        createHttpMiddleware({
          host: this.apiConfig.apiUrl,
          enableRetry: true,
          fetch,
github commercetools / nodejs / packages / product-exporter / src / main.js View on Github external
constructor(
    apiConfig: ApiConfigOptions,
    exportConfig: ExportConfigOptions,
    logger: LoggerOptions,
    accessToken: string
  ) {
    this.apiConfig = apiConfig
    this.client = createClient({
      middlewares: [
        createAuthMiddlewareForClientCredentialsFlow({
          ...this.apiConfig,
          fetch,
        }),
        createUserAgentMiddleware({
          libraryName: pkg.name,
          libraryVersion: pkg.version,
        }),
        createHttpMiddleware({
          host: this.apiConfig.apiUrl,
          enableRetry: true,
          fetch,
        }),
      ],
    })
github commercetools / nodejs / packages / inventories-exporter / src / main.js View on Github external
exportConfig: ExportConfig = {
      headerFields: null,
      format: CONS.standardOption.format,
      delimiter: CONS.standardOption.delimiter,
    },
    accessToken: string
  ) {
    this.logger = {
      error: () => {},
      info: () => {},
      warn: () => {},
      verbose: () => {},
      ...logger,
    }

    this.client = createClient({
      middlewares: [
        createAuthMiddlewareForClientCredentialsFlow({ ...apiConfig, fetch }),
        createUserAgentMiddleware({
          libraryName: name,
          libraryVersion: version,
        }),
        createHttpMiddleware({
          host: apiConfig.apiUrl,
          enableRetry: true,
          fetch,
        }),
      ],
    })
    this.exportConfig = exportConfig
    this.accessToken = accessToken
    this.reqBuilder = createRequestBuilder({
github commercetools / nodejs / packages / discount-code-importer / src / main.js View on Github external
constructor(options: ConstructorOptions, logger: LoggerOptions) {
    if (!options.apiConfig)
      throw new DiscountCodeImportError(
        'The contructor must be passed an `apiConfig` object'
      )
    if (options.batchSize > 200)
      throw new DiscountCodeImportError(
        'The `batchSize` must not be more than 200'
      )
    this.apiConfig = options.apiConfig
    this.accessToken = options.accessToken
    this.batchSize = options.batchSize || 50
    this.continueOnProblems = options.continueOnProblems || false
    this.client = createClient({
      middlewares: [
        createAuthMiddlewareForClientCredentialsFlow({
          ...this.apiConfig,
          fetch,
        }),
        createUserAgentMiddleware({
          libraryName: pkg.name,
          libraryVersion: pkg.version,
        }),
        createHttpMiddleware({
          host: this.apiConfig.apiUrl,
          fetch,
        }),
      ],
    })
github commercetools / nodejs / packages / resource-deleter / src / main.js View on Github external
constructor(options: resourceDeleterOptions) {
    if (!options.apiConfig)
      throw new Error('The constructor must passed an `apiConfig` object')

    if (!options.resource) throw new Error('A `resource` object must be passed')
    this.apiConfig = options.apiConfig
    this.client = createClient({
      middlewares: [
        createAuthMiddlewareWithExistingToken(
          options.accessToken ? `Bearer ${options.accessToken}` : ''
        ),
        createAuthMiddlewareForClientCredentialsFlow({
          ...this.apiConfig,
          fetch,
        }),
        createUserAgentMiddleware({
          libraryName: pkg.name,
          libraryVersion: pkg.version,
        }),
        createHttpMiddleware({ host: this.apiConfig.apiUrl, fetch }),
        createQueueMiddleware({
          concurrency: 20,
        }),
github contentful / extensions / marketplace / commercetools-sku / src / index.js View on Github external
projectKey: projectKey,
    credentials: {
      clientId: clientId,
      clientSecret: clientSecret
    }
  });

  const httpMiddleware = createHttpMiddleware({
    host: apiEndpoint
  });

  const queueMiddleware = createQueueMiddleware({
    concurrency: 5
  });

  return createClient({
    middlewares: [authMiddleware, httpMiddleware, queueMiddleware]
  });
}

@commercetools/sdk-client

SDK Client for usage of commercetools platform API

MIT
Latest version published 2 years ago

Package Health Score

66 / 100
Full package analysis

Popular @commercetools/sdk-client functions