@faststore/api 1.12.39 → 1.12.41

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
@@ -148,6 +148,9 @@ export declare const getResolvers: (options: Options) => {
148
148
  totals: import("./platforms/vtex/clients/commerce/types/Simulation").Total[];
149
149
  itemMetadata: null;
150
150
  }>;
151
+ redirect: (_: unknown, { term, selectedFacets }: import("./__generated__/schema").QueryRedirectArgs, ctx: import("./platforms/vtex").Context) => Promise<{
152
+ url: string | undefined;
153
+ } | null>;
151
154
  };
152
155
  Mutation: {
153
156
  validateCart: (_: unknown, { cart: { order }, session }: import("./__generated__/schema").MutationValidateCartArgs, ctx: import("./platforms/vtex").Context) => Promise<{
@@ -44,11 +44,12 @@ export declare const VtexCommerce: ({ account, environment }: Options, ctx: Cont
44
44
  refreshOutdatedData?: boolean | undefined;
45
45
  channel?: Required<Channel> | undefined;
46
46
  }) => Promise<OrderForm>;
47
- updateOrderFormItems: ({ id, orderItems, allowOutdatedData, salesChannel, }: {
47
+ updateOrderFormItems: ({ id, orderItems, allowOutdatedData, salesChannel, shouldSplitItem, }: {
48
48
  id: string;
49
49
  orderItems: OrderFormInputItem[];
50
50
  allowOutdatedData?: "paymentData" | undefined;
51
51
  salesChannel?: string | undefined;
52
+ shouldSplitItem?: boolean | null | undefined;
52
53
  }) => Promise<OrderForm>;
53
54
  setCustomData: ({ id, appId, key, value, }: {
54
55
  id: string;
@@ -38,11 +38,12 @@ export declare const getClients: (options: Options, ctx: Context) => {
38
38
  refreshOutdatedData?: boolean | undefined;
39
39
  channel?: Required<import("../utils/channel").Channel> | undefined;
40
40
  }) => Promise<import("./commerce/types/OrderForm").OrderForm>;
41
- updateOrderFormItems: ({ id, orderItems, allowOutdatedData, salesChannel, }: {
41
+ updateOrderFormItems: ({ id, orderItems, allowOutdatedData, salesChannel, shouldSplitItem, }: {
42
42
  id: string;
43
43
  orderItems: import("./commerce/types/OrderForm").OrderFormInputItem[];
44
44
  allowOutdatedData?: "paymentData" | undefined;
45
45
  salesChannel?: string | undefined;
46
+ shouldSplitItem?: boolean | null | undefined;
46
47
  }) => Promise<import("./commerce/types/OrderForm").OrderForm>;
47
48
  setCustomData: ({ id, appId, key, value, }: {
48
49
  id: string;
@@ -176,6 +176,9 @@ export declare const getResolvers: (_: Options) => {
176
176
  totals: import("./clients/commerce/types/Simulation").Total[];
177
177
  itemMetadata: null;
178
178
  }>;
179
+ redirect: (_: unknown, { term, selectedFacets }: import("../..").QueryRedirectArgs, ctx: Context) => Promise<{
180
+ url: string | undefined;
181
+ } | null>;
179
182
  };
180
183
  Mutation: {
181
184
  validateCart: (_: unknown, { cart: { order }, session }: import("../..").MutationValidateCartArgs, ctx: Context) => Promise<{
@@ -1,4 +1,4 @@
1
- import type { QueryAllCollectionsArgs, QueryAllProductsArgs, QueryCollectionArgs, QueryProductArgs, QuerySearchArgs, QueryShippingArgs } from "../../../__generated__/schema";
1
+ import type { QueryAllCollectionsArgs, QueryAllProductsArgs, QueryCollectionArgs, QueryProductArgs, QuerySearchArgs, QueryShippingArgs, QueryRedirectArgs } from "../../../__generated__/schema";
2
2
  import type { CategoryTree } from "../clients/commerce/types/CategoryTree";
3
3
  import type { Context } from "../index";
4
4
  import { SearchArgs } from "../clients/search";
@@ -62,4 +62,7 @@ export declare const Query: {
62
62
  totals: import("../clients/commerce/types/Simulation").Total[];
63
63
  itemMetadata: null;
64
64
  }>;
65
+ redirect: (_: unknown, { term, selectedFacets }: QueryRedirectArgs, ctx: Context) => Promise<{
66
+ url: string | undefined;
67
+ } | null>;
65
68
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "1.12.39",
3
+ "version": "1.12.41",
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": "872ef5ad4ff1db650a89222f96ed7073434da66c"
49
+ "gitHead": "bacc379647f54158cbb23b2056f892962a42af0c"
50
50
  }
@@ -133,7 +133,7 @@ export type IShippingItem = {
133
133
 
134
134
  /** Shopping cart input. */
135
135
  export type IStoreCart = {
136
- /** Order information, including `orderNumber` and `acceptedOffer`. */
136
+ /** Order information, including `orderNumber`, `acceptedOffer` and `shouldSplitItem`. */
137
137
  order: IStoreOrder;
138
138
  };
139
139
 
@@ -172,6 +172,8 @@ export type IStoreOrder = {
172
172
  acceptedOffer: Array<IStoreOffer>;
173
173
  /** ID of the order in [VTEX order management](https://help.vtex.com/en/tutorial/license-manager-resources-oms--60QcBsvWeum02cFi3GjBzg#). */
174
174
  orderNumber: Scalars['String'];
175
+ /** Indicates whether or not items with attachments should be split. */
176
+ shouldSplitItem?: Maybe<Scalars['Boolean']>;
175
177
  };
176
178
 
177
179
  /** Organization input. */
@@ -391,6 +393,8 @@ export type Query = {
391
393
  collection: StoreCollection;
392
394
  /** Returns the details of a product based on the specified locator. */
393
395
  product: StoreProduct;
396
+ /** Returns if there's a redirect for a search. */
397
+ redirect?: Maybe<StoreRedirect>;
394
398
  /** Returns the result of a product, facet, or suggestion search. */
395
399
  search: StoreSearchResult;
396
400
  /** Returns information about shipping simulation. */
@@ -420,6 +424,12 @@ export type QueryProductArgs = {
420
424
  };
421
425
 
422
426
 
427
+ export type QueryRedirectArgs = {
428
+ selectedFacets?: Maybe<Array<IStoreSelectedFacet>>;
429
+ term?: Maybe<Scalars['String']>;
430
+ };
431
+
432
+
423
433
  export type QuerySearchArgs = {
424
434
  after?: Maybe<Scalars['String']>;
425
435
  first: Scalars['Int'];
@@ -894,6 +904,16 @@ export type StorePropertyValue = {
894
904
  valueReference: Scalars['String'];
895
905
  };
896
906
 
907
+ /**
908
+ * Redirect informations, including url returned by the query.
909
+ * https://schema.org/Thing
910
+ */
911
+ export type StoreRedirect = {
912
+ __typename?: 'StoreRedirect';
913
+ /** URL to redirect */
914
+ url?: Maybe<Scalars['String']>;
915
+ };
916
+
897
917
  /** Information of a given review. */
898
918
  export type StoreReview = {
899
919
  __typename?: 'StoreReview';
@@ -129,11 +129,13 @@ export const VtexCommerce = (
129
129
  orderItems,
130
130
  allowOutdatedData = 'paymentData',
131
131
  salesChannel = ctx.storage.channel.salesChannel,
132
+ shouldSplitItem = true,
132
133
  }: {
133
134
  id: string
134
135
  orderItems: OrderFormInputItem[]
135
136
  allowOutdatedData?: 'paymentData'
136
137
  salesChannel?: string
138
+ shouldSplitItem?: boolean | null
137
139
  }): Promise<OrderForm> => {
138
140
  const params = new URLSearchParams({
139
141
  allowOutdatedData,
@@ -144,7 +146,10 @@ export const VtexCommerce = (
144
146
  `${base}/api/checkout/pub/orderForm/${id}/items?${params}`,
145
147
  {
146
148
  ...BASE_INIT,
147
- body: JSON.stringify({ orderItems }),
149
+ body: JSON.stringify({
150
+ orderItems,
151
+ noSplitItem: !shouldSplitItem,
152
+ }),
148
153
  method: 'PATCH',
149
154
  }
150
155
  )
@@ -19,6 +19,7 @@ import type {
19
19
  QueryProductArgs,
20
20
  QuerySearchArgs,
21
21
  QueryShippingArgs,
22
+ QueryRedirectArgs
22
23
  } from "../../../__generated__/schema"
23
24
  import type { CategoryTree } from "../clients/commerce/types/CategoryTree"
24
25
  import type { Context } from "../index"
@@ -142,9 +143,8 @@ export const Query = {
142
143
  productId: crossSelling.value,
143
144
  })
144
145
 
145
- query = `product:${
146
- products.map((x) => x.productId).slice(0, first).join(";")
147
- }`
146
+ query = `product:${products.map((x) => x.productId).slice(0, first).join(";")
147
+ }`
148
148
  }
149
149
 
150
150
  const after = maybeAfter ? Number(maybeAfter) : 0
@@ -273,4 +273,26 @@ export const Query = {
273
273
  address,
274
274
  }
275
275
  },
276
+ redirect: async (
277
+ _: unknown,
278
+ { term, selectedFacets }: QueryRedirectArgs,
279
+ ctx: Context
280
+ ) => {
281
+ // Currently the search redirection can be done through a search term or filter (facet) so we limit the redirect query to always have one of these values otherwise we do not execute it.
282
+ // https://help.vtex.com/en/tracks/vtex-intelligent-search--19wrbB7nEQcmwzDPl1l4Cb/4Gd2wLQFbCwTsh8RUDwSoL?&utm_source=autocomplete
283
+ if (!term && (!selectedFacets || !selectedFacets.length)) {
284
+ return null
285
+ }
286
+
287
+ const { redirect } = await ctx.clients.search.products({
288
+ page: 1,
289
+ count: 1,
290
+ query: term ?? undefined,
291
+ selectedFacets: selectedFacets?.flatMap(transformSelectedFacet) ?? [],
292
+ })
293
+
294
+ return {
295
+ url: redirect
296
+ }
297
+ },
276
298
  }
@@ -266,7 +266,7 @@ export const validateCart = async (
266
266
  { cart: { order }, session }: MutationValidateCartArgs,
267
267
  ctx: Context
268
268
  ) => {
269
- const { orderNumber: orderNumberFromCart, acceptedOffer } = order
269
+ const { orderNumber: orderNumberFromCart, acceptedOffer, shouldSplitItem } = order
270
270
  const {
271
271
  clients: { commerce },
272
272
  loaders: { skuLoader },
@@ -363,6 +363,7 @@ export const validateCart = async (
363
363
  .updateOrderFormItems({
364
364
  id: orderForm.orderFormId,
365
365
  orderItems: changes,
366
+ shouldSplitItem,
366
367
  })
367
368
  // update orderForm etag so we know last time we touched this orderForm
368
369
  .then((form) =>
@@ -31,7 +31,7 @@ Shopping cart input.
31
31
  """
32
32
  input IStoreCart {
33
33
  """
34
- Order information, including `orderNumber` and `acceptedOffer`.
34
+ Order information, including `orderNumber`, `acceptedOffer` and `shouldSplitItem`.
35
35
  """
36
36
  order: IStoreOrder!
37
37
  }
@@ -24,4 +24,8 @@ input IStoreOrder {
24
24
  Array with information on each accepted offer.
25
25
  """
26
26
  acceptedOffer: [IStoreOffer!]!
27
+ """
28
+ Indicates whether or not items with attachments should be split.
29
+ """
30
+ shouldSplitItem: Boolean
27
31
  }
@@ -282,4 +282,30 @@ type Query {
282
282
  country: String!
283
283
  ): ShippingData
284
284
  @cacheControl(scope: "public", sMaxAge: 120, staleWhileRevalidate: 3600)
285
+
286
+ """
287
+ Returns if there's a redirect for a search.
288
+ """
289
+ redirect(
290
+ """
291
+ Search term.
292
+ """
293
+ term: String
294
+ """
295
+ Array of selected search facets.
296
+ """
297
+ selectedFacets: [IStoreSelectedFacet!]
298
+ ): StoreRedirect
299
+ @cacheControl(scope: "public", sMaxAge: 120, staleWhileRevalidate: 3600)
300
+ }
301
+
302
+ """
303
+ Redirect informations, including url returned by the query.
304
+ https://schema.org/Thing
305
+ """
306
+ type StoreRedirect {
307
+ """
308
+ URL to redirect
309
+ """
310
+ url: String
285
311
  }