@faststore/api 2.1.90 → 2.1.98
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 +21 -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 +21 -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 +12 -11
- package/src/platforms/vtex/resolvers/validateCart.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 = "2.1.
|
|
25
|
+
var version = "2.1.90";
|
|
26
26
|
var license = "MIT";
|
|
27
27
|
var main = "dist/index.js";
|
|
28
28
|
var typings = "dist/index.d.ts";
|
|
@@ -95,7 +95,7 @@ var packageJson = {
|
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
const USER_AGENT = `${packageJson.name}@${packageJson.version}`;
|
|
98
|
-
const fetchAPI = async (info, init) => {
|
|
98
|
+
const fetchAPI = async (info, init, getHeaders) => {
|
|
99
99
|
const response = await fetch(info, {
|
|
100
100
|
...init,
|
|
101
101
|
headers: {
|
|
@@ -104,6 +104,9 @@ const fetchAPI = async (info, init) => {
|
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
106
|
if (response.ok) {
|
|
107
|
+
if (getHeaders) {
|
|
108
|
+
getHeaders(response.headers);
|
|
109
|
+
}
|
|
107
110
|
return response.status !== 204 ? response.json() : undefined;
|
|
108
111
|
}
|
|
109
112
|
console.error(info, init, response);
|
|
@@ -111,12 +114,23 @@ const fetchAPI = async (info, init) => {
|
|
|
111
114
|
throw new Error(text);
|
|
112
115
|
};
|
|
113
116
|
|
|
117
|
+
function getCookieByName(cookiename, source) {
|
|
118
|
+
var cookiestring = RegExp(cookiename + '=[^;]+').exec(source);
|
|
119
|
+
return decodeURIComponent(!!cookiestring ? cookiestring.toString().replace(/^[^=]+./, '') : '');
|
|
120
|
+
}
|
|
121
|
+
|
|
114
122
|
const BASE_INIT = {
|
|
115
123
|
method: 'POST',
|
|
116
124
|
headers: {
|
|
117
125
|
'content-type': 'application/json'
|
|
118
126
|
}
|
|
119
127
|
};
|
|
128
|
+
const setCheckoutOrderFormOwnershipCookie = (headers, ctx) => {
|
|
129
|
+
if (headers) {
|
|
130
|
+
var _headers$get;
|
|
131
|
+
ctx.storage.cookies = `CheckoutOrderFormOwnership=${getCookieByName('CheckoutOrderFormOwnership', (_headers$get = headers.get('set-cookie')) != null ? _headers$get : '')}`;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
120
134
|
const VtexCommerce = ({
|
|
121
135
|
account,
|
|
122
136
|
environment,
|
|
@@ -191,7 +205,7 @@ const VtexCommerce = ({
|
|
|
191
205
|
'content-type': 'application/json',
|
|
192
206
|
cookie: ctx.headers.cookie
|
|
193
207
|
}
|
|
194
|
-
});
|
|
208
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
195
209
|
},
|
|
196
210
|
orderForm: ({
|
|
197
211
|
id,
|
|
@@ -205,7 +219,7 @@ const VtexCommerce = ({
|
|
|
205
219
|
refreshOutdatedData: refreshOutdatedData.toString(),
|
|
206
220
|
sc: salesChannel
|
|
207
221
|
});
|
|
208
|
-
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, BASE_INIT);
|
|
222
|
+
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, BASE_INIT, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
209
223
|
},
|
|
210
224
|
updateOrderFormItems: ({
|
|
211
225
|
id,
|
|
@@ -225,7 +239,7 @@ const VtexCommerce = ({
|
|
|
225
239
|
noSplitItem: !shouldSplitItem
|
|
226
240
|
}),
|
|
227
241
|
method: 'PATCH'
|
|
228
|
-
});
|
|
242
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
229
243
|
},
|
|
230
244
|
setCustomData: ({
|
|
231
245
|
id,
|
|
@@ -239,7 +253,7 @@ const VtexCommerce = ({
|
|
|
239
253
|
value
|
|
240
254
|
}),
|
|
241
255
|
method: 'PUT'
|
|
242
|
-
});
|
|
256
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
243
257
|
},
|
|
244
258
|
region: async ({
|
|
245
259
|
postalCode,
|
|
@@ -272,7 +286,7 @@ const VtexCommerce = ({
|
|
|
272
286
|
cookie: ctx.headers.cookie
|
|
273
287
|
},
|
|
274
288
|
body: '{}'
|
|
275
|
-
});
|
|
289
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
276
290
|
},
|
|
277
291
|
subscribeToNewsletter: data => {
|
|
278
292
|
return fetchAPI(`${base}/api/dataentities/NL/documents/`, {
|