axe 7.0.2 → 8.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -4,11 +4,11 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableTo
4
4
 
5
5
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
6
 
7
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
7
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
8
 
9
9
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
10
 
11
- function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
11
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
12
12
 
13
13
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
14
 
@@ -18,9 +18,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
18
18
 
19
19
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
20
20
 
21
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
21
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
22
22
 
23
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
23
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
24
24
 
25
25
  // eslint-disable-next-line import/no-unassigned-import
26
26
  require('console-polyfill');
@@ -55,7 +55,6 @@ var aliases = {
55
55
  err: 'error'
56
56
  };
57
57
  var endpoint = 'https://api.cabinjs.com';
58
- var env = process.env.NODE_ENV || 'development';
59
58
  var levelError = "`level` invalid, must be: ".concat(levels.join(', ')); // <https://stackoverflow.com/a/43233163>
60
59
 
61
60
  function isEmpty(value) {
@@ -101,18 +100,31 @@ var Axe = /*#__PURE__*/function () {
101
100
  timeout: 5000,
102
101
  retry: 3,
103
102
  showStack: process.env.SHOW_STACK ? boolean(process.env.SHOW_STACK) : true,
104
- showMeta: process.env.SHOW_META ? boolean(process.env.SHOW_META) : true,
103
+ meta: {
104
+ show: process.env.SHOW_META ? boolean(process.env.SHOW_META) : true,
105
+ showApp: process.env.SHOW_META_APP ? boolean(process.env.SHOW_META_APP) : false,
106
+ omittedFields: process.env.OMIT_META_FIELDS ? process.env.OMIT_META_FIELDS.split(',').map(function (s) {
107
+ return s.trim();
108
+ }) : []
109
+ },
105
110
  silent: false,
106
111
  logger: console,
107
112
  name: false,
108
113
  level: 'info',
109
114
  levels: ['info', 'warn', 'error', 'fatal'],
110
- capture: process.browser ? false : env === 'production',
115
+ // TODO: if user specifies `key` and it is `process.platform === 'browser' || process.browser || env === 'production'` then set `capture` to `true`
116
+ capture: false,
111
117
  callback: false,
112
118
  appInfo: process.env.APP_INFO ? boolean(process.env.APP_INFO) : true
113
- }, config);
119
+ }, config); // For backwards compatability
120
+
121
+ if (this.config.showMeta) {
122
+ this.config.meta.show = this.config.showMeta;
123
+ delete this.config.showMeta;
124
+ }
125
+
114
126
  this.appInfo = this.config.appInfo ? isFunction(parseAppInfo) ? parseAppInfo() : false : false;
115
- this.log = this.log.bind(this); // inherit methods from parent logger
127
+ this.log = this.log.bind(this); // Inherit methods from parent logger
116
128
 
117
129
  var methods = Object.keys(this.config.logger).filter(function (key) {
118
130
  return !omittedLoggerKeys.has(key);
@@ -125,7 +137,7 @@ var Axe = /*#__PURE__*/function () {
125
137
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
126
138
  var element = _step.value;
127
139
  this[element] = this.config.logger[element];
128
- } // bind helper functions for each log level
140
+ } // Bind helper functions for each log level
129
141
 
130
142
  } catch (err) {
131
143
  _iterator.e(err);
@@ -145,13 +157,13 @@ var Axe = /*#__PURE__*/function () {
145
157
  args[_key] = arguments[_key];
146
158
  }
147
159
 
148
- return _this.log.apply(_this, _toConsumableArray([element].concat([].slice.call(args))));
160
+ return _this.log.apply(_this, _toConsumableArray([element].concat(Array.prototype.slice.call(args))));
149
161
  };
150
162
  };
151
163
 
152
164
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
153
165
  _loop();
154
- } // we could have used `auto-bind` but it's not compiled for browser
166
+ } // We could have used `auto-bind` but it's not compiled for browser
155
167
 
156
168
  } catch (err) {
157
169
  _iterator2.e(err);
@@ -162,11 +174,11 @@ var Axe = /*#__PURE__*/function () {
162
174
  this.setLevel = this.setLevel.bind(this);
163
175
  this.getNormalizedLevel = this.getNormalizedLevel.bind(this);
164
176
  this.setName = this.setName.bind(this);
165
- this.setCallback = this.setCallback.bind(this); // set the logger name
177
+ this.setCallback = this.setCallback.bind(this); // Set the logger name
166
178
 
167
- if (this.config.name) this.setName(this.config.name); // set the logger level
179
+ if (this.config.name) this.setName(this.config.name); // Set the logger level
168
180
 
169
- this.setLevel(this.config.level); // aliases
181
+ this.setLevel(this.config.level); // Aliases
170
182
 
171
183
  this.err = this.error;
172
184
  this.warning = this.warn;
@@ -180,9 +192,9 @@ var Axe = /*#__PURE__*/function () {
180
192
  }, {
181
193
  key: "setLevel",
182
194
  value: function setLevel(level) {
183
- if (!isString(level) || !levels.includes(level)) throw new Error(levelError); // support signale logger and other loggers that use `logLevel`
195
+ if (!isString(level) || !levels.includes(level)) throw new Error(levelError); // Support signale logger and other loggers that use `logLevel`
184
196
 
185
- if (isString(this.config.logger.logLevel)) this.config.logger.logLevel = level;else this.config.logger.level = level; // adjusts `this.config.levels` array
197
+ if (isString(this.config.logger.logLevel)) this.config.logger.logLevel = level;else this.config.logger.level = level; // Adjusts `this.config.levels` array
186
198
  // so that it has all proceeding (inclusive)
187
199
 
188
200
  this.config.levels = levels.slice(levels.indexOf(level));
@@ -198,7 +210,7 @@ var Axe = /*#__PURE__*/function () {
198
210
  }, {
199
211
  key: "setName",
200
212
  value: function setName(name) {
201
- if (!isString(name)) throw new Error('`name` must be a String'); // support signale logger and other loggers that use `scope`
213
+ if (!isString(name)) throw new Error('`name` must be a String'); // Support signale logger and other loggers that use `scope`
202
214
 
203
215
  if (isString(this.config.logger.scope)) this.config.logger.scope = name;else this.config.logger.name = name;
204
216
  } // eslint-disable-next-line complexity
@@ -217,7 +229,7 @@ var Axe = /*#__PURE__*/function () {
217
229
  args[_key2 - 3] = arguments[_key2];
218
230
  }
219
231
 
220
- originalArgs = originalArgs.concat([].slice.call(args));
232
+ originalArgs = originalArgs.concat(Array.prototype.slice.call(args));
221
233
  var config = this.config;
222
234
  var modifier = 0;
223
235
 
@@ -232,7 +244,7 @@ var Axe = /*#__PURE__*/function () {
232
244
  message = level;
233
245
  level = this.getNormalizedLevel(level);
234
246
  modifier = -1;
235
- } // bunyan support (meta, message, ...args)
247
+ } // Bunyan support (meta, message, ...args)
236
248
 
237
249
 
238
250
  var isBunyan = false;
@@ -242,10 +254,10 @@ var Axe = /*#__PURE__*/function () {
242
254
  var _meta = meta;
243
255
  meta = message;
244
256
  message = isString(_meta) && originalArgs.length >= 3 + modifier ? format.apply(void 0, _toConsumableArray(originalArgs.slice(2 + modifier))) : _meta;
245
- } // if message was undefined then set it to level
257
+ } // If message was undefined then set it to level
246
258
 
247
259
 
248
- if (isUndefined(message)) message = level; // if only `message` was passed then if it was an Object
260
+ if (isUndefined(message)) message = level; // If only `message` was passed then if it was an Object
249
261
  // preserve it as an Object by setting it as meta
250
262
 
251
263
  if (originalArgs.slice(1 + modifier).length === 1 && !isString(message) && !isError(message)) {
@@ -254,14 +266,14 @@ var Axe = /*#__PURE__*/function () {
254
266
  };
255
267
  message = level;
256
268
  } else if (!isBunyan && originalArgs.length >= 4 + modifier) {
257
- // if there are four or more args
269
+ // If there are four or more args
258
270
  // then infer to use util.format on everything
259
271
  message = format.apply(void 0, _toConsumableArray(originalArgs.slice(1 + modifier)));
260
272
  meta = {};
261
- } else if (!isBunyan && originalArgs.length === 3 + modifier && isString(message) && formatSpecifiers.filter(function (t) {
273
+ } else if (!isBunyan && originalArgs.length === 3 + modifier && isString(message) && formatSpecifiers.some(function (t) {
262
274
  return message.includes(t);
263
- }).length > 0) {
264
- // otherwise if there are three args and if the `message` contains
275
+ })) {
276
+ // Otherwise if there are three args and if the `message` contains
265
277
  // a placeholder token (e.g. '%s' or '%d' - see above `formatSpecifiers` variable)
266
278
  // then we can infer that the `meta` arg passed is used for formatting
267
279
  message = format(message, meta);
@@ -272,71 +284,71 @@ var Axe = /*#__PURE__*/function () {
272
284
  err: parseErr(meta)
273
285
  }; // } else if (!isPlainObject(meta) && !isUndefined(meta) && !isNull(meta)) {
274
286
  } else if (!isObject(meta) && !isUndefined(meta) && !isNull(meta)) {
275
- // if the `meta` variable passed was not an Object then convert it
287
+ // If the `meta` variable passed was not an Object then convert it
276
288
  message = format(message, meta);
277
289
  meta = {};
278
290
  } else if (!isString(message)) {
279
- // if the message is not a string then we should run `util.format` on it
291
+ // If the message is not a string then we should run `util.format` on it
280
292
  // assuming we're formatting it like it was another argument
281
293
  // (as opposed to using something like fast-json-stringify)
282
294
  message = format(message);
283
295
  }
284
- } // if (!isPlainObject(meta)) meta = {};
296
+ } // If (!isPlainObject(meta)) meta = {};
285
297
 
286
298
 
287
299
  if (!isUndefined(meta) && !isObject(meta)) meta = {
288
300
  meta: meta
289
301
  };else if (!isObject(meta)) meta = {};
290
- var err;
302
+ var error;
291
303
 
292
304
  if (isError(message)) {
293
- err = message;
294
- if (!isObject(meta.err)) meta.err = parseErr(err);
305
+ error = message;
306
+ if (!isObject(meta.err)) meta.err = parseErr(error);
295
307
  var _message = message;
296
308
  message = _message.message;
297
309
  } else if (isError(meta.err)) {
298
- err = meta.err;
299
- } // omit `callback` from `meta` if it was passed
310
+ error = meta.err;
311
+ } // Omit `callback` from `meta` if it was passed
300
312
 
301
313
 
302
314
  var callback = isFunction(config.callback) && (!isBoolean(meta.callback) || meta.callback);
303
- meta = omit(meta, ['callback']); // set default level on meta
315
+ meta = omit(meta, ['callback']); // Set default level on meta
304
316
 
305
- meta.level = level; // add `app` object to metadata
317
+ meta.level = level; // Add `app` object to metadata
306
318
 
307
- if (this.appInfo) meta.app = this.appInfo; // set the body used for returning with and sending logs
319
+ if (this.appInfo) meta.app = this.appInfo; // Set the body used for returning with and sending logs
308
320
  // (and also remove circular references)
309
321
 
310
322
  var body = safeStringify({
311
323
  message: message,
312
324
  meta: meta
313
- }); // send to Cabin or other logging service here the `message` and `meta`
325
+ }); // Send to Cabin or other logging service here the `message` and `meta`
314
326
 
315
- if (config.capture && config.levels.includes(level) && (!isError(err) || !err._captureFailed)) {
316
- // if the user didn't specify a key
327
+ if (config.capture && config.levels.includes(level) && (!isError(error) || !error._captureFailed)) {
328
+ // If the user didn't specify a key
317
329
  // and they are using the default endpoint
318
330
  // then we should throw an error to them
319
- if (config.endpoint === endpoint && !config.key) throw new Error("Cabin API key required (e.g. `{ key: 'YOUR-CABIN-API-KEY' })`)\n<https://cabinjs.com>"); // capture the log over HTTP
331
+ if (config.endpoint === endpoint && !config.key) throw new Error("Cabin API key required (e.g. `{ key: 'YOUR-CABIN-API-KEY' })`)\n<https://cabinjs.com>"); // Capture the log over HTTP
320
332
 
321
333
  var request = superagent.post(config.endpoint).set('X-Request-Id', cuid()).timeout(config.timeout);
322
- if (!process.browser) request.set('User-Agent', "axe/".concat(pkg.version)); // basic auth (e.g. Cabin API key)
334
+ if (!process.browser) request.set('User-Agent', "axe/".concat(pkg.version)); // Basic auth (e.g. Cabin API key)
323
335
 
324
- if (config.key) request.auth(config.key); // set headers if any
336
+ if (config.key) request.auth(config.key); // Set headers if any
325
337
 
326
338
  if (!isEmpty(config.headers)) request.set(config.headers);
327
- request.type('application/json').send(body).retry(config.retry).end(function (err) {
328
- if (err) {
329
- err._captureFailed = true;
339
+ request.type('application/json').send(body).retry(config.retry).end(function (error_) {
340
+ if (error_) {
341
+ error_._captureFailed = true;
330
342
 
331
- _this2.config.logger.error(err);
343
+ _this2.config.logger.error(error_);
332
344
  }
333
345
  });
334
- } // custom callback function (e.g. Slack message)
346
+ } // Custom callback function (e.g. Slack message)
335
347
 
336
348
 
337
- if (callback) config.callback(level, message, meta); // suppress logs if it was silent
349
+ if (callback) config.callback(level, message, meta); // Suppress logs if it was silent
338
350
 
339
- if (config.silent) return body; // return early if it is not a valid logging level
351
+ if (config.silent) return body; // Return early if it is not a valid logging level
340
352
 
341
353
  if (!config.levels.includes(level)) return body; //
342
354
  // determine log method to use
@@ -349,17 +361,21 @@ var Axe = /*#__PURE__*/function () {
349
361
  //
350
362
 
351
363
  var method = level;
352
- if (modifier === -1) method = 'log';else if (level === 'fatal') method = 'error'; // if there was meta information then output it
364
+ if (modifier === -1) method = 'log';else if (level === 'fatal') method = 'error'; // If there was meta information then output it
365
+ // setup ommitted fields
366
+
367
+ var omittedFields = ['level', 'err'].concat(this.config.meta.omittedFields); // Omit app is configured
353
368
 
354
- var omitted = omit(meta, ['level', 'err']); // show stack trace if necessary (along with any metadata)
369
+ if (!this.config.meta.showApp) omittedFields.push('app');
370
+ var omitted = omit(meta, omittedFields); // Show stack trace if necessary (along with any metadata)
355
371
 
356
- if (method === 'error' && isError(err) && config.showStack) {
357
- if (!config.showMeta || isEmpty(omitted)) this.config.logger.error(err);else this.config.logger.error(err, omitted);
358
- } else if (!config.showMeta || isEmpty(omitted)) {
372
+ if (method === 'error' && isError(error) && config.showStack) {
373
+ if (!config.meta.show || isEmpty(omitted)) this.config.logger.error(error);else this.config.logger.error(error, omitted);
374
+ } else if (!config.meta.show || isEmpty(omitted)) {
359
375
  this.config.logger[method](message);
360
376
  } else {
361
377
  this.config.logger[method](message, omitted);
362
- } // return the parsed body in case we need it
378
+ } // Return the parsed body in case we need it
363
379
 
364
380
 
365
381
  return body;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "axe",
3
3
  "description": "Logging add-on to send logs over HTTP to your server in Node and Browser environments. Works with any logger! Chop up your logs consistently! Made for Cabin and Lad.",
4
- "version": "7.0.2",
4
+ "version": "8.1.2",
5
5
  "author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com)",
6
6
  "ava": {
7
7
  "serial": true,
@@ -31,49 +31,49 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "@ladjs/format-util": "^1.0.4",
34
- "boolean": "^3.0.2",
34
+ "boolean": "^3.1.4",
35
35
  "console-polyfill": "^0.3.0",
36
36
  "cuid": "^2.1.8",
37
- "fast-safe-stringify": "^2.0.7",
37
+ "fast-safe-stringify": "^2.1.1",
38
38
  "format-specifiers": "^1.0.0",
39
39
  "iserror": "^0.0.2",
40
40
  "lodash.omit": "^4.5.0",
41
41
  "parse-app-info": "^4.0.2",
42
42
  "parse-err": "^0.0.12",
43
- "superagent": "^6.1.0"
43
+ "superagent": "^7.0.2"
44
44
  },
45
45
  "devDependencies": {
46
- "@babel/cli": "^7.12.8",
47
- "@babel/core": "^7.12.9",
48
- "@babel/preset-env": "^7.12.7",
49
- "@commitlint/cli": "^11.0.0",
50
- "@commitlint/config-conventional": "^11.0.0",
51
- "ava": "^3.13.0",
46
+ "@babel/cli": "^7.16.8",
47
+ "@babel/core": "^7.16.7",
48
+ "@babel/preset-env": "^7.16.8",
49
+ "@commitlint/cli": "^16.0.2",
50
+ "@commitlint/config-conventional": "^16.0.0",
51
+ "ava": "^4.0.1",
52
52
  "babelify": "^10.0.0",
53
53
  "browserify": "^17.0.0",
54
- "codecov": "^3.8.1",
55
- "consola": "^2.15.0",
56
- "cross-env": "^7.0.2",
57
- "eslint": "^7.14.0",
58
- "eslint-config-xo-lass": "^1.0.4",
59
- "eslint-plugin-compat": "^3.8.0",
54
+ "codecov": "^3.8.2",
55
+ "consola": "^2.15.3",
56
+ "cross-env": "^7.0.3",
57
+ "eslint": "^8.6.0",
58
+ "eslint-config-xo-lass": "^1.0.6",
59
+ "eslint-plugin-compat": "^4.0.1",
60
60
  "eslint-plugin-node": "^11.1.0",
61
- "express": "^4.17.1",
62
- "fixpack": "^3.0.6",
63
- "husky": "^4.3.0",
61
+ "express": "^4.17.2",
62
+ "fixpack": "^4.0.0",
63
+ "husky": "^7.0.4",
64
64
  "jsdom": "15.x",
65
- "koa": "^2.13.0",
66
- "lint-staged": "^10.5.2",
67
- "lodash": "^4.17.20",
65
+ "koa": "^2.13.4",
66
+ "lint-staged": "^12.1.7",
67
+ "lodash": "^4.17.21",
68
68
  "nyc": "^15.1.0",
69
- "pino": "^6.7.0",
70
- "remark-cli": "^9.0.0",
69
+ "pino": "^7.6.3",
70
+ "remark-cli": "^10.0.1",
71
71
  "remark-preset-github": "^4.0.1",
72
72
  "rimraf": "^3.0.2",
73
73
  "signale": "^1.4.0",
74
- "sinon": "^9.2.1",
74
+ "sinon": "^12.0.1",
75
75
  "tinyify": "https://github.com/niftylettuce/tinyify",
76
- "xo": "^0.35.0"
76
+ "xo": "^0.47.0"
77
77
  },
78
78
  "engines": {
79
79
  "node": ">=7.0.0"
@@ -169,6 +169,10 @@
169
169
  ],
170
170
  "ignore": [
171
171
  "config.js"
172
- ]
172
+ ],
173
+ "rules": {
174
+ "node/prefer-global/process": "off",
175
+ "unicorn/prefer-spread": "off"
176
+ }
173
177
  }
174
178
  }