@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.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 = "2.1.83";
21
+ var version = "2.1.90";
22
22
  var license = "MIT";
23
23
  var main = "dist/index.js";
24
24
  var typings = "dist/index.d.ts";
@@ -91,7 +91,7 @@ var packageJson = {
91
91
  };
92
92
 
93
93
  const USER_AGENT = `${packageJson.name}@${packageJson.version}`;
94
- const fetchAPI = async (info, init) => {
94
+ const fetchAPI = async (info, init, getHeaders) => {
95
95
  const response = await fetch(info, {
96
96
  ...init,
97
97
  headers: {
@@ -100,6 +100,9 @@ const fetchAPI = async (info, init) => {
100
100
  }
101
101
  });
102
102
  if (response.ok) {
103
+ if (getHeaders) {
104
+ getHeaders(response.headers);
105
+ }
103
106
  return response.status !== 204 ? response.json() : undefined;
104
107
  }
105
108
  console.error(info, init, response);
@@ -107,12 +110,23 @@ const fetchAPI = async (info, init) => {
107
110
  throw new Error(text);
108
111
  };
109
112
 
113
+ function getCookieByName(cookiename, source) {
114
+ var cookiestring = RegExp(cookiename + '=[^;]+').exec(source);
115
+ return decodeURIComponent(!!cookiestring ? cookiestring.toString().replace(/^[^=]+./, '') : '');
116
+ }
117
+
110
118
  const BASE_INIT = {
111
119
  method: 'POST',
112
120
  headers: {
113
121
  'content-type': 'application/json'
114
122
  }
115
123
  };
124
+ const setCheckoutOrderFormOwnershipCookie = (headers, ctx) => {
125
+ if (headers) {
126
+ var _headers$get;
127
+ ctx.storage.cookies = `CheckoutOrderFormOwnership=${getCookieByName('CheckoutOrderFormOwnership', (_headers$get = headers.get('set-cookie')) != null ? _headers$get : '')}`;
128
+ }
129
+ };
116
130
  const VtexCommerce = ({
117
131
  account,
118
132
  environment,
@@ -187,7 +201,7 @@ const VtexCommerce = ({
187
201
  'content-type': 'application/json',
188
202
  cookie: ctx.headers.cookie
189
203
  }
190
- });
204
+ }, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
191
205
  },
192
206
  orderForm: ({
193
207
  id,
@@ -201,7 +215,7 @@ const VtexCommerce = ({
201
215
  refreshOutdatedData: refreshOutdatedData.toString(),
202
216
  sc: salesChannel
203
217
  });
204
- return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, BASE_INIT);
218
+ return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, BASE_INIT, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
205
219
  },
206
220
  updateOrderFormItems: ({
207
221
  id,
@@ -221,7 +235,7 @@ const VtexCommerce = ({
221
235
  noSplitItem: !shouldSplitItem
222
236
  }),
223
237
  method: 'PATCH'
224
- });
238
+ }, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
225
239
  },
226
240
  setCustomData: ({
227
241
  id,
@@ -235,7 +249,7 @@ const VtexCommerce = ({
235
249
  value
236
250
  }),
237
251
  method: 'PUT'
238
- });
252
+ }, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
239
253
  },
240
254
  region: async ({
241
255
  postalCode,
@@ -268,7 +282,7 @@ const VtexCommerce = ({
268
282
  cookie: ctx.headers.cookie
269
283
  },
270
284
  body: '{}'
271
- });
285
+ }, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
272
286
  },
273
287
  subscribeToNewsletter: data => {
274
288
  return fetchAPI(`${base}/api/dataentities/NL/documents/`, {