@faststore/api 1.7.51 → 1.7.54

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.
@@ -5,7 +5,7 @@ import { fetchAPI } from '../fetch'
5
5
  import type { FacetSearchResult } from './types/FacetSearchResult'
6
6
  import type {
7
7
  ProductSearchResult,
8
- SuggestedTerms,
8
+ Suggestion,
9
9
  } from './types/ProductSearchResult'
10
10
 
11
11
  export type Sort =
@@ -90,12 +90,16 @@ export const IntelligentSearch = (
90
90
  const suggestedProducts = (
91
91
  args: Omit<SearchArgs, 'type'>
92
92
  ): Promise<ProductSearchResult> =>
93
- fetchAPI(`${base}/api/suggestion_products/?term=${args.query}`)
93
+ fetchAPI(
94
+ `${base}/_v/api/intelligent-search/product_search?query=${args.query}`
95
+ )
94
96
 
95
97
  const suggestedTerms = (
96
98
  args: Omit<SearchArgs, 'type'>
97
- ): Promise<SuggestedTerms> =>
98
- fetchAPI(`${base}/api/split/suggestion_search/?q=${args.query}`)
99
+ ): Promise<Suggestion> =>
100
+ fetchAPI(
101
+ `${base}/_v/api/intelligent-search/search_suggestions?query=${args.query}`
102
+ )
99
103
 
100
104
  const facets = (args: Omit<SearchArgs, 'type'>) =>
101
105
  search<FacetSearchResult>({ ...args, type: 'facets' })
@@ -57,17 +57,6 @@ export interface First {
57
57
  index: number
58
58
  }
59
59
 
60
- export interface SuggestedTerms {
61
- total: number
62
- sampling: boolean
63
- translated: boolean
64
- locale: string
65
- query: string
66
- operator: string
67
- suggestion: Suggestion
68
- correction: Correction
69
- }
70
-
71
60
  export interface Suggestion {
72
61
  searches: Search[]
73
62
  }
@@ -98,7 +87,7 @@ export interface Product {
98
87
  items: Item[]
99
88
  skuSpecifications?: SkuSpecification[]
100
89
  priceRange: PriceRange
101
- specificationGroups: SpecificationGroup
90
+ specificationGroups: SpecificationGroup[]
102
91
  properties: Array<{ name: string; values: string[] }>
103
92
  selectedProperties: Array<{ key: string; value: string }>
104
93
  }
@@ -133,7 +122,10 @@ export interface Item {
133
122
  modalType: any | null
134
123
  images: Image[]
135
124
  Videos: string[]
136
- variations: string[]
125
+ variations: Array<{
126
+ name: string
127
+ values: string[]
128
+ }>
137
129
  sellers: Seller[]
138
130
  attachments: Array<{
139
131
  id: number
@@ -214,5 +206,9 @@ interface PriceRange {
214
206
  interface SpecificationGroup {
215
207
  name: string
216
208
  originalName: string
217
- specifications: { name: string; originalName: string; values: string[] }
209
+ specifications: Array<{
210
+ name: string
211
+ originalName: string
212
+ values: string[]
213
+ }>
218
214
  }
@@ -73,10 +73,9 @@ export const StoreProduct: Record<string, Resolver<Root>> & {
73
73
  }
74
74
  },
75
75
  isVariantOf: (root) => root,
76
- // TODO: get this value. Fix any type
77
- additionalProperty: ({ attributes = [] }: any) =>
78
- attributes.map((attribute: any) => ({
79
- name: attribute.key,
80
- value: attribute.value,
81
- })),
76
+ additionalProperty: ({ variations = [] }) => {
77
+ return variations.flatMap(({ name, values }) =>
78
+ values.map((value) => ({ name, value }))
79
+ )
80
+ },
82
81
  }
@@ -5,24 +5,24 @@ import type { StoreProduct } from './product'
5
5
 
6
6
  type Root = PromiseType<ReturnType<typeof StoreProduct.isVariantOf>>
7
7
 
8
- const BLOCKED_PROPERTIES: Record<string, boolean> = {
9
- sellerId: true,
10
- }
8
+ const BLOCKED_SPECIFICATIONS = new Set(['allSpecifications'])
11
9
 
12
10
  export const StoreProductGroup: Record<string, Resolver<Root>> = {
13
11
  hasVariant: (root) =>
14
12
  root.isVariantOf.items.map((item) => enhanceSku(item, root.isVariantOf)),
15
13
  productGroupID: ({ isVariantOf }) => isVariantOf.productId,
16
14
  name: ({ isVariantOf }) => isVariantOf.productName,
17
- additionalProperty: ({ isVariantOf: { properties } }) =>
18
- properties.flatMap((property) => {
19
- if (BLOCKED_PROPERTIES[property.name]) {
20
- return []
21
- }
22
-
23
- return property.values.map((propertyValue) => ({
24
- name: property.name,
25
- value: propertyValue,
26
- }))
27
- }),
15
+ additionalProperty: ({ isVariantOf: { specificationGroups } }) =>
16
+ specificationGroups
17
+ // filter sku specifications so we dont mess sku with product specs
18
+ .filter(
19
+ (specificationGroup) =>
20
+ !BLOCKED_SPECIFICATIONS.has(specificationGroup.name)
21
+ )
22
+ // Transform specs back into product specs
23
+ .flatMap(({ specifications }) =>
24
+ specifications.flatMap(({ name, values }) =>
25
+ values.map((value) => ({ name, value }))
26
+ )
27
+ ),
28
28
  }
@@ -24,9 +24,7 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {
24
24
  })
25
25
  .filter((sku) => !!sku)
26
26
 
27
- const {
28
- suggestion: { searches },
29
- } = terms
27
+ const { searches } = terms
30
28
 
31
29
  return {
32
30
  terms: searches.map((item) => item.term),