@pelcro/react-pelcro-js 3.18.1-beta.1 → 3.19.0-beta.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.
package/dist/index.cjs.js CHANGED
@@ -5,6 +5,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var React = require('react');
6
6
  var ReactDOM = require('react-dom');
7
7
  var PropTypes = require('prop-types');
8
+ var os = require('os');
9
+ var http = require('http');
10
+ var https = require('https');
11
+ var url = require('url');
12
+ var util$1 = require('util');
13
+ var domain = require('domain');
14
+ var path = require('path');
15
+ var fs = require('fs');
16
+ var stream = require('stream');
17
+ var timers = require('timers');
18
+ var events = require('events');
8
19
 
9
20
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
21
 
@@ -32,6 +43,17 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
32
43
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
33
44
  var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
34
45
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
46
+ var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
47
+ var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
48
+ var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
49
+ var url__default = /*#__PURE__*/_interopDefaultLegacy(url);
50
+ var util__default = /*#__PURE__*/_interopDefaultLegacy(util$1);
51
+ var domain__default = /*#__PURE__*/_interopDefaultLegacy(domain);
52
+ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
53
+ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
54
+ var stream__default = /*#__PURE__*/_interopDefaultLegacy(stream);
55
+ var timers__default = /*#__PURE__*/_interopDefaultLegacy(timers);
56
+ var events__default = /*#__PURE__*/_interopDefaultLegacy(events);
35
57
 
36
58
  function _typeof$3(obj) {
37
59
  "@babel/helpers - typeof";
@@ -1960,7 +1982,7 @@ function transformOptions(options) {
1960
1982
  return options;
1961
1983
  }
1962
1984
 
1963
- function noop$1() {}
1985
+ function noop$3() {}
1964
1986
 
1965
1987
  var I18n = function (_EventEmitter) {
1966
1988
  _inherits$1(I18n, _EventEmitter);
@@ -2024,7 +2046,7 @@ var I18n = function (_EventEmitter) {
2024
2046
 
2025
2047
  this.options = _objectSpread$7({}, get(), this.options, transformOptions(options));
2026
2048
  this.format = this.options.interpolation.format;
2027
- if (!callback) callback = noop$1;
2049
+ if (!callback) callback = noop$3;
2028
2050
 
2029
2051
  function createClassOnDemand(ClassOrObject) {
2030
2052
  if (!ClassOrObject) return null;
@@ -2145,7 +2167,7 @@ var I18n = function (_EventEmitter) {
2145
2167
  value: function loadResources(language) {
2146
2168
  var _this3 = this;
2147
2169
 
2148
- var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$1;
2170
+ var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$3;
2149
2171
  var usedCallback = callback;
2150
2172
  var usedLng = typeof language === 'string' ? language : this.language;
2151
2173
  if (typeof language === 'function') usedCallback = language;
@@ -2190,7 +2212,7 @@ var I18n = function (_EventEmitter) {
2190
2212
  var deferred = defer();
2191
2213
  if (!lngs) lngs = this.languages;
2192
2214
  if (!ns) ns = this.options.ns;
2193
- if (!callback) callback = noop$1;
2215
+ if (!callback) callback = noop$3;
2194
2216
  this.services.backendConnector.reload(lngs, ns, function (err) {
2195
2217
  deferred.resolve();
2196
2218
  callback(err);
@@ -2445,7 +2467,7 @@ var I18n = function (_EventEmitter) {
2445
2467
  var _this8 = this;
2446
2468
 
2447
2469
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2448
- var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$1;
2470
+ var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$3;
2449
2471
 
2450
2472
  var mergedOptions = _objectSpread$7({}, this.options, options, {
2451
2473
  isClone: true
@@ -8591,6 +8613,3502 @@ if (process.env.NODE_ENV === "development") {
8591
8613
  c$1("Pelcro Store", usePelcro);
8592
8614
  }
8593
8615
 
8616
+ var stackframe = createCommonjsModule(function (module, exports) {
8617
+ (function(root, factory) {
8618
+ // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers.
8619
+
8620
+ /* istanbul ignore next */
8621
+ {
8622
+ module.exports = factory();
8623
+ }
8624
+ }(commonjsGlobal, function() {
8625
+ function _isNumber(n) {
8626
+ return !isNaN(parseFloat(n)) && isFinite(n);
8627
+ }
8628
+
8629
+ function _capitalize(str) {
8630
+ return str.charAt(0).toUpperCase() + str.substring(1);
8631
+ }
8632
+
8633
+ function _getter(p) {
8634
+ return function() {
8635
+ return this[p];
8636
+ };
8637
+ }
8638
+
8639
+ var booleanProps = ['isConstructor', 'isEval', 'isNative', 'isToplevel'];
8640
+ var numericProps = ['columnNumber', 'lineNumber'];
8641
+ var stringProps = ['fileName', 'functionName', 'source'];
8642
+ var arrayProps = ['args'];
8643
+ var objectProps = ['evalOrigin'];
8644
+
8645
+ var props = booleanProps.concat(numericProps, stringProps, arrayProps, objectProps);
8646
+
8647
+ function StackFrame(obj) {
8648
+ if (!obj) return;
8649
+ for (var i = 0; i < props.length; i++) {
8650
+ if (obj[props[i]] !== undefined) {
8651
+ this['set' + _capitalize(props[i])](obj[props[i]]);
8652
+ }
8653
+ }
8654
+ }
8655
+
8656
+ StackFrame.prototype = {
8657
+ getArgs: function() {
8658
+ return this.args;
8659
+ },
8660
+ setArgs: function(v) {
8661
+ if (Object.prototype.toString.call(v) !== '[object Array]') {
8662
+ throw new TypeError('Args must be an Array');
8663
+ }
8664
+ this.args = v;
8665
+ },
8666
+
8667
+ getEvalOrigin: function() {
8668
+ return this.evalOrigin;
8669
+ },
8670
+ setEvalOrigin: function(v) {
8671
+ if (v instanceof StackFrame) {
8672
+ this.evalOrigin = v;
8673
+ } else if (v instanceof Object) {
8674
+ this.evalOrigin = new StackFrame(v);
8675
+ } else {
8676
+ throw new TypeError('Eval Origin must be an Object or StackFrame');
8677
+ }
8678
+ },
8679
+
8680
+ toString: function() {
8681
+ var fileName = this.getFileName() || '';
8682
+ var lineNumber = this.getLineNumber() || '';
8683
+ var columnNumber = this.getColumnNumber() || '';
8684
+ var functionName = this.getFunctionName() || '';
8685
+ if (this.getIsEval()) {
8686
+ if (fileName) {
8687
+ return '[eval] (' + fileName + ':' + lineNumber + ':' + columnNumber + ')';
8688
+ }
8689
+ return '[eval]:' + lineNumber + ':' + columnNumber;
8690
+ }
8691
+ if (functionName) {
8692
+ return functionName + ' (' + fileName + ':' + lineNumber + ':' + columnNumber + ')';
8693
+ }
8694
+ return fileName + ':' + lineNumber + ':' + columnNumber;
8695
+ }
8696
+ };
8697
+
8698
+ StackFrame.fromString = function StackFrame$$fromString(str) {
8699
+ var argsStartIndex = str.indexOf('(');
8700
+ var argsEndIndex = str.lastIndexOf(')');
8701
+
8702
+ var functionName = str.substring(0, argsStartIndex);
8703
+ var args = str.substring(argsStartIndex + 1, argsEndIndex).split(',');
8704
+ var locationString = str.substring(argsEndIndex + 1);
8705
+
8706
+ if (locationString.indexOf('@') === 0) {
8707
+ var parts = /@(.+?)(?::(\d+))?(?::(\d+))?$/.exec(locationString, '');
8708
+ var fileName = parts[1];
8709
+ var lineNumber = parts[2];
8710
+ var columnNumber = parts[3];
8711
+ }
8712
+
8713
+ return new StackFrame({
8714
+ functionName: functionName,
8715
+ args: args || undefined,
8716
+ fileName: fileName,
8717
+ lineNumber: lineNumber || undefined,
8718
+ columnNumber: columnNumber || undefined
8719
+ });
8720
+ };
8721
+
8722
+ for (var i = 0; i < booleanProps.length; i++) {
8723
+ StackFrame.prototype['get' + _capitalize(booleanProps[i])] = _getter(booleanProps[i]);
8724
+ StackFrame.prototype['set' + _capitalize(booleanProps[i])] = (function(p) {
8725
+ return function(v) {
8726
+ this[p] = Boolean(v);
8727
+ };
8728
+ })(booleanProps[i]);
8729
+ }
8730
+
8731
+ for (var j = 0; j < numericProps.length; j++) {
8732
+ StackFrame.prototype['get' + _capitalize(numericProps[j])] = _getter(numericProps[j]);
8733
+ StackFrame.prototype['set' + _capitalize(numericProps[j])] = (function(p) {
8734
+ return function(v) {
8735
+ if (!_isNumber(v)) {
8736
+ throw new TypeError(p + ' must be a Number');
8737
+ }
8738
+ this[p] = Number(v);
8739
+ };
8740
+ })(numericProps[j]);
8741
+ }
8742
+
8743
+ for (var k = 0; k < stringProps.length; k++) {
8744
+ StackFrame.prototype['get' + _capitalize(stringProps[k])] = _getter(stringProps[k]);
8745
+ StackFrame.prototype['set' + _capitalize(stringProps[k])] = (function(p) {
8746
+ return function(v) {
8747
+ this[p] = String(v);
8748
+ };
8749
+ })(stringProps[k]);
8750
+ }
8751
+
8752
+ return StackFrame;
8753
+ }));
8754
+ });
8755
+
8756
+ var errorStackParser = createCommonjsModule(function (module, exports) {
8757
+ (function(root, factory) {
8758
+ // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers.
8759
+
8760
+ /* istanbul ignore next */
8761
+ {
8762
+ module.exports = factory(stackframe);
8763
+ }
8764
+ }(commonjsGlobal, function ErrorStackParser(StackFrame) {
8765
+
8766
+ var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+:\d+/;
8767
+ var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m;
8768
+ var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code])?$/;
8769
+
8770
+ return {
8771
+ /**
8772
+ * Given an Error object, extract the most information from it.
8773
+ *
8774
+ * @param {Error} error object
8775
+ * @return {Array} of StackFrames
8776
+ */
8777
+ parse: function ErrorStackParser$$parse(error) {
8778
+ if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') {
8779
+ return this.parseOpera(error);
8780
+ } else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) {
8781
+ return this.parseV8OrIE(error);
8782
+ } else if (error.stack) {
8783
+ return this.parseFFOrSafari(error);
8784
+ } else {
8785
+ throw new Error('Cannot parse given Error object');
8786
+ }
8787
+ },
8788
+
8789
+ // Separate line and column numbers from a string of the form: (URI:Line:Column)
8790
+ extractLocation: function ErrorStackParser$$extractLocation(urlLike) {
8791
+ // Fail-fast but return locations like "(native)"
8792
+ if (urlLike.indexOf(':') === -1) {
8793
+ return [urlLike];
8794
+ }
8795
+
8796
+ var regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
8797
+ var parts = regExp.exec(urlLike.replace(/[()]/g, ''));
8798
+ return [parts[1], parts[2] || undefined, parts[3] || undefined];
8799
+ },
8800
+
8801
+ parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) {
8802
+ var filtered = error.stack.split('\n').filter(function(line) {
8803
+ return !!line.match(CHROME_IE_STACK_REGEXP);
8804
+ }, this);
8805
+
8806
+ return filtered.map(function(line) {
8807
+ if (line.indexOf('(eval ') > -1) {
8808
+ // Throw away eval information until we implement stacktrace.js/stackframe#8
8809
+ line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^()]*)|(,.*$)/g, '');
8810
+ }
8811
+ var sanitizedLine = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').replace(/^.*?\s+/, '');
8812
+
8813
+ // capture and preseve the parenthesized location "(/foo/my bar.js:12:87)" in
8814
+ // case it has spaces in it, as the string is split on \s+ later on
8815
+ var location = sanitizedLine.match(/ (\(.+\)$)/);
8816
+
8817
+ // remove the parenthesized location from the line, if it was matched
8818
+ sanitizedLine = location ? sanitizedLine.replace(location[0], '') : sanitizedLine;
8819
+
8820
+ // if a location was matched, pass it to extractLocation() otherwise pass all sanitizedLine
8821
+ // because this line doesn't have function name
8822
+ var locationParts = this.extractLocation(location ? location[1] : sanitizedLine);
8823
+ var functionName = location && sanitizedLine || undefined;
8824
+ var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0];
8825
+
8826
+ return new StackFrame({
8827
+ functionName: functionName,
8828
+ fileName: fileName,
8829
+ lineNumber: locationParts[1],
8830
+ columnNumber: locationParts[2],
8831
+ source: line
8832
+ });
8833
+ }, this);
8834
+ },
8835
+
8836
+ parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) {
8837
+ var filtered = error.stack.split('\n').filter(function(line) {
8838
+ return !line.match(SAFARI_NATIVE_CODE_REGEXP);
8839
+ }, this);
8840
+
8841
+ return filtered.map(function(line) {
8842
+ // Throw away eval information until we implement stacktrace.js/stackframe#8
8843
+ if (line.indexOf(' > eval') > -1) {
8844
+ line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ':$1');
8845
+ }
8846
+
8847
+ if (line.indexOf('@') === -1 && line.indexOf(':') === -1) {
8848
+ // Safari eval frames only have function names and nothing else
8849
+ return new StackFrame({
8850
+ functionName: line
8851
+ });
8852
+ } else {
8853
+ var functionNameRegex = /((.*".+"[^@]*)?[^@]*)(?:@)/;
8854
+ var matches = line.match(functionNameRegex);
8855
+ var functionName = matches && matches[1] ? matches[1] : undefined;
8856
+ var locationParts = this.extractLocation(line.replace(functionNameRegex, ''));
8857
+
8858
+ return new StackFrame({
8859
+ functionName: functionName,
8860
+ fileName: locationParts[0],
8861
+ lineNumber: locationParts[1],
8862
+ columnNumber: locationParts[2],
8863
+ source: line
8864
+ });
8865
+ }
8866
+ }, this);
8867
+ },
8868
+
8869
+ parseOpera: function ErrorStackParser$$parseOpera(e) {
8870
+ if (!e.stacktrace || (e.message.indexOf('\n') > -1 &&
8871
+ e.message.split('\n').length > e.stacktrace.split('\n').length)) {
8872
+ return this.parseOpera9(e);
8873
+ } else if (!e.stack) {
8874
+ return this.parseOpera10(e);
8875
+ } else {
8876
+ return this.parseOpera11(e);
8877
+ }
8878
+ },
8879
+
8880
+ parseOpera9: function ErrorStackParser$$parseOpera9(e) {
8881
+ var lineRE = /Line (\d+).*script (?:in )?(\S+)/i;
8882
+ var lines = e.message.split('\n');
8883
+ var result = [];
8884
+
8885
+ for (var i = 2, len = lines.length; i < len; i += 2) {
8886
+ var match = lineRE.exec(lines[i]);
8887
+ if (match) {
8888
+ result.push(new StackFrame({
8889
+ fileName: match[2],
8890
+ lineNumber: match[1],
8891
+ source: lines[i]
8892
+ }));
8893
+ }
8894
+ }
8895
+
8896
+ return result;
8897
+ },
8898
+
8899
+ parseOpera10: function ErrorStackParser$$parseOpera10(e) {
8900
+ var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i;
8901
+ var lines = e.stacktrace.split('\n');
8902
+ var result = [];
8903
+
8904
+ for (var i = 0, len = lines.length; i < len; i += 2) {
8905
+ var match = lineRE.exec(lines[i]);
8906
+ if (match) {
8907
+ result.push(
8908
+ new StackFrame({
8909
+ functionName: match[3] || undefined,
8910
+ fileName: match[2],
8911
+ lineNumber: match[1],
8912
+ source: lines[i]
8913
+ })
8914
+ );
8915
+ }
8916
+ }
8917
+
8918
+ return result;
8919
+ },
8920
+
8921
+ // Opera 10.65+ Error.stack very similar to FF/Safari
8922
+ parseOpera11: function ErrorStackParser$$parseOpera11(error) {
8923
+ var filtered = error.stack.split('\n').filter(function(line) {
8924
+ return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/);
8925
+ }, this);
8926
+
8927
+ return filtered.map(function(line) {
8928
+ var tokens = line.split('@');
8929
+ var locationParts = this.extractLocation(tokens.pop());
8930
+ var functionCall = (tokens.shift() || '');
8931
+ var functionName = functionCall
8932
+ .replace(/<anonymous function(: (\w+))?>/, '$2')
8933
+ .replace(/\([^)]*\)/g, '') || undefined;
8934
+ var argsRaw;
8935
+ if (functionCall.match(/\(([^)]*)\)/)) {
8936
+ argsRaw = functionCall.replace(/^[^(]+\(([^)]*)\)$/, '$1');
8937
+ }
8938
+ var args = (argsRaw === undefined || argsRaw === '[arguments not available]') ?
8939
+ undefined : argsRaw.split(',');
8940
+
8941
+ return new StackFrame({
8942
+ functionName: functionName,
8943
+ args: args,
8944
+ fileName: locationParts[0],
8945
+ lineNumber: locationParts[1],
8946
+ columnNumber: locationParts[2],
8947
+ source: line
8948
+ });
8949
+ }, this);
8950
+ }
8951
+ };
8952
+ }));
8953
+ });
8954
+
8955
+ /**
8956
+ * Expose `isError`.
8957
+ */
8958
+
8959
+ var iserror = isError;
8960
+
8961
+ /**
8962
+ * Test whether `value` is error object.
8963
+ *
8964
+ * @param {*} value
8965
+ * @returns {boolean}
8966
+ */
8967
+
8968
+ function isError(value) {
8969
+ switch (Object.prototype.toString.call(value)) {
8970
+ case '[object Error]': return true;
8971
+ case '[object Exception]': return true;
8972
+ case '[object DOMException]': return true;
8973
+ default: return value instanceof Error;
8974
+ }
8975
+ }
8976
+
8977
+ var stackGenerator = createCommonjsModule(function (module, exports) {
8978
+ (function(root, factory) {
8979
+ // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers.
8980
+
8981
+ /* istanbul ignore next */
8982
+ {
8983
+ module.exports = factory(stackframe);
8984
+ }
8985
+ }(commonjsGlobal, function(StackFrame) {
8986
+ return {
8987
+ backtrace: function StackGenerator$$backtrace(opts) {
8988
+ var stack = [];
8989
+ var maxStackSize = 10;
8990
+
8991
+ if (typeof opts === 'object' && typeof opts.maxStackSize === 'number') {
8992
+ maxStackSize = opts.maxStackSize;
8993
+ }
8994
+
8995
+ var curr = arguments.callee;
8996
+ while (curr && stack.length < maxStackSize && curr['arguments']) {
8997
+ // Allow V8 optimizations
8998
+ var args = new Array(curr['arguments'].length);
8999
+ for (var i = 0; i < args.length; ++i) {
9000
+ args[i] = curr['arguments'][i];
9001
+ }
9002
+ if (/function(?:\s+([\w$]+))+\s*\(/.test(curr.toString())) {
9003
+ stack.push(new StackFrame({functionName: RegExp.$1 || undefined, args: args}));
9004
+ } else {
9005
+ stack.push(new StackFrame({args: args}));
9006
+ }
9007
+
9008
+ try {
9009
+ curr = curr.caller;
9010
+ } catch (e) {
9011
+ break;
9012
+ }
9013
+ }
9014
+ return stack;
9015
+ }
9016
+ };
9017
+ }));
9018
+ });
9019
+
9020
+ // Returns a wrapper function that returns a wrapped callback
9021
+ // The wrapper function should do some stuff, and return a
9022
+ // presumably different callback function.
9023
+ // This makes sure that own properties are retained, so that
9024
+ // decorations and such are not lost along the way.
9025
+ var wrappy_1 = wrappy;
9026
+ function wrappy (fn, cb) {
9027
+ if (fn && cb) return wrappy(fn)(cb)
9028
+
9029
+ if (typeof fn !== 'function')
9030
+ throw new TypeError('need wrapper function')
9031
+
9032
+ Object.keys(fn).forEach(function (k) {
9033
+ wrapper[k] = fn[k];
9034
+ });
9035
+
9036
+ return wrapper
9037
+
9038
+ function wrapper() {
9039
+ var args = new Array(arguments.length);
9040
+ for (var i = 0; i < args.length; i++) {
9041
+ args[i] = arguments[i];
9042
+ }
9043
+ var ret = fn.apply(this, args);
9044
+ var cb = args[args.length-1];
9045
+ if (typeof ret === 'function' && ret !== cb) {
9046
+ Object.keys(cb).forEach(function (k) {
9047
+ ret[k] = cb[k];
9048
+ });
9049
+ }
9050
+ return ret
9051
+ }
9052
+ }
9053
+
9054
+ var once_1 = wrappy_1(once$1);
9055
+ var strict = wrappy_1(onceStrict);
9056
+
9057
+ once$1.proto = once$1(function () {
9058
+ Object.defineProperty(Function.prototype, 'once', {
9059
+ value: function () {
9060
+ return once$1(this)
9061
+ },
9062
+ configurable: true
9063
+ });
9064
+
9065
+ Object.defineProperty(Function.prototype, 'onceStrict', {
9066
+ value: function () {
9067
+ return onceStrict(this)
9068
+ },
9069
+ configurable: true
9070
+ });
9071
+ });
9072
+
9073
+ function once$1 (fn) {
9074
+ var f = function () {
9075
+ if (f.called) return f.value
9076
+ f.called = true;
9077
+ return f.value = fn.apply(this, arguments)
9078
+ };
9079
+ f.called = false;
9080
+ return f
9081
+ }
9082
+
9083
+ function onceStrict (fn) {
9084
+ var f = function () {
9085
+ if (f.called)
9086
+ throw new Error(f.onceError)
9087
+ f.called = true;
9088
+ return f.value = fn.apply(this, arguments)
9089
+ };
9090
+ var name = fn.name || 'Function wrapped with `once`';
9091
+ f.onceError = name + " shouldn't be called more than once";
9092
+ f.called = false;
9093
+ return f
9094
+ }
9095
+ once_1.strict = strict;
9096
+
9097
+ var noop$2 = function() {};
9098
+
9099
+ var isRequest$1 = function(stream) {
9100
+ return stream.setHeader && typeof stream.abort === 'function';
9101
+ };
9102
+
9103
+ var isChildProcess = function(stream) {
9104
+ return stream.stdio && Array.isArray(stream.stdio) && stream.stdio.length === 3
9105
+ };
9106
+
9107
+ var eos = function(stream, opts, callback) {
9108
+ if (typeof opts === 'function') return eos(stream, null, opts);
9109
+ if (!opts) opts = {};
9110
+
9111
+ callback = once_1(callback || noop$2);
9112
+
9113
+ var ws = stream._writableState;
9114
+ var rs = stream._readableState;
9115
+ var readable = opts.readable || (opts.readable !== false && stream.readable);
9116
+ var writable = opts.writable || (opts.writable !== false && stream.writable);
9117
+ var cancelled = false;
9118
+
9119
+ var onlegacyfinish = function() {
9120
+ if (!stream.writable) onfinish();
9121
+ };
9122
+
9123
+ var onfinish = function() {
9124
+ writable = false;
9125
+ if (!readable) callback.call(stream);
9126
+ };
9127
+
9128
+ var onend = function() {
9129
+ readable = false;
9130
+ if (!writable) callback.call(stream);
9131
+ };
9132
+
9133
+ var onexit = function(exitCode) {
9134
+ callback.call(stream, exitCode ? new Error('exited with error code: ' + exitCode) : null);
9135
+ };
9136
+
9137
+ var onerror = function(err) {
9138
+ callback.call(stream, err);
9139
+ };
9140
+
9141
+ var onclose = function() {
9142
+ process.nextTick(onclosenexttick);
9143
+ };
9144
+
9145
+ var onclosenexttick = function() {
9146
+ if (cancelled) return;
9147
+ if (readable && !(rs && (rs.ended && !rs.destroyed))) return callback.call(stream, new Error('premature close'));
9148
+ if (writable && !(ws && (ws.ended && !ws.destroyed))) return callback.call(stream, new Error('premature close'));
9149
+ };
9150
+
9151
+ var onrequest = function() {
9152
+ stream.req.on('finish', onfinish);
9153
+ };
9154
+
9155
+ if (isRequest$1(stream)) {
9156
+ stream.on('complete', onfinish);
9157
+ stream.on('abort', onclose);
9158
+ if (stream.req) onrequest();
9159
+ else stream.on('request', onrequest);
9160
+ } else if (writable && !ws) { // legacy streams
9161
+ stream.on('end', onlegacyfinish);
9162
+ stream.on('close', onlegacyfinish);
9163
+ }
9164
+
9165
+ if (isChildProcess(stream)) stream.on('exit', onexit);
9166
+
9167
+ stream.on('end', onend);
9168
+ stream.on('finish', onfinish);
9169
+ if (opts.error !== false) stream.on('error', onerror);
9170
+ stream.on('close', onclose);
9171
+
9172
+ return function() {
9173
+ cancelled = true;
9174
+ stream.removeListener('complete', onfinish);
9175
+ stream.removeListener('abort', onclose);
9176
+ stream.removeListener('request', onrequest);
9177
+ if (stream.req) stream.req.removeListener('finish', onfinish);
9178
+ stream.removeListener('end', onlegacyfinish);
9179
+ stream.removeListener('close', onlegacyfinish);
9180
+ stream.removeListener('finish', onfinish);
9181
+ stream.removeListener('exit', onexit);
9182
+ stream.removeListener('end', onend);
9183
+ stream.removeListener('error', onerror);
9184
+ stream.removeListener('close', onclose);
9185
+ };
9186
+ };
9187
+
9188
+ var endOfStream = eos;
9189
+
9190
+ // we only need fs to get the ReadStream and WriteStream prototypes
9191
+
9192
+ var noop$1 = function () {};
9193
+ var ancient = /^v?\.0/.test(process.version);
9194
+
9195
+ var isFn = function (fn) {
9196
+ return typeof fn === 'function'
9197
+ };
9198
+
9199
+ var isFS = function (stream) {
9200
+ if (!ancient) return false // newer node version do not need to care about fs is a special way
9201
+ if (!fs__default['default']) return false // browser
9202
+ return (stream instanceof (fs__default['default'].ReadStream || noop$1) || stream instanceof (fs__default['default'].WriteStream || noop$1)) && isFn(stream.close)
9203
+ };
9204
+
9205
+ var isRequest = function (stream) {
9206
+ return stream.setHeader && isFn(stream.abort)
9207
+ };
9208
+
9209
+ var destroyer = function (stream, reading, writing, callback) {
9210
+ callback = once_1(callback);
9211
+
9212
+ var closed = false;
9213
+ stream.on('close', function () {
9214
+ closed = true;
9215
+ });
9216
+
9217
+ endOfStream(stream, {readable: reading, writable: writing}, function (err) {
9218
+ if (err) return callback(err)
9219
+ closed = true;
9220
+ callback();
9221
+ });
9222
+
9223
+ var destroyed = false;
9224
+ return function (err) {
9225
+ if (closed) return
9226
+ if (destroyed) return
9227
+ destroyed = true;
9228
+
9229
+ if (isFS(stream)) return stream.close(noop$1) // use close for fs streams to avoid fd leaks
9230
+ if (isRequest(stream)) return stream.abort() // request.destroy just do .end - .abort is what we want
9231
+
9232
+ if (isFn(stream.destroy)) return stream.destroy()
9233
+
9234
+ callback(err || new Error('stream was destroyed'));
9235
+ }
9236
+ };
9237
+
9238
+ var call = function (fn) {
9239
+ fn();
9240
+ };
9241
+
9242
+ var pipe = function (from, to) {
9243
+ return from.pipe(to)
9244
+ };
9245
+
9246
+ var pump = function () {
9247
+ var streams = Array.prototype.slice.call(arguments);
9248
+ var callback = isFn(streams[streams.length - 1] || noop$1) && streams.pop() || noop$1;
9249
+
9250
+ if (Array.isArray(streams[0])) streams = streams[0];
9251
+ if (streams.length < 2) throw new Error('pump requires two streams per minimum')
9252
+
9253
+ var error;
9254
+ var destroys = streams.map(function (stream, i) {
9255
+ var reading = i < streams.length - 1;
9256
+ var writing = i > 0;
9257
+ return destroyer(stream, reading, writing, function (err) {
9258
+ if (!error) error = err;
9259
+ if (err) destroys.forEach(call);
9260
+ if (reading) return
9261
+ destroys.forEach(call);
9262
+ callback(error);
9263
+ })
9264
+ });
9265
+
9266
+ return streams.reduce(pipe)
9267
+ };
9268
+
9269
+ var pump_1 = pump;
9270
+
9271
+ var byline = createCommonjsModule(function (module) {
9272
+ // Copyright (C) 2011-2015 John Hewson
9273
+ //
9274
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
9275
+ // of this software and associated documentation files (the "Software"), to
9276
+ // deal in the Software without restriction, including without limitation the
9277
+ // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9278
+ // sell copies of the Software, and to permit persons to whom the Software is
9279
+ // furnished to do so, subject to the following conditions:
9280
+ //
9281
+ // The above copyright notice and this permission notice shall be included in
9282
+ // all copies or substantial portions of the Software.
9283
+ //
9284
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9285
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9286
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9287
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9288
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
9289
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
9290
+ // IN THE SOFTWARE.
9291
+
9292
+
9293
+
9294
+ // convinience API
9295
+ module.exports = function(readStream, options) {
9296
+ return module.exports.createStream(readStream, options);
9297
+ };
9298
+
9299
+ // basic API
9300
+ module.exports.createStream = function(readStream, options) {
9301
+ if (readStream) {
9302
+ return createLineStream(readStream, options);
9303
+ } else {
9304
+ return new LineStream(options);
9305
+ }
9306
+ };
9307
+
9308
+ // deprecated API
9309
+ module.exports.createLineStream = function(readStream) {
9310
+ console.log('WARNING: byline#createLineStream is deprecated and will be removed soon');
9311
+ return createLineStream(readStream);
9312
+ };
9313
+
9314
+ function createLineStream(readStream, options) {
9315
+ if (!readStream) {
9316
+ throw new Error('expected readStream');
9317
+ }
9318
+ if (!readStream.readable) {
9319
+ throw new Error('readStream must be readable');
9320
+ }
9321
+ var ls = new LineStream(options);
9322
+ readStream.pipe(ls);
9323
+ return ls;
9324
+ }
9325
+
9326
+ //
9327
+ // using the new node v0.10 "streams2" API
9328
+ //
9329
+
9330
+ module.exports.LineStream = LineStream;
9331
+
9332
+ function LineStream(options) {
9333
+ stream__default['default'].Transform.call(this, options);
9334
+ options = options || {};
9335
+
9336
+ // use objectMode to stop the output from being buffered
9337
+ // which re-concatanates the lines, just without newlines.
9338
+ this._readableState.objectMode = true;
9339
+ this._lineBuffer = [];
9340
+ this._keepEmptyLines = options.keepEmptyLines || false;
9341
+ this._lastChunkEndedWithCR = false;
9342
+
9343
+ // take the source's encoding if we don't have one
9344
+ var self = this;
9345
+ this.on('pipe', function(src) {
9346
+ if (!self.encoding) {
9347
+ // but we can't do this for old-style streams
9348
+ if (src instanceof stream__default['default'].Readable) {
9349
+ self.encoding = src._readableState.encoding;
9350
+ }
9351
+ }
9352
+ });
9353
+ }
9354
+ util__default['default'].inherits(LineStream, stream__default['default'].Transform);
9355
+
9356
+ LineStream.prototype._transform = function(chunk, encoding, done) {
9357
+ // decode binary chunks as UTF-8
9358
+ encoding = encoding || 'utf8';
9359
+
9360
+ if (Buffer.isBuffer(chunk)) {
9361
+ if (encoding == 'buffer') {
9362
+ chunk = chunk.toString(); // utf8
9363
+ encoding = 'utf8';
9364
+ }
9365
+ else {
9366
+ chunk = chunk.toString(encoding);
9367
+ }
9368
+ }
9369
+ this._chunkEncoding = encoding;
9370
+
9371
+ // see: http://www.unicode.org/reports/tr18/#Line_Boundaries
9372
+ var lines = chunk.split(/\r\n|[\n\v\f\r\x85\u2028\u2029]/g);
9373
+
9374
+ // don't split CRLF which spans chunks
9375
+ if (this._lastChunkEndedWithCR && chunk[0] == '\n') {
9376
+ lines.shift();
9377
+ }
9378
+
9379
+ if (this._lineBuffer.length > 0) {
9380
+ this._lineBuffer[this._lineBuffer.length - 1] += lines[0];
9381
+ lines.shift();
9382
+ }
9383
+
9384
+ this._lastChunkEndedWithCR = chunk[chunk.length - 1] == '\r';
9385
+ this._lineBuffer = this._lineBuffer.concat(lines);
9386
+ this._pushBuffer(encoding, 1, done);
9387
+ };
9388
+
9389
+ LineStream.prototype._pushBuffer = function(encoding, keep, done) {
9390
+ // always buffer the last (possibly partial) line
9391
+ while (this._lineBuffer.length > keep) {
9392
+ var line = this._lineBuffer.shift();
9393
+ // skip empty lines
9394
+ if (this._keepEmptyLines || line.length > 0 ) {
9395
+ if (!this.push(this._reencode(line, encoding))) {
9396
+ // when the high-water mark is reached, defer pushes until the next tick
9397
+ var self = this;
9398
+ timers__default['default'].setImmediate(function() {
9399
+ self._pushBuffer(encoding, keep, done);
9400
+ });
9401
+ return;
9402
+ }
9403
+ }
9404
+ }
9405
+ done();
9406
+ };
9407
+
9408
+ LineStream.prototype._flush = function(done) {
9409
+ this._pushBuffer(this._chunkEncoding, 0, done);
9410
+ };
9411
+
9412
+ // see Readable::push
9413
+ LineStream.prototype._reencode = function(line, chunkEncoding) {
9414
+ if (this.encoding && this.encoding != chunkEncoding) {
9415
+ return new Buffer(line, chunkEncoding).toString(this.encoding);
9416
+ }
9417
+ else if (this.encoding) {
9418
+ // this should be the most common case, i.e. we're using an encoded source stream
9419
+ return line;
9420
+ }
9421
+ else {
9422
+ return new Buffer(line, chunkEncoding);
9423
+ }
9424
+ };
9425
+ });
9426
+ byline.createStream;
9427
+ byline.createLineStream;
9428
+ byline.LineStream;
9429
+
9430
+ var bugsnag = createCommonjsModule(function (module, exports) {
9431
+ (function(f){{module.exports=f();}})(function(){var Breadcrumb = /*#__PURE__*/function () {
9432
+ function Breadcrumb(message, metadata, type, timestamp) {
9433
+ if (timestamp === void 0) {
9434
+ timestamp = new Date();
9435
+ }
9436
+
9437
+ this.type = type;
9438
+ this.message = message;
9439
+ this.metadata = metadata;
9440
+ this.timestamp = timestamp;
9441
+ }
9442
+
9443
+ var _proto = Breadcrumb.prototype;
9444
+
9445
+ _proto.toJSON = function toJSON() {
9446
+ return {
9447
+ type: this.type,
9448
+ name: this.message,
9449
+ timestamp: this.timestamp,
9450
+ metaData: this.metadata
9451
+ };
9452
+ };
9453
+
9454
+ return Breadcrumb;
9455
+ }();
9456
+
9457
+ var _$Breadcrumb_1 = Breadcrumb;
9458
+
9459
+ var _$breadcrumbTypes_6 = ['navigation', 'request', 'process', 'log', 'user', 'state', 'error', 'manual'];
9460
+
9461
+ // Array#reduce
9462
+ var _$reduce_16 = function (arr, fn, accum) {
9463
+ var val = accum;
9464
+
9465
+ for (var i = 0, len = arr.length; i < len; i++) {
9466
+ val = fn(val, arr[i], i, arr);
9467
+ }
9468
+
9469
+ return val;
9470
+ };
9471
+
9472
+
9473
+ var _$filter_11 = function (arr, fn) {
9474
+ return _$reduce_16(arr, function (accum, item, i, arr) {
9475
+ return !fn(item, i, arr) ? accum : accum.concat(item);
9476
+ }, []);
9477
+ };
9478
+
9479
+
9480
+ var _$includes_12 = function (arr, x) {
9481
+ return _$reduce_16(arr, function (accum, item, i, arr) {
9482
+ return accum === true || item === x;
9483
+ }, false);
9484
+ };
9485
+
9486
+ // Array#isArray
9487
+ var _$isArray_13 = function (obj) {
9488
+ return Object.prototype.toString.call(obj) === '[object Array]';
9489
+ };
9490
+
9491
+ /* eslint-disable-next-line no-prototype-builtins */
9492
+ var _hasDontEnumBug = !{
9493
+ toString: null
9494
+ }.propertyIsEnumerable('toString');
9495
+
9496
+ var _dontEnums = ['toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'constructor']; // Object#keys
9497
+
9498
+ var _$keys_14 = function (obj) {
9499
+ // stripped down version of
9500
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/Keys
9501
+ var result = [];
9502
+ var prop;
9503
+
9504
+ for (prop in obj) {
9505
+ if (Object.prototype.hasOwnProperty.call(obj, prop)) result.push(prop);
9506
+ }
9507
+
9508
+ if (!_hasDontEnumBug) return result;
9509
+
9510
+ for (var i = 0, len = _dontEnums.length; i < len; i++) {
9511
+ if (Object.prototype.hasOwnProperty.call(obj, _dontEnums[i])) result.push(_dontEnums[i]);
9512
+ }
9513
+
9514
+ return result;
9515
+ };
9516
+
9517
+ var _$intRange_25 = function (min, max) {
9518
+ if (min === void 0) {
9519
+ min = 1;
9520
+ }
9521
+
9522
+ if (max === void 0) {
9523
+ max = Infinity;
9524
+ }
9525
+
9526
+ return function (value) {
9527
+ return typeof value === 'number' && parseInt('' + value, 10) === value && value >= min && value <= max;
9528
+ };
9529
+ };
9530
+
9531
+ var _$listOfFunctions_26 = function (value) {
9532
+ return typeof value === 'function' || _$isArray_13(value) && _$filter_11(value, function (f) {
9533
+ return typeof f === 'function';
9534
+ }).length === value.length;
9535
+ };
9536
+
9537
+ var _$stringWithLength_27 = function (value) {
9538
+ return typeof value === 'string' && !!value.length;
9539
+ };
9540
+
9541
+ var _$config_3 = {};
9542
+
9543
+ var defaultErrorTypes = function () {
9544
+ return {
9545
+ unhandledExceptions: true,
9546
+ unhandledRejections: true
9547
+ };
9548
+ };
9549
+
9550
+ _$config_3.schema = {
9551
+ apiKey: {
9552
+ defaultValue: function () {
9553
+ return null;
9554
+ },
9555
+ message: 'is required',
9556
+ validate: _$stringWithLength_27
9557
+ },
9558
+ appVersion: {
9559
+ defaultValue: function () {
9560
+ return undefined;
9561
+ },
9562
+ message: 'should be a string',
9563
+ validate: function (value) {
9564
+ return value === undefined || _$stringWithLength_27(value);
9565
+ }
9566
+ },
9567
+ appType: {
9568
+ defaultValue: function () {
9569
+ return undefined;
9570
+ },
9571
+ message: 'should be a string',
9572
+ validate: function (value) {
9573
+ return value === undefined || _$stringWithLength_27(value);
9574
+ }
9575
+ },
9576
+ autoDetectErrors: {
9577
+ defaultValue: function () {
9578
+ return true;
9579
+ },
9580
+ message: 'should be true|false',
9581
+ validate: function (value) {
9582
+ return value === true || value === false;
9583
+ }
9584
+ },
9585
+ enabledErrorTypes: {
9586
+ defaultValue: function () {
9587
+ return defaultErrorTypes();
9588
+ },
9589
+ message: 'should be an object containing the flags { unhandledExceptions:true|false, unhandledRejections:true|false }',
9590
+ allowPartialObject: true,
9591
+ validate: function (value) {
9592
+ // ensure we have an object
9593
+ if (typeof value !== 'object' || !value) return false;
9594
+ var providedKeys = _$keys_14(value);
9595
+ var defaultKeys = _$keys_14(defaultErrorTypes()); // ensure it only has a subset of the allowed keys
9596
+
9597
+ if (_$filter_11(providedKeys, function (k) {
9598
+ return _$includes_12(defaultKeys, k);
9599
+ }).length < providedKeys.length) return false; // ensure all of the values are boolean
9600
+
9601
+ if (_$filter_11(_$keys_14(value), function (k) {
9602
+ return typeof value[k] !== 'boolean';
9603
+ }).length > 0) return false;
9604
+ return true;
9605
+ }
9606
+ },
9607
+ onError: {
9608
+ defaultValue: function () {
9609
+ return [];
9610
+ },
9611
+ message: 'should be a function or array of functions',
9612
+ validate: _$listOfFunctions_26
9613
+ },
9614
+ onSession: {
9615
+ defaultValue: function () {
9616
+ return [];
9617
+ },
9618
+ message: 'should be a function or array of functions',
9619
+ validate: _$listOfFunctions_26
9620
+ },
9621
+ onBreadcrumb: {
9622
+ defaultValue: function () {
9623
+ return [];
9624
+ },
9625
+ message: 'should be a function or array of functions',
9626
+ validate: _$listOfFunctions_26
9627
+ },
9628
+ endpoints: {
9629
+ defaultValue: function () {
9630
+ return {
9631
+ notify: 'https://notify.bugsnag.com',
9632
+ sessions: 'https://sessions.bugsnag.com'
9633
+ };
9634
+ },
9635
+ message: 'should be an object containing endpoint URLs { notify, sessions }',
9636
+ validate: function (val) {
9637
+ return (// first, ensure it's an object
9638
+ val && typeof val === 'object' && // notify and sessions must always be set
9639
+ _$stringWithLength_27(val.notify) && _$stringWithLength_27(val.sessions) && // ensure no keys other than notify/session are set on endpoints object
9640
+ _$filter_11(_$keys_14(val), function (k) {
9641
+ return !_$includes_12(['notify', 'sessions'], k);
9642
+ }).length === 0
9643
+ );
9644
+ }
9645
+ },
9646
+ autoTrackSessions: {
9647
+ defaultValue: function (val) {
9648
+ return true;
9649
+ },
9650
+ message: 'should be true|false',
9651
+ validate: function (val) {
9652
+ return val === true || val === false;
9653
+ }
9654
+ },
9655
+ enabledReleaseStages: {
9656
+ defaultValue: function () {
9657
+ return null;
9658
+ },
9659
+ message: 'should be an array of strings',
9660
+ validate: function (value) {
9661
+ return value === null || _$isArray_13(value) && _$filter_11(value, function (f) {
9662
+ return typeof f === 'string';
9663
+ }).length === value.length;
9664
+ }
9665
+ },
9666
+ releaseStage: {
9667
+ defaultValue: function () {
9668
+ return 'production';
9669
+ },
9670
+ message: 'should be a string',
9671
+ validate: function (value) {
9672
+ return typeof value === 'string' && value.length;
9673
+ }
9674
+ },
9675
+ maxBreadcrumbs: {
9676
+ defaultValue: function () {
9677
+ return 25;
9678
+ },
9679
+ message: 'should be a number ≤100',
9680
+ validate: function (value) {
9681
+ return _$intRange_25(0, 100)(value);
9682
+ }
9683
+ },
9684
+ enabledBreadcrumbTypes: {
9685
+ defaultValue: function () {
9686
+ return _$breadcrumbTypes_6;
9687
+ },
9688
+ message: "should be null or a list of available breadcrumb types (" + _$breadcrumbTypes_6.join(',') + ")",
9689
+ validate: function (value) {
9690
+ return value === null || _$isArray_13(value) && _$reduce_16(value, function (accum, maybeType) {
9691
+ if (accum === false) return accum;
9692
+ return _$includes_12(_$breadcrumbTypes_6, maybeType);
9693
+ }, true);
9694
+ }
9695
+ },
9696
+ context: {
9697
+ defaultValue: function () {
9698
+ return undefined;
9699
+ },
9700
+ message: 'should be a string',
9701
+ validate: function (value) {
9702
+ return value === undefined || typeof value === 'string';
9703
+ }
9704
+ },
9705
+ user: {
9706
+ defaultValue: function () {
9707
+ return {};
9708
+ },
9709
+ message: 'should be an object with { id, email, name } properties',
9710
+ validate: function (value) {
9711
+ return value === null || value && _$reduce_16(_$keys_14(value), function (accum, key) {
9712
+ return accum && _$includes_12(['id', 'email', 'name'], key);
9713
+ }, true);
9714
+ }
9715
+ },
9716
+ metadata: {
9717
+ defaultValue: function () {
9718
+ return {};
9719
+ },
9720
+ message: 'should be an object',
9721
+ validate: function (value) {
9722
+ return typeof value === 'object' && value !== null;
9723
+ }
9724
+ },
9725
+ logger: {
9726
+ defaultValue: function () {
9727
+ return undefined;
9728
+ },
9729
+ message: 'should be null or an object with methods { debug, info, warn, error }',
9730
+ validate: function (value) {
9731
+ return !value || value && _$reduce_16(['debug', 'info', 'warn', 'error'], function (accum, method) {
9732
+ return accum && typeof value[method] === 'function';
9733
+ }, true);
9734
+ }
9735
+ },
9736
+ redactedKeys: {
9737
+ defaultValue: function () {
9738
+ return ['password'];
9739
+ },
9740
+ message: 'should be an array of strings|regexes',
9741
+ validate: function (value) {
9742
+ return _$isArray_13(value) && value.length === _$filter_11(value, function (s) {
9743
+ return typeof s === 'string' || s && typeof s.test === 'function';
9744
+ }).length;
9745
+ }
9746
+ },
9747
+ plugins: {
9748
+ defaultValue: function () {
9749
+ return [];
9750
+ },
9751
+ message: 'should be an array of plugin objects',
9752
+ validate: function (value) {
9753
+ return _$isArray_13(value) && value.length === _$filter_11(value, function (p) {
9754
+ return p && typeof p === 'object' && typeof p.load === 'function';
9755
+ }).length;
9756
+ }
9757
+ },
9758
+ featureFlags: {
9759
+ defaultValue: function () {
9760
+ return [];
9761
+ },
9762
+ message: 'should be an array of objects that have a "name" property',
9763
+ validate: function (value) {
9764
+ return _$isArray_13(value) && value.length === _$filter_11(value, function (feature) {
9765
+ return feature && typeof feature === 'object' && typeof feature.name === 'string';
9766
+ }).length;
9767
+ }
9768
+ }
9769
+ };
9770
+
9771
+ var _$errorStackParser_9 = errorStackParser;
9772
+
9773
+ // extends helper from babel
9774
+ // https://github.com/babel/babel/blob/916429b516e6466fd06588ee820e40e025d7f3a3/packages/babel-helpers/src/helpers.js#L377-L393
9775
+ var _$assign_10 = function (target) {
9776
+ for (var i = 1; i < arguments.length; i++) {
9777
+ var source = arguments[i];
9778
+
9779
+ for (var key in source) {
9780
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
9781
+ target[key] = source[key];
9782
+ }
9783
+ }
9784
+ }
9785
+
9786
+ return target;
9787
+ };
9788
+
9789
+
9790
+ var _$map_15 = function (arr, fn) {
9791
+ return _$reduce_16(arr, function (accum, item, i, arr) {
9792
+ return accum.concat(fn(item, i, arr));
9793
+ }, []);
9794
+ };
9795
+
9796
+ var _$safeJsonStringify_31 = function (data, replacer, space, opts) {
9797
+ var redactedKeys = opts && opts.redactedKeys ? opts.redactedKeys : [];
9798
+ var redactedPaths = opts && opts.redactedPaths ? opts.redactedPaths : [];
9799
+ return JSON.stringify(prepareObjForSerialization(data, redactedKeys, redactedPaths), replacer, space);
9800
+ };
9801
+
9802
+ var MAX_DEPTH = 20;
9803
+ var MAX_EDGES = 25000;
9804
+ var MIN_PRESERVED_DEPTH = 8;
9805
+ var REPLACEMENT_NODE = '...';
9806
+
9807
+ function isError(o) {
9808
+ return o instanceof Error || /^\[object (Error|(Dom)?Exception)\]$/.test(Object.prototype.toString.call(o));
9809
+ }
9810
+
9811
+ function throwsMessage(err) {
9812
+ return '[Throws: ' + (err ? err.message : '?') + ']';
9813
+ }
9814
+
9815
+ function find(haystack, needle) {
9816
+ for (var i = 0, len = haystack.length; i < len; i++) {
9817
+ if (haystack[i] === needle) return true;
9818
+ }
9819
+
9820
+ return false;
9821
+ } // returns true if the string `path` starts with any of the provided `paths`
9822
+
9823
+
9824
+ function isDescendent(paths, path) {
9825
+ for (var i = 0, len = paths.length; i < len; i++) {
9826
+ if (path.indexOf(paths[i]) === 0) return true;
9827
+ }
9828
+
9829
+ return false;
9830
+ }
9831
+
9832
+ function shouldRedact(patterns, key) {
9833
+ for (var i = 0, len = patterns.length; i < len; i++) {
9834
+ if (typeof patterns[i] === 'string' && patterns[i].toLowerCase() === key.toLowerCase()) return true;
9835
+ if (patterns[i] && typeof patterns[i].test === 'function' && patterns[i].test(key)) return true;
9836
+ }
9837
+
9838
+ return false;
9839
+ }
9840
+
9841
+ function __isArray_31(obj) {
9842
+ return Object.prototype.toString.call(obj) === '[object Array]';
9843
+ }
9844
+
9845
+ function safelyGetProp(obj, prop) {
9846
+ try {
9847
+ return obj[prop];
9848
+ } catch (err) {
9849
+ return throwsMessage(err);
9850
+ }
9851
+ }
9852
+
9853
+ function prepareObjForSerialization(obj, redactedKeys, redactedPaths) {
9854
+ var seen = []; // store references to objects we have seen before
9855
+
9856
+ var edges = 0;
9857
+
9858
+ function visit(obj, path) {
9859
+ function edgesExceeded() {
9860
+ return path.length > MIN_PRESERVED_DEPTH && edges > MAX_EDGES;
9861
+ }
9862
+
9863
+ edges++;
9864
+ if (path.length > MAX_DEPTH) return REPLACEMENT_NODE;
9865
+ if (edgesExceeded()) return REPLACEMENT_NODE;
9866
+ if (obj === null || typeof obj !== 'object') return obj;
9867
+ if (find(seen, obj)) return '[Circular]';
9868
+ seen.push(obj);
9869
+
9870
+ if (typeof obj.toJSON === 'function') {
9871
+ try {
9872
+ // we're not going to count this as an edge because it
9873
+ // replaces the value of the currently visited object
9874
+ edges--;
9875
+ var fResult = visit(obj.toJSON(), path);
9876
+ seen.pop();
9877
+ return fResult;
9878
+ } catch (err) {
9879
+ return throwsMessage(err);
9880
+ }
9881
+ }
9882
+
9883
+ var er = isError(obj);
9884
+
9885
+ if (er) {
9886
+ edges--;
9887
+ var eResult = visit({
9888
+ name: obj.name,
9889
+ message: obj.message
9890
+ }, path);
9891
+ seen.pop();
9892
+ return eResult;
9893
+ }
9894
+
9895
+ if (__isArray_31(obj)) {
9896
+ var aResult = [];
9897
+
9898
+ for (var i = 0, len = obj.length; i < len; i++) {
9899
+ if (edgesExceeded()) {
9900
+ aResult.push(REPLACEMENT_NODE);
9901
+ break;
9902
+ }
9903
+
9904
+ aResult.push(visit(obj[i], path.concat('[]')));
9905
+ }
9906
+
9907
+ seen.pop();
9908
+ return aResult;
9909
+ }
9910
+
9911
+ var result = {};
9912
+
9913
+ try {
9914
+ for (var prop in obj) {
9915
+ if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue;
9916
+
9917
+ if (isDescendent(redactedPaths, path.join('.')) && shouldRedact(redactedKeys, prop)) {
9918
+ result[prop] = '[REDACTED]';
9919
+ continue;
9920
+ }
9921
+
9922
+ if (edgesExceeded()) {
9923
+ result[prop] = REPLACEMENT_NODE;
9924
+ break;
9925
+ }
9926
+
9927
+ result[prop] = visit(safelyGetProp(obj, prop), path.concat(prop));
9928
+ }
9929
+ } catch (e) {}
9930
+
9931
+ seen.pop();
9932
+ return result;
9933
+ }
9934
+
9935
+ return visit(obj, []);
9936
+ }
9937
+
9938
+ function add(existingFeatures, existingFeatureKeys, name, variant) {
9939
+ if (typeof name !== 'string') {
9940
+ return;
9941
+ }
9942
+
9943
+ if (variant === undefined) {
9944
+ variant = null;
9945
+ } else if (variant !== null && typeof variant !== 'string') {
9946
+ variant = _$safeJsonStringify_31(variant);
9947
+ }
9948
+
9949
+ var existingIndex = existingFeatureKeys[name];
9950
+
9951
+ if (typeof existingIndex === 'number') {
9952
+ existingFeatures[existingIndex] = {
9953
+ name: name,
9954
+ variant: variant
9955
+ };
9956
+ return;
9957
+ }
9958
+
9959
+ existingFeatures.push({
9960
+ name: name,
9961
+ variant: variant
9962
+ });
9963
+ existingFeatureKeys[name] = existingFeatures.length - 1;
9964
+ }
9965
+
9966
+ function merge(existingFeatures, newFeatures, existingFeatureKeys) {
9967
+ if (!_$isArray_13(newFeatures)) {
9968
+ return;
9969
+ }
9970
+
9971
+ for (var i = 0; i < newFeatures.length; ++i) {
9972
+ var feature = newFeatures[i];
9973
+
9974
+ if (feature === null || typeof feature !== 'object') {
9975
+ continue;
9976
+ } // 'add' will handle if 'name' doesn't exist & 'variant' is optional
9977
+
9978
+
9979
+ add(existingFeatures, existingFeatureKeys, feature.name, feature.variant);
9980
+ }
9981
+
9982
+ return existingFeatures;
9983
+ } // convert feature flags from a map of 'name -> variant' into the format required
9984
+ // by the Bugsnag Event API:
9985
+ // [{ featureFlag: 'name', variant: 'variant' }, { featureFlag: 'name 2' }]
9986
+
9987
+
9988
+ function toEventApi(featureFlags) {
9989
+ return _$map_15(_$filter_11(featureFlags, Boolean), function (_ref) {
9990
+ var name = _ref.name,
9991
+ variant = _ref.variant;
9992
+ var flag = {
9993
+ featureFlag: name
9994
+ }; // don't add a 'variant' property unless there's actually a value
9995
+
9996
+ if (typeof variant === 'string') {
9997
+ flag.variant = variant;
9998
+ }
9999
+
10000
+ return flag;
10001
+ });
10002
+ }
10003
+
10004
+ function clear(features, featuresIndex, name) {
10005
+ var existingIndex = featuresIndex[name];
10006
+
10007
+ if (typeof existingIndex === 'number') {
10008
+ features[existingIndex] = null;
10009
+ delete featuresIndex[name];
10010
+ }
10011
+ }
10012
+
10013
+ var _$featureFlagDelegate_17 = {
10014
+ add: add,
10015
+ clear: clear,
10016
+ merge: merge,
10017
+ toEventApi: toEventApi
10018
+ };
10019
+
10020
+ // Given `err` which may be an error, does it have a stack property which is a string?
10021
+ var _$hasStack_18 = function (err) {
10022
+ return !!err && (!!err.stack || !!err.stacktrace || !!err['opera#sourceloc']) && typeof (err.stack || err.stacktrace || err['opera#sourceloc']) === 'string' && err.stack !== err.name + ": " + err.message;
10023
+ };
10024
+
10025
+ var _$iserror_19 = iserror;
10026
+
10027
+ var __add_21 = function (state, section, keyOrObj, maybeVal) {
10028
+ var _updates;
10029
+
10030
+ if (!section) return;
10031
+ var updates; // addMetadata("section", null) -> clears section
10032
+
10033
+ if (keyOrObj === null) return __clear_21(state, section); // normalise the two supported input types into object form
10034
+
10035
+ if (typeof keyOrObj === 'object') updates = keyOrObj;
10036
+ if (typeof keyOrObj === 'string') updates = (_updates = {}, _updates[keyOrObj] = maybeVal, _updates); // exit if we don't have an updates object at this point
10037
+
10038
+ if (!updates) return; // ensure a section with this name exists
10039
+
10040
+ if (!state[section]) state[section] = {}; // merge the updates with the existing section
10041
+
10042
+ state[section] = _$assign_10({}, state[section], updates);
10043
+ };
10044
+
10045
+ var get = function (state, section, key) {
10046
+ if (typeof section !== 'string') return undefined;
10047
+
10048
+ if (!key) {
10049
+ return state[section];
10050
+ }
10051
+
10052
+ if (state[section]) {
10053
+ return state[section][key];
10054
+ }
10055
+
10056
+ return undefined;
10057
+ };
10058
+
10059
+ var __clear_21 = function (state, section, key) {
10060
+ if (typeof section !== 'string') return; // clear an entire section
10061
+
10062
+ if (!key) {
10063
+ delete state[section];
10064
+ return;
10065
+ } // clear a single value from a section
10066
+
10067
+
10068
+ if (state[section]) {
10069
+ delete state[section][key];
10070
+ }
10071
+ };
10072
+
10073
+ var _$metadataDelegate_21 = {
10074
+ add: __add_21,
10075
+ get: get,
10076
+ clear: __clear_21
10077
+ };
10078
+
10079
+ var StackGenerator = stackGenerator;
10080
+
10081
+ var Event = /*#__PURE__*/function () {
10082
+ function Event(errorClass, errorMessage, stacktrace, handledState, originalError) {
10083
+ if (stacktrace === void 0) {
10084
+ stacktrace = [];
10085
+ }
10086
+
10087
+ if (handledState === void 0) {
10088
+ handledState = defaultHandledState();
10089
+ }
10090
+
10091
+ this.apiKey = undefined;
10092
+ this.context = undefined;
10093
+ this.groupingHash = undefined;
10094
+ this.originalError = originalError;
10095
+ this._handledState = handledState;
10096
+ this.severity = this._handledState.severity;
10097
+ this.unhandled = this._handledState.unhandled;
10098
+ this.app = {};
10099
+ this.device = {};
10100
+ this.request = {};
10101
+ this.breadcrumbs = [];
10102
+ this.threads = [];
10103
+ this._metadata = {};
10104
+ this._features = [];
10105
+ this._featuresIndex = {};
10106
+ this._user = {};
10107
+ this._session = undefined;
10108
+ this.errors = [createBugsnagError(errorClass, errorMessage, Event.__type, stacktrace)]; // Flags.
10109
+ // Note these are not initialised unless they are used
10110
+ // to save unnecessary bytes in the browser bundle
10111
+
10112
+ /* this.attemptImmediateDelivery, default: true */
10113
+ }
10114
+
10115
+ var _proto = Event.prototype;
10116
+
10117
+ _proto.addMetadata = function addMetadata(section, keyOrObj, maybeVal) {
10118
+ return _$metadataDelegate_21.add(this._metadata, section, keyOrObj, maybeVal);
10119
+ };
10120
+
10121
+ _proto.getMetadata = function getMetadata(section, key) {
10122
+ return _$metadataDelegate_21.get(this._metadata, section, key);
10123
+ };
10124
+
10125
+ _proto.clearMetadata = function clearMetadata(section, key) {
10126
+ return _$metadataDelegate_21.clear(this._metadata, section, key);
10127
+ };
10128
+
10129
+ _proto.addFeatureFlag = function addFeatureFlag(name, variant) {
10130
+ if (variant === void 0) {
10131
+ variant = null;
10132
+ }
10133
+
10134
+ _$featureFlagDelegate_17.add(this._features, this._featuresIndex, name, variant);
10135
+ };
10136
+
10137
+ _proto.addFeatureFlags = function addFeatureFlags(featureFlags) {
10138
+ _$featureFlagDelegate_17.merge(this._features, featureFlags, this._featuresIndex);
10139
+ };
10140
+
10141
+ _proto.getFeatureFlags = function getFeatureFlags() {
10142
+ return _$featureFlagDelegate_17.toEventApi(this._features);
10143
+ };
10144
+
10145
+ _proto.clearFeatureFlag = function clearFeatureFlag(name) {
10146
+ _$featureFlagDelegate_17.clear(this._features, this._featuresIndex, name);
10147
+ };
10148
+
10149
+ _proto.clearFeatureFlags = function clearFeatureFlags() {
10150
+ this._features = [];
10151
+ this._featuresIndex = {};
10152
+ };
10153
+
10154
+ _proto.getUser = function getUser() {
10155
+ return this._user;
10156
+ };
10157
+
10158
+ _proto.setUser = function setUser(id, email, name) {
10159
+ this._user = {
10160
+ id: id,
10161
+ email: email,
10162
+ name: name
10163
+ };
10164
+ };
10165
+
10166
+ _proto.toJSON = function toJSON() {
10167
+ return {
10168
+ payloadVersion: '4',
10169
+ exceptions: _$map_15(this.errors, function (er) {
10170
+ return _$assign_10({}, er, {
10171
+ message: er.errorMessage
10172
+ });
10173
+ }),
10174
+ severity: this.severity,
10175
+ unhandled: this._handledState.unhandled,
10176
+ severityReason: this._handledState.severityReason,
10177
+ app: this.app,
10178
+ device: this.device,
10179
+ request: this.request,
10180
+ breadcrumbs: this.breadcrumbs,
10181
+ context: this.context,
10182
+ groupingHash: this.groupingHash,
10183
+ metaData: this._metadata,
10184
+ user: this._user,
10185
+ session: this._session,
10186
+ featureFlags: this.getFeatureFlags()
10187
+ };
10188
+ };
10189
+
10190
+ return Event;
10191
+ }(); // takes a stacktrace.js style stackframe (https://github.com/stacktracejs/stackframe)
10192
+ // and returns a Bugsnag compatible stackframe (https://docs.bugsnag.com/api/error-reporting/#json-payload)
10193
+
10194
+
10195
+ var formatStackframe = function (frame) {
10196
+ var f = {
10197
+ file: frame.fileName,
10198
+ method: normaliseFunctionName(frame.functionName),
10199
+ lineNumber: frame.lineNumber,
10200
+ columnNumber: frame.columnNumber,
10201
+ code: undefined,
10202
+ inProject: undefined
10203
+ }; // Some instances result in no file:
10204
+ // - calling notify() from chrome's terminal results in no file/method.
10205
+ // - non-error exception thrown from global code in FF
10206
+ // This adds one.
10207
+
10208
+ if (f.lineNumber > -1 && !f.file && !f.method) {
10209
+ f.file = 'global code';
10210
+ }
10211
+
10212
+ return f;
10213
+ };
10214
+
10215
+ var normaliseFunctionName = function (name) {
10216
+ return /^global code$/i.test(name) ? 'global code' : name;
10217
+ };
10218
+
10219
+ var defaultHandledState = function () {
10220
+ return {
10221
+ unhandled: false,
10222
+ severity: 'warning',
10223
+ severityReason: {
10224
+ type: 'handledException'
10225
+ }
10226
+ };
10227
+ };
10228
+
10229
+ var ensureString = function (str) {
10230
+ return typeof str === 'string' ? str : '';
10231
+ };
10232
+
10233
+ function createBugsnagError(errorClass, errorMessage, type, stacktrace) {
10234
+ return {
10235
+ errorClass: ensureString(errorClass),
10236
+ errorMessage: ensureString(errorMessage),
10237
+ type: type,
10238
+ stacktrace: _$reduce_16(stacktrace, function (accum, frame) {
10239
+ var f = formatStackframe(frame); // don't include a stackframe if none of its properties are defined
10240
+
10241
+ try {
10242
+ if (JSON.stringify(f) === '{}') return accum;
10243
+ return accum.concat(f);
10244
+ } catch (e) {
10245
+ return accum;
10246
+ }
10247
+ }, [])
10248
+ };
10249
+ }
10250
+
10251
+ function getCauseStack(error) {
10252
+ if (error.cause) {
10253
+ return [error].concat(getCauseStack(error.cause));
10254
+ } else {
10255
+ return [error];
10256
+ }
10257
+ } // Helpers
10258
+
10259
+
10260
+ Event.getStacktrace = function (error, errorFramesToSkip, backtraceFramesToSkip) {
10261
+ if (_$hasStack_18(error)) return _$errorStackParser_9.parse(error).slice(errorFramesToSkip); // error wasn't provided or didn't have a stacktrace so try to walk the callstack
10262
+
10263
+ try {
10264
+ return _$filter_11(StackGenerator.backtrace(), function (frame) {
10265
+ return (frame.functionName || '').indexOf('StackGenerator$$') === -1;
10266
+ }).slice(1 + backtraceFramesToSkip);
10267
+ } catch (e) {
10268
+ return [];
10269
+ }
10270
+ };
10271
+
10272
+ Event.create = function (maybeError, tolerateNonErrors, handledState, component, errorFramesToSkip, logger) {
10273
+ if (errorFramesToSkip === void 0) {
10274
+ errorFramesToSkip = 0;
10275
+ }
10276
+
10277
+ var _normaliseError = normaliseError(maybeError, tolerateNonErrors, component, logger),
10278
+ error = _normaliseError[0],
10279
+ internalFrames = _normaliseError[1];
10280
+
10281
+ var event;
10282
+
10283
+ try {
10284
+ var stacktrace = Event.getStacktrace(error, // if an error was created/throw in the normaliseError() function, we need to
10285
+ // tell the getStacktrace() function to skip the number of frames we know will
10286
+ // be from our own functions. This is added to the number of frames deep we
10287
+ // were told about
10288
+ internalFrames > 0 ? 1 + internalFrames + errorFramesToSkip : 0, // if there's no stacktrace, the callstack may be walked to generated one.
10289
+ // this is how many frames should be removed because they come from our library
10290
+ 1 + errorFramesToSkip);
10291
+ event = new Event(error.name, error.message, stacktrace, handledState, maybeError);
10292
+ } catch (e) {
10293
+ event = new Event(error.name, error.message, [], handledState, maybeError);
10294
+ }
10295
+
10296
+ if (error.name === 'InvalidError') {
10297
+ event.addMetadata("" + component, 'non-error parameter', makeSerialisable(maybeError));
10298
+ }
10299
+
10300
+ if (error.cause) {
10301
+ var _event$errors;
10302
+
10303
+ var causes = getCauseStack(error).slice(1);
10304
+ var normalisedCauses = _$map_15(causes, function (cause) {
10305
+ // Only get stacktrace for error causes that are a valid JS Error and already have a stack
10306
+ var stacktrace = _$iserror_19(cause) && _$hasStack_18(cause) ? _$errorStackParser_9.parse(cause) : [];
10307
+
10308
+ var _normaliseError2 = normaliseError(cause, true, 'error cause'),
10309
+ error = _normaliseError2[0];
10310
+
10311
+ if (error.name === 'InvalidError') event.addMetadata('error cause', makeSerialisable(cause));
10312
+ return createBugsnagError(error.name, error.message, Event.__type, stacktrace);
10313
+ });
10314
+
10315
+ (_event$errors = event.errors).push.apply(_event$errors, normalisedCauses);
10316
+ }
10317
+
10318
+ return event;
10319
+ };
10320
+
10321
+ var makeSerialisable = function (err) {
10322
+ if (err === null) return 'null';
10323
+ if (err === undefined) return 'undefined';
10324
+ return err;
10325
+ };
10326
+
10327
+ var normaliseError = function (maybeError, tolerateNonErrors, component, logger) {
10328
+ var error;
10329
+ var internalFrames = 0;
10330
+
10331
+ var createAndLogInputError = function (reason) {
10332
+ var verb = component === 'error cause' ? 'was' : 'received';
10333
+ if (logger) logger.warn(component + " " + verb + " a non-error: \"" + reason + "\"");
10334
+ var err = new Error(component + " " + verb + " a non-error. See \"" + component + "\" tab for more detail.");
10335
+ err.name = 'InvalidError';
10336
+ return err;
10337
+ }; // In some cases:
10338
+ //
10339
+ // - the promise rejection handler (both in the browser and node)
10340
+ // - the node uncaughtException handler
10341
+ //
10342
+ // We are really limited in what we can do to get a stacktrace. So we use the
10343
+ // tolerateNonErrors option to ensure that the resulting error communicates as
10344
+ // such.
10345
+
10346
+
10347
+ if (!tolerateNonErrors) {
10348
+ if (_$iserror_19(maybeError)) {
10349
+ error = maybeError;
10350
+ } else {
10351
+ error = createAndLogInputError(typeof maybeError);
10352
+ internalFrames += 2;
10353
+ }
10354
+ } else {
10355
+ switch (typeof maybeError) {
10356
+ case 'string':
10357
+ case 'number':
10358
+ case 'boolean':
10359
+ error = new Error(String(maybeError));
10360
+ internalFrames += 1;
10361
+ break;
10362
+
10363
+ case 'function':
10364
+ error = createAndLogInputError('function');
10365
+ internalFrames += 2;
10366
+ break;
10367
+
10368
+ case 'object':
10369
+ if (maybeError !== null && _$iserror_19(maybeError)) {
10370
+ error = maybeError;
10371
+ } else if (maybeError !== null && hasNecessaryFields(maybeError)) {
10372
+ error = new Error(maybeError.message || maybeError.errorMessage);
10373
+ error.name = maybeError.name || maybeError.errorClass;
10374
+ internalFrames += 1;
10375
+ } else {
10376
+ error = createAndLogInputError(maybeError === null ? 'null' : 'unsupported object');
10377
+ internalFrames += 2;
10378
+ }
10379
+
10380
+ break;
10381
+
10382
+ default:
10383
+ error = createAndLogInputError('nothing');
10384
+ internalFrames += 2;
10385
+ }
10386
+ }
10387
+
10388
+ if (!_$hasStack_18(error)) {
10389
+ // in IE10/11 a new Error() doesn't have a stacktrace until you throw it, so try that here
10390
+ try {
10391
+ throw error;
10392
+ } catch (e) {
10393
+ if (_$hasStack_18(e)) {
10394
+ error = e; // if the error only got a stacktrace after we threw it here, we know it
10395
+ // will only have one extra internal frame from this function, regardless
10396
+ // of whether it went through createAndLogInputError() or not
10397
+
10398
+ internalFrames = 1;
10399
+ }
10400
+ }
10401
+ }
10402
+
10403
+ return [error, internalFrames];
10404
+ }; // default value for stacktrace.type
10405
+
10406
+
10407
+ Event.__type = 'browserjs';
10408
+
10409
+ var hasNecessaryFields = function (error) {
10410
+ return (typeof error.name === 'string' || typeof error.errorClass === 'string') && (typeof error.message === 'string' || typeof error.errorMessage === 'string');
10411
+ };
10412
+
10413
+ var _$Event_4 = Event;
10414
+
10415
+ // This is a heavily modified/simplified version of
10416
+ // https://github.com/othiym23/async-some
10417
+ // with the logic flipped so that it is akin to the
10418
+ // synchronous "every" method instead of "some".
10419
+ // run the asynchronous test function (fn) over each item in the array (arr)
10420
+ // in series until:
10421
+ // - fn(item, cb) => calls cb(null, false)
10422
+ // - or the end of the array is reached
10423
+ // the callback (cb) will be passed (null, false) if any of the items in arr
10424
+ // caused fn to call back with false, otherwise it will be passed (null, true)
10425
+ var _$asyncEvery_5 = function (arr, fn, cb) {
10426
+ var index = 0;
10427
+
10428
+ var next = function () {
10429
+ if (index >= arr.length) return cb(null, true);
10430
+ fn(arr[index], function (err, result) {
10431
+ if (err) return cb(err);
10432
+ if (result === false) return cb(null, false);
10433
+ index++;
10434
+ next();
10435
+ });
10436
+ };
10437
+
10438
+ next();
10439
+ };
10440
+
10441
+ var _$callbackRunner_7 = function (callbacks, event, onCallbackError, cb) {
10442
+ // This function is how we support different kinds of callback:
10443
+ // - synchronous - return value
10444
+ // - node-style async with callback - cb(err, value)
10445
+ // - promise/thenable - resolve(value)
10446
+ // It normalises each of these into the lowest common denominator – a node-style callback
10447
+ var runMaybeAsyncCallback = function (fn, cb) {
10448
+ if (typeof fn !== 'function') return cb(null);
10449
+
10450
+ try {
10451
+ // if function appears sync…
10452
+ if (fn.length !== 2) {
10453
+ var ret = fn(event); // check if it returned a "thenable" (promise)
10454
+
10455
+ if (ret && typeof ret.then === 'function') {
10456
+ return ret.then( // resolve
10457
+ function (val) {
10458
+ return setTimeout(function () {
10459
+ return cb(null, val);
10460
+ });
10461
+ }, // reject
10462
+ function (err) {
10463
+ setTimeout(function () {
10464
+ onCallbackError(err);
10465
+ return cb(null, true);
10466
+ });
10467
+ });
10468
+ }
10469
+
10470
+ return cb(null, ret);
10471
+ } // if function is async…
10472
+
10473
+
10474
+ fn(event, function (err, result) {
10475
+ if (err) {
10476
+ onCallbackError(err);
10477
+ return cb(null);
10478
+ }
10479
+
10480
+ cb(null, result);
10481
+ });
10482
+ } catch (e) {
10483
+ onCallbackError(e);
10484
+ cb(null);
10485
+ }
10486
+ };
10487
+
10488
+ _$asyncEvery_5(callbacks, runMaybeAsyncCallback, cb);
10489
+ };
10490
+
10491
+ var _$syncCallbackRunner_24 = function (callbacks, callbackArg, callbackType, logger) {
10492
+ var ignore = false;
10493
+ var cbs = callbacks.slice();
10494
+
10495
+ while (!ignore) {
10496
+ if (!cbs.length) break;
10497
+
10498
+ try {
10499
+ ignore = cbs.pop()(callbackArg) === false;
10500
+ } catch (e) {
10501
+ logger.error("Error occurred in " + callbackType + " callback, continuing anyway\u2026");
10502
+ logger.error(e);
10503
+ }
10504
+ }
10505
+
10506
+ return ignore;
10507
+ };
10508
+
10509
+ var _$pad_30 = function pad(num, size) {
10510
+ var s = '000000000' + num;
10511
+ return s.substr(s.length - size);
10512
+ };
10513
+
10514
+ var os = os__default['default'],
10515
+ padding = 2,
10516
+ pid = _$pad_30(process.pid.toString(36), padding),
10517
+ hostname = os.hostname(),
10518
+ length = hostname.length,
10519
+ hostId = _$pad_30(hostname.split('').reduce(function (prev, char) {
10520
+ return +prev + char.charCodeAt(0);
10521
+ }, +length + 36).toString(36), padding);
10522
+
10523
+ var _$fingerprint_29 = function fingerprint() {
10524
+ return pid + hostId;
10525
+ };
10526
+
10527
+ var c = 0,
10528
+ blockSize = 4,
10529
+ base = 36,
10530
+ discreteValues = Math.pow(base, blockSize);
10531
+
10532
+ function randomBlock() {
10533
+ return _$pad_30((Math.random() * discreteValues << 0).toString(base), blockSize);
10534
+ }
10535
+
10536
+ function safeCounter() {
10537
+ c = c < discreteValues ? c : 0;
10538
+ c++; // this is not subliminal
10539
+
10540
+ return c - 1;
10541
+ }
10542
+
10543
+ function cuid() {
10544
+ // Starting with a lowercase letter makes
10545
+ // it HTML element ID friendly.
10546
+ var letter = 'c',
10547
+ // hard-coded allows for sequential access
10548
+ // timestamp
10549
+ // warning: this exposes the exact date and time
10550
+ // that the uid was created.
10551
+ timestamp = new Date().getTime().toString(base),
10552
+ // Prevent same-machine collisions.
10553
+ counter = _$pad_30(safeCounter().toString(base), blockSize),
10554
+ // A few chars to generate distinct ids for different
10555
+ // clients (so different computers are far less
10556
+ // likely to generate the same id)
10557
+ print = _$fingerprint_29(),
10558
+ // Grab some more chars from Math.random()
10559
+ random = randomBlock() + randomBlock();
10560
+ return letter + timestamp + counter + print + random;
10561
+ }
10562
+
10563
+ cuid.fingerprint = _$fingerprint_29;
10564
+ var _$cuid_28 = cuid;
10565
+
10566
+ var Session = /*#__PURE__*/function () {
10567
+ function Session() {
10568
+ this.id = _$cuid_28();
10569
+ this.startedAt = new Date();
10570
+ this._handled = 0;
10571
+ this._unhandled = 0;
10572
+ this._user = {};
10573
+ this.app = {};
10574
+ this.device = {};
10575
+ }
10576
+
10577
+ var _proto = Session.prototype;
10578
+
10579
+ _proto.getUser = function getUser() {
10580
+ return this._user;
10581
+ };
10582
+
10583
+ _proto.setUser = function setUser(id, email, name) {
10584
+ this._user = {
10585
+ id: id,
10586
+ email: email,
10587
+ name: name
10588
+ };
10589
+ };
10590
+
10591
+ _proto.toJSON = function toJSON() {
10592
+ return {
10593
+ id: this.id,
10594
+ startedAt: this.startedAt,
10595
+ events: {
10596
+ handled: this._handled,
10597
+ unhandled: this._unhandled
10598
+ }
10599
+ };
10600
+ };
10601
+
10602
+ _proto._track = function _track(event) {
10603
+ this[event._handledState.unhandled ? '_unhandled' : '_handled'] += 1;
10604
+ };
10605
+
10606
+ return Session;
10607
+ }();
10608
+
10609
+ var _$Session_32 = Session;
10610
+
10611
+ var __add_2 = _$featureFlagDelegate_17.add,
10612
+ __clear_2 = _$featureFlagDelegate_17.clear,
10613
+ __merge_2 = _$featureFlagDelegate_17.merge;
10614
+
10615
+ var noop = function () {};
10616
+
10617
+ var Client = /*#__PURE__*/function () {
10618
+ function Client(configuration, schema, internalPlugins, notifier) {
10619
+ var _this = this;
10620
+
10621
+ if (schema === void 0) {
10622
+ schema = _$config_3.schema;
10623
+ }
10624
+
10625
+ if (internalPlugins === void 0) {
10626
+ internalPlugins = [];
10627
+ }
10628
+
10629
+ // notifier id
10630
+ this._notifier = notifier; // intialise opts and config
10631
+
10632
+ this._config = {};
10633
+ this._schema = schema; // i/o
10634
+
10635
+ this._delivery = {
10636
+ sendSession: noop,
10637
+ sendEvent: noop
10638
+ };
10639
+ this._logger = {
10640
+ debug: noop,
10641
+ info: noop,
10642
+ warn: noop,
10643
+ error: noop
10644
+ }; // plugins
10645
+
10646
+ this._plugins = {}; // state
10647
+
10648
+ this._breadcrumbs = [];
10649
+ this._session = null;
10650
+ this._metadata = {};
10651
+ this._featuresIndex = {};
10652
+ this._features = [];
10653
+ this._context = undefined;
10654
+ this._user = {}; // callbacks:
10655
+ // e: onError
10656
+ // s: onSession
10657
+ // sp: onSessionPayload
10658
+ // b: onBreadcrumb
10659
+ // (note these names are minified by hand because object
10660
+ // properties are not safe to minify automatically)
10661
+
10662
+ this._cbs = {
10663
+ e: [],
10664
+ s: [],
10665
+ sp: [],
10666
+ b: []
10667
+ }; // expose internal constructors
10668
+
10669
+ this.Client = Client;
10670
+ this.Event = _$Event_4;
10671
+ this.Breadcrumb = _$Breadcrumb_1;
10672
+ this.Session = _$Session_32;
10673
+ this._config = this._configure(configuration, internalPlugins);
10674
+ _$map_15(internalPlugins.concat(this._config.plugins), function (pl) {
10675
+ if (pl) _this._loadPlugin(pl);
10676
+ }); // when notify() is called we need to know how many frames are from our own source
10677
+ // this inital value is 1 not 0 because we wrap notify() to ensure it is always
10678
+ // bound to have the client as its `this` value – see below.
10679
+
10680
+ this._depth = 1;
10681
+ var self = this;
10682
+ var notify = this.notify;
10683
+
10684
+ this.notify = function () {
10685
+ return notify.apply(self, arguments);
10686
+ };
10687
+ }
10688
+
10689
+ var _proto = Client.prototype;
10690
+
10691
+ _proto.addMetadata = function addMetadata(section, keyOrObj, maybeVal) {
10692
+ return _$metadataDelegate_21.add(this._metadata, section, keyOrObj, maybeVal);
10693
+ };
10694
+
10695
+ _proto.getMetadata = function getMetadata(section, key) {
10696
+ return _$metadataDelegate_21.get(this._metadata, section, key);
10697
+ };
10698
+
10699
+ _proto.clearMetadata = function clearMetadata(section, key) {
10700
+ return _$metadataDelegate_21.clear(this._metadata, section, key);
10701
+ };
10702
+
10703
+ _proto.addFeatureFlag = function addFeatureFlag(name, variant) {
10704
+ if (variant === void 0) {
10705
+ variant = null;
10706
+ }
10707
+
10708
+ __add_2(this._features, this._featuresIndex, name, variant);
10709
+ };
10710
+
10711
+ _proto.addFeatureFlags = function addFeatureFlags(featureFlags) {
10712
+ __merge_2(this._features, featureFlags, this._featuresIndex);
10713
+ };
10714
+
10715
+ _proto.clearFeatureFlag = function clearFeatureFlag(name) {
10716
+ __clear_2(this._features, this._featuresIndex, name);
10717
+ };
10718
+
10719
+ _proto.clearFeatureFlags = function clearFeatureFlags() {
10720
+ this._features = [];
10721
+ this._featuresIndex = {};
10722
+ };
10723
+
10724
+ _proto.getContext = function getContext() {
10725
+ return this._context;
10726
+ };
10727
+
10728
+ _proto.setContext = function setContext(c) {
10729
+ this._context = c;
10730
+ };
10731
+
10732
+ _proto._configure = function _configure(opts, internalPlugins) {
10733
+ var schema = _$reduce_16(internalPlugins, function (schema, plugin) {
10734
+ if (plugin && plugin.configSchema) return _$assign_10({}, schema, plugin.configSchema);
10735
+ return schema;
10736
+ }, this._schema); // accumulate configuration and error messages
10737
+
10738
+ var _reduce = _$reduce_16(_$keys_14(schema), function (accum, key) {
10739
+ var defaultValue = schema[key].defaultValue(opts[key]);
10740
+
10741
+ if (opts[key] !== undefined) {
10742
+ var valid = schema[key].validate(opts[key]);
10743
+
10744
+ if (!valid) {
10745
+ accum.errors[key] = schema[key].message;
10746
+ accum.config[key] = defaultValue;
10747
+ } else {
10748
+ if (schema[key].allowPartialObject) {
10749
+ accum.config[key] = _$assign_10(defaultValue, opts[key]);
10750
+ } else {
10751
+ accum.config[key] = opts[key];
10752
+ }
10753
+ }
10754
+ } else {
10755
+ accum.config[key] = defaultValue;
10756
+ }
10757
+
10758
+ return accum;
10759
+ }, {
10760
+ errors: {},
10761
+ config: {}
10762
+ }),
10763
+ errors = _reduce.errors,
10764
+ config = _reduce.config;
10765
+
10766
+ if (schema.apiKey) {
10767
+ // missing api key is the only fatal error
10768
+ if (!config.apiKey) throw new Error('No Bugsnag API Key set'); // warn about an apikey that is not of the expected format
10769
+
10770
+ if (!/^[0-9a-f]{32}$/i.test(config.apiKey)) errors.apiKey = 'should be a string of 32 hexadecimal characters';
10771
+ } // update and elevate some options
10772
+
10773
+
10774
+ this._metadata = _$assign_10({}, config.metadata);
10775
+ __merge_2(this._features, config.featureFlags, this._featuresIndex);
10776
+ this._user = _$assign_10({}, config.user);
10777
+ this._context = config.context;
10778
+ if (config.logger) this._logger = config.logger; // add callbacks
10779
+
10780
+ if (config.onError) this._cbs.e = this._cbs.e.concat(config.onError);
10781
+ if (config.onBreadcrumb) this._cbs.b = this._cbs.b.concat(config.onBreadcrumb);
10782
+ if (config.onSession) this._cbs.s = this._cbs.s.concat(config.onSession); // finally warn about any invalid config where we fell back to the default
10783
+
10784
+ if (_$keys_14(errors).length) {
10785
+ this._logger.warn(generateConfigErrorMessage(errors, opts));
10786
+ }
10787
+
10788
+ return config;
10789
+ };
10790
+
10791
+ _proto.getUser = function getUser() {
10792
+ return this._user;
10793
+ };
10794
+
10795
+ _proto.setUser = function setUser(id, email, name) {
10796
+ this._user = {
10797
+ id: id,
10798
+ email: email,
10799
+ name: name
10800
+ };
10801
+ };
10802
+
10803
+ _proto._loadPlugin = function _loadPlugin(plugin) {
10804
+ var result = plugin.load(this); // JS objects are not the safest way to store arbitrarily keyed values,
10805
+ // so bookend the key with some characters that prevent tampering with
10806
+ // stuff like __proto__ etc. (only store the result if the plugin had a
10807
+ // name)
10808
+
10809
+ if (plugin.name) this._plugins["~" + plugin.name + "~"] = result;
10810
+ return this;
10811
+ };
10812
+
10813
+ _proto.getPlugin = function getPlugin(name) {
10814
+ return this._plugins["~" + name + "~"];
10815
+ };
10816
+
10817
+ _proto._setDelivery = function _setDelivery(d) {
10818
+ this._delivery = d(this);
10819
+ };
10820
+
10821
+ _proto.startSession = function startSession() {
10822
+ var session = new _$Session_32();
10823
+ session.app.releaseStage = this._config.releaseStage;
10824
+ session.app.version = this._config.appVersion;
10825
+ session.app.type = this._config.appType;
10826
+ session._user = _$assign_10({}, this._user); // run onSession callbacks
10827
+
10828
+ var ignore = _$syncCallbackRunner_24(this._cbs.s, session, 'onSession', this._logger);
10829
+
10830
+ if (ignore) {
10831
+ this._logger.debug('Session not started due to onSession callback');
10832
+
10833
+ return this;
10834
+ }
10835
+
10836
+ return this._sessionDelegate.startSession(this, session);
10837
+ };
10838
+
10839
+ _proto.addOnError = function addOnError(fn, front) {
10840
+ if (front === void 0) {
10841
+ front = false;
10842
+ }
10843
+
10844
+ this._cbs.e[front ? 'unshift' : 'push'](fn);
10845
+ };
10846
+
10847
+ _proto.removeOnError = function removeOnError(fn) {
10848
+ this._cbs.e = _$filter_11(this._cbs.e, function (f) {
10849
+ return f !== fn;
10850
+ });
10851
+ };
10852
+
10853
+ _proto._addOnSessionPayload = function _addOnSessionPayload(fn) {
10854
+ this._cbs.sp.push(fn);
10855
+ };
10856
+
10857
+ _proto.addOnSession = function addOnSession(fn) {
10858
+ this._cbs.s.push(fn);
10859
+ };
10860
+
10861
+ _proto.removeOnSession = function removeOnSession(fn) {
10862
+ this._cbs.s = _$filter_11(this._cbs.s, function (f) {
10863
+ return f !== fn;
10864
+ });
10865
+ };
10866
+
10867
+ _proto.addOnBreadcrumb = function addOnBreadcrumb(fn, front) {
10868
+ if (front === void 0) {
10869
+ front = false;
10870
+ }
10871
+
10872
+ this._cbs.b[front ? 'unshift' : 'push'](fn);
10873
+ };
10874
+
10875
+ _proto.removeOnBreadcrumb = function removeOnBreadcrumb(fn) {
10876
+ this._cbs.b = _$filter_11(this._cbs.b, function (f) {
10877
+ return f !== fn;
10878
+ });
10879
+ };
10880
+
10881
+ _proto.pauseSession = function pauseSession() {
10882
+ return this._sessionDelegate.pauseSession(this);
10883
+ };
10884
+
10885
+ _proto.resumeSession = function resumeSession() {
10886
+ return this._sessionDelegate.resumeSession(this);
10887
+ };
10888
+
10889
+ _proto.leaveBreadcrumb = function leaveBreadcrumb(message, metadata, type) {
10890
+ // coerce bad values so that the defaults get set
10891
+ message = typeof message === 'string' ? message : '';
10892
+ type = typeof type === 'string' && _$includes_12(_$breadcrumbTypes_6, type) ? type : 'manual';
10893
+ metadata = typeof metadata === 'object' && metadata !== null ? metadata : {}; // if no message, discard
10894
+
10895
+ if (!message) return;
10896
+ var crumb = new _$Breadcrumb_1(message, metadata, type); // run onBreadcrumb callbacks
10897
+
10898
+ var ignore = _$syncCallbackRunner_24(this._cbs.b, crumb, 'onBreadcrumb', this._logger);
10899
+
10900
+ if (ignore) {
10901
+ this._logger.debug('Breadcrumb not attached due to onBreadcrumb callback');
10902
+
10903
+ return;
10904
+ } // push the valid crumb onto the queue and maintain the length
10905
+
10906
+
10907
+ this._breadcrumbs.push(crumb);
10908
+
10909
+ if (this._breadcrumbs.length > this._config.maxBreadcrumbs) {
10910
+ this._breadcrumbs = this._breadcrumbs.slice(this._breadcrumbs.length - this._config.maxBreadcrumbs);
10911
+ }
10912
+ };
10913
+
10914
+ _proto._isBreadcrumbTypeEnabled = function _isBreadcrumbTypeEnabled(type) {
10915
+ var types = this._config.enabledBreadcrumbTypes;
10916
+ return types === null || _$includes_12(types, type);
10917
+ };
10918
+
10919
+ _proto.notify = function notify(maybeError, onError, postReportCallback) {
10920
+ if (postReportCallback === void 0) {
10921
+ postReportCallback = noop;
10922
+ }
10923
+
10924
+ var event = _$Event_4.create(maybeError, true, undefined, 'notify()', this._depth + 1, this._logger);
10925
+
10926
+ this._notify(event, onError, postReportCallback);
10927
+ };
10928
+
10929
+ _proto._notify = function _notify(event, onError, postReportCallback) {
10930
+ var _this2 = this;
10931
+
10932
+ if (postReportCallback === void 0) {
10933
+ postReportCallback = noop;
10934
+ }
10935
+
10936
+ event.app = _$assign_10({}, event.app, {
10937
+ releaseStage: this._config.releaseStage,
10938
+ version: this._config.appVersion,
10939
+ type: this._config.appType
10940
+ });
10941
+ event.context = event.context || this._context;
10942
+ event._metadata = _$assign_10({}, event._metadata, this._metadata);
10943
+ event._user = _$assign_10({}, event._user, this._user);
10944
+ event.breadcrumbs = this._breadcrumbs.slice();
10945
+ __merge_2(event._features, this._features, event._featuresIndex); // exit early if events should not be sent on the current releaseStage
10946
+
10947
+ if (this._config.enabledReleaseStages !== null && !_$includes_12(this._config.enabledReleaseStages, this._config.releaseStage)) {
10948
+ this._logger.warn('Event not sent due to releaseStage/enabledReleaseStages configuration');
10949
+
10950
+ return postReportCallback(null, event);
10951
+ }
10952
+
10953
+ var originalSeverity = event.severity;
10954
+
10955
+ var onCallbackError = function (err) {
10956
+ // errors in callbacks are tolerated but we want to log them out
10957
+ _this2._logger.error('Error occurred in onError callback, continuing anyway…');
10958
+
10959
+ _this2._logger.error(err);
10960
+ };
10961
+
10962
+ var callbacks = [].concat(this._cbs.e).concat(onError);
10963
+ _$callbackRunner_7(callbacks, event, onCallbackError, function (err, shouldSend) {
10964
+ if (err) onCallbackError(err);
10965
+
10966
+ if (!shouldSend) {
10967
+ _this2._logger.debug('Event not sent due to onError callback');
10968
+
10969
+ return postReportCallback(null, event);
10970
+ }
10971
+
10972
+ if (_this2._isBreadcrumbTypeEnabled('error')) {
10973
+ // only leave a crumb for the error if actually got sent
10974
+ Client.prototype.leaveBreadcrumb.call(_this2, event.errors[0].errorClass, {
10975
+ errorClass: event.errors[0].errorClass,
10976
+ errorMessage: event.errors[0].errorMessage,
10977
+ severity: event.severity
10978
+ }, 'error');
10979
+ }
10980
+
10981
+ if (originalSeverity !== event.severity) {
10982
+ event._handledState.severityReason = {
10983
+ type: 'userCallbackSetSeverity'
10984
+ };
10985
+ }
10986
+
10987
+ if (event.unhandled !== event._handledState.unhandled) {
10988
+ event._handledState.severityReason.unhandledOverridden = true;
10989
+ event._handledState.unhandled = event.unhandled;
10990
+ }
10991
+
10992
+ if (_this2._session) {
10993
+ _this2._session._track(event);
10994
+
10995
+ event._session = _this2._session;
10996
+ }
10997
+
10998
+ _this2._delivery.sendEvent({
10999
+ apiKey: event.apiKey || _this2._config.apiKey,
11000
+ notifier: _this2._notifier,
11001
+ events: [event]
11002
+ }, function (err) {
11003
+ return postReportCallback(err, event);
11004
+ });
11005
+ });
11006
+ };
11007
+
11008
+ return Client;
11009
+ }();
11010
+
11011
+ var generateConfigErrorMessage = function (errors, rawInput) {
11012
+ var er = new Error("Invalid configuration\n" + _$map_15(_$keys_14(errors), function (key) {
11013
+ return " - " + key + " " + errors[key] + ", got " + stringify(rawInput[key]);
11014
+ }).join('\n\n'));
11015
+ return er;
11016
+ };
11017
+
11018
+ var stringify = function (val) {
11019
+ switch (typeof val) {
11020
+ case 'string':
11021
+ case 'number':
11022
+ case 'object':
11023
+ return JSON.stringify(val);
11024
+
11025
+ default:
11026
+ return String(val);
11027
+ }
11028
+ };
11029
+
11030
+ var _$Client_2 = Client;
11031
+
11032
+ var _$jsonPayload_20 = {};
11033
+
11034
+ var EVENT_REDACTION_PATHS = ['events.[].metaData', 'events.[].breadcrumbs.[].metaData', 'events.[].request'];
11035
+
11036
+ _$jsonPayload_20.event = function (event, redactedKeys) {
11037
+ var payload = _$safeJsonStringify_31(event, null, null, {
11038
+ redactedPaths: EVENT_REDACTION_PATHS,
11039
+ redactedKeys: redactedKeys
11040
+ });
11041
+
11042
+ if (payload.length > 10e5) {
11043
+ event.events[0]._metadata = {
11044
+ notifier: "WARNING!\nSerialized payload was " + payload.length / 10e5 + "MB (limit = 1MB)\nmetadata was removed"
11045
+ };
11046
+ payload = _$safeJsonStringify_31(event, null, null, {
11047
+ redactedPaths: EVENT_REDACTION_PATHS,
11048
+ redactedKeys: redactedKeys
11049
+ });
11050
+ }
11051
+
11052
+ return payload;
11053
+ };
11054
+
11055
+ _$jsonPayload_20.session = function (session, redactedKeys) {
11056
+ var payload = _$safeJsonStringify_31(session, null, null);
11057
+ return payload;
11058
+ };
11059
+
11060
+ var http = http__default['default'];
11061
+
11062
+ var https = https__default['default']; // eslint-disable-next-line node/no-deprecated-api
11063
+
11064
+
11065
+ var ___require_34 = url__default['default'],
11066
+ parse = ___require_34.parse;
11067
+
11068
+ var _$request_34 = function (_ref, cb) {
11069
+ var url = _ref.url,
11070
+ headers = _ref.headers,
11071
+ body = _ref.body,
11072
+ agent = _ref.agent;
11073
+ var didError = false;
11074
+
11075
+ var onError = function (err) {
11076
+ if (didError) return;
11077
+ didError = true;
11078
+ cb(err);
11079
+ };
11080
+
11081
+ var parsedUrl = parse(url);
11082
+ var secure = parsedUrl.protocol === 'https:';
11083
+ var transport = secure ? https : http;
11084
+ var req = transport.request({
11085
+ method: 'POST',
11086
+ hostname: parsedUrl.hostname,
11087
+ port: parsedUrl.port,
11088
+ path: parsedUrl.path,
11089
+ headers: headers,
11090
+ agent: agent
11091
+ });
11092
+ req.on('error', onError);
11093
+ req.on('response', function (res) {
11094
+ bufferResponse(res, function (err, body) {
11095
+ if (err) return onError(err);
11096
+
11097
+ if (res.statusCode < 200 || res.statusCode >= 300) {
11098
+ return onError(new Error("Bad statusCode from API: " + res.statusCode + "\n" + body));
11099
+ }
11100
+
11101
+ cb(null, body);
11102
+ });
11103
+ });
11104
+ req.write(body);
11105
+ req.end();
11106
+ };
11107
+
11108
+ var bufferResponse = function (stream, cb) {
11109
+ var data = '';
11110
+ stream.on('error', cb);
11111
+ stream.setEncoding('utf8');
11112
+ stream.on('data', function (d) {
11113
+ data += d;
11114
+ });
11115
+ stream.on('end', function () {
11116
+ return cb(null, data);
11117
+ });
11118
+ };
11119
+
11120
+ var _$delivery_33 = function (client) {
11121
+ return {
11122
+ sendEvent: function (event, cb) {
11123
+ if (cb === void 0) {
11124
+ cb = function () {};
11125
+ }
11126
+
11127
+ var body = _$jsonPayload_20.event(event, client._config.redactedKeys);
11128
+
11129
+ var _cb = function (err) {
11130
+ if (err) client._logger.error("Event failed to send\u2026\n" + (err && err.stack ? err.stack : err), err);
11131
+
11132
+ if (body.length > 10e5) {
11133
+ client._logger.warn("Event oversized (" + (body.length / 10e5).toFixed(2) + " MB)");
11134
+ }
11135
+
11136
+ cb(err);
11137
+ };
11138
+
11139
+ try {
11140
+ _$request_34({
11141
+ url: client._config.endpoints.notify,
11142
+ headers: {
11143
+ 'Content-Type': 'application/json',
11144
+ 'Bugsnag-Api-Key': event.apiKey || client._config.apiKey,
11145
+ 'Bugsnag-Payload-Version': '4',
11146
+ 'Bugsnag-Sent-At': new Date().toISOString()
11147
+ },
11148
+ body: body,
11149
+ agent: client._config.agent
11150
+ }, function (err, body) {
11151
+ return _cb(err);
11152
+ });
11153
+ } catch (e) {
11154
+ _cb(e);
11155
+ }
11156
+ },
11157
+ sendSession: function (session, cb) {
11158
+ if (cb === void 0) {
11159
+ cb = function () {};
11160
+ }
11161
+
11162
+ var _cb = function (err) {
11163
+ if (err) client._logger.error("Session failed to send\u2026\n" + (err && err.stack ? err.stack : err), err);
11164
+ cb(err);
11165
+ };
11166
+
11167
+ try {
11168
+ _$request_34({
11169
+ url: client._config.endpoints.sessions,
11170
+ headers: {
11171
+ 'Content-Type': 'application/json',
11172
+ 'Bugsnag-Api-Key': client._config.apiKey,
11173
+ 'Bugsnag-Payload-Version': '1',
11174
+ 'Bugsnag-Sent-At': new Date().toISOString()
11175
+ },
11176
+ body: _$jsonPayload_20.session(session, client._config.redactedKeys),
11177
+ agent: client._config.agent
11178
+ }, function (err) {
11179
+ return _cb(err);
11180
+ });
11181
+ } catch (e) {
11182
+ _cb(e);
11183
+ }
11184
+ }
11185
+ };
11186
+ };
11187
+
11188
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
11189
+
11190
+ var schema = _$config_3.schema;
11191
+
11192
+ var __os_35 = os__default['default'];
11193
+
11194
+ var _require2 = util__default['default'],
11195
+ inspect = _require2.inspect;
11196
+
11197
+ var _$config_35 = {
11198
+ appType: _extends({}, schema.appType, {
11199
+ defaultValue: function () {
11200
+ return 'node';
11201
+ }
11202
+ }),
11203
+ projectRoot: {
11204
+ defaultValue: function () {
11205
+ return process.cwd();
11206
+ },
11207
+ validate: function (value) {
11208
+ return value === null || _$stringWithLength_27(value);
11209
+ },
11210
+ message: 'should be string'
11211
+ },
11212
+ hostname: {
11213
+ defaultValue: function () {
11214
+ return __os_35.hostname();
11215
+ },
11216
+ message: 'should be a string',
11217
+ validate: function (value) {
11218
+ return value === null || _$stringWithLength_27(value);
11219
+ }
11220
+ },
11221
+ logger: _extends({}, schema.logger, {
11222
+ defaultValue: function () {
11223
+ return getPrefixedConsole();
11224
+ }
11225
+ }),
11226
+ releaseStage: _extends({}, schema.releaseStage, {
11227
+ defaultValue: function () {
11228
+ return process.env.NODE_ENV || 'production';
11229
+ }
11230
+ }),
11231
+ agent: {
11232
+ defaultValue: function () {
11233
+ return undefined;
11234
+ },
11235
+ message: 'should be an HTTP(s) agent',
11236
+ validate: function (value) {
11237
+ return value === undefined || isAgent(value);
11238
+ }
11239
+ },
11240
+ onUncaughtException: {
11241
+ defaultValue: function () {
11242
+ return function (err, event, logger) {
11243
+ logger.error("Uncaught exception" + getContext(event) + ", the process will now terminate\u2026\n" + printError(err));
11244
+ process.exit(1);
11245
+ };
11246
+ },
11247
+ message: 'should be a function',
11248
+ validate: function (value) {
11249
+ return typeof value === 'function';
11250
+ }
11251
+ },
11252
+ onUnhandledRejection: {
11253
+ defaultValue: function () {
11254
+ return function (err, event, logger) {
11255
+ logger.error("Unhandled rejection" + getContext(event) + "\u2026\n" + printError(err));
11256
+ };
11257
+ },
11258
+ message: 'should be a function',
11259
+ validate: function (value) {
11260
+ return typeof value === 'function';
11261
+ }
11262
+ }
11263
+ };
11264
+
11265
+ var printError = function (err) {
11266
+ return err && err.stack ? err.stack : inspect(err);
11267
+ };
11268
+
11269
+ var getPrefixedConsole = function () {
11270
+ return ['debug', 'info', 'warn', 'error'].reduce(function (accum, method) {
11271
+ var consoleMethod = console[method] || console.log;
11272
+ accum[method] = consoleMethod.bind(console, '[bugsnag]');
11273
+ return accum;
11274
+ }, {});
11275
+ };
11276
+
11277
+ var getContext = function (event) {
11278
+ return event.request && Object.keys(event.request).length ? " at " + event.request.httpMethod + " " + (event.request.path || event.request.url) : '';
11279
+ };
11280
+
11281
+ var isAgent = function (value) {
11282
+ return typeof value === 'object' && value !== null || typeof value === 'boolean';
11283
+ };
11284
+
11285
+ var appStart = new Date();
11286
+
11287
+ var reset = function () {
11288
+ appStart = new Date();
11289
+ };
11290
+
11291
+ var _$app_37 = {
11292
+ name: 'appDuration',
11293
+ load: function (client) {
11294
+ client.addOnError(function (event) {
11295
+ var now = new Date();
11296
+ event.app.duration = now - appStart;
11297
+ }, true);
11298
+ return {
11299
+ reset: reset
11300
+ };
11301
+ }
11302
+ };
11303
+
11304
+ var _$nodeFallbackStack_22 = {};
11305
+ // The utilities in this file are used to save the stackframes from a known execution context
11306
+ // to use when a subsequent error has no stack frames. This happens with a lot of
11307
+ // node's builtin async callbacks when they return from the native layer with no context
11308
+ // for example:
11309
+ //
11310
+ // fs.readFile('does not exist', (err) => {
11311
+ // /* node 8 */
11312
+ // err.stack = "ENOENT: no such file or directory, open 'nope'"
11313
+ // /* node 4,6 */
11314
+ // err.stack = "Error: ENOENT: no such file or directory, open 'nope'\n at Error (native)"
11315
+ // })
11316
+ // Gets the stack string for the current execution context
11317
+ _$nodeFallbackStack_22.getStack = function () {
11318
+ // slice(3) removes the first line + this function's frame + the caller's frame,
11319
+ // so the stack begins with the caller of this function
11320
+ return new Error().stack.split('\n').slice(3).join('\n');
11321
+ }; // Given an Error and a fallbackStack from getStack(), use the fallbackStack
11322
+ // if error.stack has no genuine stackframes (according to the example above)
11323
+
11324
+
11325
+ _$nodeFallbackStack_22.maybeUseFallbackStack = function (err, fallbackStack) {
11326
+ var lines = err.stack.split('\n');
11327
+
11328
+ if (lines.length === 1 || lines.length === 2 && /at Error \(native\)/.test(lines[1])) {
11329
+ err.stack = lines[0] + "\n" + fallbackStack;
11330
+ }
11331
+
11332
+ return err;
11333
+ };
11334
+
11335
+ var _$contextualize_38 = {};
11336
+ /* eslint node/no-deprecated-api: [error, {ignoreModuleItems: ["domain"]}] */
11337
+ var domain = domain__default['default'];
11338
+
11339
+ var getStack = _$nodeFallbackStack_22.getStack,
11340
+ maybeUseFallbackStack = _$nodeFallbackStack_22.maybeUseFallbackStack;
11341
+
11342
+ _$contextualize_38 = {
11343
+ name: 'contextualize',
11344
+ load: function (client) {
11345
+ var contextualize = function (fn, onError) {
11346
+ // capture a stacktrace in case a resulting error has nothing
11347
+ var fallbackStack = getStack();
11348
+ var dom = domain.create();
11349
+ dom.on('error', function (err) {
11350
+ // check if the stacktrace has no context, if so, if so append the frames we created earlier
11351
+ if (err.stack) maybeUseFallbackStack(err, fallbackStack);
11352
+ var event = client.Event.create(err, true, {
11353
+ severity: 'error',
11354
+ unhandled: true,
11355
+ severityReason: {
11356
+ type: 'unhandledException'
11357
+ }
11358
+ }, 'contextualize()', 1);
11359
+
11360
+ client._notify(event, onError, function (e, event) {
11361
+ if (e) client._logger.error('Failed to send event to Bugsnag');
11362
+
11363
+ client._config.onUncaughtException(err, event, client._logger);
11364
+ });
11365
+ });
11366
+ process.nextTick(function () {
11367
+ return dom.run(fn);
11368
+ });
11369
+ };
11370
+
11371
+ return contextualize;
11372
+ }
11373
+ }; // add a default export for ESM modules without interop
11374
+
11375
+ _$contextualize_38["default"] = _$contextualize_38;
11376
+
11377
+ var _$intercept_39 = {};
11378
+ var __getStack_39 = _$nodeFallbackStack_22.getStack,
11379
+ __maybeUseFallbackStack_39 = _$nodeFallbackStack_22.maybeUseFallbackStack;
11380
+
11381
+ _$intercept_39 = {
11382
+ name: 'intercept',
11383
+ load: function (client) {
11384
+ var intercept = function (onError, cb) {
11385
+ if (onError === void 0) {
11386
+ onError = function () {};
11387
+ }
11388
+
11389
+ if (typeof cb !== 'function') {
11390
+ cb = onError;
11391
+
11392
+ onError = function () {};
11393
+ } // capture a stacktrace in case a resulting error has nothing
11394
+
11395
+
11396
+ var fallbackStack = __getStack_39();
11397
+ return function (err) {
11398
+ if (err) {
11399
+ // check if the stacktrace has no context, if so, if so append the frames we created earlier
11400
+ if (err.stack) __maybeUseFallbackStack_39(err, fallbackStack);
11401
+ var event = client.Event.create(err, true, {
11402
+ severity: 'warning',
11403
+ unhandled: false,
11404
+ severityReason: {
11405
+ type: 'callbackErrorIntercept'
11406
+ }
11407
+ }, 'intercept()', 1);
11408
+
11409
+ client._notify(event, onError);
11410
+
11411
+ return;
11412
+ }
11413
+
11414
+ for (var _len = arguments.length, data = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
11415
+ data[_key - 1] = arguments[_key];
11416
+ }
11417
+
11418
+ cb.apply(void 0, data); // eslint-disable-line
11419
+ };
11420
+ };
11421
+
11422
+ return intercept;
11423
+ }
11424
+ }; // add a default export for ESM modules without interop
11425
+
11426
+ _$intercept_39["default"] = _$intercept_39;
11427
+
11428
+ function ___extends_40() { ___extends_40 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return ___extends_40.apply(this, arguments); }
11429
+
11430
+ var __os_40 = os__default['default'];
11431
+ /*
11432
+ * Automatically detects Node server details ('device' in the API)
11433
+ */
11434
+
11435
+
11436
+ var _$device_40 = {
11437
+ load: function (client) {
11438
+ var device = {
11439
+ osName: __os_40.platform() + " (" + __os_40.arch() + ")",
11440
+ osVersion: __os_40.release(),
11441
+ totalMemory: __os_40.totalmem(),
11442
+ hostname: client._config.hostname,
11443
+ runtimeVersions: {
11444
+ node: process.versions.node
11445
+ }
11446
+ };
11447
+
11448
+ client._addOnSessionPayload(function (sp) {
11449
+ sp.device = ___extends_40({}, sp.device, device);
11450
+ }); // add time just as the event is sent
11451
+
11452
+
11453
+ client.addOnError(function (event) {
11454
+ event.device = ___extends_40({}, event.device, device, {
11455
+ freeMemory: __os_40.freemem(),
11456
+ time: new Date()
11457
+ });
11458
+ }, true);
11459
+ }
11460
+ };
11461
+
11462
+ var ___require_23 = path__default['default'],
11463
+ join = ___require_23.join,
11464
+ resolve = ___require_23.resolve; // normalise a path to a directory, adding a trailing slash if it doesn't already
11465
+ // have one and resolve it to make it absolute (e.g. get rid of any ".."s)
11466
+
11467
+
11468
+ var _$pathNormalizer_23 = function (p) {
11469
+ return join(resolve(p), '/');
11470
+ };
11471
+
11472
+ var _$inProject_41 = {
11473
+ load: function (client) {
11474
+ return client.addOnError(function (event) {
11475
+ if (!client._config.projectRoot) return;
11476
+ var projectRoot = _$pathNormalizer_23(client._config.projectRoot);
11477
+ var allFrames = event.errors.reduce(function (accum, er) {
11478
+ return accum.concat(er.stacktrace);
11479
+ }, []);
11480
+ allFrames.map(function (stackframe) {
11481
+ stackframe.inProject = typeof stackframe.file === 'string' && stackframe.file.indexOf(projectRoot) === 0 && !/\/node_modules\//.test(stackframe.file);
11482
+ });
11483
+ });
11484
+ }
11485
+ };
11486
+
11487
+ function ___extends_42() { ___extends_42 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return ___extends_42.apply(this, arguments); }
11488
+
11489
+ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
11490
+
11491
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11492
+
11493
+ var SURROUNDING_LINES = 3;
11494
+ var MAX_LINE_LENGTH = 200;
11495
+
11496
+ var ___require_42 = fs__default['default'],
11497
+ createReadStream = ___require_42.createReadStream;
11498
+
11499
+ var ___require2_42 = stream__default['default'],
11500
+ Writable = ___require2_42.Writable;
11501
+
11502
+ var pump = pump_1;
11503
+
11504
+ var byline$1 = byline;
11505
+
11506
+ var path = path__default['default'];
11507
+
11508
+ var _$surroundingCode_42 = {
11509
+ load: function (client) {
11510
+ if (!client._config.sendCode) return;
11511
+
11512
+ var loadSurroundingCode = function (stackframe, cache) {
11513
+ return new Promise(function (resolve, reject) {
11514
+ try {
11515
+ if (!stackframe.lineNumber || !stackframe.file) return resolve(stackframe);
11516
+ var file = path.resolve(client._config.projectRoot, stackframe.file);
11517
+ var cacheKey = file + "@" + stackframe.lineNumber;
11518
+
11519
+ if (cacheKey in cache) {
11520
+ stackframe.code = cache[cacheKey];
11521
+ return resolve(stackframe);
11522
+ }
11523
+
11524
+ getSurroundingCode(file, stackframe.lineNumber, function (err, code) {
11525
+ if (err) return resolve(stackframe);
11526
+ stackframe.code = cache[cacheKey] = code;
11527
+ return resolve(stackframe);
11528
+ });
11529
+ } catch (e) {
11530
+ return resolve(stackframe);
11531
+ }
11532
+ });
11533
+ };
11534
+
11535
+ client.addOnError(function (event) {
11536
+ return new Promise(function (resolve, reject) {
11537
+ var cache = Object.create(null);
11538
+ var allFrames = event.errors.reduce(function (accum, er) {
11539
+ return accum.concat(er.stacktrace);
11540
+ }, []);
11541
+ pMapSeries(allFrames.map(function (stackframe) {
11542
+ return function () {
11543
+ return loadSurroundingCode(stackframe, cache);
11544
+ };
11545
+ })).then(resolve)["catch"](reject);
11546
+ });
11547
+ });
11548
+ },
11549
+ configSchema: {
11550
+ sendCode: {
11551
+ defaultValue: function () {
11552
+ return true;
11553
+ },
11554
+ validate: function (value) {
11555
+ return value === true || value === false;
11556
+ },
11557
+ message: 'should be true or false'
11558
+ }
11559
+ }
11560
+ };
11561
+
11562
+ var getSurroundingCode = function (file, lineNumber, cb) {
11563
+ var start = lineNumber - SURROUNDING_LINES;
11564
+ var end = lineNumber + SURROUNDING_LINES;
11565
+ var reader = createReadStream(file, {
11566
+ encoding: 'utf8'
11567
+ });
11568
+ var splitter = new byline$1.LineStream({
11569
+ keepEmptyLines: true
11570
+ });
11571
+ var slicer = new CodeRange({
11572
+ start: start,
11573
+ end: end
11574
+ }); // if the slicer has enough lines already, no need to keep reading from the file
11575
+
11576
+ slicer.on('done', function () {
11577
+ return reader.destroy();
11578
+ });
11579
+ pump(reader, splitter, slicer, function (err) {
11580
+ // reader.destroy() causes a "premature close" error which we can tolerate
11581
+ if (err && err.message !== 'premature close') return cb(err);
11582
+ cb(null, slicer.getCode());
11583
+ });
11584
+ }; // This writable stream takes { start, end } options specifying the
11585
+ // range of lines that should be extracted from a file. Pipe a readable
11586
+ // stream to it that provides source lines as each chunk. If the range
11587
+ // is satisfied before the end of the readable stream, it will emit the
11588
+ // 'done' event. Once a 'done' or 'finish' event has been seen, call getCode()
11589
+ // to get the range in the following format:
11590
+ // {
11591
+ // '10': 'function getSquare (cb) {',
11592
+ // '11': ' rectangles.find({',
11593
+ // '12': ' length: 12',
11594
+ // '13': ' width: 12',
11595
+ // '14': ' }, err => cb)',
11596
+ // '15': '}'
11597
+ // }
11598
+
11599
+
11600
+ var CodeRange = /*#__PURE__*/function (_Writable) {
11601
+ _inheritsLoose(CodeRange, _Writable);
11602
+
11603
+ function CodeRange(opts) {
11604
+ var _this;
11605
+
11606
+ _this = _Writable.call(this, ___extends_42({}, opts, {
11607
+ decodeStrings: false
11608
+ })) || this;
11609
+ _this._start = opts.start;
11610
+ _this._end = opts.end;
11611
+ _this._n = 0;
11612
+ _this._code = {};
11613
+ return _this;
11614
+ }
11615
+
11616
+ var _proto = CodeRange.prototype;
11617
+
11618
+ _proto._write = function _write(chunk, enc, cb) {
11619
+ this._n++;
11620
+ if (this._n < this._start) return cb(null);
11621
+
11622
+ if (this._n <= this._end) {
11623
+ this._code[String(this._n)] = chunk.length <= MAX_LINE_LENGTH ? chunk : chunk.substr(0, MAX_LINE_LENGTH);
11624
+ return cb(null);
11625
+ }
11626
+
11627
+ this.emit('done');
11628
+ return cb(null);
11629
+ };
11630
+
11631
+ _proto.getCode = function getCode() {
11632
+ return this._code;
11633
+ };
11634
+
11635
+ return CodeRange;
11636
+ }(Writable);
11637
+
11638
+ var pMapSeries = function (ps) {
11639
+ return new Promise(function (resolve, reject) {
11640
+ var res = [];
11641
+ ps.reduce(function (accum, p) {
11642
+ return accum.then(function (r) {
11643
+ res.push(r);
11644
+ return p();
11645
+ });
11646
+ }, Promise.resolve()).then(function (r) {
11647
+ res.push(r);
11648
+ }).then(function () {
11649
+ resolve(res.slice(1));
11650
+ });
11651
+ });
11652
+ };
11653
+
11654
+ var _handler;
11655
+
11656
+ var _$uncaughtException_43 = {
11657
+ load: function (client) {
11658
+ if (!client._config.autoDetectErrors) return;
11659
+ if (!client._config.enabledErrorTypes.unhandledExceptions) return;
11660
+
11661
+ _handler = function (err) {
11662
+ var event = client.Event.create(err, false, {
11663
+ severity: 'error',
11664
+ unhandled: true,
11665
+ severityReason: {
11666
+ type: 'unhandledException'
11667
+ }
11668
+ }, 'uncaughtException handler', 1);
11669
+
11670
+ client._notify(event, function () {}, function (e, event) {
11671
+ if (e) client._logger.error('Failed to send event to Bugsnag');
11672
+
11673
+ client._config.onUncaughtException(err, event, client._logger);
11674
+ });
11675
+ };
11676
+
11677
+ process.on('uncaughtException', _handler);
11678
+ },
11679
+ destroy: function () {
11680
+ process.removeListener('uncaughtException', _handler);
11681
+ }
11682
+ };
11683
+
11684
+ var ___handler_44;
11685
+
11686
+ var _$unhandledRejection_44 = {
11687
+ load: function (client) {
11688
+ if (!client._config.autoDetectErrors || !client._config.enabledErrorTypes.unhandledRejections) return;
11689
+
11690
+ ___handler_44 = function (err) {
11691
+ var event = client.Event.create(err, false, {
11692
+ severity: 'error',
11693
+ unhandled: true,
11694
+ severityReason: {
11695
+ type: 'unhandledPromiseRejection'
11696
+ }
11697
+ }, 'unhandledRejection handler', 1);
11698
+ return new Promise(function (resolve) {
11699
+ client._notify(event, function () {}, function (e, event) {
11700
+ if (e) client._logger.error('Failed to send event to Bugsnag');
11701
+
11702
+ client._config.onUnhandledRejection(err, event, client._logger);
11703
+
11704
+ resolve();
11705
+ });
11706
+ });
11707
+ }; // Prepend the listener if we can (Node 6+)
11708
+
11709
+
11710
+ if (process.prependListener) {
11711
+ process.prependListener('unhandledRejection', ___handler_44);
11712
+ } else {
11713
+ process.on('unhandledRejection', ___handler_44);
11714
+ }
11715
+ },
11716
+ destroy: function () {
11717
+ process.removeListener('unhandledRejection', ___handler_44);
11718
+ }
11719
+ };
11720
+
11721
+ var _$cloneClient_8 = {};
11722
+
11723
+ var onCloneCallbacks = [];
11724
+
11725
+ _$cloneClient_8 = function (client) {
11726
+ var clone = new client.Client({}, {}, [], client._notifier);
11727
+ clone._config = client._config; // changes to these properties should not be reflected in the original client,
11728
+ // so ensure they are are (shallow) cloned
11729
+
11730
+ clone._breadcrumbs = client._breadcrumbs.slice();
11731
+ clone._metadata = _$assign_10({}, client._metadata);
11732
+ clone._features = [].concat(client._features);
11733
+ clone._featuresIndex = _$assign_10({}, client._featuresIndex);
11734
+ clone._user = _$assign_10({}, client._user);
11735
+ clone._context = client._context;
11736
+ clone._cbs = {
11737
+ e: client._cbs.e.slice(),
11738
+ s: client._cbs.s.slice(),
11739
+ sp: client._cbs.sp.slice(),
11740
+ b: client._cbs.b.slice()
11741
+ };
11742
+ clone._logger = client._logger;
11743
+ clone._delivery = client._delivery;
11744
+ clone._sessionDelegate = client._sessionDelegate;
11745
+ onCloneCallbacks.forEach(function (callback) {
11746
+ callback(clone);
11747
+ });
11748
+ return clone;
11749
+ };
11750
+
11751
+ _$cloneClient_8.registerCallback = function (callback) {
11752
+ onCloneCallbacks.push(callback);
11753
+ };
11754
+
11755
+ /**
11756
+ * Expose `Backoff`.
11757
+ */
11758
+ var _$Backoff_45 = Backoff;
11759
+ /**
11760
+ * Initialize backoff timer with `opts`.
11761
+ *
11762
+ * - `min` initial timeout in milliseconds [100]
11763
+ * - `max` max timeout [10000]
11764
+ * - `jitter` [0]
11765
+ * - `factor` [2]
11766
+ *
11767
+ * @param {Object} opts
11768
+ * @api public
11769
+ */
11770
+
11771
+ function Backoff(opts) {
11772
+ opts = opts || {};
11773
+ this.ms = opts.min || 100;
11774
+ this.max = opts.max || 10000;
11775
+ this.factor = opts.factor || 2;
11776
+ this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
11777
+ this.attempts = 0;
11778
+ }
11779
+ /**
11780
+ * Return the backoff duration.
11781
+ *
11782
+ * @return {Number}
11783
+ * @api public
11784
+ */
11785
+
11786
+
11787
+ Backoff.prototype.duration = function () {
11788
+ var ms = this.ms * Math.pow(this.factor, this.attempts++);
11789
+
11790
+ if (this.jitter) {
11791
+ var rand = Math.random();
11792
+ var deviation = Math.floor(rand * this.jitter * ms);
11793
+ ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
11794
+ }
11795
+
11796
+ return Math.min(ms, this.max) | 0;
11797
+ };
11798
+ /**
11799
+ * Reset the number of attempts.
11800
+ *
11801
+ * @api public
11802
+ */
11803
+
11804
+
11805
+ Backoff.prototype.reset = function () {
11806
+ this.attempts = 0;
11807
+ };
11808
+
11809
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
11810
+
11811
+ function ___inheritsLoose_47(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; ___setPrototypeOf_47(subClass, superClass); }
11812
+
11813
+ function ___setPrototypeOf_47(o, p) { ___setPrototypeOf_47 = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return ___setPrototypeOf_47(o, p); }
11814
+
11815
+ var DEFAULT_SUMMARY_INTERVAL = 10 * 1000;
11816
+
11817
+ var Emitter = events__default['default'].EventEmitter;
11818
+
11819
+ var _$tracker_47 = /*#__PURE__*/function (_Emitter) {
11820
+ ___inheritsLoose_47(SessionTracker, _Emitter);
11821
+
11822
+ function SessionTracker(intervalLength) {
11823
+ var _this;
11824
+
11825
+ _this = _Emitter.call(this) || this;
11826
+ _this._sessions = new Map();
11827
+ _this._interval = null;
11828
+ _this._intervalLength = intervalLength || DEFAULT_SUMMARY_INTERVAL;
11829
+ _this._summarize = _this._summarize.bind(_assertThisInitialized(_this));
11830
+ return _this;
11831
+ }
11832
+
11833
+ var _proto = SessionTracker.prototype;
11834
+
11835
+ _proto.start = function start() {
11836
+ if (!this._interval) {
11837
+ this._interval = setInterval(this._summarize, this._intervalLength).unref();
11838
+ }
11839
+ };
11840
+
11841
+ _proto.stop = function stop() {
11842
+ clearInterval(this._interval);
11843
+ this._interval = null;
11844
+ };
11845
+
11846
+ _proto.track = function track(session) {
11847
+ var key = dateToMsKey(session.startedAt);
11848
+
11849
+ var cur = this._sessions.get(key);
11850
+
11851
+ this._sessions.set(key, typeof cur === 'undefined' ? 1 : cur + 1);
11852
+
11853
+ return session;
11854
+ };
11855
+
11856
+ _proto._summarize = function _summarize() {
11857
+ var _this2 = this;
11858
+
11859
+ var summary = [];
11860
+
11861
+ this._sessions.forEach(function (val, key) {
11862
+ summary.push({
11863
+ startedAt: key,
11864
+ sessionsStarted: val
11865
+ });
11866
+
11867
+ _this2._sessions["delete"](key);
11868
+ });
11869
+
11870
+ if (!summary.length) return;
11871
+ this.emit('summary', summary);
11872
+ };
11873
+
11874
+ return SessionTracker;
11875
+ }(Emitter);
11876
+
11877
+ var dateToMsKey = function (d) {
11878
+ var dk = new Date(d);
11879
+ dk.setSeconds(0);
11880
+ dk.setMilliseconds(0);
11881
+ return dk.toISOString();
11882
+ };
11883
+
11884
+ var _$session_46 = {
11885
+ load: function (client) {
11886
+ var sessionTracker = new _$tracker_47(client._config.sessionSummaryInterval);
11887
+ sessionTracker.on('summary', sendSessionSummary(client));
11888
+ sessionTracker.start();
11889
+ client._sessionDelegate = {
11890
+ startSession: function (client, session) {
11891
+ var sessionClient = _$cloneClient_8(client);
11892
+ sessionClient._session = session;
11893
+ sessionClient._pausedSession = null;
11894
+ sessionTracker.track(sessionClient._session);
11895
+ return sessionClient;
11896
+ },
11897
+ pauseSession: function (client) {
11898
+ client._pausedSession = client._session;
11899
+ client._session = null;
11900
+ },
11901
+ resumeSession: function (client) {
11902
+ // Do nothing if there's already an active session
11903
+ if (client._session) {
11904
+ return client;
11905
+ } // If we have a paused session then make it the active session
11906
+
11907
+
11908
+ if (client._pausedSession) {
11909
+ client._session = client._pausedSession;
11910
+ client._pausedSession = null;
11911
+ return client;
11912
+ } // Otherwise start a new session
11913
+
11914
+
11915
+ return client.startSession();
11916
+ }
11917
+ };
11918
+ },
11919
+ configSchema: {
11920
+ sessionSummaryInterval: {
11921
+ defaultValue: function () {
11922
+ return undefined;
11923
+ },
11924
+ validate: function (value) {
11925
+ return value === undefined || _$intRange_25()(value);
11926
+ },
11927
+ message: 'should be a positive integer'
11928
+ }
11929
+ }
11930
+ };
11931
+
11932
+ var sendSessionSummary = function (client) {
11933
+ return function (sessionCounts) {
11934
+ // exit early if the current releaseStage is not enabled
11935
+ if (client._config.enabledReleaseStages !== null && !client._config.enabledReleaseStages.includes(client._config.releaseStage)) {
11936
+ client._logger.warn('Session not sent due to releaseStage/enabledReleaseStages configuration');
11937
+
11938
+ return;
11939
+ }
11940
+
11941
+ if (!sessionCounts.length) return;
11942
+ var backoff = new _$Backoff_45({
11943
+ min: 1000,
11944
+ max: 10000
11945
+ });
11946
+ var maxAttempts = 10;
11947
+ req(handleRes);
11948
+
11949
+ function handleRes(err) {
11950
+ if (!err) {
11951
+ var sessionCount = sessionCounts.reduce(function (accum, s) {
11952
+ return accum + s.sessionsStarted;
11953
+ }, 0);
11954
+ return client._logger.debug(sessionCount + " session(s) reported");
11955
+ }
11956
+
11957
+ if (backoff.attempts === 10) {
11958
+ client._logger.error('Session delivery failed, max retries exceeded', err);
11959
+
11960
+ return;
11961
+ }
11962
+
11963
+ client._logger.debug('Session delivery failed, retry #' + (backoff.attempts + 1) + '/' + maxAttempts, err);
11964
+
11965
+ setTimeout(function () {
11966
+ return req(handleRes);
11967
+ }, backoff.duration());
11968
+ }
11969
+
11970
+ function req(cb) {
11971
+ var payload = {
11972
+ notifier: client._notifier,
11973
+ device: {},
11974
+ app: {
11975
+ releaseStage: client._config.releaseStage,
11976
+ version: client._config.appVersion,
11977
+ type: client._config.appType
11978
+ },
11979
+ sessionCounts: sessionCounts
11980
+ };
11981
+ var ignore = _$syncCallbackRunner_24(client._cbs.sp, payload, 'onSessionPayload', client._logger);
11982
+
11983
+ if (ignore) {
11984
+ client._logger.debug('Session not sent due to onSessionPayload callback');
11985
+
11986
+ return cb(null);
11987
+ }
11988
+
11989
+ client._delivery.sendSession(payload, cb);
11990
+ }
11991
+ };
11992
+ };
11993
+
11994
+ var _$pathNormaliser_48 = {
11995
+ load: function (client) {
11996
+ client.addOnError(function (event) {
11997
+ var allFrames = event.errors.reduce(function (accum, er) {
11998
+ return accum.concat(er.stacktrace);
11999
+ }, []);
12000
+ allFrames.forEach(function (stackframe) {
12001
+ if (typeof stackframe.file !== 'string') {
12002
+ return;
12003
+ }
12004
+
12005
+ stackframe.file = stackframe.file.replace(/\\/g, '/');
12006
+ });
12007
+ });
12008
+ }
12009
+ };
12010
+
12011
+ var _$stripProjectRoot_49 = {
12012
+ load: function (client) {
12013
+ return client.addOnError(function (event) {
12014
+ if (!client._config.projectRoot) return;
12015
+ var projectRoot = _$pathNormalizer_23(client._config.projectRoot);
12016
+ var allFrames = event.errors.reduce(function (accum, er) {
12017
+ return accum.concat(er.stacktrace);
12018
+ }, []);
12019
+ allFrames.map(function (stackframe) {
12020
+ if (typeof stackframe.file === 'string' && stackframe.file.indexOf(projectRoot) === 0) {
12021
+ stackframe.file = stackframe.file.replace(projectRoot, '');
12022
+ }
12023
+ });
12024
+ });
12025
+ }
12026
+ };
12027
+
12028
+ var _$notifier_36 = {};
12029
+ function ___extends_36() { ___extends_36 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return ___extends_36.apply(this, arguments); }
12030
+
12031
+ var name = 'Bugsnag Node';
12032
+ var version = '7.18.0';
12033
+ var url = 'https://github.com/bugsnag/bugsnag-js';
12034
+
12035
+ _$Event_4.__type = 'nodejs';
12036
+
12037
+
12038
+ var __schema_36 = ___extends_36({}, _$config_3.schema, _$config_35); // remove enabledBreadcrumbTypes from the config schema
12039
+
12040
+
12041
+ delete __schema_36.enabledBreadcrumbTypes;
12042
+
12043
+ var internalPlugins = [_$app_37, _$surroundingCode_42, _$inProject_41, _$stripProjectRoot_49, _$session_46, _$device_40, _$uncaughtException_43, _$unhandledRejection_44, _$intercept_39, _$contextualize_38, _$pathNormaliser_48];
12044
+ var Bugsnag = {
12045
+ _client: null,
12046
+ createClient: function (opts) {
12047
+ // handle very simple use case where user supplies just the api key as a string
12048
+ if (typeof opts === 'string') opts = {
12049
+ apiKey: opts
12050
+ };
12051
+ if (!opts) opts = {};
12052
+ var bugsnag = new _$Client_2(opts, __schema_36, internalPlugins, {
12053
+ name: name,
12054
+ version: version,
12055
+ url: url
12056
+ });
12057
+
12058
+ bugsnag._setDelivery(_$delivery_33);
12059
+
12060
+ bugsnag._logger.debug('Loaded!');
12061
+
12062
+ bugsnag.leaveBreadcrumb = function () {
12063
+ bugsnag._logger.warn('Breadcrumbs are not supported in Node.js yet');
12064
+ };
12065
+
12066
+ bugsnag._config.enabledBreadcrumbTypes = [];
12067
+ return bugsnag;
12068
+ },
12069
+ start: function (opts) {
12070
+ if (Bugsnag._client) {
12071
+ Bugsnag._client._logger.warn('Bugsnag.start() was called more than once. Ignoring.');
12072
+
12073
+ return Bugsnag._client;
12074
+ }
12075
+
12076
+ Bugsnag._client = Bugsnag.createClient(opts);
12077
+ return Bugsnag._client;
12078
+ },
12079
+ isStarted: function () {
12080
+ return Bugsnag._client != null;
12081
+ }
12082
+ };
12083
+ Object.keys(_$Client_2.prototype).forEach(function (m) {
12084
+ if (/^_/.test(m)) return;
12085
+
12086
+ Bugsnag[m] = function () {
12087
+ if (!Bugsnag._client) return console.error("Bugsnag." + m + "() was called before Bugsnag.start()");
12088
+ Bugsnag._client._depth += 1;
12089
+
12090
+ var ret = Bugsnag._client[m].apply(Bugsnag._client, arguments);
12091
+
12092
+ Bugsnag._client._depth -= 1;
12093
+ return ret;
12094
+ };
12095
+ });
12096
+ _$notifier_36 = Bugsnag;
12097
+ _$notifier_36.Client = _$Client_2;
12098
+ _$notifier_36.Event = _$Event_4;
12099
+ _$notifier_36.Session = _$Session_32;
12100
+ _$notifier_36.Breadcrumb = _$Breadcrumb_1; // Export a "default" property for compatibility with ESM imports
12101
+
12102
+ _$notifier_36["default"] = Bugsnag;
12103
+
12104
+ return _$notifier_36;
12105
+
12106
+ });
12107
+
12108
+ });
12109
+
12110
+ var notifier = bugsnag;
12111
+
8594
12112
  /**
8595
12113
  * List of zero-decimal currencies.
8596
12114
  * @see https://stripe.com/docs/currencies#zero-decimal
@@ -8905,6 +12423,18 @@ function userMustVerifyEmail() {
8905
12423
  const isUserEmailVerified = (_window$Pelcro$user$r9 = (_window$Pelcro$user$r10 = window.Pelcro.user.read()) === null || _window$Pelcro$user$r10 === void 0 ? void 0 : _window$Pelcro$user$r10.email_confirm) !== null && _window$Pelcro$user$r9 !== void 0 ? _window$Pelcro$user$r9 : false;
8906
12424
  return window.Pelcro.user.isAuthenticated() && isEmailVerificationEnabled && !isUserEmailVerified;
8907
12425
  }
12426
+ function notifyBugsnag() {
12427
+ let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Error';
12428
+ notifier.notify(message, event => {
12429
+ var _window$Pelcro3, _window$Pelcro3$site, _window$Pelcro4, _window$Pelcro4$user, _window$Pelcro5, _window$Pelcro5$uiSet, _window$Pelcro6;
12430
+ event.addMetadata("MetaData", {
12431
+ site: (_window$Pelcro3 = window.Pelcro) === null || _window$Pelcro3 === void 0 ? void 0 : (_window$Pelcro3$site = _window$Pelcro3.site) === null || _window$Pelcro3$site === void 0 ? void 0 : _window$Pelcro3$site.read(),
12432
+ user: (_window$Pelcro4 = window.Pelcro) === null || _window$Pelcro4 === void 0 ? void 0 : (_window$Pelcro4$user = _window$Pelcro4.user) === null || _window$Pelcro4$user === void 0 ? void 0 : _window$Pelcro4$user.read(),
12433
+ uiVersion: (_window$Pelcro5 = window.Pelcro) === null || _window$Pelcro5 === void 0 ? void 0 : (_window$Pelcro5$uiSet = _window$Pelcro5.uiSettings) === null || _window$Pelcro5$uiSet === void 0 ? void 0 : _window$Pelcro5$uiSet.uiVersion,
12434
+ environment: (_window$Pelcro6 = window.Pelcro) === null || _window$Pelcro6 === void 0 ? void 0 : _window$Pelcro6.environment
12435
+ });
12436
+ });
12437
+ }
8908
12438
 
8909
12439
  const resources = {
8910
12440
  en: {
@@ -11140,7 +14670,10 @@ const initSubscriptionFromURL = () => {
11140
14670
  whenSiteReady(() => {
11141
14671
  var _selectedProduct$plan;
11142
14672
  const productsList = window.Pelcro.product.list();
11143
- if (!(productsList !== null && productsList !== void 0 && productsList.length)) return;
14673
+ if (!(productsList !== null && productsList !== void 0 && productsList.length)) {
14674
+ notifyBugsnag("initSubscriptionFromURL - Empty Products List");
14675
+ return;
14676
+ }
11144
14677
  const [productId, planId, isGiftParam] = [window.Pelcro.helpers.getURLParameter("product_id"), window.Pelcro.helpers.getURLParameter("plan_id"), window.Pelcro.helpers.getURLParameter("is_gift")];
11145
14678
  const isGift = (isGiftParam === null || isGiftParam === void 0 ? void 0 : isGiftParam.toLowerCase()) === "true";
11146
14679
  const selectedProduct = productsList.find(product => product.id === Number(productId));