From c2962537c1265be88b28d54c32aa0fdf2ce7de95 Mon Sep 17 00:00:00 2001 From: Melanie Wang Date: Wed, 9 Aug 2023 16:38:25 -0400 Subject: [PATCH] Revert "Revert "Add storefront missing headers"" --- .changeset/beige-kids-build.md | 5 +++++ .changeset/tough-schools-know.md | 2 -- .../graphql/__tests__/storefront_client.test.ts | 2 +- lib/clients/graphql/storefront_client.ts | 15 +++++++++------ lib/types.ts | 1 + 5 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 .changeset/beige-kids-build.md delete mode 100644 .changeset/tough-schools-know.md diff --git a/.changeset/beige-kids-build.md b/.changeset/beige-kids-build.md new file mode 100644 index 000000000..af9da1480 --- /dev/null +++ b/.changeset/beige-kids-build.md @@ -0,0 +1,5 @@ +--- +'@shopify/shopify-api': patch +--- + +Fix storefront header incorrectly setting private token as access token diff --git a/.changeset/tough-schools-know.md b/.changeset/tough-schools-know.md deleted file mode 100644 index a845151cc..000000000 --- a/.changeset/tough-schools-know.md +++ /dev/null @@ -1,2 +0,0 @@ ---- ---- diff --git a/lib/clients/graphql/__tests__/storefront_client.test.ts b/lib/clients/graphql/__tests__/storefront_client.test.ts index 38b9f9ac3..d21f8afaf 100644 --- a/lib/clients/graphql/__tests__/storefront_client.test.ts +++ b/lib/clients/graphql/__tests__/storefront_client.test.ts @@ -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(); }); diff --git a/lib/clients/graphql/storefront_client.ts b/lib/clients/graphql/storefront_client.ts index 22a91969c..ccc1599a2 100644 --- a/lib/clients/graphql/storefront_client.ts +++ b/lib/clients/graphql/storefront_client.ts @@ -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, }; diff --git a/lib/types.ts b/lib/types.ts index 59b1d9c6a..3d81edc14 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -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', }