@faststore/api 1.9.14 → 1.10.6

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.
@@ -1,11 +1,26 @@
1
1
  import ChannelMarshal from './channel'
2
2
  import type { Maybe } from '../../../__generated__/schema'
3
+ import { BadRequestError } from '../../errors'
3
4
 
4
5
  export interface SelectedFacet {
5
6
  key: string
6
7
  value: string
7
8
  }
8
9
 
10
+ export interface CrossSellingFacet {
11
+ key: keyof typeof FACET_CROSS_SELLING_MAP
12
+ value: string
13
+ }
14
+
15
+ export const FACET_CROSS_SELLING_MAP = {
16
+ buy: "whoboughtalsobought",
17
+ view: "whosawalsosaw",
18
+ similars: "similars",
19
+ viewAndBought: "whosawalsobought",
20
+ accessories: "accessories",
21
+ suggestions: "suggestions",
22
+ } as const
23
+
9
24
  /**
10
25
  * Transform facets from the store to VTEX platform facets.
11
26
  * For instance, the channel in Store becomes trade-policy and regionId in VTEX's realm
@@ -33,6 +48,15 @@ export const transformSelectedFacet = ({ key, value }: SelectedFacet) => {
33
48
  return { key, value: value.replace('-to-', ':') }
34
49
  }
35
50
 
51
+ case "buy":
52
+ case "view":
53
+ case "similars":
54
+ case "viewAndBought":
55
+ case "accessories":
56
+ case "suggestions": {
57
+ return [] // remove this facet from search
58
+ }
59
+
36
60
  default:
37
61
  return { key, value }
38
62
  }
@@ -52,6 +76,23 @@ export const parseRange = (range: string): [number, number] | null => {
52
76
  return splitted as [number, number]
53
77
  }
54
78
 
79
+ export const isCrossSelling = (
80
+ x: string,
81
+ ): x is CrossSellingFacet['key'] =>
82
+ typeof (FACET_CROSS_SELLING_MAP as Record<string, string>)[x] === "string"
83
+
84
+ export const findCrossSelling = (facets?: Maybe<SelectedFacet[]>) => {
85
+ const filtered = facets?.filter((x): x is CrossSellingFacet => isCrossSelling(x.key))
86
+
87
+ if (Array.isArray(filtered) && filtered.length > 1) {
88
+ throw new BadRequestError(
89
+ `You passed ${filtered.length} cross selling facets but only one is allowed. Please leave one of the following facet: ${filtered.map(x => x.key).join(',')}`
90
+ )
91
+ }
92
+
93
+ return filtered?.[0] ?? null
94
+ }
95
+
55
96
  export const findSlug = (facets?: Maybe<SelectedFacet[]>) =>
56
97
  facets?.find((x) => x.key === 'slug')?.value ?? null
57
98
 
@@ -13,9 +13,12 @@ type StoreFacetRange {
13
13
  """
14
14
  label: String!
15
15
  """
16
- Array with information on each facet value.
16
+ Minimum facet range value.
17
17
  """
18
18
  min: StoreFacetValueRange!
19
+ """
20
+ Maximum facet range value.
21
+ """
19
22
  max: StoreFacetValueRange!
20
23
  }
21
24
 
@@ -37,8 +40,17 @@ type StoreFacetBoolean {
37
40
  values: [StoreFacetValueBoolean!]!
38
41
  }
39
42
 
43
+ """
44
+ Search facet range value information. Used for minimum and maximum range values.
45
+ """
40
46
  type StoreFacetValueRange {
47
+ """
48
+ Search facet range absolute value.
49
+ """
41
50
  absolute: Float!
51
+ """
52
+ Search facet range selected value.
53
+ """
42
54
  selected: Float!
43
55
  }
44
56