// Metro module 864 (f865). import * as _slicedToArray from "./_slicedToArray"; import { getSentryCarrier } from "./Module825"; import { GLOBAL_OBJ } from "./Module821"; import { normalize } from "./normalize"; import { dsnToString } from "./dsnFromString"; let c704_4; const forEachEnvelopeItem = function forEachEnvelopeItem(envelope, a1) { for (const item of envelope[1]) { if (!a1(item, item[0].type)) { continue; } return true; } return false; }; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); c704_4 = { session: "session", sessions: "session", attachment: "attachment", transaction: "transaction", event: "error", client_report: "internal", user_report: "default", profile: "profile", profile_chunk: "profile", replay_event: "replay", replay_recording: "replay", check_in: "monitor", feedback: "feedback", span: "span", raw_security: "security", log: "log_item", metric: "metric", trace_metric: "metric" }; export function addItemToEnvelope(a0, a1) { const r9 = _slicedToArray(a0, 2); return [r9[0], [...r9[1], a1]]; } export function createAttachmentEnvelopeItem(a0) { let r10; if (typeof a0.data === "string") { const data = a0.data; const sentryCarrier = getSentryCarrier(GLOBAL_OBJ); r10 = sentryCarrier.encodePolyfill ? sentryCarrier.encodePolyfill(data) : new TextEncoder().encode(data); } else { r10 = a0.data; } return [{ type: "attachment", length: r10.length, filename: a0.filename, content_type: a0.contentType, attachment_type: a0.attachmentType }, r10]; } export function createEnvelope(a0, r2 = []) { return [a0, r2]; } export function createEventEnvelopeHeaders(a0, a1, a2, a3) { const dynamicSamplingContext = a0.sdkProcessingMetadata?.dynamicSamplingContext; return { event_id: a0.event_id, sent_at: new Date().toISOString(), ...a1 ? { sdk: a1 } : a1, ...!!a2 && a3 && { dsn: dsnToString(a3) }, ...dynamicSamplingContext && { trace: dynamicSamplingContext } }; } export function createSpanEnvelopeItem(a0) { return [{ type: "span" }, a0]; } export function envelopeContainsItemType(a0, c12515_0) { return forEachEnvelopeItem(a0, (a0, a1) => c12515_0.includes(a1)); } export function envelopeItemTypeToDataCategory(a0) { return c704_4[a0]; } export { forEachEnvelopeItem }; export function getSdkMetadataForEnvelopeHeader(a0) { if (a0?.sdk) { const sdk = a0.sdk; return { name: sdk.name, version: sdk.version }; } } export function parseEnvelope(a0) { let r42; let r3 = a0; if (typeof a0 === "string") { const sentryCarrier = getSentryCarrier(GLOBAL_OBJ); r3 = sentryCarrier.encodePolyfill ? sentryCarrier.encodePolyfill(a0) : new TextEncoder().encode(a0); } let c12516_0; const readJson = function readJson() { let r5 = c12516_0.indexOf(10); if (r5 < 0) { r5 = c12516_0.length; } const r4 = JSON; const r17 = c12516_0.subarray(0, r5); c12516_0 = c12516_0.subarray(r5 + 1); const sentryCarrier = getSentryCarrier(GLOBAL_OBJ); return r4.parse(sentryCarrier.decodePolyfill ? sentryCarrier.decodePolyfill(r17) : new TextDecoder().decode(r17)); }; c12516_0 = r3; const r35 = readJson(); const r36 = []; while (c12516_0.length) { const r9 = readJson(); const r11 = typeof r9.length === "number" ? r9.length : void 0; const r41 = [r9, ,]; if (r11) { r42 = c12516_0.subarray(0, r11); c12516_0 = c12516_0.subarray(r11 + 1); } else { r42 = readJson(); } r41[1] = r42; r36.push(r41); } return [r35, r36]; } export function serializeEnvelope(a0) { let r55; let c12517_0; const append = function append(a0) { let r49; const r3 = c12517_0; if (typeof r3 === "string") { if (typeof a0 === "string") { r49 = r3 + a0; } else { const sentryCarrier2 = getSentryCarrier(GLOBAL_OBJ); r49 = [sentryCarrier2.encodePolyfill ? sentryCarrier2.encodePolyfill(r3) : new TextEncoder().encode(r3), a0]; } c12517_0 = r49; } else { let r1 = a0; if (typeof a0 === "string") { const sentryCarrier = getSentryCarrier(GLOBAL_OBJ); r1 = sentryCarrier.encodePolyfill ? sentryCarrier.encodePolyfill(a0) : new TextEncoder().encode(a0); } r3.push(r1); } }; const [r11, r29] = a0; c12517_0 = JSON.stringify(r11); for (const item of r29) { const [r14, r40] = item; append(` ${JSON.stringify(r14)} `); if (typeof r40 !== "string" && !(r40 instanceof Uint8Array)) { try { r55 = JSON.stringify(r40); } catch ($e) { r55 = JSON.stringify(normalize(r40)); } append(r55); continue; } append(r40); } const r70 = c12517_0; let r71 = r70; if (typeof r71 !== "string") { r71 = (function concatBuffers(a0) { const uint8Array = new Uint8Array(a0.reduce((acc, item) => acc + item.length, 0)); let r25 = 0; for (const item of a0) { const r31 = r25; uint8Array.set(item, r31); r25 = r31 + item.length; } return uint8Array; })(r70); } return r71; }