@faststore/api 1.12.32 → 1.12.36
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 +209 -0
- package/dist/api.cjs.development.js +197 -89
- 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 +197 -89
- package/dist/api.esm.js.map +1 -1
- package/dist/index.d.ts +29 -9
- package/dist/platforms/vtex/clients/commerce/index.d.ts +2 -0
- package/dist/platforms/vtex/clients/commerce/types/Address.d.ts +16 -0
- package/dist/platforms/vtex/clients/commerce/types/Simulation.d.ts +2 -2
- package/dist/platforms/vtex/clients/index.d.ts +1 -0
- package/dist/platforms/vtex/clients/search/types/ProductSearchResult.d.ts +1 -0
- package/dist/platforms/vtex/index.d.ts +29 -9
- package/dist/platforms/vtex/loaders/index.d.ts +1 -1
- package/dist/platforms/vtex/loaders/simulation.d.ts +2 -2
- package/dist/platforms/vtex/resolvers/query.d.ts +21 -9
- package/dist/platforms/vtex/resolvers/searchResult.d.ts +5 -1
- package/dist/platforms/vtex/resolvers/shippingSLA.d.ts +14 -0
- package/package.json +3 -4
- package/src/__generated__/schema.ts +11 -0
- package/src/platforms/vtex/clients/search/types/ProductSearchResult.ts +1 -0
- package/src/platforms/vtex/resolvers/query.ts +6 -3
- package/src/platforms/vtex/resolvers/searchResult.ts +34 -30
- package/src/typeDefs/query.graphql +18 -0
- package/CHANGELOG.md +0 -1596
- package/LICENSE +0 -21
package/dist/index.d.ts
CHANGED
|
@@ -71,26 +71,29 @@ export declare const getResolvers: (options: Options) => {
|
|
|
71
71
|
} & {
|
|
72
72
|
attachmentsValues?: import("./platforms/vtex/clients/commerce/types/OrderForm").Attachment[] | undefined;
|
|
73
73
|
}, unknown, any>>;
|
|
74
|
-
StoreSearchResult: Record<string, import("./platforms/vtex").Resolver<
|
|
74
|
+
StoreSearchResult: Record<string, import("./platforms/vtex").Resolver<{
|
|
75
|
+
searchArgs: Pick<import("./platforms/vtex/clients/search").SearchArgs, "sort" | "selectedFacets" | "hideUnavailableItems" | "query" | "page" | "count" | "fuzzy">;
|
|
76
|
+
productSearchPromise: Promise<import("./platforms/vtex/clients/search/types/ProductSearchResult").ProductSearchResult>;
|
|
77
|
+
}, unknown, any>>;
|
|
75
78
|
StorePropertyValue: Record<string, import("./platforms/vtex").Resolver<import("./__generated__/schema").IStorePropertyValue, unknown, any>>;
|
|
76
79
|
SkuVariants: Record<string, import("./platforms/vtex").Resolver<import("./platforms/vtex/clients/search/types/ProductSearchResult").Item & {
|
|
77
80
|
isVariantOf: import("./platforms/vtex/clients/search/types/ProductSearchResult").Product;
|
|
78
81
|
} & {
|
|
79
82
|
attachmentsValues?: import("./platforms/vtex/clients/commerce/types/OrderForm").Attachment[] | undefined;
|
|
80
83
|
}, unknown, any>>;
|
|
84
|
+
ShippingSLA: Record<string, import("./platforms/vtex").Resolver<{
|
|
85
|
+
name?: string | undefined;
|
|
86
|
+
friendlyName?: string | undefined;
|
|
87
|
+
price?: number | undefined;
|
|
88
|
+
shippingEstimate?: string | undefined;
|
|
89
|
+
}, unknown, any>>;
|
|
81
90
|
ObjectOrString: import("graphql").GraphQLScalarType;
|
|
82
91
|
Query: {
|
|
83
92
|
product: (_: unknown, { locator }: import("./__generated__/schema").QueryProductArgs, ctx: import("./platforms/vtex").Context) => Promise<import("./platforms/vtex/utils/enhanceSku").EnhancedSku>;
|
|
84
93
|
collection: (_: unknown, { slug }: import("./__generated__/schema").QueryCollectionArgs, ctx: import("./platforms/vtex").Context) => Promise<import("./platforms/vtex/clients/commerce/types/Portal").CollectionPageType>;
|
|
85
94
|
search: (_: unknown, { first, after: maybeAfter, sort, term, selectedFacets }: import("./__generated__/schema").QuerySearchArgs, ctx: import("./platforms/vtex").Context) => Promise<{
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
query: string | null | undefined;
|
|
89
|
-
sort: import("./platforms/vtex/clients/search").Sort;
|
|
90
|
-
selectedFacets: {
|
|
91
|
-
key: string;
|
|
92
|
-
value: string;
|
|
93
|
-
}[];
|
|
95
|
+
searchArgs: Pick<import("./platforms/vtex/clients/search").SearchArgs, "sort" | "selectedFacets" | "hideUnavailableItems" | "query" | "page" | "count" | "fuzzy">;
|
|
96
|
+
productSearchPromise: Promise<import("./platforms/vtex/clients/search/types/ProductSearchResult").ProductSearchResult>;
|
|
94
97
|
}>;
|
|
95
98
|
allProducts: (_: unknown, { first, after: maybeAfter }: import("./__generated__/schema").QueryAllProductsArgs, ctx: import("./platforms/vtex").Context) => Promise<{
|
|
96
99
|
pageInfo: {
|
|
@@ -128,6 +131,23 @@ export declare const getResolvers: (options: Options) => {
|
|
|
128
131
|
cursor: string;
|
|
129
132
|
}[];
|
|
130
133
|
}>;
|
|
134
|
+
shipping: (_: unknown, { country, items, postalCode }: import("./__generated__/schema").QueryShippingArgs, ctx: import("./platforms/vtex").Context) => Promise<{
|
|
135
|
+
address: import("./platforms/vtex/clients/commerce/types/Address").Address;
|
|
136
|
+
items: import("./platforms/vtex/clients/commerce/types/Simulation").Item[];
|
|
137
|
+
ratesAndBenefitsData: import("./platforms/vtex/clients/commerce/types/Simulation").RatesAndBenefitsData;
|
|
138
|
+
paymentData: import("./platforms/vtex/clients/commerce/types/Simulation").PaymentData;
|
|
139
|
+
selectableGifts: any[];
|
|
140
|
+
marketingData: import("./platforms/vtex/clients/commerce/types/Simulation").MarketingData;
|
|
141
|
+
postalCode: null;
|
|
142
|
+
country: null;
|
|
143
|
+
logisticsInfo: import("./platforms/vtex/clients/commerce/types/Simulation").LogisticsInfo[];
|
|
144
|
+
messages: any[];
|
|
145
|
+
purchaseConditions: import("./platforms/vtex/clients/commerce/types/Simulation").PurchaseConditions;
|
|
146
|
+
pickupPoints: any[];
|
|
147
|
+
subscriptionData: null;
|
|
148
|
+
totals: import("./platforms/vtex/clients/commerce/types/Simulation").Total[];
|
|
149
|
+
itemMetadata: null;
|
|
150
|
+
}>;
|
|
131
151
|
};
|
|
132
152
|
Mutation: {
|
|
133
153
|
validateCart: (_: unknown, { cart: { order }, session }: import("./__generated__/schema").MutationValidateCartArgs, ctx: import("./platforms/vtex").Context) => Promise<{
|
|
@@ -11,6 +11,7 @@ import type { Session } from './types/Session';
|
|
|
11
11
|
import type { Channel } from '../../utils/channel';
|
|
12
12
|
import type { SalesChannel } from './types/SalesChannel';
|
|
13
13
|
import { MasterDataResponse } from './types/Newsletter';
|
|
14
|
+
import type { Address, AddressInput } from './types/Address';
|
|
14
15
|
declare type ValueOf<T> = T extends Record<string, infer K> ? K : never;
|
|
15
16
|
export declare const VtexCommerce: ({ account, environment }: Options, ctx: Context) => {
|
|
16
17
|
catalog: {
|
|
@@ -56,6 +57,7 @@ export declare const VtexCommerce: ({ account, environment }: Options, ctx: Cont
|
|
|
56
57
|
value: string;
|
|
57
58
|
}) => Promise<OrderForm>;
|
|
58
59
|
region: ({ postalCode, country, salesChannel, }: RegionInput) => Promise<Region>;
|
|
60
|
+
address: ({ postalCode, country, }: AddressInput) => Promise<Address>;
|
|
59
61
|
};
|
|
60
62
|
session: (search: string) => Promise<Session>;
|
|
61
63
|
subscribeToNewsletter: (data: {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface AddressInput {
|
|
2
|
+
postalCode: string;
|
|
3
|
+
country: string;
|
|
4
|
+
}
|
|
5
|
+
export interface Address {
|
|
6
|
+
postalCode: string;
|
|
7
|
+
city: string;
|
|
8
|
+
state: string;
|
|
9
|
+
country: string;
|
|
10
|
+
street: string;
|
|
11
|
+
number: string;
|
|
12
|
+
neighborhood: string;
|
|
13
|
+
complement: string;
|
|
14
|
+
reference: string;
|
|
15
|
+
geoCoordinates: [number];
|
|
16
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface ShippingItem {
|
|
2
2
|
id: string;
|
|
3
3
|
quantity: number;
|
|
4
4
|
seller: string;
|
|
@@ -12,7 +12,7 @@ export interface ShippingData {
|
|
|
12
12
|
}
|
|
13
13
|
export interface SimulationArgs {
|
|
14
14
|
country?: string;
|
|
15
|
-
items:
|
|
15
|
+
items: ShippingItem[];
|
|
16
16
|
postalCode?: string;
|
|
17
17
|
isCheckedIn?: boolean;
|
|
18
18
|
priceTables?: string[];
|
|
@@ -51,6 +51,7 @@ export declare const getClients: (options: Options, ctx: Context) => {
|
|
|
51
51
|
value: string;
|
|
52
52
|
}) => Promise<import("./commerce/types/OrderForm").OrderForm>;
|
|
53
53
|
region: ({ postalCode, country, salesChannel, }: import("./commerce/types/Region").RegionInput) => Promise<import("./commerce/types/Region").Region>;
|
|
54
|
+
address: ({ postalCode, country, }: import("./commerce/types/Address").AddressInput) => Promise<import("./commerce/types/Address").Address>;
|
|
54
55
|
};
|
|
55
56
|
session: (search: string) => Promise<import("./commerce/types/Session").Session>;
|
|
56
57
|
subscribeToNewsletter: (data: {
|
|
@@ -99,26 +99,29 @@ export declare const getResolvers: (_: Options) => {
|
|
|
99
99
|
} & {
|
|
100
100
|
attachmentsValues?: import("./clients/commerce/types/OrderForm").Attachment[] | undefined;
|
|
101
101
|
}, unknown, any>>;
|
|
102
|
-
StoreSearchResult: Record<string, Resolver<
|
|
102
|
+
StoreSearchResult: Record<string, Resolver<{
|
|
103
|
+
searchArgs: Pick<SearchArgs, "hideUnavailableItems" | "query" | "page" | "count" | "sort" | "selectedFacets" | "fuzzy">;
|
|
104
|
+
productSearchPromise: Promise<import("./clients/search/types/ProductSearchResult").ProductSearchResult>;
|
|
105
|
+
}, unknown, any>>;
|
|
103
106
|
StorePropertyValue: Record<string, Resolver<import("../..").IStorePropertyValue, unknown, any>>;
|
|
104
107
|
SkuVariants: Record<string, Resolver<import("./clients/search/types/ProductSearchResult").Item & {
|
|
105
108
|
isVariantOf: import("./clients/search/types/ProductSearchResult").Product;
|
|
106
109
|
} & {
|
|
107
110
|
attachmentsValues?: import("./clients/commerce/types/OrderForm").Attachment[] | undefined;
|
|
108
111
|
}, unknown, any>>;
|
|
112
|
+
ShippingSLA: Record<string, Resolver<{
|
|
113
|
+
name?: string | undefined;
|
|
114
|
+
friendlyName?: string | undefined;
|
|
115
|
+
price?: number | undefined;
|
|
116
|
+
shippingEstimate?: string | undefined;
|
|
117
|
+
}, unknown, any>>;
|
|
109
118
|
ObjectOrString: import("graphql").GraphQLScalarType;
|
|
110
119
|
Query: {
|
|
111
120
|
product: (_: unknown, { locator }: import("../..").QueryProductArgs, ctx: Context) => Promise<import("./utils/enhanceSku").EnhancedSku>;
|
|
112
121
|
collection: (_: unknown, { slug }: import("../..").QueryCollectionArgs, ctx: Context) => Promise<import("./clients/commerce/types/Portal").CollectionPageType>;
|
|
113
122
|
search: (_: unknown, { first, after: maybeAfter, sort, term, selectedFacets }: import("../..").QuerySearchArgs, ctx: Context) => Promise<{
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
query: string | null | undefined;
|
|
117
|
-
sort: import("./clients/search").Sort;
|
|
118
|
-
selectedFacets: {
|
|
119
|
-
key: string;
|
|
120
|
-
value: string;
|
|
121
|
-
}[];
|
|
123
|
+
searchArgs: Pick<SearchArgs, "hideUnavailableItems" | "query" | "page" | "count" | "sort" | "selectedFacets" | "fuzzy">;
|
|
124
|
+
productSearchPromise: Promise<import("./clients/search/types/ProductSearchResult").ProductSearchResult>;
|
|
122
125
|
}>;
|
|
123
126
|
allProducts: (_: unknown, { first, after: maybeAfter }: import("../..").QueryAllProductsArgs, ctx: Context) => Promise<{
|
|
124
127
|
pageInfo: {
|
|
@@ -156,6 +159,23 @@ export declare const getResolvers: (_: Options) => {
|
|
|
156
159
|
cursor: string;
|
|
157
160
|
}[];
|
|
158
161
|
}>;
|
|
162
|
+
shipping: (_: unknown, { country, items, postalCode }: import("../..").QueryShippingArgs, ctx: Context) => Promise<{
|
|
163
|
+
address: import("./clients/commerce/types/Address").Address;
|
|
164
|
+
items: import("./clients/commerce/types/Simulation").Item[];
|
|
165
|
+
ratesAndBenefitsData: import("./clients/commerce/types/Simulation").RatesAndBenefitsData;
|
|
166
|
+
paymentData: import("./clients/commerce/types/Simulation").PaymentData;
|
|
167
|
+
selectableGifts: any[];
|
|
168
|
+
marketingData: import("./clients/commerce/types/Simulation").MarketingData;
|
|
169
|
+
postalCode: null;
|
|
170
|
+
country: null;
|
|
171
|
+
logisticsInfo: import("./clients/commerce/types/Simulation").LogisticsInfo[];
|
|
172
|
+
messages: any[];
|
|
173
|
+
purchaseConditions: import("./clients/commerce/types/Simulation").PurchaseConditions;
|
|
174
|
+
pickupPoints: any[];
|
|
175
|
+
subscriptionData: null;
|
|
176
|
+
totals: import("./clients/commerce/types/Simulation").Total[];
|
|
177
|
+
itemMetadata: null;
|
|
178
|
+
}>;
|
|
159
179
|
};
|
|
160
180
|
Mutation: {
|
|
161
181
|
validateCart: (_: unknown, { cart: { order }, session }: import("../..").MutationValidateCartArgs, ctx: Context) => Promise<{
|
|
@@ -2,7 +2,7 @@ import type { Context, Options } from '..';
|
|
|
2
2
|
export declare type Loaders = ReturnType<typeof getLoaders>;
|
|
3
3
|
export declare const getLoaders: (options: Options, { clients }: Context) => {
|
|
4
4
|
skuLoader: import("dataloader")<string, import("../utils/enhanceSku").EnhancedSku, string>;
|
|
5
|
-
simulationLoader: import("dataloader")<import("../clients/commerce/types/Simulation").
|
|
5
|
+
simulationLoader: import("dataloader")<import("../clients/commerce/types/Simulation").SimulationArgs, import("../clients/commerce/types/Simulation").Simulation, import("../clients/commerce/types/Simulation").SimulationArgs>;
|
|
6
6
|
collectionLoader: import("dataloader")<string, import("../clients/commerce/types/Portal").CollectionPageType, string>;
|
|
7
7
|
salesChannelLoader: import("dataloader")<string, import("../clients/commerce/types/SalesChannel").SalesChannel, string>;
|
|
8
8
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import DataLoader from 'dataloader';
|
|
2
|
-
import type { PayloadItem, Simulation } from '../clients/commerce/types/Simulation';
|
|
3
2
|
import type { Options } from '..';
|
|
4
3
|
import type { Clients } from '../clients';
|
|
5
|
-
|
|
4
|
+
import type { Simulation, SimulationArgs } from '../clients/commerce/types/Simulation';
|
|
5
|
+
export declare const getSimulationLoader: (_: Options, clients: Clients) => DataLoader<SimulationArgs, Simulation, SimulationArgs>;
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import type { QueryAllCollectionsArgs, QueryAllProductsArgs, QueryCollectionArgs, QueryProductArgs, QuerySearchArgs } from "../../../__generated__/schema";
|
|
1
|
+
import type { QueryAllCollectionsArgs, QueryAllProductsArgs, QueryCollectionArgs, QueryProductArgs, QuerySearchArgs, QueryShippingArgs } from "../../../__generated__/schema";
|
|
2
2
|
import type { CategoryTree } from "../clients/commerce/types/CategoryTree";
|
|
3
3
|
import type { Context } from "../index";
|
|
4
|
+
import { SearchArgs } from "../clients/search";
|
|
4
5
|
export declare const Query: {
|
|
5
6
|
product: (_: unknown, { locator }: QueryProductArgs, ctx: Context) => Promise<import("../utils/enhanceSku").EnhancedSku>;
|
|
6
7
|
collection: (_: unknown, { slug }: QueryCollectionArgs, ctx: Context) => Promise<import("../clients/commerce/types/Portal").CollectionPageType>;
|
|
7
8
|
search: (_: unknown, { first, after: maybeAfter, sort, term, selectedFacets }: QuerySearchArgs, ctx: Context) => Promise<{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
query: string | null | undefined;
|
|
11
|
-
sort: import("../clients/search").Sort;
|
|
12
|
-
selectedFacets: {
|
|
13
|
-
key: string;
|
|
14
|
-
value: string;
|
|
15
|
-
}[];
|
|
9
|
+
searchArgs: Pick<SearchArgs, "sort" | "selectedFacets" | "hideUnavailableItems" | "query" | "page" | "count" | "fuzzy">;
|
|
10
|
+
productSearchPromise: Promise<import("../clients/search/types/ProductSearchResult").ProductSearchResult>;
|
|
16
11
|
}>;
|
|
17
12
|
allProducts: (_: unknown, { first, after: maybeAfter }: QueryAllProductsArgs, ctx: Context) => Promise<{
|
|
18
13
|
pageInfo: {
|
|
@@ -50,4 +45,21 @@ export declare const Query: {
|
|
|
50
45
|
cursor: string;
|
|
51
46
|
}[];
|
|
52
47
|
}>;
|
|
48
|
+
shipping: (_: unknown, { country, items, postalCode }: QueryShippingArgs, ctx: Context) => Promise<{
|
|
49
|
+
address: import("../clients/commerce/types/Address").Address;
|
|
50
|
+
items: import("../clients/commerce/types/Simulation").Item[];
|
|
51
|
+
ratesAndBenefitsData: import("../clients/commerce/types/Simulation").RatesAndBenefitsData;
|
|
52
|
+
paymentData: import("../clients/commerce/types/Simulation").PaymentData;
|
|
53
|
+
selectableGifts: any[];
|
|
54
|
+
marketingData: import("../clients/commerce/types/Simulation").MarketingData;
|
|
55
|
+
postalCode: null;
|
|
56
|
+
country: null;
|
|
57
|
+
logisticsInfo: import("../clients/commerce/types/Simulation").LogisticsInfo[];
|
|
58
|
+
messages: any[];
|
|
59
|
+
purchaseConditions: import("../clients/commerce/types/Simulation").PurchaseConditions;
|
|
60
|
+
pickupPoints: any[];
|
|
61
|
+
subscriptionData: null;
|
|
62
|
+
totals: import("../clients/commerce/types/Simulation").Total[];
|
|
63
|
+
itemMetadata: null;
|
|
64
|
+
}>;
|
|
53
65
|
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { Resolver } from '..';
|
|
2
2
|
import type { SearchArgs } from '../clients/search';
|
|
3
|
-
|
|
3
|
+
import { ProductSearchResult } from '../clients/search/types/ProductSearchResult';
|
|
4
|
+
declare type Root = {
|
|
5
|
+
searchArgs: Omit<SearchArgs, 'type'>;
|
|
6
|
+
productSearchPromise: Promise<ProductSearchResult>;
|
|
7
|
+
};
|
|
4
8
|
export declare const StoreSearchResult: Record<string, Resolver<Root>>;
|
|
5
9
|
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Resolver } from '..';
|
|
2
|
+
/**
|
|
3
|
+
* Transforms estimate (e.g 3bd) into friendly format (e.g Up to 3 business days)
|
|
4
|
+
* based on https://github.com/vtex-apps/shipping-estimate-translator/blob/13e17055d6353dd3f3f4c31bae77ab049002809b/messages/en.json
|
|
5
|
+
*/
|
|
6
|
+
export declare const getLocalizedEstimates: (estimate: string) => string;
|
|
7
|
+
declare type Root = {
|
|
8
|
+
name?: string;
|
|
9
|
+
friendlyName?: string;
|
|
10
|
+
price?: number;
|
|
11
|
+
shippingEstimate?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const ShippingSLA: Record<string, Resolver<Root>>;
|
|
14
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/api",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.36",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"p-limit": "^3.1.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@faststore/shared": "^1.12.
|
|
33
|
+
"@faststore/shared": "^1.12.35",
|
|
34
34
|
"@graphql-codegen/cli": "2.2.0",
|
|
35
35
|
"@graphql-codegen/typescript": "2.2.2",
|
|
36
36
|
"concurrently": "^6.2.1",
|
|
@@ -45,6 +45,5 @@
|
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"graphql": "^15.6.0"
|
|
48
|
-
}
|
|
49
|
-
"gitHead": "9deb68d7b10560726e2f50841d319590a7249392"
|
|
48
|
+
}
|
|
50
49
|
}
|
|
@@ -435,6 +435,15 @@ export type QueryShippingArgs = {
|
|
|
435
435
|
postalCode: Scalars['String'];
|
|
436
436
|
};
|
|
437
437
|
|
|
438
|
+
/** Search result. */
|
|
439
|
+
export type SearchMetadata = {
|
|
440
|
+
__typename?: 'SearchMetadata';
|
|
441
|
+
/** Indicates if the search term was misspelled. */
|
|
442
|
+
isTermMisspelled: Scalars['Boolean'];
|
|
443
|
+
/** Logical operator used to run the search. */
|
|
444
|
+
logicalOperator: Scalars['String'];
|
|
445
|
+
};
|
|
446
|
+
|
|
438
447
|
/** Shipping Simulation information. */
|
|
439
448
|
export type ShippingData = {
|
|
440
449
|
__typename?: 'ShippingData';
|
|
@@ -908,6 +917,8 @@ export type StoreSearchResult = {
|
|
|
908
917
|
__typename?: 'StoreSearchResult';
|
|
909
918
|
/** Array of search result facets. */
|
|
910
919
|
facets: Array<StoreFacet>;
|
|
920
|
+
/** Search result metadata. Additional data can be used to send analytics events. */
|
|
921
|
+
metadata?: Maybe<SearchMetadata>;
|
|
911
922
|
/** Search result products. */
|
|
912
923
|
products: StoreProductConnection;
|
|
913
924
|
/** Search result suggestions. */
|
|
@@ -23,6 +23,7 @@ import type {
|
|
|
23
23
|
import type { CategoryTree } from "../clients/commerce/types/CategoryTree"
|
|
24
24
|
import type { Context } from "../index"
|
|
25
25
|
import { isValidSkuId, pickBestSku } from "../utils/sku"
|
|
26
|
+
import { SearchArgs } from "../clients/search"
|
|
26
27
|
|
|
27
28
|
export const Query = {
|
|
28
29
|
product: async (_: unknown, { locator }: QueryProductArgs, ctx: Context) => {
|
|
@@ -147,15 +148,17 @@ export const Query = {
|
|
|
147
148
|
}
|
|
148
149
|
|
|
149
150
|
const after = maybeAfter ? Number(maybeAfter) : 0
|
|
150
|
-
const searchArgs = {
|
|
151
|
+
const searchArgs: Omit<SearchArgs, 'type'> = {
|
|
151
152
|
page: Math.ceil(after / first),
|
|
152
153
|
count: first,
|
|
153
|
-
query,
|
|
154
|
+
query: query ?? undefined,
|
|
154
155
|
sort: SORT_MAP[sort ?? 'score_desc'],
|
|
155
156
|
selectedFacets: selectedFacets?.flatMap(transformSelectedFacet) ?? [],
|
|
156
157
|
}
|
|
157
158
|
|
|
158
|
-
|
|
159
|
+
const productSearchPromise = ctx.clients.search.products(searchArgs)
|
|
160
|
+
|
|
161
|
+
return { searchArgs, productSearchPromise }
|
|
159
162
|
},
|
|
160
163
|
allProducts: async (
|
|
161
164
|
_: unknown,
|
|
@@ -2,17 +2,23 @@ import { enhanceSku } from '../utils/enhanceSku'
|
|
|
2
2
|
import type { Resolver } from '..'
|
|
3
3
|
import type { SearchArgs } from '../clients/search'
|
|
4
4
|
import type { Facet } from '../clients/search/types/FacetSearchResult'
|
|
5
|
+
import { ProductSearchResult } from '../clients/search/types/ProductSearchResult'
|
|
5
6
|
|
|
6
|
-
type Root =
|
|
7
|
+
type Root = {
|
|
8
|
+
searchArgs: Omit<SearchArgs, 'type'>
|
|
9
|
+
productSearchPromise: Promise<ProductSearchResult>
|
|
10
|
+
}
|
|
7
11
|
|
|
8
12
|
const isRootFacet = (facet: Facet) => facet.key === 'category-1'
|
|
9
13
|
|
|
10
14
|
export const StoreSearchResult: Record<string, Resolver<Root>> = {
|
|
11
|
-
suggestions: async (
|
|
15
|
+
suggestions: async (root, _, ctx) => {
|
|
12
16
|
const {
|
|
13
17
|
clients: { search },
|
|
14
18
|
} = ctx
|
|
15
19
|
|
|
20
|
+
const { searchArgs } = root
|
|
21
|
+
|
|
16
22
|
// If there's no search query, suggest the most popular searches.
|
|
17
23
|
if (!searchArgs.query) {
|
|
18
24
|
const topSearches = await search.topSearches()
|
|
@@ -26,10 +32,13 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {
|
|
|
26
32
|
}
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
const
|
|
30
|
-
const
|
|
35
|
+
const { productSearchPromise } = root
|
|
36
|
+
const [terms, productSearchResult] = await Promise.all([
|
|
37
|
+
search.suggestedTerms(searchArgs),
|
|
38
|
+
productSearchPromise,
|
|
39
|
+
])
|
|
31
40
|
|
|
32
|
-
const skus =
|
|
41
|
+
const skus = productSearchResult.products
|
|
33
42
|
.map((product) => {
|
|
34
43
|
const [maybeSku] = product.items
|
|
35
44
|
|
|
@@ -44,27 +53,10 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {
|
|
|
44
53
|
products: skus,
|
|
45
54
|
}
|
|
46
55
|
},
|
|
47
|
-
products: async (
|
|
48
|
-
const
|
|
49
|
-
clients: { search, sp },
|
|
50
|
-
} = ctx
|
|
56
|
+
products: async ({ productSearchPromise }) => {
|
|
57
|
+
const productSearchResult = await productSearchPromise
|
|
51
58
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
// Raise event on search's analytics API when performing
|
|
55
|
-
// a full text search.
|
|
56
|
-
if (searchArgs.query) {
|
|
57
|
-
sp.sendEvent({
|
|
58
|
-
type: 'search.query',
|
|
59
|
-
text: searchArgs.query,
|
|
60
|
-
misspelled: products.correction?.misspelled ?? false,
|
|
61
|
-
match: products.recordsFiltered,
|
|
62
|
-
operator: products.operator,
|
|
63
|
-
locale: ctx.storage.locale,
|
|
64
|
-
}).catch(console.error)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const skus = products.products
|
|
59
|
+
const skus = productSearchResult.products
|
|
68
60
|
.map((product) => {
|
|
69
61
|
const [maybeSku] = product.items
|
|
70
62
|
|
|
@@ -74,11 +66,11 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {
|
|
|
74
66
|
|
|
75
67
|
return {
|
|
76
68
|
pageInfo: {
|
|
77
|
-
hasNextPage:
|
|
78
|
-
hasPreviousPage:
|
|
69
|
+
hasNextPage: productSearchResult.pagination.after.length > 0,
|
|
70
|
+
hasPreviousPage: productSearchResult.pagination.before.length > 0,
|
|
79
71
|
startCursor: '0',
|
|
80
|
-
endCursor:
|
|
81
|
-
totalCount:
|
|
72
|
+
endCursor: productSearchResult.recordsFiltered.toString(),
|
|
73
|
+
totalCount: productSearchResult.recordsFiltered,
|
|
82
74
|
},
|
|
83
75
|
edges: skus.map((sku, index) => ({
|
|
84
76
|
node: sku,
|
|
@@ -86,7 +78,7 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {
|
|
|
86
78
|
})),
|
|
87
79
|
}
|
|
88
80
|
},
|
|
89
|
-
facets: async (searchArgs, _, ctx) => {
|
|
81
|
+
facets: async ({ searchArgs }, _, ctx) => {
|
|
90
82
|
const {
|
|
91
83
|
clients: { search: is },
|
|
92
84
|
} = ctx
|
|
@@ -103,4 +95,16 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {
|
|
|
103
95
|
|
|
104
96
|
return filteredFacets
|
|
105
97
|
},
|
|
98
|
+
metadata: async ({ searchArgs, productSearchPromise }) => {
|
|
99
|
+
if (!searchArgs.query) {
|
|
100
|
+
return null
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const productSearchResult = await productSearchPromise
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
isTermMisspelled: productSearchResult.correction?.misspelled ?? false,
|
|
107
|
+
logicalOperator: productSearchResult.operator,
|
|
108
|
+
}
|
|
109
|
+
},
|
|
106
110
|
}
|
|
@@ -148,6 +148,20 @@ type StoreSuggestions {
|
|
|
148
148
|
products: [StoreProduct!]!
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
"""
|
|
152
|
+
Search result.
|
|
153
|
+
"""
|
|
154
|
+
type SearchMetadata {
|
|
155
|
+
"""
|
|
156
|
+
Indicates if the search term was misspelled.
|
|
157
|
+
"""
|
|
158
|
+
isTermMisspelled: Boolean!
|
|
159
|
+
"""
|
|
160
|
+
Logical operator used to run the search.
|
|
161
|
+
"""
|
|
162
|
+
logicalOperator: String!
|
|
163
|
+
}
|
|
164
|
+
|
|
151
165
|
"""
|
|
152
166
|
Search result.
|
|
153
167
|
"""
|
|
@@ -164,6 +178,10 @@ type StoreSearchResult {
|
|
|
164
178
|
Search result suggestions.
|
|
165
179
|
"""
|
|
166
180
|
suggestions: StoreSuggestions!
|
|
181
|
+
"""
|
|
182
|
+
Search result metadata. Additional data can be used to send analytics events.
|
|
183
|
+
"""
|
|
184
|
+
metadata: SearchMetadata
|
|
167
185
|
}
|
|
168
186
|
|
|
169
187
|
type Query {
|