@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
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,12 +108,26 @@ const fetchAPI = async (info, init) => {
|
|
|
104
108
|
throw new Error(text);
|
|
105
109
|
};
|
|
106
110
|
|
|
111
|
+
function getCookieByName(cookiename, source) {
|
|
112
|
+
var cookiestring = RegExp(cookiename + '=[^;]+').exec(source);
|
|
113
|
+
return decodeURIComponent(!!cookiestring ? cookiestring.toString().replace(/^[^=]+./, '') : '');
|
|
114
|
+
}
|
|
115
|
+
|
|
107
116
|
const BASE_INIT = {
|
|
108
117
|
method: 'POST',
|
|
109
118
|
headers: {
|
|
110
119
|
'content-type': 'application/json'
|
|
111
120
|
}
|
|
112
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
|
+
|
|
113
131
|
const VtexCommerce = ({
|
|
114
132
|
account,
|
|
115
133
|
environment
|
|
@@ -166,7 +184,7 @@ const VtexCommerce = ({
|
|
|
166
184
|
|
|
167
185
|
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`, { ...BASE_INIT,
|
|
168
186
|
body: JSON.stringify(body)
|
|
169
|
-
});
|
|
187
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
170
188
|
},
|
|
171
189
|
orderForm: ({
|
|
172
190
|
id,
|
|
@@ -180,7 +198,7 @@ const VtexCommerce = ({
|
|
|
180
198
|
refreshOutdatedData: refreshOutdatedData.toString(),
|
|
181
199
|
sc: salesChannel
|
|
182
200
|
});
|
|
183
|
-
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));
|
|
184
202
|
},
|
|
185
203
|
updateOrderFormItems: ({
|
|
186
204
|
id,
|
|
@@ -199,7 +217,7 @@ const VtexCommerce = ({
|
|
|
199
217
|
noSplitItem: !shouldSplitItem
|
|
200
218
|
}),
|
|
201
219
|
method: 'PATCH'
|
|
202
|
-
});
|
|
220
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
203
221
|
},
|
|
204
222
|
setCustomData: ({
|
|
205
223
|
id,
|
|
@@ -212,7 +230,7 @@ const VtexCommerce = ({
|
|
|
212
230
|
value
|
|
213
231
|
}),
|
|
214
232
|
method: 'PUT'
|
|
215
|
-
});
|
|
233
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
216
234
|
},
|
|
217
235
|
region: async ({
|
|
218
236
|
postalCode,
|
|
@@ -238,7 +256,7 @@ const VtexCommerce = ({
|
|
|
238
256
|
cookie: ctx.headers.cookie
|
|
239
257
|
},
|
|
240
258
|
body: '{}'
|
|
241
|
-
});
|
|
259
|
+
}, headers => setCheckoutOrderFormOwnershipCookie(headers, ctx));
|
|
242
260
|
},
|
|
243
261
|
subscribeToNewsletter: data => {
|
|
244
262
|
return fetchAPI(`${base}/api/dataentities/NL/documents/`, { ...BASE_INIT,
|