@faststore/api 1.12.43 → 1.12.44

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.
@@ -14,7 +14,7 @@ export interface Options {
14
14
  interface FeatureFlags {
15
15
  enableOrderFormSync?: boolean;
16
16
  }
17
- export interface Context {
17
+ export interface Context extends Pick<Options, 'hideUnavailableItems'> {
18
18
  clients: Clients;
19
19
  loaders: Loaders;
20
20
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "1.12.43",
3
+ "version": "1.12.44",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -53,5 +53,5 @@
53
53
  "@envelop/core": "^1 || ^2",
54
54
  "graphql": "^15.6.0"
55
55
  },
56
- "gitHead": "6ac829dd59600d5ea9a02820294310bdecaa4b79"
56
+ "gitHead": "47358f1f317a5fbbf57eaa3ec5d5691095f2264d"
57
57
  }
@@ -42,7 +42,7 @@ interface FeatureFlags {
42
42
  enableOrderFormSync?: boolean
43
43
  }
44
44
 
45
- export interface Context {
45
+ export interface Context extends Pick<Options, 'hideUnavailableItems'> {
46
46
  clients: Clients
47
47
  loaders: Loaders
48
48
  /**
@@ -99,6 +99,7 @@ export const getContextFactory =
99
99
  }
100
100
  ctx.clients = getClients(options, ctx)
101
101
  ctx.loaders = getLoaders(options, ctx)
102
+ ctx.hideUnavailableItems = options.hideUnavailableItems
102
103
 
103
104
  return ctx
104
105
  }
@@ -3,6 +3,7 @@ import type { Resolver } from '..'
3
3
  import type { SearchArgs } from '../clients/search'
4
4
  import type { Facet } from '../clients/search/types/FacetSearchResult'
5
5
  import { ProductSearchResult } from '../clients/search/types/ProductSearchResult'
6
+ import { inStock } from '../utils/productStock'
6
7
 
7
8
  type Root = {
8
9
  searchArgs: Omit<SearchArgs, 'type'>
@@ -53,7 +54,7 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {
53
54
  products: skus,
54
55
  }
55
56
  },
56
- products: async ({ productSearchPromise }) => {
57
+ products: async ({ productSearchPromise }, _, ctx) => {
57
58
  const productSearchResult = await productSearchPromise
58
59
 
59
60
  const skus = productSearchResult.products
@@ -72,10 +73,18 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {
72
73
  endCursor: productSearchResult.recordsFiltered.toString(),
73
74
  totalCount: productSearchResult.recordsFiltered,
74
75
  },
75
- edges: skus.map((sku, index) => ({
76
- node: sku,
77
- cursor: index.toString(),
78
- })),
76
+ edges: skus
77
+ .filter((sku) => {
78
+ if (ctx.hideUnavailableItems) {
79
+ return sku.sellers.some((item) => inStock(item.commertialOffer))
80
+ } else {
81
+ return true
82
+ }
83
+ }) // TODO: remove this filter when the IS returns correctly with hideUnavailableItems
84
+ .map((sku, index) => ({
85
+ node: sku,
86
+ cursor: index.toString(),
87
+ })),
79
88
  }
80
89
  },
81
90
  facets: async ({ searchArgs }, _, ctx) => {