@scayle/storefront-core 7.40.1 → 7.41.1

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,17 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 7.41.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixes an issue where we were trying to read siblings information from a product where the data was not available
8
+
9
+ ## 7.41.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Add `purifySensitiveData` sanitization helper
14
+
3
15
  ## 7.40.1
4
16
 
5
17
  ### Patch Changes
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 SCAYLE GmbH
3
+ Copyright (c) 2024 SCAYLE GmbH
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -171,8 +171,8 @@ const getLatestCategory = categories => {
171
171
  exports.getLatestCategory = getLatestCategory;
172
172
  const getProductAndSiblingsColors = (product, colorAttributeName = "colorDetail") => {
173
173
  const productColor = (0, _backbone.getFirstAttributeValue)(product.attributes, colorAttributeName);
174
- const siblingsColors = product.siblings?.filter(sibling => sibling.isActive && !sibling.isSoldOut).map(sibling => (0, _backbone.getFirstAttributeValue)(sibling.attributes, colorAttributeName));
175
- return [productColor, ...(siblingsColors || [])].filter(color => !!color);
174
+ const siblingsColors = (product.siblings ?? []).filter(sibling => sibling.isActive).map(sibling => (0, _backbone.getFirstAttributeValue)(sibling.attributes, colorAttributeName));
175
+ return [productColor, ...siblingsColors].filter(color => !!color);
176
176
  };
177
177
  exports.getProductAndSiblingsColors = getProductAndSiblingsColors;
178
178
  const getVariantCrosssellingValues = variants => {
@@ -151,10 +151,10 @@ export const getProductAndSiblingsColors = (product, colorAttributeName = "color
151
151
  product.attributes,
152
152
  colorAttributeName
153
153
  );
154
- const siblingsColors = product.siblings?.filter((sibling) => sibling.isActive && !sibling.isSoldOut).map(
154
+ const siblingsColors = (product.siblings ?? []).filter((sibling) => sibling.isActive).map(
155
155
  (sibling) => getFirstAttributeValue(sibling.attributes, colorAttributeName)
156
156
  );
157
- return [productColor, ...siblingsColors || []].filter(
157
+ return [productColor, ...siblingsColors].filter(
158
158
  (color) => !!color
159
159
  );
160
160
  };
@@ -3,6 +3,20 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.stripShopLocaleFromPath = void 0;
6
+ exports.stripShopLocaleFromPath = exports.purifySensitiveData = void 0;
7
+ var _radash = require("radash");
8
+ const SANITIZATION_MASK = "********";
7
9
  const stripShopLocaleFromPath = (locale, path, splitter = "/") => path.split(splitter).filter(segment => segment.toLowerCase() !== locale.toLowerCase()).join("/");
8
- exports.stripShopLocaleFromPath = stripShopLocaleFromPath;
10
+ exports.stripShopLocaleFromPath = stripShopLocaleFromPath;
11
+ const purifySensitiveData = (data = {}, blacklistedKeys = ["password"]) => {
12
+ return Object.entries(data).reduce((purifiedPayload, [key, value]) => {
13
+ if ((0, _radash.isObject)(value)) {
14
+ purifiedPayload[key] = purifySensitiveData(value, blacklistedKeys);
15
+ return purifiedPayload;
16
+ }
17
+ const isSensitiveData = blacklistedKeys.some(excludedKey => key.includes(excludedKey));
18
+ purifiedPayload[key] = isSensitiveData ? SANITIZATION_MASK : value;
19
+ return purifiedPayload;
20
+ }, {});
21
+ };
22
+ exports.purifySensitiveData = purifySensitiveData;
@@ -1 +1,2 @@
1
1
  export declare const stripShopLocaleFromPath: (locale: string, path: string, splitter?: string) => string;
2
+ export declare const purifySensitiveData: (data?: Record<string, any>, blacklistedKeys?: string[]) => Record<string, any>;
@@ -1 +1,19 @@
1
+ import { isObject } from "radash";
2
+ const SANITIZATION_MASK = "********";
1
3
  export const stripShopLocaleFromPath = (locale, path, splitter = "/") => path.split(splitter).filter((segment) => segment.toLowerCase() !== locale.toLowerCase()).join("/");
4
+ export const purifySensitiveData = (data = {}, blacklistedKeys = ["password"]) => {
5
+ return Object.entries(data).reduce(
6
+ (purifiedPayload, [key, value]) => {
7
+ if (isObject(value)) {
8
+ purifiedPayload[key] = purifySensitiveData(value, blacklistedKeys);
9
+ return purifiedPayload;
10
+ }
11
+ const isSensitiveData = blacklistedKeys.some(
12
+ (excludedKey) => key.includes(excludedKey)
13
+ );
14
+ purifiedPayload[key] = isSensitiveData ? SANITIZATION_MASK : value;
15
+ return purifiedPayload;
16
+ },
17
+ {}
18
+ );
19
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "7.40.1",
3
+ "version": "7.41.1",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -71,7 +71,7 @@
71
71
  "devDependencies": {
72
72
  "@scayle/eslint-config-storefront": "3.2.6",
73
73
  "@types/crypto-js": "4.2.2",
74
- "@types/node": "20.11.17",
74
+ "@types/node": "20.11.19",
75
75
  "@types/webpack-env": "1.18.4",
76
76
  "@vitest/coverage-v8": "1.2.2",
77
77
  "dprint": "0.45.0",