@mercuryworkshop/epoxy-transport 2.1.28 → 3.0.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/.github/workflows/main.yml +96 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +679 -580
- package/dist/index.mjs +678 -579
- package/esbuild.bundle.mjs +19 -11
- package/package.json +32 -34
- package/src/main.ts +82 -31
- package/tsconfig.json +2 -2
package/esbuild.bundle.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { dtsPlugin } from "esbuild-plugin-d.ts";
|
|
2
2
|
import { build } from "esbuild";
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import fs, { readFileSync } from 'node:fs'
|
|
@@ -89,24 +89,32 @@ let makeAllPackagesExternalPlugin = {
|
|
|
89
89
|
},
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
|
|
92
93
|
build({
|
|
93
94
|
bundle: true,
|
|
94
95
|
format: "esm",
|
|
95
96
|
entryPoints: [`./src/main.ts`],
|
|
96
97
|
outfile: `./dist/index.mjs`,
|
|
97
98
|
plugins: [wasmPlugin],
|
|
98
|
-
external: ["fs", "
|
|
99
|
+
external: ["fs", "path"],
|
|
100
|
+
logLevel: "info",
|
|
99
101
|
})
|
|
100
102
|
|
|
101
|
-
build({
|
|
103
|
+
await build({
|
|
102
104
|
bundle: true,
|
|
103
105
|
format: "cjs",
|
|
104
|
-
entryPoints:
|
|
105
|
-
|
|
106
|
-
external: ["fs", "
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
entryPoints: { index: './src/main.ts' },
|
|
107
|
+
outdir: `./dist/`,
|
|
108
|
+
external: ["fs", "path"],
|
|
109
|
+
logLevel: "info",
|
|
110
|
+
plugins: [
|
|
111
|
+
wasmPlugin,
|
|
112
|
+
umdWrapper(umdWrapperOptions),
|
|
113
|
+
dtsPlugin({
|
|
114
|
+
outDir: `./dist/`,
|
|
115
|
+
tsconfig: "tsconfig.json"
|
|
116
|
+
})
|
|
117
|
+
]
|
|
112
118
|
})
|
|
119
|
+
|
|
120
|
+
fs.renameSync('./dist/main.d.ts', './dist/index.d.ts');
|
package/package.json
CHANGED
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
}
|
|
2
|
+
"name": "@mercuryworkshop/epoxy-transport",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "a bare transport that implements end-to-end encryption with epoxy-tls and wisp",
|
|
5
|
+
"main": "./dist/index.mjs",
|
|
6
|
+
"keywords": [],
|
|
7
|
+
"author": "",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"license": "AGPL-3.0-only",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/MercuryWorkshop/EpoxyTransport.git"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@mercuryworkshop/epoxy-tls": "2.1.19-1"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@mercuryworkshop/proxy-transports": "^1.0.2",
|
|
19
|
+
"esbuild": "^0.25.8",
|
|
20
|
+
"esbuild-plugin-d.ts": "^1.3.1",
|
|
21
|
+
"esbuild-plugin-umd-wrapper": "^3.0.0"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": "./dist/index.mjs",
|
|
26
|
+
"require": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "node esbuild.bundle.mjs"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/main.ts
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
RawHeaders,
|
|
3
|
+
TransferrableResponse,
|
|
4
|
+
ProxyTransport,
|
|
5
|
+
} from "@mercuryworkshop/proxy-transports";
|
|
6
|
+
import initEpoxy, {
|
|
7
|
+
EpoxyClient,
|
|
8
|
+
EpoxyClientOptions,
|
|
9
|
+
EpoxyHandlers,
|
|
10
|
+
info as epoxyInfo,
|
|
11
|
+
} from "@mercuryworkshop/epoxy-tls";
|
|
3
12
|
|
|
4
13
|
export { epoxyInfo };
|
|
5
14
|
|
|
6
15
|
export type EpoxyOptions = {
|
|
7
|
-
wisp_v2?: boolean
|
|
8
|
-
udp_extension_required?: boolean
|
|
16
|
+
wisp_v2?: boolean;
|
|
17
|
+
udp_extension_required?: boolean;
|
|
9
18
|
|
|
10
|
-
title_case_headers?: boolean
|
|
11
|
-
ws_title_case_headers?: boolean
|
|
19
|
+
title_case_headers?: boolean;
|
|
20
|
+
ws_title_case_headers?: boolean;
|
|
12
21
|
|
|
13
|
-
wisp_ws_protocols?: string[]
|
|
22
|
+
wisp_ws_protocols?: string[];
|
|
14
23
|
|
|
15
|
-
redirect_limit?: number
|
|
16
|
-
header_limit?: number
|
|
17
|
-
buffer_size?: number
|
|
18
|
-
}
|
|
24
|
+
redirect_limit?: number;
|
|
25
|
+
header_limit?: number;
|
|
26
|
+
buffer_size?: number;
|
|
27
|
+
};
|
|
19
28
|
const opts = [
|
|
20
29
|
"wisp_v2",
|
|
21
30
|
"udp_extension_required",
|
|
@@ -24,10 +33,10 @@ const opts = [
|
|
|
24
33
|
"wisp_ws_protocols",
|
|
25
34
|
"redirect_limit",
|
|
26
35
|
"header_limit",
|
|
27
|
-
"buffer_size"
|
|
36
|
+
"buffer_size",
|
|
28
37
|
];
|
|
29
38
|
|
|
30
|
-
export default class EpoxyTransport implements
|
|
39
|
+
export default class EpoxyTransport implements ProxyTransport {
|
|
31
40
|
ready = false;
|
|
32
41
|
|
|
33
42
|
client_version: typeof epoxyInfo;
|
|
@@ -52,29 +61,54 @@ export default class EpoxyTransport implements BareTransport {
|
|
|
52
61
|
|
|
53
62
|
let options = new EpoxyClientOptions();
|
|
54
63
|
options.user_agent = navigator.userAgent;
|
|
55
|
-
opts.forEach(x => this.setopt(options, x))
|
|
64
|
+
opts.forEach((x) => this.setopt(options, x));
|
|
56
65
|
this.client = new EpoxyClient(this.wisp, options);
|
|
57
66
|
|
|
58
67
|
this.ready = true;
|
|
59
68
|
}
|
|
60
69
|
|
|
61
|
-
async meta() {
|
|
70
|
+
async meta() {}
|
|
62
71
|
|
|
63
72
|
async request(
|
|
64
73
|
remote: URL,
|
|
65
74
|
method: string,
|
|
66
75
|
body: BodyInit | null,
|
|
67
|
-
headers:
|
|
76
|
+
headers: RawHeaders,
|
|
68
77
|
signal: AbortSignal | undefined
|
|
69
78
|
): Promise<TransferrableResponse> {
|
|
70
|
-
if (body instanceof Blob)
|
|
71
|
-
body = await body.arrayBuffer();
|
|
79
|
+
if (body instanceof Blob) body = await body.arrayBuffer();
|
|
72
80
|
|
|
73
81
|
try {
|
|
74
|
-
let
|
|
82
|
+
let headersObj: Record<string, string> = {};
|
|
83
|
+
for (let [key, value] of headers) {
|
|
84
|
+
if (headersObj[key]) {
|
|
85
|
+
// epoxy does not support multiple headers with the same key
|
|
86
|
+
console.warn(
|
|
87
|
+
`Duplicate header key "${key}" detected. Overwriting previous value.`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
headersObj[key] = value;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let res = await this.client.fetch(remote.href, {
|
|
94
|
+
method,
|
|
95
|
+
body,
|
|
96
|
+
headers: headersObj,
|
|
97
|
+
redirect: "manual",
|
|
98
|
+
});
|
|
99
|
+
let headersEntries: RawHeaders = [];
|
|
100
|
+
for (let [key, value] of Object.entries((res as any).rawHeaders) as any) {
|
|
101
|
+
if (Array.isArray(value)) {
|
|
102
|
+
for (let v of value) {
|
|
103
|
+
headersEntries.push([key, v]);
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
headersEntries.push([key, value]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
75
109
|
return {
|
|
76
110
|
body: res.body!,
|
|
77
|
-
headers:
|
|
111
|
+
headers: headersEntries,
|
|
78
112
|
status: res.status,
|
|
79
113
|
statusText: res.statusText,
|
|
80
114
|
};
|
|
@@ -87,24 +121,41 @@ export default class EpoxyTransport implements BareTransport {
|
|
|
87
121
|
connect(
|
|
88
122
|
url: URL,
|
|
89
123
|
protocols: string[],
|
|
90
|
-
requestHeaders:
|
|
91
|
-
onopen: (protocol: string) => void,
|
|
124
|
+
requestHeaders: RawHeaders,
|
|
125
|
+
onopen: (protocol: string, extensions: string) => void,
|
|
92
126
|
onmessage: (data: Blob | ArrayBuffer | string) => void,
|
|
93
127
|
onclose: (code: number, reason: string) => void,
|
|
94
|
-
onerror: (error: string) => void
|
|
95
|
-
): [
|
|
128
|
+
onerror: (error: string) => void
|
|
129
|
+
): [
|
|
130
|
+
(data: Blob | ArrayBuffer | string) => void,
|
|
131
|
+
(code: number, reason: string) => void,
|
|
132
|
+
] {
|
|
96
133
|
let handlers = new EpoxyHandlers(
|
|
97
|
-
|
|
98
|
-
|
|
134
|
+
// epoxy does not support getting the server selected protocol/extension
|
|
135
|
+
() => onopen("", ""),
|
|
136
|
+
// epoxy does not support getting close code/reason
|
|
137
|
+
() => onclose(1000, "Closed by remote"),
|
|
99
138
|
onerror,
|
|
100
|
-
(data: Uint8Array | string) =>
|
|
139
|
+
(data: Uint8Array | string) =>
|
|
140
|
+
//@ts-ignore
|
|
141
|
+
data instanceof Uint8Array ? onmessage(data.buffer) : onmessage(data)
|
|
101
142
|
);
|
|
102
143
|
|
|
144
|
+
let headersObj: Record<string, string> = {};
|
|
145
|
+
for (let [key, value] of requestHeaders) {
|
|
146
|
+
if (headersObj[key]) {
|
|
147
|
+
console.warn(
|
|
148
|
+
`Duplicate header key "${key}" detected. Overwriting previous value.`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
headersObj[key] = value;
|
|
152
|
+
}
|
|
153
|
+
|
|
103
154
|
let ws = this.client.connect_websocket(
|
|
104
155
|
handlers,
|
|
105
156
|
url.href,
|
|
106
157
|
protocols,
|
|
107
|
-
|
|
158
|
+
headersObj
|
|
108
159
|
);
|
|
109
160
|
|
|
110
161
|
return [
|
|
@@ -113,8 +164,8 @@ export default class EpoxyTransport implements BareTransport {
|
|
|
113
164
|
(await ws).send(data);
|
|
114
165
|
},
|
|
115
166
|
async (code, reason) => {
|
|
116
|
-
(await ws).close(code, reason || "")
|
|
117
|
-
}
|
|
118
|
-
]
|
|
167
|
+
(await ws).close(code, reason || "");
|
|
168
|
+
},
|
|
169
|
+
];
|
|
119
170
|
}
|
|
120
171
|
}
|
package/tsconfig.json
CHANGED