decord/alpha/source/lib/superagentPatch.tsx

487 lines
16 KiB
TypeScript
Raw Permalink Normal View History

2026-10-13 12:43:34 +00:00
// Module ID: 18014
// Function ID: 18015
// Name: superagentPatch
2026-10-13 12:43:34 +00:00
// Dependencies: [5, 5016, 1085, 1296, 18015, 1384, 1453, 584, 1295, 502, 1370, 2129, 1390, 1265, 1382, 18016, 1127, 18017, 18018, 7, 1255, 18021, 2000, 5727, 16286, 7022, 6100, 18031, 5903, 18032, 1481, 2]
2026-07-20 16:05:17 +00:00
2026-10-13 12:43:34 +00:00
// Module 18014 (superagentPatch)
import LogAggregatorAll from "LogAggregator" /* 7 */;
2026-10-03 08:58:59 +00:00
import Constants from "Constants" /* 1085 */;
2026-10-09 10:00:15 +00:00
import SentryUtilsDefault from "SentryUtils" /* 1255 */;
import RequestDefault from "Request" /* 1296 */;
import asyncRequire from "asyncRequire" /* 2000 */;
2026-10-12 06:59:38 +00:00
import UserLimitedAccessUtils from "UserLimitedAccessUtils" /* 7022 */;
2026-10-13 12:43:34 +00:00
import IdGenerator from "IdGenerator" /* 18015 */;
import getTimeZoneDefault from "getTimeZone" /* 18017 */;
import trackHttpRequestDefault from "trackHttpRequest" /* 18018 */;
import GuildLimitedAccessUtils from "GuildLimitedAccessUtils" /* 18031 */;
2026-10-03 08:58:59 +00:00
import _asyncToGenerator from "_asyncToGenerator" /* 5 */;
2026-10-10 08:08:14 +00:00
import ExperimentStore from "ExperimentStore" /* 5016 */;
2026-10-09 10:00:15 +00:00
import ApexExperiment from "ApexExperiment" /* 1453 */;
2026-10-03 08:58:59 +00:00
import Dispatcher from "Dispatcher" /* 584 */;
2026-10-09 10:00:15 +00:00
import HTTPUtils_mod from "HTTPUtils" /* 1295 */;
2026-10-03 08:58:59 +00:00
import size from "module_2" /* 2 */;
2026-07-23 10:11:24 +00:00
2026-10-03 08:58:59 +00:00
const require = globalThis.__r;
let c2, c3, c4, importAll, importDefault, status;
let obj2;
2026-07-20 16:05:17 +00:00
function isAnalyticsEndpoint(pathname) {
2026-07-29 08:29:29 +00:00
try {
const _URL = URL;
2026-10-03 08:58:59 +00:00
const self = this;
const self2 = this;
2026-07-29 08:29:29 +00:00
const uRL = new URL(pathname);
return re8.test(uRL.pathname);
2026-07-29 08:29:29 +00:00
} catch (err) {
2026-10-03 08:58:59 +00:00
return re8.test(pathname);
2026-07-29 08:29:29 +00:00
}
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const AbortCodes = Constants.AbortCodes;
2026-07-29 08:29:29 +00:00
let closure_6 = ["https://cdn.discordapp.com/bad-domains/updated_hashes.json", "https://cdn.discordapp.com/bad-domains/hashes.json"];
2026-10-03 08:58:59 +00:00
RequestDefault.parse[""] = JSON.parse;
const idGenerator = new IdGenerator.IdGenerator();
2026-07-29 08:29:29 +00:00
const re8 = /\/api(\/v\d+)?\/science/;
2026-10-03 08:58:59 +00:00
let obj = { name: "2026-07-reject-with-error-kill-switch", kind: "user", defaultConfig: { migrationKilled: false }, variations: obj2 };
obj2 = { 1: null };
obj2[1] = { migrationKilled: true };
const config = ApexExperiment.createApexExperiment(obj);
let closure_11 = null;
const subscription = Dispatcher.subscribe("LOGOUT", () => {
closure_11 = null;
2026-07-20 16:05:17 +00:00
});
2026-10-03 08:58:59 +00:00
let HTTPUtils = HTTPUtils_mod;
let result = HTTPUtils.setRejectWithMigratedError(function isRejectWithMigratedErrorEnabled() {
2026-08-24 06:08:38 +00:00
let tmp = closure_11;
if (null == closure_11) {
const hasLoadedExperiments = ExperimentStore.hasLoadedExperiments;
2026-07-29 08:29:29 +00:00
let tmp3 = !hasLoadedExperiments;
if (hasLoadedExperiments) {
const tmp5 = !config.getConfig({ location: "reject_with_error_migration" }).migrationKilled;
2026-08-24 06:08:38 +00:00
closure_11 = tmp5;
2026-07-29 08:29:29 +00:00
tmp3 = tmp5;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
tmp = tmp3;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return tmp;
2026-07-20 16:05:17 +00:00
});
2026-10-03 08:58:59 +00:00
HTTPUtils = HTTPUtils_mod;
let obj3 = {
2026-07-20 16:05:17 +00:00
prepareRequest(promise) {
2026-10-03 08:58:59 +00:00
let closure_1;
function populateQValues(items) {
let closure_0 = 10;
const reduced = items.reduce((arr, item) => {
if (10 === closure_0) {
arr.push(item);
} else {
const _HermesInternal = HermesInternal;
arr.push("" + item + ";q=0." + closure_0);
}
closure_0 = Math.max(closure_0 - 1, 1);
return arr;
}, []);
return reduced.join(",");
}
function getDatadogAPMUrl(generateResult) {
const str = new URLSearchParams();
str.append("query", "@http.x_client_trace_id:\"" + generateResult + "\"");
str.append("showAllSpans", "true");
const obj = closure_1(dependencyMap[5]);
const str2 = obj.toURLSafe("traces?" + str.toString(), "https://datadog.discord.tools/apm/");
let str1 = null;
if (null != str2) {
str1 = str2.toString();
}
return str1;
}
function shouldTrackHttpRequest(url) {
return !isAnalyticsEndpoint(url);
}
_require = promise;
const _default = require("AuthenticationStore").default;
const _default2 = require("DeveloperOptionsStore").default;
const _default3 = require("LocaleStore").default;
const _default4 = require("UserStore").default;
const _default5 = require("AnalyticsUtils").default;
const isPlatformEmbedded = require("PlatformUtils").isPlatformEmbedded;
2026-08-24 06:08:38 +00:00
importDefault = performance.now();
2026-07-20 16:05:17 +00:00
if ("/" === promise.url[0]) {
2026-10-03 08:58:59 +00:00
const tmpResult = require("HTTPUtils");
promise.url = tmpResult.getAPIBaseURL() + promise.url;
2026-07-29 08:29:29 +00:00
let tmp3 = "Authorization" in promise.header;
if (!tmp3) {
2026-10-03 08:58:59 +00:00
let str = "authorization";
2026-07-29 08:29:29 +00:00
tmp3 = "authorization" in promise.header;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (!tmp3) {
const result = promise.set("Authorization", _default.getToken());
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const tmpResult2 = require("updateDynamicSuperProperties");
const result1 = tmpResult2.updateDynamicSuperProperties();
const superPropertiesBase64 = _default5.getSuperPropertiesBase64();
2026-07-20 16:05:17 +00:00
if (null != superPropertiesBase64) {
2026-10-03 08:58:59 +00:00
let str2 = "X-Super-Properties";
2026-07-29 08:29:29 +00:00
const result2 = promise.set("X-Super-Properties", superPropertiesBase64);
2026-07-20 16:05:17 +00:00
}
const fingerprint = _default.getFingerprint();
2026-10-03 08:58:59 +00:00
let tmp10 = null != fingerprint && "" !== fingerprint;
2026-07-29 08:29:29 +00:00
if (tmp10) {
const result3 = promise.set("X-Fingerprint", fingerprint);
2026-07-20 16:05:17 +00:00
}
const installationForTracking = _default.getInstallationForTracking();
2026-10-03 08:58:59 +00:00
let tmp13 = null != installationForTracking && "" !== installationForTracking;
2026-07-29 08:29:29 +00:00
if (tmp13) {
const result4 = promise.set("X-Installation-ID", installationForTracking);
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
if (isPlatformEmbedded) {
2026-07-29 08:29:29 +00:00
let items = [];
2026-10-03 08:58:59 +00:00
const _default6 = require("react-native").default;
if (null != _default6) {
let Languages = _default6.getConstants().Languages;
2026-07-29 08:29:29 +00:00
if (Languages == null) {
2026-07-20 16:05:17 +00:00
Languages = [];
}
items = Languages;
}
2026-10-03 08:58:59 +00:00
const result5 = promise.set("Accept-Language", populateQValues(items));
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const result6 = promise.set("X-Discord-Locale", _default3.locale);
const tmp18 = getTimeZoneDefault();
if (null != tmp18) {
const result7 = promise.set("X-Discord-Timezone", tmp18);
2026-07-20 16:05:17 +00:00
}
const debugOptionsHeaderValue = _default2.getDebugOptionsHeaderValue();
2026-10-03 08:58:59 +00:00
const tmp21 = null != debugOptionsHeaderValue && "" !== debugOptionsHeaderValue;
if (tmp21) {
2026-07-29 08:29:29 +00:00
const result8 = promise.set("X-Debug-Options", debugOptionsHeaderValue);
2026-07-20 16:05:17 +00:00
}
const routingKeyHeaderValue = _default2.getRoutingKeyHeaderValue();
2026-10-03 08:58:59 +00:00
const tmp24 = null != routingKeyHeaderValue && "" !== routingKeyHeaderValue;
if (tmp24) {
2026-07-29 08:29:29 +00:00
const result9 = promise.set("X-Routing-Key", routingKeyHeaderValue);
2026-07-20 16:05:17 +00:00
}
if (_default2.isTracingRequests) {
2026-10-03 08:58:59 +00:00
const currentUser = _default4.getCurrentUser();
2026-07-29 08:29:29 +00:00
let str14;
2026-10-03 08:58:59 +00:00
const generate = idGenerator.generate;
2026-07-29 08:29:29 +00:00
if (currentUser != null) {
str14 = currentUser.id;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (str14 == null) {
str14 = "0";
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const generateResult = generate(str14);
2026-07-29 08:29:29 +00:00
const result10 = promise.set("x-client-trace-id", generateResult);
try {
const _URL = URL;
2026-10-03 08:58:59 +00:00
const self = this;
const self2 = this;
2026-07-29 08:29:29 +00:00
const uRL = new URL(promise.url);
if (!isAnalyticsEndpoint(uRL.pathname)) {
2026-10-03 08:58:59 +00:00
getDatadogAPMUrl(generateResult);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
} catch (err) {
2026-07-20 16:05:17 +00:00
}
}
}
2026-10-03 08:58:59 +00:00
importAll = shouldTrackHttpRequest(promise.url);
let obj2 = LogAggregatorAll;
obj2.report("Network", "Sending " + promise.method + " to " + promise.url);
2026-07-20 16:05:17 +00:00
promise.on("response", (status) => {
2026-10-03 08:58:59 +00:00
let method;
let status1;
let url;
2026-07-20 16:05:17 +00:00
let text = null;
if (null != status) {
text = null;
if (status.status >= 400) {
text = status.text;
}
}
let str = "";
if (null != text) {
const _HermesInternal = HermesInternal;
str = "and body: " + text;
}
2026-10-03 08:58:59 +00:00
({ method, url } = promise);
2026-07-20 16:05:17 +00:00
status = undefined;
2026-10-03 08:58:59 +00:00
const report = LogAggregatorAll.report;
LogAggregatorAll;
const tmp5 = promise;
2026-07-29 08:29:29 +00:00
if (status != null) {
2026-07-20 16:05:17 +00:00
status = status.status;
}
2026-10-03 08:58:59 +00:00
report("Network", "Completed " + method + " to " + url + " with status: " + status + " " + str);
const tmp8 = c2;
if (tmp8) {
const request = { url: null, method: null, status_code: status1, duration_ms: Math.round(performance.now() - closure_1) };
({ url: obj.url, method: obj.method } = tmp5);
status1 = undefined;
const tmp10 = trackHttpRequestDefault;
2026-07-29 08:29:29 +00:00
if (status != null) {
status1 = status.status;
}
const _Math = Math;
const _performance = performance;
2026-10-03 08:58:59 +00:00
tmp10(request);
2026-07-29 08:29:29 +00:00
c2 = false;
}
2026-07-20 16:05:17 +00:00
});
promise.on("error", (status, text) => {
2026-10-03 08:58:59 +00:00
let method;
let request;
let status1;
let url;
({ method, url } = promise);
2026-07-20 16:05:17 +00:00
status = undefined;
2026-10-03 08:58:59 +00:00
const report = LogAggregatorAll.report;
LogAggregatorAll;
2026-07-29 08:29:29 +00:00
if (status != null) {
2026-07-20 16:05:17 +00:00
status = status.status;
}
text = undefined;
2026-07-29 08:29:29 +00:00
if (text != null) {
2026-07-20 16:05:17 +00:00
text = text.text;
}
2026-10-03 08:58:59 +00:00
report("Network", "Failed " + method + " to " + url + " with status " + status + " and body: " + text);
2026-07-20 16:05:17 +00:00
if (null != status) {
if ("parse" in status) {
if (status.parse) {
let str = "[FILTERED]";
2026-10-03 08:58:59 +00:00
if (closure_6.includes(promise.url)) {
const xhr = tmp3.xhr;
2026-07-20 16:05:17 +00:00
let substr;
2026-07-29 08:29:29 +00:00
if (xhr != null) {
2026-07-20 16:05:17 +00:00
const responseText = xhr.responseText;
2026-07-29 08:29:29 +00:00
if (responseText != null) {
2026-07-20 16:05:17 +00:00
substr = responseText.slice(0, 1000);
}
}
str = substr;
}
2026-10-03 08:58:59 +00:00
const obj2 = { category: "superagent", message: "Failed to parse HTTP response.", data: request };
request = { method: null, url: null, responseText: str, status: status.status };
({ method: obj3.method, url: obj3.url } = promise);
const obj = SentryUtilsDefault;
obj.addBreadcrumb(obj2);
2026-07-20 16:05:17 +00:00
}
}
}
2026-10-03 08:58:59 +00:00
const tmp11 = c2;
if (tmp11) {
const request1 = { url: null, method: null, status_code: status1, duration_ms: Math.round(performance.now() - closure_1) };
({ url: obj4.url, method: obj4.method } = promise);
status1 = undefined;
const tmp13 = trackHttpRequestDefault;
2026-07-29 08:29:29 +00:00
if (text != null) {
status1 = text.status;
}
const _Math = Math;
const _performance = performance;
2026-10-03 08:58:59 +00:00
tmp13(request1);
2026-07-29 08:29:29 +00:00
c2 = false;
}
2026-07-20 16:05:17 +00:00
});
},
interceptResponse(statusCode, arg1, arg2) {
2026-10-03 08:58:59 +00:00
let flag;
let closure_0 = statusCode;
let closure_1 = arg1;
let closure_2 = arg2;
2026-07-20 16:05:17 +00:00
if (400 === statusCode.statusCode) {
2026-07-23 10:11:24 +00:00
let body = statusCode.body;
2026-10-03 08:58:59 +00:00
const tmp = null;
2026-07-29 08:29:29 +00:00
let captcha_key;
if (body != null) {
captcha_key = body.captcha_key;
}
if (captcha_key) {
2026-10-13 12:43:34 +00:00
const items = [asyncRequire(18021, dependencyMap.paths), asyncRequire(5727, dependencyMap.paths)];
2026-10-03 08:58:59 +00:00
const allResult = all(items);
const nextPromise = allResult.then((result) => {
const iter = result[Symbol.iterator]();
2026-07-29 08:29:29 +00:00
let nextResult;
if (iter !== undefined) {
nextResult = iter.next();
}
let nextResult1;
let tmp4 = tmp;
2026-10-03 08:58:59 +00:00
const _default = nextResult.default;
2026-07-29 08:29:29 +00:00
if (!tmp4) {
tmp4 = tmp6;
2026-10-03 08:58:59 +00:00
if (!tmp4) {
2026-07-29 08:29:29 +00:00
nextResult1 = iter.next();
tmp4 = tmp6;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
const extractCaptchaPropsFromResponse = nextResult1.extractCaptchaPropsFromResponse;
2026-07-29 08:29:29 +00:00
if (!tmp4) {
iter.return();
}
2026-10-03 08:58:59 +00:00
return _default.showCaptchaAsync(extractCaptchaPropsFromResponse(closure_0.body));
});
const nextPromise1 = nextPromise.then((X_Captcha_Key) => {
let captcha_rqtoken;
let captcha_session_id;
2026-07-29 08:29:29 +00:00
({ captcha_rqtoken, captcha_session_id } = X_Captcha_Key);
const obj = { "X-Captcha-Key": X_Captcha_Key.captcha_key };
if (null != captcha_rqtoken) {
obj["X-Captcha-Rqtoken"] = captcha_rqtoken;
}
if (null != captcha_session_id) {
obj["X-Captcha-Session-Id"] = captcha_session_id;
}
closure_1(obj);
2026-07-29 08:29:29 +00:00
});
2026-10-03 08:58:59 +00:00
nextPromise1.catch(arg2);
flag = true;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return flag;
2026-07-20 16:05:17 +00:00
}
if (401 === statusCode.statusCode) {
const body2 = statusCode.body;
let code;
2026-07-29 08:29:29 +00:00
if (body2 != null) {
2026-07-20 16:05:17 +00:00
code = body2.code;
}
if (code === AbortCodes.MFA_REQUIRED) {
const body3 = statusCode.body;
2026-07-29 08:29:29 +00:00
let mfa;
if (body3 != null) {
mfa = body3.mfa;
}
if (mfa) {
2026-10-13 12:43:34 +00:00
const promise4 = asyncRequire(16286, dependencyMap.paths);
2026-10-03 08:58:59 +00:00
const nextPromise2 = promise4.then((openMFAModal) => {
openMFAModal.openMFAModal(closure_0.body.mfa, closure_1, closure_2);
2026-07-29 08:29:29 +00:00
});
2026-10-03 08:58:59 +00:00
nextPromise2.catch(arg2);
flag = true;
2026-07-20 16:05:17 +00:00
}
}
}
const body4 = statusCode.body;
let code1;
2026-10-03 08:58:59 +00:00
const isLimitedAccessErrorCode = UserLimitedAccessUtils.isLimitedAccessErrorCode;
statusCode = statusCode.statusCode;
UserLimitedAccessUtils;
2026-07-29 08:29:29 +00:00
if (body4 != null) {
2026-07-20 16:05:17 +00:00
code1 = body4.code;
}
2026-10-03 08:58:59 +00:00
if (isLimitedAccessErrorCode(statusCode, code1)) {
2026-10-12 06:59:38 +00:00
const promise3 = asyncRequire(6100, dependencyMap.paths);
2026-10-03 08:58:59 +00:00
promise3.then((result) => {
result.default();
2026-07-20 16:05:17 +00:00
});
flag = false;
} else {
const body5 = statusCode.body;
let code2;
2026-10-13 12:43:34 +00:00
const isLimitedAccessErrorCode2 = tmp7(18031).isLimitedAccessErrorCode;
2026-10-03 08:58:59 +00:00
const statusCode2 = statusCode.statusCode;
GuildLimitedAccessUtils;
2026-07-29 08:29:29 +00:00
if (body5 != null) {
2026-07-20 16:05:17 +00:00
code2 = body5.code;
}
2026-10-03 08:58:59 +00:00
if (isLimitedAccessErrorCode2(statusCode2, code2)) {
2026-10-10 08:08:14 +00:00
const promise2 = asyncRequire(5903, dependencyMap.paths);
2026-10-03 08:58:59 +00:00
promise2.then((result) => {
const body = closure_0.body;
2026-07-20 16:05:17 +00:00
let guild_id;
2026-10-03 08:58:59 +00:00
const _default = result.default;
2026-07-29 08:29:29 +00:00
if (body != null) {
2026-07-20 16:05:17 +00:00
guild_id = body.guild_id;
}
2026-10-03 08:58:59 +00:00
_default(guild_id);
2026-07-20 16:05:17 +00:00
});
flag = false;
} else {
flag = 403 === statusCode.statusCode;
if (flag) {
const body6 = statusCode.body;
let code3;
2026-07-29 08:29:29 +00:00
if (body6 != null) {
2026-07-20 16:05:17 +00:00
code3 = body6.code;
}
flag = code3 === AbortCodes.RESTRICTED_HOURS_ACTIVE;
}
if (flag) {
2026-10-13 12:43:34 +00:00
const promise = asyncRequire(18032, dependencyMap.paths);
2026-10-03 08:58:59 +00:00
promise.then((openRestrictedHoursModal) => {
2026-07-20 16:05:17 +00:00
const result = openRestrictedHoursModal.openRestrictedHoursModal();
});
flag = false;
}
}
}
}
2026-10-03 08:58:59 +00:00
};
HTTPUtils.setRequestPatch(obj3);
HTTPUtils = HTTPUtils_mod;
const setAwaitOnline = HTTPUtils.setAwaitOnline;
let _require = _asyncToGenerator(async (arg0, value) => {
let closure_1;
let closure_2;
closure_0 = arg0;
if (c4 === 2) {
c4 = 3;
throw new TypeError("Generator functions may not be called on executing generators");
2026-10-03 08:58:59 +00:00
} else if (tmp3 === 3) {
if (arg0 === 1) {
throw value;
} else if (arg0 === 2) {
const obj2 = { value, done: true };
return obj2;
2026-07-29 08:29:29 +00:00
} else {
2026-10-12 06:59:38 +00:00
return { value: "IconComponent", done: null };
}
} else {
try {
c4 = 2;
2026-10-03 08:58:59 +00:00
if (0 === c3) {
if (arg0 === 1) {
c4 = 3;
throw value;
} else if (arg0 === 2) {
c4 = 3;
const obj3 = { value, done: true };
return obj3;
} else {
const _HermesInternal2 = HermesInternal;
2026-10-03 08:58:59 +00:00
const obj7 = tmp4(c3[19]);
obj7.report("Network", "Request to " + closure_0 + " failed, will retry.");
const obj8 = tmp(c3[30]);
const tmp22 = tmp;
if (!obj8.isOnline()) {
const tmp22Result = tmp22(c3[30]);
c3 = 1;
c4 = 1;
2026-10-03 08:58:59 +00:00
const obj4 = { value: tmp22Result.awaitOnline(), done: false };
return obj4;
2026-07-29 08:29:29 +00:00
}
}
} else if (arg0 === 1) {
2026-07-29 08:29:29 +00:00
c4 = 3;
throw value;
2026-10-03 08:58:59 +00:00
} else if (arg0 === 2) {
c4 = 3;
const obj5 = { value, done: true };
return obj5;
} else {
const _HermesInternal = HermesInternal;
2026-10-03 08:58:59 +00:00
const obj = tmp4(c3[19]);
obj.report("Network", "Network detected online, retrying " + closure_0);
2026-07-29 08:29:29 +00:00
}
c4 = 3;
2026-10-12 06:59:38 +00:00
return { value: "IconComponent", done: null };
2026-10-03 08:58:59 +00:00
} catch (tmp13) {
c4 = 3;
throw tmp13;
2026-07-29 08:29:29 +00:00
}
}
2026-07-29 08:29:29 +00:00
});
2026-10-03 08:58:59 +00:00
setAwaitOnline(function() {
return closure_0(...arguments);
2026-07-29 08:29:29 +00:00
});
let result1 = size.fileFinishedImporting("lib/superagentPatch.tsx");