@fkn/lib 0.4.8 → 0.4.9

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 +433 -263
  3. package/index.js +637 -327
  4. package/package.json +1 -1
package/index.js CHANGED
@@ -1,69 +1,69 @@
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-Q5m8i40Z.js";
2
- import { createTypedEventTarget as u, expose as d, relay as ee } from "osra";
3
- import { Stream as f } from "stream";
4
- import { EventEmitter as te } from "events";
5
- import { Address4 as p, Address6 as m } from "ip-address";
6
- import { Buffer as h } from "buffer";
7
- import { createElement as ne } from "react";
2
+ import { createTypedEventTarget as u, expose as ee, relay as te } from "osra";
3
+ import { Stream as d } from "stream";
4
+ import { EventEmitter as ne } from "events";
5
+ import { Address4 as f, Address6 as p } from "ip-address";
6
+ import { Buffer as m } from "buffer";
7
+ import { createElement as re } from "react";
8
8
  //#region node_modules/@mfkn/web-extension/lib/utils/extension.js
9
- var re = "FKN_WEB_EXTENSION_MAIN_WORLD_CONTENT_SCRIPT_ENABLED_EVENT_KEY", ie = "fknExtension", g = u();
10
- typeof document < "u" && document.addEventListener(re, () => {
11
- g.dispatchEvent(new CustomEvent("statuschange", { detail: { enabled: _() } }));
9
+ var ie = "FKN_WEB_EXTENSION_MAIN_WORLD_CONTENT_SCRIPT_ENABLED_EVENT_KEY", ae = "fknExtension", h = u();
10
+ typeof document < "u" && document.addEventListener(ie, () => {
11
+ h.dispatchEvent(new CustomEvent("statuschange", { detail: { enabled: g() } }));
12
12
  });
13
- var _ = () => typeof document > "u" ? !1 : document.documentElement.dataset[ie] === "true", v = null, y = (e) => {
14
- v = e;
15
- }, ae = 150, b = (e = 1e3) => new Promise((t, n) => {
16
- if (_()) return t();
13
+ var g = () => typeof document > "u" ? !1 : document.documentElement.dataset[ae] === "true", oe = null, se = (e) => {
14
+ oe = e;
15
+ }, ce = 150, _ = (e = 1e3) => new Promise((t, n) => {
16
+ if (g()) return t();
17
17
  let r, i = (e) => {
18
18
  clearTimeout(r), s.disconnect(), document.removeEventListener("readystatechange", c), e();
19
19
  }, a = () => i(async () => {
20
- if (v && (await v().catch(() => {}), _())) return t();
20
+ if (oe && (await oe().catch(() => {}), g())) return t();
21
21
  n(/* @__PURE__ */ Error("The FKN WebExtension is not installed, enabled or not exposed on this page."));
22
22
  }), o = () => {
23
- clearTimeout(r), r = setTimeout(() => _() ? i(t) : a(), ae);
23
+ clearTimeout(r), r = setTimeout(() => g() ? i(t) : a(), ce);
24
24
  }, s = new MutationObserver(() => {
25
- _() && i(t);
25
+ g() && i(t);
26
26
  }), c = () => {
27
- document.readyState === "complete" && !_() && o();
27
+ document.readyState === "complete" && !g() && o();
28
28
  };
29
29
  if (r = setTimeout(a, e), s.observe(document.documentElement, {
30
30
  attributes: !0,
31
31
  attributeFilter: ["data-fkn-extension"]
32
32
  }), document.addEventListener("readystatechange", c), document.readyState === "complete") return o();
33
- _() && i(t);
34
- }), oe, x = new Proxy({}, { get: (e, t) => async (...e) => {
35
- await b(), oe ??= d({}, {
33
+ g() && i(t);
34
+ }), le, v = new Proxy({}, { get: (e, t) => async (...e) => {
35
+ await _(), le ??= ee({}, {
36
36
  transport: window,
37
37
  revivableModules: i
38
38
  });
39
- let n = (await oe)[t];
39
+ let n = (await le)[t];
40
40
  return n(...e);
41
- } }), se = {
41
+ } }), ue = {
42
42
  scope: "network.fetch",
43
43
  category: "network",
44
44
  severity: 0,
45
45
  title: "Fetch data from other sites",
46
46
  description: "Lets the app download public data from other websites directly, past the usual cross-origin limits."
47
- }, ce = {
47
+ }, de = {
48
48
  scope: "network.fetchCredentialed",
49
49
  category: "network",
50
50
  severity: 3,
51
51
  unsafe: !0,
52
52
  title: "Fetch from other sites, signed in as you",
53
53
  description: "Lets the app fetch other sites using your logged-in session cookies, so it can read data only you should see."
54
- }, le = {
54
+ }, fe = {
55
55
  scope: "network.fetchLocal",
56
56
  category: "network",
57
57
  severity: 3,
58
58
  unsafe: !0,
59
59
  title: "Access devices on your local network",
60
60
  description: "Lets the app reach devices and services on your home or work network, which websites normally cannot touch."
61
- }, ue = (e) => {
61
+ }, pe = (e) => {
62
62
  let t = e.match(/^(\d+)\.(\d+)\.\d+\.\d+$/);
63
63
  if (!t) return !1;
64
64
  let [n, r] = [Number(t[1]), Number(t[2])];
65
65
  return n === 10 || n === 127 || n === 0 || n === 169 && r === 254 || n === 172 && r >= 16 && r <= 31 || n === 192 && r === 168;
66
- }, de = (e) => {
66
+ }, me = (e) => {
67
67
  let t;
68
68
  try {
69
69
  t = new URL(e);
@@ -71,8 +71,8 @@ var _ = () => typeof document > "u" ? !1 : document.documentElement.dataset[ie]
71
71
  return !1;
72
72
  }
73
73
  let n = t.hostname.replace(/^\[|\]$/g, "").toLowerCase().replace(/\.$/, "");
74
- return n === "localhost" || n.endsWith(".localhost") || n.endsWith(".local") || n.endsWith(".internal") || n.endsWith(".home.arpa") ? !0 : n.includes(":") ? n === "::" || n === "::1" || n.startsWith("fc") || n.startsWith("fd") || /^fe[89ab]/.test(n) || n.startsWith("::ffff:") : ue(n);
75
- }, fe = ["fkn.app", "fkn.dev"], S = (e) => {
74
+ return n === "localhost" || n.endsWith(".localhost") || n.endsWith(".local") || n.endsWith(".internal") || n.endsWith(".home.arpa") ? !0 : n.includes(":") ? n === "::" || n === "::1" || n.startsWith("fc") || n.startsWith("fd") || /^fe[89ab]/.test(n) || n.startsWith("::ffff:") : pe(n);
75
+ }, he = ["fkn.app", "fkn.dev"], ge = (e) => {
76
76
  let t;
77
77
  try {
78
78
  t = new URL(e);
@@ -81,46 +81,46 @@ var _ = () => typeof document > "u" ? !1 : document.documentElement.dataset[ie]
81
81
  }
82
82
  if (t.protocol === "chrome-extension:" || t.protocol === "moz-extension:") return !0;
83
83
  let n = t.hostname;
84
- return fe.some((e) => n === e || n.endsWith(`.${e}`));
85
- }, C = (e) => {
86
- if (S(e)) throw Error("fetch: refusing to target the extension's own pages or FKN platform domains");
87
- }, pe = ["origin", "referer"], me = (e) => {
84
+ return he.some((e) => n === e || n.endsWith(`.${e}`));
85
+ }, _e = (e) => {
86
+ if (ge(e)) throw Error("fetch: refusing to target the extension's own pages or FKN platform domains");
87
+ }, ve = ["origin", "referer"], ye = (e) => {
88
88
  if (!e?.headers) return;
89
- let t = new Headers(e.headers), n = pe.map((e) => {
89
+ let t = new Headers(e.headers), n = ve.map((e) => {
90
90
  let n = t.get(e);
91
91
  return n === null ? void 0 : [e, n];
92
92
  }).filter((e) => e !== void 0);
93
93
  return n.length ? n : void 0;
94
- }, he = async (e, t) => {
94
+ }, be = async (e, t) => {
95
95
  let n = new Request(e, t);
96
- C(n.url);
96
+ _e(n.url);
97
97
  let r = n.body ? await n.arrayBuffer() : null;
98
- return x.proxyFetch({
98
+ return v.proxyFetch({
99
99
  url: n.url,
100
100
  method: n.method,
101
101
  headers: [...n.headers],
102
102
  body: r,
103
103
  credentials: t?.credentials === "include" ? "include" : "omit",
104
104
  redirect: n.redirect,
105
- unsafeHeaders: me(t),
105
+ unsafeHeaders: ye(t),
106
106
  reason: t?.reason,
107
107
  signal: t?.signal ?? void 0
108
108
  });
109
- }, ge = {
109
+ }, xe = {
110
110
  scope: "network.readCookie",
111
111
  category: "network",
112
112
  severity: 3,
113
113
  unsafe: !0,
114
114
  title: "Read a site’s cookie",
115
115
  description: "Lets the app read a named cookie from another site, which can include the login token only that site should see."
116
- }, _e = { get: (e) => x.getCookie(e) }, ve = {
116
+ }, Se = { get: (e) => v.getCookie(e) }, Ce = {
117
117
  scope: "network.modifyRequestHeaders",
118
118
  category: "network",
119
119
  severity: 2,
120
120
  unsafe: !0,
121
121
  title: "Rewrite request headers to other sites",
122
122
  description: "Lets the app set or remove headers (like Origin and Referer) on this page’s own requests to the listed sites."
123
- }, ye = (e) => x.setRequestHeaderRule(e), be = (e) => x.removeRequestHeaderRule({ ruleId: e });
123
+ }, we = (e) => v.setRequestHeaderRule(e), Te = (e) => v.removeRequestHeaderRule({ ruleId: e });
124
124
  (() => {
125
125
  let e = {}, t = [...c.selectorModules, ...r.selectorModules];
126
126
  for (let n of t) n.render && !(n.type in e) && (e[n.type] = n.render);
@@ -128,7 +128,7 @@ var _ = () => typeof document > "u" ? !1 : document.documentElement.dataset[ie]
128
128
  })();
129
129
  //#endregion
130
130
  //#region node_modules/@mfkn/web-extension/lib/lib/frame.js
131
- var w = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", T = (e) => {
131
+ var Ee = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", De = (e) => {
132
132
  if (!e || e === "about:blank") return !1;
133
133
  let t;
134
134
  try {
@@ -140,61 +140,61 @@ var w = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", T = (e) => {
140
140
  if (t.protocol === "about:") return !1;
141
141
  let n = t.hostname;
142
142
  return n === "fkn.app" || n.endsWith(".fkn.app");
143
- }, E = (e) => {
144
- if (T(e)) throw Error("attachFrame: refusing to target the extension's own pages or fkn.app");
145
- }, xe = {
143
+ }, y = (e) => {
144
+ if (De(e)) throw Error("attachFrame: refusing to target the extension's own pages or fkn.app");
145
+ }, Oe = {
146
146
  scope: "embed.iframe",
147
147
  category: "embed",
148
148
  severity: 0,
149
149
  title: "Load another website inside this app",
150
150
  description: "Lets the app embed external pages directly inside its own view."
151
- }, Se = {
151
+ }, ke = {
152
152
  scope: "embed.open",
153
153
  category: "embed",
154
154
  severity: 0,
155
155
  title: "Open a website inside this app",
156
156
  description: "Lets the app navigate to another site without leaving its window."
157
- }, Ce = {
157
+ }, Ae = {
158
158
  scope: "embed.evaluate",
159
159
  category: "embed",
160
160
  severity: 0,
161
161
  title: "Run app code inside an embedded frame",
162
162
  description: "Lets the app execute its own code inside a page it embedded, to read back a computed result."
163
- }, we = async ({ iframe: e, domains: t = [], syncCookies: n = !0, lockdown: r = !1 }) => {
163
+ }, je = async ({ iframe: e, domains: t = [], syncCookies: n = !0, lockdown: r = !1 }) => {
164
164
  let i = crypto.randomUUID();
165
- if (E(e.src), await b(), !e.isConnected) throw Error("attachFrame: the iframe must be connected to the document before attaching");
166
- e.dispatchEvent(new CustomEvent(w, { detail: i }));
167
- let { executeLocator: a, ensureLocatorPermission: o, goto: c, evaluate: l } = await x.attachFrame({
165
+ if (y(e.src), await _(), !e.isConnected) throw Error("attachFrame: the iframe must be connected to the document before attaching");
166
+ e.dispatchEvent(new CustomEvent(Ee, { detail: i }));
167
+ let { executeLocator: a, ensureLocatorPermission: o, goto: c, evaluate: l } = await v.attachFrame({
168
168
  marker: i,
169
169
  domains: t,
170
170
  syncCookies: n,
171
171
  lockdown: r
172
- }), u = s(a, o), d = (e, t = {}) => (E(e), c({
172
+ }), u = s(a, o), ee = (e, t = {}) => (y(e), c({
173
173
  url: e,
174
174
  ...t
175
- })), ee = ((e, t) => l(e, t)), f = () => e.src;
175
+ })), te = ((e, t) => l(e, t)), d = () => e.src;
176
176
  return {
177
177
  ...u,
178
- goto: d,
179
- evaluate: ee,
180
- url: f
178
+ goto: ee,
179
+ evaluate: te,
180
+ url: d
181
181
  };
182
- }, Te = { request: (e) => x.requestPermissions(e.map((e) => ({
182
+ }, Me = { request: (e) => v.requestPermissions(e.map((e) => ({
183
183
  key: e.key,
184
184
  scope: e.scope ?? "",
185
185
  reason: e.reason
186
- }))) }, Ee = 32, De = typeof CSS < "u" && CSS.supports("clip-path", "path('M0 0H1V1H0Z')"), Oe = (e) => {
186
+ }))) }, Ne = 32, Pe = typeof CSS < "u" && CSS.supports("clip-path", "path('M0 0H1V1H0Z')"), Fe = (e) => {
187
187
  let t = e.style;
188
188
  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");
189
- }, ke = ({ x: e, y: t, width: n, height: r }) => `M${e} ${t}h${n}v${r}h${-n}Z`, Ae = (e, { modal: t, rects: n }) => {
190
- if (!De) {
189
+ }, Ie = ({ x: e, y: t, width: n, height: r }) => `M${e} ${t}h${n}v${r}h${-n}Z`, Le = (e, { modal: t, rects: n }) => {
190
+ if (!Pe) {
191
191
  let r = t || n.length > 0;
192
192
  e.style.setProperty("pointer-events", r ? "auto" : "none", "important"), e.style.setProperty("visibility", r ? "visible" : "hidden", "important");
193
193
  return;
194
194
  }
195
- let r = t ? "none" : n.length === 0 ? "inset(100%)" : `path('${n.map(ke).join("")}')`, i = r === "none" || CSS.supports("clip-path", r) ? r : "inset(100%)";
195
+ let r = t ? "none" : n.length === 0 ? "inset(100%)" : `path('${n.map(Ie).join("")}')`, i = r === "none" || CSS.supports("clip-path", r) ? r : "inset(100%)";
196
196
  e.style.setProperty("clip-path", i, "important");
197
- }, je = (e) => {
197
+ }, Re = (e) => {
198
198
  if (typeof e != "object" || !e) return null;
199
199
  let { x: t, y: n, width: r, height: i } = e;
200
200
  if (![
@@ -210,45 +210,45 @@ var w = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", T = (e) => {
210
210
  width: l - s,
211
211
  height: u - c
212
212
  };
213
- }, Me = (e) => {
213
+ }, ze = (e) => {
214
214
  if (typeof e != "object" || !e) return null;
215
- let t = e, n = (Array.isArray(t.rects) ? t.rects.slice(0, Ee) : []).map(je).filter((e) => e !== null && e.width > 0 && e.height > 0);
215
+ let t = e, n = (Array.isArray(t.rects) ? t.rects.slice(0, Ne) : []).map(Re).filter((e) => e !== null && e.width > 0 && e.height > 0);
216
216
  return {
217
217
  modal: t.modal === !0,
218
218
  rects: n
219
219
  };
220
- }, D = null, Ne = () => D !== null, Pe = (e) => {
221
- Oe(e), Ae(e, {
220
+ }, b = null, Be = () => b !== null, Ve = (e) => {
221
+ Fe(e), Le(e, {
222
222
  modal: !1,
223
223
  rects: []
224
- }), D = e;
225
- }, Fe = (e) => {
226
- if (!D) return;
227
- let t = Me(e);
228
- t && Ae(D, t);
229
- }, Ie = "https://fkn.app", O = typeof globalThis < "u" && globalThis.document ? globalThis.document : void 0, Le = O?.querySelector(`iframe[src="${Ie}/api"]`) ?? null, k = O?.createElement("iframe") ?? null;
230
- !Le && k && O && (k.src = `${Ie}/api`, O.body.appendChild(k));
231
- var A = Le ?? k, Re = A?.contentWindow ?? null;
232
- A && O && Pe(A);
233
- var j = (() => {
234
- if (typeof window < "u") return Re ? {
224
+ }), b = e;
225
+ }, He = (e) => {
226
+ if (!b) return;
227
+ let t = ze(e);
228
+ t && Le(b, t);
229
+ }, Ue = "https://fkn.app", x = typeof globalThis < "u" && globalThis.document ? globalThis.document : void 0, We = x?.querySelector(`iframe[src="${Ue}/api"]`) ?? null, S = x?.createElement("iframe") ?? null;
230
+ !We && S && x && (S.src = `${Ue}/api`, x.body.appendChild(S));
231
+ var C = We ?? S, Ge = C?.contentWindow ?? null;
232
+ C && x && Ve(C);
233
+ var Ke = (() => {
234
+ if (typeof window < "u") return Ge ? {
235
235
  receive: window,
236
- emit: Re
236
+ emit: Ge
237
237
  } : void 0;
238
238
  if (typeof self < "u") return {
239
239
  receive: self,
240
240
  emit: self
241
241
  };
242
- })(), ze = j !== void 0, M = j ? d({}, {
242
+ })(), qe = Ke !== void 0, w = Ke ? ee({}, {
243
243
  key: "fkn-api",
244
- transport: j
244
+ transport: Ke
245
245
  }) : new Promise(() => {});
246
- M.then((e) => {
247
- Ne() && e.overlay.setHost(Fe);
246
+ w.then((e) => {
247
+ Be() && e.overlay.setHost(He);
248
248
  }, () => {});
249
249
  //#endregion
250
250
  //#region src/lib/fkn-target.ts
251
- var Be = ["fkn.app", "fkn.dev"], Ve = (e) => {
251
+ var Je = ["fkn.app", "fkn.dev"], Ye = (e) => {
252
252
  let t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n;
253
253
  try {
254
254
  n = new URL(t);
@@ -256,9 +256,9 @@ var Be = ["fkn.app", "fkn.dev"], Ve = (e) => {
256
256
  return;
257
257
  }
258
258
  let r = n.hostname;
259
- if (Be.some((e) => r === e || r.endsWith(`.${e}`))) throw Error(`fetch refuses FKN platform domains (${r})`);
260
- }, He = (e, t) => (Ve(e), M.then((n) => n.cloud.fetch(e, t))), Ue = async () => {
261
- let e = await M.then((e) => e.cloud.quota());
259
+ if (Je.some((e) => r === e || r.endsWith(`.${e}`))) throw Error(`fetch refuses FKN platform domains (${r})`);
260
+ }, Xe = (e, t) => (Ye(e), w.then((n) => n.cloud.fetch(e, t))), Ze = async () => {
261
+ let e = await w.then((e) => e.cloud.quota());
262
262
  return {
263
263
  premium: e.premium,
264
264
  overQuota: e.overQuota,
@@ -269,9 +269,16 @@ var Be = ["fkn.app", "fkn.dev"], Ve = (e) => {
269
269
  bytesPerSecond: e.bytesPerSecond,
270
270
  bitsPerSecond: e.bytesPerSecond * 8
271
271
  };
272
- }, We = /* @__PURE__ */ n({ lookup: () => Ge }), Ge = (e, t) => M.then((n) => n.cloud.dns.lookup(e, t)), Ke = new TextEncoder();
272
+ }, Qe = /* @__PURE__ */ n({ lookup: () => $e }), $e = (e, t) => w.then((n) => n.cloud.dns.lookup(e, t)), et = /* @__PURE__ */ n({
273
+ available: () => tt,
274
+ list: () => nt,
275
+ quota: () => rt,
276
+ readFile: () => T,
277
+ remove: () => at,
278
+ writeFile: () => it
279
+ }), tt = () => w.then((e) => e.cloud.fs.available()).catch(() => !1), nt = () => w.then((e) => e.cloud.fs.list()), rt = () => w.then((e) => e.cloud.fs.quota()), T = async (e) => await (await w).cloud.fs.readFile(e), it = (e, t, n) => w.then((r) => r.cloud.fs.writeFile(e, t, n?.contentType ?? null)).then(() => void 0), at = (e) => w.then((t) => t.cloud.fs.remove(e)).then(() => void 0), ot = new TextEncoder();
273
280
  new TextDecoder();
274
- var N = (e) => p.isValid(e), P = (e) => m.isValid(e), qe = (e) => N(e) ? 4 : P(e) ? 6 : 0, Je = (...e) => {
281
+ var st = (e) => f.isValid(e), ct = (e) => p.isValid(e), lt = (e) => st(e) ? 4 : ct(e) ? 6 : 0, ut = (...e) => {
275
282
  if (typeof e[0] == "string") throw Error("FKN WebVPN does not support IPC connections");
276
283
  let t = typeof e.at(-1) == "function" ? e.at(-1) : void 0;
277
284
  return e[0] && typeof e[0] == "object" ? {
@@ -282,7 +289,7 @@ var N = (e) => p.isValid(e), P = (e) => m.isValid(e), qe = (e) => N(e) ? 4 : P(e
282
289
  host: typeof e[1] == "string" ? e[1] : void 0,
283
290
  callback: t
284
291
  };
285
- }, Ye = (...e) => {
292
+ }, dt = (...e) => {
286
293
  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;
287
294
  return typeof e[0] == "object" ? {
288
295
  ...e[0],
@@ -294,7 +301,7 @@ var N = (e) => p.isValid(e), P = (e) => m.isValid(e), qe = (e) => N(e) ? 4 : P(e
294
301
  port: n,
295
302
  callback: t
296
303
  };
297
- }, Xe = (...e) => {
304
+ }, ft = (...e) => {
298
305
  let t = typeof e.at(-1) == "function" ? e.at(-1) : void 0, n = e[0];
299
306
  if (typeof e[2] == "number") return {
300
307
  message: n,
@@ -319,18 +326,18 @@ var N = (e) => p.isValid(e), P = (e) => m.isValid(e), qe = (e) => N(e) ? 4 : P(e
319
326
  new TextEncoder(), new TextDecoder();
320
327
  //#endregion
321
328
  //#region src/lib/webvpn/net.ts
322
- var Ze = /* @__PURE__ */ n({
323
- Server: () => I,
324
- Socket: () => F,
325
- _default: () => tt,
326
- connect: () => Qe,
327
- createConnection: () => $e,
328
- createServer: () => et,
329
- default: () => tt,
330
- isIP: () => qe,
331
- isIPv4: () => N,
332
- isIPv6: () => P
333
- }), F = class extends f.Duplex {
329
+ var pt = /* @__PURE__ */ n({
330
+ Server: () => D,
331
+ Socket: () => E,
332
+ _default: () => _t,
333
+ connect: () => mt,
334
+ createConnection: () => ht,
335
+ createServer: () => gt,
336
+ default: () => _t,
337
+ isIP: () => lt,
338
+ isIPv4: () => st,
339
+ isIPv6: () => ct
340
+ }), E = class extends d.Duplex {
334
341
  _localAddress;
335
342
  _remoteAddress;
336
343
  _webVPNTcpSocketPromise;
@@ -390,7 +397,7 @@ var Ze = /* @__PURE__ */ n({
390
397
  }).catch(n);
391
398
  }
392
399
  connect(...e) {
393
- let t = Je(...e), n = this.__webvpn_tcp_socket_init__(M.then((e) => e.cloud.webvpn.tcpSocket({
400
+ let t = ut(...e), n = this.__webvpn_tcp_socket_init__(w.then((e) => e.cloud.webvpn.tcpSocket({
394
401
  remoteAddress: t.host ?? "localhost",
395
402
  remotePort: t.port
396
403
  })));
@@ -517,7 +524,7 @@ var Ze = /* @__PURE__ */ n({
517
524
  return this._remoteAddress.family;
518
525
  }
519
526
  timeout;
520
- }, I = class extends te {
527
+ }, D = class extends ne {
521
528
  _localAddress;
522
529
  _webVPNTcpSocketListenerPromise;
523
530
  constructor(e, t) {
@@ -535,10 +542,10 @@ var Ze = /* @__PURE__ */ n({
535
542
  }), this._webVPNTcpSocketListenerPromise;
536
543
  }
537
544
  listen(...e) {
538
- let t = Je(...e), n = (e) => {
539
- let t = new F({ connection: Promise.resolve(e) });
545
+ let t = ut(...e), n = (e) => {
546
+ let t = new E({ connection: Promise.resolve(e) });
540
547
  this.emit("connection", t);
541
- }, r = (e) => M.then((r) => r.cloud.webvpn.tcpSocketListener({
548
+ }, r = (e) => w.then((r) => r.cloud.webvpn.tcpSocketListener({
542
549
  localAddress: e,
543
550
  localPort: t.port,
544
551
  onConnection: n
@@ -572,23 +579,23 @@ var Ze = /* @__PURE__ */ n({
572
579
  connections;
573
580
  listening;
574
581
  async [Symbol.asyncDispose]() {}
575
- }, Qe = (e, t) => new F().connect(e, t), $e = (e, t) => new F().connect(e, t), et = (e, t) => {
582
+ }, mt = (e, t) => new E().connect(e, t), ht = (e, t) => new E().connect(e, t), gt = (e, t) => {
576
583
  typeof e == "function" && (t = e, e = void 0);
577
- let n = new I(e);
584
+ let n = new D(e);
578
585
  return t && n.on("connection", t), n;
579
- }, tt = {
580
- Socket: F,
581
- Server: I,
582
- connect: Qe,
583
- createConnection: $e,
584
- createServer: et,
585
- isIP: qe,
586
- isIPv4: N,
587
- isIPv6: P
588
- }, nt = /* @__PURE__ */ n({
589
- Socket: () => rt,
590
- createSocket: () => ot
591
- }), rt = class extends te {
586
+ }, _t = {
587
+ Socket: E,
588
+ Server: D,
589
+ connect: mt,
590
+ createConnection: ht,
591
+ createServer: gt,
592
+ isIP: lt,
593
+ isIPv4: st,
594
+ isIPv6: ct
595
+ }, vt = /* @__PURE__ */ n({
596
+ Socket: () => yt,
597
+ createSocket: () => Ct
598
+ }), yt = class extends ne {
592
599
  _type;
593
600
  _localAddress;
594
601
  _remoteAddress;
@@ -649,7 +656,7 @@ var Ze = /* @__PURE__ */ n({
649
656
  a += n.byteLength, l = t.getUint16(a), a += 2;
650
657
  }
651
658
  let u = t.getUint32(a);
652
- a += 4, this.emit("message", h.from(e.slice(a, a + u)), {
659
+ a += 4, this.emit("message", m.from(e.slice(a, a + u)), {
653
660
  address: s,
654
661
  family: c,
655
662
  port: l,
@@ -658,10 +665,10 @@ var Ze = /* @__PURE__ */ n({
658
665
  }
659
666
  }
660
667
  _peerTail(e, t) {
661
- if (e === void 0 || t === void 0) return it;
668
+ if (e === void 0 || t === void 0) return bt;
662
669
  let n = `${e}|${t}`, r = this._peerTailCache.get(n);
663
670
  if (r) return r;
664
- let i = p.isValid(e) ? L(e) : R(e), a = new Uint8Array(1 + i.byteLength + 2);
671
+ let i = f.isValid(e) ? O(e) : St(e), a = new Uint8Array(1 + i.byteLength + 2);
665
672
  return a[0] = i.byteLength === 4 ? 0 : 1, a.set(i, 1), new DataView(a.buffer).setUint16(1 + i.byteLength, t), this._peerTailCache.set(n, a), a;
666
673
  }
667
674
  _portSend(e, t, n) {
@@ -676,8 +683,8 @@ var Ze = /* @__PURE__ */ n({
676
683
  }));
677
684
  }
678
685
  addMembership(e, t) {
679
- if (p.isValid(e)) {
680
- let n = L(e), r = t && p.isValid(t) ? L(t) : new Uint8Array([
686
+ if (f.isValid(e)) {
687
+ let n = O(e), r = t && f.isValid(t) ? O(t) : new Uint8Array([
681
688
  0,
682
689
  0,
683
690
  0,
@@ -688,8 +695,8 @@ var Ze = /* @__PURE__ */ n({
688
695
  group: n,
689
696
  interface: r
690
697
  });
691
- } else if (m.isValid(e)) {
692
- let t = R(e);
698
+ } else if (p.isValid(e)) {
699
+ let t = St(e);
693
700
  this._setUdpOption({
694
701
  type: 7,
695
702
  group: t,
@@ -702,8 +709,8 @@ var Ze = /* @__PURE__ */ n({
702
709
  return this._localAddress;
703
710
  }
704
711
  bind(...e) {
705
- let t = Ye(...e), n = this._type === "udp6" ? "::" : "0.0.0.0";
706
- return this._webVPNUdpSocketPromise = M.then((e) => e.cloud.webvpn.udpSocket({
712
+ let t = dt(...e), n = this._type === "udp6" ? "::" : "0.0.0.0";
713
+ return this._webVPNUdpSocketPromise = w.then((e) => e.cloud.webvpn.udpSocket({
707
714
  type: this._type,
708
715
  address: t.address ?? n,
709
716
  port: t.port,
@@ -713,7 +720,7 @@ var Ze = /* @__PURE__ */ n({
713
720
  else {
714
721
  let t = e.dataReadableStream.getReader(), n = async () => {
715
722
  let { value: e, done: r } = await t.read();
716
- r || (this.emit("message", h.from(e.data), {
723
+ r || (this.emit("message", m.from(e.data), {
717
724
  address: e.address,
718
725
  family: e.family,
719
726
  port: e.port,
@@ -768,8 +775,8 @@ var Ze = /* @__PURE__ */ n({
768
775
  });
769
776
  }
770
777
  dropMembership(e, t) {
771
- if (p.isValid(e)) {
772
- let n = L(e), r = t && p.isValid(t) ? L(t) : new Uint8Array([
778
+ if (f.isValid(e)) {
779
+ let n = O(e), r = t && f.isValid(t) ? O(t) : new Uint8Array([
773
780
  0,
774
781
  0,
775
782
  0,
@@ -780,8 +787,8 @@ var Ze = /* @__PURE__ */ n({
780
787
  group: n,
781
788
  interface: r
782
789
  });
783
- } else if (m.isValid(e)) {
784
- let t = R(e);
790
+ } else if (p.isValid(e)) {
791
+ let t = St(e);
785
792
  this._setUdpOption({
786
793
  type: 8,
787
794
  group: t,
@@ -814,12 +821,12 @@ var Ze = /* @__PURE__ */ n({
814
821
  }
815
822
  send(...e) {
816
823
  this._webVPNUdpSocketPromise || this.bind();
817
- let t = Xe(...e), n = this._type === "udp6" ? "::1" : "127.0.0.1";
824
+ let t = ft(...e), n = this._type === "udp6" ? "::1" : "127.0.0.1";
818
825
  if (!this._webVPNUdpSocketPromise) throw Error("Socket not bound");
819
826
  this._webVPNUdpSocketPromise.then((e) => {
820
827
  if (!e) throw Error("Socket not bound");
821
- let r = at(t.message), i = t.callback, a = t.address ?? n, o = this._remoteAddress !== void 0 && t.address === void 0;
822
- if (this._dataPort && (o || p.isValid(a) || m.isValid(a))) {
828
+ let r = xt(t.message), i = t.callback, a = t.address ?? n, o = this._remoteAddress !== void 0 && t.address === void 0;
829
+ if (this._dataPort && (o || f.isValid(a) || p.isValid(a))) {
823
830
  this._portSend(r, o ? void 0 : a, o ? void 0 : t.port), i?.call(this, null, r.byteLength);
824
831
  return;
825
832
  }
@@ -880,43 +887,43 @@ var Ze = /* @__PURE__ */ n({
880
887
  this.close(e);
881
888
  });
882
889
  }
883
- }, it = new Uint8Array([2]), at = (e) => {
884
- if (typeof e == "string") return Ke.encode(e);
890
+ }, bt = new Uint8Array([2]), xt = (e) => {
891
+ if (typeof e == "string") return ot.encode(e);
885
892
  if (e instanceof Uint8Array) return e;
886
893
  if (ArrayBuffer.isView(e)) return new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
887
894
  if (Array.isArray(e)) {
888
- let t = e.map(at), n = new Uint8Array(t.reduce((e, t) => e + t.byteLength, 0)), r = 0;
895
+ let t = e.map(xt), n = new Uint8Array(t.reduce((e, t) => e + t.byteLength, 0)), r = 0;
889
896
  for (let e of t) n.set(e, r), r += e.byteLength;
890
897
  return n;
891
898
  }
892
899
  return new Uint8Array(e);
893
- }, L = (e) => {
900
+ }, O = (e) => {
894
901
  let t = e.split(".").map((e) => parseInt(e, 10));
895
902
  if (t.length !== 4 || t.some((e) => Number.isNaN(e) || e < 0 || e > 255)) throw Error(`Invalid IPv4 address: ${e}`);
896
903
  return new Uint8Array(t);
897
- }, R = (e) => {
898
- let t = new m(e).getBitsBase16(0, 128).match(/.{2}/g);
904
+ }, St = (e) => {
905
+ let t = new p(e).getBitsBase16(0, 128).match(/.{2}/g);
899
906
  if (!t || t.length !== 16) throw Error(`Invalid IPv6 address: ${e}`);
900
907
  return new Uint8Array(t.map((e) => parseInt(e, 16)));
901
- }, ot = (e, t) => {
902
- let n = new rt(typeof e == "string" ? { type: e } : e);
908
+ }, Ct = (e, t) => {
909
+ let n = new yt(typeof e == "string" ? { type: e } : e);
903
910
  return t && n.on("message", t), n;
904
- }, st = /* @__PURE__ */ n({
905
- Agent: () => Y,
906
- ClientRequest: () => q,
907
- HTTPParser: () => U,
908
- IncomingMessage: () => W,
909
- METHODS: () => lt,
910
- STATUS_CODES: () => z,
911
- Server: () => J,
912
- ServerResponse: () => K,
913
- _default: () => bt,
914
- createServer: () => yt,
915
- default: () => bt,
916
- get: () => vt,
917
- globalAgent: () => _t,
918
- request: () => X
919
- }), ct = new TextDecoder("latin1"), lt = /* @__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 = {
911
+ }, wt = /* @__PURE__ */ n({
912
+ Agent: () => Vt,
913
+ ClientRequest: () => zt,
914
+ HTTPParser: () => A,
915
+ IncomingMessage: () => j,
916
+ METHODS: () => Et,
917
+ STATUS_CODES: () => Dt,
918
+ Server: () => Bt,
919
+ ServerResponse: () => Lt,
920
+ _default: () => Kt,
921
+ createServer: () => Gt,
922
+ default: () => Kt,
923
+ get: () => Wt,
924
+ globalAgent: () => Ht,
925
+ request: () => Ut
926
+ }), Tt = new TextDecoder("latin1"), Et = /* @__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("."), Dt = {
920
927
  100: "Continue",
921
928
  101: "Switching Protocols",
922
929
  102: "Processing",
@@ -980,7 +987,7 @@ var Ze = /* @__PURE__ */ n({
980
987
  509: "Bandwidth Limit Exceeded",
981
988
  510: "Not Extended",
982
989
  511: "Network Authentication Required"
983
- }, ut = new Set([
990
+ }, Ot = new Set([
984
991
  "content-type",
985
992
  "content-length",
986
993
  "user-agent",
@@ -999,18 +1006,18 @@ var Ze = /* @__PURE__ */ n({
999
1006
  "server",
1000
1007
  "age",
1001
1008
  "expires"
1002
- ]), B = 13, V = 10, dt = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/, H = (e, t) => (e.code = t, e), ft = (e, t) => {
1009
+ ]), kt = 13, At = 10, jt = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/, k = (e, t) => (e.code = t, e), Mt = (e, t) => {
1003
1010
  if (e.length === 0) return t;
1004
1011
  if (t.length === 0) return e;
1005
1012
  let n = new Uint8Array(e.length + t.length);
1006
1013
  return n.set(e, 0), n.set(t, e.length), n;
1007
- }, pt = (e, t) => {
1008
- for (let n = t; n + 1 < e.length; n++) if (e[n] === B && e[n + 1] === V) return n;
1014
+ }, Nt = (e, t) => {
1015
+ for (let n = t; n + 1 < e.length; n++) if (e[n] === kt && e[n + 1] === At) return n;
1009
1016
  return -1;
1010
- }, mt = (e) => {
1011
- 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;
1017
+ }, Pt = (e) => {
1018
+ for (let t = 0; t + 3 < e.length; t++) if (e[t] === kt && e[t + 1] === At && e[t + 2] === kt && e[t + 3] === At) return t;
1012
1019
  return -1;
1013
- }, U = class {
1020
+ }, A = class {
1014
1021
  buf = new Uint8Array();
1015
1022
  state = "HEAD";
1016
1023
  framing = "none";
@@ -1021,10 +1028,10 @@ var Ze = /* @__PURE__ */ n({
1021
1028
  this.mode = e, this.handlers = t;
1022
1029
  }
1023
1030
  execute(e) {
1024
- this.buf = ft(this.buf, e);
1031
+ this.buf = Mt(this.buf, e);
1025
1032
  let t = !0;
1026
1033
  for (; t;) if (t = !1, this.state === "HEAD") {
1027
- let e = mt(this.buf);
1034
+ let e = Pt(this.buf);
1028
1035
  if (e === -1) return;
1029
1036
  let n = this.buf.subarray(0, e);
1030
1037
  this.buf = this.buf.subarray(e + 4);
@@ -1039,7 +1046,7 @@ var Ze = /* @__PURE__ */ n({
1039
1046
  this.state = "HEAD", this.framing = "none", this.bodyRemaining = 0, this.chunkState = "size", this.skipBody = !1;
1040
1047
  }
1041
1048
  parseHead(e) {
1042
- let t = ct.decode(e).split("\r\n"), n = t.shift() ?? "", r = [];
1049
+ let t = Tt.decode(e).split("\r\n"), n = t.shift() ?? "", r = [];
1043
1050
  for (let e of t) (e.startsWith(" ") || e.startsWith(" ")) && r.length > 0 ? r[r.length - 1] += " " + e.trim() : r.push(e);
1044
1051
  let i = [], a = {};
1045
1052
  for (let e of r) {
@@ -1077,7 +1084,7 @@ var Ze = /* @__PURE__ */ n({
1077
1084
  return;
1078
1085
  }
1079
1086
  let i = e[r];
1080
- i === void 0 ? e[r] = n : ut.has(r) || (e[r] = `${i}, ${n}`);
1087
+ i === void 0 ? e[r] = n : Ot.has(r) || (e[r] = `${i}, ${n}`);
1081
1088
  }
1082
1089
  setupBody(e) {
1083
1090
  if (this.skipBody) {
@@ -1110,9 +1117,9 @@ var Ze = /* @__PURE__ */ n({
1110
1117
  }
1111
1118
  consumeChunked() {
1112
1119
  for (;;) if (this.chunkState === "size") {
1113
- let e = pt(this.buf, 0);
1120
+ let e = Nt(this.buf, 0);
1114
1121
  if (e === -1) return !1;
1115
- let t = ct.decode(this.buf.subarray(0, e)), n = parseInt(t.split(";")[0].trim(), 16);
1122
+ let t = Tt.decode(this.buf.subarray(0, e)), n = parseInt(t.split(";")[0].trim(), 16);
1116
1123
  if (this.buf = this.buf.subarray(e + 2), Number.isNaN(n)) return !0;
1117
1124
  n === 0 ? this.chunkState = "trailer" : (this.bodyRemaining = n, this.chunkState = "data");
1118
1125
  } else if (this.chunkState === "data") {
@@ -1123,13 +1130,13 @@ var Ze = /* @__PURE__ */ n({
1123
1130
  if (this.buf.length < 2) return !1;
1124
1131
  this.buf = this.buf.subarray(2), this.chunkState = "size";
1125
1132
  } else {
1126
- let e = pt(this.buf, 0);
1133
+ let e = Nt(this.buf, 0);
1127
1134
  if (e === -1) return !1;
1128
1135
  let t = e === 0;
1129
1136
  if (this.buf = this.buf.subarray(e + 2), t) return !0;
1130
1137
  }
1131
1138
  }
1132
- }, ht = (e, t) => h.isBuffer(e) ? e : typeof e == "string" ? h.from(e, t ?? "utf8") : e instanceof Uint8Array ? h.from(e) : e instanceof ArrayBuffer ? h.from(new Uint8Array(e)) : h.from(String(e)), W = class extends f.Readable {
1139
+ }, Ft = (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)), j = class extends d.Readable {
1133
1140
  httpVersion = "1.1";
1134
1141
  httpVersionMajor = 1;
1135
1142
  httpVersionMinor = 1;
@@ -1156,16 +1163,16 @@ var Ze = /* @__PURE__ */ n({
1156
1163
  setTimeout(e, t) {
1157
1164
  return this.socket.setTimeout(e, t), this;
1158
1165
  }
1159
- }, G = class extends f.Writable {
1166
+ }, It = class extends d.Writable {
1160
1167
  _headerStore = /* @__PURE__ */ new Map();
1161
1168
  headersSent = !1;
1162
1169
  chunkedEncoding = !1;
1163
1170
  finished = !1;
1164
1171
  _bodyWritten = !1;
1165
1172
  setHeader(e, t) {
1166
- if (this.headersSent) throw H(/* @__PURE__ */ Error("Cannot set headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
1167
- if (typeof e != "string" || !dt.test(e)) throw H(/* @__PURE__ */ TypeError(`Header name must be a valid HTTP token [${JSON.stringify(String(e))}]`), "ERR_INVALID_HTTP_TOKEN");
1168
- if (t === void 0) throw H(/* @__PURE__ */ TypeError(`Invalid value "undefined" for header "${e}"`), "ERR_HTTP_INVALID_HEADER_VALUE");
1173
+ if (this.headersSent) throw k(/* @__PURE__ */ Error("Cannot set headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
1174
+ if (typeof e != "string" || !jt.test(e)) throw k(/* @__PURE__ */ TypeError(`Header name must be a valid HTTP token [${JSON.stringify(String(e))}]`), "ERR_INVALID_HTTP_TOKEN");
1175
+ if (t === void 0) throw k(/* @__PURE__ */ TypeError(`Invalid value "undefined" for header "${e}"`), "ERR_HTTP_INVALID_HEADER_VALUE");
1169
1176
  return this._headerStore.set(e.toLowerCase(), [e, Array.isArray(t) ? [...t] : t]), this;
1170
1177
  }
1171
1178
  getHeader(e) {
@@ -1205,30 +1212,30 @@ var Ze = /* @__PURE__ */ n({
1205
1212
  return this._bodyWritten = !0, super.write(e, t, n);
1206
1213
  }
1207
1214
  _write(e, t, n) {
1208
- let r = ht(e), i = [];
1209
- if (this.headersSent ||= (this._implicitHeader(), i.push(h.from(this._headBlock, "latin1")), !0), this.chunkedEncoding ? r.length > 0 && (i.push(h.from(`${r.length.toString(16)}\r\n`, "latin1")), i.push(r), i.push(h.from("\r\n", "latin1"))) : i.push(r), i.length === 0) {
1215
+ let r = Ft(e), i = [];
1216
+ 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) {
1210
1217
  n();
1211
1218
  return;
1212
1219
  }
1213
- this._writeToSocket(h.concat(i), n);
1220
+ this._writeToSocket(m.concat(i), n);
1214
1221
  }
1215
1222
  _final(e) {
1216
1223
  let t = [];
1217
- if (this.headersSent ||= (!this.chunkedEncoding && !this.hasHeader("content-length") && this.setHeader("Content-Length", 0), this._implicitHeader(), t.push(h.from(this._headBlock, "latin1")), !0), this.chunkedEncoding && t.push(h.from("0\r\n\r\n", "latin1")), this.finished = !0, t.length === 0) {
1224
+ 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) {
1218
1225
  e();
1219
1226
  return;
1220
1227
  }
1221
- this._writeToSocket(h.concat(t), e);
1228
+ this._writeToSocket(m.concat(t), e);
1222
1229
  }
1223
1230
  end(e, t, n) {
1224
1231
  if (e != null && typeof e != "function" && !this._bodyWritten && !this.headersSent && !this.chunkedEncoding && !this.hasHeader("content-length")) {
1225
1232
  let n = typeof t == "string" ? t : void 0;
1226
- this.setHeader("Content-Length", ht(e, n).length);
1233
+ this.setHeader("Content-Length", Ft(e, n).length);
1227
1234
  }
1228
1235
  return super.end(e, t, n);
1229
1236
  }
1230
1237
  _headBlock;
1231
- }, K = class extends G {
1238
+ }, Lt = class extends It {
1232
1239
  statusCode = 200;
1233
1240
  statusMessage;
1234
1241
  _writeHeadCalled = !1;
@@ -1245,7 +1252,7 @@ var Ze = /* @__PURE__ */ n({
1245
1252
  return !(e >= 100 && e < 200 || e === 204 || e === 304);
1246
1253
  }
1247
1254
  writeHead(e, t, n) {
1248
- if (this._writeHeadCalled || this.headersSent) throw H(/* @__PURE__ */ Error("Cannot render headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
1255
+ if (this._writeHeadCalled || this.headersSent) throw k(/* @__PURE__ */ Error("Cannot render headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
1249
1256
  this._writeHeadCalled = !0, this.statusCode = e;
1250
1257
  let r = n;
1251
1258
  if (typeof t == "string" ? this.statusMessage = t : t != null && (r = t), Array.isArray(r)) {
@@ -1263,16 +1270,16 @@ var Ze = /* @__PURE__ */ n({
1263
1270
  }
1264
1271
  }
1265
1272
  _implicitHeader() {
1266
- let e = this.statusMessage ?? z[this.statusCode] ?? "unknown";
1273
+ let e = this.statusMessage ?? Dt[this.statusCode] ?? "unknown";
1267
1274
  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}`);
1268
1275
  }
1269
1276
  writeContinue() {
1270
- this._writeToSocket(h.from("HTTP/1.1 100 Continue\r\n\r\n", "latin1"), () => {});
1277
+ this._writeToSocket(m.from("HTTP/1.1 100 Continue\r\n\r\n", "latin1"), () => {});
1271
1278
  }
1272
1279
  setTimeout(e, t) {
1273
1280
  return this.socket?.setTimeout(e, t), this;
1274
1281
  }
1275
- }, gt = (...e) => {
1282
+ }, Rt = (...e) => {
1276
1283
  let t = {}, n = {}, r, i = [...e], a = i.shift();
1277
1284
  if (typeof a == "string" || a instanceof URL) {
1278
1285
  let e = typeof a == "string" ? new URL(a) : a;
@@ -1294,7 +1301,7 @@ var Ze = /* @__PURE__ */ n({
1294
1301
  },
1295
1302
  callback: r
1296
1303
  };
1297
- }, q = class extends G {
1304
+ }, zt = class extends It {
1298
1305
  method;
1299
1306
  path;
1300
1307
  host;
@@ -1316,7 +1323,7 @@ var Ze = /* @__PURE__ */ n({
1316
1323
  let e = this.protocol === "https:" && r === 443 || this.protocol !== "https:" && r === 80;
1317
1324
  this.setHeader("Host", e ? n : `${n}:${r}`);
1318
1325
  }
1319
- e.auth && !this.hasHeader("authorization") && this.setHeader("Authorization", `Basic ${h.from(e.auth).toString("base64")}`), this.socket = new F(), this.emit("socket", this.socket), this.socket.on("error", (e) => {
1326
+ e.auth && !this.hasHeader("authorization") && this.setHeader("Authorization", `Basic ${m.from(e.auth).toString("base64")}`), this.socket = new E(), this.emit("socket", this.socket), this.socket.on("error", (e) => {
1320
1327
  this._aborted || this.emit("error", e);
1321
1328
  }), this._attachResponseParser(), this.socket.connect({
1322
1329
  host: n,
@@ -1332,12 +1339,12 @@ var Ze = /* @__PURE__ */ n({
1332
1339
  this._headBlock = this._storeHeader(`${this.method} ${this.path} HTTP/1.1`);
1333
1340
  }
1334
1341
  _attachResponseParser() {
1335
- let e = new W(this.socket), t = new U("response", {
1342
+ let e = new j(this.socket), t = new A("response", {
1336
1343
  onHeaders: (n) => {
1337
1344
  e._applyHead(n), this.method === "HEAD" && (t.skipBody = !0), this.res = e, this.emit("response", e);
1338
1345
  },
1339
1346
  onBody: (t) => {
1340
- e.push(h.from(t));
1347
+ e.push(m.from(t));
1341
1348
  },
1342
1349
  onComplete: () => {
1343
1350
  e.complete = !0, e.push(null);
@@ -1376,22 +1383,22 @@ var Ze = /* @__PURE__ */ n({
1376
1383
  setSocketKeepAlive(e, t) {
1377
1384
  this.socket.setKeepAlive(e, t);
1378
1385
  }
1379
- }, J = new Proxy(class extends I {
1386
+ }, Bt = new Proxy(class extends D {
1380
1387
  constructor(e, t) {
1381
1388
  let n = {}, r = t;
1382
1389
  typeof e == "function" ? r = e : e && (n = e), super(n), r && this.on("request", r), this.on("connection", (e) => this._handleConnection(e));
1383
1390
  }
1384
1391
  _handleConnection(e) {
1385
- let t = null, n = new U("request", {
1392
+ let t = null, n = new A("request", {
1386
1393
  onHeaders: (r) => {
1387
- t = new W(e), t._applyHead(r), r.method === "HEAD" && (n.skipBody = !0);
1388
- let i = new K(t), a = String(r.headers.connection ?? "").toLowerCase();
1394
+ t = new j(e), t._applyHead(r), r.method === "HEAD" && (n.skipBody = !0);
1395
+ let i = new Lt(t), a = String(r.headers.connection ?? "").toLowerCase();
1389
1396
  i._keepAlive = r.httpVersionMinor >= 1 ? a !== "close" : a === "keep-alive", i.on("finish", () => {
1390
1397
  i._keepAlive || e.end();
1391
1398
  }), this.emit("request", t, i);
1392
1399
  },
1393
1400
  onBody: (e) => {
1394
- t?.push(h.from(e));
1401
+ t?.push(m.from(e));
1395
1402
  },
1396
1403
  onComplete: () => {
1397
1404
  t && (t.complete = !0, t.push(null)), t = null;
@@ -1401,7 +1408,7 @@ var Ze = /* @__PURE__ */ n({
1401
1408
  n.finish(), t && t.push(null);
1402
1409
  }), e.on("error", (t) => this.emit("clientError", t, e));
1403
1410
  }
1404
- }, { apply: (e, t, n) => new e(...n) }), Y = class {
1411
+ }, { apply: (e, t, n) => new e(...n) }), Vt = class {
1405
1412
  maxSockets;
1406
1413
  maxFreeSockets;
1407
1414
  keepAlive;
@@ -1413,166 +1420,469 @@ var Ze = /* @__PURE__ */ n({
1413
1420
  return `${e.host ?? "localhost"}:${e.port ?? ""}:${e.localAddress ?? ""}`;
1414
1421
  }
1415
1422
  destroy() {}
1416
- }, _t = new Y(), X = (...e) => {
1417
- let { options: t, callback: n } = gt(...e);
1418
- return new q(t, n);
1419
- }, vt = (...e) => {
1420
- let t = X(...e);
1423
+ }, Ht = new Vt(), Ut = (...e) => {
1424
+ let { options: t, callback: n } = Rt(...e);
1425
+ return new zt(t, n);
1426
+ }, Wt = (...e) => {
1427
+ let t = Ut(...e);
1421
1428
  return t.end(), t;
1422
- }, yt = (e, t) => new J(e, t), bt = {
1423
- METHODS: lt,
1424
- STATUS_CODES: z,
1425
- Agent: Y,
1426
- globalAgent: _t,
1427
- Server: J,
1428
- ServerResponse: K,
1429
- IncomingMessage: W,
1430
- ClientRequest: q,
1431
- OutgoingMessage: G,
1432
- createServer: yt,
1433
- request: X,
1434
- get: vt
1435
- }, xt = /* @__PURE__ */ n({
1436
- available: () => St,
1437
- dgram: () => nt,
1438
- dns: () => We,
1439
- fetch: () => He,
1440
- http: () => st,
1441
- net: () => Ze,
1442
- quota: () => Ue
1443
- }), St = () => ze, Z = async (e) => {
1429
+ }, Gt = (e, t) => new Bt(e, t), Kt = {
1430
+ METHODS: Et,
1431
+ STATUS_CODES: Dt,
1432
+ Agent: Vt,
1433
+ globalAgent: Ht,
1434
+ Server: Bt,
1435
+ ServerResponse: Lt,
1436
+ IncomingMessage: j,
1437
+ ClientRequest: zt,
1438
+ OutgoingMessage: It,
1439
+ createServer: Gt,
1440
+ request: Ut,
1441
+ get: Wt
1442
+ }, qt = /* @__PURE__ */ n({
1443
+ available: () => Jt,
1444
+ dgram: () => vt,
1445
+ dns: () => Qe,
1446
+ fetch: () => Xe,
1447
+ fs: () => et,
1448
+ http: () => wt,
1449
+ net: () => pt,
1450
+ quota: () => Ze
1451
+ }), Jt = () => qe, Yt = async (e) => {
1444
1452
  if (typeof window > "u") return !1;
1445
- if (_()) return !0;
1446
- let t = await M, n = null, r = new Promise((e) => {
1453
+ if (g()) return !0;
1454
+ let t = await w, n = null, r = new Promise((e) => {
1447
1455
  n = () => {
1448
- _() && e(!0);
1449
- }, g.addEventListener("statuschange", n);
1456
+ g() && e(!0);
1457
+ }, h.addEventListener("statuschange", n);
1450
1458
  }), i = t.installPrompt.show(e).then(() => !1), a = await Promise.race([r, i]);
1451
- return n && g.removeEventListener("statuschange", n), await t.installPrompt.hide().catch(() => {}), a;
1452
- }, Q = null;
1453
- y(() => (Q ||= Z().then(() => void 0).finally(() => {
1454
- Q = null;
1455
- }), Q));
1459
+ return n && h.removeEventListener("statuschange", n), await t.installPrompt.hide().catch(() => {}), a;
1460
+ }, Xt = null;
1461
+ se(() => (Xt ||= Yt().then(() => void 0).finally(() => {
1462
+ Xt = null;
1463
+ }), Xt));
1456
1464
  //#endregion
1457
1465
  //#region src/lib/desktop.ts
1458
- var Ct = /* @__PURE__ */ n({
1459
- available: () => wt,
1460
- dgram: () => Ot,
1461
- dns: () => Et,
1462
- fetch: () => Tt,
1463
- fs: () => kt,
1464
- net: () => Dt
1465
- }), wt = () => !1, $ = (e) => (...t) => {
1466
+ var Zt = /* @__PURE__ */ n({
1467
+ available: () => Qt,
1468
+ dgram: () => nn,
1469
+ dns: () => en,
1470
+ fetch: () => $t,
1471
+ fs: () => rn,
1472
+ net: () => tn
1473
+ }), Qt = () => !1, M = (e) => (...t) => {
1466
1474
  throw Error(`The FKN desktop app is not connected, desktop.${e} is unavailable`);
1467
- }, Tt = $("fetch"), Et = { lookup: $("dns.lookup") }, Dt = {
1468
- connect: $("net.connect"),
1469
- createConnection: $("net.createConnection"),
1470
- createServer: $("net.createServer")
1471
- }, Ot = { createSocket: $("dgram.createSocket") }, kt = {
1472
- isLocalDirectorySupported: () => !1,
1473
- pickLocalDirectory: $("fs.pickLocalDirectory"),
1474
- queryDirectoryPermission: $("fs.queryDirectoryPermission"),
1475
- ensureDirectoryPermission: $("fs.ensureDirectoryPermission")
1476
- }, At = () => typeof document < "u" && _(), jt = async (e, t) => {
1477
- if (Ve(e), t?.credentials === "include") {
1475
+ }, $t = M("fetch"), en = { lookup: M("dns.lookup") }, tn = {
1476
+ connect: M("net.connect"),
1477
+ createConnection: M("net.createConnection"),
1478
+ createServer: M("net.createServer")
1479
+ }, nn = { createSocket: M("dgram.createSocket") }, rn = {
1480
+ available: async () => !1,
1481
+ list: M("fs.list"),
1482
+ readFile: M("fs.readFile"),
1483
+ writeFile: M("fs.writeFile"),
1484
+ remove: M("fs.remove")
1485
+ }, an = () => typeof document < "u" && g(), on = async (e, t) => {
1486
+ if (Ye(e), t?.credentials === "include") {
1478
1487
  if (typeof document > "u") throw Error("fetch with credentials needs the FKN extension, which only exists in window realms");
1479
- return he(e, t);
1488
+ return be(e, t);
1480
1489
  }
1481
- return At() ? he(e, {
1490
+ return an() ? be(e, {
1482
1491
  ...t,
1483
1492
  credentials: "omit"
1484
- }) : wt() ? Tt(e, t) : He(e, t);
1485
- }, Mt = /* @__PURE__ */ n({
1486
- ATTACH_FRAME_EVENT_KEY: () => w,
1487
- assertAttachableFrameUrl: () => E,
1488
- assertFetchableUrl: () => C,
1489
- attachFrame: () => we,
1490
- attachFramePermission: () => xe,
1491
- available: () => At,
1493
+ }) : Qt() ? $t(e, t) : Xe(e, t);
1494
+ }, sn = /* @__PURE__ */ n({
1495
+ ATTACH_FRAME_EVENT_KEY: () => Ee,
1496
+ assertAttachableFrameUrl: () => y,
1497
+ assertFetchableUrl: () => _e,
1498
+ attachFrame: () => je,
1499
+ attachFramePermission: () => Oe,
1500
+ available: () => an,
1492
1501
  box: () => l,
1493
- cookies: () => _e,
1502
+ cookies: () => Se,
1494
1503
  createVideoElementHandle: () => e,
1495
- evaluatePermission: () => Ce,
1496
- events: () => g,
1497
- extension: () => g,
1498
- fetch: () => he,
1499
- fetchCredentialedPermission: () => ce,
1500
- fetchLocalPermission: () => le,
1501
- fetchPermission: () => se,
1502
- gotoPermission: () => Se,
1504
+ evaluatePermission: () => Ae,
1505
+ events: () => h,
1506
+ extension: () => h,
1507
+ fetch: () => be,
1508
+ fetchCredentialedPermission: () => de,
1509
+ fetchLocalPermission: () => fe,
1510
+ fetchPermission: () => ue,
1511
+ gotoPermission: () => ke,
1503
1512
  handleRevivableModules: () => i,
1504
- isBlockedFetchUrl: () => S,
1505
- isBlockedFrameUrl: () => T,
1506
- isExtensionExposed: () => _,
1507
- isLocalNetworkUrl: () => de,
1513
+ isBlockedFetchUrl: () => ge,
1514
+ isBlockedFrameUrl: () => De,
1515
+ isExtensionExposed: () => g,
1516
+ isLocalNetworkUrl: () => me,
1508
1517
  isType: () => t,
1509
- modifyRequestHeadersPermission: () => ve,
1510
- permissions: () => Te,
1511
- promptInstall: () => Z,
1512
- readCookiePermission: () => ge,
1513
- removeRequestHeaderRule: () => be,
1518
+ modifyRequestHeadersPermission: () => Ce,
1519
+ permissions: () => Me,
1520
+ promptInstall: () => Yt,
1521
+ readCookiePermission: () => xe,
1522
+ removeRequestHeaderRule: () => Te,
1514
1523
  revive: () => o,
1515
- setMissingExtensionHandler: () => y,
1516
- setRequestHeaderRule: () => ye,
1524
+ setMissingExtensionHandler: () => se,
1525
+ setRequestHeaderRule: () => we,
1517
1526
  type: () => a,
1518
- waitForExtensionExposure: () => b
1519
- }), Nt = /* @__PURE__ */ n({
1520
- ensureDirectoryPermission: () => Lt,
1521
- isLocalDirectorySupported: () => Pt,
1522
- pickLocalDirectory: () => Ft,
1523
- queryDirectoryPermission: () => It
1524
- }), Pt = () => typeof window < "u" && "showDirectoryPicker" in window, Ft = async (e = {}) => {
1525
- if (!Pt()) return;
1526
- let t = window.showDirectoryPicker;
1527
- return t({
1528
- mode: "readwrite",
1529
- ...e
1530
- }).catch((e) => {
1531
- if (e?.name !== "AbortError") throw e;
1527
+ waitForExtensionExposure: () => _
1528
+ }), cn = /* @__PURE__ */ n({
1529
+ available: () => fn,
1530
+ list: () => hn,
1531
+ readFile: () => pn,
1532
+ remove: () => mn,
1533
+ writeFile: () => N
1534
+ }), ln = () => navigator.storage.getDirectory(), un = (e) => {
1535
+ let t = e.split("/").filter((e) => e && e !== ".");
1536
+ if (t.some((e) => e === "..") || !t.length) throw Error("opfs: invalid path");
1537
+ return t;
1538
+ }, dn = async (e, t) => {
1539
+ let n = await ln();
1540
+ for (let r of e) n = await n.getDirectoryHandle(r, { create: t });
1541
+ return n;
1542
+ }, fn = async () => {
1543
+ try {
1544
+ return typeof navigator < "u" && !!navigator.storage?.getDirectory && !!await ln();
1545
+ } catch {
1546
+ return !1;
1547
+ }
1548
+ }, N = async (e, t, n) => {
1549
+ let r = un(e), i = r.pop(), a = await (await (await dn(r, !0)).getFileHandle(i, { create: !0 })).createWritable({ keepExistingData: !1 });
1550
+ try {
1551
+ let e = t instanceof Blob ? t : new Blob([t], n?.contentType ? { type: n.contentType } : void 0);
1552
+ await a.write(e);
1553
+ } finally {
1554
+ await a.close();
1555
+ }
1556
+ }, pn = async (e) => {
1557
+ let t = un(e), n = t.pop();
1558
+ return (await (await dn(t, !1)).getFileHandle(n)).getFile();
1559
+ }, mn = async (e) => {
1560
+ let t = un(e), n = t.pop();
1561
+ await (await dn(t, !1)).removeEntry(n, { recursive: !0 });
1562
+ }, hn = async () => {
1563
+ let e = [], t = async (n, r) => {
1564
+ for await (let [i, a] of n.entries()) {
1565
+ let n = r ? `${r}/${i}` : i;
1566
+ if (a.kind === "file") {
1567
+ let t = await a.getFile();
1568
+ e.push({
1569
+ path: n,
1570
+ size: t.size,
1571
+ contentType: t.type || null,
1572
+ updatedAt: new Date(t.lastModified).toISOString()
1573
+ });
1574
+ } else await t(a, n);
1575
+ }
1576
+ };
1577
+ return await t(await ln(), ""), e;
1578
+ }, gn = /* @__PURE__ */ n({
1579
+ available: () => vn,
1580
+ list: () => yn,
1581
+ pull: () => Cn,
1582
+ readFile: () => bn,
1583
+ remove: () => Sn,
1584
+ writeFile: () => xn
1585
+ }), _n, P = async () => await (_n ??= fn().catch(() => !1)) ? !0 : (_n = void 0, !1), F = () => tt().catch(() => !1), vn = async () => await P() || await F(), yn = async () => {
1586
+ let [e, t] = await Promise.all([P().then((e) => e ? hn() : []).catch(() => []), F().then((e) => e ? nt() : []).catch(() => [])]), n = /* @__PURE__ */ new Map(), r = (e) => {
1587
+ let t = Date.parse(e.updatedAt ?? "");
1588
+ return Number.isFinite(t) ? t : 0;
1589
+ }, i = (e) => {
1590
+ let t = n.get(e.path);
1591
+ (!t || r(e) >= r(t)) && n.set(e.path, e);
1592
+ };
1593
+ for (let t of e) i(t);
1594
+ for (let e of t) i(e);
1595
+ return [...n.values()];
1596
+ }, bn = async (e) => {
1597
+ if (await P()) try {
1598
+ return await pn(e);
1599
+ } catch (e) {
1600
+ if (e?.name !== "NotFoundError") throw e;
1601
+ }
1602
+ let t = await T(e);
1603
+ return await P() && N(e, t).catch(() => {}), t;
1604
+ }, xn = async (e, t, n) => {
1605
+ let r = t instanceof Blob ? t : new Blob([t], n?.contentType ? { type: n.contentType } : void 0);
1606
+ if (await P()) {
1607
+ await N(e, r, n), await F() && it(e, r, n).catch((e) => console.warn("fs: cloud replicate failed", e));
1608
+ return;
1609
+ }
1610
+ if (await F()) return it(e, r, n);
1611
+ throw Error("fs: no storage backend available");
1612
+ }, Sn = async (e) => {
1613
+ let t = [];
1614
+ if (await P() && t.push(mn(e).catch(() => {})), await F() && t.push(at(e).catch(() => {})), !t.length) throw Error("fs: no storage backend available");
1615
+ await Promise.all(t);
1616
+ }, Cn = async (e) => {
1617
+ let t = await T(e);
1618
+ return await P() && await N(e, t), t;
1619
+ }, I = new Map([["", {
1620
+ kind: "dir",
1621
+ mtimeMs: 0
1622
+ }]]), L = /* @__PURE__ */ new Set(), R = /* @__PURE__ */ new Set(), wn = () => Date.now(), z = (e, t, n) => {
1623
+ let r = /* @__PURE__ */ Error(`${e}: ${{
1624
+ ENOENT: "no such file or directory",
1625
+ EEXIST: "file already exists",
1626
+ ENOTDIR: "not a directory",
1627
+ EISDIR: "illegal operation on a directory",
1628
+ ENOTEMPTY: "directory not empty"
1629
+ }[e] ?? e}, ${n} '${t}'`);
1630
+ return r.code = e, r.path = t, r.syscall = n, r;
1631
+ }, B = (e) => {
1632
+ let t = [];
1633
+ for (let n of e.split("/")) if (!(!n || n === ".")) {
1634
+ if (n === "..") {
1635
+ t.pop();
1636
+ continue;
1637
+ }
1638
+ t.push(n);
1639
+ }
1640
+ return t.join("/");
1641
+ }, V = (e) => e.split("/").slice(0, -1).join("/"), H = (e) => {
1642
+ if (!e) return;
1643
+ let t = e.split("/"), n = "";
1644
+ for (let e of t) {
1645
+ n = n ? `${n}/${e}` : e;
1646
+ let t = I.get(n);
1647
+ if (!t) I.set(n, {
1648
+ kind: "dir",
1649
+ mtimeMs: wn()
1650
+ });
1651
+ else if (t.kind === "file") throw z("ENOTDIR", n, "mkdir");
1652
+ }
1653
+ }, Tn, U = () => Tn ??= (async () => {
1654
+ let e = await yn().catch(() => []);
1655
+ for (let t of e) try {
1656
+ let e = B(t.path);
1657
+ if (L.has(e)) continue;
1658
+ let n = await (await bn(t.path)).arrayBuffer();
1659
+ H(V(e));
1660
+ let r = Date.parse(t.updatedAt ?? "");
1661
+ I.set(e, {
1662
+ kind: "file",
1663
+ data: new Uint8Array(n),
1664
+ mtimeMs: Number.isFinite(r) ? r : wn()
1665
+ });
1666
+ } catch {}
1667
+ })(), En = async () => {
1668
+ Tn = void 0, await U();
1669
+ }, W = async () => {
1670
+ let e = [...L].map(async (e) => {
1671
+ let t = I.get(e);
1672
+ if (t?.kind !== "file") {
1673
+ L.delete(e);
1674
+ return;
1675
+ }
1676
+ let n = t.data;
1677
+ try {
1678
+ await xn(e, n), I.get(e)?.kind === "file" && I.get(e).data === n && L.delete(e);
1679
+ } catch {}
1680
+ }), t = [...R].map(async (e) => {
1681
+ try {
1682
+ await Sn(e), R.delete(e);
1683
+ } catch {}
1684
+ });
1685
+ await Promise.all([...e, ...t]);
1686
+ }, Dn, On = () => {
1687
+ Dn ||= setTimeout(() => {
1688
+ Dn = void 0, W().catch(() => {});
1689
+ }, 250);
1690
+ };
1691
+ typeof addEventListener < "u" && (addEventListener("pagehide", () => {
1692
+ W().catch(() => {});
1693
+ }), addEventListener("visibilitychange", () => {
1694
+ typeof document < "u" && document.visibilityState === "hidden" && W().catch(() => {});
1695
+ }));
1696
+ var kn = (e, t) => ({
1697
+ size: t.kind === "file" ? t.data.byteLength : 0,
1698
+ mtimeMs: t.mtimeMs,
1699
+ mtime: new Date(t.mtimeMs),
1700
+ atimeMs: t.mtimeMs,
1701
+ ctimeMs: t.mtimeMs,
1702
+ mode: t.kind === "file" ? 420 : 493,
1703
+ isFile: () => t.kind === "file",
1704
+ isDirectory: () => t.kind === "dir",
1705
+ isSymbolicLink: () => !1
1706
+ }), An = (e) => I.has(B(e)), G = (e) => {
1707
+ let t = B(e), n = I.get(t);
1708
+ if (!n) throw z("ENOENT", e, "stat");
1709
+ return kn(t, n);
1710
+ }, jn = (e) => {
1711
+ let t = I.get(B(e));
1712
+ if (!t) throw z("ENOENT", e, "open");
1713
+ if (t.kind === "dir") throw z("EISDIR", e, "read");
1714
+ return t.data;
1715
+ }, K = (e, t, n) => {
1716
+ let r = B(e);
1717
+ if (!r) throw z("EISDIR", e, "open");
1718
+ let i = I.get(r);
1719
+ if (i?.kind === "dir") throw z("EISDIR", e, "open");
1720
+ H(V(r));
1721
+ let a = n && i?.kind === "file" ? Mn(i.data, t) : t;
1722
+ I.set(r, {
1723
+ kind: "file",
1724
+ data: a,
1725
+ mtimeMs: wn()
1726
+ }), L.add(r), R.delete(r), On();
1727
+ }, Mn = (e, t) => {
1728
+ let n = new Uint8Array(e.byteLength + t.byteLength);
1729
+ return n.set(e, 0), n.set(t, e.byteLength), n;
1730
+ }, Nn = (e, t) => {
1731
+ let n = B(e);
1732
+ if (n) {
1733
+ if (I.has(n)) {
1734
+ if (t) return;
1735
+ throw z("EEXIST", e, "mkdir");
1736
+ }
1737
+ if (!t && !I.has(V(n))) throw z("ENOENT", e, "mkdir");
1738
+ H(n);
1739
+ }
1740
+ }, Pn = (e) => {
1741
+ let t = B(e), n = I.get(t);
1742
+ if (!n) throw z("ENOENT", e, "scandir");
1743
+ if (n.kind === "file") throw z("ENOTDIR", e, "scandir");
1744
+ let r = t ? `${t}/` : "", i = /* @__PURE__ */ new Set();
1745
+ for (let e of I.keys()) {
1746
+ if (!e || !e.startsWith(r)) continue;
1747
+ let t = e.slice(r.length);
1748
+ if (!t || t.includes("/")) {
1749
+ t.includes("/") && i.add(t.split("/")[0]);
1750
+ continue;
1751
+ }
1752
+ i.add(t);
1753
+ }
1754
+ return [...i];
1755
+ }, q = (e, t) => {
1756
+ let n = B(e);
1757
+ if (!I.get(n)) {
1758
+ if (t) return;
1759
+ throw z("ENOENT", e, "unlink");
1760
+ }
1761
+ let r = `${n}/`, i = [...I.keys()].filter((e) => e.startsWith(r));
1762
+ if (i.length && !t) throw z("ENOTEMPTY", e, "rmdir");
1763
+ for (let e of [n, ...i]) {
1764
+ let t = I.get(e);
1765
+ I.delete(e), t?.kind === "file" && (L.delete(e), R.add(e));
1766
+ }
1767
+ On();
1768
+ }, Fn = (e, t) => {
1769
+ let n = B(e), r = B(t);
1770
+ if (!n) throw z("EBUSY", e, "rename");
1771
+ if (r === n || r.startsWith(`${n}/`)) throw z("EINVAL", e, "rename");
1772
+ let i = I.get(n);
1773
+ if (!i) throw z("ENOENT", e, "rename");
1774
+ let a = I.get(r);
1775
+ if (a) {
1776
+ if (a.kind !== i.kind) throw z(i.kind === "dir" ? "ENOTDIR" : "EISDIR", t, "rename");
1777
+ q(r, !0);
1778
+ }
1779
+ H(V(r));
1780
+ let o = `${n}/`, s = [n, ...[...I.keys()].filter((e) => e.startsWith(o))];
1781
+ for (let e of s) {
1782
+ let t = r + e.slice(n.length), i = I.get(e);
1783
+ I.set(t, i), I.delete(e), i.kind === "file" && (L.add(t), R.delete(t), L.delete(e), R.add(e));
1784
+ }
1785
+ On();
1786
+ }, In = /* @__PURE__ */ n({
1787
+ appendFile: () => er,
1788
+ appendFileSync: () => Hn,
1789
+ exists: () => sr,
1790
+ existsSync: () => Un,
1791
+ flush: () => W,
1792
+ lstatSync: () => Gn,
1793
+ mkdir: () => rr,
1794
+ mkdirSync: () => qn,
1795
+ mount: () => U,
1796
+ promises: () => cr,
1797
+ readFile: () => Qn,
1798
+ readFileSync: () => Bn,
1799
+ readdir: () => nr,
1800
+ readdirSync: () => Kn,
1801
+ remount: () => En,
1802
+ rename: () => or,
1803
+ renameSync: () => Zn,
1804
+ rm: () => ir,
1805
+ rmSync: () => Jn,
1806
+ rmdirSync: () => Yn,
1807
+ stat: () => tr,
1808
+ statSync: () => Wn,
1809
+ unlink: () => ar,
1810
+ unlinkSync: () => Xn,
1811
+ writeFile: () => $n,
1812
+ writeFileSync: () => Vn
1813
+ }), J = (e) => typeof e == "string" ? e : e instanceof URL ? decodeURIComponent(e.pathname) : e.toString(), Ln = (e) => typeof e == "string" ? e : e?.encoding ?? void 0, Rn = (e) => typeof e == "object" && !!e?.recursive, zn = (e, t) => {
1814
+ let n = Ln(t);
1815
+ return n ? m.from(e).toString(n) : m.from(e);
1816
+ }, Y = (e, t) => {
1817
+ if (typeof e == "string") return new Uint8Array(m.from(e, Ln(t) ?? "utf8"));
1818
+ if (e instanceof Uint8Array) return e.slice();
1819
+ if (e instanceof ArrayBuffer) return new Uint8Array(e).slice();
1820
+ if (ArrayBuffer.isView(e)) return new Uint8Array(e.buffer, e.byteOffset, e.byteLength).slice();
1821
+ throw TypeError("The \"data\" argument must be of type string, Buffer, TypedArray, or DataView");
1822
+ }, Bn = (e, t) => zn(jn(J(e)), t), Vn = (e, t, n) => K(J(e), Y(t, n), !1), Hn = (e, t, n) => K(J(e), Y(t, n), !0), Un = (e) => An(J(e)), Wn = (e) => G(J(e)), Gn = Wn, Kn = (e) => Pn(J(e)), qn = (e, t) => Nn(J(e), Rn(t)), Jn = (e, t) => q(J(e), !!t?.recursive), Yn = (e, t) => q(J(e), !!t?.recursive), Xn = (e) => q(J(e), !1), Zn = (e, t) => Fn(J(e), J(t)), X = (e, t) => {
1823
+ U().finally(() => {
1824
+ let n;
1825
+ try {
1826
+ n = e();
1827
+ } catch (e) {
1828
+ t(e);
1829
+ return;
1830
+ }
1831
+ t(null, n);
1532
1832
  });
1533
- }, It = async (e, t = "readwrite") => {
1534
- let { queryPermission: n } = e;
1535
- return await n?.call(e, { mode: t }) ?? "granted";
1536
- }, Lt = async (e, t = "readwrite") => {
1537
- if (await It(e, t) === "granted") return !0;
1538
- let { requestPermission: n } = e;
1539
- return await n?.call(e, { mode: t }) === "granted";
1540
- }, Rt = "https://fkn.app", zt = (e, t) => {
1833
+ }, Z = (e, t) => typeof e == "function" ? e : t, Q = (e) => typeof e == "function" ? void 0 : e, Qn = (e, t, n) => X(() => zn(jn(J(e)), Q(t)), Z(t, n)), $n = (e, t, n, r) => X(() => K(J(e), Y(t, Q(n)), !1), Z(n, r)), er = (e, t, n, r) => X(() => K(J(e), Y(t, Q(n)), !0), Z(n, r)), tr = (e, t) => X(() => G(J(e)), t), nr = (e, t, n) => X(() => Pn(J(e)), Z(t, n)), rr = (e, t, n) => X(() => Nn(J(e), Rn(Q(t))), Z(t, n)), ir = (e, t, n) => X(() => q(J(e), !!Q(t)?.recursive), Z(t, n)), ar = (e, t) => X(() => q(J(e), !1), t), or = (e, t, n) => X(() => Fn(J(e), J(t)), n), sr = (e, t) => {
1834
+ U().finally(() => t(An(J(e))));
1835
+ }, $ = (e) => U().then(() => e()), cr = {
1836
+ readFile: (e, t) => $(() => zn(jn(J(e)), t)),
1837
+ writeFile: (e, t, n) => $(() => K(J(e), Y(t, n), !1)),
1838
+ appendFile: (e, t, n) => $(() => K(J(e), Y(t, n), !0)),
1839
+ stat: (e) => $(() => G(J(e))),
1840
+ lstat: (e) => $(() => G(J(e))),
1841
+ readdir: (e) => $(() => Pn(J(e))),
1842
+ mkdir: (e, t) => $(() => Nn(J(e), Rn(t))),
1843
+ rm: (e, t) => $(() => q(J(e), !!t?.recursive)),
1844
+ rmdir: (e, t) => $(() => q(J(e), !!t?.recursive)),
1845
+ unlink: (e) => $(() => q(J(e), !1)),
1846
+ rename: (e, t) => $(() => Fn(J(e), J(t))),
1847
+ access: (e) => $(() => {
1848
+ if (!An(J(e))) throw z("ENOENT", J(e), "access");
1849
+ })
1850
+ }, lr = "https://fkn.app", ur = (e, t) => {
1541
1851
  if (typeof window > "u") throw Error("FKN @fkn/lib: relayWorker must be called from the main thread");
1542
- if (!A?.contentWindow) throw Error("FKN @fkn/lib: relayWorker called before the FKN iframe was injected");
1543
- ee({
1852
+ if (!C?.contentWindow) throw Error("FKN @fkn/lib: relayWorker called before the FKN iframe was injected");
1853
+ te({
1544
1854
  receive: window,
1545
- emit: A.contentWindow
1855
+ emit: C.contentWindow
1546
1856
  }, e, {
1547
1857
  key: "fkn-api",
1548
- originA: t?.originA ?? Rt,
1858
+ originA: t?.originA ?? lr,
1549
1859
  originB: t?.originB ?? "*",
1550
1860
  unregisterSignal: t?.unregisterSignal
1551
1861
  });
1552
- }, Bt = async () => typeof window > "u" ? !1 : (await M).connect.prompt(location.origin).catch(() => !1), Vt = /* @__PURE__ */ n({
1553
- info: () => Wt,
1554
- login: () => Ht,
1555
- logout: () => Ut,
1556
- onChange: () => Gt
1557
- }), Ht = async () => typeof window > "u" ? !1 : (await M).account.login(location.origin).catch(() => !1), Ut = async () => {
1558
- typeof window > "u" || await (await M).account.logout().catch(() => {});
1559
- }, Wt = async () => {
1862
+ }, dr = async () => typeof window > "u" ? !1 : (await w).connect.prompt(location.origin).catch(() => !1), fr = /* @__PURE__ */ n({
1863
+ info: () => hr,
1864
+ login: () => pr,
1865
+ logout: () => mr,
1866
+ onChange: () => gr
1867
+ }), pr = async () => typeof window > "u" ? !1 : (await w).account.login(location.origin).catch(() => !1), mr = async () => {
1868
+ typeof window > "u" || await (await w).account.logout().catch(() => {});
1869
+ }, hr = async () => {
1560
1870
  if (typeof window > "u") return null;
1561
- let e = await M.then((e) => e.account.info()).catch(() => null);
1871
+ let e = await w.then((e) => e.account.info()).catch(() => null);
1562
1872
  return e ? {
1563
1873
  name: e.name,
1564
1874
  image: e.image,
1565
1875
  premium: e.premium,
1566
1876
  premiumUntil: e.premiumUntil ? Date.parse(e.premiumUntil) : null
1567
1877
  } : null;
1568
- }, Gt = async (e) => {
1878
+ }, gr = async (e) => {
1569
1879
  if (typeof window > "u") return () => {};
1570
- let t = await M.catch(() => null);
1880
+ let t = await w.catch(() => null);
1571
1881
  if (!t) return () => {};
1572
1882
  let n = await t.account.onChange(e).catch(() => null);
1573
1883
  return typeof n == "function" ? n : () => {};
1574
- }, Kt = "https://fkn.app", qt = (e = location.origin) => `${Kt}/connect-button?origin=${encodeURIComponent(e)}`, Jt = ({ className: e, style: t } = {}) => ne("iframe", {
1575
- src: qt(),
1884
+ }, _r = "https://fkn.app", vr = (e = location.origin) => `${_r}/connect-button?origin=${encodeURIComponent(e)}`, yr = ({ className: e, style: t } = {}) => re("iframe", {
1885
+ src: vr(),
1576
1886
  title: "Connect your FKN account",
1577
1887
  className: e,
1578
1888
  style: {
@@ -1585,4 +1895,4 @@ var Ct = /* @__PURE__ */ n({
1585
1895
  }
1586
1896
  });
1587
1897
  //#endregion
1588
- export { w as ATTACH_FRAME_EVENT_KEY, Jt as ConnectButton, Vt as account, E as assertAttachableFrameUrl, C as assertFetchableUrl, we as attachFrame, xe as attachFramePermission, l as box, xt as cloud, Bt as connect, qt as connectButtonUrl, _e as cookies, e as createVideoElementHandle, Ct as desktop, nt as dgram, We as dns, Ce as evaluatePermission, Mt as extension, jt as fetch, ce as fetchCredentialedPermission, le as fetchLocalPermission, se as fetchPermission, Nt as fs, Se as gotoPermission, i as handleRevivableModules, st as http, S as isBlockedFetchUrl, T as isBlockedFrameUrl, _ as isExtensionExposed, de as isLocalNetworkUrl, t as isType, ve as modifyRequestHeadersPermission, Ze as net, Te as permissions, Z as promptInstall, ge as readCookiePermission, zt as relayWorker, be as removeRequestHeaderRule, o as revive, y as setMissingExtensionHandler, ye as setRequestHeaderRule, a as type, b as waitForExtensionExposure };
1898
+ export { Ee as ATTACH_FRAME_EVENT_KEY, yr as ConnectButton, fr as account, y as assertAttachableFrameUrl, _e as assertFetchableUrl, je as attachFrame, Oe as attachFramePermission, l as box, qt as cloud, dr as connect, vr as connectButtonUrl, Se as cookies, e as createVideoElementHandle, Zt as desktop, vt as dgram, Qe as dns, Ae as evaluatePermission, sn as extension, on as fetch, de as fetchCredentialedPermission, fe as fetchLocalPermission, ue as fetchPermission, gn as fs, ke as gotoPermission, i as handleRevivableModules, wt as http, ge as isBlockedFetchUrl, De as isBlockedFrameUrl, g as isExtensionExposed, me as isLocalNetworkUrl, t as isType, Ce as modifyRequestHeadersPermission, pt as net, In as nodeFs, cn as opfs, Me as permissions, Yt as promptInstall, xe as readCookiePermission, ur as relayWorker, Te as removeRequestHeaderRule, o as revive, se as setMissingExtensionHandler, we as setRequestHeaderRule, a as type, _ as waitForExtensionExposure };