@fkn/lib 0.3.11 → 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.
package/index.js CHANGED
@@ -1,167 +1,104 @@
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-DhCNXAk2.js";
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`, h = (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
- }, se = (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
- }, ce = (e) => {
36
- if (typeof e != "object" || !e) return null;
37
- let t = e, n = (Array.isArray(t.rects) ? t.rects.slice(0, re) : []).map(se).filter((e) => e !== null && e.width > 0 && e.height > 0);
38
- return {
39
- modal: t.modal === !0,
40
- rects: n
41
- };
42
- }, g = null, le = () => g !== null, ue = (e) => {
43
- ae(e), h(e, {
44
- modal: !1,
45
- rects: []
46
- }), g = e;
47
- }, de = (e) => {
48
- if (!g) return;
49
- let t = ce(e);
50
- t && h(g, t);
51
- }, _ = "https://fkn.app", v = typeof globalThis < "u" && globalThis.document ? globalThis.document : void 0, fe = v?.querySelector(`iframe[src="${_}/api"]`) ?? null, y = v?.createElement("iframe") ?? null;
52
- !fe && y && v && (y.src = `${_}/api`, v.body.appendChild(y));
53
- var b = fe ?? y, pe = b?.contentWindow ?? null;
54
- b && v && ue(b);
55
- var me = (() => {
56
- if (typeof window < "u") return pe ? {
57
- receive: window,
58
- emit: pe
59
- } : void 0;
60
- if (typeof self < "u") return {
61
- receive: self,
62
- emit: self
63
- };
64
- })(), x = me ? te({}, {
65
- key: "fkn-api",
66
- transport: me
67
- }) : new Promise(() => {});
68
- x.then((e) => {
69
- le() && e.setOverlayHost(de);
70
- }, () => {});
71
- //#endregion
72
- //#region src/lib/proxy.ts
73
- var he = (e, t) => x.then((n) => n.proxyFetch(e, t)), ge = "https://fkn.app", _e = (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 ?? ge,
82
- originB: t?.originB ?? "*",
83
- unregisterSignal: t?.unregisterSignal
84
- });
85
- }, ve = "FKN_WEB_EXTENSION_MAIN_WORLD_CONTENT_SCRIPT_ENABLED_EVENT_KEY", ye = "fknExtension", S = ee();
86
- typeof document < "u" && document.addEventListener(ve, (e) => {
87
- S.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 C = () => document.documentElement.dataset[ye] === "true", w = null, T = (e) => {
90
- w = e;
91
- }, be = 150, E = (e = 1e3) => new Promise((t, n) => {
92
- if (C()) 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 (w && (await w().catch(() => {}), C())) 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(() => C() ? i(t) : a(), be);
22
+ clearTimeout(r), r = setTimeout(() => h() ? i(t) : a(), oe);
100
23
  }, s = new MutationObserver(() => {
101
- C() && i(t);
24
+ h() && i(t);
102
25
  }), c = () => {
103
- document.readyState === "complete" && !C() && 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
- C() && i(t);
110
- }), D, O = new Proxy({}, { get: (e, t) => async (...e) => {
111
- await E(), D ??= 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 D)[t];
38
+ let n = (await se)[t];
116
39
  return n(...e);
117
- } }), xe = {
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
- }, Se = {
46
+ }, le = {
124
47
  scope: "network.fetchCredentialed",
125
48
  category: "network",
126
49
  severity: 3,
127
50
  unsafe: !0,
128
- title: "Fetch from other sites signed in as you",
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
- }, Ce = ["origin", "referer"], we = (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 = Ce.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
- }, Te = async (e, t) => {
138
- let n = new Request(e, t), r = n.body ? await n.arrayBuffer() : null;
139
- return O.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: we(t),
83
+ unsafeHeaders: fe(t),
147
84
  reason: t?.reason,
148
85
  signal: t?.signal ?? void 0
149
86
  });
150
- }, Ee = {
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
- }, De = { get: (e) => O.getCookie(e) }, Oe = {
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
- }, ke = (e) => O.setRequestHeaderRule(e), Ae = (e) => O.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 C = () => document.documentElement.dataset[ye] === "true", w = null, T = (e)
169
106
  })();
170
107
  //#endregion
171
108
  //#region node_modules/@mfkn/web-extension/lib/lib/frame.js
172
- var k = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", A = (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 k = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", A = (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
- }, j = (e) => {
185
- if (A(e)) throw Error("attachFrame: refusing to target the extension's own pages or fkn.app");
186
- }, je = {
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
- }, Me = {
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
- }, Ne = async ({ iframe: e, domains: t = [] }) => {
135
+ }, be = async ({ iframe: e, domains: t = [] }) => {
199
136
  let n = crypto.randomUUID();
200
- if (j(e.src), await E(), !e.isConnected) throw Error("attachFrame: the iframe must be connected to the document before attaching");
201
- e.dispatchEvent(new CustomEvent(k, { detail: n }));
202
- let { executeLocator: r, ensureLocatorPermission: i, goto: a } = await O.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 = {}) => (j(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,28 +148,99 @@ var k = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", A = (e) => {
211
148
  goto: c,
212
149
  url: l
213
150
  };
214
- }, Pe = { request: (e) => O.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
- }))) }, M = async (e) => {
219
- if (typeof window > "u") return !1;
220
- if (C()) return !0;
221
- let t = await x, n = null, r = new Promise((e) => {
222
- n = () => {
223
- C() && e(!0);
224
- }, S.addEventListener("statuschange", n);
225
- }), i = t.showInstallPrompt(e).then(() => !1), a = await Promise.race([r, i]);
226
- return n && S.removeEventListener("statuschange", n), await t.hideInstallPrompt().catch(() => {}), a;
227
- }, N = null;
228
- T(() => (N ||= M().then(() => void 0).finally(() => {
229
- N = null;
230
- }), N));
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/webvpn/utils.ts
233
- var Fe = 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();
234
242
  new TextDecoder();
235
- var P = (e) => f.isValid(e), F = (e) => p.isValid(e), I = (e) => P(e) ? 4 : F(e) ? 6 : 0, L = (...e) => {
243
+ var N = (e) => d.isValid(e), P = (e) => f.isValid(e), He = (e) => N(e) ? 4 : P(e) ? 6 : 0, Ue = (...e) => {
236
244
  if (typeof e[0] == "string") throw Error("FKN WebVPN does not support IPC connections");
237
245
  let t = typeof e.at(-1) == "function" ? e.at(-1) : void 0;
238
246
  return e[0] && typeof e[0] == "object" ? {
@@ -243,7 +251,7 @@ var P = (e) => f.isValid(e), F = (e) => p.isValid(e), I = (e) => P(e) ? 4 : F(e)
243
251
  host: typeof e[1] == "string" ? e[1] : void 0,
244
252
  callback: t
245
253
  };
246
- }, Ie = (...e) => {
254
+ }, We = (...e) => {
247
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;
248
256
  return typeof e[0] == "object" ? {
249
257
  ...e[0],
@@ -255,7 +263,7 @@ var P = (e) => f.isValid(e), F = (e) => p.isValid(e), I = (e) => P(e) ? 4 : F(e)
255
263
  port: n,
256
264
  callback: t
257
265
  };
258
- }, Le = (...e) => {
266
+ }, Ge = (...e) => {
259
267
  let t = typeof e.at(-1) == "function" ? e.at(-1) : void 0, n = e[0];
260
268
  if (typeof e[2] == "number") return {
261
269
  message: n,
@@ -280,18 +288,18 @@ var P = (e) => f.isValid(e), F = (e) => p.isValid(e), I = (e) => P(e) ? 4 : F(e)
280
288
  new TextEncoder(), new TextDecoder();
281
289
  //#endregion
282
290
  //#region src/lib/webvpn/net.ts
283
- var Re = /* @__PURE__ */ n({
284
- Server: () => z,
285
- Socket: () => R,
286
- _default: () => He,
287
- connect: () => ze,
288
- createConnection: () => Be,
289
- createServer: () => Ve,
290
- default: () => He,
291
- isIP: () => I,
292
- isIPv4: () => P,
293
- isIPv6: () => F
294
- }), R = 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 {
295
303
  _localAddress;
296
304
  _remoteAddress;
297
305
  _webVPNTcpSocketPromise;
@@ -351,7 +359,7 @@ var Re = /* @__PURE__ */ n({
351
359
  }).catch(n);
352
360
  }
353
361
  connect(...e) {
354
- let t = L(...e), n = this.__webvpn_tcp_socket_init__(x.then((e) => e.webVpnTcpSocket({
362
+ let t = Ue(...e), n = this.__webvpn_tcp_socket_init__(j.then((e) => e.cloud.webvpn.tcpSocket({
355
363
  remoteAddress: t.host ?? "localhost",
356
364
  remotePort: t.port
357
365
  })));
@@ -478,7 +486,7 @@ var Re = /* @__PURE__ */ n({
478
486
  return this._remoteAddress.family;
479
487
  }
480
488
  timeout;
481
- }, z = class extends d {
489
+ }, I = class extends re {
482
490
  _localAddress;
483
491
  _webVPNTcpSocketListenerPromise;
484
492
  constructor(e, t) {
@@ -496,10 +504,10 @@ var Re = /* @__PURE__ */ n({
496
504
  }), this._webVPNTcpSocketListenerPromise;
497
505
  }
498
506
  listen(...e) {
499
- let t = L(...e), n = (e) => {
500
- let t = new R({ connection: Promise.resolve(e) });
507
+ let t = Ue(...e), n = (e) => {
508
+ let t = new F({ connection: Promise.resolve(e) });
501
509
  this.emit("connection", t);
502
- }, r = (e) => x.then((r) => r.webVpnTcpSocketListener({
510
+ }, r = (e) => j.then((r) => r.cloud.webvpn.tcpSocketListener({
503
511
  localAddress: e,
504
512
  localPort: t.port,
505
513
  onConnection: n
@@ -533,23 +541,23 @@ var Re = /* @__PURE__ */ n({
533
541
  connections;
534
542
  listening;
535
543
  async [Symbol.asyncDispose]() {}
536
- }, ze = (e, t) => new R().connect(e, t), Be = (e, t) => new R().connect(e, t), Ve = (e, t) => {
544
+ }, qe = (e, t) => new F().connect(e, t), Je = (e, t) => new F().connect(e, t), L = (e, t) => {
537
545
  typeof e == "function" && (t = e, e = void 0);
538
- let n = new z(e);
546
+ let n = new I(e);
539
547
  return t && n.on("connection", t), n;
540
- }, He = {
541
- Socket: R,
542
- Server: z,
543
- connect: ze,
544
- createConnection: Be,
545
- createServer: Ve,
546
- isIP: I,
547
- isIPv4: P,
548
- isIPv6: F
549
- }, Ue = /* @__PURE__ */ n({
550
- Socket: () => We,
551
- createSocket: () => Ke
552
- }), We = 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 {
553
561
  _type;
554
562
  _localAddress;
555
563
  _remoteAddress;
@@ -577,8 +585,8 @@ var Re = /* @__PURE__ */ n({
577
585
  });
578
586
  }
579
587
  addMembership(e, t) {
580
- if (f.isValid(e)) {
581
- let n = B(e), r = t && f.isValid(t) ? B(t) : new Uint8Array([
588
+ if (d.isValid(e)) {
589
+ let n = R(e), r = t && d.isValid(t) ? R(t) : new Uint8Array([
582
590
  0,
583
591
  0,
584
592
  0,
@@ -589,8 +597,8 @@ var Re = /* @__PURE__ */ n({
589
597
  group: n,
590
598
  interface: r
591
599
  });
592
- } else if (p.isValid(e)) {
593
- let t = Ge(e);
600
+ } else if (f.isValid(e)) {
601
+ let t = Qe(e);
594
602
  this._setUdpOption({
595
603
  type: 7,
596
604
  group: t,
@@ -603,15 +611,15 @@ var Re = /* @__PURE__ */ n({
603
611
  return this._localAddress;
604
612
  }
605
613
  bind(...e) {
606
- let t = Ie(...e), n = this._type === "udp6" ? "::" : "0.0.0.0";
607
- return this._webVPNUdpSocketPromise = x.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({
608
616
  type: this._type,
609
617
  address: t.address ?? n,
610
618
  port: t.port
611
619
  })).then((e) => {
612
620
  let t = e.dataReadableStream.getReader(), n = async () => {
613
621
  let { value: e, done: r } = await t.read();
614
- r || (this.emit("message", m.from(e.data), {
622
+ r || (this.emit("message", p.from(e.data), {
615
623
  address: e.address,
616
624
  family: e.family,
617
625
  port: e.port,
@@ -664,8 +672,8 @@ var Re = /* @__PURE__ */ n({
664
672
  });
665
673
  }
666
674
  dropMembership(e, t) {
667
- if (f.isValid(e)) {
668
- let n = B(e), r = t && f.isValid(t) ? B(t) : new Uint8Array([
675
+ if (d.isValid(e)) {
676
+ let n = R(e), r = t && d.isValid(t) ? R(t) : new Uint8Array([
669
677
  0,
670
678
  0,
671
679
  0,
@@ -676,8 +684,8 @@ var Re = /* @__PURE__ */ n({
676
684
  group: n,
677
685
  interface: r
678
686
  });
679
- } else if (p.isValid(e)) {
680
- let t = Ge(e);
687
+ } else if (f.isValid(e)) {
688
+ let t = Qe(e);
681
689
  this._setUdpOption({
682
690
  type: 8,
683
691
  group: t,
@@ -710,11 +718,11 @@ var Re = /* @__PURE__ */ n({
710
718
  }
711
719
  send(...e) {
712
720
  this._webVPNUdpSocketPromise || this.bind();
713
- let t = Le(...e), n = this._type === "udp6" ? "::1" : "127.0.0.1";
721
+ let t = Ge(...e), n = this._type === "udp6" ? "::1" : "127.0.0.1";
714
722
  if (!this._webVPNUdpSocketPromise) throw Error("Socket not bound");
715
723
  this._webVPNUdpSocketPromise.then((e) => {
716
724
  if (!e) throw Error("Socket not bound");
717
- let r = typeof t.message == "string" ? Fe.encode(t.message) : t.message;
725
+ let r = typeof t.message == "string" ? Ve.encode(t.message) : t.message;
718
726
  e.send({
719
727
  ...t,
720
728
  address: t.address ?? n,
@@ -772,33 +780,33 @@ var Re = /* @__PURE__ */ n({
772
780
  this.close(e);
773
781
  });
774
782
  }
775
- }, B = (e) => {
783
+ }, R = (e) => {
776
784
  let t = e.split(".").map((e) => parseInt(e, 10));
777
785
  if (t.length !== 4 || t.some((e) => Number.isNaN(e) || e < 0 || e > 255)) throw Error(`Invalid IPv4 address: ${e}`);
778
786
  return new Uint8Array(t);
779
- }, Ge = (e) => {
780
- 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);
781
789
  if (!t || t.length !== 16) throw Error(`Invalid IPv6 address: ${e}`);
782
790
  return new Uint8Array(t.map((e) => parseInt(e, 16)));
783
- }, Ke = (e, t) => {
784
- let n = new We(typeof e == "string" ? { type: e } : e);
791
+ }, $e = (e, t) => {
792
+ let n = new Ze(typeof e == "string" ? { type: e } : e);
785
793
  return t && n.on("message", t), n;
786
- }, qe = /* @__PURE__ */ n({
787
- Agent: () => Q,
788
- ClientRequest: () => X,
789
- HTTPParser: () => K,
790
- IncomingMessage: () => q,
791
- METHODS: () => Ye,
792
- STATUS_CODES: () => V,
793
- Server: () => Z,
794
- ServerResponse: () => Y,
795
- _default: () => at,
796
- createServer: () => it,
797
- default: () => at,
798
- get: () => rt,
799
- globalAgent: () => nt,
800
- request: () => $
801
- }), Je = new TextDecoder("latin1"), Ye = /* @__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("."), V = {
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 = {
802
810
  100: "Continue",
803
811
  101: "Switching Protocols",
804
812
  102: "Processing",
@@ -862,7 +870,7 @@ var Re = /* @__PURE__ */ n({
862
870
  509: "Bandwidth Limit Exceeded",
863
871
  510: "Not Extended",
864
872
  511: "Network Authentication Required"
865
- }, Xe = new Set([
873
+ }, rt = new Set([
866
874
  "content-type",
867
875
  "content-length",
868
876
  "user-agent",
@@ -881,18 +889,18 @@ var Re = /* @__PURE__ */ n({
881
889
  "server",
882
890
  "age",
883
891
  "expires"
884
- ]), H = 13, U = 10, Ze = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/, W = (e, t) => (e.code = t, e), Qe = (e, t) => {
892
+ ]), B = 13, V = 10, it = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/, H = (e, t) => (e.code = t, e), at = (e, t) => {
885
893
  if (e.length === 0) return t;
886
894
  if (t.length === 0) return e;
887
895
  let n = new Uint8Array(e.length + t.length);
888
896
  return n.set(e, 0), n.set(t, e.length), n;
889
- }, G = (e, t) => {
890
- for (let n = t; n + 1 < e.length; n++) if (e[n] === H && e[n + 1] === U) 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;
891
899
  return -1;
892
- }, $e = (e) => {
893
- for (let t = 0; t + 3 < e.length; t++) if (e[t] === H && e[t + 1] === U && e[t + 2] === H && e[t + 3] === U) 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;
894
902
  return -1;
895
- }, K = class {
903
+ }, U = class {
896
904
  buf = new Uint8Array();
897
905
  state = "HEAD";
898
906
  framing = "none";
@@ -903,10 +911,10 @@ var Re = /* @__PURE__ */ n({
903
911
  this.mode = e, this.handlers = t;
904
912
  }
905
913
  execute(e) {
906
- this.buf = Qe(this.buf, e);
914
+ this.buf = at(this.buf, e);
907
915
  let t = !0;
908
916
  for (; t;) if (t = !1, this.state === "HEAD") {
909
- let e = $e(this.buf);
917
+ let e = st(this.buf);
910
918
  if (e === -1) return;
911
919
  let n = this.buf.subarray(0, e);
912
920
  this.buf = this.buf.subarray(e + 4);
@@ -921,7 +929,7 @@ var Re = /* @__PURE__ */ n({
921
929
  this.state = "HEAD", this.framing = "none", this.bodyRemaining = 0, this.chunkState = "size", this.skipBody = !1;
922
930
  }
923
931
  parseHead(e) {
924
- let t = Je.decode(e).split("\r\n"), n = t.shift() ?? "", r = [];
932
+ let t = tt.decode(e).split("\r\n"), n = t.shift() ?? "", r = [];
925
933
  for (let e of t) (e.startsWith(" ") || e.startsWith(" ")) && r.length > 0 ? r[r.length - 1] += " " + e.trim() : r.push(e);
926
934
  let i = [], a = {};
927
935
  for (let e of r) {
@@ -959,7 +967,7 @@ var Re = /* @__PURE__ */ n({
959
967
  return;
960
968
  }
961
969
  let i = e[r];
962
- i === void 0 ? e[r] = n : Xe.has(r) || (e[r] = `${i}, ${n}`);
970
+ i === void 0 ? e[r] = n : rt.has(r) || (e[r] = `${i}, ${n}`);
963
971
  }
964
972
  setupBody(e) {
965
973
  if (this.skipBody) {
@@ -992,9 +1000,9 @@ var Re = /* @__PURE__ */ n({
992
1000
  }
993
1001
  consumeChunked() {
994
1002
  for (;;) if (this.chunkState === "size") {
995
- let e = G(this.buf, 0);
1003
+ let e = ot(this.buf, 0);
996
1004
  if (e === -1) return !1;
997
- let t = Je.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);
998
1006
  if (this.buf = this.buf.subarray(e + 2), Number.isNaN(n)) return !0;
999
1007
  n === 0 ? this.chunkState = "trailer" : (this.bodyRemaining = n, this.chunkState = "data");
1000
1008
  } else if (this.chunkState === "data") {
@@ -1005,13 +1013,13 @@ var Re = /* @__PURE__ */ n({
1005
1013
  if (this.buf.length < 2) return !1;
1006
1014
  this.buf = this.buf.subarray(2), this.chunkState = "size";
1007
1015
  } else {
1008
- let e = G(this.buf, 0);
1016
+ let e = ot(this.buf, 0);
1009
1017
  if (e === -1) return !1;
1010
1018
  let t = e === 0;
1011
1019
  if (this.buf = this.buf.subarray(e + 2), t) return !0;
1012
1020
  }
1013
1021
  }
1014
- }, et = (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 {
1015
1023
  httpVersion = "1.1";
1016
1024
  httpVersionMajor = 1;
1017
1025
  httpVersionMinor = 1;
@@ -1038,16 +1046,16 @@ var Re = /* @__PURE__ */ n({
1038
1046
  setTimeout(e, t) {
1039
1047
  return this.socket.setTimeout(e, t), this;
1040
1048
  }
1041
- }, J = class extends u.Writable {
1049
+ }, G = class extends u.Writable {
1042
1050
  _headerStore = /* @__PURE__ */ new Map();
1043
1051
  headersSent = !1;
1044
1052
  chunkedEncoding = !1;
1045
1053
  finished = !1;
1046
1054
  _bodyWritten = !1;
1047
1055
  setHeader(e, t) {
1048
- if (this.headersSent) throw W(/* @__PURE__ */ Error("Cannot set headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
1049
- if (typeof e != "string" || !Ze.test(e)) throw W(/* @__PURE__ */ TypeError(`Header name must be a valid HTTP token [${JSON.stringify(String(e))}]`), "ERR_INVALID_HTTP_TOKEN");
1050
- if (t === void 0) throw W(/* @__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");
1051
1059
  return this._headerStore.set(e.toLowerCase(), [e, Array.isArray(t) ? [...t] : t]), this;
1052
1060
  }
1053
1061
  getHeader(e) {
@@ -1087,30 +1095,30 @@ var Re = /* @__PURE__ */ n({
1087
1095
  return this._bodyWritten = !0, super.write(e, t, n);
1088
1096
  }
1089
1097
  _write(e, t, n) {
1090
- let r = et(e), i = [];
1091
- 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) {
1092
1100
  n();
1093
1101
  return;
1094
1102
  }
1095
- this._writeToSocket(m.concat(i), n);
1103
+ this._writeToSocket(p.concat(i), n);
1096
1104
  }
1097
1105
  _final(e) {
1098
1106
  let t = [];
1099
- 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) {
1100
1108
  e();
1101
1109
  return;
1102
1110
  }
1103
- this._writeToSocket(m.concat(t), e);
1111
+ this._writeToSocket(p.concat(t), e);
1104
1112
  }
1105
1113
  end(e, t, n) {
1106
1114
  if (e != null && typeof e != "function" && !this._bodyWritten && !this.headersSent && !this.chunkedEncoding && !this.hasHeader("content-length")) {
1107
1115
  let n = typeof t == "string" ? t : void 0;
1108
- this.setHeader("Content-Length", et(e, n).length);
1116
+ this.setHeader("Content-Length", ct(e, n).length);
1109
1117
  }
1110
1118
  return super.end(e, t, n);
1111
1119
  }
1112
1120
  _headBlock;
1113
- }, Y = class extends J {
1121
+ }, K = class extends G {
1114
1122
  statusCode = 200;
1115
1123
  statusMessage;
1116
1124
  _writeHeadCalled = !1;
@@ -1127,7 +1135,7 @@ var Re = /* @__PURE__ */ n({
1127
1135
  return !(e >= 100 && e < 200 || e === 204 || e === 304);
1128
1136
  }
1129
1137
  writeHead(e, t, n) {
1130
- if (this._writeHeadCalled || this.headersSent) throw W(/* @__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");
1131
1139
  this._writeHeadCalled = !0, this.statusCode = e;
1132
1140
  let r = n;
1133
1141
  if (typeof t == "string" ? this.statusMessage = t : t != null && (r = t), Array.isArray(r)) {
@@ -1145,16 +1153,16 @@ var Re = /* @__PURE__ */ n({
1145
1153
  }
1146
1154
  }
1147
1155
  _implicitHeader() {
1148
- let e = this.statusMessage ?? V[this.statusCode] ?? "unknown";
1156
+ let e = this.statusMessage ?? z[this.statusCode] ?? "unknown";
1149
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}`);
1150
1158
  }
1151
1159
  writeContinue() {
1152
- 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"), () => {});
1153
1161
  }
1154
1162
  setTimeout(e, t) {
1155
1163
  return this.socket?.setTimeout(e, t), this;
1156
1164
  }
1157
- }, tt = (...e) => {
1165
+ }, lt = (...e) => {
1158
1166
  let t = {}, n = {}, r, i = [...e], a = i.shift();
1159
1167
  if (typeof a == "string" || a instanceof URL) {
1160
1168
  let e = typeof a == "string" ? new URL(a) : a;
@@ -1176,7 +1184,7 @@ var Re = /* @__PURE__ */ n({
1176
1184
  },
1177
1185
  callback: r
1178
1186
  };
1179
- }, X = class extends J {
1187
+ }, q = class extends G {
1180
1188
  method;
1181
1189
  path;
1182
1190
  host;
@@ -1198,7 +1206,7 @@ var Re = /* @__PURE__ */ n({
1198
1206
  let e = this.protocol === "https:" && r === 443 || this.protocol !== "https:" && r === 80;
1199
1207
  this.setHeader("Host", e ? n : `${n}:${r}`);
1200
1208
  }
1201
- e.auth && !this.hasHeader("authorization") && this.setHeader("Authorization", `Basic ${m.from(e.auth).toString("base64")}`), this.socket = new R(), 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) => {
1202
1210
  this._aborted || this.emit("error", e);
1203
1211
  }), this._attachResponseParser(), this.socket.connect({
1204
1212
  host: n,
@@ -1214,12 +1222,12 @@ var Re = /* @__PURE__ */ n({
1214
1222
  this._headBlock = this._storeHeader(`${this.method} ${this.path} HTTP/1.1`);
1215
1223
  }
1216
1224
  _attachResponseParser() {
1217
- let e = new q(this.socket), t = new K("response", {
1225
+ let e = new W(this.socket), t = new U("response", {
1218
1226
  onHeaders: (n) => {
1219
1227
  e._applyHead(n), this.method === "HEAD" && (t.skipBody = !0), this.res = e, this.emit("response", e);
1220
1228
  },
1221
1229
  onBody: (t) => {
1222
- e.push(m.from(t));
1230
+ e.push(p.from(t));
1223
1231
  },
1224
1232
  onComplete: () => {
1225
1233
  e.complete = !0, e.push(null);
@@ -1258,22 +1266,22 @@ var Re = /* @__PURE__ */ n({
1258
1266
  setSocketKeepAlive(e, t) {
1259
1267
  this.socket.setKeepAlive(e, t);
1260
1268
  }
1261
- }, Z = new Proxy(class extends z {
1269
+ }, J = new Proxy(class extends I {
1262
1270
  constructor(e, t) {
1263
1271
  let n = {}, r = t;
1264
1272
  typeof e == "function" ? r = e : e && (n = e), super(n), r && this.on("request", r), this.on("connection", (e) => this._handleConnection(e));
1265
1273
  }
1266
1274
  _handleConnection(e) {
1267
- let t = null, n = new K("request", {
1275
+ let t = null, n = new U("request", {
1268
1276
  onHeaders: (r) => {
1269
- t = new q(e), t._applyHead(r), r.method === "HEAD" && (n.skipBody = !0);
1270
- 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();
1271
1279
  i._keepAlive = r.httpVersionMinor >= 1 ? a !== "close" : a === "keep-alive", i.on("finish", () => {
1272
1280
  i._keepAlive || e.end();
1273
1281
  }), this.emit("request", t, i);
1274
1282
  },
1275
1283
  onBody: (e) => {
1276
- t?.push(m.from(e));
1284
+ t?.push(p.from(e));
1277
1285
  },
1278
1286
  onComplete: () => {
1279
1287
  t && (t.complete = !0, t.push(null)), t = null;
@@ -1283,7 +1291,7 @@ var Re = /* @__PURE__ */ n({
1283
1291
  n.finish(), t && t.push(null);
1284
1292
  }), e.on("error", (t) => this.emit("clientError", t, e));
1285
1293
  }
1286
- }, { apply: (e, t, n) => new e(...n) }), Q = class {
1294
+ }, { apply: (e, t, n) => new e(...n) }), Y = class {
1287
1295
  maxSockets;
1288
1296
  maxFreeSockets;
1289
1297
  keepAlive;
@@ -1295,25 +1303,139 @@ var Re = /* @__PURE__ */ n({
1295
1303
  return `${e.host ?? "localhost"}:${e.port ?? ""}:${e.localAddress ?? ""}`;
1296
1304
  }
1297
1305
  destroy() {}
1298
- }, nt = new Q(), $ = (...e) => {
1299
- let { options: t, callback: n } = tt(...e);
1300
- return new X(t, n);
1301
- }, rt = (...e) => {
1302
- 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);
1303
1311
  return t.end(), t;
1304
- }, it = (e, t) => new Z(e, t), at = {
1305
- METHODS: Ye,
1306
- STATUS_CODES: V,
1307
- Agent: Q,
1308
- globalAgent: nt,
1309
- Server: Z,
1310
- ServerResponse: Y,
1311
- IncomingMessage: q,
1312
- ClientRequest: X,
1313
- OutgoingMessage: J,
1314
- createServer: it,
1315
- request: $,
1316
- get: rt
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
+ });
1317
1439
  };
1318
1440
  //#endregion
1319
- export { k as ATTACH_FRAME_EVENT_KEY, j as assertAttachableFrameUrl, Ne as attachFrame, je as attachFramePermission, l as box, De as cookies, e as createVideoElementHandle, Ue as dgram, S as extension, Te as fetch, Se as fetchCredentialedPermission, xe as fetchPermission, Me as gotoPermission, i as handleRevivableModules, qe as http, A as isBlockedFrameUrl, C as isExtensionExposed, t as isType, Oe as modifyRequestHeadersPermission, Re as net, Pe as permissions, M as promptInstall, Ee as readCookiePermission, _e as relayWorker, Ae as removeRequestHeaderRule, o as revive, he as serverProxyFetch, T as setMissingExtensionHandler, ke as setRequestHeaderRule, a as type, E 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 };