@graphcommerce/algolia-products 9.1.0-canary.31 → 9.1.0-canary.33
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.
- package/CHANGELOG.md +8 -0
- package/mesh/algoliaHitToMagentoProduct.ts +23 -13
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @graphcommerce/algolia-products
|
|
2
2
|
|
|
3
|
+
## 9.1.0-canary.33
|
|
4
|
+
|
|
5
|
+
## 9.1.0-canary.32
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- [#2516](https://github.com/graphcommerce-org/graphcommerce/pull/2516) [`edd9be6`](https://github.com/graphcommerce-org/graphcommerce/commit/edd9be6cbb37e7da99cc2e74ac269f0b7ddfaaaa) - feat(GCOM-1585): normalize input values from Algolia to schema compliant values ([@FrankHarland](https://github.com/FrankHarland))
|
|
10
|
+
|
|
3
11
|
## 9.1.0-canary.31
|
|
4
12
|
|
|
5
13
|
## 9.1.0-canary.30
|
|
@@ -118,6 +118,23 @@ export type ProductsItemsItem = NonNullable<
|
|
|
118
118
|
__typename: (typeof algoliaTypeToTypename)[keyof typeof algoliaTypeToTypename]
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Ensures a GraphQL-safe string from various input types. If the value is:
|
|
123
|
+
*
|
|
124
|
+
* - An array: returns the first non-empty item as a string
|
|
125
|
+
* - A string: returns it as-is
|
|
126
|
+
* - Anything else: returns an empty string
|
|
127
|
+
*/
|
|
128
|
+
export function normalizeToString(value: unknown): string {
|
|
129
|
+
if (typeof value === 'string') return value
|
|
130
|
+
if (Array.isArray(value)) {
|
|
131
|
+
const firstNonEmpty = value.find((v) => typeof v === 'string' && v.trim() !== '')
|
|
132
|
+
return typeof firstNonEmpty === 'string' ? firstNonEmpty : ''
|
|
133
|
+
}
|
|
134
|
+
console.log('[@graphcommerce/algolia-products] normalizeToString could not convert', value)
|
|
135
|
+
return ''
|
|
136
|
+
}
|
|
137
|
+
|
|
121
138
|
/**
|
|
122
139
|
* Mapping function to map Algolia hit to Magento product.
|
|
123
140
|
*
|
|
@@ -141,8 +158,6 @@ export function algoliaHitToMagentoProduct(
|
|
|
141
158
|
thumbnail_url,
|
|
142
159
|
type_id,
|
|
143
160
|
url,
|
|
144
|
-
description,
|
|
145
|
-
short_description,
|
|
146
161
|
|
|
147
162
|
// not used
|
|
148
163
|
ordered_qty,
|
|
@@ -154,15 +169,9 @@ export function algoliaHitToMagentoProduct(
|
|
|
154
169
|
...rest
|
|
155
170
|
} = additionalProperties
|
|
156
171
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
*/
|
|
161
|
-
for (const [key, value] of Object.entries(rest)) {
|
|
162
|
-
if (value !== null && Array.isArray(value)) {
|
|
163
|
-
rest[key] = value.join(' ')
|
|
164
|
-
}
|
|
165
|
-
}
|
|
172
|
+
// We flatten any custom attribute array values to a string as 95% of the time they are an array
|
|
173
|
+
// because the product is a configurable (which creates an array of values).
|
|
174
|
+
for (const [key, value] of Object.entries(rest)) rest[key] = normalizeToString(value)
|
|
166
175
|
|
|
167
176
|
return {
|
|
168
177
|
staged: false,
|
|
@@ -177,8 +186,6 @@ export function algoliaHitToMagentoProduct(
|
|
|
177
186
|
review_count: 0,
|
|
178
187
|
rating_summary: Number(rating_summary),
|
|
179
188
|
reviews: { items: [], page_info: {} },
|
|
180
|
-
description: description ? { html: description } : null,
|
|
181
|
-
short_description: short_description ? { html: short_description } : null,
|
|
182
189
|
// canonical_url: null,
|
|
183
190
|
// categories: [],
|
|
184
191
|
// country_of_manufacture: null,
|
|
@@ -204,6 +211,9 @@ export function algoliaHitToMagentoProduct(
|
|
|
204
211
|
// upsell_products: [],
|
|
205
212
|
url_key: algoliaUrlToUrlKey(url, storeConfig?.product_url_suffix),
|
|
206
213
|
url_suffix: storeConfig?.product_url_suffix,
|
|
214
|
+
|
|
207
215
|
...rest,
|
|
216
|
+
description: rest.description ? { html: rest.description } : null,
|
|
217
|
+
short_description: rest.short_description ? { html: rest.short_description } : null,
|
|
208
218
|
}
|
|
209
219
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/algolia-products",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "9.1.0-canary.
|
|
5
|
+
"version": "9.1.0-canary.33",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"generate": "tsx scripts/generate-spec.mts"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@graphcommerce/google-datalayer": "^9.1.0-canary.
|
|
19
|
-
"@graphcommerce/graphql": "^9.1.0-canary.
|
|
20
|
-
"@graphcommerce/graphql-mesh": "^9.1.0-canary.
|
|
21
|
-
"@graphcommerce/magento-customer": "^9.1.0-canary.
|
|
22
|
-
"@graphcommerce/magento-product": "^9.1.0-canary.
|
|
23
|
-
"@graphcommerce/magento-search": "^9.1.0-canary.
|
|
24
|
-
"@graphcommerce/next-config": "^9.1.0-canary.
|
|
25
|
-
"@graphcommerce/next-ui": "^9.1.0-canary.
|
|
18
|
+
"@graphcommerce/google-datalayer": "^9.1.0-canary.33",
|
|
19
|
+
"@graphcommerce/graphql": "^9.1.0-canary.33",
|
|
20
|
+
"@graphcommerce/graphql-mesh": "^9.1.0-canary.33",
|
|
21
|
+
"@graphcommerce/magento-customer": "^9.1.0-canary.33",
|
|
22
|
+
"@graphcommerce/magento-product": "^9.1.0-canary.33",
|
|
23
|
+
"@graphcommerce/magento-search": "^9.1.0-canary.33",
|
|
24
|
+
"@graphcommerce/next-config": "^9.1.0-canary.33",
|
|
25
|
+
"@graphcommerce/next-ui": "^9.1.0-canary.33",
|
|
26
26
|
"react": "^18.2.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|