@shopgate/pwa-core 7.32.2-alpha.8 → 7.33.0-beta.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.
Files changed (2) hide show
  1. package/helpers/error.js +23 -4
  2. package/package.json +1 -1
package/helpers/error.js CHANGED
@@ -1,11 +1,17 @@
1
+ const UNDESCRIBABLE = 'a value that could not be described';
2
+
1
3
  /**
2
- * Describes a value without its content, since it can be personal data.
4
+ * Describes a value without its content.
3
5
  * @param {*} value The value.
4
- * @returns {string} Primitives and errors as text, objects as their keys and their error code.
6
+ * @param {Array[]} parents The arrays the value is nested in.
7
+ * @returns {string} The description.
5
8
  */
6
- export const describeValue = value => {
9
+ const describe = (value, parents) => {
7
10
  if (Array.isArray(value)) {
8
- return `[${value.map(describeValue).join(', ')}]`;
11
+ if (parents.includes(value)) {
12
+ return '[circular]';
13
+ }
14
+ return `[${value.map(entry => describe(entry, [].concat(parents, [value]))).join(', ')}]`;
9
15
  }
10
16
  if (!value || typeof value !== 'object' || value instanceof Error) {
11
17
  return String(value);
@@ -14,6 +20,19 @@ export const describeValue = value => {
14
20
  return `{${code}keys: ${Object.keys(value).join(', ')}}`;
15
21
  };
16
22
 
23
+ /**
24
+ * Describes a value without its content, since it can be personal data. It never throws.
25
+ * @param {*} value The value.
26
+ * @returns {string} Primitives and errors as text, objects as their keys and their error code.
27
+ */
28
+ export const describeValue = value => {
29
+ try {
30
+ return describe(value, []);
31
+ } catch (error) {
32
+ return UNDESCRIBABLE;
33
+ }
34
+ };
35
+
17
36
  /**
18
37
  * Defines properties on an error itself, so that they also replace properties the error only
19
38
  * has a getter for.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/pwa-core",
3
- "version": "7.32.2-alpha.8",
3
+ "version": "7.33.0-beta.1",
4
4
  "description": "Core library for the Shopgate Connect PWA.",
5
5
  "author": "Support <support@shopgate.com>",
6
6
  "license": "Apache-2.0",