Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
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: () => {},
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',
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,
})
}
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,
}),
],
})
}
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,
}
}
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,
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
}
)
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, ''),
'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: () => {},