@faststore/api 1.12.40 → 1.12.42

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<{
@@ -12,6 +12,7 @@ import type { Channel } from '../../utils/channel';
12
12
  import type { SalesChannel } from './types/SalesChannel';
13
13
  import { MasterDataResponse } from './types/Newsletter';
14
14
  import type { Address, AddressInput } from './types/Address';
15
+ import { ShippingDataBody } from './types/ShippingData';
15
16
  declare type ValueOf<T> = T extends Record<string, infer K> ? K : never;
16
17
  export declare const VtexCommerce: ({ account, environment }: Options, ctx: Context) => {
17
18
  catalog: {
@@ -37,7 +38,7 @@ export declare const VtexCommerce: ({ account, environment }: Options, ctx: Cont
37
38
  simulation: (args: SimulationArgs, { salesChannel }?: SimulationOptions) => Promise<Simulation>;
38
39
  shippingData: ({ id, body, }: {
39
40
  id: string;
40
- body: unknown;
41
+ body: ShippingDataBody;
41
42
  }) => Promise<OrderForm>;
42
43
  orderForm: ({ id, refreshOutdatedData, channel, }: {
43
44
  id: string;
@@ -0,0 +1,28 @@
1
+ export interface ShippingDataBody {
2
+ clearAddressIfPostalCodeNotFound?: boolean;
3
+ selectedAddresses?: SelectedAddress[];
4
+ logisticsInfo?: LogisticsInfo[];
5
+ }
6
+ export interface SelectedAddress {
7
+ addressType?: string;
8
+ receiverName?: string;
9
+ postalCode?: string | null;
10
+ city?: string;
11
+ state?: string;
12
+ country?: string;
13
+ street?: string;
14
+ number?: string;
15
+ neighborhood?: string;
16
+ complement?: string;
17
+ reference?: string;
18
+ geoCoordinates?: GeoCoordinates | null | [];
19
+ }
20
+ export interface GeoCoordinates {
21
+ latitude: GLfloat;
22
+ longitude: GLfloat;
23
+ }
24
+ export interface LogisticsInfo {
25
+ itemIndex?: number;
26
+ selectedDeliveryChannel?: string;
27
+ selectedSla?: string;
28
+ }
@@ -31,7 +31,7 @@ export declare const getClients: (options: Options, ctx: Context) => {
31
31
  simulation: (args: import("./commerce/types/Simulation").SimulationArgs, { salesChannel }?: import("./commerce/types/Simulation").SimulationOptions) => Promise<import("./commerce/types/Simulation").Simulation>;
32
32
  shippingData: ({ id, body, }: {
33
33
  id: string;
34
- body: unknown;
34
+ body: import("./commerce/types/ShippingData").ShippingDataBody;
35
35
  }) => Promise<import("./commerce/types/OrderForm").OrderForm>;
36
36
  orderForm: ({ id, refreshOutdatedData, channel, }: {
37
37
  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.40",
3
+ "version": "1.12.42",
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": "950ce98d6df648dba88bf714286798208ac2bf7c"
49
+ "gitHead": "65e4e781d2b4864373e4b50b37511a095c674382"
50
50
  }
@@ -393,6 +393,8 @@ export type Query = {
393
393
  collection: StoreCollection;
394
394
  /** Returns the details of a product based on the specified locator. */
395
395
  product: StoreProduct;
396
+ /** Returns if there's a redirect for a search. */
397
+ redirect?: Maybe<StoreRedirect>;
396
398
  /** Returns the result of a product, facet, or suggestion search. */
397
399
  search: StoreSearchResult;
398
400
  /** Returns information about shipping simulation. */
@@ -422,6 +424,12 @@ export type QueryProductArgs = {
422
424
  };
423
425
 
424
426
 
427
+ export type QueryRedirectArgs = {
428
+ selectedFacets?: Maybe<Array<IStoreSelectedFacet>>;
429
+ term?: Maybe<Scalars['String']>;
430
+ };
431
+
432
+
425
433
  export type QuerySearchArgs = {
426
434
  after?: Maybe<Scalars['String']>;
427
435
  first: Scalars['Int'];
@@ -896,6 +904,16 @@ export type StorePropertyValue = {
896
904
  valueReference: Scalars['String'];
897
905
  };
898
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
+
899
917
  /** Information of a given review. */
900
918
  export type StoreReview = {
901
919
  __typename?: 'StoreReview';
@@ -19,6 +19,7 @@ import { getCookie } from '../../utils/getCookies'
19
19
  import type { SalesChannel } from './types/SalesChannel'
20
20
  import { MasterDataResponse } from './types/Newsletter'
21
21
  import type { Address, AddressInput } from './types/Address'
22
+ import { ShippingDataBody } from './types/ShippingData'
22
23
 
23
24
  type ValueOf<T> = T extends Record<string, infer K> ? K : never
24
25
 
@@ -94,8 +95,15 @@ export const VtexCommerce = (
94
95
  body,
95
96
  }: {
96
97
  id: string
97
- body: unknown
98
+ body: ShippingDataBody
98
99
  }): Promise<OrderForm> => {
100
+ if (body.selectedAddresses) {
101
+ body.selectedAddresses.forEach((address) => {
102
+ if (address.geoCoordinates === null) {
103
+ address.geoCoordinates = [];
104
+ }
105
+ });
106
+ }
99
107
  return fetchAPI(
100
108
  `${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`,
101
109
  {
@@ -180,8 +188,7 @@ export const VtexCommerce = (
180
188
  salesChannel,
181
189
  }: RegionInput): Promise<Region> => {
182
190
  return fetchAPI(
183
- `${base}/api/checkout/pub/regions/?postalCode=${postalCode}&country=${country}&sc=${
184
- salesChannel ?? ''
191
+ `${base}/api/checkout/pub/regions/?postalCode=${postalCode}&country=${country}&sc=${salesChannel ?? ''
185
192
  }`
186
193
  )
187
194
  },
@@ -0,0 +1,31 @@
1
+ export interface ShippingDataBody {
2
+ clearAddressIfPostalCodeNotFound?: boolean;
3
+ selectedAddresses?: SelectedAddress[];
4
+ logisticsInfo?: LogisticsInfo[];
5
+ }
6
+
7
+ export interface SelectedAddress {
8
+ addressType?: string;
9
+ receiverName?: string;
10
+ postalCode?: string | null;
11
+ city?: string;
12
+ state?: string;
13
+ country?: string;
14
+ street?: string;
15
+ number?: string;
16
+ neighborhood?: string;
17
+ complement?: string;
18
+ reference?: string;
19
+ geoCoordinates?: GeoCoordinates | null | [];
20
+ }
21
+
22
+ export interface GeoCoordinates {
23
+ latitude: GLfloat;
24
+ longitude: GLfloat;
25
+ }
26
+
27
+ export interface LogisticsInfo {
28
+ itemIndex?: number;
29
+ selectedDeliveryChannel?: string;
30
+ selectedSla?: string;
31
+ }
@@ -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
  }
@@ -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
  }