@honeybadger-io/js 6.8.3 → 6.9.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.
@@ -16,8 +16,4 @@ export declare function localURLPathname(url: string): any;
16
16
  export declare function decodeCookie(string: string): Record<string, unknown>;
17
17
  export declare function encodeCookie(object: any): string;
18
18
  export declare const preferCatch: boolean;
19
- /** globalThis has fairly good support. But just in case, lets check its defined.
20
- * @see {https://caniuse.com/?search=globalThis}
21
- */
22
- export declare function globalThisOrWindow(): typeof globalThis;
23
19
  //# sourceMappingURL=util.d.ts.map
@@ -51,7 +51,7 @@ var server$1 = {};
51
51
 
52
52
  var src = {};
53
53
 
54
- var client$1 = {};
54
+ var events = {};
55
55
 
56
56
  var util$1 = {};
57
57
 
@@ -258,7 +258,7 @@ var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(stackTraceParser_esm);
258
258
  }
259
259
  };
260
260
  Object.defineProperty(exports, "__esModule", { value: true });
261
- exports.isBrowserConfig = exports.clone = exports.formatCGIData = exports.filterUrl = exports.filter = exports.generateStackTrace = exports.endpoint = exports.instrumentConsole = 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;
261
+ exports.logDeprecatedMethod = exports.globalThisOrWindow = exports.isBrowserConfig = exports.clone = exports.formatCGIData = exports.filterUrl = exports.filter = exports.generateStackTrace = exports.endpoint = exports.instrumentConsole = 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;
262
262
  /* eslint-disable prefer-rest-params */
263
263
  var stackTraceParser = __importStar(require$$0$1);
264
264
  function merge(obj1, obj2) {
@@ -799,9 +799,80 @@ var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(stackTraceParser_esm);
799
799
  return config.async !== undefined;
800
800
  }
801
801
  exports.isBrowserConfig = isBrowserConfig;
802
+ /** globalThis has fairly good support. But just in case, lets check its defined.
803
+ * @see {https://caniuse.com/?search=globalThis}
804
+ */
805
+ function globalThisOrWindow() {
806
+ if (typeof globalThis !== 'undefined') {
807
+ return globalThis;
808
+ }
809
+ if (typeof self !== 'undefined') {
810
+ return self;
811
+ }
812
+ return window;
813
+ }
814
+ exports.globalThisOrWindow = globalThisOrWindow;
815
+ var _deprecatedMethodCalls = {};
816
+ /**
817
+ * Logs a deprecation warning, every X calls to the method.
818
+ */
819
+ function logDeprecatedMethod(logger, oldMethod, newMethod, callCountThreshold) {
820
+ if (callCountThreshold === void 0) { callCountThreshold = 100; }
821
+ var key = "".concat(oldMethod, "-").concat(newMethod);
822
+ if (typeof _deprecatedMethodCalls[key] === 'undefined') {
823
+ _deprecatedMethodCalls[key] = 0;
824
+ }
825
+ if (_deprecatedMethodCalls[key] % callCountThreshold !== 0) {
826
+ _deprecatedMethodCalls[key]++;
827
+ return;
828
+ }
829
+ var msg = "Deprecation warning: ".concat(oldMethod, " has been deprecated; please use ").concat(newMethod, " instead.");
830
+ logger.warn(msg);
831
+ _deprecatedMethodCalls[key]++;
832
+ }
833
+ exports.logDeprecatedMethod = logDeprecatedMethod;
802
834
 
803
835
  } (util$1));
804
836
 
837
+ Object.defineProperty(events, "__esModule", { value: true });
838
+ var util_1$7 = util$1;
839
+ function default_1$2(_window) {
840
+ if (_window === void 0) { _window = (0, util_1$7.globalThisOrWindow)(); }
841
+ return {
842
+ shouldReloadOnConfigure: false,
843
+ load: function (client) {
844
+ function sendEventsToInsights() {
845
+ return client.config.eventsEnabled;
846
+ }
847
+ if (!sendEventsToInsights()) {
848
+ return;
849
+ }
850
+ (0, util_1$7.instrumentConsole)(_window, function (level, args) {
851
+ if (!sendEventsToInsights()) {
852
+ return;
853
+ }
854
+ if (args.length === 0) {
855
+ return;
856
+ }
857
+ var data = {
858
+ severity: level,
859
+ };
860
+ if (typeof args[0] === 'string') {
861
+ data.message = args[0];
862
+ data.args = args.slice(1);
863
+ }
864
+ else {
865
+ data.args = args;
866
+ }
867
+ client.event('log', data);
868
+ });
869
+ }
870
+ };
871
+ }
872
+ events.default = default_1$2;
873
+
874
+ var client$1 = {};
875
+
805
876
  var store = {};
806
877
 
807
878
  Object.defineProperty(store, "__esModule", { value: true });
@@ -876,6 +947,7 @@ defaults.CONFIG = {
876
947
  revision: null,
877
948
  reportData: null,
878
949
  breadcrumbsEnabled: true,
950
+ // we could decide the value of eventsEnabled based on `env` and `developmentEnvironments`
879
951
  eventsEnabled: false,
880
952
  maxBreadcrumbs: 40,
881
953
  maxObjectDepth: 8,
@@ -956,8 +1028,8 @@ var ThrottledEventsLogger = /** @class */ (function () {
956
1028
  this.config[k] = opts[k];
957
1029
  }
958
1030
  };
959
- ThrottledEventsLogger.prototype.logEvent = function (data) {
960
- this.queue.push(data);
1031
+ ThrottledEventsLogger.prototype.log = function (payload) {
1032
+ this.queue.push(payload);
961
1033
  if (!this.isProcessing) {
962
1034
  this.processQueue();
963
1035
  }
@@ -1016,8 +1088,9 @@ var ThrottledEventsLogger = /** @class */ (function () {
1016
1088
  /**
1017
1089
  * todo: improve this
1018
1090
  *
1019
- * The EventsLogger overrides the console methods
1020
- * so if we want to log something we need to use the original methods
1091
+ * The EventsLogger overrides the console methods to enable automatic instrumentation
1092
+ * of console logs to the Honeybadger API.
1093
+ * So if we want to log something in here we need to use the original methods.
1021
1094
  */
1022
1095
  ThrottledEventsLogger.prototype.originalLogger = function () {
1023
1096
  var _a, _b, _c, _d, _e;
@@ -1105,7 +1178,7 @@ var Client = /** @class */ (function () {
1105
1178
  this.__notifier = {
1106
1179
  name: '@honeybadger-io/core',
1107
1180
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/core',
1108
- version: '6.8.3'
1181
+ version: '6.9.0'
1109
1182
  };
1110
1183
  this.config = __assign$1(__assign$1({}, defaults_1.CONFIG), opts);
1111
1184
  this.__initStore();
@@ -1309,8 +1382,20 @@ var Client = /** @class */ (function () {
1309
1382
  });
1310
1383
  return this;
1311
1384
  };
1385
+ /**
1386
+ * @deprecated Use {@link event} instead.
1387
+ */
1312
1388
  Client.prototype.logEvent = function (data) {
1313
- this.__eventsLogger.logEvent(data);
1389
+ (0, util_1$4.logDeprecatedMethod)(this.logger, 'Honeybadger.logEvent', 'Honeybadger.event');
1390
+ this.event('log', data);
1391
+ };
1392
+ Client.prototype.event = function (type, data) {
1393
+ var _a;
1394
+ if (typeof type === 'object') {
1395
+ data = type;
1396
+ type = (_a = type['event_type']) !== null && _a !== void 0 ? _a : undefined;
1397
+ }
1398
+ this.__eventsLogger.log(__assign$1({ event_type: type, ts: new Date().toISOString() }, data));
1314
1399
  };
1315
1400
  Client.prototype.__getBreadcrumbs = function () {
1316
1401
  return this.__store.getContents('breadcrumbs').slice();
@@ -1496,13 +1581,20 @@ Object.defineProperty(types, "__esModule", { value: true });
1496
1581
  __setModuleDefault(result, mod);
1497
1582
  return result;
1498
1583
  };
1584
+ var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1585
+ return (mod && mod.__esModule) ? mod : { "default": mod };
1586
+ };
1499
1587
  Object.defineProperty(exports, "__esModule", { value: true });
1500
- exports.Util = exports.Types = exports.Client = void 0;
1588
+ exports.Plugins = exports.Util = exports.Types = exports.Client = void 0;
1589
+ var events_1 = __importDefault(events);
1501
1590
  var client_1 = client$1;
1502
1591
  Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
1503
1592
  __exportStar(store, exports);
1504
1593
  exports.Types = __importStar(types);
1505
1594
  exports.Util = __importStar(util$1);
1595
+ exports.Plugins = {
1596
+ events: events_1.default
1597
+ };
1506
1598
 
1507
1599
  } (src));
1508
1600
 
@@ -2617,7 +2709,8 @@ client.CheckInsClient = CheckInsClient;
2617
2709
  var endpoint = core_1.Util.endpoint;
2618
2710
  var DEFAULT_PLUGINS = [
2619
2711
  (0, uncaught_exception_plugin_1.default)(),
2620
- (0, unhandled_rejection_plugin_1.default)()
2712
+ (0, unhandled_rejection_plugin_1.default)(),
2713
+ core_1.Plugins.events(),
2621
2714
  ];
2622
2715
  var Honeybadger = /** @class */ (function (_super) {
2623
2716
  __extends(Honeybadger, _super);
@@ -2769,7 +2862,7 @@ client.CheckInsClient = CheckInsClient;
2769
2862
  var NOTIFIER = {
2770
2863
  name: '@honeybadger-io/js',
2771
2864
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
2772
- version: '6.8.3'
2865
+ version: '6.9.0'
2773
2866
  };
2774
2867
  var userAgent = function () {
2775
2868
  return "Honeybadger JS Server Client ".concat(NOTIFIER.version, ", ").concat(os_1.default.version(), "; ").concat(os_1.default.platform());