From 69e0b4af0c86f44fe6dd62948d3b01da8419888f Mon Sep 17 00:00:00 2001 From: Victor Campos Date: Wed, 22 Oct 2025 12:16:51 -0600 Subject: [PATCH] chore: improve the way we supply b2b cdn url --- .env.example | 7 ++++++- core/b2b/loader.tsx | 8 +++----- core/b2b/script-production.tsx | 12 ++++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index 80240ce092..0ed77c3cd3 100644 --- a/.env.example +++ b/.env.example @@ -51,4 +51,9 @@ B2B_API_HOST=https://api-b2b.bigcommerce.com BIGCOMMERCE_ACCESS_TOKEN= # URL for the local buyer portal instance. Uncomment if developing locally. -# LOCAL_BUYER_PORTAL_HOST=http://localhost:3001 \ No newline at end of file +# LOCAL_BUYER_PORTAL_HOST=http://localhost:3001 + +# If you don't need local buyer portal but you need to work in a different environment +# this variable will supply the correct microapps cdn url. +# It will default to "production". +# BUYER_PORTAL_ENVIRONMENT=production diff --git a/core/b2b/loader.tsx b/core/b2b/loader.tsx index 58db961435..613f0e7bd8 100644 --- a/core/b2b/loader.tsx +++ b/core/b2b/loader.tsx @@ -9,7 +9,7 @@ const EnvironmentSchema = z.object({ BIGCOMMERCE_STORE_HASH: z.string({ message: 'BIGCOMMERCE_STORE_HASH is required' }), BIGCOMMERCE_CHANNEL_ID: z.string({ message: 'BIGCOMMERCE_CHANNEL_ID is required' }), LOCAL_BUYER_PORTAL_HOST: z.string().url().optional(), - STAGING_B2B_CDN_ORIGIN: z.string().optional(), + BUYER_PORTAL_ENVIRONMENT: z.enum(['production', 'staging', 'integration']).optional().default('production'), }); export async function B2BLoader() { @@ -17,7 +17,7 @@ export async function B2BLoader() { BIGCOMMERCE_STORE_HASH, BIGCOMMERCE_CHANNEL_ID, LOCAL_BUYER_PORTAL_HOST, - STAGING_B2B_CDN_ORIGIN, + BUYER_PORTAL_ENVIRONMENT, } = EnvironmentSchema.parse(process.env); const session = await auth(); @@ -34,13 +34,11 @@ export async function B2BLoader() { ); } - const environment = STAGING_B2B_CDN_ORIGIN === 'true' ? 'staging' : 'production'; - return ( diff --git a/core/b2b/script-production.tsx b/core/b2b/script-production.tsx index eb2f4f7ef5..80168edc32 100644 --- a/core/b2b/script-production.tsx +++ b/core/b2b/script-production.tsx @@ -9,14 +9,22 @@ interface Props { storeHash: string; channelId: string; token?: string; - environment: 'staging' | 'production'; + environment: 'staging' | 'production' | 'integration'; cartId?: string | null; } +const CDN_BY_ENV: Record = { + production: 'https://microapps.bigcommerce.com', + staging: 'https://microapps.staging.zone', + integration: 'https://microapps.integration.zone', +}; + export function ScriptProduction({ cartId, storeHash, channelId, token, environment }: Props) { useB2BAuth(token); useB2BCart(cartId); + const src = `${CDN_BY_ENV[environment]}/b2b-buyer-portal/headless.js`; + return ( <>