Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
})
}, 7000)
.then(credentials => {
apiConfig = {
host: 'https://auth.sphere.io',
apiUrl: 'https://api.sphere.io',
projectKey,
credentials: {
clientId: credentials.clientId,
clientSecret: credentials.clientSecret,
},
fetch,
}
const authMiddleware = createAuthMiddlewareForClientCredentialsFlow(
apiConfig
)
client = createClient({
middlewares: [
authMiddleware,
queueMiddleware,
userAgentMiddleware,
httpMiddleware,
],
})
})
.then(() => clearData(apiConfig, 'channels'))
export function createData(apiConfig, entityName, data, id) {
const client = createClient({
middlewares: [
createAuthMiddlewareForClientCredentialsFlow({ ...apiConfig, fetch }),
createHttpMiddleware({ host: apiConfig.apiUrl, fetch }),
],
})
const requestOption = { projectKey: apiConfig.projectKey }
const service = createRequestBuilder(requestOption)[entityName]
return Promise.all(
data.map(_data => {
if (id) service.byId(id)
const request = {
uri: service.build(),
method: 'POST',
body: _data,
}
return client.execute(request)
})
)
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({
projectKey: apiConfig.projectKey,
})
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,
}),
],
})
this.syncDiscountCodes = createSyncDiscountCodes()
constructor(options: ConstructorOptions, logger: LoggerOptions) {
if (!options.apiConfig)
throw new StateImportError(
'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()
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,
}),
],
})
this.predicate = options.predicate
constructor(options: ExporterOptions, logger: LoggerOptions) {
if (!options.apiConfig)
throw new Error('The contructor must be passed an `apiConfig` object')
if (options.batchSize > 500)
throw new Error('The `batchSize` must not be more than 500')
this.apiConfig = options.apiConfig
this.client = createClient({
middlewares: [
createAuthMiddlewareForClientCredentialsFlow({
...this.apiConfig,
fetch,
}),
createUserAgentMiddleware({
libraryName: pkg.name,
libraryVersion: pkg.version,
}),
createHttpMiddleware({
host: this.apiConfig.apiUrl,
enableRetry: true,
fetch,
}),
],
})
const defaultOptions = {
function makeCommerceToolsClient({
parameters: {
installation: { apiEndpoint, authApiEndpoint, projectKey, clientId, clientSecret }
}
}) {
const authMiddleware = createAuthMiddlewareForClientCredentialsFlow({
host: authApiEndpoint,
projectKey: projectKey,
credentials: {
clientId: clientId,
clientSecret: clientSecret
}
});
const httpMiddleware = createHttpMiddleware({
host: apiEndpoint
});
const queueMiddleware = createQueueMiddleware({
concurrency: 5
});
constructor(options: ExporterOptions, logger: LoggerOptions) {
if (!options.apiConfig)
throw new Error('The constructor must be passed an `apiConfig` object')
if (!options.csvHeaders && options.exportFormat === 'csv')
throw new Error(
'The constructor must be passed a `csvHeaders` array for CSV export'
)
this.apiConfig = options.apiConfig
this.client = createClient({
middlewares: [
createAuthMiddlewareForClientCredentialsFlow({
...this.apiConfig,
fetch,
}),
createUserAgentMiddleware({
libraryName: pkg.name,
libraryVersion: pkg.version,
}),
createHttpMiddleware({
host: this.apiConfig.apiUrl,
enableRetry: true,
fetch,
}),
],
})
const defaultOptions = {