Skip to content

Commit

Permalink
fix: do not pass empty sessionid to js-api-client (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
Plopix authored Aug 30, 2023
1 parent d3b1df8 commit afafc0d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-islands-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@crystallize/import-utilities': patch
---

do not pass empty sessionid to js-api-client
53 changes: 27 additions & 26 deletions src/bootstrap-tenant/bootstrapper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
},
Expand All @@ -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)
},
Expand Down Expand Up @@ -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, {})

Expand Down Expand Up @@ -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)
},
Expand Down

0 comments on commit afafc0d

Please sign in to comment.