@faststore/api 2.2.22 → 2.2.33

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.
@@ -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.22",
3
+ "version": "2.2.33",
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.22",
41
- "@faststore/shared": "^2.2.22",
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": "a5acbfeb73a13bf60686f7fec9b5cff739dfd5ac"
61
+ "gitHead": "3ef3bacdc55e2a9719398e5920a564b231a86bc5"
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,
@@ -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