UNPKG

insomnia-plugin-valorant

Version:
387 lines 19.9 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const log_sleuth_1 = __importStar(require("./util/log-sleuth")); const try_in_order_1 = require("./util/try-in-order"); const read_lockfile_1 = require("./util/read-lockfile"); const has_workspace_actions_bug_1 = require("./util/has-workspace-actions-bug"); const open_webview_popup_1 = require("./util/auth/open-webview-popup"); const webview_logout_1 = require("./util/auth/webview-logout"); const auth_from_riot_client_1 = require("./util/auth/auth-from-riot-client"); const check_webview_data_1 = require("./util/auth/check-webview-data"); const get_region_1 = require("./util/auth/get-region"); const get_entitlement_1 = require("./util/auth/get-entitlement"); const get_pregame_match_id_1 = require("./util/api/get-pregame-match-id"); const get_current_game_match_id_1 = require("./util/api/get-current-game-match-id"); const get_party_id_1 = require("./util/api/get-party-id"); const only_one_1 = require("./util/only-one"); const cache_result_1 = require("./util/cache-result"); const get_pas_token_1 = require("./util/auth/get-pas-token"); const XMPPManager_1 = require("./xmpp/XMPPManager"); const XMPPMITMManager_1 = require("./xmpp/XMPPMITMManager"); module.exports.workspaceActions = [ { label: 'Remove Saved Valorant Data', action: async (context) => { // cookies and region are not used anymore, but are kept for clearing old data await Promise.all(['successfulLogin', 'expiresAt', 'cookies', 'token', 'entitlement', 'puuid', 'region'].map(key => context.store.removeItem(key))); context['app'].alert('Cleared Valorant data!'); } }, { label: 'Riot Login', action: async (context) => { //TODO make popup open immediately and show a loading screen until the logout action completes await (0, webview_logout_1.webviewLogout)(); try { const partialAuthInfo = await (0, open_webview_popup_1.openWebViewPopup)(context); cachedAuthInfo = { ...partialAuthInfo, entitlement: await (0, get_entitlement_1.getEntitlement)(partialAuthInfo.accessToken) }; } catch (ignored) { } } }, { label: 'Riot Logout', action: async () => { await (0, webview_logout_1.webviewLogout)(); } } ]; if ((0, has_workspace_actions_bug_1.hasWorkspaceActionsBug)()) { module.exports.requestActions = module.exports.workspaceActions; } const xmppManager = new XMPPManager_1.XMPPManager(); const xmppMITMManager = new XMPPMITMManager_1.XMPPMITMManager(); const defaultClientPlatformString = 'ew0KCSJwbGF0Zm9ybVR5cGUiOiAiUEMiLA0KCSJwbGF0Zm9ybU9TIjogIldpbmRvd3MiLA0KCSJwbGF0Zm9ybU9TVmVyc2lvbiI6ICIxMC4wLjE5MDQyLjEuMjU2LjY0Yml0IiwNCgkicGxhdGZvcm1DaGlwc2V0IjogIlVua25vd24iDQp9'; let cachedCompleteLogInfo = undefined; let cachedAuthInfo = undefined; let cachedRegionInfo = undefined; let cachedClientVersion = undefined; async function getOrLoadLogInfo() { if (cachedCompleteLogInfo !== undefined) return cachedCompleteLogInfo; const info = await (0, log_sleuth_1.default)(); if (!info) throw new Error('Could not find log info'); for (const key of log_sleuth_1.infoKeys) { if (info[key] === undefined) throw new Error(`Could not find log info for ${key}`); } cachedCompleteLogInfo = info; return cachedCompleteLogInfo; } async function getOrLoadAuthInfo() { if (cachedAuthInfo !== undefined && cachedAuthInfo.expiresAt > Date.now()) return cachedAuthInfo; try { const partialAuthInfo = await (0, try_in_order_1.tryInOrderLabeled)([ { label: 'Use auth from Riot Client', func: async () => await (0, auth_from_riot_client_1.authFromRiotClient)() }, { label: 'Use auth from stored login workspace action', func: async () => await (0, check_webview_data_1.checkWebViewData)() } ]); cachedAuthInfo = { ...partialAuthInfo, entitlement: await (0, get_entitlement_1.getEntitlement)(partialAuthInfo.accessToken) }; return cachedAuthInfo; } catch (e) { let message = `${e}\n\nTry logging in with the "Riot Login" workspace action`; if ((0, has_workspace_actions_bug_1.hasWorkspaceActionsBug)()) { message += '\n\nNote - It seems like you\'re using a version of Insomnia that has a bug with workspace actions. As a workaround, you can use the dropdown actions on a request.'; } throw new Error(message); } } async function getOrLoadPASToken() { if (cachedAuthInfo?.pasToken !== undefined && cachedAuthInfo.expiresAt > Date.now()) return cachedAuthInfo.pasToken; const authInfo = await getOrLoadAuthInfo(); cachedAuthInfo = { ...authInfo, pasToken: await (0, get_pas_token_1.getPASToken)(authInfo.accessToken) }; return cachedAuthInfo.pasToken; } async function getOrLoadRegionInfo() { if (cachedRegionInfo !== undefined) return cachedRegionInfo; if (cachedCompleteLogInfo !== undefined) { cachedRegionInfo = { region: cachedCompleteLogInfo.region, shard: cachedCompleteLogInfo.shard }; return cachedRegionInfo; } try { const logInfo = await getOrLoadLogInfo(); cachedRegionInfo = { region: logInfo.region, shard: logInfo.shard }; return cachedRegionInfo; } catch (logError) { try { const authInfo = await getOrLoadAuthInfo(); cachedRegionInfo = await (0, get_region_1.getRegion)(authInfo.accessToken, authInfo.idToken); return cachedRegionInfo; } catch (authError) { throw [logError, authError]; } } } async function getOrLoadClientVersion() { if (cachedClientVersion !== undefined) return cachedClientVersion; /* note that the api endpoint and the logs have a different format for the version, but it seems both work log version: release-07.10-6-2100005 api version: release-07.10-shipping-6-2100005 */ cachedClientVersion = await (0, try_in_order_1.tryInOrder)([ async () => (await getOrLoadLogInfo()).clientVersion, async () => (await (await fetch('https://valorant-api.com/v1/version')).json()).data.riotClientVersion ]); return cachedClientVersion; } // Some names are preceded by "valorant_" because I expect they might conflict with tags added by other plugins module.exports.templateTags = [ { name: 'client_platform', displayName: 'Client Platform', description: 'Valorant client platform', run: (0, only_one_1.onlyOne)(async (ctx) => { if (ctx.valorantOverrides?.clientPlatform !== undefined && ctx.valorantOverrides.clientPlatform.length !== 0) return ctx.valorantOverrides.clientPlatform; return defaultClientPlatformString; }) }, { name: 'client_version', displayName: 'Client Version', description: 'Valorant client version', run: (0, only_one_1.onlyOne)(async (ctx) => { if (ctx.valorantOverrides?.clientVersion !== undefined && ctx.valorantOverrides.clientVersion.length !== 0) return ctx.valorantOverrides.clientVersion; return await getOrLoadClientVersion(); }) }, { name: 'lockfile_port', displayName: 'Lockfile Port', description: 'Valorant lockfile port', run: (0, only_one_1.onlyOne)(async (ctx) => { if (ctx.valorantOverrides?.lockfilePort !== undefined && ctx.valorantOverrides.lockfilePort.length !== 0) return ctx.valorantOverrides.lockfilePort; try { return (await (0, read_lockfile_1.readLockfile)()).port; } catch (e) { throw new Error('Lockfile not found! Is Valorant running?'); } }) }, { name: 'lockfile_password', displayName: 'Lockfile Password', description: 'Valorant lockfile password', run: (0, only_one_1.onlyOne)(async (ctx) => { if (ctx.valorantOverrides?.lockfilePassword !== undefined && ctx.valorantOverrides.lockfilePassword.length !== 0) return ctx.valorantOverrides.lockfilePassword; try { return (await (0, read_lockfile_1.readLockfile)()).password; } catch (e) { throw new Error('Lockfile not found! Is Valorant running?'); } }) }, { name: 'puuid', displayName: 'PUUID', description: 'Valorant PUUID', run: (0, only_one_1.onlyOne)(async (ctx) => { if (ctx.valorantOverrides?.puuid !== undefined && ctx.valorantOverrides.puuid.length !== 0) return ctx.valorantOverrides.puuid; if (cachedAuthInfo !== undefined) return cachedAuthInfo.puuid; if (cachedCompleteLogInfo !== undefined) return cachedCompleteLogInfo.puuid; return await (0, try_in_order_1.tryInOrderLabeled)([ { label: 'Use puuid from log file scraping', func: async () => (await getOrLoadLogInfo()).puuid }, { label: 'Use puuid from auth info', func: async () => (await getOrLoadAuthInfo()).puuid } ]); }) }, { name: 'valorant_region', displayName: 'Region', description: 'Valorant account region', run: (0, only_one_1.onlyOne)(async (ctx) => { if (ctx.valorantOverrides?.region !== undefined && ctx.valorantOverrides.region.length !== 0) return ctx.valorantOverrides.region; if (cachedRegionInfo !== undefined) return cachedRegionInfo.region; return (await getOrLoadRegionInfo()).region; }) }, { name: 'valorant_shard', displayName: 'Shard', description: 'Valorant account shard', run: (0, only_one_1.onlyOne)(async (ctx) => { if (ctx.valorantOverrides?.shard !== undefined && ctx.valorantOverrides.shard.length !== 0) return ctx.valorantOverrides.shard; if (cachedRegionInfo !== undefined) return cachedRegionInfo.shard; return (await getOrLoadRegionInfo()).shard; }) }, { name: 'valorant_token', displayName: 'Token', description: 'Valorant auth token', run: (0, only_one_1.onlyOne)(async (ctx) => { if (ctx.valorantOverrides?.token !== undefined && ctx.valorantOverrides.token.length !== 0) return ctx.valorantOverrides.token; return (await getOrLoadAuthInfo()).accessToken; }) }, { name: 'valorant_entitlement', displayName: 'Entitlement', description: 'Valorant entitlement token', run: (0, only_one_1.onlyOne)(async (ctx) => { if (ctx.valorantOverrides?.entitlement !== undefined && ctx.valorantOverrides.entitlement.length !== 0) return ctx.valorantOverrides.entitlement; return (await getOrLoadAuthInfo()).entitlement; }) }, { name: 'valorant_id_token', displayName: 'ID Token', description: 'Valorant ID token', run: (0, only_one_1.onlyOne)(async (ctx) => { if (ctx.valorantOverrides?.idToken !== undefined && ctx.valorantOverrides.idToken.length !== 0) return ctx.valorantOverrides.idToken; return (await getOrLoadAuthInfo()).idToken; }) }, { name: 'valorant_pas_token', displayName: 'PAS Token', description: 'Valorant PAS token', run: (0, only_one_1.onlyOne)(async (ctx) => { if (ctx.valorantOverrides?.pasToken !== undefined && ctx.valorantOverrides.pasToken.length !== 0) return ctx.valorantOverrides.pasToken; return await getOrLoadPASToken(); }) }, { name: 'pregame_match_id', displayName: 'Pre-Game Match ID', description: 'Valorant pre-game match ID', run: (0, cache_result_1.cacheResult)(1_000, (0, only_one_1.onlyOne)(async (ctx) => { if (ctx.valorantOverrides?.pregameMatchId !== undefined && ctx.valorantOverrides.pregameMatchId.length !== 0) return ctx.valorantOverrides.pregameMatchId; //TODO refactor this to make the overrides easier to read and remove duplicate logic const token = (ctx.valorantOverrides?.token !== undefined && ctx.valorantOverrides.token.length !== 0) ? ctx.valorantOverrides.token : (await getOrLoadAuthInfo()).accessToken; const entitlement = (ctx.valorantOverrides?.entitlement !== undefined && ctx.valorantOverrides.entitlement.length !== 0) ? ctx.valorantOverrides.entitlement : (await getOrLoadAuthInfo()).entitlement; const region = (ctx.valorantOverrides?.region !== undefined && ctx.valorantOverrides.region.length !== 0) ? ctx.valorantOverrides.region : (await getOrLoadRegionInfo()).region; const shard = (ctx.valorantOverrides?.shard !== undefined && ctx.valorantOverrides.shard.length !== 0) ? ctx.valorantOverrides.shard : (await getOrLoadRegionInfo()).shard; const puuid = (ctx.valorantOverrides?.puuid !== undefined && ctx.valorantOverrides.puuid.length !== 0) ? ctx.valorantOverrides.puuid : (await getOrLoadAuthInfo()).puuid; const clientVersion = (ctx.valorantOverrides?.clientVersion !== undefined && ctx.valorantOverrides.clientVersion.length !== 0) ? ctx.valorantOverrides.clientVersion : await getOrLoadClientVersion(); const clientPlatform = ctx.valorantOverrides?.clientPlatform !== undefined && ctx.valorantOverrides.clientPlatform.length !== 0 ? ctx.valorantOverrides.clientPlatform : defaultClientPlatformString; return await (0, get_pregame_match_id_1.getPregameMatchId)(shard, region, puuid, clientVersion, clientPlatform, token, entitlement); })) }, { name: 'current_game_match_id', displayName: 'Current Game Match ID', description: 'Valorant current game match ID', run: (0, cache_result_1.cacheResult)(1_000, (0, only_one_1.onlyOne)(async (ctx) => { if (ctx.valorantOverrides?.currentGameMatchId !== undefined && ctx.valorantOverrides.currentGameMatchId.length !== 0) return ctx.valorantOverrides.currentGameMatchId; const token = (ctx.valorantOverrides?.token !== undefined && ctx.valorantOverrides.token.length !== 0) ? ctx.valorantOverrides.token : (await getOrLoadAuthInfo()).accessToken; const entitlement = (ctx.valorantOverrides?.entitlement !== undefined && ctx.valorantOverrides.entitlement.length !== 0) ? ctx.valorantOverrides.entitlement : (await getOrLoadAuthInfo()).entitlement; const region = (ctx.valorantOverrides?.region !== undefined && ctx.valorantOverrides.region.length !== 0) ? ctx.valorantOverrides.region : (await getOrLoadRegionInfo()).region; const shard = (ctx.valorantOverrides?.shard !== undefined && ctx.valorantOverrides.shard.length !== 0) ? ctx.valorantOverrides.shard : (await getOrLoadRegionInfo()).shard; const puuid = (ctx.valorantOverrides?.puuid !== undefined && ctx.valorantOverrides.puuid.length !== 0) ? ctx.valorantOverrides.puuid : (await getOrLoadAuthInfo()).puuid; const clientVersion = (ctx.valorantOverrides?.clientVersion !== undefined && ctx.valorantOverrides.clientVersion.length !== 0) ? ctx.valorantOverrides.clientVersion : await getOrLoadClientVersion(); const clientPlatform = ctx.valorantOverrides?.clientPlatform !== undefined && ctx.valorantOverrides.clientPlatform.length !== 0 ? ctx.valorantOverrides.clientPlatform : defaultClientPlatformString; return (0, get_current_game_match_id_1.getCurrentGameMatchId)(shard, region, puuid, clientVersion, clientPlatform, token, entitlement); })) }, { name: 'party_id', displayName: 'Party ID', description: 'Valorant party ID', run: (0, cache_result_1.cacheResult)(1_000, (0, only_one_1.onlyOne)(async (ctx) => { if (ctx.valorantOverrides?.partyId !== undefined && ctx.valorantOverrides.partyId.length !== 0) return ctx.valorantOverrides.partyId; const token = (ctx.valorantOverrides?.token !== undefined && ctx.valorantOverrides.token.length !== 0) ? ctx.valorantOverrides.token : (await getOrLoadAuthInfo()).accessToken; const entitlement = (ctx.valorantOverrides?.entitlement !== undefined && ctx.valorantOverrides.entitlement.length !== 0) ? ctx.valorantOverrides.entitlement : (await getOrLoadAuthInfo()).entitlement; const region = (ctx.valorantOverrides?.region !== undefined && ctx.valorantOverrides.region.length !== 0) ? ctx.valorantOverrides.region : (await getOrLoadRegionInfo()).region; const shard = (ctx.valorantOverrides?.shard !== undefined && ctx.valorantOverrides.shard.length !== 0) ? ctx.valorantOverrides.shard : (await getOrLoadRegionInfo()).shard; const puuid = (ctx.valorantOverrides?.puuid !== undefined && ctx.valorantOverrides.puuid.length !== 0) ? ctx.valorantOverrides.puuid : (await getOrLoadAuthInfo()).puuid; const clientVersion = (ctx.valorantOverrides?.clientVersion !== undefined && ctx.valorantOverrides.clientVersion.length !== 0) ? ctx.valorantOverrides.clientVersion : await getOrLoadClientVersion(); const clientPlatform = ctx.valorantOverrides?.clientPlatform !== undefined && ctx.valorantOverrides.clientPlatform.length !== 0 ? ctx.valorantOverrides.clientPlatform : defaultClientPlatformString; return await (0, get_party_id_1.getPartyId)(shard, region, puuid, clientVersion, clientPlatform, token, entitlement); })) }, { name: 'xmpp_websocket_url', displayName: 'Riot XMPP', description: 'Riot XMPP websocket URL', run: (0, only_one_1.onlyOne)(async () => { return await xmppManager.getWebsocketURL(); }) }, { name: 'xmpp_mitm_websocket_url', displayName: 'Riot XMPP MITM', description: 'Riot XMPP MITM websocket URL', run: (0, only_one_1.onlyOne)(async () => { return await xmppMITMManager.getWebsocketURL(); }) } ]; //# sourceMappingURL=index.js.map