@fkn/lib 0.2.0 → 0.2.1
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/index.cjs +1 -1
- package/build/index.js +6 -6
- package/package.json +1 -1
package/build/index.cjs
CHANGED
|
@@ -1 +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}/
|
|
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}/api"]`),c=globalThis.document?.createElement("iframe");!l&&c&&(c.src=`${w}/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},D=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 U=(r,e)=>{const t=new N(typeof r=="string"?{type:r}:r);return e&&t.on("message",e),t},x=Object.freeze(Object.defineProperty({__proto__:null,Socket:N,createSocket:U},Symbol.toStringTag,{value:"Module"}));exports.dgram=x;exports.net=D;exports.serverProxyFetch=C;
|
package/build/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import { expose as T } from "osra";
|
|
|
2
2
|
import { Stream as V } from "stream";
|
|
3
3
|
import { EventEmitter as p } from "events";
|
|
4
4
|
import { Address4 as g, Address6 as v } from "ip-address";
|
|
5
|
-
const _ = "https://fkn.app", l = globalThis?.document.querySelector(`iframe[src="${_}/
|
|
6
|
-
!l && c && (c.src = `${_}/
|
|
5
|
+
const _ = "https://fkn.app", l = globalThis?.document.querySelector(`iframe[src="${_}/api"]`), c = globalThis.document?.createElement("iframe");
|
|
6
|
+
!l && c && (c.src = `${_}/api`, c.style.display = "none", document.body.appendChild(c));
|
|
7
7
|
const w = l || c, z = w.contentWindow;
|
|
8
8
|
if (!w.contentWindow)
|
|
9
9
|
throw new Error("Missing iframe content window");
|
|
@@ -55,7 +55,7 @@ const h = (r) => g.isValid(r), m = (r) => v.isValid(r), S = (r) => h(r) ? 4 : m(
|
|
|
55
55
|
port: t,
|
|
56
56
|
callback: e
|
|
57
57
|
};
|
|
58
|
-
},
|
|
58
|
+
}, D = (...r) => {
|
|
59
59
|
const e = typeof r.at(-1) == "function" ? r.at(-1) : void 0, t = r[0];
|
|
60
60
|
if (typeof r[2] == "number") {
|
|
61
61
|
const o = r[1], s = r[2], n = typeof r[3] == "number" ? r[3] : 0, i = typeof r[4] == "string" ? r[4] : "localhost";
|
|
@@ -420,7 +420,7 @@ class E extends p {
|
|
|
420
420
|
}
|
|
421
421
|
send(...e) {
|
|
422
422
|
this._webVPNUdpSocketPromise || this.bind();
|
|
423
|
-
const t =
|
|
423
|
+
const t = D(...e);
|
|
424
424
|
if (!this._webVPNUdpSocketPromise)
|
|
425
425
|
throw new Error("Socket not bound");
|
|
426
426
|
this._webVPNUdpSocketPromise.then((o) => {
|
|
@@ -463,7 +463,7 @@ class E extends p {
|
|
|
463
463
|
});
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
|
-
const
|
|
466
|
+
const M = (r, e) => {
|
|
467
467
|
const t = new E(
|
|
468
468
|
typeof r == "string" ? { type: r } : r
|
|
469
469
|
);
|
|
@@ -471,7 +471,7 @@ const D = (r, e) => {
|
|
|
471
471
|
}, K = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
472
472
|
__proto__: null,
|
|
473
473
|
Socket: E,
|
|
474
|
-
createSocket:
|
|
474
|
+
createSocket: M
|
|
475
475
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
476
476
|
export {
|
|
477
477
|
K as dgram,
|