Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Revert "Revert "Add storefront missing headers""
Browse files Browse the repository at this point in the history
  • Loading branch information
mllemango authored Aug 9, 2023
1 parent 948720f commit c296253
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-kids-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/shopify-api': patch
---

Fix storefront header incorrectly setting private token as access token
2 changes: 0 additions & 2 deletions .changeset/tough-schools-know.md

This file was deleted.

2 changes: 1 addition & 1 deletion lib/clients/graphql/__tests__/storefront_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('Storefront GraphQL client', () => {
path: `/api/${shopify.config.apiVersion}/graphql.json`,
data: QUERY,
headers: {
[ShopifyHeader.StorefrontAccessToken]: 'private_token',
[ShopifyHeader.StorefrontPrivateToken]: 'private_token',
},
}).toMatchMadeHttpRequest();
});
Expand Down
15 changes: 9 additions & 6 deletions lib/clients/graphql/storefront_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ export class StorefrontClient extends GraphqlClient {

protected getApiHeaders(): HeaderParams {
const sdkVariant = LIBRARY_NAME.toLowerCase().split(' ').join('-');

const privateToken =
this.storefrontClass().config.privateAppStorefrontAccessToken;
const tokenHeaderParam =
privateToken === undefined
? {[ShopifyHeader.StorefrontAccessToken]: this.storefrontAccessToken}
: ({
[ShopifyHeader.StorefrontPrivateToken]: privateToken,
} as HeaderParams);
return {
[ShopifyHeader.StorefrontAccessToken]: this.storefrontClass().config
.isCustomStoreApp
? this.storefrontClass().config.privateAppStorefrontAccessToken ||
this.storefrontAccessToken
: this.storefrontAccessToken,
...tokenHeaderParam,
[ShopifyHeader.StorefrontSDKVariant]: sdkVariant,
[ShopifyHeader.StorefrontSDKVersion]: SHOPIFY_API_LIBRARY_VERSION,
};
Expand Down
1 change: 1 addition & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export enum ShopifyHeader {
Topic = 'X-Shopify-Topic',
WebhookId = 'X-Shopify-Webhook-Id',
StorefrontAccessToken = 'X-Shopify-Storefront-Access-Token',
StorefrontPrivateToken = 'Shopify-Storefront-Private-Token',
StorefrontSDKVariant = 'X-SDK-Variant',
StorefrontSDKVersion = 'X-SDK-Version',
}
Expand Down

0 comments on commit c296253

Please sign in to comment.