@faststore/api 2.2.30 → 2.2.35
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 +34 -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 +34 -7
- package/dist/api.esm.js.map +1 -1
- package/dist/platforms/vtex/clients/commerce/index.d.ts +3 -0
- package/dist/platforms/vtex/clients/index.d.ts +3 -0
- package/package.json +4 -4
- package/src/platforms/vtex/clients/commerce/index.ts +11 -0
- package/src/platforms/vtex/resolvers/searchResult.ts +20 -3
- package/src/platforms/vtex/resolvers/validateCart.ts +21 -1
|
@@ -47,6 +47,9 @@ export declare const VtexCommerce: ({ account, environment, incrementAddress }:
|
|
|
47
47
|
refreshOutdatedData?: boolean | undefined;
|
|
48
48
|
channel?: Required<Channel> | undefined;
|
|
49
49
|
}) => Promise<OrderForm>;
|
|
50
|
+
clearOrderFormMessages: ({ id }: {
|
|
51
|
+
id: string;
|
|
52
|
+
}) => Promise<any>;
|
|
50
53
|
updateOrderFormItems: ({ id, orderItems, allowOutdatedData, salesChannel, shouldSplitItem, }: {
|
|
51
54
|
id: string;
|
|
52
55
|
orderItems: OrderFormInputItem[];
|
|
@@ -40,6 +40,9 @@ export declare const getClients: (options: Options, ctx: Context) => {
|
|
|
40
40
|
refreshOutdatedData?: boolean | undefined;
|
|
41
41
|
channel?: Required<import("../utils/channel").Channel> | undefined;
|
|
42
42
|
}) => Promise<import("./commerce/types/OrderForm").OrderForm>;
|
|
43
|
+
clearOrderFormMessages: ({ id }: {
|
|
44
|
+
id: string;
|
|
45
|
+
}) => Promise<any>;
|
|
43
46
|
updateOrderFormItems: ({ id, orderItems, allowOutdatedData, salesChannel, shouldSplitItem, }: {
|
|
44
47
|
id: string;
|
|
45
48
|
orderItems: import("./commerce/types/OrderForm").OrderFormInputItem[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/api",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.35",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@envelop/core": "^2.6.0",
|
|
40
|
-
"@faststore/eslint-config": "^2.2.
|
|
41
|
-
"@faststore/shared": "^2.2.
|
|
40
|
+
"@faststore/eslint-config": "^2.2.33",
|
|
41
|
+
"@faststore/shared": "^2.2.33",
|
|
42
42
|
"@graphql-codegen/cli": "2.2.0",
|
|
43
43
|
"@graphql-codegen/typescript": "2.2.2",
|
|
44
44
|
"@types/express": "^4.17.16",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"@envelop/core": "^1 || ^2",
|
|
59
59
|
"graphql": "^15.6.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "dbb59ea5a444b7b542481b6842ab8bc230ed9a94"
|
|
62
62
|
}
|
|
@@ -163,6 +163,17 @@ export const VtexCommerce = (
|
|
|
163
163
|
requestInit
|
|
164
164
|
)
|
|
165
165
|
},
|
|
166
|
+
|
|
167
|
+
clearOrderFormMessages: ({ id }: { id: string }) => {
|
|
168
|
+
return fetchAPI(
|
|
169
|
+
`${base}/api/checkout/pub/orderForm/${id}/messages/clear`,
|
|
170
|
+
{
|
|
171
|
+
...BASE_INIT,
|
|
172
|
+
body: '{}',
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
},
|
|
176
|
+
|
|
166
177
|
updateOrderFormItems: ({
|
|
167
178
|
id,
|
|
168
179
|
orderItems,
|
|
@@ -9,7 +9,12 @@ export type Root = {
|
|
|
9
9
|
productSearchPromise: Promise<ProductSearchResult>
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
const isRootFacet = (facet: Facet
|
|
12
|
+
const isRootFacet = (facet: Facet, isDepartment: boolean, isBrand: boolean) =>
|
|
13
|
+
isDepartment
|
|
14
|
+
? facet.key === 'category-1'
|
|
15
|
+
: isBrand
|
|
16
|
+
? facet.key === 'brand'
|
|
17
|
+
: false
|
|
13
18
|
|
|
14
19
|
export const StoreSearchResult: Record<string, Resolver<Root>> = {
|
|
15
20
|
suggestions: async (root, _, ctx) => {
|
|
@@ -89,9 +94,21 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {
|
|
|
89
94
|
|
|
90
95
|
const isCollectionPage = !searchArgs.query
|
|
91
96
|
|
|
97
|
+
const isDepartment = searchArgs.selectedFacets?.length
|
|
98
|
+
? searchArgs.selectedFacets[0].key === 'category-1'
|
|
99
|
+
: false
|
|
100
|
+
|
|
101
|
+
const isBrand = searchArgs.selectedFacets?.length
|
|
102
|
+
? searchArgs.selectedFacets[0].key === 'brand'
|
|
103
|
+
: false
|
|
104
|
+
|
|
92
105
|
const filteredFacets = facets
|
|
93
|
-
// Remove root facet on category pages
|
|
94
|
-
|
|
106
|
+
// Remove root facet on category and brand pages
|
|
107
|
+
// TODO: Hide category filters for category pages. E.g. /office/desks
|
|
108
|
+
.filter(
|
|
109
|
+
(facet) =>
|
|
110
|
+
!isCollectionPage || !isRootFacet(facet, isDepartment, isBrand)
|
|
111
|
+
)
|
|
95
112
|
|
|
96
113
|
return filteredFacets
|
|
97
114
|
},
|
|
@@ -214,6 +214,15 @@ const getOrderForm = async (id: string, { clients: { commerce } }: Context) => {
|
|
|
214
214
|
})
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
const clearOrderFormMessages = async (
|
|
218
|
+
id: string,
|
|
219
|
+
{ clients: { commerce } }: Context
|
|
220
|
+
) => {
|
|
221
|
+
return commerce.checkout.clearOrderFormMessages({
|
|
222
|
+
id,
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
|
|
217
226
|
const updateOrderFormShippingData = async (
|
|
218
227
|
orderForm: OrderForm,
|
|
219
228
|
session: Maybe<IStoreSession> | undefined,
|
|
@@ -310,6 +319,12 @@ export const validateCart = async (
|
|
|
310
319
|
// Step1: Get OrderForm from VTEX Commerce
|
|
311
320
|
const orderForm = await getOrderForm(orderNumber, ctx)
|
|
312
321
|
|
|
322
|
+
// Clear messages so it doesn't keep populating toasts on a loop
|
|
323
|
+
// In the next validateCart mutation it will only have messages if a new message is created on orderForm
|
|
324
|
+
if (orderForm.messages.length !== 0) {
|
|
325
|
+
await clearOrderFormMessages(orderNumber, ctx)
|
|
326
|
+
}
|
|
327
|
+
|
|
313
328
|
// Step1.5: Check if another system changed the orderForm with this orderNumber
|
|
314
329
|
// If so, this means the user interacted with this cart elsewhere and expects
|
|
315
330
|
// to see this new cart state instead of what's stored on the user's browser.
|
|
@@ -386,8 +401,13 @@ export const validateCart = async (
|
|
|
386
401
|
.then((form: OrderForm) => setOrderFormEtag(form, commerce))
|
|
387
402
|
.then(joinItems)
|
|
388
403
|
|
|
404
|
+
const equalMessages = deepEquals(
|
|
405
|
+
orderForm.messages,
|
|
406
|
+
updatedOrderForm.messages
|
|
407
|
+
)
|
|
408
|
+
|
|
389
409
|
// Step5: If no changes detected before/after updating orderForm, the order is validated
|
|
390
|
-
if (equals(order, updatedOrderForm)) {
|
|
410
|
+
if (equals(order, updatedOrderForm) && equalMessages) {
|
|
391
411
|
return null
|
|
392
412
|
}
|
|
393
413
|
// Step6: There were changes, convert orderForm to StoreCart
|