Files
discord-decomp/_bundle/applyClientOptions_6417.js
T
2026-11-01 12:12:55 +02:00

193 lines
6.3 KiB
JavaScript

// Metro module 6417 (f6418).
import { uuid4, addExceptionMechanism } from "./Module6379";
import { dateTimestampInSeconds } from "./Module6382";
import { getGlobalScope } from "./Module6395";
import { mergeScopeData, applyScopeDataToEvent } from "./Module6418";
import { notifyEventProcessors } from "./Module6419";
import { DEFAULT_ENVIRONMENT } from "./Module6405";
import { truncate } from "./Module6377";
import { getFilenameToDebugIdMap } from "./getFilenameToDebugIdMap_6420";
import { normalize } from "./normalize_6413";
import { Scope } from "./ScopeClass";
let applyDebugIds, applyDebugMeta, _excluded;
const applyClientOptions = function applyClientOptions(a0, { environment, release, dist, maxValueLength = 250 }) {
a0.environment = a0.environment || environment || DEFAULT_ENVIRONMENT;
const release2 = a0.release;
if (release2 ? !release2 : release) {
a0.release = release;
}
const dist2 = a0.dist;
if (dist2 ? !dist2 : dist) {
a0.dist = dist;
}
if (a0.message) {
a0.message = truncate(a0.message, maxValueLength);
}
const r26 = a0.exception && a0.exception.values && a0.exception.values[0];
if (r26 && r26.value) {
r26.value = truncate(r26.value, maxValueLength);
}
const request = a0.request;
if (request && request.url) {
request.url = truncate(request.url, maxValueLength);
}
};
applyDebugIds = function applyDebugIds(a0, stackParser) {
const filenameToDebugIdMap = getFilenameToDebugIdMap(stackParser);
try {
a0.exception.values.forEach((value) => {
value.stacktrace.frames.forEach((frame) => {
if (filenameToDebugIdMap ? frame.filename : filenameToDebugIdMap) {
frame.debug_id = filenameToDebugIdMap[frame.filename];
}
});
});
} catch ($e) {}
};
applyDebugMeta = function applyDebugMeta(a0) {
let images;
const r3 = {};
let c15720_0 = r3;
try {
a0.exception.values.forEach((value) => {
value.stacktrace.frames.forEach((frame) => {
if (frame.debug_id) {
if (frame.abs_path) {
c15720_0[frame.abs_path] = frame.debug_id;
} else if (frame.filename) {
c15720_0[frame.filename] = frame.debug_id;
}
delete frame["debug_id"];
}
});
});
} catch ($e) {}
if (Object.keys(r3).length !== 0) {
a0.debug_meta = a0.debug_meta || {};
a0.debug_meta.images = a0.debug_meta.images || [];
images = a0.debug_meta.images;
Object.entries(r3).forEach((item) => {
const [code_file, debug_id] = item;
images.push({
type: "sourcemap",
code_file,
debug_id
});
});
}
};
_excluded = ["user", "level", "extra", "contexts", "tags", "fingerprint", "requestSession", "propagationContext"];
export { applyClientOptions };
export { applyDebugIds };
export { applyDebugMeta };
export function parseEventHintOrCaptureContext(a0) {
if (a0) {
return a0 instanceof Scope || typeof a0 === "function" ? {
captureContext: a0
} : Object.keys(a0).some((item) => _excluded.includes(item)) ? {
captureContext: a0
} : a0;
}
}
export function prepareEvent(a0, a1, a2, a3, a4, a5) {
const { normalizeDepth = 3, normalizeMaxBreadth = 1000 } = a0;
const r8 = {
...a1,
event_id: a1.event_id || a2.event_id || uuid4(),
timestamp: a1.timestamp || dateTimestampInSeconds()
};
const r33 = a2.integrations || a0.integrations.map((integration) => integration.name);
applyClientOptions(r8, a0);
if (r33.length > 0) {
r8.sdk = r8.sdk || {};
r8.sdk.integrations = [...r8.sdk.integrations || [], ...r33];
}
if (a4) {
a4.emit("applyFrameMetadata", a1);
}
if (a1.type === void 0) {
applyDebugIds(r8, a0.stackParser);
}
const captureContext = a2.captureContext;
let r58 = a3;
if (captureContext) {
const r66 = a3 ? a3.clone() : new Scope();
r66.update(captureContext);
r58 = r66;
}
if (a2.mechanism) {
addExceptionMechanism(r8, a2.mechanism);
}
const r78 = a4 ? a4.getEventProcessors() : [];
const scopeData = getGlobalScope().getScopeData();
if (a5) {
mergeScopeData(scopeData, a5.getScopeData());
}
if (r58) {
mergeScopeData(scopeData, r58.getScopeData());
}
const attachments = [...a2.attachments || [], ...scopeData.attachments];
if (attachments.length) {
a2.attachments = attachments;
}
applyScopeDataToEvent(r8, scopeData);
return notifyEventProcessors([...r78, ...scopeData.eventProcessors], r8, a2).then((result) => {
if (result) {
applyDebugMeta(result);
}
let r20 = result;
if (typeof normalizeDepth === "number") {
r20 = result;
if (normalizeDepth > 0) {
const normalizeDepth2 = normalizeDepth;
const normalizeMaxBreadth2 = normalizeMaxBreadth;
let r21 = null;
if (result) {
const r4 = {
...result,
...result.breadcrumbs && {
breadcrumbs: result.breadcrumbs.map((breadcrumb) => ({
...breadcrumb,
...breadcrumb.data && {
data: normalize(breadcrumb.data, normalizeDepth2, normalizeMaxBreadth2)
}
}))
},
...result.user && {
user: normalize(result.user, normalizeDepth, normalizeMaxBreadth)
},
...result.contexts && {
contexts: normalize(result.contexts, normalizeDepth, normalizeMaxBreadth)
},
...result.extra && {
extra: normalize(result.extra, normalizeDepth, normalizeMaxBreadth)
}
};
if (result.contexts && result.contexts.trace && r4.contexts) {
r4.contexts.trace = result.contexts.trace;
if (result.contexts.trace.data) {
r4.contexts.trace.data = normalize(result.contexts.trace.data, normalizeDepth, normalizeMaxBreadth);
}
}
if (result.spans) {
r4.spans = result.spans.map((span) => ({
...span,
...span.data && {
data: normalize(span.data, normalizeDepth2, normalizeMaxBreadth2)
}
}));
}
const r91 = result.contexts && result.contexts.flags && r4.contexts;
r21 = r4;
if (r91) {
r4.contexts.flags = normalize(result.contexts.flags, 3, normalizeMaxBreadth);
r21 = r4;
}
}
r20 = r21;
}
}
return r20;
});
}