@faststore/api 1.8.2 → 1.8.5

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,13 +1,13 @@
1
- import type { Resolver } from '..'
2
- import type { StoreAggregateOffer } from './aggregateOffer'
3
1
  import {
4
- getFirstSeller,
2
+ availability,
5
3
  inStock,
6
4
  inStockOrderFormItem,
7
- getItemPriceByKey,
5
+ price,
6
+ sellingPrice,
8
7
  } from '../utils/productStock'
8
+ import type { Resolver } from '..'
9
+ import type { StoreAggregateOffer } from './aggregateOffer'
9
10
  import type { ArrayElementType } from '../../../typings'
10
- import type { Item } from '../clients/search/types/ProductSearchResult'
11
11
  import type { EnhancedSku } from '../utils/enhanceSku'
12
12
  import type { OrderFormItem } from '../clients/commerce/types/OrderForm'
13
13
 
@@ -17,98 +17,93 @@ type SearchProduct = ArrayElementType<
17
17
  >
18
18
  type Root = SearchProduct | OrderFormProduct
19
19
 
20
- const isSearchItem = (item: any): item is Item => 'sellers' in item
21
- const isOrderFormItem = (item: any): item is OrderFormProduct =>
22
- 'skuName' in item
20
+ const isSearchItem = (item: Root): item is SearchProduct =>
21
+ 'Price' in item && 'seller' in item && 'product' in item
23
22
 
24
- const getAvailability = (available: boolean) =>
25
- available ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock'
23
+ const isOrderFormItem = (item: Root): item is OrderFormProduct =>
24
+ 'skuName' in item
26
25
 
27
26
  export const StoreOffer: Record<string, Resolver<Root>> = {
28
27
  priceCurrency: () => '',
29
- priceValidUntil: (item) => {
30
- if (isSearchItem(item)) {
31
- return getFirstSeller(item.sellers)?.commertialOffer.PriceValidUntil ?? ''
28
+ priceValidUntil: (root) => {
29
+ if (isSearchItem(root)) {
30
+ return root.PriceValidUntil ?? ''
32
31
  }
33
32
 
34
- if (isOrderFormItem(item)) {
35
- return item.priceValidUntil ?? ''
33
+ if (isOrderFormItem(root)) {
34
+ return root.priceValidUntil ?? ''
36
35
  }
37
36
 
38
37
  return null
39
38
  },
40
39
  itemCondition: () => 'https://schema.org/NewCondition',
41
- availability: async (item) => {
42
- if (isSearchItem(item)) {
43
- return getAvailability(!!inStock(item))
40
+ availability: async (root) => {
41
+ if (isSearchItem(root)) {
42
+ return availability(inStock(root))
44
43
  }
45
44
 
46
- if (isOrderFormItem(item)) {
47
- return getAvailability(inStockOrderFormItem(item.availability))
45
+ if (isOrderFormItem(root)) {
46
+ return availability(inStockOrderFormItem(root.availability))
48
47
  }
49
48
 
50
49
  return null
51
50
  },
52
- seller: (item) => {
53
- if (isSearchItem(item)) {
51
+ seller: (root) => {
52
+ if (isSearchItem(root)) {
54
53
  return {
55
- identifier: getFirstSeller(item.sellers)?.sellerId ?? '',
54
+ identifier: root.seller.sellerId ?? '',
56
55
  }
57
56
  }
58
57
 
59
- if (isOrderFormItem(item)) {
58
+ if (isOrderFormItem(root)) {
60
59
  return {
61
- identifier: item.seller,
60
+ identifier: root.seller,
62
61
  }
63
62
  }
64
63
 
65
64
  return null
66
65
  },
67
- price: (item) => {
68
- if (isSearchItem(item)) {
69
- return getItemPriceByKey(item, 'spotPrice')
66
+ price: (root) => {
67
+ if (isSearchItem(root)) {
68
+ return price(root)
70
69
  }
71
70
 
72
- if (isOrderFormItem(item)) {
73
- return item.price / 1e2
71
+ if (isOrderFormItem(root)) {
72
+ return root.price / 1e2
74
73
  }
75
74
 
76
75
  return null
77
76
  },
78
- sellingPrice: (item) => {
79
- if (isSearchItem(item)) {
80
- return getItemPriceByKey(item, 'Price')
77
+ sellingPrice: (root) => {
78
+ if (isSearchItem(root)) {
79
+ return sellingPrice(root)
81
80
  }
82
81
 
83
- if (isOrderFormItem(item)) {
84
- return item.sellingPrice / 1e2
82
+ if (isOrderFormItem(root)) {
83
+ return root.sellingPrice / 1e2
85
84
  }
86
85
 
87
86
  return null
88
87
  },
89
- listPrice: (item) => {
90
- if (isSearchItem(item)) {
91
- return getItemPriceByKey(item, 'ListPrice')
88
+ listPrice: (root) => {
89
+ if (isSearchItem(root)) {
90
+ return root.ListPrice
92
91
  }
93
92
 
94
- if (isOrderFormItem(item)) {
95
- return item.listPrice / 1e2
93
+ if (isOrderFormItem(root)) {
94
+ return root.listPrice / 1e2
96
95
  }
97
96
 
98
97
  return null
99
98
  },
100
99
  itemOffered: ({ product }) => product,
101
- quantity: (item) => {
102
- if (isSearchItem(item)) {
103
- return item.sellers.reduce(
104
- (quantity, seller) =>
105
- quantity + seller.commertialOffer.AvailableQuantity,
106
- 0
107
- )
100
+ quantity: (root) => {
101
+ if (isSearchItem(root)) {
102
+ return root.AvailableQuantity ?? 0
108
103
  }
109
104
 
110
- if (isOrderFormItem(item)) {
111
- return item.quantity
105
+ if (isOrderFormItem(root)) {
106
+ return root.quantity
112
107
  }
113
108
 
114
109
  return null
@@ -1,9 +1,9 @@
1
+ import { enhanceCommercialOffer } from '../utils/enhanceCommercialOffer'
2
+ import { bestOfferFirst } from '../utils/productStock'
3
+ import type { EnhancedCommercialOffer } from '../utils/enhanceCommercialOffer'
1
4
  import type { Resolver } from '..'
2
- import { sortOfferByPrice } from '../utils/productStock'
3
5
  import type { PromiseType } from '../../../typings'
4
6
  import type { Query } from './query'
5
- import type { Item } from '../clients/search/types/ProductSearchResult'
6
- import type { EnhancedSku } from '../utils/enhanceSku'
7
7
 
8
8
  type Root = PromiseType<ReturnType<typeof Query.product>>
9
9
 
@@ -19,7 +19,7 @@ const nonEmptyArray = <T>(array: T[] | null | undefined) =>
19
19
  Array.isArray(array) && array.length > 0 ? array : null
20
20
 
21
21
  export const StoreProduct: Record<string, Resolver<Root>> & {
22
- offers: Resolver<Root, any, { items: Item[]; product: EnhancedSku }>
22
+ offers: Resolver<Root, any, EnhancedCommercialOffer[]>
23
23
  isVariantOf: Resolver<Root, any, Root>
24
24
  } = {
25
25
  productID: ({ itemId }) => itemId,
@@ -66,12 +66,16 @@ export const StoreProduct: Record<string, Resolver<Root>> & {
66
66
  gtin: ({ referenceId }) => referenceId[0]?.Value ?? '',
67
67
  review: () => [],
68
68
  aggregateRating: () => ({}),
69
- offers: (product): { items: Item[]; product: Root } => {
70
- return {
71
- items: sortOfferByPrice(product.isVariantOf.items),
72
- product,
73
- }
74
- },
69
+ offers: (root) =>
70
+ root.sellers
71
+ .flatMap((seller) =>
72
+ enhanceCommercialOffer({
73
+ offer: seller.commertialOffer,
74
+ seller,
75
+ product: root,
76
+ })
77
+ )
78
+ .sort(bestOfferFirst),
75
79
  isVariantOf: (root) => root,
76
80
  additionalProperty: ({ variations = [] }) => {
77
81
  return variations.flatMap(({ name, values }) =>
@@ -0,0 +1,24 @@
1
+ import type {
2
+ CommertialOffer,
3
+ Seller,
4
+ } from '../clients/search/types/ProductSearchResult'
5
+ import type { EnhancedSku } from './enhanceSku'
6
+
7
+ export type EnhancedCommercialOffer = CommertialOffer & {
8
+ seller: Seller
9
+ product: EnhancedSku
10
+ }
11
+
12
+ export const enhanceCommercialOffer = ({
13
+ offer,
14
+ seller,
15
+ product,
16
+ }: {
17
+ offer: CommertialOffer
18
+ seller: Seller
19
+ product: EnhancedSku
20
+ }): EnhancedCommercialOffer => ({
21
+ ...offer,
22
+ product,
23
+ seller,
24
+ })
@@ -1,33 +1,30 @@
1
- import type {
2
- Item,
3
- Seller,
4
- CommertialOffer,
5
- } from '../clients/search/types/ProductSearchResult'
1
+ import type { CommertialOffer } from '../clients/search/types/ProductSearchResult'
6
2
 
7
- export const inStock = (item: Item) =>
8
- item.sellers.find((seller) => seller.commertialOffer.AvailableQuantity > 0)
3
+ export const inStock = (offer: Pick<CommertialOffer, 'AvailableQuantity'>) =>
4
+ offer.AvailableQuantity > 0
9
5
 
10
- export const getFirstSeller = (sellers: Seller[]): Seller | undefined =>
11
- sellers[0]
6
+ export const price = (offer: Pick<CommertialOffer, 'spotPrice'>) =>
7
+ offer.spotPrice ?? 0
8
+ export const sellingPrice = (offer: CommertialOffer) => offer.Price ?? 0
12
9
 
13
- export const getItemPriceByKey = (
14
- item: Item,
15
- key: keyof CommertialOffer
16
- ): number => getFirstSeller(item.sellers)?.commertialOffer[key] ?? 0
10
+ export const availability = (available: boolean) =>
11
+ available ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock'
17
12
 
18
13
  // Smallest Available Selling Price First
19
- export const sortOfferByPrice = (items: Item[]): Item[] =>
20
- items.sort((a, b) => {
21
- if (inStock(a) && !inStock(b)) {
22
- return -1
23
- }
14
+ export const bestOfferFirst = (
15
+ a: Pick<CommertialOffer, 'AvailableQuantity' | 'spotPrice'>,
16
+ b: Pick<CommertialOffer, 'AvailableQuantity' | 'spotPrice'>
17
+ ) => {
18
+ if (inStock(a) && !inStock(b)) {
19
+ return -1
20
+ }
24
21
 
25
- if (!inStock(a) && inStock(b)) {
26
- return 1
27
- }
22
+ if (!inStock(a) && inStock(b)) {
23
+ return 1
24
+ }
28
25
 
29
- return getItemPriceByKey(a, 'Price') - getItemPriceByKey(b, 'Price')
30
- })
26
+ return price(a) - price(b)
27
+ }
31
28
 
32
- export const inStockOrderFormItem = (availability: string) =>
33
- availability === 'available'
29
+ export const inStockOrderFormItem = (itemAvailability: string) =>
30
+ itemAvailability === 'available'
@@ -1,10 +1,25 @@
1
+ """
2
+ Aggregate offer information, for a given SKU that is available to be fulfilled by multiple sellers.
3
+ """
1
4
  type StoreAggregateOffer {
2
- # Highest spot price amongst all sellers
5
+ """
6
+ Highest price among all sellers.
7
+ """
3
8
  highPrice: Float!
4
- # Lowest spot price amongst all sellers
9
+ """
10
+ Lowest price among all sellers.
11
+ """
5
12
  lowPrice: Float!
6
- # Number of sellers selling this sku
13
+ """
14
+ Number of sellers selling this SKU.
15
+ """
7
16
  offerCount: Int!
17
+ """
18
+ ISO code of the currency used for the offer prices.
19
+ """
8
20
  priceCurrency: String!
21
+ """
22
+ Array with information on each available offer.
23
+ """
9
24
  offers: [StoreOffer!]!
10
25
  }
@@ -1,4 +1,13 @@
1
+ """
2
+ Average rating, based on multiple ratings or reviews.
3
+ """
1
4
  type StoreAggregateRating {
5
+ """
6
+ Value of the aggregate rating.
7
+ """
2
8
  ratingValue: Float!
9
+ """
10
+ Total number of ratings.
11
+ """
3
12
  reviewCount: Int!
4
13
  }
@@ -1,3 +1,9 @@
1
+ """
2
+ information about the author of a product review or rating.
3
+ """
1
4
  type StoreAuthor {
5
+ """
6
+ Author name.
7
+ """
2
8
  name: String!
3
9
  }
@@ -1,3 +1,9 @@
1
+ """
2
+ Brand of a given product.
3
+ """
1
4
  type StoreBrand {
5
+ """
6
+ Brand name.
7
+ """
2
8
  name: String!
3
9
  }
@@ -1,10 +1,31 @@
1
+ """
2
+ Item of a list.
3
+ """
1
4
  type StoreListItem {
5
+ """
6
+ List item value.
7
+ """
2
8
  item: String!
9
+ """
10
+ Name of the list item.
11
+ """
3
12
  name: String!
13
+ """
14
+ Position of the item in the list.
15
+ """
4
16
  position: Int!
5
17
  }
6
18
 
19
+ """
20
+ List of items consisting of chain linked web pages, ending with the current page.
21
+ """
7
22
  type StoreBreadcrumbList {
23
+ """
24
+ Array with breadcrumb elements.
25
+ """
8
26
  itemListElement: [StoreListItem!]!
27
+ """
28
+ Number of breadcrumbs in the list.
29
+ """
9
30
  numberOfItems: Int!
10
31
  }
@@ -1,13 +1,37 @@
1
+ """
2
+ Shopping cart message.
3
+ """
1
4
  type StoreCartMessage {
5
+ """
6
+ Shopping cart message text.
7
+ """
2
8
  text: String!
9
+ """
10
+ Shopping cart message status, which can be `INFO`, `WARNING` OR `ERROR`.
11
+ """
3
12
  status: StoreStatus!
4
13
  }
5
14
 
15
+ """
16
+ Shopping cart information.
17
+ """
6
18
  type StoreCart {
19
+ """
20
+ Order information, including `orderNumber` and `acceptedOffer`.
21
+ """
7
22
  order: StoreOrder!
23
+ """
24
+ List of shopping cart messages.
25
+ """
8
26
  messages: [StoreCartMessage!]!
9
27
  }
10
28
 
29
+ """
30
+ Shopping cart identification input.
31
+ """
11
32
  input IStoreCart {
33
+ """
34
+ Order information, including `orderNumber` and `acceptedOffer`.
35
+ """
12
36
  order: IStoreOrder!
13
37
  }
@@ -1,3 +1,6 @@
1
+ """
2
+ Product collection type. Possible values are `Department`, `Category`, `Brand` or `Cluster`.
3
+ """
1
4
  enum StoreCollectionType {
2
5
  Department
3
6
  Category
@@ -5,22 +8,56 @@ enum StoreCollectionType {
5
8
  Cluster
6
9
  }
7
10
 
11
+ """
12
+ Product collection facet, used for search.
13
+ """
8
14
  type StoreCollectionFacet {
15
+ """
16
+ Facet key.
17
+ """
9
18
  key: String!
19
+ """
20
+ Facet value.
21
+ """
10
22
  value: String!
11
23
  }
12
24
 
25
+ """
26
+ Collection meta information. Used for search.
27
+ """
13
28
  type StoreCollectionMeta {
29
+ """
30
+ List of selected collection facets.
31
+ """
14
32
  selectedFacets: [StoreCollectionFacet!]!
15
33
  }
16
34
 
35
+ """
36
+ Product collection information.
37
+ """
17
38
  type StoreCollection {
18
- # Meta tag data
39
+ """
40
+ Meta tag data.
41
+ """
19
42
  seo: StoreSeo!
20
- # location for structured data
43
+ """
44
+ List of items consisting of chain linked web pages, ending with the current page.
45
+ """
21
46
  breadcrumbList: StoreBreadcrumbList!
47
+ """
48
+ Collection meta information. Used for search.
49
+ """
22
50
  meta: StoreCollectionMeta!
51
+ """
52
+ Collection ID.
53
+ """
23
54
  id: ID!
55
+ """
56
+ Corresponding collection URL slug, with which to retrieve this entity.
57
+ """
24
58
  slug: String!
59
+ """
60
+ Collection type.
61
+ """
25
62
  type: StoreCollectionType!
26
63
  }
@@ -1,14 +1,43 @@
1
+ """
2
+ Search facet information.
3
+ """
1
4
  type StoreFacet {
5
+ """
6
+ Facet key.
7
+ """
2
8
  key: String!
9
+ """
10
+ Facet label.
11
+ """
3
12
  label: String!
13
+ """
14
+ Array with information on each facet value.
15
+ """
4
16
  values: [StoreFacetValue!]!
17
+ """
18
+ Facet type. Possible values are `BOOLEAN` and `RANGE`.
19
+ """
5
20
  type: StoreFacetType!
6
21
  }
7
22
 
23
+ """
24
+ Information of a specific facet value.
25
+ """
8
26
  type StoreFacetValue {
27
+ """
28
+ Facet value.
29
+ """
9
30
  value: String!
31
+ """
32
+ Facet value label.
33
+ """
10
34
  label: String!
35
+ """
36
+ Indicates whether facet is selected.
37
+ """
11
38
  selected: Boolean!
12
- # Number of items with this facet
39
+ """
40
+ Number of items with this facet.
41
+ """
13
42
  quantity: Int!
14
43
  }
@@ -1,9 +1,27 @@
1
+ """
2
+ Image.
3
+ """
1
4
  type StoreImage {
5
+ """
6
+ Image URL.
7
+ """
2
8
  url: String!
9
+ """
10
+ Alias for the image.
11
+ """
3
12
  alternateName: String!
4
13
  }
5
14
 
15
+ """
16
+ Image input.
17
+ """
6
18
  input IStoreImage {
19
+ """
20
+ Image input URL.
21
+ """
7
22
  url: String!
23
+ """
24
+ Alias for the input image.
25
+ """
8
26
  alternateName: String!
9
27
  }
@@ -1,18 +1,46 @@
1
+ """
2
+ Session information.
3
+ """
1
4
  type StoreSession {
5
+ """
6
+ Session channel.
7
+ """
2
8
  channel: String
9
+ """
10
+ Session country.
11
+ """
3
12
  country: String
13
+ """
14
+ Session postal code.
15
+ """
4
16
  postalCode: String
5
17
  }
6
18
 
19
+ """
20
+ Session input.
21
+ """
7
22
  input IStoreSession {
23
+ """
24
+ Session input channel.
25
+ """
8
26
  channel: String
27
+ """
28
+ Session input country.
29
+ """
9
30
  country: String
31
+ """
32
+ Session input postal code.
33
+ """
10
34
  postalCode: String
11
35
  }
12
36
 
13
37
  type Mutation {
14
- # Returns the order if anything changed with the order. Null if the order is valid
38
+ """
39
+ Returns the order if anything has changed in it, or `null` if the order is valid.
40
+ """
15
41
  validateCart(cart: IStoreCart!): StoreCart
16
-
42
+ """
43
+ Update session information.
44
+ """
17
45
  updateSession(session: IStoreSession!): StoreSession!
18
46
  }
@@ -1,21 +1,71 @@
1
+ """
2
+ Offer information.
3
+ """
1
4
  type StoreOffer {
5
+ """
6
+ This is displayed as the "from" price in the context of promotions' price comparison. This may change before it reaches the shelf.
7
+ """
2
8
  listPrice: Float!
9
+ """
10
+ Computed price before applying coupons, taxes or benefits. This may change before it reaches the shelf.
11
+ """
3
12
  sellingPrice: Float!
13
+ """
14
+ ISO code of the currency used for the offer prices.
15
+ """
4
16
  priceCurrency: String!
5
- # Also known as spotPrice
17
+ """
18
+ Also known as spot price.
19
+ """
6
20
  price: Float!
21
+ """
22
+ 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.
23
+ """
7
24
  priceValidUntil: String!
25
+ """
26
+ Offer item condition.
27
+ """
8
28
  itemCondition: String!
29
+ """
30
+ Offer item availability.
31
+ """
9
32
  availability: String!
33
+ """
34
+ Seller responsible for the offer.
35
+ """
10
36
  seller: StoreOrganization!
37
+ """
38
+ Information on the item being offered.
39
+ """
11
40
  itemOffered: StoreProduct!
41
+ """
42
+ Number of items offered.
43
+ """
12
44
  quantity: Int!
13
45
  }
14
46
 
47
+ """
48
+ Offer input.
49
+ """
15
50
  input IStoreOffer {
51
+ """
52
+ Also known as spot price.
53
+ """
16
54
  price: Float!
55
+ """
56
+ This is displayed as the "from" price in the context of promotions' price comparison. This may change before it reaches the shelf.
57
+ """
17
58
  listPrice: Float!
59
+ """
60
+ Seller responsible for the offer.
61
+ """
18
62
  seller: IStoreOrganization!
63
+ """
64
+ Information on the item being offered.
65
+ """
19
66
  itemOffered: IStoreProduct!
67
+ """
68
+ Number of items offered.
69
+ """
20
70
  quantity: Int!
21
71
  }