@petezah-games/scramjet-controller 0.0.9 → 0.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.
- package/README.md +68 -0
- package/package.json +37 -3
- package/src/index.ts +0 -437
- package/src/inject.ts +0 -245
- package/src/sw.ts +0 -159
- package/src/types.d.ts +0 -95
- package/src/typesEntry.ts +0 -6
- package/tsconfig.json +0 -24
- package/tsconfig.types.json +0 -16
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Scramjet Controller
|
|
2
|
+
|
|
3
|
+
The controller package manages the coordination between the main application, service workers, and proxy transports in the Scramjet proxy. It handles RPC communication, request routing, and resource management across different execution contexts.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides the core orchestration layer for Scramjet, enabling:
|
|
8
|
+
|
|
9
|
+
- **RPC Communication**: Two-way RPC communication between the main thread, service workers, and transport layers
|
|
10
|
+
- **Request Routing**: Handling and forwarding HTTP/HTTPS requests through configured proxy transports
|
|
11
|
+
- **Resource Injection**: Injecting Scramjet utilities into web pages
|
|
12
|
+
- **Service Worker Integration**: Managing multiple service worker instances and their lifecycle
|
|
13
|
+
- **Cookie Management**: Centralized cookie jar for maintaining session state across requests
|
|
14
|
+
|
|
15
|
+
## Structure
|
|
16
|
+
|
|
17
|
+
### Core Modules
|
|
18
|
+
|
|
19
|
+
- **`index.ts`** - Main Controller class that coordinates between transports and service workers. Handles request processing, frame management, and RPC setup.
|
|
20
|
+
- **`inject.ts`** - Injection script that runs in the service worker context. Implements RemoteTransport to communicate back to the main controller via MessagePort.
|
|
21
|
+
- **`sw.ts`** - Service worker hooks that manage controller registration, request interception, and service worker lifecycle.
|
|
22
|
+
- **`types.d.ts`** - Type definitions for RPC messages and communication interfaces between different contexts.
|
|
23
|
+
- **`typesEntry.ts`** - Type entry point for the package exports.
|
|
24
|
+
|
|
25
|
+
## Exports
|
|
26
|
+
|
|
27
|
+
The package exports three main entry points:
|
|
28
|
+
|
|
29
|
+
- **`@petezah-games/scramjet-controller`** - Main Controller API
|
|
30
|
+
- **`@petezah-games/scramjet-controller/inject`** - Injection utilities for service workers
|
|
31
|
+
- **`@petezah-games/scramjet-controller/worker`** - Service worker
|
|
32
|
+
|
|
33
|
+
## Key Features
|
|
34
|
+
|
|
35
|
+
### Controller Class
|
|
36
|
+
|
|
37
|
+
The main `Controller` class manages:
|
|
38
|
+
- Connection to proxy transports
|
|
39
|
+
- Service worker lifecycle and registration
|
|
40
|
+
- Frame management for multiple contexts
|
|
41
|
+
- RPC communication with service workers
|
|
42
|
+
- Request interception and routing via Scramjet
|
|
43
|
+
|
|
44
|
+
### Configuration
|
|
45
|
+
|
|
46
|
+
Default configuration includes:
|
|
47
|
+
- `prefix`: `/~/sj/` - URL prefix for controller routes
|
|
48
|
+
- `virtualWasmPath`: `scramjet.wasm.js` - Virtual path for WASM module
|
|
49
|
+
- `injectPath`: `/controller/controller.inject.js` - Path to injection script
|
|
50
|
+
- `scramjetPath`: `/scramjet/scramjet.js` - Path to main Scramjet library
|
|
51
|
+
- `wasmPath`: `/scramjet/scramjet.wasm` - Path to WASM binary
|
|
52
|
+
|
|
53
|
+
### RPC Methods
|
|
54
|
+
|
|
55
|
+
The controller exposes RPC methods for:
|
|
56
|
+
- `ready` - Signals when the service worker is ready
|
|
57
|
+
- `request` - Processes HTTP requests
|
|
58
|
+
- Additional transport initialization and management
|
|
59
|
+
|
|
60
|
+
## Dependencies
|
|
61
|
+
|
|
62
|
+
- `@mercuryworkshop/scramjet` - Core proxy rewriting library
|
|
63
|
+
- `@mercuryworkshop/proxy-transports` - Transport abstraction layer
|
|
64
|
+
- `@mercuryworkshop/rpc` - RPC helper for inter-context communication
|
|
65
|
+
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
The controller is typically initialized by the bootstrap package, which sets up the service worker registration and injects the controller into the page context. Applications should interact with the controller through the RPC interface for request handling and configuration.
|
package/package.json
CHANGED
|
@@ -1,9 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@petezah-games/scramjet-controller",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Controller for Scramjet proxy, it manages coordination between application, service workers, and proxy transports",
|
|
4
5
|
"type": "module",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
6
|
+
"license": "AGPL-3.0-only",
|
|
7
|
+
"author": "PeteZah Games",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/petezah-games/scramjet"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/petezah-games/scramjet/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/petezah-games/scramjet#readme",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"proxy",
|
|
18
|
+
"scramjet",
|
|
19
|
+
"web-proxy",
|
|
20
|
+
"service-worker",
|
|
21
|
+
"rpc",
|
|
22
|
+
"transport"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"import": "./dist/controller.api.js",
|
|
27
|
+
"types": "./dist/types/index.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./inject": {
|
|
30
|
+
"import": "./dist/controller.inject.js",
|
|
31
|
+
"types": "./dist/types/inject.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./worker": {
|
|
34
|
+
"import": "./dist/controller.sw.js",
|
|
35
|
+
"types": "./dist/types/sw.d.ts"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist"
|
|
40
|
+
],
|
|
7
41
|
"dependencies": {
|
|
8
42
|
"@mercuryworkshop/proxy-transports": "1.0.2",
|
|
9
43
|
"@mercuryworkshop/scramjet": "2.0.2-alpha"
|
package/src/index.ts
DELETED
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
import { type MethodsDefinition, RpcHelper } from "@mercuryworkshop/rpc";
|
|
2
|
-
import type * as ScramjetGlobal from "@mercuryworkshop/scramjet";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
type TransportToController,
|
|
6
|
-
type Controllerbound,
|
|
7
|
-
type ControllerToTransport,
|
|
8
|
-
type SWbound,
|
|
9
|
-
type WebSocketMessage,
|
|
10
|
-
} from "./types";
|
|
11
|
-
import {
|
|
12
|
-
BareCompatibleClient,
|
|
13
|
-
BareResponse,
|
|
14
|
-
type ProxyTransport,
|
|
15
|
-
} from "@mercuryworkshop/proxy-transports";
|
|
16
|
-
import * as $scramjet from '@mercuryworkshop/scramjet';
|
|
17
|
-
|
|
18
|
-
const cookieJar = new $scramjet.CookieJar();
|
|
19
|
-
|
|
20
|
-
type Config = {
|
|
21
|
-
wasmPath: string;
|
|
22
|
-
injectPath: string;
|
|
23
|
-
scramjetPath: string;
|
|
24
|
-
virtualWasmPath: string;
|
|
25
|
-
prefix: string;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const config: Config = {
|
|
29
|
-
prefix: "/~/sj/",
|
|
30
|
-
virtualWasmPath: "scramjet.wasm.js",
|
|
31
|
-
injectPath: "/controller/controller.inject.js",
|
|
32
|
-
scramjetPath: "/scramjet/scramjet.js",
|
|
33
|
-
wasmPath: "/scramjet/scramjet.wasm",
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const cfg = {
|
|
37
|
-
flags: {
|
|
38
|
-
...$scramjet.defaultConfig.flags,
|
|
39
|
-
allowFailedIntercepts: true,
|
|
40
|
-
},
|
|
41
|
-
maskedfiles: ["inject.js", "scramjet.wasm.js"],
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const frames: Record<string, Frame> = {};
|
|
45
|
-
|
|
46
|
-
let wasmPayload: string | null = null;
|
|
47
|
-
|
|
48
|
-
function makeId(): string {
|
|
49
|
-
return Math.random().toString(36).substring(2, 10);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const codecEncode = (url: string) => {
|
|
53
|
-
if (!url) return url;
|
|
54
|
-
|
|
55
|
-
return encodeURIComponent(url);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const codecDecode = (url: string) => {
|
|
59
|
-
if (!url) return url;
|
|
60
|
-
|
|
61
|
-
return decodeURIComponent(url);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
type ControllerInit = {
|
|
65
|
-
serviceworker: ServiceWorker;
|
|
66
|
-
transport: ProxyTransport;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
let wasmAlreadyFetched = false;
|
|
70
|
-
|
|
71
|
-
async function loadScramjetWasm() {
|
|
72
|
-
if (wasmAlreadyFetched) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let resp = await fetch(config.wasmPath);
|
|
77
|
-
$scramjet.setWasm(await resp.arrayBuffer());
|
|
78
|
-
wasmAlreadyFetched = true;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export class Controller {
|
|
82
|
-
id: string;
|
|
83
|
-
prefix: string;
|
|
84
|
-
frames: Frame[] = [];
|
|
85
|
-
cookieJar = new $scramjet.CookieJar();
|
|
86
|
-
|
|
87
|
-
rpc: RpcHelper<Controllerbound, SWbound>;
|
|
88
|
-
private ready: Promise<[void, void]>;
|
|
89
|
-
private readyResolve!: () => void;
|
|
90
|
-
public isReady: boolean = false;
|
|
91
|
-
|
|
92
|
-
transport: ProxyTransport;
|
|
93
|
-
|
|
94
|
-
private methods: MethodsDefinition<Controllerbound> = {
|
|
95
|
-
ready: async () => {
|
|
96
|
-
this.readyResolve();
|
|
97
|
-
},
|
|
98
|
-
request: async (data) => {
|
|
99
|
-
try {
|
|
100
|
-
let path = new URL(data.rawUrl).pathname;
|
|
101
|
-
const frame = this.frames.find((f) => path.startsWith(f.prefix));
|
|
102
|
-
if (!frame) throw new Error("No frame found for request");
|
|
103
|
-
|
|
104
|
-
if (path === frame.prefix + config.virtualWasmPath) {
|
|
105
|
-
if (!wasmPayload) {
|
|
106
|
-
const resp = await fetch(config.wasmPath);
|
|
107
|
-
const buf = await resp.arrayBuffer();
|
|
108
|
-
const b64 = btoa(
|
|
109
|
-
new Uint8Array(buf)
|
|
110
|
-
.reduce(
|
|
111
|
-
(data, byte) => (data.push(String.fromCharCode(byte)), data),
|
|
112
|
-
[] as any
|
|
113
|
-
)
|
|
114
|
-
.join("")
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
let payload = "";
|
|
118
|
-
payload +=
|
|
119
|
-
"if ('document' in self && document.currentScript) { document.currentScript.remove(); }\n";
|
|
120
|
-
payload += `self.WASM = '${b64}';`;
|
|
121
|
-
wasmPayload = payload;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return [
|
|
125
|
-
{
|
|
126
|
-
body: wasmPayload,
|
|
127
|
-
status: 200,
|
|
128
|
-
statusText: "OK",
|
|
129
|
-
headers: [["Content-Type", "application/javascript"]],
|
|
130
|
-
},
|
|
131
|
-
[],
|
|
132
|
-
];
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
let sjheaders = $scramjet.ScramjetHeaders.fromRawHeaders(
|
|
136
|
-
data.initialHeaders
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
const fetchresponse = await frame.fetchHandler.handleFetch({
|
|
140
|
-
initialHeaders: sjheaders,
|
|
141
|
-
rawClientUrl: data.rawClientUrl
|
|
142
|
-
? new URL(data.rawClientUrl)
|
|
143
|
-
: undefined,
|
|
144
|
-
rawUrl: new URL(data.rawUrl),
|
|
145
|
-
destination: data.destination,
|
|
146
|
-
method: data.method,
|
|
147
|
-
mode: data.mode,
|
|
148
|
-
referrer: data.referrer,
|
|
149
|
-
body: data.body,
|
|
150
|
-
cache: data.cache,
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
return [
|
|
154
|
-
{
|
|
155
|
-
body: fetchresponse.body,
|
|
156
|
-
status: fetchresponse.status,
|
|
157
|
-
statusText: fetchresponse.statusText,
|
|
158
|
-
headers: fetchresponse.headers.toRawHeaders(),
|
|
159
|
-
},
|
|
160
|
-
fetchresponse.body instanceof ReadableStream ||
|
|
161
|
-
fetchresponse.body instanceof ArrayBuffer
|
|
162
|
-
? [fetchresponse.body]
|
|
163
|
-
: [],
|
|
164
|
-
];
|
|
165
|
-
} catch (e) {
|
|
166
|
-
console.error("Error in controller request handler:", e);
|
|
167
|
-
throw e;
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
initRemoteTransport: async (port) => {
|
|
171
|
-
const rpc = new RpcHelper<TransportToController, ControllerToTransport>(
|
|
172
|
-
{
|
|
173
|
-
request: async ({ remote, method, body, headers }) => {
|
|
174
|
-
let response = await this.transport.request(
|
|
175
|
-
new URL(remote),
|
|
176
|
-
method,
|
|
177
|
-
body,
|
|
178
|
-
headers,
|
|
179
|
-
undefined
|
|
180
|
-
);
|
|
181
|
-
return [response, [response.body]];
|
|
182
|
-
},
|
|
183
|
-
connect: async ({ url, protocols, requestHeaders, port }) => {
|
|
184
|
-
let resolve: (arg: TransportToController["connect"][1]) => void;
|
|
185
|
-
let promise = new Promise<TransportToController["connect"][1]>(
|
|
186
|
-
(res) => (resolve = res)
|
|
187
|
-
);
|
|
188
|
-
const [send, close] = this.transport.connect(
|
|
189
|
-
new URL(url),
|
|
190
|
-
protocols,
|
|
191
|
-
requestHeaders,
|
|
192
|
-
(protocol, extensions) => {
|
|
193
|
-
resolve({
|
|
194
|
-
result: "success",
|
|
195
|
-
protocol: protocol,
|
|
196
|
-
extensions: extensions,
|
|
197
|
-
});
|
|
198
|
-
},
|
|
199
|
-
(data) => {
|
|
200
|
-
port.postMessage(
|
|
201
|
-
{
|
|
202
|
-
type: "data",
|
|
203
|
-
data: data,
|
|
204
|
-
} as WebSocketMessage,
|
|
205
|
-
data instanceof ArrayBuffer ? [data] : []
|
|
206
|
-
);
|
|
207
|
-
},
|
|
208
|
-
(close, reason) => {
|
|
209
|
-
port.postMessage({
|
|
210
|
-
type: "close",
|
|
211
|
-
code: close,
|
|
212
|
-
reason: reason,
|
|
213
|
-
} as WebSocketMessage);
|
|
214
|
-
},
|
|
215
|
-
(error) => {
|
|
216
|
-
resolve({
|
|
217
|
-
result: "failure",
|
|
218
|
-
error: error,
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
);
|
|
222
|
-
port.onmessageerror = (ev) => {
|
|
223
|
-
console.error(
|
|
224
|
-
"Transport port messageerror (this should never happen!)",
|
|
225
|
-
ev
|
|
226
|
-
);
|
|
227
|
-
};
|
|
228
|
-
port.onmessage = ({ data }: { data: WebSocketMessage }) => {
|
|
229
|
-
if (data.type === "data") {
|
|
230
|
-
send(data.data);
|
|
231
|
-
} else if (data.type === "close") {
|
|
232
|
-
close(data.code, data.reason);
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
return [await promise, []];
|
|
237
|
-
},
|
|
238
|
-
},
|
|
239
|
-
"transport",
|
|
240
|
-
(data, transfer) => port.postMessage(data, transfer)
|
|
241
|
-
);
|
|
242
|
-
port.onmessageerror = (ev) => {
|
|
243
|
-
console.error(
|
|
244
|
-
"Transport port messageerror (this should never happen!)",
|
|
245
|
-
ev
|
|
246
|
-
);
|
|
247
|
-
};
|
|
248
|
-
port.onmessage = (e) => {
|
|
249
|
-
rpc.recieve(e.data);
|
|
250
|
-
};
|
|
251
|
-
rpc.call("ready", undefined, []);
|
|
252
|
-
},
|
|
253
|
-
sendSetCookie: async ({ url, cookie }) => { },
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
constructor(public init: ControllerInit) {
|
|
257
|
-
this.transport = init.transport;
|
|
258
|
-
this.id = makeId();
|
|
259
|
-
this.prefix = config.prefix + this.id + "/";
|
|
260
|
-
|
|
261
|
-
this.ready = Promise.all([
|
|
262
|
-
new Promise<void>((resolve) => {
|
|
263
|
-
this.readyResolve = resolve;
|
|
264
|
-
}),
|
|
265
|
-
loadScramjetWasm(),
|
|
266
|
-
]);
|
|
267
|
-
|
|
268
|
-
let channel = new MessageChannel();
|
|
269
|
-
this.rpc = new RpcHelper<Controllerbound, SWbound>(
|
|
270
|
-
this.methods,
|
|
271
|
-
"tabchannel-" + this.id,
|
|
272
|
-
(data, transfer) => {
|
|
273
|
-
channel.port1.postMessage(data, transfer);
|
|
274
|
-
}
|
|
275
|
-
);
|
|
276
|
-
channel.port1.addEventListener("message", (e) => {
|
|
277
|
-
this.rpc.recieve(e.data);
|
|
278
|
-
});
|
|
279
|
-
channel.port1.start();
|
|
280
|
-
|
|
281
|
-
init.serviceworker.postMessage(
|
|
282
|
-
{
|
|
283
|
-
$controller$init: {
|
|
284
|
-
prefix: config.prefix + this.id,
|
|
285
|
-
id: this.id,
|
|
286
|
-
},
|
|
287
|
-
},
|
|
288
|
-
[channel.port2]
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
createFrame(element?: HTMLIFrameElement): Frame {
|
|
293
|
-
if (!this.ready) {
|
|
294
|
-
throw new Error(
|
|
295
|
-
"Controller is not ready! Try awaiting controller.wait()"
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
element ??= document.createElement("iframe");
|
|
299
|
-
const frame = new Frame(this, element);
|
|
300
|
-
this.frames.push(frame);
|
|
301
|
-
return frame;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
wait(): Promise<void> {
|
|
305
|
-
return this.ready;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
function yieldGetInjectScripts(
|
|
310
|
-
cookieJar: ScramjetGlobal.CookieJar,
|
|
311
|
-
config: Config,
|
|
312
|
-
sjconfig: ScramjetGlobal.ScramjetConfig,
|
|
313
|
-
prefix: URL
|
|
314
|
-
) {
|
|
315
|
-
let getInjectScripts: ScramjetGlobal.ScramjetInterface["getInjectScripts"] = (
|
|
316
|
-
meta,
|
|
317
|
-
handler,
|
|
318
|
-
script
|
|
319
|
-
) => {
|
|
320
|
-
return [
|
|
321
|
-
script(config.scramjetPath),
|
|
322
|
-
script(config.injectPath),
|
|
323
|
-
script(prefix.href + config.virtualWasmPath),
|
|
324
|
-
script(
|
|
325
|
-
"data:text/javascript;base64," +
|
|
326
|
-
btoa(`
|
|
327
|
-
document.currentScript.remove();
|
|
328
|
-
$scramjetController.load({
|
|
329
|
-
config: ${JSON.stringify(config)},
|
|
330
|
-
sjconfig: ${JSON.stringify(sjconfig)},
|
|
331
|
-
cookies: ${cookieJar.dump()},
|
|
332
|
-
prefix: new URL("${prefix.href}"),
|
|
333
|
-
yieldGetInjectScripts: ${yieldGetInjectScripts.toString()},
|
|
334
|
-
codecEncode: ${codecEncode.toString()},
|
|
335
|
-
codecDecode: ${codecDecode.toString()},
|
|
336
|
-
})
|
|
337
|
-
`)
|
|
338
|
-
),
|
|
339
|
-
];
|
|
340
|
-
};
|
|
341
|
-
return getInjectScripts;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
class Frame {
|
|
345
|
-
fetchHandler: ScramjetGlobal.ScramjetFetchHandler;
|
|
346
|
-
id: string;
|
|
347
|
-
prefix: string;
|
|
348
|
-
|
|
349
|
-
get context(): ScramjetGlobal.ScramjetContext {
|
|
350
|
-
let sjcfg = {
|
|
351
|
-
...$scramjet.defaultConfig,
|
|
352
|
-
...cfg,
|
|
353
|
-
};
|
|
354
|
-
return {
|
|
355
|
-
cookieJar,
|
|
356
|
-
prefix: new URL(this.prefix, location.href),
|
|
357
|
-
config: sjcfg,
|
|
358
|
-
interface: {
|
|
359
|
-
getInjectScripts: yieldGetInjectScripts(
|
|
360
|
-
this.controller.cookieJar,
|
|
361
|
-
config,
|
|
362
|
-
{ ...$scramjet.defaultConfig, ...cfg },
|
|
363
|
-
new URL(this.prefix, location.href)
|
|
364
|
-
),
|
|
365
|
-
getWorkerInjectScripts: (meta, type, script) => {
|
|
366
|
-
let str = "";
|
|
367
|
-
|
|
368
|
-
str += script(config.scramjetPath);
|
|
369
|
-
str += script(this.prefix + config.virtualWasmPath);
|
|
370
|
-
str += `
|
|
371
|
-
(()=>{
|
|
372
|
-
const { ScramjetClient, CookieJar, setWasm } = $scramjet;
|
|
373
|
-
|
|
374
|
-
setWasm(Uint8Array.from(atob(self.WASM), (c) => c.charCodeAt(0)));
|
|
375
|
-
delete self.WASM;
|
|
376
|
-
|
|
377
|
-
const sjconfig = ${JSON.stringify(sjcfg)};
|
|
378
|
-
const prefix = new URL("${this.prefix}", location.href);
|
|
379
|
-
|
|
380
|
-
const context = {
|
|
381
|
-
interface: {
|
|
382
|
-
codecEncode: ${codecEncode.toString()},
|
|
383
|
-
codecDecode: ${codecDecode.toString()},
|
|
384
|
-
},
|
|
385
|
-
prefix,
|
|
386
|
-
config: sjconfig
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
const client = new ScramjetClient(globalThis, {
|
|
390
|
-
context,
|
|
391
|
-
transport: null,
|
|
392
|
-
shouldPassthroughWebsocket: (url) => {
|
|
393
|
-
return url === "wss://anura.pro/";
|
|
394
|
-
}
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
client.hook();
|
|
398
|
-
})();
|
|
399
|
-
`;
|
|
400
|
-
|
|
401
|
-
return str;
|
|
402
|
-
},
|
|
403
|
-
codecEncode,
|
|
404
|
-
codecDecode,
|
|
405
|
-
},
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
constructor(
|
|
410
|
-
public controller: Controller,
|
|
411
|
-
public element: HTMLIFrameElement
|
|
412
|
-
) {
|
|
413
|
-
this.id = makeId();
|
|
414
|
-
this.prefix = this.controller.prefix + this.id + "/";
|
|
415
|
-
|
|
416
|
-
this.fetchHandler = new $scramjet.ScramjetFetchHandler({
|
|
417
|
-
crossOriginIsolated: self.crossOriginIsolated,
|
|
418
|
-
context: this.context,
|
|
419
|
-
transport: controller.transport,
|
|
420
|
-
async sendSetCookie(url, cookie) { },
|
|
421
|
-
async fetchBlobUrl(url) {
|
|
422
|
-
return BareResponse.fromNativeResponse(await fetch(url));
|
|
423
|
-
},
|
|
424
|
-
async fetchDataUrl(url) {
|
|
425
|
-
return BareResponse.fromNativeResponse(await fetch(url));
|
|
426
|
-
},
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
go(url: string) {
|
|
431
|
-
const encoded = $scramjet.rewriteUrl(url, this.context, {
|
|
432
|
-
origin: new URL(location.href),
|
|
433
|
-
base: new URL(location.href),
|
|
434
|
-
});
|
|
435
|
-
this.element.src = encoded;
|
|
436
|
-
}
|
|
437
|
-
}
|
package/src/inject.ts
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import type { CookieJar, ScramjetConfig } from "@mercuryworkshop/scramjet";
|
|
2
|
-
import * as $scramjet from "@mercuryworkshop/scramjet";
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
RawHeaders,
|
|
6
|
-
ProxyTransport,
|
|
7
|
-
TransferrableResponse,
|
|
8
|
-
} from "@mercuryworkshop/proxy-transports";
|
|
9
|
-
|
|
10
|
-
import { RpcHelper } from "@mercuryworkshop/rpc";
|
|
11
|
-
import type {
|
|
12
|
-
ControllerToTransport,
|
|
13
|
-
TransportToController,
|
|
14
|
-
WebSocketData,
|
|
15
|
-
WebSocketMessage,
|
|
16
|
-
} from "./types";
|
|
17
|
-
|
|
18
|
-
const MessagePort_postMessage = MessagePort.prototype.postMessage;
|
|
19
|
-
const postMessage = (
|
|
20
|
-
port: MessagePort,
|
|
21
|
-
data: any,
|
|
22
|
-
transfer?: Transferable[]
|
|
23
|
-
) => {
|
|
24
|
-
MessagePort_postMessage.call(port, data, transfer as any);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
class RemoteTransport implements ProxyTransport {
|
|
28
|
-
private readyResolve!: () => void;
|
|
29
|
-
private readyPromise: Promise<void> = new Promise((resolve) => {
|
|
30
|
-
this.readyResolve = resolve;
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
public ready = false;
|
|
34
|
-
async init() {
|
|
35
|
-
await this.readyPromise;
|
|
36
|
-
this.ready = true;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
private rpc: RpcHelper<ControllerToTransport, TransportToController>;
|
|
40
|
-
constructor(public port: MessagePort) {
|
|
41
|
-
this.rpc = new RpcHelper<ControllerToTransport, TransportToController>(
|
|
42
|
-
{
|
|
43
|
-
ready: async () => {
|
|
44
|
-
this.readyResolve();
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
"transport",
|
|
48
|
-
(data, transfer) => {
|
|
49
|
-
postMessage(port, data, transfer);
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
port.onmessageerror = (ev) => {
|
|
53
|
-
console.error("onmessageerror (this should never happen!)", ev);
|
|
54
|
-
};
|
|
55
|
-
port.onmessage = (ev) => {
|
|
56
|
-
this.rpc.recieve(ev.data);
|
|
57
|
-
};
|
|
58
|
-
port.start();
|
|
59
|
-
}
|
|
60
|
-
connect(
|
|
61
|
-
url: URL,
|
|
62
|
-
protocols: string[],
|
|
63
|
-
requestHeaders: RawHeaders,
|
|
64
|
-
onopen: (protocol: string, extensions: string) => void,
|
|
65
|
-
onmessage: (data: Blob | ArrayBuffer | string) => void,
|
|
66
|
-
onclose: (code: number, reason: string) => void,
|
|
67
|
-
onerror: (error: string) => void
|
|
68
|
-
): [
|
|
69
|
-
(data: Blob | ArrayBuffer | string) => void,
|
|
70
|
-
(code: number, reason: string) => void,
|
|
71
|
-
] {
|
|
72
|
-
const channel = new MessageChannel();
|
|
73
|
-
let port = channel.port1;
|
|
74
|
-
console.warn("connecting");
|
|
75
|
-
this.rpc
|
|
76
|
-
.call(
|
|
77
|
-
"connect",
|
|
78
|
-
{
|
|
79
|
-
url: url.href,
|
|
80
|
-
protocols,
|
|
81
|
-
requestHeaders,
|
|
82
|
-
port: channel.port2,
|
|
83
|
-
},
|
|
84
|
-
[channel.port2]
|
|
85
|
-
)
|
|
86
|
-
.then((response) => {
|
|
87
|
-
console.log(response);
|
|
88
|
-
if (response.result === "success") {
|
|
89
|
-
onopen(response.protocol, response.extensions);
|
|
90
|
-
} else {
|
|
91
|
-
onerror(response.error);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
port.onmessage = (ev) => {
|
|
95
|
-
const message = ev.data as WebSocketMessage;
|
|
96
|
-
if (message.type === "data") {
|
|
97
|
-
onmessage(message.data);
|
|
98
|
-
} else if (message.type === "close") {
|
|
99
|
-
onclose(message.code, message.reason);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
port.onmessageerror = (ev) => {
|
|
103
|
-
console.error("onmessageerror (this should never happen!)", ev);
|
|
104
|
-
onerror("Message error in transport port");
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
return [
|
|
108
|
-
(data) => {
|
|
109
|
-
postMessage(
|
|
110
|
-
port,
|
|
111
|
-
{
|
|
112
|
-
type: "data",
|
|
113
|
-
data: data,
|
|
114
|
-
},
|
|
115
|
-
data instanceof ArrayBuffer ? [data] : []
|
|
116
|
-
);
|
|
117
|
-
},
|
|
118
|
-
(code) => {
|
|
119
|
-
postMessage(port, {
|
|
120
|
-
type: "close",
|
|
121
|
-
code: code,
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async request(
|
|
128
|
-
remote: URL,
|
|
129
|
-
method: string,
|
|
130
|
-
body: BodyInit | null,
|
|
131
|
-
headers: RawHeaders,
|
|
132
|
-
signal: AbortSignal | undefined
|
|
133
|
-
): Promise<TransferrableResponse> {
|
|
134
|
-
return await this.rpc.call("request", {
|
|
135
|
-
remote: remote.href,
|
|
136
|
-
method,
|
|
137
|
-
body,
|
|
138
|
-
headers,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
meta() {
|
|
143
|
-
return {};
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const sw = navigator.serviceWorker.controller;
|
|
148
|
-
const { SCRAMJETCLIENT, ScramjetClient, CookieJar, setWasm } = $scramjet;
|
|
149
|
-
|
|
150
|
-
type Config = any;
|
|
151
|
-
type Init = {
|
|
152
|
-
config: Config;
|
|
153
|
-
sjconfig: ScramjetConfig;
|
|
154
|
-
cookies: string;
|
|
155
|
-
prefix: URL;
|
|
156
|
-
yieldGetInjectScripts: (
|
|
157
|
-
cookieJar: CookieJar,
|
|
158
|
-
config: Config,
|
|
159
|
-
sjconfig: ScramjetConfig,
|
|
160
|
-
prefix: URL
|
|
161
|
-
) => any;
|
|
162
|
-
codecEncode: (input: string) => string;
|
|
163
|
-
codecDecode: (input: string) => string;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export function load({
|
|
167
|
-
config,
|
|
168
|
-
sjconfig,
|
|
169
|
-
cookies,
|
|
170
|
-
prefix,
|
|
171
|
-
yieldGetInjectScripts,
|
|
172
|
-
codecEncode,
|
|
173
|
-
codecDecode,
|
|
174
|
-
}: Init) {
|
|
175
|
-
let client;
|
|
176
|
-
if (SCRAMJETCLIENT in globalThis) {
|
|
177
|
-
client = globalThis[SCRAMJETCLIENT];
|
|
178
|
-
} else {
|
|
179
|
-
setWasm(Uint8Array.from(atob(self.WASM), (c) => c.charCodeAt(0)));
|
|
180
|
-
delete self.WASM;
|
|
181
|
-
|
|
182
|
-
const channel = new MessageChannel();
|
|
183
|
-
const transport = new RemoteTransport(channel.port1);
|
|
184
|
-
sw?.postMessage(
|
|
185
|
-
{
|
|
186
|
-
$sw$initRemoteTransport: {
|
|
187
|
-
port: channel.port2,
|
|
188
|
-
prefix: prefix.href,
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
[channel.port2]
|
|
192
|
-
);
|
|
193
|
-
|
|
194
|
-
const cookieJar = new CookieJar();
|
|
195
|
-
cookieJar.load(cookies);
|
|
196
|
-
|
|
197
|
-
const context = {
|
|
198
|
-
interface: {
|
|
199
|
-
getInjectScripts: yieldGetInjectScripts(
|
|
200
|
-
cookieJar,
|
|
201
|
-
config,
|
|
202
|
-
sjconfig,
|
|
203
|
-
prefix
|
|
204
|
-
),
|
|
205
|
-
codecEncode,
|
|
206
|
-
codecDecode,
|
|
207
|
-
},
|
|
208
|
-
prefix,
|
|
209
|
-
cookieJar,
|
|
210
|
-
config: sjconfig,
|
|
211
|
-
};
|
|
212
|
-
function createFrameId() {
|
|
213
|
-
return `${Array(8)
|
|
214
|
-
.fill(0)
|
|
215
|
-
.map(() => Math.floor(Math.random() * 36).toString(36))
|
|
216
|
-
.join("")}`;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const frame = globalThis.frameElement as HTMLIFrameElement | null;
|
|
220
|
-
if (frame && !frame.name) {
|
|
221
|
-
frame.name = createFrameId();
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
client = new ScramjetClient(globalThis, {
|
|
225
|
-
context,
|
|
226
|
-
transport,
|
|
227
|
-
sendSetCookie: async (url, cookie) => {
|
|
228
|
-
// sw.postMessage({
|
|
229
|
-
// $controller$setCookie: {
|
|
230
|
-
// url,
|
|
231
|
-
// cookie
|
|
232
|
-
// }
|
|
233
|
-
// });
|
|
234
|
-
},
|
|
235
|
-
shouldPassthroughWebsocket: (url) => {
|
|
236
|
-
return url === "wss://anura.pro/";
|
|
237
|
-
},
|
|
238
|
-
shouldBlockMessageEvent(i) {
|
|
239
|
-
return false;
|
|
240
|
-
},
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
client.hook();
|
|
244
|
-
}
|
|
245
|
-
}
|
package/src/sw.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
declare var clients: Clients;
|
|
2
|
-
import { RpcHelper } from "@mercuryworkshop/rpc";
|
|
3
|
-
import type { Controllerbound, SWbound } from "./types";
|
|
4
|
-
import type { RawHeaders } from "@mercuryworkshop/proxy-transports";
|
|
5
|
-
import { ScramjetHeaders } from "@mercuryworkshop/scramjet";
|
|
6
|
-
|
|
7
|
-
function makeId(): string {
|
|
8
|
-
return Math.random().toString(36).substring(2, 10);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
let cookieResolvers: Record<string, (value: void) => void> = {};
|
|
12
|
-
addEventListener("message", (e) => {
|
|
13
|
-
if (!e.data) return;
|
|
14
|
-
if (typeof e.data != "object") return;
|
|
15
|
-
if (e.data.$sw$setCookieDone && typeof e.data.$sw$setCookieDone == "object") {
|
|
16
|
-
const done = e.data.$sw$setCookieDone;
|
|
17
|
-
|
|
18
|
-
const resolver = cookieResolvers[done.id];
|
|
19
|
-
if (resolver) {
|
|
20
|
-
resolver();
|
|
21
|
-
delete cookieResolvers[done.id];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
e.data.$sw$initRemoteTransport &&
|
|
27
|
-
typeof e.data.$sw$initRemoteTransport == "object"
|
|
28
|
-
) {
|
|
29
|
-
const { port, prefix } = e.data.$sw$initRemoteTransport;
|
|
30
|
-
|
|
31
|
-
const relevantcontroller = tabs.find((tab) =>
|
|
32
|
-
new URL(prefix).pathname.startsWith(tab.prefix)
|
|
33
|
-
);
|
|
34
|
-
if (!relevantcontroller) {
|
|
35
|
-
console.error("No relevant controller found for transport init");
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
relevantcontroller.rpc.call("initRemoteTransport", port, [port]);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
class ControllerReference {
|
|
43
|
-
rpc: RpcHelper<SWbound, Controllerbound>;
|
|
44
|
-
|
|
45
|
-
constructor(
|
|
46
|
-
public prefix: string,
|
|
47
|
-
public id: string,
|
|
48
|
-
port: MessagePort
|
|
49
|
-
) {
|
|
50
|
-
this.rpc = new RpcHelper(
|
|
51
|
-
{
|
|
52
|
-
sendSetCookie: async ({ url, cookie }) => {
|
|
53
|
-
let clients = await self.clients.matchAll();
|
|
54
|
-
let promises = [];
|
|
55
|
-
|
|
56
|
-
for (const client of clients) {
|
|
57
|
-
let id = makeId();
|
|
58
|
-
client.postMessage({
|
|
59
|
-
$controller$setCookie: {
|
|
60
|
-
url,
|
|
61
|
-
cookie,
|
|
62
|
-
id,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
promises.push(
|
|
66
|
-
new Promise<void>((resolve) => {
|
|
67
|
-
cookieResolvers[id] = resolve;
|
|
68
|
-
})
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
await Promise.race([
|
|
72
|
-
new Promise<void>((resolve) =>
|
|
73
|
-
setTimeout(() => {
|
|
74
|
-
console.error(
|
|
75
|
-
"timed out waiting for set cookie response (deadlock?)"
|
|
76
|
-
);
|
|
77
|
-
resolve();
|
|
78
|
-
}, 1000)
|
|
79
|
-
),
|
|
80
|
-
promises,
|
|
81
|
-
]);
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
"tabchannel-" + id,
|
|
85
|
-
(data, transfer) => {
|
|
86
|
-
port.postMessage(data, transfer);
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
port.addEventListener("message", (e) => {
|
|
90
|
-
this.rpc.recieve(e.data);
|
|
91
|
-
});
|
|
92
|
-
port.onmessageerror = console.error;
|
|
93
|
-
|
|
94
|
-
this.rpc.call("ready", null);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const tabs: ControllerReference[] = [];
|
|
99
|
-
|
|
100
|
-
addEventListener("message", (e) => {
|
|
101
|
-
if (!e.data) return;
|
|
102
|
-
if (typeof e.data != "object") return;
|
|
103
|
-
if (!e.data.$controller$init) return;
|
|
104
|
-
if (typeof e.data.$controller$init != "object") return;
|
|
105
|
-
const init = e.data.$controller$init;
|
|
106
|
-
|
|
107
|
-
tabs.push(new ControllerReference(init.prefix, init.id, e.ports[0]));
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
export function shouldRoute(event: FetchEvent): boolean {
|
|
111
|
-
const url = new URL(event.request.url);
|
|
112
|
-
const tab = tabs.find((tab) => url.pathname.startsWith(tab.prefix));
|
|
113
|
-
return tab !== undefined;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export async function route(event: FetchEvent): Promise<Response> {
|
|
117
|
-
try {
|
|
118
|
-
const url = new URL(event.request.url);
|
|
119
|
-
const tab = tabs.find((tab) => url.pathname.startsWith(tab.prefix))!;
|
|
120
|
-
const client = await clients.get(event.clientId);
|
|
121
|
-
|
|
122
|
-
const rawheaders: RawHeaders = [...event.request.headers];
|
|
123
|
-
|
|
124
|
-
const response = await tab.rpc.call(
|
|
125
|
-
"request",
|
|
126
|
-
{
|
|
127
|
-
rawUrl: event.request.url,
|
|
128
|
-
destination: event.request.destination,
|
|
129
|
-
mode: event.request.mode,
|
|
130
|
-
referrer: event.request.referrer,
|
|
131
|
-
method: event.request.method,
|
|
132
|
-
body: event.request.body,
|
|
133
|
-
cache: event.request.cache,
|
|
134
|
-
forceCrossOriginIsolated: false,
|
|
135
|
-
initialHeaders: rawheaders,
|
|
136
|
-
rawClientUrl: client ? client.url : undefined,
|
|
137
|
-
},
|
|
138
|
-
event.request.body instanceof ReadableStream ||
|
|
139
|
-
// @ts-expect-error the types for fetchevent are messed up
|
|
140
|
-
event.request.body instanceof ArrayBuffer
|
|
141
|
-
? [event.request.body]
|
|
142
|
-
: undefined
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
return new Response(response.body, {
|
|
146
|
-
status: response.status,
|
|
147
|
-
statusText: response.statusText,
|
|
148
|
-
headers: response.headers,
|
|
149
|
-
});
|
|
150
|
-
} catch (e) {
|
|
151
|
-
console.error("Service Worker error:", e);
|
|
152
|
-
return new Response(
|
|
153
|
-
"Internal Service Worker Error: " + (e as Error).message,
|
|
154
|
-
{
|
|
155
|
-
status: 500,
|
|
156
|
-
}
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
}
|
package/src/types.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import type { RawHeaders } from "@mercuryworkshop/proxy-transports";
|
|
2
|
-
|
|
3
|
-
export type BodyType =
|
|
4
|
-
| string
|
|
5
|
-
| ArrayBuffer
|
|
6
|
-
| Blob
|
|
7
|
-
| ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
8
|
-
|
|
9
|
-
export type TransferRequest = {
|
|
10
|
-
rawUrl: string;
|
|
11
|
-
destination: RequestDestination;
|
|
12
|
-
mode: RequestMode;
|
|
13
|
-
referrer: string;
|
|
14
|
-
method: string;
|
|
15
|
-
body: BodyType | null;
|
|
16
|
-
cache: RequestCache;
|
|
17
|
-
forceCrossOriginIsolated: boolean;
|
|
18
|
-
initialHeaders: RawHeaders;
|
|
19
|
-
rawClientUrl?: string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type TransferResponse = {
|
|
23
|
-
body: BodyType;
|
|
24
|
-
headers: RawHeaders;
|
|
25
|
-
status: number;
|
|
26
|
-
statusText: string;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type Controllerbound = {
|
|
30
|
-
ready: [];
|
|
31
|
-
request: [TransferRequest, TransferResponse];
|
|
32
|
-
sendSetCookie: [
|
|
33
|
-
{
|
|
34
|
-
url: string;
|
|
35
|
-
cookie: string;
|
|
36
|
-
},
|
|
37
|
-
];
|
|
38
|
-
initRemoteTransport: [MessagePort];
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export type SWbound = {
|
|
42
|
-
sendSetCookie: [
|
|
43
|
-
{
|
|
44
|
-
url: string;
|
|
45
|
-
cookie: string;
|
|
46
|
-
},
|
|
47
|
-
];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export type TransportToController = {
|
|
51
|
-
request: [
|
|
52
|
-
{
|
|
53
|
-
remote: string;
|
|
54
|
-
method: string;
|
|
55
|
-
body: BodyInit | null;
|
|
56
|
-
headers: RawHeaders;
|
|
57
|
-
// signal: AbortSignal | undefined
|
|
58
|
-
},
|
|
59
|
-
TransferrableResponse,
|
|
60
|
-
];
|
|
61
|
-
connect: [
|
|
62
|
-
{
|
|
63
|
-
url: string;
|
|
64
|
-
protocols: string[];
|
|
65
|
-
requestHeaders: RawHeaders;
|
|
66
|
-
port: MessagePort;
|
|
67
|
-
},
|
|
68
|
-
(
|
|
69
|
-
| {
|
|
70
|
-
result: "success";
|
|
71
|
-
protocol: string;
|
|
72
|
-
extensions: string;
|
|
73
|
-
}
|
|
74
|
-
| {
|
|
75
|
-
result: "failure";
|
|
76
|
-
error: string;
|
|
77
|
-
}
|
|
78
|
-
),
|
|
79
|
-
];
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export type ControllerToTransport = {
|
|
83
|
-
ready: [];
|
|
84
|
-
};
|
|
85
|
-
export type WebSocketData = string | ArrayBuffer | Blob;
|
|
86
|
-
export type WebSocketMessage =
|
|
87
|
-
| {
|
|
88
|
-
type: "data";
|
|
89
|
-
data: WebSocketData;
|
|
90
|
-
}
|
|
91
|
-
| {
|
|
92
|
-
type: "close";
|
|
93
|
-
code: number;
|
|
94
|
-
reason: string;
|
|
95
|
-
};
|
package/src/typesEntry.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"useDefineForClassFields": true,
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"lib": ["ES2022", "webworker", "DOM", "DOM.Iterable"],
|
|
7
|
-
"types": [],
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
/* Bundler mode */
|
|
10
|
-
"moduleResolution": "bundler",
|
|
11
|
-
"allowImportingTsExtensions": true,
|
|
12
|
-
"verbatimModuleSyntax": true,
|
|
13
|
-
"moduleDetection": "force",
|
|
14
|
-
"noEmit": true,
|
|
15
|
-
/* Linting */
|
|
16
|
-
"strict": true,
|
|
17
|
-
"noUnusedLocals": true,
|
|
18
|
-
"noUnusedParameters": false,
|
|
19
|
-
"erasableSyntaxOnly": false,
|
|
20
|
-
"noFallthroughCasesInSwitch": true,
|
|
21
|
-
"noUncheckedSideEffectImports": true
|
|
22
|
-
},
|
|
23
|
-
"include": ["src"]
|
|
24
|
-
}
|
package/tsconfig.types.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"emitDeclarationOnly": true,
|
|
6
|
-
"declarationDir": "./dist/types",
|
|
7
|
-
"removeComments": false,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
"noEmitOnError": false,
|
|
10
|
-
"noEmit": false,
|
|
11
|
-
"strict": false,
|
|
12
|
-
"noUnusedLocals": false,
|
|
13
|
-
"noUnusedParameters": false
|
|
14
|
-
},
|
|
15
|
-
"include": ["src"]
|
|
16
|
-
}
|