@scayle/storefront-core 7.64.3 → 7.64.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 7.64.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Replaced `radash` utils with custom native implementations
8
+
3
9
  ## 7.64.3
4
10
 
5
11
  ### Patch Changes
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.transformToWhereCondition = exports.transformStateToFilters = exports.transformSortToFilter = exports.transformMinAndMaxPriceToFilter = exports.serializeFilters = exports.mergeFilters = exports.isFilterActive = exports.groupFiltersByKey = exports.groupFilterableValuesByKey = exports.getGroupedFilterableValues = exports.getFilterablePriceValue = exports.getActiveFilters = exports.deserializeFilters = void 0;
7
7
  var _storefrontApi = require("@scayle/storefront-api");
8
- var _radash = require("radash");
9
8
  var _sortingHelper = require("./sortingHelper.cjs");
10
9
  const transformToWhereCondition = conditions => {
11
10
  const where = {
@@ -108,7 +107,13 @@ const getActiveFilters = (filters, activeFilters) => {
108
107
  };
109
108
  exports.getActiveFilters = getActiveFilters;
110
109
  const groupFiltersByKey = filters => {
111
- return Object.entries((0, _radash.group)(filters, it => it.key));
110
+ const groupedFilters = filters.reduce((acc, item) => {
111
+ const groupId = item.key;
112
+ if (!acc[groupId]) acc[groupId] = [];
113
+ acc[groupId].push(item);
114
+ return acc;
115
+ }, {});
116
+ return Object.entries(groupedFilters);
112
117
  };
113
118
  exports.groupFiltersByKey = groupFiltersByKey;
114
119
  const transformMinAndMaxPriceToFilter = prices => {
@@ -145,7 +150,7 @@ const getFilterablePriceValue = (filterableValues, key = "min") => {
145
150
  };
146
151
  exports.getFilterablePriceValue = getFilterablePriceValue;
147
152
  const serializeFilters = filter => {
148
- if ((0, _radash.isEmpty)(filter)) {
153
+ if (Object.keys(filter).length === 0) {
149
154
  return void 0;
150
155
  }
151
156
  return Object.assign({}, ...Object.entries(filter).map(([filterName, filterValue]) => {
@@ -33,7 +33,7 @@ export declare const transformStateToFilters: (state: {
33
33
  export declare const mergeFilters: (filters: TransformedFilter[]) => Record<string, any>;
34
34
  export declare const isFilterActive: (filters: Record<string, any>, filterToCheck: TransformedFilter) => any;
35
35
  export declare const getActiveFilters: (filters: Record<string, any>, activeFilters: Record<string, any>) => TransformedFilter[];
36
- export declare const groupFiltersByKey: (filters: TransformedFilter[]) => any[];
36
+ export declare const groupFiltersByKey: (filters: TransformedFilter[]) => [string, TransformedFilter[]][];
37
37
  export declare const transformMinAndMaxPriceToFilter: (prices: (CentAmount | undefined)[]) => any;
38
38
  export declare const transformSortToFilter: (sort: string) => {
39
39
  by: import("@scayle/storefront-api").APISortOption;
@@ -1,5 +1,4 @@
1
1
  import { FilterTypes } from "@scayle/storefront-api";
2
- import { group, isEmpty } from "radash";
3
2
  import { getSortByValue } from "./sortingHelper.mjs";
4
3
  export const transformToWhereCondition = (conditions) => {
5
4
  const where = { attributes: [] };
@@ -96,7 +95,13 @@ export const getActiveFilters = (filters, activeFilters) => {
96
95
  return [].concat(...Object.values(filters)).filter((item) => isFilterActive(activeFilters, item)) || [];
97
96
  };
98
97
  export const groupFiltersByKey = (filters) => {
99
- return Object.entries(group(filters, (it) => it.key));
98
+ const groupedFilters = filters.reduce((acc, item) => {
99
+ const groupId = item.key;
100
+ if (!acc[groupId]) acc[groupId] = [];
101
+ acc[groupId].push(item);
102
+ return acc;
103
+ }, {});
104
+ return Object.entries(groupedFilters);
100
105
  };
101
106
  export const transformMinAndMaxPriceToFilter = (prices) => {
102
107
  const [min = 0, max = 1e5] = prices;
@@ -127,7 +132,7 @@ export const getFilterablePriceValue = (filterableValues, key = "min") => {
127
132
  return prices.value[key];
128
133
  };
129
134
  export const serializeFilters = (filter) => {
130
- if (isEmpty(filter)) {
135
+ if (Object.keys(filter).length === 0) {
131
136
  return void 0;
132
137
  }
133
138
  return Object.assign(
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.slugify = exports.isVariantInStock = exports.isInStock = exports.getVariantCrosssellingValues = exports.getVariantBySize = exports.getVariant = exports.getTotalAppliedReductions = exports.getSizeFromVariant = exports.getSizeFromSpecificVariant = exports.getProductSiblings = exports.getProductPath = exports.getProductColors = exports.getProductAndSiblingsColors = exports.getPrice = exports.getOriginalPrice = exports.getLowestPrice = exports.getLatestCategory = exports.getCategoriesByRoute = exports.getBadgeLabel = exports.getAttribute = exports.getAppliedReductionsByCategory = exports.getAllSizesFromVariants = void 0;
7
7
  var _storefrontApi = require("@scayle/storefront-api");
8
- var _radash = require("radash");
9
8
  var _slugify = _interopRequireDefault(require("slugify"));
10
9
  var _product = require("../constants/product.cjs");
11
10
  var _attributeHelpers = require("./attributeHelpers.cjs");
@@ -97,7 +96,10 @@ const getVariant = (variants, id) => {
97
96
  return variants?.find(variant => variant.id === id);
98
97
  };
99
98
  exports.getVariant = getVariant;
100
- const getAllSizesFromVariants = (variantsAttributes, attributeName = "shopSize") => (0, _radash.unique)(variantsAttributes.map(variant => (0, _storefrontApi.getFirstAttributeValue)(variant.attributes, attributeName)).filter(Boolean), it => it?.id);
99
+ const getAllSizesFromVariants = (variantsAttributes, attributeName = "shopSize") => {
100
+ const array = variantsAttributes.map(variant => (0, _storefrontApi.getFirstAttributeValue)(variant.attributes, attributeName)).filter(Boolean);
101
+ return [...new Map(array.map(item => [item?.id ?? item, item])).values()];
102
+ };
101
103
  exports.getAllSizesFromVariants = getAllSizesFromVariants;
102
104
  const getProductSiblings = (product, colorAttributeName = "colorDetail") => {
103
105
  if (!product) {
@@ -180,7 +182,7 @@ const getVariantCrosssellingValues = variants => {
180
182
  return [];
181
183
  }
182
184
  const crossellings = variants.map(variant => variant.advancedAttributes?.variantCrosssellings).filter(Boolean);
183
- const uniqueCrossellings = (0, _radash.unique)(crossellings, it => it?.id);
185
+ const uniqueCrossellings = [...new Map(crossellings.map(item => [item?.id ?? item, item])).values()];
184
186
  const values = uniqueCrossellings.map(r => r?.values);
185
187
  const fieldSets = (0, _arrayHelpers.flattenDeep)(values).map(r => r?.fieldSet);
186
188
  return (0, _arrayHelpers.flattenDeep)(fieldSets).map(r => r?.value).filter(it => !!it);
@@ -30,7 +30,7 @@ export declare const getAppliedReductionsByCategory: (price: VariantPrice | Bask
30
30
  export declare const getSizeFromVariant: (variant: Variant, attributeName?: string) => Value | undefined;
31
31
  export declare const getSizeFromSpecificVariant: (product: Product, variantId?: number) => Value | null | undefined;
32
32
  export declare const getVariant: (variants: Variant[], id: number) => Variant | undefined;
33
- export declare const getAllSizesFromVariants: (variantsAttributes: Variant[], attributeName?: string) => (Value | undefined)[];
33
+ export declare const getAllSizesFromVariants: (variantsAttributes: Variant[], attributeName?: string) => any[];
34
34
  export declare const getProductSiblings: (product?: Product | null, colorAttributeName?: string) => ProductSibling[];
35
35
  export declare const getProductColors: (product: Product, colorAttributeName?: string) => string[];
36
36
  export declare const getVariantBySize: (variants: Variant[], size: Value, sizeAttributeName?: string) => Variant | undefined;
@@ -1,5 +1,4 @@
1
1
  import { getFirstAttributeValue } from "@scayle/storefront-api";
2
- import { unique } from "radash";
3
2
  import baseSlugify from "slugify";
4
3
  import { ProductImageType } from "../constants/product.mjs";
5
4
  import { getAttributeValue, getAttributeValueTuples } from "./attributeHelpers.mjs";
@@ -73,12 +72,12 @@ export const getSizeFromSpecificVariant = (product, variantId) => {
73
72
  export const getVariant = (variants, id) => {
74
73
  return variants?.find((variant) => variant.id === id);
75
74
  };
76
- export const getAllSizesFromVariants = (variantsAttributes, attributeName = "shopSize") => unique(
77
- variantsAttributes.map(
75
+ export const getAllSizesFromVariants = (variantsAttributes, attributeName = "shopSize") => {
76
+ const array = variantsAttributes.map(
78
77
  (variant) => getFirstAttributeValue(variant.attributes, attributeName)
79
- ).filter(Boolean),
80
- (it) => it?.id
81
- );
78
+ ).filter(Boolean);
79
+ return [...new Map(array.map((item) => [item?.id ?? item, item])).values()];
80
+ };
82
81
  export const getProductSiblings = (product, colorAttributeName = "colorDetail") => {
83
82
  if (!product) {
84
83
  return [];
@@ -163,7 +162,9 @@ export const getVariantCrosssellingValues = (variants) => {
163
162
  return [];
164
163
  }
165
164
  const crossellings = variants.map((variant) => variant.advancedAttributes?.variantCrosssellings).filter(Boolean);
166
- const uniqueCrossellings = unique(crossellings, (it) => it?.id);
165
+ const uniqueCrossellings = [
166
+ ...new Map(crossellings.map((item) => [item?.id ?? item, item])).values()
167
+ ];
167
168
  const values = uniqueCrossellings.map((r) => r?.values);
168
169
  const fieldSets = flattenDeep(values).map((r) => r?.fieldSet);
169
170
  return flattenDeep(fieldSets).map((r) => r?.value).filter((it) => !!it);
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.stripShopLocaleFromPath = exports.purifySensitiveValue = exports.purifySensitiveData = exports.createAndPurifyHeaders = void 0;
7
- var _radash = require("radash");
8
7
  const SANITIZATION_MASK = "********";
9
8
  const regex = /(?<!^).(?!$)/g;
10
9
  const stripShopLocaleFromPath = (locale, path, splitter = "/") => path.split(splitter).filter(segment => segment.toLowerCase() !== locale.toLowerCase()).join("/");
@@ -15,7 +14,7 @@ const purifySensitiveValue = (value, showFirstAndLastChar = false) => {
15
14
  exports.purifySensitiveValue = purifySensitiveValue;
16
15
  const purifySensitiveData = (data = {}, blacklistedKeys = ["password"], showFirstAndLastChar = false) => {
17
16
  return Object.entries(data).reduce((purifiedPayload, [key, value]) => {
18
- if ((0, _radash.isObject)(value)) {
17
+ if (!!value && value.constructor === Object) {
19
18
  purifiedPayload[key] = purifySensitiveData(value, blacklistedKeys);
20
19
  return purifiedPayload;
21
20
  }
@@ -30,7 +29,7 @@ const purifySensitiveData = (data = {}, blacklistedKeys = ["password"], showFirs
30
29
  };
31
30
  exports.purifySensitiveData = purifySensitiveData;
32
31
  const createAndPurifyHeaders = headers => {
33
- const sanitizedHeaders = (0, _radash.shake)(headers);
32
+ const sanitizedHeaders = Object.fromEntries(Object.entries(headers).filter(([_, value]) => value !== void 0));
34
33
  return new Headers(sanitizedHeaders);
35
34
  };
36
35
  exports.createAndPurifyHeaders = createAndPurifyHeaders;
@@ -1,4 +1,3 @@
1
- import { isObject, shake } from "radash";
2
1
  const SANITIZATION_MASK = "********";
3
2
  const regex = /(?<!^).(?!$)/g;
4
3
  export const stripShopLocaleFromPath = (locale, path, splitter = "/") => path.split(splitter).filter((segment) => segment.toLowerCase() !== locale.toLowerCase()).join("/");
@@ -8,7 +7,7 @@ export const purifySensitiveValue = (value, showFirstAndLastChar = false) => {
8
7
  export const purifySensitiveData = (data = {}, blacklistedKeys = ["password"], showFirstAndLastChar = false) => {
9
8
  return Object.entries(data).reduce(
10
9
  (purifiedPayload, [key, value]) => {
11
- if (isObject(value)) {
10
+ if (!!value && value.constructor === Object) {
12
11
  purifiedPayload[key] = purifySensitiveData(value, blacklistedKeys);
13
12
  return purifiedPayload;
14
13
  }
@@ -26,6 +25,8 @@ export const purifySensitiveData = (data = {}, blacklistedKeys = ["password"], s
26
25
  );
27
26
  };
28
27
  export const createAndPurifyHeaders = (headers) => {
29
- const sanitizedHeaders = shake(headers);
28
+ const sanitizedHeaders = Object.fromEntries(
29
+ Object.entries(headers).filter(([_, value]) => value !== void 0)
30
+ );
30
31
  return new Headers(sanitizedHeaders);
31
32
  };
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getSortingValues = exports.getSortByValue = void 0;
7
7
  var _storefrontApi = require("@scayle/storefront-api");
8
- var _radash = require("radash");
9
8
  var _sorting = require("../constants/sorting.cjs");
10
9
  const SORTING_VALUES = {
11
10
  topSeller: {
@@ -44,7 +43,9 @@ const SORTING_VALUES = {
44
43
  query: _sorting.SortQuery.REDUCTION_ASC
45
44
  }
46
45
  };
47
- const getSortingValues = (options = ["topSeller", "dateNewest", "priceDesc", "priceAsc", "reductionDesc", "reductionAsc"]) => (0, _radash.pick)(SORTING_VALUES, options);
46
+ const getSortingValues = (options = ["topSeller", "dateNewest", "priceDesc", "priceAsc", "reductionDesc", "reductionAsc"]) => {
47
+ return Object.fromEntries(options.filter(key => key in SORTING_VALUES).map(key => [key, SORTING_VALUES[key]]));
48
+ };
48
49
  exports.getSortingValues = getSortingValues;
49
50
  const getSortByValue = (query, defaultSort) => {
50
51
  switch (query) {
@@ -1,42 +1,37 @@
1
1
  import { APISortOption, APISortOrder } from '@scayle/storefront-api';
2
2
  import type { Query, SortingValueKey } from '../index';
3
- export declare const getSortingValues: (options?: Array<SortingValueKey>) => Pick<{
4
- topSeller: {
3
+ export declare const getSortingValues: (options?: Array<SortingValueKey>) => {
4
+ [k: string]: {
5
5
  by: APISortOption;
6
6
  direction: APISortOrder;
7
7
  name: "topseller";
8
8
  query: "topseller";
9
- };
10
- dateNewest: {
9
+ } | {
11
10
  by: APISortOption;
12
11
  name: "date_newest";
13
12
  query: "date-newest";
14
- };
15
- priceDesc: {
13
+ } | {
16
14
  by: APISortOption;
17
15
  direction: APISortOrder;
18
16
  name: "price_desc";
19
17
  query: "price-desc";
20
- };
21
- priceAsc: {
18
+ } | {
22
19
  by: APISortOption;
23
20
  direction: APISortOrder;
24
21
  name: "price_asc";
25
22
  query: "price-asc";
26
- };
27
- reductionDesc: {
23
+ } | {
28
24
  by: APISortOption;
29
25
  direction: APISortOrder;
30
26
  name: "reduction_desc";
31
27
  query: "reduction-desc";
32
- };
33
- reductionAsc: {
28
+ } | {
34
29
  by: APISortOption;
35
30
  direction: APISortOrder;
36
31
  name: "reduction_asc";
37
32
  query: "reduction-asc";
38
33
  };
39
- }, SortingValueKey>;
34
+ };
40
35
  export declare const getSortByValue: (query: Query, defaultSort?: SortingValueKey) => {
41
36
  by: APISortOption;
42
37
  direction: APISortOrder;
@@ -1,5 +1,4 @@
1
1
  import { APISortOption, APISortOrder } from "@scayle/storefront-api";
2
- import { pick } from "radash";
3
2
  import { SortName, SortQuery } from "../constants/sorting.mjs";
4
3
  const SORTING_VALUES = {
5
4
  topSeller: {
@@ -45,7 +44,13 @@ export const getSortingValues = (options = [
45
44
  "priceAsc",
46
45
  "reductionDesc",
47
46
  "reductionAsc"
48
- ]) => pick(SORTING_VALUES, options);
47
+ ]) => {
48
+ return Object.fromEntries(
49
+ options.filter((key) => key in SORTING_VALUES).map(
50
+ (key) => [key, SORTING_VALUES[key]]
51
+ )
52
+ );
53
+ };
49
54
  export const getSortByValue = (query, defaultSort) => {
50
55
  switch (query) {
51
56
  case SortQuery.PRICE_DESC:
@@ -33,7 +33,7 @@ const getCheckoutToken = exports.getCheckoutToken = async function getCheckoutTo
33
33
  carrier,
34
34
  basketId: context.basketKey,
35
35
  campaignKey: context.campaignKey
36
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.64.3"}`).setProtectedHeader({
36
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.64.4"}`).setProtectedHeader({
37
37
  alg: "HS256",
38
38
  typ: "JWT"
39
39
  }).sign(secret);
@@ -27,7 +27,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
27
27
  carrier,
28
28
  basketId: context.basketKey,
29
29
  campaignKey: context.campaignKey
30
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.64.3"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
30
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.64.4"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
31
31
  return {
32
32
  accessToken: refreshedAccessToken,
33
33
  checkoutJwt
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "7.64.3",
3
+ "version": "7.64.4",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -63,7 +63,6 @@
63
63
  "crypto-js": "^4.2.0",
64
64
  "hookable": "^5.5.3",
65
65
  "jose": "^5.6.3",
66
- "radash": "^12.1.0",
67
66
  "slugify": "^1.6.6",
68
67
  "ufo": "^1.5.3",
69
68
  "uncrypto": "^0.1.3",
@@ -72,18 +71,18 @@
72
71
  "devDependencies": {
73
72
  "@scayle/eslint-config-storefront": "4.3.0",
74
73
  "@types/crypto-js": "4.2.2",
75
- "@types/node": "20.16.1",
74
+ "@types/node": "20.16.5",
76
75
  "@types/webpack-env": "1.18.5",
77
76
  "@vitest/coverage-v8": "2.0.5",
78
77
  "dprint": "0.47.2",
79
- "eslint": "9.9.1",
78
+ "eslint": "9.10.0",
80
79
  "eslint-formatter-gitlab": "5.1.0",
81
80
  "publint": "0.2.10",
82
81
  "rimraf": "6.0.1",
83
82
  "ts-node": "10.9.2",
84
- "typescript": "5.5.4",
83
+ "typescript": "5.6.2",
85
84
  "unbuild": "2.0.0",
86
- "unstorage": "1.10.2",
85
+ "unstorage": "1.12.0",
87
86
  "vitest": "2.0.5"
88
87
  },
89
88
  "optionalDependencies": {