@@ -163,7 +163,7 @@ function shopApiCaller(configuration: ClientConfiguration, options?: CreateClien
163163 let shopApiToken = configuration . shopApiToken ;
164164 return async function callApi < T > ( query : string , variables ?: VariablesType ) : Promise < T > {
165165 if ( ! shopApiToken && options ?. shopApiToken ?. doNotFetch !== true ) {
166- //static auth token is not enough for shop api token retrieval
166+ //static auth token must be removed to fetch the shop api token
167167 const { staticAuthToken, ...withoutStaticAuthToken } = configuration ;
168168 const headers = {
169169 'Content-type' : 'application/json; charset=UTF-8' ,
@@ -204,13 +204,49 @@ function shopApiCaller(configuration: ClientConfiguration, options?: CreateClien
204204
205205export function createClient ( configuration : ClientConfiguration , options ?: CreateClientOptions ) : ClientInterface {
206206 const identifier = configuration . tenantIdentifier ;
207+
208+ // let's rewrite the configuration based on the need of the endpoint
209+ // authenticationHeaders manages this priority: sessionId > staticAuthToken > accessTokenId/accessTokenSecret
210+ const commonConfig : ClientConfiguration = {
211+ tenantIdentifier : configuration . tenantIdentifier ,
212+ tenantId : configuration . tenantId ,
213+ origin : configuration . origin ,
214+ } ;
215+
216+ // static auth token is excluded
217+ const pimConfig : ClientConfiguration = {
218+ ...commonConfig ,
219+ sessionId : configuration . sessionId ,
220+ accessTokenId : configuration . accessTokenId ,
221+ accessTokenSecret : configuration . accessTokenSecret ,
222+ } ;
223+
224+ // sessionId is excluded
225+ const catalogConfig : ClientConfiguration = {
226+ ...commonConfig ,
227+ staticAuthToken : configuration . staticAuthToken ,
228+ accessTokenId : configuration . accessTokenId ,
229+ accessTokenSecret : configuration . accessTokenSecret ,
230+ } ;
231+
232+ // sessionId and static auth token are excluded
233+ const tokenOnlyConfig : ClientConfiguration = {
234+ ...commonConfig ,
235+ accessTokenId : configuration . accessTokenId ,
236+ accessTokenSecret : configuration . accessTokenSecret ,
237+ } ;
238+
207239 return {
208- catalogueApi : createApiCaller ( apiHost ( configuration ) ( [ identifier , 'catalogue' ] ) , configuration , options ) ,
209- searchApi : createApiCaller ( apiHost ( configuration ) ( [ identifier , 'search' ] ) , configuration , options ) ,
210- orderApi : createApiCaller ( apiHost ( configuration ) ( [ identifier , 'orders' ] ) , configuration , options ) ,
211- subscriptionApi : createApiCaller ( apiHost ( configuration ) ( [ identifier , 'subscriptions' ] ) , configuration , options ) ,
212- pimApi : createApiCaller ( apiHost ( configuration ) ( [ 'graphql' ] , 'pim' ) , configuration , options ) ,
213- nextPimApi : createApiCaller ( apiHost ( configuration ) ( [ `@${ identifier } ` ] ) , configuration , options ) ,
240+ catalogueApi : createApiCaller ( apiHost ( configuration ) ( [ identifier , 'catalogue' ] ) , catalogConfig , options ) ,
241+ searchApi : createApiCaller ( apiHost ( configuration ) ( [ identifier , 'search' ] ) , catalogConfig , options ) ,
242+ orderApi : createApiCaller ( apiHost ( configuration ) ( [ identifier , 'orders' ] ) , tokenOnlyConfig , options ) ,
243+ subscriptionApi : createApiCaller (
244+ apiHost ( configuration ) ( [ identifier , 'subscriptions' ] ) ,
245+ tokenOnlyConfig ,
246+ options ,
247+ ) ,
248+ pimApi : createApiCaller ( apiHost ( configuration ) ( [ 'graphql' ] , 'pim' ) , pimConfig , options ) ,
249+ nextPimApi : createApiCaller ( apiHost ( configuration ) ( [ `@${ identifier } ` ] ) , pimConfig , options ) ,
214250 shopCartApi : shopApiCaller ( configuration , options ) ,
215251 config : {
216252 tenantId : configuration . tenantId ,
0 commit comments