@fkn/lib 0.1.0 → 0.2.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/build/api.d.ts +72 -4
- package/build/dom.d.ts +1 -2
- package/build/index.cjs +1 -0
- package/build/index.d.ts +2 -2
- package/build/index.js +454 -101
- package/build/test.d.ts +0 -0
- package/build/webvpn/dgram.d.ts +64 -0
- package/build/webvpn/index.d.ts +1 -52
- package/build/webvpn/net.d.ts +134 -0
- package/build/webvpn/utils.d.ts +32 -0
- package/package.json +14 -7
- package/build/plugin/index.d.ts +0 -1
- package/build/target.d.ts +0 -6
- package/build/utils/call.d.ts +0 -3
- package/build/utils/index.d.ts +0 -1
package/build/api.d.ts
CHANGED
|
@@ -1,4 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export declare const apiPromise: Promise<{
|
|
2
|
+
readonly WEBVPN_TCP_SOCKET: ({ remoteAddress: _remoteAddress, remotePort }: {
|
|
3
|
+
remoteAddress: string;
|
|
4
|
+
remotePort: number;
|
|
5
|
+
}) => Promise<{
|
|
6
|
+
localAddress: string;
|
|
7
|
+
localFamily: "IPv4" | "IPv6";
|
|
8
|
+
localPort: number;
|
|
9
|
+
remoteAddress: string;
|
|
10
|
+
remoteFamily: "IPv4" | "IPv6";
|
|
11
|
+
remotePort: number;
|
|
12
|
+
dataReadableStream: ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
13
|
+
dataWritableStream: WritableStream<Uint8Array<ArrayBuffer>>;
|
|
14
|
+
end: () => Promise<void>;
|
|
15
|
+
destroy: () => Promise<void>;
|
|
16
|
+
destroySoon: () => Promise<void>;
|
|
17
|
+
resetAndDestroy: () => Promise<void>;
|
|
18
|
+
}>;
|
|
19
|
+
readonly WEBVPN_TCP_SOCKET_LISTENER: ({ localAddress: _localAddress, localPort, onConnection }: {
|
|
20
|
+
localAddress: string;
|
|
21
|
+
localPort: number;
|
|
22
|
+
onConnection: (connection: import('@mfkn/web/src/api/webvpn/tcp').TcpSocketResult) => void;
|
|
23
|
+
}) => Promise<{
|
|
24
|
+
localAddress: string;
|
|
25
|
+
localFamily: "IPv4" | "IPv6";
|
|
26
|
+
localPort: number;
|
|
27
|
+
close: () => Promise<void>;
|
|
28
|
+
}>;
|
|
29
|
+
readonly WEBVPN_UDP_SOCKET: ({ type, port, address }: {
|
|
30
|
+
type: "udp4" | "udp6";
|
|
31
|
+
port: number;
|
|
32
|
+
address: string;
|
|
33
|
+
}) => Promise<{
|
|
34
|
+
localAddress: string;
|
|
35
|
+
localFamily: "IPv4" | "IPv6";
|
|
36
|
+
localPort: number;
|
|
37
|
+
dataReadableStream: ReadableStream<{
|
|
38
|
+
data: ArrayBuffer;
|
|
39
|
+
size: number;
|
|
40
|
+
family: "IPv4" | "IPv6";
|
|
41
|
+
address: string;
|
|
42
|
+
port: number;
|
|
43
|
+
}>;
|
|
44
|
+
connect: ({ remoteAddress: _remoteAddress, remotePort }: {
|
|
45
|
+
remoteAddress: string;
|
|
46
|
+
remotePort: number;
|
|
47
|
+
}) => Promise<void>;
|
|
48
|
+
send: ({ message, address: _remoteAddress, port: remotePort }: {
|
|
49
|
+
message: ArrayBuffer;
|
|
50
|
+
address?: string;
|
|
51
|
+
port?: number;
|
|
52
|
+
}) => Promise<void>;
|
|
53
|
+
close: () => Promise<void>;
|
|
54
|
+
}>;
|
|
55
|
+
readonly DNS_LOOKUP: (hostname: string, options: {
|
|
56
|
+
all?: boolean;
|
|
57
|
+
family: 0 | 4 | 6;
|
|
58
|
+
}, callback: (err: Error | undefined, addresses: import('@mfkn/web/src/api/dns').AddressLookupResult | import('@mfkn/web/src/api/dns').AddressLookupResult[] | undefined) => void) => Promise<void>;
|
|
59
|
+
readonly SERVER_PROXY_FETCH: ({ input, init }: {
|
|
60
|
+
input: import('@mfkn/web/src/api/proxy/server-proxy-fetch').ProxyFetchRequestInfo;
|
|
61
|
+
init?: import('@mfkn/web/src/api/proxy/server-proxy-fetch').ProxyFetchRequestInit;
|
|
62
|
+
}) => Promise<{
|
|
63
|
+
headers: any;
|
|
64
|
+
body: ReadableStream<Uint8Array<ArrayBufferLike>> | null;
|
|
65
|
+
type: ResponseType;
|
|
66
|
+
url: string;
|
|
67
|
+
ok: boolean;
|
|
68
|
+
redirected: boolean;
|
|
69
|
+
status: number;
|
|
70
|
+
statusText: string;
|
|
71
|
+
}>;
|
|
72
|
+
}>;
|
package/build/dom.d.ts
CHANGED
package/build/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const V=require("osra"),v=require("stream"),_=require("events"),p=require("ip-address"),w="https://fkn.app",l=globalThis?.document.querySelector(`iframe[src="${w}/sandbox-api"]`),c=globalThis.document?.createElement("iframe");!l&&c&&(c.src=`${w}/sandbox-api`,c.style.display="none",document.body.appendChild(c));const P=l||c,g=P.contentWindow;if(!P.contentWindow)throw new Error("Missing iframe content window");const z=()=>new Promise((r,e)=>{V.expose({},{key:"fkn-api",local:window,remote:g}).then(r).catch(e),setTimeout(()=>{e(new Error("Timeout waiting for api to be exposed"))},50)}),S=()=>z().then(r=>r).catch(r=>{if(r.message==="Timeout waiting for api to be exposed")return S();throw r}),a=S(),C=async(r,e)=>{const t=r,o=e,{body:s,...n}=await(await a).SERVER_PROXY_FETCH({input:t,init:o});return new Response(s,{...n,headers:{...n.headers,...n.headers&&{setCookie:n.headers["set-cookie"]}}})},M=new TextEncoder;new TextDecoder;const h=r=>p.Address4.isValid(r),m=r=>p.Address6.isValid(r),b=r=>h(r)?4:m(r)?6:0,y=(...r)=>{if(typeof r[0]=="string")throw new Error("FKN WebVPN does not support IPC connections");const e=typeof r.at(-1)=="function"?r.at(-1):void 0;return r[0]&&typeof r[0]=="object"?{...r[0],callback:e}:{port:r[0]??0,host:typeof r[1]=="string"?r[1]:"localhost",callback:e}},I=(...r)=>{const e=typeof r.at(-1)=="function"?r.at(-1):void 0,t=r[0]??0,o=typeof r[1]=="string"?r[1]:"localhost";return typeof r[0]=="object"?{...r[0],address:r[0].address??o,port:r[0].port??t,callback:e}:{address:o,port:t,callback:e}},R=(...r)=>{const e=typeof r.at(-1)=="function"?r.at(-1):void 0,t=r[0];if(typeof r[2]=="number"){const o=r[1],s=r[2],n=typeof r[3]=="number"?r[3]:0,i=typeof r[4]=="string"?r[4]:"localhost";return{message:t,offset:o,length:s,port:n,address:i,callback:e}}else{const o=typeof r[1]=="number"?r[1]:0,s=typeof r[2]=="string"?r[2]:"localhost";return{message:t,offset:0,length:t.length,port:o,address:s,callback:e}}};class d extends v.Stream.Duplex{_localAddress;_remoteAddress;_webVPNTcpSocketPromise;constructor(e){if(e?.fd!==void 0)throw new Error("FKN WebVPN does not support file descriptors");super(e),e?.connection&&this.__webvpn_tcp_socket_init__(e.connection)}__webvpn_tcp_socket_init__(e){if(this._webVPNTcpSocketPromise=e.then(t=>{const o=t.dataReadableStream.getReader(),s=t.dataWritableStream.getWriter();return this._localAddress={address:t.localAddress,family:t.localFamily,port:t.localPort},this._remoteAddress={address:t.remoteAddress,family:t.remoteFamily,port:t.remotePort},{...t,reader:o,writer:s}}).catch(t=>{this.emit("error",t)}),!this._webVPNTcpSocketPromise)throw new Error("Socket not connected");return this._webVPNTcpSocketPromise.then(t=>{!t||this.emit("connect")}),this._webVPNTcpSocketPromise}_read(e){if(!this._webVPNTcpSocketPromise)throw new Error("Socket not connected");this._webVPNTcpSocketPromise.then(t=>{if(!t)throw new Error("Socket not connected");t.reader.read().then(({value:o,done:s})=>{if(s){this.push(null);return}this.push(o)}).catch(o=>{this.emit("error",o),this.destroy(o)})})}_write(e,t,o){if(!this._webVPNTcpSocketPromise)throw new Error("Socket not connected");this._webVPNTcpSocketPromise.then(s=>{if(!s)throw new Error("Socket not connected");s.writer.write(e),o&&o()})}connect(...e){const t=y(...e),o=this.__webvpn_tcp_socket_init__(a.then(s=>s.WEBVPN_TCP_SOCKET({remoteAddress:t.host,remotePort:t.port})));return t.callback&&o.then(s=>{!s||t.callback()}),this}_end(...e){return this._webVPNTcpSocketPromise?(e.length!==0&&this.write(e[0],e[1],e[2]),this._webVPNTcpSocketPromise.then(async t=>{!t||await t.end()}),this):this}_destroy(e){return this._webVPNTcpSocketPromise?(this._webVPNTcpSocketPromise.then(async t=>{!t||await t.destroy()}),this):this}destroySoon(){!this._webVPNTcpSocketPromise||this._webVPNTcpSocketPromise.then(async e=>{!e||await e.destroySoon()})}resetAndDestroy(){return this._webVPNTcpSocketPromise?(this._webVPNTcpSocketPromise.then(async e=>{!e||await e.resetAndDestroy()}),this):this}setTimeout(e,t){return this}setNoDelay(e){return this}setKeepAlive(e,t){return this}write(e,t,...o){return super.write(e,t,...o)}address(){return this._localAddress??{}}unref(){return this}ref(){return this}autoSelectFamilyAttemptedAddresses;bufferSize;bytesRead;bytesWritten;connecting;pending;get localAddress(){if(!this._localAddress)throw new Error("Socket is not connected");return this._localAddress.address}get localPort(){if(!this._localAddress)throw new Error("Socket is not connected");return this._localAddress.port}get localFamily(){if(!this._localAddress)throw new Error("Socket is not connected");return this._localAddress.family}readyState;get remoteAddress(){if(!this._remoteAddress)throw new Error("Socket is not connected");return this._remoteAddress.address}get remotePort(){if(!this._remoteAddress)throw new Error("Socket is not connected");return this._remoteAddress.port}get remoteFamily(){if(!this._remoteAddress)throw new Error("Socket is not connected");return this._remoteAddress.family}timeout}class u extends _.EventEmitter{_localAddress;_webVPNTcpSocketListenerPromise;constructor(e,t){super(e),t&&this.on("connection",t),e?.connection&&this.__webvpn_tcp_socket_listener_init__(e.connection)}__webvpn_tcp_socket_listener_init__(e){return this._webVPNTcpSocketListenerPromise=e.then(t=>(this._localAddress={address:t.localAddress,family:t.localFamily,port:t.localPort},t)).catch(t=>{this.emit("error",t)}),this._webVPNTcpSocketListenerPromise.then(t=>{!t||this.emit("listening")}),this._webVPNTcpSocketListenerPromise}listen(...e){const t=y(...e),o=this.__webvpn_tcp_socket_listener_init__(a.then(s=>s.WEBVPN_TCP_SOCKET_LISTENER({localAddress:t.host,localPort:t.port,onConnection:n=>{const i=new d({connection:Promise.resolve(n)});this.emit("connection",i)}})));return t.callback&&o.then(s=>{!s||t.callback()}),this}close(e){return this._webVPNTcpSocketListenerPromise?(this._webVPNTcpSocketListenerPromise.then(t=>{!t||(t.close(),this.emit("close"),this._localAddress=void 0,e&&e())}),this):this}address(){return this._localAddress??null}getConnections(e){throw new Error("Method not implemented.")}ref(){throw new Error("Method not implemented.")}unref(){throw new Error("Method not implemented.")}maxConnections;connections;listening;async[Symbol.asyncDispose](){}}const k=(r,e)=>new d().connect(r,e),A=(r,e)=>new d().connect(r,e),E=(r,e)=>{const t=new u(r);return e&&t.on("connection",e),t},f={Socket:d,Server:u,connect:k,createConnection:A,createServer:E,isIP:b,isIPv4:h,isIPv6:m},x=Object.freeze(Object.defineProperty({__proto__:null,Socket:d,Server:u,connect:k,createConnection:A,createServer:E,isIP:b,isIPv4:h,isIPv6:m,_default:f,default:f},Symbol.toStringTag,{value:"Module"}));class N extends _.EventEmitter{_type;_localAddress;_remoteAddress;_webVPNUdpSocketPromise;constructor(e){if(super(e),!e)throw new Error("Missing options");this._type=e.type}addMembership(e,t){}address(){if(!this._localAddress)throw new Error("EBADF");return this._localAddress}bind(...e){const t=I(...e);return this._webVPNUdpSocketPromise=a.then(o=>o.WEBVPN_UDP_SOCKET({type:this._type,address:t.address,port:t.port})).then(o=>{const s=o.dataReadableStream.getReader(),n=async()=>{const{value:i,done:T}=await s.read();T||(this.emit("message",{data:i.data,rinfo:{address:i.address,family:i.family,port:i.port,size:i.size}}),n())};return n(),this._localAddress={address:o.localAddress,family:o.localFamily,port:o.localPort},o}).catch(o=>{this.emit("error",o)}),this._webVPNUdpSocketPromise.then(o=>{!o||this.emit("listening")}),t.callback&&this._webVPNUdpSocketPromise.then(o=>{!o||t.callback()}),this}close(e){if(!this._webVPNUdpSocketPromise)throw new Error("Socket not bound");return this._webVPNUdpSocketPromise.then(async t=>{if(!t)throw new Error("Socket not bound");await t.close(),e&&e(),this.emit("close")}),this}connect(...e){if(!this._webVPNUdpSocketPromise)throw new Error("Socket not bound");this._webVPNUdpSocketPromise.then(async t=>{if(!t)throw new Error("Socket not bound");const o=e[0],s=typeof e[1]=="string"?e[1]:"localhost",n=typeof e.at(-1)=="function"?e.at(-1):void 0;await t.connect({remotePort:o,remoteAddress:s}),n&&n()})}disconnect(){if(!this._webVPNUdpSocketPromise)throw new Error("Socket not bound");this._webVPNUdpSocketPromise.then(async e=>{if(!e)throw new Error("Socket not bound");await e.connect({remotePort:0,remoteAddress:this._type==="udp4"?"0.0.0.0":"::"})})}dropMembership(e,t){}getRecvBufferSize(){return 0}getSendBufferSize(){return 0}getSendQueueSize(){return 0}getSendQueueCount(){return 0}ref(){return this}remoteAddress(){if(!this._remoteAddress)throw new Error("ERR_SOCKET_DGRAM_NOT_CONNECTED");return{address:this._remoteAddress.address,family:this._remoteAddress.family,port:this._remoteAddress.port}}send(...e){this._webVPNUdpSocketPromise||this.bind();const t=R(...e);if(!this._webVPNUdpSocketPromise)throw new Error("Socket not bound");this._webVPNUdpSocketPromise.then(o=>{if(!o)throw new Error("Socket not bound");const s=typeof t.message=="string"?M.encode(t.message):t.message;o.send({...t,message:s.buffer})})}setBroadcast(e){}setMulticastInterface(e){}setMulticastLoopback(e){return!0}setMulticastTTL(e){return e}setRecvBufferSize(e){}setSendBufferSize(e){}setTTL(e){return e}unref(){return this}addSourceSpecificMembership(e,t,o){}dropSourceSpecificMembership(e,t,o){}async[Symbol.asyncDispose](){await new Promise(e=>{this.close(e)})}}const D=(r,e)=>{const t=new N(typeof r=="string"?{type:r}:r);return e&&t.on("message",e),t},U=Object.freeze(Object.defineProperty({__proto__:null,Socket:N,createSocket:D},Symbol.toStringTag,{value:"Module"}));exports.dgram=U;exports.net=x;exports.serverProxyFetch=C;
|
package/build/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { serverProxyFetch } from './proxy';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export * as net from './webvpn/net';
|
|
3
|
+
export * as dgram from './webvpn/dgram';
|
package/build/index.js
CHANGED
|
@@ -1,127 +1,480 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const t = setInterval(
|
|
21
|
-
() => g(l, { key: "fkn-sandbox" })("APP_READY", {}).then(() => {
|
|
22
|
-
m(l), clearInterval(t);
|
|
23
|
-
}).catch(() => {
|
|
24
|
-
console.warn("Failed to connect to sandbox, trying again in 10ms");
|
|
25
|
-
}),
|
|
26
|
-
10
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
const _ = (t, e) => u().then(
|
|
30
|
-
(a) => g(a, { key: "fkn-sandbox-api" })(t, e)
|
|
31
|
-
), y = async (t, e) => {
|
|
32
|
-
const a = t, s = e, { body: I, ...r } = await _("SERVER_PROXY_FETCH", { input: a, init: s });
|
|
1
|
+
import { expose as T } from "osra";
|
|
2
|
+
import { Stream as V } from "stream";
|
|
3
|
+
import { EventEmitter as p } from "events";
|
|
4
|
+
import { Address4 as g, Address6 as v } from "ip-address";
|
|
5
|
+
const _ = "https://fkn.app", l = globalThis?.document.querySelector(`iframe[src="${_}/sandbox-api"]`), c = globalThis.document?.createElement("iframe");
|
|
6
|
+
!l && c && (c.src = `${_}/sandbox-api`, c.style.display = "none", document.body.appendChild(c));
|
|
7
|
+
const w = l || c, z = w.contentWindow;
|
|
8
|
+
if (!w.contentWindow)
|
|
9
|
+
throw new Error("Missing iframe content window");
|
|
10
|
+
const C = () => new Promise((r, e) => {
|
|
11
|
+
T({}, { key: "fkn-api", local: window, remote: z }).then(r).catch(e), setTimeout(() => {
|
|
12
|
+
e(new Error("Timeout waiting for api to be exposed"));
|
|
13
|
+
}, 50);
|
|
14
|
+
}), P = () => C().then((r) => r).catch((r) => {
|
|
15
|
+
if (r.message === "Timeout waiting for api to be exposed")
|
|
16
|
+
return P();
|
|
17
|
+
throw r;
|
|
18
|
+
}), a = P(), W = async (r, e) => {
|
|
19
|
+
const t = r, o = e, { body: s, ...n } = await (await a).SERVER_PROXY_FETCH({ input: t, init: o });
|
|
33
20
|
return new Response(
|
|
34
|
-
|
|
21
|
+
s,
|
|
35
22
|
{
|
|
36
|
-
...
|
|
23
|
+
...n,
|
|
37
24
|
headers: {
|
|
38
|
-
...
|
|
39
|
-
...
|
|
40
|
-
setCookie:
|
|
25
|
+
...n.headers,
|
|
26
|
+
...n.headers && {
|
|
27
|
+
setCookie: n.headers["set-cookie"]
|
|
41
28
|
}
|
|
42
29
|
}
|
|
43
30
|
}
|
|
44
31
|
);
|
|
32
|
+
}, I = new TextEncoder();
|
|
33
|
+
new TextDecoder();
|
|
34
|
+
const h = (r) => g.isValid(r), m = (r) => v.isValid(r), S = (r) => h(r) ? 4 : m(r) ? 6 : 0, b = (...r) => {
|
|
35
|
+
if (typeof r[0] == "string")
|
|
36
|
+
throw new Error("FKN WebVPN does not support IPC connections");
|
|
37
|
+
const e = typeof r.at(-1) == "function" ? r.at(-1) : void 0;
|
|
38
|
+
return r[0] && typeof r[0] == "object" ? {
|
|
39
|
+
...r[0],
|
|
40
|
+
callback: e
|
|
41
|
+
} : {
|
|
42
|
+
port: r[0] ?? 0,
|
|
43
|
+
host: typeof r[1] == "string" ? r[1] : "localhost",
|
|
44
|
+
callback: e
|
|
45
|
+
};
|
|
46
|
+
}, R = (...r) => {
|
|
47
|
+
const e = typeof r.at(-1) == "function" ? r.at(-1) : void 0, t = r[0] ?? 0, o = typeof r[1] == "string" ? r[1] : "localhost";
|
|
48
|
+
return typeof r[0] == "object" ? {
|
|
49
|
+
...r[0],
|
|
50
|
+
address: r[0].address ?? o,
|
|
51
|
+
port: r[0].port ?? t,
|
|
52
|
+
callback: e
|
|
53
|
+
} : {
|
|
54
|
+
address: o,
|
|
55
|
+
port: t,
|
|
56
|
+
callback: e
|
|
57
|
+
};
|
|
58
|
+
}, x = (...r) => {
|
|
59
|
+
const e = typeof r.at(-1) == "function" ? r.at(-1) : void 0, t = r[0];
|
|
60
|
+
if (typeof r[2] == "number") {
|
|
61
|
+
const o = r[1], s = r[2], n = typeof r[3] == "number" ? r[3] : 0, i = typeof r[4] == "string" ? r[4] : "localhost";
|
|
62
|
+
return {
|
|
63
|
+
message: t,
|
|
64
|
+
offset: o,
|
|
65
|
+
length: s,
|
|
66
|
+
port: n,
|
|
67
|
+
address: i,
|
|
68
|
+
callback: e
|
|
69
|
+
};
|
|
70
|
+
} else {
|
|
71
|
+
const o = typeof r[1] == "number" ? r[1] : 0, s = typeof r[2] == "string" ? r[2] : "localhost";
|
|
72
|
+
return {
|
|
73
|
+
message: t,
|
|
74
|
+
offset: 0,
|
|
75
|
+
length: t.length,
|
|
76
|
+
port: o,
|
|
77
|
+
address: s,
|
|
78
|
+
callback: e
|
|
79
|
+
};
|
|
80
|
+
}
|
|
45
81
|
};
|
|
46
|
-
class
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
constructor() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
82
|
+
class d extends V.Duplex {
|
|
83
|
+
_localAddress;
|
|
84
|
+
_remoteAddress;
|
|
85
|
+
_webVPNTcpSocketPromise;
|
|
86
|
+
constructor(e) {
|
|
87
|
+
if (e?.fd !== void 0)
|
|
88
|
+
throw new Error("FKN WebVPN does not support file descriptors");
|
|
89
|
+
super(e), e?.connection && this.__webvpn_tcp_socket_init__(e.connection);
|
|
90
|
+
}
|
|
91
|
+
__webvpn_tcp_socket_init__(e) {
|
|
92
|
+
if (this._webVPNTcpSocketPromise = e.then((t) => {
|
|
93
|
+
const o = t.dataReadableStream.getReader(), s = t.dataWritableStream.getWriter();
|
|
94
|
+
return this._localAddress = {
|
|
95
|
+
address: t.localAddress,
|
|
96
|
+
family: t.localFamily,
|
|
97
|
+
port: t.localPort
|
|
98
|
+
}, this._remoteAddress = {
|
|
99
|
+
address: t.remoteAddress,
|
|
100
|
+
family: t.remoteFamily,
|
|
101
|
+
port: t.remotePort
|
|
102
|
+
}, {
|
|
103
|
+
...t,
|
|
104
|
+
reader: o,
|
|
105
|
+
writer: s
|
|
106
|
+
};
|
|
107
|
+
}).catch((t) => {
|
|
108
|
+
this.emit("error", t);
|
|
109
|
+
}), !this._webVPNTcpSocketPromise)
|
|
110
|
+
throw new Error("Socket not connected");
|
|
111
|
+
return this._webVPNTcpSocketPromise.then((t) => {
|
|
112
|
+
!t || this.emit("connect");
|
|
113
|
+
}), this._webVPNTcpSocketPromise;
|
|
114
|
+
}
|
|
115
|
+
_read(e) {
|
|
116
|
+
if (!this._webVPNTcpSocketPromise)
|
|
117
|
+
throw new Error("Socket not connected");
|
|
118
|
+
this._webVPNTcpSocketPromise.then((t) => {
|
|
119
|
+
if (!t)
|
|
120
|
+
throw new Error("Socket not connected");
|
|
121
|
+
t.reader.read().then(({ value: o, done: s }) => {
|
|
122
|
+
if (s) {
|
|
123
|
+
this.push(null);
|
|
124
|
+
return;
|
|
56
125
|
}
|
|
57
|
-
|
|
58
|
-
|
|
126
|
+
this.push(o);
|
|
127
|
+
}).catch((o) => {
|
|
128
|
+
this.emit("error", o), this.destroy(o);
|
|
59
129
|
});
|
|
60
130
|
});
|
|
61
131
|
}
|
|
132
|
+
_write(e, t, o) {
|
|
133
|
+
if (!this._webVPNTcpSocketPromise)
|
|
134
|
+
throw new Error("Socket not connected");
|
|
135
|
+
this._webVPNTcpSocketPromise.then((s) => {
|
|
136
|
+
if (!s)
|
|
137
|
+
throw new Error("Socket not connected");
|
|
138
|
+
s.writer.write(e), o && o();
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
connect(...e) {
|
|
142
|
+
const t = b(...e), o = this.__webvpn_tcp_socket_init__(
|
|
143
|
+
a.then(
|
|
144
|
+
(s) => s.WEBVPN_TCP_SOCKET({
|
|
145
|
+
remoteAddress: t.host,
|
|
146
|
+
remotePort: t.port
|
|
147
|
+
})
|
|
148
|
+
)
|
|
149
|
+
);
|
|
150
|
+
return t.callback && o.then((s) => {
|
|
151
|
+
!s || t.callback();
|
|
152
|
+
}), this;
|
|
153
|
+
}
|
|
154
|
+
_end(...e) {
|
|
155
|
+
return this._webVPNTcpSocketPromise ? (e.length !== 0 && this.write(e[0], e[1], e[2]), this._webVPNTcpSocketPromise.then(async (t) => {
|
|
156
|
+
!t || await t.end();
|
|
157
|
+
}), this) : this;
|
|
158
|
+
}
|
|
159
|
+
_destroy(e) {
|
|
160
|
+
return this._webVPNTcpSocketPromise ? (this._webVPNTcpSocketPromise.then(async (t) => {
|
|
161
|
+
!t || await t.destroy();
|
|
162
|
+
}), this) : this;
|
|
163
|
+
}
|
|
164
|
+
destroySoon() {
|
|
165
|
+
!this._webVPNTcpSocketPromise || this._webVPNTcpSocketPromise.then(async (e) => {
|
|
166
|
+
!e || await e.destroySoon();
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
resetAndDestroy() {
|
|
170
|
+
return this._webVPNTcpSocketPromise ? (this._webVPNTcpSocketPromise.then(async (e) => {
|
|
171
|
+
!e || await e.resetAndDestroy();
|
|
172
|
+
}), this) : this;
|
|
173
|
+
}
|
|
174
|
+
setTimeout(e, t) {
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
setNoDelay(e) {
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
setKeepAlive(e, t) {
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
write(e, t, ...o) {
|
|
184
|
+
return super.write(e, t, ...o);
|
|
185
|
+
}
|
|
186
|
+
address() {
|
|
187
|
+
return this._localAddress ?? {};
|
|
188
|
+
}
|
|
189
|
+
unref() {
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
ref() {
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
autoSelectFamilyAttemptedAddresses;
|
|
196
|
+
bufferSize;
|
|
197
|
+
bytesRead;
|
|
198
|
+
bytesWritten;
|
|
199
|
+
connecting;
|
|
200
|
+
pending;
|
|
201
|
+
get localAddress() {
|
|
202
|
+
if (!this._localAddress)
|
|
203
|
+
throw new Error("Socket is not connected");
|
|
204
|
+
return this._localAddress.address;
|
|
205
|
+
}
|
|
206
|
+
get localPort() {
|
|
207
|
+
if (!this._localAddress)
|
|
208
|
+
throw new Error("Socket is not connected");
|
|
209
|
+
return this._localAddress.port;
|
|
210
|
+
}
|
|
211
|
+
get localFamily() {
|
|
212
|
+
if (!this._localAddress)
|
|
213
|
+
throw new Error("Socket is not connected");
|
|
214
|
+
return this._localAddress.family;
|
|
215
|
+
}
|
|
216
|
+
readyState;
|
|
217
|
+
get remoteAddress() {
|
|
218
|
+
if (!this._remoteAddress)
|
|
219
|
+
throw new Error("Socket is not connected");
|
|
220
|
+
return this._remoteAddress.address;
|
|
221
|
+
}
|
|
222
|
+
get remotePort() {
|
|
223
|
+
if (!this._remoteAddress)
|
|
224
|
+
throw new Error("Socket is not connected");
|
|
225
|
+
return this._remoteAddress.port;
|
|
226
|
+
}
|
|
227
|
+
get remoteFamily() {
|
|
228
|
+
if (!this._remoteAddress)
|
|
229
|
+
throw new Error("Socket is not connected");
|
|
230
|
+
return this._remoteAddress.family;
|
|
231
|
+
}
|
|
232
|
+
timeout;
|
|
233
|
+
}
|
|
234
|
+
class u extends p {
|
|
235
|
+
_localAddress;
|
|
236
|
+
_webVPNTcpSocketListenerPromise;
|
|
237
|
+
constructor(e, t) {
|
|
238
|
+
super(e), t && this.on("connection", t), e?.connection && this.__webvpn_tcp_socket_listener_init__(e.connection);
|
|
239
|
+
}
|
|
240
|
+
__webvpn_tcp_socket_listener_init__(e) {
|
|
241
|
+
return this._webVPNTcpSocketListenerPromise = e.then((t) => (this._localAddress = {
|
|
242
|
+
address: t.localAddress,
|
|
243
|
+
family: t.localFamily,
|
|
244
|
+
port: t.localPort
|
|
245
|
+
}, t)).catch((t) => {
|
|
246
|
+
this.emit("error", t);
|
|
247
|
+
}), this._webVPNTcpSocketListenerPromise.then((t) => {
|
|
248
|
+
!t || this.emit("listening");
|
|
249
|
+
}), this._webVPNTcpSocketListenerPromise;
|
|
250
|
+
}
|
|
251
|
+
listen(...e) {
|
|
252
|
+
const t = b(...e), o = this.__webvpn_tcp_socket_listener_init__(
|
|
253
|
+
a.then(
|
|
254
|
+
(s) => s.WEBVPN_TCP_SOCKET_LISTENER({
|
|
255
|
+
localAddress: t.host,
|
|
256
|
+
localPort: t.port,
|
|
257
|
+
onConnection: (n) => {
|
|
258
|
+
const i = new d({ connection: Promise.resolve(n) });
|
|
259
|
+
this.emit("connection", i);
|
|
260
|
+
}
|
|
261
|
+
})
|
|
262
|
+
)
|
|
263
|
+
);
|
|
264
|
+
return t.callback && o.then((s) => {
|
|
265
|
+
!s || t.callback();
|
|
266
|
+
}), this;
|
|
267
|
+
}
|
|
62
268
|
close(e) {
|
|
63
|
-
this.
|
|
269
|
+
return this._webVPNTcpSocketListenerPromise ? (this._webVPNTcpSocketListenerPromise.then((t) => {
|
|
270
|
+
!t || (t.close(), this.emit("close"), this._localAddress = void 0, e && e());
|
|
271
|
+
}), this) : this;
|
|
64
272
|
}
|
|
65
|
-
|
|
66
|
-
return this.
|
|
273
|
+
address() {
|
|
274
|
+
return this._localAddress ?? null;
|
|
275
|
+
}
|
|
276
|
+
getConnections(e) {
|
|
277
|
+
throw new Error("Method not implemented.");
|
|
278
|
+
}
|
|
279
|
+
ref() {
|
|
280
|
+
throw new Error("Method not implemented.");
|
|
281
|
+
}
|
|
282
|
+
unref() {
|
|
283
|
+
throw new Error("Method not implemented.");
|
|
284
|
+
}
|
|
285
|
+
maxConnections;
|
|
286
|
+
connections;
|
|
287
|
+
listening;
|
|
288
|
+
async [Symbol.asyncDispose]() {
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
const y = (r, e) => new d().connect(r, e), k = (r, e) => new d().connect(r, e), A = (r, e) => {
|
|
292
|
+
const t = new u(r);
|
|
293
|
+
return e && t.on("connection", e), t;
|
|
294
|
+
}, f = {
|
|
295
|
+
Socket: d,
|
|
296
|
+
Server: u,
|
|
297
|
+
connect: y,
|
|
298
|
+
createConnection: k,
|
|
299
|
+
createServer: A,
|
|
300
|
+
isIP: S,
|
|
301
|
+
isIPv4: h,
|
|
302
|
+
isIPv6: m
|
|
303
|
+
}, B = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
304
|
+
__proto__: null,
|
|
305
|
+
Socket: d,
|
|
306
|
+
Server: u,
|
|
307
|
+
connect: y,
|
|
308
|
+
createConnection: k,
|
|
309
|
+
createServer: A,
|
|
310
|
+
isIP: S,
|
|
311
|
+
isIPv4: h,
|
|
312
|
+
isIPv6: m,
|
|
313
|
+
_default: f,
|
|
314
|
+
default: f
|
|
315
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
316
|
+
class E extends p {
|
|
317
|
+
_type;
|
|
318
|
+
_localAddress;
|
|
319
|
+
_remoteAddress;
|
|
320
|
+
_webVPNUdpSocketPromise;
|
|
321
|
+
constructor(e) {
|
|
322
|
+
if (super(e), !e)
|
|
323
|
+
throw new Error("Missing options");
|
|
324
|
+
this._type = e.type;
|
|
325
|
+
}
|
|
326
|
+
addMembership(e, t) {
|
|
327
|
+
}
|
|
328
|
+
address() {
|
|
329
|
+
if (!this._localAddress)
|
|
330
|
+
throw new Error("EBADF");
|
|
331
|
+
return this._localAddress;
|
|
332
|
+
}
|
|
333
|
+
bind(...e) {
|
|
334
|
+
const t = R(...e);
|
|
335
|
+
return this._webVPNUdpSocketPromise = a.then(
|
|
336
|
+
(o) => o.WEBVPN_UDP_SOCKET({
|
|
337
|
+
type: this._type,
|
|
338
|
+
address: t.address,
|
|
339
|
+
port: t.port
|
|
340
|
+
})
|
|
341
|
+
).then((o) => {
|
|
342
|
+
const s = o.dataReadableStream.getReader(), n = async () => {
|
|
343
|
+
const { value: i, done: N } = await s.read();
|
|
344
|
+
N || (this.emit("message", {
|
|
345
|
+
data: i.data,
|
|
346
|
+
rinfo: {
|
|
347
|
+
address: i.address,
|
|
348
|
+
family: i.family,
|
|
349
|
+
port: i.port,
|
|
350
|
+
size: i.size
|
|
351
|
+
}
|
|
352
|
+
}), n());
|
|
353
|
+
};
|
|
354
|
+
return n(), this._localAddress = {
|
|
355
|
+
address: o.localAddress,
|
|
356
|
+
family: o.localFamily,
|
|
357
|
+
port: o.localPort
|
|
358
|
+
}, o;
|
|
359
|
+
}).catch((o) => {
|
|
360
|
+
this.emit("error", o);
|
|
361
|
+
}), this._webVPNUdpSocketPromise.then((o) => {
|
|
362
|
+
!o || this.emit("listening");
|
|
363
|
+
}), t.callback && this._webVPNUdpSocketPromise.then((o) => {
|
|
364
|
+
!o || t.callback();
|
|
365
|
+
}), this;
|
|
366
|
+
}
|
|
367
|
+
close(e) {
|
|
368
|
+
if (!this._webVPNUdpSocketPromise)
|
|
369
|
+
throw new Error("Socket not bound");
|
|
370
|
+
return this._webVPNUdpSocketPromise.then(async (t) => {
|
|
371
|
+
if (!t)
|
|
372
|
+
throw new Error("Socket not bound");
|
|
373
|
+
await t.close(), e && e(), this.emit("close");
|
|
374
|
+
}), this;
|
|
375
|
+
}
|
|
376
|
+
connect(...e) {
|
|
377
|
+
if (!this._webVPNUdpSocketPromise)
|
|
378
|
+
throw new Error("Socket not bound");
|
|
379
|
+
this._webVPNUdpSocketPromise.then(async (t) => {
|
|
380
|
+
if (!t)
|
|
381
|
+
throw new Error("Socket not bound");
|
|
382
|
+
const o = e[0], s = typeof e[1] == "string" ? e[1] : "localhost", n = typeof e.at(-1) == "function" ? e.at(-1) : void 0;
|
|
383
|
+
await t.connect({ remotePort: o, remoteAddress: s }), n && n();
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
disconnect() {
|
|
387
|
+
if (!this._webVPNUdpSocketPromise)
|
|
388
|
+
throw new Error("Socket not bound");
|
|
389
|
+
this._webVPNUdpSocketPromise.then(async (e) => {
|
|
390
|
+
if (!e)
|
|
391
|
+
throw new Error("Socket not bound");
|
|
392
|
+
await e.connect({ remotePort: 0, remoteAddress: this._type === "udp4" ? "0.0.0.0" : "::" });
|
|
67
393
|
});
|
|
68
394
|
}
|
|
69
|
-
|
|
70
|
-
|
|
395
|
+
dropMembership(e, t) {
|
|
396
|
+
}
|
|
397
|
+
getRecvBufferSize() {
|
|
398
|
+
return 0;
|
|
71
399
|
}
|
|
72
|
-
|
|
73
|
-
return
|
|
400
|
+
getSendBufferSize() {
|
|
401
|
+
return 0;
|
|
74
402
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return { readable: e, writable: a };
|
|
403
|
+
getSendQueueSize() {
|
|
404
|
+
return 0;
|
|
78
405
|
}
|
|
79
|
-
|
|
80
|
-
return
|
|
406
|
+
getSendQueueCount() {
|
|
407
|
+
return 0;
|
|
81
408
|
}
|
|
82
|
-
|
|
83
|
-
|
|
409
|
+
ref() {
|
|
410
|
+
return this;
|
|
411
|
+
}
|
|
412
|
+
remoteAddress() {
|
|
413
|
+
if (!this._remoteAddress)
|
|
414
|
+
throw new Error("ERR_SOCKET_DGRAM_NOT_CONNECTED");
|
|
84
415
|
return {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
set incomingHighWaterMark(a) {
|
|
89
|
-
e._awaitedInternals.datagrams.setIncomingHighWaterMark(a);
|
|
90
|
-
},
|
|
91
|
-
get incomingMaxAge() {
|
|
92
|
-
return e._awaitedInternals.datagrams.incomingMaxAge;
|
|
93
|
-
},
|
|
94
|
-
set incomingMaxAge(a) {
|
|
95
|
-
e._awaitedInternals.datagrams.setIncomingMaxAge(a);
|
|
96
|
-
},
|
|
97
|
-
get maxDatagramSize() {
|
|
98
|
-
return e._awaitedInternals.datagrams.maxDatagramSize;
|
|
99
|
-
},
|
|
100
|
-
get outgoingHighWaterMark() {
|
|
101
|
-
return e._awaitedInternals.datagrams.outgoingHighWaterMark;
|
|
102
|
-
},
|
|
103
|
-
set outgoingHighWaterMark(a) {
|
|
104
|
-
e._awaitedInternals.datagrams.setOutgoingHighWaterMark(a);
|
|
105
|
-
},
|
|
106
|
-
get outgoingMaxAge() {
|
|
107
|
-
return e._awaitedInternals.datagrams.outgoingMaxAge;
|
|
108
|
-
},
|
|
109
|
-
set outgoingMaxAge(a) {
|
|
110
|
-
e._awaitedInternals.datagrams.setOutgoingMaxAge(a);
|
|
111
|
-
},
|
|
112
|
-
get readable() {
|
|
113
|
-
return e._awaitedInternals.datagrams.readable;
|
|
114
|
-
},
|
|
115
|
-
get writable() {
|
|
116
|
-
return e._awaitedInternals.datagrams.writable;
|
|
117
|
-
}
|
|
416
|
+
address: this._remoteAddress.address,
|
|
417
|
+
family: this._remoteAddress.family,
|
|
418
|
+
port: this._remoteAddress.port
|
|
118
419
|
};
|
|
119
420
|
}
|
|
421
|
+
send(...e) {
|
|
422
|
+
this._webVPNUdpSocketPromise || this.bind();
|
|
423
|
+
const t = x(...e);
|
|
424
|
+
if (!this._webVPNUdpSocketPromise)
|
|
425
|
+
throw new Error("Socket not bound");
|
|
426
|
+
this._webVPNUdpSocketPromise.then((o) => {
|
|
427
|
+
if (!o)
|
|
428
|
+
throw new Error("Socket not bound");
|
|
429
|
+
const s = typeof t.message == "string" ? I.encode(t.message) : t.message;
|
|
430
|
+
o.send({
|
|
431
|
+
...t,
|
|
432
|
+
message: s.buffer
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
setBroadcast(e) {
|
|
437
|
+
}
|
|
438
|
+
setMulticastInterface(e) {
|
|
439
|
+
}
|
|
440
|
+
setMulticastLoopback(e) {
|
|
441
|
+
return !0;
|
|
442
|
+
}
|
|
443
|
+
setMulticastTTL(e) {
|
|
444
|
+
return e;
|
|
445
|
+
}
|
|
446
|
+
setRecvBufferSize(e) {
|
|
447
|
+
}
|
|
448
|
+
setSendBufferSize(e) {
|
|
449
|
+
}
|
|
450
|
+
setTTL(e) {
|
|
451
|
+
return e;
|
|
452
|
+
}
|
|
453
|
+
unref() {
|
|
454
|
+
return this;
|
|
455
|
+
}
|
|
456
|
+
addSourceSpecificMembership(e, t, o) {
|
|
457
|
+
}
|
|
458
|
+
dropSourceSpecificMembership(e, t, o) {
|
|
459
|
+
}
|
|
460
|
+
async [Symbol.asyncDispose]() {
|
|
461
|
+
await new Promise((e) => {
|
|
462
|
+
this.close(e);
|
|
463
|
+
});
|
|
464
|
+
}
|
|
120
465
|
}
|
|
466
|
+
const D = (r, e) => {
|
|
467
|
+
const t = new E(
|
|
468
|
+
typeof r == "string" ? { type: r } : r
|
|
469
|
+
);
|
|
470
|
+
return e && t.on("message", e), t;
|
|
471
|
+
}, K = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
472
|
+
__proto__: null,
|
|
473
|
+
Socket: E,
|
|
474
|
+
createSocket: D
|
|
475
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
121
476
|
export {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
y as serverProxyFetch,
|
|
126
|
-
b as setApiTarget
|
|
477
|
+
K as dgram,
|
|
478
|
+
B as net,
|
|
479
|
+
W as serverProxyFetch
|
|
127
480
|
};
|
package/build/test.d.ts
ADDED
|
File without changes
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { BindOptions, Socket as DgramSocket, RemoteInfo, SocketOptions, SocketType } from 'dgram';
|
|
2
|
+
import { AddressInfo } from 'net';
|
|
3
|
+
import { ApiResolvers } from '@mfkn/web/src/api/resolvers';
|
|
4
|
+
import { EventEmitter } from 'events';
|
|
5
|
+
interface EventEmitterOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Enables automatic capturing of promise rejection.
|
|
8
|
+
*/
|
|
9
|
+
captureRejections?: boolean | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare class Socket extends EventEmitter implements DgramSocket {
|
|
12
|
+
_type: 'udp4' | 'udp6';
|
|
13
|
+
_localAddress?: {
|
|
14
|
+
address: string;
|
|
15
|
+
family: string;
|
|
16
|
+
port: number;
|
|
17
|
+
};
|
|
18
|
+
_remoteAddress?: {
|
|
19
|
+
address: string;
|
|
20
|
+
family: string;
|
|
21
|
+
port: number;
|
|
22
|
+
};
|
|
23
|
+
_webVPNUdpSocketPromise?: Promise<Awaited<ReturnType<ApiResolvers['WEBVPN_UDP_SOCKET']>> | undefined>;
|
|
24
|
+
constructor(options: SocketOptions & EventEmitterOptions & {
|
|
25
|
+
connection?: ReturnType<ApiResolvers['WEBVPN_UDP_SOCKET']>;
|
|
26
|
+
});
|
|
27
|
+
addMembership(multicastAddress: string, multicastInterface?: string | undefined): void;
|
|
28
|
+
address(): AddressInfo;
|
|
29
|
+
bind(port?: number | undefined, address?: string | undefined, callback?: (() => void) | undefined): this;
|
|
30
|
+
bind(port?: number | undefined, callback?: (() => void) | undefined): this;
|
|
31
|
+
bind(callback?: (() => void) | undefined): this;
|
|
32
|
+
bind(options: BindOptions, callback?: (() => void) | undefined): this;
|
|
33
|
+
close(callback?: (() => void) | undefined): this;
|
|
34
|
+
connect(port: number, address?: string, callback?: () => void): void;
|
|
35
|
+
connect(port: number, callback: () => void): void;
|
|
36
|
+
disconnect(): void;
|
|
37
|
+
dropMembership(multicastAddress: string, multicastInterface?: string | undefined): void;
|
|
38
|
+
getRecvBufferSize(): number;
|
|
39
|
+
getSendBufferSize(): number;
|
|
40
|
+
getSendQueueSize(): number;
|
|
41
|
+
getSendQueueCount(): number;
|
|
42
|
+
ref(): this;
|
|
43
|
+
remoteAddress(): AddressInfo;
|
|
44
|
+
send(msg: string | readonly any[] | Uint8Array, port?: number | undefined, address?: string | undefined, callback?: ((error: Error | null, bytes: number) => void) | undefined): void;
|
|
45
|
+
send(msg: string | readonly any[] | Uint8Array, port?: number | undefined, callback?: ((error: Error | null, bytes: number) => void) | undefined): void;
|
|
46
|
+
send(msg: string | readonly any[] | Uint8Array, callback?: ((error: Error | null, bytes: number) => void) | undefined): void;
|
|
47
|
+
send(msg: string | Uint8Array, offset: number, length: number, port?: number | undefined, address?: string | undefined, callback?: ((error: Error | null, bytes: number) => void) | undefined): void;
|
|
48
|
+
send(msg: string | Uint8Array, offset: number, length: number, port?: number | undefined, callback?: ((error: Error | null, bytes: number) => void) | undefined): void;
|
|
49
|
+
send(msg: string | Uint8Array, offset: number, length: number, callback?: ((error: Error | null, bytes: number) => void) | undefined): void;
|
|
50
|
+
send(msg: unknown, offset?: unknown, length?: unknown, port?: unknown, address?: unknown, callback?: unknown): void;
|
|
51
|
+
setBroadcast(flag: boolean): void;
|
|
52
|
+
setMulticastInterface(multicastInterface: string): void;
|
|
53
|
+
setMulticastLoopback(flag: boolean): boolean;
|
|
54
|
+
setMulticastTTL(ttl: number): number;
|
|
55
|
+
setRecvBufferSize(size: number): void;
|
|
56
|
+
setSendBufferSize(size: number): void;
|
|
57
|
+
setTTL(ttl: number): number;
|
|
58
|
+
unref(): this;
|
|
59
|
+
addSourceSpecificMembership(sourceAddress: string, groupAddress: string, multicastInterface?: string | undefined): void;
|
|
60
|
+
dropSourceSpecificMembership(sourceAddress: string, groupAddress: string, multicastInterface?: string | undefined): void;
|
|
61
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
export declare const createSocket: (options: SocketType | SocketOptions, callback?: (msg: Buffer, rinfo: RemoteInfo) => void) => Socket;
|
|
64
|
+
export {};
|
package/build/webvpn/index.d.ts
CHANGED
|
@@ -1,52 +1 @@
|
|
|
1
|
-
|
|
2
|
-
ready: undefined;
|
|
3
|
-
close: ({ closeCode, reason }: {
|
|
4
|
-
closeCode?: number;
|
|
5
|
-
reason?: string;
|
|
6
|
-
}) => void;
|
|
7
|
-
incomingBidirectionalStreams: ReadableStream<any>;
|
|
8
|
-
incomingUnidirectionalStreams: ReadableStream<any>;
|
|
9
|
-
createBidirectionalStream: () => Promise<{
|
|
10
|
-
readable: ReadableStream<any>;
|
|
11
|
-
writable: WritableStream<any>;
|
|
12
|
-
}>;
|
|
13
|
-
createUnidirectionalStream: () => Promise<WritableStream<any>>;
|
|
14
|
-
datagrams: {
|
|
15
|
-
incomingHighWaterMark: number;
|
|
16
|
-
setIncomingHighWaterMark: (value: number) => void;
|
|
17
|
-
incomingMaxAge: number;
|
|
18
|
-
setIncomingMaxAge: (value: number) => void;
|
|
19
|
-
maxDatagramSize: number;
|
|
20
|
-
outgoingHighWaterMark: number;
|
|
21
|
-
setOutgoingHighWaterMark: (value: number) => void;
|
|
22
|
-
outgoingMaxAge: number;
|
|
23
|
-
setOutgoingMaxAge: (value: number) => void;
|
|
24
|
-
readable: ReadableStream<any>;
|
|
25
|
-
writable: WritableStream<any>;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
export declare class WebVPNWebTransport implements WebTransport {
|
|
29
|
-
_internals: Promise<WebVPNWebTransportResponse>;
|
|
30
|
-
_awaitedInternals: WebVPNWebTransportResponse;
|
|
31
|
-
closed: Promise<WebTransportCloseInfo>;
|
|
32
|
-
constructor();
|
|
33
|
-
close(closeInfo?: WebTransportCloseInfo): void;
|
|
34
|
-
get ready(): Promise<undefined>;
|
|
35
|
-
get incomingBidirectionalStreams(): ReadableStream<any>;
|
|
36
|
-
get incomingUnidirectionalStreams(): ReadableStream<any>;
|
|
37
|
-
createBidirectionalStream(): Promise<{
|
|
38
|
-
readable: ReadableStream<any>;
|
|
39
|
-
writable: WritableStream<any>;
|
|
40
|
-
}>;
|
|
41
|
-
createUnidirectionalStream(): Promise<WritableStream<any>>;
|
|
42
|
-
get datagrams(): {
|
|
43
|
-
incomingHighWaterMark: number;
|
|
44
|
-
incomingMaxAge: number;
|
|
45
|
-
readonly maxDatagramSize: number;
|
|
46
|
-
outgoingHighWaterMark: number;
|
|
47
|
-
outgoingMaxAge: number;
|
|
48
|
-
readonly readable: ReadableStream<any>;
|
|
49
|
-
readonly writable: WritableStream<any>;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
export {};
|
|
1
|
+
export * from './utils';
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Socket as NetSocket, SocketConnectOpts, SocketConstructorOpts, Server as TCPServer, ServerOpts, ListenOptions, AddressInfo } from 'net';
|
|
2
|
+
import { ApiResolvers } from '@mfkn/web/src/api/resolvers';
|
|
3
|
+
import { DuplexOptions, Stream } from 'stream';
|
|
4
|
+
import { EventEmitter } from 'events';
|
|
5
|
+
import { isIP, isIPv4, isIPv6 } from './utils';
|
|
6
|
+
export declare class Socket extends Stream.Duplex implements NetSocket {
|
|
7
|
+
_localAddress?: {
|
|
8
|
+
address: string;
|
|
9
|
+
family: string;
|
|
10
|
+
port: number;
|
|
11
|
+
};
|
|
12
|
+
_remoteAddress?: {
|
|
13
|
+
address: string;
|
|
14
|
+
family: string;
|
|
15
|
+
port: number;
|
|
16
|
+
};
|
|
17
|
+
_webVPNTcpSocketPromise?: Promise<(Awaited<ReturnType<ApiResolvers['WEBVPN_TCP_SOCKET']>> & {
|
|
18
|
+
reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
19
|
+
writer: WritableStreamDefaultWriter<Uint8Array>;
|
|
20
|
+
}) | undefined>;
|
|
21
|
+
constructor(options?: SocketConstructorOpts & DuplexOptions & {
|
|
22
|
+
connection?: ReturnType<ApiResolvers['WEBVPN_TCP_SOCKET']>;
|
|
23
|
+
});
|
|
24
|
+
__webvpn_tcp_socket_init__(connection: ReturnType<ApiResolvers['WEBVPN_TCP_SOCKET']>): Promise<({
|
|
25
|
+
localAddress: string;
|
|
26
|
+
localFamily: "IPv4" | "IPv6";
|
|
27
|
+
localPort: number;
|
|
28
|
+
remoteAddress: string;
|
|
29
|
+
remoteFamily: "IPv4" | "IPv6";
|
|
30
|
+
remotePort: number;
|
|
31
|
+
dataReadableStream: ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
32
|
+
dataWritableStream: WritableStream<Uint8Array<ArrayBuffer>>;
|
|
33
|
+
end: () => Promise<void>;
|
|
34
|
+
destroy: () => Promise<void>;
|
|
35
|
+
destroySoon: () => Promise<void>;
|
|
36
|
+
resetAndDestroy: () => Promise<void>;
|
|
37
|
+
} & {
|
|
38
|
+
reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
39
|
+
writer: WritableStreamDefaultWriter<Uint8Array>;
|
|
40
|
+
}) | undefined>;
|
|
41
|
+
/** STREAM IMPL */
|
|
42
|
+
_read(size: number): void;
|
|
43
|
+
_write(chunk: Uint8Array, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
44
|
+
/** SOCKET IMPL */
|
|
45
|
+
connect(options: SocketConnectOpts, connectionListener?: (() => void) | undefined): this;
|
|
46
|
+
connect(port: number, host: string, connectionListener?: (() => void) | undefined): this;
|
|
47
|
+
connect(port: number, connectionListener?: (() => void) | undefined): this;
|
|
48
|
+
connect(path: string, connectionListener?: (() => void) | undefined): this;
|
|
49
|
+
connect(port: unknown, host?: unknown, connectionListener?: unknown): this;
|
|
50
|
+
_end(chunk: any, cb?: () => void): this;
|
|
51
|
+
_end(chunk: any, encoding?: BufferEncoding, cb?: () => void): this;
|
|
52
|
+
_destroy(error?: Error | null | undefined): this;
|
|
53
|
+
destroySoon(): void;
|
|
54
|
+
resetAndDestroy(): this;
|
|
55
|
+
setTimeout(timeout: number, callback?: (() => void) | undefined): this;
|
|
56
|
+
setNoDelay(noDelay?: boolean | undefined): this;
|
|
57
|
+
setKeepAlive(enable?: boolean | undefined, initialDelay?: number | undefined): this;
|
|
58
|
+
write(buffer: Uint8Array | string, cb?: (err?: Error) => void): boolean;
|
|
59
|
+
write(str: Uint8Array | string, encoding?: BufferEncoding, cb?: (err?: Error) => void): boolean;
|
|
60
|
+
address(): AddressInfo | {};
|
|
61
|
+
unref(): this;
|
|
62
|
+
ref(): this;
|
|
63
|
+
autoSelectFamilyAttemptedAddresses: string[];
|
|
64
|
+
bufferSize: number;
|
|
65
|
+
bytesRead: number;
|
|
66
|
+
bytesWritten: number;
|
|
67
|
+
connecting: boolean;
|
|
68
|
+
pending: boolean;
|
|
69
|
+
get localAddress(): string;
|
|
70
|
+
get localPort(): number;
|
|
71
|
+
get localFamily(): string;
|
|
72
|
+
readyState: SocketReadyState;
|
|
73
|
+
get remoteAddress(): string;
|
|
74
|
+
get remotePort(): number;
|
|
75
|
+
get remoteFamily(): string;
|
|
76
|
+
timeout?: number | undefined;
|
|
77
|
+
}
|
|
78
|
+
interface EventEmitterOptions {
|
|
79
|
+
/**
|
|
80
|
+
* Enables automatic capturing of promise rejection.
|
|
81
|
+
*/
|
|
82
|
+
captureRejections?: boolean | undefined;
|
|
83
|
+
}
|
|
84
|
+
export declare class Server extends EventEmitter implements TCPServer {
|
|
85
|
+
_localAddress?: {
|
|
86
|
+
address: string;
|
|
87
|
+
family: string;
|
|
88
|
+
port: number;
|
|
89
|
+
};
|
|
90
|
+
_webVPNTcpSocketListenerPromise?: Promise<Awaited<ReturnType<ApiResolvers['WEBVPN_TCP_SOCKET_LISTENER']>> | undefined>;
|
|
91
|
+
constructor(options?: ServerOpts & EventEmitterOptions & {
|
|
92
|
+
connection?: ReturnType<ApiResolvers['WEBVPN_TCP_SOCKET_LISTENER']>;
|
|
93
|
+
}, connectionListener?: (socket: Socket) => void);
|
|
94
|
+
__webvpn_tcp_socket_listener_init__(connection: ReturnType<ApiResolvers['WEBVPN_TCP_SOCKET_LISTENER']>): Promise<{
|
|
95
|
+
localAddress: string;
|
|
96
|
+
localFamily: "IPv4" | "IPv6";
|
|
97
|
+
localPort: number;
|
|
98
|
+
close: () => Promise<void>;
|
|
99
|
+
} | undefined>;
|
|
100
|
+
listen(port?: number | undefined, hostname?: string | undefined, backlog?: number | undefined, listeningListener?: (() => void) | undefined): this;
|
|
101
|
+
listen(port?: number | undefined, hostname?: string | undefined, listeningListener?: (() => void) | undefined): this;
|
|
102
|
+
listen(port?: number | undefined, backlog?: number | undefined, listeningListener?: (() => void) | undefined): this;
|
|
103
|
+
listen(port?: number | undefined, listeningListener?: (() => void) | undefined): this;
|
|
104
|
+
listen(path: string, backlog?: number | undefined, listeningListener?: (() => void) | undefined): this;
|
|
105
|
+
listen(path: string, listeningListener?: (() => void) | undefined): this;
|
|
106
|
+
listen(options: ListenOptions, listeningListener?: (() => void) | undefined): this;
|
|
107
|
+
listen(handle: any, backlog?: number | undefined, listeningListener?: (() => void) | undefined): this;
|
|
108
|
+
listen(handle: any, listeningListener?: (() => void) | undefined): this;
|
|
109
|
+
listen(port?: unknown, hostname?: unknown, backlog?: unknown, listeningListener?: unknown): this;
|
|
110
|
+
close(callback?: ((err?: Error | undefined) => void) | undefined): this;
|
|
111
|
+
address(): string | AddressInfo | null;
|
|
112
|
+
getConnections(cb: (error: Error | null, count: number) => void): void;
|
|
113
|
+
ref(): this;
|
|
114
|
+
unref(): this;
|
|
115
|
+
maxConnections: number;
|
|
116
|
+
connections: number;
|
|
117
|
+
listening: boolean;
|
|
118
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
119
|
+
}
|
|
120
|
+
export declare const connect: (options: SocketConnectOpts, connectionListener?: () => void) => Socket;
|
|
121
|
+
export declare const createConnection: (options: SocketConnectOpts, connectionListener?: () => void) => Socket;
|
|
122
|
+
export declare const createServer: (options: ServerOpts, connectionListener?: (socket: Socket) => void) => Server;
|
|
123
|
+
export { isIP, isIPv4, isIPv6 };
|
|
124
|
+
export declare const _default: {
|
|
125
|
+
Socket: typeof Socket;
|
|
126
|
+
Server: typeof Server;
|
|
127
|
+
connect: (options: SocketConnectOpts, connectionListener?: () => void) => Socket;
|
|
128
|
+
createConnection: (options: SocketConnectOpts, connectionListener?: () => void) => Socket;
|
|
129
|
+
createServer: (options: ServerOpts, connectionListener?: (socket: Socket) => void) => Server;
|
|
130
|
+
isIP: (input: string) => 0 | 4 | 6;
|
|
131
|
+
isIPv4: (input: string) => boolean;
|
|
132
|
+
isIPv6: (input: string) => boolean;
|
|
133
|
+
};
|
|
134
|
+
export default _default;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ListenOptions, SocketConnectOpts } from 'net';
|
|
2
|
+
import { BindOptions } from 'dgram';
|
|
3
|
+
export declare const textEncoder: TextEncoder;
|
|
4
|
+
export declare const textDecoder: TextDecoder;
|
|
5
|
+
export declare const isIPv4: (input: string) => boolean;
|
|
6
|
+
export declare const isIPv6: (input: string) => boolean;
|
|
7
|
+
export declare const isIP: (input: string) => 0 | 4 | 6;
|
|
8
|
+
type TcpConnectArgs = [options: SocketConnectOpts, connectionListener?: () => void] | [port: number, host: string, connectionListener?: () => void] | [port: number, connectionListener?: () => void] | [path: string, connectionListener?: () => void];
|
|
9
|
+
type TcpListenArgs = [port?: number, hostname?: string, backlog?: number, listeningListener?: (() => void)] | [port?: number, hostname?: string, listeningListener?: (() => void)] | [port?: number, backlog?: number, listeningListener?: (() => void)] | [port?: number, listeningListener?: (() => void)] | [path: string, backlog?: number, listeningListener?: (() => void)] | [path: string, listeningListener?: (() => void)] | [options: ListenOptions, listeningListener?: (() => void)] | [handle: any, backlog?: number, listeningListener?: (() => void)] | [handle: any, listeningListener?: (() => void)];
|
|
10
|
+
export declare const normalizeNetArgs: <T extends TcpConnectArgs | TcpListenArgs>(...args: T) => ((T[0] extends object ? T[0] : never) & {
|
|
11
|
+
callback: (() => void) | undefined;
|
|
12
|
+
}) | {
|
|
13
|
+
port: number;
|
|
14
|
+
host: string;
|
|
15
|
+
callback: (() => void) | undefined;
|
|
16
|
+
};
|
|
17
|
+
export declare const normalizeDgramBindArgs: (...args: [port?: number, address?: string, callback?: () => void] | [port?: number, callback?: () => void] | [callback?: () => void] | [options: BindOptions, callback?: () => void]) => {
|
|
18
|
+
address: string;
|
|
19
|
+
port: number;
|
|
20
|
+
callback: (() => void) | undefined;
|
|
21
|
+
exclusive?: boolean | undefined;
|
|
22
|
+
fd?: number | undefined;
|
|
23
|
+
};
|
|
24
|
+
export declare const normalizeDgramSendArgs: (...args: [msg: string | readonly any[] | Uint8Array, port: number, address: string, callback: (error: Error | null, bytes: number) => void] | [msg: string | readonly any[] | Uint8Array, port: number, callback: (error: Error | null, bytes: number) => void] | [msg: string | readonly any[] | Uint8Array, callback: (error: Error | null, bytes: number) => void] | [msg: string | Uint8Array, offset: number, length: number, port: number, address: string, callback: (error: Error | null, bytes: number) => void] | [msg: string | Uint8Array, offset: number, length: number, port: number, callback: (error: Error | null, bytes: number) => void] | [msg: string | Uint8Array, offset: number, length: number, callback: (error: Error | null, bytes: number) => void]) => {
|
|
25
|
+
message: string | readonly any[] | Uint8Array<ArrayBufferLike>;
|
|
26
|
+
offset: number | ((error: Error | null, bytes: number) => void);
|
|
27
|
+
length: number;
|
|
28
|
+
port: number;
|
|
29
|
+
address: string;
|
|
30
|
+
callback: (() => void) | undefined;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fkn/lib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"types": "build/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -10,21 +10,28 @@
|
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@mfkn/web": "file:../web",
|
|
12
12
|
"@mfkn/web-extension": "git+https://github.com/MFKN/web-extension.git",
|
|
13
|
+
"@rollup/plugin-inject": "^5.0.5",
|
|
14
|
+
"@types/node": "^22.7.5",
|
|
13
15
|
"concurrently": "^7.6.0",
|
|
16
|
+
"node-stdlib-browser": "^1.2.1",
|
|
14
17
|
"parse-torrent-file": "^4.2.2",
|
|
15
|
-
"typescript": "^5.
|
|
18
|
+
"typescript": "^5.7.2",
|
|
16
19
|
"vite": "^3.2.5",
|
|
20
|
+
"vite-plugin-dts": "^4.2.3",
|
|
17
21
|
"webextension-polyfill": "^0.10.0"
|
|
18
22
|
},
|
|
19
23
|
"scripts": {
|
|
20
24
|
"dev": "concurrently \"vite build --watch --mode development\" \"tsc --watch\"",
|
|
21
|
-
"build": "vite build
|
|
22
|
-
"build-watch": "vite build --watch --mode production
|
|
23
|
-
"build-dev": "vite build --mode development
|
|
25
|
+
"build": "vite build",
|
|
26
|
+
"build-watch": "vite build --watch --mode production",
|
|
27
|
+
"build-dev": "vite build --mode development",
|
|
24
28
|
"dev-watch": "vite build --watch --mode development",
|
|
25
|
-
"build-types": "tsc"
|
|
29
|
+
"build-types": "tsc",
|
|
30
|
+
"dev-web": "vite --port 4560 --host 0.0.0.0"
|
|
26
31
|
},
|
|
27
32
|
"dependencies": {
|
|
28
|
-
"
|
|
33
|
+
"events": "^3.3.0",
|
|
34
|
+
"ip-address": "^10.0.1",
|
|
35
|
+
"osra": "^0.1.2"
|
|
29
36
|
}
|
|
30
37
|
}
|
package/build/plugin/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const showPluginBrowser: () => Promise<any>;
|
package/build/target.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Target } from 'osra';
|
|
2
|
-
export declare let _resolve: any, _reject: any;
|
|
3
|
-
export declare let target: Promise<Target>;
|
|
4
|
-
export declare const initTargetPromise: () => Promise<Target>;
|
|
5
|
-
export declare const initialTargetPromise: Promise<Target>;
|
|
6
|
-
export declare const setTarget: (newTarget: Target | Promise<Target>) => Promise<void>;
|
package/build/utils/call.d.ts
DELETED
package/build/utils/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './call';
|