1
1
/* eslint-disable import/prefer-default-export, import/no-cycle */
2
- import { getConfigValue , getCookie } from './configs.js' ;
2
+ import {
3
+ getConfigValue , getCookie , getHeaders ,
4
+ } from './configs.js' ;
3
5
import { getConsent } from './scripts.js' ;
4
6
5
7
/* Common query fragments */
@@ -20,22 +22,18 @@ export const priceFieldsFragment = `fragment priceFields on ProductViewPrice {
20
22
}` ;
21
23
22
24
export async function commerceEndpointWithQueryParams ( ) {
23
- // Set Query Parameters so they can be appended to the endpoint
24
25
const urlWithQueryParams = new URL ( await getConfigValue ( 'commerce-endpoint' ) ) ;
25
- urlWithQueryParams . searchParams . append ( 'Magento-Environment-Id' , await getConfigValue ( 'commerce-environment-id' ) ) ;
26
- urlWithQueryParams . searchParams . append ( 'Magento-Website-Code' , await getConfigValue ( 'commerce-website-code' ) ) ;
27
- urlWithQueryParams . searchParams . append ( 'Magento-Store-View-Code' , await getConfigValue ( 'commerce-store-view-code' ) ) ;
28
- urlWithQueryParams . searchParams . append ( 'Magento-Store-Code' , await getConfigValue ( 'commerce-store-code' ) ) ;
29
- urlWithQueryParams . searchParams . append ( 'Magento-Customer-Group' , await getConfigValue ( 'commerce-customer-group' ) ) ;
26
+ // Set some query parameters for use as a cache-buster. No other purpose.
27
+ urlWithQueryParams . searchParams . append ( 'ac-storecode' , await getConfigValue ( 'commerce.headers.cs.Magento-Store-Code' ) ) ;
30
28
return urlWithQueryParams ;
31
29
}
32
30
33
31
/* Common functionality */
34
32
35
33
export async function performCatalogServiceQuery ( query , variables ) {
36
34
const headers = {
35
+ ...( await getHeaders ( 'cs' ) ) ,
37
36
'Content-Type' : 'application/json' ,
38
- 'x-api-key' : await getConfigValue ( 'commerce-x-api-key' ) ,
39
37
} ;
40
38
41
39
const apiCall = await commerceEndpointWithQueryParams ( ) ;
@@ -66,7 +64,7 @@ export async function performMonolithGraphQLQuery(query, variables, GET = true,
66
64
67
65
const headers = {
68
66
'Content-Type' : 'application/json' ,
69
- Store : await getConfigValue ( 'commerce-store-view-code ' ) ,
67
+ Store : await getConfigValue ( 'commerce.headers.cs.Magento-Store-View-Code ' ) ,
70
68
} ;
71
69
72
70
if ( USE_TOKEN ) {
@@ -161,7 +159,7 @@ export async function trackHistory() {
161
159
return ;
162
160
}
163
161
// Store product view history in session storage
164
- const storeViewCode = await getConfigValue ( 'commerce-store-view-code ' ) ;
162
+ const storeViewCode = await getConfigValue ( 'commerce.headers.cs.Magento-Store-View-Code ' ) ;
165
163
window . adobeDataLayer . push ( ( dl ) => {
166
164
dl . addEventListener ( 'adobeDataLayer:change' , ( event ) => {
167
165
if ( ! event . productContext ) {
0 commit comments