mirror of
https://github.com/MarSeventh/CloudFlare-ImgBed.git
synced 2026-04-25 14:44:58 +00:00
3788 lines
113 KiB
JavaScript
3788 lines
113 KiB
JavaScript
var __defProp = Object.defineProperty;
|
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
var __publicField = (obj, key, value) => {
|
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
return value;
|
|
};
|
|
var __accessCheck = (obj, member, msg) => {
|
|
if (!member.has(obj))
|
|
throw TypeError("Cannot " + msg);
|
|
};
|
|
var __privateGet = (obj, member, getter) => {
|
|
__accessCheck(obj, member, "read from private field");
|
|
return getter ? getter.call(obj) : member.get(obj);
|
|
};
|
|
var __privateAdd = (obj, member, value) => {
|
|
if (member.has(obj))
|
|
throw TypeError("Cannot add the same private member more than once");
|
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
};
|
|
var __privateSet = (obj, member, value, setter) => {
|
|
__accessCheck(obj, member, "write to private field");
|
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
return value;
|
|
};
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/is.js
|
|
var objectToString = Object.prototype.toString;
|
|
function isError(wat) {
|
|
switch (objectToString.call(wat)) {
|
|
case "[object Error]":
|
|
case "[object Exception]":
|
|
case "[object DOMException]":
|
|
return true;
|
|
default:
|
|
return isInstanceOf(wat, Error);
|
|
}
|
|
}
|
|
function isBuiltin(wat, className) {
|
|
return objectToString.call(wat) === `[object ${className}]`;
|
|
}
|
|
function isString(wat) {
|
|
return isBuiltin(wat, "String");
|
|
}
|
|
function isPrimitive(wat) {
|
|
return wat === null || typeof wat !== "object" && typeof wat !== "function";
|
|
}
|
|
function isPlainObject(wat) {
|
|
return isBuiltin(wat, "Object");
|
|
}
|
|
function isEvent(wat) {
|
|
return typeof Event !== "undefined" && isInstanceOf(wat, Event);
|
|
}
|
|
function isElement(wat) {
|
|
return typeof Element !== "undefined" && isInstanceOf(wat, Element);
|
|
}
|
|
function isThenable(wat) {
|
|
return Boolean(wat && wat.then && typeof wat.then === "function");
|
|
}
|
|
function isSyntheticEvent(wat) {
|
|
return isPlainObject(wat) && "nativeEvent" in wat && "preventDefault" in wat && "stopPropagation" in wat;
|
|
}
|
|
function isNaN2(wat) {
|
|
return typeof wat === "number" && wat !== wat;
|
|
}
|
|
function isInstanceOf(wat, base) {
|
|
try {
|
|
return wat instanceof base;
|
|
} catch (_e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/worldwide.js
|
|
function isGlobalObj(obj) {
|
|
return obj && obj.Math == Math ? obj : void 0;
|
|
}
|
|
var GLOBAL_OBJ = typeof globalThis == "object" && isGlobalObj(globalThis) || // eslint-disable-next-line no-restricted-globals
|
|
typeof window == "object" && isGlobalObj(window) || typeof self == "object" && isGlobalObj(self) || typeof global == "object" && isGlobalObj(global) || function() {
|
|
return this;
|
|
}() || {};
|
|
function getGlobalObject() {
|
|
return GLOBAL_OBJ;
|
|
}
|
|
function getGlobalSingleton(name, creator, obj) {
|
|
const gbl = obj || GLOBAL_OBJ;
|
|
const __SENTRY__ = gbl.__SENTRY__ = gbl.__SENTRY__ || {};
|
|
const singleton = __SENTRY__[name] || (__SENTRY__[name] = creator());
|
|
return singleton;
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/browser.js
|
|
var WINDOW = getGlobalObject();
|
|
function htmlTreeAsString(elem, keyAttrs) {
|
|
try {
|
|
let currentElem = elem;
|
|
const MAX_TRAVERSE_HEIGHT = 5;
|
|
const MAX_OUTPUT_LEN = 80;
|
|
const out = [];
|
|
let height = 0;
|
|
let len = 0;
|
|
const separator = " > ";
|
|
const sepLength = separator.length;
|
|
let nextStr;
|
|
while (currentElem && height++ < MAX_TRAVERSE_HEIGHT) {
|
|
nextStr = _htmlElementAsString(currentElem, keyAttrs);
|
|
if (nextStr === "html" || height > 1 && len + out.length * sepLength + nextStr.length >= MAX_OUTPUT_LEN) {
|
|
break;
|
|
}
|
|
out.push(nextStr);
|
|
len += nextStr.length;
|
|
currentElem = currentElem.parentNode;
|
|
}
|
|
return out.reverse().join(separator);
|
|
} catch (_oO) {
|
|
return "<unknown>";
|
|
}
|
|
}
|
|
function _htmlElementAsString(el, keyAttrs) {
|
|
const elem = el;
|
|
const out = [];
|
|
let className;
|
|
let classes;
|
|
let key;
|
|
let attr;
|
|
let i;
|
|
if (!elem || !elem.tagName) {
|
|
return "";
|
|
}
|
|
out.push(elem.tagName.toLowerCase());
|
|
const keyAttrPairs = keyAttrs && keyAttrs.length ? keyAttrs.filter((keyAttr) => elem.getAttribute(keyAttr)).map((keyAttr) => [keyAttr, elem.getAttribute(keyAttr)]) : null;
|
|
if (keyAttrPairs && keyAttrPairs.length) {
|
|
keyAttrPairs.forEach((keyAttrPair) => {
|
|
out.push(`[${keyAttrPair[0]}="${keyAttrPair[1]}"]`);
|
|
});
|
|
} else {
|
|
if (elem.id) {
|
|
out.push(`#${elem.id}`);
|
|
}
|
|
className = elem.className;
|
|
if (className && isString(className)) {
|
|
classes = className.split(/\s+/);
|
|
for (i = 0; i < classes.length; i++) {
|
|
out.push(`.${classes[i]}`);
|
|
}
|
|
}
|
|
}
|
|
const allowedAttrs = ["type", "name", "title", "alt"];
|
|
for (i = 0; i < allowedAttrs.length; i++) {
|
|
key = allowedAttrs[i];
|
|
attr = elem.getAttribute(key);
|
|
if (attr) {
|
|
out.push(`[${key}="${attr}"]`);
|
|
}
|
|
}
|
|
return out.join("");
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/error.js
|
|
var SentryError = class extends Error {
|
|
/** Display name of this error instance. */
|
|
constructor(message, logLevel = "warn") {
|
|
super(message);
|
|
this.message = message;
|
|
;
|
|
this.name = new.target.prototype.constructor.name;
|
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
this.logLevel = logLevel;
|
|
}
|
|
};
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/dsn.js
|
|
var DSN_REGEX = /^(?:(\w+):)\/\/(?:(\w+)(?::(\w+)?)?@)([\w.-]+)(?::(\d+))?\/(.+)/;
|
|
function isValidProtocol(protocol) {
|
|
return protocol === "http" || protocol === "https";
|
|
}
|
|
function dsnToString(dsn, withPassword = false) {
|
|
const { host, path, pass, port, projectId, protocol, publicKey } = dsn;
|
|
return `${protocol}://${publicKey}${withPassword && pass ? `:${pass}` : ""}@${host}${port ? `:${port}` : ""}/${path ? `${path}/` : path}${projectId}`;
|
|
}
|
|
function dsnFromString(str) {
|
|
const match2 = DSN_REGEX.exec(str);
|
|
if (!match2) {
|
|
throw new SentryError(`Invalid Sentry Dsn: ${str}`);
|
|
}
|
|
const [protocol, publicKey, pass = "", host, port = "", lastPath] = match2.slice(1);
|
|
let path = "";
|
|
let projectId = lastPath;
|
|
const split = projectId.split("/");
|
|
if (split.length > 1) {
|
|
path = split.slice(0, -1).join("/");
|
|
projectId = split.pop();
|
|
}
|
|
if (projectId) {
|
|
const projectMatch = projectId.match(/^\d+/);
|
|
if (projectMatch) {
|
|
projectId = projectMatch[0];
|
|
}
|
|
}
|
|
return dsnFromComponents({ host, pass, path, projectId, port, protocol, publicKey });
|
|
}
|
|
function dsnFromComponents(components) {
|
|
return {
|
|
protocol: components.protocol,
|
|
publicKey: components.publicKey || "",
|
|
pass: components.pass || "",
|
|
host: components.host,
|
|
port: components.port || "",
|
|
path: components.path || "",
|
|
projectId: components.projectId
|
|
};
|
|
}
|
|
function validateDsn(dsn) {
|
|
if (!(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__)) {
|
|
return;
|
|
}
|
|
const { port, projectId, protocol } = dsn;
|
|
const requiredComponents = ["protocol", "publicKey", "host", "projectId"];
|
|
requiredComponents.forEach((component) => {
|
|
if (!dsn[component]) {
|
|
throw new SentryError(`Invalid Sentry Dsn: ${component} missing`);
|
|
}
|
|
});
|
|
if (!projectId.match(/^\d+$/)) {
|
|
throw new SentryError(`Invalid Sentry Dsn: Invalid projectId ${projectId}`);
|
|
}
|
|
if (!isValidProtocol(protocol)) {
|
|
throw new SentryError(`Invalid Sentry Dsn: Invalid protocol ${protocol}`);
|
|
}
|
|
if (port && isNaN(parseInt(port, 10))) {
|
|
throw new SentryError(`Invalid Sentry Dsn: Invalid port ${port}`);
|
|
}
|
|
return true;
|
|
}
|
|
function makeDsn(from) {
|
|
const components = typeof from === "string" ? dsnFromString(from) : dsnFromComponents(from);
|
|
validateDsn(components);
|
|
return components;
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/logger.js
|
|
var PREFIX = "Sentry Logger ";
|
|
var CONSOLE_LEVELS = ["debug", "info", "warn", "error", "log", "assert", "trace"];
|
|
function consoleSandbox(callback) {
|
|
if (!("console" in GLOBAL_OBJ)) {
|
|
return callback();
|
|
}
|
|
const originalConsole = GLOBAL_OBJ.console;
|
|
const wrappedLevels = {};
|
|
CONSOLE_LEVELS.forEach((level) => {
|
|
const originalWrappedFunc = originalConsole[level] && originalConsole[level].__sentry_original__;
|
|
if (level in originalConsole && originalWrappedFunc) {
|
|
wrappedLevels[level] = originalConsole[level];
|
|
originalConsole[level] = originalWrappedFunc;
|
|
}
|
|
});
|
|
try {
|
|
return callback();
|
|
} finally {
|
|
Object.keys(wrappedLevels).forEach((level) => {
|
|
originalConsole[level] = wrappedLevels[level];
|
|
});
|
|
}
|
|
}
|
|
function makeLogger() {
|
|
let enabled = false;
|
|
const logger2 = {
|
|
enable: () => {
|
|
enabled = true;
|
|
},
|
|
disable: () => {
|
|
enabled = false;
|
|
}
|
|
};
|
|
if (typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) {
|
|
CONSOLE_LEVELS.forEach((name) => {
|
|
logger2[name] = (...args) => {
|
|
if (enabled) {
|
|
consoleSandbox(() => {
|
|
GLOBAL_OBJ.console[name](`${PREFIX}[${name}]:`, ...args);
|
|
});
|
|
}
|
|
};
|
|
});
|
|
} else {
|
|
CONSOLE_LEVELS.forEach((name) => {
|
|
logger2[name] = () => void 0;
|
|
});
|
|
}
|
|
return logger2;
|
|
}
|
|
var logger;
|
|
if (typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) {
|
|
logger = getGlobalSingleton("logger", makeLogger);
|
|
} else {
|
|
logger = makeLogger();
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/string.js
|
|
function truncate(str, max = 0) {
|
|
if (typeof str !== "string" || max === 0) {
|
|
return str;
|
|
}
|
|
return str.length <= max ? str : `${str.substr(0, max)}...`;
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/object.js
|
|
function addNonEnumerableProperty(obj, name, value) {
|
|
Object.defineProperty(obj, name, {
|
|
// enumerable: false, // the default, so we can save on bundle size by not explicitly setting it
|
|
value,
|
|
writable: true,
|
|
configurable: true
|
|
});
|
|
}
|
|
function urlEncode(object) {
|
|
return Object.keys(object).map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(object[key])}`).join("&");
|
|
}
|
|
function convertToPlainObject(value) {
|
|
if (isError(value)) {
|
|
return {
|
|
message: value.message,
|
|
name: value.name,
|
|
stack: value.stack,
|
|
...getOwnProperties(value)
|
|
};
|
|
} else if (isEvent(value)) {
|
|
const newObj = {
|
|
type: value.type,
|
|
target: serializeEventTarget(value.target),
|
|
currentTarget: serializeEventTarget(value.currentTarget),
|
|
...getOwnProperties(value)
|
|
};
|
|
if (typeof CustomEvent !== "undefined" && isInstanceOf(value, CustomEvent)) {
|
|
newObj.detail = value.detail;
|
|
}
|
|
return newObj;
|
|
} else {
|
|
return value;
|
|
}
|
|
}
|
|
function serializeEventTarget(target) {
|
|
try {
|
|
return isElement(target) ? htmlTreeAsString(target) : Object.prototype.toString.call(target);
|
|
} catch (_oO) {
|
|
return "<unknown>";
|
|
}
|
|
}
|
|
function getOwnProperties(obj) {
|
|
if (typeof obj === "object" && obj !== null) {
|
|
const extractedProps = {};
|
|
for (const property in obj) {
|
|
if (Object.prototype.hasOwnProperty.call(obj, property)) {
|
|
extractedProps[property] = obj[property];
|
|
}
|
|
}
|
|
return extractedProps;
|
|
} else {
|
|
return {};
|
|
}
|
|
}
|
|
function extractExceptionKeysForMessage(exception, maxLength = 40) {
|
|
const keys = Object.keys(convertToPlainObject(exception));
|
|
keys.sort();
|
|
if (!keys.length) {
|
|
return "[object has no keys]";
|
|
}
|
|
if (keys[0].length >= maxLength) {
|
|
return truncate(keys[0], maxLength);
|
|
}
|
|
for (let includedKeys = keys.length; includedKeys > 0; includedKeys--) {
|
|
const serialized = keys.slice(0, includedKeys).join(", ");
|
|
if (serialized.length > maxLength) {
|
|
continue;
|
|
}
|
|
if (includedKeys === keys.length) {
|
|
return serialized;
|
|
}
|
|
return truncate(serialized, maxLength);
|
|
}
|
|
return "";
|
|
}
|
|
function dropUndefinedKeys(inputValue) {
|
|
const memoizationMap = /* @__PURE__ */ new Map();
|
|
return _dropUndefinedKeys(inputValue, memoizationMap);
|
|
}
|
|
function _dropUndefinedKeys(inputValue, memoizationMap) {
|
|
if (isPlainObject(inputValue)) {
|
|
const memoVal = memoizationMap.get(inputValue);
|
|
if (memoVal !== void 0) {
|
|
return memoVal;
|
|
}
|
|
const returnValue = {};
|
|
memoizationMap.set(inputValue, returnValue);
|
|
for (const key of Object.keys(inputValue)) {
|
|
if (typeof inputValue[key] !== "undefined") {
|
|
returnValue[key] = _dropUndefinedKeys(inputValue[key], memoizationMap);
|
|
}
|
|
}
|
|
return returnValue;
|
|
}
|
|
if (Array.isArray(inputValue)) {
|
|
const memoVal = memoizationMap.get(inputValue);
|
|
if (memoVal !== void 0) {
|
|
return memoVal;
|
|
}
|
|
const returnValue = [];
|
|
memoizationMap.set(inputValue, returnValue);
|
|
inputValue.forEach((item) => {
|
|
returnValue.push(_dropUndefinedKeys(item, memoizationMap));
|
|
});
|
|
return returnValue;
|
|
}
|
|
return inputValue;
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/buildPolyfills/_optionalChain.js
|
|
function _optionalChain(ops) {
|
|
let lastAccessLHS = void 0;
|
|
let value = ops[0];
|
|
let i = 1;
|
|
while (i < ops.length) {
|
|
const op = ops[i];
|
|
const fn = ops[i + 1];
|
|
i += 2;
|
|
if ((op === "optionalAccess" || op === "optionalCall") && value == null) {
|
|
return;
|
|
}
|
|
if (op === "access" || op === "optionalAccess") {
|
|
lastAccessLHS = value;
|
|
value = fn(value);
|
|
} else if (op === "call" || op === "optionalCall") {
|
|
value = fn((...args) => value.call(lastAccessLHS, ...args));
|
|
lastAccessLHS = void 0;
|
|
}
|
|
}
|
|
return value;
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/stacktrace.js
|
|
var STACKTRACE_LIMIT = 50;
|
|
function createStackParser(...parsers) {
|
|
const sortedParsers = parsers.sort((a, b) => a[0] - b[0]).map((p) => p[1]);
|
|
return (stack, skipFirst = 0) => {
|
|
const frames = [];
|
|
for (const line of stack.split("\n").slice(skipFirst)) {
|
|
const cleanedLine = line.replace(/\(error: (.*)\)/, "$1");
|
|
for (const parser of sortedParsers) {
|
|
const frame = parser(cleanedLine);
|
|
if (frame) {
|
|
frames.push(frame);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return stripSentryFramesAndReverse(frames);
|
|
};
|
|
}
|
|
function stackParserFromStackParserOptions(stackParser) {
|
|
if (Array.isArray(stackParser)) {
|
|
return createStackParser(...stackParser);
|
|
}
|
|
return stackParser;
|
|
}
|
|
function stripSentryFramesAndReverse(stack) {
|
|
if (!stack.length) {
|
|
return [];
|
|
}
|
|
let localStack = stack;
|
|
const firstFrameFunction = localStack[0].function || "";
|
|
const lastFrameFunction = localStack[localStack.length - 1].function || "";
|
|
if (firstFrameFunction.indexOf("captureMessage") !== -1 || firstFrameFunction.indexOf("captureException") !== -1) {
|
|
localStack = localStack.slice(1);
|
|
}
|
|
if (lastFrameFunction.indexOf("sentryWrapped") !== -1) {
|
|
localStack = localStack.slice(0, -1);
|
|
}
|
|
return localStack.slice(0, STACKTRACE_LIMIT).map((frame) => ({
|
|
...frame,
|
|
filename: frame.filename || localStack[0].filename,
|
|
function: frame.function || "?"
|
|
})).reverse();
|
|
}
|
|
var defaultFunctionName = "<anonymous>";
|
|
function getFunctionName(fn) {
|
|
try {
|
|
if (!fn || typeof fn !== "function") {
|
|
return defaultFunctionName;
|
|
}
|
|
return fn.name || defaultFunctionName;
|
|
} catch (e) {
|
|
return defaultFunctionName;
|
|
}
|
|
}
|
|
function node(getModule2) {
|
|
const FILENAME_MATCH = /^\s*[-]{4,}$/;
|
|
const FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/;
|
|
return (line) => {
|
|
if (line.match(FILENAME_MATCH)) {
|
|
return {
|
|
filename: line
|
|
};
|
|
}
|
|
const lineMatch = line.match(FULL_MATCH);
|
|
if (!lineMatch) {
|
|
return void 0;
|
|
}
|
|
let object;
|
|
let method;
|
|
let functionName;
|
|
let typeName;
|
|
let methodName;
|
|
if (lineMatch[1]) {
|
|
functionName = lineMatch[1];
|
|
let methodStart = functionName.lastIndexOf(".");
|
|
if (functionName[methodStart - 1] === ".") {
|
|
methodStart--;
|
|
}
|
|
if (methodStart > 0) {
|
|
object = functionName.substr(0, methodStart);
|
|
method = functionName.substr(methodStart + 1);
|
|
const objectEnd = object.indexOf(".Module");
|
|
if (objectEnd > 0) {
|
|
functionName = functionName.substr(objectEnd + 1);
|
|
object = object.substr(0, objectEnd);
|
|
}
|
|
}
|
|
typeName = void 0;
|
|
}
|
|
if (method) {
|
|
typeName = object;
|
|
methodName = method;
|
|
}
|
|
if (method === "<anonymous>") {
|
|
methodName = void 0;
|
|
functionName = void 0;
|
|
}
|
|
if (functionName === void 0) {
|
|
methodName = methodName || "<anonymous>";
|
|
functionName = typeName ? `${typeName}.${methodName}` : methodName;
|
|
}
|
|
const filename = _optionalChain([lineMatch, "access", (_) => _[2], "optionalAccess", (_2) => _2.startsWith, "call", (_3) => _3("file://")]) ? lineMatch[2].substr(7) : lineMatch[2];
|
|
const isNative = lineMatch[5] === "native";
|
|
const isInternal = isNative || filename && !filename.startsWith("/") && !filename.startsWith(".") && filename.indexOf(":\\") !== 1;
|
|
const in_app = !isInternal && filename !== void 0 && !filename.includes("node_modules/");
|
|
return {
|
|
filename,
|
|
module: _optionalChain([getModule2, "optionalCall", (_4) => _4(filename)]),
|
|
function: functionName,
|
|
lineno: parseInt(lineMatch[3], 10) || void 0,
|
|
colno: parseInt(lineMatch[4], 10) || void 0,
|
|
in_app
|
|
};
|
|
};
|
|
}
|
|
function nodeStackLineParser(getModule2) {
|
|
return [90, node(getModule2)];
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/memo.js
|
|
function memoBuilder() {
|
|
const hasWeakSet = typeof WeakSet === "function";
|
|
const inner = hasWeakSet ? /* @__PURE__ */ new WeakSet() : [];
|
|
function memoize(obj) {
|
|
if (hasWeakSet) {
|
|
if (inner.has(obj)) {
|
|
return true;
|
|
}
|
|
inner.add(obj);
|
|
return false;
|
|
}
|
|
for (let i = 0; i < inner.length; i++) {
|
|
const value = inner[i];
|
|
if (value === obj) {
|
|
return true;
|
|
}
|
|
}
|
|
inner.push(obj);
|
|
return false;
|
|
}
|
|
function unmemoize(obj) {
|
|
if (hasWeakSet) {
|
|
inner.delete(obj);
|
|
} else {
|
|
for (let i = 0; i < inner.length; i++) {
|
|
if (inner[i] === obj) {
|
|
inner.splice(i, 1);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return [memoize, unmemoize];
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/misc.js
|
|
function uuid4() {
|
|
const gbl = GLOBAL_OBJ;
|
|
const crypto = gbl.crypto || gbl.msCrypto;
|
|
if (crypto && crypto.randomUUID) {
|
|
return crypto.randomUUID().replace(/-/g, "");
|
|
}
|
|
const getRandomByte = crypto && crypto.getRandomValues ? () => crypto.getRandomValues(new Uint8Array(1))[0] : () => Math.random() * 16;
|
|
return ([1e7] + 1e3 + 4e3 + 8e3 + 1e11).replace(
|
|
/[018]/g,
|
|
(c) => (
|
|
// eslint-disable-next-line no-bitwise
|
|
(c ^ (getRandomByte() & 15) >> c / 4).toString(16)
|
|
)
|
|
);
|
|
}
|
|
function getFirstException(event) {
|
|
return event.exception && event.exception.values ? event.exception.values[0] : void 0;
|
|
}
|
|
function addExceptionTypeValue(event, value, type) {
|
|
const exception = event.exception = event.exception || {};
|
|
const values = exception.values = exception.values || [];
|
|
const firstException = values[0] = values[0] || {};
|
|
if (!firstException.value) {
|
|
firstException.value = value || "";
|
|
}
|
|
if (!firstException.type) {
|
|
firstException.type = type || "Error";
|
|
}
|
|
}
|
|
function addExceptionMechanism(event, newMechanism) {
|
|
const firstException = getFirstException(event);
|
|
if (!firstException) {
|
|
return;
|
|
}
|
|
const defaultMechanism = { type: "generic", handled: true };
|
|
const currentMechanism = firstException.mechanism;
|
|
firstException.mechanism = { ...defaultMechanism, ...currentMechanism, ...newMechanism };
|
|
if (newMechanism && "data" in newMechanism) {
|
|
const mergedData = { ...currentMechanism && currentMechanism.data, ...newMechanism.data };
|
|
firstException.mechanism.data = mergedData;
|
|
}
|
|
}
|
|
function checkOrSetAlreadyCaught(exception) {
|
|
if (exception && exception.__sentry_captured__) {
|
|
return true;
|
|
}
|
|
try {
|
|
addNonEnumerableProperty(exception, "__sentry_captured__", true);
|
|
} catch (err) {
|
|
}
|
|
return false;
|
|
}
|
|
function arrayify(maybeArray) {
|
|
return Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/env.js
|
|
function isBrowserBundle() {
|
|
return typeof __SENTRY_BROWSER_BUNDLE__ !== "undefined" && !!__SENTRY_BROWSER_BUNDLE__;
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/node.js
|
|
function isNodeEnv() {
|
|
return !isBrowserBundle() && Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]";
|
|
}
|
|
function dynamicRequire(mod, request) {
|
|
return mod.require(request);
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/normalize.js
|
|
function normalize(input, depth = Infinity, maxProperties = Infinity) {
|
|
try {
|
|
return visit("", input, depth, maxProperties);
|
|
} catch (err) {
|
|
return { ERROR: `**non-serializable** (${err})` };
|
|
}
|
|
}
|
|
function normalizeToSize(object, depth = 3, maxSize = 100 * 1024) {
|
|
const normalized = normalize(object, depth);
|
|
if (jsonSize(normalized) > maxSize) {
|
|
return normalizeToSize(object, depth - 1, maxSize);
|
|
}
|
|
return normalized;
|
|
}
|
|
function visit(key, value, depth = Infinity, maxProperties = Infinity, memo = memoBuilder()) {
|
|
const [memoize, unmemoize] = memo;
|
|
if (value === null || ["number", "boolean", "string"].includes(typeof value) && !isNaN2(value)) {
|
|
return value;
|
|
}
|
|
const stringified = stringifyValue(key, value);
|
|
if (!stringified.startsWith("[object ")) {
|
|
return stringified;
|
|
}
|
|
if (value["__sentry_skip_normalization__"]) {
|
|
return value;
|
|
}
|
|
if (depth === 0) {
|
|
return stringified.replace("object ", "");
|
|
}
|
|
if (memoize(value)) {
|
|
return "[Circular ~]";
|
|
}
|
|
const valueWithToJSON = value;
|
|
if (valueWithToJSON && typeof valueWithToJSON.toJSON === "function") {
|
|
try {
|
|
const jsonValue = valueWithToJSON.toJSON();
|
|
return visit("", jsonValue, depth - 1, maxProperties, memo);
|
|
} catch (err) {
|
|
}
|
|
}
|
|
const normalized = Array.isArray(value) ? [] : {};
|
|
let numAdded = 0;
|
|
const visitable = convertToPlainObject(value);
|
|
for (const visitKey in visitable) {
|
|
if (!Object.prototype.hasOwnProperty.call(visitable, visitKey)) {
|
|
continue;
|
|
}
|
|
if (numAdded >= maxProperties) {
|
|
normalized[visitKey] = "[MaxProperties ~]";
|
|
break;
|
|
}
|
|
const visitValue = visitable[visitKey];
|
|
normalized[visitKey] = visit(visitKey, visitValue, depth - 1, maxProperties, memo);
|
|
numAdded++;
|
|
}
|
|
unmemoize(value);
|
|
return normalized;
|
|
}
|
|
function stringifyValue(key, value) {
|
|
try {
|
|
if (key === "domain" && value && typeof value === "object" && value._events) {
|
|
return "[Domain]";
|
|
}
|
|
if (key === "domainEmitter") {
|
|
return "[DomainEmitter]";
|
|
}
|
|
if (typeof global !== "undefined" && value === global) {
|
|
return "[Global]";
|
|
}
|
|
if (typeof window !== "undefined" && value === window) {
|
|
return "[Window]";
|
|
}
|
|
if (typeof document !== "undefined" && value === document) {
|
|
return "[Document]";
|
|
}
|
|
if (isSyntheticEvent(value)) {
|
|
return "[SyntheticEvent]";
|
|
}
|
|
if (typeof value === "number" && value !== value) {
|
|
return "[NaN]";
|
|
}
|
|
if (value === void 0) {
|
|
return "[undefined]";
|
|
}
|
|
if (typeof value === "function") {
|
|
return `[Function: ${getFunctionName(value)}]`;
|
|
}
|
|
if (typeof value === "symbol") {
|
|
return `[${String(value)}]`;
|
|
}
|
|
if (typeof value === "bigint") {
|
|
return `[BigInt: ${String(value)}]`;
|
|
}
|
|
return `[object ${Object.getPrototypeOf(value).constructor.name}]`;
|
|
} catch (err) {
|
|
return `**non-serializable** (${err})`;
|
|
}
|
|
}
|
|
function utf8Length(value) {
|
|
return ~-encodeURI(value).split(/%..|./).length;
|
|
}
|
|
function jsonSize(value) {
|
|
return utf8Length(JSON.stringify(value));
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/path.js
|
|
var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^/]+?|)(\.[^./]*|))(?:[/]*)$/;
|
|
function splitPath(filename) {
|
|
const parts = splitPathRe.exec(filename);
|
|
return parts ? parts.slice(1) : [];
|
|
}
|
|
function basename(path, ext) {
|
|
let f = splitPath(path)[2];
|
|
if (ext && f.substr(ext.length * -1) === ext) {
|
|
f = f.substr(0, f.length - ext.length);
|
|
}
|
|
return f;
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/syncpromise.js
|
|
var States;
|
|
(function(States2) {
|
|
const PENDING = 0;
|
|
States2[States2["PENDING"] = PENDING] = "PENDING";
|
|
const RESOLVED = 1;
|
|
States2[States2["RESOLVED"] = RESOLVED] = "RESOLVED";
|
|
const REJECTED = 2;
|
|
States2[States2["REJECTED"] = REJECTED] = "REJECTED";
|
|
})(States || (States = {}));
|
|
function resolvedSyncPromise(value) {
|
|
return new SyncPromise((resolve2) => {
|
|
resolve2(value);
|
|
});
|
|
}
|
|
function rejectedSyncPromise(reason) {
|
|
return new SyncPromise((_, reject) => {
|
|
reject(reason);
|
|
});
|
|
}
|
|
var SyncPromise = class {
|
|
__init() {
|
|
this._state = States.PENDING;
|
|
}
|
|
__init2() {
|
|
this._handlers = [];
|
|
}
|
|
constructor(executor) {
|
|
;
|
|
SyncPromise.prototype.__init.call(this);
|
|
SyncPromise.prototype.__init2.call(this);
|
|
SyncPromise.prototype.__init3.call(this);
|
|
SyncPromise.prototype.__init4.call(this);
|
|
SyncPromise.prototype.__init5.call(this);
|
|
SyncPromise.prototype.__init6.call(this);
|
|
try {
|
|
executor(this._resolve, this._reject);
|
|
} catch (e) {
|
|
this._reject(e);
|
|
}
|
|
}
|
|
/** JSDoc */
|
|
then(onfulfilled, onrejected) {
|
|
return new SyncPromise((resolve2, reject) => {
|
|
this._handlers.push([
|
|
false,
|
|
(result) => {
|
|
if (!onfulfilled) {
|
|
resolve2(result);
|
|
} else {
|
|
try {
|
|
resolve2(onfulfilled(result));
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
}
|
|
},
|
|
(reason) => {
|
|
if (!onrejected) {
|
|
reject(reason);
|
|
} else {
|
|
try {
|
|
resolve2(onrejected(reason));
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
}
|
|
}
|
|
]);
|
|
this._executeHandlers();
|
|
});
|
|
}
|
|
/** JSDoc */
|
|
catch(onrejected) {
|
|
return this.then((val) => val, onrejected);
|
|
}
|
|
/** JSDoc */
|
|
finally(onfinally) {
|
|
return new SyncPromise((resolve2, reject) => {
|
|
let val;
|
|
let isRejected;
|
|
return this.then(
|
|
(value) => {
|
|
isRejected = false;
|
|
val = value;
|
|
if (onfinally) {
|
|
onfinally();
|
|
}
|
|
},
|
|
(reason) => {
|
|
isRejected = true;
|
|
val = reason;
|
|
if (onfinally) {
|
|
onfinally();
|
|
}
|
|
}
|
|
).then(() => {
|
|
if (isRejected) {
|
|
reject(val);
|
|
return;
|
|
}
|
|
resolve2(val);
|
|
});
|
|
});
|
|
}
|
|
/** JSDoc */
|
|
__init3() {
|
|
this._resolve = (value) => {
|
|
this._setResult(States.RESOLVED, value);
|
|
};
|
|
}
|
|
/** JSDoc */
|
|
__init4() {
|
|
this._reject = (reason) => {
|
|
this._setResult(States.REJECTED, reason);
|
|
};
|
|
}
|
|
/** JSDoc */
|
|
__init5() {
|
|
this._setResult = (state, value) => {
|
|
if (this._state !== States.PENDING) {
|
|
return;
|
|
}
|
|
if (isThenable(value)) {
|
|
void value.then(this._resolve, this._reject);
|
|
return;
|
|
}
|
|
this._state = state;
|
|
this._value = value;
|
|
this._executeHandlers();
|
|
};
|
|
}
|
|
/** JSDoc */
|
|
__init6() {
|
|
this._executeHandlers = () => {
|
|
if (this._state === States.PENDING) {
|
|
return;
|
|
}
|
|
const cachedHandlers = this._handlers.slice();
|
|
this._handlers = [];
|
|
cachedHandlers.forEach((handler2) => {
|
|
if (handler2[0]) {
|
|
return;
|
|
}
|
|
if (this._state === States.RESOLVED) {
|
|
handler2[1](this._value);
|
|
}
|
|
if (this._state === States.REJECTED) {
|
|
handler2[2](this._value);
|
|
}
|
|
handler2[0] = true;
|
|
});
|
|
};
|
|
}
|
|
};
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/promisebuffer.js
|
|
function makePromiseBuffer(limit) {
|
|
const buffer = [];
|
|
function isReady() {
|
|
return limit === void 0 || buffer.length < limit;
|
|
}
|
|
function remove(task) {
|
|
return buffer.splice(buffer.indexOf(task), 1)[0];
|
|
}
|
|
function add(taskProducer) {
|
|
if (!isReady()) {
|
|
return rejectedSyncPromise(new SentryError("Not adding Promise because buffer limit was reached."));
|
|
}
|
|
const task = taskProducer();
|
|
if (buffer.indexOf(task) === -1) {
|
|
buffer.push(task);
|
|
}
|
|
void task.then(() => remove(task)).then(
|
|
null,
|
|
() => remove(task).then(null, () => {
|
|
})
|
|
);
|
|
return task;
|
|
}
|
|
function drain(timeout) {
|
|
return new SyncPromise((resolve2, reject) => {
|
|
let counter = buffer.length;
|
|
if (!counter) {
|
|
return resolve2(true);
|
|
}
|
|
const capturedSetTimeout = setTimeout(() => {
|
|
if (timeout && timeout > 0) {
|
|
resolve2(false);
|
|
}
|
|
}, timeout);
|
|
buffer.forEach((item) => {
|
|
void resolvedSyncPromise(item).then(() => {
|
|
if (!--counter) {
|
|
clearTimeout(capturedSetTimeout);
|
|
resolve2(true);
|
|
}
|
|
}, reject);
|
|
});
|
|
});
|
|
}
|
|
return {
|
|
$: buffer,
|
|
add,
|
|
drain
|
|
};
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/time.js
|
|
var WINDOW2 = getGlobalObject();
|
|
var dateTimestampSource = {
|
|
nowSeconds: () => Date.now() / 1e3
|
|
};
|
|
function getBrowserPerformance() {
|
|
const { performance } = WINDOW2;
|
|
if (!performance || !performance.now) {
|
|
return void 0;
|
|
}
|
|
const timeOrigin = Date.now() - performance.now();
|
|
return {
|
|
now: () => performance.now(),
|
|
timeOrigin
|
|
};
|
|
}
|
|
function getNodePerformance() {
|
|
try {
|
|
const perfHooks = dynamicRequire(module, "perf_hooks");
|
|
return perfHooks.performance;
|
|
} catch (_) {
|
|
return void 0;
|
|
}
|
|
}
|
|
var platformPerformance = isNodeEnv() ? getNodePerformance() : getBrowserPerformance();
|
|
var timestampSource = platformPerformance === void 0 ? dateTimestampSource : {
|
|
nowSeconds: () => (platformPerformance.timeOrigin + platformPerformance.now()) / 1e3
|
|
};
|
|
var dateTimestampInSeconds = dateTimestampSource.nowSeconds.bind(dateTimestampSource);
|
|
var timestampInSeconds = timestampSource.nowSeconds.bind(timestampSource);
|
|
var _browserPerformanceTimeOriginMode;
|
|
var browserPerformanceTimeOrigin = (() => {
|
|
const { performance } = WINDOW2;
|
|
if (!performance || !performance.now) {
|
|
_browserPerformanceTimeOriginMode = "none";
|
|
return void 0;
|
|
}
|
|
const threshold = 3600 * 1e3;
|
|
const performanceNow = performance.now();
|
|
const dateNow = Date.now();
|
|
const timeOriginDelta = performance.timeOrigin ? Math.abs(performance.timeOrigin + performanceNow - dateNow) : threshold;
|
|
const timeOriginIsReliable = timeOriginDelta < threshold;
|
|
const navigationStart = performance.timing && performance.timing.navigationStart;
|
|
const hasNavigationStart = typeof navigationStart === "number";
|
|
const navigationStartDelta = hasNavigationStart ? Math.abs(navigationStart + performanceNow - dateNow) : threshold;
|
|
const navigationStartIsReliable = navigationStartDelta < threshold;
|
|
if (timeOriginIsReliable || navigationStartIsReliable) {
|
|
if (timeOriginDelta <= navigationStartDelta) {
|
|
_browserPerformanceTimeOriginMode = "timeOrigin";
|
|
return performance.timeOrigin;
|
|
} else {
|
|
_browserPerformanceTimeOriginMode = "navigationStart";
|
|
return navigationStart;
|
|
}
|
|
}
|
|
_browserPerformanceTimeOriginMode = "dateNow";
|
|
return dateNow;
|
|
})();
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/envelope.js
|
|
function createEnvelope(headers, items = []) {
|
|
return [headers, items];
|
|
}
|
|
function addItemToEnvelope(envelope, newItem) {
|
|
const [headers, items] = envelope;
|
|
return [headers, [...items, newItem]];
|
|
}
|
|
function forEachEnvelopeItem(envelope, callback) {
|
|
const envelopeItems = envelope[1];
|
|
envelopeItems.forEach((envelopeItem) => {
|
|
const envelopeItemType = envelopeItem[0].type;
|
|
callback(envelopeItem, envelopeItemType);
|
|
});
|
|
}
|
|
function encodeUTF8(input, textEncoder) {
|
|
const utf8 = textEncoder || new TextEncoder();
|
|
return utf8.encode(input);
|
|
}
|
|
function serializeEnvelope(envelope, textEncoder) {
|
|
const [envHeaders, items] = envelope;
|
|
let parts = JSON.stringify(envHeaders);
|
|
function append(next) {
|
|
if (typeof parts === "string") {
|
|
parts = typeof next === "string" ? parts + next : [encodeUTF8(parts, textEncoder), next];
|
|
} else {
|
|
parts.push(typeof next === "string" ? encodeUTF8(next, textEncoder) : next);
|
|
}
|
|
}
|
|
for (const item of items) {
|
|
const [itemHeaders, payload] = item;
|
|
append(`
|
|
${JSON.stringify(itemHeaders)}
|
|
`);
|
|
if (typeof payload === "string" || payload instanceof Uint8Array) {
|
|
append(payload);
|
|
} else {
|
|
let stringifiedPayload;
|
|
try {
|
|
stringifiedPayload = JSON.stringify(payload);
|
|
} catch (e) {
|
|
stringifiedPayload = JSON.stringify(normalize(payload));
|
|
}
|
|
append(stringifiedPayload);
|
|
}
|
|
}
|
|
return typeof parts === "string" ? parts : concatBuffers(parts);
|
|
}
|
|
function concatBuffers(buffers) {
|
|
const totalLength = buffers.reduce((acc, buf) => acc + buf.length, 0);
|
|
const merged = new Uint8Array(totalLength);
|
|
let offset = 0;
|
|
for (const buffer of buffers) {
|
|
merged.set(buffer, offset);
|
|
offset += buffer.length;
|
|
}
|
|
return merged;
|
|
}
|
|
function createAttachmentEnvelopeItem(attachment, textEncoder) {
|
|
const buffer = typeof attachment.data === "string" ? encodeUTF8(attachment.data, textEncoder) : attachment.data;
|
|
return [
|
|
dropUndefinedKeys({
|
|
type: "attachment",
|
|
length: buffer.length,
|
|
filename: attachment.filename,
|
|
content_type: attachment.contentType,
|
|
attachment_type: attachment.attachmentType
|
|
}),
|
|
buffer
|
|
];
|
|
}
|
|
var ITEM_TYPE_TO_DATA_CATEGORY_MAP = {
|
|
session: "session",
|
|
sessions: "session",
|
|
attachment: "attachment",
|
|
transaction: "transaction",
|
|
event: "error",
|
|
client_report: "internal",
|
|
user_report: "default"
|
|
};
|
|
function envelopeItemTypeToDataCategory(type) {
|
|
return ITEM_TYPE_TO_DATA_CATEGORY_MAP[type];
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/utils/esm/ratelimit.js
|
|
var DEFAULT_RETRY_AFTER = 60 * 1e3;
|
|
function parseRetryAfterHeader(header, now = Date.now()) {
|
|
const headerDelay = parseInt(`${header}`, 10);
|
|
if (!isNaN(headerDelay)) {
|
|
return headerDelay * 1e3;
|
|
}
|
|
const headerDate = Date.parse(`${header}`);
|
|
if (!isNaN(headerDate)) {
|
|
return headerDate - now;
|
|
}
|
|
return DEFAULT_RETRY_AFTER;
|
|
}
|
|
function disabledUntil(limits, category) {
|
|
return limits[category] || limits.all || 0;
|
|
}
|
|
function isRateLimited(limits, category, now = Date.now()) {
|
|
return disabledUntil(limits, category) > now;
|
|
}
|
|
function updateRateLimits(limits, { statusCode, headers }, now = Date.now()) {
|
|
const updatedRateLimits = {
|
|
...limits
|
|
};
|
|
const rateLimitHeader = headers && headers["x-sentry-rate-limits"];
|
|
const retryAfterHeader = headers && headers["retry-after"];
|
|
if (rateLimitHeader) {
|
|
for (const limit of rateLimitHeader.trim().split(",")) {
|
|
const [retryAfter, categories] = limit.split(":", 2);
|
|
const headerDelay = parseInt(retryAfter, 10);
|
|
const delay = (!isNaN(headerDelay) ? headerDelay : 60) * 1e3;
|
|
if (!categories) {
|
|
updatedRateLimits.all = now + delay;
|
|
} else {
|
|
for (const category of categories.split(";")) {
|
|
updatedRateLimits[category] = now + delay;
|
|
}
|
|
}
|
|
}
|
|
} else if (retryAfterHeader) {
|
|
updatedRateLimits.all = now + parseRetryAfterHeader(retryAfterHeader, now);
|
|
} else if (statusCode === 429) {
|
|
updatedRateLimits.all = now + 60 * 1e3;
|
|
}
|
|
return updatedRateLimits;
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/core/esm/session.js
|
|
function makeSession(context) {
|
|
const startingTime = timestampInSeconds();
|
|
const session = {
|
|
sid: uuid4(),
|
|
init: true,
|
|
timestamp: startingTime,
|
|
started: startingTime,
|
|
duration: 0,
|
|
status: "ok",
|
|
errors: 0,
|
|
ignoreDuration: false,
|
|
toJSON: () => sessionToJSON(session)
|
|
};
|
|
if (context) {
|
|
updateSession(session, context);
|
|
}
|
|
return session;
|
|
}
|
|
function updateSession(session, context = {}) {
|
|
if (context.user) {
|
|
if (!session.ipAddress && context.user.ip_address) {
|
|
session.ipAddress = context.user.ip_address;
|
|
}
|
|
if (!session.did && !context.did) {
|
|
session.did = context.user.id || context.user.email || context.user.username;
|
|
}
|
|
}
|
|
session.timestamp = context.timestamp || timestampInSeconds();
|
|
if (context.ignoreDuration) {
|
|
session.ignoreDuration = context.ignoreDuration;
|
|
}
|
|
if (context.sid) {
|
|
session.sid = context.sid.length === 32 ? context.sid : uuid4();
|
|
}
|
|
if (context.init !== void 0) {
|
|
session.init = context.init;
|
|
}
|
|
if (!session.did && context.did) {
|
|
session.did = `${context.did}`;
|
|
}
|
|
if (typeof context.started === "number") {
|
|
session.started = context.started;
|
|
}
|
|
if (session.ignoreDuration) {
|
|
session.duration = void 0;
|
|
} else if (typeof context.duration === "number") {
|
|
session.duration = context.duration;
|
|
} else {
|
|
const duration = session.timestamp - session.started;
|
|
session.duration = duration >= 0 ? duration : 0;
|
|
}
|
|
if (context.release) {
|
|
session.release = context.release;
|
|
}
|
|
if (context.environment) {
|
|
session.environment = context.environment;
|
|
}
|
|
if (!session.ipAddress && context.ipAddress) {
|
|
session.ipAddress = context.ipAddress;
|
|
}
|
|
if (!session.userAgent && context.userAgent) {
|
|
session.userAgent = context.userAgent;
|
|
}
|
|
if (typeof context.errors === "number") {
|
|
session.errors = context.errors;
|
|
}
|
|
if (context.status) {
|
|
session.status = context.status;
|
|
}
|
|
}
|
|
function closeSession(session, status) {
|
|
let context = {};
|
|
if (status) {
|
|
context = { status };
|
|
} else if (session.status === "ok") {
|
|
context = { status: "exited" };
|
|
}
|
|
updateSession(session, context);
|
|
}
|
|
function sessionToJSON(session) {
|
|
return dropUndefinedKeys({
|
|
sid: `${session.sid}`,
|
|
init: session.init,
|
|
// Make sure that sec is converted to ms for date constructor
|
|
started: new Date(session.started * 1e3).toISOString(),
|
|
timestamp: new Date(session.timestamp * 1e3).toISOString(),
|
|
status: session.status,
|
|
errors: session.errors,
|
|
did: typeof session.did === "number" || typeof session.did === "string" ? `${session.did}` : void 0,
|
|
duration: session.duration,
|
|
attrs: {
|
|
release: session.release,
|
|
environment: session.environment,
|
|
ip_address: session.ipAddress,
|
|
user_agent: session.userAgent
|
|
}
|
|
});
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/core/esm/scope.js
|
|
var DEFAULT_MAX_BREADCRUMBS = 100;
|
|
var Scope = class {
|
|
/** Flag if notifying is happening. */
|
|
/** Callback for client to receive scope changes. */
|
|
/** Callback list that will be called after {@link applyToEvent}. */
|
|
/** Array of breadcrumbs. */
|
|
/** User */
|
|
/** Tags */
|
|
/** Extra */
|
|
/** Contexts */
|
|
/** Attachments */
|
|
/**
|
|
* A place to stash data which is needed at some point in the SDK's event processing pipeline but which shouldn't get
|
|
* sent to Sentry
|
|
*/
|
|
/** Fingerprint */
|
|
/** Severity */
|
|
// eslint-disable-next-line deprecation/deprecation
|
|
/** Transaction Name */
|
|
/** Span */
|
|
/** Session */
|
|
/** Request Mode Session Status */
|
|
// NOTE: Any field which gets added here should get added not only to the constructor but also to the `clone` method.
|
|
constructor() {
|
|
this._notifyingListeners = false;
|
|
this._scopeListeners = [];
|
|
this._eventProcessors = [];
|
|
this._breadcrumbs = [];
|
|
this._attachments = [];
|
|
this._user = {};
|
|
this._tags = {};
|
|
this._extra = {};
|
|
this._contexts = {};
|
|
this._sdkProcessingMetadata = {};
|
|
}
|
|
/**
|
|
* Inherit values from the parent scope.
|
|
* @param scope to clone.
|
|
*/
|
|
static clone(scope) {
|
|
const newScope = new Scope();
|
|
if (scope) {
|
|
newScope._breadcrumbs = [...scope._breadcrumbs];
|
|
newScope._tags = { ...scope._tags };
|
|
newScope._extra = { ...scope._extra };
|
|
newScope._contexts = { ...scope._contexts };
|
|
newScope._user = scope._user;
|
|
newScope._level = scope._level;
|
|
newScope._span = scope._span;
|
|
newScope._session = scope._session;
|
|
newScope._transactionName = scope._transactionName;
|
|
newScope._fingerprint = scope._fingerprint;
|
|
newScope._eventProcessors = [...scope._eventProcessors];
|
|
newScope._requestSession = scope._requestSession;
|
|
newScope._attachments = [...scope._attachments];
|
|
newScope._sdkProcessingMetadata = { ...scope._sdkProcessingMetadata };
|
|
}
|
|
return newScope;
|
|
}
|
|
/**
|
|
* Add internal on change listener. Used for sub SDKs that need to store the scope.
|
|
* @hidden
|
|
*/
|
|
addScopeListener(callback) {
|
|
this._scopeListeners.push(callback);
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
addEventProcessor(callback) {
|
|
this._eventProcessors.push(callback);
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setUser(user) {
|
|
this._user = user || {};
|
|
if (this._session) {
|
|
updateSession(this._session, { user });
|
|
}
|
|
this._notifyScopeListeners();
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
getUser() {
|
|
return this._user;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
getRequestSession() {
|
|
return this._requestSession;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setRequestSession(requestSession) {
|
|
this._requestSession = requestSession;
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setTags(tags) {
|
|
this._tags = {
|
|
...this._tags,
|
|
...tags
|
|
};
|
|
this._notifyScopeListeners();
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setTag(key, value) {
|
|
this._tags = { ...this._tags, [key]: value };
|
|
this._notifyScopeListeners();
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setExtras(extras) {
|
|
this._extra = {
|
|
...this._extra,
|
|
...extras
|
|
};
|
|
this._notifyScopeListeners();
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setExtra(key, extra) {
|
|
this._extra = { ...this._extra, [key]: extra };
|
|
this._notifyScopeListeners();
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setFingerprint(fingerprint) {
|
|
this._fingerprint = fingerprint;
|
|
this._notifyScopeListeners();
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setLevel(level) {
|
|
this._level = level;
|
|
this._notifyScopeListeners();
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setTransactionName(name) {
|
|
this._transactionName = name;
|
|
this._notifyScopeListeners();
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setContext(key, context) {
|
|
if (context === null) {
|
|
delete this._contexts[key];
|
|
} else {
|
|
this._contexts[key] = context;
|
|
}
|
|
this._notifyScopeListeners();
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setSpan(span) {
|
|
this._span = span;
|
|
this._notifyScopeListeners();
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
getSpan() {
|
|
return this._span;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
getTransaction() {
|
|
const span = this.getSpan();
|
|
return span && span.transaction;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setSession(session) {
|
|
if (!session) {
|
|
delete this._session;
|
|
} else {
|
|
this._session = session;
|
|
}
|
|
this._notifyScopeListeners();
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
getSession() {
|
|
return this._session;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
update(captureContext) {
|
|
if (!captureContext) {
|
|
return this;
|
|
}
|
|
if (typeof captureContext === "function") {
|
|
const updatedScope = captureContext(this);
|
|
return updatedScope instanceof Scope ? updatedScope : this;
|
|
}
|
|
if (captureContext instanceof Scope) {
|
|
this._tags = { ...this._tags, ...captureContext._tags };
|
|
this._extra = { ...this._extra, ...captureContext._extra };
|
|
this._contexts = { ...this._contexts, ...captureContext._contexts };
|
|
if (captureContext._user && Object.keys(captureContext._user).length) {
|
|
this._user = captureContext._user;
|
|
}
|
|
if (captureContext._level) {
|
|
this._level = captureContext._level;
|
|
}
|
|
if (captureContext._fingerprint) {
|
|
this._fingerprint = captureContext._fingerprint;
|
|
}
|
|
if (captureContext._requestSession) {
|
|
this._requestSession = captureContext._requestSession;
|
|
}
|
|
} else if (isPlainObject(captureContext)) {
|
|
captureContext = captureContext;
|
|
this._tags = { ...this._tags, ...captureContext.tags };
|
|
this._extra = { ...this._extra, ...captureContext.extra };
|
|
this._contexts = { ...this._contexts, ...captureContext.contexts };
|
|
if (captureContext.user) {
|
|
this._user = captureContext.user;
|
|
}
|
|
if (captureContext.level) {
|
|
this._level = captureContext.level;
|
|
}
|
|
if (captureContext.fingerprint) {
|
|
this._fingerprint = captureContext.fingerprint;
|
|
}
|
|
if (captureContext.requestSession) {
|
|
this._requestSession = captureContext.requestSession;
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
clear() {
|
|
this._breadcrumbs = [];
|
|
this._tags = {};
|
|
this._extra = {};
|
|
this._user = {};
|
|
this._contexts = {};
|
|
this._level = void 0;
|
|
this._transactionName = void 0;
|
|
this._fingerprint = void 0;
|
|
this._requestSession = void 0;
|
|
this._span = void 0;
|
|
this._session = void 0;
|
|
this._notifyScopeListeners();
|
|
this._attachments = [];
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
addBreadcrumb(breadcrumb, maxBreadcrumbs) {
|
|
const maxCrumbs = typeof maxBreadcrumbs === "number" ? maxBreadcrumbs : DEFAULT_MAX_BREADCRUMBS;
|
|
if (maxCrumbs <= 0) {
|
|
return this;
|
|
}
|
|
const mergedBreadcrumb = {
|
|
timestamp: dateTimestampInSeconds(),
|
|
...breadcrumb
|
|
};
|
|
this._breadcrumbs = [...this._breadcrumbs, mergedBreadcrumb].slice(-maxCrumbs);
|
|
this._notifyScopeListeners();
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
clearBreadcrumbs() {
|
|
this._breadcrumbs = [];
|
|
this._notifyScopeListeners();
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
addAttachment(attachment) {
|
|
this._attachments.push(attachment);
|
|
return this;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
getAttachments() {
|
|
return this._attachments;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
clearAttachments() {
|
|
this._attachments = [];
|
|
return this;
|
|
}
|
|
/**
|
|
* Applies data from the scope to the event and runs all event processors on it.
|
|
*
|
|
* @param event Event
|
|
* @param hint Object containing additional information about the original exception, for use by the event processors.
|
|
* @hidden
|
|
*/
|
|
applyToEvent(event, hint = {}) {
|
|
if (this._extra && Object.keys(this._extra).length) {
|
|
event.extra = { ...this._extra, ...event.extra };
|
|
}
|
|
if (this._tags && Object.keys(this._tags).length) {
|
|
event.tags = { ...this._tags, ...event.tags };
|
|
}
|
|
if (this._user && Object.keys(this._user).length) {
|
|
event.user = { ...this._user, ...event.user };
|
|
}
|
|
if (this._contexts && Object.keys(this._contexts).length) {
|
|
event.contexts = { ...this._contexts, ...event.contexts };
|
|
}
|
|
if (this._level) {
|
|
event.level = this._level;
|
|
}
|
|
if (this._transactionName) {
|
|
event.transaction = this._transactionName;
|
|
}
|
|
if (this._span) {
|
|
event.contexts = { trace: this._span.getTraceContext(), ...event.contexts };
|
|
const transactionName = this._span.transaction && this._span.transaction.name;
|
|
if (transactionName) {
|
|
event.tags = { transaction: transactionName, ...event.tags };
|
|
}
|
|
}
|
|
this._applyFingerprint(event);
|
|
event.breadcrumbs = [...event.breadcrumbs || [], ...this._breadcrumbs];
|
|
event.breadcrumbs = event.breadcrumbs.length > 0 ? event.breadcrumbs : void 0;
|
|
event.sdkProcessingMetadata = { ...event.sdkProcessingMetadata, ...this._sdkProcessingMetadata };
|
|
return this._notifyEventProcessors([...getGlobalEventProcessors(), ...this._eventProcessors], event, hint);
|
|
}
|
|
/**
|
|
* Add data which will be accessible during event processing but won't get sent to Sentry
|
|
*/
|
|
setSDKProcessingMetadata(newData) {
|
|
this._sdkProcessingMetadata = { ...this._sdkProcessingMetadata, ...newData };
|
|
return this;
|
|
}
|
|
/**
|
|
* This will be called after {@link applyToEvent} is finished.
|
|
*/
|
|
_notifyEventProcessors(processors, event, hint, index = 0) {
|
|
return new SyncPromise((resolve2, reject) => {
|
|
const processor = processors[index];
|
|
if (event === null || typeof processor !== "function") {
|
|
resolve2(event);
|
|
} else {
|
|
const result = processor({ ...event }, hint);
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && processor.id && result === null && logger.log(`Event processor "${processor.id}" dropped event`);
|
|
if (isThenable(result)) {
|
|
void result.then((final) => this._notifyEventProcessors(processors, final, hint, index + 1).then(resolve2)).then(null, reject);
|
|
} else {
|
|
void this._notifyEventProcessors(processors, result, hint, index + 1).then(resolve2).then(null, reject);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
/**
|
|
* This will be called on every set call.
|
|
*/
|
|
_notifyScopeListeners() {
|
|
if (!this._notifyingListeners) {
|
|
this._notifyingListeners = true;
|
|
this._scopeListeners.forEach((callback) => {
|
|
callback(this);
|
|
});
|
|
this._notifyingListeners = false;
|
|
}
|
|
}
|
|
/**
|
|
* Applies fingerprint from the scope to the event if there's one,
|
|
* uses message if there's one instead or get rid of empty fingerprint
|
|
*/
|
|
_applyFingerprint(event) {
|
|
event.fingerprint = event.fingerprint ? arrayify(event.fingerprint) : [];
|
|
if (this._fingerprint) {
|
|
event.fingerprint = event.fingerprint.concat(this._fingerprint);
|
|
}
|
|
if (event.fingerprint && !event.fingerprint.length) {
|
|
delete event.fingerprint;
|
|
}
|
|
}
|
|
};
|
|
function getGlobalEventProcessors() {
|
|
return getGlobalSingleton("globalEventProcessors", () => []);
|
|
}
|
|
function addGlobalEventProcessor(callback) {
|
|
getGlobalEventProcessors().push(callback);
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/core/esm/hub.js
|
|
var NIL_EVENT_ID = "00000000000000000000000000000000";
|
|
var API_VERSION = 4;
|
|
var DEFAULT_BREADCRUMBS = 100;
|
|
var Hub = class {
|
|
/** Is a {@link Layer}[] containing the client and scope */
|
|
__init() {
|
|
this._stack = [{}];
|
|
}
|
|
/** Contains the last event id of a captured event. */
|
|
/**
|
|
* Creates a new instance of the hub, will push one {@link Layer} into the
|
|
* internal stack on creation.
|
|
*
|
|
* @param client bound to the hub.
|
|
* @param scope bound to the hub.
|
|
* @param version number, higher number means higher priority.
|
|
*/
|
|
constructor(client, scope = new Scope(), _version = API_VERSION) {
|
|
;
|
|
this._version = _version;
|
|
Hub.prototype.__init.call(this);
|
|
this.getStackTop().scope = scope;
|
|
if (client) {
|
|
this.bindClient(client);
|
|
}
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
isOlderThan(version) {
|
|
return this._version < version;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
bindClient(client) {
|
|
const top = this.getStackTop();
|
|
top.client = client;
|
|
if (client && client.setupIntegrations) {
|
|
client.setupIntegrations();
|
|
}
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
pushScope() {
|
|
const scope = Scope.clone(this.getScope());
|
|
this.getStack().push({
|
|
client: this.getClient(),
|
|
scope
|
|
});
|
|
return scope;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
popScope() {
|
|
if (this.getStack().length <= 1)
|
|
return false;
|
|
return !!this.getStack().pop();
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
withScope(callback) {
|
|
const scope = this.pushScope();
|
|
try {
|
|
callback(scope);
|
|
} finally {
|
|
this.popScope();
|
|
}
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
getClient() {
|
|
return this.getStackTop().client;
|
|
}
|
|
/** Returns the scope of the top stack. */
|
|
getScope() {
|
|
return this.getStackTop().scope;
|
|
}
|
|
/** Returns the scope stack for domains or the process. */
|
|
getStack() {
|
|
return this._stack;
|
|
}
|
|
/** Returns the topmost scope layer in the order domain > local > process. */
|
|
getStackTop() {
|
|
return this._stack[this._stack.length - 1];
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
captureException(exception, hint) {
|
|
const syntheticException = new Error("Sentry syntheticException");
|
|
this._lastEventId = this._withClient((client, scope) => {
|
|
return client.captureException(
|
|
exception,
|
|
{
|
|
originalException: exception,
|
|
syntheticException,
|
|
...hint
|
|
},
|
|
scope
|
|
);
|
|
}) || NIL_EVENT_ID;
|
|
return this._lastEventId;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
captureMessage(message, level, hint) {
|
|
const syntheticException = new Error(message);
|
|
this._lastEventId = this._withClient((client, scope) => {
|
|
return client.captureMessage(
|
|
message,
|
|
level,
|
|
{
|
|
originalException: message,
|
|
syntheticException,
|
|
...hint
|
|
},
|
|
scope
|
|
);
|
|
}) || NIL_EVENT_ID;
|
|
return this._lastEventId;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
captureEvent(event, hint) {
|
|
const clientId = this._withClient((client, scope) => {
|
|
return client.captureEvent(event, { ...hint }, scope);
|
|
}) || NIL_EVENT_ID;
|
|
if (event.type !== "transaction") {
|
|
this._lastEventId = clientId;
|
|
}
|
|
return clientId;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
lastEventId() {
|
|
return this._lastEventId;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
addBreadcrumb(breadcrumb, hint) {
|
|
const { scope, client } = this.getStackTop();
|
|
if (!scope || !client)
|
|
return;
|
|
const { beforeBreadcrumb = null, maxBreadcrumbs = DEFAULT_BREADCRUMBS } = client.getOptions && client.getOptions() || {};
|
|
if (maxBreadcrumbs <= 0)
|
|
return;
|
|
const timestamp = dateTimestampInSeconds();
|
|
const mergedBreadcrumb = { timestamp, ...breadcrumb };
|
|
const finalBreadcrumb = beforeBreadcrumb ? consoleSandbox(() => beforeBreadcrumb(mergedBreadcrumb, hint)) : mergedBreadcrumb;
|
|
if (finalBreadcrumb === null)
|
|
return;
|
|
scope.addBreadcrumb(finalBreadcrumb, maxBreadcrumbs);
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setUser(user) {
|
|
const scope = this.getScope();
|
|
if (scope)
|
|
scope.setUser(user);
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setTags(tags) {
|
|
const scope = this.getScope();
|
|
if (scope)
|
|
scope.setTags(tags);
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setExtras(extras) {
|
|
const scope = this.getScope();
|
|
if (scope)
|
|
scope.setExtras(extras);
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setTag(key, value) {
|
|
const scope = this.getScope();
|
|
if (scope)
|
|
scope.setTag(key, value);
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
setExtra(key, extra) {
|
|
const scope = this.getScope();
|
|
if (scope)
|
|
scope.setExtra(key, extra);
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
setContext(name, context) {
|
|
const scope = this.getScope();
|
|
if (scope)
|
|
scope.setContext(name, context);
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
configureScope(callback) {
|
|
const { scope, client } = this.getStackTop();
|
|
if (scope && client) {
|
|
callback(scope);
|
|
}
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
run(callback) {
|
|
const oldHub = makeMain(this);
|
|
try {
|
|
callback(this);
|
|
} finally {
|
|
makeMain(oldHub);
|
|
}
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
getIntegration(integration) {
|
|
const client = this.getClient();
|
|
if (!client)
|
|
return null;
|
|
try {
|
|
return client.getIntegration(integration);
|
|
} catch (_oO) {
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.warn(`Cannot retrieve integration ${integration.id} from the current Hub`);
|
|
return null;
|
|
}
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
startTransaction(context, customSamplingContext) {
|
|
return this._callExtensionMethod("startTransaction", context, customSamplingContext);
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
traceHeaders() {
|
|
return this._callExtensionMethod("traceHeaders");
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
captureSession(endSession = false) {
|
|
if (endSession) {
|
|
return this.endSession();
|
|
}
|
|
this._sendSessionUpdate();
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
endSession() {
|
|
const layer = this.getStackTop();
|
|
const scope = layer && layer.scope;
|
|
const session = scope && scope.getSession();
|
|
if (session) {
|
|
closeSession(session);
|
|
}
|
|
this._sendSessionUpdate();
|
|
if (scope) {
|
|
scope.setSession();
|
|
}
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
startSession(context) {
|
|
const { scope, client } = this.getStackTop();
|
|
const { release, environment } = client && client.getOptions() || {};
|
|
const { userAgent } = GLOBAL_OBJ.navigator || {};
|
|
const session = makeSession({
|
|
release,
|
|
environment,
|
|
...scope && { user: scope.getUser() },
|
|
...userAgent && { userAgent },
|
|
...context
|
|
});
|
|
if (scope) {
|
|
const currentSession = scope.getSession && scope.getSession();
|
|
if (currentSession && currentSession.status === "ok") {
|
|
updateSession(currentSession, { status: "exited" });
|
|
}
|
|
this.endSession();
|
|
scope.setSession(session);
|
|
}
|
|
return session;
|
|
}
|
|
/**
|
|
* Returns if default PII should be sent to Sentry and propagated in ourgoing requests
|
|
* when Tracing is used.
|
|
*/
|
|
shouldSendDefaultPii() {
|
|
const client = this.getClient();
|
|
const options = client && client.getOptions();
|
|
return Boolean(options && options.sendDefaultPii);
|
|
}
|
|
/**
|
|
* Sends the current Session on the scope
|
|
*/
|
|
_sendSessionUpdate() {
|
|
const { scope, client } = this.getStackTop();
|
|
if (!scope)
|
|
return;
|
|
const session = scope.getSession();
|
|
if (session) {
|
|
if (client && client.captureSession) {
|
|
client.captureSession(session);
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* Internal helper function to call a method on the top client if it exists.
|
|
*
|
|
* @param method The method to call on the client.
|
|
* @param args Arguments to pass to the client function.
|
|
*/
|
|
_withClient(callback) {
|
|
const { scope, client } = this.getStackTop();
|
|
return client && callback(client, scope);
|
|
}
|
|
/**
|
|
* Calls global extension method and binding current instance to the function call
|
|
*/
|
|
// @ts-ignore Function lacks ending return statement and return type does not include 'undefined'. ts(2366)
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
_callExtensionMethod(method, ...args) {
|
|
const carrier = getMainCarrier();
|
|
const sentry = carrier.__SENTRY__;
|
|
if (sentry && sentry.extensions && typeof sentry.extensions[method] === "function") {
|
|
return sentry.extensions[method].apply(this, args);
|
|
}
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.warn(`Extension method ${method} couldn't be found, doing nothing.`);
|
|
}
|
|
};
|
|
function getMainCarrier() {
|
|
GLOBAL_OBJ.__SENTRY__ = GLOBAL_OBJ.__SENTRY__ || {
|
|
extensions: {},
|
|
hub: void 0
|
|
};
|
|
return GLOBAL_OBJ;
|
|
}
|
|
function makeMain(hub) {
|
|
const registry = getMainCarrier();
|
|
const oldHub = getHubFromCarrier(registry);
|
|
setHubOnCarrier(registry, hub);
|
|
return oldHub;
|
|
}
|
|
function getCurrentHub() {
|
|
const registry = getMainCarrier();
|
|
if (!hasHubOnCarrier(registry) || getHubFromCarrier(registry).isOlderThan(API_VERSION)) {
|
|
setHubOnCarrier(registry, new Hub());
|
|
}
|
|
if (isNodeEnv()) {
|
|
return getHubFromActiveDomain(registry);
|
|
}
|
|
return getHubFromCarrier(registry);
|
|
}
|
|
function getHubFromActiveDomain(registry) {
|
|
try {
|
|
const sentry = getMainCarrier().__SENTRY__;
|
|
const activeDomain = sentry && sentry.extensions && sentry.extensions.domain && sentry.extensions.domain.active;
|
|
if (!activeDomain) {
|
|
return getHubFromCarrier(registry);
|
|
}
|
|
if (!hasHubOnCarrier(activeDomain) || getHubFromCarrier(activeDomain).isOlderThan(API_VERSION)) {
|
|
const registryHubTopStack = getHubFromCarrier(registry).getStackTop();
|
|
setHubOnCarrier(activeDomain, new Hub(registryHubTopStack.client, Scope.clone(registryHubTopStack.scope)));
|
|
}
|
|
return getHubFromCarrier(activeDomain);
|
|
} catch (_Oo) {
|
|
return getHubFromCarrier(registry);
|
|
}
|
|
}
|
|
function hasHubOnCarrier(carrier) {
|
|
return !!(carrier && carrier.__SENTRY__ && carrier.__SENTRY__.hub);
|
|
}
|
|
function getHubFromCarrier(carrier) {
|
|
return getGlobalSingleton("hub", () => new Hub(), carrier);
|
|
}
|
|
function setHubOnCarrier(carrier, hub) {
|
|
if (!carrier)
|
|
return false;
|
|
const __SENTRY__ = carrier.__SENTRY__ = carrier.__SENTRY__ || {};
|
|
__SENTRY__.hub = hub;
|
|
return true;
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/core/esm/api.js
|
|
var SENTRY_API_VERSION = "7";
|
|
function getBaseApiEndpoint(dsn) {
|
|
const protocol = dsn.protocol ? `${dsn.protocol}:` : "";
|
|
const port = dsn.port ? `:${dsn.port}` : "";
|
|
return `${protocol}//${dsn.host}${port}${dsn.path ? `/${dsn.path}` : ""}/api/`;
|
|
}
|
|
function _getIngestEndpoint(dsn) {
|
|
return `${getBaseApiEndpoint(dsn)}${dsn.projectId}/envelope/`;
|
|
}
|
|
function _encodedAuth(dsn, sdkInfo) {
|
|
return urlEncode({
|
|
// We send only the minimum set of required information. See
|
|
// https://github.com/getsentry/sentry-javascript/issues/2572.
|
|
sentry_key: dsn.publicKey,
|
|
sentry_version: SENTRY_API_VERSION,
|
|
...sdkInfo && { sentry_client: `${sdkInfo.name}/${sdkInfo.version}` }
|
|
});
|
|
}
|
|
function getEnvelopeEndpointWithUrlEncodedAuth(dsn, tunnelOrOptions = {}) {
|
|
const tunnel = typeof tunnelOrOptions === "string" ? tunnelOrOptions : tunnelOrOptions.tunnel;
|
|
const sdkInfo = typeof tunnelOrOptions === "string" || !tunnelOrOptions._metadata ? void 0 : tunnelOrOptions._metadata.sdk;
|
|
return tunnel ? tunnel : `${_getIngestEndpoint(dsn)}?${_encodedAuth(dsn, sdkInfo)}`;
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/core/esm/envelope.js
|
|
function getSdkMetadataForEnvelopeHeader(metadata) {
|
|
if (!metadata || !metadata.sdk) {
|
|
return;
|
|
}
|
|
const { name, version } = metadata.sdk;
|
|
return { name, version };
|
|
}
|
|
function enhanceEventWithSdkInfo(event, sdkInfo) {
|
|
if (!sdkInfo) {
|
|
return event;
|
|
}
|
|
event.sdk = event.sdk || {};
|
|
event.sdk.name = event.sdk.name || sdkInfo.name;
|
|
event.sdk.version = event.sdk.version || sdkInfo.version;
|
|
event.sdk.integrations = [...event.sdk.integrations || [], ...sdkInfo.integrations || []];
|
|
event.sdk.packages = [...event.sdk.packages || [], ...sdkInfo.packages || []];
|
|
return event;
|
|
}
|
|
function createSessionEnvelope(session, dsn, metadata, tunnel) {
|
|
const sdkInfo = getSdkMetadataForEnvelopeHeader(metadata);
|
|
const envelopeHeaders = {
|
|
sent_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
...sdkInfo && { sdk: sdkInfo },
|
|
...!!tunnel && { dsn: dsnToString(dsn) }
|
|
};
|
|
const envelopeItem = "aggregates" in session ? [{ type: "sessions" }, session] : [{ type: "session" }, session];
|
|
return createEnvelope(envelopeHeaders, [envelopeItem]);
|
|
}
|
|
function createEventEnvelope(event, dsn, metadata, tunnel) {
|
|
const sdkInfo = getSdkMetadataForEnvelopeHeader(metadata);
|
|
const eventType = event.type || "event";
|
|
enhanceEventWithSdkInfo(event, metadata && metadata.sdk);
|
|
const envelopeHeaders = createEventEnvelopeHeaders(event, sdkInfo, tunnel, dsn);
|
|
delete event.sdkProcessingMetadata;
|
|
const eventItem = [{ type: eventType }, event];
|
|
return createEnvelope(envelopeHeaders, [eventItem]);
|
|
}
|
|
function createEventEnvelopeHeaders(event, sdkInfo, tunnel, dsn) {
|
|
const dynamicSamplingContext = event.sdkProcessingMetadata && event.sdkProcessingMetadata.dynamicSamplingContext;
|
|
return {
|
|
event_id: event.event_id,
|
|
sent_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
...sdkInfo && { sdk: sdkInfo },
|
|
...!!tunnel && { dsn: dsnToString(dsn) },
|
|
...event.type === "transaction" && dynamicSamplingContext && {
|
|
trace: dropUndefinedKeys({ ...dynamicSamplingContext })
|
|
}
|
|
};
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/core/esm/integration.js
|
|
var installedIntegrations = [];
|
|
function filterDuplicates(integrations) {
|
|
const integrationsByName = {};
|
|
integrations.forEach((currentInstance) => {
|
|
const { name } = currentInstance;
|
|
const existingInstance = integrationsByName[name];
|
|
if (existingInstance && !existingInstance.isDefaultInstance && currentInstance.isDefaultInstance) {
|
|
return;
|
|
}
|
|
integrationsByName[name] = currentInstance;
|
|
});
|
|
return Object.values(integrationsByName);
|
|
}
|
|
function getIntegrationsToSetup(options) {
|
|
const defaultIntegrations = options.defaultIntegrations || [];
|
|
const userIntegrations = options.integrations;
|
|
defaultIntegrations.forEach((integration) => {
|
|
integration.isDefaultInstance = true;
|
|
});
|
|
let integrations;
|
|
if (Array.isArray(userIntegrations)) {
|
|
integrations = [...defaultIntegrations, ...userIntegrations];
|
|
} else if (typeof userIntegrations === "function") {
|
|
integrations = arrayify(userIntegrations(defaultIntegrations));
|
|
} else {
|
|
integrations = defaultIntegrations;
|
|
}
|
|
const finalIntegrations = filterDuplicates(integrations);
|
|
const debugIndex = finalIntegrations.findIndex((integration) => integration.name === "Debug");
|
|
if (debugIndex !== -1) {
|
|
const [debugInstance] = finalIntegrations.splice(debugIndex, 1);
|
|
finalIntegrations.push(debugInstance);
|
|
}
|
|
return finalIntegrations;
|
|
}
|
|
function setupIntegrations(integrations) {
|
|
const integrationIndex = {};
|
|
integrations.forEach((integration) => {
|
|
integrationIndex[integration.name] = integration;
|
|
if (installedIntegrations.indexOf(integration.name) === -1) {
|
|
integration.setupOnce(addGlobalEventProcessor, getCurrentHub);
|
|
installedIntegrations.push(integration.name);
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.log(`Integration installed: ${integration.name}`);
|
|
}
|
|
});
|
|
return integrationIndex;
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/core/esm/baseclient.js
|
|
var ALREADY_SEEN_ERROR = "Not capturing exception because it's already been captured.";
|
|
var BaseClient = class {
|
|
/** Options passed to the SDK. */
|
|
/** The client Dsn, if specified in options. Without this Dsn, the SDK will be disabled. */
|
|
/** Array of set up integrations. */
|
|
__init() {
|
|
this._integrations = {};
|
|
}
|
|
/** Indicates whether this client's integrations have been set up. */
|
|
__init2() {
|
|
this._integrationsInitialized = false;
|
|
}
|
|
/** Number of calls being processed */
|
|
__init3() {
|
|
this._numProcessing = 0;
|
|
}
|
|
/** Holds flushable */
|
|
__init4() {
|
|
this._outcomes = {};
|
|
}
|
|
/**
|
|
* Initializes this client instance.
|
|
*
|
|
* @param options Options for the client.
|
|
*/
|
|
constructor(options) {
|
|
;
|
|
BaseClient.prototype.__init.call(this);
|
|
BaseClient.prototype.__init2.call(this);
|
|
BaseClient.prototype.__init3.call(this);
|
|
BaseClient.prototype.__init4.call(this);
|
|
this._options = options;
|
|
if (options.dsn) {
|
|
this._dsn = makeDsn(options.dsn);
|
|
const url = getEnvelopeEndpointWithUrlEncodedAuth(this._dsn, options);
|
|
this._transport = options.transport({
|
|
recordDroppedEvent: this.recordDroppedEvent.bind(this),
|
|
...options.transportOptions,
|
|
url
|
|
});
|
|
} else {
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.warn("No DSN provided, client will not do anything.");
|
|
}
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
captureException(exception, hint, scope) {
|
|
if (checkOrSetAlreadyCaught(exception)) {
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.log(ALREADY_SEEN_ERROR);
|
|
return;
|
|
}
|
|
let eventId;
|
|
this._process(
|
|
this.eventFromException(exception, hint).then((event) => this._captureEvent(event, hint, scope)).then((result) => {
|
|
eventId = result;
|
|
})
|
|
);
|
|
return eventId;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
captureMessage(message, level, hint, scope) {
|
|
let eventId;
|
|
const promisedEvent = isPrimitive(message) ? this.eventFromMessage(String(message), level, hint) : this.eventFromException(message, hint);
|
|
this._process(
|
|
promisedEvent.then((event) => this._captureEvent(event, hint, scope)).then((result) => {
|
|
eventId = result;
|
|
})
|
|
);
|
|
return eventId;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
captureEvent(event, hint, scope) {
|
|
if (hint && hint.originalException && checkOrSetAlreadyCaught(hint.originalException)) {
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.log(ALREADY_SEEN_ERROR);
|
|
return;
|
|
}
|
|
let eventId;
|
|
this._process(
|
|
this._captureEvent(event, hint, scope).then((result) => {
|
|
eventId = result;
|
|
})
|
|
);
|
|
return eventId;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
captureSession(session) {
|
|
if (!this._isEnabled()) {
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.warn("SDK not enabled, will not capture session.");
|
|
return;
|
|
}
|
|
if (!(typeof session.release === "string")) {
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.warn("Discarded session because of missing or non-string release");
|
|
} else {
|
|
this.sendSession(session);
|
|
updateSession(session, { init: false });
|
|
}
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
getDsn() {
|
|
return this._dsn;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
getOptions() {
|
|
return this._options;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
getTransport() {
|
|
return this._transport;
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
flush(timeout) {
|
|
const transport = this._transport;
|
|
if (transport) {
|
|
return this._isClientDoneProcessing(timeout).then((clientFinished) => {
|
|
return transport.flush(timeout).then((transportFlushed) => clientFinished && transportFlushed);
|
|
});
|
|
} else {
|
|
return resolvedSyncPromise(true);
|
|
}
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
close(timeout) {
|
|
return this.flush(timeout).then((result) => {
|
|
this.getOptions().enabled = false;
|
|
return result;
|
|
});
|
|
}
|
|
/**
|
|
* Sets up the integrations
|
|
*/
|
|
setupIntegrations() {
|
|
if (this._isEnabled() && !this._integrationsInitialized) {
|
|
this._integrations = setupIntegrations(this._options.integrations);
|
|
this._integrationsInitialized = true;
|
|
}
|
|
}
|
|
/**
|
|
* Gets an installed integration by its `id`.
|
|
*
|
|
* @returns The installed integration or `undefined` if no integration with that `id` was installed.
|
|
*/
|
|
getIntegrationById(integrationId) {
|
|
return this._integrations[integrationId];
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
getIntegration(integration) {
|
|
try {
|
|
return this._integrations[integration.id] || null;
|
|
} catch (_oO) {
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.warn(`Cannot retrieve integration ${integration.id} from the current Client`);
|
|
return null;
|
|
}
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
sendEvent(event, hint = {}) {
|
|
if (this._dsn) {
|
|
let env = createEventEnvelope(event, this._dsn, this._options._metadata, this._options.tunnel);
|
|
for (const attachment of hint.attachments || []) {
|
|
env = addItemToEnvelope(
|
|
env,
|
|
createAttachmentEnvelopeItem(
|
|
attachment,
|
|
this._options.transportOptions && this._options.transportOptions.textEncoder
|
|
)
|
|
);
|
|
}
|
|
this._sendEnvelope(env);
|
|
}
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
sendSession(session) {
|
|
if (this._dsn) {
|
|
const env = createSessionEnvelope(session, this._dsn, this._options._metadata, this._options.tunnel);
|
|
this._sendEnvelope(env);
|
|
}
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
recordDroppedEvent(reason, category, _event) {
|
|
if (this._options.sendClientReports) {
|
|
const key = `${reason}:${category}`;
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.log(`Adding outcome: "${key}"`);
|
|
this._outcomes[key] = this._outcomes[key] + 1 || 1;
|
|
}
|
|
}
|
|
/** Updates existing session based on the provided event */
|
|
_updateSessionFromEvent(session, event) {
|
|
let crashed = false;
|
|
let errored = false;
|
|
const exceptions = event.exception && event.exception.values;
|
|
if (exceptions) {
|
|
errored = true;
|
|
for (const ex of exceptions) {
|
|
const mechanism = ex.mechanism;
|
|
if (mechanism && mechanism.handled === false) {
|
|
crashed = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
const sessionNonTerminal = session.status === "ok";
|
|
const shouldUpdateAndSend = sessionNonTerminal && session.errors === 0 || sessionNonTerminal && crashed;
|
|
if (shouldUpdateAndSend) {
|
|
updateSession(session, {
|
|
...crashed && { status: "crashed" },
|
|
errors: session.errors || Number(errored || crashed)
|
|
});
|
|
this.captureSession(session);
|
|
}
|
|
}
|
|
/**
|
|
* Determine if the client is finished processing. Returns a promise because it will wait `timeout` ms before saying
|
|
* "no" (resolving to `false`) in order to give the client a chance to potentially finish first.
|
|
*
|
|
* @param timeout The time, in ms, after which to resolve to `false` if the client is still busy. Passing `0` (or not
|
|
* passing anything) will make the promise wait as long as it takes for processing to finish before resolving to
|
|
* `true`.
|
|
* @returns A promise which will resolve to `true` if processing is already done or finishes before the timeout, and
|
|
* `false` otherwise
|
|
*/
|
|
_isClientDoneProcessing(timeout) {
|
|
return new SyncPromise((resolve2) => {
|
|
let ticked = 0;
|
|
const tick = 1;
|
|
const interval = setInterval(() => {
|
|
if (this._numProcessing == 0) {
|
|
clearInterval(interval);
|
|
resolve2(true);
|
|
} else {
|
|
ticked += tick;
|
|
if (timeout && ticked >= timeout) {
|
|
clearInterval(interval);
|
|
resolve2(false);
|
|
}
|
|
}
|
|
}, tick);
|
|
});
|
|
}
|
|
/** Determines whether this SDK is enabled and a valid Dsn is present. */
|
|
_isEnabled() {
|
|
return this.getOptions().enabled !== false && this._dsn !== void 0;
|
|
}
|
|
/**
|
|
* Adds common information to events.
|
|
*
|
|
* The information includes release and environment from `options`,
|
|
* breadcrumbs and context (extra, tags and user) from the scope.
|
|
*
|
|
* Information that is already present in the event is never overwritten. For
|
|
* nested objects, such as the context, keys are merged.
|
|
*
|
|
* @param event The original event.
|
|
* @param hint May contain additional information about the original exception.
|
|
* @param scope A scope containing event metadata.
|
|
* @returns A new event with more information.
|
|
*/
|
|
_prepareEvent(event, hint, scope) {
|
|
const { normalizeDepth = 3, normalizeMaxBreadth = 1e3 } = this.getOptions();
|
|
const prepared = {
|
|
...event,
|
|
event_id: event.event_id || hint.event_id || uuid4(),
|
|
timestamp: event.timestamp || dateTimestampInSeconds()
|
|
};
|
|
this._applyClientOptions(prepared);
|
|
this._applyIntegrationsMetadata(prepared);
|
|
let finalScope = scope;
|
|
if (hint.captureContext) {
|
|
finalScope = Scope.clone(finalScope).update(hint.captureContext);
|
|
}
|
|
let result = resolvedSyncPromise(prepared);
|
|
if (finalScope && finalScope.getAttachments) {
|
|
const attachments = [...hint.attachments || [], ...finalScope.getAttachments()];
|
|
if (attachments.length) {
|
|
hint.attachments = attachments;
|
|
}
|
|
result = finalScope.applyToEvent(prepared, hint);
|
|
}
|
|
return result.then((evt) => {
|
|
if (typeof normalizeDepth === "number" && normalizeDepth > 0) {
|
|
return this._normalizeEvent(evt, normalizeDepth, normalizeMaxBreadth);
|
|
}
|
|
return evt;
|
|
});
|
|
}
|
|
/**
|
|
* Applies `normalize` function on necessary `Event` attributes to make them safe for serialization.
|
|
* Normalized keys:
|
|
* - `breadcrumbs.data`
|
|
* - `user`
|
|
* - `contexts`
|
|
* - `extra`
|
|
* @param event Event
|
|
* @returns Normalized event
|
|
*/
|
|
_normalizeEvent(event, depth, maxBreadth) {
|
|
if (!event) {
|
|
return null;
|
|
}
|
|
const normalized = {
|
|
...event,
|
|
...event.breadcrumbs && {
|
|
breadcrumbs: event.breadcrumbs.map((b) => ({
|
|
...b,
|
|
...b.data && {
|
|
data: normalize(b.data, depth, maxBreadth)
|
|
}
|
|
}))
|
|
},
|
|
...event.user && {
|
|
user: normalize(event.user, depth, maxBreadth)
|
|
},
|
|
...event.contexts && {
|
|
contexts: normalize(event.contexts, depth, maxBreadth)
|
|
},
|
|
...event.extra && {
|
|
extra: normalize(event.extra, depth, maxBreadth)
|
|
}
|
|
};
|
|
if (event.contexts && event.contexts.trace && normalized.contexts) {
|
|
normalized.contexts.trace = event.contexts.trace;
|
|
if (event.contexts.trace.data) {
|
|
normalized.contexts.trace.data = normalize(event.contexts.trace.data, depth, maxBreadth);
|
|
}
|
|
}
|
|
if (event.spans) {
|
|
normalized.spans = event.spans.map((span) => {
|
|
if (span.data) {
|
|
span.data = normalize(span.data, depth, maxBreadth);
|
|
}
|
|
return span;
|
|
});
|
|
}
|
|
return normalized;
|
|
}
|
|
/**
|
|
* Enhances event using the client configuration.
|
|
* It takes care of all "static" values like environment, release and `dist`,
|
|
* as well as truncating overly long values.
|
|
* @param event event instance to be enhanced
|
|
*/
|
|
_applyClientOptions(event) {
|
|
const options = this.getOptions();
|
|
const { environment, release, dist, maxValueLength = 250 } = options;
|
|
if (!("environment" in event)) {
|
|
event.environment = "environment" in options ? environment : "production";
|
|
}
|
|
if (event.release === void 0 && release !== void 0) {
|
|
event.release = release;
|
|
}
|
|
if (event.dist === void 0 && dist !== void 0) {
|
|
event.dist = dist;
|
|
}
|
|
if (event.message) {
|
|
event.message = truncate(event.message, maxValueLength);
|
|
}
|
|
const exception = event.exception && event.exception.values && event.exception.values[0];
|
|
if (exception && exception.value) {
|
|
exception.value = truncate(exception.value, maxValueLength);
|
|
}
|
|
const request = event.request;
|
|
if (request && request.url) {
|
|
request.url = truncate(request.url, maxValueLength);
|
|
}
|
|
}
|
|
/**
|
|
* This function adds all used integrations to the SDK info in the event.
|
|
* @param event The event that will be filled with all integrations.
|
|
*/
|
|
_applyIntegrationsMetadata(event) {
|
|
const integrationsArray = Object.keys(this._integrations);
|
|
if (integrationsArray.length > 0) {
|
|
event.sdk = event.sdk || {};
|
|
event.sdk.integrations = [...event.sdk.integrations || [], ...integrationsArray];
|
|
}
|
|
}
|
|
/**
|
|
* Processes the event and logs an error in case of rejection
|
|
* @param event
|
|
* @param hint
|
|
* @param scope
|
|
*/
|
|
_captureEvent(event, hint = {}, scope) {
|
|
return this._processEvent(event, hint, scope).then(
|
|
(finalEvent) => {
|
|
return finalEvent.event_id;
|
|
},
|
|
(reason) => {
|
|
if (typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) {
|
|
const sentryError = reason;
|
|
if (sentryError.logLevel === "log") {
|
|
logger.log(sentryError.message);
|
|
} else {
|
|
logger.warn(sentryError);
|
|
}
|
|
}
|
|
return void 0;
|
|
}
|
|
);
|
|
}
|
|
/**
|
|
* Processes an event (either error or message) and sends it to Sentry.
|
|
*
|
|
* This also adds breadcrumbs and context information to the event. However,
|
|
* platform specific meta data (such as the User's IP address) must be added
|
|
* by the SDK implementor.
|
|
*
|
|
*
|
|
* @param event The event to send to Sentry.
|
|
* @param hint May contain additional information about the original exception.
|
|
* @param scope A scope containing event metadata.
|
|
* @returns A SyncPromise that resolves with the event or rejects in case event was/will not be send.
|
|
*/
|
|
_processEvent(event, hint, scope) {
|
|
const options = this.getOptions();
|
|
const { sampleRate } = options;
|
|
if (!this._isEnabled()) {
|
|
return rejectedSyncPromise(new SentryError("SDK not enabled, will not capture event.", "log"));
|
|
}
|
|
const isTransaction = event.type === "transaction";
|
|
const beforeSendProcessorName = isTransaction ? "beforeSendTransaction" : "beforeSend";
|
|
const beforeSendProcessor = options[beforeSendProcessorName];
|
|
if (!isTransaction && typeof sampleRate === "number" && Math.random() > sampleRate) {
|
|
this.recordDroppedEvent("sample_rate", "error", event);
|
|
return rejectedSyncPromise(
|
|
new SentryError(
|
|
`Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`,
|
|
"log"
|
|
)
|
|
);
|
|
}
|
|
return this._prepareEvent(event, hint, scope).then((prepared) => {
|
|
if (prepared === null) {
|
|
this.recordDroppedEvent("event_processor", event.type || "error", event);
|
|
throw new SentryError("An event processor returned `null`, will not send event.", "log");
|
|
}
|
|
const isInternalException = hint.data && hint.data.__sentry__ === true;
|
|
if (isInternalException || !beforeSendProcessor) {
|
|
return prepared;
|
|
}
|
|
const beforeSendResult = beforeSendProcessor(prepared, hint);
|
|
return _validateBeforeSendResult(beforeSendResult, beforeSendProcessorName);
|
|
}).then((processedEvent) => {
|
|
if (processedEvent === null) {
|
|
this.recordDroppedEvent("before_send", event.type || "error", event);
|
|
throw new SentryError(`\`${beforeSendProcessorName}\` returned \`null\`, will not send event.`, "log");
|
|
}
|
|
const session = scope && scope.getSession();
|
|
if (!isTransaction && session) {
|
|
this._updateSessionFromEvent(session, processedEvent);
|
|
}
|
|
const transactionInfo = processedEvent.transaction_info;
|
|
if (isTransaction && transactionInfo && processedEvent.transaction !== event.transaction) {
|
|
const source = "custom";
|
|
processedEvent.transaction_info = {
|
|
...transactionInfo,
|
|
source,
|
|
changes: [
|
|
...transactionInfo.changes,
|
|
{
|
|
source,
|
|
// use the same timestamp as the processed event.
|
|
timestamp: processedEvent.timestamp,
|
|
propagations: transactionInfo.propagations
|
|
}
|
|
]
|
|
};
|
|
}
|
|
this.sendEvent(processedEvent, hint);
|
|
return processedEvent;
|
|
}).then(null, (reason) => {
|
|
if (reason instanceof SentryError) {
|
|
throw reason;
|
|
}
|
|
this.captureException(reason, {
|
|
data: {
|
|
__sentry__: true
|
|
},
|
|
originalException: reason
|
|
});
|
|
throw new SentryError(
|
|
`Event processing pipeline threw an error, original event will not be sent. Details have been sent as a new event.
|
|
Reason: ${reason}`
|
|
);
|
|
});
|
|
}
|
|
/**
|
|
* Occupies the client with processing and event
|
|
*/
|
|
_process(promise) {
|
|
this._numProcessing++;
|
|
void promise.then(
|
|
(value) => {
|
|
this._numProcessing--;
|
|
return value;
|
|
},
|
|
(reason) => {
|
|
this._numProcessing--;
|
|
return reason;
|
|
}
|
|
);
|
|
}
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
_sendEnvelope(envelope) {
|
|
if (this._transport && this._dsn) {
|
|
this._transport.send(envelope).then(null, (reason) => {
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.error("Error while sending event:", reason);
|
|
});
|
|
} else {
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.error("Transport disabled");
|
|
}
|
|
}
|
|
/**
|
|
* Clears outcomes on this client and returns them.
|
|
*/
|
|
_clearOutcomes() {
|
|
const outcomes = this._outcomes;
|
|
this._outcomes = {};
|
|
return Object.keys(outcomes).map((key) => {
|
|
const [reason, category] = key.split(":");
|
|
return {
|
|
reason,
|
|
category,
|
|
quantity: outcomes[key]
|
|
};
|
|
});
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
};
|
|
function _validateBeforeSendResult(beforeSendResult, beforeSendProcessorName) {
|
|
const invalidValueError = `\`${beforeSendProcessorName}\` must return \`null\` or a valid event.`;
|
|
if (isThenable(beforeSendResult)) {
|
|
return beforeSendResult.then(
|
|
(event) => {
|
|
if (!isPlainObject(event) && event !== null) {
|
|
throw new SentryError(invalidValueError);
|
|
}
|
|
return event;
|
|
},
|
|
(e) => {
|
|
throw new SentryError(`\`${beforeSendProcessorName}\` rejected with ${e}`);
|
|
}
|
|
);
|
|
} else if (!isPlainObject(beforeSendResult) && beforeSendResult !== null) {
|
|
throw new SentryError(invalidValueError);
|
|
}
|
|
return beforeSendResult;
|
|
}
|
|
|
|
// ../../../node_modules/@sentry/core/esm/transports/base.js
|
|
var DEFAULT_TRANSPORT_BUFFER_SIZE = 30;
|
|
function createTransport(options, makeRequest, buffer = makePromiseBuffer(options.bufferSize || DEFAULT_TRANSPORT_BUFFER_SIZE)) {
|
|
let rateLimits = {};
|
|
const flush = (timeout) => buffer.drain(timeout);
|
|
function send(envelope) {
|
|
const filteredEnvelopeItems = [];
|
|
forEachEnvelopeItem(envelope, (item, type) => {
|
|
const envelopeItemDataCategory = envelopeItemTypeToDataCategory(type);
|
|
if (isRateLimited(rateLimits, envelopeItemDataCategory)) {
|
|
const event = getEventForEnvelopeItem(item, type);
|
|
options.recordDroppedEvent("ratelimit_backoff", envelopeItemDataCategory, event);
|
|
} else {
|
|
filteredEnvelopeItems.push(item);
|
|
}
|
|
});
|
|
if (filteredEnvelopeItems.length === 0) {
|
|
return resolvedSyncPromise();
|
|
}
|
|
const filteredEnvelope = createEnvelope(envelope[0], filteredEnvelopeItems);
|
|
const recordEnvelopeLoss = (reason) => {
|
|
forEachEnvelopeItem(filteredEnvelope, (item, type) => {
|
|
const event = getEventForEnvelopeItem(item, type);
|
|
options.recordDroppedEvent(reason, envelopeItemTypeToDataCategory(type), event);
|
|
});
|
|
};
|
|
const requestTask = () => makeRequest({ body: serializeEnvelope(filteredEnvelope, options.textEncoder) }).then(
|
|
(response) => {
|
|
if (response.statusCode !== void 0 && (response.statusCode < 200 || response.statusCode >= 300)) {
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.warn(`Sentry responded with status code ${response.statusCode} to sent event.`);
|
|
}
|
|
rateLimits = updateRateLimits(rateLimits, response);
|
|
},
|
|
(error) => {
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.error("Failed while sending event:", error);
|
|
recordEnvelopeLoss("network_error");
|
|
}
|
|
);
|
|
return buffer.add(requestTask).then(
|
|
(result) => result,
|
|
(error) => {
|
|
if (error instanceof SentryError) {
|
|
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.error("Skipped sending event because buffer is full.");
|
|
recordEnvelopeLoss("queue_overflow");
|
|
return resolvedSyncPromise();
|
|
} else {
|
|
throw error;
|
|
}
|
|
}
|
|
);
|
|
}
|
|
return {
|
|
send,
|
|
flush
|
|
};
|
|
}
|
|
function getEventForEnvelopeItem(item, type) {
|
|
if (type !== "event" && type !== "transaction") {
|
|
return void 0;
|
|
}
|
|
return Array.isArray(item) ? item[1] : void 0;
|
|
}
|
|
|
|
// ../../../node_modules/toucan-js/dist/index.esm.js
|
|
function isObject(value) {
|
|
return typeof value === "object" && value !== null;
|
|
}
|
|
function isMechanism(value) {
|
|
return isObject(value) && "handled" in value && typeof value.handled === "boolean" && "type" in value && typeof value.type === "string";
|
|
}
|
|
function containsMechanism(value) {
|
|
return isObject(value) && "mechanism" in value && isMechanism(value["mechanism"]);
|
|
}
|
|
function getSentryRelease() {
|
|
if (GLOBAL_OBJ.SENTRY_RELEASE && GLOBAL_OBJ.SENTRY_RELEASE.id) {
|
|
return GLOBAL_OBJ.SENTRY_RELEASE.id;
|
|
}
|
|
}
|
|
function setOnOptional(target, entry) {
|
|
if (target !== void 0) {
|
|
target[entry[0]] = entry[1];
|
|
return target;
|
|
} else {
|
|
return { [entry[0]]: entry[1] };
|
|
}
|
|
}
|
|
function parseStackFrames(stackParser, error) {
|
|
return stackParser(error.stack || "", 1);
|
|
}
|
|
function extractMessage(ex) {
|
|
const message = ex && ex.message;
|
|
if (!message) {
|
|
return "No error message";
|
|
}
|
|
if (message.error && typeof message.error.message === "string") {
|
|
return message.error.message;
|
|
}
|
|
return message;
|
|
}
|
|
function exceptionFromError(stackParser, error) {
|
|
const exception = {
|
|
type: error.name || error.constructor.name,
|
|
value: extractMessage(error)
|
|
};
|
|
const frames = parseStackFrames(stackParser, error);
|
|
if (frames.length) {
|
|
exception.stacktrace = { frames };
|
|
}
|
|
if (exception.type === void 0 && exception.value === "") {
|
|
exception.value = "Unrecoverable error caught";
|
|
}
|
|
return exception;
|
|
}
|
|
function eventFromUnknownInput(sdk, stackParser, exception, hint) {
|
|
let ex;
|
|
const providedMechanism = hint && hint.data && containsMechanism(hint.data) ? hint.data.mechanism : void 0;
|
|
const mechanism = providedMechanism ?? {
|
|
handled: true,
|
|
type: "generic"
|
|
};
|
|
if (!isError(exception)) {
|
|
if (isPlainObject(exception)) {
|
|
const message = `Non-Error exception captured with keys: ${extractExceptionKeysForMessage(exception)}`;
|
|
const client = sdk?.getClient();
|
|
const normalizeDepth = client && client.getOptions().normalizeDepth;
|
|
sdk?.configureScope((scope) => {
|
|
scope.setExtra("__serialized__", normalizeToSize(exception, normalizeDepth));
|
|
});
|
|
ex = hint && hint.syntheticException || new Error(message);
|
|
ex.message = message;
|
|
} else {
|
|
ex = hint && hint.syntheticException || new Error(exception);
|
|
ex.message = exception;
|
|
}
|
|
mechanism.synthetic = true;
|
|
} else {
|
|
ex = exception;
|
|
}
|
|
const event = {
|
|
exception: {
|
|
values: [exceptionFromError(stackParser, ex)]
|
|
}
|
|
};
|
|
addExceptionTypeValue(event, void 0, void 0);
|
|
addExceptionMechanism(event, mechanism);
|
|
return {
|
|
...event,
|
|
event_id: hint && hint.event_id
|
|
};
|
|
}
|
|
function eventFromMessage(stackParser, message, level = "info", hint, attachStacktrace) {
|
|
const event = {
|
|
event_id: hint && hint.event_id,
|
|
level,
|
|
message
|
|
};
|
|
if (attachStacktrace && hint && hint.syntheticException) {
|
|
const frames = parseStackFrames(stackParser, hint.syntheticException);
|
|
if (frames.length) {
|
|
event.exception = {
|
|
values: [
|
|
{
|
|
value: message,
|
|
stacktrace: { frames }
|
|
}
|
|
]
|
|
};
|
|
}
|
|
}
|
|
return event;
|
|
}
|
|
var DEFAULT_LIMIT = 5;
|
|
var _LinkedErrors = class {
|
|
name = _LinkedErrors.id;
|
|
limit;
|
|
constructor(options = {}) {
|
|
this.limit = options.limit || DEFAULT_LIMIT;
|
|
}
|
|
setupOnce(addGlobalEventProcessor2, getCurrentHub2) {
|
|
const client = getCurrentHub2().getClient();
|
|
if (!client) {
|
|
return;
|
|
}
|
|
addGlobalEventProcessor2((event, hint) => {
|
|
const self2 = getCurrentHub2().getIntegration(_LinkedErrors);
|
|
if (!self2) {
|
|
return event;
|
|
}
|
|
return handler(client.getOptions().stackParser, self2.limit, event, hint);
|
|
});
|
|
}
|
|
};
|
|
var LinkedErrors = _LinkedErrors;
|
|
__publicField(LinkedErrors, "id", "LinkedErrors");
|
|
function handler(parser, limit, event, hint) {
|
|
if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {
|
|
return event;
|
|
}
|
|
const linkedErrors = walkErrorTree(parser, limit, hint.originalException);
|
|
event.exception.values = [...linkedErrors, ...event.exception.values];
|
|
return event;
|
|
}
|
|
function walkErrorTree(parser, limit, error, stack = []) {
|
|
if (!isInstanceOf(error.cause, Error) || stack.length + 1 >= limit) {
|
|
return stack;
|
|
}
|
|
const exception = exceptionFromError(parser, error.cause);
|
|
return walkErrorTree(parser, limit, error.cause, [
|
|
exception,
|
|
...stack
|
|
]);
|
|
}
|
|
var defaultRequestDataOptions = {
|
|
allowedHeaders: ["CF-RAY", "CF-Worker"]
|
|
};
|
|
var _options;
|
|
var _RequestData = class {
|
|
constructor(options = {}) {
|
|
__publicField(this, "name", _RequestData.id);
|
|
__privateAdd(this, _options, void 0);
|
|
__privateSet(this, _options, { ...defaultRequestDataOptions, ...options });
|
|
}
|
|
setupOnce(addGlobalEventProcessor2, getCurrentHub2) {
|
|
const client = getCurrentHub2().getClient();
|
|
if (!client) {
|
|
return;
|
|
}
|
|
addGlobalEventProcessor2((event) => {
|
|
const { sdkProcessingMetadata } = event;
|
|
const self2 = getCurrentHub2().getIntegration(_RequestData);
|
|
if (!self2 || !sdkProcessingMetadata) {
|
|
return event;
|
|
}
|
|
if ("request" in sdkProcessingMetadata && sdkProcessingMetadata.request instanceof Request) {
|
|
event.request = toEventRequest(sdkProcessingMetadata.request, __privateGet(this, _options));
|
|
event.user = toEventUser(event.user ?? {}, sdkProcessingMetadata.request, __privateGet(this, _options));
|
|
}
|
|
if ("requestData" in sdkProcessingMetadata) {
|
|
if (event.request) {
|
|
event.request.data = sdkProcessingMetadata.requestData;
|
|
} else {
|
|
event.request = {
|
|
data: sdkProcessingMetadata.requestData
|
|
};
|
|
}
|
|
}
|
|
return event;
|
|
});
|
|
}
|
|
};
|
|
var RequestData = _RequestData;
|
|
_options = new WeakMap();
|
|
__publicField(RequestData, "id", "RequestData");
|
|
function toEventUser(user, request, options) {
|
|
const ip_address = request.headers.get("CF-Connecting-IP");
|
|
const { allowedIps } = options;
|
|
const newUser = { ...user };
|
|
if (!("ip_address" in user) && // If ip_address is already set from explicitly called setUser, we don't want to overwrite it
|
|
ip_address && allowedIps !== void 0 && testAllowlist(ip_address, allowedIps)) {
|
|
newUser.ip_address = ip_address;
|
|
}
|
|
return Object.keys(newUser).length > 0 ? newUser : void 0;
|
|
}
|
|
function toEventRequest(request, options) {
|
|
const cookieString = request.headers.get("cookie");
|
|
let cookies = void 0;
|
|
if (cookieString) {
|
|
try {
|
|
cookies = parseCookie(cookieString);
|
|
} catch (e) {
|
|
}
|
|
}
|
|
const headers = {};
|
|
for (const [k, v] of request.headers.entries()) {
|
|
if (k !== "cookie") {
|
|
headers[k] = v;
|
|
}
|
|
}
|
|
const eventRequest = {
|
|
method: request.method,
|
|
cookies,
|
|
headers
|
|
};
|
|
try {
|
|
const url = new URL(request.url);
|
|
eventRequest.url = `${url.protocol}//${url.hostname}${url.pathname}`;
|
|
eventRequest.query_string = url.search;
|
|
} catch (e) {
|
|
const qi = request.url.indexOf("?");
|
|
if (qi < 0) {
|
|
eventRequest.url = request.url;
|
|
} else {
|
|
eventRequest.url = request.url.substr(0, qi);
|
|
eventRequest.query_string = request.url.substr(qi + 1);
|
|
}
|
|
}
|
|
const { allowedHeaders, allowedCookies, allowedSearchParams } = options;
|
|
if (allowedHeaders !== void 0 && eventRequest.headers) {
|
|
eventRequest.headers = applyAllowlistToObject(eventRequest.headers, allowedHeaders);
|
|
if (Object.keys(eventRequest.headers).length === 0) {
|
|
delete eventRequest.headers;
|
|
}
|
|
} else {
|
|
delete eventRequest.headers;
|
|
}
|
|
if (allowedCookies !== void 0 && eventRequest.cookies) {
|
|
eventRequest.cookies = applyAllowlistToObject(eventRequest.cookies, allowedCookies);
|
|
if (Object.keys(eventRequest.cookies).length === 0) {
|
|
delete eventRequest.cookies;
|
|
}
|
|
} else {
|
|
delete eventRequest.cookies;
|
|
}
|
|
if (allowedSearchParams !== void 0) {
|
|
const params = Object.fromEntries(new URLSearchParams(eventRequest.query_string));
|
|
const allowedParams = new URLSearchParams();
|
|
Object.keys(applyAllowlistToObject(params, allowedSearchParams)).forEach((allowedKey) => {
|
|
allowedParams.set(allowedKey, params[allowedKey]);
|
|
});
|
|
eventRequest.query_string = allowedParams.toString();
|
|
} else {
|
|
delete eventRequest.query_string;
|
|
}
|
|
return eventRequest;
|
|
}
|
|
function testAllowlist(target, allowlist) {
|
|
if (typeof allowlist === "boolean") {
|
|
return allowlist;
|
|
} else if (allowlist instanceof RegExp) {
|
|
return allowlist.test(target);
|
|
} else if (Array.isArray(allowlist)) {
|
|
const allowlistLowercased = allowlist.map((item) => item.toLowerCase());
|
|
return allowlistLowercased.includes(target);
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
function applyAllowlistToObject(target, allowlist) {
|
|
let predicate = () => false;
|
|
if (typeof allowlist === "boolean") {
|
|
return allowlist ? target : {};
|
|
} else if (allowlist instanceof RegExp) {
|
|
predicate = (item) => allowlist.test(item);
|
|
} else if (Array.isArray(allowlist)) {
|
|
const allowlistLowercased = allowlist.map((item) => item.toLowerCase());
|
|
predicate = (item) => allowlistLowercased.includes(item);
|
|
} else {
|
|
return {};
|
|
}
|
|
return Object.keys(target).map((key) => key.toLowerCase()).filter((key) => predicate(key)).reduce((allowed, key) => {
|
|
allowed[key] = target[key];
|
|
return allowed;
|
|
}, {});
|
|
}
|
|
function parseCookie(cookieString) {
|
|
if (typeof cookieString !== "string") {
|
|
return {};
|
|
}
|
|
try {
|
|
return cookieString.split(";").map((part) => part.split("=")).reduce((acc, [cookieKey, cookieValue]) => {
|
|
acc[decodeURIComponent(cookieKey.trim())] = decodeURIComponent(cookieValue.trim());
|
|
return acc;
|
|
}, {});
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|
|
function setupIntegrations2(integrations, sdk) {
|
|
const integrationIndex = {};
|
|
integrations.forEach((integration) => {
|
|
integrationIndex[integration.name] = integration;
|
|
integration.setupOnce((callback) => {
|
|
sdk.getScope()?.addEventProcessor(callback);
|
|
}, () => sdk);
|
|
});
|
|
return integrationIndex;
|
|
}
|
|
var ToucanClient = class extends BaseClient {
|
|
/**
|
|
* Some functions need to access the Hub (Toucan instance) this client is bound to,
|
|
* but calling 'getCurrentHub()' is unsafe because it uses globals.
|
|
* So we store a reference to the Hub after binding to it and provide it to methods that need it.
|
|
*/
|
|
#sdk = null;
|
|
/**
|
|
* Creates a new Toucan SDK instance.
|
|
* @param options Configuration options for this SDK.
|
|
*/
|
|
constructor(options) {
|
|
options._metadata = options._metadata || {};
|
|
options._metadata.sdk = options._metadata.sdk || {
|
|
name: "toucan-js",
|
|
packages: [
|
|
{
|
|
name: "npm:toucan-js",
|
|
version: "3.0.0"
|
|
}
|
|
],
|
|
version: "3.0.0"
|
|
};
|
|
super(options);
|
|
}
|
|
/**
|
|
* By default, integrations are stored in a global. We want to store them in a local instance because they may have contextual data, such as event request.
|
|
*/
|
|
setupIntegrations() {
|
|
if (this._isEnabled() && !this._integrationsInitialized && this.#sdk) {
|
|
this._integrations = setupIntegrations2(this._options.integrations, this.#sdk);
|
|
this._integrationsInitialized = true;
|
|
}
|
|
}
|
|
eventFromException(exception, hint) {
|
|
return resolvedSyncPromise(eventFromUnknownInput(this.#sdk, this._options.stackParser, exception, hint));
|
|
}
|
|
eventFromMessage(message, level = "info", hint) {
|
|
return resolvedSyncPromise(eventFromMessage(this._options.stackParser, message, level, hint, this._options.attachStacktrace));
|
|
}
|
|
_prepareEvent(event, hint, scope) {
|
|
event.platform = event.platform || "javascript";
|
|
if (this.getOptions().request) {
|
|
event.sdkProcessingMetadata = setOnOptional(event.sdkProcessingMetadata, [
|
|
"request",
|
|
this.getOptions().request
|
|
]);
|
|
}
|
|
if (this.getOptions().requestData) {
|
|
event.sdkProcessingMetadata = setOnOptional(event.sdkProcessingMetadata, [
|
|
"requestData",
|
|
this.getOptions().requestData
|
|
]);
|
|
}
|
|
return super._prepareEvent(event, hint, scope);
|
|
}
|
|
getSdk() {
|
|
return this.#sdk;
|
|
}
|
|
setSdk(sdk) {
|
|
this.#sdk = sdk;
|
|
}
|
|
/**
|
|
* Sets the request body context on all future events.
|
|
*
|
|
* @param body Request body.
|
|
* @example
|
|
* const body = await request.text();
|
|
* toucan.setRequestBody(body);
|
|
*/
|
|
setRequestBody(body) {
|
|
this.getOptions().requestData = body;
|
|
}
|
|
};
|
|
function workersStackLineParser(getModule2) {
|
|
const [arg1, arg2] = nodeStackLineParser(getModule2);
|
|
const fn = (line) => {
|
|
const result = arg2(line);
|
|
if (result) {
|
|
const filename = result.filename;
|
|
result.abs_path = filename !== void 0 && !filename.startsWith("/") ? `/${filename}` : filename;
|
|
result.in_app = filename !== void 0;
|
|
}
|
|
return result;
|
|
};
|
|
return [arg1, fn];
|
|
}
|
|
function getModule(filename) {
|
|
if (!filename) {
|
|
return;
|
|
}
|
|
return basename(filename, ".js");
|
|
}
|
|
var defaultStackParser = createStackParser(workersStackLineParser(getModule));
|
|
function makeFetchTransport(options) {
|
|
function makeRequest({ body }) {
|
|
try {
|
|
const request = fetch(options.url, {
|
|
method: "POST",
|
|
headers: options.headers,
|
|
body
|
|
}).then((response) => {
|
|
return {
|
|
statusCode: response.status,
|
|
headers: {
|
|
"retry-after": response.headers.get("Retry-After"),
|
|
"x-sentry-rate-limits": response.headers.get("X-Sentry-Rate-Limits")
|
|
}
|
|
};
|
|
});
|
|
if (options.context) {
|
|
options.context.waitUntil(request);
|
|
}
|
|
return request;
|
|
} catch (e) {
|
|
return rejectedSyncPromise(e);
|
|
}
|
|
}
|
|
return createTransport(options, makeRequest);
|
|
}
|
|
var Toucan = class extends Hub {
|
|
constructor(options) {
|
|
options.defaultIntegrations = options.defaultIntegrations === false ? [] : [
|
|
...Array.isArray(options.defaultIntegrations) ? options.defaultIntegrations : [
|
|
new RequestData(options.requestDataOptions),
|
|
new LinkedErrors()
|
|
]
|
|
];
|
|
if (options.release === void 0) {
|
|
const detectedRelease = getSentryRelease();
|
|
if (detectedRelease !== void 0) {
|
|
options.release = detectedRelease;
|
|
}
|
|
}
|
|
const client = new ToucanClient({
|
|
...options,
|
|
transport: makeFetchTransport,
|
|
integrations: getIntegrationsToSetup(options),
|
|
stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),
|
|
transportOptions: {
|
|
...options.transportOptions,
|
|
context: options.context
|
|
}
|
|
});
|
|
super(client);
|
|
client.setSdk(this);
|
|
client.setupIntegrations();
|
|
}
|
|
/**
|
|
* Sets the request body context on all future events.
|
|
*
|
|
* @param body Request body.
|
|
* @example
|
|
* const body = await request.text();
|
|
* toucan.setRequestBody(body);
|
|
*/
|
|
setRequestBody(body) {
|
|
this.getClient()?.setRequestBody(body);
|
|
}
|
|
};
|
|
|
|
// _middleware.ts
|
|
var onRequest = async (context) => {
|
|
context.data.sentry = new Toucan({
|
|
context,
|
|
...context.pluginArgs
|
|
});
|
|
try {
|
|
return await context.next();
|
|
} catch (thrown) {
|
|
context.data.sentry.captureException(thrown);
|
|
throw thrown;
|
|
}
|
|
};
|
|
|
|
// ../.wrangler/tmp/pages-CU0o5d/functionsRoutes-0.5195048230868211.mjs
|
|
var routes = [
|
|
{
|
|
routePath: "/",
|
|
mountPath: "/",
|
|
method: "",
|
|
middlewares: [onRequest],
|
|
modules: []
|
|
}
|
|
];
|
|
|
|
// ../../../node_modules/path-to-regexp/dist.es2015/index.js
|
|
function lexer(str) {
|
|
var tokens = [];
|
|
var i = 0;
|
|
while (i < str.length) {
|
|
var char = str[i];
|
|
if (char === "*" || char === "+" || char === "?") {
|
|
tokens.push({ type: "MODIFIER", index: i, value: str[i++] });
|
|
continue;
|
|
}
|
|
if (char === "\\") {
|
|
tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] });
|
|
continue;
|
|
}
|
|
if (char === "{") {
|
|
tokens.push({ type: "OPEN", index: i, value: str[i++] });
|
|
continue;
|
|
}
|
|
if (char === "}") {
|
|
tokens.push({ type: "CLOSE", index: i, value: str[i++] });
|
|
continue;
|
|
}
|
|
if (char === ":") {
|
|
var name = "";
|
|
var j = i + 1;
|
|
while (j < str.length) {
|
|
var code = str.charCodeAt(j);
|
|
if (
|
|
// `0-9`
|
|
code >= 48 && code <= 57 || // `A-Z`
|
|
code >= 65 && code <= 90 || // `a-z`
|
|
code >= 97 && code <= 122 || // `_`
|
|
code === 95
|
|
) {
|
|
name += str[j++];
|
|
continue;
|
|
}
|
|
break;
|
|
}
|
|
if (!name)
|
|
throw new TypeError("Missing parameter name at ".concat(i));
|
|
tokens.push({ type: "NAME", index: i, value: name });
|
|
i = j;
|
|
continue;
|
|
}
|
|
if (char === "(") {
|
|
var count = 1;
|
|
var pattern = "";
|
|
var j = i + 1;
|
|
if (str[j] === "?") {
|
|
throw new TypeError('Pattern cannot start with "?" at '.concat(j));
|
|
}
|
|
while (j < str.length) {
|
|
if (str[j] === "\\") {
|
|
pattern += str[j++] + str[j++];
|
|
continue;
|
|
}
|
|
if (str[j] === ")") {
|
|
count--;
|
|
if (count === 0) {
|
|
j++;
|
|
break;
|
|
}
|
|
} else if (str[j] === "(") {
|
|
count++;
|
|
if (str[j + 1] !== "?") {
|
|
throw new TypeError("Capturing groups are not allowed at ".concat(j));
|
|
}
|
|
}
|
|
pattern += str[j++];
|
|
}
|
|
if (count)
|
|
throw new TypeError("Unbalanced pattern at ".concat(i));
|
|
if (!pattern)
|
|
throw new TypeError("Missing pattern at ".concat(i));
|
|
tokens.push({ type: "PATTERN", index: i, value: pattern });
|
|
i = j;
|
|
continue;
|
|
}
|
|
tokens.push({ type: "CHAR", index: i, value: str[i++] });
|
|
}
|
|
tokens.push({ type: "END", index: i, value: "" });
|
|
return tokens;
|
|
}
|
|
function parse(str, options) {
|
|
if (options === void 0) {
|
|
options = {};
|
|
}
|
|
var tokens = lexer(str);
|
|
var _a = options.prefixes, prefixes = _a === void 0 ? "./" : _a;
|
|
var defaultPattern = "[^".concat(escapeString(options.delimiter || "/#?"), "]+?");
|
|
var result = [];
|
|
var key = 0;
|
|
var i = 0;
|
|
var path = "";
|
|
var tryConsume = function(type) {
|
|
if (i < tokens.length && tokens[i].type === type)
|
|
return tokens[i++].value;
|
|
};
|
|
var mustConsume = function(type) {
|
|
var value2 = tryConsume(type);
|
|
if (value2 !== void 0)
|
|
return value2;
|
|
var _a2 = tokens[i], nextType = _a2.type, index = _a2.index;
|
|
throw new TypeError("Unexpected ".concat(nextType, " at ").concat(index, ", expected ").concat(type));
|
|
};
|
|
var consumeText = function() {
|
|
var result2 = "";
|
|
var value2;
|
|
while (value2 = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR")) {
|
|
result2 += value2;
|
|
}
|
|
return result2;
|
|
};
|
|
while (i < tokens.length) {
|
|
var char = tryConsume("CHAR");
|
|
var name = tryConsume("NAME");
|
|
var pattern = tryConsume("PATTERN");
|
|
if (name || pattern) {
|
|
var prefix = char || "";
|
|
if (prefixes.indexOf(prefix) === -1) {
|
|
path += prefix;
|
|
prefix = "";
|
|
}
|
|
if (path) {
|
|
result.push(path);
|
|
path = "";
|
|
}
|
|
result.push({
|
|
name: name || key++,
|
|
prefix,
|
|
suffix: "",
|
|
pattern: pattern || defaultPattern,
|
|
modifier: tryConsume("MODIFIER") || ""
|
|
});
|
|
continue;
|
|
}
|
|
var value = char || tryConsume("ESCAPED_CHAR");
|
|
if (value) {
|
|
path += value;
|
|
continue;
|
|
}
|
|
if (path) {
|
|
result.push(path);
|
|
path = "";
|
|
}
|
|
var open = tryConsume("OPEN");
|
|
if (open) {
|
|
var prefix = consumeText();
|
|
var name_1 = tryConsume("NAME") || "";
|
|
var pattern_1 = tryConsume("PATTERN") || "";
|
|
var suffix = consumeText();
|
|
mustConsume("CLOSE");
|
|
result.push({
|
|
name: name_1 || (pattern_1 ? key++ : ""),
|
|
pattern: name_1 && !pattern_1 ? defaultPattern : pattern_1,
|
|
prefix,
|
|
suffix,
|
|
modifier: tryConsume("MODIFIER") || ""
|
|
});
|
|
continue;
|
|
}
|
|
mustConsume("END");
|
|
}
|
|
return result;
|
|
}
|
|
function match(str, options) {
|
|
var keys = [];
|
|
var re = pathToRegexp(str, keys, options);
|
|
return regexpToFunction(re, keys, options);
|
|
}
|
|
function regexpToFunction(re, keys, options) {
|
|
if (options === void 0) {
|
|
options = {};
|
|
}
|
|
var _a = options.decode, decode = _a === void 0 ? function(x) {
|
|
return x;
|
|
} : _a;
|
|
return function(pathname) {
|
|
var m = re.exec(pathname);
|
|
if (!m)
|
|
return false;
|
|
var path = m[0], index = m.index;
|
|
var params = /* @__PURE__ */ Object.create(null);
|
|
var _loop_1 = function(i2) {
|
|
if (m[i2] === void 0)
|
|
return "continue";
|
|
var key = keys[i2 - 1];
|
|
if (key.modifier === "*" || key.modifier === "+") {
|
|
params[key.name] = m[i2].split(key.prefix + key.suffix).map(function(value) {
|
|
return decode(value, key);
|
|
});
|
|
} else {
|
|
params[key.name] = decode(m[i2], key);
|
|
}
|
|
};
|
|
for (var i = 1; i < m.length; i++) {
|
|
_loop_1(i);
|
|
}
|
|
return { path, index, params };
|
|
};
|
|
}
|
|
function escapeString(str) {
|
|
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
|
|
}
|
|
function flags(options) {
|
|
return options && options.sensitive ? "" : "i";
|
|
}
|
|
function regexpToRegexp(path, keys) {
|
|
if (!keys)
|
|
return path;
|
|
var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g;
|
|
var index = 0;
|
|
var execResult = groupsRegex.exec(path.source);
|
|
while (execResult) {
|
|
keys.push({
|
|
// Use parenthesized substring match if available, index otherwise
|
|
name: execResult[1] || index++,
|
|
prefix: "",
|
|
suffix: "",
|
|
modifier: "",
|
|
pattern: ""
|
|
});
|
|
execResult = groupsRegex.exec(path.source);
|
|
}
|
|
return path;
|
|
}
|
|
function arrayToRegexp(paths, keys, options) {
|
|
var parts = paths.map(function(path) {
|
|
return pathToRegexp(path, keys, options).source;
|
|
});
|
|
return new RegExp("(?:".concat(parts.join("|"), ")"), flags(options));
|
|
}
|
|
function stringToRegexp(path, keys, options) {
|
|
return tokensToRegexp(parse(path, options), keys, options);
|
|
}
|
|
function tokensToRegexp(tokens, keys, options) {
|
|
if (options === void 0) {
|
|
options = {};
|
|
}
|
|
var _a = options.strict, strict = _a === void 0 ? false : _a, _b = options.start, start = _b === void 0 ? true : _b, _c = options.end, end = _c === void 0 ? true : _c, _d = options.encode, encode = _d === void 0 ? function(x) {
|
|
return x;
|
|
} : _d, _e = options.delimiter, delimiter = _e === void 0 ? "/#?" : _e, _f = options.endsWith, endsWith = _f === void 0 ? "" : _f;
|
|
var endsWithRe = "[".concat(escapeString(endsWith), "]|$");
|
|
var delimiterRe = "[".concat(escapeString(delimiter), "]");
|
|
var route = start ? "^" : "";
|
|
for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
|
|
var token = tokens_1[_i];
|
|
if (typeof token === "string") {
|
|
route += escapeString(encode(token));
|
|
} else {
|
|
var prefix = escapeString(encode(token.prefix));
|
|
var suffix = escapeString(encode(token.suffix));
|
|
if (token.pattern) {
|
|
if (keys)
|
|
keys.push(token);
|
|
if (prefix || suffix) {
|
|
if (token.modifier === "+" || token.modifier === "*") {
|
|
var mod = token.modifier === "*" ? "?" : "";
|
|
route += "(?:".concat(prefix, "((?:").concat(token.pattern, ")(?:").concat(suffix).concat(prefix, "(?:").concat(token.pattern, "))*)").concat(suffix, ")").concat(mod);
|
|
} else {
|
|
route += "(?:".concat(prefix, "(").concat(token.pattern, ")").concat(suffix, ")").concat(token.modifier);
|
|
}
|
|
} else {
|
|
if (token.modifier === "+" || token.modifier === "*") {
|
|
route += "((?:".concat(token.pattern, ")").concat(token.modifier, ")");
|
|
} else {
|
|
route += "(".concat(token.pattern, ")").concat(token.modifier);
|
|
}
|
|
}
|
|
} else {
|
|
route += "(?:".concat(prefix).concat(suffix, ")").concat(token.modifier);
|
|
}
|
|
}
|
|
}
|
|
if (end) {
|
|
if (!strict)
|
|
route += "".concat(delimiterRe, "?");
|
|
route += !options.endsWith ? "$" : "(?=".concat(endsWithRe, ")");
|
|
} else {
|
|
var endToken = tokens[tokens.length - 1];
|
|
var isEndDelimited = typeof endToken === "string" ? delimiterRe.indexOf(endToken[endToken.length - 1]) > -1 : endToken === void 0;
|
|
if (!strict) {
|
|
route += "(?:".concat(delimiterRe, "(?=").concat(endsWithRe, "))?");
|
|
}
|
|
if (!isEndDelimited) {
|
|
route += "(?=".concat(delimiterRe, "|").concat(endsWithRe, ")");
|
|
}
|
|
}
|
|
return new RegExp(route, flags(options));
|
|
}
|
|
function pathToRegexp(path, keys, options) {
|
|
if (path instanceof RegExp)
|
|
return regexpToRegexp(path, keys);
|
|
if (Array.isArray(path))
|
|
return arrayToRegexp(path, keys, options);
|
|
return stringToRegexp(path, keys, options);
|
|
}
|
|
|
|
// ../../../node_modules/wrangler/templates/pages-template-plugin.ts
|
|
var escapeRegex = /[.+?^${}()|[\]\\]/g;
|
|
function* executeRequest(request, relativePathname) {
|
|
for (const route of [...routes].reverse()) {
|
|
if (route.method && route.method !== request.method) {
|
|
continue;
|
|
}
|
|
const routeMatcher = match(route.routePath.replace(escapeRegex, "\\$&"), {
|
|
end: false
|
|
});
|
|
const mountMatcher = match(route.mountPath.replace(escapeRegex, "\\$&"), {
|
|
end: false
|
|
});
|
|
const matchResult = routeMatcher(relativePathname);
|
|
const mountMatchResult = mountMatcher(relativePathname);
|
|
if (matchResult && mountMatchResult) {
|
|
for (const handler2 of route.middlewares.flat()) {
|
|
yield {
|
|
handler: handler2,
|
|
params: matchResult.params,
|
|
path: mountMatchResult.path
|
|
};
|
|
}
|
|
}
|
|
}
|
|
for (const route of routes) {
|
|
if (route.method && route.method !== request.method) {
|
|
continue;
|
|
}
|
|
const routeMatcher = match(route.routePath.replace(escapeRegex, "\\$&"), {
|
|
end: true
|
|
});
|
|
const mountMatcher = match(route.mountPath.replace(escapeRegex, "\\$&"), {
|
|
end: false
|
|
});
|
|
const matchResult = routeMatcher(relativePathname);
|
|
const mountMatchResult = mountMatcher(relativePathname);
|
|
if (matchResult && mountMatchResult && route.modules.length) {
|
|
for (const handler2 of route.modules.flat()) {
|
|
yield {
|
|
handler: handler2,
|
|
params: matchResult.params,
|
|
path: matchResult.path
|
|
};
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
function pages_template_plugin_default(pluginArgs) {
|
|
const onRequest2 = async (workerContext) => {
|
|
let { request } = workerContext;
|
|
const { env, next } = workerContext;
|
|
let { data } = workerContext;
|
|
const url = new URL(request.url);
|
|
const relativePathname = `/${url.pathname.replace(workerContext.functionPath, "") || ""}`.replace(/^\/\//, "/");
|
|
const handlerIterator = executeRequest(request, relativePathname);
|
|
const pluginNext = async (input, init) => {
|
|
if (input !== void 0) {
|
|
let url2 = input;
|
|
if (typeof input === "string") {
|
|
url2 = new URL(input, request.url).toString();
|
|
}
|
|
request = new Request(url2, init);
|
|
}
|
|
const result = handlerIterator.next();
|
|
if (result.done === false) {
|
|
const { handler: handler2, params, path } = result.value;
|
|
const context = {
|
|
request: new Request(request.clone()),
|
|
functionPath: workerContext.functionPath + path,
|
|
next: pluginNext,
|
|
params,
|
|
get data() {
|
|
return data;
|
|
},
|
|
set data(value) {
|
|
if (typeof value !== "object" || value === null) {
|
|
throw new Error("context.data must be an object");
|
|
}
|
|
data = value;
|
|
},
|
|
pluginArgs,
|
|
env,
|
|
waitUntil: workerContext.waitUntil.bind(workerContext),
|
|
passThroughOnException: workerContext.passThroughOnException.bind(workerContext)
|
|
};
|
|
const response = await handler2(context);
|
|
return cloneResponse(response);
|
|
} else {
|
|
return next(request);
|
|
}
|
|
};
|
|
return pluginNext();
|
|
};
|
|
return onRequest2;
|
|
}
|
|
var cloneResponse = (response) => (
|
|
// https://fetch.spec.whatwg.org/#null-body-status
|
|
new Response(
|
|
[101, 204, 205, 304].includes(response.status) ? null : response.body,
|
|
response
|
|
)
|
|
);
|
|
export {
|
|
pages_template_plugin_default as default
|
|
};
|
|
//# sourceMappingURL=index.js.map
|