@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/index.d.ts CHANGED
@@ -128,9 +128,7 @@ export declare const getResolvers: (options: Options) => {
128
128
  }>;
129
129
  };
130
130
  Mutation: {
131
- validateCart: (_: unknown, { cart: { order } }: {
132
- cart: import("./__generated__/schema").IStoreCart;
133
- }, ctx: import("./platforms/vtex").Context) => Promise<{
131
+ validateCart: (_: unknown, { cart: { order }, session }: import("./__generated__/schema").MutationValidateCartArgs, ctx: import("./platforms/vtex").Context) => Promise<{
134
132
  order: {
135
133
  orderNumber: string;
136
134
  acceptedOffer: Promise<{
@@ -34,6 +34,10 @@ export declare const VtexCommerce: ({ account, environment }: Options, ctx: Cont
34
34
  };
35
35
  checkout: {
36
36
  simulation: (args: SimulationArgs, { salesChannel }?: SimulationOptions) => Promise<Simulation>;
37
+ shippingData: ({ id, body }: {
38
+ id: string;
39
+ body: unknown;
40
+ }) => Promise<OrderForm>;
37
41
  orderForm: ({ id, refreshOutdatedData, channel, }: {
38
42
  id: string;
39
43
  refreshOutdatedData?: boolean | undefined;
@@ -29,6 +29,10 @@ export declare const getClients: (options: Options, ctx: Context) => {
29
29
  };
30
30
  checkout: {
31
31
  simulation: (args: import("./commerce/types/Simulation").SimulationArgs, { salesChannel }?: import("./commerce/types/Simulation").SimulationOptions) => Promise<import("./commerce/types/Simulation").Simulation>;
32
+ shippingData: ({ id, body }: {
33
+ id: string;
34
+ body: unknown;
35
+ }) => Promise<import("./commerce/types/OrderForm").OrderForm>;
32
36
  orderForm: ({ id, refreshOutdatedData, channel, }: {
33
37
  id: string;
34
38
  refreshOutdatedData?: boolean | undefined;
@@ -158,9 +158,7 @@ export declare const getResolvers: (_: Options) => {
158
158
  }>;
159
159
  };
160
160
  Mutation: {
161
- validateCart: (_: unknown, { cart: { order } }: {
162
- cart: import("../..").IStoreCart;
163
- }, ctx: Context) => Promise<{
161
+ validateCart: (_: unknown, { cart: { order }, session }: import("../..").MutationValidateCartArgs, ctx: Context) => Promise<{
164
162
  order: {
165
163
  orderNumber: string;
166
164
  acceptedOffer: Promise<{
@@ -1,7 +1,5 @@
1
1
  export declare const Mutation: {
2
- validateCart: (_: unknown, { cart: { order } }: {
3
- cart: import("../../..").IStoreCart;
4
- }, ctx: import("..").Context) => Promise<{
2
+ validateCart: (_: unknown, { cart: { order }, session }: import("../../..").MutationValidateCartArgs, ctx: import("..").Context) => Promise<{
5
3
  order: {
6
4
  orderNumber: string;
7
5
  acceptedOffer: Promise<{
@@ -1,4 +1,4 @@
1
- import type { IStoreCart } from '../../../__generated__/schema';
1
+ import type { MutationValidateCartArgs } from '../../../__generated__/schema';
2
2
  import type { Context } from '..';
3
3
  /**
4
4
  * This resolver implements the optimistic cart behavior. The main idea in here
@@ -13,9 +13,7 @@ import type { Context } from '..';
13
13
  * 3. Update the orderForm in VTEX platform accordingly
14
14
  * 4. If any changes were made, send to the UI the new cart. Null otherwise
15
15
  */
16
- export declare const validateCart: (_: unknown, { cart: { order } }: {
17
- cart: IStoreCart;
18
- }, ctx: Context) => Promise<{
16
+ export declare const validateCart: (_: unknown, { cart: { order }, session }: MutationValidateCartArgs, ctx: Context) => Promise<{
19
17
  order: {
20
18
  orderNumber: string;
21
19
  acceptedOffer: Promise<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "1.11.4",
3
+ "version": "1.11.7",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -46,5 +46,5 @@
46
46
  "peerDependencies": {
47
47
  "graphql": "^15.6.0"
48
48
  },
49
- "gitHead": "01591e2a58aa8d0ec505b8b4d0ca9c33d4244942"
49
+ "gitHead": "0cd611b59da838e4939992888ce60ea768e5e32e"
50
50
  }
@@ -208,6 +208,7 @@ export type MutationSubscribeToNewsletterArgs = {
208
208
 
209
209
  export type MutationValidateCartArgs = {
210
210
  cart: IStoreCart;
211
+ session?: Maybe<IStoreSession>;
211
212
  };
212
213
 
213
214
 
@@ -610,6 +611,8 @@ export type StoreProduct = {
610
611
  offers: StoreAggregateOffer;
611
612
  /** Product ID, such as [ISBN](https://www.isbn-international.org/content/what-isbn) or similar global IDs. */
612
613
  productID: Scalars['String'];
614
+ /** The product's release date. Formatted using https://en.wikipedia.org/wiki/ISO_8601 */
615
+ releaseDate: Scalars['String'];
613
616
  /** Array with review information. */
614
617
  review: Array<StoreReview>;
615
618
  /** Meta tag data. */
@@ -85,6 +85,17 @@ export const VtexCommerce = (
85
85
  }
86
86
  )
87
87
  },
88
+ shippingData: (
89
+ { id, body }: { id: string; body: unknown },
90
+ ): Promise<OrderForm> => {
91
+ return fetchAPI(
92
+ `${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`,
93
+ {
94
+ ...BASE_INIT,
95
+ body: JSON.stringify(body),
96
+ },
97
+ );
98
+ },
88
99
  orderForm: ({
89
100
  id,
90
101
  refreshOutdatedData = true,
@@ -1,17 +1,15 @@
1
1
  import deepEquals from 'fast-deep-equal'
2
2
 
3
3
  import { md5 } from '../utils/md5'
4
- import {
5
- attachmentToPropertyValue,
6
- getPropertyId,
7
- VALUE_REFERENCES,
8
- } from '../utils/propertyValue'
4
+ import { attachmentToPropertyValue, getPropertyId, VALUE_REFERENCES } from '../utils/propertyValue'
9
5
 
10
6
  import type {
11
- IStoreCart,
7
+ IStoreSession,
12
8
  IStoreOffer,
13
9
  IStoreOrder,
14
10
  IStorePropertyValue,
11
+ Maybe,
12
+ MutationValidateCartArgs,
15
13
  } from '../../../__generated__/schema'
16
14
  import type {
17
15
  OrderForm,
@@ -197,6 +195,31 @@ const isOrderFormStale = (form: OrderForm) => {
197
195
  return newEtag !== oldEtag
198
196
  }
199
197
 
198
+ // Returns the regionalized orderForm
199
+ const getOrderForm = async (
200
+ id: string,
201
+ session: Maybe<IStoreSession> | undefined,
202
+ { clients: { commerce } }: Context,
203
+ ) => {
204
+ const orderForm = await commerce.checkout.orderForm({
205
+ id,
206
+ });
207
+
208
+ const shouldUpdateShippingData =
209
+ orderForm.shippingData?.address?.postalCode != session?.postalCode;
210
+
211
+ if (shouldUpdateShippingData) {
212
+ return commerce.checkout.shippingData({
213
+ id: orderForm.orderFormId,
214
+ body: {
215
+ selectedAddresses: [session],
216
+ },
217
+ });
218
+ }
219
+
220
+ return orderForm;
221
+ };
222
+
200
223
  /**
201
224
  * This resolver implements the optimistic cart behavior. The main idea in here
202
225
  * is that we receive a cart from the UI (as query params) and we validate it with
@@ -212,7 +235,7 @@ const isOrderFormStale = (form: OrderForm) => {
212
235
  */
213
236
  export const validateCart = async (
214
237
  _: unknown,
215
- { cart: { order } }: { cart: IStoreCart },
238
+ { cart: { order }, session }: MutationValidateCartArgs,
216
239
  ctx: Context,
217
240
  ) => {
218
241
  const { enableOrderFormSync } = ctx.storage.flags
@@ -223,9 +246,7 @@ export const validateCart = async (
223
246
  } = ctx
224
247
 
225
248
  // Step1: Get OrderForm from VTEX Commerce
226
- const orderForm = await commerce.checkout.orderForm({
227
- id: orderNumber,
228
- })
249
+ const orderForm = await getOrderForm(orderNumber, session, ctx)
229
250
 
230
251
  // Step1.5: Check if another system changed the orderForm with this orderNumber
231
252
  // If so, this means the user interacted with this cart elsewhere and expects
@@ -2,7 +2,7 @@ type Mutation {
2
2
  """
3
3
  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`.
4
4
  """
5
- validateCart(cart: IStoreCart!): StoreCart
5
+ validateCart(cart: IStoreCart!, session: IStoreSession): StoreCart
6
6
  """
7
7
  Updates a web session with the specified values.
8
8
  """