@augustdigital/sdk 9.7.0 → 9.7.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.
|
@@ -12,6 +12,19 @@ export declare function sanitizeString(input: string): string;
|
|
|
12
12
|
* …), and `cause`. Subclass constructors are NOT invoked — they may have
|
|
13
13
|
* positional signatures (`new AugustAuthError(code, message, opts)`) that would
|
|
14
14
|
* misalign if we naively passed the sanitized message as the first arg.
|
|
15
|
+
*
|
|
16
|
+
* Every write onto the clone goes through `Object.defineProperty` rather than
|
|
17
|
+
* assignment: the clone inherits `err`'s prototype, and some libraries make
|
|
18
|
+
* properties read-only there — `@solana/web3.js` defines `name` as non-writable
|
|
19
|
+
* on its error classes (`TransactionExpiredTimeoutError`, …). Assigning to an
|
|
20
|
+
* inherited non-writable property throws a `TypeError` in strict mode, which
|
|
21
|
+
* would escape from inside a caller's `catch` (e.g. `Logger.log.error`) and
|
|
22
|
+
* replace the error being reported. Defining an own property shadows the
|
|
23
|
+
* prototype's instead; each one is writable, configurable and enumerable,
|
|
24
|
+
* exactly as the plain assignment used to create it.
|
|
25
|
+
*
|
|
26
|
+
* @param err - Any caught value; non-`Error` values are returned unchanged.
|
|
27
|
+
* @returns A redacted clone for `Error` instances, otherwise `err` itself.
|
|
15
28
|
*/
|
|
16
29
|
export declare function sanitizeError(err: unknown): unknown;
|
|
17
30
|
/** Sanitize arbitrary log input (strings, errors, objects, arrays, primitives). */
|
|
@@ -72,30 +72,42 @@ function sanitizeString(input) {
|
|
|
72
72
|
* …), and `cause`. Subclass constructors are NOT invoked — they may have
|
|
73
73
|
* positional signatures (`new AugustAuthError(code, message, opts)`) that would
|
|
74
74
|
* misalign if we naively passed the sanitized message as the first arg.
|
|
75
|
+
*
|
|
76
|
+
* Every write onto the clone goes through `Object.defineProperty` rather than
|
|
77
|
+
* assignment: the clone inherits `err`'s prototype, and some libraries make
|
|
78
|
+
* properties read-only there — `@solana/web3.js` defines `name` as non-writable
|
|
79
|
+
* on its error classes (`TransactionExpiredTimeoutError`, …). Assigning to an
|
|
80
|
+
* inherited non-writable property throws a `TypeError` in strict mode, which
|
|
81
|
+
* would escape from inside a caller's `catch` (e.g. `Logger.log.error`) and
|
|
82
|
+
* replace the error being reported. Defining an own property shadows the
|
|
83
|
+
* prototype's instead; each one is writable, configurable and enumerable,
|
|
84
|
+
* exactly as the plain assignment used to create it.
|
|
85
|
+
*
|
|
86
|
+
* @param err - Any caught value; non-`Error` values are returned unchanged.
|
|
87
|
+
* @returns A redacted clone for `Error` instances, otherwise `err` itself.
|
|
75
88
|
*/
|
|
76
89
|
function sanitizeError(err) {
|
|
77
90
|
if (!(err instanceof Error))
|
|
78
91
|
return err;
|
|
79
92
|
const safe = Object.create(Object.getPrototypeOf(err));
|
|
93
|
+
const define = (key, value) => Object.defineProperty(safe, key, {
|
|
94
|
+
value,
|
|
95
|
+
writable: true,
|
|
96
|
+
configurable: true,
|
|
97
|
+
enumerable: true,
|
|
98
|
+
});
|
|
80
99
|
for (const key of Object.getOwnPropertyNames(err)) {
|
|
81
100
|
const value = err[key];
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
else if (key === 'stack' && typeof value === 'string') {
|
|
86
|
-
safe[key] = sanitizeString(value);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
safe[key] = value;
|
|
90
|
-
}
|
|
101
|
+
const redact = (key === 'message' || key === 'stack') && typeof value === 'string';
|
|
102
|
+
define(key, redact ? sanitizeString(value) : value);
|
|
91
103
|
}
|
|
92
104
|
if (!safe.message && typeof err.message === 'string') {
|
|
93
|
-
|
|
105
|
+
define('message', sanitizeString(err.message));
|
|
94
106
|
}
|
|
95
107
|
if (!safe.stack && typeof err.stack === 'string') {
|
|
96
|
-
|
|
108
|
+
define('stack', sanitizeString(err.stack));
|
|
97
109
|
}
|
|
98
|
-
|
|
110
|
+
define('name', err.name);
|
|
99
111
|
return safe;
|
|
100
112
|
}
|
|
101
113
|
/** Sanitize arbitrary log input (strings, errors, objects, arrays, primitives). */
|