@scayle/storefront-core 8.45.1 → 8.46.0
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
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# @scayle/storefront-core
|
|
2
2
|
|
|
3
|
+
## 8.46.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added `getAttributeValuesByGroupId` function to the `attributeHelpers` helper for retrieving attribute values by their numeric attribute group ID.
|
|
8
|
+
|
|
9
|
+
This function allows you to retrieve attribute values filtered by a specific attribute group ID, providing a more targeted approach when working with grouped product attributes.
|
|
10
|
+
The existing `getAttributeValues` function has been renamed to `getAttributeValuesByName` to better differentiate between the two lookup methods.
|
|
11
|
+
|
|
12
|
+
### Usage Examples
|
|
13
|
+
|
|
14
|
+
Both functions return an array of values for consistency, making them safe to use in iterations. For single-select attributes, the value is wrapped in an array. For multi-select attributes, the array is returned directly.
|
|
15
|
+
|
|
16
|
+
#### Looking up by name (existing, now renamed):
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import { getAttributeValuesByName } from '@scayle/storefront-core'
|
|
20
|
+
|
|
21
|
+
// Single-select attribute
|
|
22
|
+
const sizes = getAttributeValuesByName(product.attributes, 'size')
|
|
23
|
+
// Returns: [{ id: 1, label: 'M', value: 'medium' }]
|
|
24
|
+
|
|
25
|
+
// Multi-select attribute
|
|
26
|
+
const colors = getAttributeValuesByName(product.attributes, 'color')
|
|
27
|
+
// Returns: [{ id: 1, label: 'Red' }, { id: 2, label: 'Blue' }]
|
|
28
|
+
|
|
29
|
+
// Non-existent attribute
|
|
30
|
+
const missing = getAttributeValuesByName(product.attributes, 'doesNotExist')
|
|
31
|
+
// Returns: []
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
#### Looking up by group ID (new):
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { getAttributeValuesByGroupId } from '@scayle/storefront-core'
|
|
38
|
+
|
|
39
|
+
// Look up attribute by its numeric ID from the SCAYLE API
|
|
40
|
+
const promotionValues = getAttributeValuesByGroupId(product.attributes, 42)
|
|
41
|
+
// Returns: [{ id: 123, label: 'Summer Sale', value: 'summer-2024' }]
|
|
42
|
+
|
|
43
|
+
// Non-existent attribute group
|
|
44
|
+
const missing = getAttributeValuesByGroupId(product.attributes, 9999)
|
|
45
|
+
// Returns: []
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### When to Use Each Function
|
|
49
|
+
|
|
50
|
+
- **`getAttributeValuesByName`**: Use when you know the attribute name key (e.g., 'color', 'size'). This is the most common use case in application code.
|
|
51
|
+
- **`getAttributeValuesByGroupId`**: Use when you have the numeric attribute group ID from the SCAYLE API, such as when processing API configurations, handling dynamic attribute mappings, or working with attribute group references.
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
**Dependencies**
|
|
56
|
+
|
|
57
|
+
- Updated dependency to @scayle/storefront-api@18.17.0
|
|
58
|
+
|
|
3
59
|
## 8.45.1
|
|
4
60
|
|
|
5
61
|
### Patch Changes
|
|
@@ -1,5 +1,64 @@
|
|
|
1
1
|
import type { Attributes, Value } from '@scayle/storefront-api';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Returns the first value of an attribute.
|
|
4
|
+
* This function is useful when you need to get the first value of an attribute.
|
|
5
|
+
*
|
|
6
|
+
* This returns undefined, if the attribute doesn't exist or if it doesn't have any values.
|
|
7
|
+
*
|
|
8
|
+
* @param attributes - The product attributes object
|
|
9
|
+
* @param attributeName - The name of the attribute to look up
|
|
10
|
+
*
|
|
11
|
+
* @returns The first value of the attribute, or undefined if the attribute doesn't exist or has no values
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const firstColor = getFirstAttributeValue(product.attributes, 'color')
|
|
16
|
+
* // Returns: { id: 1, label: 'Red', value: 'red' }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const getFirstAttributeValue: (attributes: Attributes | undefined, attributeName: string) => Value | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Returns all values of an attribute group by its name key.
|
|
22
|
+
* This function always returns an array, making it safe to use in iterations.
|
|
23
|
+
* For single-select attributes, the value is wrapped in an array.
|
|
24
|
+
* For multi-select attributes, the array is returned directly.
|
|
25
|
+
*
|
|
26
|
+
* @param attributes - The product attributes object
|
|
27
|
+
* @param name - The name key of the attribute group to look up (e.g., 'color', 'size')
|
|
28
|
+
*
|
|
29
|
+
* @returns An array of values, or an empty array if the attribute doesn't exist or has no values
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // Single-select attribute
|
|
34
|
+
* const sizes = getAttributeValuesByName(product.attributes, 'size')
|
|
35
|
+
* // Returns: [{ id: 1, label: 'M', value: 'medium' }]
|
|
36
|
+
*
|
|
37
|
+
* // Multi-select attribute
|
|
38
|
+
* const colors = getAttributeValuesByName(product.attributes, 'color')
|
|
39
|
+
* // Returns: [{ id: 1, label: 'Red' }, { id: 2, label: 'Blue' }]
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare const getAttributeValuesByName: (attributes: Attributes | undefined, name: string) => Value[];
|
|
43
|
+
/**
|
|
44
|
+
* Returns all values of an attribute group by its numeric ID.
|
|
45
|
+
*
|
|
46
|
+
* This function searches through all attribute groups to find one matching the given ID.
|
|
47
|
+
* This is useful when you need to look up attributes by their SCAYLE API identifier rather than by name.
|
|
48
|
+
* Like {@link getAttributeValuesByName}, this always returns an array for consistency.
|
|
49
|
+
*
|
|
50
|
+
* @param attributes - The product attributes object
|
|
51
|
+
* @param groupId - The numeric ID of the attribute group to look up
|
|
52
|
+
* @returns An array of values, or an empty array if the attribute doesn't exist or has no values
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Look up by attribute group ID instead of name
|
|
57
|
+
* const promotionValues = getAttributeValuesByGroupId(product.attributes, 42)
|
|
58
|
+
* // Returns: [{ id: 123, label: 'Summer Sale', value: 'summer-2024' }]
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const getAttributeValuesByGroupId: (attributes: Attributes | undefined, groupId: number) => Value[];
|
|
3
62
|
/**
|
|
4
63
|
* Retrieves the value or label of the first attribute value for a given attribute name.
|
|
5
64
|
*
|
|
@@ -18,4 +77,7 @@ export declare const getAttributeValue: (attributes: Attributes | undefined, att
|
|
|
18
77
|
* @returns An array of attribute values, filtered to remove any null or undefined values.
|
|
19
78
|
*/
|
|
20
79
|
export declare const getManyAttributeValueTuples: (attributes: Attributes | undefined, attributeNames: string[]) => Value[];
|
|
21
|
-
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated This function will be removed in the next major version. Use {@link getAttributeValuesByName} instead.
|
|
82
|
+
*/
|
|
83
|
+
export { getAttributeValuesByName as getAttributeValueTuples };
|
|
@@ -1,7 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export const getFirstAttributeValue = (attributes, attributeName) => {
|
|
2
|
+
const attribute = attributes && attributes[attributeName];
|
|
3
|
+
if (!attribute || !attribute.values) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
if (attribute.multiSelect) {
|
|
7
|
+
return attribute.values.length > 0 ? attribute.values[0] : void 0;
|
|
8
|
+
}
|
|
9
|
+
return attribute.values;
|
|
10
|
+
};
|
|
11
|
+
export const getAttributeValuesByName = (attributes, name) => {
|
|
12
|
+
const attribute = attributes && attributes[name];
|
|
13
|
+
if (!attribute || !attribute.values) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
if (attribute.multiSelect) {
|
|
17
|
+
return attribute.values;
|
|
18
|
+
}
|
|
19
|
+
return [attribute.values];
|
|
20
|
+
};
|
|
21
|
+
export const getAttributeValuesByGroupId = (attributes, groupId) => {
|
|
22
|
+
if (!attributes) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
const attribute = Object.values(attributes).find((attribute2) => attribute2?.id === groupId);
|
|
26
|
+
if (!attribute || !attribute.values) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
if (attribute.multiSelect) {
|
|
30
|
+
return attribute.values;
|
|
31
|
+
}
|
|
32
|
+
return [attribute.values];
|
|
33
|
+
};
|
|
5
34
|
export const getAttributeValue = (attributes, attributeName) => {
|
|
6
35
|
const values = getFirstAttributeValue(attributes, attributeName);
|
|
7
36
|
return values?.value ?? values?.label;
|
|
@@ -9,4 +38,4 @@ export const getAttributeValue = (attributes, attributeName) => {
|
|
|
9
38
|
export const getManyAttributeValueTuples = (attributes, attributeNames) => {
|
|
10
39
|
return attributeNames.map((key) => getFirstAttributeValue(attributes, key)).filter((entry) => !!entry);
|
|
11
40
|
};
|
|
12
|
-
export {
|
|
41
|
+
export { getAttributeValuesByName as getAttributeValueTuples };
|
|
@@ -33,7 +33,7 @@ export const getCheckoutToken = defineRpcHandler(async (jwtPayload = {}, context
|
|
|
33
33
|
carrier,
|
|
34
34
|
basketId: context.basketKey,
|
|
35
35
|
campaignKey
|
|
36
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.
|
|
36
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.46.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
|
|
37
37
|
return {
|
|
38
38
|
accessToken: refreshedAccessToken,
|
|
39
39
|
checkoutJwt
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-core",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.46.0",
|
|
4
4
|
"description": "Collection of essential utilities to work with the Storefront API",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,26 +48,26 @@
|
|
|
48
48
|
"ufo": "^1.5.3",
|
|
49
49
|
"uncrypto": "^0.1.3",
|
|
50
50
|
"utility-types": "^3.11.0",
|
|
51
|
-
"@scayle/storefront-api": "18.
|
|
51
|
+
"@scayle/storefront-api": "18.17.0",
|
|
52
52
|
"@scayle/unstorage-scayle-kv-driver": "2.0.6"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/crypto-js": "4.2.2",
|
|
56
|
-
"@types/node": "22.18.
|
|
56
|
+
"@types/node": "22.18.12",
|
|
57
57
|
"@types/webpack-env": "1.18.8",
|
|
58
58
|
"@vitest/coverage-v8": "3.2.4",
|
|
59
59
|
"dprint": "0.50.2",
|
|
60
60
|
"eslint-formatter-gitlab": "6.0.1",
|
|
61
|
-
"eslint": "9.
|
|
61
|
+
"eslint": "9.38.0",
|
|
62
62
|
"fishery": "2.3.1",
|
|
63
|
-
"publint": "0.3.
|
|
63
|
+
"publint": "0.3.15",
|
|
64
64
|
"rimraf": "6.0.1",
|
|
65
65
|
"typescript": "5.9.3",
|
|
66
66
|
"unbuild": "3.6.1",
|
|
67
67
|
"unstorage": "1.17.1",
|
|
68
68
|
"vitest": "3.2.4",
|
|
69
|
-
"@scayle/
|
|
70
|
-
"@scayle/
|
|
69
|
+
"@scayle/vitest-config-storefront": "1.0.0",
|
|
70
|
+
"@scayle/eslint-config-storefront": "4.7.10"
|
|
71
71
|
},
|
|
72
72
|
"volta": {
|
|
73
73
|
"node": "22.20.0"
|