@shopify/cli
Version:
A CLI tool to build for the Shopify platform
1,099 lines (1,091 loc) • 108 kB
JavaScript
import {
require_once
} from "./chunk-SHWOPMLQ.js";
import {
fanoutHooks,
getEnvironmentData,
getLastSeenUserIdAfterAuth,
isLocalEnvironment,
reportAnalyticsEvent
} from "./chunk-SKMKK4HY.js";
import {
runWithRateLimit
} from "./chunk-OIOM46UG.js";
import {
CLI_KIT_VERSION
} from "./chunk-S2JA5KN5.js";
import {
AbortSilentError,
CancelExecution,
bugsnagApiKey,
cleanSingleStackTracePath,
errorMapper,
getAllPublicMetadata,
getAllSensitiveMetadata,
handler,
outputDebug,
outputInfo,
reportingRateLimit,
require_stacktracey,
shouldReportErrorAsUnexpected
} from "./chunk-HJSZAWSQ.js";
import {
require_lib
} from "./chunk-VLBE545G.js";
import {
cwd,
isAbsolutePath,
joinPath,
normalizePath,
relativePath
} from "./chunk-EG6MBBEN.js";
import {
__commonJS,
__require,
__toESM,
init_cjs_shims
} from "./chunk-PKR7KJ6P.js";
// ../../node_modules/.pnpm/stackframe@1.3.4/node_modules/stackframe/stackframe.js
var require_stackframe = __commonJS({
"../../node_modules/.pnpm/stackframe@1.3.4/node_modules/stackframe/stackframe.js"(exports, module) {
init_cjs_shims();
(function(root, factory) {
"use strict";
typeof define == "function" && define.amd ? define("stackframe", [], factory) : typeof exports == "object" ? module.exports = factory() : root.StackFrame = factory();
})(exports, function() {
"use strict";
function _isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function _capitalize(str) {
return str.charAt(0).toUpperCase() + str.substring(1);
}
function _getter(p) {
return function() {
return this[p];
};
}
var booleanProps = ["isConstructor", "isEval", "isNative", "isToplevel"], numericProps = ["columnNumber", "lineNumber"], stringProps = ["fileName", "functionName", "source"], arrayProps = ["args"], objectProps = ["evalOrigin"], props = booleanProps.concat(numericProps, stringProps, arrayProps, objectProps);
function StackFrame(obj) {
if (obj)
for (var i2 = 0; i2 < props.length; i2++)
obj[props[i2]] !== void 0 && this["set" + _capitalize(props[i2])](obj[props[i2]]);
}
StackFrame.prototype = {
getArgs: function() {
return this.args;
},
setArgs: function(v) {
if (Object.prototype.toString.call(v) !== "[object Array]")
throw new TypeError("Args must be an Array");
this.args = v;
},
getEvalOrigin: function() {
return this.evalOrigin;
},
setEvalOrigin: function(v) {
if (v instanceof StackFrame)
this.evalOrigin = v;
else if (v instanceof Object)
this.evalOrigin = new StackFrame(v);
else
throw new TypeError("Eval Origin must be an Object or StackFrame");
},
toString: function() {
var fileName = this.getFileName() || "", lineNumber = this.getLineNumber() || "", columnNumber = this.getColumnNumber() || "", functionName = this.getFunctionName() || "";
return this.getIsEval() ? fileName ? "[eval] (" + fileName + ":" + lineNumber + ":" + columnNumber + ")" : "[eval]:" + lineNumber + ":" + columnNumber : functionName ? functionName + " (" + fileName + ":" + lineNumber + ":" + columnNumber + ")" : fileName + ":" + lineNumber + ":" + columnNumber;
}
}, StackFrame.fromString = function(str) {
var argsStartIndex = str.indexOf("("), argsEndIndex = str.lastIndexOf(")"), functionName = str.substring(0, argsStartIndex), args = str.substring(argsStartIndex + 1, argsEndIndex).split(","), locationString = str.substring(argsEndIndex + 1);
if (locationString.indexOf("@") === 0)
var parts = /@(.+?)(?::(\d+))?(?::(\d+))?$/.exec(locationString, ""), fileName = parts[1], lineNumber = parts[2], columnNumber = parts[3];
return new StackFrame({
functionName,
args: args || void 0,
fileName,
lineNumber: lineNumber || void 0,
columnNumber: columnNumber || void 0
});
};
for (var i = 0; i < booleanProps.length; i++)
StackFrame.prototype["get" + _capitalize(booleanProps[i])] = _getter(booleanProps[i]), StackFrame.prototype["set" + _capitalize(booleanProps[i])] = /* @__PURE__ */ (function(p) {
return function(v) {
this[p] = !!v;
};
})(booleanProps[i]);
for (var j = 0; j < numericProps.length; j++)
StackFrame.prototype["get" + _capitalize(numericProps[j])] = _getter(numericProps[j]), StackFrame.prototype["set" + _capitalize(numericProps[j])] = /* @__PURE__ */ (function(p) {
return function(v) {
if (!_isNumber(v))
throw new TypeError(p + " must be a Number");
this[p] = Number(v);
};
})(numericProps[j]);
for (var k = 0; k < stringProps.length; k++)
StackFrame.prototype["get" + _capitalize(stringProps[k])] = _getter(stringProps[k]), StackFrame.prototype["set" + _capitalize(stringProps[k])] = /* @__PURE__ */ (function(p) {
return function(v) {
this[p] = String(v);
};
})(stringProps[k]);
return StackFrame;
});
}
});
// ../../node_modules/.pnpm/error-stack-parser@2.1.4/node_modules/error-stack-parser/error-stack-parser.js
var require_error_stack_parser = __commonJS({
"../../node_modules/.pnpm/error-stack-parser@2.1.4/node_modules/error-stack-parser/error-stack-parser.js"(exports, module) {
init_cjs_shims();
(function(root, factory) {
"use strict";
typeof define == "function" && define.amd ? define("error-stack-parser", ["stackframe"], factory) : typeof exports == "object" ? module.exports = factory(require_stackframe()) : root.ErrorStackParser = factory(root.StackFrame);
})(exports, function(StackFrame) {
"use strict";
var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+:\d+/, CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m, SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code])?$/;
return {
/**
* Given an Error object, extract the most information from it.
*
* @param {Error} error object
* @return {Array} of StackFrames
*/
parse: function(error) {
if (typeof error.stacktrace < "u" || typeof error["opera#sourceloc"] < "u")
return this.parseOpera(error);
if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP))
return this.parseV8OrIE(error);
if (error.stack)
return this.parseFFOrSafari(error);
throw new Error("Cannot parse given Error object");
},
// Separate line and column numbers from a string of the form: (URI:Line:Column)
extractLocation: function(urlLike) {
if (urlLike.indexOf(":") === -1)
return [urlLike];
var regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/, parts = regExp.exec(urlLike.replace(/[()]/g, ""));
return [parts[1], parts[2] || void 0, parts[3] || void 0];
},
parseV8OrIE: function(error) {
var filtered = error.stack.split(`
`).filter(function(line) {
return !!line.match(CHROME_IE_STACK_REGEXP);
}, this);
return filtered.map(function(line) {
line.indexOf("(eval ") > -1 && (line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, ""));
var sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, ""), location = sanitizedLine.match(/ (\(.+\)$)/);
sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
var locationParts = this.extractLocation(location ? location[1] : sanitizedLine), functionName = location && sanitizedLine || void 0, fileName = ["eval", "<anonymous>"].indexOf(locationParts[0]) > -1 ? void 0 : locationParts[0];
return new StackFrame({
functionName,
fileName,
lineNumber: locationParts[1],
columnNumber: locationParts[2],
source: line
});
}, this);
},
parseFFOrSafari: function(error) {
var filtered = error.stack.split(`
`).filter(function(line) {
return !line.match(SAFARI_NATIVE_CODE_REGEXP);
}, this);
return filtered.map(function(line) {
if (line.indexOf(" > eval") > -1 && (line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1")), line.indexOf("@") === -1 && line.indexOf(":") === -1)
return new StackFrame({
functionName: line
});
var functionNameRegex = /((.*".+"[^@]*)?[^@]*)(?:@)/, matches = line.match(functionNameRegex), functionName = matches && matches[1] ? matches[1] : void 0, locationParts = this.extractLocation(line.replace(functionNameRegex, ""));
return new StackFrame({
functionName,
fileName: locationParts[0],
lineNumber: locationParts[1],
columnNumber: locationParts[2],
source: line
});
}, this);
},
parseOpera: function(e) {
return !e.stacktrace || e.message.indexOf(`
`) > -1 && e.message.split(`
`).length > e.stacktrace.split(`
`).length ? this.parseOpera9(e) : e.stack ? this.parseOpera11(e) : this.parseOpera10(e);
},
parseOpera9: function(e) {
for (var lineRE = /Line (\d+).*script (?:in )?(\S+)/i, lines = e.message.split(`
`), result = [], i = 2, len = lines.length; i < len; i += 2) {
var match = lineRE.exec(lines[i]);
match && result.push(new StackFrame({
fileName: match[2],
lineNumber: match[1],
source: lines[i]
}));
}
return result;
},
parseOpera10: function(e) {
for (var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i, lines = e.stacktrace.split(`
`), result = [], i = 0, len = lines.length; i < len; i += 2) {
var match = lineRE.exec(lines[i]);
match && result.push(
new StackFrame({
functionName: match[3] || void 0,
fileName: match[2],
lineNumber: match[1],
source: lines[i]
})
);
}
return result;
},
// Opera 10.65+ Error.stack very similar to FF/Safari
parseOpera11: function(error) {
var filtered = error.stack.split(`
`).filter(function(line) {
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/);
}, this);
return filtered.map(function(line) {
var tokens = line.split("@"), locationParts = this.extractLocation(tokens.pop()), functionCall = tokens.shift() || "", functionName = functionCall.replace(/<anonymous function(: (\w+))?>/, "$2").replace(/\([^)]*\)/g, "") || void 0, argsRaw;
functionCall.match(/\(([^)]*)\)/) && (argsRaw = functionCall.replace(/^[^(]+\(([^)]*)\)$/, "$1"));
var args = argsRaw === void 0 || argsRaw === "[arguments not available]" ? void 0 : argsRaw.split(",");
return new StackFrame({
functionName,
args,
fileName: locationParts[0],
lineNumber: locationParts[1],
columnNumber: locationParts[2],
source: line
});
}, this);
}
};
});
}
});
// ../../node_modules/.pnpm/iserror@0.0.2/node_modules/iserror/index.js
var require_iserror = __commonJS({
"../../node_modules/.pnpm/iserror@0.0.2/node_modules/iserror/index.js"(exports, module) {
init_cjs_shims();
module.exports = isError;
function isError(value) {
switch (Object.prototype.toString.call(value)) {
case "[object Error]":
return !0;
case "[object Exception]":
return !0;
case "[object DOMException]":
return !0;
default:
return value instanceof Error;
}
}
}
});
// ../../node_modules/.pnpm/stack-generator@2.0.10/node_modules/stack-generator/stack-generator.js
var require_stack_generator = __commonJS({
"../../node_modules/.pnpm/stack-generator@2.0.10/node_modules/stack-generator/stack-generator.js"(exports, module) {
init_cjs_shims();
(function(root, factory) {
"use strict";
typeof define == "function" && define.amd ? define("stack-generator", ["stackframe"], factory) : typeof exports == "object" ? module.exports = factory(require_stackframe()) : root.StackGenerator = factory(root.StackFrame);
})(exports, function(StackFrame) {
return {
backtrace: function(opts) {
var stack = [], maxStackSize = 10;
typeof opts == "object" && typeof opts.maxStackSize == "number" && (maxStackSize = opts.maxStackSize);
for (var curr = arguments.callee; curr && stack.length < maxStackSize && curr.arguments; ) {
for (var args = new Array(curr.arguments.length), i = 0; i < args.length; ++i)
args[i] = curr.arguments[i];
/function(?:\s+([\w$]+))+\s*\(/.test(curr.toString()) ? stack.push(new StackFrame({ functionName: RegExp.$1 || void 0, args })) : stack.push(new StackFrame({ args }));
try {
curr = curr.caller;
} catch {
break;
}
}
return stack;
}
};
});
}
});
// ../../node_modules/.pnpm/end-of-stream@1.4.5/node_modules/end-of-stream/index.js
var require_end_of_stream = __commonJS({
"../../node_modules/.pnpm/end-of-stream@1.4.5/node_modules/end-of-stream/index.js"(exports, module) {
init_cjs_shims();
var once = require_once(), noop = function() {
}, qnt = global.Bare ? queueMicrotask : process.nextTick.bind(process), isRequest = function(stream) {
return stream.setHeader && typeof stream.abort == "function";
}, isChildProcess = function(stream) {
return stream.stdio && Array.isArray(stream.stdio) && stream.stdio.length === 3;
}, eos = function(stream, opts, callback) {
if (typeof opts == "function") return eos(stream, null, opts);
opts || (opts = {}), callback = once(callback || noop);
var ws = stream._writableState, rs = stream._readableState, readable = opts.readable || opts.readable !== !1 && stream.readable, writable = opts.writable || opts.writable !== !1 && stream.writable, cancelled = !1, onlegacyfinish = function() {
stream.writable || onfinish();
}, onfinish = function() {
writable = !1, readable || callback.call(stream);
}, onend = function() {
readable = !1, writable || callback.call(stream);
}, onexit = function(exitCode) {
callback.call(stream, exitCode ? new Error("exited with error code: " + exitCode) : null);
}, onerror = function(err) {
callback.call(stream, err);
}, onclose = function() {
qnt(onclosenexttick);
}, onclosenexttick = function() {
if (!cancelled) {
if (readable && !(rs && rs.ended && !rs.destroyed)) return callback.call(stream, new Error("premature close"));
if (writable && !(ws && ws.ended && !ws.destroyed)) return callback.call(stream, new Error("premature close"));
}
}, onrequest = function() {
stream.req.on("finish", onfinish);
};
return isRequest(stream) ? (stream.on("complete", onfinish), stream.on("abort", onclose), stream.req ? onrequest() : stream.on("request", onrequest)) : writable && !ws && (stream.on("end", onlegacyfinish), stream.on("close", onlegacyfinish)), isChildProcess(stream) && stream.on("exit", onexit), stream.on("end", onend), stream.on("finish", onfinish), opts.error !== !1 && stream.on("error", onerror), stream.on("close", onclose), function() {
cancelled = !0, stream.removeListener("complete", onfinish), stream.removeListener("abort", onclose), stream.removeListener("request", onrequest), stream.req && stream.req.removeListener("finish", onfinish), stream.removeListener("end", onlegacyfinish), stream.removeListener("close", onlegacyfinish), stream.removeListener("finish", onfinish), stream.removeListener("exit", onexit), stream.removeListener("end", onend), stream.removeListener("error", onerror), stream.removeListener("close", onclose);
};
};
module.exports = eos;
}
});
// ../../node_modules/.pnpm/pump@3.0.2/node_modules/pump/index.js
var require_pump = __commonJS({
"../../node_modules/.pnpm/pump@3.0.2/node_modules/pump/index.js"(exports, module) {
init_cjs_shims();
var once = require_once(), eos = require_end_of_stream(), fs;
try {
fs = __require("fs");
} catch {
}
var noop = function() {
}, ancient = /^v?\.0/.test(process.version), isFn = function(fn) {
return typeof fn == "function";
}, isFS = function(stream) {
return !ancient || !fs ? !1 : (stream instanceof (fs.ReadStream || noop) || stream instanceof (fs.WriteStream || noop)) && isFn(stream.close);
}, isRequest = function(stream) {
return stream.setHeader && isFn(stream.abort);
}, destroyer = function(stream, reading, writing, callback) {
callback = once(callback);
var closed = !1;
stream.on("close", function() {
closed = !0;
}), eos(stream, { readable: reading, writable: writing }, function(err) {
if (err) return callback(err);
closed = !0, callback();
});
var destroyed = !1;
return function(err) {
if (!closed && !destroyed) {
if (destroyed = !0, isFS(stream)) return stream.close(noop);
if (isRequest(stream)) return stream.abort();
if (isFn(stream.destroy)) return stream.destroy();
callback(err || new Error("stream was destroyed"));
}
};
}, call = function(fn) {
fn();
}, pipe = function(from, to) {
return from.pipe(to);
}, pump = function() {
var streams = Array.prototype.slice.call(arguments), callback = isFn(streams[streams.length - 1] || noop) && streams.pop() || noop;
if (Array.isArray(streams[0]) && (streams = streams[0]), streams.length < 2) throw new Error("pump requires two streams per minimum");
var error, destroys = streams.map(function(stream, i) {
var reading = i < streams.length - 1, writing = i > 0;
return destroyer(stream, reading, writing, function(err) {
error || (error = err), err && destroys.forEach(call), !reading && (destroys.forEach(call), callback(error));
});
});
return streams.reduce(pipe);
};
module.exports = pump;
}
});
// ../../node_modules/.pnpm/byline@5.0.0/node_modules/byline/lib/byline.js
var require_byline = __commonJS({
"../../node_modules/.pnpm/byline@5.0.0/node_modules/byline/lib/byline.js"(exports, module) {
init_cjs_shims();
var stream = __require("stream"), util = __require("util"), timers = __require("timers");
module.exports = function(readStream, options) {
return module.exports.createStream(readStream, options);
};
module.exports.createStream = function(readStream, options) {
return readStream ? createLineStream(readStream, options) : new LineStream(options);
};
module.exports.createLineStream = function(readStream) {
return console.log("WARNING: byline#createLineStream is deprecated and will be removed soon"), createLineStream(readStream);
};
function createLineStream(readStream, options) {
if (!readStream)
throw new Error("expected readStream");
if (!readStream.readable)
throw new Error("readStream must be readable");
var ls = new LineStream(options);
return readStream.pipe(ls), ls;
}
module.exports.LineStream = LineStream;
function LineStream(options) {
stream.Transform.call(this, options), options = options || {}, this._readableState.objectMode = !0, this._lineBuffer = [], this._keepEmptyLines = options.keepEmptyLines || !1, this._lastChunkEndedWithCR = !1;
var self2 = this;
this.on("pipe", function(src) {
self2.encoding || src instanceof stream.Readable && (self2.encoding = src._readableState.encoding);
});
}
util.inherits(LineStream, stream.Transform);
LineStream.prototype._transform = function(chunk, encoding, done) {
encoding = encoding || "utf8", Buffer.isBuffer(chunk) && (encoding == "buffer" ? (chunk = chunk.toString(), encoding = "utf8") : chunk = chunk.toString(encoding)), this._chunkEncoding = encoding;
var lines = chunk.split(/\r\n|[\n\v\f\r\x85\u2028\u2029]/g);
this._lastChunkEndedWithCR && chunk[0] == `
` && lines.shift(), this._lineBuffer.length > 0 && (this._lineBuffer[this._lineBuffer.length - 1] += lines[0], lines.shift()), this._lastChunkEndedWithCR = chunk[chunk.length - 1] == "\r", this._lineBuffer = this._lineBuffer.concat(lines), this._pushBuffer(encoding, 1, done);
};
LineStream.prototype._pushBuffer = function(encoding, keep, done) {
for (; this._lineBuffer.length > keep; ) {
var line = this._lineBuffer.shift();
if ((this._keepEmptyLines || line.length > 0) && !this.push(this._reencode(line, encoding))) {
var self2 = this;
timers.setImmediate(function() {
self2._pushBuffer(encoding, keep, done);
});
return;
}
}
done();
};
LineStream.prototype._flush = function(done) {
this._pushBuffer(this._chunkEncoding, 0, done);
};
LineStream.prototype._reencode = function(line, chunkEncoding) {
return this.encoding && this.encoding != chunkEncoding ? new Buffer(line, chunkEncoding).toString(this.encoding) : this.encoding ? line : new Buffer(line, chunkEncoding);
};
}
});
// ../../node_modules/.pnpm/@bugsnag+node@8.6.0/node_modules/@bugsnag/node/dist/bugsnag.js
var require_bugsnag = __commonJS({
"../../node_modules/.pnpm/@bugsnag+node@8.6.0/node_modules/@bugsnag/node/dist/bugsnag.js"(exports, module) {
init_cjs_shims();
(function(f) {
if (typeof exports == "object" && typeof module < "u")
module.exports = f();
else if (typeof define == "function" && define.amd)
define([], f);
else {
var g;
typeof window < "u" ? g = window : typeof global < "u" ? g = global : typeof self < "u" ? g = self : g = this, g.bugsnag = f();
}
})(function() {
var define2, module2, exports2, Breadcrumb = /* @__PURE__ */ (function() {
function Breadcrumb2(message, metadata, type, timestamp) {
timestamp === void 0 && (timestamp = /* @__PURE__ */ new Date()), this.type = type, this.message = message, this.metadata = metadata, this.timestamp = timestamp;
}
var _proto = Breadcrumb2.prototype;
return _proto.toJSON = function() {
return {
type: this.type,
name: this.message,
timestamp: this.timestamp,
metaData: this.metadata
};
}, Breadcrumb2;
})(), _$Breadcrumb_7 = Breadcrumb, _$breadcrumbTypes_12 = ["navigation", "request", "process", "log", "user", "state", "error", "manual"], _$reduce_22 = function(arr, fn, accum) {
for (var val = accum, i = 0, len = arr.length; i < len; i++) val = fn(val, arr[i], i, arr);
return val;
}, _$filter_17 = function(arr, fn) {
return _$reduce_22(arr, function(accum, item, i, arr2) {
return fn(item, i, arr2) ? accum.concat(item) : accum;
}, []);
}, _$includes_18 = function(arr, x) {
return _$reduce_22(arr, function(accum, item, i, arr2) {
return accum === !0 || item === x;
}, !1);
}, _$isArray_19 = function(obj) {
return Object.prototype.toString.call(obj) === "[object Array]";
}, _hasDontEnumBug = !{
toString: null
}.propertyIsEnumerable("toString"), _dontEnums = ["toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "constructor"], _$keys_20 = function(obj) {
var result = [], prop;
for (prop in obj)
Object.prototype.hasOwnProperty.call(obj, prop) && result.push(prop);
if (!_hasDontEnumBug) return result;
for (var i = 0, len = _dontEnums.length; i < len; i++)
Object.prototype.hasOwnProperty.call(obj, _dontEnums[i]) && result.push(_dontEnums[i]);
return result;
}, _$intRange_31 = function(min, max) {
return min === void 0 && (min = 1), max === void 0 && (max = 1 / 0), function(value) {
return typeof value == "number" && parseInt("" + value, 10) === value && value >= min && value <= max;
};
}, _$listOfFunctions_32 = function(value) {
return typeof value == "function" || _$isArray_19(value) && _$filter_17(value, function(f) {
return typeof f == "function";
}).length === value.length;
}, _$stringWithLength_33 = function(value) {
return typeof value == "string" && !!value.length;
}, _$config_9 = {}, defaultErrorTypes = function() {
return {
unhandledExceptions: !0,
unhandledRejections: !0
};
};
_$config_9.schema = {
apiKey: {
defaultValue: function() {
return null;
},
message: "is required",
validate: _$stringWithLength_33
},
appVersion: {
defaultValue: function() {
},
message: "should be a string",
validate: function(value) {
return value === void 0 || _$stringWithLength_33(value);
}
},
appType: {
defaultValue: function() {
},
message: "should be a string",
validate: function(value) {
return value === void 0 || _$stringWithLength_33(value);
}
},
autoDetectErrors: {
defaultValue: function() {
return !0;
},
message: "should be true|false",
validate: function(value) {
return value === !0 || value === !1;
}
},
enabledErrorTypes: {
defaultValue: function() {
return defaultErrorTypes();
},
message: "should be an object containing the flags { unhandledExceptions:true|false, unhandledRejections:true|false }",
allowPartialObject: !0,
validate: function(value) {
if (typeof value != "object" || !value) return !1;
var providedKeys = _$keys_20(value), defaultKeys = _$keys_20(defaultErrorTypes());
return !(_$filter_17(providedKeys, function(k) {
return _$includes_18(defaultKeys, k);
}).length < providedKeys.length || _$filter_17(_$keys_20(value), function(k) {
return typeof value[k] != "boolean";
}).length > 0);
}
},
onError: {
defaultValue: function() {
return [];
},
message: "should be a function or array of functions",
validate: _$listOfFunctions_32
},
onSession: {
defaultValue: function() {
return [];
},
message: "should be a function or array of functions",
validate: _$listOfFunctions_32
},
onBreadcrumb: {
defaultValue: function() {
return [];
},
message: "should be a function or array of functions",
validate: _$listOfFunctions_32
},
endpoints: {
defaultValue: function(endpoints) {
return typeof endpoints > "u" ? {
notify: "https://notify.bugsnag.com",
sessions: "https://sessions.bugsnag.com"
} : {
notify: null,
sessions: null
};
},
message: "should be an object containing endpoint URLs { notify, sessions }",
validate: function(val) {
return (
// first, ensure it's an object
val && typeof val == "object" && // notify and sessions must always be set
_$stringWithLength_33(val.notify) && _$stringWithLength_33(val.sessions) && // ensure no keys other than notify/session are set on endpoints object
_$filter_17(_$keys_20(val), function(k) {
return !_$includes_18(["notify", "sessions"], k);
}).length === 0
);
}
},
autoTrackSessions: {
defaultValue: function(val) {
return !0;
},
message: "should be true|false",
validate: function(val) {
return val === !0 || val === !1;
}
},
enabledReleaseStages: {
defaultValue: function() {
return null;
},
message: "should be an array of strings",
validate: function(value) {
return value === null || _$isArray_19(value) && _$filter_17(value, function(f) {
return typeof f == "string";
}).length === value.length;
}
},
releaseStage: {
defaultValue: function() {
return "production";
},
message: "should be a string",
validate: function(value) {
return typeof value == "string" && value.length;
}
},
maxBreadcrumbs: {
defaultValue: function() {
return 25;
},
message: "should be a number \u2264100",
validate: function(value) {
return _$intRange_31(0, 100)(value);
}
},
enabledBreadcrumbTypes: {
defaultValue: function() {
return _$breadcrumbTypes_12;
},
message: "should be null or a list of available breadcrumb types (" + _$breadcrumbTypes_12.join(",") + ")",
validate: function(value) {
return value === null || _$isArray_19(value) && _$reduce_22(value, function(accum, maybeType) {
return accum === !1 ? accum : _$includes_18(_$breadcrumbTypes_12, maybeType);
}, !0);
}
},
context: {
defaultValue: function() {
},
message: "should be a string",
validate: function(value) {
return value === void 0 || typeof value == "string";
}
},
user: {
defaultValue: function() {
return {};
},
message: "should be an object with { id, email, name } properties",
validate: function(value) {
return value === null || value && _$reduce_22(_$keys_20(value), function(accum, key) {
return accum && _$includes_18(["id", "email", "name"], key);
}, !0);
}
},
metadata: {
defaultValue: function() {
return {};
},
message: "should be an object",
validate: function(value) {
return typeof value == "object" && value !== null;
}
},
logger: {
defaultValue: function() {
},
message: "should be null or an object with methods { debug, info, warn, error }",
validate: function(value) {
return !value || value && _$reduce_22(["debug", "info", "warn", "error"], function(accum, method) {
return accum && typeof value[method] == "function";
}, !0);
}
},
redactedKeys: {
defaultValue: function() {
return ["password"];
},
message: "should be an array of strings|regexes",
validate: function(value) {
return _$isArray_19(value) && value.length === _$filter_17(value, function(s) {
return typeof s == "string" || s && typeof s.test == "function";
}).length;
}
},
plugins: {
defaultValue: function() {
return [];
},
message: "should be an array of plugin objects",
validate: function(value) {
return _$isArray_19(value) && value.length === _$filter_17(value, function(p) {
return p && typeof p == "object" && typeof p.load == "function";
}).length;
}
},
featureFlags: {
defaultValue: function() {
return [];
},
message: 'should be an array of objects that have a "name" property',
validate: function(value) {
return _$isArray_19(value) && value.length === _$filter_17(value, function(feature) {
return feature && typeof feature == "object" && typeof feature.name == "string";
}).length;
}
},
reportUnhandledPromiseRejectionsAsHandled: {
defaultValue: function() {
return !1;
},
message: "should be true|false",
validate: function(value) {
return value === !0 || value === !1;
}
},
sendPayloadChecksums: {
defaultValue: function() {
return !1;
},
message: "should be true|false",
validate: function(value) {
return value === !0 || value === !1;
}
}
};
var _$errorStackParser_15 = require_error_stack_parser(), _$assign_16 = function(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source)
Object.prototype.hasOwnProperty.call(source, key) && (target[key] = source[key]);
}
return target;
}, _$map_21 = function(arr, fn) {
return _$reduce_22(arr, function(accum, item, i, arr2) {
return accum.concat(fn(item, i, arr2));
}, []);
}, _$safeJsonStringify_5 = function(data, replacer, space, opts) {
var redactedKeys = opts && opts.redactedKeys ? opts.redactedKeys : [], redactedPaths = opts && opts.redactedPaths ? opts.redactedPaths : [];
return JSON.stringify(prepareObjForSerialization(data, redactedKeys, redactedPaths), replacer, space);
}, MAX_DEPTH = 20, MAX_EDGES = 25e3, MIN_PRESERVED_DEPTH = 8, REPLACEMENT_NODE = "...";
function isError(o) {
return o instanceof Error || /^\[object (Error|(Dom)?Exception)\]$/.test(Object.prototype.toString.call(o));
}
function throwsMessage(err) {
return "[Throws: " + (err ? err.message : "?") + "]";
}
function find(haystack, needle) {
for (var i = 0, len = haystack.length; i < len; i++)
if (haystack[i] === needle) return !0;
return !1;
}
function isDescendent(paths, path2) {
for (var i = 0, len = paths.length; i < len; i++)
if (path2.indexOf(paths[i]) === 0) return !0;
return !1;
}
function shouldRedact(patterns, key) {
for (var i = 0, len = patterns.length; i < len; i++)
if (typeof patterns[i] == "string" && patterns[i].toLowerCase() === key.toLowerCase() || patterns[i] && typeof patterns[i].test == "function" && patterns[i].test(key)) return !0;
return !1;
}
function __isArray_5(obj) {
return Object.prototype.toString.call(obj) === "[object Array]";
}
function safelyGetProp(obj, prop) {
try {
return obj[prop];
} catch (err) {
return throwsMessage(err);
}
}
function prepareObjForSerialization(obj, redactedKeys, redactedPaths) {
var seen = [], edges = 0;
function visit(obj2, path2) {
function edgesExceeded() {
return path2.length > MIN_PRESERVED_DEPTH && edges > MAX_EDGES;
}
if (edges++, path2.length > MAX_DEPTH || edgesExceeded()) return REPLACEMENT_NODE;
if (obj2 === null || typeof obj2 != "object") return obj2;
if (find(seen, obj2)) return "[Circular]";
if (seen.push(obj2), typeof obj2.toJSON == "function")
try {
edges--;
var fResult = visit(obj2.toJSON(), path2);
return seen.pop(), fResult;
} catch (err) {
return throwsMessage(err);
}
var er = isError(obj2);
if (er) {
edges--;
var eResult = visit({
name: obj2.name,
message: obj2.message
}, path2);
return seen.pop(), eResult;
}
if (__isArray_5(obj2)) {
for (var aResult = [], i = 0, len = obj2.length; i < len; i++) {
if (edgesExceeded()) {
aResult.push(REPLACEMENT_NODE);
break;
}
aResult.push(visit(obj2[i], path2.concat("[]")));
}
return seen.pop(), aResult;
}
var result = {};
try {
for (var prop in obj2)
if (Object.prototype.hasOwnProperty.call(obj2, prop)) {
if (isDescendent(redactedPaths, path2.join(".")) && shouldRedact(redactedKeys, prop)) {
result[prop] = "[REDACTED]";
continue;
}
if (edgesExceeded()) {
result[prop] = REPLACEMENT_NODE;
break;
}
result[prop] = visit(safelyGetProp(obj2, prop), path2.concat(prop));
}
} catch {
}
return seen.pop(), result;
}
return visit(obj, []);
}
function add(existingFeatures, existingFeatureKeys, name2, variant) {
if (typeof name2 == "string") {
variant === void 0 ? variant = null : variant !== null && typeof variant != "string" && (variant = _$safeJsonStringify_5(variant));
var existingIndex = existingFeatureKeys[name2];
if (typeof existingIndex == "number") {
existingFeatures[existingIndex] = {
name: name2,
variant
};
return;
}
existingFeatures.push({
name: name2,
variant
}), existingFeatureKeys[name2] = existingFeatures.length - 1;
}
}
function merge(existingFeatures, newFeatures, existingFeatureKeys) {
if (_$isArray_19(newFeatures)) {
for (var i = 0; i < newFeatures.length; ++i) {
var feature = newFeatures[i];
feature === null || typeof feature != "object" || add(existingFeatures, existingFeatureKeys, feature.name, feature.variant);
}
return existingFeatures;
}
}
function toEventApi(featureFlags) {
return _$map_21(_$filter_17(featureFlags, Boolean), function(_ref) {
var name2 = _ref.name, variant = _ref.variant, flag = {
featureFlag: name2
};
return typeof variant == "string" && (flag.variant = variant), flag;
});
}
function clear(features, featuresIndex, name2) {
var existingIndex = featuresIndex[name2];
typeof existingIndex == "number" && (features[existingIndex] = null, delete featuresIndex[name2]);
}
var _$featureFlagDelegate_23 = {
add,
clear,
merge,
toEventApi
}, _$hasStack_24 = function(err) {
return !!err && (!!err.stack || !!err.stacktrace || !!err["opera#sourceloc"]) && typeof (err.stack || err.stacktrace || err["opera#sourceloc"]) == "string" && err.stack !== err.name + ": " + err.message;
}, _$iserror_25 = require_iserror(), __add_27 = function(state, section, keyOrObj, maybeVal) {
var _updates;
if (section) {
var updates;
if (keyOrObj === null) return __clear_27(state, section);
typeof keyOrObj == "object" && (updates = keyOrObj), typeof keyOrObj == "string" && (updates = (_updates = {}, _updates[keyOrObj] = maybeVal, _updates)), updates && (section === "__proto__" || section === "constructor" || section === "prototype" || (state[section] || (state[section] = {}), state[section] = _$assign_16({}, state[section], updates)));
}
}, get = function(state, section, key) {
if (typeof section == "string") {
if (!key)
return state[section];
if (state[section])
return state[section][key];
}
}, __clear_27 = function(state, section, key) {
if (typeof section == "string") {
if (!key) {
delete state[section];
return;
}
section === "__proto__" || section === "constructor" || section === "prototype" || state[section] && delete state[section][key];
}
}, _$metadataDelegate_27 = {
add: __add_27,
get,
clear: __clear_27
};
function _extends() {
return _extends = Object.assign ? Object.assign.bind() : function(n) {
for (var e = 1; e < arguments.length; e++) {
var t = arguments[e];
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
}
return n;
}, _extends.apply(null, arguments);
}
var StackGenerator = require_stack_generator(), Event = /* @__PURE__ */ (function() {
function Event2(errorClass, errorMessage, stacktrace, handledState, originalError) {
stacktrace === void 0 && (stacktrace = []), handledState === void 0 && (handledState = defaultHandledState()), this.apiKey = void 0, this.context = void 0, this.groupingHash = void 0, this.originalError = originalError, this._handledState = handledState, this.severity = this._handledState.severity, this.unhandled = this._handledState.unhandled, this.app = {}, this.device = {}, this.request = {}, this.breadcrumbs = [], this.threads = [], this._metadata = {}, this._features = [], this._featuresIndex = {}, this._user = {}, this._session = void 0, this._correlation = void 0, this._groupingDiscriminator = void 0, this.errors = [createBugsnagError(errorClass, errorMessage, Event2.__type, stacktrace)];
}
var _proto = Event2.prototype;
return _proto.addMetadata = function(section, keyOrObj, maybeVal) {
return _$metadataDelegate_27.add(this._metadata, section, keyOrObj, maybeVal);
}, _proto.setTraceCorrelation = function(traceId, spanId) {
typeof traceId == "string" && (this._correlation = _extends({
traceId
}, typeof spanId == "string" ? {
spanId
} : {}));
}, _proto.getGroupingDiscriminator = function() {
return this._groupingDiscriminator;
}, _proto.setGroupingDiscriminator = function(value) {
var previousValue = this._groupingDiscriminator;
return (typeof value == "string" || value === null || value === void 0) && (this._groupingDiscriminator = value), previousValue;
}, _proto.getMetadata = function(section, key) {
return _$metadataDelegate_27.get(this._metadata, section, key);
}, _proto.clearMetadata = function(section, key) {
return _$metadataDelegate_27.clear(this._metadata, section, key);
}, _proto.addFeatureFlag = function(name2, variant) {
variant === void 0 && (variant = null), _$featureFlagDelegate_23.add(this._features, this._featuresIndex, name2, variant);
}, _proto.addFeatureFlags = function(featureFlags) {
_$featureFlagDelegate_23.merge(this._features, featureFlags, this._featuresIndex);
}, _proto.getFeatureFlags = function() {
return _$featureFlagDelegate_23.toEventApi(this._features);
}, _proto.clearFeatureFlag = function(name2) {
_$featureFlagDelegate_23.clear(this._features, this._featuresIndex, name2);
}, _proto.clearFeatureFlags = function() {
this._features = [], this._featuresIndex = {};
}, _proto.getUser = function() {
return this._user;
}, _proto.setUser = function(id, email, name2) {
this._user = {
id,
email,
name: name2
};
}, _proto.toJSON = function() {
return {
payloadVersion: "4",
exceptions: _$map_21(this.errors, function(er) {
return _$assign_16({}, er, {
message: er.errorMessage
});
}),
severity: this.severity,
unhandled: this._handledState.unhandled,
severityReason: this._handledState.severityReason,
app: this.app,
device: this.device,
request: this.request,
breadcrumbs: this.breadcrumbs,
context: this.context,
groupingHash: this.groupingHash,
groupingDiscriminator: this._groupingDiscriminator,
metaData: this._metadata,
user: this._user,
session: this._session,
featureFlags: this.getFeatureFlags(),
correlation: this._correlation
};
}, Event2;
})(), formatStackframe = function(frame) {
var f = {
file: frame.fileName,
method: normaliseFunctionName(frame.functionName),
lineNumber: frame.lineNumber,
columnNumber: frame.columnNumber,
code: void 0,
inProject: void 0
};
return f.lineNumber > -1 && !f.file && !f.method && (f.file = "global code"), f;
}, normaliseFunctionName = function(name2) {
return /^global code$/i.test(name2) ? "global code" : name2;
}, defaultHandledState = function() {
return {
unhandled: !1,
severity: "warning",
severityReason: {
type: "handledException"
}
};
}, ensureString = function(str) {
return typeof str == "string" ? str : "";
};
function createBugsnagError(errorClass, errorMessage, type, stacktrace) {
return {
errorClass: ensureString(errorClass),
errorMessage: ensureString(errorMessage),
type,
stacktrace: _$reduce_22(stacktrace, function(accum, frame) {
var f = formatStackframe(frame);
try {
return JSON.stringify(f) === "{}" ? accum : accum.concat(f);
} catch {
return accum;
}
}, [])
};
}
function getCauseStack(error) {
return error.cause ? [error].concat(getCauseStack(error.cause)) : [error];
}
Event.getStacktrace = function(error, errorFramesToSkip, backtraceFramesToSkip) {
if (_$hasStack_24(error)) return _$errorStackParser_15.parse(error).slice(errorFramesToSkip);
try {
return _$filter_17(StackGenerator.backtrace(), function(frame) {
return (frame.functionName || "").indexOf("StackGenerator$$") === -1;
}).slice(1 + backtraceFramesToSkip);
} catch {
return [];
}
}, Event.create = function(maybeError, tolerateNonErrors, handledState, component, errorFramesToSkip, logger) {
errorFramesToSkip === void 0 && (errorFramesToSkip = 0);
var _normaliseError = normaliseError(maybeError, tolerateNonErrors, component, logger), error = _normaliseError[0], internalFrames = _normaliseError[1], event;
try {
var stacktrace = Event.getStacktrace(
error,
// if an error was created/throw in the normaliseError() function, we need to
// tell the getStacktrace() function to skip the number of frames we know will
// be from our own functions. This is added to the number of frames deep we
// were told about
internalFrames > 0 ? 1 + internalFrames + errorFramesToSkip : 0,
// if there's no stacktrace, the callstack may be walked to generated one.
// this is how many frames should be removed because they come from our library
1 + errorFramesToSkip
);
event = new Event(error.name, error.message, stacktrace, handledState, maybeError);
} catch {
event = new Event(error.name, error.message, [], handledState, maybeError);
}
if (error.name === "InvalidError" && event.addMetadata("" + component, "non-error parameter", makeSerialisable(maybeError)), error.cause) {
var _event$errors, causes = getCauseStack(error).slice(1), normalisedCauses = _$map_21(causes, function(cause) {
var stacktrace2 = _$iserror_25(cause) && _$hasStack_24(cause) ? _$errorStackParser_15.parse(cause) : [], _normaliseError2 = normaliseError(cause, !0, "error cause"), error2 = _normaliseError2[0];
return error2.name === "InvalidError" && event.addMetadata("error cause", makeSerialisable(cause)), createBugsnagError(error2.name, error2.message, Event.__type, stacktrace2);
});
(_event$errors = event.errors).push.apply(_event$errors, normalisedCauses);
}
return event;
};
var makeSerialisable = function(err) {
return err === null ? "null" : err === void 0 ? "undefined" : err;
}, normaliseError = function(maybeError, tolerateNonErrors, component, logger) {
var error, internalFrames = 0, createAndLogInputError = function(reason) {
var verb = component === "error cause" ? "was" : "received";
logger && logger.warn(component + " " + verb + ' a non-error: "' + reason + '"');
var err = new Error(component + " " + verb + ' a non-error. See "' + component + '" tab for more detail.');
return err.name = "InvalidError", err;
};
i