@honeybadger-io/js 3.2.4 → 4.0.0-beta.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.
Files changed (34) hide show
  1. package/dist/browser/honeybadger.js +193 -80
  2. package/dist/browser/honeybadger.js.map +1 -1
  3. package/dist/browser/honeybadger.min.js +1 -1
  4. package/dist/browser/honeybadger.min.js.map +1 -1
  5. package/dist/browser/types/browser/util.d.ts +1 -1
  6. package/dist/browser/types/core/client.d.ts +9 -1
  7. package/dist/browser/types/core/error.d.ts +3 -0
  8. package/dist/browser/types/core/types.d.ts +5 -4
  9. package/dist/browser/types/core/util.d.ts +4 -2
  10. package/dist/browser/types/server/aws_lambda.d.ts +9 -0
  11. package/dist/browser/types/server/integrations/uncaught_exception.d.ts +2 -0
  12. package/dist/browser/types/server/integrations/unhandled_rejection.d.ts +2 -0
  13. package/dist/browser/types/server/middleware.d.ts +4 -0
  14. package/dist/browser/types/server/util.d.ts +9 -0
  15. package/dist/browser/types/server.d.ts +13 -0
  16. package/dist/server/honeybadger.d.ts +2 -1
  17. package/dist/server/honeybadger.js +313 -93
  18. package/dist/server/types/browser/integrations/breadcrumbs.d.ts +2 -0
  19. package/dist/server/types/browser/integrations/event_listeners.d.ts +2 -0
  20. package/dist/server/types/browser/integrations/onerror.d.ts +3 -0
  21. package/dist/server/types/browser/integrations/onunhandledrejection.d.ts +2 -0
  22. package/dist/server/types/browser/integrations/timers.d.ts +2 -0
  23. package/dist/server/types/browser/util.d.ts +18 -0
  24. package/dist/server/types/browser.d.ts +15 -0
  25. package/dist/server/types/core/client.d.ts +9 -1
  26. package/dist/server/types/core/error.d.ts +3 -0
  27. package/dist/server/types/core/types.d.ts +5 -4
  28. package/dist/server/types/core/util.d.ts +4 -2
  29. package/dist/server/types/server/aws_lambda.d.ts +9 -0
  30. package/dist/server/types/server/middleware.d.ts +3 -5
  31. package/dist/server/types/server/util.d.ts +7 -0
  32. package/dist/server/types/server.d.ts +2 -1
  33. package/honeybadger.d.ts +2 -1
  34. package/package.json +23 -21
@@ -56,7 +56,45 @@ var __assign = function() {
56
56
  return t;
57
57
  };
58
58
  return __assign.apply(this, arguments);
59
- };
59
+ };
60
+
61
+ function __awaiter(thisArg, _arguments, P, generator) {
62
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
63
+ return new (P || (P = Promise))(function (resolve, reject) {
64
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
65
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
66
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
67
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
68
+ });
69
+ }
70
+
71
+ function __generator(thisArg, body) {
72
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
73
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
74
+ function verb(n) { return function (v) { return step([n, v]); }; }
75
+ function step(op) {
76
+ if (f) throw new TypeError("Generator is already executing.");
77
+ while (_) try {
78
+ 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;
79
+ if (y = 0, t) op = [op[0] & 2, t.value];
80
+ switch (op[0]) {
81
+ case 0: case 1: t = op; break;
82
+ case 4: _.label++; return { value: op[1], done: false };
83
+ case 5: _.label++; y = op[1]; op = [0]; continue;
84
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
87
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
88
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
89
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
90
+ if (t[2]) _.ops.pop();
91
+ _.trys.pop(); continue;
92
+ }
93
+ op = body.call(thisArg, _);
94
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
95
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
96
+ }
97
+ }
60
98
 
61
99
  var UNKNOWN_FUNCTION = '<unknown>';
62
100
  /**
@@ -221,7 +259,8 @@ function objectIsEmpty(obj) {
221
259
  function makeBacktrace(stack, shift) {
222
260
  if (shift === void 0) { shift = 0; }
223
261
  try {
224
- var backtrace = parse(stack).map(function (line) {
262
+ var backtrace = parse(stack)
263
+ .map(function (line) {
225
264
  return {
226
265
  file: line.file,
227
266
  method: line.methodName,
@@ -237,17 +276,39 @@ function makeBacktrace(stack, shift) {
237
276
  return [];
238
277
  }
239
278
  }
279
+ function getSourceForBacktrace(backtrace, getSourceFileHandler, cb) {
280
+ if (!getSourceFileHandler || !backtrace || !backtrace.length) {
281
+ cb([]);
282
+ return;
283
+ }
284
+ var result = [];
285
+ var getSourceFromFile = function (index) {
286
+ if (index === void 0) { index = 0; }
287
+ if (!backtrace.length) {
288
+ return cb(result);
289
+ }
290
+ var trace = backtrace.splice(0)[index];
291
+ getSourceFileHandler(trace.file, (function (fileContent) {
292
+ result[index] = getSourceCodeSnippet(fileContent, trace.number);
293
+ getSourceFromFile(index + 1);
294
+ }));
295
+ };
296
+ getSourceFromFile();
297
+ }
240
298
  function runBeforeNotifyHandlers(notice, handlers) {
299
+ var result = true;
241
300
  for (var i = 0, len = handlers.length; i < len; i++) {
242
301
  var handler = handlers[i];
243
302
  if (handler(notice) === false) {
244
- return false;
303
+ result = false;
245
304
  }
246
305
  }
247
- return true;
306
+ return result;
248
307
  }
249
308
  function runAfterNotifyHandlers(notice, handlers, error) {
250
- if (error === void 0) { error = undefined; }
309
+ if (notice && notice.afterNotify) {
310
+ handlers.unshift(notice.afterNotify);
311
+ }
251
312
  for (var i = 0, len = handlers.length; i < len; i++) {
252
313
  handlers[i](error, notice);
253
314
  }
@@ -335,8 +396,13 @@ function logger(client) {
335
396
  for (var _i = 0; _i < arguments.length; _i++) {
336
397
  args[_i] = arguments[_i];
337
398
  }
338
- if (method === 'debug' && !client.config.debug) {
339
- return;
399
+ if (method === 'debug') {
400
+ if (!client.config.debug) {
401
+ return;
402
+ }
403
+ // Log at default level so that you don't need to also enable verbose
404
+ // logging in Chrome.
405
+ method = 'log';
340
406
  }
341
407
  args.unshift('[Honeybadger]');
342
408
  (_a = client.config.logger)[method].apply(_a, args);
@@ -375,7 +441,7 @@ function makeNotice(thing) {
375
441
  function endpoint(config, path) {
376
442
  var endpoint = config.endpoint.trim().replace(/\/$/, '');
377
443
  path = path.trim().replace(/(^\/|\/$)/g, '');
378
- return endpoint + "/" + path;
444
+ return "".concat(endpoint, "/").concat(path);
379
445
  }
380
446
  function generateStackTrace() {
381
447
  try {
@@ -434,7 +500,9 @@ function filter(obj, filters) {
434
500
  return newObj;
435
501
  }
436
502
  if (is('Array', obj)) {
437
- return obj.map(function (v) { return filter(v); });
503
+ return obj.map(function (v) {
504
+ return filter(v);
505
+ });
438
506
  }
439
507
  if (is('Function', obj)) {
440
508
  return '[FUNC]';
@@ -470,7 +538,7 @@ function filterUrl(url, filters) {
470
538
  query.split(/[&]\s?/).forEach(function (pair) {
471
539
  var _a = pair.split('=', 2), key = _a[0], value = _a[1];
472
540
  if (filterMatch(key, filters)) {
473
- result = result.replace(key + "=" + value, key + "=[FILTERED]");
541
+ result = result.replace("".concat(key, "=").concat(value), "".concat(key, "=[FILTERED]"));
474
542
  }
475
543
  });
476
544
  return result;
@@ -484,11 +552,30 @@ function formatCGIData(vars, prefix) {
484
552
  });
485
553
  return formattedVars;
486
554
  }
555
+ function getSourceCodeSnippet(fileData, lineNumber, sourceRadius) {
556
+ if (sourceRadius === void 0) { sourceRadius = 2; }
557
+ if (!fileData) {
558
+ return null;
559
+ }
560
+ var lines = fileData.split('\n');
561
+ // add one empty line because array index starts from 0, but error line number is counted from 1
562
+ lines.unshift('');
563
+ var start = lineNumber - sourceRadius;
564
+ var end = lineNumber + sourceRadius;
565
+ var result = {};
566
+ for (var i = start; i <= end; i++) {
567
+ var line = lines[i];
568
+ if (typeof line === 'string') {
569
+ result[i] = line;
570
+ }
571
+ }
572
+ return result;
573
+ }
487
574
 
488
575
  var notifier = {
489
576
  name: 'honeybadger-js',
490
577
  url: 'https://github.com/honeybadger-io/honeybadger-js',
491
- version: '3.2.4'
578
+ version: '4.0.0-beta.0'
492
579
  };
493
580
  // Split at commas
494
581
  var TAG_SEPARATOR = /,/;
@@ -511,7 +598,7 @@ var Client = /** @class */ (function () {
511
598
  this.__beforeNotifyHandlers = [];
512
599
  /** @internal */
513
600
  this.__afterNotifyHandlers = [];
514
- 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'], disabled: false, debug: false, tags: null, enableUncaught: true, enableUnhandledRejection: true, afterUncaught: function () { return true; }, filters: ['creditcard', 'password'], __plugins: [] }, opts);
601
+ 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);
515
602
  this.logger = logger(this);
516
603
  }
517
604
  Client.prototype.factory = function (_opts) {
@@ -561,22 +648,106 @@ var Client = /** @class */ (function () {
561
648
  this.__breadcrumbs = [];
562
649
  return this;
563
650
  };
564
- Client.prototype.notify = function (notice, name, extra) {
651
+ Client.prototype.notify = function (noticeable, name, extra) {
652
+ var _this = this;
565
653
  if (name === void 0) { name = undefined; }
566
654
  if (extra === void 0) { extra = undefined; }
567
- if (!this.config.apiKey) {
568
- this.logger.warn('Unable to send error report: no API key has been configured');
569
- return false;
655
+ var preConditionError = null;
656
+ var notice = this.makeNotice(noticeable, name, extra);
657
+ if (!notice) {
658
+ this.logger.debug('failed to build error report');
659
+ preConditionError = new Error('failed to build error report');
570
660
  }
571
- if (this.config.disabled) {
572
- this.logger.warn('Deprecation warning: instead of `disabled: true`, use `reportData: false` to explicitly disable Honeybadger reporting. (Dropping notice: honeybadger.js is disabled)');
573
- return false;
661
+ if (!preConditionError && this.config.reportData === false) {
662
+ this.logger.debug('skipping error report: honeybadger.js is disabled', notice);
663
+ preConditionError = new Error('honeybadger.js is disabled');
664
+ }
665
+ if (!preConditionError && this.__developmentMode()) {
666
+ this.logger.log('honeybadger.js is in development mode; the following error report will be sent in production.', notice);
667
+ preConditionError = new Error('honeybadger.js is in development mode');
668
+ }
669
+ if (!preConditionError && !this.config.apiKey) {
670
+ this.logger.warn('could not send error report: no API key has been configured', notice);
671
+ preConditionError = new Error('missing API key');
672
+ }
673
+ var beforeNotifyResult = runBeforeNotifyHandlers(notice, this.__beforeNotifyHandlers);
674
+ if (!preConditionError && !beforeNotifyResult) {
675
+ this.logger.debug('skipping error report: beforeNotify handlers returned false', notice);
676
+ preConditionError = new Error('beforeNotify handlers returned false');
574
677
  }
575
- if (!this.__reportData()) {
576
- this.logger.debug('Dropping notice: honeybadger.js is in development mode');
678
+ if (preConditionError) {
679
+ runAfterNotifyHandlers(notice, this.__afterNotifyHandlers, preConditionError);
577
680
  return false;
578
681
  }
579
- notice = makeNotice(notice);
682
+ this.addBreadcrumb('Honeybadger Notice', {
683
+ category: 'notice',
684
+ metadata: {
685
+ message: notice.message,
686
+ name: notice.name,
687
+ stack: notice.stack
688
+ }
689
+ });
690
+ notice.__breadcrumbs = this.config.breadcrumbsEnabled ? this.__breadcrumbs.slice() : [];
691
+ // we need to have the source file data before the beforeNotifyHandlers,
692
+ // in case they modify them
693
+ var sourceCodeData = notice ? notice.backtrace.slice() : null;
694
+ getSourceForBacktrace(sourceCodeData, this.__getSourceFileHandler, function (sourcePerTrace) {
695
+ sourcePerTrace.forEach(function (source, index) {
696
+ notice.backtrace[index].source = source;
697
+ });
698
+ _this.__send(notice);
699
+ });
700
+ return true;
701
+ };
702
+ /**
703
+ * An async version of {@link notify} that resolves only after the notice has been reported to Honeybadger.
704
+ * Implemented using the {@link afterNotify} hook.
705
+ * Rejects if for any reason the report failed to be reported.
706
+ * Useful in serverless environments (AWS Lambda).
707
+ */
708
+ Client.prototype.notifyAsync = function (noticeable, name, extra) {
709
+ var _this = this;
710
+ if (name === void 0) { name = undefined; }
711
+ if (extra === void 0) { extra = undefined; }
712
+ return new Promise(function (resolve, reject) {
713
+ var applyAfterNotify = function (partialNotice) {
714
+ var originalAfterNotify = partialNotice.afterNotify;
715
+ partialNotice.afterNotify = function (err) {
716
+ originalAfterNotify === null || originalAfterNotify === void 0 ? void 0 : originalAfterNotify.call(_this, err);
717
+ if (err) {
718
+ return reject(err);
719
+ }
720
+ resolve();
721
+ };
722
+ };
723
+ // We have to respect any afterNotify hooks that come from the arguments
724
+ var objectToOverride;
725
+ if (noticeable.afterNotify) {
726
+ objectToOverride = noticeable;
727
+ }
728
+ else if (name && name.afterNotify) {
729
+ objectToOverride = name;
730
+ }
731
+ else if (extra && extra.afterNotify) {
732
+ objectToOverride = extra;
733
+ }
734
+ else if (name && typeof name === 'object') {
735
+ objectToOverride = name;
736
+ }
737
+ else if (extra) {
738
+ objectToOverride = extra;
739
+ }
740
+ else {
741
+ objectToOverride = name = {};
742
+ }
743
+ applyAfterNotify(objectToOverride);
744
+ _this.notify(noticeable, name, extra);
745
+ });
746
+ };
747
+ Client.prototype.makeNotice = function (noticeable, name, extra) {
748
+ if (name === void 0) { name = undefined; }
749
+ if (extra === void 0) { extra = undefined; }
750
+ var notice = makeNotice(noticeable);
580
751
  if (name && !(typeof name === 'object')) {
581
752
  var n = String(name);
582
753
  name = { name: n };
@@ -588,7 +759,7 @@ var Client = /** @class */ (function () {
588
759
  notice = mergeNotice(notice, extra);
589
760
  }
590
761
  if (objectIsEmpty(notice)) {
591
- return false;
762
+ return null;
592
763
  }
593
764
  var noticeTags = this.__constructTags(notice.tags);
594
765
  var contextTags = this.__constructTags(this.__context["tags"]);
@@ -612,19 +783,7 @@ var Client = /** @class */ (function () {
612
783
  backtraceShift = 2;
613
784
  }
614
785
  notice.backtrace = makeBacktrace(notice.stack, backtraceShift);
615
- if (!runBeforeNotifyHandlers(notice, this.__beforeNotifyHandlers)) {
616
- return false;
617
- }
618
- this.addBreadcrumb('Honeybadger Notice', {
619
- category: 'notice',
620
- metadata: {
621
- message: notice.message,
622
- name: notice.name,
623
- stack: notice.stack
624
- }
625
- });
626
- notice.__breadcrumbs = this.config.breadcrumbsEnabled ? this.__breadcrumbs.slice() : [];
627
- return this.__send(notice);
786
+ return notice;
628
787
  };
629
788
  Client.prototype.addBreadcrumb = function (message, opts) {
630
789
  if (!this.config.breadcrumbsEnabled) {
@@ -647,11 +806,11 @@ var Client = /** @class */ (function () {
647
806
  return this;
648
807
  };
649
808
  /** @internal */
650
- Client.prototype.__reportData = function () {
651
- if (this.config.reportData !== null) {
652
- return this.config.reportData;
809
+ Client.prototype.__developmentMode = function () {
810
+ if (this.config.reportData === true) {
811
+ return false;
653
812
  }
654
- return !(this.config.environment && this.config.developmentEnvironments.includes(this.config.environment));
813
+ return (this.config.environment && this.config.developmentEnvironments.includes(this.config.environment));
655
814
  };
656
815
  /** @internal */
657
816
  Client.prototype.__send = function (_notice) {
@@ -711,7 +870,7 @@ function fatallyLogAndExit(err) {
711
870
  process.exit(1);
712
871
  }
713
872
  function getStats(cb) {
714
- var load = os__default['default'].loadavg(), stats = {
873
+ var load = os__default["default"].loadavg(), stats = {
715
874
  load: {
716
875
  one: load[0],
717
876
  five: load[1],
@@ -719,8 +878,8 @@ function getStats(cb) {
719
878
  },
720
879
  mem: {}
721
880
  };
722
- if (fs__default['default'].existsSync('/proc/meminfo')) {
723
- return fs__default['default'].readFile('/proc/meminfo', 'utf8', parseStats);
881
+ if (fs__default["default"].existsSync('/proc/meminfo')) {
882
+ return fs__default["default"].readFile('/proc/meminfo', 'utf8', parseStats);
724
883
  }
725
884
  fallback();
726
885
  function parseStats(err, memData) {
@@ -743,21 +902,117 @@ function getStats(cb) {
743
902
  }
744
903
  function fallback() {
745
904
  stats.mem = {
746
- free: os__default['default'].freemem(),
747
- total: os__default['default'].totalmem()
905
+ free: os__default["default"].freemem(),
906
+ total: os__default["default"].totalmem()
748
907
  };
749
908
  return cb(stats);
750
909
  }
751
910
  }
911
+ /**
912
+ * Get source file if possible, used to build `notice.backtrace.source`
913
+ *
914
+ * @param path to source code
915
+ * @param cb callback with fileContent
916
+ */
917
+ function getSourceFile(path, cb) {
918
+ fs__default["default"].readFile(path, 'utf-8', function (err, data) {
919
+ cb(err ? null : data);
920
+ });
921
+ }
922
+
923
+ function isHandlerSync(handler) {
924
+ return handler.length > 2;
925
+ }
926
+ function asyncHandler(handler, hb) {
927
+ var _this = this;
928
+ return function (event, context) { return __awaiter(_this, void 0, void 0, function () {
929
+ var err_1;
930
+ return __generator(this, function (_a) {
931
+ switch (_a.label) {
932
+ case 0:
933
+ _a.trys.push([0, 2, , 3]);
934
+ return [4 /*yield*/, handler(event, context)];
935
+ case 1: return [2 /*return*/, _a.sent()];
936
+ case 2:
937
+ err_1 = _a.sent();
938
+ return [2 /*return*/, new Promise(function (_, reject) {
939
+ hb.notify(err_1, {
940
+ afterNotify: function () {
941
+ hb.clear();
942
+ reject(err_1);
943
+ }
944
+ });
945
+ })];
946
+ case 3: return [2 /*return*/];
947
+ }
948
+ });
949
+ }); };
950
+ }
951
+ function syncHandler(handler, hb) {
952
+ return function (event, context, cb) {
953
+ var hbHandler = function (err) {
954
+ hb.notify(err, {
955
+ afterNotify: function () {
956
+ hb.clear();
957
+ cb(err);
958
+ }
959
+ });
960
+ };
961
+ try {
962
+ handler(event, context, function (error, result) {
963
+ if (error) {
964
+ return hbHandler(error);
965
+ }
966
+ cb(null, result);
967
+ });
968
+ }
969
+ catch (err) {
970
+ hbHandler(err);
971
+ }
972
+ };
973
+ }
974
+ function lambdaHandler(handler) {
975
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
976
+ var hb = this;
977
+ if (isHandlerSync(handler)) {
978
+ return syncHandler(handler, hb);
979
+ }
980
+ return asyncHandler(handler, hb);
981
+ }
982
+ var listenerRemoved = false;
983
+ /**
984
+ * Removes AWS Lambda default listener that
985
+ * exits the process before letting us report to honeybadger.
986
+ */
987
+ function removeAwsDefaultUncaughtExceptionListener() {
988
+ if (listenerRemoved) {
989
+ return;
990
+ }
991
+ listenerRemoved = true;
992
+ var listeners = process.listeners('uncaughtException');
993
+ if (listeners.length === 0) {
994
+ return;
995
+ }
996
+ // We assume it's the first listener
997
+ process.removeListener('uncaughtException', listeners[0]);
998
+ }
752
999
 
753
1000
  var count = 0;
1001
+ function removeAwsLambdaListener() {
1002
+ var isLambda = !!process.env.LAMBDA_TASK_ROOT;
1003
+ if (!isLambda) {
1004
+ return;
1005
+ }
1006
+ removeAwsDefaultUncaughtExceptionListener();
1007
+ }
754
1008
  function uncaughtException () {
755
1009
  return {
756
1010
  load: function (client) {
757
1011
  if (!client.config.enableUncaught) {
758
1012
  return;
759
1013
  }
760
- process.on('uncaughtException', function (uncaughtError) {
1014
+ removeAwsLambdaListener();
1015
+ process.on('uncaughtException', function honeybadgerUncaughtExceptionListener(uncaughtError) {
761
1016
  // Prevent recursive errors
762
1017
  if (count > 1) {
763
1018
  fatallyLogAndExit(uncaughtError);
@@ -801,7 +1056,7 @@ function fullUrl(req) {
801
1056
  // @ts-ignore The old @types/node incorrectly defines `address` as string|Address
802
1057
  var port = address ? address.port : undefined;
803
1058
  // @ts-ignore
804
- return url__default['default'].format({
1059
+ return url__default["default"].format({
805
1060
  protocol: req.protocol,
806
1061
  hostname: req.hostname,
807
1062
  port: port,
@@ -811,7 +1066,7 @@ function fullUrl(req) {
811
1066
  }
812
1067
  function requestHandler(req, res, next) {
813
1068
  this.clear();
814
- var dom = domain__default['default'].create();
1069
+ var dom = domain__default["default"].create();
815
1070
  dom.on('error', next);
816
1071
  dom.run(next);
817
1072
  }
@@ -828,43 +1083,12 @@ function errorHandler(err, req, _res, next) {
828
1083
  });
829
1084
  return next(err);
830
1085
  }
831
- function lambdaHandler(handler) {
832
- return function lambdaHandler(event, context, callback) {
833
- // eslint-disable-next-line prefer-rest-params
834
- var args = arguments;
835
- var dom = domain__default['default'].create();
836
- // eslint-disable-next-line @typescript-eslint/no-this-alias
837
- var hb = this;
838
- dom.on('error', function (err) {
839
- hb.notify(err, {
840
- afterNotify: function () {
841
- hb.clear();
842
- callback(err);
843
- }
844
- });
845
- });
846
- dom.run(function () {
847
- process.nextTick(function () {
848
- Promise.resolve(handler.apply(this, args))
849
- .then(function () { hb.clear(); })
850
- .catch(function (err) {
851
- hb.notify(err, {
852
- afterNotify: function () {
853
- hb.clear();
854
- callback(err);
855
- }
856
- });
857
- });
858
- });
859
- });
860
- }.bind(this);
861
- }
862
1086
 
863
1087
  var Honeybadger = /** @class */ (function (_super) {
864
1088
  __extends(Honeybadger, _super);
865
1089
  function Honeybadger(opts) {
866
1090
  if (opts === void 0) { opts = {}; }
867
- var _this = _super.call(this, __assign({ afterUncaught: fatallyLogAndExit, projectRoot: process.cwd(), hostname: os__default['default'].hostname() }, opts)) || this;
1091
+ var _this = _super.call(this, __assign({ afterUncaught: fatallyLogAndExit, projectRoot: process.cwd(), hostname: os__default["default"].hostname() }, opts)) || this;
868
1092
  /** @internal */
869
1093
  _this.__beforeNotifyHandlers = [
870
1094
  function (notice) {
@@ -877,6 +1101,7 @@ var Honeybadger = /** @class */ (function (_super) {
877
1101
  });
878
1102
  }
879
1103
  ];
1104
+ _this.__getSourceFileHandler = getSourceFile.bind(_this);
880
1105
  _this.errorHandler = errorHandler.bind(_this);
881
1106
  _this.requestHandler = requestHandler.bind(_this);
882
1107
  _this.lambdaHandler = lambdaHandler.bind(_this);
@@ -889,13 +1114,9 @@ var Honeybadger = /** @class */ (function (_super) {
889
1114
  Honeybadger.prototype.__send = function (notice) {
890
1115
  var _this = this;
891
1116
  var protocol = new url.URL(this.config.endpoint).protocol;
892
- var transport = (protocol === "http:" ? http__default['default'] : https__default['default']);
1117
+ var transport = (protocol === "http:" ? http__default["default"] : https__default["default"]);
893
1118
  var payload = this.__buildPayload(notice);
894
1119
  payload.server.pid = process.pid;
895
- var handlers = Array.prototype.slice.call(this.__afterNotifyHandlers);
896
- if (notice.afterNotify) {
897
- handlers.unshift(notice.afterNotify);
898
- }
899
1120
  getStats(function (stats) {
900
1121
  payload.server.stats = stats;
901
1122
  var data = Buffer.from(JSON.stringify(sanitize(payload, _this.config.maxObjectDepth)), 'utf8');
@@ -908,32 +1129,31 @@ var Honeybadger = /** @class */ (function (_super) {
908
1129
  }
909
1130
  };
910
1131
  var req = transport.request(endpoint(_this.config, '/v1/notices/js'), options, function (res) {
911
- _this.logger.debug("statusCode: " + res.statusCode);
1132
+ _this.logger.debug("statusCode: ".concat(res.statusCode));
912
1133
  var body = '';
913
1134
  res.on('data', function (chunk) {
914
1135
  body += chunk;
915
1136
  });
916
1137
  res.on('end', function () {
917
1138
  if (res.statusCode !== 201) {
918
- runAfterNotifyHandlers(notice, handlers, new Error("Bad HTTP response: " + res.statusCode));
919
- _this.logger.warn("Error report failed: unknown response from server. code=" + res.statusCode);
1139
+ runAfterNotifyHandlers(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
1140
+ _this.logger.warn("Error report failed: unknown response from server. code=".concat(res.statusCode));
920
1141
  return;
921
1142
  }
922
1143
  var uuid = JSON.parse(body).id;
923
1144
  runAfterNotifyHandlers(merge(notice, {
924
1145
  id: uuid
925
- }), handlers);
926
- _this.logger.info('Error report sent.', "id=" + uuid);
1146
+ }), _this.__afterNotifyHandlers);
1147
+ _this.logger.info('Error report sent.', "id=".concat(uuid));
927
1148
  });
928
1149
  });
929
1150
  req.on('error', function (err) {
930
- _this.logger.error('Error report failed: an unknown error occurred.', "message=" + err.message);
931
- runAfterNotifyHandlers(notice, handlers, err);
1151
+ _this.logger.error('Error report failed: an unknown error occurred.', "message=".concat(err.message));
1152
+ runAfterNotifyHandlers(notice, _this.__afterNotifyHandlers, err);
932
1153
  });
933
1154
  req.write(data);
934
1155
  req.end();
935
1156
  });
936
- return true;
937
1157
  };
938
1158
  return Honeybadger;
939
1159
  }(Client));
@@ -0,0 +1,2 @@
1
+ import { Plugin } from '../../core/types';
2
+ export default function (_window?: Window & typeof globalThis): Plugin;
@@ -0,0 +1,2 @@
1
+ import { Plugin } from '../../core/types';
2
+ export default function (_window?: Window & typeof globalThis): Plugin;
@@ -0,0 +1,3 @@
1
+ import { Plugin } from '../../core/types';
2
+ export declare function ignoreNextOnError(): void;
3
+ export declare function onError(_window?: any): Plugin;
@@ -0,0 +1,2 @@
1
+ import { Plugin } from '../../core/types';
2
+ export default function (_window?: any): Plugin;
@@ -0,0 +1,2 @@
1
+ import { Plugin } from '../../core/types';
2
+ export default function (_window?: Window & typeof globalThis): Plugin;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Converts an HTMLElement into a human-readable string.
3
+ * @param {!HTMLElement} element
4
+ * @return {string}
5
+ */
6
+ export declare function stringNameOfElement(element: HTMLElement): string;
7
+ export declare function stringSelectorOfElement(element: any): any;
8
+ export declare function stringTextOfElement(element: any): any;
9
+ export declare function nativeFetch(): boolean;
10
+ export declare function parseURL(url: any): {
11
+ protocol: any;
12
+ host: any;
13
+ pathname: any;
14
+ };
15
+ export declare function localURLPathname(url: any): any;
16
+ export declare function decodeCookie(string: string): Record<string, unknown>;
17
+ export declare function encodeCookie(object: any): string;
18
+ export declare const preferCatch: boolean;
@@ -0,0 +1,15 @@
1
+ import Client from './core/client';
2
+ import { Config } from './core/types';
3
+ interface BrowserConfig extends Config {
4
+ async: boolean;
5
+ maxErrors: number;
6
+ }
7
+ declare class Honeybadger extends Client {
8
+ config: BrowserConfig;
9
+ constructor(opts?: Partial<BrowserConfig>);
10
+ configure(opts?: Partial<BrowserConfig>): Client;
11
+ resetMaxErrors(): number;
12
+ factory(opts?: Partial<BrowserConfig>): Honeybadger;
13
+ }
14
+ declare const _default: Honeybadger;
15
+ export default _default;