@faststore/api 1.12.45 → 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 +32 -69
- 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 +32 -69
- package/dist/api.esm.js.map +1 -1
- package/dist/platforms/vtex/clients/commerce/index.d.ts +0 -1
- package/dist/platforms/vtex/clients/fetch.d.ts +1 -1
- package/dist/platforms/vtex/clients/index.d.ts +0 -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 +30 -30
- package/src/platforms/vtex/clients/fetch.ts +9 -1
- package/src/platforms/vtex/index.ts +1 -0
- package/src/platforms/vtex/resolvers/validateCart.ts +10 -33
- package/src/utils/get-cookie-by-name.ts +6 -0
- package/dist/platforms/vtex/utils/getCookies.d.ts +0 -1
- package/src/platforms/vtex/utils/getCookies.ts +0 -8
package/dist/api.esm.js
CHANGED
|
@@ -18,7 +18,7 @@ import { trace, context, SpanKind } from '@opentelemetry/api';
|
|
|
18
18
|
import { SeverityNumber } from '@opentelemetry/api-logs';
|
|
19
19
|
|
|
20
20
|
var name = "@faststore/api";
|
|
21
|
-
var version = "1.12.
|
|
21
|
+
var version = "1.12.46";
|
|
22
22
|
var license = "MIT";
|
|
23
23
|
var main = "dist/index.js";
|
|
24
24
|
var typings = "dist/index.d.ts";
|
|
@@ -88,7 +88,7 @@ var packageJson = {
|
|
|
88
88
|
};
|
|
89
89
|
|
|
90
90
|
const USER_AGENT = `${packageJson.name}@${packageJson.version}`;
|
|
91
|
-
const fetchAPI = async (info, init) => {
|
|
91
|
+
const fetchAPI = async (info, init, getHeaders) => {
|
|
92
92
|
const response = await fetch(info, { ...init,
|
|
93
93
|
headers: { ...(init == null ? void 0 : init.headers),
|
|
94
94
|
'User-Agent': USER_AGENT
|
|
@@ -96,6 +96,10 @@ const fetchAPI = async (info, init) => {
|
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
if (response.ok) {
|
|
99
|
+
if (getHeaders) {
|
|
100
|
+
getHeaders(response.headers);
|
|
101
|
+
}
|
|
102
|
+
|
|
99
103
|
return response.status !== 204 ? response.json() : undefined;
|
|
100
104
|
}
|
|
101
105
|
|
|
@@ -104,18 +108,10 @@ const fetchAPI = async (info, init) => {
|
|
|
104
108
|
throw new Error(text);
|
|
105
109
|
};
|
|
106
110
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (parts.length === 2) {
|
|
112
|
-
var _parts$pop$split$shif, _parts$pop;
|
|
113
|
-
|
|
114
|
-
return (_parts$pop$split$shif = parts == null ? void 0 : (_parts$pop = parts.pop()) == null ? void 0 : _parts$pop.split(';').shift()) != null ? _parts$pop$split$shif : '';
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return '';
|
|
118
|
-
};
|
|
111
|
+
function getCookieByName(cookiename, source) {
|
|
112
|
+
var cookiestring = RegExp(cookiename + '=[^;]+').exec(source);
|
|
113
|
+
return decodeURIComponent(!!cookiestring ? cookiestring.toString().replace(/^[^=]+./, '') : '');
|
|
114
|
+
}
|
|
119
115
|
|
|
120
116
|
const BASE_INIT = {
|
|
121
117
|
method: 'POST',
|
|
@@ -123,6 +119,15 @@ const BASE_INIT = {
|
|
|
123
119
|
'content-type': 'application/json'
|
|
124
120
|
}
|
|
125
121
|
};
|
|
122
|
+
|
|
123
|
+
const setCheckoutOrderFormOwnershipCookie = (headers, ctx) => {
|
|
124
|
+
if (headers) {
|
|
125
|
+
var _headers$get;
|
|
126
|
+
|
|
127
|
+
ctx.storage.cookies = `CheckoutOrderFormOwnership=${getCookieByName('CheckoutOrderFormOwnership', (_headers$get = headers.get('set-cookie')) != null ? _headers$get : '')}`;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
126
131
|
const VtexCommerce = ({
|
|
127
132
|
account,
|
|
128
133
|
environment
|
|
@@ -179,7 +184,7 @@ const VtexCommerce = ({
|
|
|
179
184
|
|
|
180
185
|
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`, { ...BASE_INIT,
|
|
181
186
|
body: JSON.stringify(body)
|
|
182
|
-
});
|
|
187
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
183
188
|
},
|
|
184
189
|
orderForm: ({
|
|
185
190
|
id,
|
|
@@ -193,7 +198,7 @@ const VtexCommerce = ({
|
|
|
193
198
|
refreshOutdatedData: refreshOutdatedData.toString(),
|
|
194
199
|
sc: salesChannel
|
|
195
200
|
});
|
|
196
|
-
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, BASE_INIT);
|
|
201
|
+
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, BASE_INIT, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
197
202
|
},
|
|
198
203
|
updateOrderFormItems: ({
|
|
199
204
|
id,
|
|
@@ -212,7 +217,7 @@ const VtexCommerce = ({
|
|
|
212
217
|
noSplitItem: !shouldSplitItem
|
|
213
218
|
}),
|
|
214
219
|
method: 'PATCH'
|
|
215
|
-
});
|
|
220
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
216
221
|
},
|
|
217
222
|
setCustomData: ({
|
|
218
223
|
id,
|
|
@@ -225,7 +230,7 @@ const VtexCommerce = ({
|
|
|
225
230
|
value
|
|
226
231
|
}),
|
|
227
232
|
method: 'PUT'
|
|
228
|
-
});
|
|
233
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
229
234
|
},
|
|
230
235
|
region: async ({
|
|
231
236
|
postalCode,
|
|
@@ -244,36 +249,14 @@ const VtexCommerce = ({
|
|
|
244
249
|
session: search => {
|
|
245
250
|
const params = new URLSearchParams(search);
|
|
246
251
|
params.set('items', 'profile.id,profile.email,profile.firstName,profile.lastName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol');
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
// cookie set
|
|
250
|
-
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
251
|
-
method: 'GET',
|
|
252
|
-
headers: {
|
|
253
|
-
'content-type': 'application/json',
|
|
254
|
-
cookie: ctx.headers.cookie
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
} else {
|
|
258
|
-
// cookie unset -> create session
|
|
259
|
-
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
260
|
-
method: 'POST',
|
|
261
|
-
headers: {
|
|
262
|
-
'content-type': 'application/json',
|
|
263
|
-
cookie: ctx.headers.cookie
|
|
264
|
-
},
|
|
265
|
-
body: '{}'
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
},
|
|
269
|
-
getSessionOrder: () => {
|
|
270
|
-
return fetchAPI(`${base}/api/sessions?items=checkout.orderFormId`, {
|
|
271
|
-
method: 'GET',
|
|
252
|
+
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
253
|
+
method: 'POST',
|
|
272
254
|
headers: {
|
|
273
255
|
'content-type': 'application/json',
|
|
274
256
|
cookie: ctx.headers.cookie
|
|
275
|
-
}
|
|
276
|
-
|
|
257
|
+
},
|
|
258
|
+
body: '{}'
|
|
259
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
277
260
|
},
|
|
278
261
|
subscribeToNewsletter: data => {
|
|
279
262
|
return fetchAPI(`${base}/api/dataentities/NL/documents/`, { ...BASE_INIT,
|
|
@@ -1239,22 +1222,7 @@ const isOrderFormStale = form => {
|
|
|
1239
1222
|
|
|
1240
1223
|
const newEtag = getOrderFormEtag(form);
|
|
1241
1224
|
return newEtag !== oldEtag;
|
|
1242
|
-
};
|
|
1243
|
-
|
|
1244
|
-
async function getOrderNumberFromSession(headers = {}, commerce) {
|
|
1245
|
-
const cookieSession = getCookie('vtex_session', headers.cookie);
|
|
1246
|
-
|
|
1247
|
-
if (cookieSession) {
|
|
1248
|
-
var _namespaces$checkout, _namespaces$checkout$;
|
|
1249
|
-
|
|
1250
|
-
const {
|
|
1251
|
-
namespaces
|
|
1252
|
-
} = await commerce.getSessionOrder();
|
|
1253
|
-
return (_namespaces$checkout = namespaces.checkout) == null ? void 0 : (_namespaces$checkout$ = _namespaces$checkout.orderFormId) == null ? void 0 : _namespaces$checkout$.value;
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
return;
|
|
1257
|
-
} // Returns the regionalized orderForm
|
|
1225
|
+
}; // Returns the regionalized orderForm
|
|
1258
1226
|
|
|
1259
1227
|
|
|
1260
1228
|
const getOrderForm = async (id, session, {
|
|
@@ -1310,10 +1278,8 @@ const validateCart = async (_, {
|
|
|
1310
1278
|
},
|
|
1311
1279
|
session
|
|
1312
1280
|
}, ctx) => {
|
|
1313
|
-
var _ref;
|
|
1314
|
-
|
|
1315
1281
|
const {
|
|
1316
|
-
orderNumber
|
|
1282
|
+
orderNumber,
|
|
1317
1283
|
acceptedOffer,
|
|
1318
1284
|
shouldSplitItem
|
|
1319
1285
|
} = order;
|
|
@@ -1323,8 +1289,7 @@ const validateCart = async (_, {
|
|
|
1323
1289
|
},
|
|
1324
1290
|
loaders: {
|
|
1325
1291
|
skuLoader
|
|
1326
|
-
}
|
|
1327
|
-
headers
|
|
1292
|
+
}
|
|
1328
1293
|
} = ctx;
|
|
1329
1294
|
const channel = session == null ? void 0 : session.channel;
|
|
1330
1295
|
const locale = session == null ? void 0 : session.locale;
|
|
@@ -1335,10 +1300,8 @@ const validateCart = async (_, {
|
|
|
1335
1300
|
|
|
1336
1301
|
if (locale) {
|
|
1337
1302
|
mutateLocaleContext(ctx, locale);
|
|
1338
|
-
}
|
|
1303
|
+
} // Step1: Get OrderForm from VTEX Commerce
|
|
1339
1304
|
|
|
1340
|
-
const orderNumberFromSession = await getOrderNumberFromSession(headers, commerce);
|
|
1341
|
-
const orderNumber = (_ref = orderNumberFromSession != null ? orderNumberFromSession : orderNumberFromCart) != null ? _ref : ''; // Step1: Get OrderForm from VTEX Commerce
|
|
1342
1305
|
|
|
1343
1306
|
const orderForm = await getOrderForm(orderNumber, session, ctx); // Step1.5: Check if another system changed the orderForm with this orderNumber
|
|
1344
1307
|
// If so, this means the user interacted with this cart elsewhere and expects
|