@faststore/api 2.1.66 → 2.1.78

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "2.1.66",
3
+ "version": "2.1.78",
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.1.53",
40
- "@faststore/shared": "^2.1.53",
39
+ "@faststore/eslint-config": "^2.1.78",
40
+ "@faststore/shared": "^2.1.78",
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": "a88fa12d654e7145278b839345efbf75e43e0228"
59
+ "gitHead": "847d5c45e0b3929558d0acd39359f47d783f2cf3"
60
60
  }
@@ -219,20 +219,23 @@ async function getOrderNumberFromSession(
219
219
  }
220
220
 
221
221
  // Returns the regionalized orderForm
222
- const getOrderForm = async (
223
- id: string,
224
- session: Maybe<IStoreSession> | undefined,
225
- { clients: { commerce } }: Context
226
- ) => {
227
- const orderForm = await commerce.checkout.orderForm({
222
+ const getOrderForm = async (id: string, { clients: { commerce } }: Context) => {
223
+ return commerce.checkout.orderForm({
228
224
  id,
229
225
  })
226
+ }
230
227
 
228
+ const updateOrderFormShippingData = async (
229
+ orderForm: OrderForm,
230
+ session: Maybe<IStoreSession> | undefined,
231
+ { clients: { commerce } }: Context
232
+ ) => {
231
233
  // Stores that are not yet providing the session while validating the cart
232
234
  // should not be able to update the shipping data
233
235
  //
234
236
  // This was causing errors while validating regionalizated carts
235
237
  // because the following code was trying to change the shippingData to an undefined address/session
238
+
236
239
  if (!session) {
237
240
  return orderForm
238
241
  }
@@ -277,7 +280,6 @@ const getOrderForm = async (
277
280
  true
278
281
  )
279
282
  }
280
-
281
283
  return orderForm
282
284
  }
283
285
 
@@ -328,7 +330,7 @@ export const validateCart = async (
328
330
  const orderNumber = orderNumberFromSession ?? orderNumberFromCart ?? ''
329
331
 
330
332
  // Step1: Get OrderForm from VTEX Commerce
331
- const orderForm = await getOrderForm(orderNumber, session, ctx)
333
+ const orderForm = await getOrderForm(orderNumber, ctx)
332
334
 
333
335
  // Step1.1: Checks if the orderForm id has changed. There are three cases for this:
334
336
  // Social Selling: the vtex_session cookie contains a new orderForm id with Social Selling data
@@ -410,15 +412,16 @@ export const validateCart = async (
410
412
  orderItems: changes,
411
413
  shouldSplitItem,
412
414
  })
415
+ // update orderForm shippingData
416
+ .then((form: OrderForm) => updateOrderFormShippingData(form, session, ctx))
413
417
  // update orderForm etag so we know last time we touched this orderForm
414
- .then((form) => setOrderFormEtag(form, commerce))
418
+ .then((form: OrderForm) => setOrderFormEtag(form, commerce))
415
419
  .then(joinItems)
416
420
 
417
421
  // Step5: If no changes detected before/after updating orderForm, the order is validated
418
422
  if (equals(order, updatedOrderForm)) {
419
423
  return null
420
424
  }
421
-
422
425
  // Step6: There were changes, convert orderForm to StoreCart
423
426
  return orderFormToCart(updatedOrderForm, skuLoader)
424
427
  }