@faststore/api 1.8.35 → 1.8.38
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/CHANGELOG.md +30 -0
- package/dist/api.cjs.development.js +58 -19
- 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 +58 -19
- package/dist/api.esm.js.map +1 -1
- package/dist/platforms/vtex/clients/index.d.ts +0 -1
- package/dist/platforms/vtex/clients/search/index.d.ts +0 -1
- package/dist/platforms/vtex/index.d.ts +2 -0
- package/dist/platforms/vtex/utils/channel.d.ts +0 -2
- package/dist/platforms/vtex/utils/contex.d.ts +3 -0
- package/dist/platforms/vtex/utils/facets.d.ts +2 -0
- package/package.json +2 -2
- package/src/platforms/vtex/clients/search/index.ts +19 -13
- package/src/platforms/vtex/index.ts +3 -0
- package/src/platforms/vtex/resolvers/query.ts +22 -11
- package/src/platforms/vtex/resolvers/searchResult.ts +1 -1
- package/src/platforms/vtex/utils/channel.ts +0 -6
- package/src/platforms/vtex/utils/contex.ts +10 -0
- package/src/platforms/vtex/utils/facets.ts +11 -0
|
@@ -6,6 +6,7 @@ export interface Options {
|
|
|
6
6
|
account: string;
|
|
7
7
|
environment: 'vtexcommercestable' | 'vtexcommercebeta';
|
|
8
8
|
channel: string;
|
|
9
|
+
locale: string;
|
|
9
10
|
hideUnavailableItems: boolean;
|
|
10
11
|
flags?: FeatureFlags;
|
|
11
12
|
}
|
|
@@ -23,6 +24,7 @@ export interface Context {
|
|
|
23
24
|
* */
|
|
24
25
|
storage: {
|
|
25
26
|
channel: Required<Channel>;
|
|
27
|
+
locale: string;
|
|
26
28
|
flags: FeatureFlags;
|
|
27
29
|
};
|
|
28
30
|
headers: Record<string, string>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Context } from '..';
|
|
2
1
|
export interface Channel {
|
|
3
2
|
regionId?: string;
|
|
4
3
|
salesChannel?: string;
|
|
@@ -7,4 +6,3 @@ export default class ChannelMarshal {
|
|
|
7
6
|
static parse(channelString: string): Required<Channel>;
|
|
8
7
|
static stringify(channel: Channel): string;
|
|
9
8
|
}
|
|
10
|
-
export declare const mutateChannelContext: (ctx: Context, channelString: string) => void;
|
|
@@ -13,3 +13,5 @@ export declare const transformSelectedFacet: ({ key, value }: SelectedFacet) =>
|
|
|
13
13
|
key: string;
|
|
14
14
|
value: string;
|
|
15
15
|
};
|
|
16
|
+
export declare const findLocale: (facets?: SelectedFacet[] | null | undefined) => string | null;
|
|
17
|
+
export declare const findChannel: (facets?: SelectedFacet[] | null | undefined) => string | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/api",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.38",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"graphql": "^15.6.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "cf381aba27aecec9e756044b38c854680bab5c61"
|
|
49
49
|
}
|
|
@@ -105,6 +105,7 @@ export const IntelligentSearch = (
|
|
|
105
105
|
query,
|
|
106
106
|
sort,
|
|
107
107
|
fuzzy,
|
|
108
|
+
locale: ctx.storage.locale,
|
|
108
109
|
})
|
|
109
110
|
|
|
110
111
|
if (hideUnavailableItems !== undefined) {
|
|
@@ -123,22 +124,28 @@ export const IntelligentSearch = (
|
|
|
123
124
|
const products = (args: Omit<SearchArgs, 'type'>) =>
|
|
124
125
|
search<ProductSearchResult>({ ...args, type: 'product_search' })
|
|
125
126
|
|
|
126
|
-
const suggestedProducts = (
|
|
127
|
-
args: Omit<SearchArgs, 'type'>
|
|
128
|
-
): Promise<ProductSearchResult> =>
|
|
129
|
-
fetchAPI(
|
|
130
|
-
`${base}/_v/api/intelligent-search/product_search?query=${args.query}`
|
|
131
|
-
)
|
|
132
|
-
|
|
133
127
|
const suggestedTerms = (
|
|
134
128
|
args: Omit<SearchArgs, 'type'>
|
|
135
|
-
): Promise<Suggestion> =>
|
|
136
|
-
|
|
137
|
-
|
|
129
|
+
): Promise<Suggestion> => {
|
|
130
|
+
const params = new URLSearchParams({
|
|
131
|
+
query: args.query?.toString() ?? '',
|
|
132
|
+
locale: ctx.storage.locale,
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
return fetchAPI(
|
|
136
|
+
`${base}/_v/api/intelligent-search/search_suggestions?${params.toString()}`
|
|
138
137
|
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const topSearches = (): Promise<Suggestion> => {
|
|
141
|
+
const params = new URLSearchParams({
|
|
142
|
+
locale: ctx.storage.locale,
|
|
143
|
+
})
|
|
139
144
|
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
return fetchAPI(
|
|
146
|
+
`${base}/_v/api/intelligent-search/top_searches?${params.toString()}`
|
|
147
|
+
)
|
|
148
|
+
}
|
|
142
149
|
|
|
143
150
|
const facets = (args: Omit<SearchArgs, 'type'>) =>
|
|
144
151
|
search<FacetSearchResult>({ ...args, type: 'facets' })
|
|
@@ -147,7 +154,6 @@ export const IntelligentSearch = (
|
|
|
147
154
|
facets,
|
|
148
155
|
products,
|
|
149
156
|
suggestedTerms,
|
|
150
|
-
suggestedProducts,
|
|
151
157
|
topSearches,
|
|
152
158
|
}
|
|
153
159
|
}
|
|
@@ -26,6 +26,7 @@ export interface Options {
|
|
|
26
26
|
environment: 'vtexcommercestable' | 'vtexcommercebeta'
|
|
27
27
|
// Default sales channel to use for fetching products
|
|
28
28
|
channel: string
|
|
29
|
+
locale: string
|
|
29
30
|
hideUnavailableItems: boolean
|
|
30
31
|
flags?: FeatureFlags
|
|
31
32
|
}
|
|
@@ -45,6 +46,7 @@ export interface Context {
|
|
|
45
46
|
* */
|
|
46
47
|
storage: {
|
|
47
48
|
channel: Required<Channel>
|
|
49
|
+
locale: string
|
|
48
50
|
flags: FeatureFlags
|
|
49
51
|
}
|
|
50
52
|
headers: Record<string, string>
|
|
@@ -79,6 +81,7 @@ export const getContextFactory = (options: Options) => (ctx: any): Context => {
|
|
|
79
81
|
ctx.storage = {
|
|
80
82
|
channel: ChannelMarshal.parse(options.channel),
|
|
81
83
|
flags: options.flags ?? {},
|
|
84
|
+
locale: options.locale,
|
|
82
85
|
}
|
|
83
86
|
ctx.clients = getClients(options, ctx)
|
|
84
87
|
ctx.loaders = getLoaders(options, ctx)
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { mutateChannelContext, mutateLocaleContext } from '../utils/contex'
|
|
1
2
|
import { enhanceSku } from '../utils/enhanceSku'
|
|
2
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
findChannel,
|
|
5
|
+
findLocale,
|
|
6
|
+
transformSelectedFacet,
|
|
7
|
+
} from '../utils/facets'
|
|
3
8
|
import { SORT_MAP } from '../utils/sort'
|
|
4
9
|
import { StoreCollection } from './collection'
|
|
5
10
|
import type {
|
|
@@ -11,16 +16,19 @@ import type {
|
|
|
11
16
|
} from '../../../__generated__/schema'
|
|
12
17
|
import type { CategoryTree } from '../clients/commerce/types/CategoryTree'
|
|
13
18
|
import type { Context } from '../index'
|
|
14
|
-
import { mutateChannelContext } from '../utils/channel'
|
|
15
19
|
|
|
16
20
|
export const Query = {
|
|
17
21
|
product: async (_: unknown, { locator }: QueryProductArgs, ctx: Context) => {
|
|
18
22
|
// Insert channel in context for later usage
|
|
19
|
-
const
|
|
20
|
-
|
|
23
|
+
const channel = findChannel(locator)
|
|
24
|
+
const locale = findLocale(locator)
|
|
21
25
|
|
|
22
|
-
if (
|
|
23
|
-
mutateChannelContext(ctx,
|
|
26
|
+
if (channel) {
|
|
27
|
+
mutateChannelContext(ctx, channel)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (locale) {
|
|
31
|
+
mutateLocaleContext(ctx, locale)
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
const {
|
|
@@ -42,12 +50,15 @@ export const Query = {
|
|
|
42
50
|
ctx: Context
|
|
43
51
|
) => {
|
|
44
52
|
// Insert channel in context for later usage
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
const channel = findChannel(selectedFacets)
|
|
54
|
+
const locale = findLocale(selectedFacets)
|
|
55
|
+
|
|
56
|
+
if (channel) {
|
|
57
|
+
mutateChannelContext(ctx, channel)
|
|
58
|
+
}
|
|
48
59
|
|
|
49
|
-
if (
|
|
50
|
-
|
|
60
|
+
if (locale) {
|
|
61
|
+
mutateLocaleContext(ctx, locale)
|
|
51
62
|
}
|
|
52
63
|
|
|
53
64
|
const after = maybeAfter ? Number(maybeAfter) : 0
|
|
@@ -24,7 +24,7 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const terms = await search.suggestedTerms(searchArgs)
|
|
27
|
-
const products = await search.
|
|
27
|
+
const products = await search.products(searchArgs)
|
|
28
28
|
|
|
29
29
|
const skus = products.products
|
|
30
30
|
.map((product) => {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { Context } from '..'
|
|
2
|
-
|
|
3
1
|
export interface Channel {
|
|
4
2
|
regionId?: string
|
|
5
3
|
salesChannel?: string
|
|
@@ -25,7 +23,3 @@ export default class ChannelMarshal {
|
|
|
25
23
|
return JSON.stringify(channel)
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
|
-
|
|
29
|
-
export const mutateChannelContext = (ctx: Context, channelString: string) => {
|
|
30
|
-
ctx.storage.channel = ChannelMarshal.parse(channelString)
|
|
31
|
-
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import ChannelMarshal from './channel'
|
|
2
|
+
import type { Context } from '..'
|
|
3
|
+
|
|
4
|
+
export const mutateChannelContext = (ctx: Context, channelString: string) => {
|
|
5
|
+
ctx.storage.channel = ChannelMarshal.parse(channelString)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const mutateLocaleContext = (ctx: Context, locale: string) => {
|
|
9
|
+
ctx.storage.locale = locale
|
|
10
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ChannelMarshal from './channel'
|
|
2
|
+
import type { Maybe } from '../../../__generated__/schema'
|
|
2
3
|
|
|
3
4
|
export interface SelectedFacet {
|
|
4
5
|
key: string
|
|
@@ -24,7 +25,17 @@ export const transformSelectedFacet = ({ key, value }: SelectedFacet) => {
|
|
|
24
25
|
return channelFacets
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
case 'locale': {
|
|
29
|
+
return [] // remove this facet from search
|
|
30
|
+
}
|
|
31
|
+
|
|
27
32
|
default:
|
|
28
33
|
return { key, value }
|
|
29
34
|
}
|
|
30
35
|
}
|
|
36
|
+
|
|
37
|
+
export const findLocale = (facets?: Maybe<SelectedFacet[]>) =>
|
|
38
|
+
facets?.find((x) => x.key === 'locale')?.value ?? null
|
|
39
|
+
|
|
40
|
+
export const findChannel = (facets?: Maybe<SelectedFacet[]>) =>
|
|
41
|
+
facets?.find((facet) => facet.key === 'channel')?.value ?? null
|