@honeybadger-io/js 6.2.0 → 6.4.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.
@@ -296,6 +296,9 @@ var require$$0 = /*@__PURE__*/getAugmentedNamespace(stackTraceParser_esm);
296
296
  function makeBacktrace(stack, filterHbSourceCode, logger) {
297
297
  if (filterHbSourceCode === void 0) { filterHbSourceCode = false; }
298
298
  if (logger === void 0) { logger = console; }
299
+ if (!stack) {
300
+ return [];
301
+ }
299
302
  try {
300
303
  var backtrace = stackTraceParser
301
304
  .parse(stack)
@@ -412,14 +415,20 @@ var require$$0 = /*@__PURE__*/getAugmentedNamespace(stackTraceParser_esm);
412
415
  }
413
416
  exports.getSourceForBacktrace = getSourceForBacktrace;
414
417
  function runBeforeNotifyHandlers(notice, handlers) {
418
+ var results = [];
415
419
  var result = true;
416
420
  for (var i = 0, len = handlers.length; i < len; i++) {
417
421
  var handler = handlers[i];
418
- if (handler(notice) === false) {
422
+ var handlerResult = handler(notice);
423
+ if (handlerResult === false) {
419
424
  result = false;
420
425
  }
426
+ results.push(handlerResult);
421
427
  }
422
- return result;
428
+ return {
429
+ results: results,
430
+ result: result
431
+ };
423
432
  }
424
433
  exports.runBeforeNotifyHandlers = runBeforeNotifyHandlers;
425
434
  function runAfterNotifyHandlers(notice, handlers, error) {
@@ -808,6 +817,42 @@ var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
808
817
  };
809
818
  return __assign.apply(this, arguments);
810
819
  };
820
+ var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
821
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
822
+ return new (P || (P = Promise))(function (resolve, reject) {
823
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
824
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
825
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
826
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
827
+ });
828
+ };
829
+ var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
830
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
831
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
832
+ function verb(n) { return function (v) { return step([n, v]); }; }
833
+ function step(op) {
834
+ if (f) throw new TypeError("Generator is already executing.");
835
+ while (_) try {
836
+ 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;
837
+ if (y = 0, t) op = [op[0] & 2, t.value];
838
+ switch (op[0]) {
839
+ case 0: case 1: t = op; break;
840
+ case 4: _.label++; return { value: op[1], done: false };
841
+ case 5: _.label++; y = op[1]; op = [0]; continue;
842
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
843
+ default:
844
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
845
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
846
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
847
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
848
+ if (t[2]) _.ops.pop();
849
+ _.trys.pop(); continue;
850
+ }
851
+ op = body.call(thisArg, _);
852
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
853
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
854
+ }
855
+ };
811
856
  Object.defineProperty(client, "__esModule", { value: true });
812
857
  client.Client = void 0;
813
858
  var util_1$4 = util$1;
@@ -826,7 +871,7 @@ var Client = /** @class */ (function () {
826
871
  this.__notifier = {
827
872
  name: '@honeybadger-io/core',
828
873
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/core',
829
- version: '6.2.0'
874
+ version: '6.4.0'
830
875
  };
831
876
  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);
832
877
  this.__initStore();
@@ -839,6 +884,13 @@ var Client = /** @class */ (function () {
839
884
  Client.prototype.getNotifier = function () {
840
885
  return this.__notifier;
841
886
  };
887
+ /**
888
+ * CAREFUL: When adding a new notifier or updating the name of an existing notifier,
889
+ * the Honeybadger rails project may need its mappings updated.
890
+ * See https://github.com/honeybadger-io/honeybadger/blob/master/app/presenters/breadcrumbs_presenter.rb
891
+ * https://github.com/honeybadger-io/honeybadger/blob/master/app/models/parser/java_script.rb
892
+ * https://github.com/honeybadger-io/honeybadger/blob/master/app/models/language.rb
893
+ **/
842
894
  Client.prototype.setNotifier = function (notifier) {
843
895
  this.__notifier = notifier;
844
896
  };
@@ -887,81 +939,26 @@ var Client = /** @class */ (function () {
887
939
  var _this = this;
888
940
  if (name === void 0) { name = undefined; }
889
941
  if (extra === void 0) { extra = undefined; }
890
- var preConditionError = null;
891
942
  var notice = this.makeNotice(noticeable, name, extra);
892
- if (!notice) {
893
- this.logger.debug('failed to build error report');
894
- preConditionError = new Error('failed to build error report');
895
- }
896
- if (!preConditionError && this.config.reportData === false) {
897
- this.logger.debug('skipping error report: honeybadger.js is disabled', notice);
898
- preConditionError = new Error('honeybadger.js is disabled');
899
- }
900
- if (!preConditionError && this.__developmentMode()) {
901
- this.logger.log('honeybadger.js is in development mode; the following error report will be sent in production.', notice);
902
- preConditionError = new Error('honeybadger.js is in development mode');
903
- }
904
- if (!preConditionError && !this.config.apiKey) {
905
- this.logger.warn('could not send error report: no API key has been configured', notice);
906
- preConditionError = new Error('missing API key');
907
- }
908
943
  // we need to have the source file data before the beforeNotifyHandlers,
909
944
  // in case they modify them
910
945
  var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$4.shallowClone)(trace); }) : null;
911
- var beforeNotifyResult = (0, util_1$4.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
912
- if (!preConditionError && !beforeNotifyResult) {
913
- this.logger.debug('skipping error report: beforeNotify handlers returned false', notice);
914
- preConditionError = new Error('beforeNotify handlers returned false');
915
- }
916
- if (preConditionError) {
917
- (0, util_1$4.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionError);
946
+ var preConditionsResult = this.__runPreconditions(notice);
947
+ if (preConditionsResult instanceof Error) {
948
+ (0, util_1$4.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionsResult);
918
949
  return false;
919
950
  }
920
- this.addBreadcrumb('Honeybadger Notice', {
921
- category: 'notice',
922
- metadata: {
923
- message: notice.message,
924
- name: notice.name,
925
- stack: notice.stack
926
- }
927
- });
928
- var breadcrumbs = this.__store.getContents('breadcrumbs');
929
- notice.__breadcrumbs = this.config.breadcrumbsEnabled ? breadcrumbs : [];
930
- (0, util_1$4.getSourceForBacktrace)(sourceCodeData, this.__getSourceFileHandler)
931
- .then(function (sourcePerTrace) {
932
- sourcePerTrace.forEach(function (source, index) {
933
- notice.backtrace[index].source = source;
934
- });
935
- var payload = _this.__buildPayload(notice);
936
- _this.__transport
937
- .send({
938
- headers: {
939
- 'X-API-Key': _this.config.apiKey,
940
- 'Content-Type': 'application/json',
941
- 'Accept': 'text/json, application/json'
942
- },
943
- method: 'POST',
944
- endpoint: (0, util_1$4.endpoint)(_this.config.endpoint, '/v1/notices/js'),
945
- maxObjectDepth: _this.config.maxObjectDepth,
946
- logger: _this.logger,
947
- }, payload)
948
- .then(function (res) {
949
- if (res.statusCode !== 201) {
950
- (0, util_1$4.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
951
- _this.logger.warn("Error report failed: unknown response from server. code=".concat(res.statusCode));
952
- return;
951
+ if (preConditionsResult instanceof Promise) {
952
+ preConditionsResult.then(function (result) {
953
+ if (result instanceof Error) {
954
+ (0, util_1$4.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, result);
955
+ return false;
953
956
  }
954
- var uuid = JSON.parse(res.body).id;
955
- (0, util_1$4.runAfterNotifyHandlers)((0, util_1$4.merge)(notice, {
956
- id: uuid
957
- }), _this.__afterNotifyHandlers);
958
- _this.logger.info("Error report sent \u26A1 https://app.honeybadger.io/notice/".concat(uuid));
959
- })
960
- .catch(function (err) {
961
- _this.logger.error('Error report failed: an unknown error occurred.', "message=".concat(err.message));
962
- (0, util_1$4.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
957
+ return _this.__send(notice, sourceCodeData);
963
958
  });
964
- });
959
+ return true;
960
+ }
961
+ this.__send(notice, sourceCodeData).catch(function (_err) { });
965
962
  return true;
966
963
  };
967
964
  /**
@@ -1126,6 +1123,101 @@ var Client = /** @class */ (function () {
1126
1123
  }
1127
1124
  return tags.toString().split(TAG_SEPARATOR).filter(function (tag) { return NOT_BLANK.test(tag); });
1128
1125
  };
1126
+ Client.prototype.__runPreconditions = function (notice) {
1127
+ var _this = this;
1128
+ var preConditionError = null;
1129
+ if (!notice) {
1130
+ this.logger.debug('failed to build error report');
1131
+ preConditionError = new Error('failed to build error report');
1132
+ }
1133
+ if (this.config.reportData === false) {
1134
+ this.logger.debug('skipping error report: honeybadger.js is disabled', notice);
1135
+ preConditionError = new Error('honeybadger.js is disabled');
1136
+ }
1137
+ if (this.__developmentMode()) {
1138
+ this.logger.log('honeybadger.js is in development mode; the following error report will be sent in production.', notice);
1139
+ preConditionError = new Error('honeybadger.js is in development mode');
1140
+ }
1141
+ if (!this.config.apiKey) {
1142
+ this.logger.warn('could not send error report: no API key has been configured', notice);
1143
+ preConditionError = new Error('missing API key');
1144
+ }
1145
+ var beforeNotifyResult = (0, util_1$4.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
1146
+ if (!preConditionError && !beforeNotifyResult.result) {
1147
+ this.logger.debug('skipping error report: one or more beforeNotify handlers returned false', notice);
1148
+ preConditionError = new Error('beforeNotify handlers returned false');
1149
+ }
1150
+ if (beforeNotifyResult.results.length && beforeNotifyResult.results.some(function (result) { return result instanceof Promise; })) {
1151
+ return Promise.allSettled(beforeNotifyResult.results)
1152
+ .then(function (results) {
1153
+ if (!preConditionError && (results.some(function (result) { return result.status === 'rejected' || result.value === false; }))) {
1154
+ _this.logger.debug('skipping error report: one or more beforeNotify handlers returned false', notice);
1155
+ preConditionError = new Error('beforeNotify handlers (async) returned false');
1156
+ }
1157
+ if (preConditionError) {
1158
+ return preConditionError;
1159
+ }
1160
+ });
1161
+ }
1162
+ return preConditionError;
1163
+ };
1164
+ Client.prototype.__send = function (notice, originalBacktrace) {
1165
+ var _this = this;
1166
+ if (this.config.breadcrumbsEnabled) {
1167
+ this.addBreadcrumb('Honeybadger Notice', {
1168
+ category: 'notice',
1169
+ metadata: {
1170
+ message: notice.message,
1171
+ name: notice.name,
1172
+ stack: notice.stack
1173
+ }
1174
+ });
1175
+ notice.__breadcrumbs = this.__store.getContents('breadcrumbs');
1176
+ }
1177
+ else {
1178
+ notice.__breadcrumbs = [];
1179
+ }
1180
+ return (0, util_1$4.getSourceForBacktrace)(originalBacktrace, this.__getSourceFileHandler)
1181
+ .then(function (sourcePerTrace) { return __awaiter$1(_this, void 0, void 0, function () {
1182
+ var payload;
1183
+ return __generator$1(this, function (_a) {
1184
+ sourcePerTrace.forEach(function (source, index) {
1185
+ notice.backtrace[index].source = source;
1186
+ });
1187
+ payload = this.__buildPayload(notice);
1188
+ return [2 /*return*/, this.__transport
1189
+ .send({
1190
+ headers: {
1191
+ 'X-API-Key': this.config.apiKey,
1192
+ 'Content-Type': 'application/json',
1193
+ 'Accept': 'text/json, application/json'
1194
+ },
1195
+ method: 'POST',
1196
+ endpoint: (0, util_1$4.endpoint)(this.config.endpoint, '/v1/notices/js'),
1197
+ maxObjectDepth: this.config.maxObjectDepth,
1198
+ logger: this.logger,
1199
+ }, payload)];
1200
+ });
1201
+ }); })
1202
+ .then(function (res) {
1203
+ if (res.statusCode !== 201) {
1204
+ (0, util_1$4.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
1205
+ _this.logger.warn("Error report failed: unknown response from server. code=".concat(res.statusCode));
1206
+ return false;
1207
+ }
1208
+ var uuid = JSON.parse(res.body).id;
1209
+ (0, util_1$4.runAfterNotifyHandlers)((0, util_1$4.merge)(notice, {
1210
+ id: uuid
1211
+ }), _this.__afterNotifyHandlers);
1212
+ _this.logger.info("Error report sent \u26A1 https://app.honeybadger.io/notice/".concat(uuid));
1213
+ return true;
1214
+ })
1215
+ .catch(function (err) {
1216
+ _this.logger.error('Error report failed: an unknown error occurred.', "message=".concat(err.message));
1217
+ (0, util_1$4.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
1218
+ return false;
1219
+ });
1220
+ };
1129
1221
  return Client;
1130
1222
  }());
1131
1223
  client.Client = Client;
@@ -1896,7 +1988,7 @@ stacked_store.StackedStore = StackedStore;
1896
1988
  var NOTIFIER = {
1897
1989
  name: '@honeybadger-io/js',
1898
1990
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
1899
- version: '6.2.0'
1991
+ version: '6.4.0'
1900
1992
  };
1901
1993
  singleton.setNotifier(NOTIFIER);
1902
1994
  var core_2 = src;