@mercuryworkshop/scramjet 2.0.1-alpha → 2.0.5-alpha

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 (57) hide show
  1. package/dist/167400cb144aab22.wasm +0 -0
  2. package/dist/2919e49b986edf8c.wasm +0 -0
  3. package/dist/5aed1d5e48aab205.wasm +0 -0
  4. package/dist/882d77912a3c8e3a.wasm +0 -0
  5. package/dist/ac6aa30297a80464.wasm +0 -0
  6. package/dist/c10a57758af882c8.wasm +0 -0
  7. package/dist/cfd04aaae6955b67.wasm +0 -0
  8. package/dist/d06a90fd413b36cf.wasm +0 -0
  9. package/dist/dda06914899a6c28.wasm +0 -0
  10. package/dist/scramjet.js +7 -6
  11. package/dist/scramjet.js.map +1 -1
  12. package/dist/scramjet.mjs +8 -7
  13. package/dist/scramjet.mjs.map +1 -1
  14. package/dist/scramjet.wasm +0 -0
  15. package/dist/scramjet_bundled.js +7 -6
  16. package/dist/scramjet_bundled.js.map +1 -1
  17. package/dist/scramjet_bundled.mjs +7 -6
  18. package/dist/scramjet_bundled.mjs.map +1 -1
  19. package/dist/types/Tap.d.ts +32 -0
  20. package/dist/types/client/client.d.ts +59 -35
  21. package/dist/types/client/events.d.ts +9 -37
  22. package/dist/types/client/global.d.ts +4 -0
  23. package/dist/types/client/helpers.d.ts +1 -1
  24. package/dist/types/client/location.d.ts +1 -1
  25. package/dist/types/client/shared/unproxy.d.ts +19 -0
  26. package/dist/types/client/shared/wrap.d.ts +2 -2
  27. package/dist/types/client/singletonbox.d.ts +2 -0
  28. package/dist/types/client/unproxy.generated.d.ts +50 -0
  29. package/dist/types/fetch/body.d.ts +3 -0
  30. package/dist/types/fetch/fetch.d.ts +7 -0
  31. package/dist/types/fetch/headers.d.ts +19 -0
  32. package/dist/types/fetch/index.d.ts +91 -43
  33. package/dist/types/fetch/parse.d.ts +22 -0
  34. package/dist/types/fetch/util.d.ts +7 -0
  35. package/dist/types/index.d.ts +2 -0
  36. package/dist/types/shared/cookie.d.ts +13 -5
  37. package/dist/types/shared/htmlRules.d.ts +1 -1
  38. package/dist/types/shared/index.d.ts +31 -3
  39. package/dist/types/shared/mime.d.ts +39 -0
  40. package/dist/types/shared/refresh.d.ts +7 -0
  41. package/dist/types/shared/rewriters/css.d.ts +2 -2
  42. package/dist/types/shared/rewriters/html.d.ts +31 -4
  43. package/dist/types/shared/rewriters/js.d.ts +3 -3
  44. package/dist/types/shared/rewriters/url.d.ts +19 -5
  45. package/dist/types/shared/rewriters/wasm.d.ts +1 -2
  46. package/dist/types/shared/rewriters/worker.d.ts +1 -1
  47. package/dist/types/shared/set-cookie-parser.d.ts +20 -0
  48. package/dist/types/shared/snapshot.d.ts +236 -0
  49. package/dist/types/shared/sniffEncoding.d.ts +65 -0
  50. package/dist/types/shared/util.d.ts +2 -0
  51. package/dist/types/symbols.d.ts +1 -2
  52. package/dist/types/types.d.ts +4 -50
  53. package/package.json +7 -13
  54. package/dist/c34a4f083a11eae2.wasm +0 -0
  55. package/dist/scramjet.wasm.wasm +0 -0
  56. package/dist/types/shared/security/index.d.ts +0 -1
  57. package/dist/types/shared/security/siteTests.d.ts +0 -1
@@ -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 {};
@@ -1,16 +1,21 @@
1
- type ScramjetFrame = any;
2
- import { BareCompatibleClient, ProxyTransport } from "@mercuryworkshop/proxy-transports";
3
- import { type URLMeta } from "../shared/rewriters/url";
4
- import { ScramjetContext } from "../shared";
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
5
  import { SingletonBox } from "./singletonbox";
6
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";
7
10
  export type ScramjetClientInit = {
8
11
  context: ScramjetContext;
9
12
  transport: ProxyTransport;
10
- sendSetCookie: (url: URL, cookie: string) => Promise<void>;
13
+ sendSetCookie: (cookies: CookieSyncEntry[], options?: CookieSyncOptions) => Promise<void>;
11
14
  shouldPassthroughWebsocket?: (url: string | URL) => boolean;
12
15
  shouldBlockMessageEvent?: (ev: MessageEvent) => boolean;
13
16
  hookSubcontext: (self: Self, frame?: HTMLIFrameElement) => ScramjetClient;
17
+ initHeaders: RawHeaders;
18
+ history: TrackedHistoryState[];
14
19
  };
15
20
  type NativeStore = {
16
21
  store: Record<string, any>;
@@ -22,40 +27,45 @@ type DescriptorStore = {
22
27
  get: (target: string, that: any) => any;
23
28
  set: (target: string, that: any, value: any) => void;
24
29
  };
25
- export type AnyFunction = Function;
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>>;
26
36
  export type ScramjetModule = {
27
37
  enabled: (client: ScramjetClient) => boolean | undefined;
28
- disabled: (client: ScramjetClient, self: typeof globalThis) => void | undefined;
38
+ disabled: (client: ScramjetClient, self: GlobalThis) => void | undefined;
29
39
  order: number | undefined;
30
- default: (client: ScramjetClient, self: typeof globalThis) => void;
40
+ default: (client: ScramjetClient, self: GlobalThis) => void;
31
41
  };
32
- export type ProxyCtx = {
33
- fn: AnyFunction;
34
- this: any;
35
- args: any[];
36
- newTarget: AnyFunction;
37
- return: (r: any) => void;
38
- call: () => any;
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>>>;
39
49
  };
40
- export type Proxy = {
41
- construct?(ctx: ProxyCtx): any;
42
- apply?(ctx: ProxyCtx): any;
50
+ export type Proxy<T extends string = string> = {
51
+ construct?(ctx: ProxyCtx<T, "construct">): any;
52
+ apply?(ctx: ProxyCtx<T, "apply">): any;
43
53
  };
44
- export type TrapCtx<T> = {
54
+ export type TrapCtx<T extends string> = {
45
55
  this: any;
46
- get: () => T;
47
- set: (v: T) => void;
56
+ get: () => GlobalTraverse<T>;
57
+ set: (v: GlobalTraverse<T>) => void;
48
58
  };
49
- export type Trap<T> = {
59
+ export type Trap<T extends string> = {
50
60
  writable?: boolean;
51
61
  value?: any;
52
62
  enumerable?: boolean;
53
63
  configurable?: boolean;
54
- get?: (ctx: TrapCtx<T>) => T;
55
- set?: (ctx: TrapCtx<T>, v: T) => void;
64
+ get?: (ctx: TrapCtx<T>) => GlobalTraverse<T>;
65
+ set?: (ctx: TrapCtx<T>, v: GlobalTraverse<T>) => void;
56
66
  };
57
67
  export declare class ScramjetClient {
58
- global: typeof globalThis;
68
+ global: GlobalThis;
59
69
  init: ScramjetClientInit;
60
70
  locationProxy: any;
61
71
  serviceWorker: ServiceWorkerContainer;
@@ -73,17 +83,31 @@ export declare class ScramjetClient {
73
83
  meta: URLMeta;
74
84
  box: SingletonBox;
75
85
  context: ScramjetContext;
76
- constructor(global: typeof globalThis, init: ScramjetClientInit);
77
- get frame(): ScramjetFrame | null;
78
- get isSubframe(): boolean;
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;
79
101
  hook(): void;
80
- get url(): URL;
81
- set url(url: URL | string);
82
- Proxy(name: string | string[], handler: Proxy): void;
83
- RawProxy(target: any, prop: string, handler: Proxy, debugname?: string): void;
84
- Trap<T>(name: string | string[], descriptor: Trap<T>): PropertyDescriptor;
85
- RawTrap<T>(target: any, prop: string, descriptor: Trap<T>): PropertyDescriptor;
86
- rewriteUrl(url: string | URL): string;
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;
87
111
  unrewriteUrl(url: string | URL): string;
88
112
  flagEnabled(flag: keyof ScramjetConfig["flags"]): boolean;
89
113
  get config(): ScramjetConfig;
@@ -1,38 +1,10 @@
1
- import { ScramjetClient } from "./index";
2
- /**
3
- * Union type for all Scramjet proxified navigation events.
4
- */
5
- export type ScramjetEvent = NavigateEvent | UrlChangeEvent | ScramjetContextEvent;
6
- /**
7
- * Type map for all Scramjet navigation events with their corresponding event types.
8
- */
9
- export type ScramjetEvents = {
10
- navigate: NavigateEvent;
11
- urlchange: UrlChangeEvent;
12
- contextInit: ScramjetContextEvent;
1
+ export type LifecycleHooks = {
2
+ navigate: {
3
+ context: {
4
+ type: "location" | "history" | "hashchange";
5
+ };
6
+ props: {
7
+ url: string;
8
+ };
9
+ };
13
10
  };
14
- /**
15
- * Navigation event class fired when Scramjet frame navigates to a new proxified URL.
16
- */
17
- export declare class NavigateEvent extends Event {
18
- url: string;
19
- type: string;
20
- constructor(url: string);
21
- }
22
- /**
23
- * URL change event class fired when the proxified URL changes in a Scramjet frame.
24
- */
25
- export declare class UrlChangeEvent extends Event {
26
- url: string;
27
- type: string;
28
- constructor(url: string);
29
- }
30
- /**
31
- * Event class fired when Scramjet initializes in a frame.
32
- */
33
- export declare class ScramjetContextEvent extends Event {
34
- window: Self;
35
- client: ScramjetClient;
36
- type: string;
37
- constructor(window: Self, client: ScramjetClient);
38
- }
@@ -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;
@@ -1 +1 @@
1
- export declare function getOwnPropertyDescriptorHandler(target: any, prop: any): TypedPropertyDescriptor<any>;
1
+ export declare function getOwnPropertyDescriptorHandler(target: any, prop: any): PropertyDescriptor;
@@ -1,2 +1,2 @@
1
1
  import { ScramjetClient } from "./index";
2
- export declare function createLocationProxy(client: ScramjetClient, self: typeof globalThis): any;
2
+ export declare function createLocationProxy(client: ScramjetClient, self: GlobalThis): any;
@@ -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 {};
@@ -1,4 +1,4 @@
1
1
  import { ScramjetClient } from "../index";
2
- export declare function createWrapFn(client: ScramjetClient, self: typeof globalThis): (identifier: any, strict: boolean) => any;
2
+ export declare function createWrapFn(client: ScramjetClient, self: GlobalThis): (identifier: any, strict: boolean) => any;
3
3
  export declare const order = 4;
4
- export default function (client: ScramjetClient, self: typeof globalThis): void;
4
+ export default function (client: ScramjetClient, self: GlobalThis): void;
@@ -1,3 +1,4 @@
1
+ import { IncrementalHtmlRewriter } from "../shared";
1
2
  import { ScramjetClient } from "./client";
2
3
  import { SourceMaps } from "./shared/sourcemaps";
3
4
  export declare class SingletonBox {
@@ -6,6 +7,7 @@ export declare class SingletonBox {
6
7
  globals: Map<Self, ScramjetClient>;
7
8
  documents: Map<Document, ScramjetClient>;
8
9
  locations: Map<Location, ScramjetClient>;
10
+ writeRewriters: WeakMap<Document, IncrementalHtmlRewriter>;
9
11
  ctors: Record<string, Function[]>;
10
12
  sourcemaps: SourceMaps;
11
13
  constructor(ownerclient: ScramjetClient);
@@ -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";
@@ -1,11 +1,14 @@
1
- import { BareCompatibleClient, BareResponse, ProxyTransport, RawHeaders, BareRequestInit } from "@mercuryworkshop/proxy-transports";
1
+ import { BareCompatibleClient, BareResponse, ProxyTransport, BareRequestInit } from "@mercuryworkshop/proxy-transports";
2
2
  import { type URLMeta } from "../shared/rewriters/url";
3
+ import { type ScramjetRequestMode } from "./parse";
3
4
  import { ScramjetHeaders } from "../shared/headers";
4
- import { ScramjetContext } from "../shared";
5
- import DomHandler from "domhandler";
5
+ import { HtmlRewriterHooks, ScramjetContext } from "../shared";
6
+ import { TapInstance } from "../Tap";
7
+ import { _URL, _Map } from "../shared/snapshot";
6
8
  export interface ScramjetFetchRequest {
7
9
  rawUrl: URL;
8
- destination: RequestDestination;
10
+ rawReferrer: string | null;
11
+ rawDestination: RequestDestination;
9
12
  mode: RequestMode;
10
13
  referrer: string;
11
14
  method: string;
@@ -13,12 +16,25 @@ export interface ScramjetFetchRequest {
13
16
  cache: RequestCache;
14
17
  initialHeaders: ScramjetHeaders;
15
18
  rawClientUrl?: URL;
19
+ /** The service worker FetchEvent.clientId that originated this request. */
20
+ clientId: string;
16
21
  }
17
22
  export interface ScramjetFetchParsed {
18
- url: URL;
19
- clientUrl?: URL;
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;
20
34
  meta: URLMeta;
21
- scriptType: "module" | "regular";
35
+ isModule: boolean;
36
+ referrerPolicy?: string;
37
+ trackedClient?: ScramjetFetchTrackedClient;
22
38
  }
23
39
  export interface ScramjetFetchResponse {
24
40
  body: BodyType;
@@ -26,55 +42,87 @@ export interface ScramjetFetchResponse {
26
42
  status: number;
27
43
  statusText: string;
28
44
  }
45
+ export type CookieSyncEntry = {
46
+ url: URL;
47
+ cookie: string;
48
+ };
49
+ export type CookieSyncOptions = {
50
+ clear?: boolean;
51
+ destination?: RequestDestination;
52
+ };
29
53
  export type FetchHandlerInit = {
30
54
  transport: ProxyTransport;
31
55
  context: ScramjetContext;
32
56
  crossOriginIsolated?: boolean;
33
- sendSetCookie: (url: URL, cookie: string) => Promise<void>;
57
+ sendSetCookie: (cookies: CookieSyncEntry[], options?: CookieSyncOptions) => Promise<void>;
34
58
  fetchDataUrl(dataUrl: string): Promise<BareResponse>;
35
59
  fetchBlobUrl(blobUrl: string): Promise<BareResponse>;
36
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
+ }
37
70
  export declare class ScramjetFetchHandler extends EventTarget {
38
71
  client: BareCompatibleClient;
39
72
  crossOriginIsolated: boolean;
40
73
  context: ScramjetContext;
74
+ trackedClients: _Map<string, ScramjetFetchTrackedClient>;
75
+ hooks: {
76
+ rewriter: {
77
+ html: TapInstance<HtmlRewriterHooks>;
78
+ };
79
+ fetch: TapInstance<FetchHooks>;
80
+ };
41
81
  fetchDataUrl: (dataUrl: string) => Promise<Response>;
42
82
  fetchBlobUrl: (blobUrl: string) => Promise<Response>;
43
- sendSetCookie: (url: URL, cookie: string) => Promise<void>;
83
+ sendSetCookie: (cookies: CookieSyncEntry[], options?: CookieSyncOptions) => Promise<void>;
44
84
  constructor(init: FetchHandlerInit);
45
85
  handleFetch(request: ScramjetFetchRequest): Promise<ScramjetFetchResponse>;
46
86
  }
47
- export declare function parseRequest(request: ScramjetFetchRequest, handler: ScramjetFetchHandler): ScramjetFetchParsed;
48
- export declare function rewriteHeaders(handler: ScramjetFetchHandler, request: ScramjetFetchRequest, parsed: ScramjetFetchParsed, rawHeaders: RawHeaders): Promise<ScramjetHeaders>;
49
- type BodyType = string | ArrayBuffer | Blob | ReadableStream<any>;
50
- export declare class ScramjetHTMLPreRewriteEvent extends Event {
51
- handler: DomHandler;
52
- context: ScramjetFetchRequest;
53
- parsed: ScramjetFetchParsed;
54
- constructor(handler: DomHandler, context: ScramjetFetchRequest, parsed: ScramjetFetchParsed);
55
- }
56
- export declare class ScramjetHTMLPostRewriteEvent extends Event {
57
- handler: DomHandler;
58
- context: ScramjetFetchRequest;
59
- parsed: ScramjetFetchParsed;
60
- constructor(handler: DomHandler, context: ScramjetFetchRequest, parsed: ScramjetFetchParsed);
61
- }
62
- export declare class ScramjetResponseEvent extends Event {
63
- context: ScramjetFetchRequest;
64
- parsed: ScramjetFetchParsed;
65
- response: ScramjetFetchResponse;
66
- _response?: ScramjetFetchResponse | Promise<ScramjetFetchResponse>;
67
- constructor(context: ScramjetFetchRequest, parsed: ScramjetFetchParsed, response: ScramjetFetchResponse);
68
- respondWith(response: ScramjetFetchResponse | Promise<ScramjetFetchResponse>): void;
69
- }
70
- export declare class ScramjetRequestEvent extends Event {
71
- context: ScramjetFetchRequest;
72
- url: URL;
73
- parsed: ScramjetFetchParsed;
74
- init: BareRequestInit;
75
- client: BareCompatibleClient;
76
- _response?: BareResponse | Promise<BareResponse> | Response | Promise<Response>;
77
- constructor(context: ScramjetFetchRequest, url: URL, parsed: ScramjetFetchParsed, init: BareRequestInit, client: BareCompatibleClient);
78
- respondWith(response: BareResponse | Promise<BareResponse>): void;
79
- }
80
- export {};
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;
@@ -5,5 +5,7 @@ export * from "./shared";
5
5
  export * from "./symbols";
6
6
  export * from "./types";
7
7
  export * from "./fetch";
8
+ export * from "./Tap";
9
+ export { BareResponse } from "@mercuryworkshop/proxy-transports";
8
10
  export declare const defaultConfig: ScramjetConfig;
9
11
  export declare const defaultConfigDev: ScramjetConfig;
@@ -2,17 +2,25 @@ export type Cookie = {
2
2
  name: string;
3
3
  value: string;
4
4
  path?: string;
5
- expires?: string;
5
+ expires?: number;
6
6
  maxAge?: number;
7
7
  domain?: string;
8
+ hostOnly?: boolean;
8
9
  secure?: boolean;
9
10
  httpOnly?: boolean;
10
- sameSite?: "strict" | "lax" | "none";
11
+ sameSite?: string;
11
12
  };
12
13
  export declare class CookieJar {
13
14
  private cookies;
14
- setCookies(cookies: string[], url: URL): void;
15
- getCookies(url: URL, fromJs: boolean): string;
16
- load(cookies: string): null;
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;
17
25
  dump(): string;
18
26
  }
@@ -1,5 +1,5 @@
1
1
  import { URLMeta } from "./rewriters/url";
2
- import { ScramjetContext } from "./";
2
+ import { ScramjetContext } from "../shared";
3
3
  export declare const htmlRules: {
4
4
  [key: string]: "*" | string[] | ((...any: any[]) => string | null);
5
5
  fn: (value: string, context: ScramjetContext, meta: URLMeta) => string | null;