Skip to content

Commit

Permalink
all initializers accept headers from config
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Rugh <[email protected]>
  • Loading branch information
sirugh committed Jan 8, 2025
1 parent eff0b42 commit feea93a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
6 changes: 4 additions & 2 deletions scripts/initializers/account.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 4 additions & 2 deletions scripts/initializers/auth.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 4 additions & 2 deletions scripts/initializers/cart.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 4 additions & 2 deletions scripts/initializers/checkout.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
14 changes: 8 additions & 6 deletions scripts/initializers/order.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -19,22 +19,24 @@ 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: {
...labels,
},
};

if (pathname.includes(CUSTOMER_ORDERS_PATH)) {
return;
}

const pathsRequiringRedirects = [
ORDER_DETAILS_PATH,
CUSTOMER_ORDER_DETAILS_PATH,
Expand Down

0 comments on commit feea93a

Please sign in to comment.