@scayle/storefront-core 7.40.1 → 7.41.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,11 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 7.41.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add `purifySensitiveData` sanitization helper
8
+
3
9
  ## 7.40.1
4
10
 
5
11
  ### Patch Changes
@@ -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.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",