3 const { common
} = require('@squeep/api-dingus');
7 * Recursively freeze an object.
8 * @param {object} o object to freeze
9 * @returns {object} frozen object
11 const freezeDeep
= (o
) => {
13 Object
.getOwnPropertyNames(o
).forEach((prop
) => {
14 if (Object
.hasOwn(o
, prop
)
15 && ['object', 'function'].includes(typeof o
[prop
]) // eslint-disable-line security/detect-object-injection
16 && !Object
.isFrozen(o
[prop
])) { // eslint-disable-line security/detect-object-injection
17 return freezeDeep(o
[prop
]); // eslint-disable-line security/detect-object-injection
24 * Return a new object duplicating `o`, without the properties specified.
25 * @param {object} o source object
26 * @param {string[]} props list of property names to omit
27 * @returns {object} pruned object
29 const omit
= (o
, props
) => {
30 return Object
.fromEntries(Object
.entries(o
).filter(([k
]) => !props
.includes(k
)));
34 * Helper to log mystery-box statistics.
35 * @param {object} logger logger
36 * @param {Function} logger.debug log debug
37 * @param {string} scope scope
38 * @returns {Function} stats log decorator
40 const mysteryBoxLogger
= (logger
, scope
) => {
42 logger
.debug(scope
, `${s.packageName}@${s.packageVersion}:${s.method}`, omit(s
, [
51 * Hide sensitive part of an Authorization header.
52 * @param {string} authHeader header value
53 * @returns {string} scrubbed header value
55 const obscureAuthorizationHeader
= (authHeader
) => {
59 const space
= authHeader
.indexOf(' ');
60 // This blurs entire string if no space found, because -1.
61 return authHeader
.slice(0, space
+ 1) + '*'.repeat(authHeader
.length
- (space
+ 1));
64 module
.exports
= Object
.assign(Object
.create(common
), {
67 obscureAuthorizationHeader
,