From feea93a93068b1d3275275ab616bb61149a3cb5f Mon Sep 17 00:00:00 2001 From: Stephen Rugh Date: Wed, 8 Jan 2025 10:12:07 -0600 Subject: [PATCH] all initializers accept headers from config Signed-off-by: Stephen Rugh --- scripts/initializers/account.js | 6 ++++-- scripts/initializers/auth.js | 6 ++++-- scripts/initializers/cart.js | 6 ++++-- scripts/initializers/checkout.js | 6 ++++-- scripts/initializers/order.js | 14 ++++++++------ 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/scripts/initializers/account.js b/scripts/initializers/account.js index e5dd940959..87423cbb41 100644 --- a/scripts/initializers/account.js +++ b/scripts/initializers/account.js @@ -1,11 +1,13 @@ import { initializers } from '@dropins/tools/initializer.js'; -import { initialize } from '@dropins/storefront-account/api.js'; +import { initialize, setFetchGraphQlHeaders } from '@dropins/storefront-account/api.js'; import { initializeDropin } from './index.js'; import { fetchPlaceholders } from '../aem.js'; +import { getHeaders } from '../configs.js'; await initializeDropin(async () => { - const labels = await fetchPlaceholders(); + setFetchGraphQlHeaders(await getHeaders('account')); + const labels = await fetchPlaceholders(); const langDefinitions = { default: { ...labels, diff --git a/scripts/initializers/auth.js b/scripts/initializers/auth.js index c60f736b9f..91f243fe4d 100644 --- a/scripts/initializers/auth.js +++ b/scripts/initializers/auth.js @@ -1,12 +1,14 @@ /* eslint-disable import/no-cycle */ import { initializers } from '@dropins/tools/initializer.js'; -import { initialize } from '@dropins/storefront-auth/api.js'; +import { initialize, setFetchGraphQlHeaders } from '@dropins/storefront-auth/api.js'; import { initializeDropin } from './index.js'; import { fetchPlaceholders } from '../aem.js'; +import { getHeaders } from '../configs.js'; await initializeDropin(async () => { - const labels = await fetchPlaceholders(); + setFetchGraphQlHeaders(await getHeaders('auth')); + const labels = await fetchPlaceholders(); const langDefinitions = { default: { ...labels, diff --git a/scripts/initializers/cart.js b/scripts/initializers/cart.js index 109719dc35..71703a5891 100644 --- a/scripts/initializers/cart.js +++ b/scripts/initializers/cart.js @@ -1,12 +1,14 @@ /* eslint-disable import/no-cycle */ import { initializers } from '@dropins/tools/initializer.js'; -import { initialize } from '@dropins/storefront-cart/api.js'; +import { initialize, setFetchGraphQlHeaders } from '@dropins/storefront-cart/api.js'; import { initializeDropin } from './index.js'; import { fetchPlaceholders } from '../aem.js'; +import { getHeaders } from '../configs.js'; await initializeDropin(async () => { - const labels = await fetchPlaceholders(); + setFetchGraphQlHeaders(await getHeaders('cart')); + const labels = await fetchPlaceholders(); const langDefinitions = { default: { ...labels, diff --git a/scripts/initializers/checkout.js b/scripts/initializers/checkout.js index 80935232e3..857b61ff4c 100644 --- a/scripts/initializers/checkout.js +++ b/scripts/initializers/checkout.js @@ -1,11 +1,13 @@ import { initializers } from '@dropins/tools/initializer.js'; -import { initialize } from '@dropins/storefront-checkout/api.js'; +import { initialize, setFetchGraphQlHeaders } from '@dropins/storefront-checkout/api.js'; import { initializeDropin } from './index.js'; import { fetchPlaceholders } from '../aem.js'; +import { getHeaders } from '../configs.js'; await initializeDropin(async () => { - const labels = await fetchPlaceholders(); + setFetchGraphQlHeaders(await getHeaders('checkout')); + const labels = await fetchPlaceholders(); const langDefinitions = { default: { ...labels, diff --git a/scripts/initializers/order.js b/scripts/initializers/order.js index 23f263c5dd..6a10da04df 100644 --- a/scripts/initializers/order.js +++ b/scripts/initializers/order.js @@ -1,7 +1,7 @@ import { events } from '@dropins/tools/event-bus.js'; import { initializers } from '@dropins/tools/initializer.js'; -import { initialize } from '@dropins/storefront-order/api.js'; -import { checkIsAuthenticated } from '../configs.js'; +import { initialize, setFetchGraphQlHeaders } from '@dropins/storefront-order/api.js'; +import { checkIsAuthenticated, getHeaders } from '../configs.js'; import { initializeDropin } from './index.js'; import { fetchPlaceholders } from '../aem.js'; @@ -19,11 +19,17 @@ import { await initializeDropin(async () => { const { pathname, searchParams } = new URL(window.location.href); + if (pathname.includes(CUSTOMER_ORDERS_PATH)) { + return; + } const isAccountPage = pathname.includes(CUSTOMER_PATH); const orderRef = searchParams.get('orderRef'); const returnRef = searchParams.get('returnRef'); const orderNumber = searchParams.get('orderNumber'); const isTokenProvided = orderRef && orderRef.length > 20; + + setFetchGraphQlHeaders(await getHeaders('order')); + const labels = await fetchPlaceholders(); const langDefinitions = { default: { @@ -31,10 +37,6 @@ await initializeDropin(async () => { }, }; - if (pathname.includes(CUSTOMER_ORDERS_PATH)) { - return; - } - const pathsRequiringRedirects = [ ORDER_DETAILS_PATH, CUSTOMER_ORDER_DETAILS_PATH,