@fkn/lib 0.9.72 → 0.9.73
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/{account-CZYGFU5m.cjs → account-BdwCDacQ.cjs} +1 -1
- package/{account-CXUwroRM.d.ts → account-C9w41S0_.d.ts} +1 -1
- package/{account-Czik26yc.js → account-URj9bMMj.js} +2 -2
- package/{account-generation-BTxZWNQz.cjs → account-generation--7m_60Fl.cjs} +1 -1
- package/{account-generation-D2hoQYXp.js → account-generation-DgK9YHiL.js} +1 -1
- package/{account-storage-CIfiAHa1.cjs → account-storage-CQ8k71N3.cjs} +1 -1
- package/{account-storage-DcbJCOvI.js → account-storage-CcdeHbnj.js} +2 -2
- package/account.cjs +1 -1
- package/account.d.ts +2 -2
- package/account.js +1 -1
- package/{api-oE2v5tpj.cjs → api-BORAfb8e.cjs} +2 -2
- package/{api-e82hhULK.js → api-De7vAubY.js} +1 -1
- package/{api-DhwJz0vo.d.ts → api-iKK1u-V0.d.ts} +25 -1
- package/api.cjs +1 -1
- package/api.d.ts +2 -2
- package/api.js +1 -1
- package/{broker-frame-BClLp2ZV.js → broker-frame-AQDD3D9E.js} +1 -1
- package/{broker-frame-BKHtDSjv.cjs → broker-frame-cVEhez7A.cjs} +1 -1
- package/broker-frame.cjs +1 -1
- package/broker-frame.js +1 -1
- package/cloud/dgram.cjs +1 -1
- package/cloud/dgram.d.ts +1 -1
- package/cloud/dgram.js +1 -1
- package/cloud/dns.cjs +1 -1
- package/cloud/dns.d.ts +2 -2
- package/cloud/dns.js +1 -1
- package/cloud/fetch.cjs +1 -1
- package/cloud/fetch.d.ts +1 -1
- package/cloud/fetch.js +1 -1
- package/cloud/fs/promises.cjs +1 -1
- package/cloud/fs/promises.js +1 -1
- package/cloud/fs.cjs +1 -1
- package/cloud/fs.js +2 -2
- package/cloud/http.cjs +1 -1
- package/cloud/http.d.ts +1 -1
- package/cloud/http.js +1 -1
- package/cloud/net.cjs +1 -1
- package/cloud/net.d.ts +1 -1
- package/cloud/net.js +1 -1
- package/{cloud-DRfcPLdB.d.ts → cloud-BDTtnMtj.d.ts} +5 -5
- package/{cloud-6ddOLS37.cjs → cloud-Buku7KQJ.cjs} +1 -1
- package/{cloud-BV96BYFR.js → cloud-Bv_GUwcG.js} +9 -9
- package/cloud.cjs +1 -1
- package/cloud.d.ts +6 -6
- package/cloud.js +7 -7
- package/{contract-CDdIE_Es.d.ts → contract-Cqq1vOqF.d.ts} +35 -1
- package/contract.cjs +1 -1
- package/contract.d.ts +2 -2
- package/contract.js +2 -2
- package/{dgram-wTKAuRI3.cjs → dgram-BgWDRjw-.cjs} +1 -1
- package/{dgram-CPQqam5Z.d.ts → dgram-BggVwnRp.d.ts} +3 -3
- package/{dgram-CTcHo7BL.js → dgram-CYegbMMa.js} +1 -1
- package/dgram.cjs +1 -1
- package/dgram.d.ts +1 -1
- package/dgram.js +1 -1
- package/{dns-OXiS-nXH.cjs → dns-CtxN7cCj.cjs} +1 -1
- package/{dns-Cdmp7tw4.js → dns-DTbLD2s6.js} +1 -1
- package/{dns-_NCe2YLS.d.ts → dns-DeuTGd8C.d.ts} +1 -1
- package/dns.cjs +1 -1
- package/dns.d.ts +2 -2
- package/dns.js +1 -1
- package/{extension-DlPOuZum.js → extension-0RxQ4Bor.js} +4 -4
- package/{extension-eA0r72hp.cjs → extension-DHx7sHE4.cjs} +1 -1
- package/extension.cjs +1 -1
- package/extension.js +2 -2
- package/fs/promises.cjs +1 -1
- package/fs/promises.js +1 -1
- package/{fs-CiZZf0ne.cjs → fs-1Q6VCx3d.cjs} +1 -1
- package/{fs-BHfRf_xt.js → fs-BJdr72O6.js} +1 -1
- package/{fs-CLvS_YSq.cjs → fs-BPfRlX_R.cjs} +1 -1
- package/{fs-9LWii1mp.js → fs-C0RZ54fk.js} +3 -3
- package/fs.cjs +1 -1
- package/fs.js +2 -2
- package/{http-Cg5aK6Jn.js → http-D-rs8b6m.js} +1 -1
- package/{http-KKqCypOh.cjs → http-DkvhaPVT.cjs} +1 -1
- package/{http-rzQOrCmq.d.ts → http-LhyEQ2D8.d.ts} +1 -1
- package/http.cjs +1 -1
- package/http.d.ts +1 -1
- package/http.js +1 -1
- package/index.cjs +1 -1
- package/index.d.ts +11 -11
- package/index.js +13 -13
- package/{lib-B895LZTn.js → lib-B4Th0aXQ.js} +1 -1
- package/{lib-BJzKHh4X.cjs → lib-By2YAF1s.cjs} +1 -1
- package/{net-i4BzwpoN.cjs → net-B3SziNT3.cjs} +1 -1
- package/{net-B4IqLeN8.d.ts → net-CK_1P9_C.d.ts} +3 -3
- package/{net-BUeelrnH.js → net-C_R3PDi7.js} +1 -1
- package/net.cjs +1 -1
- package/net.d.ts +1 -1
- package/net.js +1 -1
- package/package.json +6 -1
- package/{packages-Bw1OE9Ra.cjs → packages-BwD1QMOz.cjs} +1 -1
- package/{packages-C27FhPmh.js → packages-CNXf-8A8.js} +1 -1
- package/{packages-SwO4CxMl.d.ts → packages-FCSR6WEw.d.ts} +1 -1
- package/packages.cjs +1 -1
- package/packages.d.ts +2 -2
- package/packages.js +1 -1
- package/{proxy-khQQJbGw.cjs → proxy-CgISk6T6.cjs} +1 -1
- package/{proxy-BET3xNJw.js → proxy-OrF-WHyi.js} +2 -2
- package/{proxy-CzP07me0.d.ts → proxy-Xe45WiQU.d.ts} +2 -2
- package/{relay-choice-DB1F7bcn.d.ts → relay-choice-BhdjlopH.d.ts} +1 -1
- package/{rooms-C8FW4mDY.cjs → rooms-B_sM_Z93.cjs} +1 -1
- package/{rooms-r09iUhIA.js → rooms-Dz13jhtS.js} +1 -1
- package/{rooms-3XplwXzb.d.ts → rooms-lJGFgMXH.d.ts} +1 -1
- package/rooms.cjs +1 -1
- package/rooms.d.ts +2 -2
- package/rooms.js +1 -1
- package/{storage-BINUKDl1.cjs → storage-B49NeC-h.cjs} +1 -1
- package/{storage-CFk2AT4V.js → storage-Dd3miXPI.js} +3 -3
- package/{storage-C38adB-z.d.ts → storage-ngeijVxI.d.ts} +1 -1
- package/storage.cjs +1 -1
- package/storage.d.ts +2 -2
- package/storage.js +1 -1
- package/websocket.cjs +1 -0
- package/websocket.d.ts +48 -0
- package/websocket.js +179 -0
package/websocket.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
type Handler<E extends Event> = ((event: E) => unknown) | null;
|
|
2
|
+
/**
|
|
3
|
+
* The platform's `WebSocket`, opened by FKN's proxy on the node the session uses: the server sees that node's address,
|
|
4
|
+
* never the person's, and the proxy applies its egress validation, fair-use limits and metering as for a fetch. Its
|
|
5
|
+
* messages pass through the proxy's memory, so it is for servers the browser should not reach from its own address.
|
|
6
|
+
*
|
|
7
|
+
* It behaves as the platform's, events and their order included, with what the platform also refuses: a url that is
|
|
8
|
+
* not `ws:`, `wss:`, `http:` or `https:`, a fragment, a protocol that is not a token or is offered twice. It also
|
|
9
|
+
* refuses FKN's own hosts and a protocol named `fkn-proxy` or starting `fkn-proxy.`, which carry the target to the
|
|
10
|
+
* proxy. Nothing reconnects by itself. A Worker needs `relayWorker` from its page first; without it the socket fails
|
|
11
|
+
* once the broker has not answered within the deadline of `apiWithin`. `extensions` is always empty.
|
|
12
|
+
*/
|
|
13
|
+
export declare class WebSocket extends EventTarget {
|
|
14
|
+
#private;
|
|
15
|
+
static readonly CONNECTING = 0;
|
|
16
|
+
static readonly OPEN = 1;
|
|
17
|
+
static readonly CLOSING = 2;
|
|
18
|
+
static readonly CLOSED = 3;
|
|
19
|
+
readonly CONNECTING: 0;
|
|
20
|
+
readonly OPEN: 1;
|
|
21
|
+
readonly CLOSING: 2;
|
|
22
|
+
readonly CLOSED: 3;
|
|
23
|
+
readonly url: string;
|
|
24
|
+
readonly extensions = "";
|
|
25
|
+
constructor(url: string | URL, protocols?: string | string[]);
|
|
26
|
+
get readyState(): 0 | 1 | 2 | 3;
|
|
27
|
+
get protocol(): string;
|
|
28
|
+
get bufferedAmount(): number;
|
|
29
|
+
get binaryType(): BinaryType;
|
|
30
|
+
set binaryType(type: BinaryType);
|
|
31
|
+
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
|
|
32
|
+
close(code?: number, reason?: string): void;
|
|
33
|
+
get onopen(): Handler<Event>;
|
|
34
|
+
set onopen(handler: Handler<Event>);
|
|
35
|
+
get onmessage(): Handler<MessageEvent>;
|
|
36
|
+
set onmessage(handler: Handler<MessageEvent>);
|
|
37
|
+
get onerror(): Handler<Event>;
|
|
38
|
+
set onerror(handler: Handler<Event>);
|
|
39
|
+
get onclose(): Handler<CloseEvent>;
|
|
40
|
+
set onclose(handler: Handler<CloseEvent>);
|
|
41
|
+
}
|
|
42
|
+
export interface WebSocket {
|
|
43
|
+
addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
44
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
45
|
+
removeEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
|
46
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
package/websocket.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { i as e } from "./broker-frame-AQDD3D9E.js";
|
|
2
|
+
import { s as t } from "./api-De7vAubY.js";
|
|
3
|
+
import { t as n } from "./busy-C1JPjoZ_.js";
|
|
4
|
+
import { PROXY_WEBSOCKET_ENTRY as r, PROXY_WEBSOCKET_MARKER as i } from "./contract.js";
|
|
5
|
+
// src/websocket.ts
|
|
6
|
+
var a = 0, o = 1, s = 2, c = 3, l = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/, u = new TextEncoder(), d = {
|
|
7
|
+
code: 1006,
|
|
8
|
+
reason: "",
|
|
9
|
+
wasClean: !1,
|
|
10
|
+
error: !1
|
|
11
|
+
}, f = (e) => {
|
|
12
|
+
let t;
|
|
13
|
+
try {
|
|
14
|
+
t = new URL(e, globalThis.document?.baseURI ?? globalThis.location?.href);
|
|
15
|
+
} catch {
|
|
16
|
+
throw new DOMException(`The URL '${e}' is invalid.`, "SyntaxError");
|
|
17
|
+
}
|
|
18
|
+
if (t.protocol === "http:" ? t.protocol = "ws:" : t.protocol === "https:" && (t.protocol = "wss:"), t.protocol !== "ws:" && t.protocol !== "wss:") throw new DOMException(`The URL's scheme must be either 'http', 'https', 'ws', or 'wss'. '${t.protocol}' is not allowed.`, "SyntaxError");
|
|
19
|
+
if (t.hash || t.href.endsWith("#")) throw new DOMException("The URL contains a fragment identifier.", "SyntaxError");
|
|
20
|
+
return t;
|
|
21
|
+
}, p = (e) => {
|
|
22
|
+
if (typeof e == "string") return [e, u.encode(e).byteLength];
|
|
23
|
+
if (e instanceof Blob) return [e, e.size];
|
|
24
|
+
let t = ArrayBuffer.isView(e) ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength) : new Uint8Array(e);
|
|
25
|
+
return [t.slice().buffer, t.byteLength];
|
|
26
|
+
}, m = class extends EventTarget {
|
|
27
|
+
static CONNECTING = a;
|
|
28
|
+
static OPEN = o;
|
|
29
|
+
static CLOSING = s;
|
|
30
|
+
static CLOSED = c;
|
|
31
|
+
url;
|
|
32
|
+
extensions = "";
|
|
33
|
+
#e = "blob";
|
|
34
|
+
#t = a;
|
|
35
|
+
#n = "";
|
|
36
|
+
#r = 0;
|
|
37
|
+
#i;
|
|
38
|
+
#a;
|
|
39
|
+
#o;
|
|
40
|
+
#s;
|
|
41
|
+
#c = /* @__PURE__ */ new Map();
|
|
42
|
+
constructor(a, o = []) {
|
|
43
|
+
super();
|
|
44
|
+
let s = f(a), c = typeof o == "string" ? [o] : [...o];
|
|
45
|
+
if (new Set(c).size !== c.length || c.some((e) => !l.test(e))) throw new DOMException("The subprotocols are not unique tokens.", "SyntaxError");
|
|
46
|
+
if (c.some((e) => e === "fkn-proxy" || e.startsWith("fkn-proxy."))) throw new DOMException(`The subprotocol '${i}' and those starting '${r}' are FKN's.`, "SyntaxError");
|
|
47
|
+
if (e(s.hostname)) throw Error(`websocket refuses FKN platform domains (${s.hostname})`);
|
|
48
|
+
this.url = s.href, this.#i = s.origin, this.#s = n("websocket"), t("a websocket").then((e) => e.cloud.websocket({
|
|
49
|
+
url: this.url,
|
|
50
|
+
protocols: c
|
|
51
|
+
})).then((e) => this.#l(e)).catch(() => this.#u({
|
|
52
|
+
...d,
|
|
53
|
+
error: !0
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
get readyState() {
|
|
57
|
+
return this.#t;
|
|
58
|
+
}
|
|
59
|
+
get protocol() {
|
|
60
|
+
return this.#n;
|
|
61
|
+
}
|
|
62
|
+
get bufferedAmount() {
|
|
63
|
+
return this.#r;
|
|
64
|
+
}
|
|
65
|
+
get binaryType() {
|
|
66
|
+
return this.#e;
|
|
67
|
+
}
|
|
68
|
+
set binaryType(e) {
|
|
69
|
+
(e === "blob" || e === "arraybuffer") && (this.#e = e);
|
|
70
|
+
}
|
|
71
|
+
send(e) {
|
|
72
|
+
if (this.#t === a) throw new DOMException("Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.", "InvalidStateError");
|
|
73
|
+
let [t, n] = p(e);
|
|
74
|
+
this.#r += n, this.#t === o && this.#o.write(t).then(() => {
|
|
75
|
+
this.#r -= n;
|
|
76
|
+
}, () => {});
|
|
77
|
+
}
|
|
78
|
+
close(e, t) {
|
|
79
|
+
if (e !== void 0 && e !== 1e3 && (e < 3e3 || e > 4999)) throw new DOMException(`The close code must be either 1000, or between 3000 and 4999. ${e} is neither.`, "InvalidAccessError");
|
|
80
|
+
if (t !== void 0 && u.encode(t).byteLength > 123) throw new DOMException("The close reason must not be greater than 123 UTF-8 bytes.", "SyntaxError");
|
|
81
|
+
if (this.#t === s || this.#t === c) return;
|
|
82
|
+
if (e === void 0 && t !== void 0 && (e = 1e3), this.#t === a) {
|
|
83
|
+
this.#t = s, setTimeout(() => this.#u({
|
|
84
|
+
...d,
|
|
85
|
+
error: !0
|
|
86
|
+
}), 0);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
this.#t = s;
|
|
90
|
+
let n = this.#a;
|
|
91
|
+
this.#o.close().catch(() => {}).then(() => n.close(e, t)).catch(() => {});
|
|
92
|
+
}
|
|
93
|
+
async #l(e) {
|
|
94
|
+
if (this.#t !== a) {
|
|
95
|
+
e.close().catch(() => {});
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
this.#a = e, this.#n = e.protocol, this.#o = e.writable.getWriter(), this.#t = o, this.dispatchEvent(new Event("open"));
|
|
99
|
+
let t = e.readable.getReader();
|
|
100
|
+
try {
|
|
101
|
+
for (;;) {
|
|
102
|
+
let { value: e, done: n } = await t.read();
|
|
103
|
+
if (n) break;
|
|
104
|
+
if (this.#t !== o) continue;
|
|
105
|
+
let r = typeof e == "string" || this.#e === "arraybuffer" ? e : new Blob([e]);
|
|
106
|
+
this.dispatchEvent(new MessageEvent("message", {
|
|
107
|
+
data: r,
|
|
108
|
+
origin: this.#i
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
} catch {
|
|
112
|
+
return this.#u(d);
|
|
113
|
+
}
|
|
114
|
+
let n = await e.closed.then((e) => typeof e?.code == "number" ? e : d, () => d);
|
|
115
|
+
this.#u(n);
|
|
116
|
+
}
|
|
117
|
+
#u({ code: e, reason: t, wasClean: n, error: r }) {
|
|
118
|
+
this.#t !== c && (this.#t = c, this.#s(), r && this.dispatchEvent(new Event("error")), this.dispatchEvent(new CloseEvent("close", {
|
|
119
|
+
code: e,
|
|
120
|
+
reason: t,
|
|
121
|
+
wasClean: n
|
|
122
|
+
})));
|
|
123
|
+
}
|
|
124
|
+
#d(e) {
|
|
125
|
+
return this.#c.get(e)?.handler ?? null;
|
|
126
|
+
}
|
|
127
|
+
#f(e, t) {
|
|
128
|
+
let n = this.#c.get(e);
|
|
129
|
+
if (typeof t != "function") {
|
|
130
|
+
n && this.removeEventListener(e, n.listener), this.#c.delete(e);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (n) {
|
|
134
|
+
n.handler = t;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
let r = {
|
|
138
|
+
handler: t,
|
|
139
|
+
listener: (e) => {
|
|
140
|
+
r.handler.call(this, e);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
this.#c.set(e, r), this.addEventListener(e, r.listener);
|
|
144
|
+
}
|
|
145
|
+
get onopen() {
|
|
146
|
+
return this.#d("open");
|
|
147
|
+
}
|
|
148
|
+
set onopen(e) {
|
|
149
|
+
this.#f("open", e);
|
|
150
|
+
}
|
|
151
|
+
get onmessage() {
|
|
152
|
+
return this.#d("message");
|
|
153
|
+
}
|
|
154
|
+
set onmessage(e) {
|
|
155
|
+
this.#f("message", e);
|
|
156
|
+
}
|
|
157
|
+
get onerror() {
|
|
158
|
+
return this.#d("error");
|
|
159
|
+
}
|
|
160
|
+
set onerror(e) {
|
|
161
|
+
this.#f("error", e);
|
|
162
|
+
}
|
|
163
|
+
get onclose() {
|
|
164
|
+
return this.#d("close");
|
|
165
|
+
}
|
|
166
|
+
set onclose(e) {
|
|
167
|
+
this.#f("close", e);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
for (let [e, t] of Object.entries({
|
|
171
|
+
CONNECTING: a,
|
|
172
|
+
OPEN: o,
|
|
173
|
+
CLOSING: s,
|
|
174
|
+
CLOSED: c
|
|
175
|
+
})) Object.defineProperty(m.prototype, e, {
|
|
176
|
+
value: t,
|
|
177
|
+
enumerable: !0
|
|
178
|
+
});
|
|
179
|
+
export { m as WebSocket };
|