How to use @commercetools/sdk-middleware-user-agent - 10 common examples

To help you get started, we’ve selected a few @commercetools/sdk-middleware-user-agent 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 / packages / product-json-to-csv / src / main.js View on Github external
constructor(
    apiConfig: ApiConfigOptions,
    parserConfig: ParserConfigOptions,
    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,
          fetch,
        }),
      ],
    })

    const defaultConfig = {
      categoryBy: 'name', // key, externalId or namedPath supported
      categoryOrderHintBy: 'name', // key, externalId or name supported
      delimiter: ',',
      fillAllRows: false,
      onlyMasterVariants: false,
github commercetools / nodejs / packages / csv-parser-price / src / main.js View on Github external
constructor({ apiConfig, logger, csvConfig = {}, accessToken }) {
    this.client = createClient({
      middlewares: [
        createAuthMiddlewareForClientCredentialsFlow({ ...apiConfig, fetch }),
        createUserAgentMiddleware({
          libraryName: 'csv-parser-price',
          libraryVersion: version,
        }),
        createHttpMiddleware({
          host: apiConfig.apiUrl,
          fetch,
        }),
      ],
    })

    this.apiConfig = apiConfig
    this.accessToken = accessToken

    // noop the logger if not defined, should not polute stdout
    this.logger = logger || {
      error: () => {},
github commercetools / nodejs / integration-tests / sdk / channels.it.js View on Github external
const ignoredResponseKeys = [
    'id',
    'createdAt',
    'createdBy',
    'lastModifiedAt',
    'lastModifiedBy',
  ]
  const service = createRequestBuilder({ projectKey }).channels
  const httpMiddleware = createHttpMiddleware({
    host: 'https://api.sphere.io',
    fetch,
  })
  const queueMiddleware = createQueueMiddleware({
    concurrency: 5,
  })
  const userAgentMiddleware = createUserAgentMiddleware({
    libraryName: pkg.name,
    libraryVersion: pkg.version,
    contactUrl: 'https://github.com/commercetools/nodejs',
    contactEmail: 'npmjs@commercetools.com',
  })
  const key = uniqueId('channel_')
  let channelResponse
  let client
  let apiConfig

  beforeAll(() =>
    getCredentials(projectKey)
      .then(credentials => {
        apiConfig = {
          host: 'https://auth.sphere.io',
          apiUrl: 'https://api.sphere.io',
github commercetools / nodejs / packages / inventories-exporter / src / main.js View on Github external
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({
      projectKey: apiConfig.projectKey,
    })
  }
github commercetools / nodejs / packages / csv-parser-state / src / main.js View on Github external
static _setupClient(
    apiConfig: ApiConfigOptions,
    accessToken: string
  ): Object {
    if (!apiConfig)
      throw new Error('The constructor must be passed an `apiConfig` object')
    return createClient({
      middlewares: [
        createAuthMiddlewareWithExistingToken(
          accessToken ? `Bearer ${accessToken}` : ''
        ),
        createAuthMiddlewareForClientCredentialsFlow({ ...apiConfig, fetch }),
        createUserAgentMiddleware({
          libraryName: pkg.name,
          libraryVersion: pkg.version,
        }),
        createHttpMiddleware({
          host: apiConfig.apiUrl,
          fetch,
        }),
      ],
    })
  }
github commercetools / nodejs / packages / personal-data-erasure / src / main.js View on Github external
constructor(options: ErasureOptions) {
    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, fetch }),
      ],
    })

    this.logger = {
      ...silentLogger,
      ...options.logger,
    }
  }
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,
        }),
      ],
    })

    this.predicate = options.predicate

    this.logger = {
      ...silentLogger,
      ...options.logger,
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,
        }),
      ],
    })
    this.logger = {
      ...silentLogger,
      ...options.logger,
    }
    this.predicate = options.predicate
    this.resource = options.resource
  }
github commercetools / nodejs / packages / discount-code-importer / src / main.js View on Github external
)
    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,
        }),
      ],
    })

    this.syncDiscountCodes = createSyncDiscountCodes()

    this.logger = logger || {
      error: npmlog.error.bind(this, ''),
      warn: npmlog.warn.bind(this, ''),
      info: npmlog.info.bind(this, ''),
github commercetools / nodejs / packages / state-importer / src / main.js View on Github external
'The constructor must be passed an `apiConfig` object'
      )

    this.apiConfig = options.apiConfig
    this.accessToken = options.accessToken
    this.continueOnProblems = options.continueOnProblems || false
    this.client = createClient({
      middlewares: [
        createAuthMiddlewareWithExistingToken(
          this.accessToken ? `Bearer ${this.accessToken}` : ''
        ),
        createAuthMiddlewareForClientCredentialsFlow({
          ...this.apiConfig,
          fetch,
        }),
        createUserAgentMiddleware({
          libraryName: pkg.name,
          libraryVersion: pkg.version,
        }),
        createHttpMiddleware({
          host: this.apiConfig.apiUrl,
          fetch,
        }),
      ],
    })

    this.syncStates = createSyncStates()

    this.logger = logger || {
      error: () => {},
      warn: () => {},
      info: () => {},

@commercetools/sdk-middleware-user-agent

Middleware for setting the User-Agent on the HTTP request, to use with @commercetools/sdk-client

MIT
Latest version published 2 years ago

Package Health Score

64 / 100
Full package analysis

Popular @commercetools/sdk-middleware-user-agent functions