@fkn/lib 0.3.12 → 0.4.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.
Files changed (4) hide show
  1. package/index.cjs +5 -5
  2. package/index.d.ts +1555 -1304
  3. package/index.js +383 -282
  4. package/package.json +1 -1
package/index.js CHANGED
@@ -1,167 +1,104 @@
1
1
  import { d as e, f as t, g as n, i as r, l as i, m as a, p as o, r as s, t as c, u as l } from "./locator-DUbu14FW.js";
2
2
  import { createTypedEventTarget as ee, expose as te, relay as ne } from "osra";
3
3
  import { Stream as u } from "stream";
4
- import { EventEmitter as d } from "events";
5
- import { Address4 as f, Address6 as p } from "ip-address";
6
- import { Buffer as m } from "buffer";
7
- //#region src/lib/overlay.ts
8
- var re = 32, ie = typeof CSS < "u" && CSS.supports("clip-path", "path('M0 0H1V1H0Z')"), ae = (e) => {
9
- let t = e.style;
10
- t.setProperty("display", "block", "important"), t.setProperty("position", "fixed", "important"), t.setProperty("top", "0", "important"), t.setProperty("left", "0", "important"), t.setProperty("width", "100%", "important"), t.setProperty("height", "100%", "important"), t.setProperty("border", "none", "important"), t.setProperty("clip-path", "inset(100%)", "important"), t.setProperty("background", "transparent"), t.setProperty("color-scheme", "normal"), t.setProperty("z-index", "2147483647"), e.setAttribute("title", "FKN");
11
- }, oe = ({ x: e, y: t, width: n, height: r }) => `M${e} ${t}h${n}v${r}h${-n}Z`, se = (e, { modal: t, rects: n }) => {
12
- if (!ie) {
13
- let r = t || n.length > 0;
14
- e.style.setProperty("pointer-events", r ? "auto" : "none", "important"), e.style.setProperty("visibility", r ? "visible" : "hidden", "important");
15
- return;
16
- }
17
- let r = t ? "none" : n.length === 0 ? "inset(100%)" : `path('${n.map(oe).join("")}')`, i = r === "none" || CSS.supports("clip-path", r) ? r : "inset(100%)";
18
- e.style.setProperty("clip-path", i, "important");
19
- }, ce = (e) => {
20
- if (typeof e != "object" || !e) return null;
21
- let { x: t, y: n, width: r, height: i } = e;
22
- if (![
23
- t,
24
- n,
25
- r,
26
- i
27
- ].every((e) => typeof e == "number" && Number.isFinite(e))) return null;
28
- let a = window.innerWidth, o = window.innerHeight, s = Math.max(0, Math.min(Math.round(t), a)), c = Math.max(0, Math.min(Math.round(n), o)), l = Math.max(s, Math.min(Math.round(t + r), a)), ee = Math.max(c, Math.min(Math.round(n + i), o));
29
- return {
30
- x: s,
31
- y: c,
32
- width: l - s,
33
- height: ee - c
34
- };
35
- }, le = (e) => {
36
- if (typeof e != "object" || !e) return null;
37
- let t = e, n = (Array.isArray(t.rects) ? t.rects.slice(0, re) : []).map(ce).filter((e) => e !== null && e.width > 0 && e.height > 0);
38
- return {
39
- modal: t.modal === !0,
40
- rects: n
41
- };
42
- }, h = null, ue = () => h !== null, de = (e) => {
43
- ae(e), se(e, {
44
- modal: !1,
45
- rects: []
46
- }), h = e;
47
- }, fe = (e) => {
48
- if (!h) return;
49
- let t = le(e);
50
- t && se(h, t);
51
- }, g = "https://fkn.app", _ = typeof globalThis < "u" && globalThis.document ? globalThis.document : void 0, v = _?.querySelector(`iframe[src="${g}/api"]`) ?? null, y = _?.createElement("iframe") ?? null;
52
- !v && y && _ && (y.src = `${g}/api`, _.body.appendChild(y));
53
- var b = v ?? y, x = b?.contentWindow ?? null;
54
- b && _ && de(b);
55
- var pe = (() => {
56
- if (typeof window < "u") return x ? {
57
- receive: window,
58
- emit: x
59
- } : void 0;
60
- if (typeof self < "u") return {
61
- receive: self,
62
- emit: self
63
- };
64
- })(), S = pe ? te({}, {
65
- key: "fkn-api",
66
- transport: pe
67
- }) : new Promise(() => {});
68
- S.then((e) => {
69
- ue() && e.setOverlayHost(fe);
70
- }, () => {});
71
- //#endregion
72
- //#region src/lib/proxy.ts
73
- var me = (e, t) => S.then((n) => n.proxyFetch(e, t)), he = "https://fkn.app", ge = (e, t) => {
74
- if (typeof window > "u") throw Error("FKN @fkn/lib: relayWorker must be called from the main thread");
75
- if (!b?.contentWindow) throw Error("FKN @fkn/lib: relayWorker called before the FKN iframe was injected");
76
- ne({
77
- receive: window,
78
- emit: b.contentWindow
79
- }, e, {
80
- key: "fkn-api",
81
- originA: t?.originA ?? he,
82
- originB: t?.originB ?? "*",
83
- unregisterSignal: t?.unregisterSignal
84
- });
85
- }, _e = "FKN_WEB_EXTENSION_MAIN_WORLD_CONTENT_SCRIPT_ENABLED_EVENT_KEY", ve = "fknExtension", C = ee();
86
- typeof document < "u" && document.addEventListener(_e, (e) => {
87
- C.dispatchEvent(new CustomEvent("statuschange", { detail: { enabled: e.detail.enabled } }));
4
+ import { EventEmitter as re } from "events";
5
+ import { Address4 as d, Address6 as f } from "ip-address";
6
+ import { Buffer as p } from "buffer";
7
+ //#region node_modules/@mfkn/web-extension/lib/utils/extension.js
8
+ var ie = "FKN_WEB_EXTENSION_MAIN_WORLD_CONTENT_SCRIPT_ENABLED_EVENT_KEY", ae = "fknExtension", m = ee();
9
+ typeof document < "u" && document.addEventListener(ie, (e) => {
10
+ m.dispatchEvent(new CustomEvent("statuschange", { detail: { enabled: e.detail.enabled } }));
88
11
  });
89
- var w = () => document.documentElement.dataset[ve] === "true", T = null, E = (e) => {
90
- T = e;
91
- }, ye = 150, D = (e = 1e3) => new Promise((t, n) => {
92
- if (w()) return t();
12
+ var h = () => typeof document > "u" ? !1 : document.documentElement.dataset[ae] === "true", g = null, _ = (e) => {
13
+ g = e;
14
+ }, oe = 150, v = (e = 1e3) => new Promise((t, n) => {
15
+ if (h()) return t();
93
16
  let r, i = (e) => {
94
17
  clearTimeout(r), s.disconnect(), document.removeEventListener("readystatechange", c), e();
95
18
  }, a = () => i(async () => {
96
- if (T && (await T().catch(() => {}), w())) return t();
19
+ if (g && (await g().catch(() => {}), h())) return t();
97
20
  n(/* @__PURE__ */ Error("The FKN WebExtension is not installed, enabled or not exposed on this page."));
98
21
  }), o = () => {
99
- clearTimeout(r), r = setTimeout(() => w() ? i(t) : a(), ye);
22
+ clearTimeout(r), r = setTimeout(() => h() ? i(t) : a(), oe);
100
23
  }, s = new MutationObserver(() => {
101
- w() && i(t);
24
+ h() && i(t);
102
25
  }), c = () => {
103
- document.readyState === "complete" && !w() && o();
26
+ document.readyState === "complete" && !h() && o();
104
27
  };
105
28
  if (r = setTimeout(a, e), s.observe(document.documentElement, {
106
29
  attributes: !0,
107
30
  attributeFilter: ["data-fkn-extension"]
108
31
  }), document.addEventListener("readystatechange", c), document.readyState === "complete") return o();
109
- w() && i(t);
110
- }), O, k = new Proxy({}, { get: (e, t) => async (...e) => {
111
- await D(), O ??= te({}, {
32
+ h() && i(t);
33
+ }), se, y = new Proxy({}, { get: (e, t) => async (...e) => {
34
+ await v(), se ??= te({}, {
112
35
  transport: window,
113
36
  revivableModules: i
114
37
  });
115
- let n = (await O)[t];
38
+ let n = (await se)[t];
116
39
  return n(...e);
117
- } }), be = {
40
+ } }), ce = {
118
41
  scope: "network.fetch",
119
42
  category: "network",
120
43
  severity: 0,
121
44
  title: "Fetch data from other sites",
122
45
  description: "Lets the app download public data from other websites directly, past the usual cross-origin limits."
123
- }, xe = {
46
+ }, le = {
124
47
  scope: "network.fetchCredentialed",
125
48
  category: "network",
126
49
  severity: 3,
127
50
  unsafe: !0,
128
51
  title: "Fetch from other sites, signed in as you",
129
52
  description: "Lets the app fetch other sites using your logged-in session cookies, so it can read data only you should see."
130
- }, Se = ["origin", "referer"], Ce = (e) => {
53
+ }, ue = ["fkn.app", "fkn.dev"], b = (e) => {
54
+ let t;
55
+ try {
56
+ t = new URL(e);
57
+ } catch {
58
+ return !1;
59
+ }
60
+ if (t.protocol === "chrome-extension:" || t.protocol === "moz-extension:") return !0;
61
+ let n = t.hostname;
62
+ return ue.some((e) => n === e || n.endsWith(`.${e}`));
63
+ }, x = (e) => {
64
+ if (b(e)) throw Error("fetch: refusing to target the extension's own pages or FKN platform domains");
65
+ }, de = ["origin", "referer"], fe = (e) => {
131
66
  if (!e?.headers) return;
132
- let t = new Headers(e.headers), n = Se.map((e) => {
67
+ let t = new Headers(e.headers), n = de.map((e) => {
133
68
  let n = t.get(e);
134
69
  return n === null ? void 0 : [e, n];
135
70
  }).filter((e) => e !== void 0);
136
71
  return n.length ? n : void 0;
137
- }, we = async (e, t) => {
138
- let n = new Request(e, t), r = n.body ? await n.arrayBuffer() : null;
139
- return k.proxyFetch({
72
+ }, S = async (e, t) => {
73
+ let n = new Request(e, t);
74
+ x(n.url);
75
+ let r = n.body ? await n.arrayBuffer() : null;
76
+ return y.proxyFetch({
140
77
  url: n.url,
141
78
  method: n.method,
142
79
  headers: [...n.headers],
143
80
  body: r,
144
81
  credentials: t?.credentials === "include" ? "include" : "omit",
145
82
  redirect: n.redirect,
146
- unsafeHeaders: Ce(t),
83
+ unsafeHeaders: fe(t),
147
84
  reason: t?.reason,
148
85
  signal: t?.signal ?? void 0
149
86
  });
150
- }, Te = {
87
+ }, pe = {
151
88
  scope: "network.readCookie",
152
89
  category: "network",
153
90
  severity: 3,
154
91
  unsafe: !0,
155
92
  title: "Read a site’s cookie",
156
93
  description: "Lets the app read a named cookie from another site, which can include the login token only that site should see."
157
- }, Ee = { get: (e) => k.getCookie(e) }, De = {
94
+ }, me = { get: (e) => y.getCookie(e) }, he = {
158
95
  scope: "network.modifyRequestHeaders",
159
96
  category: "network",
160
97
  severity: 2,
161
98
  unsafe: !0,
162
99
  title: "Rewrite request headers to other sites",
163
100
  description: "Lets the app set or remove headers (like Origin and Referer) on this page’s own requests to the listed sites."
164
- }, Oe = (e) => k.setRequestHeaderRule(e), ke = (e) => k.removeRequestHeaderRule({ ruleId: e });
101
+ }, ge = (e) => y.setRequestHeaderRule(e), _e = (e) => y.removeRequestHeaderRule({ ruleId: e });
165
102
  (() => {
166
103
  let e = {}, t = [...c.selectorModules, ...r.selectorModules];
167
104
  for (let n of t) n.render && !(n.type in e) && (e[n.type] = n.render);
@@ -169,7 +106,7 @@ var w = () => document.documentElement.dataset[ve] === "true", T = null, E = (e)
169
106
  })();
170
107
  //#endregion
171
108
  //#region node_modules/@mfkn/web-extension/lib/lib/frame.js
172
- var A = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", j = (e) => {
109
+ var C = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", w = (e) => {
173
110
  if (!e || e === "about:blank") return !1;
174
111
  let t;
175
112
  try {
@@ -181,28 +118,28 @@ var A = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", j = (e) => {
181
118
  if (t.protocol === "about:") return !1;
182
119
  let n = t.hostname;
183
120
  return n === "fkn.app" || n.endsWith(".fkn.app");
184
- }, M = (e) => {
185
- if (j(e)) throw Error("attachFrame: refusing to target the extension's own pages or fkn.app");
186
- }, Ae = {
121
+ }, T = (e) => {
122
+ if (w(e)) throw Error("attachFrame: refusing to target the extension's own pages or fkn.app");
123
+ }, ve = {
187
124
  scope: "embed.iframe",
188
125
  category: "embed",
189
126
  severity: 0,
190
127
  title: "Load another website inside this app",
191
128
  description: "Lets the app embed external pages directly inside its own view."
192
- }, je = {
129
+ }, ye = {
193
130
  scope: "embed.open",
194
131
  category: "embed",
195
132
  severity: 0,
196
133
  title: "Open a website inside this app",
197
134
  description: "Lets the app navigate to another site without leaving its window."
198
- }, Me = async ({ iframe: e, domains: t = [] }) => {
135
+ }, be = async ({ iframe: e, domains: t = [] }) => {
199
136
  let n = crypto.randomUUID();
200
- if (M(e.src), await D(), !e.isConnected) throw Error("attachFrame: the iframe must be connected to the document before attaching");
201
- e.dispatchEvent(new CustomEvent(A, { detail: n }));
202
- let { executeLocator: r, ensureLocatorPermission: i, goto: a } = await k.attachFrame({
137
+ if (T(e.src), await v(), !e.isConnected) throw Error("attachFrame: the iframe must be connected to the document before attaching");
138
+ e.dispatchEvent(new CustomEvent(C, { detail: n }));
139
+ let { executeLocator: r, ensureLocatorPermission: i, goto: a } = await y.attachFrame({
203
140
  marker: n,
204
141
  domains: t
205
- }), o = s(r, i), c = (e, t = {}) => (M(e), a({
142
+ }), o = s(r, i), c = (e, t = {}) => (T(e), a({
206
143
  url: e,
207
144
  ...t
208
145
  })), l = () => e.src;
@@ -211,49 +148,99 @@ var A = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", j = (e) => {
211
148
  goto: c,
212
149
  url: l
213
150
  };
214
- }, Ne = { request: (e) => k.requestPermissions(e.map((e) => ({
151
+ }, xe = { request: (e) => y.requestPermissions(e.map((e) => ({
215
152
  key: e.key,
216
153
  scope: e.scope ?? "",
217
154
  reason: e.reason
218
- }))) }, N = async (e) => {
219
- if (typeof window > "u") return !1;
220
- if (w()) return !0;
221
- let t = await S, n = null, r = new Promise((e) => {
222
- n = () => {
223
- w() && e(!0);
224
- }, C.addEventListener("statuschange", n);
225
- }), i = t.showInstallPrompt(e).then(() => !1), a = await Promise.race([r, i]);
226
- return n && C.removeEventListener("statuschange", n), await t.hideInstallPrompt().catch(() => {}), a;
227
- }, P = null;
228
- E(() => (P ||= N().then(() => void 0).finally(() => {
229
- P = null;
230
- }), P));
155
+ }))) }, Se = 32, Ce = typeof CSS < "u" && CSS.supports("clip-path", "path('M0 0H1V1H0Z')"), we = (e) => {
156
+ let t = e.style;
157
+ t.setProperty("display", "block", "important"), t.setProperty("position", "fixed", "important"), t.setProperty("top", "0", "important"), t.setProperty("left", "0", "important"), t.setProperty("width", "100%", "important"), t.setProperty("height", "100%", "important"), t.setProperty("border", "none", "important"), t.setProperty("clip-path", "inset(100%)", "important"), t.setProperty("background", "transparent"), t.setProperty("color-scheme", "normal"), t.setProperty("z-index", "2147483647"), e.setAttribute("title", "FKN");
158
+ }, Te = ({ x: e, y: t, width: n, height: r }) => `M${e} ${t}h${n}v${r}h${-n}Z`, Ee = (e, { modal: t, rects: n }) => {
159
+ if (!Ce) {
160
+ let r = t || n.length > 0;
161
+ e.style.setProperty("pointer-events", r ? "auto" : "none", "important"), e.style.setProperty("visibility", r ? "visible" : "hidden", "important");
162
+ return;
163
+ }
164
+ let r = t ? "none" : n.length === 0 ? "inset(100%)" : `path('${n.map(Te).join("")}')`, i = r === "none" || CSS.supports("clip-path", r) ? r : "inset(100%)";
165
+ e.style.setProperty("clip-path", i, "important");
166
+ }, De = (e) => {
167
+ if (typeof e != "object" || !e) return null;
168
+ let { x: t, y: n, width: r, height: i } = e;
169
+ if (![
170
+ t,
171
+ n,
172
+ r,
173
+ i
174
+ ].every((e) => typeof e == "number" && Number.isFinite(e))) return null;
175
+ let a = window.innerWidth, o = window.innerHeight, s = Math.max(0, Math.min(Math.round(t), a)), c = Math.max(0, Math.min(Math.round(n), o)), l = Math.max(s, Math.min(Math.round(t + r), a)), ee = Math.max(c, Math.min(Math.round(n + i), o));
176
+ return {
177
+ x: s,
178
+ y: c,
179
+ width: l - s,
180
+ height: ee - c
181
+ };
182
+ }, Oe = (e) => {
183
+ if (typeof e != "object" || !e) return null;
184
+ let t = e, n = (Array.isArray(t.rects) ? t.rects.slice(0, Se) : []).map(De).filter((e) => e !== null && e.width > 0 && e.height > 0);
185
+ return {
186
+ modal: t.modal === !0,
187
+ rects: n
188
+ };
189
+ }, E = null, ke = () => E !== null, Ae = (e) => {
190
+ we(e), Ee(e, {
191
+ modal: !1,
192
+ rects: []
193
+ }), E = e;
194
+ }, je = (e) => {
195
+ if (!E) return;
196
+ let t = Oe(e);
197
+ t && Ee(E, t);
198
+ }, Me = "https://fkn.app", D = typeof globalThis < "u" && globalThis.document ? globalThis.document : void 0, Ne = D?.querySelector(`iframe[src="${Me}/api"]`) ?? null, O = D?.createElement("iframe") ?? null;
199
+ !Ne && O && D && (O.src = `${Me}/api`, D.body.appendChild(O));
200
+ var k = Ne ?? O, Pe = k?.contentWindow ?? null;
201
+ k && D && Ae(k);
202
+ var A = (() => {
203
+ if (typeof window < "u") return Pe ? {
204
+ receive: window,
205
+ emit: Pe
206
+ } : void 0;
207
+ if (typeof self < "u") return {
208
+ receive: self,
209
+ emit: self
210
+ };
211
+ })(), Fe = A !== void 0, j = A ? te({}, {
212
+ key: "fkn-api",
213
+ transport: A
214
+ }) : new Promise(() => {});
215
+ j.then((e) => {
216
+ ke() && e.overlay.setHost(je);
217
+ }, () => {});
231
218
  //#endregion
232
- //#region src/lib/fs.ts
233
- var Pe = /* @__PURE__ */ n({
234
- ensureDirectoryPermission: () => Ie,
235
- isLocalDirectorySupported: () => F,
236
- pickLocalDirectory: () => Fe,
237
- queryDirectoryPermission: () => I
238
- }), F = () => typeof window < "u" && "showDirectoryPicker" in window, Fe = async (e = {}) => {
239
- if (!F()) return;
240
- let t = window.showDirectoryPicker;
241
- return t({
242
- mode: "readwrite",
243
- ...e
244
- }).catch((e) => {
245
- if (e?.name !== "AbortError") throw e;
246
- });
247
- }, I = async (e, t = "readwrite") => {
248
- let { queryPermission: n } = e;
249
- return await n?.call(e, { mode: t }) ?? "granted";
250
- }, Ie = async (e, t = "readwrite") => {
251
- if (await I(e, t) === "granted") return !0;
252
- let { requestPermission: n } = e;
253
- return await n?.call(e, { mode: t }) === "granted";
254
- }, Le = new TextEncoder();
219
+ //#region src/lib/fkn-target.ts
220
+ var Ie = ["fkn.app", "fkn.dev"], Le = (e) => {
221
+ let t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n;
222
+ try {
223
+ n = new URL(t);
224
+ } catch {
225
+ return;
226
+ }
227
+ let r = n.hostname;
228
+ if (Ie.some((e) => r === e || r.endsWith(`.${e}`))) throw Error(`fetch refuses FKN platform domains (${r})`);
229
+ }, M = (e, t) => (Le(e), j.then((n) => n.cloud.fetch(e, t))), Re = async () => {
230
+ let e = await j.then((e) => e.cloud.quota());
231
+ return {
232
+ premium: e.premium,
233
+ overQuota: e.overQuota,
234
+ throttled: e.overQuota && !e.premium,
235
+ usedBytes: e.usedBytes,
236
+ limitBytes: e.limitBytes,
237
+ remainingBytes: e.remaining,
238
+ bytesPerSecond: e.bytesPerSecond,
239
+ bitsPerSecond: e.bytesPerSecond * 8
240
+ };
241
+ }, ze = /* @__PURE__ */ n({ lookup: () => Be }), Be = (e, t) => j.then((n) => n.cloud.dns.lookup(e, t)), Ve = new TextEncoder();
255
242
  new TextDecoder();
256
- var L = (e) => f.isValid(e), R = (e) => p.isValid(e), Re = (e) => L(e) ? 4 : R(e) ? 6 : 0, ze = (...e) => {
243
+ var N = (e) => d.isValid(e), P = (e) => f.isValid(e), He = (e) => N(e) ? 4 : P(e) ? 6 : 0, Ue = (...e) => {
257
244
  if (typeof e[0] == "string") throw Error("FKN WebVPN does not support IPC connections");
258
245
  let t = typeof e.at(-1) == "function" ? e.at(-1) : void 0;
259
246
  return e[0] && typeof e[0] == "object" ? {
@@ -264,7 +251,7 @@ var L = (e) => f.isValid(e), R = (e) => p.isValid(e), Re = (e) => L(e) ? 4 : R(e
264
251
  host: typeof e[1] == "string" ? e[1] : void 0,
265
252
  callback: t
266
253
  };
267
- }, Be = (...e) => {
254
+ }, We = (...e) => {
268
255
  let t = typeof e.at(-1) == "function" ? e.at(-1) : void 0, n = e[0] ?? 0, r = typeof e[1] == "string" ? e[1] : void 0;
269
256
  return typeof e[0] == "object" ? {
270
257
  ...e[0],
@@ -276,7 +263,7 @@ var L = (e) => f.isValid(e), R = (e) => p.isValid(e), Re = (e) => L(e) ? 4 : R(e
276
263
  port: n,
277
264
  callback: t
278
265
  };
279
- }, Ve = (...e) => {
266
+ }, Ge = (...e) => {
280
267
  let t = typeof e.at(-1) == "function" ? e.at(-1) : void 0, n = e[0];
281
268
  if (typeof e[2] == "number") return {
282
269
  message: n,
@@ -301,18 +288,18 @@ var L = (e) => f.isValid(e), R = (e) => p.isValid(e), Re = (e) => L(e) ? 4 : R(e
301
288
  new TextEncoder(), new TextDecoder();
302
289
  //#endregion
303
290
  //#region src/lib/webvpn/net.ts
304
- var He = /* @__PURE__ */ n({
305
- Server: () => B,
306
- Socket: () => z,
307
- _default: () => Ke,
308
- connect: () => Ue,
309
- createConnection: () => We,
310
- createServer: () => Ge,
311
- default: () => Ke,
312
- isIP: () => Re,
313
- isIPv4: () => L,
314
- isIPv6: () => R
315
- }), z = class extends u.Duplex {
291
+ var Ke = /* @__PURE__ */ n({
292
+ Server: () => I,
293
+ Socket: () => F,
294
+ _default: () => Ye,
295
+ connect: () => qe,
296
+ createConnection: () => Je,
297
+ createServer: () => L,
298
+ default: () => Ye,
299
+ isIP: () => He,
300
+ isIPv4: () => N,
301
+ isIPv6: () => P
302
+ }), F = class extends u.Duplex {
316
303
  _localAddress;
317
304
  _remoteAddress;
318
305
  _webVPNTcpSocketPromise;
@@ -372,7 +359,7 @@ var He = /* @__PURE__ */ n({
372
359
  }).catch(n);
373
360
  }
374
361
  connect(...e) {
375
- let t = ze(...e), n = this.__webvpn_tcp_socket_init__(S.then((e) => e.webVpnTcpSocket({
362
+ let t = Ue(...e), n = this.__webvpn_tcp_socket_init__(j.then((e) => e.cloud.webvpn.tcpSocket({
376
363
  remoteAddress: t.host ?? "localhost",
377
364
  remotePort: t.port
378
365
  })));
@@ -499,7 +486,7 @@ var He = /* @__PURE__ */ n({
499
486
  return this._remoteAddress.family;
500
487
  }
501
488
  timeout;
502
- }, B = class extends d {
489
+ }, I = class extends re {
503
490
  _localAddress;
504
491
  _webVPNTcpSocketListenerPromise;
505
492
  constructor(e, t) {
@@ -517,10 +504,10 @@ var He = /* @__PURE__ */ n({
517
504
  }), this._webVPNTcpSocketListenerPromise;
518
505
  }
519
506
  listen(...e) {
520
- let t = ze(...e), n = (e) => {
521
- let t = new z({ connection: Promise.resolve(e) });
507
+ let t = Ue(...e), n = (e) => {
508
+ let t = new F({ connection: Promise.resolve(e) });
522
509
  this.emit("connection", t);
523
- }, r = (e) => S.then((r) => r.webVpnTcpSocketListener({
510
+ }, r = (e) => j.then((r) => r.cloud.webvpn.tcpSocketListener({
524
511
  localAddress: e,
525
512
  localPort: t.port,
526
513
  onConnection: n
@@ -554,23 +541,23 @@ var He = /* @__PURE__ */ n({
554
541
  connections;
555
542
  listening;
556
543
  async [Symbol.asyncDispose]() {}
557
- }, Ue = (e, t) => new z().connect(e, t), We = (e, t) => new z().connect(e, t), Ge = (e, t) => {
544
+ }, qe = (e, t) => new F().connect(e, t), Je = (e, t) => new F().connect(e, t), L = (e, t) => {
558
545
  typeof e == "function" && (t = e, e = void 0);
559
- let n = new B(e);
546
+ let n = new I(e);
560
547
  return t && n.on("connection", t), n;
561
- }, Ke = {
562
- Socket: z,
563
- Server: B,
564
- connect: Ue,
565
- createConnection: We,
566
- createServer: Ge,
567
- isIP: Re,
568
- isIPv4: L,
569
- isIPv6: R
570
- }, qe = /* @__PURE__ */ n({
571
- Socket: () => Je,
572
- createSocket: () => Xe
573
- }), Je = class extends d {
548
+ }, Ye = {
549
+ Socket: F,
550
+ Server: I,
551
+ connect: qe,
552
+ createConnection: Je,
553
+ createServer: L,
554
+ isIP: He,
555
+ isIPv4: N,
556
+ isIPv6: P
557
+ }, Xe = /* @__PURE__ */ n({
558
+ Socket: () => Ze,
559
+ createSocket: () => $e
560
+ }), Ze = class extends re {
574
561
  _type;
575
562
  _localAddress;
576
563
  _remoteAddress;
@@ -598,8 +585,8 @@ var He = /* @__PURE__ */ n({
598
585
  });
599
586
  }
600
587
  addMembership(e, t) {
601
- if (f.isValid(e)) {
602
- let n = V(e), r = t && f.isValid(t) ? V(t) : new Uint8Array([
588
+ if (d.isValid(e)) {
589
+ let n = R(e), r = t && d.isValid(t) ? R(t) : new Uint8Array([
603
590
  0,
604
591
  0,
605
592
  0,
@@ -610,8 +597,8 @@ var He = /* @__PURE__ */ n({
610
597
  group: n,
611
598
  interface: r
612
599
  });
613
- } else if (p.isValid(e)) {
614
- let t = Ye(e);
600
+ } else if (f.isValid(e)) {
601
+ let t = Qe(e);
615
602
  this._setUdpOption({
616
603
  type: 7,
617
604
  group: t,
@@ -624,15 +611,15 @@ var He = /* @__PURE__ */ n({
624
611
  return this._localAddress;
625
612
  }
626
613
  bind(...e) {
627
- let t = Be(...e), n = this._type === "udp6" ? "::" : "0.0.0.0";
628
- return this._webVPNUdpSocketPromise = S.then((e) => e.webVpnUdpSocket({
614
+ let t = We(...e), n = this._type === "udp6" ? "::" : "0.0.0.0";
615
+ return this._webVPNUdpSocketPromise = j.then((e) => e.cloud.webvpn.udpSocket({
629
616
  type: this._type,
630
617
  address: t.address ?? n,
631
618
  port: t.port
632
619
  })).then((e) => {
633
620
  let t = e.dataReadableStream.getReader(), n = async () => {
634
621
  let { value: e, done: r } = await t.read();
635
- r || (this.emit("message", m.from(e.data), {
622
+ r || (this.emit("message", p.from(e.data), {
636
623
  address: e.address,
637
624
  family: e.family,
638
625
  port: e.port,
@@ -685,8 +672,8 @@ var He = /* @__PURE__ */ n({
685
672
  });
686
673
  }
687
674
  dropMembership(e, t) {
688
- if (f.isValid(e)) {
689
- let n = V(e), r = t && f.isValid(t) ? V(t) : new Uint8Array([
675
+ if (d.isValid(e)) {
676
+ let n = R(e), r = t && d.isValid(t) ? R(t) : new Uint8Array([
690
677
  0,
691
678
  0,
692
679
  0,
@@ -697,8 +684,8 @@ var He = /* @__PURE__ */ n({
697
684
  group: n,
698
685
  interface: r
699
686
  });
700
- } else if (p.isValid(e)) {
701
- let t = Ye(e);
687
+ } else if (f.isValid(e)) {
688
+ let t = Qe(e);
702
689
  this._setUdpOption({
703
690
  type: 8,
704
691
  group: t,
@@ -731,11 +718,11 @@ var He = /* @__PURE__ */ n({
731
718
  }
732
719
  send(...e) {
733
720
  this._webVPNUdpSocketPromise || this.bind();
734
- let t = Ve(...e), n = this._type === "udp6" ? "::1" : "127.0.0.1";
721
+ let t = Ge(...e), n = this._type === "udp6" ? "::1" : "127.0.0.1";
735
722
  if (!this._webVPNUdpSocketPromise) throw Error("Socket not bound");
736
723
  this._webVPNUdpSocketPromise.then((e) => {
737
724
  if (!e) throw Error("Socket not bound");
738
- let r = typeof t.message == "string" ? Le.encode(t.message) : t.message;
725
+ let r = typeof t.message == "string" ? Ve.encode(t.message) : t.message;
739
726
  e.send({
740
727
  ...t,
741
728
  address: t.address ?? n,
@@ -793,33 +780,33 @@ var He = /* @__PURE__ */ n({
793
780
  this.close(e);
794
781
  });
795
782
  }
796
- }, V = (e) => {
783
+ }, R = (e) => {
797
784
  let t = e.split(".").map((e) => parseInt(e, 10));
798
785
  if (t.length !== 4 || t.some((e) => Number.isNaN(e) || e < 0 || e > 255)) throw Error(`Invalid IPv4 address: ${e}`);
799
786
  return new Uint8Array(t);
800
- }, Ye = (e) => {
801
- let t = new p(e).getBitsBase16(0, 128).match(/.{2}/g);
787
+ }, Qe = (e) => {
788
+ let t = new f(e).getBitsBase16(0, 128).match(/.{2}/g);
802
789
  if (!t || t.length !== 16) throw Error(`Invalid IPv6 address: ${e}`);
803
790
  return new Uint8Array(t.map((e) => parseInt(e, 16)));
804
- }, Xe = (e, t) => {
805
- let n = new Je(typeof e == "string" ? { type: e } : e);
791
+ }, $e = (e, t) => {
792
+ let n = new Ze(typeof e == "string" ? { type: e } : e);
806
793
  return t && n.on("message", t), n;
807
- }, Ze = /* @__PURE__ */ n({
808
- Agent: () => Q,
809
- ClientRequest: () => X,
810
- HTTPParser: () => K,
811
- IncomingMessage: () => q,
812
- METHODS: () => $e,
813
- STATUS_CODES: () => H,
814
- Server: () => Z,
815
- ServerResponse: () => Y,
816
- _default: () => ut,
817
- createServer: () => lt,
818
- default: () => ut,
819
- get: () => ct,
820
- globalAgent: () => st,
821
- request: () => $
822
- }), Qe = new TextDecoder("latin1"), $e = /* @__PURE__ */ "ACL.BIND.CHECKOUT.CONNECT.COPY.DELETE.GET.HEAD.LINK.LOCK.M-SEARCH.MERGE.MKACTIVITY.MKCALENDAR.MKCOL.MOVE.NOTIFY.OPTIONS.PATCH.POST.PROPFIND.PROPPATCH.PURGE.PUT.REBIND.REPORT.SEARCH.SOURCE.SUBSCRIBE.TRACE.UNBIND.UNLINK.UNLOCK.UNSUBSCRIBE".split("."), H = {
794
+ }, et = /* @__PURE__ */ n({
795
+ Agent: () => Y,
796
+ ClientRequest: () => q,
797
+ HTTPParser: () => U,
798
+ IncomingMessage: () => W,
799
+ METHODS: () => nt,
800
+ STATUS_CODES: () => z,
801
+ Server: () => J,
802
+ ServerResponse: () => K,
803
+ _default: () => pt,
804
+ createServer: () => ft,
805
+ default: () => pt,
806
+ get: () => dt,
807
+ globalAgent: () => ut,
808
+ request: () => X
809
+ }), tt = new TextDecoder("latin1"), nt = /* @__PURE__ */ "ACL.BIND.CHECKOUT.CONNECT.COPY.DELETE.GET.HEAD.LINK.LOCK.M-SEARCH.MERGE.MKACTIVITY.MKCALENDAR.MKCOL.MOVE.NOTIFY.OPTIONS.PATCH.POST.PROPFIND.PROPPATCH.PURGE.PUT.REBIND.REPORT.SEARCH.SOURCE.SUBSCRIBE.TRACE.UNBIND.UNLINK.UNLOCK.UNSUBSCRIBE".split("."), z = {
823
810
  100: "Continue",
824
811
  101: "Switching Protocols",
825
812
  102: "Processing",
@@ -883,7 +870,7 @@ var He = /* @__PURE__ */ n({
883
870
  509: "Bandwidth Limit Exceeded",
884
871
  510: "Not Extended",
885
872
  511: "Network Authentication Required"
886
- }, et = new Set([
873
+ }, rt = new Set([
887
874
  "content-type",
888
875
  "content-length",
889
876
  "user-agent",
@@ -902,18 +889,18 @@ var He = /* @__PURE__ */ n({
902
889
  "server",
903
890
  "age",
904
891
  "expires"
905
- ]), U = 13, W = 10, tt = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/, G = (e, t) => (e.code = t, e), nt = (e, t) => {
892
+ ]), B = 13, V = 10, it = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/, H = (e, t) => (e.code = t, e), at = (e, t) => {
906
893
  if (e.length === 0) return t;
907
894
  if (t.length === 0) return e;
908
895
  let n = new Uint8Array(e.length + t.length);
909
896
  return n.set(e, 0), n.set(t, e.length), n;
910
- }, rt = (e, t) => {
911
- for (let n = t; n + 1 < e.length; n++) if (e[n] === U && e[n + 1] === W) return n;
897
+ }, ot = (e, t) => {
898
+ for (let n = t; n + 1 < e.length; n++) if (e[n] === B && e[n + 1] === V) return n;
912
899
  return -1;
913
- }, it = (e) => {
914
- for (let t = 0; t + 3 < e.length; t++) if (e[t] === U && e[t + 1] === W && e[t + 2] === U && e[t + 3] === W) return t;
900
+ }, st = (e) => {
901
+ for (let t = 0; t + 3 < e.length; t++) if (e[t] === B && e[t + 1] === V && e[t + 2] === B && e[t + 3] === V) return t;
915
902
  return -1;
916
- }, K = class {
903
+ }, U = class {
917
904
  buf = new Uint8Array();
918
905
  state = "HEAD";
919
906
  framing = "none";
@@ -924,10 +911,10 @@ var He = /* @__PURE__ */ n({
924
911
  this.mode = e, this.handlers = t;
925
912
  }
926
913
  execute(e) {
927
- this.buf = nt(this.buf, e);
914
+ this.buf = at(this.buf, e);
928
915
  let t = !0;
929
916
  for (; t;) if (t = !1, this.state === "HEAD") {
930
- let e = it(this.buf);
917
+ let e = st(this.buf);
931
918
  if (e === -1) return;
932
919
  let n = this.buf.subarray(0, e);
933
920
  this.buf = this.buf.subarray(e + 4);
@@ -942,7 +929,7 @@ var He = /* @__PURE__ */ n({
942
929
  this.state = "HEAD", this.framing = "none", this.bodyRemaining = 0, this.chunkState = "size", this.skipBody = !1;
943
930
  }
944
931
  parseHead(e) {
945
- let t = Qe.decode(e).split("\r\n"), n = t.shift() ?? "", r = [];
932
+ let t = tt.decode(e).split("\r\n"), n = t.shift() ?? "", r = [];
946
933
  for (let e of t) (e.startsWith(" ") || e.startsWith(" ")) && r.length > 0 ? r[r.length - 1] += " " + e.trim() : r.push(e);
947
934
  let i = [], a = {};
948
935
  for (let e of r) {
@@ -980,7 +967,7 @@ var He = /* @__PURE__ */ n({
980
967
  return;
981
968
  }
982
969
  let i = e[r];
983
- i === void 0 ? e[r] = n : et.has(r) || (e[r] = `${i}, ${n}`);
970
+ i === void 0 ? e[r] = n : rt.has(r) || (e[r] = `${i}, ${n}`);
984
971
  }
985
972
  setupBody(e) {
986
973
  if (this.skipBody) {
@@ -1013,9 +1000,9 @@ var He = /* @__PURE__ */ n({
1013
1000
  }
1014
1001
  consumeChunked() {
1015
1002
  for (;;) if (this.chunkState === "size") {
1016
- let e = rt(this.buf, 0);
1003
+ let e = ot(this.buf, 0);
1017
1004
  if (e === -1) return !1;
1018
- let t = Qe.decode(this.buf.subarray(0, e)), n = parseInt(t.split(";")[0].trim(), 16);
1005
+ let t = tt.decode(this.buf.subarray(0, e)), n = parseInt(t.split(";")[0].trim(), 16);
1019
1006
  if (this.buf = this.buf.subarray(e + 2), Number.isNaN(n)) return !0;
1020
1007
  n === 0 ? this.chunkState = "trailer" : (this.bodyRemaining = n, this.chunkState = "data");
1021
1008
  } else if (this.chunkState === "data") {
@@ -1026,13 +1013,13 @@ var He = /* @__PURE__ */ n({
1026
1013
  if (this.buf.length < 2) return !1;
1027
1014
  this.buf = this.buf.subarray(2), this.chunkState = "size";
1028
1015
  } else {
1029
- let e = rt(this.buf, 0);
1016
+ let e = ot(this.buf, 0);
1030
1017
  if (e === -1) return !1;
1031
1018
  let t = e === 0;
1032
1019
  if (this.buf = this.buf.subarray(e + 2), t) return !0;
1033
1020
  }
1034
1021
  }
1035
- }, at = (e, t) => m.isBuffer(e) ? e : typeof e == "string" ? m.from(e, t ?? "utf8") : e instanceof Uint8Array ? m.from(e) : e instanceof ArrayBuffer ? m.from(new Uint8Array(e)) : m.from(String(e)), q = class extends u.Readable {
1022
+ }, ct = (e, t) => p.isBuffer(e) ? e : typeof e == "string" ? p.from(e, t ?? "utf8") : e instanceof Uint8Array ? p.from(e) : e instanceof ArrayBuffer ? p.from(new Uint8Array(e)) : p.from(String(e)), W = class extends u.Readable {
1036
1023
  httpVersion = "1.1";
1037
1024
  httpVersionMajor = 1;
1038
1025
  httpVersionMinor = 1;
@@ -1059,16 +1046,16 @@ var He = /* @__PURE__ */ n({
1059
1046
  setTimeout(e, t) {
1060
1047
  return this.socket.setTimeout(e, t), this;
1061
1048
  }
1062
- }, J = class extends u.Writable {
1049
+ }, G = class extends u.Writable {
1063
1050
  _headerStore = /* @__PURE__ */ new Map();
1064
1051
  headersSent = !1;
1065
1052
  chunkedEncoding = !1;
1066
1053
  finished = !1;
1067
1054
  _bodyWritten = !1;
1068
1055
  setHeader(e, t) {
1069
- if (this.headersSent) throw G(/* @__PURE__ */ Error("Cannot set headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
1070
- if (typeof e != "string" || !tt.test(e)) throw G(/* @__PURE__ */ TypeError(`Header name must be a valid HTTP token [${JSON.stringify(String(e))}]`), "ERR_INVALID_HTTP_TOKEN");
1071
- if (t === void 0) throw G(/* @__PURE__ */ TypeError(`Invalid value "undefined" for header "${e}"`), "ERR_HTTP_INVALID_HEADER_VALUE");
1056
+ if (this.headersSent) throw H(/* @__PURE__ */ Error("Cannot set headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
1057
+ if (typeof e != "string" || !it.test(e)) throw H(/* @__PURE__ */ TypeError(`Header name must be a valid HTTP token [${JSON.stringify(String(e))}]`), "ERR_INVALID_HTTP_TOKEN");
1058
+ if (t === void 0) throw H(/* @__PURE__ */ TypeError(`Invalid value "undefined" for header "${e}"`), "ERR_HTTP_INVALID_HEADER_VALUE");
1072
1059
  return this._headerStore.set(e.toLowerCase(), [e, Array.isArray(t) ? [...t] : t]), this;
1073
1060
  }
1074
1061
  getHeader(e) {
@@ -1108,30 +1095,30 @@ var He = /* @__PURE__ */ n({
1108
1095
  return this._bodyWritten = !0, super.write(e, t, n);
1109
1096
  }
1110
1097
  _write(e, t, n) {
1111
- let r = at(e), i = [];
1112
- if (this.headersSent ||= (this._implicitHeader(), i.push(m.from(this._headBlock, "latin1")), !0), this.chunkedEncoding ? r.length > 0 && (i.push(m.from(`${r.length.toString(16)}\r\n`, "latin1")), i.push(r), i.push(m.from("\r\n", "latin1"))) : i.push(r), i.length === 0) {
1098
+ let r = ct(e), i = [];
1099
+ if (this.headersSent ||= (this._implicitHeader(), i.push(p.from(this._headBlock, "latin1")), !0), this.chunkedEncoding ? r.length > 0 && (i.push(p.from(`${r.length.toString(16)}\r\n`, "latin1")), i.push(r), i.push(p.from("\r\n", "latin1"))) : i.push(r), i.length === 0) {
1113
1100
  n();
1114
1101
  return;
1115
1102
  }
1116
- this._writeToSocket(m.concat(i), n);
1103
+ this._writeToSocket(p.concat(i), n);
1117
1104
  }
1118
1105
  _final(e) {
1119
1106
  let t = [];
1120
- if (this.headersSent ||= (!this.chunkedEncoding && !this.hasHeader("content-length") && this.setHeader("Content-Length", 0), this._implicitHeader(), t.push(m.from(this._headBlock, "latin1")), !0), this.chunkedEncoding && t.push(m.from("0\r\n\r\n", "latin1")), this.finished = !0, t.length === 0) {
1107
+ if (this.headersSent ||= (!this.chunkedEncoding && !this.hasHeader("content-length") && this.setHeader("Content-Length", 0), this._implicitHeader(), t.push(p.from(this._headBlock, "latin1")), !0), this.chunkedEncoding && t.push(p.from("0\r\n\r\n", "latin1")), this.finished = !0, t.length === 0) {
1121
1108
  e();
1122
1109
  return;
1123
1110
  }
1124
- this._writeToSocket(m.concat(t), e);
1111
+ this._writeToSocket(p.concat(t), e);
1125
1112
  }
1126
1113
  end(e, t, n) {
1127
1114
  if (e != null && typeof e != "function" && !this._bodyWritten && !this.headersSent && !this.chunkedEncoding && !this.hasHeader("content-length")) {
1128
1115
  let n = typeof t == "string" ? t : void 0;
1129
- this.setHeader("Content-Length", at(e, n).length);
1116
+ this.setHeader("Content-Length", ct(e, n).length);
1130
1117
  }
1131
1118
  return super.end(e, t, n);
1132
1119
  }
1133
1120
  _headBlock;
1134
- }, Y = class extends J {
1121
+ }, K = class extends G {
1135
1122
  statusCode = 200;
1136
1123
  statusMessage;
1137
1124
  _writeHeadCalled = !1;
@@ -1148,7 +1135,7 @@ var He = /* @__PURE__ */ n({
1148
1135
  return !(e >= 100 && e < 200 || e === 204 || e === 304);
1149
1136
  }
1150
1137
  writeHead(e, t, n) {
1151
- if (this._writeHeadCalled || this.headersSent) throw G(/* @__PURE__ */ Error("Cannot render headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
1138
+ if (this._writeHeadCalled || this.headersSent) throw H(/* @__PURE__ */ Error("Cannot render headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
1152
1139
  this._writeHeadCalled = !0, this.statusCode = e;
1153
1140
  let r = n;
1154
1141
  if (typeof t == "string" ? this.statusMessage = t : t != null && (r = t), Array.isArray(r)) {
@@ -1166,16 +1153,16 @@ var He = /* @__PURE__ */ n({
1166
1153
  }
1167
1154
  }
1168
1155
  _implicitHeader() {
1169
- let e = this.statusMessage ?? H[this.statusCode] ?? "unknown";
1156
+ let e = this.statusMessage ?? z[this.statusCode] ?? "unknown";
1170
1157
  this.sendDate && !this.hasHeader("date") && this.setHeader("Date", (/* @__PURE__ */ new Date()).toUTCString()), this.hasHeader("connection") || this.setHeader("Connection", this._keepAlive ? "keep-alive" : "close"), this._headBlock = this._storeHeader(`HTTP/1.1 ${this.statusCode} ${e}`);
1171
1158
  }
1172
1159
  writeContinue() {
1173
- this._writeToSocket(m.from("HTTP/1.1 100 Continue\r\n\r\n", "latin1"), () => {});
1160
+ this._writeToSocket(p.from("HTTP/1.1 100 Continue\r\n\r\n", "latin1"), () => {});
1174
1161
  }
1175
1162
  setTimeout(e, t) {
1176
1163
  return this.socket?.setTimeout(e, t), this;
1177
1164
  }
1178
- }, ot = (...e) => {
1165
+ }, lt = (...e) => {
1179
1166
  let t = {}, n = {}, r, i = [...e], a = i.shift();
1180
1167
  if (typeof a == "string" || a instanceof URL) {
1181
1168
  let e = typeof a == "string" ? new URL(a) : a;
@@ -1197,7 +1184,7 @@ var He = /* @__PURE__ */ n({
1197
1184
  },
1198
1185
  callback: r
1199
1186
  };
1200
- }, X = class extends J {
1187
+ }, q = class extends G {
1201
1188
  method;
1202
1189
  path;
1203
1190
  host;
@@ -1219,7 +1206,7 @@ var He = /* @__PURE__ */ n({
1219
1206
  let e = this.protocol === "https:" && r === 443 || this.protocol !== "https:" && r === 80;
1220
1207
  this.setHeader("Host", e ? n : `${n}:${r}`);
1221
1208
  }
1222
- e.auth && !this.hasHeader("authorization") && this.setHeader("Authorization", `Basic ${m.from(e.auth).toString("base64")}`), this.socket = new z(), this.emit("socket", this.socket), this.socket.on("error", (e) => {
1209
+ e.auth && !this.hasHeader("authorization") && this.setHeader("Authorization", `Basic ${p.from(e.auth).toString("base64")}`), this.socket = new F(), this.emit("socket", this.socket), this.socket.on("error", (e) => {
1223
1210
  this._aborted || this.emit("error", e);
1224
1211
  }), this._attachResponseParser(), this.socket.connect({
1225
1212
  host: n,
@@ -1235,12 +1222,12 @@ var He = /* @__PURE__ */ n({
1235
1222
  this._headBlock = this._storeHeader(`${this.method} ${this.path} HTTP/1.1`);
1236
1223
  }
1237
1224
  _attachResponseParser() {
1238
- let e = new q(this.socket), t = new K("response", {
1225
+ let e = new W(this.socket), t = new U("response", {
1239
1226
  onHeaders: (n) => {
1240
1227
  e._applyHead(n), this.method === "HEAD" && (t.skipBody = !0), this.res = e, this.emit("response", e);
1241
1228
  },
1242
1229
  onBody: (t) => {
1243
- e.push(m.from(t));
1230
+ e.push(p.from(t));
1244
1231
  },
1245
1232
  onComplete: () => {
1246
1233
  e.complete = !0, e.push(null);
@@ -1279,22 +1266,22 @@ var He = /* @__PURE__ */ n({
1279
1266
  setSocketKeepAlive(e, t) {
1280
1267
  this.socket.setKeepAlive(e, t);
1281
1268
  }
1282
- }, Z = new Proxy(class extends B {
1269
+ }, J = new Proxy(class extends I {
1283
1270
  constructor(e, t) {
1284
1271
  let n = {}, r = t;
1285
1272
  typeof e == "function" ? r = e : e && (n = e), super(n), r && this.on("request", r), this.on("connection", (e) => this._handleConnection(e));
1286
1273
  }
1287
1274
  _handleConnection(e) {
1288
- let t = null, n = new K("request", {
1275
+ let t = null, n = new U("request", {
1289
1276
  onHeaders: (r) => {
1290
- t = new q(e), t._applyHead(r), r.method === "HEAD" && (n.skipBody = !0);
1291
- let i = new Y(t), a = String(r.headers.connection ?? "").toLowerCase();
1277
+ t = new W(e), t._applyHead(r), r.method === "HEAD" && (n.skipBody = !0);
1278
+ let i = new K(t), a = String(r.headers.connection ?? "").toLowerCase();
1292
1279
  i._keepAlive = r.httpVersionMinor >= 1 ? a !== "close" : a === "keep-alive", i.on("finish", () => {
1293
1280
  i._keepAlive || e.end();
1294
1281
  }), this.emit("request", t, i);
1295
1282
  },
1296
1283
  onBody: (e) => {
1297
- t?.push(m.from(e));
1284
+ t?.push(p.from(e));
1298
1285
  },
1299
1286
  onComplete: () => {
1300
1287
  t && (t.complete = !0, t.push(null)), t = null;
@@ -1304,7 +1291,7 @@ var He = /* @__PURE__ */ n({
1304
1291
  n.finish(), t && t.push(null);
1305
1292
  }), e.on("error", (t) => this.emit("clientError", t, e));
1306
1293
  }
1307
- }, { apply: (e, t, n) => new e(...n) }), Q = class {
1294
+ }, { apply: (e, t, n) => new e(...n) }), Y = class {
1308
1295
  maxSockets;
1309
1296
  maxFreeSockets;
1310
1297
  keepAlive;
@@ -1316,25 +1303,139 @@ var He = /* @__PURE__ */ n({
1316
1303
  return `${e.host ?? "localhost"}:${e.port ?? ""}:${e.localAddress ?? ""}`;
1317
1304
  }
1318
1305
  destroy() {}
1319
- }, st = new Q(), $ = (...e) => {
1320
- let { options: t, callback: n } = ot(...e);
1321
- return new X(t, n);
1322
- }, ct = (...e) => {
1323
- let t = $(...e);
1306
+ }, ut = new Y(), X = (...e) => {
1307
+ let { options: t, callback: n } = lt(...e);
1308
+ return new q(t, n);
1309
+ }, dt = (...e) => {
1310
+ let t = X(...e);
1324
1311
  return t.end(), t;
1325
- }, lt = (e, t) => new Z(e, t), ut = {
1326
- METHODS: $e,
1327
- STATUS_CODES: H,
1328
- Agent: Q,
1329
- globalAgent: st,
1330
- Server: Z,
1331
- ServerResponse: Y,
1332
- IncomingMessage: q,
1333
- ClientRequest: X,
1334
- OutgoingMessage: J,
1335
- createServer: lt,
1336
- request: $,
1337
- get: ct
1312
+ }, ft = (e, t) => new J(e, t), pt = {
1313
+ METHODS: nt,
1314
+ STATUS_CODES: z,
1315
+ Agent: Y,
1316
+ globalAgent: ut,
1317
+ Server: J,
1318
+ ServerResponse: K,
1319
+ IncomingMessage: W,
1320
+ ClientRequest: q,
1321
+ OutgoingMessage: G,
1322
+ createServer: ft,
1323
+ request: X,
1324
+ get: dt
1325
+ }, mt = /* @__PURE__ */ n({
1326
+ available: () => ht,
1327
+ dgram: () => Xe,
1328
+ dns: () => ze,
1329
+ fetch: () => M,
1330
+ http: () => et,
1331
+ net: () => Ke,
1332
+ quota: () => Re
1333
+ }), ht = () => Fe, Z = async (e) => {
1334
+ if (typeof window > "u") return !1;
1335
+ if (h()) return !0;
1336
+ let t = await j, n = null, r = new Promise((e) => {
1337
+ n = () => {
1338
+ h() && e(!0);
1339
+ }, m.addEventListener("statuschange", n);
1340
+ }), i = t.installPrompt.show(e).then(() => !1), a = await Promise.race([r, i]);
1341
+ return n && m.removeEventListener("statuschange", n), await t.installPrompt.hide().catch(() => {}), a;
1342
+ }, Q = null;
1343
+ _(() => (Q ||= Z().then(() => void 0).finally(() => {
1344
+ Q = null;
1345
+ }), Q));
1346
+ //#endregion
1347
+ //#region src/lib/desktop.ts
1348
+ var gt = /* @__PURE__ */ n({
1349
+ available: () => _t,
1350
+ dgram: () => xt,
1351
+ dns: () => yt,
1352
+ fetch: () => vt,
1353
+ fs: () => St,
1354
+ net: () => bt
1355
+ }), _t = () => !1, $ = (e) => (...t) => {
1356
+ throw Error(`The FKN desktop app is not connected, desktop.${e} is unavailable`);
1357
+ }, vt = $("fetch"), yt = { lookup: $("dns.lookup") }, bt = {
1358
+ connect: $("net.connect"),
1359
+ createConnection: $("net.createConnection"),
1360
+ createServer: $("net.createServer")
1361
+ }, xt = { createSocket: $("dgram.createSocket") }, St = {
1362
+ isLocalDirectorySupported: () => !1,
1363
+ pickLocalDirectory: $("fs.pickLocalDirectory"),
1364
+ queryDirectoryPermission: $("fs.queryDirectoryPermission"),
1365
+ ensureDirectoryPermission: $("fs.ensureDirectoryPermission")
1366
+ }, Ct = () => typeof document < "u" && h(), wt = async (e, t) => {
1367
+ if (Le(e), t?.credentials === "include") {
1368
+ if (typeof document > "u") throw Error("fetch with credentials needs the FKN extension, which only exists in window realms");
1369
+ return S(e, t);
1370
+ }
1371
+ return Ct() ? S(e, {
1372
+ ...t,
1373
+ credentials: "omit"
1374
+ }) : _t() ? vt(e, t) : M(e, t);
1375
+ }, Tt = /* @__PURE__ */ n({
1376
+ ATTACH_FRAME_EVENT_KEY: () => C,
1377
+ assertAttachableFrameUrl: () => T,
1378
+ assertFetchableUrl: () => x,
1379
+ attachFrame: () => be,
1380
+ attachFramePermission: () => ve,
1381
+ available: () => Ct,
1382
+ box: () => l,
1383
+ cookies: () => me,
1384
+ createVideoElementHandle: () => e,
1385
+ events: () => m,
1386
+ extension: () => m,
1387
+ fetch: () => S,
1388
+ fetchCredentialedPermission: () => le,
1389
+ fetchPermission: () => ce,
1390
+ gotoPermission: () => ye,
1391
+ handleRevivableModules: () => i,
1392
+ isBlockedFetchUrl: () => b,
1393
+ isBlockedFrameUrl: () => w,
1394
+ isExtensionExposed: () => h,
1395
+ isType: () => t,
1396
+ modifyRequestHeadersPermission: () => he,
1397
+ permissions: () => xe,
1398
+ promptInstall: () => Z,
1399
+ readCookiePermission: () => pe,
1400
+ removeRequestHeaderRule: () => _e,
1401
+ revive: () => o,
1402
+ setMissingExtensionHandler: () => _,
1403
+ setRequestHeaderRule: () => ge,
1404
+ type: () => a,
1405
+ waitForExtensionExposure: () => v
1406
+ }), Et = /* @__PURE__ */ n({
1407
+ ensureDirectoryPermission: () => At,
1408
+ isLocalDirectorySupported: () => Dt,
1409
+ pickLocalDirectory: () => Ot,
1410
+ queryDirectoryPermission: () => kt
1411
+ }), Dt = () => typeof window < "u" && "showDirectoryPicker" in window, Ot = async (e = {}) => {
1412
+ if (!Dt()) return;
1413
+ let t = window.showDirectoryPicker;
1414
+ return t({
1415
+ mode: "readwrite",
1416
+ ...e
1417
+ }).catch((e) => {
1418
+ if (e?.name !== "AbortError") throw e;
1419
+ });
1420
+ }, kt = async (e, t = "readwrite") => {
1421
+ let { queryPermission: n } = e;
1422
+ return await n?.call(e, { mode: t }) ?? "granted";
1423
+ }, At = async (e, t = "readwrite") => {
1424
+ if (await kt(e, t) === "granted") return !0;
1425
+ let { requestPermission: n } = e;
1426
+ return await n?.call(e, { mode: t }) === "granted";
1427
+ }, jt = "https://fkn.app", Mt = (e, t) => {
1428
+ if (typeof window > "u") throw Error("FKN @fkn/lib: relayWorker must be called from the main thread");
1429
+ if (!k?.contentWindow) throw Error("FKN @fkn/lib: relayWorker called before the FKN iframe was injected");
1430
+ ne({
1431
+ receive: window,
1432
+ emit: k.contentWindow
1433
+ }, e, {
1434
+ key: "fkn-api",
1435
+ originA: t?.originA ?? jt,
1436
+ originB: t?.originB ?? "*",
1437
+ unregisterSignal: t?.unregisterSignal
1438
+ });
1338
1439
  };
1339
1440
  //#endregion
1340
- export { A as ATTACH_FRAME_EVENT_KEY, M as assertAttachableFrameUrl, Me as attachFrame, Ae as attachFramePermission, l as box, Ee as cookies, e as createVideoElementHandle, qe as dgram, C as extension, we as fetch, xe as fetchCredentialedPermission, be as fetchPermission, Pe as fs, je as gotoPermission, i as handleRevivableModules, Ze as http, j as isBlockedFrameUrl, w as isExtensionExposed, t as isType, De as modifyRequestHeadersPermission, He as net, Ne as permissions, N as promptInstall, Te as readCookiePermission, ge as relayWorker, ke as removeRequestHeaderRule, o as revive, me as serverProxyFetch, E as setMissingExtensionHandler, Oe as setRequestHeaderRule, a as type, D as waitForExtensionExposure };
1441
+ export { C as ATTACH_FRAME_EVENT_KEY, T as assertAttachableFrameUrl, x as assertFetchableUrl, be as attachFrame, ve as attachFramePermission, l as box, mt as cloud, me as cookies, e as createVideoElementHandle, gt as desktop, Xe as dgram, ze as dns, Tt as extension, wt as fetch, le as fetchCredentialedPermission, ce as fetchPermission, Et as fs, ye as gotoPermission, i as handleRevivableModules, et as http, b as isBlockedFetchUrl, w as isBlockedFrameUrl, h as isExtensionExposed, t as isType, he as modifyRequestHeadersPermission, Ke as net, xe as permissions, Z as promptInstall, pe as readCookiePermission, Mt as relayWorker, _e as removeRequestHeaderRule, o as revive, M as serverProxyFetch, _ as setMissingExtensionHandler, ge as setRequestHeaderRule, a as type, v as waitForExtensionExposure };