@mercuryworkshop/proxy-bootstrap 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.downloads/controller/package/dist/controller.api.js +44 -0
- package/dist/.downloads/controller/package/dist/controller.api.js.map +1 -0
- package/dist/.downloads/controller/package/dist/controller.inject.js +2 -0
- package/dist/.downloads/controller/package/dist/controller.inject.js.map +1 -0
- package/dist/.downloads/controller/package/dist/controller.sw.js +2 -0
- package/dist/.downloads/controller/package/dist/controller.sw.js.map +1 -0
- package/dist/.downloads/controller/package/dist/types/cache.d.ts +39 -0
- package/dist/.downloads/controller/package/dist/types/index.d.ts +74 -0
- package/dist/.downloads/controller/package/dist/types/inject.d.ts +16 -0
- package/dist/.downloads/controller/package/dist/types/sw.d.ts +2 -0
- package/dist/.downloads/controller/package/dist/types/symbols.d.ts +1 -0
- package/dist/.downloads/controller/package/dist/types/typesEntry.d.ts +5 -0
- package/dist/.downloads/controller/package/package.json +16 -0
- package/dist/.downloads/controller/package/src/cache.ts +473 -0
- package/dist/.downloads/controller/package/src/index.ts +809 -0
- package/dist/.downloads/controller/package/src/inject.ts +370 -0
- package/dist/.downloads/controller/package/src/sw.ts +231 -0
- package/dist/.downloads/controller/package/src/symbols.ts +1 -0
- package/dist/.downloads/controller/package/src/types.d.ts +139 -0
- package/dist/.downloads/controller/package/src/typesEntry.ts +6 -0
- package/dist/.downloads/controller/package/tsconfig.json +24 -0
- package/dist/.downloads/controller/package/tsconfig.types.json +16 -0
- package/dist/.downloads/libcurl-transport/package/LICENSE +661 -0
- package/dist/.downloads/libcurl-transport/package/README.md +52 -0
- package/dist/.downloads/libcurl-transport/package/dist/index.d.ts +25 -0
- package/dist/.downloads/libcurl-transport/package/dist/index.js +6500 -0
- package/dist/.downloads/libcurl-transport/package/dist/index.mjs +6481 -0
- package/dist/.downloads/libcurl-transport/package/package.json +37 -0
- package/dist/.downloads/scramjet/package/dist/167400cb144aab22.wasm +0 -0
- package/dist/.downloads/scramjet/package/dist/2919e49b986edf8c.wasm +0 -0
- package/dist/.downloads/scramjet/package/dist/5aed1d5e48aab205.wasm +0 -0
- package/dist/.downloads/scramjet/package/dist/882d77912a3c8e3a.wasm +0 -0
- package/dist/.downloads/scramjet/package/dist/ac6aa30297a80464.wasm +0 -0
- package/dist/.downloads/scramjet/package/dist/c10a57758af882c8.wasm +0 -0
- package/dist/.downloads/scramjet/package/dist/cfd04aaae6955b67.wasm +0 -0
- package/dist/.downloads/scramjet/package/dist/d06a90fd413b36cf.wasm +0 -0
- package/dist/.downloads/scramjet/package/dist/dda06914899a6c28.wasm +0 -0
- package/dist/.downloads/scramjet/package/dist/scramjet.js +34 -0
- package/dist/.downloads/scramjet/package/dist/scramjet.js.map +1 -0
- package/dist/.downloads/scramjet/package/dist/scramjet.mjs +34 -0
- package/dist/.downloads/scramjet/package/dist/scramjet.mjs.map +1 -0
- package/dist/.downloads/scramjet/package/dist/scramjet.wasm +0 -0
- package/dist/.downloads/scramjet/package/dist/scramjet_bundled.js +34 -0
- package/dist/.downloads/scramjet/package/dist/scramjet_bundled.js.map +1 -0
- package/dist/.downloads/scramjet/package/dist/scramjet_bundled.mjs +34 -0
- package/dist/.downloads/scramjet/package/dist/scramjet_bundled.mjs.map +1 -0
- package/dist/.downloads/scramjet/package/dist/types/Tap.d.ts +32 -0
- package/dist/.downloads/scramjet/package/dist/types/client/client.d.ts +115 -0
- package/dist/.downloads/scramjet/package/dist/types/client/entry.d.ts +5 -0
- package/dist/.downloads/scramjet/package/dist/types/client/events.d.ts +10 -0
- package/dist/.downloads/scramjet/package/dist/types/client/global.d.ts +4 -0
- package/dist/.downloads/scramjet/package/dist/types/client/helpers.d.ts +1 -0
- package/dist/.downloads/scramjet/package/dist/types/client/index.d.ts +7 -0
- package/dist/.downloads/scramjet/package/dist/types/client/location.d.ts +2 -0
- package/dist/.downloads/scramjet/package/dist/types/client/shared/eval.d.ts +3 -0
- package/dist/.downloads/scramjet/package/dist/types/client/shared/sourcemaps.d.ts +19 -0
- package/dist/.downloads/scramjet/package/dist/types/client/shared/unproxy.d.ts +19 -0
- package/dist/.downloads/scramjet/package/dist/types/client/shared/wrap.d.ts +4 -0
- package/dist/.downloads/scramjet/package/dist/types/client/singletonbox.d.ts +16 -0
- package/dist/.downloads/scramjet/package/dist/types/client/unproxy.generated.d.ts +50 -0
- package/dist/.downloads/scramjet/package/dist/types/fetch/body.d.ts +3 -0
- package/dist/.downloads/scramjet/package/dist/types/fetch/fetch.d.ts +7 -0
- package/dist/.downloads/scramjet/package/dist/types/fetch/headers.d.ts +19 -0
- package/dist/.downloads/scramjet/package/dist/types/fetch/index.d.ts +128 -0
- package/dist/.downloads/scramjet/package/dist/types/fetch/parse.d.ts +22 -0
- package/dist/.downloads/scramjet/package/dist/types/fetch/util.d.ts +7 -0
- package/dist/.downloads/scramjet/package/dist/types/index.d.ts +11 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/cookie.d.ts +26 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/headers.d.ts +13 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/htmlRules.d.ts +6 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/index.d.ts +51 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/mime.d.ts +39 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/refresh.d.ts +7 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/rewriters/css.d.ts +4 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/rewriters/html.d.ts +33 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/rewriters/index.d.ts +6 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/rewriters/js.d.ts +11 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/rewriters/url.d.ts +25 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/rewriters/wasm.d.ts +7 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/rewriters/worker.d.ts +3 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/set-cookie-parser.d.ts +20 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/snapshot.d.ts +236 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/sniffEncoding.d.ts +65 -0
- package/dist/.downloads/scramjet/package/dist/types/shared/util.d.ts +2 -0
- package/dist/.downloads/scramjet/package/dist/types/symbols.d.ts +6 -0
- package/dist/.downloads/scramjet/package/dist/types/types.d.ts +68 -0
- package/dist/.downloads/scramjet/package/lib/index.cjs +7 -0
- package/dist/.downloads/scramjet/package/lib/index.d.ts +8 -0
- package/dist/.downloads/scramjet/package/lib/types.d.ts +20 -0
- package/dist/.downloads/scramjet/package/package.json +93 -0
- package/dist/bootstrap-client.js +169 -0
- package/dist/bootstrap-client.js.map +1 -0
- package/dist/bootstrap-server.js +406 -0
- package/dist/bootstrap-server.js.map +1 -0
- package/dist/bootstrap-static.js +476 -0
- package/dist/bootstrap-static.js.map +1 -0
- package/dist/types/client.d.ts +4 -0
- package/dist/types/clientcommon.d.ts +2 -0
- package/dist/types/common.d.ts +30 -0
- package/dist/types/server.d.ts +24 -0
- package/dist/types/static.d.ts +1 -0
- package/package.json +30 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type Description = {
|
|
2
|
+
context?: object;
|
|
3
|
+
props?: object;
|
|
4
|
+
};
|
|
5
|
+
type Callback<T extends Description> = (context: T["context"], props: T["props"]) => void | Promise<void>;
|
|
6
|
+
type Sorter = (other: Plugin) => number;
|
|
7
|
+
type CallbackInfo<T extends Description> = {
|
|
8
|
+
callback: Callback<T>;
|
|
9
|
+
plugin: Plugin;
|
|
10
|
+
sorter: Sorter;
|
|
11
|
+
};
|
|
12
|
+
type InternalHookDescription = {
|
|
13
|
+
tap: TapInternal;
|
|
14
|
+
key: string;
|
|
15
|
+
};
|
|
16
|
+
type TapInternal = {
|
|
17
|
+
callbacks: Record<string, CallbackInfo<Description>[]>;
|
|
18
|
+
};
|
|
19
|
+
export type TapInstance<T extends Record<string, Description>> = {
|
|
20
|
+
[K in keyof T]: T[K] & InternalHookDescription;
|
|
21
|
+
};
|
|
22
|
+
export declare class Plugin {
|
|
23
|
+
name: string;
|
|
24
|
+
constructor(name: string);
|
|
25
|
+
tap<T extends Description>(hook: T, callback: Callback<T>, sorter?: Sorter): void;
|
|
26
|
+
}
|
|
27
|
+
export declare class Tap {
|
|
28
|
+
static dispatch<T extends Description>(hook: T, context: T["context"], props: T["props"]): Promise<void[]>;
|
|
29
|
+
static tap<T extends Description>(hook: T, callback: Callback<T>, plugin: Plugin, sorter: Sorter): void;
|
|
30
|
+
static create<T extends Record<string, Description>>(): TapInstance<T>;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { BareCompatibleClient, ProxyTransport, RawHeaders } from "@mercuryworkshop/proxy-transports";
|
|
2
|
+
import { LifecycleHooks } from "./events";
|
|
3
|
+
import { RewriteUrlOptions, type URLMeta } from "../shared/rewriters/url";
|
|
4
|
+
import { HtmlRewriterHooks, ScramjetContext, ScramjetHeaders } from "../shared";
|
|
5
|
+
import { SingletonBox } from "./singletonbox";
|
|
6
|
+
import { ScramjetConfig } from "../types";
|
|
7
|
+
import { type CookieSyncEntry, type CookieSyncOptions, TrackedHistoryState } from "../fetch";
|
|
8
|
+
import { AnyFunction } from "../types";
|
|
9
|
+
import { _URL } from "../shared/snapshot";
|
|
10
|
+
export type ScramjetClientInit = {
|
|
11
|
+
context: ScramjetContext;
|
|
12
|
+
transport: ProxyTransport;
|
|
13
|
+
sendSetCookie: (cookies: CookieSyncEntry[], options?: CookieSyncOptions) => Promise<void>;
|
|
14
|
+
shouldPassthroughWebsocket?: (url: string | URL) => boolean;
|
|
15
|
+
shouldBlockMessageEvent?: (ev: MessageEvent) => boolean;
|
|
16
|
+
hookSubcontext: (self: Self, frame?: HTMLIFrameElement) => ScramjetClient;
|
|
17
|
+
initHeaders: RawHeaders;
|
|
18
|
+
history: TrackedHistoryState[];
|
|
19
|
+
};
|
|
20
|
+
type NativeStore = {
|
|
21
|
+
store: Record<string, any>;
|
|
22
|
+
call: (target: string, that: any, ...args: any[]) => any;
|
|
23
|
+
construct: (target: string, ...args: any[]) => any;
|
|
24
|
+
};
|
|
25
|
+
type DescriptorStore = {
|
|
26
|
+
store: Record<string, PropertyDescriptor>;
|
|
27
|
+
get: (target: string, that: any) => any;
|
|
28
|
+
set: (target: string, that: any, value: any) => void;
|
|
29
|
+
};
|
|
30
|
+
type Traverse<O extends Record<any, any>, P extends string> = P extends `${infer K}.${infer R}` ? Traverse<O[K], R> : O[P];
|
|
31
|
+
type GlobalTraverse<P extends string> = Traverse<GlobalThis & Record<string, any>, P>;
|
|
32
|
+
type IfEquals<T, U, Y = unknown, N = never> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? Y : N;
|
|
33
|
+
type ProxyApplyThis<T extends string> = unknown extends ThisParameterType<Extract<GlobalTraverse<T>, AnyFunction>> ? T extends `${infer ClassName}.prototype.${string}` ? GlobalTraverse<ClassName> extends {
|
|
34
|
+
prototype: infer Proto;
|
|
35
|
+
} ? Proto : unknown : unknown : ThisParameterType<Extract<GlobalTraverse<T>, AnyFunction>>;
|
|
36
|
+
export type ScramjetModule = {
|
|
37
|
+
enabled: (client: ScramjetClient) => boolean | undefined;
|
|
38
|
+
disabled: (client: ScramjetClient, self: GlobalThis) => void | undefined;
|
|
39
|
+
order: number | undefined;
|
|
40
|
+
default: (client: ScramjetClient, self: GlobalThis) => void;
|
|
41
|
+
};
|
|
42
|
+
export type ProxyCtx<T extends string = string, U extends "construct" | "apply" = "apply"> = {
|
|
43
|
+
fn: GlobalTraverse<T>;
|
|
44
|
+
this: IfEquals<U, "construct", null, ProxyApplyThis<T>>;
|
|
45
|
+
args: IfEquals<U, "construct", ConstructorParameters<GlobalTraverse<T>>, Parameters<GlobalTraverse<T>>>;
|
|
46
|
+
newTarget: IfEquals<U, "construct", GlobalTraverse<T>, null>;
|
|
47
|
+
return: (r: IfEquals<U, "construct", InstanceType<GlobalTraverse<T>>, ReturnType<GlobalTraverse<T>>>) => void;
|
|
48
|
+
call: () => IfEquals<U, "construct", InstanceType<GlobalTraverse<T>>, ReturnType<GlobalTraverse<T>>>;
|
|
49
|
+
};
|
|
50
|
+
export type Proxy<T extends string = string> = {
|
|
51
|
+
construct?(ctx: ProxyCtx<T, "construct">): any;
|
|
52
|
+
apply?(ctx: ProxyCtx<T, "apply">): any;
|
|
53
|
+
};
|
|
54
|
+
export type TrapCtx<T extends string> = {
|
|
55
|
+
this: any;
|
|
56
|
+
get: () => GlobalTraverse<T>;
|
|
57
|
+
set: (v: GlobalTraverse<T>) => void;
|
|
58
|
+
};
|
|
59
|
+
export type Trap<T extends string> = {
|
|
60
|
+
writable?: boolean;
|
|
61
|
+
value?: any;
|
|
62
|
+
enumerable?: boolean;
|
|
63
|
+
configurable?: boolean;
|
|
64
|
+
get?: (ctx: TrapCtx<T>) => GlobalTraverse<T>;
|
|
65
|
+
set?: (ctx: TrapCtx<T>, v: GlobalTraverse<T>) => void;
|
|
66
|
+
};
|
|
67
|
+
export declare class ScramjetClient {
|
|
68
|
+
global: GlobalThis;
|
|
69
|
+
init: ScramjetClientInit;
|
|
70
|
+
locationProxy: any;
|
|
71
|
+
serviceWorker: ServiceWorkerContainer;
|
|
72
|
+
bare: BareCompatibleClient;
|
|
73
|
+
natives: NativeStore;
|
|
74
|
+
descriptors: DescriptorStore;
|
|
75
|
+
wrapfn: (i: any, ...args: any) => any;
|
|
76
|
+
eventcallbacks: Map<any, [
|
|
77
|
+
{
|
|
78
|
+
event: string;
|
|
79
|
+
originalCallback: AnyFunction;
|
|
80
|
+
proxiedCallback: AnyFunction;
|
|
81
|
+
}
|
|
82
|
+
]>;
|
|
83
|
+
meta: URLMeta;
|
|
84
|
+
box: SingletonBox;
|
|
85
|
+
context: ScramjetContext;
|
|
86
|
+
initHeaders: ScramjetHeaders;
|
|
87
|
+
history: TrackedHistoryState[];
|
|
88
|
+
hooks: {
|
|
89
|
+
rewriter: {
|
|
90
|
+
html: import("../Tap").TapInstance<HtmlRewriterHooks>;
|
|
91
|
+
};
|
|
92
|
+
lifecycle: import("../Tap").TapInstance<LifecycleHooks>;
|
|
93
|
+
};
|
|
94
|
+
constructor(global: GlobalThis, init: ScramjetClientInit);
|
|
95
|
+
/** Apply document injection init when a client was already installed (e.g. early contentWindow). */
|
|
96
|
+
syncDocumentInit(init: {
|
|
97
|
+
initHeaders: RawHeaders;
|
|
98
|
+
history: TrackedHistoryState[];
|
|
99
|
+
cookies?: string;
|
|
100
|
+
}): void;
|
|
101
|
+
hook(): void;
|
|
102
|
+
get url(): _URL;
|
|
103
|
+
set url(url: _URL | string);
|
|
104
|
+
Proxy<T extends string>(name: T, handler: Proxy<T>): void;
|
|
105
|
+
Proxy<const T extends readonly string[]>(name: T, handler: Proxy<T[number]>): void;
|
|
106
|
+
RawProxy(target: any, prop: string, handler: Proxy<any>, debugname?: string): void;
|
|
107
|
+
Trap<T extends string>(name: T, handler: Trap<T>): void;
|
|
108
|
+
Trap<const T extends readonly string[]>(name: T, handler: Trap<T[number]>): void;
|
|
109
|
+
RawTrap(target: any, prop: string, descriptor: Trap<any>): void;
|
|
110
|
+
rewriteUrl(url: string | URL, options?: RewriteUrlOptions): string;
|
|
111
|
+
unrewriteUrl(url: string | URL): string;
|
|
112
|
+
flagEnabled(flag: keyof ScramjetConfig["flags"]): boolean;
|
|
113
|
+
get config(): ScramjetConfig;
|
|
114
|
+
}
|
|
115
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ScramjetClient } from "./index";
|
|
2
|
+
export declare const UNSAFE_GLOBALS: string[];
|
|
3
|
+
export declare function createGlobalProxy(client: ScramjetClient, self: typeof globalThis): typeof globalThis;
|
|
4
|
+
export declare function createDocumentProxy(client: ScramjetClient, self: typeof globalThis): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getOwnPropertyDescriptorHandler(target: any, prop: any): PropertyDescriptor;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ScramjetClient } from "../index";
|
|
2
|
+
declare enum RewriteType {
|
|
3
|
+
Insert = 0,
|
|
4
|
+
Replace = 1
|
|
5
|
+
}
|
|
6
|
+
type Rewrite = {
|
|
7
|
+
start: number;
|
|
8
|
+
} & ({
|
|
9
|
+
type: RewriteType.Insert;
|
|
10
|
+
size: number;
|
|
11
|
+
} | {
|
|
12
|
+
type: RewriteType.Replace;
|
|
13
|
+
end: number;
|
|
14
|
+
str: string;
|
|
15
|
+
});
|
|
16
|
+
export type SourceMaps = Record<string, Rewrite[]>;
|
|
17
|
+
export declare const enabled: (client: ScramjetClient) => boolean;
|
|
18
|
+
export default function (client: ScramjetClient, self: Self): void;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ProxyCtx, ScramjetClient } from "../client";
|
|
2
|
+
/**
|
|
3
|
+
* Maps each fast-path wrapper function back to the native function it
|
|
4
|
+
* stands in for, so `Function.prototype.toString` interception
|
|
5
|
+
* (sourcemaps.ts) can return the original native source string and avoid
|
|
6
|
+
* leaking our wrapper's body to anti-tampering checks. Module-level so
|
|
7
|
+
* it survives across module loads and is shared with sourcemaps.ts.
|
|
8
|
+
*/
|
|
9
|
+
export declare const NATIVE_BACKING: WeakMap<AnyFunction, AnyFunction>;
|
|
10
|
+
type AnyFunction = (...args: any[]) => any;
|
|
11
|
+
export declare const order = 3;
|
|
12
|
+
export declare const enabled: (c: ScramjetClient) => boolean;
|
|
13
|
+
export default function (client: ScramjetClient, self: typeof window): void;
|
|
14
|
+
/**
|
|
15
|
+
* Legacy helper retained for backward compatibility with any consumer that
|
|
16
|
+
* imported it. New code should rely on the IDL-driven hooks installed above.
|
|
17
|
+
*/
|
|
18
|
+
export declare function unproxy(ctx: ProxyCtx, client: ScramjetClient): void;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ScramjetClient } from "../index";
|
|
2
|
+
export declare function createWrapFn(client: ScramjetClient, self: GlobalThis): (identifier: any, strict: boolean) => any;
|
|
3
|
+
export declare const order = 4;
|
|
4
|
+
export default function (client: ScramjetClient, self: GlobalThis): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IncrementalHtmlRewriter } from "../shared";
|
|
2
|
+
import { ScramjetClient } from "./client";
|
|
3
|
+
import { SourceMaps } from "./shared/sourcemaps";
|
|
4
|
+
export declare class SingletonBox {
|
|
5
|
+
ownerclient: ScramjetClient;
|
|
6
|
+
clients: ScramjetClient[];
|
|
7
|
+
globals: Map<Self, ScramjetClient>;
|
|
8
|
+
documents: Map<Document, ScramjetClient>;
|
|
9
|
+
locations: Map<Location, ScramjetClient>;
|
|
10
|
+
writeRewriters: WeakMap<Document, IncrementalHtmlRewriter>;
|
|
11
|
+
ctors: Record<string, Function[]>;
|
|
12
|
+
sourcemaps: SourceMaps;
|
|
13
|
+
constructor(ownerclient: ScramjetClient);
|
|
14
|
+
registerClient(client: ScramjetClient, global: Self): void;
|
|
15
|
+
instanceof(obj: any, name: string): boolean;
|
|
16
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single character proxy "kind" tag:
|
|
3
|
+
* "w" -> Window/WindowProxy "d" -> Document
|
|
4
|
+
* "*" -> overload disagrees, probe the value at runtime
|
|
5
|
+
*/
|
|
6
|
+
export type ProxyKind = "w" | "d" | "*";
|
|
7
|
+
/**
|
|
8
|
+
* Selector for a Window/Document value reachable from an operation argument.
|
|
9
|
+
* [argIdx, kind] -- the entire argument
|
|
10
|
+
* [argIdx, kind, ...path] -- a property path inside a dict arg
|
|
11
|
+
* (e.g. options.root)
|
|
12
|
+
*/
|
|
13
|
+
export type ArgSelector = readonly [
|
|
14
|
+
argIdx: number,
|
|
15
|
+
kind: "w" | "d",
|
|
16
|
+
...path: string[]
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Operation/constructor table entry:
|
|
20
|
+
* [owner, member, isStatic, isCtor, argSelectors, returnKind]
|
|
21
|
+
*
|
|
22
|
+
* - owner is the interface/namespace name (e.g. "Document", "Window")
|
|
23
|
+
* - member is the method name; "" for constructors
|
|
24
|
+
* - isStatic=true patches `Owner.member`, false patches `Owner.prototype.member`
|
|
25
|
+
* - isCtor=true patches the interface constructor itself
|
|
26
|
+
* - returnKind="" means no return wrapping needed
|
|
27
|
+
*/
|
|
28
|
+
export type OpEntry = readonly [
|
|
29
|
+
owner: string,
|
|
30
|
+
member: string,
|
|
31
|
+
isStatic: boolean,
|
|
32
|
+
isCtor: boolean,
|
|
33
|
+
argSelectors: readonly ArgSelector[],
|
|
34
|
+
returnKind: ProxyKind | ""
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* Attribute table entry:
|
|
38
|
+
* [owner, member, isStatic, kind, readonly]
|
|
39
|
+
*
|
|
40
|
+
* isStatic=true patches `Owner.member`, false patches `Owner.prototype.member`.
|
|
41
|
+
*/
|
|
42
|
+
export type AttrEntry = readonly [
|
|
43
|
+
owner: string,
|
|
44
|
+
member: string,
|
|
45
|
+
isStatic: boolean,
|
|
46
|
+
kind: ProxyKind,
|
|
47
|
+
readonly: boolean
|
|
48
|
+
];
|
|
49
|
+
export declare const OPERATIONS: readonly OpEntry[];
|
|
50
|
+
export declare const ATTRIBUTES: readonly AttrEntry[];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { BareResponse } from "@mercuryworkshop/proxy-transports";
|
|
2
|
+
import { BodyType, ScramjetFetchHandler, ScramjetFetchParsed, ScramjetFetchRequest } from ".";
|
|
3
|
+
export declare function rewriteBody(handler: ScramjetFetchHandler, request: ScramjetFetchRequest, parsed: ScramjetFetchParsed, response: BareResponse): Promise<BodyType>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BareResponse } from "@mercuryworkshop/proxy-transports";
|
|
2
|
+
import { ScramjetFetchHandler, ScramjetFetchParsed, ScramjetFetchRequest, ScramjetFetchResponse } from ".";
|
|
3
|
+
import { ScramjetHeaders } from "../shared";
|
|
4
|
+
export declare function doHandleFetch(handler: ScramjetFetchHandler, request: ScramjetFetchRequest): Promise<ScramjetFetchResponse>;
|
|
5
|
+
export declare function doNetworkFetch(handler: ScramjetFetchHandler, request: ScramjetFetchRequest, parsed: ScramjetFetchParsed, newheaders: ScramjetHeaders): Promise<BareResponse>;
|
|
6
|
+
/** Simplified registrable-domain check used for cross-site redirect detection. */
|
|
7
|
+
export declare function registrableDomainForRedirect(hostname: string): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ScramjetHeaders } from "../shared";
|
|
2
|
+
import { ScramjetFetchHandler, ScramjetFetchParsed, ScramjetFetchRequest } from ".";
|
|
3
|
+
import { RawHeaders } from "@mercuryworkshop/proxy-transports";
|
|
4
|
+
export declare function rewriteResponseHeaders(handler: ScramjetFetchHandler, request: ScramjetFetchRequest, parsed: ScramjetFetchParsed, rawHeaders: RawHeaders): Promise<ScramjetHeaders>;
|
|
5
|
+
export declare function rewriteRequestHeaders(request: ScramjetFetchRequest, handler: ScramjetFetchHandler, parsed: ScramjetFetchParsed): ScramjetHeaders;
|
|
6
|
+
/**
|
|
7
|
+
* Compute the immediate Sec-Fetch-Site relation between an initiator origin and
|
|
8
|
+
* a destination URL.
|
|
9
|
+
*
|
|
10
|
+
* - "same-origin" if scheme + host + port match exactly.
|
|
11
|
+
* - "same-site" if scheme matches and the registrable domains match.
|
|
12
|
+
* - "cross-site" otherwise.
|
|
13
|
+
*/
|
|
14
|
+
export declare function computeFetchSite(originUrl: URL, destUrl: URL): "same-origin" | "same-site" | "cross-site";
|
|
15
|
+
/**
|
|
16
|
+
* Combine two Sec-Fetch-Site classifications, returning the "worst" (least
|
|
17
|
+
* trusted) of the two. Used when propagating state through redirect chains.
|
|
18
|
+
*/
|
|
19
|
+
export declare function worstFetchSite(a: "none" | "same-origin" | "same-site" | "cross-site", b: "none" | "same-origin" | "same-site" | "cross-site"): "none" | "same-origin" | "same-site" | "cross-site";
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { BareCompatibleClient, BareResponse, ProxyTransport, BareRequestInit } from "@mercuryworkshop/proxy-transports";
|
|
2
|
+
import { type URLMeta } from "../shared/rewriters/url";
|
|
3
|
+
import { type ScramjetRequestMode } from "./parse";
|
|
4
|
+
import { ScramjetHeaders } from "../shared/headers";
|
|
5
|
+
import { HtmlRewriterHooks, ScramjetContext } from "../shared";
|
|
6
|
+
import { TapInstance } from "../Tap";
|
|
7
|
+
import { _URL, _Map } from "../shared/snapshot";
|
|
8
|
+
export interface ScramjetFetchRequest {
|
|
9
|
+
rawUrl: URL;
|
|
10
|
+
rawReferrer: string | null;
|
|
11
|
+
rawDestination: RequestDestination;
|
|
12
|
+
mode: RequestMode;
|
|
13
|
+
referrer: string;
|
|
14
|
+
method: string;
|
|
15
|
+
body: BodyType | null;
|
|
16
|
+
cache: RequestCache;
|
|
17
|
+
initialHeaders: ScramjetHeaders;
|
|
18
|
+
rawClientUrl?: URL;
|
|
19
|
+
/** The service worker FetchEvent.clientId that originated this request. */
|
|
20
|
+
clientId: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ScramjetFetchParsed {
|
|
23
|
+
url: _URL;
|
|
24
|
+
clientUrl?: _URL;
|
|
25
|
+
referrerSourceUrl?: _URL | null;
|
|
26
|
+
hadExtraParams: boolean;
|
|
27
|
+
crossSiteRedirect: boolean;
|
|
28
|
+
fetchSiteState?: "same-origin" | "same-site" | "cross-site";
|
|
29
|
+
fetchInitiatorOrigin?: string;
|
|
30
|
+
fetchCredentialsInclude?: boolean;
|
|
31
|
+
fetchMode?: ScramjetRequestMode;
|
|
32
|
+
isIframe?: boolean;
|
|
33
|
+
destination: RequestDestination;
|
|
34
|
+
meta: URLMeta;
|
|
35
|
+
isModule: boolean;
|
|
36
|
+
referrerPolicy?: string;
|
|
37
|
+
trackedClient?: ScramjetFetchTrackedClient;
|
|
38
|
+
}
|
|
39
|
+
export interface ScramjetFetchResponse {
|
|
40
|
+
body: BodyType;
|
|
41
|
+
headers: ScramjetHeaders;
|
|
42
|
+
status: number;
|
|
43
|
+
statusText: string;
|
|
44
|
+
}
|
|
45
|
+
export type CookieSyncEntry = {
|
|
46
|
+
url: URL;
|
|
47
|
+
cookie: string;
|
|
48
|
+
};
|
|
49
|
+
export type CookieSyncOptions = {
|
|
50
|
+
clear?: boolean;
|
|
51
|
+
destination?: RequestDestination;
|
|
52
|
+
};
|
|
53
|
+
export type FetchHandlerInit = {
|
|
54
|
+
transport: ProxyTransport;
|
|
55
|
+
context: ScramjetContext;
|
|
56
|
+
crossOriginIsolated?: boolean;
|
|
57
|
+
sendSetCookie: (cookies: CookieSyncEntry[], options?: CookieSyncOptions) => Promise<void>;
|
|
58
|
+
fetchDataUrl(dataUrl: string): Promise<BareResponse>;
|
|
59
|
+
fetchBlobUrl(blobUrl: string): Promise<BareResponse>;
|
|
60
|
+
};
|
|
61
|
+
export type TrackedHistoryState = {
|
|
62
|
+
url: string;
|
|
63
|
+
refererPolicy?: string;
|
|
64
|
+
};
|
|
65
|
+
export declare class ScramjetFetchTrackedClient {
|
|
66
|
+
clientId: string;
|
|
67
|
+
history: TrackedHistoryState[];
|
|
68
|
+
constructor(clientId: string);
|
|
69
|
+
}
|
|
70
|
+
export declare class ScramjetFetchHandler extends EventTarget {
|
|
71
|
+
client: BareCompatibleClient;
|
|
72
|
+
crossOriginIsolated: boolean;
|
|
73
|
+
context: ScramjetContext;
|
|
74
|
+
trackedClients: _Map<string, ScramjetFetchTrackedClient>;
|
|
75
|
+
hooks: {
|
|
76
|
+
rewriter: {
|
|
77
|
+
html: TapInstance<HtmlRewriterHooks>;
|
|
78
|
+
};
|
|
79
|
+
fetch: TapInstance<FetchHooks>;
|
|
80
|
+
};
|
|
81
|
+
fetchDataUrl: (dataUrl: string) => Promise<Response>;
|
|
82
|
+
fetchBlobUrl: (blobUrl: string) => Promise<Response>;
|
|
83
|
+
sendSetCookie: (cookies: CookieSyncEntry[], options?: CookieSyncOptions) => Promise<void>;
|
|
84
|
+
constructor(init: FetchHandlerInit);
|
|
85
|
+
handleFetch(request: ScramjetFetchRequest): Promise<ScramjetFetchResponse>;
|
|
86
|
+
}
|
|
87
|
+
export type FetchHooks = {
|
|
88
|
+
intercept: {
|
|
89
|
+
context: {
|
|
90
|
+
request: ScramjetFetchRequest;
|
|
91
|
+
parsed: ScramjetFetchParsed;
|
|
92
|
+
};
|
|
93
|
+
props: {
|
|
94
|
+
response?: ScramjetFetchResponse;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
request: {
|
|
98
|
+
context: {
|
|
99
|
+
request: ScramjetFetchRequest;
|
|
100
|
+
parsed: ScramjetFetchParsed;
|
|
101
|
+
client: BareCompatibleClient;
|
|
102
|
+
};
|
|
103
|
+
props: {
|
|
104
|
+
init: BareRequestInit;
|
|
105
|
+
url: URL;
|
|
106
|
+
earlyResponse?: BareResponse;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
preresponse: {
|
|
110
|
+
context: {
|
|
111
|
+
request: ScramjetFetchRequest;
|
|
112
|
+
parsed: ScramjetFetchParsed;
|
|
113
|
+
};
|
|
114
|
+
props: {
|
|
115
|
+
response: BareResponse;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
response: {
|
|
119
|
+
context: {
|
|
120
|
+
request: ScramjetFetchRequest;
|
|
121
|
+
parsed: ScramjetFetchParsed;
|
|
122
|
+
};
|
|
123
|
+
props: {
|
|
124
|
+
response: ScramjetFetchResponse;
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
export type BodyType = string | ArrayBuffer | Blob | ReadableStream<any>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ScramjetFetchHandler, ScramjetFetchParsed, ScramjetFetchRequest } from ".";
|
|
2
|
+
export declare const QP: {
|
|
3
|
+
readonly referrerPolicy: "$rfp";
|
|
4
|
+
readonly referrerSource: "$rfs";
|
|
5
|
+
readonly isModule: "$module";
|
|
6
|
+
readonly topFrame: "$tf";
|
|
7
|
+
readonly parentFrame: "$pf";
|
|
8
|
+
readonly isIframe: "$iframe";
|
|
9
|
+
readonly mode: "$mode";
|
|
10
|
+
readonly credentials: "$cred";
|
|
11
|
+
readonly destination: "$dest";
|
|
12
|
+
readonly initiatorOrigin: "$io";
|
|
13
|
+
readonly fetchSite: "$fs";
|
|
14
|
+
readonly crossSiteRedirect: "$csr";
|
|
15
|
+
};
|
|
16
|
+
export type QueryParamKey = keyof typeof QP;
|
|
17
|
+
export type QueryParams = Partial<Record<QueryParamKey, string>>;
|
|
18
|
+
export declare function parseQueryParams(searchParams: URLSearchParams): {
|
|
19
|
+
params: QueryParams;
|
|
20
|
+
extras: Record<string, string>;
|
|
21
|
+
};
|
|
22
|
+
export declare function parseRequest(request: ScramjetFetchRequest, handler: ScramjetFetchHandler): ScramjetFetchParsed;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ScramjetHeaders } from "../shared";
|
|
2
|
+
import { BareResponse } from "@mercuryworkshop/proxy-transports";
|
|
3
|
+
import { ScramjetFetchParsed } from ".";
|
|
4
|
+
export declare function normalizeContentType(parsed: ScramjetFetchParsed, headers: ScramjetHeaders): void;
|
|
5
|
+
export declare function isRedirect(response: BareResponse): boolean;
|
|
6
|
+
export declare function isDocument(parsed: ScramjetFetchParsed): boolean;
|
|
7
|
+
export declare function createReferrerString(clientUrl: URL, resource: URL, policy: string | null): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "./global.d";
|
|
2
|
+
import { ScramjetConfig } from "./types";
|
|
3
|
+
export * from "./client";
|
|
4
|
+
export * from "./shared";
|
|
5
|
+
export * from "./symbols";
|
|
6
|
+
export * from "./types";
|
|
7
|
+
export * from "./fetch";
|
|
8
|
+
export * from "./Tap";
|
|
9
|
+
export { BareResponse } from "@mercuryworkshop/proxy-transports";
|
|
10
|
+
export declare const defaultConfig: ScramjetConfig;
|
|
11
|
+
export declare const defaultConfigDev: ScramjetConfig;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type Cookie = {
|
|
2
|
+
name: string;
|
|
3
|
+
value: string;
|
|
4
|
+
path?: string;
|
|
5
|
+
expires?: number;
|
|
6
|
+
maxAge?: number;
|
|
7
|
+
domain?: string;
|
|
8
|
+
hostOnly?: boolean;
|
|
9
|
+
secure?: boolean;
|
|
10
|
+
httpOnly?: boolean;
|
|
11
|
+
sameSite?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare class CookieJar {
|
|
14
|
+
private cookies;
|
|
15
|
+
private byDomain;
|
|
16
|
+
private defaultPath;
|
|
17
|
+
private pathMatches;
|
|
18
|
+
private indexCookie;
|
|
19
|
+
private unindexCookie;
|
|
20
|
+
private removeById;
|
|
21
|
+
setCookies(cookieString: string, url: URL): void;
|
|
22
|
+
getCookies(url: URL, fromJs: boolean, sameSiteContext?: "strict" | "lax" | "cross-site"): string;
|
|
23
|
+
load(cookies: string | Record<string, Cookie>): void;
|
|
24
|
+
clear(): void;
|
|
25
|
+
dump(): string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RawHeaders } from "@mercuryworkshop/proxy-transports";
|
|
2
|
+
export declare class ScramjetHeaders {
|
|
3
|
+
headers: {};
|
|
4
|
+
set(key: string, v: string): void;
|
|
5
|
+
get(key: string): string | null;
|
|
6
|
+
delete(key: string): void;
|
|
7
|
+
has(key: string): boolean;
|
|
8
|
+
toRawHeaders(): RawHeaders;
|
|
9
|
+
toNativeHeaders(): Headers;
|
|
10
|
+
static fromRawHeaders(raw: RawHeaders): ScramjetHeaders;
|
|
11
|
+
static fromNativeHeaders(native: Headers): ScramjetHeaders;
|
|
12
|
+
clone(): ScramjetHeaders;
|
|
13
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { URLMeta } from "./rewriters/url";
|
|
2
|
+
import { ScramjetContext } from "../shared";
|
|
3
|
+
export declare const htmlRules: {
|
|
4
|
+
[key: string]: "*" | string[] | ((...any: any[]) => string | null);
|
|
5
|
+
fn: (value: string, context: ScramjetContext, meta: URLMeta) => string | null;
|
|
6
|
+
}[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ScramjetConfig, ScramjetFlags, ScramjetVersionInfo } from "../types";
|
|
2
|
+
import DomHandler, { Element } from "domhandler";
|
|
3
|
+
import { URLMeta } from "./rewriters/url";
|
|
4
|
+
import { CookieJar } from "./cookie";
|
|
5
|
+
import { TapInstance } from "../Tap";
|
|
6
|
+
import { HtmlContext } from "../shared/rewriters/html";
|
|
7
|
+
export * from "./cookie";
|
|
8
|
+
export * from "./headers";
|
|
9
|
+
export * from "./htmlRules";
|
|
10
|
+
export * from "./mime";
|
|
11
|
+
export * from "./rewriters";
|
|
12
|
+
export declare function flagEnabled(flag: keyof ScramjetFlags, context: ScramjetContext, url: URL): boolean;
|
|
13
|
+
export type ScramjetInterface = {
|
|
14
|
+
codecEncode: (input: string) => string;
|
|
15
|
+
codecDecode: (input: string) => string;
|
|
16
|
+
getInjectScripts(meta: URLMeta, handler: DomHandler, htmlcontext: HtmlContext, script: (src: string) => Element): Element[];
|
|
17
|
+
getWorkerInjectScripts?(meta: URLMeta, isModule: boolean, script: (src: string) => string): string;
|
|
18
|
+
};
|
|
19
|
+
export type ScramjetContext = {
|
|
20
|
+
config: ScramjetConfig;
|
|
21
|
+
prefix: URL;
|
|
22
|
+
interface: ScramjetInterface;
|
|
23
|
+
cookieJar: CookieJar;
|
|
24
|
+
hooks?: {
|
|
25
|
+
rewriter: {
|
|
26
|
+
html: TapInstance<HtmlRewriterHooks>;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export declare const versionInfo: ScramjetVersionInfo;
|
|
31
|
+
export type HtmlRewriterHooks = {
|
|
32
|
+
pre: {
|
|
33
|
+
context: {
|
|
34
|
+
handler: DomHandler;
|
|
35
|
+
meta: URLMeta;
|
|
36
|
+
origHtml: string;
|
|
37
|
+
htmlcontext: HtmlContext;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
post: {
|
|
41
|
+
context: {
|
|
42
|
+
handler: DomHandler;
|
|
43
|
+
meta: URLMeta;
|
|
44
|
+
origHtml: string;
|
|
45
|
+
htmlcontext: HtmlContext;
|
|
46
|
+
};
|
|
47
|
+
props: {
|
|
48
|
+
setRawHtml?: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface ParsedMimeType {
|
|
2
|
+
type: string;
|
|
3
|
+
subtype: string;
|
|
4
|
+
/** `type`/`subtype` in ASCII lowercase; excludes parameters. */
|
|
5
|
+
essence: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Parses a MIME type string (e.g. a Content-Type value) into type, subtype, and essence.
|
|
9
|
+
* Returns null if the input is not a valid MIME type.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseMimeType(input: string): ParsedMimeType | null;
|
|
12
|
+
/** A MIME type whose type is "image". */
|
|
13
|
+
export declare function isImageMimeType(mime: string | ParsedMimeType): boolean;
|
|
14
|
+
/** Audio, video, or essence `application/ogg`. */
|
|
15
|
+
export declare function isAudioOrVideoMimeType(mime: string | ParsedMimeType): boolean;
|
|
16
|
+
/** Type `font` or a registered font essence. */
|
|
17
|
+
export declare function isFontMimeType(mime: string | ParsedMimeType): boolean;
|
|
18
|
+
/** Subtype ends with `+zip` or essence `application/zip`. */
|
|
19
|
+
export declare function isZipBasedMimeType(mime: string | ParsedMimeType): boolean;
|
|
20
|
+
/** One of the archive essences. */
|
|
21
|
+
export declare function isArchiveMimeType(mime: string | ParsedMimeType): boolean;
|
|
22
|
+
/** Subtype ends with `+xml` or essence `text/xml` / `application/xml`. */
|
|
23
|
+
export declare function isXmlMimeType(mime: string | ParsedMimeType): boolean;
|
|
24
|
+
/** Essence `text/html`. */
|
|
25
|
+
export declare function isHtmlMimeType(mime: string | ParsedMimeType): boolean;
|
|
26
|
+
/** XML, HTML, or `application/pdf`. */
|
|
27
|
+
export declare function isScriptableMimeType(mime: string | ParsedMimeType): boolean;
|
|
28
|
+
/** Essence is one of the JavaScript MIME type essences. */
|
|
29
|
+
export declare function isJavascriptMimeType(mime: string | ParsedMimeType): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* True if the string is an ASCII case-insensitive match for one of the
|
|
32
|
+
* JavaScript MIME type essence strings (not necessarily a full parsed MIME type).
|
|
33
|
+
*/
|
|
34
|
+
export declare function isJavascriptMimeTypeEssenceMatch(s: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* MIME types typically shown inline in a browsing context (navigation / iframe),
|
|
37
|
+
* as opposed to triggering a download when Content-Disposition is absent.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isInlineDisplayableMimeType(mime: string | ParsedMimeType): boolean;
|