From a6e5fb1a789ed042b631bf2c9484402bf55a8cfb Mon Sep 17 00:00:00 2001 From: Brett Cutting Date: Wed, 27 Nov 2024 12:03:55 +1000 Subject: [PATCH] MI-121: fix fomatting of release-notes.md file. Update the getBcCustomerIdFromMeshToken function to look for a bc_customer_id but comment as deprected to make the fix backwards compatible. --- packages/modules/bigcommerce/release-notes.md | 7 ++----- packages/modules/bigcommerce/src/types/index.ts | 2 ++ packages/modules/bigcommerce/src/utils/tokens.ts | 6 +++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/modules/bigcommerce/release-notes.md b/packages/modules/bigcommerce/release-notes.md index 57b8ef85..ad76040c 100644 --- a/packages/modules/bigcommerce/release-notes.md +++ b/packages/modules/bigcommerce/release-notes.md @@ -1,13 +1,10 @@ # BigCommerce GraphQl Module Release Notes -## bigcommerce-graphql-module-1.0.8 +## bigcommerce-graphql-module-1.1.0 #### Changes: -- Updates the "generateMeshToken" function to return a "customer_id" property instead of "bc_customer_id". -Updates the "getBcCustomerIdFromMeshToken" function to look for a "customer_id" property instead of "bc_customer_id". -This is due to the Auth Module generating a JWT containing a "customer_id" property -but the BigCommerce Module decodes the JWT and looks for a "bc_customer_id" property. +- Updates the "generateMeshToken" function to return a "customer_id" property instead of "bc_customer_id". Updates the "getBcCustomerIdFromMeshToken" function to look for a "customer_id" property instead of "bc_customer_id". This is due to the Auth Module generating a JWT containing a "customer_id" property but the BigCommerce Module decodes the JWT and looks for a "bc_customer_id" property. #### Tickets diff --git a/packages/modules/bigcommerce/src/types/index.ts b/packages/modules/bigcommerce/src/types/index.ts index 3a90cb4b..96307e36 100644 --- a/packages/modules/bigcommerce/src/types/index.ts +++ b/packages/modules/bigcommerce/src/types/index.ts @@ -181,6 +181,8 @@ export interface DecodedCustomerImpersonationToken { } export interface MeshToken { + /* @deprecated since v1.0.1. Use "customer_id" instead */ + bc_customer_id: number; customer_id: number; iat: number; exp: number; diff --git a/packages/modules/bigcommerce/src/utils/tokens.ts b/packages/modules/bigcommerce/src/utils/tokens.ts index bdf85853..3d484a2d 100644 --- a/packages/modules/bigcommerce/src/utils/tokens.ts +++ b/packages/modules/bigcommerce/src/utils/tokens.ts @@ -32,7 +32,9 @@ export const getBcCustomerIdFromMeshToken = (meshToken: string): number => { if (meshToken?.toLowerCase().startsWith('bearer')) { const splitMeshToken = meshToken.split(' ')[1]; const decodedMeshToken = verify(splitMeshToken, JWT_PRIVATE_KEY) as MeshToken; - return decodedMeshToken.customer_id; + + /* @deprecated since v1.0.1. Use "customer_id" instead of "bc_customer_id" */ + return decodedMeshToken.customer_id || decodedMeshToken.bc_customer_id; } else { throw new Error(`Need to send Bearer token`); } @@ -54,6 +56,8 @@ export const getBcCustomerIdFromMeshToken = (meshToken: string): number => { */ export const generateMeshToken = (entityId: number): string => { const payload = { + /* @deprecated since v1.0.1. Use "customer_id" instead */ + bc_customer_id: entityId, customer_id: entityId, exp: getUnixTimeStampInSecondsForMidnightTonight(), };