@faststore/api 1.11.4 → 1.11.7

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.esm.js CHANGED
@@ -67,6 +67,14 @@ const VtexCommerce = ({
67
67
  body: JSON.stringify(args)
68
68
  });
69
69
  },
70
+ shippingData: ({
71
+ id,
72
+ body
73
+ }) => {
74
+ return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`, { ...BASE_INIT,
75
+ body: JSON.stringify(body)
76
+ });
77
+ },
70
78
  orderForm: ({
71
79
  id,
72
80
  refreshOutdatedData = true,
@@ -1070,6 +1078,31 @@ const isOrderFormStale = form => {
1070
1078
 
1071
1079
  const newEtag = getOrderFormEtag(form);
1072
1080
  return newEtag !== oldEtag;
1081
+ }; // Returns the regionalized orderForm
1082
+
1083
+
1084
+ const getOrderForm = async (id, session, {
1085
+ clients: {
1086
+ commerce
1087
+ }
1088
+ }) => {
1089
+ var _orderForm$shippingDa, _orderForm$shippingDa2;
1090
+
1091
+ const orderForm = await commerce.checkout.orderForm({
1092
+ id
1093
+ });
1094
+ const shouldUpdateShippingData = ((_orderForm$shippingDa = orderForm.shippingData) == null ? void 0 : (_orderForm$shippingDa2 = _orderForm$shippingDa.address) == null ? void 0 : _orderForm$shippingDa2.postalCode) != (session == null ? void 0 : session.postalCode);
1095
+
1096
+ if (shouldUpdateShippingData) {
1097
+ return commerce.checkout.shippingData({
1098
+ id: orderForm.orderFormId,
1099
+ body: {
1100
+ selectedAddresses: [session]
1101
+ }
1102
+ });
1103
+ }
1104
+
1105
+ return orderForm;
1073
1106
  };
1074
1107
  /**
1075
1108
  * This resolver implements the optimistic cart behavior. The main idea in here
@@ -1089,7 +1122,8 @@ const isOrderFormStale = form => {
1089
1122
  const validateCart = async (_, {
1090
1123
  cart: {
1091
1124
  order
1092
- }
1125
+ },
1126
+ session
1093
1127
  }, ctx) => {
1094
1128
  const {
1095
1129
  enableOrderFormSync
@@ -1107,9 +1141,7 @@ const validateCart = async (_, {
1107
1141
  }
1108
1142
  } = ctx; // Step1: Get OrderForm from VTEX Commerce
1109
1143
 
1110
- const orderForm = await commerce.checkout.orderForm({
1111
- id: orderNumber
1112
- }); // Step1.5: Check if another system changed the orderForm with this orderNumber
1144
+ const orderForm = await getOrderForm(orderNumber, session, ctx); // Step1.5: Check if another system changed the orderForm with this orderNumber
1113
1145
  // If so, this means the user interacted with this cart elsewhere and expects
1114
1146
  // to see this new cart state instead of what's stored on the user's browser.
1115
1147
 
@@ -2177,8 +2209,8 @@ var doc$6 = {"kind":"Document","definitions":[{"kind":"UnionTypeDefinition","nam
2177
2209
  var doc$7 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Image.","block":true},"name":{"kind":"Name","value":"StoreImage"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Image URL.","block":true},"name":{"kind":"Name","value":"url"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Alias for the image.","block":true},"name":{"kind":"Name","value":"alternateName"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}]},{"kind":"InputObjectTypeDefinition","description":{"kind":"StringValue","value":"Image input.","block":true},"name":{"kind":"Name","value":"IStoreImage"},"directives":[],"fields":[{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Image input URL.","block":true},"name":{"kind":"Name","value":"url"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Alias for the input image.","block":true},"name":{"kind":"Name","value":"alternateName"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}]}],"loc":{"start":0,"end":291}};
2178
2210
  doc$7.loc.source = {"body":"\"\"\"\nImage.\n\"\"\"\ntype StoreImage {\n \"\"\"\n Image URL.\n \"\"\"\n url: String!\n \"\"\"\n Alias for the image.\n \"\"\"\n alternateName: String!\n}\n\n\"\"\"\nImage input.\n\"\"\"\ninput IStoreImage {\n \"\"\"\n Image input URL.\n \"\"\"\n url: String!\n \"\"\"\n Alias for the input image.\n \"\"\"\n alternateName: String!\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
2179
2211
 
2180
- var doc$8 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","name":{"kind":"Name","value":"Mutation"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Checks for changes between the cart presented in the UI and the cart stored in the ecommerce platform. If changes are detected, it returns the cart stored on the platform. Otherwise, it returns `null`.","block":true},"name":{"kind":"Name","value":"validateCart"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"cart"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreCart"}}},"directives":[]}],"type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreCart"}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Updates a web session with the specified values.","block":true},"name":{"kind":"Name","value":"validateSession"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"session"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreSession"}}},"directives":[]},{"kind":"InputValueDefinition","name":{"kind":"Name","value":"search"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}],"type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreSession"}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Subscribes a new person to the newsletter list.","block":true},"name":{"kind":"Name","value":"subscribeToNewsletter"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"data"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IPersonNewsletter"}}},"directives":[]}],"type":{"kind":"NamedType","name":{"kind":"Name","value":"PersonNewsletter"}},"directives":[]}]}],"loc":{"start":0,"end":546}};
2181
- doc$8.loc.source = {"body":"type Mutation {\n \"\"\"\n Checks for changes between the cart presented in the UI and the cart stored in the ecommerce platform. If changes are detected, it returns the cart stored on the platform. Otherwise, it returns `null`.\n \"\"\"\n validateCart(cart: IStoreCart!): StoreCart\n \"\"\"\n Updates a web session with the specified values.\n \"\"\"\n validateSession(session: IStoreSession!, search: String!): StoreSession\n \"\"\"\n Subscribes a new person to the newsletter list.\n \"\"\"\n subscribeToNewsletter(data: IPersonNewsletter!): PersonNewsletter\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
2212
+ var doc$8 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","name":{"kind":"Name","value":"Mutation"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Checks for changes between the cart presented in the UI and the cart stored in the ecommerce platform. If changes are detected, it returns the cart stored on the platform. Otherwise, it returns `null`.","block":true},"name":{"kind":"Name","value":"validateCart"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"cart"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreCart"}}},"directives":[]},{"kind":"InputValueDefinition","name":{"kind":"Name","value":"session"},"type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreSession"}},"directives":[]}],"type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreCart"}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Updates a web session with the specified values.","block":true},"name":{"kind":"Name","value":"validateSession"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"session"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreSession"}}},"directives":[]},{"kind":"InputValueDefinition","name":{"kind":"Name","value":"search"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}],"type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreSession"}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Subscribes a new person to the newsletter list.","block":true},"name":{"kind":"Name","value":"subscribeToNewsletter"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"data"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IPersonNewsletter"}}},"directives":[]}],"type":{"kind":"NamedType","name":{"kind":"Name","value":"PersonNewsletter"}},"directives":[]}]}],"loc":{"start":0,"end":570}};
2213
+ doc$8.loc.source = {"body":"type Mutation {\n \"\"\"\n Checks for changes between the cart presented in the UI and the cart stored in the ecommerce platform. If changes are detected, it returns the cart stored on the platform. Otherwise, it returns `null`.\n \"\"\"\n validateCart(cart: IStoreCart!, session: IStoreSession): StoreCart\n \"\"\"\n Updates a web session with the specified values.\n \"\"\"\n validateSession(session: IStoreSession!, search: String!): StoreSession\n \"\"\"\n Subscribes a new person to the newsletter list.\n \"\"\"\n subscribeToNewsletter(data: IPersonNewsletter!): PersonNewsletter\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
2182
2214
 
2183
2215
  var doc$9 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Offer information.","block":true},"name":{"kind":"Name","value":"StoreOffer"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"This is displayed as the \"from\" price in the context of promotions' price comparison. This may change before it reaches the shelf.","block":true},"name":{"kind":"Name","value":"listPrice"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Computed price before applying coupons, taxes or benefits. This may change before it reaches the shelf.","block":true},"name":{"kind":"Name","value":"sellingPrice"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"ISO code of the currency used for the offer prices.","block":true},"name":{"kind":"Name","value":"priceCurrency"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Also known as spot price.","block":true},"name":{"kind":"Name","value":"price"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Next date in which price is scheduled to change. If there is no scheduled change, this will be set a year in the future from current time.","block":true},"name":{"kind":"Name","value":"priceValidUntil"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Offer item condition.","block":true},"name":{"kind":"Name","value":"itemCondition"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Offer item availability.","block":true},"name":{"kind":"Name","value":"availability"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Seller responsible for the offer.","block":true},"name":{"kind":"Name","value":"seller"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreOrganization"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Information on the item being offered.","block":true},"name":{"kind":"Name","value":"itemOffered"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreProduct"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Number of items offered.","block":true},"name":{"kind":"Name","value":"quantity"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},"directives":[]}]},{"kind":"InputObjectTypeDefinition","description":{"kind":"StringValue","value":"Offer input.","block":true},"name":{"kind":"Name","value":"IStoreOffer"},"directives":[],"fields":[{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Also known as spot price.","block":true},"name":{"kind":"Name","value":"price"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"This is displayed as the \"from\" price in the context of promotions' price comparison. This may change before it reaches the shelf.","block":true},"name":{"kind":"Name","value":"listPrice"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Seller responsible for the offer.","block":true},"name":{"kind":"Name","value":"seller"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreOrganization"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Information on the item being offered.","block":true},"name":{"kind":"Name","value":"itemOffered"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreProduct"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Number of items offered.","block":true},"name":{"kind":"Name","value":"quantity"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},"directives":[]}]}],"loc":{"start":0,"end":1501}};
2184
2216
  doc$9.loc.source = {"body":"\"\"\"\nOffer information.\n\"\"\"\ntype StoreOffer {\n \"\"\"\n This is displayed as the \"from\" price in the context of promotions' price comparison. This may change before it reaches the shelf.\n \"\"\"\n listPrice: Float!\n \"\"\"\n Computed price before applying coupons, taxes or benefits. This may change before it reaches the shelf.\n \"\"\"\n sellingPrice: Float!\n \"\"\"\n ISO code of the currency used for the offer prices.\n \"\"\"\n priceCurrency: String!\n \"\"\"\n Also known as spot price.\n \"\"\"\n price: Float!\n \"\"\"\n Next date in which price is scheduled to change. If there is no scheduled change, this will be set a year in the future from current time.\n \"\"\"\n priceValidUntil: String!\n \"\"\"\n Offer item condition.\n \"\"\"\n itemCondition: String!\n \"\"\"\n Offer item availability.\n \"\"\"\n availability: String!\n \"\"\"\n Seller responsible for the offer.\n \"\"\"\n seller: StoreOrganization!\n \"\"\"\n Information on the item being offered.\n \"\"\"\n itemOffered: StoreProduct!\n \"\"\"\n Number of items offered.\n \"\"\"\n quantity: Int!\n}\n\n\"\"\"\nOffer input.\n\"\"\"\ninput IStoreOffer {\n \"\"\"\n Also known as spot price.\n \"\"\"\n price: Float!\n \"\"\"\n This is displayed as the \"from\" price in the context of promotions' price comparison. This may change before it reaches the shelf.\n \"\"\"\n listPrice: Float!\n \"\"\"\n Seller responsible for the offer.\n \"\"\"\n seller: IStoreOrganization!\n \"\"\"\n Information on the item being offered.\n \"\"\"\n itemOffered: IStoreProduct!\n \"\"\"\n Number of items offered.\n \"\"\"\n quantity: Int!\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};