Skip to content

Commit

Permalink
fix(js-api-client): allow auto fetch shop api token with static auth …
Browse files Browse the repository at this point in the history
…token in the configuration
  • Loading branch information
Plopix committed Mar 15, 2024
1 parent 2f79087 commit 4c635df
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/js-api-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@crystallize/js-api-client",
"license": "MIT",
"version": "2.3.0",
"version": "2.3.1",
"author": "Crystallize <[email protected]> (https://crystallize.com)",
"contributors": [
"Sébastien Morel <[email protected]>",
Expand Down
4 changes: 3 additions & 1 deletion components/js-api-client/src/core/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@ function shopApiCaller(configuration: ClientConfiguration, options?: CreateClien
let shopApiToken = configuration.shopApiToken;
return async function callApi<T>(query: string, variables?: VariablesType): Promise<T> {
if (!shopApiToken && options?.shopApiToken?.doNotFetch !== true) {
//static auth token is not enough for shop api token retrieval
const { staticAuthToken, ...withoutStaticAuthToken } = configuration;
const headers = {
'Content-type': 'application/json; charset=UTF-8',
Accept: 'application/json',
...authenticationHeaders(configuration),
...authenticationHeaders(withoutStaticAuthToken),
};
const response = await fetch(apiHost(configuration)([`@${identifier}`, 'auth', 'token'], 'shop-api'), {
method: 'POST',
Expand Down

0 comments on commit 4c635df

Please sign in to comment.