axe 8.1.0 → 9.0.0
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/README.md +6 -29
- package/dist/axe.js +4556 -3082
- package/dist/axe.min.js +1 -1
- package/lib/index.js +197 -254
- package/package.json +35 -79
package/lib/index.js
CHANGED
|
@@ -1,64 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
8
|
-
|
|
9
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
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; } } }; }
|
|
12
|
-
|
|
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
|
-
|
|
15
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
16
|
-
|
|
17
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
18
|
-
|
|
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
|
-
|
|
21
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
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); }
|
|
24
|
-
|
|
25
3
|
// eslint-disable-next-line import/no-unassigned-import
|
|
26
4
|
require('console-polyfill');
|
|
27
5
|
|
|
28
|
-
|
|
6
|
+
const cuid = require('cuid');
|
|
29
7
|
|
|
30
|
-
|
|
8
|
+
const format = require('@ladjs/format-util');
|
|
31
9
|
|
|
32
|
-
|
|
10
|
+
const formatSpecifiers = require('format-specifiers');
|
|
33
11
|
|
|
34
|
-
|
|
12
|
+
const isError = require('iserror');
|
|
35
13
|
|
|
36
|
-
|
|
14
|
+
const omit = require('lodash.omit');
|
|
37
15
|
|
|
38
|
-
|
|
16
|
+
const parseAppInfo = require('parse-app-info');
|
|
39
17
|
|
|
40
|
-
|
|
18
|
+
const parseErr = require('parse-err');
|
|
41
19
|
|
|
42
|
-
|
|
20
|
+
const safeStringify = require('fast-safe-stringify');
|
|
43
21
|
|
|
44
|
-
|
|
22
|
+
const superagent = require('superagent');
|
|
45
23
|
|
|
46
|
-
|
|
47
|
-
|
|
24
|
+
const {
|
|
25
|
+
boolean
|
|
26
|
+
} = require('boolean');
|
|
48
27
|
|
|
49
|
-
|
|
28
|
+
const pkg = require('../package.json');
|
|
50
29
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
30
|
+
const omittedLoggerKeys = new Set(['config', 'log']);
|
|
31
|
+
const levels = ['trace', 'debug', 'info', 'warn', 'error', 'fatal'];
|
|
32
|
+
const aliases = {
|
|
54
33
|
warning: 'warn',
|
|
55
34
|
err: 'error'
|
|
56
35
|
};
|
|
57
|
-
|
|
58
|
-
|
|
36
|
+
const endpoint = 'https://api.cabinjs.com';
|
|
37
|
+
const levelError = "`level` invalid, must be: ".concat(levels.join(', ')); // <https://stackoverflow.com/a/43233163>
|
|
59
38
|
|
|
60
39
|
function isEmpty(value) {
|
|
61
|
-
return value === undefined || value === null ||
|
|
40
|
+
return value === undefined || value === null || typeof value === 'object' && Object.keys(value).length === 0 || typeof value === 'string' && value.trim().length === 0;
|
|
62
41
|
}
|
|
63
42
|
|
|
64
43
|
function isNull(value) {
|
|
@@ -70,7 +49,7 @@ function isUndefined(value) {
|
|
|
70
49
|
}
|
|
71
50
|
|
|
72
51
|
function isObject(value) {
|
|
73
|
-
return
|
|
52
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
74
53
|
}
|
|
75
54
|
|
|
76
55
|
function isString(value) {
|
|
@@ -85,27 +64,22 @@ function isBoolean(value) {
|
|
|
85
64
|
return typeof value === 'boolean';
|
|
86
65
|
}
|
|
87
66
|
|
|
88
|
-
|
|
89
|
-
|
|
67
|
+
class Axe {
|
|
68
|
+
constructor() {
|
|
90
69
|
var _this = this;
|
|
91
70
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
_classCallCheck(this, Axe);
|
|
95
|
-
|
|
71
|
+
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
96
72
|
this.config = Object.assign({
|
|
97
73
|
key: '',
|
|
98
|
-
endpoint
|
|
74
|
+
endpoint,
|
|
99
75
|
headers: {},
|
|
100
76
|
timeout: 5000,
|
|
101
77
|
retry: 3,
|
|
102
78
|
showStack: process.env.SHOW_STACK ? boolean(process.env.SHOW_STACK) : true,
|
|
103
79
|
meta: {
|
|
104
80
|
show: process.env.SHOW_META ? boolean(process.env.SHOW_META) : true,
|
|
105
|
-
showApp: process.env.SHOW_META_APP ? boolean(process.env.SHOW_META_APP) :
|
|
106
|
-
omittedFields: process.env.OMIT_META_FIELDS ? process.env.OMIT_META_FIELDS.split(',').map(
|
|
107
|
-
return s.trim();
|
|
108
|
-
}) : []
|
|
81
|
+
showApp: process.env.SHOW_META_APP ? boolean(process.env.SHOW_META_APP) : false,
|
|
82
|
+
omittedFields: process.env.OMIT_META_FIELDS ? process.env.OMIT_META_FIELDS.split(',').map(s => s.trim()) : []
|
|
109
83
|
},
|
|
110
84
|
silent: false,
|
|
111
85
|
logger: console,
|
|
@@ -126,50 +100,23 @@ var Axe = /*#__PURE__*/function () {
|
|
|
126
100
|
this.appInfo = this.config.appInfo ? isFunction(parseAppInfo) ? parseAppInfo() : false : false;
|
|
127
101
|
this.log = this.log.bind(this); // Inherit methods from parent logger
|
|
128
102
|
|
|
129
|
-
|
|
130
|
-
return !omittedLoggerKeys.has(key);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
var _iterator = _createForOfIteratorHelper(methods),
|
|
134
|
-
_step;
|
|
135
|
-
|
|
136
|
-
try {
|
|
137
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
138
|
-
var element = _step.value;
|
|
139
|
-
this[element] = this.config.logger[element];
|
|
140
|
-
} // Bind helper functions for each log level
|
|
103
|
+
const methods = Object.keys(this.config.logger).filter(key => !omittedLoggerKeys.has(key));
|
|
141
104
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
_iterator.f();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
var _iterator2 = _createForOfIteratorHelper(levels),
|
|
149
|
-
_step2;
|
|
105
|
+
for (const element of methods) {
|
|
106
|
+
this[element] = this.config.logger[element];
|
|
107
|
+
} // Bind helper functions for each log level
|
|
150
108
|
|
|
151
|
-
try {
|
|
152
|
-
var _loop = function _loop() {
|
|
153
|
-
var element = _step2.value;
|
|
154
109
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
110
|
+
for (const element of levels) {
|
|
111
|
+
this[element] = function () {
|
|
112
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
113
|
+
args[_key] = arguments[_key];
|
|
114
|
+
}
|
|
159
115
|
|
|
160
|
-
|
|
161
|
-
};
|
|
116
|
+
return _this.log(element, ...Array.prototype.slice.call(args));
|
|
162
117
|
};
|
|
118
|
+
} // We could have used `auto-bind` but it's not compiled for browser
|
|
163
119
|
|
|
164
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
165
|
-
_loop();
|
|
166
|
-
} // We could have used `auto-bind` but it's not compiled for browser
|
|
167
|
-
|
|
168
|
-
} catch (err) {
|
|
169
|
-
_iterator2.e(err);
|
|
170
|
-
} finally {
|
|
171
|
-
_iterator2.f();
|
|
172
|
-
}
|
|
173
120
|
|
|
174
121
|
this.setLevel = this.setLevel.bind(this);
|
|
175
122
|
this.getNormalizedLevel = this.getNormalizedLevel.bind(this);
|
|
@@ -184,205 +131,201 @@ var Axe = /*#__PURE__*/function () {
|
|
|
184
131
|
this.warning = this.warn;
|
|
185
132
|
}
|
|
186
133
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
this.config.callback = callback;
|
|
191
|
-
}
|
|
192
|
-
}, {
|
|
193
|
-
key: "setLevel",
|
|
194
|
-
value: function setLevel(level) {
|
|
195
|
-
if (!isString(level) || !levels.includes(level)) throw new Error(levelError); // Support signale logger and other loggers that use `logLevel`
|
|
134
|
+
setCallback(callback) {
|
|
135
|
+
this.config.callback = callback;
|
|
136
|
+
}
|
|
196
137
|
|
|
197
|
-
|
|
198
|
-
|
|
138
|
+
setLevel(level) {
|
|
139
|
+
if (!isString(level) || !levels.includes(level)) throw new Error(levelError); // Support signale logger and other loggers that use `logLevel`
|
|
199
140
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}, {
|
|
203
|
-
key: "getNormalizedLevel",
|
|
204
|
-
value: function getNormalizedLevel(level) {
|
|
205
|
-
if (!isString(level)) return 'info';
|
|
206
|
-
if (isString(aliases[level])) return aliases[level];
|
|
207
|
-
if (!levels.includes(level)) return 'info';
|
|
208
|
-
return level;
|
|
209
|
-
}
|
|
210
|
-
}, {
|
|
211
|
-
key: "setName",
|
|
212
|
-
value: function setName(name) {
|
|
213
|
-
if (!isString(name)) throw new Error('`name` must be a String'); // Support signale logger and other loggers that use `scope`
|
|
214
|
-
|
|
215
|
-
if (isString(this.config.logger.scope)) this.config.logger.scope = name;else this.config.logger.name = name;
|
|
216
|
-
} // eslint-disable-next-line complexity
|
|
217
|
-
|
|
218
|
-
}, {
|
|
219
|
-
key: "log",
|
|
220
|
-
value: function log(level, message, meta) {
|
|
221
|
-
var _this2 = this;
|
|
222
|
-
|
|
223
|
-
var originalArgs = [];
|
|
224
|
-
if (!isUndefined(level)) originalArgs.push(level);
|
|
225
|
-
if (!isUndefined(message)) originalArgs.push(message);
|
|
226
|
-
if (!isUndefined(meta)) originalArgs.push(meta);
|
|
227
|
-
|
|
228
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
|
229
|
-
args[_key2 - 3] = arguments[_key2];
|
|
230
|
-
}
|
|
141
|
+
if (isString(this.config.logger.logLevel)) this.config.logger.logLevel = level;else this.config.logger.level = level; // Adjusts `this.config.levels` array
|
|
142
|
+
// so that it has all proceeding (inclusive)
|
|
231
143
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
var modifier = 0;
|
|
144
|
+
this.config.levels = levels.slice(levels.indexOf(level));
|
|
145
|
+
}
|
|
235
146
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
} else if (!isString(level) || !levels.includes(level)) {
|
|
243
|
-
meta = message;
|
|
244
|
-
message = level;
|
|
245
|
-
level = this.getNormalizedLevel(level);
|
|
246
|
-
modifier = -1;
|
|
247
|
-
} // Bunyan support (meta, message, ...args)
|
|
147
|
+
getNormalizedLevel(level) {
|
|
148
|
+
if (!isString(level)) return 'info';
|
|
149
|
+
if (isString(aliases[level])) return aliases[level];
|
|
150
|
+
if (!levels.includes(level)) return 'info';
|
|
151
|
+
return level;
|
|
152
|
+
}
|
|
248
153
|
|
|
154
|
+
setName(name) {
|
|
155
|
+
if (!isString(name)) throw new Error('`name` must be a String'); // Support signale logger and other loggers that use `scope`
|
|
249
156
|
|
|
250
|
-
|
|
157
|
+
if (isString(this.config.logger.scope)) this.config.logger.scope = name;else this.config.logger.name = name;
|
|
158
|
+
} // eslint-disable-next-line complexity
|
|
251
159
|
|
|
252
|
-
if ((isObject(message) || Array.isArray(message)) && isString(meta)) {
|
|
253
|
-
isBunyan = true;
|
|
254
|
-
var _meta = meta;
|
|
255
|
-
meta = message;
|
|
256
|
-
message = isString(_meta) && originalArgs.length >= 3 + modifier ? format.apply(void 0, _toConsumableArray(originalArgs.slice(2 + modifier))) : _meta;
|
|
257
|
-
} // If message was undefined then set it to level
|
|
258
160
|
|
|
161
|
+
log(level, message, meta) {
|
|
162
|
+
const originalArgs = [];
|
|
163
|
+
if (!isUndefined(level)) originalArgs.push(level);
|
|
164
|
+
if (!isUndefined(message)) originalArgs.push(message);
|
|
165
|
+
if (!isUndefined(meta)) originalArgs.push(meta);
|
|
259
166
|
|
|
260
|
-
|
|
261
|
-
|
|
167
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
|
168
|
+
args[_key2 - 3] = arguments[_key2];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
for (const arg of Array.prototype.slice.call(args)) {
|
|
172
|
+
originalArgs.push(arg);
|
|
173
|
+
}
|
|
262
174
|
|
|
263
|
-
|
|
175
|
+
const {
|
|
176
|
+
config
|
|
177
|
+
} = this;
|
|
178
|
+
let modifier = 0;
|
|
179
|
+
|
|
180
|
+
if (isString(level) && isString(aliases[level])) {
|
|
181
|
+
level = aliases[level];
|
|
182
|
+
} else if (isError(level)) {
|
|
183
|
+
meta = message;
|
|
184
|
+
message = level;
|
|
185
|
+
level = 'error';
|
|
186
|
+
} else if (!isString(level) || !levels.includes(level)) {
|
|
187
|
+
meta = message;
|
|
188
|
+
message = level;
|
|
189
|
+
level = this.getNormalizedLevel(level);
|
|
190
|
+
modifier = -1;
|
|
191
|
+
} // Bunyan support (meta, message, ...args)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
let isBunyan = false;
|
|
195
|
+
|
|
196
|
+
if ((isObject(message) || Array.isArray(message)) && isString(meta)) {
|
|
197
|
+
isBunyan = true;
|
|
198
|
+
const _meta = meta;
|
|
199
|
+
meta = message;
|
|
200
|
+
message = isString(_meta) && originalArgs.length >= 3 + modifier ? format(...originalArgs.slice(2 + modifier)) : _meta;
|
|
201
|
+
} // If message was undefined then set it to level
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
if (isUndefined(message)) message = level; // If only `message` was passed then if it was an Object
|
|
205
|
+
// preserve it as an Object by setting it as meta
|
|
206
|
+
|
|
207
|
+
if (originalArgs.slice(1 + modifier).length === 1 && !isString(message) && !isError(message)) {
|
|
208
|
+
meta = {
|
|
209
|
+
message
|
|
210
|
+
};
|
|
211
|
+
message = level;
|
|
212
|
+
} else if (!isBunyan && originalArgs.length >= 4 + modifier) {
|
|
213
|
+
// If there are four or more args
|
|
214
|
+
// then infer to use util.format on everything
|
|
215
|
+
message = format(...originalArgs.slice(1 + modifier));
|
|
216
|
+
meta = {};
|
|
217
|
+
} else if (!isBunyan && originalArgs.length === 3 + modifier && isString(message) && formatSpecifiers.some(t => message.includes(t))) {
|
|
218
|
+
// Otherwise if there are three args and if the `message` contains
|
|
219
|
+
// a placeholder token (e.g. '%s' or '%d' - see above `formatSpecifiers` variable)
|
|
220
|
+
// then we can infer that the `meta` arg passed is used for formatting
|
|
221
|
+
message = format(message, meta);
|
|
222
|
+
meta = {};
|
|
223
|
+
} else if (!isError(message)) {
|
|
224
|
+
if (isError(meta)) {
|
|
264
225
|
meta = {
|
|
265
|
-
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
// If there are four or more args
|
|
270
|
-
// then infer to use util.format on everything
|
|
271
|
-
message = format.apply(void 0, _toConsumableArray(originalArgs.slice(1 + modifier)));
|
|
272
|
-
meta = {};
|
|
273
|
-
} else if (!isBunyan && originalArgs.length === 3 + modifier && isString(message) && formatSpecifiers.filter(function (t) {
|
|
274
|
-
return message.includes(t);
|
|
275
|
-
}).length > 0) {
|
|
276
|
-
// Otherwise if there are three args and if the `message` contains
|
|
277
|
-
// a placeholder token (e.g. '%s' or '%d' - see above `formatSpecifiers` variable)
|
|
278
|
-
// then we can infer that the `meta` arg passed is used for formatting
|
|
226
|
+
err: parseErr(meta)
|
|
227
|
+
}; // } else if (!isPlainObject(meta) && !isUndefined(meta) && !isNull(meta)) {
|
|
228
|
+
} else if (!isObject(meta) && !isUndefined(meta) && !isNull(meta)) {
|
|
229
|
+
// If the `meta` variable passed was not an Object then convert it
|
|
279
230
|
message = format(message, meta);
|
|
280
231
|
meta = {};
|
|
281
|
-
} else if (!
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
message = format(message, meta);
|
|
289
|
-
meta = {};
|
|
290
|
-
} else if (!isString(message)) {
|
|
291
|
-
// If the message is not a string then we should run `util.format` on it
|
|
292
|
-
// assuming we're formatting it like it was another argument
|
|
293
|
-
// (as opposed to using something like fast-json-stringify)
|
|
294
|
-
message = format(message);
|
|
295
|
-
}
|
|
296
|
-
} // If (!isPlainObject(meta)) meta = {};
|
|
297
|
-
|
|
232
|
+
} else if (!isString(message)) {
|
|
233
|
+
// If the message is not a string then we should run `util.format` on it
|
|
234
|
+
// assuming we're formatting it like it was another argument
|
|
235
|
+
// (as opposed to using something like fast-json-stringify)
|
|
236
|
+
message = format(message);
|
|
237
|
+
}
|
|
238
|
+
} // If (!isPlainObject(meta)) meta = {};
|
|
298
239
|
|
|
299
|
-
if (!isUndefined(meta) && !isObject(meta)) meta = {
|
|
300
|
-
meta: meta
|
|
301
|
-
};else if (!isObject(meta)) meta = {};
|
|
302
|
-
var error;
|
|
303
240
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
} else if (isError(meta.err)) {
|
|
310
|
-
error = meta.err;
|
|
311
|
-
} // Omit `callback` from `meta` if it was passed
|
|
241
|
+
if (!isUndefined(meta) && !isObject(meta)) meta = {
|
|
242
|
+
meta
|
|
243
|
+
};else if (!isObject(meta)) meta = {};
|
|
244
|
+
const hadErrorInMeta = isObject(meta.err);
|
|
245
|
+
let error;
|
|
312
246
|
|
|
247
|
+
if (isError(message)) {
|
|
248
|
+
error = message;
|
|
249
|
+
if (!hadErrorInMeta) meta.err = parseErr(error);
|
|
250
|
+
({
|
|
251
|
+
message
|
|
252
|
+
} = message);
|
|
253
|
+
} else if (isError(meta.err)) {
|
|
254
|
+
error = meta.err;
|
|
255
|
+
} // Omit `callback` from `meta` if it was passed
|
|
313
256
|
|
|
314
|
-
var callback = isFunction(config.callback) && (!isBoolean(meta.callback) || meta.callback);
|
|
315
|
-
meta = omit(meta, ['callback']); // Set default level on meta
|
|
316
257
|
|
|
317
|
-
|
|
258
|
+
const callback = isFunction(config.callback) && (!isBoolean(meta.callback) || meta.callback);
|
|
259
|
+
meta = omit(meta, ['callback']); // Set default level on meta
|
|
318
260
|
|
|
319
|
-
|
|
320
|
-
// (and also remove circular references)
|
|
261
|
+
meta.level = level; // Add `app` object to metadata
|
|
321
262
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
meta: meta
|
|
325
|
-
}); // Send to Cabin or other logging service here the `message` and `meta`
|
|
263
|
+
if (this.appInfo) meta.app = this.appInfo; // Set the body used for returning with and sending logs
|
|
264
|
+
// (and also remove circular references)
|
|
326
265
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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
|
|
266
|
+
const body = safeStringify({
|
|
267
|
+
message,
|
|
268
|
+
meta
|
|
269
|
+
}); // Send to Cabin or other logging service here the `message` and `meta`
|
|
332
270
|
|
|
333
|
-
|
|
334
|
-
|
|
271
|
+
if (config.capture && config.levels.includes(level) && (!isError(error) || !error._captureFailed)) {
|
|
272
|
+
// If the user didn't specify a key
|
|
273
|
+
// and they are using the default endpoint
|
|
274
|
+
// then we should throw an error to them
|
|
275
|
+
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
|
|
335
276
|
|
|
336
|
-
|
|
277
|
+
const request = superagent.post(config.endpoint).set('X-Request-Id', cuid()).timeout(config.timeout);
|
|
278
|
+
if (!process.browser) request.set('User-Agent', "axe/".concat(pkg.version)); // Basic auth (e.g. Cabin API key)
|
|
337
279
|
|
|
338
|
-
|
|
339
|
-
request.type('application/json').send(body).retry(config.retry).end(function (error_) {
|
|
340
|
-
if (error_) {
|
|
341
|
-
error_._captureFailed = true;
|
|
280
|
+
if (config.key) request.auth(config.key); // Set headers if any
|
|
342
281
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
282
|
+
if (!isEmpty(config.headers)) request.set(config.headers);
|
|
283
|
+
request.type('application/json').send(body).retry(config.retry).end(error_ => {
|
|
284
|
+
if (error_) {
|
|
285
|
+
error_._captureFailed = true;
|
|
286
|
+
this.config.logger.error(error_);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
} // Custom callback function (e.g. Slack message)
|
|
347
290
|
|
|
348
291
|
|
|
349
|
-
|
|
292
|
+
if (callback) config.callback(level, message, meta); // Suppress logs if it was silent
|
|
350
293
|
|
|
351
|
-
|
|
294
|
+
if (config.silent) return body; // Return early if it is not a valid logging level
|
|
352
295
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
296
|
+
if (!config.levels.includes(level)) return body; //
|
|
297
|
+
// determine log method to use
|
|
298
|
+
//
|
|
299
|
+
// if we didn't pass a level as a method
|
|
300
|
+
// (e.g. console.info), then we should still
|
|
301
|
+
// use the logger's `log` method to output
|
|
302
|
+
//
|
|
303
|
+
// and fatal should use error (e.g. in browser)
|
|
304
|
+
//
|
|
362
305
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
306
|
+
let method = level;
|
|
307
|
+
if (modifier === -1) method = 'log';else if (level === 'fatal') method = 'error'; // If there was meta information then output it
|
|
308
|
+
// setup ommitted fields
|
|
366
309
|
|
|
367
|
-
|
|
310
|
+
const omittedFields = [...this.config.meta.omittedFields];
|
|
311
|
+
omittedFields.push('level');
|
|
312
|
+
if (!hadErrorInMeta) omittedFields.push('err'); // Omit app is configured
|
|
368
313
|
|
|
369
|
-
|
|
370
|
-
|
|
314
|
+
if (!this.config.meta.showApp) omittedFields.push('app');
|
|
315
|
+
const omitted = omit(meta, omittedFields); // Show stack trace if necessary (along with any metadata)
|
|
371
316
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
317
|
+
if (isError(error) && config.showStack) {
|
|
318
|
+
if (!config.meta.show || isEmpty(omitted)) this.config.logger[method](error);else this.config.logger[method](error, omitted);
|
|
319
|
+
} else if (!config.meta.show || isEmpty(omitted)) {
|
|
320
|
+
this.config.logger[method](message);
|
|
321
|
+
} else {
|
|
322
|
+
this.config.logger[method](message, omitted);
|
|
323
|
+
} // Return the parsed body in case we need it
|
|
379
324
|
|
|
380
325
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
}]);
|
|
326
|
+
return body;
|
|
327
|
+
}
|
|
384
328
|
|
|
385
|
-
|
|
386
|
-
}();
|
|
329
|
+
}
|
|
387
330
|
|
|
388
331
|
module.exports = Axe;
|