From b05984c7ba2960b4f5ce4a3370bfb7dd232883bc Mon Sep 17 00:00:00 2001 From: Ryan Wilson Date: Thu, 25 Jul 2024 14:24:18 -0400 Subject: [PATCH] Finish refactoring types in AeroSandbox --- .../build/customBuilds/frankenUV.workers.ts | 2 +- src/AeroSandbox/build/featureMembers.ts | 26 ++--- src/AeroSandbox/src/init$aero.ts | 4 + .../src/interceptors/concealer/blob.ts | 2 +- .../src/interceptors/concealer/css.ts | 2 +- .../src/interceptors/concealer/error.ts | 2 +- .../src/interceptors/concealer/launchQueue.ts | 2 +- .../concealer/misc/scriptSandboxing.ts | 2 +- .../interceptors/concealer/moduleScripts.ts | 2 +- .../src/interceptors/concealer/navigation.ts | 8 +- .../src/interceptors/concealer/payment.ts | 2 +- .../interceptors/concealer/presentation.ts | 2 +- .../src/interceptors/concealer/push.ts | 2 +- .../src/interceptors/concealer/secure.ts | 2 +- .../src/interceptors/loc/history.ts | 2 +- src/AeroSandbox/src/interceptors/loc/open.ts | 2 +- .../privacySandbox/credentials.ts | 2 +- .../src/interceptors/req/eventSource.ts | 2 +- src/AeroSandbox/src/interceptors/req/fetch.ts | 2 +- src/AeroSandbox/src/interceptors/req/wrtc.ts | 2 +- src/AeroSandbox/src/interceptors/req/ws.ts | 2 +- src/AeroSandbox/src/interceptors/req/wt.ts | 2 +- .../src/interceptors/storage/iDB.ts | 2 +- .../src/interceptors/storage/sharedStorage.ts | 2 +- .../src/interceptors/storage/sql.ts | 2 +- .../src/sandboxers/JS/JSRewriter.ts | 2 +- .../src/sandboxers/JS/backends/AeroGel.ts | 96 +++++++++---------- src/AeroSandbox/tsconfig.json | 1 - src/AeroSandbox/types/$aero.d.ts | 7 +- src/AeroSandbox/types/aeroSandbox.d.ts | 21 ++++ src/AeroSandbox/types/apiInterceptors.d.ts | 50 ++++++---- src/AeroSandbox/types/config.d.ts | 21 +--- src/AeroSandbox/types/customBuilds.d.ts | 1 + src/AeroSandbox/types/draftAPIs.d.ts | 3 - src/AeroSandbox/types/generic.ts | 1 + src/AeroSandbox/types/index.d.ts | 47 --------- src/AeroSandbox/types/rewriters.d.ts | 0 src/AeroSandbox/types/rewriters/html.d.ts | 2 + src/AeroSandbox/types/rewriters/js.d.ts | 2 + src/AeroSandbox/types/unsupportedAPIs.d.ts | 7 ++ src/config.ts | 54 +++++------ tsconfig.json | 86 ++++++++--------- 42 files changed, 230 insertions(+), 253 deletions(-) create mode 100644 src/AeroSandbox/src/init$aero.ts create mode 100644 src/AeroSandbox/types/aeroSandbox.d.ts create mode 100644 src/AeroSandbox/types/customBuilds.d.ts delete mode 100644 src/AeroSandbox/types/draftAPIs.d.ts create mode 100644 src/AeroSandbox/types/generic.ts delete mode 100644 src/AeroSandbox/types/index.d.ts delete mode 100644 src/AeroSandbox/types/rewriters.d.ts create mode 100644 src/AeroSandbox/types/unsupportedAPIs.d.ts diff --git a/src/AeroSandbox/build/customBuilds/frankenUV.workers.ts b/src/AeroSandbox/build/customBuilds/frankenUV.workers.ts index d916faa..a6fe2b7 100644 --- a/src/AeroSandbox/build/customBuilds/frankenUV.workers.ts +++ b/src/AeroSandbox/build/customBuilds/frankenUV.workers.ts @@ -1,4 +1,4 @@ -import { UVRewriterWorkerMembers } from "$types/index.d"; +import { UVRewriterWorkerMembers } from "$types/customBuilds"; import type { UVConfig } from "@titaniumnetwork-dev/ultraviolet"; import { defaultProxyFeatures } from "../../build/featureMembers"; diff --git a/src/AeroSandbox/build/featureMembers.ts b/src/AeroSandbox/build/featureMembers.ts index bae337e..0699d87 100644 --- a/src/AeroSandbox/build/featureMembers.ts +++ b/src/AeroSandbox/build/featureMembers.ts @@ -1,26 +1,26 @@ -import { InterceptionFeaturesEnum } from "$types/index.d"; +import { InterceptionFeaturesEnum } from "$types/apiInterceptors"; // TODO: Put all of these terms in the API Interception Glossary /** @note: These do not cover Origin Isolation although Origin Emulation is a type of Origin Isolation. Origin Emulation is a superset of Origin Isolation. */ const originEmulationFeatures = - InterceptionFeaturesEnum.corsEmulation | - InterceptionFeaturesEnum.cacheEmulation | - InterceptionFeaturesEnum.privacySandbox | - InterceptionFeaturesEnum.nestedSWs; + InterceptionFeaturesEnum.corsEmulation | + InterceptionFeaturesEnum.cacheEmulation | + InterceptionFeaturesEnum.privacySandbox | + InterceptionFeaturesEnum.nestedSWs; /** @note: These do not cover Origin Concealers although Origin Isolation is a type of Origin Concealing. Origin Isolation is a superset of Origin Concealment. */ const miscOriginIsolators = InterceptionFeaturesEnum.messageIsolation; const miscOriginConcealers = - InterceptionFeaturesEnum.elementConcealment | - InterceptionFeaturesEnum.errorConcealment; + InterceptionFeaturesEnum.elementConcealment | + InterceptionFeaturesEnum.errorConcealment; const defaultSWProxyFeatures = originEmulationFeatures | miscOriginConcealers; const defaultProxyFeatures = - defaultSWProxyFeatures | InterceptionFeaturesEnum.requestUrlProxifier; + defaultSWProxyFeatures | InterceptionFeaturesEnum.requestUrlProxifier; export { - originEmulationFeatures, - miscOriginIsolators, - miscOriginConcealers, - defaultSWProxyFeatures, - defaultProxyFeatures + originEmulationFeatures, + miscOriginIsolators, + miscOriginConcealers, + defaultSWProxyFeatures, + defaultProxyFeatures, }; diff --git a/src/AeroSandbox/src/init$aero.ts b/src/AeroSandbox/src/init$aero.ts new file mode 100644 index 0000000..b8f1220 --- /dev/null +++ b/src/AeroSandbox/src/init$aero.ts @@ -0,0 +1,4 @@ +import { AeroGlobalType } from "$types/$aero.d"; + +// The rest of the aero props are set in the SW injects before this file is executed +// I have no use for this file yet diff --git a/src/AeroSandbox/src/interceptors/concealer/blob.ts b/src/AeroSandbox/src/interceptors/concealer/blob.ts index 61a3ab4..851e4ca 100644 --- a/src/AeroSandbox/src/interceptors/concealer/blob.ts +++ b/src/AeroSandbox/src/interceptors/concealer/blob.ts @@ -1,4 +1,4 @@ -import { APIInterceptor } from "$types/index.d"; +import { APIInterceptor } from "$types/apiInterceptors"; import isHtml from "$shared/isHTML"; export default { diff --git a/src/AeroSandbox/src/interceptors/concealer/css.ts b/src/AeroSandbox/src/interceptors/concealer/css.ts index 619d9ba..6d8d3f2 100644 --- a/src/AeroSandbox/src/interceptors/concealer/css.ts +++ b/src/AeroSandbox/src/interceptors/concealer/css.ts @@ -6,7 +6,7 @@ */ import { afterPrefix } from "$shared/getProxyUrl"; -import { APIInterceptor, ExposedContextsEnum } from "$types/index.d"; +import { APIInterceptor, ExposedContextsEnum } from "$types/apiInterceptors"; // Proxy the getters for shadow root stylesheets diff --git a/src/AeroSandbox/src/interceptors/concealer/error.ts b/src/AeroSandbox/src/interceptors/concealer/error.ts index 7d5ae3f..4268137 100644 --- a/src/AeroSandbox/src/interceptors/concealer/error.ts +++ b/src/AeroSandbox/src/interceptors/concealer/error.ts @@ -1,4 +1,4 @@ -import { APIInterceptor, SupportEnum } from "$types/index.d"; +import { APIInterceptor, SupportEnum } from "$types/apiInterceptors"; import config from "$aero/config"; const { aeroPrefix } = config; diff --git a/src/AeroSandbox/src/interceptors/concealer/launchQueue.ts b/src/AeroSandbox/src/interceptors/concealer/launchQueue.ts index e108e06..e105847 100644 --- a/src/AeroSandbox/src/interceptors/concealer/launchQueue.ts +++ b/src/AeroSandbox/src/interceptors/concealer/launchQueue.ts @@ -1,4 +1,4 @@ -import { APIInterceptor, SupportEnum } from "$types/index.d"; +import { APIInterceptor, SupportEnum } from "$types/apiInterceptors"; import { afterPrefix } from "$shared/getProxyUrl"; diff --git a/src/AeroSandbox/src/interceptors/concealer/misc/scriptSandboxing.ts b/src/AeroSandbox/src/interceptors/concealer/misc/scriptSandboxing.ts index 133dad0..e93eb4d 100644 --- a/src/AeroSandbox/src/interceptors/concealer/misc/scriptSandboxing.ts +++ b/src/AeroSandbox/src/interceptors/concealer/misc/scriptSandboxing.ts @@ -2,7 +2,7 @@ import { APIInterceptor, ExposedContextsEnum, proxifiedObjGeneratorContext, -} from "$types/index.d"; +} from "$types/apiInterceptors"; import locationProxy from "$shared/proxyLocation"; diff --git a/src/AeroSandbox/src/interceptors/concealer/moduleScripts.ts b/src/AeroSandbox/src/interceptors/concealer/moduleScripts.ts index 05828db..d485aec 100644 --- a/src/AeroSandbox/src/interceptors/concealer/moduleScripts.ts +++ b/src/AeroSandbox/src/interceptors/concealer/moduleScripts.ts @@ -1,4 +1,4 @@ -import { APIInterceptor } from "$types/index.d"; +import { APIInterceptor } from "$types/apiInterceptors"; import { proxyLocation } from "$shared/proxyLocation"; /** diff --git a/src/AeroSandbox/src/interceptors/concealer/navigation.ts b/src/AeroSandbox/src/interceptors/concealer/navigation.ts index bd34f54..5a54308 100644 --- a/src/AeroSandbox/src/interceptors/concealer/navigation.ts +++ b/src/AeroSandbox/src/interceptors/concealer/navigation.ts @@ -1,14 +1,10 @@ // Not finished -import config from "$aero/config"; -const { flags } = config; - -import { afterPrefix } from "$shared"; +import { afterPrefix } from "$shared/getProxyUrl"; import { proxyLocation } from "$shared/proxyLocation"; -import proxyMessage from "$shared/proxyMessage"; -import { APIInterceptor, SupportEnum } from "$types/index.d"; +import { APIInterceptor, SupportEnum } from "$types/apiInterceptors"; export default [ // Entries diff --git a/src/AeroSandbox/src/interceptors/concealer/payment.ts b/src/AeroSandbox/src/interceptors/concealer/payment.ts index f40a377..e1c2a6d 100644 --- a/src/AeroSandbox/src/interceptors/concealer/payment.ts +++ b/src/AeroSandbox/src/interceptors/concealer/payment.ts @@ -1,4 +1,4 @@ -import { APIInterceptor, SupportEnum } from "$types/index.d"; +import { APIInterceptor, SupportEnum } from "$types/apiInterceptors"; import { proxyGetString } from "$shared/stringProxy"; diff --git a/src/AeroSandbox/src/interceptors/concealer/presentation.ts b/src/AeroSandbox/src/interceptors/concealer/presentation.ts index d9645b1..080f417 100644 --- a/src/AeroSandbox/src/interceptors/concealer/presentation.ts +++ b/src/AeroSandbox/src/interceptors/concealer/presentation.ts @@ -1,4 +1,4 @@ -import { APIInterceptor, SupportEnum } from "$types/index.d"; +import { APIInterceptor, SupportEnum } from "$types/apiInterceptors"; import { proxyGetString } from "$shared/stringProxy"; diff --git a/src/AeroSandbox/src/interceptors/concealer/push.ts b/src/AeroSandbox/src/interceptors/concealer/push.ts index 16b1def..8b5e1b2 100644 --- a/src/AeroSandbox/src/interceptors/concealer/push.ts +++ b/src/AeroSandbox/src/interceptors/concealer/push.ts @@ -1,4 +1,4 @@ -import { APIInterceptor, ExposedContextsEnum } from "$types/index.d"; +import { APIInterceptor, ExposedContextsEnum } from "$types/apiInterceptors"; import { proxyGetString } from "$shared/stringProxy"; export default { diff --git a/src/AeroSandbox/src/interceptors/concealer/secure.ts b/src/AeroSandbox/src/interceptors/concealer/secure.ts index a44e483..ce66143 100644 --- a/src/AeroSandbox/src/interceptors/concealer/secure.ts +++ b/src/AeroSandbox/src/interceptors/concealer/secure.ts @@ -1,4 +1,4 @@ -import { APIInterceptor, ExposedContextsEnum } from "$types/index.d"; +import { APIInterceptor, ExposedContextsEnum } from "$types/apiInterceptors"; import config from "config"; const { flags } = config; diff --git a/src/AeroSandbox/src/interceptors/loc/history.ts b/src/AeroSandbox/src/interceptors/loc/history.ts index 56a67d1..95bdd58 100644 --- a/src/AeroSandbox/src/interceptors/loc/history.ts +++ b/src/AeroSandbox/src/interceptors/loc/history.ts @@ -1,4 +1,4 @@ -import { APIInterceptor, ExposedContextsEnum } from "$types/index.d"; +import { APIInterceptor, ExposedContextsEnum } from "$types/apiInterceptors"; import rewriteSrc from "$shared/src"; diff --git a/src/AeroSandbox/src/interceptors/loc/open.ts b/src/AeroSandbox/src/interceptors/loc/open.ts index 26cd459..614ff27 100644 --- a/src/AeroSandbox/src/interceptors/loc/open.ts +++ b/src/AeroSandbox/src/interceptors/loc/open.ts @@ -1,4 +1,4 @@ -import { APIInterceptor, ExposedContextsEnum } from "$types/index.d"; +import { APIInterceptor, ExposedContextsEnum } from "$types/apiInterceptors"; import rewriteSrc from "$shared/src"; diff --git a/src/AeroSandbox/src/interceptors/originIsolators/privacySandbox/credentials.ts b/src/AeroSandbox/src/interceptors/originIsolators/privacySandbox/credentials.ts index a2d7c8f..f2c965d 100644 --- a/src/AeroSandbox/src/interceptors/originIsolators/privacySandbox/credentials.ts +++ b/src/AeroSandbox/src/interceptors/originIsolators/privacySandbox/credentials.ts @@ -4,7 +4,7 @@ * This whole file encompasses the {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API WebAuthn}, {@link https://developer.mozilla.org/en-US/docs/Web/API/FedCM_API FedCM}, {@link https://wicg.github.io/web-otp WebOTP} APIs */ -import { APIInterceptor, ExposedContextsEnum } from "$types/index.d"; +import { APIInterceptor, ExposedContextsEnum } from "$types/apiInterceptors"; import { proxyLocation } from "$shared/proxyLocation"; import { afterPrefix } from "$shared/getProxyUrl"; diff --git a/src/AeroSandbox/src/interceptors/req/eventSource.ts b/src/AeroSandbox/src/interceptors/req/eventSource.ts index eaa389f..bb8bcf4 100644 --- a/src/AeroSandbox/src/interceptors/req/eventSource.ts +++ b/src/AeroSandbox/src/interceptors/req/eventSource.ts @@ -1,7 +1,7 @@ import { APIInterceptor, SpecialInterceptionFeaturesEnum, -} from "$types/index.d"; +} from "$types/apiInterceptors"; import { proxyConstructString } from "$shared/stringProxy"; diff --git a/src/AeroSandbox/src/interceptors/req/fetch.ts b/src/AeroSandbox/src/interceptors/req/fetch.ts index e1743a9..14a72ac 100644 --- a/src/AeroSandbox/src/interceptors/req/fetch.ts +++ b/src/AeroSandbox/src/interceptors/req/fetch.ts @@ -1,4 +1,4 @@ -import { APIInterceptor, ExposedContextsEnum } from "$types/index.d"; +import { APIInterceptor, ExposedContextsEnum } from "$types/apiInterceptors"; import { handleFetchEvent } from "$aero_browser/util/swlessUtils"; export default { diff --git a/src/AeroSandbox/src/interceptors/req/wrtc.ts b/src/AeroSandbox/src/interceptors/req/wrtc.ts index 8242be6..77d6149 100644 --- a/src/AeroSandbox/src/interceptors/req/wrtc.ts +++ b/src/AeroSandbox/src/interceptors/req/wrtc.ts @@ -2,7 +2,7 @@ import { AltProtocolEnum, APIInterceptor, ExposedContextsEnum, -} from "$types/index.d"; +} from "$types/apiInterceptors"; import config from "$aero/config"; const { wrtcBackends } = config; diff --git a/src/AeroSandbox/src/interceptors/req/ws.ts b/src/AeroSandbox/src/interceptors/req/ws.ts index 3a22f06..b909fe1 100644 --- a/src/AeroSandbox/src/interceptors/req/ws.ts +++ b/src/AeroSandbox/src/interceptors/req/ws.ts @@ -1,4 +1,4 @@ -import { AltProtocolEnum, APIInterceptor } from "$types/index.d"; +import { AltProtocolEnum, APIInterceptor } from "$types/apiInterceptors"; import { BareClient } from "@mercuryworkshop/bare-mux"; diff --git a/src/AeroSandbox/src/interceptors/req/wt.ts b/src/AeroSandbox/src/interceptors/req/wt.ts index 69a617b..db4a1a1 100644 --- a/src/AeroSandbox/src/interceptors/req/wt.ts +++ b/src/AeroSandbox/src/interceptors/req/wt.ts @@ -1,4 +1,4 @@ -import { APIInterceptor } from "$types/index.d"; +import { APIInterceptor } from "$types/apiInterceptors"; // Only supported on Chromium export default { diff --git a/src/AeroSandbox/src/interceptors/storage/iDB.ts b/src/AeroSandbox/src/interceptors/storage/iDB.ts index 6341cb0..169fd25 100644 --- a/src/AeroSandbox/src/interceptors/storage/iDB.ts +++ b/src/AeroSandbox/src/interceptors/storage/iDB.ts @@ -1,4 +1,4 @@ -import { APIInterceptor } from "$types/index.d"; +import { APIInterceptor } from "$types/apiInterceptors"; import config from "$aero/config"; diff --git a/src/AeroSandbox/src/interceptors/storage/sharedStorage.ts b/src/AeroSandbox/src/interceptors/storage/sharedStorage.ts index 81a581a..88cd401 100644 --- a/src/AeroSandbox/src/interceptors/storage/sharedStorage.ts +++ b/src/AeroSandbox/src/interceptors/storage/sharedStorage.ts @@ -1,5 +1,5 @@ import config from "$aero/config"; -import { APIInterceptor } from "$types/index.d"; +import { APIInterceptor } from "$types/apiInterceptors"; const { prefix } = config; import { storageNomenclature } from "./shared"; diff --git a/src/AeroSandbox/src/interceptors/storage/sql.ts b/src/AeroSandbox/src/interceptors/storage/sql.ts index a03f2d5..aa3ebca 100644 --- a/src/AeroSandbox/src/interceptors/storage/sql.ts +++ b/src/AeroSandbox/src/interceptors/storage/sql.ts @@ -1,4 +1,4 @@ -import { APIInterceptor, SupportEnum } from "$types/index.d"; +import { APIInterceptor, SupportEnum } from "$types/apiInterceptors"; import config from "$aero/config"; const { prefix } = config; diff --git a/src/AeroSandbox/src/sandboxers/JS/JSRewriter.ts b/src/AeroSandbox/src/sandboxers/JS/JSRewriter.ts index aa1fa94..3b43607 100644 --- a/src/AeroSandbox/src/sandboxers/JS/JSRewriter.ts +++ b/src/AeroSandbox/src/sandboxers/JS/JSRewriter.ts @@ -4,7 +4,7 @@ import { aerogelParser, astParser, astWalker, -} from "../../../types/aeroSandbox"; +} from "../../../types/rewriters/js"; import ASTRewriter from "./backends/AST"; import AeroGel from "./backends/AeroGel"; diff --git a/src/AeroSandbox/src/sandboxers/JS/backends/AeroGel.ts b/src/AeroSandbox/src/sandboxers/JS/backends/AeroGel.ts index 8184f39..e3f7f64 100644 --- a/src/AeroSandbox/src/sandboxers/JS/backends/AeroGel.ts +++ b/src/AeroSandbox/src/sandboxers/JS/backends/AeroGel.ts @@ -1,8 +1,8 @@ import { - AeroGelConfig, - aerogelParser, - keywordReplacementType -} from "../../../../types/index"; + AeroGelConfig, + aerogelParser, + keywordReplacementType, +} from "../../../../types/aeroSandbox"; //import esniff from "esniff"; @@ -11,25 +11,25 @@ var INCLUDE_ESNIFF: boolean; // TODO: Setup test cases export default class AeroGel { - config: AeroGelConfig; - constructor(config: AeroGelConfig) { - this.config = config; - } - applyNewConfig(config: AeroGelConfig) { - this.config = config; - } - static supportedParsers(): aerogelParser[] { - let supports: aerogelParser[] = []; - if (INCLUDE_ESNIFF) supports.push("esniff"); - return supports; - } - /** This essentially the rewriter - * @param script The script to jail. Before it is jailed the let/const to fake vars RegExp rewriting occurs. - * @param isModule Module scripts don't need to be rewritten because they don't require fake vars for scope emulation since module scripts run in their own isolated scope. - * @example TODO: Provide an example - */ - jailScript(script: string, isModule: boolean) { - return /* js */ ` + config: AeroGelConfig; + constructor(config: AeroGelConfig) { + this.config = config; + } + applyNewConfig(config: AeroGelConfig) { + this.config = config; + } + static supportedParsers(): aerogelParser[] { + let supports: aerogelParser[] = []; + if (INCLUDE_ESNIFF) supports.push("esniff"); + return supports; + } + /** This essentially the rewriter + * @param script The script to jail. Before it is jailed the let/const to fake vars RegExp rewriting occurs. + * @param isModule Module scripts don't need to be rewritten because they don't require fake vars for scope emulation since module scripts run in their own isolated scope. + * @example TODO: Provide an example + */ + jailScript(script: string, isModule: boolean) { + return /* js */ ` !() => { ${isModule ? script : this.rewriteScript(script)} }().call({ @@ -38,10 +38,10 @@ export default class AeroGel { location: ${this.config.objPaths.proxy.location} }); `; - } - /** This method is specifically for `var keyword rewriting` */ - rewriteScript(script: string): string { - /* + } + /** This method is specifically for `var keyword rewriting` */ + rewriteScript(script: string): string { + /* if (INCLUDE_ESNIFF) { let letIndicies = []; let constIndicies = []; @@ -73,27 +73,23 @@ export default class AeroGel { script = this.replaceKeywords(script, keywordReplacements); } */ - return script; - } - replaceKeywords( - str: string, - keywordReplacements: keywordReplacementType - ): string { - const charArr = Array.from(str); - let totalAddedToIndex = 0; - for (const [indexStr, replacementData] of Object.entries( - keywordReplacements - )) { - const { keywordLen, replacementStr } = replacementData; - const index = parseInt(indexStr); - const replacementArr = Array.from(replacementStr); - totalAddedToIndex += replacementArr.length - keywordLen; - charArr.splice( - index + totalAddedToIndex, - keywordLen, - replacementStr - ); - } - return charArr.join(""); - } + return script; + } + replaceKeywords( + str: string, + keywordReplacements: keywordReplacementType + ): string { + const charArr = Array.from(str); + let totalAddedToIndex = 0; + for (const [indexStr, replacementData] of Object.entries( + keywordReplacements + )) { + const { keywordLen, replacementStr } = replacementData; + const index = parseInt(indexStr); + const replacementArr = Array.from(replacementStr); + totalAddedToIndex += replacementArr.length - keywordLen; + charArr.splice(index + totalAddedToIndex, keywordLen, replacementStr); + } + return charArr.join(""); + } } diff --git a/src/AeroSandbox/tsconfig.json b/src/AeroSandbox/tsconfig.json index 333c181..be00ee3 100644 --- a/src/AeroSandbox/tsconfig.json +++ b/src/AeroSandbox/tsconfig.json @@ -19,7 +19,6 @@ }, "include": [ "src/**/*.ts", - "build/customBuilds/**/*.ts", "./config.ts", "types/**/*.d.ts", "src/interceptors/concealer/element.ts.old", diff --git a/src/AeroSandbox/types/$aero.d.ts b/src/AeroSandbox/types/$aero.d.ts index afd2814..7cb17fe 100644 --- a/src/AeroSandbox/types/$aero.d.ts +++ b/src/AeroSandbox/types/$aero.d.ts @@ -1,13 +1,14 @@ -import type { AeroSandboxLogger } from "$aero/src/shared/Loggers"; -import type { BareTransport } from "@mercuryworkshop/bare-mux"; +import type { AeroSandboxLogger } from "$shared/Loggers"; +import type BareClient from "@mercuryworkshop/bare-mux"; -interface AeroGlobalType { +export interface AeroGlobalType { $sec: { csp: string; init: string; }; $bc: BareClient; logger: AeroSandboxLogger; + prefix: string; } declare global { diff --git a/src/AeroSandbox/types/aeroSandbox.d.ts b/src/AeroSandbox/types/aeroSandbox.d.ts new file mode 100644 index 0000000..7ca2263 --- /dev/null +++ b/src/AeroSandbox/types/aeroSandbox.d.ts @@ -0,0 +1,21 @@ +import { SupportEnum, InterceptionFeaturesEnum } from "$types/apiInterceptors"; + +import type { BareTransport } from "@mercuryworkshop/bare-mux"; + +export interface AeroSandboxConfig { + proxyConfig: ProxyConfig; + /** These enum members enable code inside of the Proxy handler that provide other things you may want to use AeroSandbox for */ + specialInterceptionFeatures?: InterceptionFeaturesEnum; + supports: SupportEnum; + proxyGlobalContext: "$aero"; +} + +// This is the typical proxy config. This is only what is used to format and unformat urls. +export type ProxyConfig = { + BareTransport: BareTransport; + prefix: string; + encodeUrl: (url: string) => string; + decodeUrl: (url: string) => string; + // This is for WebRTC proxying. The API is disabled, if this isn't provided. + webrtcTurnServers?: string[]; +}; diff --git a/src/AeroSandbox/types/apiInterceptors.d.ts b/src/AeroSandbox/types/apiInterceptors.d.ts index 3f6e8ac..9c5ec33 100644 --- a/src/AeroSandbox/types/apiInterceptors.d.ts +++ b/src/AeroSandbox/types/apiInterceptors.d.ts @@ -1,19 +1,22 @@ -type overwriteRecordsType = { [key: string]; Object }; +import { overwriteRecordsType } from "$types/generic"; // biome-ignore lint/suspicious/noExplicitAny: -type revokableProxyRet = { proxy: any; revoke: () => void }; +export type revokableProxyRet = { proxy: any; revoke: () => void }; interface proxifiedObjGeneratorContext { specialInterceptionFeatures?: InterceptionFeaturesEnum; // might be removed I will just replace the in the entire JS file I am importingproxyGlobalContext: string; overwriteRecords?: overwriteRecordsType; } -type proxifiedObjType = revokableProxyRet | proxifiyObjGenerator; -type proxifiyObjGenerator = ( +export type proxifiedObjType = revokableProxyRet | proxifiyObjGenerator; +export type proxifiyObjGenerator = ( ctx: proxifiedObjGeneratorContext ) => proxifiedObjType; -type proxifyGetter = (ctx: proxifiedObjGeneratorContext) => any; +// biome-ignore lint/suspicious/noExplicitAny: +export type proxifyGetter = (ctx: proxifiedObjGeneratorContext) => any; -type objectPropertyModifier = (ctx: proxifiedObjGeneratorContext) => void; +export type objectPropertyModifier = ( + ctx: proxifiedObjGeneratorContext +) => void; /** This is a generic type interface used for intersection in other interfaces below */ interface APIInterceptorGeneric { @@ -34,39 +37,45 @@ interface APIInterceptorGeneric { /** This number determines how late the API injectors will be injected. It is similar to the index property in CSS. If not set, the default is zero. */ insertLevel?: number; } -type APIInterceptorForProxyObjects = APIInterceptorGeneric & { +export type APIInterceptorForProxyObjects = APIInterceptorGeneric & { /** This is specifically for objects that use the ES6 Proxy Object or re-implement the API from scratch. proxifiedObjGenFunc is a handler which returns the proxified object depending on the context given, which is determined by how the AeroSandboxBundler class is configured with the config in the constructor.*/ + // biome-ignore lint/complexity/noBannedTypes: proxifiedObj?: Object | proxifiyObjGenerator; exposedContexts: anyWorkerEnumMember; }; -type APIInterceptorForProxyObjectsInWorker = APIInterceptorGeneric & { +export type APIInterceptorForProxyObjectsInWorker = APIInterceptorGeneric & { + // biome-ignore lint/complexity/noBannedTypes: proxifiedObjWorkerVersion?: Object; exposedContexts: anyWorkerEnumMember; }; -type APIInterceptorForProxifiyingGetters = APIInterceptorGeneric & { +export type APIInterceptorForProxifiyingGetters = APIInterceptorGeneric & { proxifyGetter?: proxifyGetter; }; -type APIInterceptorForModifyingObjectProperties = APIInterceptorGeneric & { - /** This is for overwriting properties with the `Object` type class */ - modifyObjectProperty: objectPropertyModifier; -}; +export type APIInterceptorForModifyingObjectProperties = + APIInterceptorGeneric & { + /** This is for overwriting properties with the `Object` type class */ + modifyObjectProperty: objectPropertyModifier; + }; // TODO: Make it possible in AeroSandbox to view the API Interceptor and determine if it should be included in AeroSandbox or not with a handler /** This is what is exported in every API Interceptor. Omitting any of the properties with the Enum type will act as if every member of the Enum is present. */ -type APIInterceptor = +export type APIInterceptor = | APIInterceptorForProxyObjects | APIInterceptorForProxyObjectsInWorker | APIInterceptorForProxifiyingGetters | APIInterceptorForModifyingObjectProperties; +// Support Enums // These enums are inspired by the WebIDL spec -enum SupportEnum { +// biome-ignore lint/style/useEnumInitializers: +export enum SupportEnum { deprecated, nonstandard, draft, shippingChromium, originTrialExclusive, } -enum ExposedContextsEnum { +// biome-ignore lint/style/useEnumInitializers: +export enum ExposedContextsEnum { dedicatedWorker, sharedWorker, audioWorklet, @@ -77,7 +86,7 @@ enum ExposedContextsEnum { serviceWorker, window, } -type anyWorkerEnumMember = +export type anyWorkerEnumMember = | ExposedContextsEnum.animationWorklet | ExposedContextsEnum.audioWorklet | ExposedContextsEnum.dedicatedWorker @@ -86,13 +95,14 @@ type anyWorkerEnumMember = | ExposedContextsEnum.serviceWorker | ExposedContextsEnum.sharedStorageWorklet | ExposedContextsEnum.sharedWorker; -enum AltProtocolEnum { +// biome-ignore lint/style/useEnumInitializers: +export enum AltProtocolEnum { webRTC, webSockets, webTransport, } - -enum InterceptionFeaturesEnum { +// biome-ignore lint/style/useEnumInitializers: +export enum InterceptionFeaturesEnum { /** This member requires the correct context to be passed down in the proxy's global context */ corsEmulation, /** This member requires the correct context to be passed down in the proxy's global context */ diff --git a/src/AeroSandbox/types/config.d.ts b/src/AeroSandbox/types/config.d.ts index e001084..965cc98 100644 --- a/src/AeroSandbox/types/config.d.ts +++ b/src/AeroSandbox/types/config.d.ts @@ -1,23 +1,10 @@ +import { HTMLRewriterModes } from "./rewriters/html"; + export type Config = { - Support: SupportEnum; - /** - * This is not needed, if you are running this on aero itself, since it will automatically have the proper namespace already (no need for mapping). - */ - ProxyConfig: ProxyConfig; - htmlInterception?: HtmlInterceptionConfig; // Enable Element API inteception and HTML interception - redirectors?: boolean; // Enable redirectors; default true. Concelears and redirectors are distinct options, because you might be trying to intercept link redirection. See DEV.md. - concealers?: boolean; // Enable concealers; default true - concealVars?: string[]; // This will use a script rewriter to conceal variables other than $aero - jsRewriter?: Function; - nestedSWSupport: boolean; // This requires that you import the nested SW library into your main SW file - // Extra features - FakerAPI?: FakerAPIConfig; // I recommend disabling: redirectors, if you enable it because it would probably not be necessary - SWlessRuntime?: SWlessRuntimeConfig; rewriters: { html: { - /** DOMParser is be the default */ - // TODO: Make this an enum instead - mode: "DOMParser" | "Mutation Observer"; + /** DOMParser is the default */ + mode: HTMLRewriterModes; replaceRedirectorsWithNavigationEvents: { /** This will be enabled by default*/ enabled: boolean; diff --git a/src/AeroSandbox/types/customBuilds.d.ts b/src/AeroSandbox/types/customBuilds.d.ts new file mode 100644 index 0000000..fcaf87d --- /dev/null +++ b/src/AeroSandbox/types/customBuilds.d.ts @@ -0,0 +1 @@ +export enum UVRewriterWorkerMembers {} diff --git a/src/AeroSandbox/types/draftAPIs.d.ts b/src/AeroSandbox/types/draftAPIs.d.ts deleted file mode 100644 index 887ab65..0000000 --- a/src/AeroSandbox/types/draftAPIs.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -/// -/// diff --git a/src/AeroSandbox/types/generic.ts b/src/AeroSandbox/types/generic.ts new file mode 100644 index 0000000..11ea79b --- /dev/null +++ b/src/AeroSandbox/types/generic.ts @@ -0,0 +1 @@ +export type overwriteRecordsType = { [key: string]; Object }; diff --git a/src/AeroSandbox/types/index.d.ts b/src/AeroSandbox/types/index.d.ts deleted file mode 100644 index ae62225..0000000 --- a/src/AeroSandbox/types/index.d.ts +++ /dev/null @@ -1,47 +0,0 @@ -// Config types - -// TODO: Provide types for the Presentation API - -import { InterceptionFeaturesEnum, APIInterceptor } from "$types/index.d"; - -// TODO: Make it possible to use the same configuration used in the AeroSandbox constructor in the AeroSandbox WebPack module to remove features in compile-time and be tree-shaken. You could still configure the AeroSandbox instance using the same configuration type at runtime. Still, if you attempt to enable something disabled at compile-time, the compile-time disabled options in the API Interceptor CTX in the proxifiedObjGenFunc handler would not be present even if enabled in the runtime config. In the compile-time config you would also be able to disable APIs from coming with AeroSandbox and use of them would throw an exception with NeverThrow. All of the APIs will be wrapped with NeverThrow. - -interface AeroSandboxConfig { - proxyConfig: ProxyConfig; - /** These enum members enable code inside of the Proxy handler that provide other things you may want to use AeroSandbox for */ - specialInterceptionFeatures?: InterceptionFeaturesEnum; - supports: SupportEnum; - proxyGlobalContext: "$aero"; -} - -// This is the typical proxy config. This is only what is used to format and unformat urls. -type ProxyConfig = { - BareTransport: BareTransport; - prefix: string; - encodeUrl: (url: string) => string; - decodeUrl: (url: string) => string; - // If provided, it will prevent the bare/wisp servers from being revealed through fetch. This will also be used for determining the WS server. This is only for proxies. - proxyEndpoints?: string[]; - // This is for WebRTC proxying. The API is disabled, if this isn't provided. - webrtcTurnServers?: string[]; -}; - -type HtmlInterceptionConfig = { - enable?: boolean; - // In interception proxies, like aero, parameters like integrity and ... are put in the arguments to then be handled by the SW through emulation. This is because the bodies are obviously going to need to be modified, which will go against the integrity, meaning that it has to be checked later on. - paramsPassthrough?: boolean; -}; - -type FakerAPIConfig = { - enable: boolean; - allowFakerExcludes?: boolean; // default false -}; - -interface SWlessRuntimeConfig { - enable: boolean; - // Refer to DEV.md for the options below - scriptMarker: boolean; - extendedAPI: boolean; -} - -// Bundler types diff --git a/src/AeroSandbox/types/rewriters.d.ts b/src/AeroSandbox/types/rewriters.d.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/AeroSandbox/types/rewriters/html.d.ts b/src/AeroSandbox/types/rewriters/html.d.ts index e2587d1..4b55678 100644 --- a/src/AeroSandbox/types/rewriters/html.d.ts +++ b/src/AeroSandbox/types/rewriters/html.d.ts @@ -14,6 +14,8 @@ export interface EscapeRule { mustContain?: string[]; cannotContain?: string[]; // Interception methods + // biome-ignore lint/complexity/noBannedTypes: rewriter?: Function; + // biome-ignore lint/complexity/noBannedTypes: emulator?: Function; } diff --git a/src/AeroSandbox/types/rewriters/js.d.ts b/src/AeroSandbox/types/rewriters/js.d.ts index 68ad201..974b7ec 100644 --- a/src/AeroSandbox/types/rewriters/js.d.ts +++ b/src/AeroSandbox/types/rewriters/js.d.ts @@ -1,3 +1,5 @@ +import { overwriteRecordsType } from "$types/generic"; + /** @warning Basic Regexp is unsupported as of now and will never be recommended */ export type rewriterMode = "aerogel" | "ast" | "basic_regexp"; export type aerogelParser = "esniff"; diff --git a/src/AeroSandbox/types/unsupportedAPIs.d.ts b/src/AeroSandbox/types/unsupportedAPIs.d.ts new file mode 100644 index 0000000..c434cb6 --- /dev/null +++ b/src/AeroSandbox/types/unsupportedAPIs.d.ts @@ -0,0 +1,7 @@ +// These types are for the APIs that aren't present in dom.d.ts, but are still supported in AeroSandbox. The rest are in `webidlGen/*`. + +/// +/// +/// + +// TODO: Provide types for the Presentation API diff --git a/src/config.ts b/src/config.ts index e329c48..a4210ce 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,35 +1,35 @@ import { Config } from "$aero/types/types"; -import { AeroJSProxyConfig } from "./AeroSandbox/types/index.d"; +import { AeroJSProxyConfig } from "./AeroSandbox/types/aeroSandbox"; // This is horribly out of date do not look at the default config aero sandbox will build one day... const config: Config = { - prefix: "/go/", - aeroPrefix: "/aero", - aeroPathFilter: path => - ["aero.config.js", "uv.config.js", "aero.sandbox.ts"].includes(path), // This is probably wrong - webrtcTurnServers: ["stun:stun.l.google.com:19302"], - urlEncoder: () => {}, - cacheKey: "httpCache", - dynamicConfig: { - dbName: "aero", - id: "update" - }, - aeroJSParserConfig: AeroJSProxyConfig, - flags: { - // Emulation - emulateSecureContext: false, - corsEmulation: true, - // Aero Sandbox options - concealNamespace: true - }, - debugMode: true, - debug: { - errors: true, - url: true, - src: true, - scoping: true - } + prefix: "/go/", + aeroPrefix: "/aero", + aeroPathFilter: path => + ["aero.config.js", "uv.config.js", "aero.sandbox.ts"].includes(path), // This is probably wrong + webrtcTurnServers: ["stun:stun.l.google.com:19302"], + urlEncoder: () => {}, + cacheKey: "httpCache", + dynamicConfig: { + dbName: "aero", + id: "update", + }, + aeroJSParserConfig: AeroJSProxyConfig, + flags: { + // Emulation + emulateSecureContext: false, + corsEmulation: true, + // Aero Sandbox options + concealNamespace: true, + }, + debugMode: true, + debug: { + errors: true, + url: true, + src: true, + scoping: true, + }, }; export default config; diff --git a/tsconfig.json b/tsconfig.json index 5c28b75..ff4d0a8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,45 +1,45 @@ { - "compilerOptions": { - "target": "ESNext", - "moduleResolution": "NodeNext", - "module": "NodeNext", - "baseUrl": "./", - "lib": ["ESNext", "WebWorker", "WebWorker.ImportScripts"], - "allowSyntheticDefaultImports": true, - "esModuleInterop": true, - "paths": { - "$aero/*": ["*"], - "$sandbox/*": ["src/AeroSandbox/src/*"], - "$src/*": ["src/*"], - "$sw/*": ["src/this/*"], - "$shared/*": ["src/shared/*"], - "$alt_backends/*": ["src/altBackends/*"], - "$util/*": ["src/this/util/*"], - "$rewriters/*": ["src/this/rewriters/*"], - "$nested_sws/*": ["src/this/nestedSWs/*"], - "$cors/*": ["src/this/cors/*"], - "$embeds/*": ["src/this/embeds/*"], - "$handlers/*": ["src/this/handlers/*"], - "$types/*": ["types/*"] - }, - "types": [ - "./types/index.d.ts", - "./src/AeroSandbox/types/index.d.ts", - "@types/serviceworker", - "@types/web-app-manifest" - ] - }, - "include": [ - "src/**/*.ts", - "./src/AeroSandbox/src/shared/*.ts", - "types/**/*.ts", - "./src/AeroSandbox/types/index.d.ts" - ], - "exclude": [ - "rspack.config.ts", - "./src/this/nestedSW", - "./src/AeroSandbox/src", - "./src/AeroSandbox/rsbuild.config.ts", - "./src/AeroSandbox/build" - ] + "compilerOptions": { + "target": "ESNext", + "moduleResolution": "NodeNext", + "module": "NodeNext", + "baseUrl": "./", + "lib": ["ESNext", "WebWorker", "WebWorker.ImportScripts"], + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "paths": { + "$aero/*": ["*"], + "$sandbox/*": ["src/AeroSandbox/src/*"], + "$src/*": ["src/*"], + "$sw/*": ["src/this/*"], + "$shared/*": ["src/shared/*"], + "$alt_backends/*": ["src/altBackends/*"], + "$util/*": ["src/this/util/*"], + "$rewriters/*": ["src/this/rewriters/*"], + "$nested_sws/*": ["src/this/nestedSWs/*"], + "$cors/*": ["src/this/cors/*"], + "$embeds/*": ["src/this/embeds/*"], + "$handlers/*": ["src/this/handlers/*"], + "$types/*": ["types/*"] + }, + "types": [ + "./types/index.d.ts", + "./src/AeroSandbox/types/index.d.ts", + "@types/serviceworker", + "@types/web-app-manifest" + ] + }, + "include": [ + "src/**/*.ts", + "./src/AeroSandbox/src/shared/*.ts", + "types/**/*.ts", + "src/AeroSandbox/types/aeroSandbox.d.ts" + ], + "exclude": [ + "rspack.config.ts", + "./src/this/nestedSW", + "./src/AeroSandbox/src", + "./src/AeroSandbox/rsbuild.config.ts", + "./src/AeroSandbox/build" + ] }