@faststore/api 2.2.0-alpha.0 → 2.2.0-alpha.1
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 +14 -65
- 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 +14 -65
- package/dist/api.esm.js.map +1 -1
- package/dist/platforms/vtex/clients/commerce/index.d.ts +0 -1
- package/dist/platforms/vtex/clients/index.d.ts +0 -1
- package/package.json +4 -4
- package/src/platforms/vtex/clients/commerce/index.ts +4 -26
- package/src/platforms/vtex/resolvers/validateCart.ts +6 -37
- package/dist/platforms/vtex/utils/getCookies.d.ts +0 -1
- package/src/platforms/vtex/utils/getCookies.ts +0 -8
|
@@ -64,7 +64,6 @@ export declare const VtexCommerce: ({ account, environment, incrementAddress }:
|
|
|
64
64
|
address: ({ postalCode, country, }: AddressInput) => Promise<Address>;
|
|
65
65
|
};
|
|
66
66
|
session: (search: string) => Promise<Session>;
|
|
67
|
-
getSessionOrder: () => Promise<Session>;
|
|
68
67
|
subscribeToNewsletter: (data: {
|
|
69
68
|
name: string;
|
|
70
69
|
email: string;
|
|
@@ -57,7 +57,6 @@ export declare const getClients: (options: Options, ctx: Context) => {
|
|
|
57
57
|
address: ({ postalCode, country, }: import("./commerce/types/Address").AddressInput) => Promise<import("./commerce/types/Address").Address>;
|
|
58
58
|
};
|
|
59
59
|
session: (search: string) => Promise<import("./commerce/types/Session").Session>;
|
|
60
|
-
getSessionOrder: () => Promise<import("./commerce/types/Session").Session>;
|
|
61
60
|
subscribeToNewsletter: (data: {
|
|
62
61
|
name: string;
|
|
63
62
|
email: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/api",
|
|
3
|
-
"version": "2.2.0-alpha.
|
|
3
|
+
"version": "2.2.0-alpha.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@envelop/core": "^2.6.0",
|
|
39
|
-
"@faststore/eslint-config": "^2.2.0-alpha.
|
|
40
|
-
"@faststore/shared": "^2.2.0-alpha.
|
|
39
|
+
"@faststore/eslint-config": "^2.2.0-alpha.1",
|
|
40
|
+
"@faststore/shared": "^2.2.0-alpha.1",
|
|
41
41
|
"@graphql-codegen/cli": "2.2.0",
|
|
42
42
|
"@graphql-codegen/typescript": "2.2.2",
|
|
43
43
|
"@types/express": "^4.17.16",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"@envelop/core": "^1 || ^2",
|
|
57
57
|
"graphql": "^15.6.0"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "6eff908883fa54cb72d548b12a610490df833804"
|
|
60
60
|
}
|
|
@@ -15,7 +15,6 @@ import type {
|
|
|
15
15
|
} from './types/Simulation'
|
|
16
16
|
import type { Session } from './types/Session'
|
|
17
17
|
import type { Channel } from '../../utils/channel'
|
|
18
|
-
import { getCookie } from '../../utils/getCookies'
|
|
19
18
|
import type { SalesChannel } from './types/SalesChannel'
|
|
20
19
|
import { MasterDataResponse } from './types/Newsletter'
|
|
21
20
|
import type { Address, AddressInput } from './types/Address'
|
|
@@ -131,7 +130,7 @@ export const VtexCommerce = (
|
|
|
131
130
|
headers: {
|
|
132
131
|
'content-type': 'application/json',
|
|
133
132
|
cookie: ctx.headers.cookie,
|
|
134
|
-
}
|
|
133
|
+
},
|
|
135
134
|
}
|
|
136
135
|
)
|
|
137
136
|
},
|
|
@@ -243,34 +242,13 @@ export const VtexCommerce = (
|
|
|
243
242
|
'items',
|
|
244
243
|
'profile.id,profile.email,profile.firstName,profile.lastName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol'
|
|
245
244
|
)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
249
|
-
method: 'GET',
|
|
250
|
-
headers: {
|
|
251
|
-
'content-type': 'application/json',
|
|
252
|
-
cookie: ctx.headers.cookie,
|
|
253
|
-
},
|
|
254
|
-
})
|
|
255
|
-
} else {
|
|
256
|
-
// cookie unset -> create session
|
|
257
|
-
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
258
|
-
method: 'POST',
|
|
259
|
-
headers: {
|
|
260
|
-
'content-type': 'application/json',
|
|
261
|
-
cookie: ctx.headers.cookie,
|
|
262
|
-
},
|
|
263
|
-
body: '{}',
|
|
264
|
-
})
|
|
265
|
-
}
|
|
266
|
-
},
|
|
267
|
-
getSessionOrder: (): Promise<Session> => {
|
|
268
|
-
return fetchAPI(`${base}/api/sessions?items=public.orderFormId`, {
|
|
269
|
-
method: 'GET',
|
|
245
|
+
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
246
|
+
method: 'POST',
|
|
270
247
|
headers: {
|
|
271
248
|
'content-type': 'application/json',
|
|
272
249
|
cookie: ctx.headers.cookie,
|
|
273
250
|
},
|
|
251
|
+
body: '{}',
|
|
274
252
|
})
|
|
275
253
|
},
|
|
276
254
|
subscribeToNewsletter: (data: {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import deepEquals from 'fast-deep-equal'
|
|
2
2
|
|
|
3
3
|
import { mutateChannelContext, mutateLocaleContext } from '../utils/contex'
|
|
4
|
-
import { getCookie } from '../utils/getCookies'
|
|
5
4
|
import { md5 } from '../utils/md5'
|
|
6
5
|
import {
|
|
7
6
|
attachmentToPropertyValue,
|
|
@@ -128,7 +127,10 @@ const joinItems = (form: OrderForm) => {
|
|
|
128
127
|
const [item] = items
|
|
129
128
|
const quantity = items.reduce((acc, i) => acc + i.quantity, 0)
|
|
130
129
|
const totalPrice = items.reduce(
|
|
131
|
-
(acc, i) =>
|
|
130
|
+
(acc, i) =>
|
|
131
|
+
acc +
|
|
132
|
+
(i?.priceDefinition?.total ??
|
|
133
|
+
(i?.quantity ?? 0) * (i?.sellingPrice ?? 0)),
|
|
132
134
|
0
|
|
133
135
|
)
|
|
134
136
|
|
|
@@ -205,19 +207,6 @@ const isOrderFormStale = (form: OrderForm) => {
|
|
|
205
207
|
return newEtag !== oldEtag
|
|
206
208
|
}
|
|
207
209
|
|
|
208
|
-
async function getOrderNumberFromSession(
|
|
209
|
-
headers: Record<string, string> = {},
|
|
210
|
-
commerce: Context['clients']['commerce']
|
|
211
|
-
) {
|
|
212
|
-
const cookieSession = getCookie('vtex_session', headers.cookie)
|
|
213
|
-
|
|
214
|
-
if (cookieSession) {
|
|
215
|
-
const { namespaces } = await commerce.getSessionOrder()
|
|
216
|
-
return namespaces.public?.orderFormId?.value ?? undefined
|
|
217
|
-
}
|
|
218
|
-
return
|
|
219
|
-
}
|
|
220
|
-
|
|
221
210
|
// Returns the regionalized orderForm
|
|
222
211
|
const getOrderForm = async (id: string, { clients: { commerce } }: Context) => {
|
|
223
212
|
return commerce.checkout.orderForm({
|
|
@@ -301,15 +290,10 @@ export const validateCart = async (
|
|
|
301
290
|
{ cart: { order }, session }: MutationValidateCartArgs,
|
|
302
291
|
ctx: Context
|
|
303
292
|
) => {
|
|
304
|
-
const {
|
|
305
|
-
orderNumber: orderNumberFromCart,
|
|
306
|
-
acceptedOffer,
|
|
307
|
-
shouldSplitItem,
|
|
308
|
-
} = order
|
|
293
|
+
const { orderNumber, acceptedOffer, shouldSplitItem } = order
|
|
309
294
|
const {
|
|
310
295
|
clients: { commerce },
|
|
311
296
|
loaders: { skuLoader },
|
|
312
|
-
headers,
|
|
313
297
|
} = ctx
|
|
314
298
|
|
|
315
299
|
const channel = session?.channel
|
|
@@ -323,25 +307,10 @@ export const validateCart = async (
|
|
|
323
307
|
mutateLocaleContext(ctx, locale)
|
|
324
308
|
}
|
|
325
309
|
|
|
326
|
-
const orderNumberFromSession = await getOrderNumberFromSession(
|
|
327
|
-
headers,
|
|
328
|
-
commerce
|
|
329
|
-
)
|
|
330
|
-
const orderNumber = orderNumberFromSession ?? orderNumberFromCart ?? ''
|
|
331
|
-
|
|
332
310
|
// Step1: Get OrderForm from VTEX Commerce
|
|
333
311
|
const orderForm = await getOrderForm(orderNumber, ctx)
|
|
334
312
|
|
|
335
|
-
// Step1.
|
|
336
|
-
// Social Selling: the vtex_session cookie contains a new orderForm id with Social Selling data
|
|
337
|
-
// My Orders: the customer clicks on reordering through generating a new cart and when returning to the faststore, this information needs to be returned by vtex_session cookie.
|
|
338
|
-
// New session: a new user enters the website and has no orderForm attributed to it (has no relation to the vtex_session cookie).
|
|
339
|
-
// In all cases, the origin orderForm should replace the copy that's in the browser
|
|
340
|
-
if (orderForm.orderFormId != orderNumberFromCart) {
|
|
341
|
-
return orderFormToCart(orderForm, skuLoader)
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
// Step1.2: Check if another system changed the orderForm with this orderNumber
|
|
313
|
+
// Step1.5: Check if another system changed the orderForm with this orderNumber
|
|
345
314
|
// If so, this means the user interacted with this cart elsewhere and expects
|
|
346
315
|
// to see this new cart state instead of what's stored on the user's browser.
|
|
347
316
|
const isStale = isOrderFormStale(orderForm)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getCookie: (name: string, cookie: string) => string;
|