update dependencies and devDependencies, fix breaking changes from mystery-box update
[squeep-authentication-module] / lib / common.js
1 'use strict';
2
3 const { common } = require('@squeep/api-dingus');
4
5
6 /**
7 * Recursively freeze an object.
8 * @param {Object} o
9 * @returns {Object}
10 */
11 const freezeDeep = (o) => {
12 Object.freeze(o);
13 Object.getOwnPropertyNames(o).forEach((prop) => {
14 if (Object.hasOwnProperty.call(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
18 }
19 });
20 return o;
21 };
22
23 const omit = (o, props) => {
24 return Object.fromEntries(Object.entries(o).filter(([k]) => !props.includes(k)));
25 };
26
27 const mysteryBoxLogger = (logger, scope) => {
28 return (s) => {
29 logger.debug(scope, `${s.packageName}@${s.packageVersion}:${s.method}`, omit(s, [
30 'packageName',
31 'packageVersion',
32 'method',
33 ]));
34 };
35 };
36
37 module.exports = Object.assign(Object.create(common), {
38 freezeDeep,
39 mysteryBoxLogger,
40 omit,
41 });