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

224 lines
6.4 KiB
JavaScript

// Metro module 869 (f870).
import { getCurrentScope, getClient, getIsolationScope, withIsolationScope } from "./Module848";
import { parseEventHintOrCaptureContext } from "./applyClientOptions";
import { DEBUG_BUILD } from "./Module823";
import { debug } from "./consoleSandbox";
import { uuid4 } from "./Module830";
import { timestampInSeconds } from "./dateTimestampInSeconds";
import { isThenable } from "./isInstanceOf";
import { startNewTrace } from "./createChildOrRootSpan";
import { GLOBAL_OBJ } from "./Module821";
import { closeSession, makeSession, updateSession } from "./updateSession";
const captureCheckIn = function captureCheckIn(a0, a1) {
const currentScope = getCurrentScope();
const client = getClient();
if (client) {
if (client.captureCheckIn) {
return client.captureCheckIn(a0, a1, currentScope);
}
if (DEBUG_BUILD) {
debug.warn("Cannot capture check-in. Client does not support sending check-ins.");
}
} else if (DEBUG_BUILD) {
debug.warn("Cannot capture check-in. No client defined.");
}
return uuid4();
};
Object.defineProperty(exports, Symbol.toStringTag, {
value: "Module"
});
export function addEventProcessor(a0) {
getIsolationScope().addEventProcessor(a0);
}
export { captureCheckIn };
export function captureEvent(a0, a1) {
return getCurrentScope().captureEvent(a0, a1);
}
export function captureException(a0, a1) {
return getCurrentScope().captureException(a0, parseEventHintOrCaptureContext(a1));
}
export function captureMessage(a0, a1) {
const r5 = typeof a1 === "string" ? a1 : void 0;
const r4 = typeof a1 !== "string" ? {
captureContext: a1
} : void 0;
return getCurrentScope().captureMessage(a0, r5, r4);
}
export function captureSession(r4 = false) {
const isolationScope = getIsolationScope();
if (r4) {
const r22 = getCurrentScope().getSession() || isolationScope.getSession();
if (r22) {
closeSession(r22);
}
const isolationScope2 = getIsolationScope();
const client2 = getClient();
const session2 = isolationScope2.getSession();
if (session2 && client2) {
client2.captureSession(session2);
}
isolationScope.setSession();
} else {
const client = getClient();
const session = isolationScope.getSession();
if (session && client) {
client.captureSession(session);
}
}
}
export async function close(c23866_0) {
let r24;
const client = getClient();
if (client) {
r24 = client.close(c23866_0);
} else {
if (DEBUG_BUILD) {
debug.warn("Cannot flush events and disable SDK. No client defined.");
}
r24 = Promise.resolve(false);
}
return r24;
}
export function endSession() {
const isolationScope = getIsolationScope();
const r6 = getCurrentScope().getSession() || isolationScope.getSession();
if (r6) {
closeSession(r6);
}
const isolationScope2 = getIsolationScope();
const client = getClient();
const session = isolationScope2.getSession();
if (session && client) {
client.captureSession(session);
}
isolationScope.setSession();
}
export async function flush(c23865_0) {
let r24;
const client = getClient();
if (client) {
r24 = client.flush(c23865_0);
} else {
if (DEBUG_BUILD) {
debug.warn("Cannot flush events. No client defined.");
}
r24 = Promise.resolve(false);
}
return r24;
}
export function isEnabled() {
const client = getClient();
return (client == null ? void 0 : client.getOptions().enabled) !== false && !!(client == null ? void 0 : client.getTransport());
}
export function isInitialized() {
return !!getClient();
}
export function lastEventId() {
return getIsolationScope().lastEventId();
}
export function setContext(a0, a1) {
getIsolationScope().setContext(a0, a1);
}
export function setExtra(a0, a1) {
getIsolationScope().setExtra(a0, a1);
}
export function setExtras(a0) {
getIsolationScope().setExtras(a0);
}
export function setTag(a0, a1) {
getIsolationScope().setTag(a0, a1);
}
export function setTags(a0) {
getIsolationScope().setTags(a0);
}
export function setUser(a0) {
getIsolationScope().setUser(a0);
}
export function startSession(a0) {
const isolationScope = getIsolationScope();
const currentScope = getCurrentScope();
const userAgent = (GLOBAL_OBJ.navigator || {}).userAgent;
const r34 = makeSession({
user: currentScope.getUser() || isolationScope.getUser(),
...userAgent && {
userAgent
},
...a0
});
const session = isolationScope.getSession();
if (session?.status === "ok") {
updateSession(session, {
status: "exited"
});
}
const isolationScope2 = getIsolationScope();
const r54 = getCurrentScope().getSession() || isolationScope2.getSession();
if (r54) {
closeSession(r54);
}
const isolationScope3 = getIsolationScope();
const client = getClient();
const session2 = isolationScope3.getSession();
if (session2 && client) {
client.captureSession(session2);
}
isolationScope2.setSession();
isolationScope.setSession(r34);
return r34;
}
export function withMonitor(monitorSlug, c12527_1, c12527_2) {
const runCallback2 = function runCallback() {
let r18, r26;
let checkInId, c23867_1;
const finishCheckIn2 = function finishCheckIn(a0) {
L8: {
const r4 = {
monitorSlug,
status: a0,
checkInId,
duration: timestampInSeconds() - c23867_1
};
const currentScope = getCurrentScope();
const client = getClient();
if (client) {
if (client.captureCheckIn) {
client.captureCheckIn(r4, void 0, currentScope);
break L8;
}
if (DEBUG_BUILD) {
debug.warn("Cannot capture check-in. Client does not support sending check-ins.");
}
} else if (DEBUG_BUILD) {
debug.warn("Cannot capture check-in. No client defined.");
}
uuid4();
}
};
checkInId = captureCheckIn({
monitorSlug,
status: "in_progress"
}, c12527_2);
c23867_1 = timestampInSeconds();
try {
r18 = c12527_1();
} catch (r31) {
finishCheckIn2("error");
throw r31;
}
if (isThenable(r18)) {
r26 = r18.then((result) => {
finishCheckIn2("ok");
return result;
}, (a0) => {
finishCheckIn2("error");
throw a0;
});
} else {
finishCheckIn2("ok");
r26 = r18;
}
return r26;
};
return withIsolationScope(() => c12527_2?.isolateTrace ? startNewTrace(runCallback2) : runCallback2());
}