X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fcommon.js;h=5563254f0bab35b7b54322dd46ad0cfa9c49e3c4;hb=4c4e541aaf46de91b9b5e9b4640d7336ffe29f5b;hp=1c19aeb9dbde3172858ee3dcea9a00ceb1a8004e;hpb=53ef948ea83106e82d55e60d6695a15e94bf725e;p=squeep-authentication-module diff --git a/lib/common.js b/lib/common.js index 1c19aeb..5563254 100644 --- a/lib/common.js +++ b/lib/common.js @@ -1,12 +1,15 @@ 'use strict'; const { common } = require('@squeep/api-dingus'); +const { randomBytes } = require('node:crypto'); +const { promisify } = require('node:util'); +const randomBytesAsync = promisify(randomBytes); /** * Recursively freeze an object. - * @param {Object} o - * @returns {Object} + * @param {object} o object to freeze + * @returns {object} frozen object */ const freezeDeep = (o) => { Object.freeze(o); @@ -22,9 +25,9 @@ const freezeDeep = (o) => { /** * Return a new object duplicating `o`, without the properties specified. - * @param {Object} o - * @param {String[]} props - * @returns {Object} + * @param {object} o source object + * @param {string[]} props list of property names to omit + * @returns {object} pruned object */ const omit = (o, props) => { return Object.fromEntries(Object.entries(o).filter(([k]) => !props.includes(k))); @@ -32,9 +35,10 @@ const omit = (o, props) => { /** * Helper to log mystery-box statistics. - * @param {ConsoleLike} logger - * @param {String} scope - * @returns {Function} + * @param {object} logger logger + * @param {Function} logger.debug log debug + * @param {string} scope scope + * @returns {Function} stats log decorator */ const mysteryBoxLogger = (logger, scope) => { return (s) => { @@ -48,8 +52,8 @@ const mysteryBoxLogger = (logger, scope) => { /** * Hide sensitive part of an Authorization header. - * @param {String} authHeader - * @returns {String} + * @param {string} authHeader header value + * @returns {string} scrubbed header value */ const obscureAuthorizationHeader = (authHeader) => { if (!authHeader) { @@ -65,4 +69,5 @@ module.exports = Object.assign(Object.create(common), { mysteryBoxLogger, obscureAuthorizationHeader, omit, -}); \ No newline at end of file + randomBytesAsync, +});