From: Justin Wind Date: Sat, 10 Jun 2023 18:48:11 +0000 (-0700) Subject: minor cleanups X-Git-Tag: v1.3.1~3 X-Git-Url: http://git.squeep.com/?p=squeep-authentication-module;a=commitdiff_plain;h=681ff60618195ab6754e5b8718a32e53ab2222ec minor cleanups --- diff --git a/.eslintrc.json b/.eslintrc.json index e6c6f89..b3ffbe2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -11,7 +11,7 @@ "plugin:sonarjs/recommended" ], "parserOptions": { - "ecmaVersion": 2018 + "ecmaVersion": "latest" }, "plugins": [ "node", diff --git a/lib/authenticator.js b/lib/authenticator.js index 040834f..ba5d921 100644 --- a/lib/authenticator.js +++ b/lib/authenticator.js @@ -189,7 +189,7 @@ class Authenticator { (cookieHeader || '').split(/; */).forEach((field) => { const [ name, value ] = common.splitFirst(field, '=', null).map((x) => x && decodeURIComponent(x.trim())); if (name && !(name in cookie)) { - if (value && value.startsWith('"') && value.endsWith('"')) { + if (value?.startsWith('"') && value.endsWith('"')) { cookie[name] = value.slice(1, -1); // eslint-disable-line security/detect-object-injection } else { cookie[name] = value; // eslint-disable-line security/detect-object-injection diff --git a/lib/common.js b/lib/common.js index 816b65c..d69e6ad 100644 --- a/lib/common.js +++ b/lib/common.js @@ -20,10 +20,22 @@ const freezeDeep = (o) => { return o; }; +/** + * Return a new object duplicating `o`, without the properties specified. + * @param {Object} o + * @param {String[]} props + * @returns {Object} + */ const omit = (o, props) => { return Object.fromEntries(Object.entries(o).filter(([k]) => !props.includes(k))); }; +/** + * Helper to log mystery-box statistics. + * @param {ConsoleLike} logger + * @param {String} scope + * @returns {Function} + */ const mysteryBoxLogger = (logger, scope) => { return (s) => { logger.debug(scope, `${s.packageName}@${s.packageVersion}:${s.method}`, omit(s, [ diff --git a/lib/session-manager.js b/lib/session-manager.js index 6af1017..cb4c712 100644 --- a/lib/session-manager.js +++ b/lib/session-manager.js @@ -23,8 +23,8 @@ class SessionManager { * @param {Number=} options.authenticator.inactiveSessionLifespanSeconds * @param {Boolean} options.authenticator.secureAuthOnly * @param {Object} options.dingus - * @param {Object} options.dingus.proxyPrefix - * @param {Object} options.dingus.selfBaseUrl + * @param {String} options.dingus.proxyPrefix + * @param {String} options.dingus.selfBaseUrl */ constructor(logger, authenticator, options) { this.logger = logger; @@ -140,13 +140,13 @@ class SessionManager { && me) { let profile; profile = await this.indieAuthCommunication.fetchProfile(me); - if ((!profile || !profile.metadata) + if ((!profile?.metadata) && meAutoScheme) { this.logger.debug(_scope, 'trying http fallback', { ctx }); me.protocol = 'http'; profile = await this.indieAuthCommunication.fetchProfile(me); } - if (!profile || !profile.metadata) { + if (!profile?.metadata) { this.logger.debug(_scope, 'failed to find any profile information at url', { ctx }); ctx.errors.push(`No profile information was found at '${me}'.`); } else { diff --git a/package.json b/package.json index 16fb07e..9c6784c 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "pam" ], "engines": { - "node": ">=14" + "node": "^14 >=14.18 || >=15.7" }, "author": "Justin Wind ", "license": "ISC",