@faststore/api 2.2.49 → 2.2.52
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/cjs/package.json +1 -1
- package/dist/cjs/src/platforms/vtex/clients/commerce/index.js +23 -50
- package/dist/cjs/src/platforms/vtex/clients/commerce/index.js.map +1 -1
- package/dist/cjs/src/platforms/vtex/utils/cookies.d.ts +21 -3
- package/dist/cjs/src/platforms/vtex/utils/cookies.js +18 -6
- package/dist/cjs/src/platforms/vtex/utils/cookies.js.map +1 -1
- package/dist/esm/package.json +1 -1
- package/dist/esm/src/platforms/vtex/clients/commerce/index.js +24 -51
- package/dist/esm/src/platforms/vtex/clients/commerce/index.js.map +1 -1
- package/dist/esm/src/platforms/vtex/utils/cookies.d.ts +21 -3
- package/dist/esm/src/platforms/vtex/utils/cookies.js +15 -5
- package/dist/esm/src/platforms/vtex/utils/cookies.js.map +1 -1
- package/package.json +4 -4
- package/src/platforms/vtex/clients/commerce/index.ts +28 -51
- package/src/platforms/vtex/utils/cookies.ts +33 -7
package/dist/cjs/package.json
CHANGED
|
@@ -12,8 +12,11 @@ const BASE_INIT = {
|
|
|
12
12
|
const VtexCommerce = ({ account, environment, incrementAddress }, ctx) => {
|
|
13
13
|
const base = `https://${account}.${environment}.com.br`;
|
|
14
14
|
const storeCookies = (0, cookies_1.getStoreCookie)(ctx);
|
|
15
|
+
const withCookie = (0, cookies_1.getWithCookie)(ctx);
|
|
15
16
|
// replacing www. only for testing while www.vtexfaststore.com is configured with www
|
|
16
|
-
const forwardedHost = (new Headers(ctx.headers).get('x-forwarded-host') ??
|
|
17
|
+
const forwardedHost = (new Headers(ctx.headers).get('x-forwarded-host') ??
|
|
18
|
+
ctx.headers?.host ??
|
|
19
|
+
'').replace('www.', '');
|
|
17
20
|
return {
|
|
18
21
|
catalog: {
|
|
19
22
|
salesChannel: (sc) => (0, fetch_1.fetchAPI)(`${base}/api/catalog_system/pub/saleschannel/${sc}`, undefined, { storeCookies }),
|
|
@@ -43,13 +46,10 @@ const VtexCommerce = ({ account, environment, incrementAddress }, ctx) => {
|
|
|
43
46
|
const params = new URLSearchParams({
|
|
44
47
|
sc: salesChannel,
|
|
45
48
|
});
|
|
46
|
-
const headers = {
|
|
49
|
+
const headers = withCookie({
|
|
47
50
|
'content-type': 'application/json',
|
|
48
51
|
'X-FORWARDED-HOST': forwardedHost,
|
|
49
|
-
};
|
|
50
|
-
const cookie = (0, cookies_1.getUpdatedCookie)(ctx);
|
|
51
|
-
if (cookie)
|
|
52
|
-
headers.cookie = cookie;
|
|
52
|
+
});
|
|
53
53
|
return (0, fetch_1.fetchAPI)(`${base}/api/checkout/pub/orderForms/simulation?${params.toString()}`, {
|
|
54
54
|
...BASE_INIT,
|
|
55
55
|
headers,
|
|
@@ -73,13 +73,10 @@ const VtexCommerce = ({ account, environment, incrementAddress }, ctx) => {
|
|
|
73
73
|
selectedAddresses: selectedAddresses,
|
|
74
74
|
clearAddressIfPostalCodeNotFound: incrementAddress,
|
|
75
75
|
};
|
|
76
|
-
const headers = {
|
|
76
|
+
const headers = withCookie({
|
|
77
77
|
'content-type': 'application/json',
|
|
78
78
|
'X-FORWARDED-HOST': forwardedHost,
|
|
79
|
-
};
|
|
80
|
-
const cookie = (0, cookies_1.getUpdatedCookie)(ctx);
|
|
81
|
-
if (cookie)
|
|
82
|
-
headers.cookie = cookie;
|
|
79
|
+
});
|
|
83
80
|
return (0, fetch_1.fetchAPI)(`${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`, {
|
|
84
81
|
...BASE_INIT,
|
|
85
82
|
headers,
|
|
@@ -92,26 +89,20 @@ const VtexCommerce = ({ account, environment, incrementAddress }, ctx) => {
|
|
|
92
89
|
refreshOutdatedData: refreshOutdatedData.toString(),
|
|
93
90
|
sc: salesChannel,
|
|
94
91
|
});
|
|
95
|
-
const headers = {
|
|
92
|
+
const headers = withCookie({
|
|
96
93
|
'content-type': 'application/json',
|
|
97
94
|
'X-FORWARDED-HOST': forwardedHost,
|
|
98
|
-
};
|
|
99
|
-
const cookie = (0, cookies_1.getUpdatedCookie)(ctx);
|
|
100
|
-
if (cookie)
|
|
101
|
-
headers.cookie = cookie;
|
|
95
|
+
});
|
|
102
96
|
return (0, fetch_1.fetchAPI)(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, {
|
|
103
97
|
...BASE_INIT,
|
|
104
98
|
headers,
|
|
105
99
|
}, { storeCookies });
|
|
106
100
|
},
|
|
107
101
|
clearOrderFormMessages: ({ id }) => {
|
|
108
|
-
const headers = {
|
|
102
|
+
const headers = withCookie({
|
|
109
103
|
'content-type': 'application/json',
|
|
110
104
|
'X-FORWARDED-HOST': forwardedHost,
|
|
111
|
-
};
|
|
112
|
-
const cookie = (0, cookies_1.getUpdatedCookie)(ctx);
|
|
113
|
-
if (cookie)
|
|
114
|
-
headers.cookie = cookie;
|
|
105
|
+
});
|
|
115
106
|
return (0, fetch_1.fetchAPI)(`${base}/api/checkout/pub/orderForm/${id}/messages/clear`, {
|
|
116
107
|
...BASE_INIT,
|
|
117
108
|
headers,
|
|
@@ -123,13 +114,10 @@ const VtexCommerce = ({ account, environment, incrementAddress }, ctx) => {
|
|
|
123
114
|
allowOutdatedData,
|
|
124
115
|
sc: salesChannel,
|
|
125
116
|
});
|
|
126
|
-
const headers = {
|
|
117
|
+
const headers = withCookie({
|
|
127
118
|
'content-type': 'application/json',
|
|
128
119
|
'X-FORWARDED-HOST': forwardedHost,
|
|
129
|
-
};
|
|
130
|
-
const cookie = (0, cookies_1.getUpdatedCookie)(ctx);
|
|
131
|
-
if (cookie)
|
|
132
|
-
headers.cookie = cookie;
|
|
120
|
+
});
|
|
133
121
|
return (0, fetch_1.fetchAPI)(`${base}/api/checkout/pub/orderForm/${id}/items?${params}`, {
|
|
134
122
|
headers,
|
|
135
123
|
body: JSON.stringify({
|
|
@@ -140,13 +128,10 @@ const VtexCommerce = ({ account, environment, incrementAddress }, ctx) => {
|
|
|
140
128
|
}, { storeCookies });
|
|
141
129
|
},
|
|
142
130
|
setCustomData: ({ id, appId, key, value, }) => {
|
|
143
|
-
const headers = {
|
|
131
|
+
const headers = withCookie({
|
|
144
132
|
'content-type': 'application/json',
|
|
145
133
|
'X-FORWARDED-HOST': forwardedHost,
|
|
146
|
-
};
|
|
147
|
-
const cookie = (0, cookies_1.getUpdatedCookie)(ctx);
|
|
148
|
-
if (cookie)
|
|
149
|
-
headers.cookie = cookie;
|
|
134
|
+
});
|
|
150
135
|
return (0, fetch_1.fetchAPI)(`${base}/api/checkout/pub/orderForm/${id}/customData/${appId}/${key}`, {
|
|
151
136
|
headers,
|
|
152
137
|
body: JSON.stringify({ value }),
|
|
@@ -162,25 +147,19 @@ const VtexCommerce = ({ account, environment, incrementAddress }, ctx) => {
|
|
|
162
147
|
? params.append('postalCode', postalCode)
|
|
163
148
|
: params.append('geoCoordinates', `${geoCoordinates?.longitude};${geoCoordinates?.latitude}`);
|
|
164
149
|
const url = `${base}/api/checkout/pub/regions/?${params.toString()}`;
|
|
165
|
-
const headers = {
|
|
150
|
+
const headers = withCookie({
|
|
166
151
|
'content-type': 'application/json',
|
|
167
152
|
'X-FORWARDED-HOST': forwardedHost,
|
|
168
|
-
};
|
|
169
|
-
const cookie = (0, cookies_1.getUpdatedCookie)(ctx);
|
|
170
|
-
if (cookie)
|
|
171
|
-
headers.cookie = cookie;
|
|
153
|
+
});
|
|
172
154
|
return (0, fetch_1.fetchAPI)(url, {
|
|
173
155
|
headers,
|
|
174
156
|
}, { storeCookies });
|
|
175
157
|
},
|
|
176
158
|
address: async ({ postalCode, country, }) => {
|
|
177
|
-
const headers = {
|
|
159
|
+
const headers = withCookie({
|
|
178
160
|
'content-type': 'application/json',
|
|
179
161
|
'X-FORWARDED-HOST': forwardedHost,
|
|
180
|
-
};
|
|
181
|
-
const cookie = (0, cookies_1.getUpdatedCookie)(ctx);
|
|
182
|
-
if (cookie)
|
|
183
|
-
headers.cookie = cookie;
|
|
162
|
+
});
|
|
184
163
|
return (0, fetch_1.fetchAPI)(`${base}/api/checkout/pub/postal-code/${country}/${postalCode}`, {
|
|
185
164
|
headers,
|
|
186
165
|
}, { storeCookies });
|
|
@@ -189,15 +168,9 @@ const VtexCommerce = ({ account, environment, incrementAddress }, ctx) => {
|
|
|
189
168
|
session: (search) => {
|
|
190
169
|
const params = new URLSearchParams(search);
|
|
191
170
|
params.set('items', 'profile.id,profile.email,profile.firstName,profile.lastName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol');
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
'content-type': 'application/json',
|
|
196
|
-
cookie,
|
|
197
|
-
}
|
|
198
|
-
: {
|
|
199
|
-
'content-type': 'application/json',
|
|
200
|
-
};
|
|
171
|
+
const headers = withCookie({
|
|
172
|
+
'content-type': 'application/json',
|
|
173
|
+
});
|
|
201
174
|
return (0, fetch_1.fetchAPI)(`${base}/api/sessions?${params.toString()}`, {
|
|
202
175
|
method: 'POST',
|
|
203
176
|
headers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/platforms/vtex/clients/commerce/index.ts"],"names":[],"mappings":";;;AACA,oCAAmC;AAoBnC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/platforms/vtex/clients/commerce/index.ts"],"names":[],"mappings":";;;AACA,oCAAmC;AAoBnC,iDAAmE;AAInE,MAAM,SAAS,GAAG;IAChB,MAAM,EAAE,MAAM;IACd,OAAO,EAAE;QACP,cAAc,EAAE,kBAAkB;KACnC;CACF,CAAA;AAEM,MAAM,YAAY,GAAG,CAC1B,EAAE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAW,EACnD,GAAY,EACZ,EAAE;IACF,MAAM,IAAI,GAAG,WAAW,OAAO,IAAI,WAAW,SAAS,CAAA;IACvD,MAAM,YAAY,GAAG,IAAA,wBAAc,EAAC,GAAG,CAAC,CAAA;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JAAuJ,CACxJ,CAAA;YAED,MAAM,OAAO,GAAgB,UAAU,CAAC;gBACtC,cAAc,EAAE,kBAAkB;aACnC,CAAC,CAAA;YAEF,OAAO,IAAA,gBAAQ,EACb,GAAG,IAAI,iBAAiB,MAAM,CAAC,QAAQ,EAAE,EAAE,EAC3C;gBACE,MAAM,EAAE,MAAM;gBACd,OAAO;gBACP,IAAI,EAAE,IAAI;aACX,EACD,EAAE,YAAY,EAAE,CACjB,CAAA;QACH,CAAC;QACD,qBAAqB,EAAE,CAAC,IAGvB,EAA+B,EAAE;YAChC,OAAO,IAAA,gBAAQ,EACb,GAAG,IAAI,iCAAiC,EACxC;gBACE,GAAG,SAAS;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC;gBAC1D,MAAM,EAAE,OAAO;aAChB,EACD,EAAE,YAAY,EAAE,CACjB,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC,CAAA;AA1UY,QAAA,YAAY,gBA0UxB"}
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import type { Context } from '../index';
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export interface ContextForCookies {
|
|
3
|
+
headers: Context['headers'];
|
|
4
|
+
storage: Pick<Context['storage'], 'cookies'>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* This function updates the ctx.storage.cookies, that is used in each request.
|
|
8
|
+
*
|
|
9
|
+
* ctx.storage.cookies is a Map<string[1], Record<string, string>[2]> where,
|
|
10
|
+
* [1] cookie key
|
|
11
|
+
* [2] {
|
|
12
|
+
* value: cookie value,
|
|
13
|
+
* setCookie: setCookie used in browser response
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
export declare const updatesContextStorageCookies: (ctx: Pick<Context, 'storage'>, setCookieValue: string) => void;
|
|
17
|
+
export declare const setCookie: (ctx: Pick<Context, 'storage'>, headers: Headers) => void;
|
|
18
|
+
export declare const getStoreCookie: (ctx: Pick<Context, 'storage'>) => (headers: Headers) => void;
|
|
4
19
|
/**
|
|
5
20
|
* This function returns a modified copy of the original cookie header (ctx.headers.cookie from the first request)
|
|
6
21
|
* with the cookie values that comes in each request (ctx.storage.cookies).
|
|
@@ -13,7 +28,10 @@ export declare const getStoreCookie: (ctx: Context) => (headers: Headers) => voi
|
|
|
13
28
|
* setCookie: setCookie used in browser response
|
|
14
29
|
* }
|
|
15
30
|
*/
|
|
16
|
-
export declare const getUpdatedCookie: (ctx:
|
|
31
|
+
export declare const getUpdatedCookie: (ctx: ContextForCookies) => string | null;
|
|
32
|
+
export declare const getWithCookie: (ctx: ContextForCookies) => <T extends Record<string, any>>(headers: T) => T & {
|
|
33
|
+
cookie?: string | undefined;
|
|
34
|
+
};
|
|
17
35
|
/**
|
|
18
36
|
* This function updates the cookie value based on its key
|
|
19
37
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updatesCookieValueByKey = exports.getUpdatedCookie = exports.getStoreCookie = exports.setCookie = void 0;
|
|
3
|
+
exports.updatesCookieValueByKey = exports.getWithCookie = exports.getUpdatedCookie = exports.getStoreCookie = exports.setCookie = exports.updatesContextStorageCookies = void 0;
|
|
4
4
|
const MATCH_FIRST_SET_COOKIE_KEY_VALUE = /^([^=]+)=([^;]*)/;
|
|
5
5
|
/**
|
|
6
6
|
* This function updates the ctx.storage.cookies, that is used in each request.
|
|
@@ -12,7 +12,7 @@ const MATCH_FIRST_SET_COOKIE_KEY_VALUE = /^([^=]+)=([^;]*)/;
|
|
|
12
12
|
* setCookie: setCookie used in browser response
|
|
13
13
|
* }
|
|
14
14
|
*/
|
|
15
|
-
const updatesContextStorageCookies = (
|
|
15
|
+
const updatesContextStorageCookies = (ctx, setCookieValue) => {
|
|
16
16
|
const matchCookie = setCookieValue.match(MATCH_FIRST_SET_COOKIE_KEY_VALUE);
|
|
17
17
|
if (matchCookie) {
|
|
18
18
|
const cookieKey = matchCookie[1];
|
|
@@ -23,13 +23,14 @@ const updatesContextStorageCookies = (setCookieValue, ctx) => {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
exports.updatesContextStorageCookies = updatesContextStorageCookies;
|
|
27
|
+
const setCookie = (ctx, headers) => {
|
|
27
28
|
headers
|
|
28
29
|
.getSetCookie()
|
|
29
|
-
.forEach((setCookieValue) => updatesContextStorageCookies(
|
|
30
|
+
.forEach((setCookieValue) => (0, exports.updatesContextStorageCookies)(ctx, setCookieValue));
|
|
30
31
|
};
|
|
31
32
|
exports.setCookie = setCookie;
|
|
32
|
-
const getStoreCookie = (ctx) => (headers) => (0, exports.setCookie)(
|
|
33
|
+
const getStoreCookie = (ctx) => (headers) => (0, exports.setCookie)(ctx, headers);
|
|
33
34
|
exports.getStoreCookie = getStoreCookie;
|
|
34
35
|
/**
|
|
35
36
|
* This function returns a modified copy of the original cookie header (ctx.headers.cookie from the first request)
|
|
@@ -54,6 +55,17 @@ const getUpdatedCookie = (ctx) => {
|
|
|
54
55
|
return contextStorageCookies.reduce((existingCookies, [storageCookieKey, { value: storageCookieValue }]) => (0, exports.updatesCookieValueByKey)(existingCookies, storageCookieKey, storageCookieValue), ctx.headers.cookie);
|
|
55
56
|
};
|
|
56
57
|
exports.getUpdatedCookie = getUpdatedCookie;
|
|
58
|
+
const getWithCookie = (ctx) => function withCookie(headers) {
|
|
59
|
+
const updatedCookie = (0, exports.getUpdatedCookie)(ctx);
|
|
60
|
+
if (!updatedCookie) {
|
|
61
|
+
return headers;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
...headers,
|
|
65
|
+
cookie: updatedCookie,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
exports.getWithCookie = getWithCookie;
|
|
57
69
|
/**
|
|
58
70
|
* This function updates the cookie value based on its key
|
|
59
71
|
*
|
|
@@ -68,7 +80,7 @@ const updatesCookieValueByKey = (existingCookies, storageCookieKey, storageCooki
|
|
|
68
80
|
const cookieParts = existingCookies.match(MATCH_COOKIE_KEY_VALUE);
|
|
69
81
|
// replaces original cookie with the one coming from storage
|
|
70
82
|
if (cookieParts) {
|
|
71
|
-
return existingCookies.replace(
|
|
83
|
+
return existingCookies.replace(cookieParts[0], `${cookieParts[1]}=${storageCookieValue}`);
|
|
72
84
|
}
|
|
73
85
|
// add new storage cookie to the original list of cookies
|
|
74
86
|
return `${existingCookies};${storageCookieKey}=${storageCookieValue}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookies.js","sourceRoot":"","sources":["../../../../../../src/platforms/vtex/utils/cookies.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"cookies.js","sourceRoot":"","sources":["../../../../../../src/platforms/vtex/utils/cookies.ts"],"names":[],"mappings":";;;AAOA,MAAM,gCAAgC,GAAG,kBAAkB,CAAA;AAE3D;;;;;;;;;GASG;AACI,MAAM,4BAA4B,GAAG,CAC1C,GAA6B,EAC7B,cAAsB,EACtB,EAAE;IACF,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAA;IAE1E,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;QAChC,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;QAElC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE;YACjC,KAAK,EAAE,WAAW;YAClB,SAAS,EAAE,cAAc;SAC1B,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAA;AAfY,QAAA,4BAA4B,gCAexC;AAEM,MAAM,SAAS,GAAG,CAAC,GAA6B,EAAE,OAAgB,EAAE,EAAE;IAC3E,OAAO;SACJ,YAAY,EAAE;SACd,OAAO,CAAC,CAAC,cAAc,EAAE,EAA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AACH,CAAC,CAAA;AAdU,QAAA,aAAa,iBAcvB;AAEH;;;;;;;;GAQG;AACI,MAAM,uBAAuB,GAAG,CACrC,eAAuB,EACvB,gBAAwB,EACxB,kBAA0B,EAC1B,EAAE;IACF,MAAM,sBAAsB,GAAG,IAAI,MAAM,CAAC,IAAI,gBAAgB,WAAW,CAAC,CAAA;IAC1E,MAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA;IAEjE,4DAA4D;IAC5D,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,eAAe,CAAC,OAAO,CAC5B,WAAW,CAAC,CAAC,CAAC,EACd,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,kBAAkB,EAAE,CAC1C,CAAA;IACH,CAAC;IAED,yDAAyD;IACzD,OAAO,GAAG,eAAe,IAAI,gBAAgB,IAAI,kBAAkB,EAAE,CAAA;AACvE,CAAC,CAAA;AAlBY,QAAA,uBAAuB,2BAkBnC"}
|
package/dist/esm/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fetchAPI } from '../fetch';
|
|
2
|
-
import {
|
|
2
|
+
import { getStoreCookie, getWithCookie } from '../../utils/cookies';
|
|
3
3
|
const BASE_INIT = {
|
|
4
4
|
method: 'POST',
|
|
5
5
|
headers: {
|
|
@@ -9,8 +9,11 @@ const BASE_INIT = {
|
|
|
9
9
|
export const VtexCommerce = ({ account, environment, incrementAddress }, ctx) => {
|
|
10
10
|
const base = `https://${account}.${environment}.com.br`;
|
|
11
11
|
const storeCookies = getStoreCookie(ctx);
|
|
12
|
+
const withCookie = getWithCookie(ctx);
|
|
12
13
|
// replacing www. only for testing while www.vtexfaststore.com is configured with www
|
|
13
|
-
const forwardedHost = (new Headers(ctx.headers).get('x-forwarded-host') ??
|
|
14
|
+
const forwardedHost = (new Headers(ctx.headers).get('x-forwarded-host') ??
|
|
15
|
+
ctx.headers?.host ??
|
|
16
|
+
'').replace('www.', '');
|
|
14
17
|
return {
|
|
15
18
|
catalog: {
|
|
16
19
|
salesChannel: (sc) => fetchAPI(`${base}/api/catalog_system/pub/saleschannel/${sc}`, undefined, { storeCookies }),
|
|
@@ -40,13 +43,10 @@ export const VtexCommerce = ({ account, environment, incrementAddress }, ctx) =>
|
|
|
40
43
|
const params = new URLSearchParams({
|
|
41
44
|
sc: salesChannel,
|
|
42
45
|
});
|
|
43
|
-
const headers = {
|
|
46
|
+
const headers = withCookie({
|
|
44
47
|
'content-type': 'application/json',
|
|
45
48
|
'X-FORWARDED-HOST': forwardedHost,
|
|
46
|
-
};
|
|
47
|
-
const cookie = getUpdatedCookie(ctx);
|
|
48
|
-
if (cookie)
|
|
49
|
-
headers.cookie = cookie;
|
|
49
|
+
});
|
|
50
50
|
return fetchAPI(`${base}/api/checkout/pub/orderForms/simulation?${params.toString()}`, {
|
|
51
51
|
...BASE_INIT,
|
|
52
52
|
headers,
|
|
@@ -70,13 +70,10 @@ export const VtexCommerce = ({ account, environment, incrementAddress }, ctx) =>
|
|
|
70
70
|
selectedAddresses: selectedAddresses,
|
|
71
71
|
clearAddressIfPostalCodeNotFound: incrementAddress,
|
|
72
72
|
};
|
|
73
|
-
const headers = {
|
|
73
|
+
const headers = withCookie({
|
|
74
74
|
'content-type': 'application/json',
|
|
75
75
|
'X-FORWARDED-HOST': forwardedHost,
|
|
76
|
-
};
|
|
77
|
-
const cookie = getUpdatedCookie(ctx);
|
|
78
|
-
if (cookie)
|
|
79
|
-
headers.cookie = cookie;
|
|
76
|
+
});
|
|
80
77
|
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`, {
|
|
81
78
|
...BASE_INIT,
|
|
82
79
|
headers,
|
|
@@ -89,26 +86,20 @@ export const VtexCommerce = ({ account, environment, incrementAddress }, ctx) =>
|
|
|
89
86
|
refreshOutdatedData: refreshOutdatedData.toString(),
|
|
90
87
|
sc: salesChannel,
|
|
91
88
|
});
|
|
92
|
-
const headers = {
|
|
89
|
+
const headers = withCookie({
|
|
93
90
|
'content-type': 'application/json',
|
|
94
91
|
'X-FORWARDED-HOST': forwardedHost,
|
|
95
|
-
};
|
|
96
|
-
const cookie = getUpdatedCookie(ctx);
|
|
97
|
-
if (cookie)
|
|
98
|
-
headers.cookie = cookie;
|
|
92
|
+
});
|
|
99
93
|
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, {
|
|
100
94
|
...BASE_INIT,
|
|
101
95
|
headers,
|
|
102
96
|
}, { storeCookies });
|
|
103
97
|
},
|
|
104
98
|
clearOrderFormMessages: ({ id }) => {
|
|
105
|
-
const headers = {
|
|
99
|
+
const headers = withCookie({
|
|
106
100
|
'content-type': 'application/json',
|
|
107
101
|
'X-FORWARDED-HOST': forwardedHost,
|
|
108
|
-
};
|
|
109
|
-
const cookie = getUpdatedCookie(ctx);
|
|
110
|
-
if (cookie)
|
|
111
|
-
headers.cookie = cookie;
|
|
102
|
+
});
|
|
112
103
|
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/messages/clear`, {
|
|
113
104
|
...BASE_INIT,
|
|
114
105
|
headers,
|
|
@@ -120,13 +111,10 @@ export const VtexCommerce = ({ account, environment, incrementAddress }, ctx) =>
|
|
|
120
111
|
allowOutdatedData,
|
|
121
112
|
sc: salesChannel,
|
|
122
113
|
});
|
|
123
|
-
const headers = {
|
|
114
|
+
const headers = withCookie({
|
|
124
115
|
'content-type': 'application/json',
|
|
125
116
|
'X-FORWARDED-HOST': forwardedHost,
|
|
126
|
-
};
|
|
127
|
-
const cookie = getUpdatedCookie(ctx);
|
|
128
|
-
if (cookie)
|
|
129
|
-
headers.cookie = cookie;
|
|
117
|
+
});
|
|
130
118
|
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/items?${params}`, {
|
|
131
119
|
headers,
|
|
132
120
|
body: JSON.stringify({
|
|
@@ -137,13 +125,10 @@ export const VtexCommerce = ({ account, environment, incrementAddress }, ctx) =>
|
|
|
137
125
|
}, { storeCookies });
|
|
138
126
|
},
|
|
139
127
|
setCustomData: ({ id, appId, key, value, }) => {
|
|
140
|
-
const headers = {
|
|
128
|
+
const headers = withCookie({
|
|
141
129
|
'content-type': 'application/json',
|
|
142
130
|
'X-FORWARDED-HOST': forwardedHost,
|
|
143
|
-
};
|
|
144
|
-
const cookie = getUpdatedCookie(ctx);
|
|
145
|
-
if (cookie)
|
|
146
|
-
headers.cookie = cookie;
|
|
131
|
+
});
|
|
147
132
|
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/customData/${appId}/${key}`, {
|
|
148
133
|
headers,
|
|
149
134
|
body: JSON.stringify({ value }),
|
|
@@ -159,25 +144,19 @@ export const VtexCommerce = ({ account, environment, incrementAddress }, ctx) =>
|
|
|
159
144
|
? params.append('postalCode', postalCode)
|
|
160
145
|
: params.append('geoCoordinates', `${geoCoordinates?.longitude};${geoCoordinates?.latitude}`);
|
|
161
146
|
const url = `${base}/api/checkout/pub/regions/?${params.toString()}`;
|
|
162
|
-
const headers = {
|
|
147
|
+
const headers = withCookie({
|
|
163
148
|
'content-type': 'application/json',
|
|
164
149
|
'X-FORWARDED-HOST': forwardedHost,
|
|
165
|
-
};
|
|
166
|
-
const cookie = getUpdatedCookie(ctx);
|
|
167
|
-
if (cookie)
|
|
168
|
-
headers.cookie = cookie;
|
|
150
|
+
});
|
|
169
151
|
return fetchAPI(url, {
|
|
170
152
|
headers,
|
|
171
153
|
}, { storeCookies });
|
|
172
154
|
},
|
|
173
155
|
address: async ({ postalCode, country, }) => {
|
|
174
|
-
const headers = {
|
|
156
|
+
const headers = withCookie({
|
|
175
157
|
'content-type': 'application/json',
|
|
176
158
|
'X-FORWARDED-HOST': forwardedHost,
|
|
177
|
-
};
|
|
178
|
-
const cookie = getUpdatedCookie(ctx);
|
|
179
|
-
if (cookie)
|
|
180
|
-
headers.cookie = cookie;
|
|
159
|
+
});
|
|
181
160
|
return fetchAPI(`${base}/api/checkout/pub/postal-code/${country}/${postalCode}`, {
|
|
182
161
|
headers,
|
|
183
162
|
}, { storeCookies });
|
|
@@ -186,15 +165,9 @@ export const VtexCommerce = ({ account, environment, incrementAddress }, ctx) =>
|
|
|
186
165
|
session: (search) => {
|
|
187
166
|
const params = new URLSearchParams(search);
|
|
188
167
|
params.set('items', 'profile.id,profile.email,profile.firstName,profile.lastName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol');
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
'content-type': 'application/json',
|
|
193
|
-
cookie,
|
|
194
|
-
}
|
|
195
|
-
: {
|
|
196
|
-
'content-type': 'application/json',
|
|
197
|
-
};
|
|
168
|
+
const headers = withCookie({
|
|
169
|
+
'content-type': 'application/json',
|
|
170
|
+
});
|
|
198
171
|
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
199
172
|
method: 'POST',
|
|
200
173
|
headers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/platforms/vtex/clients/commerce/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAoBnC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/platforms/vtex/clients/commerce/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAoBnC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAInE,MAAM,SAAS,GAAG;IAChB,MAAM,EAAE,MAAM;IACd,OAAO,EAAE;QACP,cAAc,EAAE,kBAAkB;KACnC;CACF,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,EAAE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAW,EACnD,GAAY,EACZ,EAAE;IACF,MAAM,IAAI,GAAG,WAAW,OAAO,IAAI,WAAW,SAAS,CAAA;IACvD,MAAM,YAAY,GAAG,cAA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E,kBAAkB;aACnC,CAAC,CAAA;YAEF,OAAO,QAAQ,CACb,GAAG,IAAI,iBAAiB,MAAM,CAAC,QAAQ,EAAE,EAAE,EAC3C;gBACE,MAAM,EAAE,MAAM;gBACd,OAAO;gBACP,IAAI,EAAE,IAAI;aACX,EACD,EAAE,YAAY,EAAE,CACjB,CAAA;QACH,CAAC;QACD,qBAAqB,EAAE,CAAC,IAGvB,EAA+B,EAAE;YAChC,OAAO,QAAQ,CACb,GAAG,IAAI,iCAAiC,EACxC;gBACE,GAAG,SAAS;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC;gBAC1D,MAAM,EAAE,OAAO;aAChB,EACD,EAAE,YAAY,EAAE,CACjB,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import type { Context } from '../index';
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export interface ContextForCookies {
|
|
3
|
+
headers: Context['headers'];
|
|
4
|
+
storage: Pick<Context['storage'], 'cookies'>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* This function updates the ctx.storage.cookies, that is used in each request.
|
|
8
|
+
*
|
|
9
|
+
* ctx.storage.cookies is a Map<string[1], Record<string, string>[2]> where,
|
|
10
|
+
* [1] cookie key
|
|
11
|
+
* [2] {
|
|
12
|
+
* value: cookie value,
|
|
13
|
+
* setCookie: setCookie used in browser response
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
export declare const updatesContextStorageCookies: (ctx: Pick<Context, 'storage'>, setCookieValue: string) => void;
|
|
17
|
+
export declare const setCookie: (ctx: Pick<Context, 'storage'>, headers: Headers) => void;
|
|
18
|
+
export declare const getStoreCookie: (ctx: Pick<Context, 'storage'>) => (headers: Headers) => void;
|
|
4
19
|
/**
|
|
5
20
|
* This function returns a modified copy of the original cookie header (ctx.headers.cookie from the first request)
|
|
6
21
|
* with the cookie values that comes in each request (ctx.storage.cookies).
|
|
@@ -13,7 +28,10 @@ export declare const getStoreCookie: (ctx: Context) => (headers: Headers) => voi
|
|
|
13
28
|
* setCookie: setCookie used in browser response
|
|
14
29
|
* }
|
|
15
30
|
*/
|
|
16
|
-
export declare const getUpdatedCookie: (ctx:
|
|
31
|
+
export declare const getUpdatedCookie: (ctx: ContextForCookies) => string | null;
|
|
32
|
+
export declare const getWithCookie: (ctx: ContextForCookies) => <T extends Record<string, any>>(headers: T) => T & {
|
|
33
|
+
cookie?: string | undefined;
|
|
34
|
+
};
|
|
17
35
|
/**
|
|
18
36
|
* This function updates the cookie value based on its key
|
|
19
37
|
*
|
|
@@ -9,7 +9,7 @@ const MATCH_FIRST_SET_COOKIE_KEY_VALUE = /^([^=]+)=([^;]*)/;
|
|
|
9
9
|
* setCookie: setCookie used in browser response
|
|
10
10
|
* }
|
|
11
11
|
*/
|
|
12
|
-
const updatesContextStorageCookies = (
|
|
12
|
+
export const updatesContextStorageCookies = (ctx, setCookieValue) => {
|
|
13
13
|
const matchCookie = setCookieValue.match(MATCH_FIRST_SET_COOKIE_KEY_VALUE);
|
|
14
14
|
if (matchCookie) {
|
|
15
15
|
const cookieKey = matchCookie[1];
|
|
@@ -20,12 +20,12 @@ const updatesContextStorageCookies = (setCookieValue, ctx) => {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
|
-
export const setCookie = (
|
|
23
|
+
export const setCookie = (ctx, headers) => {
|
|
24
24
|
headers
|
|
25
25
|
.getSetCookie()
|
|
26
|
-
.forEach((setCookieValue) => updatesContextStorageCookies(
|
|
26
|
+
.forEach((setCookieValue) => updatesContextStorageCookies(ctx, setCookieValue));
|
|
27
27
|
};
|
|
28
|
-
export const getStoreCookie = (ctx) => (headers) => setCookie(
|
|
28
|
+
export const getStoreCookie = (ctx) => (headers) => setCookie(ctx, headers);
|
|
29
29
|
/**
|
|
30
30
|
* This function returns a modified copy of the original cookie header (ctx.headers.cookie from the first request)
|
|
31
31
|
* with the cookie values that comes in each request (ctx.storage.cookies).
|
|
@@ -48,6 +48,16 @@ export const getUpdatedCookie = (ctx) => {
|
|
|
48
48
|
}
|
|
49
49
|
return contextStorageCookies.reduce((existingCookies, [storageCookieKey, { value: storageCookieValue }]) => updatesCookieValueByKey(existingCookies, storageCookieKey, storageCookieValue), ctx.headers.cookie);
|
|
50
50
|
};
|
|
51
|
+
export const getWithCookie = (ctx) => function withCookie(headers) {
|
|
52
|
+
const updatedCookie = getUpdatedCookie(ctx);
|
|
53
|
+
if (!updatedCookie) {
|
|
54
|
+
return headers;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
...headers,
|
|
58
|
+
cookie: updatedCookie,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
51
61
|
/**
|
|
52
62
|
* This function updates the cookie value based on its key
|
|
53
63
|
*
|
|
@@ -62,7 +72,7 @@ export const updatesCookieValueByKey = (existingCookies, storageCookieKey, stora
|
|
|
62
72
|
const cookieParts = existingCookies.match(MATCH_COOKIE_KEY_VALUE);
|
|
63
73
|
// replaces original cookie with the one coming from storage
|
|
64
74
|
if (cookieParts) {
|
|
65
|
-
return existingCookies.replace(
|
|
75
|
+
return existingCookies.replace(cookieParts[0], `${cookieParts[1]}=${storageCookieValue}`);
|
|
66
76
|
}
|
|
67
77
|
// add new storage cookie to the original list of cookies
|
|
68
78
|
return `${existingCookies};${storageCookieKey}=${storageCookieValue}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookies.js","sourceRoot":"","sources":["../../../../../../src/platforms/vtex/utils/cookies.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cookies.js","sourceRoot":"","sources":["../../../../../../src/platforms/vtex/utils/cookies.ts"],"names":[],"mappings":"AAOA,MAAM,gCAAgC,GAAG,kBAAkB,CAAA;AAE3D;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,4BAA4B,G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js",
|
|
6
6
|
"typings": "dist/esm/src/index.d.ts",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@envelop/core": "^2.6.0",
|
|
53
|
-
"@faststore/eslint-config": "^2.2.
|
|
54
|
-
"@faststore/shared": "^2.2.
|
|
53
|
+
"@faststore/eslint-config": "^2.2.52",
|
|
54
|
+
"@faststore/shared": "^2.2.52",
|
|
55
55
|
"@graphql-codegen/cli": "2.2.0",
|
|
56
56
|
"@graphql-codegen/typescript": "2.2.2",
|
|
57
57
|
"@types/express": "^4.17.16",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"volta": {
|
|
77
77
|
"extends": "../../package.json"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "ac3400c44c5088f570681217c224a596b0db3e39"
|
|
80
80
|
}
|
|
@@ -19,7 +19,7 @@ import type { SalesChannel } from './types/SalesChannel'
|
|
|
19
19
|
import { MasterDataResponse } from './types/Newsletter'
|
|
20
20
|
import type { Address, AddressInput } from './types/Address'
|
|
21
21
|
import { DeliveryMode, SelectedAddress } from './types/ShippingData'
|
|
22
|
-
import {
|
|
22
|
+
import { getStoreCookie, getWithCookie } from '../../utils/cookies'
|
|
23
23
|
|
|
24
24
|
type ValueOf<T> = T extends Record<string, infer K> ? K : never
|
|
25
25
|
|
|
@@ -36,8 +36,13 @@ export const VtexCommerce = (
|
|
|
36
36
|
) => {
|
|
37
37
|
const base = `https://${account}.${environment}.com.br`
|
|
38
38
|
const storeCookies = getStoreCookie(ctx)
|
|
39
|
+
const withCookie = getWithCookie(ctx)
|
|
39
40
|
// replacing www. only for testing while www.vtexfaststore.com is configured with www
|
|
40
|
-
const forwardedHost = (
|
|
41
|
+
const forwardedHost = (
|
|
42
|
+
new Headers(ctx.headers).get('x-forwarded-host') ??
|
|
43
|
+
ctx.headers?.host ??
|
|
44
|
+
''
|
|
45
|
+
).replace('www.', '')
|
|
41
46
|
|
|
42
47
|
return {
|
|
43
48
|
catalog: {
|
|
@@ -101,13 +106,10 @@ export const VtexCommerce = (
|
|
|
101
106
|
sc: salesChannel,
|
|
102
107
|
})
|
|
103
108
|
|
|
104
|
-
const headers: HeadersInit = {
|
|
109
|
+
const headers: HeadersInit = withCookie({
|
|
105
110
|
'content-type': 'application/json',
|
|
106
111
|
'X-FORWARDED-HOST': forwardedHost,
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const cookie = getUpdatedCookie(ctx)
|
|
110
|
-
if (cookie) headers.cookie = cookie
|
|
112
|
+
})
|
|
111
113
|
|
|
112
114
|
return fetchAPI(
|
|
113
115
|
`${base}/api/checkout/pub/orderForms/simulation?${params.toString()}`,
|
|
@@ -151,13 +153,10 @@ export const VtexCommerce = (
|
|
|
151
153
|
clearAddressIfPostalCodeNotFound: incrementAddress,
|
|
152
154
|
}
|
|
153
155
|
|
|
154
|
-
const headers: HeadersInit = {
|
|
156
|
+
const headers: HeadersInit = withCookie({
|
|
155
157
|
'content-type': 'application/json',
|
|
156
158
|
'X-FORWARDED-HOST': forwardedHost,
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const cookie = getUpdatedCookie(ctx)
|
|
160
|
-
if (cookie) headers.cookie = cookie
|
|
159
|
+
})
|
|
161
160
|
|
|
162
161
|
return fetchAPI(
|
|
163
162
|
`${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`,
|
|
@@ -184,13 +183,10 @@ export const VtexCommerce = (
|
|
|
184
183
|
sc: salesChannel,
|
|
185
184
|
})
|
|
186
185
|
|
|
187
|
-
const headers: HeadersInit = {
|
|
186
|
+
const headers: HeadersInit = withCookie({
|
|
188
187
|
'content-type': 'application/json',
|
|
189
188
|
'X-FORWARDED-HOST': forwardedHost,
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const cookie = getUpdatedCookie(ctx)
|
|
193
|
-
if (cookie) headers.cookie = cookie
|
|
189
|
+
})
|
|
194
190
|
|
|
195
191
|
return fetchAPI(
|
|
196
192
|
`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`,
|
|
@@ -202,13 +198,10 @@ export const VtexCommerce = (
|
|
|
202
198
|
)
|
|
203
199
|
},
|
|
204
200
|
clearOrderFormMessages: ({ id }: { id: string }) => {
|
|
205
|
-
const headers: HeadersInit = {
|
|
201
|
+
const headers: HeadersInit = withCookie({
|
|
206
202
|
'content-type': 'application/json',
|
|
207
203
|
'X-FORWARDED-HOST': forwardedHost,
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const cookie = getUpdatedCookie(ctx)
|
|
211
|
-
if (cookie) headers.cookie = cookie
|
|
204
|
+
})
|
|
212
205
|
|
|
213
206
|
return fetchAPI(
|
|
214
207
|
`${base}/api/checkout/pub/orderForm/${id}/messages/clear`,
|
|
@@ -237,13 +230,10 @@ export const VtexCommerce = (
|
|
|
237
230
|
sc: salesChannel,
|
|
238
231
|
})
|
|
239
232
|
|
|
240
|
-
const headers: HeadersInit = {
|
|
233
|
+
const headers: HeadersInit = withCookie({
|
|
241
234
|
'content-type': 'application/json',
|
|
242
235
|
'X-FORWARDED-HOST': forwardedHost,
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const cookie = getUpdatedCookie(ctx)
|
|
246
|
-
if (cookie) headers.cookie = cookie
|
|
236
|
+
})
|
|
247
237
|
|
|
248
238
|
return fetchAPI(
|
|
249
239
|
`${base}/api/checkout/pub/orderForm/${id}/items?${params}`,
|
|
@@ -269,13 +259,10 @@ export const VtexCommerce = (
|
|
|
269
259
|
key: string
|
|
270
260
|
value: string
|
|
271
261
|
}): Promise<OrderForm> => {
|
|
272
|
-
const headers: HeadersInit = {
|
|
262
|
+
const headers: HeadersInit = withCookie({
|
|
273
263
|
'content-type': 'application/json',
|
|
274
264
|
'X-FORWARDED-HOST': forwardedHost,
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const cookie = getUpdatedCookie(ctx)
|
|
278
|
-
if (cookie) headers.cookie = cookie
|
|
265
|
+
})
|
|
279
266
|
|
|
280
267
|
return fetchAPI(
|
|
281
268
|
`${base}/api/checkout/pub/orderForm/${id}/customData/${appId}/${key}`,
|
|
@@ -305,13 +292,10 @@ export const VtexCommerce = (
|
|
|
305
292
|
)
|
|
306
293
|
|
|
307
294
|
const url = `${base}/api/checkout/pub/regions/?${params.toString()}`
|
|
308
|
-
const headers: HeadersInit = {
|
|
295
|
+
const headers: HeadersInit = withCookie({
|
|
309
296
|
'content-type': 'application/json',
|
|
310
297
|
'X-FORWARDED-HOST': forwardedHost,
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const cookie = getUpdatedCookie(ctx)
|
|
314
|
-
if (cookie) headers.cookie = cookie
|
|
298
|
+
})
|
|
315
299
|
|
|
316
300
|
return fetchAPI(
|
|
317
301
|
url,
|
|
@@ -325,13 +309,10 @@ export const VtexCommerce = (
|
|
|
325
309
|
postalCode,
|
|
326
310
|
country,
|
|
327
311
|
}: AddressInput): Promise<Address> => {
|
|
328
|
-
const headers: HeadersInit = {
|
|
312
|
+
const headers: HeadersInit = withCookie({
|
|
329
313
|
'content-type': 'application/json',
|
|
330
314
|
'X-FORWARDED-HOST': forwardedHost,
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
const cookie = getUpdatedCookie(ctx)
|
|
334
|
-
if (cookie) headers.cookie = cookie
|
|
315
|
+
})
|
|
335
316
|
|
|
336
317
|
return fetchAPI(
|
|
337
318
|
`${base}/api/checkout/pub/postal-code/${country}/${postalCode}`,
|
|
@@ -349,15 +330,11 @@ export const VtexCommerce = (
|
|
|
349
330
|
'items',
|
|
350
331
|
'profile.id,profile.email,profile.firstName,profile.lastName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol'
|
|
351
332
|
)
|
|
352
|
-
|
|
353
|
-
const headers: HeadersInit =
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
: {
|
|
359
|
-
'content-type': 'application/json',
|
|
360
|
-
}
|
|
333
|
+
|
|
334
|
+
const headers: HeadersInit = withCookie({
|
|
335
|
+
'content-type': 'application/json',
|
|
336
|
+
})
|
|
337
|
+
|
|
361
338
|
return fetchAPI(
|
|
362
339
|
`${base}/api/sessions?${params.toString()}`,
|
|
363
340
|
{
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Context } from '../index'
|
|
2
2
|
|
|
3
|
+
export interface ContextForCookies {
|
|
4
|
+
headers: Context['headers']
|
|
5
|
+
storage: Pick<Context['storage'], 'cookies'>
|
|
6
|
+
}
|
|
7
|
+
|
|
3
8
|
const MATCH_FIRST_SET_COOKIE_KEY_VALUE = /^([^=]+)=([^;]*)/
|
|
4
9
|
|
|
5
10
|
/**
|
|
@@ -12,8 +17,12 @@ const MATCH_FIRST_SET_COOKIE_KEY_VALUE = /^([^=]+)=([^;]*)/
|
|
|
12
17
|
* setCookie: setCookie used in browser response
|
|
13
18
|
* }
|
|
14
19
|
*/
|
|
15
|
-
const updatesContextStorageCookies = (
|
|
20
|
+
export const updatesContextStorageCookies = (
|
|
21
|
+
ctx: Pick<Context, 'storage'>,
|
|
22
|
+
setCookieValue: string
|
|
23
|
+
) => {
|
|
16
24
|
const matchCookie = setCookieValue.match(MATCH_FIRST_SET_COOKIE_KEY_VALUE)
|
|
25
|
+
|
|
17
26
|
if (matchCookie) {
|
|
18
27
|
const cookieKey = matchCookie[1]
|
|
19
28
|
const cookieValue = matchCookie[2]
|
|
@@ -25,16 +34,17 @@ const updatesContextStorageCookies = (setCookieValue: string, ctx: Context) => {
|
|
|
25
34
|
}
|
|
26
35
|
}
|
|
27
36
|
|
|
28
|
-
export const setCookie = (
|
|
37
|
+
export const setCookie = (ctx: Pick<Context, 'storage'>, headers: Headers) => {
|
|
29
38
|
headers
|
|
30
39
|
.getSetCookie()
|
|
31
40
|
.forEach((setCookieValue) =>
|
|
32
|
-
updatesContextStorageCookies(
|
|
41
|
+
updatesContextStorageCookies(ctx, setCookieValue)
|
|
33
42
|
)
|
|
34
43
|
}
|
|
35
44
|
|
|
36
|
-
export const getStoreCookie =
|
|
37
|
-
|
|
45
|
+
export const getStoreCookie =
|
|
46
|
+
(ctx: Pick<Context, 'storage'>) => (headers: Headers) =>
|
|
47
|
+
setCookie(ctx, headers)
|
|
38
48
|
|
|
39
49
|
/**
|
|
40
50
|
* This function returns a modified copy of the original cookie header (ctx.headers.cookie from the first request)
|
|
@@ -48,7 +58,7 @@ export const getStoreCookie = (ctx: Context) => (headers: Headers) =>
|
|
|
48
58
|
* setCookie: setCookie used in browser response
|
|
49
59
|
* }
|
|
50
60
|
*/
|
|
51
|
-
export const getUpdatedCookie = (ctx:
|
|
61
|
+
export const getUpdatedCookie = (ctx: ContextForCookies) => {
|
|
52
62
|
if (!ctx.headers?.cookie) {
|
|
53
63
|
return null
|
|
54
64
|
}
|
|
@@ -70,6 +80,22 @@ export const getUpdatedCookie = (ctx: Context) => {
|
|
|
70
80
|
)
|
|
71
81
|
}
|
|
72
82
|
|
|
83
|
+
export const getWithCookie = (ctx: ContextForCookies) =>
|
|
84
|
+
function withCookie<T extends Record<string, any>>(
|
|
85
|
+
headers: T
|
|
86
|
+
): T & { cookie?: string } {
|
|
87
|
+
const updatedCookie = getUpdatedCookie(ctx)
|
|
88
|
+
|
|
89
|
+
if (!updatedCookie) {
|
|
90
|
+
return headers
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
...headers,
|
|
95
|
+
cookie: updatedCookie,
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
73
99
|
/**
|
|
74
100
|
* This function updates the cookie value based on its key
|
|
75
101
|
*
|
|
@@ -90,7 +116,7 @@ export const updatesCookieValueByKey = (
|
|
|
90
116
|
// replaces original cookie with the one coming from storage
|
|
91
117
|
if (cookieParts) {
|
|
92
118
|
return existingCookies.replace(
|
|
93
|
-
|
|
119
|
+
cookieParts[0],
|
|
94
120
|
`${cookieParts[1]}=${storageCookieValue}`
|
|
95
121
|
)
|
|
96
122
|
}
|