@faststore/api 1.12.6 → 1.12.8

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.
@@ -12,7 +12,7 @@ export interface ProductSearchResult {
12
12
  query: string;
13
13
  operator: 'and' | 'or';
14
14
  fuzzy: string;
15
- correction: Correction;
15
+ correction?: Correction;
16
16
  }
17
17
  interface Correction {
18
18
  misspelled: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "1.12.6",
3
+ "version": "1.12.8",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -46,5 +46,5 @@
46
46
  "peerDependencies": {
47
47
  "graphql": "^15.6.0"
48
48
  },
49
- "gitHead": "74bbbc8c3573be89754ccb50b0d1bc135b332ca9"
49
+ "gitHead": "52dd802b9e028d3860603e47387f250a24f264ce"
50
50
  }
@@ -12,7 +12,7 @@ export interface ProductSearchResult {
12
12
  query: string
13
13
  operator: 'and' | 'or'
14
14
  fuzzy: string
15
- correction: Correction
15
+ correction?: Correction
16
16
  }
17
17
 
18
18
  interface Correction {
@@ -53,6 +53,22 @@ export const Query = {
53
53
 
54
54
  const sku = await skuLoader.load(skuId)
55
55
 
56
+ /**
57
+ * Here be dragons 🦄🦄🦄
58
+ *
59
+ * In some cases, the slug has a valid skuId for a different
60
+ * product. This condition makes sure that the fetched sku
61
+ * is the one we actually asked for
62
+ * */
63
+ if (
64
+ slug && sku.isVariantOf.linkText &&
65
+ !slug.startsWith(sku.isVariantOf.linkText)
66
+ ) {
67
+ throw new Error(
68
+ `Slug was set but the fetched sku does not satisfy the slug condition. slug: ${slug}, linkText: ${sku.isVariantOf.linkText}`,
69
+ )
70
+ }
71
+
56
72
  return sku
57
73
  } catch (err) {
58
74
  if (slug == null) {
@@ -57,7 +57,7 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {
57
57
  sp.sendEvent({
58
58
  type: 'search.query',
59
59
  text: searchArgs.query,
60
- misspelled: products.correction.misspelled,
60
+ misspelled: products.correction?.misspelled ?? false,
61
61
  match: products.recordsFiltered,
62
62
  operator: products.operator,
63
63
  }).catch(console.error)