@faststore/api 1.8.32 → 1.8.35

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,5 +1,12 @@
1
+ import type { IStorePropertyValue } from '../../../__generated__/schema';
2
+ import type { Attachment } from '../clients/commerce/types/OrderForm';
1
3
  export declare const VALUE_REFERENCES: {
2
- readonly variation: "VARIATION";
3
4
  readonly attachment: "ATTACHMENT";
4
5
  readonly specification: "SPECIFICATION";
5
6
  };
7
+ export declare function attachmentToPropertyValue(attachment: Attachment): {
8
+ name: string;
9
+ value: Record<string, string>;
10
+ valueReference: "ATTACHMENT";
11
+ };
12
+ export declare function getPropertyId(item: IStorePropertyValue): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "1.8.32",
3
+ "version": "1.8.35",
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": "ab3e45f518c9ce93c6d71e8fb4a83ade0ac7f14d"
48
+ "gitHead": "2fd108e719fd2450c755e622af0cde78d640a9b2"
49
49
  }
@@ -472,6 +472,8 @@ export type StorePropertyValue = {
472
472
  __typename?: 'StorePropertyValue';
473
473
  /** Property name. */
474
474
  name: Scalars['String'];
475
+ /** Property id. This propert changes according to the content of the object. */
476
+ propertyID: Scalars['String'];
475
477
  /** Property value. May hold a string or the string representation of an object. */
476
478
  value: Scalars['ObjectOrString'];
477
479
  /** Specifies the nature of the value */
@@ -14,6 +14,7 @@ import { StoreReview } from './resolvers/review'
14
14
  import { StoreSearchResult } from './resolvers/searchResult'
15
15
  import { StoreSeo } from './resolvers/seo'
16
16
  import { ObjectOrString } from './resolvers/objectOrString'
17
+ import { StorePropertyValue } from './resolvers/propertyValue'
17
18
  import type { Loaders } from './loaders'
18
19
  import type { Clients } from './clients'
19
20
  import type { Channel } from './utils/channel'
@@ -68,6 +69,7 @@ const Resolvers = {
68
69
  StoreReview,
69
70
  StoreProductGroup,
70
71
  StoreSearchResult,
72
+ StorePropertyValue,
71
73
  ObjectOrString,
72
74
  Query,
73
75
  Mutation,
@@ -5,7 +5,10 @@ import type { EnhancedCommercialOffer } from '../utils/enhanceCommercialOffer'
5
5
  import type { Resolver } from '..'
6
6
  import type { PromiseType } from '../../../typings'
7
7
  import type { Query } from './query'
8
- import { VALUE_REFERENCES } from '../utils/propertyValue'
8
+ import {
9
+ attachmentToPropertyValue,
10
+ VALUE_REFERENCES,
11
+ } from '../utils/propertyValue'
9
12
  import type { Attachment } from '../clients/commerce/types/OrderForm'
10
13
 
11
14
  type QueryProduct = PromiseType<ReturnType<typeof Query.product>>
@@ -91,23 +94,24 @@ export const StoreProduct: Record<string, Resolver<Root>> & {
91
94
  )
92
95
  .sort(bestOfferFirst),
93
96
  isVariantOf: (root) => root,
94
- additionalProperty: ({ variations = [], attachmentsValues }) => {
95
- const propertyValueVariations = variations.flatMap(({ name, values }) =>
96
- values.map((value) => ({
97
- name,
98
- value,
99
- valueReference: VALUE_REFERENCES.variation,
100
- }))
97
+ additionalProperty: ({
98
+ // Search uses the name variations for specifications
99
+ variations: specifications = [],
100
+ attachmentsValues = [],
101
+ }) => {
102
+ const propertyValueSpecifications = specifications.flatMap(
103
+ ({ name, values }) =>
104
+ values.map((value) => ({
105
+ name,
106
+ value,
107
+ valueReference: VALUE_REFERENCES.specification,
108
+ }))
101
109
  )
102
110
 
103
- const propertyValueAttachments = (attachmentsValues ?? []).map(
104
- (attachment) => ({
105
- name: attachment.name,
106
- value: attachment.content,
107
- valueReference: VALUE_REFERENCES.attachment,
108
- })
111
+ const propertyValueAttachments = attachmentsValues.map(
112
+ attachmentToPropertyValue
109
113
  )
110
114
 
111
- return [...propertyValueVariations, ...propertyValueAttachments]
115
+ return [...propertyValueSpecifications, ...propertyValueAttachments]
112
116
  },
113
117
  }
@@ -0,0 +1,12 @@
1
+ import type { Resolver } from '..'
2
+ import type { IStorePropertyValue } from '../../../__generated__/schema'
3
+ import { getPropertyId } from '../utils/propertyValue'
4
+
5
+ type Root = IStorePropertyValue
6
+
7
+ export const StorePropertyValue: Record<string, Resolver<Root>> = {
8
+ propertyID: (root) => getPropertyId(root),
9
+ name: ({ name }) => name,
10
+ value: ({ value }) => value,
11
+ valueReference: ({ valueReference }) => valueReference,
12
+ }
@@ -12,7 +12,11 @@ import type {
12
12
  OrderFormItem,
13
13
  } from '../clients/commerce/types/OrderForm'
14
14
  import type { Context } from '..'
15
- import { VALUE_REFERENCES } from '../utils/propertyValue'
15
+ import {
16
+ attachmentToPropertyValue,
17
+ getPropertyId,
18
+ VALUE_REFERENCES,
19
+ } from '../utils/propertyValue'
16
20
 
17
21
  type Indexed<T> = T & { index?: number }
18
22
 
@@ -21,26 +25,12 @@ const getAttachments = (item: IStoreOffer) =>
21
25
  (i) => i.valueReference === VALUE_REFERENCES.attachment
22
26
  )
23
27
 
24
- const serializeAttachment = (item: IStoreOffer) => {
25
- const attachments = getAttachments(item)
26
-
27
- if (attachments?.length === 0) {
28
- return null
29
- }
30
-
31
- return attachments
32
- ?.map(
33
- (attachment) => `${attachment.name}:${JSON.stringify(attachment.value)}`
34
- )
35
- .join('-')
36
- }
37
-
38
28
  const getId = (item: IStoreOffer) =>
39
29
  [
40
30
  item.itemOffered.sku,
41
31
  item.seller.identifier,
42
32
  item.price,
43
- serializeAttachment(item),
33
+ item.itemOffered.additionalProperty?.map(getPropertyId).join('-'),
44
34
  ]
45
35
  .filter(Boolean)
46
36
  .join('::')
@@ -57,6 +47,7 @@ const orderFormItemToOffer = (
57
47
  sku: item.id,
58
48
  image: [],
59
49
  name: item.name,
50
+ additionalProperty: item.attachments.map(attachmentToPropertyValue),
60
51
  },
61
52
  index,
62
53
  })
@@ -68,7 +59,7 @@ const offerToOrderItemInput = (
68
59
  seller: offer.seller.identifier,
69
60
  id: offer.itemOffered.sku,
70
61
  index: offer.index,
71
- attachments: getAttachments(offer)?.map((attachment) => ({
62
+ attachments: (getAttachments(offer) ?? []).map((attachment) => ({
72
63
  name: attachment.name,
73
64
  content: attachment.value,
74
65
  })),
@@ -1,5 +1,22 @@
1
+ import type { IStorePropertyValue } from '../../../__generated__/schema'
2
+ import type { Attachment } from '../clients/commerce/types/OrderForm'
3
+ import { md5 } from './md5'
4
+
1
5
  export const VALUE_REFERENCES = {
2
- variation: 'VARIATION',
3
6
  attachment: 'ATTACHMENT',
4
7
  specification: 'SPECIFICATION',
5
8
  } as const
9
+
10
+ export function attachmentToPropertyValue(attachment: Attachment) {
11
+ return {
12
+ name: attachment.name,
13
+ value: attachment.content,
14
+ valueReference: VALUE_REFERENCES.attachment,
15
+ }
16
+ }
17
+
18
+ export function getPropertyId(item: IStorePropertyValue) {
19
+ return md5(
20
+ `${item.name}:${JSON.stringify(item.value)}:${item.valueReference}`
21
+ )
22
+ }
@@ -2,6 +2,10 @@
2
2
  Properties that can be associated with products and products groups.
3
3
  """
4
4
  type StorePropertyValue {
5
+ """
6
+ Property id. This propert changes according to the content of the object.
7
+ """
8
+ propertyID: String!
5
9
  """
6
10
  Property value. May hold a string or the string representation of an object.
7
11
  """