@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
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const fetchAPI: (info: RequestInfo, init?: RequestInit | undefined) => Promise<any>;
|
|
1
|
+
export declare const fetchAPI: (info: RequestInfo, init?: RequestInit | undefined, getHeaders?: ((headers: Headers) => void) | undefined) => Promise<any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function getCookieByName(cookiename: string, source: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/api",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.47",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"@envelop/core": "^1 || ^2",
|
|
54
54
|
"graphql": "^15.6.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "fb17d8b4870de83e2d738c99e2f46ff51209407d"
|
|
57
57
|
}
|
|
@@ -19,6 +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 { ShippingDataBody } from './types/ShippingData'
|
|
22
|
+
import getCookieByName from '../../../../utils/get-cookie-by-name'
|
|
22
23
|
|
|
23
24
|
type ValueOf<T> = T extends Record<string, infer K> ? K : never
|
|
24
25
|
|
|
@@ -29,6 +30,18 @@ const BASE_INIT = {
|
|
|
29
30
|
},
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
const setCheckoutOrderFormOwnershipCookie = (
|
|
34
|
+
headers: Headers,
|
|
35
|
+
ctx: Context
|
|
36
|
+
) => {
|
|
37
|
+
if (headers) {
|
|
38
|
+
ctx.storage.cookies = `CheckoutOrderFormOwnership=${getCookieByName(
|
|
39
|
+
'CheckoutOrderFormOwnership',
|
|
40
|
+
headers.get('set-cookie') ?? ''
|
|
41
|
+
)}`
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
32
45
|
export const VtexCommerce = (
|
|
33
46
|
{ account, environment }: Options,
|
|
34
47
|
ctx: Context
|
|
@@ -108,7 +121,8 @@ export const VtexCommerce = (
|
|
|
108
121
|
{
|
|
109
122
|
...BASE_INIT,
|
|
110
123
|
body: JSON.stringify(body),
|
|
111
|
-
}
|
|
124
|
+
},
|
|
125
|
+
(headers) => setCheckoutOrderFormOwnershipCookie(headers, ctx)
|
|
112
126
|
)
|
|
113
127
|
},
|
|
114
128
|
orderForm: ({
|
|
@@ -128,7 +142,8 @@ export const VtexCommerce = (
|
|
|
128
142
|
|
|
129
143
|
return fetchAPI(
|
|
130
144
|
`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`,
|
|
131
|
-
BASE_INIT
|
|
145
|
+
BASE_INIT,
|
|
146
|
+
(headers) => setCheckoutOrderFormOwnershipCookie(headers, ctx)
|
|
132
147
|
)
|
|
133
148
|
},
|
|
134
149
|
updateOrderFormItems: ({
|
|
@@ -158,7 +173,8 @@ export const VtexCommerce = (
|
|
|
158
173
|
noSplitItem: !shouldSplitItem,
|
|
159
174
|
}),
|
|
160
175
|
method: 'PATCH',
|
|
161
|
-
}
|
|
176
|
+
},
|
|
177
|
+
(headers) => setCheckoutOrderFormOwnershipCookie(headers, ctx)
|
|
162
178
|
)
|
|
163
179
|
},
|
|
164
180
|
setCustomData: ({
|
|
@@ -178,7 +194,8 @@ export const VtexCommerce = (
|
|
|
178
194
|
...BASE_INIT,
|
|
179
195
|
body: JSON.stringify({ value }),
|
|
180
196
|
method: 'PUT',
|
|
181
|
-
}
|
|
197
|
+
},
|
|
198
|
+
(headers) => setCheckoutOrderFormOwnershipCookie(headers, ctx)
|
|
182
199
|
)
|
|
183
200
|
},
|
|
184
201
|
region: async ({
|
|
@@ -208,14 +225,18 @@ export const VtexCommerce = (
|
|
|
208
225
|
'items',
|
|
209
226
|
'profile.id,profile.email,profile.firstName,profile.lastName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol'
|
|
210
227
|
)
|
|
211
|
-
return fetchAPI(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
228
|
+
return fetchAPI(
|
|
229
|
+
`${base}/api/sessions?${params.toString()}`,
|
|
230
|
+
{
|
|
231
|
+
method: 'POST',
|
|
232
|
+
headers: {
|
|
233
|
+
'content-type': 'application/json',
|
|
234
|
+
cookie: ctx.headers.cookie,
|
|
235
|
+
},
|
|
236
|
+
body: '{}',
|
|
216
237
|
},
|
|
217
|
-
|
|
218
|
-
|
|
238
|
+
(headers) => setCheckoutOrderFormOwnershipCookie(headers, ctx)
|
|
239
|
+
)
|
|
219
240
|
},
|
|
220
241
|
subscribeToNewsletter: (data: {
|
|
221
242
|
name: string
|
|
@@ -3,7 +3,11 @@ import packageJson from '../../../../package.json'
|
|
|
3
3
|
|
|
4
4
|
const USER_AGENT = `${packageJson.name}@${packageJson.version}`
|
|
5
5
|
|
|
6
|
-
export const fetchAPI = async (
|
|
6
|
+
export const fetchAPI = async (
|
|
7
|
+
info: RequestInfo,
|
|
8
|
+
init?: RequestInit,
|
|
9
|
+
getHeaders?: (headers: Headers) => void
|
|
10
|
+
) => {
|
|
7
11
|
const response = await fetch(info, {
|
|
8
12
|
...init,
|
|
9
13
|
headers: {
|
|
@@ -13,6 +17,10 @@ export const fetchAPI = async (info: RequestInfo, init?: RequestInit) => {
|
|
|
13
17
|
})
|
|
14
18
|
|
|
15
19
|
if (response.ok) {
|
|
20
|
+
if (getHeaders) {
|
|
21
|
+
getHeaders(response.headers)
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
return response.status !== 204 ? response.json() : undefined
|
|
17
25
|
}
|
|
18
26
|
|