@faststore/api 1.12.46 → 1.12.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.cjs.development.js +25 -7
- package/dist/api.cjs.development.js.map +1 -1
- package/dist/api.cjs.production.min.js +1 -1
- package/dist/api.cjs.production.min.js.map +1 -1
- package/dist/api.esm.js +25 -7
- package/dist/api.esm.js.map +1 -1
- package/dist/platforms/vtex/clients/fetch.d.ts +1 -1
- package/dist/platforms/vtex/index.d.ts +1 -0
- package/dist/utils/get-cookie-by-name.d.ts +1 -0
- package/package.json +2 -2
- package/src/platforms/vtex/clients/commerce/index.ts +32 -11
- package/src/platforms/vtex/clients/fetch.ts +9 -1
- package/src/platforms/vtex/index.ts +1 -0
- package/src/utils/get-cookie-by-name.ts +6 -0
|
@@ -22,7 +22,7 @@ var api = require('@opentelemetry/api');
|
|
|
22
22
|
var apiLogs = require('@opentelemetry/api-logs');
|
|
23
23
|
|
|
24
24
|
var name = "@faststore/api";
|
|
25
|
-
var version = "1.12.
|
|
25
|
+
var version = "1.12.46";
|
|
26
26
|
var license = "MIT";
|
|
27
27
|
var main = "dist/index.js";
|
|
28
28
|
var typings = "dist/index.d.ts";
|
|
@@ -92,7 +92,7 @@ var packageJson = {
|
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
const USER_AGENT = `${packageJson.name}@${packageJson.version}`;
|
|
95
|
-
const fetchAPI = async (info, init) => {
|
|
95
|
+
const fetchAPI = async (info, init, getHeaders) => {
|
|
96
96
|
const response = await fetch(info, { ...init,
|
|
97
97
|
headers: { ...(init == null ? void 0 : init.headers),
|
|
98
98
|
'User-Agent': USER_AGENT
|
|
@@ -100,6 +100,10 @@ const fetchAPI = async (info, init) => {
|
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
if (response.ok) {
|
|
103
|
+
if (getHeaders) {
|
|
104
|
+
getHeaders(response.headers);
|
|
105
|
+
}
|
|
106
|
+
|
|
103
107
|
return response.status !== 204 ? response.json() : undefined;
|
|
104
108
|
}
|
|
105
109
|
|
|
@@ -108,12 +112,26 @@ const fetchAPI = async (info, init) => {
|
|
|
108
112
|
throw new Error(text);
|
|
109
113
|
};
|
|
110
114
|
|
|
115
|
+
function getCookieByName(cookiename, source) {
|
|
116
|
+
var cookiestring = RegExp(cookiename + '=[^;]+').exec(source);
|
|
117
|
+
return decodeURIComponent(!!cookiestring ? cookiestring.toString().replace(/^[^=]+./, '') : '');
|
|
118
|
+
}
|
|
119
|
+
|
|
111
120
|
const BASE_INIT = {
|
|
112
121
|
method: 'POST',
|
|
113
122
|
headers: {
|
|
114
123
|
'content-type': 'application/json'
|
|
115
124
|
}
|
|
116
125
|
};
|
|
126
|
+
|
|
127
|
+
const setCheckoutOrderFormOwnershipCookie = (headers, ctx) => {
|
|
128
|
+
if (headers) {
|
|
129
|
+
var _headers$get;
|
|
130
|
+
|
|
131
|
+
ctx.storage.cookies = `CheckoutOrderFormOwnership=${getCookieByName('CheckoutOrderFormOwnership', (_headers$get = headers.get('set-cookie')) != null ? _headers$get : '')}`;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
117
135
|
const VtexCommerce = ({
|
|
118
136
|
account,
|
|
119
137
|
environment
|
|
@@ -170,7 +188,7 @@ const VtexCommerce = ({
|
|
|
170
188
|
|
|
171
189
|
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`, { ...BASE_INIT,
|
|
172
190
|
body: JSON.stringify(body)
|
|
173
|
-
});
|
|
191
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
174
192
|
},
|
|
175
193
|
orderForm: ({
|
|
176
194
|
id,
|
|
@@ -184,7 +202,7 @@ const VtexCommerce = ({
|
|
|
184
202
|
refreshOutdatedData: refreshOutdatedData.toString(),
|
|
185
203
|
sc: salesChannel
|
|
186
204
|
});
|
|
187
|
-
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, BASE_INIT);
|
|
205
|
+
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, BASE_INIT, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
188
206
|
},
|
|
189
207
|
updateOrderFormItems: ({
|
|
190
208
|
id,
|
|
@@ -203,7 +221,7 @@ const VtexCommerce = ({
|
|
|
203
221
|
noSplitItem: !shouldSplitItem
|
|
204
222
|
}),
|
|
205
223
|
method: 'PATCH'
|
|
206
|
-
});
|
|
224
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
207
225
|
},
|
|
208
226
|
setCustomData: ({
|
|
209
227
|
id,
|
|
@@ -216,7 +234,7 @@ const VtexCommerce = ({
|
|
|
216
234
|
value
|
|
217
235
|
}),
|
|
218
236
|
method: 'PUT'
|
|
219
|
-
});
|
|
237
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
220
238
|
},
|
|
221
239
|
region: async ({
|
|
222
240
|
postalCode,
|
|
@@ -242,7 +260,7 @@ const VtexCommerce = ({
|
|
|
242
260
|
cookie: ctx.headers.cookie
|
|
243
261
|
},
|
|
244
262
|
body: '{}'
|
|
245
|
-
});
|
|
263
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
246
264
|
},
|
|
247
265
|
subscribeToNewsletter: data => {
|
|
248
266
|
return fetchAPI(`${base}/api/dataentities/NL/documents/`, { ...BASE_INIT,
|