From afafc0d6993a266e715f8f2501ec9c037b1255c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Morel?= Date: Wed, 30 Aug 2023 16:13:36 -0700 Subject: [PATCH] fix: do not pass empty sessionid to js-api-client (#94) --- .changeset/rude-islands-relate.md | 5 ++ src/bootstrap-tenant/bootstrapper/index.ts | 53 +++++++++++----------- 2 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 .changeset/rude-islands-relate.md diff --git a/.changeset/rude-islands-relate.md b/.changeset/rude-islands-relate.md new file mode 100644 index 0000000..cd44d1a --- /dev/null +++ b/.changeset/rude-islands-relate.md @@ -0,0 +1,5 @@ +--- +'@crystallize/import-utilities': patch +--- + +do not pass empty sessionid to js-api-client diff --git a/src/bootstrap-tenant/bootstrapper/index.ts b/src/bootstrap-tenant/bootstrapper/index.ts index 1f50683..ee48d29 100644 --- a/src/bootstrap-tenant/bootstrapper/index.ts +++ b/src/bootstrap-tenant/bootstrapper/index.ts @@ -41,7 +41,7 @@ import { import { createAPICaller } from './utils/api' import { setOrders } from './orders' import { setCustomers } from './customers' -import { createClient, createMassCallClient } from '@crystallize/js-api-client' +import { ClientConfiguration, createClient, createMassCallClient } from '@crystallize/js-api-client' import { getExistingOrders } from './utils/get-all-orders' import { getExistingCustomers } from './utils/get-all-customers' @@ -194,11 +194,10 @@ export class Bootstrapper extends EventEmitter { setSessionId = (sessionId: string) => { // PIM this.PIMAPIManager = createAPICaller({ - uri: `https://${ - this.env === 'dev' - ? 'pim-dev.crystallize.digital' - : 'pim.crystallize.com' - }/graphql`, + uri: `https://${this.env === 'dev' + ? 'pim-dev.crystallize.digital' + : 'pim.crystallize.com' + }/graphql`, errorNotifier: (error: BootstrapperError) => { this.emit(EVENT_NAMES.ERROR, error) }, @@ -212,11 +211,10 @@ export class Bootstrapper extends EventEmitter { setAccessToken = (ACCESS_TOKEN_ID: string, ACCESS_TOKEN_SECRET: string) => { // PIM this.PIMAPIManager = createAPICaller({ - uri: `https://${ - this.env === 'dev' - ? 'pim-dev.crystallize.digital' - : 'pim.crystallize.com' - }/graphql`, + uri: `https://${this.env === 'dev' + ? 'pim-dev.crystallize.digital' + : 'pim.crystallize.com' + }/graphql`, errorNotifier: (error: BootstrapperError) => { this.emit(EVENT_NAMES.ERROR, error) }, @@ -302,21 +300,25 @@ export class Bootstrapper extends EventEmitter { this.context.fileUploader.context = this.context this.context.defaultLanguage = tenant.defaults.language - const baseUrl = `https://${ - this.env === 'dev' - ? 'api-dev.crystallize.digital' - : 'api.crystallize.com' - }/${this.context.tenantIdentifier}` + const baseUrl = `https://${this.env === 'dev' + ? 'api-dev.crystallize.digital' + : 'api.crystallize.com' + }/${this.context.tenantIdentifier}` - const client = createClient({ + let clientConfig: ClientConfiguration = { tenantIdentifier: this.context.tenantIdentifier, tenantId: this.context.tenantId, accessTokenId: this.PIMAPIManager?.CRYSTALLIZE_ACCESS_TOKEN_ID, accessTokenSecret: this.PIMAPIManager?.CRYSTALLIZE_ACCESS_TOKEN_SECRET, - sessionId: this.PIMAPIManager?.CRYSTALLIZE_SESSION_ID, - origin: - this.env === 'dev' ? '-dev.crystallize.digital' : '.crystallize.com', - }) + origin: this.env === 'dev' ? '-dev.crystallize.digital' : '.crystallize.com', + } + if (`${this.PIMAPIManager?.CRYSTALLIZE_SESSION_ID}`.length > 0) { + clientConfig = { + ...clientConfig, + sessionId: this.PIMAPIManager?.CRYSTALLIZE_SESSION_ID, + } + } + const client = createClient(clientConfig) this.context.client = createMassCallClient(client, {}) @@ -346,11 +348,10 @@ export class Bootstrapper extends EventEmitter { // Orders this.ordersAPIManager = createAPICaller({ - uri: `https://${ - this.env === 'dev' - ? 'api-dev.crystallize.digital' - : 'api.crystallize.com' - }/${this.tenantIdentifier}/orders`, + uri: `https://${this.env === 'dev' + ? 'api-dev.crystallize.digital' + : 'api.crystallize.com' + }/${this.tenantIdentifier}/orders`, errorNotifier: (error: BootstrapperError) => { this.emit(EVENT_NAMES.ERROR, error) },