From 07bf59d8ac7f5fc6d5ac5e6b92a37afdbb896790 Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Sat, 18 Mar 2023 13:51:01 -0700 Subject: [PATCH] update dependencies and devDependencies, fix breaking changes from myster-box --- package-lock.json | 60 +++++++++++++++++++++++++++------------------- package.json | 4 ++-- src/common.js | 24 +++++++++++++++++++ src/manager.js | 3 ++- test/src/common.js | 41 +++++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index c116e34..fe76f2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,12 +11,12 @@ "dependencies": { "@squeep/amqp-helper": "git+https://git.squeep.com/squeep-amqp-helper#v1.0.0", "@squeep/api-dingus": "git+https://git.squeep.com/squeep-api-dingus/#v1.2.9", - "@squeep/authentication-module": "git+https://git.squeep.com/squeep-authentication-module/#v1.2.12", + "@squeep/authentication-module": "git+https://git.squeep.com/squeep-authentication-module/#v1.3.0", "@squeep/chores": "git+https://git.squeep.com/squeep-chores/#v1.0.0", "@squeep/html-template-helper": "git+https://git.squeep.com/squeep-html-template-helper#v1.4.0", "@squeep/indieauth-helper": "git+https://git.squeep.com/squeep-indieauth-helper/#v1.2.2", "@squeep/logger-json-console": "git+https://git.squeep.com/squeep-logger-json-console#v1.0.2", - "@squeep/mystery-box": "^1.2.2", + "@squeep/mystery-box": "^2.0.1", "@squeep/resource-authentication-module": "git+https://git.squeep.com/squeep-resource-authentication-module#v1.0.0", "@squeep/roman": "^1.0.0", "@squeep/web-linking": "^1.0.7", @@ -861,20 +861,20 @@ } }, "node_modules/@squeep/authentication-module": { - "version": "1.2.12", - "resolved": "git+https://git.squeep.com/squeep-authentication-module/#9a7d5352698481c0857ba8827e31c7cb97625133", + "version": "1.3.0", + "resolved": "git+https://git.squeep.com/squeep-authentication-module/#6557437fcef1d780b54e39ab93e07a6be36e4447", "license": "ISC", "dependencies": { "@squeep/api-dingus": "git+https://git.squeep.com/squeep-api-dingus/#v1.2.9", "@squeep/html-template-helper": "git+https://git.squeep.com/squeep-html-template-helper#v1.4.0", - "@squeep/indieauth-helper": "git+https://git.squeep.com/squeep-indieauth-helper/#v1.1.7", - "@squeep/mystery-box": "^1.2.0" + "@squeep/indieauth-helper": "git+https://git.squeep.com/squeep-indieauth-helper/#v1.2.0", + "@squeep/mystery-box": "^2.0.1" }, "engines": { "node": ">=14" }, "optionalDependencies": { - "argon2": "^0.30.1", + "argon2": "^0.30.3", "node-linux-pam": "^0.2.1" } }, @@ -935,9 +935,9 @@ } }, "node_modules/@squeep/mystery-box": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/@squeep/mystery-box/-/mystery-box-1.2.2.tgz", - "integrity": "sha512-pbepyJEqnA48ABzthhnOXUFMOGP417gKbZiIRit54iYZ0ZaMg1NWAs2ha5c//Q7hU94A8jPnsRFDtyMCvliNeg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@squeep/mystery-box/-/mystery-box-2.0.1.tgz", + "integrity": "sha512-is8Uqvcm27pm49ZaQL/KOizo89SiTuTZElQoyuPX34TvcnsOTN2eN2YxdVSwKusZwYi+mmE8brrAtBcM/Ttpwg==", "engines": { "node": "^14 >=14.18.0 || >=15.7.0" } @@ -1182,9 +1182,9 @@ } }, "node_modules/aproba": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", - "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz", + "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==", "optional": true }, "node_modules/archy": { @@ -3554,6 +3554,12 @@ "node": ">=0.10.0" } }, + "node_modules/node-linux-pam/node_modules/aproba": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", + "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", + "optional": true + }, "node_modules/node-linux-pam/node_modules/are-we-there-yet": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.7.tgz", @@ -6253,14 +6259,14 @@ } }, "@squeep/authentication-module": { - "version": "git+https://git.squeep.com/squeep-authentication-module/#9a7d5352698481c0857ba8827e31c7cb97625133", - "from": "@squeep/authentication-module@git+https://git.squeep.com/squeep-authentication-module/#v1.2.12", + "version": "git+https://git.squeep.com/squeep-authentication-module/#6557437fcef1d780b54e39ab93e07a6be36e4447", + "from": "@squeep/authentication-module@git+https://git.squeep.com/squeep-authentication-module/#v1.3.0", "requires": { "@squeep/api-dingus": "git+https://git.squeep.com/squeep-api-dingus/#v1.2.9", "@squeep/html-template-helper": "git+https://git.squeep.com/squeep-html-template-helper#v1.4.0", - "@squeep/indieauth-helper": "git+https://git.squeep.com/squeep-indieauth-helper/#v1.1.7", - "@squeep/mystery-box": "^1.2.0", - "argon2": "^0.30.1", + "@squeep/indieauth-helper": "git+https://git.squeep.com/squeep-indieauth-helper/#v1.2.0", + "@squeep/mystery-box": "^2.0.1", + "argon2": "^0.30.3", "node-linux-pam": "^0.2.1" } }, @@ -6302,9 +6308,9 @@ "from": "@squeep/logger-json-console@git+https://git.squeep.com/squeep-logger-json-console#v1.0.2" }, "@squeep/mystery-box": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/@squeep/mystery-box/-/mystery-box-1.2.2.tgz", - "integrity": "sha512-pbepyJEqnA48ABzthhnOXUFMOGP417gKbZiIRit54iYZ0ZaMg1NWAs2ha5c//Q7hU94A8jPnsRFDtyMCvliNeg==" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@squeep/mystery-box/-/mystery-box-2.0.1.tgz", + "integrity": "sha512-is8Uqvcm27pm49ZaQL/KOizo89SiTuTZElQoyuPX34TvcnsOTN2eN2YxdVSwKusZwYi+mmE8brrAtBcM/Ttpwg==" }, "@squeep/resource-authentication-module": { "version": "git+https://git.squeep.com/squeep-resource-authentication-module#69a2f5e7d73dd3f58e07b652c306daa8b253245d", @@ -6494,9 +6500,9 @@ } }, "aproba": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", - "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz", + "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==", "optional": true }, "archy": { @@ -8238,6 +8244,12 @@ "integrity": "sha512-TIGnTpdo+E3+pCyAluZvtED5p5wCqLdezCyhPZzKPcxvFplEt4i+W7OONCKgeZFT3+y5NZZfOOS/Bdcanm1MYA==", "optional": true }, + "aproba": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", + "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", + "optional": true + }, "are-we-there-yet": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.7.tgz", diff --git a/package.json b/package.json index 880d15d..c914082 100644 --- a/package.json +++ b/package.json @@ -34,12 +34,12 @@ "dependencies": { "@squeep/amqp-helper": "git+https://git.squeep.com/squeep-amqp-helper#v1.0.0", "@squeep/api-dingus": "git+https://git.squeep.com/squeep-api-dingus/#v1.2.9", - "@squeep/authentication-module": "git+https://git.squeep.com/squeep-authentication-module/#v1.2.12", + "@squeep/authentication-module": "git+https://git.squeep.com/squeep-authentication-module/#v1.3.0", "@squeep/chores": "git+https://git.squeep.com/squeep-chores/#v1.0.0", "@squeep/html-template-helper": "git+https://git.squeep.com/squeep-html-template-helper#v1.4.0", "@squeep/indieauth-helper": "git+https://git.squeep.com/squeep-indieauth-helper/#v1.2.2", "@squeep/logger-json-console": "git+https://git.squeep.com/squeep-logger-json-console#v1.0.2", - "@squeep/mystery-box": "^1.2.2", + "@squeep/mystery-box": "^2.0.1", "@squeep/resource-authentication-module": "git+https://git.squeep.com/squeep-resource-authentication-module#v1.0.0", "@squeep/roman": "^1.0.0", "@squeep/web-linking": "^1.0.7", diff --git a/src/common.js b/src/common.js index d58f535..90ae9d2 100644 --- a/src/common.js +++ b/src/common.js @@ -151,6 +151,28 @@ const dateToEpoch = (date) => { return Math.ceil(dateMs / 1000); }; + +const omit = (o, props) => { + return Object.fromEntries(Object.entries(o).filter(([k]) => !props.includes(k))) +}; + + +/** + * Log Mystery Box statistics events. + * @param {Console} logger + * @param {String} scope + */ +const mysteryBoxLogger = (logger, scope) => { + return (s) => { + logger.debug(scope, `${s.packageName}@${s.packageVersion}:${s.method}`, omit(s, [ + 'packageName', + 'packageVersion', + 'method', + ])); + }; +}; + + module.exports = { ...common, axiosResponseLogData, @@ -159,7 +181,9 @@ module.exports = { ensureArray, freezeDeep, logTruncate, + mysteryBoxLogger, newSecret, + omit, randomBytesAsync, validScope, validError, diff --git a/src/manager.js b/src/manager.js index 0d43027..01a9416 100644 --- a/src/manager.js +++ b/src/manager.js @@ -28,7 +28,8 @@ class Manager { if (options.queues.amqp.url) { this.queuePublisher = new QueuePublisher(logger, options.queues.amqp); } - this.mysteryBox = new MysteryBox(logger, options); + this.mysteryBox = new MysteryBox(options); + this.mysteryBox.on('statistics', common.mysteryBoxLogger(logger, _fileScope(this.constructor.name))); // We need to know how the outside world sees us, to verify if a // profile indicates us as the auth server. diff --git a/test/src/common.js b/test/src/common.js index 1115f0a..a24db1f 100644 --- a/test/src/common.js +++ b/test/src/common.js @@ -2,6 +2,8 @@ 'use strict'; const assert = require('assert'); +const sinon = require('sinon'); +const StubLogger = require('../stub-logger'); const common = require('../../src/common'); describe('Common', function () { @@ -178,4 +180,43 @@ describe('Common', function () { }); }); // dateToEpoch + describe('omit', function () { + it('covers', function () { + const obj = { + foo: true, + bar: 'bar', + baz: { + quux: false, + }, + }; + const omitted = ['bar', 'baz']; + const expected = { + foo: true, + }; + const result = common.omit(obj, omitted); + assert.deepStrictEqual(result, expected); + }); + }); // omit + + describe('mysteryBoxLogger', function () { + let mbl, stubLogger; + beforeEach(function () { + stubLogger = new StubLogger(); + stubLogger._reset(); + mbl = common.mysteryBoxLogger(stubLogger, 'test:scope'); + }); + afterEach(function () { + sinon.restore(); + }); + it('covers', function () { + const stat = { + packageName: 'fake-mystery-box', + packageVersion: '0.0.0', + data: 'exists', + }; + mbl(stat); + assert(stubLogger.debug.called); + }); + }); // mysteryBoxLogger + }); // Common -- 2.43.2