@honeybadger-io/js 4.7.4 → 4.8.1

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.
@@ -181,515 +181,570 @@
181
181
 
182
182
  var require$$0 = /*@__PURE__*/getAugmentedNamespace(stackTraceParser_esm);
183
183
 
184
- var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
185
- if (k2 === undefined) k2 = k;
186
- var desc = Object.getOwnPropertyDescriptor(m, k);
187
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
188
- desc = { enumerable: true, get: function() { return m[k]; } };
189
- }
190
- Object.defineProperty(o, k2, desc);
191
- }) : (function(o, m, k, k2) {
192
- if (k2 === undefined) k2 = k;
193
- o[k2] = m[k];
194
- }));
195
- var __setModuleDefault = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) {
196
- Object.defineProperty(o, "default", { enumerable: true, value: v });
197
- }) : function(o, v) {
198
- o["default"] = v;
199
- });
200
- var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
201
- if (mod && mod.__esModule) return mod;
202
- var result = {};
203
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
204
- __setModuleDefault(result, mod);
205
- return result;
206
- };
207
- var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
208
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
209
- return new (P || (P = Promise))(function (resolve, reject) {
210
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
211
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
212
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
213
- step((generator = generator.apply(thisArg, _arguments || [])).next());
214
- });
215
- };
216
- var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
217
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
218
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
219
- function verb(n) { return function (v) { return step([n, v]); }; }
220
- function step(op) {
221
- if (f) throw new TypeError("Generator is already executing.");
222
- while (_) try {
223
- 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;
224
- if (y = 0, t) op = [op[0] & 2, t.value];
225
- switch (op[0]) {
226
- case 0: case 1: t = op; break;
227
- case 4: _.label++; return { value: op[1], done: false };
228
- case 5: _.label++; y = op[1]; op = [0]; continue;
229
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
230
- default:
231
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
232
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
233
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
234
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
235
- if (t[2]) _.ops.pop();
236
- _.trys.pop(); continue;
237
- }
238
- op = body.call(thisArg, _);
239
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
240
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
241
- }
242
- };
243
- Object.defineProperty(util$1, "__esModule", { value: true });
244
- util$1.isBrowserConfig = util$1.clone = util$1.formatCGIData = util$1.filterUrl = util$1.filter = util$1.generateStackTrace = util$1.endpoint = util$1.instrument = util$1.isErrorObject = util$1.makeNotice = util$1.logger = util$1.sanitize = util$1.shallowClone = util$1.runAfterNotifyHandlers = util$1.runBeforeNotifyHandlers = util$1.getSourceForBacktrace = util$1.getCauses = util$1.makeBacktrace = util$1.objectIsExtensible = util$1.objectIsEmpty = util$1.mergeNotice = util$1.merge = void 0;
245
- var stackTraceParser = __importStar(require$$0);
246
- function merge(obj1, obj2) {
247
- var result = {};
248
- for (var k in obj1) {
249
- result[k] = obj1[k];
250
- }
251
- for (var k in obj2) {
252
- result[k] = obj2[k];
253
- }
254
- return result;
255
- }
256
- util$1.merge = merge;
257
- function mergeNotice(notice1, notice2) {
258
- var result = merge(notice1, notice2);
259
- if (notice1.context && notice2.context) {
260
- result.context = merge(notice1.context, notice2.context);
261
- }
262
- return result;
263
- }
264
- util$1.mergeNotice = mergeNotice;
265
- function objectIsEmpty(obj) {
266
- for (var k in obj) {
267
- if (Object.prototype.hasOwnProperty.call(obj, k)) {
268
- return false;
269
- }
270
- }
271
- return true;
272
- }
273
- util$1.objectIsEmpty = objectIsEmpty;
274
- function objectIsExtensible(obj) {
275
- if (typeof Object.isExtensible !== 'function') {
276
- return true;
277
- }
278
- return Object.isExtensible(obj);
279
- }
280
- util$1.objectIsExtensible = objectIsExtensible;
281
- function makeBacktrace(stack, shift) {
282
- if (shift === void 0) { shift = 0; }
283
- try {
284
- var backtrace = stackTraceParser
285
- .parse(stack)
286
- .map(function (line) {
287
- return {
288
- file: line.file,
289
- method: line.methodName,
290
- number: line.lineNumber,
291
- column: line.column
292
- };
293
- });
294
- backtrace.splice(0, shift);
295
- return backtrace;
296
- }
297
- catch (_err) {
298
- // TODO: log error
299
- return [];
300
- }
301
- }
302
- util$1.makeBacktrace = makeBacktrace;
303
- function getCauses(notice) {
304
- if (notice.cause) {
305
- var causes = [];
306
- var cause = notice;
307
- while (causes.length < 3 && (cause = cause.cause)) {
308
- causes.push({
309
- class: cause.name,
310
- message: cause.message,
311
- backtrace: typeof cause.stack == 'string' ? makeBacktrace(cause.stack) : null
312
- });
313
- }
314
- return causes;
315
- }
316
- return [];
317
- }
318
- util$1.getCauses = getCauses;
319
- function getSourceForBacktrace(backtrace, getSourceFileHandler) {
320
- return __awaiter(this, void 0, void 0, function () {
321
- var result, index, trace, fileContent;
322
- return __generator(this, function (_a) {
323
- switch (_a.label) {
324
- case 0:
325
- result = [];
326
- if (!getSourceFileHandler || !backtrace || !backtrace.length) {
327
- return [2 /*return*/, result];
328
- }
329
- index = 0;
330
- _a.label = 1;
331
- case 1:
332
- if (!backtrace.length) return [3 /*break*/, 3];
333
- trace = backtrace.splice(0)[index];
334
- return [4 /*yield*/, getSourceFileHandler(trace.file)];
335
- case 2:
336
- fileContent = _a.sent();
337
- result[index] = getSourceCodeSnippet(fileContent, trace.number);
338
- index++;
339
- return [3 /*break*/, 1];
340
- case 3: return [2 /*return*/, result];
341
- }
342
- });
343
- });
344
- }
345
- util$1.getSourceForBacktrace = getSourceForBacktrace;
346
- function runBeforeNotifyHandlers(notice, handlers) {
347
- var result = true;
348
- for (var i = 0, len = handlers.length; i < len; i++) {
349
- var handler = handlers[i];
350
- if (handler(notice) === false) {
351
- result = false;
352
- }
353
- }
354
- return result;
355
- }
356
- util$1.runBeforeNotifyHandlers = runBeforeNotifyHandlers;
357
- function runAfterNotifyHandlers(notice, handlers, error) {
358
- if (notice && notice.afterNotify) {
359
- notice.afterNotify(error, notice);
360
- }
361
- for (var i = 0, len = handlers.length; i < len; i++) {
362
- handlers[i](error, notice);
363
- }
364
- return true;
365
- }
366
- util$1.runAfterNotifyHandlers = runAfterNotifyHandlers;
367
- // Returns a new object with properties from other object.
368
- function shallowClone(obj) {
369
- if (typeof (obj) !== 'object' || obj === null) {
370
- return {};
371
- }
372
- var result = {};
373
- for (var k in obj) {
374
- result[k] = obj[k];
375
- }
376
- return result;
377
- }
378
- util$1.shallowClone = shallowClone;
379
- function sanitize$2(obj, maxDepth) {
380
- if (maxDepth === void 0) { maxDepth = 8; }
381
- var seenObjects = [];
382
- function seen(obj) {
383
- if (!obj || typeof (obj) !== 'object') {
384
- return false;
385
- }
386
- for (var i = 0; i < seenObjects.length; i++) {
387
- var value = seenObjects[i];
388
- if (value === obj) {
389
- return true;
390
- }
391
- }
392
- seenObjects.push(obj);
393
- return false;
394
- }
395
- function canSerialize(obj) {
396
- var typeOfObj = typeof obj;
397
- // Functions are TMI
398
- if (/function/.test(typeOfObj)) {
399
- // Let special toJSON method pass as it's used by JSON.stringify (#722)
400
- return obj.name === 'toJSON';
401
- }
402
- // Symbols can't convert to strings.
403
- if (/symbol/.test(typeOfObj)) {
404
- return false;
405
- }
406
- if (obj === null) {
407
- return false;
408
- }
409
- // No prototype, likely created with `Object.create(null)`.
410
- if (typeof obj === 'object' && typeof obj.hasOwnProperty === 'undefined') {
411
- return false;
412
- }
413
- return true;
414
- }
415
- function serialize(obj, depth) {
416
- if (depth === void 0) { depth = 0; }
417
- if (depth >= maxDepth) {
418
- return '[DEPTH]';
419
- }
420
- // Inspect invalid types
421
- if (!canSerialize(obj)) {
422
- return Object.prototype.toString.call(obj);
423
- }
424
- // Halt circular references
425
- if (seen(obj)) {
426
- return '[RECURSION]';
427
- }
428
- // Serialize inside arrays
429
- if (Array.isArray(obj)) {
430
- return obj.map(function (o) { return safeSerialize(o, depth + 1); });
431
- }
432
- // Serialize inside objects
433
- if (typeof (obj) === 'object') {
434
- var ret = {};
435
- for (var k in obj) {
436
- var v = obj[k];
437
- if (Object.prototype.hasOwnProperty.call(obj, k) && (k != null) && (v != null)) {
438
- ret[k] = safeSerialize(v, depth + 1);
439
- }
440
- }
441
- return ret;
442
- }
443
- // Return everything else untouched
444
- return obj;
445
- }
446
- function safeSerialize(obj, depth) {
447
- if (depth === void 0) { depth = 0; }
448
- try {
449
- return serialize(obj, depth);
450
- }
451
- catch (e) {
452
- return "[ERROR] ".concat(e);
453
- }
454
- }
455
- return safeSerialize(obj);
456
- }
457
- util$1.sanitize = sanitize$2;
458
- function logger(client) {
459
- var log = function (method) {
460
- return function () {
461
- var _a;
462
- var args = [];
463
- for (var _i = 0; _i < arguments.length; _i++) {
464
- args[_i] = arguments[_i];
465
- }
466
- if (method === 'debug') {
467
- if (!client.config.debug) {
468
- return;
469
- }
470
- // Log at default level so that you don't need to also enable verbose
471
- // logging in Chrome.
472
- method = 'log';
473
- }
474
- args.unshift('[Honeybadger]');
475
- (_a = client.config.logger)[method].apply(_a, args);
476
- };
477
- };
478
- return {
479
- log: log('log'),
480
- info: log('info'),
481
- debug: log('debug'),
482
- warn: log('warn'),
483
- error: log('error')
484
- };
485
- }
486
- util$1.logger = logger;
487
- /**
488
- * Converts any object into a notice object (which at minimum has the same
489
- * properties as Error, but supports additional Honeybadger properties.)
490
- */
491
- function makeNotice$1(thing) {
492
- var notice;
493
- if (!thing) {
494
- notice = {};
495
- }
496
- else if (isErrorObject(thing)) {
497
- var e = thing;
498
- notice = merge(thing, { name: e.name, message: e.message, stack: e.stack, cause: e.cause });
499
- }
500
- else if (typeof thing === 'object') {
501
- notice = shallowClone(thing);
502
- }
503
- else {
504
- var m = String(thing);
505
- notice = { message: m };
506
- }
507
- return notice;
508
- }
509
- util$1.makeNotice = makeNotice$1;
510
- function isErrorObject(thing) {
511
- return thing instanceof Error
512
- || Object.prototype.toString.call(thing) === '[object Error]'; // Important for cross-realm objects
513
- }
514
- util$1.isErrorObject = isErrorObject;
515
- /**
516
- * Instrument an existing function inside an object (usually global).
517
- * @param {!Object} object
518
- * @param {!String} name
519
- * @param {!Function} replacement
520
- */
521
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
522
- function instrument$5(object, name, replacement) {
523
- if (!object || !name || !replacement || !(name in object)) {
524
- return;
525
- }
526
- var original = object[name];
527
- while (original && original.__hb_original) {
528
- original = original.__hb_original;
529
- }
530
- try {
531
- object[name] = replacement(original);
532
- object[name].__hb_original = original;
533
- }
534
- catch (_e) {
535
- // Ignores errors like this one:
536
- // Error: TypeError: Cannot set property onunhandledrejection of [object Object] which has only a getter
537
- // 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
538
- }
539
- }
540
- util$1.instrument = instrument$5;
541
- function endpoint(base, path) {
542
- var endpoint = base.trim().replace(/\/$/, '');
543
- path = path.trim().replace(/(^\/|\/$)/g, '');
544
- return "".concat(endpoint, "/").concat(path);
545
- }
546
- util$1.endpoint = endpoint;
547
- function generateStackTrace() {
548
- try {
549
- throw new Error('');
550
- }
551
- catch (e) {
552
- if (e.stack) {
553
- return e.stack;
554
- }
555
- }
556
- var maxStackSize = 10;
557
- var stack = [];
558
- var curr = arguments.callee;
559
- while (curr && stack.length < maxStackSize) {
560
- if (/function(?:\s+([\w$]+))+\s*\(/.test(curr.toString())) {
561
- stack.push(RegExp.$1 || '<anonymous>');
562
- }
563
- else {
564
- stack.push('<anonymous>');
565
- }
566
- try {
567
- curr = curr.caller;
568
- }
569
- catch (e) {
570
- break;
571
- }
572
- }
573
- return stack.join('\n');
574
- }
575
- util$1.generateStackTrace = generateStackTrace;
576
- function filter(obj, filters) {
577
- if (!is('Object', obj)) {
578
- return;
579
- }
580
- if (!is('Array', filters)) {
581
- filters = [];
582
- }
583
- var seen = [];
584
- function filter(obj) {
585
- var k, newObj;
586
- if (is('Object', obj) || is('Array', obj)) {
587
- if (seen.indexOf(obj) !== -1) {
588
- return '[CIRCULAR DATA STRUCTURE]';
589
- }
590
- seen.push(obj);
591
- }
592
- if (is('Object', obj)) {
593
- newObj = {};
594
- for (k in obj) {
595
- if (filterMatch(k, filters)) {
596
- newObj[k] = '[FILTERED]';
597
- }
598
- else {
599
- newObj[k] = filter(obj[k]);
600
- }
601
- }
602
- return newObj;
603
- }
604
- if (is('Array', obj)) {
605
- return obj.map(function (v) {
606
- return filter(v);
607
- });
608
- }
609
- if (is('Function', obj)) {
610
- return '[FUNC]';
611
- }
612
- return obj;
613
- }
614
- return filter(obj);
615
- }
616
- util$1.filter = filter;
617
- function filterMatch(key, filters) {
618
- for (var i = 0; i < filters.length; i++) {
619
- if (key.toLowerCase().indexOf(filters[i].toLowerCase()) !== -1) {
620
- return true;
621
- }
622
- }
623
- return false;
624
- }
625
- function is(type, obj) {
626
- var klass = Object.prototype.toString.call(obj).slice(8, -1);
627
- return obj !== undefined && obj !== null && klass === type;
628
- }
629
- function filterUrl(url, filters) {
630
- if (!filters) {
631
- return url;
632
- }
633
- if (typeof url !== 'string') {
634
- return url;
635
- }
636
- var query = url.split(/\?/, 2)[1];
637
- if (!query) {
638
- return url;
639
- }
640
- var result = url;
641
- query.split(/[&]\s?/).forEach(function (pair) {
642
- var _a = pair.split('=', 2), key = _a[0], value = _a[1];
643
- if (filterMatch(key, filters)) {
644
- result = result.replace("".concat(key, "=").concat(value), "".concat(key, "=[FILTERED]"));
645
- }
646
- });
647
- return result;
648
- }
649
- util$1.filterUrl = filterUrl;
650
- function formatCGIData(vars, prefix) {
651
- if (prefix === void 0) { prefix = ''; }
652
- var formattedVars = {};
653
- Object.keys(vars).forEach(function (key) {
654
- var formattedKey = prefix + key.replace(/\W/g, '_').toUpperCase();
655
- formattedVars[formattedKey] = vars[key];
656
- });
657
- return formattedVars;
658
- }
659
- util$1.formatCGIData = formatCGIData;
660
- function clone(obj) {
661
- return JSON.parse(JSON.stringify(obj));
662
- }
663
- util$1.clone = clone;
664
- function getSourceCodeSnippet(fileData, lineNumber, sourceRadius) {
665
- if (sourceRadius === void 0) { sourceRadius = 2; }
666
- if (!fileData) {
667
- return null;
668
- }
669
- var lines = fileData.split('\n');
670
- // add one empty line because array index starts from 0, but error line number is counted from 1
671
- lines.unshift('');
672
- var start = lineNumber - sourceRadius;
673
- var end = lineNumber + sourceRadius;
674
- var result = {};
675
- for (var i = start; i <= end; i++) {
676
- var line = lines[i];
677
- if (typeof line === 'string') {
678
- result[i] = line;
679
- }
680
- }
681
- return result;
682
- }
683
- function isBrowserConfig(config) {
684
- return config.async !== undefined;
685
- }
686
- util$1.isBrowserConfig = isBrowserConfig;
184
+ (function (exports) {
185
+ var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
186
+ if (k2 === undefined) k2 = k;
187
+ var desc = Object.getOwnPropertyDescriptor(m, k);
188
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
189
+ desc = { enumerable: true, get: function() { return m[k]; } };
190
+ }
191
+ Object.defineProperty(o, k2, desc);
192
+ }) : (function(o, m, k, k2) {
193
+ if (k2 === undefined) k2 = k;
194
+ o[k2] = m[k];
195
+ }));
196
+ var __setModuleDefault = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) {
197
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
198
+ }) : function(o, v) {
199
+ o["default"] = v;
200
+ });
201
+ var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
202
+ if (mod && mod.__esModule) return mod;
203
+ var result = {};
204
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
205
+ __setModuleDefault(result, mod);
206
+ return result;
207
+ };
208
+ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
209
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
210
+ return new (P || (P = Promise))(function (resolve, reject) {
211
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
212
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
213
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
214
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
215
+ });
216
+ };
217
+ var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
218
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
219
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
220
+ function verb(n) { return function (v) { return step([n, v]); }; }
221
+ function step(op) {
222
+ if (f) throw new TypeError("Generator is already executing.");
223
+ while (_) try {
224
+ 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;
225
+ if (y = 0, t) op = [op[0] & 2, t.value];
226
+ switch (op[0]) {
227
+ case 0: case 1: t = op; break;
228
+ case 4: _.label++; return { value: op[1], done: false };
229
+ case 5: _.label++; y = op[1]; op = [0]; continue;
230
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
231
+ default:
232
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
233
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
234
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
235
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
236
+ if (t[2]) _.ops.pop();
237
+ _.trys.pop(); continue;
238
+ }
239
+ op = body.call(thisArg, _);
240
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
241
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
242
+ }
243
+ };
244
+ Object.defineProperty(exports, "__esModule", { value: true });
245
+ 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;
246
+ var stackTraceParser = __importStar(require$$0);
247
+ function merge(obj1, obj2) {
248
+ var result = {};
249
+ for (var k in obj1) {
250
+ result[k] = obj1[k];
251
+ }
252
+ for (var k in obj2) {
253
+ result[k] = obj2[k];
254
+ }
255
+ return result;
256
+ }
257
+ exports.merge = merge;
258
+ function mergeNotice(notice1, notice2) {
259
+ var result = merge(notice1, notice2);
260
+ if (notice1.context && notice2.context) {
261
+ result.context = merge(notice1.context, notice2.context);
262
+ }
263
+ return result;
264
+ }
265
+ exports.mergeNotice = mergeNotice;
266
+ function objectIsEmpty(obj) {
267
+ for (var k in obj) {
268
+ if (Object.prototype.hasOwnProperty.call(obj, k)) {
269
+ return false;
270
+ }
271
+ }
272
+ return true;
273
+ }
274
+ exports.objectIsEmpty = objectIsEmpty;
275
+ function objectIsExtensible(obj) {
276
+ if (typeof Object.isExtensible !== 'function') {
277
+ return true;
278
+ }
279
+ return Object.isExtensible(obj);
280
+ }
281
+ exports.objectIsExtensible = objectIsExtensible;
282
+ function makeBacktrace(stack, filterHbSourceCode, logger) {
283
+ if (filterHbSourceCode === void 0) { filterHbSourceCode = false; }
284
+ if (logger === void 0) { logger = console; }
285
+ try {
286
+ var backtrace = stackTraceParser
287
+ .parse(stack)
288
+ .map(function (line) {
289
+ return {
290
+ file: line.file,
291
+ method: line.methodName,
292
+ number: line.lineNumber,
293
+ column: line.column
294
+ };
295
+ });
296
+ if (filterHbSourceCode) {
297
+ backtrace.splice(0, calculateBacktraceShift(backtrace));
298
+ }
299
+ return backtrace;
300
+ }
301
+ catch (err) {
302
+ logger.debug(err);
303
+ return [];
304
+ }
305
+ }
306
+ exports.makeBacktrace = makeBacktrace;
307
+ function isFrameFromHbSourceCode(frame) {
308
+ var hasHbFile = false;
309
+ var hasHbMethod = false;
310
+ if (frame.file) {
311
+ hasHbFile = frame.file.toLowerCase().indexOf('@honeybadger-io') > -1;
312
+ }
313
+ if (frame.method) {
314
+ hasHbMethod = frame.method.toLowerCase().indexOf('@honeybadger-io') > -1;
315
+ }
316
+ return hasHbFile || hasHbMethod;
317
+ }
318
+ exports.DEFAULT_BACKTRACE_SHIFT = 3;
319
+ /**
320
+ * If {@link generateStackTrace} is used, we want to exclude frames that come from
321
+ * Honeybadger's source code.
322
+ *
323
+ * Logic:
324
+ * - For each frame, increment the shift if source code is from Honeybadger
325
+ * - If a frame from an <anonymous> file is encountered increment the shift ONLY if between Honeybadger source code
326
+ * (i.e. previous and next frames are from Honeybadger)
327
+ * - Exit when frame encountered is not from Honeybadger source code
328
+ *
329
+ * Note: this will not always work, especially in browser versions where code
330
+ * is minified, uglified and bundled.
331
+ * For those cases we default to 3:
332
+ * - generateStackTrace
333
+ * - makeNotice
334
+ * - notify
335
+ */
336
+ function calculateBacktraceShift(backtrace) {
337
+ var shift = 0;
338
+ for (var i = 0; i < backtrace.length; i++) {
339
+ var frame = backtrace[i];
340
+ if (isFrameFromHbSourceCode(frame)) {
341
+ shift++;
342
+ continue;
343
+ }
344
+ if (!frame.file || frame.file === '<anonymous>') {
345
+ var nextFrame = backtrace[i + 1];
346
+ if (nextFrame && isFrameFromHbSourceCode(nextFrame)) {
347
+ shift++;
348
+ continue;
349
+ }
350
+ }
351
+ break;
352
+ }
353
+ return shift || exports.DEFAULT_BACKTRACE_SHIFT;
354
+ }
355
+ exports.calculateBacktraceShift = calculateBacktraceShift;
356
+ function getCauses(notice, logger) {
357
+ if (notice.cause) {
358
+ var causes = [];
359
+ var cause = notice;
360
+ while (causes.length < 3 && (cause = cause.cause)) {
361
+ causes.push({
362
+ class: cause.name,
363
+ message: cause.message,
364
+ backtrace: typeof cause.stack == 'string' ? makeBacktrace(cause.stack, false, logger) : null
365
+ });
366
+ }
367
+ return causes;
368
+ }
369
+ return [];
370
+ }
371
+ exports.getCauses = getCauses;
372
+ function getSourceForBacktrace(backtrace, getSourceFileHandler) {
373
+ return __awaiter(this, void 0, void 0, function () {
374
+ var result, index, trace, fileContent;
375
+ return __generator(this, function (_a) {
376
+ switch (_a.label) {
377
+ case 0:
378
+ result = [];
379
+ if (!getSourceFileHandler || !backtrace || !backtrace.length) {
380
+ return [2 /*return*/, result];
381
+ }
382
+ index = 0;
383
+ _a.label = 1;
384
+ case 1:
385
+ if (!backtrace.length) return [3 /*break*/, 3];
386
+ trace = backtrace.splice(0)[index];
387
+ return [4 /*yield*/, getSourceFileHandler(trace.file)];
388
+ case 2:
389
+ fileContent = _a.sent();
390
+ result[index] = getSourceCodeSnippet(fileContent, trace.number);
391
+ index++;
392
+ return [3 /*break*/, 1];
393
+ case 3: return [2 /*return*/, result];
394
+ }
395
+ });
396
+ });
397
+ }
398
+ exports.getSourceForBacktrace = getSourceForBacktrace;
399
+ function runBeforeNotifyHandlers(notice, handlers) {
400
+ var result = true;
401
+ for (var i = 0, len = handlers.length; i < len; i++) {
402
+ var handler = handlers[i];
403
+ if (handler(notice) === false) {
404
+ result = false;
405
+ }
406
+ }
407
+ return result;
408
+ }
409
+ exports.runBeforeNotifyHandlers = runBeforeNotifyHandlers;
410
+ function runAfterNotifyHandlers(notice, handlers, error) {
411
+ if (notice && notice.afterNotify) {
412
+ notice.afterNotify(error, notice);
413
+ }
414
+ for (var i = 0, len = handlers.length; i < len; i++) {
415
+ handlers[i](error, notice);
416
+ }
417
+ return true;
418
+ }
419
+ exports.runAfterNotifyHandlers = runAfterNotifyHandlers;
420
+ // Returns a new object with properties from other object.
421
+ function shallowClone(obj) {
422
+ if (typeof (obj) !== 'object' || obj === null) {
423
+ return {};
424
+ }
425
+ var result = {};
426
+ for (var k in obj) {
427
+ result[k] = obj[k];
428
+ }
429
+ return result;
430
+ }
431
+ exports.shallowClone = shallowClone;
432
+ function sanitize(obj, maxDepth) {
433
+ if (maxDepth === void 0) { maxDepth = 8; }
434
+ var seenObjects = [];
435
+ function seen(obj) {
436
+ if (!obj || typeof (obj) !== 'object') {
437
+ return false;
438
+ }
439
+ for (var i = 0; i < seenObjects.length; i++) {
440
+ var value = seenObjects[i];
441
+ if (value === obj) {
442
+ return true;
443
+ }
444
+ }
445
+ seenObjects.push(obj);
446
+ return false;
447
+ }
448
+ function canSerialize(obj) {
449
+ var typeOfObj = typeof obj;
450
+ // Functions are TMI
451
+ if (/function/.test(typeOfObj)) {
452
+ // Let special toJSON method pass as it's used by JSON.stringify (#722)
453
+ return obj.name === 'toJSON';
454
+ }
455
+ // Symbols can't convert to strings.
456
+ if (/symbol/.test(typeOfObj)) {
457
+ return false;
458
+ }
459
+ if (obj === null) {
460
+ return false;
461
+ }
462
+ // No prototype, likely created with `Object.create(null)`.
463
+ if (typeof obj === 'object' && typeof obj.hasOwnProperty === 'undefined') {
464
+ return false;
465
+ }
466
+ return true;
467
+ }
468
+ function serialize(obj, depth) {
469
+ if (depth === void 0) { depth = 0; }
470
+ if (depth >= maxDepth) {
471
+ return '[DEPTH]';
472
+ }
473
+ // Inspect invalid types
474
+ if (!canSerialize(obj)) {
475
+ return Object.prototype.toString.call(obj);
476
+ }
477
+ // Halt circular references
478
+ if (seen(obj)) {
479
+ return '[RECURSION]';
480
+ }
481
+ // Serialize inside arrays
482
+ if (Array.isArray(obj)) {
483
+ return obj.map(function (o) { return safeSerialize(o, depth + 1); });
484
+ }
485
+ // Serialize inside objects
486
+ if (typeof (obj) === 'object') {
487
+ var ret = {};
488
+ for (var k in obj) {
489
+ var v = obj[k];
490
+ if (Object.prototype.hasOwnProperty.call(obj, k) && (k != null) && (v != null)) {
491
+ ret[k] = safeSerialize(v, depth + 1);
492
+ }
493
+ }
494
+ return ret;
495
+ }
496
+ // Return everything else untouched
497
+ return obj;
498
+ }
499
+ function safeSerialize(obj, depth) {
500
+ if (depth === void 0) { depth = 0; }
501
+ try {
502
+ return serialize(obj, depth);
503
+ }
504
+ catch (e) {
505
+ return "[ERROR] ".concat(e);
506
+ }
507
+ }
508
+ return safeSerialize(obj);
509
+ }
510
+ exports.sanitize = sanitize;
511
+ function logger(client) {
512
+ var log = function (method) {
513
+ return function () {
514
+ var _a;
515
+ var args = [];
516
+ for (var _i = 0; _i < arguments.length; _i++) {
517
+ args[_i] = arguments[_i];
518
+ }
519
+ if (method === 'debug') {
520
+ if (!client.config.debug) {
521
+ return;
522
+ }
523
+ // Log at default level so that you don't need to also enable verbose
524
+ // logging in Chrome.
525
+ method = 'log';
526
+ }
527
+ args.unshift('[Honeybadger]');
528
+ (_a = client.config.logger)[method].apply(_a, args);
529
+ };
530
+ };
531
+ return {
532
+ log: log('log'),
533
+ info: log('info'),
534
+ debug: log('debug'),
535
+ warn: log('warn'),
536
+ error: log('error')
537
+ };
538
+ }
539
+ exports.logger = logger;
540
+ /**
541
+ * Converts any object into a notice object (which at minimum has the same
542
+ * properties as Error, but supports additional Honeybadger properties.)
543
+ */
544
+ function makeNotice(thing) {
545
+ var notice;
546
+ if (!thing) {
547
+ notice = {};
548
+ }
549
+ else if (isErrorObject(thing)) {
550
+ var e = thing;
551
+ notice = merge(thing, { name: e.name, message: e.message, stack: e.stack, cause: e.cause });
552
+ }
553
+ else if (typeof thing === 'object') {
554
+ notice = shallowClone(thing);
555
+ }
556
+ else {
557
+ var m = String(thing);
558
+ notice = { message: m };
559
+ }
560
+ return notice;
561
+ }
562
+ exports.makeNotice = makeNotice;
563
+ function isErrorObject(thing) {
564
+ return thing instanceof Error
565
+ || Object.prototype.toString.call(thing) === '[object Error]'; // Important for cross-realm objects
566
+ }
567
+ exports.isErrorObject = isErrorObject;
568
+ /**
569
+ * Instrument an existing function inside an object (usually global).
570
+ * @param {!Object} object
571
+ * @param {!String} name
572
+ * @param {!Function} replacement
573
+ */
574
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
575
+ function instrument(object, name, replacement) {
576
+ if (!object || !name || !replacement || !(name in object)) {
577
+ return;
578
+ }
579
+ var original = object[name];
580
+ while (original && original.__hb_original) {
581
+ original = original.__hb_original;
582
+ }
583
+ try {
584
+ object[name] = replacement(original);
585
+ object[name].__hb_original = original;
586
+ }
587
+ catch (_e) {
588
+ // Ignores errors like this one:
589
+ // Error: TypeError: Cannot set property onunhandledrejection of [object Object] which has only a getter
590
+ // 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
591
+ }
592
+ }
593
+ exports.instrument = instrument;
594
+ function endpoint(base, path) {
595
+ var endpoint = base.trim().replace(/\/$/, '');
596
+ path = path.trim().replace(/(^\/|\/$)/g, '');
597
+ return "".concat(endpoint, "/").concat(path);
598
+ }
599
+ exports.endpoint = endpoint;
600
+ function generateStackTrace() {
601
+ try {
602
+ throw new Error('');
603
+ }
604
+ catch (e) {
605
+ if (e.stack) {
606
+ return e.stack;
607
+ }
608
+ }
609
+ var maxStackSize = 10;
610
+ var stack = [];
611
+ var curr = arguments.callee;
612
+ while (curr && stack.length < maxStackSize) {
613
+ if (/function(?:\s+([\w$]+))+\s*\(/.test(curr.toString())) {
614
+ stack.push(RegExp.$1 || '<anonymous>');
615
+ }
616
+ else {
617
+ stack.push('<anonymous>');
618
+ }
619
+ try {
620
+ curr = curr.caller;
621
+ }
622
+ catch (e) {
623
+ break;
624
+ }
625
+ }
626
+ return stack.join('\n');
627
+ }
628
+ exports.generateStackTrace = generateStackTrace;
629
+ function filter(obj, filters) {
630
+ if (!is('Object', obj)) {
631
+ return;
632
+ }
633
+ if (!is('Array', filters)) {
634
+ filters = [];
635
+ }
636
+ var seen = [];
637
+ function filter(obj) {
638
+ var k, newObj;
639
+ if (is('Object', obj) || is('Array', obj)) {
640
+ if (seen.indexOf(obj) !== -1) {
641
+ return '[CIRCULAR DATA STRUCTURE]';
642
+ }
643
+ seen.push(obj);
644
+ }
645
+ if (is('Object', obj)) {
646
+ newObj = {};
647
+ for (k in obj) {
648
+ if (filterMatch(k, filters)) {
649
+ newObj[k] = '[FILTERED]';
650
+ }
651
+ else {
652
+ newObj[k] = filter(obj[k]);
653
+ }
654
+ }
655
+ return newObj;
656
+ }
657
+ if (is('Array', obj)) {
658
+ return obj.map(function (v) {
659
+ return filter(v);
660
+ });
661
+ }
662
+ if (is('Function', obj)) {
663
+ return '[FUNC]';
664
+ }
665
+ return obj;
666
+ }
667
+ return filter(obj);
668
+ }
669
+ exports.filter = filter;
670
+ function filterMatch(key, filters) {
671
+ for (var i = 0; i < filters.length; i++) {
672
+ if (key.toLowerCase().indexOf(filters[i].toLowerCase()) !== -1) {
673
+ return true;
674
+ }
675
+ }
676
+ return false;
677
+ }
678
+ function is(type, obj) {
679
+ var klass = Object.prototype.toString.call(obj).slice(8, -1);
680
+ return obj !== undefined && obj !== null && klass === type;
681
+ }
682
+ function filterUrl(url, filters) {
683
+ if (!filters) {
684
+ return url;
685
+ }
686
+ if (typeof url !== 'string') {
687
+ return url;
688
+ }
689
+ var query = url.split(/\?/, 2)[1];
690
+ if (!query) {
691
+ return url;
692
+ }
693
+ var result = url;
694
+ query.split(/[&]\s?/).forEach(function (pair) {
695
+ var _a = pair.split('=', 2), key = _a[0], value = _a[1];
696
+ if (filterMatch(key, filters)) {
697
+ result = result.replace("".concat(key, "=").concat(value), "".concat(key, "=[FILTERED]"));
698
+ }
699
+ });
700
+ return result;
701
+ }
702
+ exports.filterUrl = filterUrl;
703
+ function formatCGIData(vars, prefix) {
704
+ if (prefix === void 0) { prefix = ''; }
705
+ var formattedVars = {};
706
+ Object.keys(vars).forEach(function (key) {
707
+ var formattedKey = prefix + key.replace(/\W/g, '_').toUpperCase();
708
+ formattedVars[formattedKey] = vars[key];
709
+ });
710
+ return formattedVars;
711
+ }
712
+ exports.formatCGIData = formatCGIData;
713
+ function clone(obj) {
714
+ return JSON.parse(JSON.stringify(obj));
715
+ }
716
+ exports.clone = clone;
717
+ function getSourceCodeSnippet(fileData, lineNumber, sourceRadius) {
718
+ if (sourceRadius === void 0) { sourceRadius = 2; }
719
+ if (!fileData) {
720
+ return null;
721
+ }
722
+ var lines = fileData.split('\n');
723
+ // add one empty line because array index starts from 0, but error line number is counted from 1
724
+ lines.unshift('');
725
+ var start = lineNumber - sourceRadius;
726
+ var end = lineNumber + sourceRadius;
727
+ var result = {};
728
+ for (var i = start; i <= end; i++) {
729
+ var line = lines[i];
730
+ if (typeof line === 'string') {
731
+ result[i] = line;
732
+ }
733
+ }
734
+ return result;
735
+ }
736
+ function isBrowserConfig(config) {
737
+ return config.async !== undefined;
738
+ }
739
+ exports.isBrowserConfig = isBrowserConfig;
740
+
741
+ } (util$1));
687
742
 
688
743
  var store = {};
689
744
 
690
745
  Object.defineProperty(store, "__esModule", { value: true });
691
746
  store.GlobalStore = void 0;
692
- var util_1$2 = util$1;
747
+ var util_1$7 = util$1;
693
748
  var GlobalStore = /** @class */ (function () {
694
749
  function GlobalStore(contents, breadcrumbsLimit) {
695
750
  this.contents = contents;
@@ -706,7 +761,7 @@
706
761
  return JSON.parse(JSON.stringify(value));
707
762
  };
708
763
  GlobalStore.prototype.setContext = function (context) {
709
- this.contents.context = (0, util_1$2.merge)(this.contents.context, context || {});
764
+ this.contents.context = (0, util_1$7.merge)(this.contents.context, context || {});
710
765
  };
711
766
  GlobalStore.prototype.addBreadcrumb = function (breadcrumb) {
712
767
  if (this.contents.breadcrumbs.length == this.breadcrumbsLimit) {
@@ -738,12 +793,12 @@
738
793
  };
739
794
  Object.defineProperty(client, "__esModule", { value: true });
740
795
  client.Client = void 0;
741
- var util_1$1 = util$1;
796
+ var util_1$6 = util$1;
742
797
  var store_1 = store;
743
798
  var notifier = {
744
799
  name: 'honeybadger-js',
745
800
  url: 'https://github.com/honeybadger-io/honeybadger-js',
746
- version: '4.7.4'
801
+ version: '4.8.1'
747
802
  };
748
803
  // Split at commas and spaces
749
804
  var TAG_SEPARATOR = /,|\s+/;
@@ -759,7 +814,7 @@
759
814
  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);
760
815
  this.__initStore();
761
816
  this.__transport = transport;
762
- this.logger = (0, util_1$1.logger)(this);
817
+ this.logger = (0, util_1$6.logger)(this);
763
818
  }
764
819
  Client.prototype.getVersion = function () {
765
820
  return notifier.version;
@@ -829,14 +884,14 @@
829
884
  }
830
885
  // we need to have the source file data before the beforeNotifyHandlers,
831
886
  // in case they modify them
832
- var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$1.shallowClone)(trace); }) : null;
833
- var beforeNotifyResult = (0, util_1$1.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
887
+ var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$6.shallowClone)(trace); }) : null;
888
+ var beforeNotifyResult = (0, util_1$6.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
834
889
  if (!preConditionError && !beforeNotifyResult) {
835
890
  this.logger.debug('skipping error report: beforeNotify handlers returned false', notice);
836
891
  preConditionError = new Error('beforeNotify handlers returned false');
837
892
  }
838
893
  if (preConditionError) {
839
- (0, util_1$1.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionError);
894
+ (0, util_1$6.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionError);
840
895
  return false;
841
896
  }
842
897
  this.addBreadcrumb('Honeybadger Notice', {
@@ -849,7 +904,7 @@
849
904
  });
850
905
  var breadcrumbs = this.__store.getContents('breadcrumbs');
851
906
  notice.__breadcrumbs = this.config.breadcrumbsEnabled ? breadcrumbs : [];
852
- (0, util_1$1.getSourceForBacktrace)(sourceCodeData, this.__getSourceFileHandler)
907
+ (0, util_1$6.getSourceForBacktrace)(sourceCodeData, this.__getSourceFileHandler)
853
908
  .then(function (sourcePerTrace) {
854
909
  sourcePerTrace.forEach(function (source, index) {
855
910
  notice.backtrace[index].source = source;
@@ -863,26 +918,25 @@
863
918
  'Accept': 'text/json, application/json'
864
919
  },
865
920
  method: 'POST',
866
- endpoint: (0, util_1$1.endpoint)(_this.config.endpoint, '/v1/notices/js'),
921
+ endpoint: (0, util_1$6.endpoint)(_this.config.endpoint, '/v1/notices/js'),
867
922
  maxObjectDepth: _this.config.maxObjectDepth,
868
923
  logger: _this.logger,
869
- async: (0, util_1$1.isBrowserConfig)(_this.config) ? _this.config.async : undefined,
870
924
  }, payload)
871
925
  .then(function (res) {
872
926
  if (res.statusCode !== 201) {
873
- (0, util_1$1.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
927
+ (0, util_1$6.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
874
928
  _this.logger.warn("Error report failed: unknown response from server. code=".concat(res.statusCode));
875
929
  return;
876
930
  }
877
931
  var uuid = JSON.parse(res.body).id;
878
- (0, util_1$1.runAfterNotifyHandlers)((0, util_1$1.merge)(notice, {
932
+ (0, util_1$6.runAfterNotifyHandlers)((0, util_1$6.merge)(notice, {
879
933
  id: uuid
880
934
  }), _this.__afterNotifyHandlers);
881
935
  _this.logger.info("Error report sent \u26A1 https://app.honeybadger.io/notice/".concat(uuid));
882
936
  })
883
937
  .catch(function (err) {
884
938
  _this.logger.error('Error report failed: an unknown error occurred.', "message=".concat(err.message));
885
- (0, util_1$1.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
939
+ (0, util_1$6.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
886
940
  });
887
941
  });
888
942
  return true;
@@ -935,18 +989,18 @@
935
989
  Client.prototype.makeNotice = function (noticeable, name, extra) {
936
990
  if (name === void 0) { name = undefined; }
937
991
  if (extra === void 0) { extra = undefined; }
938
- var notice = (0, util_1$1.makeNotice)(noticeable);
992
+ var notice = (0, util_1$6.makeNotice)(noticeable);
939
993
  if (name && !(typeof name === 'object')) {
940
994
  var n = String(name);
941
995
  name = { name: n };
942
996
  }
943
997
  if (name) {
944
- notice = (0, util_1$1.mergeNotice)(notice, name);
998
+ notice = (0, util_1$6.mergeNotice)(notice, name);
945
999
  }
946
1000
  if (typeof extra === 'object' && extra !== null) {
947
- notice = (0, util_1$1.mergeNotice)(notice, extra);
1001
+ notice = (0, util_1$6.mergeNotice)(notice, extra);
948
1002
  }
949
- if ((0, util_1$1.objectIsEmpty)(notice)) {
1003
+ if ((0, util_1$6.objectIsEmpty)(notice)) {
950
1004
  return null;
951
1005
  }
952
1006
  var context = this.__store.getContents('context');
@@ -956,9 +1010,9 @@
956
1010
  // Turning into a Set will remove duplicates
957
1011
  var tags = noticeTags.concat(contextTags).concat(configTags);
958
1012
  var uniqueTags = tags.filter(function (item, index) { return tags.indexOf(item) === index; });
959
- notice = (0, util_1$1.merge)(notice, {
1013
+ notice = (0, util_1$6.merge)(notice, {
960
1014
  name: notice.name || 'Error',
961
- context: (0, util_1$1.merge)(context, notice.context),
1015
+ context: (0, util_1$6.merge)(context, notice.context),
962
1016
  projectRoot: notice.projectRoot || this.config.projectRoot,
963
1017
  environment: notice.environment || this.config.environment,
964
1018
  component: notice.component || this.config.component,
@@ -966,12 +1020,13 @@
966
1020
  revision: notice.revision || this.config.revision,
967
1021
  tags: uniqueTags,
968
1022
  });
969
- var backtraceShift = 0;
970
1023
  if (typeof notice.stack !== 'string' || !notice.stack.trim()) {
971
- notice.stack = (0, util_1$1.generateStackTrace)();
972
- backtraceShift = 2;
1024
+ notice.stack = (0, util_1$6.generateStackTrace)();
1025
+ notice.backtrace = (0, util_1$6.makeBacktrace)(notice.stack, true, this.logger);
1026
+ }
1027
+ else {
1028
+ notice.backtrace = (0, util_1$6.makeBacktrace)(notice.stack, false, this.logger);
973
1029
  }
974
- notice.backtrace = (0, util_1$1.makeBacktrace)(notice.stack, backtraceShift);
975
1030
  return notice;
976
1031
  };
977
1032
  Client.prototype.addBreadcrumb = function (message, opts) {
@@ -979,7 +1034,7 @@
979
1034
  return;
980
1035
  }
981
1036
  opts = opts || {};
982
- var metadata = (0, util_1$1.shallowClone)(opts.metadata);
1037
+ var metadata = (0, util_1$6.shallowClone)(opts.metadata);
983
1038
  var category = opts.category || 'custom';
984
1039
  var timestamp = new Date().toISOString();
985
1040
  this.__store.addBreadcrumb({
@@ -1003,8 +1058,8 @@
1003
1058
  return (this.config.environment && this.config.developmentEnvironments.includes(this.config.environment));
1004
1059
  };
1005
1060
  Client.prototype.__buildPayload = function (notice) {
1006
- var headers = (0, util_1$1.filter)(notice.headers, this.config.filters) || {};
1007
- var cgiData = (0, util_1$1.filter)(__assign(__assign({}, notice.cgiData), (0, util_1$1.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1061
+ var headers = (0, util_1$6.filter)(notice.headers, this.config.filters) || {};
1062
+ var cgiData = (0, util_1$6.filter)(__assign(__assign({}, notice.cgiData), (0, util_1$6.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1008
1063
  return {
1009
1064
  notifier: notifier,
1010
1065
  breadcrumbs: {
@@ -1017,16 +1072,16 @@
1017
1072
  backtrace: notice.backtrace,
1018
1073
  fingerprint: notice.fingerprint,
1019
1074
  tags: notice.tags,
1020
- causes: (0, util_1$1.getCauses)(notice),
1075
+ causes: (0, util_1$6.getCauses)(notice, this.logger),
1021
1076
  },
1022
1077
  request: {
1023
- url: (0, util_1$1.filterUrl)(notice.url, this.config.filters),
1078
+ url: (0, util_1$6.filterUrl)(notice.url, this.config.filters),
1024
1079
  component: notice.component,
1025
1080
  action: notice.action,
1026
1081
  context: notice.context,
1027
1082
  cgi_data: cgiData,
1028
- params: (0, util_1$1.filter)(notice.params, this.config.filters) || {},
1029
- session: (0, util_1$1.filter)(notice.session, this.config.filters) || {}
1083
+ params: (0, util_1$6.filter)(notice.params, this.config.filters) || {},
1084
+ session: (0, util_1$6.filter)(notice.session, this.config.filters) || {}
1030
1085
  },
1031
1086
  server: {
1032
1087
  project_root: notice.projectRoot,
@@ -1092,7 +1147,7 @@
1092
1147
  var util = {};
1093
1148
 
1094
1149
  Object.defineProperty(util, "__esModule", { value: true });
1095
- util.preferCatch = util.encodeCookie = util.decodeCookie = util.localURLPathname = util.parseURL = util.nativeFetch = util.stringTextOfElement = util.stringSelectorOfElement = util.stringNameOfElement = void 0;
1150
+ util.globalThisOrWindow = util.preferCatch = util.encodeCookie = util.decodeCookie = util.localURLPathname = util.parseURL = util.nativeFetch = util.stringTextOfElement = util.stringSelectorOfElement = util.stringNameOfElement = void 0;
1096
1151
  /**
1097
1152
  * Converts an HTMLElement into a human-readable string.
1098
1153
  * @param {!HTMLElement} element
@@ -1149,10 +1204,11 @@
1149
1204
  }
1150
1205
  util.stringTextOfElement = stringTextOfElement;
1151
1206
  function nativeFetch() {
1152
- if (!window.fetch) {
1207
+ var global = globalThisOrWindow();
1208
+ if (!global.fetch) {
1153
1209
  return false;
1154
1210
  }
1155
- if (isNative(window.fetch)) {
1211
+ if (isNative(global.fetch)) {
1156
1212
  return true;
1157
1213
  }
1158
1214
  // If fetch isn't native, it may be wrapped by someone else. Try to get
@@ -1248,6 +1304,9 @@
1248
1304
  // will provide more information in modern browsers.
1249
1305
  util.preferCatch = (function () {
1250
1306
  var preferCatch = true;
1307
+ // In case we're in an environment without access to "window", lets make sure theres a window.
1308
+ if (typeof window === 'undefined')
1309
+ return preferCatch;
1251
1310
  // IE < 10
1252
1311
  if (!window.atob) {
1253
1312
  preferCatch = false;
@@ -1265,6 +1324,19 @@
1265
1324
  }
1266
1325
  return preferCatch;
1267
1326
  })();
1327
+ /** globalThis has fairly good support. But just in case, lets check its defined.
1328
+ * @see {https://caniuse.com/?search=globalThis}
1329
+ */
1330
+ function globalThisOrWindow() {
1331
+ if (typeof globalThis !== 'undefined') {
1332
+ return globalThis;
1333
+ }
1334
+ if (typeof self !== 'undefined') {
1335
+ return self;
1336
+ }
1337
+ return window;
1338
+ }
1339
+ util.globalThisOrWindow = globalThisOrWindow;
1268
1340
 
1269
1341
  var onerror = {};
1270
1342
 
@@ -1272,6 +1344,7 @@
1272
1344
  onerror.onError = onerror.ignoreNextOnError = void 0;
1273
1345
  /* eslint-disable prefer-rest-params */
1274
1346
  var core_1$5 = src;
1347
+ var util_1$5 = util;
1275
1348
  var instrument$4 = core_1$5.Util.instrument, makeNotice = core_1$5.Util.makeNotice;
1276
1349
  var ignoreOnError = 0;
1277
1350
  var currentTimeout;
@@ -1285,7 +1358,7 @@
1285
1358
  onerror.ignoreNextOnError = ignoreNextOnError;
1286
1359
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1287
1360
  function onError(_window) {
1288
- if (_window === void 0) { _window = window; }
1361
+ if (_window === void 0) { _window = (0, util_1$5.globalThisOrWindow)(); }
1289
1362
  return {
1290
1363
  load: function (client) {
1291
1364
  instrument$4(_window, 'onerror', function (original) {
@@ -1330,7 +1403,7 @@
1330
1403
  return function (msg, url, line, col, err) {
1331
1404
  onerror(msg, url, line, col, err);
1332
1405
  if (typeof original === 'function') {
1333
- return original.apply(window, arguments);
1406
+ return original.apply(_window, arguments);
1334
1407
  }
1335
1408
  return false;
1336
1409
  };
@@ -1345,10 +1418,11 @@
1345
1418
  Object.defineProperty(onunhandledrejection, "__esModule", { value: true });
1346
1419
  /* eslint-disable prefer-rest-params */
1347
1420
  var core_1$4 = src;
1421
+ var util_1$4 = util;
1348
1422
  var instrument$3 = core_1$4.Util.instrument;
1349
1423
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1350
1424
  function default_1$3(_window) {
1351
- if (_window === void 0) { _window = window; }
1425
+ if (_window === void 0) { _window = (0, util_1$4.globalThisOrWindow)(); }
1352
1426
  return {
1353
1427
  load: function (client) {
1354
1428
  if (!client.config.enableUnhandledRejection) {
@@ -1406,10 +1480,10 @@
1406
1480
  Object.defineProperty(breadcrumbs, "__esModule", { value: true });
1407
1481
  /* eslint-disable prefer-rest-params */
1408
1482
  var core_1$3 = src;
1409
- var util_1 = util;
1483
+ var util_1$3 = util;
1410
1484
  var sanitize$1 = core_1$3.Util.sanitize, instrument$2 = core_1$3.Util.instrument;
1411
1485
  function default_1$2(_window) {
1412
- if (_window === void 0) { _window = window; }
1486
+ if (_window === void 0) { _window = (0, util_1$3.globalThisOrWindow)(); }
1413
1487
  return {
1414
1488
  load: function (client) {
1415
1489
  function breadcrumbsEnabled(type) {
@@ -1467,9 +1541,9 @@
1467
1541
  _window.addEventListener('click', function (event) {
1468
1542
  var message, selector, text;
1469
1543
  try {
1470
- message = (0, util_1.stringNameOfElement)(event.target);
1471
- selector = (0, util_1.stringSelectorOfElement)(event.target);
1472
- text = (0, util_1.stringTextOfElement)(event.target);
1544
+ message = (0, util_1$3.stringNameOfElement)(event.target);
1545
+ selector = (0, util_1$3.stringSelectorOfElement)(event.target);
1546
+ text = (0, util_1$3.stringTextOfElement)(event.target);
1473
1547
  }
1474
1548
  catch (e) {
1475
1549
  message = 'UI Click';
@@ -1488,13 +1562,16 @@
1488
1562
  event: event
1489
1563
  }
1490
1564
  });
1491
- }, true);
1565
+ }, _window.location ? true : false); // In CloudFlare workers useCapture must be false. window.locaiton is a hacky way to detect it.
1492
1566
  })();
1493
1567
  // Breadcrumbs: instrument XMLHttpRequest
1494
1568
  (function () {
1495
1569
  if (!breadcrumbsEnabled('network')) {
1496
1570
  return;
1497
1571
  }
1572
+ // Some environments may not support XMLHttpRequest.
1573
+ if (typeof XMLHttpRequest === 'undefined')
1574
+ return;
1498
1575
  // -- On xhr.open: capture initial metadata
1499
1576
  instrument$2(XMLHttpRequest.prototype, 'open', function (original) {
1500
1577
  return function () {
@@ -1502,7 +1579,7 @@
1502
1579
  var xhr = this;
1503
1580
  var url = arguments[1];
1504
1581
  var method = typeof arguments[0] === 'string' ? arguments[0].toUpperCase() : arguments[0];
1505
- var message = "".concat(method, " ").concat((0, util_1.localURLPathname)(url));
1582
+ var message = "".concat(method, " ").concat((0, util_1$3.localURLPathname)(url));
1506
1583
  this.__hb_xhr = {
1507
1584
  type: 'xhr',
1508
1585
  method: method,
@@ -1559,7 +1636,7 @@
1559
1636
  if (!breadcrumbsEnabled('network')) {
1560
1637
  return;
1561
1638
  }
1562
- if (!(0, util_1.nativeFetch)()) {
1639
+ if (!(0, util_1$3.nativeFetch)()) {
1563
1640
  // Polyfills use XHR.
1564
1641
  return;
1565
1642
  }
@@ -1587,7 +1664,8 @@
1587
1664
  if (typeof method === 'string') {
1588
1665
  method = method.toUpperCase();
1589
1666
  }
1590
- var message = "".concat(method, " ").concat((0, util_1.localURLPathname)(url));
1667
+ // localURLPathname cant be constructed for CF workers due to reliance on "document".
1668
+ var message = "".concat(method, " ").concat(typeof document === 'undefined' ? url : (0, util_1$3.localURLPathname)(url));
1591
1669
  var metadata = {
1592
1670
  type: 'fetch',
1593
1671
  method: method,
@@ -1618,6 +1696,10 @@
1618
1696
  if (!breadcrumbsEnabled('navigation')) {
1619
1697
  return;
1620
1698
  }
1699
+ if (_window.location == null) {
1700
+ // Most likely in a CF worker, we should be listening to fetch requests instead.
1701
+ return;
1702
+ }
1621
1703
  // The last known href of the current page
1622
1704
  var lastHref = _window.location.href;
1623
1705
  function recordUrlChange(from, to) {
@@ -1663,9 +1745,10 @@
1663
1745
  Object.defineProperty(timers, "__esModule", { value: true });
1664
1746
  /* eslint-disable prefer-rest-params */
1665
1747
  var core_1$2 = src;
1748
+ var util_1$2 = util;
1666
1749
  var instrument$1 = core_1$2.Util.instrument;
1667
1750
  function default_1$1(_window) {
1668
- if (_window === void 0) { _window = window; }
1751
+ if (_window === void 0) { _window = (0, util_1$2.globalThisOrWindow)(); }
1669
1752
  return {
1670
1753
  load: function (client) {
1671
1754
  // Wrap timers
@@ -1699,9 +1782,10 @@
1699
1782
 
1700
1783
  Object.defineProperty(event_listeners, "__esModule", { value: true });
1701
1784
  var core_1$1 = src;
1785
+ var util_1$1 = util;
1702
1786
  var instrument = core_1$1.Util.instrument;
1703
1787
  function default_1(_window) {
1704
- if (_window === void 0) { _window = window; }
1788
+ if (_window === void 0) { _window = (0, util_1$1.globalThisOrWindow)(); }
1705
1789
  return {
1706
1790
  load: function (client) {
1707
1791
  // Wrap event listeners
@@ -1742,31 +1826,88 @@
1742
1826
 
1743
1827
  var transport = {};
1744
1828
 
1829
+ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
1830
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1831
+ return new (P || (P = Promise))(function (resolve, reject) {
1832
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1833
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1834
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1835
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1836
+ });
1837
+ };
1838
+ var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1839
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
1840
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1841
+ function verb(n) { return function (v) { return step([n, v]); }; }
1842
+ function step(op) {
1843
+ if (f) throw new TypeError("Generator is already executing.");
1844
+ while (_) try {
1845
+ 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;
1846
+ if (y = 0, t) op = [op[0] & 2, t.value];
1847
+ switch (op[0]) {
1848
+ case 0: case 1: t = op; break;
1849
+ case 4: _.label++; return { value: op[1], done: false };
1850
+ case 5: _.label++; y = op[1]; op = [0]; continue;
1851
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
1852
+ default:
1853
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
1854
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
1855
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
1856
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
1857
+ if (t[2]) _.ops.pop();
1858
+ _.trys.pop(); continue;
1859
+ }
1860
+ op = body.call(thisArg, _);
1861
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
1862
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1863
+ }
1864
+ };
1745
1865
  Object.defineProperty(transport, "__esModule", { value: true });
1746
1866
  transport.BrowserTransport = void 0;
1747
1867
  var core_1 = src;
1868
+ var util_1 = util;
1748
1869
  var sanitize = core_1.Util.sanitize;
1870
+ /**
1871
+ * Helper function to get typesafe Object.entries()
1872
+ * https://twitter.com/mattpocockuk/status/1502264005251018754?lang=en
1873
+ */
1874
+ function objectEntries(obj) {
1875
+ return Object.entries(obj);
1876
+ }
1749
1877
  var BrowserTransport = /** @class */ (function () {
1750
1878
  function BrowserTransport() {
1751
1879
  }
1752
1880
  BrowserTransport.prototype.send = function (options, payload) {
1753
- return new Promise(function (resolve, reject) {
1754
- try {
1755
- var x_1 = new XMLHttpRequest();
1756
- x_1.open(options.method, options.endpoint, options.async);
1757
- if (Object.keys(options.headers || []).length) {
1758
- for (var i in options.headers) {
1759
- if (typeof options.headers[i] !== 'undefined') {
1760
- x_1.setRequestHeader(i, String(options.headers[i]));
1881
+ return __awaiter(this, void 0, void 0, function () {
1882
+ var headerArray, headers, requestInit, response, body;
1883
+ return __generator(this, function (_a) {
1884
+ switch (_a.label) {
1885
+ case 0:
1886
+ headerArray = options.headers ? objectEntries(options.headers) : [];
1887
+ headers = {};
1888
+ headerArray.forEach(function (_a) {
1889
+ var key = _a[0], value = _a[1];
1890
+ if (key != null && value != null) {
1891
+ headers[String(key)] = String(value);
1892
+ }
1893
+ });
1894
+ requestInit = {
1895
+ method: options.method,
1896
+ headers: headers
1897
+ };
1898
+ // GET methods cannot have a body.
1899
+ if (options.method === 'POST') {
1900
+ requestInit.body = payload ? JSON.stringify(sanitize(payload, options.maxObjectDepth)) : undefined;
1761
1901
  }
1762
- }
1902
+ return [4 /*yield*/, (0, util_1.globalThisOrWindow)().fetch(options.endpoint, requestInit)];
1903
+ case 1:
1904
+ response = _a.sent();
1905
+ return [4 /*yield*/, response.text()];
1906
+ case 2:
1907
+ body = _a.sent();
1908
+ return [2 /*return*/, Promise.resolve({ statusCode: response.status, body: body })];
1763
1909
  }
1764
- x_1.send(payload ? JSON.stringify(sanitize(payload, options.maxObjectDepth)) : undefined);
1765
- x_1.onload = function () { return resolve({ statusCode: x_1.status, body: x_1.response }); };
1766
- }
1767
- catch (err) {
1768
- reject(err);
1769
- }
1910
+ });
1770
1911
  });
1771
1912
  };
1772
1913
  return BrowserTransport;
@@ -1818,7 +1959,14 @@
1818
1959
  __extends(Honeybadger, _super);
1819
1960
  function Honeybadger(opts) {
1820
1961
  if (opts === void 0) { opts = {}; }
1821
- var _this = _super.call(this, __assign({ async: true, maxErrors: null, projectRoot: window.location.protocol + '//' + window.location.host }, opts), new transport_1.BrowserTransport()) || this;
1962
+ var _this = this;
1963
+ var global = (0, util_1.globalThisOrWindow)();
1964
+ var projectRoot = '';
1965
+ // Cloudflare workers do not have access to location API.
1966
+ if (global.location != null) {
1967
+ projectRoot = global.location.protocol + '//' + global.location.host;
1968
+ }
1969
+ _this = _super.call(this, __assign({ async: true, maxErrors: null, projectRoot: projectRoot }, opts), new transport_1.BrowserTransport()) || this;
1822
1970
  /** @internal */
1823
1971
  _this.__errorsSent = 0;
1824
1972
  /** @internal */
@@ -1830,7 +1978,7 @@
1830
1978
  _this.logger.debug('Dropping notice: max errors exceeded', notice);
1831
1979
  return false;
1832
1980
  }
1833
- if (notice && !notice.url) {
1981
+ if (notice && !notice.url && typeof document !== 'undefined') {
1834
1982
  notice.url = document.URL;
1835
1983
  }
1836
1984
  _this.__incrementErrorsCount();
@@ -1861,7 +2009,7 @@
1861
2009
  HTTP_COOKIE: undefined
1862
2010
  };
1863
2011
  cgiData.HTTP_USER_AGENT = navigator.userAgent;
1864
- if (document.referrer.match(/\S/)) {
2012
+ if (typeof document !== 'undefined' && document.referrer.match(/\S/)) {
1865
2013
  cgiData.HTTP_REFERER = document.referrer;
1866
2014
  }
1867
2015
  var cookiesObject;