@honeybadger-io/js 5.1.5-alpha-3 → 5.2.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.
@@ -1,1879 +0,0 @@
1
- import require$$0$1 from 'os';
2
- import require$$1$1 from 'domain';
3
- import require$$1 from 'fs';
4
- import require$$2 from 'util';
5
- import require$$0$2 from 'url';
6
- import require$$2$1 from 'http';
7
- import require$$3 from 'https';
8
-
9
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
10
-
11
- function getDefaultExportFromCjs (x) {
12
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
13
- }
14
-
15
- function getAugmentedNamespace(n) {
16
- var f = n.default;
17
- if (typeof f == "function") {
18
- var a = function () {
19
- return f.apply(this, arguments);
20
- };
21
- a.prototype = f.prototype;
22
- } else a = {};
23
- Object.defineProperty(a, '__esModule', {value: true});
24
- Object.keys(n).forEach(function (k) {
25
- var d = Object.getOwnPropertyDescriptor(n, k);
26
- Object.defineProperty(a, k, d.get ? d : {
27
- enumerable: true,
28
- get: function () {
29
- return n[k];
30
- }
31
- });
32
- });
33
- return a;
34
- }
35
-
36
- var server$1 = {};
37
-
38
- var src = {};
39
-
40
- var client = {};
41
-
42
- var util$1 = {};
43
-
44
- var UNKNOWN_FUNCTION = '<unknown>';
45
- /**
46
- * This parses the different stack traces and puts them into one format
47
- * This borrows heavily from TraceKit (https://github.com/csnover/TraceKit)
48
- */
49
-
50
- function parse(stackString) {
51
- var lines = stackString.split('\n');
52
- return lines.reduce(function (stack, line) {
53
- var parseResult = parseChrome(line) || parseWinjs(line) || parseGecko(line) || parseNode(line) || parseJSC(line);
54
-
55
- if (parseResult) {
56
- stack.push(parseResult);
57
- }
58
-
59
- return stack;
60
- }, []);
61
- }
62
- var chromeRe = /^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/|[a-z]:\\|\\\\).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
63
- var chromeEvalRe = /\((\S*)(?::(\d+))(?::(\d+))\)/;
64
-
65
- function parseChrome(line) {
66
- var parts = chromeRe.exec(line);
67
-
68
- if (!parts) {
69
- return null;
70
- }
71
-
72
- var isNative = parts[2] && parts[2].indexOf('native') === 0; // start of line
73
-
74
- var isEval = parts[2] && parts[2].indexOf('eval') === 0; // start of line
75
-
76
- var submatch = chromeEvalRe.exec(parts[2]);
77
-
78
- if (isEval && submatch != null) {
79
- // throw out eval line/column and use top-most line/column number
80
- parts[2] = submatch[1]; // url
81
-
82
- parts[3] = submatch[2]; // line
83
-
84
- parts[4] = submatch[3]; // column
85
- }
86
-
87
- return {
88
- file: !isNative ? parts[2] : null,
89
- methodName: parts[1] || UNKNOWN_FUNCTION,
90
- arguments: isNative ? [parts[2]] : [],
91
- lineNumber: parts[3] ? +parts[3] : null,
92
- column: parts[4] ? +parts[4] : null
93
- };
94
- }
95
-
96
- var winjsRe = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
97
-
98
- function parseWinjs(line) {
99
- var parts = winjsRe.exec(line);
100
-
101
- if (!parts) {
102
- return null;
103
- }
104
-
105
- return {
106
- file: parts[2],
107
- methodName: parts[1] || UNKNOWN_FUNCTION,
108
- arguments: [],
109
- lineNumber: +parts[3],
110
- column: parts[4] ? +parts[4] : null
111
- };
112
- }
113
-
114
- var geckoRe = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i;
115
- var geckoEvalRe = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
116
-
117
- function parseGecko(line) {
118
- var parts = geckoRe.exec(line);
119
-
120
- if (!parts) {
121
- return null;
122
- }
123
-
124
- var isEval = parts[3] && parts[3].indexOf(' > eval') > -1;
125
- var submatch = geckoEvalRe.exec(parts[3]);
126
-
127
- if (isEval && submatch != null) {
128
- // throw out eval line/column and use top-most line number
129
- parts[3] = submatch[1];
130
- parts[4] = submatch[2];
131
- parts[5] = null; // no column when eval
132
- }
133
-
134
- return {
135
- file: parts[3],
136
- methodName: parts[1] || UNKNOWN_FUNCTION,
137
- arguments: parts[2] ? parts[2].split(',') : [],
138
- lineNumber: parts[4] ? +parts[4] : null,
139
- column: parts[5] ? +parts[5] : null
140
- };
141
- }
142
-
143
- var javaScriptCoreRe = /^\s*(?:([^@]*)(?:\((.*?)\))?@)?(\S.*?):(\d+)(?::(\d+))?\s*$/i;
144
-
145
- function parseJSC(line) {
146
- var parts = javaScriptCoreRe.exec(line);
147
-
148
- if (!parts) {
149
- return null;
150
- }
151
-
152
- return {
153
- file: parts[3],
154
- methodName: parts[1] || UNKNOWN_FUNCTION,
155
- arguments: [],
156
- lineNumber: +parts[4],
157
- column: parts[5] ? +parts[5] : null
158
- };
159
- }
160
-
161
- var nodeRe = /^\s*at (?:((?:\[object object\])?[^\\/]+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$/i;
162
-
163
- function parseNode(line) {
164
- var parts = nodeRe.exec(line);
165
-
166
- if (!parts) {
167
- return null;
168
- }
169
-
170
- return {
171
- file: parts[2],
172
- methodName: parts[1] || UNKNOWN_FUNCTION,
173
- arguments: [],
174
- lineNumber: +parts[3],
175
- column: parts[4] ? +parts[4] : null
176
- };
177
- }
178
-
179
- var stackTraceParser_esm = /*#__PURE__*/Object.freeze({
180
- __proto__: null,
181
- parse: parse
182
- });
183
-
184
- var require$$0 = /*@__PURE__*/getAugmentedNamespace(stackTraceParser_esm);
185
-
186
- (function (exports) {
187
- var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
188
- if (k2 === undefined) k2 = k;
189
- var desc = Object.getOwnPropertyDescriptor(m, k);
190
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
191
- desc = { enumerable: true, get: function() { return m[k]; } };
192
- }
193
- Object.defineProperty(o, k2, desc);
194
- }) : (function(o, m, k, k2) {
195
- if (k2 === undefined) k2 = k;
196
- o[k2] = m[k];
197
- }));
198
- var __setModuleDefault = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) {
199
- Object.defineProperty(o, "default", { enumerable: true, value: v });
200
- }) : function(o, v) {
201
- o["default"] = v;
202
- });
203
- var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
204
- if (mod && mod.__esModule) return mod;
205
- var result = {};
206
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
207
- __setModuleDefault(result, mod);
208
- return result;
209
- };
210
- var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
211
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
212
- return new (P || (P = Promise))(function (resolve, reject) {
213
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
214
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
215
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
216
- step((generator = generator.apply(thisArg, _arguments || [])).next());
217
- });
218
- };
219
- var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
220
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
221
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
222
- function verb(n) { return function (v) { return step([n, v]); }; }
223
- function step(op) {
224
- if (f) throw new TypeError("Generator is already executing.");
225
- while (_) try {
226
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
227
- if (y = 0, t) op = [op[0] & 2, t.value];
228
- switch (op[0]) {
229
- case 0: case 1: t = op; break;
230
- case 4: _.label++; return { value: op[1], done: false };
231
- case 5: _.label++; y = op[1]; op = [0]; continue;
232
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
233
- default:
234
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
235
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
236
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
237
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
238
- if (t[2]) _.ops.pop();
239
- _.trys.pop(); continue;
240
- }
241
- op = body.call(thisArg, _);
242
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
243
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
244
- }
245
- };
246
- Object.defineProperty(exports, "__esModule", { value: true });
247
- exports.isBrowserConfig = exports.clone = exports.formatCGIData = exports.filterUrl = exports.filter = exports.generateStackTrace = exports.endpoint = exports.instrument = exports.isErrorObject = exports.makeNotice = exports.logger = exports.sanitize = exports.shallowClone = exports.runAfterNotifyHandlers = exports.runBeforeNotifyHandlers = exports.getSourceForBacktrace = exports.getCauses = exports.calculateBacktraceShift = exports.DEFAULT_BACKTRACE_SHIFT = exports.makeBacktrace = exports.objectIsExtensible = exports.objectIsEmpty = exports.mergeNotice = exports.merge = void 0;
248
- var stackTraceParser = __importStar(require$$0);
249
- function merge(obj1, obj2) {
250
- var result = {};
251
- for (var k in obj1) {
252
- result[k] = obj1[k];
253
- }
254
- for (var k in obj2) {
255
- result[k] = obj2[k];
256
- }
257
- return result;
258
- }
259
- exports.merge = merge;
260
- function mergeNotice(notice1, notice2) {
261
- var result = merge(notice1, notice2);
262
- if (notice1.context && notice2.context) {
263
- result.context = merge(notice1.context, notice2.context);
264
- }
265
- return result;
266
- }
267
- exports.mergeNotice = mergeNotice;
268
- function objectIsEmpty(obj) {
269
- for (var k in obj) {
270
- if (Object.prototype.hasOwnProperty.call(obj, k)) {
271
- return false;
272
- }
273
- }
274
- return true;
275
- }
276
- exports.objectIsEmpty = objectIsEmpty;
277
- function objectIsExtensible(obj) {
278
- if (typeof Object.isExtensible !== 'function') {
279
- return true;
280
- }
281
- return Object.isExtensible(obj);
282
- }
283
- exports.objectIsExtensible = objectIsExtensible;
284
- function makeBacktrace(stack, filterHbSourceCode, logger) {
285
- if (filterHbSourceCode === void 0) { filterHbSourceCode = false; }
286
- if (logger === void 0) { logger = console; }
287
- try {
288
- var backtrace = stackTraceParser
289
- .parse(stack)
290
- .map(function (line) {
291
- return {
292
- file: line.file,
293
- method: line.methodName,
294
- number: line.lineNumber,
295
- column: line.column
296
- };
297
- });
298
- if (filterHbSourceCode) {
299
- backtrace.splice(0, calculateBacktraceShift(backtrace));
300
- }
301
- return backtrace;
302
- }
303
- catch (err) {
304
- logger.debug(err);
305
- return [];
306
- }
307
- }
308
- exports.makeBacktrace = makeBacktrace;
309
- function isFrameFromHbSourceCode(frame) {
310
- var hasHbFile = false;
311
- var hasHbMethod = false;
312
- if (frame.file) {
313
- hasHbFile = frame.file.toLowerCase().indexOf('@honeybadger-io') > -1;
314
- }
315
- if (frame.method) {
316
- hasHbMethod = frame.method.toLowerCase().indexOf('@honeybadger-io') > -1;
317
- }
318
- return hasHbFile || hasHbMethod;
319
- }
320
- exports.DEFAULT_BACKTRACE_SHIFT = 3;
321
- /**
322
- * If {@link generateStackTrace} is used, we want to exclude frames that come from
323
- * Honeybadger's source code.
324
- *
325
- * Logic:
326
- * - For each frame, increment the shift if source code is from Honeybadger
327
- * - If a frame from an <anonymous> file is encountered increment the shift ONLY if between Honeybadger source code
328
- * (i.e. previous and next frames are from Honeybadger)
329
- * - Exit when frame encountered is not from Honeybadger source code
330
- *
331
- * Note: this will not always work, especially in browser versions where code
332
- * is minified, uglified and bundled.
333
- * For those cases we default to 3:
334
- * - generateStackTrace
335
- * - makeNotice
336
- * - notify
337
- */
338
- function calculateBacktraceShift(backtrace) {
339
- var shift = 0;
340
- for (var i = 0; i < backtrace.length; i++) {
341
- var frame = backtrace[i];
342
- if (isFrameFromHbSourceCode(frame)) {
343
- shift++;
344
- continue;
345
- }
346
- if (!frame.file || frame.file === '<anonymous>') {
347
- var nextFrame = backtrace[i + 1];
348
- if (nextFrame && isFrameFromHbSourceCode(nextFrame)) {
349
- shift++;
350
- continue;
351
- }
352
- }
353
- break;
354
- }
355
- return shift || exports.DEFAULT_BACKTRACE_SHIFT;
356
- }
357
- exports.calculateBacktraceShift = calculateBacktraceShift;
358
- function getCauses(notice, logger) {
359
- if (notice.cause) {
360
- var causes = [];
361
- var cause = notice;
362
- while (causes.length < 3 && (cause = cause.cause)) {
363
- causes.push({
364
- class: cause.name,
365
- message: cause.message,
366
- backtrace: typeof cause.stack == 'string' ? makeBacktrace(cause.stack, false, logger) : null
367
- });
368
- }
369
- return causes;
370
- }
371
- return [];
372
- }
373
- exports.getCauses = getCauses;
374
- function getSourceForBacktrace(backtrace, getSourceFileHandler) {
375
- return __awaiter(this, void 0, void 0, function () {
376
- var result, index, trace, fileContent;
377
- return __generator(this, function (_a) {
378
- switch (_a.label) {
379
- case 0:
380
- result = [];
381
- if (!getSourceFileHandler || !backtrace || !backtrace.length) {
382
- return [2 /*return*/, result];
383
- }
384
- index = 0;
385
- _a.label = 1;
386
- case 1:
387
- if (!backtrace.length) return [3 /*break*/, 3];
388
- trace = backtrace.splice(0)[index];
389
- return [4 /*yield*/, getSourceFileHandler(trace.file)];
390
- case 2:
391
- fileContent = _a.sent();
392
- result[index] = getSourceCodeSnippet(fileContent, trace.number);
393
- index++;
394
- return [3 /*break*/, 1];
395
- case 3: return [2 /*return*/, result];
396
- }
397
- });
398
- });
399
- }
400
- exports.getSourceForBacktrace = getSourceForBacktrace;
401
- function runBeforeNotifyHandlers(notice, handlers) {
402
- var result = true;
403
- for (var i = 0, len = handlers.length; i < len; i++) {
404
- var handler = handlers[i];
405
- if (handler(notice) === false) {
406
- result = false;
407
- }
408
- }
409
- return result;
410
- }
411
- exports.runBeforeNotifyHandlers = runBeforeNotifyHandlers;
412
- function runAfterNotifyHandlers(notice, handlers, error) {
413
- if (notice && notice.afterNotify) {
414
- notice.afterNotify(error, notice);
415
- }
416
- for (var i = 0, len = handlers.length; i < len; i++) {
417
- handlers[i](error, notice);
418
- }
419
- return true;
420
- }
421
- exports.runAfterNotifyHandlers = runAfterNotifyHandlers;
422
- // Returns a new object with properties from other object.
423
- function shallowClone(obj) {
424
- if (typeof (obj) !== 'object' || obj === null) {
425
- return {};
426
- }
427
- var result = {};
428
- for (var k in obj) {
429
- result[k] = obj[k];
430
- }
431
- return result;
432
- }
433
- exports.shallowClone = shallowClone;
434
- function sanitize(obj, maxDepth) {
435
- if (maxDepth === void 0) { maxDepth = 8; }
436
- var seenObjects = [];
437
- function seen(obj) {
438
- if (!obj || typeof (obj) !== 'object') {
439
- return false;
440
- }
441
- for (var i = 0; i < seenObjects.length; i++) {
442
- var value = seenObjects[i];
443
- if (value === obj) {
444
- return true;
445
- }
446
- }
447
- seenObjects.push(obj);
448
- return false;
449
- }
450
- function canSerialize(obj) {
451
- var typeOfObj = typeof obj;
452
- // Functions are TMI
453
- if (/function/.test(typeOfObj)) {
454
- // Let special toJSON method pass as it's used by JSON.stringify (#722)
455
- return obj.name === 'toJSON';
456
- }
457
- // Symbols can't convert to strings.
458
- if (/symbol/.test(typeOfObj)) {
459
- return false;
460
- }
461
- if (obj === null) {
462
- return false;
463
- }
464
- // No prototype, likely created with `Object.create(null)`.
465
- if (typeof obj === 'object' && typeof obj.hasOwnProperty === 'undefined') {
466
- return false;
467
- }
468
- return true;
469
- }
470
- function serialize(obj, depth) {
471
- if (depth === void 0) { depth = 0; }
472
- if (depth >= maxDepth) {
473
- return '[DEPTH]';
474
- }
475
- // Inspect invalid types
476
- if (!canSerialize(obj)) {
477
- return Object.prototype.toString.call(obj);
478
- }
479
- // Halt circular references
480
- if (seen(obj)) {
481
- return '[RECURSION]';
482
- }
483
- // Serialize inside arrays
484
- if (Array.isArray(obj)) {
485
- return obj.map(function (o) { return safeSerialize(o, depth + 1); });
486
- }
487
- // Serialize inside objects
488
- if (typeof (obj) === 'object') {
489
- var ret = {};
490
- for (var k in obj) {
491
- var v = obj[k];
492
- if (Object.prototype.hasOwnProperty.call(obj, k) && (k != null) && (v != null)) {
493
- ret[k] = safeSerialize(v, depth + 1);
494
- }
495
- }
496
- return ret;
497
- }
498
- // Return everything else untouched
499
- return obj;
500
- }
501
- function safeSerialize(obj, depth) {
502
- if (depth === void 0) { depth = 0; }
503
- try {
504
- return serialize(obj, depth);
505
- }
506
- catch (e) {
507
- return "[ERROR] ".concat(e);
508
- }
509
- }
510
- return safeSerialize(obj);
511
- }
512
- exports.sanitize = sanitize;
513
- function logger(client) {
514
- var log = function (method) {
515
- return function () {
516
- var _a;
517
- var args = [];
518
- for (var _i = 0; _i < arguments.length; _i++) {
519
- args[_i] = arguments[_i];
520
- }
521
- if (method === 'debug') {
522
- if (!client.config.debug) {
523
- return;
524
- }
525
- // Log at default level so that you don't need to also enable verbose
526
- // logging in Chrome.
527
- method = 'log';
528
- }
529
- args.unshift('[Honeybadger]');
530
- (_a = client.config.logger)[method].apply(_a, args);
531
- };
532
- };
533
- return {
534
- log: log('log'),
535
- info: log('info'),
536
- debug: log('debug'),
537
- warn: log('warn'),
538
- error: log('error')
539
- };
540
- }
541
- exports.logger = logger;
542
- /**
543
- * Converts any object into a notice object (which at minimum has the same
544
- * properties as Error, but supports additional Honeybadger properties.)
545
- */
546
- function makeNotice(thing) {
547
- var notice;
548
- if (!thing) {
549
- notice = {};
550
- }
551
- else if (isErrorObject(thing)) {
552
- var e = thing;
553
- notice = merge(thing, { name: e.name, message: e.message, stack: e.stack, cause: e.cause });
554
- }
555
- else if (typeof thing === 'object') {
556
- notice = shallowClone(thing);
557
- }
558
- else {
559
- var m = String(thing);
560
- notice = { message: m };
561
- }
562
- return notice;
563
- }
564
- exports.makeNotice = makeNotice;
565
- function isErrorObject(thing) {
566
- return thing instanceof Error
567
- || Object.prototype.toString.call(thing) === '[object Error]'; // Important for cross-realm objects
568
- }
569
- exports.isErrorObject = isErrorObject;
570
- /**
571
- * Instrument an existing function inside an object (usually global).
572
- * @param {!Object} object
573
- * @param {!String} name
574
- * @param {!Function} replacement
575
- */
576
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
577
- function instrument(object, name, replacement) {
578
- if (!object || !name || !replacement || !(name in object)) {
579
- return;
580
- }
581
- try {
582
- var original = object[name];
583
- while (original && original.__hb_original) {
584
- original = original.__hb_original;
585
- }
586
- object[name] = replacement(original);
587
- object[name].__hb_original = original;
588
- }
589
- catch (_e) {
590
- // Ignores errors where "original" is a restricted object (see #1001)
591
- // Uncaught Error: Permission denied to access property "__hb_original"
592
- // Also ignores:
593
- // Error: TypeError: Cannot set property onunhandledrejection of [object Object] which has only a getter
594
- // User-Agent: Mozilla/5.0 (Linux; Android 10; SAMSUNG SM-G960F) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/12.1 Chrome/79.0.3945.136 Mobile Safari/537.36
595
- }
596
- }
597
- exports.instrument = instrument;
598
- function endpoint(base, path) {
599
- var endpoint = base.trim().replace(/\/$/, '');
600
- path = path.trim().replace(/(^\/|\/$)/g, '');
601
- return "".concat(endpoint, "/").concat(path);
602
- }
603
- exports.endpoint = endpoint;
604
- function generateStackTrace() {
605
- try {
606
- throw new Error('');
607
- }
608
- catch (e) {
609
- if (e.stack) {
610
- return e.stack;
611
- }
612
- }
613
- var maxStackSize = 10;
614
- var stack = [];
615
- var curr = arguments.callee;
616
- while (curr && stack.length < maxStackSize) {
617
- if (/function(?:\s+([\w$]+))+\s*\(/.test(curr.toString())) {
618
- stack.push(RegExp.$1 || '<anonymous>');
619
- }
620
- else {
621
- stack.push('<anonymous>');
622
- }
623
- try {
624
- curr = curr.caller;
625
- }
626
- catch (e) {
627
- break;
628
- }
629
- }
630
- return stack.join('\n');
631
- }
632
- exports.generateStackTrace = generateStackTrace;
633
- function filter(obj, filters) {
634
- if (!is('Object', obj)) {
635
- return;
636
- }
637
- if (!is('Array', filters)) {
638
- filters = [];
639
- }
640
- var seen = [];
641
- function filter(obj) {
642
- var k, newObj;
643
- if (is('Object', obj) || is('Array', obj)) {
644
- if (seen.indexOf(obj) !== -1) {
645
- return '[CIRCULAR DATA STRUCTURE]';
646
- }
647
- seen.push(obj);
648
- }
649
- if (is('Object', obj)) {
650
- newObj = {};
651
- for (k in obj) {
652
- if (filterMatch(k, filters)) {
653
- newObj[k] = '[FILTERED]';
654
- }
655
- else {
656
- newObj[k] = filter(obj[k]);
657
- }
658
- }
659
- return newObj;
660
- }
661
- if (is('Array', obj)) {
662
- return obj.map(function (v) {
663
- return filter(v);
664
- });
665
- }
666
- if (is('Function', obj)) {
667
- return '[FUNC]';
668
- }
669
- return obj;
670
- }
671
- return filter(obj);
672
- }
673
- exports.filter = filter;
674
- function filterMatch(key, filters) {
675
- for (var i = 0; i < filters.length; i++) {
676
- if (key.toLowerCase().indexOf(filters[i].toLowerCase()) !== -1) {
677
- return true;
678
- }
679
- }
680
- return false;
681
- }
682
- function is(type, obj) {
683
- var klass = Object.prototype.toString.call(obj).slice(8, -1);
684
- return obj !== undefined && obj !== null && klass === type;
685
- }
686
- function filterUrl(url, filters) {
687
- if (!filters) {
688
- return url;
689
- }
690
- if (typeof url !== 'string') {
691
- return url;
692
- }
693
- var query = url.split(/\?/, 2)[1];
694
- if (!query) {
695
- return url;
696
- }
697
- var result = url;
698
- query.split(/[&]\s?/).forEach(function (pair) {
699
- var _a = pair.split('=', 2), key = _a[0], value = _a[1];
700
- if (filterMatch(key, filters)) {
701
- result = result.replace("".concat(key, "=").concat(value), "".concat(key, "=[FILTERED]"));
702
- }
703
- });
704
- return result;
705
- }
706
- exports.filterUrl = filterUrl;
707
- function formatCGIData(vars, prefix) {
708
- if (prefix === void 0) { prefix = ''; }
709
- var formattedVars = {};
710
- Object.keys(vars).forEach(function (key) {
711
- var formattedKey = prefix + key.replace(/\W/g, '_').toUpperCase();
712
- formattedVars[formattedKey] = vars[key];
713
- });
714
- return formattedVars;
715
- }
716
- exports.formatCGIData = formatCGIData;
717
- function clone(obj) {
718
- return JSON.parse(JSON.stringify(obj));
719
- }
720
- exports.clone = clone;
721
- function getSourceCodeSnippet(fileData, lineNumber, sourceRadius) {
722
- if (sourceRadius === void 0) { sourceRadius = 2; }
723
- if (!fileData) {
724
- return null;
725
- }
726
- var lines = fileData.split('\n');
727
- // add one empty line because array index starts from 0, but error line number is counted from 1
728
- lines.unshift('');
729
- var start = lineNumber - sourceRadius;
730
- var end = lineNumber + sourceRadius;
731
- var result = {};
732
- for (var i = start; i <= end; i++) {
733
- var line = lines[i];
734
- if (typeof line === 'string') {
735
- result[i] = line;
736
- }
737
- }
738
- return result;
739
- }
740
- function isBrowserConfig(config) {
741
- return config.async !== undefined;
742
- }
743
- exports.isBrowserConfig = isBrowserConfig;
744
-
745
- } (util$1));
746
-
747
- var store = {};
748
-
749
- Object.defineProperty(store, "__esModule", { value: true });
750
- store.GlobalStore = void 0;
751
- var util_1$5 = util$1;
752
- var GlobalStore = /** @class */ (function () {
753
- function GlobalStore(contents, breadcrumbsLimit) {
754
- this.contents = contents;
755
- this.breadcrumbsLimit = breadcrumbsLimit;
756
- }
757
- GlobalStore.create = function (contents, breadcrumbsLimit) {
758
- return new GlobalStore(contents, breadcrumbsLimit);
759
- };
760
- GlobalStore.prototype.available = function () {
761
- return true;
762
- };
763
- GlobalStore.prototype.getContents = function (key) {
764
- var value = key ? this.contents[key] : this.contents;
765
- return JSON.parse(JSON.stringify(value));
766
- };
767
- GlobalStore.prototype.setContext = function (context) {
768
- this.contents.context = (0, util_1$5.merge)(this.contents.context, context || {});
769
- };
770
- GlobalStore.prototype.addBreadcrumb = function (breadcrumb) {
771
- if (this.contents.breadcrumbs.length == this.breadcrumbsLimit) {
772
- this.contents.breadcrumbs.shift();
773
- }
774
- this.contents.breadcrumbs.push(breadcrumb);
775
- };
776
- GlobalStore.prototype.clear = function () {
777
- this.contents.context = {};
778
- this.contents.breadcrumbs = [];
779
- };
780
- GlobalStore.prototype.run = function (callback) {
781
- return callback();
782
- };
783
- return GlobalStore;
784
- }());
785
- store.GlobalStore = GlobalStore;
786
-
787
- var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
788
- __assign = Object.assign || function(t) {
789
- for (var s, i = 1, n = arguments.length; i < n; i++) {
790
- s = arguments[i];
791
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
792
- t[p] = s[p];
793
- }
794
- return t;
795
- };
796
- return __assign.apply(this, arguments);
797
- };
798
- Object.defineProperty(client, "__esModule", { value: true });
799
- client.Client = void 0;
800
- var util_1$4 = util$1;
801
- var store_1 = store;
802
- var notifier = {
803
- name: 'honeybadger-js',
804
- url: 'https://github.com/honeybadger-io/honeybadger-js',
805
- version: '5.1.1'
806
- };
807
- // Split at commas and spaces
808
- var TAG_SEPARATOR = /,|\s+/;
809
- // Checks for non-blank characters
810
- var NOT_BLANK = /\S/;
811
- var Client = /** @class */ (function () {
812
- function Client(opts, transport) {
813
- if (opts === void 0) { opts = {}; }
814
- this.__pluginsExecuted = false;
815
- this.__store = null;
816
- this.__beforeNotifyHandlers = [];
817
- this.__afterNotifyHandlers = [];
818
- this.config = __assign({ apiKey: null, endpoint: 'https://api.honeybadger.io', environment: null, hostname: null, projectRoot: null, component: null, action: null, revision: null, reportData: null, breadcrumbsEnabled: true, maxBreadcrumbs: 40, maxObjectDepth: 8, logger: console, developmentEnvironments: ['dev', 'development', 'test'], debug: false, tags: null, enableUncaught: true, enableUnhandledRejection: true, afterUncaught: function () { return true; }, filters: ['creditcard', 'password'], __plugins: [] }, opts);
819
- this.__initStore();
820
- this.__transport = transport;
821
- this.logger = (0, util_1$4.logger)(this);
822
- }
823
- Client.prototype.getVersion = function () {
824
- return notifier.version;
825
- };
826
- Client.prototype.configure = function (opts) {
827
- var _this = this;
828
- if (opts === void 0) { opts = {}; }
829
- for (var k in opts) {
830
- this.config[k] = opts[k];
831
- }
832
- if (!this.__pluginsExecuted) {
833
- this.__pluginsExecuted = true;
834
- this.config.__plugins.forEach(function (plugin) { return plugin.load(_this); });
835
- }
836
- return this;
837
- };
838
- Client.prototype.__initStore = function () {
839
- this.__store = new store_1.GlobalStore({ context: {}, breadcrumbs: [] }, this.config.maxBreadcrumbs);
840
- };
841
- Client.prototype.beforeNotify = function (handler) {
842
- this.__beforeNotifyHandlers.push(handler);
843
- return this;
844
- };
845
- Client.prototype.afterNotify = function (handler) {
846
- this.__afterNotifyHandlers.push(handler);
847
- return this;
848
- };
849
- Client.prototype.setContext = function (context) {
850
- if (typeof context === 'object' && context != null) {
851
- this.__store.setContext(context);
852
- }
853
- return this;
854
- };
855
- Client.prototype.resetContext = function (context) {
856
- this.logger.warn('Deprecation warning: `Honeybadger.resetContext()` has been deprecated; please use `Honeybadger.clear()` instead.');
857
- this.__store.clear();
858
- if (typeof context === 'object' && context !== null) {
859
- this.__store.setContext(context);
860
- }
861
- return this;
862
- };
863
- Client.prototype.clear = function () {
864
- this.__store.clear();
865
- return this;
866
- };
867
- Client.prototype.notify = function (noticeable, name, extra) {
868
- var _this = this;
869
- if (name === void 0) { name = undefined; }
870
- if (extra === void 0) { extra = undefined; }
871
- var preConditionError = null;
872
- var notice = this.makeNotice(noticeable, name, extra);
873
- if (!notice) {
874
- this.logger.debug('failed to build error report');
875
- preConditionError = new Error('failed to build error report');
876
- }
877
- if (!preConditionError && this.config.reportData === false) {
878
- this.logger.debug('skipping error report: honeybadger.js is disabled', notice);
879
- preConditionError = new Error('honeybadger.js is disabled');
880
- }
881
- if (!preConditionError && this.__developmentMode()) {
882
- this.logger.log('honeybadger.js is in development mode; the following error report will be sent in production.', notice);
883
- preConditionError = new Error('honeybadger.js is in development mode');
884
- }
885
- if (!preConditionError && !this.config.apiKey) {
886
- this.logger.warn('could not send error report: no API key has been configured', notice);
887
- preConditionError = new Error('missing API key');
888
- }
889
- // we need to have the source file data before the beforeNotifyHandlers,
890
- // in case they modify them
891
- var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$4.shallowClone)(trace); }) : null;
892
- var beforeNotifyResult = (0, util_1$4.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
893
- if (!preConditionError && !beforeNotifyResult) {
894
- this.logger.debug('skipping error report: beforeNotify handlers returned false', notice);
895
- preConditionError = new Error('beforeNotify handlers returned false');
896
- }
897
- if (preConditionError) {
898
- (0, util_1$4.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionError);
899
- return false;
900
- }
901
- this.addBreadcrumb('Honeybadger Notice', {
902
- category: 'notice',
903
- metadata: {
904
- message: notice.message,
905
- name: notice.name,
906
- stack: notice.stack
907
- }
908
- });
909
- var breadcrumbs = this.__store.getContents('breadcrumbs');
910
- notice.__breadcrumbs = this.config.breadcrumbsEnabled ? breadcrumbs : [];
911
- (0, util_1$4.getSourceForBacktrace)(sourceCodeData, this.__getSourceFileHandler)
912
- .then(function (sourcePerTrace) {
913
- sourcePerTrace.forEach(function (source, index) {
914
- notice.backtrace[index].source = source;
915
- });
916
- var payload = _this.__buildPayload(notice);
917
- _this.__transport
918
- .send({
919
- headers: {
920
- 'X-API-Key': _this.config.apiKey,
921
- 'Content-Type': 'application/json',
922
- 'Accept': 'text/json, application/json'
923
- },
924
- method: 'POST',
925
- endpoint: (0, util_1$4.endpoint)(_this.config.endpoint, '/v1/notices/js'),
926
- maxObjectDepth: _this.config.maxObjectDepth,
927
- logger: _this.logger,
928
- }, payload)
929
- .then(function (res) {
930
- if (res.statusCode !== 201) {
931
- (0, util_1$4.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
932
- _this.logger.warn("Error report failed: unknown response from server. code=".concat(res.statusCode));
933
- return;
934
- }
935
- var uuid = JSON.parse(res.body).id;
936
- (0, util_1$4.runAfterNotifyHandlers)((0, util_1$4.merge)(notice, {
937
- id: uuid
938
- }), _this.__afterNotifyHandlers);
939
- _this.logger.info("Error report sent \u26A1 https://app.honeybadger.io/notice/".concat(uuid));
940
- })
941
- .catch(function (err) {
942
- _this.logger.error('Error report failed: an unknown error occurred.', "message=".concat(err.message));
943
- (0, util_1$4.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
944
- });
945
- });
946
- return true;
947
- };
948
- /**
949
- * An async version of {@link notify} that resolves only after the notice has been reported to Honeybadger.
950
- * Implemented using the {@link afterNotify} hook.
951
- * Rejects if for any reason the report failed to be reported.
952
- * Useful in serverless environments (AWS Lambda).
953
- */
954
- Client.prototype.notifyAsync = function (noticeable, name, extra) {
955
- var _this = this;
956
- if (name === void 0) { name = undefined; }
957
- if (extra === void 0) { extra = undefined; }
958
- return new Promise(function (resolve, reject) {
959
- var applyAfterNotify = function (partialNotice) {
960
- var originalAfterNotify = partialNotice.afterNotify;
961
- partialNotice.afterNotify = function (err) {
962
- originalAfterNotify === null || originalAfterNotify === void 0 ? void 0 : originalAfterNotify.call(_this, err);
963
- if (err) {
964
- return reject(err);
965
- }
966
- resolve();
967
- };
968
- };
969
- // We have to respect any afterNotify hooks that come from the arguments
970
- var objectToOverride;
971
- if (noticeable.afterNotify) {
972
- objectToOverride = noticeable;
973
- }
974
- else if (name && name.afterNotify) {
975
- objectToOverride = name;
976
- }
977
- else if (extra && extra.afterNotify) {
978
- objectToOverride = extra;
979
- }
980
- else if (name && typeof name === 'object') {
981
- objectToOverride = name;
982
- }
983
- else if (extra) {
984
- objectToOverride = extra;
985
- }
986
- else {
987
- objectToOverride = name = {};
988
- }
989
- applyAfterNotify(objectToOverride);
990
- _this.notify(noticeable, name, extra);
991
- });
992
- };
993
- Client.prototype.makeNotice = function (noticeable, name, extra) {
994
- if (name === void 0) { name = undefined; }
995
- if (extra === void 0) { extra = undefined; }
996
- var notice = (0, util_1$4.makeNotice)(noticeable);
997
- if (name && !(typeof name === 'object')) {
998
- var n = String(name);
999
- name = { name: n };
1000
- }
1001
- if (name) {
1002
- notice = (0, util_1$4.mergeNotice)(notice, name);
1003
- }
1004
- if (typeof extra === 'object' && extra !== null) {
1005
- notice = (0, util_1$4.mergeNotice)(notice, extra);
1006
- }
1007
- if ((0, util_1$4.objectIsEmpty)(notice)) {
1008
- return null;
1009
- }
1010
- var context = this.__store.getContents('context');
1011
- var noticeTags = this.__constructTags(notice.tags);
1012
- var contextTags = this.__constructTags(context['tags']);
1013
- var configTags = this.__constructTags(this.config.tags);
1014
- // Turning into a Set will remove duplicates
1015
- var tags = noticeTags.concat(contextTags).concat(configTags);
1016
- var uniqueTags = tags.filter(function (item, index) { return tags.indexOf(item) === index; });
1017
- notice = (0, util_1$4.merge)(notice, {
1018
- name: notice.name || 'Error',
1019
- context: (0, util_1$4.merge)(context, notice.context),
1020
- projectRoot: notice.projectRoot || this.config.projectRoot,
1021
- environment: notice.environment || this.config.environment,
1022
- component: notice.component || this.config.component,
1023
- action: notice.action || this.config.action,
1024
- revision: notice.revision || this.config.revision,
1025
- tags: uniqueTags,
1026
- });
1027
- if (typeof notice.stack !== 'string' || !notice.stack.trim()) {
1028
- notice.stack = (0, util_1$4.generateStackTrace)();
1029
- notice.backtrace = (0, util_1$4.makeBacktrace)(notice.stack, true, this.logger);
1030
- }
1031
- else {
1032
- notice.backtrace = (0, util_1$4.makeBacktrace)(notice.stack, false, this.logger);
1033
- }
1034
- return notice;
1035
- };
1036
- Client.prototype.addBreadcrumb = function (message, opts) {
1037
- if (!this.config.breadcrumbsEnabled) {
1038
- return;
1039
- }
1040
- opts = opts || {};
1041
- var metadata = (0, util_1$4.shallowClone)(opts.metadata);
1042
- var category = opts.category || 'custom';
1043
- var timestamp = new Date().toISOString();
1044
- this.__store.addBreadcrumb({
1045
- category: category,
1046
- message: message,
1047
- metadata: metadata,
1048
- timestamp: timestamp
1049
- });
1050
- return this;
1051
- };
1052
- Client.prototype.__getBreadcrumbs = function () {
1053
- return this.__store.getContents('breadcrumbs').slice();
1054
- };
1055
- Client.prototype.__getContext = function () {
1056
- return this.__store.getContents('context');
1057
- };
1058
- Client.prototype.__developmentMode = function () {
1059
- if (this.config.reportData === true) {
1060
- return false;
1061
- }
1062
- return (this.config.environment && this.config.developmentEnvironments.includes(this.config.environment));
1063
- };
1064
- Client.prototype.__buildPayload = function (notice) {
1065
- var headers = (0, util_1$4.filter)(notice.headers, this.config.filters) || {};
1066
- var cgiData = (0, util_1$4.filter)(__assign(__assign({}, notice.cgiData), (0, util_1$4.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1067
- return {
1068
- notifier: notifier,
1069
- breadcrumbs: {
1070
- enabled: !!this.config.breadcrumbsEnabled,
1071
- trail: notice.__breadcrumbs || []
1072
- },
1073
- error: {
1074
- class: notice.name,
1075
- message: notice.message,
1076
- backtrace: notice.backtrace,
1077
- fingerprint: notice.fingerprint,
1078
- tags: notice.tags,
1079
- causes: (0, util_1$4.getCauses)(notice, this.logger),
1080
- },
1081
- request: {
1082
- url: (0, util_1$4.filterUrl)(notice.url, this.config.filters),
1083
- component: notice.component,
1084
- action: notice.action,
1085
- context: notice.context,
1086
- cgi_data: cgiData,
1087
- params: (0, util_1$4.filter)(notice.params, this.config.filters) || {},
1088
- session: (0, util_1$4.filter)(notice.session, this.config.filters) || {}
1089
- },
1090
- server: {
1091
- project_root: notice.projectRoot,
1092
- environment_name: notice.environment,
1093
- revision: notice.revision,
1094
- hostname: this.config.hostname,
1095
- time: new Date().toUTCString()
1096
- },
1097
- details: notice.details || {}
1098
- };
1099
- };
1100
- Client.prototype.__constructTags = function (tags) {
1101
- if (!tags) {
1102
- return [];
1103
- }
1104
- return tags.toString().split(TAG_SEPARATOR).filter(function (tag) { return NOT_BLANK.test(tag); });
1105
- };
1106
- return Client;
1107
- }());
1108
- client.Client = Client;
1109
-
1110
- var types = {};
1111
-
1112
- Object.defineProperty(types, "__esModule", { value: true });
1113
-
1114
- (function (exports) {
1115
- var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1116
- if (k2 === undefined) k2 = k;
1117
- var desc = Object.getOwnPropertyDescriptor(m, k);
1118
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1119
- desc = { enumerable: true, get: function() { return m[k]; } };
1120
- }
1121
- Object.defineProperty(o, k2, desc);
1122
- }) : (function(o, m, k, k2) {
1123
- if (k2 === undefined) k2 = k;
1124
- o[k2] = m[k];
1125
- }));
1126
- var __setModuleDefault = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) {
1127
- Object.defineProperty(o, "default", { enumerable: true, value: v });
1128
- }) : function(o, v) {
1129
- o["default"] = v;
1130
- });
1131
- var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
1132
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1133
- };
1134
- var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
1135
- if (mod && mod.__esModule) return mod;
1136
- var result = {};
1137
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1138
- __setModuleDefault(result, mod);
1139
- return result;
1140
- };
1141
- Object.defineProperty(exports, "__esModule", { value: true });
1142
- exports.Util = exports.Types = exports.Client = void 0;
1143
- var client_1 = client;
1144
- Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
1145
- __exportStar(store, exports);
1146
- exports.Types = __importStar(types);
1147
- exports.Util = __importStar(util$1);
1148
-
1149
- } (src));
1150
-
1151
- var util = {};
1152
-
1153
- var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
1154
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1155
- return new (P || (P = Promise))(function (resolve, reject) {
1156
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1157
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1158
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1159
- step((generator = generator.apply(thisArg, _arguments || [])).next());
1160
- });
1161
- };
1162
- var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1163
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
1164
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1165
- function verb(n) { return function (v) { return step([n, v]); }; }
1166
- function step(op) {
1167
- if (f) throw new TypeError("Generator is already executing.");
1168
- while (_) try {
1169
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1170
- if (y = 0, t) op = [op[0] & 2, t.value];
1171
- switch (op[0]) {
1172
- case 0: case 1: t = op; break;
1173
- case 4: _.label++; return { value: op[1], done: false };
1174
- case 5: _.label++; y = op[1]; op = [0]; continue;
1175
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
1176
- default:
1177
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
1178
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
1179
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
1180
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
1181
- if (t[2]) _.ops.pop();
1182
- _.trys.pop(); continue;
1183
- }
1184
- op = body.call(thisArg, _);
1185
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
1186
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1187
- }
1188
- };
1189
- var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1190
- return (mod && mod.__esModule) ? mod : { "default": mod };
1191
- };
1192
- Object.defineProperty(util, "__esModule", { value: true });
1193
- util.getSourceFile = util.getStats = util.fatallyLogAndExit = void 0;
1194
- var os_1 = __importDefault$2(require$$0$1);
1195
- var fs_1 = __importDefault$2(require$$1);
1196
- var util_1$3 = require$$2;
1197
- var readFile = (0, util_1$3.promisify)(fs_1.default.readFile);
1198
- function fatallyLogAndExit(err) {
1199
- console.error('[Honeybadger] Exiting process due to uncaught exception');
1200
- console.error(err.stack || err);
1201
- process.exit(1);
1202
- }
1203
- util.fatallyLogAndExit = fatallyLogAndExit;
1204
- function getStats() {
1205
- return __awaiter(this, void 0, void 0, function () {
1206
- var load, stats, fallback, memData, data, results;
1207
- return __generator(this, function (_a) {
1208
- switch (_a.label) {
1209
- case 0:
1210
- load = os_1.default.loadavg();
1211
- stats = {
1212
- load: {
1213
- one: load[0],
1214
- five: load[1],
1215
- fifteen: load[2]
1216
- },
1217
- mem: {}
1218
- };
1219
- fallback = function () {
1220
- stats.mem = {
1221
- free: os_1.default.freemem(),
1222
- total: os_1.default.totalmem()
1223
- };
1224
- };
1225
- if (!fs_1.default.existsSync('/proc/meminfo')) {
1226
- fallback();
1227
- return [2 /*return*/, stats];
1228
- }
1229
- _a.label = 1;
1230
- case 1:
1231
- _a.trys.push([1, 3, , 4]);
1232
- return [4 /*yield*/, readFile('/proc/meminfo', 'utf8')
1233
- // The first four lines, in order, are Total, Free, Buffers, Cached.
1234
- // @TODO: Figure out if there's a way to only read these lines
1235
- ];
1236
- case 2:
1237
- memData = _a.sent();
1238
- data = memData.split('\n').slice(0, 4);
1239
- results = data.map(function (i) {
1240
- return parseInt(/\s+(\d+)\skB/i.exec(i)[1], 10) / 1024.0;
1241
- });
1242
- stats.mem = {
1243
- total: results[0],
1244
- free: results[1],
1245
- buffers: results[2],
1246
- cached: results[3],
1247
- free_total: results[1] + results[2] + results[3]
1248
- };
1249
- return [3 /*break*/, 4];
1250
- case 3:
1251
- _a.sent();
1252
- fallback();
1253
- return [3 /*break*/, 4];
1254
- case 4: return [2 /*return*/, stats];
1255
- }
1256
- });
1257
- });
1258
- }
1259
- util.getStats = getStats;
1260
- /**
1261
- * Get source file if possible, used to build `notice.backtrace.source`
1262
- *
1263
- * @param path to source code
1264
- */
1265
- function getSourceFile(path) {
1266
- return __awaiter(this, void 0, void 0, function () {
1267
- return __generator(this, function (_a) {
1268
- switch (_a.label) {
1269
- case 0:
1270
- _a.trys.push([0, 2, , 3]);
1271
- return [4 /*yield*/, readFile(path, 'utf-8')];
1272
- case 1: return [2 /*return*/, _a.sent()];
1273
- case 2:
1274
- _a.sent();
1275
- return [2 /*return*/, null];
1276
- case 3: return [2 /*return*/];
1277
- }
1278
- });
1279
- });
1280
- }
1281
- util.getSourceFile = getSourceFile;
1282
-
1283
- var uncaught_exception = {};
1284
-
1285
- var aws_lambda = {};
1286
-
1287
- Object.defineProperty(aws_lambda, "__esModule", { value: true });
1288
- aws_lambda.removeAwsDefaultUncaughtExceptionListener = aws_lambda.lambdaHandler = void 0;
1289
- function isHandlerSync(handler) {
1290
- return handler.length > 2;
1291
- }
1292
- function reportToHoneybadger(hb, err, callback) {
1293
- hb.notify(err, {
1294
- afterNotify: function () {
1295
- hb.clear();
1296
- callback(err);
1297
- }
1298
- });
1299
- }
1300
- function asyncHandler(handler, hb) {
1301
- return function wrappedLambdaHandler(event, context) {
1302
- return new Promise(function (resolve, reject) {
1303
- hb.run(function () {
1304
- var timeoutHandler = setupTimeoutWarning(hb, context);
1305
- try {
1306
- var result = handler(event, context);
1307
- // check if handler returns a promise
1308
- if (result && result.then) {
1309
- result
1310
- .then(resolve)
1311
- .catch(function (err) { return reportToHoneybadger(hb, err, reject); })
1312
- .finally(function () { return clearTimeout(timeoutHandler); });
1313
- }
1314
- else {
1315
- clearTimeout(timeoutHandler);
1316
- resolve(result);
1317
- }
1318
- }
1319
- catch (err) {
1320
- clearTimeout(timeoutHandler);
1321
- reportToHoneybadger(hb, err, reject);
1322
- }
1323
- });
1324
- });
1325
- };
1326
- }
1327
- function syncHandler(handler, hb) {
1328
- return function wrappedLambdaHandler(event, context, cb) {
1329
- hb.run(function () {
1330
- var timeoutHandler = setupTimeoutWarning(hb, context);
1331
- try {
1332
- handler(event, context, function (error, result) {
1333
- clearTimeout(timeoutHandler);
1334
- if (error) {
1335
- return reportToHoneybadger(hb, error, cb);
1336
- }
1337
- cb(null, result);
1338
- });
1339
- }
1340
- catch (err) {
1341
- clearTimeout(timeoutHandler);
1342
- reportToHoneybadger(hb, err, cb);
1343
- }
1344
- });
1345
- };
1346
- }
1347
- function shouldReportTimeoutWarning(hb, context) {
1348
- return typeof context.getRemainingTimeInMillis === 'function' && !!(hb.config.reportTimeoutWarning);
1349
- }
1350
- function setupTimeoutWarning(hb, context) {
1351
- if (!shouldReportTimeoutWarning(hb, context)) {
1352
- return;
1353
- }
1354
- var delay = context.getRemainingTimeInMillis() - (hb.config.timeoutWarningThresholdMs);
1355
- return setTimeout(function () {
1356
- hb.notify("".concat(context.functionName, "[").concat(context.functionVersion, "] may have timed out"));
1357
- }, delay > 0 ? delay : 0);
1358
- }
1359
- function lambdaHandler(handler) {
1360
- // eslint-disable-next-line @typescript-eslint/no-this-alias
1361
- var hb = this;
1362
- if (isHandlerSync(handler)) {
1363
- return syncHandler(handler, hb);
1364
- }
1365
- return asyncHandler(handler, hb);
1366
- }
1367
- aws_lambda.lambdaHandler = lambdaHandler;
1368
- var listenerRemoved = false;
1369
- /**
1370
- * Removes AWS Lambda default listener that
1371
- * exits the process before letting us report to honeybadger.
1372
- */
1373
- function removeAwsDefaultUncaughtExceptionListener() {
1374
- if (listenerRemoved) {
1375
- return;
1376
- }
1377
- listenerRemoved = true;
1378
- var listeners = process.listeners('uncaughtException');
1379
- if (listeners.length === 0) {
1380
- return;
1381
- }
1382
- // We assume it's the first listener
1383
- process.removeListener('uncaughtException', listeners[0]);
1384
- }
1385
- aws_lambda.removeAwsDefaultUncaughtExceptionListener = removeAwsDefaultUncaughtExceptionListener;
1386
-
1387
- Object.defineProperty(uncaught_exception, "__esModule", { value: true });
1388
- var util_1$2 = util;
1389
- var aws_lambda_1 = aws_lambda;
1390
- var isReporting$1 = false;
1391
- var handlerAlreadyCalled = false;
1392
- function removeAwsLambdaListener() {
1393
- var isLambda = !!process.env.LAMBDA_TASK_ROOT;
1394
- if (!isLambda) {
1395
- return;
1396
- }
1397
- (0, aws_lambda_1.removeAwsDefaultUncaughtExceptionListener)();
1398
- }
1399
- /**
1400
- * If there are no other uncaughtException listeners,
1401
- * we want to report the exception to Honeybadger and
1402
- * mimic the default behavior of NodeJs,
1403
- * which is to exit the process with code 1
1404
- */
1405
- function hasOtherUncaughtExceptionListeners() {
1406
- return process.listeners('uncaughtException').length > 1;
1407
- }
1408
- function default_1$1() {
1409
- return {
1410
- load: function (client) {
1411
- if (!client.config.enableUncaught) {
1412
- return;
1413
- }
1414
- removeAwsLambdaListener();
1415
- process.on('uncaughtException', function honeybadgerUncaughtExceptionListener(uncaughtError) {
1416
- if (!client.config.enableUncaught) {
1417
- client.config.afterUncaught(uncaughtError);
1418
- if (!hasOtherUncaughtExceptionListeners()) {
1419
- (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1420
- }
1421
- return;
1422
- }
1423
- // report only the first error - prevent reporting recursive errors
1424
- if (handlerAlreadyCalled) {
1425
- if (!hasOtherUncaughtExceptionListeners()) {
1426
- (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1427
- }
1428
- return;
1429
- }
1430
- if (isReporting$1) {
1431
- return;
1432
- }
1433
- isReporting$1 = true;
1434
- client.notify(uncaughtError, {
1435
- afterNotify: function (_err, _notice) {
1436
- isReporting$1 = false;
1437
- handlerAlreadyCalled = true;
1438
- client.config.afterUncaught(uncaughtError);
1439
- if (!hasOtherUncaughtExceptionListeners()) {
1440
- (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1441
- }
1442
- }
1443
- });
1444
- });
1445
- }
1446
- };
1447
- }
1448
- uncaught_exception.default = default_1$1;
1449
-
1450
- var unhandled_rejection = {};
1451
-
1452
- Object.defineProperty(unhandled_rejection, "__esModule", { value: true });
1453
- var util_1$1 = util;
1454
- var isReporting = false;
1455
- /**
1456
- * If there are no other unhandledRejection listeners,
1457
- * we want to report the exception to Honeybadger and
1458
- * mimic the default behavior of NodeJs,
1459
- * which is to exit the process with code 1
1460
- */
1461
- function hasOtherUnhandledRejectionListeners() {
1462
- return process.listeners('unhandledRejection').length > 1;
1463
- }
1464
- function default_1() {
1465
- return {
1466
- load: function (client) {
1467
- if (!client.config.enableUnhandledRejection) {
1468
- return;
1469
- }
1470
- process.on('unhandledRejection', function honeybadgerUnhandledRejectionListener(reason, _promise) {
1471
- if (!client.config.enableUnhandledRejection) {
1472
- if (!hasOtherUnhandledRejectionListeners() && !isReporting) {
1473
- (0, util_1$1.fatallyLogAndExit)(reason);
1474
- }
1475
- return;
1476
- }
1477
- isReporting = true;
1478
- client.notify(reason, { component: 'unhandledRejection' }, {
1479
- afterNotify: function () {
1480
- isReporting = false;
1481
- if (!hasOtherUnhandledRejectionListeners()) {
1482
- (0, util_1$1.fatallyLogAndExit)(reason);
1483
- }
1484
- }
1485
- });
1486
- });
1487
- }
1488
- };
1489
- }
1490
- unhandled_rejection.default = default_1;
1491
-
1492
- var middleware = {};
1493
-
1494
- var __importDefault$1 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1495
- return (mod && mod.__esModule) ? mod : { "default": mod };
1496
- };
1497
- Object.defineProperty(middleware, "__esModule", { value: true });
1498
- middleware.errorHandler = middleware.requestHandler = void 0;
1499
- var url_1$1 = __importDefault$1(require$$0$2);
1500
- function fullUrl(req) {
1501
- var connection = req.connection;
1502
- var address = connection && connection.address();
1503
- // @ts-ignore The old @types/node incorrectly defines `address` as string|Address
1504
- var port = address ? address.port : undefined;
1505
- // @ts-ignore
1506
- return url_1$1.default.format({
1507
- protocol: req.protocol,
1508
- hostname: req.hostname,
1509
- port: port,
1510
- pathname: req.path,
1511
- query: req.query
1512
- });
1513
- }
1514
- function requestHandler(req, res, next) {
1515
- this.withRequest(req, next, next);
1516
- }
1517
- middleware.requestHandler = requestHandler;
1518
- function errorHandler(err, req, _res, next) {
1519
- this.notify(err, {
1520
- url: fullUrl(req),
1521
- params: req.body,
1522
- // @ts-ignore
1523
- session: req.session,
1524
- headers: req.headers,
1525
- cgiData: {
1526
- REQUEST_METHOD: req.method
1527
- }
1528
- });
1529
- if (next) {
1530
- return next(err);
1531
- }
1532
- }
1533
- middleware.errorHandler = errorHandler;
1534
-
1535
- var transport = {};
1536
-
1537
- var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1538
- return (mod && mod.__esModule) ? mod : { "default": mod };
1539
- };
1540
- Object.defineProperty(transport, "__esModule", { value: true });
1541
- transport.ServerTransport = void 0;
1542
- var core_1$1 = src;
1543
- var url_1 = require$$0$2;
1544
- var http_1 = __importDefault(require$$2$1);
1545
- var https_1 = __importDefault(require$$3);
1546
- var util_1 = util;
1547
- var sanitize = core_1$1.Util.sanitize;
1548
- var ServerTransport = /** @class */ (function () {
1549
- function ServerTransport() {
1550
- }
1551
- ServerTransport.prototype.send = function (options, payload) {
1552
- var _this = this;
1553
- var _a = new url_1.URL(options.endpoint), protocol = _a.protocol, hostname = _a.hostname, pathname = _a.pathname;
1554
- var transport = (protocol === 'http:' ? http_1.default : https_1.default);
1555
- return new Promise(function (resolve, reject) {
1556
- var promise;
1557
- // this should not be here. it should be done before reaching the transport layer
1558
- // it could be inside a beforeNotifyHandler, but is not possible at the moment because those handlers are synchronous
1559
- if (_this.isNoticePayload(payload)) {
1560
- promise = _this.appendMetadata(payload);
1561
- }
1562
- else {
1563
- promise = Promise.resolve();
1564
- }
1565
- promise.then(function () {
1566
- //
1567
- // We use a httpOptions object to limit issues with libraries that may patch Node.js
1568
- // See https://github.com/honeybadger-io/honeybadger-js/issues/825#issuecomment-1193113433
1569
- var httpOptions = {
1570
- method: options.method,
1571
- headers: options.headers,
1572
- path: pathname,
1573
- protocol: protocol,
1574
- hostname: hostname,
1575
- };
1576
- var data = undefined;
1577
- if (payload) {
1578
- data = Buffer.from(JSON.stringify(sanitize(payload, options.maxObjectDepth)), 'utf8');
1579
- httpOptions.headers['Content-Length'] = data.length;
1580
- }
1581
- var req = transport.request(httpOptions, function (res) {
1582
- options.logger.debug("statusCode: ".concat(res.statusCode));
1583
- var body = '';
1584
- res.on('data', function (chunk) {
1585
- body += chunk;
1586
- });
1587
- res.on('end', function () { return resolve({ statusCode: res.statusCode, body: body }); });
1588
- });
1589
- req.on('error', function (err) { return reject(err); });
1590
- if (data) {
1591
- req.write(data);
1592
- }
1593
- req.end();
1594
- });
1595
- });
1596
- };
1597
- ServerTransport.prototype.isNoticePayload = function (payload) {
1598
- return payload && payload.error !== undefined;
1599
- };
1600
- ServerTransport.prototype.appendMetadata = function (payload) {
1601
- payload.server.pid = process.pid;
1602
- return (0, util_1.getStats)()
1603
- .then(function (stats) {
1604
- payload.server.stats = stats;
1605
- });
1606
- };
1607
- return ServerTransport;
1608
- }());
1609
- transport.ServerTransport = ServerTransport;
1610
-
1611
- var stacked_store = {};
1612
-
1613
- var async_store = {};
1614
-
1615
- Object.defineProperty(async_store, "__esModule", { value: true });
1616
- async_store.AsyncStore = void 0;
1617
- var kHoneybadgerStore = Symbol.for('kHoneybadgerStore');
1618
- var AsyncStore = /** @class */ (function () {
1619
- function AsyncStore(asyncLocalStorage, contents, breadcrumbsLimit) {
1620
- this.als = asyncLocalStorage;
1621
- this.contents = contents;
1622
- this.breadcrumbsLimit = breadcrumbsLimit;
1623
- }
1624
- /**
1625
- * Attempt to create a new AsyncStore instance
1626
- */
1627
- AsyncStore.create = function (contents, breadcrumbsLimit) {
1628
- try {
1629
- // eslint-disable-next-line @typescript-eslint/no-var-requires
1630
- var AsyncLocalStorage_1 = require('async_hooks').AsyncLocalStorage;
1631
- return new AsyncStore(new AsyncLocalStorage_1, contents, breadcrumbsLimit);
1632
- }
1633
- catch (e) {
1634
- return null;
1635
- }
1636
- };
1637
- /**
1638
- * This returns the live store object, so we can mutate it.
1639
- * If we're in an async context (a `run()` callback), the stored contents at this point will be returned.
1640
- * Otherwise, the initial stored contents will be returned.
1641
- */
1642
- AsyncStore.prototype.__currentContents = function () {
1643
- return this.als.getStore() || this.contents;
1644
- };
1645
- AsyncStore.prototype.getContents = function (key) {
1646
- var value = key ? this.__currentContents()[key] : this.__currentContents();
1647
- return JSON.parse(JSON.stringify(value));
1648
- };
1649
- AsyncStore.prototype.available = function () {
1650
- return !!this.als.getStore();
1651
- };
1652
- AsyncStore.prototype.setContext = function (context) {
1653
- Object.assign(this.__currentContents().context, context || {});
1654
- };
1655
- AsyncStore.prototype.addBreadcrumb = function (breadcrumb) {
1656
- if (this.__currentContents().breadcrumbs.length == this.breadcrumbsLimit) {
1657
- this.__currentContents().breadcrumbs.shift();
1658
- }
1659
- this.__currentContents().breadcrumbs.push(breadcrumb);
1660
- };
1661
- AsyncStore.prototype.clear = function () {
1662
- this.__currentContents().context = {};
1663
- this.__currentContents().breadcrumbs = [];
1664
- };
1665
- AsyncStore.prototype.run = function (callback, request) {
1666
- // When entering an async context, we pass in *a copy* of the initial contents.
1667
- // This allows every request to start from the same state
1668
- // and add data specific to them, without overlapping.
1669
- if (!request) {
1670
- return this.als.run(this.getContents(), callback);
1671
- }
1672
- var contents;
1673
- if (request[kHoneybadgerStore]) {
1674
- contents = request[kHoneybadgerStore];
1675
- }
1676
- else {
1677
- contents = this.getContents();
1678
- request[kHoneybadgerStore] = contents;
1679
- }
1680
- return this.als.run(contents, callback);
1681
- };
1682
- return AsyncStore;
1683
- }());
1684
- async_store.AsyncStore = AsyncStore;
1685
-
1686
- Object.defineProperty(stacked_store, "__esModule", { value: true });
1687
- stacked_store.StackedStore = void 0;
1688
- var core_1 = src;
1689
- var async_store_1 = async_store;
1690
- /**
1691
- * A store that's really a "stack" of stores (async and global)
1692
- * Will proxy calls to the async store if it's active (ie when we enter an async context via `ALS.run()`),
1693
- * otherwise it will fall back to the global store.
1694
- * Both stores in the stack start out with the same contents object.
1695
- * Note that the asyncStore may be null if ALS is not supported.
1696
- */
1697
- var StackedStore = /** @class */ (function () {
1698
- function StackedStore(breadcrumbsLimit) {
1699
- this.contents = { context: {}, breadcrumbs: [] };
1700
- this.asyncStore = async_store_1.AsyncStore.create(this.contents, breadcrumbsLimit);
1701
- this.globalStore = core_1.GlobalStore.create(this.contents, breadcrumbsLimit);
1702
- }
1703
- StackedStore.prototype.__activeStore = function () {
1704
- var _a;
1705
- return ((_a = this.asyncStore) === null || _a === void 0 ? void 0 : _a.available()) ? this.asyncStore : this.globalStore;
1706
- };
1707
- StackedStore.prototype.available = function () {
1708
- return true;
1709
- };
1710
- // @ts-ignore
1711
- StackedStore.prototype.getContents = function (key) {
1712
- return this.__activeStore().getContents(key);
1713
- };
1714
- StackedStore.prototype.setContext = function (context) {
1715
- this.__activeStore().setContext(context);
1716
- };
1717
- StackedStore.prototype.addBreadcrumb = function (breadcrumb) {
1718
- this.__activeStore().addBreadcrumb(breadcrumb);
1719
- };
1720
- StackedStore.prototype.clear = function () {
1721
- this.__activeStore().clear();
1722
- };
1723
- StackedStore.prototype.run = function (callback, request) {
1724
- // We explicitly favour the async store here, if ALS is supported. It's the whole point of the `run()` method
1725
- return this.asyncStore ? this.asyncStore.run(callback, request) : this.globalStore.run(callback);
1726
- };
1727
- return StackedStore;
1728
- }());
1729
- stacked_store.StackedStore = StackedStore;
1730
-
1731
- (function (exports) {
1732
- var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
1733
- var extendStatics = function (d, b) {
1734
- extendStatics = Object.setPrototypeOf ||
1735
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1736
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
1737
- return extendStatics(d, b);
1738
- };
1739
- return function (d, b) {
1740
- if (typeof b !== "function" && b !== null)
1741
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1742
- extendStatics(d, b);
1743
- function __() { this.constructor = d; }
1744
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1745
- };
1746
- })();
1747
- var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
1748
- __assign = Object.assign || function(t) {
1749
- for (var s, i = 1, n = arguments.length; i < n; i++) {
1750
- s = arguments[i];
1751
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
1752
- t[p] = s[p];
1753
- }
1754
- return t;
1755
- };
1756
- return __assign.apply(this, arguments);
1757
- };
1758
- var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1759
- return (mod && mod.__esModule) ? mod : { "default": mod };
1760
- };
1761
- Object.defineProperty(exports, "__esModule", { value: true });
1762
- exports.Types = void 0;
1763
- var os_1 = __importDefault(require$$0$1);
1764
- var domain_1 = __importDefault(require$$1$1);
1765
- var core_1 = src;
1766
- var util_1 = util;
1767
- var uncaught_exception_1 = __importDefault(uncaught_exception);
1768
- var unhandled_rejection_1 = __importDefault(unhandled_rejection);
1769
- var middleware_1 = middleware;
1770
- var aws_lambda_1 = aws_lambda;
1771
- var transport_1 = transport;
1772
- var stacked_store_1 = stacked_store;
1773
- var endpoint = core_1.Util.endpoint;
1774
- var Honeybadger = /** @class */ (function (_super) {
1775
- __extends(Honeybadger, _super);
1776
- function Honeybadger(opts) {
1777
- if (opts === void 0) { opts = {}; }
1778
- var _this = this;
1779
- var _a;
1780
- _this = _super.call(this, __assign({ afterUncaught: util_1.fatallyLogAndExit, projectRoot: process.cwd(), hostname: os_1.default.hostname() }, opts), new transport_1.ServerTransport()) || this;
1781
- /** @internal */
1782
- _this.__beforeNotifyHandlers = [
1783
- function (notice) {
1784
- if (notice && notice.backtrace) {
1785
- notice.backtrace.forEach(function (line) {
1786
- if (line.file) {
1787
- line.file = line.file.replace(/.*\/node_modules\/(.+)/, '[NODE_MODULES]/$1');
1788
- line.file = line.file.replace(notice.projectRoot, '[PROJECT_ROOT]');
1789
- }
1790
- return line;
1791
- });
1792
- }
1793
- }
1794
- ];
1795
- // serverless defaults
1796
- var config = _this.config;
1797
- config.reportTimeoutWarning = (_a = config.reportTimeoutWarning) !== null && _a !== void 0 ? _a : true;
1798
- config.timeoutWarningThresholdMs = config.timeoutWarningThresholdMs || 50;
1799
- _this.__getSourceFileHandler = util_1.getSourceFile.bind(_this);
1800
- _this.errorHandler = middleware_1.errorHandler.bind(_this);
1801
- _this.requestHandler = middleware_1.requestHandler.bind(_this);
1802
- _this.lambdaHandler = aws_lambda_1.lambdaHandler.bind(_this);
1803
- return _this;
1804
- }
1805
- Honeybadger.prototype.factory = function (opts) {
1806
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1807
- return new Honeybadger(opts);
1808
- };
1809
- Honeybadger.prototype.configure = function (opts) {
1810
- if (opts === void 0) { opts = {}; }
1811
- return _super.prototype.configure.call(this, opts);
1812
- };
1813
- Honeybadger.prototype.__initStore = function () {
1814
- // @ts-ignore
1815
- this.__store = new stacked_store_1.StackedStore(this.config.maxBreadcrumbs);
1816
- };
1817
- Honeybadger.prototype.showUserFeedbackForm = function () {
1818
- throw new Error('Honeybadger.showUserFeedbackForm() is not supported on the server-side');
1819
- };
1820
- Honeybadger.prototype.checkIn = function (id) {
1821
- var _this = this;
1822
- return this.__transport
1823
- .send({
1824
- method: 'GET',
1825
- endpoint: endpoint(this.config.endpoint, "v1/check_in/".concat(id)),
1826
- logger: this.logger,
1827
- })
1828
- .then(function () {
1829
- _this.logger.info('CheckIn sent');
1830
- return Promise.resolve();
1831
- })
1832
- .catch(function (err) {
1833
- _this.logger.error('CheckIn failed: an unknown error occurred.', "message=".concat(err.message));
1834
- });
1835
- };
1836
- // This method is intended for web frameworks.
1837
- // It allows us to track context for individual requests without leaking to other requests
1838
- // by doing two things:
1839
- // 1. Using AsyncLocalStorage so the context is tracked across async operations.
1840
- // 2. Attaching the store contents to the request object,
1841
- // so, even if the store is destroyed, we can still recover the context for a given request
1842
- // (for example, in an error-handling middleware)
1843
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1844
- Honeybadger.prototype.withRequest = function (request, handler, onError) {
1845
- var _this = this;
1846
- if (onError) {
1847
- // ALS is fine for context-tracking, but `domain` allows us to catch errors
1848
- // thrown asynchronously (timers, event emitters)
1849
- // We can't use unhandledRejection/uncaughtException listeners; they're global and shared across all requests
1850
- // But the `onError` handler might be request-specific.
1851
- // Note that this doesn't still handle all cases. `domain` has its own problems:
1852
- // See https://github.com/honeybadger-io/honeybadger-js/pull/711
1853
- var dom = domain_1.default.create();
1854
- var onErrorWithContext = function (err) { return _this.__store.run(function () { return onError(err); }, request); };
1855
- dom.on('error', onErrorWithContext);
1856
- handler = dom.bind(handler);
1857
- }
1858
- return this.__store.run(handler, request);
1859
- };
1860
- Honeybadger.prototype.run = function (callback) {
1861
- return this.__store.run(callback);
1862
- };
1863
- return Honeybadger;
1864
- }(core_1.Client));
1865
- var core_2 = src;
1866
- Object.defineProperty(exports, "Types", { enumerable: true, get: function () { return core_2.Types; } });
1867
- exports.default = new Honeybadger({
1868
- __plugins: [
1869
- (0, uncaught_exception_1.default)(),
1870
- (0, unhandled_rejection_1.default)()
1871
- ],
1872
- });
1873
-
1874
- } (server$1));
1875
-
1876
- var server = /*@__PURE__*/getDefaultExportFromCjs(server$1);
1877
-
1878
- export { server as default };
1879
- //# sourceMappingURL=honeybadger.esm.js.map