@@ -23,19 +23,24 @@ import { resolveConfig } from './config.js';
23
23
* @param {Config } config
24
24
*/
25
25
async function fetchProductCS ( sku , config ) {
26
+ console . log ( 'config: ' , config ) ;
27
+ const { catalogEndpoint = 'https://catalog-service.adobe.io/graphql' } = config ;
26
28
const query = getProductQueryCS ( { sku } ) ;
27
-
28
- const resp = await fetch ( `https://catalog-service.adobe.io/graphql?query=${ encodeURIComponent ( query ) } ` , {
29
+ const resp = await fetch ( `${ catalogEndpoint } ?query=${ encodeURIComponent ( query ) } ` , {
29
30
headers : {
30
- origin : 'https://api.adobecommerce.live' ,
31
+ origin : config . origin ?? 'https://api.adobecommerce.live' ,
31
32
'x-api-key' : config . apiKey ,
32
33
'Magento-Environment-Id' : config . magentoEnvironmentId ,
33
34
'Magento-Website-Code' : config . magentoWebsiteCode ,
34
35
'Magento-Store-View-Code' : config . magentoStoreViewCode ,
36
+ 'Magento-Store-Code' : config . magentoStoreCode ,
35
37
} ,
36
38
} ) ;
37
39
if ( ! resp . ok ) {
38
40
console . warn ( 'failed to fetch product: ' , resp . status , resp . statusText ) ;
41
+ try {
42
+ console . info ( 'body: ' , await resp . text ( ) ) ;
43
+ } catch { /* noop */ }
39
44
throw errorWithResponse ( resp . status , 'failed to fetch product' ) ;
40
45
}
41
46
@@ -66,15 +71,19 @@ async function fetchProductCore(opt, config) {
66
71
67
72
const resp = await fetch ( `${ config . coreEndpoint } ?query=${ encodeURIComponent ( query ) } ` , {
68
73
headers : {
69
- origin : 'https://api.adobecommerce.live' ,
74
+ origin : config . origin ?? 'https://api.adobecommerce.live' ,
70
75
'x-api-key' : config . apiKey ,
71
76
'Magento-Environment-Id' : config . magentoEnvironmentId ,
72
77
'Magento-Website-Code' : config . magentoWebsiteCode ,
73
78
'Magento-Store-View-Code' : config . magentoStoreViewCode ,
79
+ 'Magento-Store-Code' : config . magentoStoreCode ,
74
80
} ,
75
81
} ) ;
76
82
if ( ! resp . ok ) {
77
83
console . warn ( 'failed to fetch product: ' , resp . status , resp . statusText ) ;
84
+ try {
85
+ console . info ( 'body: ' , await resp . text ( ) ) ;
86
+ } catch { /* noop */ }
78
87
throw errorWithResponse ( resp . status , 'failed to fetch product' ) ;
79
88
}
80
89
@@ -99,19 +108,24 @@ async function lookupProductSKU(urlkey, config) {
99
108
const query = getProductSKUQuery ( { urlkey } ) ;
100
109
const resp = await fetch ( `${ config . coreEndpoint } ?query=${ encodeURIComponent ( query ) } ` , {
101
110
headers : {
102
- origin : 'https://api.adobecommerce.live' ,
111
+ origin : config . origin ?? 'https://api.adobecommerce.live' ,
103
112
'x-api-key' : config . apiKey ,
104
113
'Magento-Environment-Id' : config . magentoEnvironmentId ,
105
114
'Magento-Website-Code' : config . magentoWebsiteCode ,
106
115
'Magento-Store-View-Code' : config . magentoStoreViewCode ,
116
+ 'Magento-Store-Code' : config . magentoStoreCode ,
107
117
} ,
108
118
} ) ;
109
119
if ( ! resp . ok ) {
110
120
console . warn ( 'failed to fetch product sku: ' , resp . status , resp . statusText ) ;
121
+ try {
122
+ console . info ( 'body: ' , await resp . text ( ) ) ;
123
+ } catch { /* noop */ }
111
124
throw errorWithResponse ( resp . status , 'failed to fetch product sku' ) ;
112
125
}
113
126
114
127
const json = await resp . json ( ) ;
128
+ console . log ( 'json: ' , JSON . stringify ( json , undefined , 2 ) ) ;
115
129
try {
116
130
const [ product ] = json . data . products . items ;
117
131
if ( ! product ) {
0 commit comments