@faststore/api 1.8.1 → 1.8.4

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/__generated__/schema.d.ts +155 -0
  3. package/dist/api.cjs.development.js +129 -123
  4. package/dist/api.cjs.development.js.map +1 -1
  5. package/dist/api.cjs.production.min.js +1 -1
  6. package/dist/api.cjs.production.min.js.map +1 -1
  7. package/dist/api.esm.js +129 -123
  8. package/dist/api.esm.js.map +1 -1
  9. package/dist/index.d.ts +4 -17
  10. package/dist/platforms/vtex/clients/search/types/ProductSearchResult.d.ts +1 -1
  11. package/dist/platforms/vtex/index.d.ts +4 -17
  12. package/dist/platforms/vtex/resolvers/aggregateOffer.d.ts +2 -5
  13. package/dist/platforms/vtex/resolvers/product.d.ts +2 -6
  14. package/dist/platforms/vtex/utils/enhanceCommercialOffer.d.ts +11 -0
  15. package/dist/platforms/vtex/utils/productStock.d.ts +7 -6
  16. package/package.json +2 -2
  17. package/src/__generated__/schema.ts +155 -0
  18. package/src/platforms/vtex/clients/search/types/ProductSearchResult.ts +1 -1
  19. package/src/platforms/vtex/resolvers/aggregateOffer.ts +15 -13
  20. package/src/platforms/vtex/resolvers/offer.ts +44 -49
  21. package/src/platforms/vtex/resolvers/product.ts +14 -10
  22. package/src/platforms/vtex/utils/enhanceCommercialOffer.ts +24 -0
  23. package/src/platforms/vtex/utils/productStock.ts +22 -25
  24. package/src/typeDefs/aggregateOffer.graphql +18 -3
  25. package/src/typeDefs/aggregateRating.graphql +9 -0
  26. package/src/typeDefs/author.graphql +6 -0
  27. package/src/typeDefs/brand.graphql +6 -0
  28. package/src/typeDefs/breadcrumb.graphql +21 -0
  29. package/src/typeDefs/cart.graphql +24 -0
  30. package/src/typeDefs/collection.graphql +39 -2
  31. package/src/typeDefs/facet.graphql +30 -1
  32. package/src/typeDefs/image.graphql +18 -0
  33. package/src/typeDefs/mutation.graphql +30 -2
  34. package/src/typeDefs/offer.graphql +51 -1
  35. package/src/typeDefs/order.graphql +18 -0
  36. package/src/typeDefs/organization.graphql +12 -0
  37. package/src/typeDefs/pageInfo.graphql +18 -1
  38. package/src/typeDefs/person.graphql +15 -0
  39. package/src/typeDefs/product.graphql +60 -3
  40. package/src/typeDefs/productGroup.graphql +15 -0
  41. package/src/typeDefs/propertyValue.graphql +9 -0
  42. package/src/typeDefs/query.graphql +66 -0
@@ -1,12 +1,9 @@
1
- import type { Item } from '../clients/search/types/ProductSearchResult';
1
+ import type { EnhancedCommercialOffer } from '../utils/enhanceCommercialOffer';
2
2
  import type { StoreProduct } from './product';
3
3
  import type { PromiseType } from '../../../typings';
4
4
  import type { Resolver } from '..';
5
- import type { EnhancedSku } from '../utils/enhanceSku';
6
5
  declare type Root = PromiseType<ReturnType<typeof StoreProduct.offers>>;
7
6
  export declare const StoreAggregateOffer: Record<string, Resolver<Root>> & {
8
- offers: Resolver<Root, any, Array<Item & {
9
- product: EnhancedSku;
10
- }>>;
7
+ offers: Resolver<Root, any, EnhancedCommercialOffer[]>;
11
8
  };
12
9
  export {};
@@ -1,14 +1,10 @@
1
+ import type { EnhancedCommercialOffer } from '../utils/enhanceCommercialOffer';
1
2
  import type { Resolver } from '..';
2
3
  import type { PromiseType } from '../../../typings';
3
4
  import type { Query } from './query';
4
- import type { Item } from '../clients/search/types/ProductSearchResult';
5
- import type { EnhancedSku } from '../utils/enhanceSku';
6
5
  declare type Root = PromiseType<ReturnType<typeof Query.product>>;
7
6
  export declare const StoreProduct: Record<string, Resolver<Root>> & {
8
- offers: Resolver<Root, any, {
9
- items: Item[];
10
- product: EnhancedSku;
11
- }>;
7
+ offers: Resolver<Root, any, EnhancedCommercialOffer[]>;
12
8
  isVariantOf: Resolver<Root, any, Root>;
13
9
  };
14
10
  export {};
@@ -0,0 +1,11 @@
1
+ import type { CommertialOffer, Seller } from '../clients/search/types/ProductSearchResult';
2
+ import type { EnhancedSku } from './enhanceSku';
3
+ export declare type EnhancedCommercialOffer = CommertialOffer & {
4
+ seller: Seller;
5
+ product: EnhancedSku;
6
+ };
7
+ export declare const enhanceCommercialOffer: ({ offer, seller, product, }: {
8
+ offer: CommertialOffer;
9
+ seller: Seller;
10
+ product: EnhancedSku;
11
+ }) => EnhancedCommercialOffer;
@@ -1,6 +1,7 @@
1
- import type { Item, Seller, CommertialOffer } from '../clients/search/types/ProductSearchResult';
2
- export declare const inStock: (item: Item) => Seller | undefined;
3
- export declare const getFirstSeller: (sellers: Seller[]) => Seller | undefined;
4
- export declare const getItemPriceByKey: (item: Item, key: keyof CommertialOffer) => number;
5
- export declare const sortOfferByPrice: (items: Item[]) => Item[];
6
- export declare const inStockOrderFormItem: (availability: string) => boolean;
1
+ import type { CommertialOffer } from '../clients/search/types/ProductSearchResult';
2
+ export declare const inStock: (offer: Pick<CommertialOffer, 'AvailableQuantity'>) => boolean;
3
+ export declare const price: (offer: Pick<CommertialOffer, 'spotPrice'>) => number;
4
+ export declare const sellingPrice: (offer: CommertialOffer) => number;
5
+ export declare const availability: (available: boolean) => "https://schema.org/InStock" | "https://schema.org/OutOfStock";
6
+ export declare const bestOfferFirst: (a: Pick<CommertialOffer, 'AvailableQuantity' | 'spotPrice'>, b: Pick<CommertialOffer, 'AvailableQuantity' | 'spotPrice'>) => number;
7
+ export declare const inStockOrderFormItem: (itemAvailability: string) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "1.8.1",
3
+ "version": "1.8.4",
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": "1fd480adb0fa578377f67e65af9a12c717d0671e"
48
+ "gitHead": "9438cf7d4269b9d20180c31a3121d4c1e5d63089"
49
49
  }
@@ -11,52 +11,79 @@ export type Scalars = {
11
11
  Float: number;
12
12
  };
13
13
 
14
+ /** Shopping cart identification input. */
14
15
  export type IStoreCart = {
16
+ /** Order information, including `orderNumber` and `acceptedOffer`. */
15
17
  order: IStoreOrder;
16
18
  };
17
19
 
20
+ /** Image input. */
18
21
  export type IStoreImage = {
22
+ /** Alias for the input image. */
19
23
  alternateName: Scalars['String'];
24
+ /** Image input URL. */
20
25
  url: Scalars['String'];
21
26
  };
22
27
 
28
+ /** Offer input. */
23
29
  export type IStoreOffer = {
30
+ /** Information on the item being offered. */
24
31
  itemOffered: IStoreProduct;
32
+ /** This is displayed as the "from" price in the context of promotions' price comparison. This may change before it reaches the shelf. */
25
33
  listPrice: Scalars['Float'];
34
+ /** Also known as spot price. */
26
35
  price: Scalars['Float'];
36
+ /** Number of items offered. */
27
37
  quantity: Scalars['Int'];
38
+ /** Seller responsible for the offer. */
28
39
  seller: IStoreOrganization;
29
40
  };
30
41
 
42
+ /** Offer input. */
31
43
  export type IStoreOrder = {
44
+ /** Array with information on each accepted offer. */
32
45
  acceptedOffer: Array<IStoreOffer>;
46
+ /** Order shopping cart ID, also known as `orderFormId`. */
33
47
  orderNumber: Scalars['String'];
34
48
  };
35
49
 
50
+ /** Organization input. */
36
51
  export type IStoreOrganization = {
52
+ /** Organization ID. */
37
53
  identifier: Scalars['String'];
38
54
  };
39
55
 
56
+ /** Product input. */
40
57
  export type IStoreProduct = {
58
+ /** Array of product images. */
41
59
  image: Array<IStoreImage>;
60
+ /** Product name. */
42
61
  name: Scalars['String'];
62
+ /** Stock Keeping Unit ID. */
43
63
  sku: Scalars['String'];
44
64
  };
45
65
 
66
+ /** Selected facet input. */
46
67
  export type IStoreSelectedFacet = {
47
68
  key: Scalars['String'];
48
69
  value: Scalars['String'];
49
70
  };
50
71
 
72
+ /** Session input. */
51
73
  export type IStoreSession = {
74
+ /** Session input channel. */
52
75
  channel?: Maybe<Scalars['String']>;
76
+ /** Session input country. */
53
77
  country?: Maybe<Scalars['String']>;
78
+ /** Session input postal code. */
54
79
  postalCode?: Maybe<Scalars['String']>;
55
80
  };
56
81
 
57
82
  export type Mutation = {
58
83
  __typename?: 'Mutation';
84
+ /** Update session information. */
59
85
  updateSession: StoreSession;
86
+ /** Returns the order if anything has changed in it, or `null` if the order is valid. */
60
87
  validateCart?: Maybe<StoreCart>;
61
88
  };
62
89
 
@@ -111,82 +138,123 @@ export type QuerySearchArgs = {
111
138
  term?: Maybe<Scalars['String']>;
112
139
  };
113
140
 
141
+ /** Aggregate offer information, for a given SKU that is available to be fulfilled by multiple sellers. */
114
142
  export type StoreAggregateOffer = {
115
143
  __typename?: 'StoreAggregateOffer';
144
+ /** Highest price among all sellers. */
116
145
  highPrice: Scalars['Float'];
146
+ /** Lowest price among all sellers. */
117
147
  lowPrice: Scalars['Float'];
148
+ /** Number of sellers selling this SKU. */
118
149
  offerCount: Scalars['Int'];
150
+ /** Array with information on each available offer. */
119
151
  offers: Array<StoreOffer>;
152
+ /** ISO code of the currency used for the offer prices. */
120
153
  priceCurrency: Scalars['String'];
121
154
  };
122
155
 
156
+ /** Average rating, based on multiple ratings or reviews. */
123
157
  export type StoreAggregateRating = {
124
158
  __typename?: 'StoreAggregateRating';
159
+ /** Value of the aggregate rating. */
125
160
  ratingValue: Scalars['Float'];
161
+ /** Total number of ratings. */
126
162
  reviewCount: Scalars['Int'];
127
163
  };
128
164
 
165
+ /** information about the author of a product review or rating. */
129
166
  export type StoreAuthor = {
130
167
  __typename?: 'StoreAuthor';
168
+ /** Author name. */
131
169
  name: Scalars['String'];
132
170
  };
133
171
 
172
+ /** Brand of a given product. */
134
173
  export type StoreBrand = {
135
174
  __typename?: 'StoreBrand';
175
+ /** Brand name. */
136
176
  name: Scalars['String'];
137
177
  };
138
178
 
179
+ /** List of items consisting of chain linked web pages, ending with the current page. */
139
180
  export type StoreBreadcrumbList = {
140
181
  __typename?: 'StoreBreadcrumbList';
182
+ /** Array with breadcrumb elements. */
141
183
  itemListElement: Array<StoreListItem>;
184
+ /** Number of breadcrumbs in the list. */
142
185
  numberOfItems: Scalars['Int'];
143
186
  };
144
187
 
188
+ /** Shopping cart information. */
145
189
  export type StoreCart = {
146
190
  __typename?: 'StoreCart';
191
+ /** List of shopping cart messages. */
147
192
  messages: Array<StoreCartMessage>;
193
+ /** Order information, including `orderNumber` and `acceptedOffer`. */
148
194
  order: StoreOrder;
149
195
  };
150
196
 
197
+ /** Shopping cart message. */
151
198
  export type StoreCartMessage = {
152
199
  __typename?: 'StoreCartMessage';
200
+ /** Shopping cart message status, which can be `INFO`, `WARNING` OR `ERROR`. */
153
201
  status: StoreStatus;
202
+ /** Shopping cart message text. */
154
203
  text: Scalars['String'];
155
204
  };
156
205
 
206
+ /** Product collection information. */
157
207
  export type StoreCollection = {
158
208
  __typename?: 'StoreCollection';
209
+ /** List of items consisting of chain linked web pages, ending with the current page. */
159
210
  breadcrumbList: StoreBreadcrumbList;
211
+ /** Collection ID. */
160
212
  id: Scalars['ID'];
213
+ /** Collection meta information. Used for search. */
161
214
  meta: StoreCollectionMeta;
215
+ /** Meta tag data. */
162
216
  seo: StoreSeo;
217
+ /** Corresponding collection URL slug, with which to retrieve this entity. */
163
218
  slug: Scalars['String'];
219
+ /** Collection type. */
164
220
  type: StoreCollectionType;
165
221
  };
166
222
 
223
+ /** Collection connection pagination information. */
167
224
  export type StoreCollectionConnection = {
168
225
  __typename?: 'StoreCollectionConnection';
226
+ /** Array with collection connection page edges. */
169
227
  edges: Array<StoreCollectionEdge>;
228
+ /** Collection connection page information. */
170
229
  pageInfo: StorePageInfo;
171
230
  };
172
231
 
232
+ /** Collection pagination edge. */
173
233
  export type StoreCollectionEdge = {
174
234
  __typename?: 'StoreCollectionEdge';
235
+ /** Collection pagination cursor. */
175
236
  cursor: Scalars['String'];
237
+ /** Collection pagination node. */
176
238
  node: StoreCollection;
177
239
  };
178
240
 
241
+ /** Product collection facet, used for search. */
179
242
  export type StoreCollectionFacet = {
180
243
  __typename?: 'StoreCollectionFacet';
244
+ /** Facet key. */
181
245
  key: Scalars['String'];
246
+ /** Facet value. */
182
247
  value: Scalars['String'];
183
248
  };
184
249
 
250
+ /** Collection meta information. Used for search. */
185
251
  export type StoreCollectionMeta = {
186
252
  __typename?: 'StoreCollectionMeta';
253
+ /** List of selected collection facets. */
187
254
  selectedFacets: Array<StoreCollectionFacet>;
188
255
  };
189
256
 
257
+ /** Product collection type. Possible values are `Department`, `Category`, `Brand` or `Cluster`. */
190
258
  export const enum StoreCollectionType {
191
259
  Brand = 'Brand',
192
260
  Category = 'Category',
@@ -194,124 +262,199 @@ export const enum StoreCollectionType {
194
262
  Department = 'Department'
195
263
  };
196
264
 
265
+ /** Search facet information. */
197
266
  export type StoreFacet = {
198
267
  __typename?: 'StoreFacet';
268
+ /** Facet key. */
199
269
  key: Scalars['String'];
270
+ /** Facet label. */
200
271
  label: Scalars['String'];
272
+ /** Facet type. Possible values are `BOOLEAN` and `RANGE`. */
201
273
  type: StoreFacetType;
274
+ /** Array with information on each facet value. */
202
275
  values: Array<StoreFacetValue>;
203
276
  };
204
277
 
278
+ /** Search facet type. */
205
279
  export const enum StoreFacetType {
206
280
  Boolean = 'BOOLEAN',
207
281
  Range = 'RANGE'
208
282
  };
209
283
 
284
+ /** Information of a specific facet value. */
210
285
  export type StoreFacetValue = {
211
286
  __typename?: 'StoreFacetValue';
287
+ /** Facet value label. */
212
288
  label: Scalars['String'];
289
+ /** Number of items with this facet. */
213
290
  quantity: Scalars['Int'];
291
+ /** Indicates whether facet is selected. */
214
292
  selected: Scalars['Boolean'];
293
+ /** Facet value. */
215
294
  value: Scalars['String'];
216
295
  };
217
296
 
297
+ /** Image. */
218
298
  export type StoreImage = {
219
299
  __typename?: 'StoreImage';
300
+ /** Alias for the image. */
220
301
  alternateName: Scalars['String'];
302
+ /** Image URL. */
221
303
  url: Scalars['String'];
222
304
  };
223
305
 
306
+ /** Item of a list. */
224
307
  export type StoreListItem = {
225
308
  __typename?: 'StoreListItem';
309
+ /** List item value. */
226
310
  item: Scalars['String'];
311
+ /** Name of the list item. */
227
312
  name: Scalars['String'];
313
+ /** Position of the item in the list. */
228
314
  position: Scalars['Int'];
229
315
  };
230
316
 
317
+ /** Offer information. */
231
318
  export type StoreOffer = {
232
319
  __typename?: 'StoreOffer';
320
+ /** Offer item availability. */
233
321
  availability: Scalars['String'];
322
+ /** Offer item condition. */
234
323
  itemCondition: Scalars['String'];
324
+ /** Information on the item being offered. */
235
325
  itemOffered: StoreProduct;
326
+ /** This is displayed as the "from" price in the context of promotions' price comparison. This may change before it reaches the shelf. */
236
327
  listPrice: Scalars['Float'];
328
+ /** Also known as spot price. */
237
329
  price: Scalars['Float'];
330
+ /** ISO code of the currency used for the offer prices. */
238
331
  priceCurrency: Scalars['String'];
332
+ /** Next date in which price is scheduled to change. If there is no scheduled change, this will be set a year in the future from current time. */
239
333
  priceValidUntil: Scalars['String'];
334
+ /** Number of items offered. */
240
335
  quantity: Scalars['Int'];
336
+ /** Seller responsible for the offer. */
241
337
  seller: StoreOrganization;
338
+ /** Computed price before applying coupons, taxes or benefits. This may change before it reaches the shelf. */
242
339
  sellingPrice: Scalars['Float'];
243
340
  };
244
341
 
342
+ /** Information of a specific order. */
245
343
  export type StoreOrder = {
246
344
  __typename?: 'StoreOrder';
345
+ /** Array with information on each accepted offer. */
247
346
  acceptedOffer: Array<StoreOffer>;
347
+ /** Order shopping cart ID, also known as `orderFormId`. */
248
348
  orderNumber: Scalars['String'];
249
349
  };
250
350
 
351
+ /** Organization. */
251
352
  export type StoreOrganization = {
252
353
  __typename?: 'StoreOrganization';
354
+ /** Organization ID. */
253
355
  identifier: Scalars['String'];
254
356
  };
255
357
 
358
+ /** Page information. */
256
359
  export type StorePageInfo = {
257
360
  __typename?: 'StorePageInfo';
361
+ /** Page cursor end. */
258
362
  endCursor: Scalars['String'];
363
+ /** Indicates whether next page exists. */
259
364
  hasNextPage: Scalars['Boolean'];
365
+ /** Indicates whether previous page exists. */
260
366
  hasPreviousPage: Scalars['Boolean'];
367
+ /** Page cursor start. */
261
368
  startCursor: Scalars['String'];
369
+ /** Total number of items (products or collections), not pages. */
262
370
  totalCount: Scalars['Int'];
263
371
  };
264
372
 
373
+ /** Client profile data. */
265
374
  export type StorePerson = {
266
375
  __typename?: 'StorePerson';
376
+ /** Client email. */
267
377
  email: Scalars['String'];
378
+ /** Client last name. */
268
379
  familyName: Scalars['String'];
380
+ /** Client first name. */
269
381
  givenName: Scalars['String'];
382
+ /** Client ID. */
270
383
  id: Scalars['String'];
271
384
  };
272
385
 
386
+ /** Product information. */
273
387
  export type StoreProduct = {
274
388
  __typename?: 'StoreProduct';
389
+ /** Array of additional properties. */
275
390
  additionalProperty: Array<StorePropertyValue>;
391
+ /** Aggregate ratings data. */
276
392
  aggregateRating: StoreAggregateRating;
393
+ /** Product brand. */
277
394
  brand: StoreBrand;
395
+ /** List of items consisting of chain linked web pages, ending with the current page. */
278
396
  breadcrumbList: StoreBreadcrumbList;
397
+ /** Product description. */
279
398
  description: Scalars['String'];
399
+ /** Global Trade Item Number. */
280
400
  gtin: Scalars['String'];
401
+ /** Array of images. */
281
402
  image: Array<StoreImage>;
403
+ /** Indicates product group related to this product. */
282
404
  isVariantOf: StoreProductGroup;
405
+ /** Product name. */
283
406
  name: Scalars['String'];
407
+ /** Aggregate offer information. */
284
408
  offers: StoreAggregateOffer;
409
+ /** Product ID. */
285
410
  productID: Scalars['String'];
411
+ /** Array with review information. */
286
412
  review: Array<StoreReview>;
413
+ /** Meta tag data. */
287
414
  seo: StoreSeo;
415
+ /** Stock Keeping Unit ID. */
288
416
  sku: Scalars['String'];
417
+ /** Corresponding collection URL slug, with which to retrieve this entity. */
289
418
  slug: Scalars['String'];
290
419
  };
291
420
 
421
+ /** Product connection pagination information. */
292
422
  export type StoreProductConnection = {
293
423
  __typename?: 'StoreProductConnection';
424
+ /** Array with product connection page edges. */
294
425
  edges: Array<StoreProductEdge>;
426
+ /** Product connection page information. */
295
427
  pageInfo: StorePageInfo;
296
428
  };
297
429
 
430
+ /** Product pagination edge. */
298
431
  export type StoreProductEdge = {
299
432
  __typename?: 'StoreProductEdge';
433
+ /** Product pagination cursor. */
300
434
  cursor: Scalars['String'];
435
+ /** Product pagination node. */
301
436
  node: StoreProduct;
302
437
  };
303
438
 
439
+ /** Product group information. */
304
440
  export type StoreProductGroup = {
305
441
  __typename?: 'StoreProductGroup';
442
+ /** Array of additional properties. */
306
443
  additionalProperty: Array<StorePropertyValue>;
444
+ /** Array of variants related to product group. */
307
445
  hasVariant: Array<StoreProduct>;
446
+ /** Product group name. */
308
447
  name: Scalars['String'];
448
+ /** Product group ID. */
309
449
  productGroupID: Scalars['String'];
310
450
  };
311
451
 
452
+ /** Properties that can be associated with products and products groups. */
312
453
  export type StorePropertyValue = {
313
454
  __typename?: 'StorePropertyValue';
455
+ /** Property name. */
314
456
  name: Scalars['String'];
457
+ /** Property value. */
315
458
  value: Scalars['String'];
316
459
  };
317
460
 
@@ -327,10 +470,14 @@ export type StoreReviewRating = {
327
470
  ratingValue: Scalars['Float'];
328
471
  };
329
472
 
473
+ /** Search result. */
330
474
  export type StoreSearchResult = {
331
475
  __typename?: 'StoreSearchResult';
476
+ /** Array of search result facets. */
332
477
  facets: Array<StoreFacet>;
478
+ /** Search result products. */
333
479
  products: StoreProductConnection;
480
+ /** Search result suggestions. */
334
481
  suggestions: StoreSuggestions;
335
482
  };
336
483
 
@@ -342,13 +489,18 @@ export type StoreSeo = {
342
489
  titleTemplate: Scalars['String'];
343
490
  };
344
491
 
492
+ /** Session information. */
345
493
  export type StoreSession = {
346
494
  __typename?: 'StoreSession';
495
+ /** Session channel. */
347
496
  channel?: Maybe<Scalars['String']>;
497
+ /** Session country. */
348
498
  country?: Maybe<Scalars['String']>;
499
+ /** Session postal code. */
349
500
  postalCode?: Maybe<Scalars['String']>;
350
501
  };
351
502
 
503
+ /** Product sorting options used in search. */
352
504
  export const enum StoreSort {
353
505
  DiscountDesc = 'discount_desc',
354
506
  NameAsc = 'name_asc',
@@ -366,8 +518,11 @@ export const enum StoreStatus {
366
518
  Warning = 'WARNING'
367
519
  };
368
520
 
521
+ /** Suggestions information. */
369
522
  export type StoreSuggestions = {
370
523
  __typename?: 'StoreSuggestions';
524
+ /** Array with suggestion products' information. */
371
525
  products?: Maybe<Array<StoreProduct>>;
526
+ /** Array with suggestion terms. */
372
527
  terms?: Maybe<Array<Scalars['String']>>;
373
528
  };
@@ -154,7 +154,7 @@ export interface CommertialOffer {
154
154
  ItemMetadataAttachment: any[]
155
155
  Price: number
156
156
  ListPrice: number
157
- spotPrice?: number
157
+ spotPrice: number
158
158
  PriceWithoutDiscount: number
159
159
  RewardValue: number
160
160
  PriceValidUntil: string
@@ -1,23 +1,25 @@
1
- import type { Item } from '../clients/search/types/ProductSearchResult'
1
+ import { inStock } from '../utils/productStock'
2
+ import type { EnhancedCommercialOffer } from '../utils/enhanceCommercialOffer'
2
3
  import type { StoreProduct } from './product'
3
4
  import type { PromiseType } from '../../../typings'
4
5
  import type { Resolver } from '..'
5
- import type { EnhancedSku } from '../utils/enhanceSku'
6
6
 
7
7
  type Root = PromiseType<ReturnType<typeof StoreProduct.offers>>
8
8
 
9
9
  export const StoreAggregateOffer: Record<string, Resolver<Root>> & {
10
- offers: Resolver<Root, any, Array<Item & { product: EnhancedSku }>>
10
+ offers: Resolver<Root, any, EnhancedCommercialOffer[]>
11
11
  } = {
12
- highPrice: ({ product }) =>
13
- product.isVariantOf.priceRange.sellingPrice.highPrice ?? 0,
14
- lowPrice: (root) =>
15
- root.product.isVariantOf.priceRange.sellingPrice.lowPrice ?? 0,
16
- offerCount: ({ items }) => items.length,
12
+ highPrice: (offers) => {
13
+ const availableOffers = offers.filter(inStock)
14
+
15
+ return availableOffers[availableOffers.length - 1]?.Price ?? 0
16
+ },
17
+ lowPrice: (offers) => {
18
+ const availableOffers = offers.filter(inStock)
19
+
20
+ return availableOffers[0]?.Price ?? 0
21
+ },
22
+ offerCount: (offers) => offers.length,
17
23
  priceCurrency: () => '',
18
- offers: ({ items, product }) =>
19
- items.map((item) => ({
20
- ...item,
21
- product,
22
- })),
24
+ offers: (offers) => offers,
23
25
  }