@faststore/api 1.12.40 → 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/__generated__/schema.d.ts +15 -0
- package/dist/api.cjs.development.js +27 -3
- package/dist/api.cjs.development.js.map +1 -1
- package/dist/api.cjs.production.min.js +1 -1
- package/dist/api.cjs.production.min.js.map +1 -1
- package/dist/api.esm.js +27 -3
- package/dist/api.esm.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/platforms/vtex/index.d.ts +3 -0
- package/dist/platforms/vtex/resolvers/query.d.ts +4 -1
- package/package.json +2 -2
- package/src/__generated__/schema.ts +18 -0
- package/src/platforms/vtex/resolvers/query.ts +25 -3
- package/src/typeDefs/query.graphql +26 -0
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<{
|
|
@@ -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.
|
|
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": "
|
|
49
|
+
"gitHead": "bacc379647f54158cbb23b2056f892962a42af0c"
|
|
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 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
|
-
|
|
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
|
}
|