minor cleanups
[squeep-authentication-module] / lib / common.js
index c0aaf3799c7f3d2609ae2ce7ee8c6cec3482facb..d69e6ad6a2131d12d975dbaaddaca70fdb3551e5 100644 (file)
@@ -18,8 +18,36 @@ 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, [
+      'packageName',
+      'packageVersion',
+      'method',
+    ]));
+  };
+};
 
 module.exports = Object.assign(Object.create(common), {
   freezeDeep,
+  mysteryBoxLogger,
+  omit,
 });
\ No newline at end of file