@faststore/api 1.8.34 → 1.8.37
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 +33 -0
- package/dist/api.cjs.development.js +67 -17
- 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 +67 -17
- package/dist/api.esm.js.map +1 -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 +28 -8
- package/src/platforms/vtex/index.ts +3 -0
- package/src/platforms/vtex/resolvers/query.ts +22 -11
- 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
|
@@ -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.37",
|
|
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": "297531783e1ebb6c2444b8c6586af43d34d28003"
|
|
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) {
|
|
@@ -125,20 +126,39 @@ export const IntelligentSearch = (
|
|
|
125
126
|
|
|
126
127
|
const suggestedProducts = (
|
|
127
128
|
args: Omit<SearchArgs, 'type'>
|
|
128
|
-
): Promise<ProductSearchResult> =>
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
): Promise<ProductSearchResult> => {
|
|
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/product_search?${params.toString()}`
|
|
131
137
|
)
|
|
138
|
+
}
|
|
132
139
|
|
|
133
140
|
const suggestedTerms = (
|
|
134
141
|
args: Omit<SearchArgs, 'type'>
|
|
135
|
-
): Promise<Suggestion> =>
|
|
136
|
-
|
|
137
|
-
|
|
142
|
+
): Promise<Suggestion> => {
|
|
143
|
+
const params = new URLSearchParams({
|
|
144
|
+
query: args.query?.toString() ?? '',
|
|
145
|
+
locale: ctx.storage.locale,
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
return fetchAPI(
|
|
149
|
+
`${base}/_v/api/intelligent-search/search_suggestions?${params.toString()}`
|
|
138
150
|
)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const topSearches = (): Promise<Suggestion> => {
|
|
154
|
+
const params = new URLSearchParams({
|
|
155
|
+
locale: ctx.storage.locale,
|
|
156
|
+
})
|
|
139
157
|
|
|
140
|
-
|
|
141
|
-
|
|
158
|
+
return fetchAPI(
|
|
159
|
+
`${base}/_v/api/intelligent-search/top_searches?${params.toString()}`
|
|
160
|
+
)
|
|
161
|
+
}
|
|
142
162
|
|
|
143
163
|
const facets = (args: Omit<SearchArgs, 'type'>) =>
|
|
144
164
|
search<FacetSearchResult>({ ...args, type: 'facets' })
|
|
@@ -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
|
|
@@ -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
|