@mercuryworkshop/scramjet 1.0.1 → 1.1.0

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.
Files changed (59) hide show
  1. package/LICENSE +3 -3
  2. package/README.md +89 -21
  3. package/dist/scramjet.all.js +196 -0
  4. package/dist/scramjet.all.js.map +1 -0
  5. package/dist/scramjet.bundle.js +196 -7
  6. package/dist/scramjet.bundle.js.map +1 -7
  7. package/dist/scramjet.sync.js +2 -0
  8. package/dist/scramjet.sync.js.map +1 -0
  9. package/dist/scramjet.wasm.wasm +0 -0
  10. package/dist/types/client/client.d.ts +78 -0
  11. package/dist/types/client/entry.d.ts +8 -0
  12. package/dist/types/client/events.d.ts +66 -0
  13. package/dist/types/client/helpers.d.ts +1 -0
  14. package/dist/types/client/index.d.ts +8 -0
  15. package/dist/types/client/location.d.ts +2 -0
  16. package/dist/types/client/shared/eval.d.ts +3 -0
  17. package/dist/types/client/shared/sourcemaps.d.ts +19 -0
  18. package/dist/types/client/shared/wrap.d.ts +4 -0
  19. package/dist/types/client/singletonbox.d.ts +12 -0
  20. package/dist/types/client/swruntime.d.ts +40 -0
  21. package/dist/types/controller/controller.d.ts +16 -0
  22. package/dist/types/controller/frame.d.ts +103 -0
  23. package/dist/types/controller/index.d.ts +2 -0
  24. package/dist/types/entry.d.ts +160 -0
  25. package/dist/types/index.d.ts +8 -0
  26. package/dist/types/shared/cookie.d.ts +18 -0
  27. package/dist/types/shared/headers.d.ts +4 -0
  28. package/dist/types/shared/htmlRules.d.ts +6 -0
  29. package/dist/types/shared/index.d.ts +12 -0
  30. package/dist/types/shared/rewriters/css.d.ts +3 -0
  31. package/dist/types/shared/rewriters/headers.d.ts +18 -0
  32. package/dist/types/shared/rewriters/html.d.ts +6 -0
  33. package/dist/types/shared/rewriters/index.d.ts +7 -0
  34. package/dist/types/shared/rewriters/js.d.ts +10 -0
  35. package/dist/types/shared/rewriters/url.d.ts +10 -0
  36. package/dist/types/shared/rewriters/wasm.d.ts +7 -0
  37. package/dist/types/shared/rewriters/worker.d.ts +2 -0
  38. package/dist/types/shared/security/forceReferrer.d.ts +49 -0
  39. package/dist/types/shared/security/index.d.ts +2 -0
  40. package/dist/types/shared/security/siteTests.d.ts +33 -0
  41. package/dist/types/symbols.d.ts +7 -0
  42. package/dist/types/types.d.ts +135 -0
  43. package/dist/types/worker/error.d.ts +2 -0
  44. package/dist/types/worker/fakesw.d.ts +12 -0
  45. package/dist/types/worker/fetch.d.ts +26 -0
  46. package/dist/types/worker/index.d.ts +143 -0
  47. package/lib/index.cjs +7 -0
  48. package/lib/index.d.ts +8 -3
  49. package/lib/noop.js +0 -0
  50. package/package.json +101 -34
  51. package/dist/scramjet.client.js +0 -1
  52. package/dist/scramjet.client.js.map +0 -7
  53. package/dist/scramjet.codecs.js +0 -3
  54. package/dist/scramjet.codecs.js.map +0 -7
  55. package/dist/scramjet.config.js +0 -1
  56. package/dist/scramjet.config.js.map +0 -7
  57. package/dist/scramjet.worker.js +0 -42
  58. package/dist/scramjet.worker.js.map +0 -7
  59. package/lib/index.js +0 -5
@@ -0,0 +1,2 @@
1
+ addEventListener("message",({data:{sab:e,args:[t,n,s,r,o],body:a,headers:g}})=>{let i=new DataView(e),l=new Uint8Array(e),d=new XMLHttpRequest;if(d.responseType="arraybuffer",d.open(t,n,!0,r,o),g)for(let[e,t]of Object.entries(g))d.setRequestHeader(e,t);d.send(a),d.onload=()=>{let t=1;i.setUint16(t,d.status),t+=2;let n=d.getAllResponseHeaders();i.setUint32(t,n.length),t+=4,e.byteLength<t+n.length&&e.grow(t+n.length),l.set(new TextEncoder().encode(n),t),t+=n.length,i.setUint32(t,d.response.byteLength),t+=4,e.byteLength<t+d.response.byteLength&&e.grow(t+d.response.byteLength),l.set(new Uint8Array(d.response),t),i.setUint8(0,1)},d.ontimeout=d.onerror=d.onabort=()=>{console.error("xhr failed"),i.setUint8(0,1)}});
2
+ //# sourceMappingURL=scramjet.sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scramjet.sync.js","sources":["webpack://@mercuryworkshop/scramjet/./src/sync.ts"],"sourcesContent":["addEventListener(\n\t\"message\",\n\t({\n\t\tdata: {\n\t\t\tsab,\n\t\t\targs: [method, url, _, username, password],\n\t\t\tbody,\n\t\t\theaders,\n\t\t},\n\t}) => {\n\t\tconst view = new DataView(sab);\n\t\tconst u8view = new Uint8Array(sab);\n\n\t\tconst xhr = new XMLHttpRequest();\n\t\txhr.responseType = \"arraybuffer\";\n\n\t\t// force async since we need it to resolve to the sw\n\t\txhr.open(method, url, true, username, password);\n\n\t\tif (headers)\n\t\t\tfor (const [k, v] of Object.entries(headers)) {\n\t\t\t\txhr.setRequestHeader(k, v as string);\n\t\t\t}\n\n\t\txhr.send(body);\n\n\t\txhr.onload = () => {\n\t\t\tlet cursor = 1; // first byte is the lock\n\n\t\t\tview.setUint16(cursor, xhr.status);\n\t\t\tcursor += 2;\n\n\t\t\t// next write the header string\n\t\t\tconst headers = xhr.getAllResponseHeaders();\n\t\t\tview.setUint32(cursor, headers.length);\n\t\t\tcursor += 4;\n\n\t\t\tif (sab.byteLength < cursor + headers.length)\n\t\t\t\tsab.grow(cursor + headers.length);\n\t\t\tu8view.set(new TextEncoder().encode(headers), cursor);\n\t\t\tcursor += headers.length;\n\n\t\t\tview.setUint32(cursor, xhr.response.byteLength);\n\t\t\tcursor += 4;\n\n\t\t\tif (sab.byteLength < cursor + xhr.response.byteLength)\n\t\t\t\tsab.grow(cursor + xhr.response.byteLength);\n\t\t\tu8view.set(new Uint8Array(xhr.response), cursor);\n\n\t\t\t// release the lock, main thread will stop spinning now\n\t\t\tview.setUint8(0, 1);\n\t\t};\n\t\txhr.ontimeout =\n\t\t\txhr.onerror =\n\t\t\txhr.onabort =\n\t\t\t\t() => {\n\t\t\t\t\tconsole.error(\"xhr failed\");\n\t\t\t\t\tview.setUint8(0, 1);\n\t\t\t\t};\n\t}\n);\n"],"names":["addEventListener","sab","method","url","_","username","password","body","headers","view","DataView","u8view","Uint8Array","xhr","XMLHttpRequest","k","v","Object","cursor","TextEncoder","console"],"mappings":"AAAAA,iBACC,UACA,CAAC,CACA,KAAM,CACLC,IAAAA,CAAG,CACH,KAAM,CAACC,EAAQC,EAAKC,EAAGC,EAAUC,EAAS,CAC1CC,KAAAA,CAAI,CACJC,QAAAA,CAAO,CACP,CACD,IACA,IAAMC,EAAO,IAAIC,SAAST,GACpBU,EAAS,IAAIC,WAAWX,GAExBY,EAAM,IAAIC,eAMhB,GALAD,EAAI,YAAY,CAAG,cAGnBA,EAAI,IAAI,CAACX,EAAQC,EAAK,GAAME,EAAUC,GAElCE,EACH,IAAK,GAAM,CAACO,EAAGC,EAAE,GAAIC,OAAO,OAAO,CAACT,GACnCK,EAAI,gBAAgB,CAACE,EAAGC,GAG1BH,EAAI,IAAI,CAACN,GAETM,EAAI,MAAM,CAAG,KACZ,IAAIK,EAAS,EAEbT,EAAK,SAAS,CAACS,EAAQL,EAAI,MAAM,EACjCK,GAAU,EAGV,IAAMV,EAAUK,EAAI,qBAAqB,GACzCJ,EAAK,SAAS,CAACS,EAAQV,EAAQ,MAAM,EACrCU,GAAU,EAENjB,EAAI,UAAU,CAAGiB,EAASV,EAAQ,MAAM,EAC3CP,EAAI,IAAI,CAACiB,EAASV,EAAQ,MAAM,EACjCG,EAAO,GAAG,CAAC,IAAIQ,cAAc,MAAM,CAACX,GAAUU,GAC9CA,GAAUV,EAAQ,MAAM,CAExBC,EAAK,SAAS,CAACS,EAAQL,EAAI,QAAQ,CAAC,UAAU,EAC9CK,GAAU,EAENjB,EAAI,UAAU,CAAGiB,EAASL,EAAI,QAAQ,CAAC,UAAU,EACpDZ,EAAI,IAAI,CAACiB,EAASL,EAAI,QAAQ,CAAC,UAAU,EAC1CF,EAAO,GAAG,CAAC,IAAIC,WAAWC,EAAI,QAAQ,EAAGK,GAGzCT,EAAK,QAAQ,CAAC,EAAG,EAClB,EACAI,EAAI,SAAS,CACZA,EAAI,OAAO,CACXA,EAAI,OAAO,CACV,KACCO,QAAQ,KAAK,CAAC,cACdX,EAAK,QAAQ,CAAC,EAAG,EAClB,CACH"}
Binary file
@@ -0,0 +1,78 @@
1
+ import { ScramjetFrame } from "../controller/frame";
2
+ import { type URLMeta } from "../shared/rewriters/url";
3
+ import { CookieStore } from "../shared/cookie";
4
+ import { SingletonBox } from "./singletonbox";
5
+ import BareClient from "@mercuryworkshop/bare-mux";
6
+ type NativeStore = {
7
+ store: Record<string, any>;
8
+ call: (target: string, that: any, ...args: any[]) => any;
9
+ construct: (target: string, ...args: any[]) => any;
10
+ };
11
+ type DescriptorStore = {
12
+ store: Record<string, PropertyDescriptor>;
13
+ get: (target: string, that: any) => any;
14
+ set: (target: string, that: any, value: any) => void;
15
+ };
16
+ export type AnyFunction = Function;
17
+ export type ScramjetModule = {
18
+ enabled: (client: ScramjetClient) => boolean | undefined;
19
+ disabled: (client: ScramjetClient, self: typeof globalThis) => void | undefined;
20
+ order: number | undefined;
21
+ default: (client: ScramjetClient, self: typeof globalThis) => void;
22
+ };
23
+ export type ProxyCtx = {
24
+ fn: AnyFunction;
25
+ this: any;
26
+ args: any[];
27
+ newTarget: AnyFunction;
28
+ return: (r: any) => void;
29
+ call: () => any;
30
+ };
31
+ export type Proxy = {
32
+ construct?(ctx: ProxyCtx): any;
33
+ apply?(ctx: ProxyCtx): any;
34
+ };
35
+ export type TrapCtx<T> = {
36
+ this: any;
37
+ get: () => T;
38
+ set: (v: T) => void;
39
+ };
40
+ export type Trap<T> = {
41
+ writable?: boolean;
42
+ value?: any;
43
+ enumerable?: boolean;
44
+ configurable?: boolean;
45
+ get?: (ctx: TrapCtx<T>) => T;
46
+ set?: (ctx: TrapCtx<T>, v: T) => void;
47
+ };
48
+ export declare class ScramjetClient {
49
+ global: typeof globalThis;
50
+ locationProxy: any;
51
+ serviceWorker: ServiceWorkerContainer;
52
+ bare: BareClient;
53
+ natives: NativeStore;
54
+ descriptors: DescriptorStore;
55
+ wrapfn: (i: any, ...args: any) => any;
56
+ cookieStore: CookieStore;
57
+ eventcallbacks: Map<any, [
58
+ {
59
+ event: string;
60
+ originalCallback: AnyFunction;
61
+ proxiedCallback: AnyFunction;
62
+ }
63
+ ]>;
64
+ meta: URLMeta;
65
+ box: SingletonBox;
66
+ constructor(global: typeof globalThis);
67
+ get frame(): ScramjetFrame | null;
68
+ get isSubframe(): boolean;
69
+ loadcookies(cookiestr: string): void;
70
+ hook(): void;
71
+ get url(): URL;
72
+ set url(url: URL | string);
73
+ Proxy(name: string | string[], handler: Proxy): void;
74
+ RawProxy(target: any, prop: string, handler: Proxy): void;
75
+ Trap<T>(name: string | string[], descriptor: Trap<T>): PropertyDescriptor;
76
+ RawTrap<T>(target: any, prop: string, descriptor: Trap<T>): PropertyDescriptor;
77
+ }
78
+ export {};
@@ -0,0 +1,8 @@
1
+ import { ScramjetConfig } from "../types";
2
+ export declare const iswindow: boolean;
3
+ export declare const isworker: boolean;
4
+ export declare const issw: boolean;
5
+ export declare const isdedicated: boolean;
6
+ export declare const isshared: boolean;
7
+ export declare const isemulatedsw: boolean;
8
+ export declare function loadAndHook(config: ScramjetConfig): void;
@@ -0,0 +1,66 @@
1
+ import { ScramjetClient } from "./index";
2
+ /**
3
+ * Union type for all global Scramjet events.
4
+ */
5
+ export type ScramjetGlobalEvent = ScramjetGlobalDownloadEvent;
6
+ /**
7
+ * Event class for proxified download interception.
8
+ */
9
+ export declare class ScramjetGlobalDownloadEvent extends Event {
10
+ download: ScramjetDownload;
11
+ type: string;
12
+ constructor(download: ScramjetDownload);
13
+ }
14
+ /**
15
+ * Map for all global Scramjet events with their corresponding event types.
16
+ */
17
+ export type ScramjetGlobalEvents = {
18
+ download: ScramjetGlobalDownloadEvent;
19
+ };
20
+ /**
21
+ * Event for proxified download interception.
22
+ */
23
+ export type ScramjetDownload = {
24
+ filename?: string;
25
+ url: string;
26
+ type: string;
27
+ body: ReadableStream<Uint8Array>;
28
+ length: number;
29
+ };
30
+ /**
31
+ * Union type for all Scramjet proxified navigation events.
32
+ */
33
+ export type ScramjetEvent = NavigateEvent | UrlChangeEvent | ScramjetContextEvent;
34
+ /**
35
+ * Type map for all Scramjet navigation events with their corresponding event types.
36
+ */
37
+ export type ScramjetEvents = {
38
+ navigate: NavigateEvent;
39
+ urlchange: UrlChangeEvent;
40
+ contextInit: ScramjetContextEvent;
41
+ };
42
+ /**
43
+ * Navigation event class fired when Scramjet frame navigates to a new proxified URL.
44
+ */
45
+ export declare class NavigateEvent extends Event {
46
+ url: string;
47
+ type: string;
48
+ constructor(url: string);
49
+ }
50
+ /**
51
+ * URL change event class fired when the proxified URL changes in a Scramjet frame.
52
+ */
53
+ export declare class UrlChangeEvent extends Event {
54
+ url: string;
55
+ type: string;
56
+ constructor(url: string);
57
+ }
58
+ /**
59
+ * Event class fired when Scramjet initializes in a frame.
60
+ */
61
+ export declare class ScramjetContextEvent extends Event {
62
+ window: Self;
63
+ client: ScramjetClient;
64
+ type: string;
65
+ constructor(window: Self, client: ScramjetClient);
66
+ }
@@ -0,0 +1 @@
1
+ export declare function getOwnPropertyDescriptorHandler(target: any, prop: any): TypedPropertyDescriptor<any>;
@@ -0,0 +1,8 @@
1
+ export * from "./client";
2
+ export * from "./entry";
3
+ export * from "./events";
4
+ export * from "./helpers";
5
+ export * from "./location";
6
+ export * from "./swruntime";
7
+ export * from "./index";
8
+ export * from "./location";
@@ -0,0 +1,2 @@
1
+ import { ScramjetClient } from "./index";
2
+ export declare function createLocationProxy(client: ScramjetClient, self: typeof globalThis): any;
@@ -0,0 +1,3 @@
1
+ import { ScramjetClient } from "../index";
2
+ export default function (client: ScramjetClient, self: Self): void;
3
+ export declare function indirectEval(this: ScramjetClient, strict: boolean, js: any): any;
@@ -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,4 @@
1
+ import { ScramjetClient } from "../index";
2
+ export declare function createWrapFn(client: ScramjetClient, self: typeof globalThis): (identifier: any, strict: boolean) => any;
3
+ export declare const order = 4;
4
+ export default function (client: ScramjetClient, self: typeof globalThis): void;
@@ -0,0 +1,12 @@
1
+ import { ScramjetClient } from "./client";
2
+ import { SourceMaps } from "./shared/sourcemaps";
3
+ export declare class SingletonBox {
4
+ ownerclient: ScramjetClient;
5
+ clients: ScramjetClient[];
6
+ globals: Map<Self, ScramjetClient>;
7
+ documents: Map<Document, ScramjetClient>;
8
+ locations: Map<Location, ScramjetClient>;
9
+ sourcemaps: SourceMaps;
10
+ constructor(ownerclient: ScramjetClient);
11
+ registerClient(client: ScramjetClient, global: Self): void;
12
+ }
@@ -0,0 +1,40 @@
1
+ import { ScramjetClient } from "./index";
2
+ export declare class ScramjetServiceWorkerRuntime {
3
+ client: ScramjetClient;
4
+ recvport: MessagePort;
5
+ constructor(client: ScramjetClient);
6
+ hook(): void;
7
+ }
8
+ export type TransferrableResponse = {
9
+ body: ReadableStream;
10
+ headers: [string, string][];
11
+ status: number;
12
+ statusText: string;
13
+ };
14
+ export type TransferrableRequest = {
15
+ body: ReadableStream;
16
+ headers: [string, string][];
17
+ destinitation: RequestDestination;
18
+ method: Request["method"];
19
+ mode: Request["mode"];
20
+ url: string;
21
+ };
22
+ type FetchResponseMessage = {
23
+ scramjet$type: "fetch";
24
+ scramjet$response: TransferrableResponse;
25
+ };
26
+ type FetchRequestMessage = {
27
+ scramjet$type: "fetch";
28
+ scramjet$request: TransferrableRequest;
29
+ };
30
+ type MessageTypeR2W = FetchResponseMessage;
31
+ type MessageTypeW2R = FetchRequestMessage;
32
+ type MessageCommon = {
33
+ scramjet$type: string;
34
+ scramjet$token: number;
35
+ };
36
+ export type MessageR2W = MessageCommon & MessageTypeR2W;
37
+ export type MessageW2R = MessageCommon & MessageTypeW2R & {
38
+ scramjet$port?: MessagePort;
39
+ };
40
+ export {};
@@ -0,0 +1,16 @@
1
+ import { ScramjetInitConfig, ScramjetDB } from "../types";
2
+ import { ScramjetFrame } from "./frame";
3
+ import { IDBPDatabase } from "idb";
4
+ import { ScramjetGlobalEvents } from "../client/events";
5
+ export declare class ScramjetController extends EventTarget {
6
+ #private;
7
+ private db;
8
+ constructor(config: Partial<ScramjetInitConfig>);
9
+ init(): Promise<void>;
10
+ createFrame(frame?: HTMLIFrameElement): ScramjetFrame;
11
+ encodeUrl(url: string | URL): string;
12
+ decodeUrl(url: string | URL): string;
13
+ openIDB(): Promise<IDBPDatabase<ScramjetDB>>;
14
+ modifyConfig(newconfig: Partial<ScramjetInitConfig>): Promise<void>;
15
+ addEventListener<K extends keyof ScramjetGlobalEvents>(type: K, listener: (event: ScramjetGlobalEvents[K]) => void, options?: boolean | AddEventListenerOptions): void;
16
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @fileoverview Contains abstractions for using Scrmajet under an iframe.
3
+ */
4
+ import { ScramjetController } from "./index";
5
+ import type { ScramjetClient } from "../client/index";
6
+ import type { ScramjetEvents } from "../client/events";
7
+ /**
8
+ * An abstraction over proxy iframe creation, which lets you manage instances of Scramjet and not have to worry about the proxy internals, since everything you need is already proxified.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const { ScramjetController } = $scramjetLoadController();
13
+ * const scramjet = new ScramjetController({ prefix: "/scramjet/" });
14
+ * await scramjet.init();
15
+ *
16
+ * const frame = scramjet.createFrame();
17
+ * document.body.appendChild(frame.frame);
18
+ *
19
+ * // Navigate to a URL
20
+ * frame.go("https://example.com");
21
+ *
22
+ * // Listen for proxified navigation events
23
+ * frame.addEventListener("urlchange", (e) => {
24
+ * console.log("URL changed to:", e.url);
25
+ * });
26
+ *
27
+ * // Go back
28
+ * frame.back();
29
+ * // Go forward
30
+ * frame.forward();
31
+ * // Reload page
32
+ * frame.reload();
33
+ * ```
34
+ */
35
+ export declare class ScramjetFrame extends EventTarget {
36
+ private controller;
37
+ frame: HTMLIFrameElement;
38
+ /**
39
+ * Create a ScramjetFrame instance. You likely won't need to interact the {@link ScramjetFrame.constructor | constructor} directly.
40
+ * You can instead use {@link ScramjetController.createFrame} on your existing `ScramjetController`.
41
+ *
42
+ * @param controller The `ScramjetController` instance that manages this frame with.
43
+ * @param frame The frame to be controlled for you under Scramjet.
44
+ */
45
+ constructor(controller: ScramjetController, frame: HTMLIFrameElement);
46
+ /**
47
+ * Returns the {@link ScramjetClient} instance running inside the iframe's contentWindow.
48
+ *
49
+ * @returns The `ScramjetClient` instance.
50
+ */
51
+ get client(): ScramjetClient;
52
+ /**
53
+ * Returns the proxified URL.
54
+ *
55
+ * @returns The proxified URL.
56
+ */
57
+ get url(): URL;
58
+ /**
59
+ * Navigates the iframe to a new URL under Scramjet.
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * frame.go("https://example.net");
64
+ * ```
65
+ *
66
+ * @param url A real URL to navigate to
67
+ */
68
+ go(url: string | URL): void;
69
+ /**
70
+ * Goes backwards in the browser history.
71
+ */
72
+ back(): void;
73
+ /**
74
+ * Goes forward in the browser history.
75
+ */
76
+ forward(): void;
77
+ /**
78
+ * Reloads the iframe.
79
+ */
80
+ reload(): void;
81
+ /**
82
+ * Binds event listeners to listen for proxified navigation events in Scramjet.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * // Listen for URL changes
87
+ * frame.addEventListener("urlchange", (event) => {
88
+ * console.log("URL changed:", event.url);
89
+ * document.title = event.url; // Update page title
90
+ * });
91
+ *
92
+ * // Listen for navigation events
93
+ * frame.addEventListener("navigate", (event) => {
94
+ * console.log("Navigating to:", event.url);
95
+ * });
96
+ * ```
97
+ *
98
+ * @param type Type of event to listen for.
99
+ * @param listener Event listener to dispatch.
100
+ * @param options Options for the event listener.
101
+ */
102
+ addEventListener<K extends keyof ScramjetEvents>(type: K, listener: (event: ScramjetEvents[K]) => void, options?: boolean | AddEventListenerOptions): void;
103
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./frame";
2
+ export * from "./controller";
@@ -0,0 +1,160 @@
1
+ import type { ScramjetVersionInfo } from "./types";
2
+ /**
3
+ * @category Window Context
4
+ */
5
+ export type { ScramjetFlags } from "./types";
6
+ /**
7
+ * @category Window Context
8
+ */
9
+ export type { ScramjetInitConfig } from "./types";
10
+ /**
11
+ * @category Window Context
12
+ */
13
+ export type { ScramjetGlobalEvent } from "./client/events";
14
+ /**
15
+ * @category Window Context
16
+ */
17
+ export type { ScramjetGlobalDownloadEvent } from "./client/events";
18
+ /**
19
+ * @category Window Context
20
+ */
21
+ export type { ScramjetGlobalEvents } from "./client/events";
22
+ /**
23
+ * @category Window Context
24
+ */
25
+ export type { ScramjetDownload } from "./client/events";
26
+ /**
27
+ * @category Window Context
28
+ */
29
+ export type { ScramjetEvent } from "./client/events";
30
+ /**
31
+ * @category Window Context
32
+ */
33
+ export type { ScramjetEvents } from "./client/events";
34
+ /**
35
+ * @category Window Context
36
+ */
37
+ export type { NavigateEvent } from "./client/events";
38
+ /**
39
+ * @category Window Context
40
+ */
41
+ export type { UrlChangeEvent } from "./client/events";
42
+ /**
43
+ * @category Window Context
44
+ */
45
+ export type { ScramjetContextEvent } from "./client/events";
46
+ /**
47
+ * @category Window Context
48
+ */
49
+ export type { ScramjetController } from "./controller";
50
+ /**
51
+ * @category Window Context
52
+ */
53
+ export type { ScramjetFrame } from "./controller/frame";
54
+ /**
55
+ * @category Window Context
56
+ */
57
+ export type { ScramjetClient } from "./client";
58
+ /**
59
+ * @category Service Worker Context
60
+ */
61
+ export type { ScramjetServiceWorker } from "./worker";
62
+ /**
63
+ * @fileoverview Scramjet Entry Point. This module contain global constants and factory functions to load the APIs in the bundle.
64
+ *
65
+ * @categoryDescription Window Context
66
+ * APIs for the main window context, which includes creating Scramjet Frames and the Controller for managing the Scramjet proxy behavior in the SW.
67
+ * @categoryDescription Service Worker Context
68
+ * APIs designed for the service worker context, where the core logic resides. These are the essentials and include the the `ScramjetServiceWorker`.
69
+ */
70
+ /**
71
+ * Factory function that creates the `ScramjetController` class.
72
+ *
73
+ * @returns The `ScramjetController` class.
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const { ScramjetController } = $scramjetLoadController();
78
+ *
79
+ * const scramjet = new ScramjetController({
80
+ * prefix: "/scramjet/"
81
+ * });
82
+ *
83
+ * await scramjet.init();
84
+ *
85
+ * const frame = scramjet.createFrame();
86
+ * document.body.appendChild(frame.frame);
87
+ * frame.navigate("https://example.com");
88
+ * ```
89
+ *
90
+ * @category Window Context
91
+ */
92
+ export declare function $scramjetLoadController(): any;
93
+ /**
94
+ * Factory function that creates the `ScramjetClient` for controlling sandboxing.
95
+ *
96
+ * @returns The `ScramjetClient` class.
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * const ScramjetClient = $scramjetLoadClient();
101
+ *
102
+ * const scramjetClient = new ScramjetClient.ScramjetClient();
103
+ * ```
104
+ * @category Window Context
105
+ */
106
+ export declare function $scramjetLoadClient(): any;
107
+ /**
108
+ * Factory function that creates the `ScramjetServiceWorker` class.
109
+ *
110
+ * @returns The `ScramjetServiceWorker` class.
111
+ *
112
+ * Plain SW example
113
+ * @example
114
+ * ```typescript
115
+ * // In your Service Worker
116
+ * const { ScramjetServiceWorker } = $scramjetLoadWorker();
117
+ *
118
+ * const scramjet = new ScramjetServiceWorker();
119
+ *
120
+ * self.addEventListener("fetch", async (ev) => {
121
+ * await scramjet.loadConfig();
122
+ *
123
+ * if (scramjet.route(ev)) {
124
+ * ev.respondWith(scramjet.fetch(ev));
125
+ * }
126
+ * });
127
+ * ```
128
+ *
129
+ * Workbox-powered SW routing example
130
+ * @example
131
+ * ```typescript
132
+ * // In your Service Worker (ensure you are using a bundler for Workbox)
133
+ * // This is more useful for a webOS or if you have Offline PWA support on your proxy site
134
+ * import { registerRoute } from 'workbox-routing';
135
+ *
136
+ * const { ScramjetServiceWorker } = $scramjetLoadWorker();
137
+ *
138
+ * const scramjet = new ScramjetServiceWorker();
139
+ *
140
+ * registerRoute(
141
+ * ({ request }) => {
142
+ * return scramjet.route({ request });
143
+ * },
144
+ * async ({ event }) => {
145
+ * await scramjet.loadConfig();
146
+ *
147
+ * return scramjet.fetch(event);
148
+ * }
149
+ * );
150
+ * ```
151
+ *
152
+ * @category Service Worker Context
153
+ */
154
+ export declare function $scramjetLoadWorker(): any;
155
+ /**
156
+ * Version information for the current Scramjet build.
157
+ *
158
+ * @category Window Context
159
+ */
160
+ export declare const $scramjetVersion: ScramjetVersionInfo;
@@ -0,0 +1,8 @@
1
+ import "./global.d";
2
+ export * from "./client";
3
+ export * from "./controller";
4
+ export * from "./shared";
5
+ export * from "./worker";
6
+ export * from "./entry";
7
+ export * from "./symbols";
8
+ export * from "./types";
@@ -0,0 +1,18 @@
1
+ export type Cookie = {
2
+ name: string;
3
+ value: string;
4
+ path?: string;
5
+ expires?: string;
6
+ maxAge?: number;
7
+ domain?: string;
8
+ secure?: boolean;
9
+ httpOnly?: boolean;
10
+ sameSite?: "strict" | "lax" | "none";
11
+ };
12
+ export declare class CookieStore {
13
+ private cookies;
14
+ setCookies(cookies: string[], url: URL): void;
15
+ getCookies(url: URL, fromJs: boolean): string;
16
+ load(cookies: string): null;
17
+ dump(): string;
18
+ }
@@ -0,0 +1,4 @@
1
+ export declare class ScramjetHeaders {
2
+ headers: {};
3
+ set(key: string, v: string): void;
4
+ }
@@ -0,0 +1,6 @@
1
+ import { CookieStore } from "./cookie";
2
+ import { URLMeta } from "./rewriters/url";
3
+ export declare const htmlRules: {
4
+ [key: string]: "*" | string[] | ((...any: any[]) => string | null);
5
+ fn: (value: string, meta: URLMeta, cookieStore: CookieStore) => string | null;
6
+ }[];
@@ -0,0 +1,12 @@
1
+ import { ScramjetConfig, ScramjetFlags } from "../types";
2
+ export * from "./cookie";
3
+ export * from "./headers";
4
+ export * from "./htmlRules";
5
+ export * from "./rewriters";
6
+ export * from "./security";
7
+ export declare let codecEncode: (input: string) => string;
8
+ export declare let codecDecode: (input: string) => string;
9
+ export declare function loadCodecs(): void;
10
+ export declare function flagEnabled(flag: keyof ScramjetFlags, url: URL): boolean;
11
+ export declare let config: ScramjetConfig;
12
+ export declare function setConfig(newConfig: ScramjetConfig): void;
@@ -0,0 +1,3 @@
1
+ import { URLMeta } from "./url";
2
+ export declare function rewriteCss(css: string, meta: URLMeta): string;
3
+ export declare function unrewriteCss(css: string): string;
@@ -0,0 +1,18 @@
1
+ import type { default as BareClient, BareHeaders } from "@mercuryworkshop/bare-mux";
2
+ import { type URLMeta } from "./url";
3
+ interface StoredReferrerPolicies {
4
+ get(url: string): Promise<{
5
+ policy: string;
6
+ referrer: string;
7
+ } | null>;
8
+ set(url: string, policy: string, referrer: string): Promise<void>;
9
+ }
10
+ /**
11
+ * Rewrites response headers
12
+ * @param rawHeaders Headers before they were rewritten
13
+ * @param meta Parsed Proxy URL
14
+ * @param client `BareClient` instance used for fetching
15
+ * @param isNavigationRequest Whether the request is a navigation request
16
+ */
17
+ export declare function rewriteHeaders(rawHeaders: BareHeaders, meta: URLMeta, client: BareClient, storedReferrerPolicies: StoredReferrerPolicies): Promise<{}>;
18
+ export {};
@@ -0,0 +1,6 @@
1
+ import { URLMeta } from "./url";
2
+ import { CookieStore } from "../cookie";
3
+ export declare function getInjectScripts<T>(cookieStore: CookieStore, script: (src: string) => T): T[];
4
+ export declare function rewriteHtml(html: string, cookieStore: CookieStore, meta: URLMeta, fromTop?: boolean): string;
5
+ export declare function unrewriteHtml(html: string): string;
6
+ export declare function rewriteSrcset(srcset: string, meta: URLMeta): string;
@@ -0,0 +1,7 @@
1
+ export * from "./css";
2
+ export * from "./headers";
3
+ export * from "./html";
4
+ export * from "./js";
5
+ export * from "./url";
6
+ export * from "./worker";
7
+ export * from "./wasm";
@@ -0,0 +1,10 @@
1
+ import { URLMeta } from "./url";
2
+ type RewriterResult = {
3
+ js: string | Uint8Array;
4
+ map: Uint8Array | null;
5
+ tag: string;
6
+ errors: string[];
7
+ };
8
+ export declare function rewriteJsInner(js: string | Uint8Array, url: string | null, meta: URLMeta, module?: boolean): RewriterResult;
9
+ export declare function rewriteJs(js: string | Uint8Array, url: string | null, meta: URLMeta, module?: boolean): string | Uint8Array;
10
+ export {};