// Metro module 6423 (f6424). import * as _slicedToArray from "./_slicedToArray"; import * as _classCallCheck from "./_classCallCheck"; import * as __createClass from "./_createClass"; import { makeDsn, dsnToString } from "./dsnFromString_6415"; import { DEBUG_BUILD } from "./Module6396"; import { logger } from "./consoleSandbox_6368"; import { uuid4, checkOrSetAlreadyCaught } from "./Module6379"; import * as _isInstanceOf from "./isInstanceOf_6375"; import { isParameterizedString, isPrimitive, isThenable } from "./isInstanceOf_6375"; import { updateSession } from "./updateSession_6391"; import { resolvedSyncPromise, SyncPromise, rejectedSyncPromise } from "./SyncPromise_6392"; import { setupIntegration, afterSetupIntegrations, setupIntegrations } from "./setupIntegration_6424"; import { createEventEnvelope, createSessionEnvelope } from "./Module6411"; import { addItemToEnvelope, createAttachmentEnvelopeItem } from "./forEachEnvelopeItem_6412"; import { getCurrentScope, getIsolationScope, getTraceContextFromScope } from "./Module6395"; import { prepareEvent } from "./applyClientOptions_6417"; import { getDynamicSamplingContextFromScope } from "./getDynamicSamplingContextFromSpan_6404"; import { SentryError } from "./SentryError_6425"; import { parseSampleRate } from "./Module6408"; import { createClientReportEnvelope } from "./Module6426"; import { showSpanDropWarning } from "./spanTimeInputToSeconds"; let isTransactionEvent, c4121_4; let BaseClient; let env4121 = {}; const isErrorEvent = function isErrorEvent(a0) { return a0.type === void 0; }; isTransactionEvent = function isTransactionEvent(a0) { return a0.type === "transaction"; }; c4121_4 = "Not capturing exception because it's already been captured."; BaseClient = function BaseClient(a0) { "use strict"; let r26, r27; let c25861_1; let c25861_0 = a0; _classCallCheck(this, BaseClient); this._options = a0; this._integrations = {}; this._numProcessing = 0; this._outcomes = {}; this._hooks = {}; this._eventProcessors = []; if (a0.dsn) { this._dsn = makeDsn(a0.dsn); r26 = dependencyMap; r27 = require; } else { r26 = dependencyMap; r27 = require; if (DEBUG_BUILD) { logger.warn("No DSN provided, client will not send events."); r26 = dependencyMap; r27 = require; } } if (this._dsn) { const envelopeEndpointWithUrlEncodedAuth = r27(r26[6]).getEnvelopeEndpointWithUrlEncodedAuth(this._dsn, a0.tunnel, a0._metadata ? a0._metadata.sdk : void 0); this._transport = a0.transport.call(a0, { tunnel: this._options.tunnel, recordDroppedEvent: this.recordDroppedEvent.bind(this), ...a0.transportOptions, url: envelopeEndpointWithUrlEncodedAuth }); } const r58 = ["enableTracing", "tracesSampleRate", "tracesSampler"].find((item) => item in c25861_0 && c25861_0[item] == null); c25861_1 = r58; if (r58) { r27(r26[5]).consoleSandbox(() => { console.warn(`[Sentry] Deprecation warning: \`${c25861_1}\` is set to undefined, which leads to tracing being enabled. In v9, a value of \`undefined\` will result in tracing being disabled.`); }); } }; exports.BaseClient = __createClass(BaseClient, [{ key: "captureException", value: function captureException(a0, a1, c25862_1) { "use strict"; const event_id = uuid4(); if (checkOrSetAlreadyCaught(a0)) { if (DEBUG_BUILD) { logger.log(c4121_4); } return event_id; } const r19 = { event_id, ...a1 }; let c25862_0 = r19; this._process(this.eventFromException(a0, r19).then((result) => this._captureEvent(result, c25862_0, c25862_1))); return r19.event_id; } }, { key: "captureMessage", value: function captureMessage(a0, a1, a2, c25863_1) { "use strict"; const r15 = { event_id: uuid4(), ...a2 }; let c25863_0 = r15; const r21 = isParameterizedString(a0) ? a0 : String(a0); this._process((isPrimitive(a0) ? this.eventFromMessage(r21, a1, r15) : this.eventFromException(a0, r15)).then((result) => this._captureEvent(result, c25863_0, c25863_1))); return r15.event_id; } }, { key: "captureEvent", value: function captureEvent(a0, a1, a2) { "use strict"; const event_id = uuid4(); if (a1 && a1.originalException && checkOrSetAlreadyCaught(a1.originalException)) { if (DEBUG_BUILD) { logger.log(c4121_4); } return event_id; } const r21 = { event_id, ...a1 }; let capturedSpanScope = (a0.sdkProcessingMetadata || {}).capturedSpanScope; const _process2 = this._process; const _captureEvent2 = this._captureEvent; if (!capturedSpanScope) { capturedSpanScope = a2; } _process2.call(this, _captureEvent2.call(this, a0, r21, capturedSpanScope)); return r21.event_id; } }, { key: "captureSession", value: function captureSession(a0) { "use strict"; if (typeof a0.release !== "string") { if (DEBUG_BUILD) { logger.warn("Discarded session because of missing or non-string release"); } } else { this.sendSession(a0); updateSession(a0, { init: false }); } } }, { key: "getDsn", value: function getDsn() { "use strict"; return this._dsn; } }, { key: "getOptions", value: function getOptions() { "use strict"; return this._options; } }, { key: "getSdkMetadata", value: function getSdkMetadata() { "use strict"; return this._options._metadata; } }, { key: "getTransport", value: function getTransport() { "use strict"; return this._transport; } }, { key: "flush", value: function flush(a0) { "use strict"; let r13; let c25864_0 = a0; const _transport = this._transport; if (_transport) { this.emit("flush"); r13 = this._isClientDoneProcessing(a0).then((c29768_0) => _transport.flush(c25864_0).then((result) => c29768_0 && result)); } else { r13 = resolvedSyncPromise(true); } return r13; } }, { key: "close", value: function close(a0) { "use strict"; return this.flush(a0).then((result) => { this.getOptions().enabled = false; this.emit("close"); return result; }); } }, { key: "getEventProcessors", value: function getEventProcessors() { "use strict"; return this._eventProcessors; } }, { key: "addEventProcessor", value: function addEventProcessor(a0) { "use strict"; this._eventProcessors.push(a0); } }, { key: "init", value: function init() { "use strict"; if (this._isEnabled() || this._options.integrations.some((integration) => integration.name.startsWith("Spotlight"))) { this._setupIntegrations(); } } }, { key: "getIntegrationByName", value: function getIntegrationByName(a0) { "use strict"; return this._integrations[a0]; } }, { key: "addIntegration", value: function addIntegration(a0) { "use strict"; const r9 = this._integrations[a0.name]; setupIntegration(this, a0, this._integrations); if (!r9) { afterSetupIntegrations(this, [a0]); } } }, { key: "sendEvent", value: function sendEvent(a0) { "use strict"; let c25866_0 = a0; let r3 = arguments[1]; if (r3 === void 0) { r3 = {}; } this.emit("beforeSendEvent", a0, r3); let r33 = createEventEnvelope(a0, this._dsn, this._options._metadata, this._options.tunnel); const r34 = r3.attachments || []; for (const item of r34) { r33 = addItemToEnvelope(r33, createAttachmentEnvelopeItem(item)); } const r51 = this.sendEnvelope(r33); if (r51) { r51.then((result) => this.emit("afterSendEvent", c25866_0, result), null); } } }, { key: "sendSession", value: function sendSession(a0) { "use strict"; this.sendEnvelope(createSessionEnvelope(a0, this._dsn, this._options._metadata, this._options.tunnel)); } }, { key: "recordDroppedEvent", value: function recordDroppedEvent(a0, a1, a2) { "use strict"; if (this._options.sendClientReports) { const r5 = typeof a2 === "number" ? a2 : 1; const r16 = `${a0}:${a1}`; if (DEBUG_BUILD) { logger.log(`Recording outcome: "${r16}"${r5 > 1 ? ` (${r5} times)` : ""}`); } this._outcomes[r16] = (this._outcomes[r16] || 0) + r5; } } }, { key: "on", value: function on(a0, a1) { "use strict"; let c25867_0 = a1; const _hooks = this._hooks; const r6 = this._hooks[a0] || []; _hooks[a0] = r6; let c25867_1 = r6; r6.push(a1); return () => { const r6 = c25867_1.indexOf(c25867_0); if (r6 > -1) { c25867_1.splice(r6, 1); } }; } }, { key: "emit", value: function emit(a0) { "use strict"; let c25868_0 = Array.prototype.slice.call(arguments, 1); const r8 = this._hooks[a0]; if (r8) { r8.forEach((item) => item.apply(void 0, [...c25868_0])); } } }, { key: "sendEnvelope", value: function sendEnvelope(a0) { "use strict"; let r25; this.emit("beforeEnvelope", a0); if (this._isEnabled() && this._transport) { r25 = this._transport.send(a0).then(null, (a0) => { if (DEBUG_BUILD) { logger.error("Error while sending envelope:", a0); } return a0; }); } else { if (DEBUG_BUILD) { logger.error("Transport disabled"); } r25 = resolvedSyncPromise({}); } return r25; } }, { key: "_setupIntegrations", value: function _setupIntegrations() { "use strict"; const integrations = this._options.integrations; this._integrations = setupIntegrations(this, integrations); afterSetupIntegrations(this, integrations); } }, { key: "_updateSessionFromEvent", value: function _updateSessionFromEvent(a0, a1) { "use strict"; let r21; let r22 = a1.level === "fatal"; const r23 = a1.exception && a1.exception.values; let r7 = false; if (r23) { let r26 = r23[Symbol.iterator](); const next = r26.next; while (true) { const r28 = r26 === void 0 ? void 0 : (r21 = next.call(r26)).done ? r26 = void 0 : r21.value; const r9 = r26; r7 = true; if (r9 === void 0) { break; } L9: { try { const mechanism = r28.mechanism; if (!mechanism) { continue; } if (mechanism.handled === false) { r22 = true; break L9; } continue; } catch (r34) { if (r26 !== void 0 && typeof r26.return === "function") { try { r26.return(); } catch {} } throw r34; } } const r33 = r26; if (r33 !== void 0 && typeof r33.return === "function") { r33.return(); } r7 = true; break; } } let r38 = a0.status === "ok"; let r39 = r38 ? a0.errors === 0 : r38; if (!r39) { if (r38) { r38 = r22; } r39 = r38; } if (r39) { const r48 = r22 && { status: "crashed" }; let errors = a0.errors; if (!errors) { const r53 = Number; if (!r7) { r7 = r22; } errors = r53(r7); } updateSession(a0, { ...r48, errors }); this.captureSession(a0); } } }, { key: "_isClientDoneProcessing", value: function _isClientDoneProcessing(c25869_0) { "use strict"; return new SyncPromise((c29769_0) => { let c29769_1 = 0; let c29769_2 = setInterval(() => { if (this._numProcessing == 0) { clearInterval(c29769_2); c29769_0(true); } else { const r9 = c29769_1 + 1; c29769_1 = r9; if (c25869_0 && r9 >= c25869_0) { clearInterval(c29769_2); c29769_0(false); } } }, 1); }); } }, { key: "_isEnabled", value: function _isEnabled() { "use strict"; return this.getOptions().enabled !== false && this._transport !== void 0; } }, { key: "_prepareEvent", value: function _prepareEvent(a0, a1) { "use strict"; let r11 = arguments[2]; if (r11 === void 0) { r11 = getCurrentScope(); } const currentScope = r11; let r10 = arguments[3]; if (r10 === void 0) { r10 = getIsolationScope(); } const options2 = this.getOptions(); const integrations2 = Object.keys(this._integrations); const integrations = a1.integrations; if (integrations ? !integrations : integrations2.length > 0) { a1.integrations = integrations2; } this.emit("preprocessEvent", a0, a1); if (!a0.type) { r10.setLastEventId.call(r10, a0.event_id || a1.event_id); } return prepareEvent(options2, a0, a1, currentScope, this, r10).then((result) => { if (result === null) { return result; } result.contexts = { trace: getTraceContextFromScope(currentScope), ...result.contexts }; result.sdkProcessingMetadata = { dynamicSamplingContext: getDynamicSamplingContextFromScope(this, currentScope), ...result.sdkProcessingMetadata }; return result; }); } }, { key: "_captureEvent", value: function _captureEvent(a0) { "use strict"; let r6 = arguments[1]; if (r6 === void 0) { r6 = {}; } return this._processEvent(a0, r6, arguments[2]).then((result) => result.event_id, (a0) => { L5: { if (DEBUG_BUILD) { if (a0 instanceof SentryError && a0.logLevel === "log") { logger.log(a0.message); break L5; } logger.warn(a0); } } }); } }, { key: "_processEvent", value: function _processEvent(a0, a1, a2) { "use strict"; const _this = this; let c25871_1 = a0; let c25871_2 = a1; let c25871_3 = a2; const options = this.getOptions(); const sampleRate = options.sampleRate; let c25871_5 = a0.type === "transaction"; const type = a0.type; const r6 = a0.type || "error"; let c25871_6 = `before send for type \`${r6}\``; const r27 = sampleRate !== void 0 ? parseSampleRate(sampleRate) : void 0; if (type === void 0 && typeof r27 === "number" && Math.random() > r27) { this.recordDroppedEvent("sample_rate", "error", a0); return rejectedSyncPromise(new SentryError(`Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`, "log")); } let c25871_0 = r6 !== "replay_event" ? r6 : "replay"; return this._prepareEvent(a0, a1, a2, (a0.sdkProcessingMetadata || {}).capturedSpanIsolationScope).then((result) => { let r38; if (result === null) { _this.recordDroppedEvent("event_processor", c25871_0, c25871_1); throw new SentryError("An event processor returned `null`, will not send event.", "log"); } if (c25871_2.data && c25871_2.data.__sentry__ === true) { return result; } let c29770_0, c29770_1; const r20 = (function processBeforeSend(a0, { beforeSend, beforeSendTransaction, beforeSendSpan }, a2, a3) { if (isErrorEvent(a2) && beforeSend) { return beforeSend(a2, a3); } if (isTransactionEvent(a2)) { if (a2.spans && beforeSendSpan) { const spans = []; for (const span of a2.spans) { const r37 = beforeSendSpan(span); if (r37) { spans.push(r37); } else { showSpanDropWarning(); a0.recordDroppedEvent("before_send", "span"); } } a2.spans = spans; } if (beforeSendTransaction) { if (a2.spans) { a2.sdkProcessingMetadata = { ...a2.sdkProcessingMetadata, spanCountBeforeProcessing: a2.spans.length }; } return beforeSendTransaction(a2, a3); } } return a2; })(_this, options, result, c25871_2); c29770_0 = c25871_6; c29770_1 = void 0; const r25 = `${c25871_6} must return \`null\` or a valid event.`; c29770_1 = r25; if (isThenable(r20)) { r38 = r20.then((result) => { if (!_isInstanceOf.isPlainObject(result) && result !== null) { throw new SentryError(c29770_1); } return result; }, (a0) => { throw new SentryError(`${c29770_0} rejected with ${a0}`); }); } else { const isPlainObject = _isInstanceOf.isPlainObject(r20); r38 = r20; if (!isPlainObject) { r38 = r20; if (r38 !== null) { throw new SentryError(r25); } } } return r38; }).then((result) => { if (result === null) { _this.recordDroppedEvent("before_send", c25871_0, c25871_1); if (c25871_5) { _this.recordDroppedEvent("before_send", "span", 1 + (c25871_1.spans || []).length); } throw new SentryError(`${c25871_6} returned \`null\`, will not send event.`, "log"); } const r6 = c25871_3 && c25871_3.getSession(); if (c25871_5 ? !c25871_5 : r6) { _this._updateSessionFromEvent(r6, result); } if (c25871_5) { const r8 = (result.sdkProcessingMetadata && result.sdkProcessingMetadata.spanCountBeforeProcessing || 0) - (result.spans ? result.spans.length : 0); if (r8 > 0) { _this.recordDroppedEvent("before_send", "span", r8); } } const transaction_info = result.transaction_info; if (c25871_5 && transaction_info && result.transaction !== c25871_1.transaction) { result.transaction_info = { ...transaction_info, source: "custom" }; } _this.sendEvent(result, c25871_2); return result; }).then(null, (a0) => { if (a0 instanceof SentryError) { throw a0; } _this.captureException(a0, { data: { __sentry__: true }, originalException: a0 }); throw new SentryError(`Event processing pipeline threw an error, original event will not be sent. Details have been sent as a new event. Reason: ${a0}`); }); } }, { key: "_process", value: function _process(a0) { "use strict"; this._numProcessing = this._numProcessing + 1; a0.then((result) => { this._numProcessing = this._numProcessing - 1; return result; }, (a0) => { this._numProcessing = this._numProcessing - 1; return a0; }); } }, { key: "_clearOutcomes", value: function _clearOutcomes() { "use strict"; const _outcomes = this._outcomes; this._outcomes = {}; return Object.entries(_outcomes).map((item) => { const [r8, quantity] = item; const r32 = _slicedToArray(r8.split(":"), 2); return { reason: r32[0], category: r32[1], quantity }; }); } }, { key: "_flushOutcomes", value: function _flushOutcomes() { "use strict"; if (DEBUG_BUILD) { logger.log("Flushing outcomes..."); } const r6 = this._clearOutcomes(); if (r6.length !== 0) { if (this._dsn) { if (DEBUG_BUILD) { logger.log("Sending outcomes:", r6); } this.sendEnvelope(createClientReportEnvelope(r6, this._options.tunnel && dsnToString(this._dsn))); } else if (DEBUG_BUILD) { logger.log("No dsn provided, will not send outcomes"); } } else if (DEBUG_BUILD) { logger.log("No outcomes to send"); } } }]);