@fkn/lib 0.9.33 → 0.9.34

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 (77) hide show
  1. package/account.cjs +1 -1
  2. package/account.js +1 -1
  3. package/{api-BlAtp6lc.js → api-BdTgLphT.js} +61 -46
  4. package/{api-Cc5qxCHP.d.ts → api-Bgsg9t9D.d.ts} +3 -1
  5. package/api-MW-Lm0u8.cjs +3 -0
  6. package/api.cjs +1 -1
  7. package/api.d.ts +2 -2
  8. package/api.js +1 -1
  9. package/attach-policy.cjs +1 -1
  10. package/attach-policy.d.ts +30 -5
  11. package/attach-policy.js +16 -18
  12. package/cloud/dns.d.ts +1 -1
  13. package/cloud/fetch.cjs +1 -1
  14. package/cloud/fetch.d.ts +1 -1
  15. package/cloud/fetch.js +1 -1
  16. package/cloud/fs.cjs +1 -1
  17. package/cloud/fs.js +1 -1
  18. package/cloud/net.d.ts +1 -1
  19. package/{cloud-D0Ebu5bX.d.ts → cloud-C40YCPuv.d.ts} +4 -4
  20. package/cloud-DBNeXS9R.js +272 -0
  21. package/cloud-DHuqVKrl.cjs +1 -0
  22. package/cloud.cjs +1 -1
  23. package/cloud.d.ts +3 -3
  24. package/cloud.js +2 -2
  25. package/{contract-CahPObYc.d.ts → contract-Gd543I6m.d.ts} +21 -1
  26. package/contract.d.ts +2 -2
  27. package/dgram.cjs +1 -1
  28. package/dgram.d.ts +2 -2
  29. package/dgram.js +1 -1
  30. package/dns.cjs +1 -1
  31. package/dns.d.ts +1 -1
  32. package/dns.js +1 -1
  33. package/{extension-DNkuFy1Y.d.ts → extension-Bm-PwsD6.d.ts} +23 -147
  34. package/extension-DALH11b4.js +87 -0
  35. package/extension-lR-cSs2P.cjs +1 -0
  36. package/extension.cjs +1 -1
  37. package/extension.d.ts +3 -3
  38. package/extension.js +3 -3
  39. package/fs/promises.cjs +1 -1
  40. package/fs/promises.js +1 -1
  41. package/{fs-DxDxbvRS.cjs → fs-Bv3aFjqA.cjs} +1 -1
  42. package/{fs-BSsWw8HM.js → fs-O2bp9J0x.js} +1 -1
  43. package/fs.cjs +1 -1
  44. package/fs.js +1 -1
  45. package/hosts-C4-8lWwz.js +161 -0
  46. package/hosts-DD4rDeQH.cjs +1 -0
  47. package/http.d.ts +1 -1
  48. package/{index-DH3_12nU.d.ts → index-DIK21kfh.d.ts} +278 -5
  49. package/index.cjs +1 -1
  50. package/index.d.ts +5 -5
  51. package/index.js +62 -62
  52. package/{lib-duLPF_WZ.js → lib-C3f3XmGZ.js} +544 -393
  53. package/lib-WiHTYaNP.cjs +53 -0
  54. package/{net-BXPEJToS.d.ts → net-BBtYFEzu.d.ts} +2 -2
  55. package/net.cjs +1 -1
  56. package/net.d.ts +1 -1
  57. package/net.js +1 -1
  58. package/package.json +1 -1
  59. package/packages.cjs +1 -1
  60. package/packages.d.ts +1 -1
  61. package/packages.js +1 -1
  62. package/{proxy-DxiJU5Y_.d.ts → proxy-XeHtHIdZ.d.ts} +2 -2
  63. package/proxy-_m6Sqcr6.cjs +1 -0
  64. package/proxy-fXckOcRn.js +60 -0
  65. package/rooms.cjs +1 -1
  66. package/rooms.d.ts +1 -1
  67. package/rooms.js +1 -1
  68. package/{storage-Bo01npo9.js → storage-C6Cd4J5E.js} +1 -1
  69. package/{storage-DEjjVCT2.cjs → storage-D2eBifiu.cjs} +1 -1
  70. package/api-Beky02FK.cjs +0 -3
  71. package/cloud-BZmduWyX.cjs +0 -1
  72. package/cloud-DaVb11IV.js +0 -174
  73. package/extension-D70dtUvW.cjs +0 -1
  74. package/extension-DdXNlt9_.js +0 -84
  75. package/lib-DLM2M3_i.cjs +0 -53
  76. package/proxy-DexG-Wmk.cjs +0 -1
  77. package/proxy-VY0HRl2E.js +0 -75
@@ -0,0 +1,272 @@
1
+ import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
2
+ import { X as t, _ as n, b as r, c as i, f as a, g as o, o as s, s as c, u as l } from "./lib-C3f3XmGZ.js";
3
+ import { f as u, s as d, t as f } from "./hosts-C4-8lWwz.js";
4
+ import { a as p, c as m, n as h, o as g } from "./api-BdTgLphT.js";
5
+ import { t as _ } from "./busy-B189uX--.js";
6
+ import { t as v } from "./proxy-fXckOcRn.js";
7
+ import { frameFetchVerdict as y } from "./attach-policy.js";
8
+ import { t as b } from "./dns.js";
9
+ import { t as x } from "./cloud/fs.js";
10
+ import { t as S } from "./net.js";
11
+ import { t as C } from "./dgram.js";
12
+ import { t as w } from "./http.js";
13
+ import { expose as T } from "osra";
14
+ //#region src/cloud/frame-broker.ts
15
+ var E = async () => {
16
+ let e = () => g("frame consent");
17
+ try {
18
+ let t = await e();
19
+ return {
20
+ request: typeof t.frameConsent.request == "function" ? t.frameConsent.request : void 0,
21
+ ensure: t.frameConsent.ensure
22
+ };
23
+ } catch (t) {
24
+ if (!(t instanceof h)) throw t;
25
+ return {
26
+ request: void 0,
27
+ ensure: (t) => e().then((e) => e.frameConsent.ensure(t))
28
+ };
29
+ }
30
+ }, D = "frame: this frame no longer holds the document the app attached it to", O = !1, k = () => {
31
+ O || (O = !0, console.warn("[fkn-frame] this FKN broker is too old to ask for permission categories, so nothing was asked for upfront and each capability is asked for as it is first used. Reloading the page picks up the current broker."));
32
+ }, A = (e) => [...e].flatMap((e) => {
33
+ try {
34
+ return [new URL(e).hostname];
35
+ } catch {
36
+ return [];
37
+ }
38
+ }), j = (e, t, n) => n === null ? `frame.${e}: the user did not grant ${t} here` : `frame.${e}: the user did not grant ${t} on ${n}`, M = (e) => {
39
+ let { assertLive: t, attach: n, current: a, declaredHosts: o, documentHost: l, ensure: p, request: m, session: h, approvedOrigins: g } = e, _ = /* @__PURE__ */ new Set(), v = async () => l ? await l() : (() => {
40
+ try {
41
+ return new URL(a()).hostname;
42
+ } catch {
43
+ return "";
44
+ }
45
+ })(), b = () => f([...o, ...A(g)]), x = async (e) => (await m([e]))[0] ?? !1;
46
+ return {
47
+ gate: async ({ operation: e, args: a, phase: s }) => {
48
+ t();
49
+ let l = u(e, a);
50
+ if (l === null) return;
51
+ let S = i(l);
52
+ if (S === void 0 || S === "auto") return;
53
+ if (e === "fetch") {
54
+ let e = y({
55
+ session: h,
56
+ declaredHosts: o,
57
+ approvedOrigins: g
58
+ }, s === "ensure" ? void 0 : a[0], { classifier: "fetchTarget" });
59
+ if (s === "ensure" && !h) throw r(e.kind === "refuse" ? e.reason : "", "fetch");
60
+ if (s !== "ensure" && e.kind === "refuse") throw r(e.reason, "fetch");
61
+ if (!m) {
62
+ if (e.kind === "refuse") throw r(e.reason, "fetch");
63
+ if (!await p({
64
+ scope: d(a[0], a[1]).scope,
65
+ hosts: e.promptHosts
66
+ })) throw r("frame.fetch: the user did not grant this", "fetch");
67
+ return;
68
+ }
69
+ let t = e.kind === "consent" ? e.targetHost : await v(), n = f([t, ...o]);
70
+ if (!n.length) throw r("frame: navigate the frame before fetch", "fetch");
71
+ if (await x({
72
+ category: "network",
73
+ hosts: n
74
+ }) === !1) throw r(j("fetch", "network", t || null), "fetch");
75
+ return;
76
+ }
77
+ let C = await v();
78
+ if (!C) throw r(`frame: navigate the frame before ${e}`, e);
79
+ if (!b().includes(C)) throw r(D, e);
80
+ if (!m) return;
81
+ let w = c(l);
82
+ if (w === void 0 || S === "critical" && _.has(`${l} ${C}`)) return;
83
+ let T = f([C, ...o]), E = await x(S === "critical" ? {
84
+ key: l,
85
+ hosts: T,
86
+ attach: n
87
+ } : {
88
+ category: w,
89
+ hosts: T
90
+ });
91
+ if (E === !1) throw r(j(e, w, null), e);
92
+ if (E === "once" && s !== "ensure") for (let e of T) _.add(`${l} ${e}`);
93
+ },
94
+ requestCategories: async (e) => {
95
+ t();
96
+ let r = await v(), a = f(r ? [r, ...o] : o);
97
+ if (!a.length) throw TypeError("frame.request: navigate the frame or declare domains first");
98
+ let c = e.map((e) => {
99
+ let t = e.key;
100
+ return {
101
+ named: t,
102
+ critical: t !== void 0 && i(t) === "critical",
103
+ category: e.category ?? (t === void 0 ? void 0 : s(t)) ?? "interaction"
104
+ };
105
+ }), l = ({ named: e, critical: t, category: n }, r) => ({
106
+ category: n,
107
+ ...t ? { key: e } : {},
108
+ hosts: a,
109
+ allow: r
110
+ });
111
+ if (!m) return k(), c.map((e) => l(e, !1));
112
+ let u = await m(c.map(({ named: e, critical: t, category: r }) => t ? {
113
+ key: e,
114
+ hosts: a,
115
+ attach: n
116
+ } : {
117
+ category: r,
118
+ hosts: a
119
+ }));
120
+ return c.map((e, t) => l(e, u[t] !== void 0 && u[t] !== !1));
121
+ }
122
+ };
123
+ }, N = (e) => e, P = "autoplay; fullscreen; encrypted-media; picture-in-picture; clipboard-read; clipboard-write", F = 2e4, I = 65e3, L = 3e4, R = 5e3, z = /* @__PURE__ */ new Set([]), B = () => "https://fkn.app", V = (e) => !e || e === "about:blank", H = (e) => e ? "" : `incognito-${crypto.randomUUID()}`, U = ({ target: e, session: t, domains: n, attach: r }) => {
124
+ let i = new URL("/attach-frame", B());
125
+ return e && i.searchParams.set("url", e), t && i.searchParams.set("session", t), n.length && i.searchParams.set("domains", n.join(",")), i.searchParams.set("attach", r), i.href;
126
+ }, W = (e, t, n) => {
127
+ let r, i = new Promise((e, i) => {
128
+ r = setTimeout(() => i(Error(n)), t);
129
+ });
130
+ return Promise.race([e, i]).finally(() => clearTimeout(r));
131
+ }, G = (e, t) => {
132
+ let n = () => {
133
+ a(), t();
134
+ }, r = e.parentNode, i = new MutationObserver(() => {
135
+ (!e.isConnected || e.parentNode !== r) && (a(), t());
136
+ }), a = () => {
137
+ window.removeEventListener("pagehide", n), i.disconnect();
138
+ };
139
+ window.addEventListener("pagehide", n, { once: !0 }), r && i.observe(r, { childList: !0 }), e.isConnected || (a(), t());
140
+ }, K = () => Object.assign(/* @__PURE__ */ Error("cloud.attachFrame: the attached iframe left the document or was reloaded; attach a fresh iframe"), { name: o }), q = (e, t) => {
141
+ let n = [...e.split(";"), ...t.split(";")].map((e) => e.trim()).filter(Boolean);
142
+ return [...new Set(n)].join("; ");
143
+ }, J = [
144
+ 300,
145
+ 1200,
146
+ 4e3
147
+ ], Y = (e) => {
148
+ let t = () => {
149
+ if (!e.isConnected) return;
150
+ let t = e.style.height, n = e.getBoundingClientRect();
151
+ n.height && (e.style.height = `${n.height - 1}px`, setTimeout(() => {
152
+ e.style.height = t;
153
+ }, 50));
154
+ };
155
+ t();
156
+ for (let e of J) setTimeout(t, e);
157
+ }, X = (e) => {
158
+ let t = e.getAttribute("sandbox");
159
+ if (t === null) return;
160
+ let n = new Set(t.toLowerCase().split(/\s+/).filter(Boolean)), r = ["allow-scripts", "allow-same-origin"].filter((e) => !n.has(e));
161
+ if (r.length) throw Error(`cloud.attachFrame: the iframe's sandbox attribute must include ${r.join(" and ")} for the render proxy to load`);
162
+ }, Z = async ({ iframe: e, domains: r = [], syncCookies: i = !0, lockdown: o = !1, permissions: s }) => {
163
+ if (typeof window > "u") throw Error("cloud.attachFrame needs a window realm");
164
+ if (o) throw Error("cloud.attachFrame does not support lockdown; use the extension backend for a sealed frame");
165
+ if (!e.isConnected) throw Error("cloud.attachFrame: the iframe must be connected to the document before attaching");
166
+ X(e);
167
+ let c = e.getAttribute("src") ?? "", u = (() => {
168
+ if (V(c)) return null;
169
+ try {
170
+ return new URL(e.src || c, location.href);
171
+ } catch {
172
+ throw Error(`cloud.attachFrame: the iframe src is not a valid URL: ${c}`);
173
+ }
174
+ })();
175
+ if (u) {
176
+ let e = new URL("/attach-frame", B());
177
+ if (u.origin === e.origin && u.pathname === e.pathname) throw Error("cloud.attachFrame: this iframe is already attached; navigate with the Frame returned by that attach or use a fresh iframe");
178
+ }
179
+ let d = u?.href ?? "";
180
+ d && a(d);
181
+ let p = d, m = H(i), h = f(r), g = /* @__PURE__ */ new Set();
182
+ try {
183
+ g.add(new URL(d).origin);
184
+ } catch {}
185
+ let v = new AbortController(), y = e.referrerPolicy, b = e.allow, x = crypto.randomUUID();
186
+ if (e.referrerPolicy = "origin", e.allow = q(P, e.allow), e.src = U({
187
+ target: d,
188
+ session: m,
189
+ domains: h,
190
+ attach: x
191
+ }), !e.contentWindow) throw Error("cloud.attachFrame: the iframe window is not available");
192
+ try {
193
+ let r = await W(T({}, {
194
+ key: "fkn-attach-frame",
195
+ origin: B(),
196
+ transport: {
197
+ receive: window,
198
+ emit: e.contentWindow
199
+ },
200
+ unregisterSignal: v.signal,
201
+ revivableModules: N(t)
202
+ }), F, "cloud.attachFrame: timed out connecting to the render proxy page");
203
+ await W(r.ready(), I, "cloud.attachFrame: the render proxy never became ready"), d && Y(e), G(e, () => v.abort());
204
+ let i = _("attached frame");
205
+ v.signal.aborted ? i() : v.signal.addEventListener("abort", i, { once: !0 });
206
+ let a = e.contentWindow, o = () => {
207
+ if (!(!v.signal.aborted && e.isConnected && e.contentWindow === a)) throw v.abort(), K();
208
+ }, { gate: c, requestCategories: u } = M({
209
+ session: m,
210
+ declaredHosts: h,
211
+ approvedOrigins: g,
212
+ attach: x,
213
+ assertLive: o,
214
+ documentHost: typeof r.documentHost == "function" ? () => r.documentHost() : void 0,
215
+ current: () => p,
216
+ ...await E()
217
+ }), f = l({
218
+ executor: {
219
+ execute: (e, t, i) => z.has(t) ? Promise.reject(n(t, "cloud")) : (o(), r.executeLocator(e, t, i)),
220
+ highlight: async () => {}
221
+ },
222
+ gate: c,
223
+ request: u,
224
+ goto: async (t, n = {}) => {
225
+ let i = new URL(t, location.href).href;
226
+ o();
227
+ let { timeoutMs: a } = n, s = (() => {
228
+ try {
229
+ return new URL(i).origin;
230
+ } catch {
231
+ return "";
232
+ }
233
+ })(), c = s !== "" && !g.has(s);
234
+ c && g.add(s);
235
+ try {
236
+ await W(r.goto(i, n), (a ?? L) + R, "cloud.attachFrame: the render proxy did not answer goto; the frame may have been detached or its page reloaded");
237
+ } catch (e) {
238
+ throw c && g.delete(s), e;
239
+ }
240
+ p = i, Y(e);
241
+ },
242
+ url: () => p
243
+ });
244
+ return s?.length && await f.request(s), f;
245
+ } catch (t) {
246
+ throw v.abort(), e.referrerPolicy = y, e.allow = b, e.src = d || "about:blank", t;
247
+ }
248
+ }, ee = () => typeof window < "u" && !0, Q = async () => {
249
+ let e = await p.then((e) => e.cloud.quota());
250
+ return {
251
+ premium: e.premium,
252
+ overQuota: e.overQuota,
253
+ throttled: e.overQuota && !e.premium,
254
+ usedBytes: e.usedBytes,
255
+ limitBytes: e.limitBytes,
256
+ remainingBytes: e.remaining,
257
+ bytesPerSecond: e.bytesPerSecond,
258
+ bitsPerSecond: e.bytesPerSecond * 8
259
+ };
260
+ }, te = /* @__PURE__ */ e({
261
+ attachFrame: () => Z,
262
+ available: () => $,
263
+ dgram: () => C,
264
+ dns: () => b,
265
+ fetch: () => v,
266
+ fs: () => x,
267
+ http: () => w,
268
+ net: () => S,
269
+ quota: () => Q
270
+ }), $ = () => m;
271
+ //#endregion
272
+ export { ee as a, Z as i, te as n, Q as r, $ as t };
@@ -0,0 +1 @@
1
+ const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./lib-WiHTYaNP.cjs"),n=require("./hosts-DD4rDeQH.cjs"),r=require("./api-MW-Lm0u8.cjs"),i=require("./busy-Dv8wzE5M.cjs"),a=require("./proxy-_m6Sqcr6.cjs"),o=require("./attach-policy.cjs"),s=require("./dns.cjs"),c=require("./cloud/fs.cjs"),l=require("./net.cjs"),u=require("./dgram.cjs"),d=require("./http.cjs");let f=require("osra");var p=async()=>{let e=()=>r.o(`frame consent`);try{let t=await e();return{request:typeof t.frameConsent.request==`function`?t.frameConsent.request:void 0,ensure:t.frameConsent.ensure}}catch(t){if(!(t instanceof r.n))throw t;return{request:void 0,ensure:t=>e().then(e=>e.frameConsent.ensure(t))}}},m=`frame: this frame no longer holds the document the app attached it to`,h=!1,g=()=>{h||(h=!0,console.warn(`[fkn-frame] this FKN broker is too old to ask for permission categories, so nothing was asked for upfront and each capability is asked for as it is first used. Reloading the page picks up the current broker.`))},_=e=>[...e].flatMap(e=>{try{return[new URL(e).hostname]}catch{return[]}}),v=(e,t,n)=>n===null?`frame.${e}: the user did not grant ${t} here`:`frame.${e}: the user did not grant ${t} on ${n}`,y=e=>{let{assertLive:r,attach:i,current:a,declaredHosts:s,documentHost:c,ensure:l,request:u,session:d,approvedOrigins:f}=e,p=new Set,h=async()=>c?await c():(()=>{try{return new URL(a()).hostname}catch{return``}})(),y=()=>n.t([...s,..._(f)]),b=async e=>(await u([e]))[0]??!1;return{gate:async({operation:e,args:a,phase:c})=>{r();let g=n.f(e,a);if(g===null)return;let _=t.c(g);if(_===void 0||_===`auto`)return;if(e===`fetch`){let e=o.frameFetchVerdict({session:d,declaredHosts:s,approvedOrigins:f},c===`ensure`?void 0:a[0],{classifier:`fetchTarget`});if(c===`ensure`&&!d)throw t.b(e.kind===`refuse`?e.reason:``,`fetch`);if(c!==`ensure`&&e.kind===`refuse`)throw t.b(e.reason,`fetch`);if(!u){if(e.kind===`refuse`)throw t.b(e.reason,`fetch`);if(!await l({scope:n.s(a[0],a[1]).scope,hosts:e.promptHosts}))throw t.b(`frame.fetch: the user did not grant this`,`fetch`);return}let r=e.kind===`consent`?e.targetHost:await h(),i=n.t([r,...s]);if(!i.length)throw t.b(`frame: navigate the frame before fetch`,`fetch`);if(await b({category:`network`,hosts:i})===!1)throw t.b(v(`fetch`,`network`,r||null),`fetch`);return}let x=await h();if(!x)throw t.b(`frame: navigate the frame before ${e}`,e);if(!y().includes(x))throw t.b(m,e);if(!u)return;let S=t.s(g);if(S===void 0||_===`critical`&&p.has(`${g} ${x}`))return;let C=n.t([x,...s]),w=await b(_===`critical`?{key:g,hosts:C,attach:i}:{category:S,hosts:C});if(w===!1)throw t.b(v(e,S,null),e);if(w===`once`&&c!==`ensure`)for(let e of C)p.add(`${g} ${e}`)},requestCategories:async e=>{r();let a=await h(),o=n.t(a?[a,...s]:s);if(!o.length)throw TypeError(`frame.request: navigate the frame or declare domains first`);let c=e.map(e=>{let n=e.key;return{named:n,critical:n!==void 0&&t.c(n)===`critical`,category:e.category??(n===void 0?void 0:t.o(n))??`interaction`}}),l=({named:e,critical:t,category:n},r)=>({category:n,...t?{key:e}:{},hosts:o,allow:r});if(!u)return g(),c.map(e=>l(e,!1));let d=await u(c.map(({named:e,critical:t,category:n})=>t?{key:e,hosts:o,attach:i}:{category:n,hosts:o}));return c.map((e,t)=>l(e,d[t]!==void 0&&d[t]!==!1))}}},b=e=>e,x=`autoplay; fullscreen; encrypted-media; picture-in-picture; clipboard-read; clipboard-write`,S=2e4,C=65e3,w=3e4,T=5e3,E=new Set([]),D=()=>`https://fkn.app`,O=e=>!e||e===`about:blank`,k=e=>e?``:`incognito-${crypto.randomUUID()}`,A=({target:e,session:t,domains:n,attach:r})=>{let i=new URL(`/attach-frame`,D());return e&&i.searchParams.set(`url`,e),t&&i.searchParams.set(`session`,t),n.length&&i.searchParams.set(`domains`,n.join(`,`)),i.searchParams.set(`attach`,r),i.href},j=(e,t,n)=>{let r,i=new Promise((e,i)=>{r=setTimeout(()=>i(Error(n)),t)});return Promise.race([e,i]).finally(()=>clearTimeout(r))},M=(e,t)=>{let n=()=>{a(),t()},r=e.parentNode,i=new MutationObserver(()=>{(!e.isConnected||e.parentNode!==r)&&(a(),t())}),a=()=>{window.removeEventListener(`pagehide`,n),i.disconnect()};window.addEventListener(`pagehide`,n,{once:!0}),r&&i.observe(r,{childList:!0}),e.isConnected||(a(),t())},N=()=>Object.assign(Error(`cloud.attachFrame: the attached iframe left the document or was reloaded; attach a fresh iframe`),{name:t.g}),P=(e,t)=>{let n=[...e.split(`;`),...t.split(`;`)].map(e=>e.trim()).filter(Boolean);return[...new Set(n)].join(`; `)},F=[300,1200,4e3],I=e=>{let t=()=>{if(!e.isConnected)return;let t=e.style.height,n=e.getBoundingClientRect();n.height&&(e.style.height=`${n.height-1}px`,setTimeout(()=>{e.style.height=t},50))};t();for(let e of F)setTimeout(t,e)},L=e=>{let t=e.getAttribute(`sandbox`);if(t===null)return;let n=new Set(t.toLowerCase().split(/\s+/).filter(Boolean)),r=[`allow-scripts`,`allow-same-origin`].filter(e=>!n.has(e));if(r.length)throw Error(`cloud.attachFrame: the iframe's sandbox attribute must include ${r.join(` and `)} for the render proxy to load`)},R=async({iframe:e,domains:r=[],syncCookies:a=!0,lockdown:o=!1,permissions:s})=>{if(typeof window>`u`)throw Error(`cloud.attachFrame needs a window realm`);if(o)throw Error(`cloud.attachFrame does not support lockdown; use the extension backend for a sealed frame`);if(!e.isConnected)throw Error(`cloud.attachFrame: the iframe must be connected to the document before attaching`);L(e);let c=e.getAttribute(`src`)??``,l=(()=>{if(O(c))return null;try{return new URL(e.src||c,location.href)}catch{throw Error(`cloud.attachFrame: the iframe src is not a valid URL: ${c}`)}})();if(l){let e=new URL(`/attach-frame`,D());if(l.origin===e.origin&&l.pathname===e.pathname)throw Error(`cloud.attachFrame: this iframe is already attached; navigate with the Frame returned by that attach or use a fresh iframe`)}let u=l?.href??``;u&&t.f(u);let d=u,m=k(a),h=n.t(r),g=new Set;try{g.add(new URL(u).origin)}catch{}let _=new AbortController,v=e.referrerPolicy,F=e.allow,R=crypto.randomUUID();if(e.referrerPolicy=`origin`,e.allow=P(x,e.allow),e.src=A({target:u,session:m,domains:h,attach:R}),!e.contentWindow)throw Error(`cloud.attachFrame: the iframe window is not available`);try{let n=await j((0,f.expose)({},{key:`fkn-attach-frame`,origin:D(),transport:{receive:window,emit:e.contentWindow},unregisterSignal:_.signal,revivableModules:b(t.X)}),S,`cloud.attachFrame: timed out connecting to the render proxy page`);await j(n.ready(),C,`cloud.attachFrame: the render proxy never became ready`),u&&I(e),M(e,()=>_.abort());let r=i.t(`attached frame`);_.signal.aborted?r():_.signal.addEventListener(`abort`,r,{once:!0});let a=e.contentWindow,o=()=>{if(!(!_.signal.aborted&&e.isConnected&&e.contentWindow===a))throw _.abort(),N()},{gate:c,requestCategories:l}=y({session:m,declaredHosts:h,approvedOrigins:g,attach:R,assertLive:o,documentHost:typeof n.documentHost==`function`?()=>n.documentHost():void 0,current:()=>d,...await p()}),v=t.u({executor:{execute:(e,r,i)=>E.has(r)?Promise.reject(t._(r,`cloud`)):(o(),n.executeLocator(e,r,i)),highlight:async()=>{}},gate:c,request:l,goto:async(t,r={})=>{let i=new URL(t,location.href).href;o();let{timeoutMs:a}=r,s=(()=>{try{return new URL(i).origin}catch{return``}})(),c=s!==``&&!g.has(s);c&&g.add(s);try{await j(n.goto(i,r),(a??w)+T,`cloud.attachFrame: the render proxy did not answer goto; the frame may have been detached or its page reloaded`)}catch(e){throw c&&g.delete(s),e}d=i,I(e)},url:()=>d});return s?.length&&await v.request(s),v}catch(t){throw _.abort(),e.referrerPolicy=v,e.allow=F,e.src=u||`about:blank`,t}},z=()=>typeof window<`u`&&!0,B=async()=>{let e=await r.a.then(e=>e.cloud.quota());return{premium:e.premium,overQuota:e.overQuota,throttled:e.overQuota&&!e.premium,usedBytes:e.usedBytes,limitBytes:e.limitBytes,remainingBytes:e.remaining,bytesPerSecond:e.bytesPerSecond,bitsPerSecond:e.bytesPerSecond*8}},V=e.t({attachFrame:()=>R,available:()=>H,dgram:()=>u.t,dns:()=>s.t,fetch:()=>a.t,fs:()=>c.t,http:()=>d.t,net:()=>l.t,quota:()=>B}),H=()=>r.c;Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return H}});
package/cloud.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./proxy-DexG-Wmk.cjs"),t=require("./cloud-BZmduWyX.cjs"),n=require("./dns.cjs"),r=require("./cloud/fs.cjs"),i=require("./net.cjs"),a=require("./dgram.cjs"),o=require("./http.cjs");exports.attachFrame=t.i,exports.available=t.t,Object.defineProperty(exports,"dgram",{enumerable:!0,get:function(){return a.t}}),Object.defineProperty(exports,"dns",{enumerable:!0,get:function(){return n.t}}),exports.fetch=e.t,Object.defineProperty(exports,"fs",{enumerable:!0,get:function(){return r.t}}),Object.defineProperty(exports,"http",{enumerable:!0,get:function(){return o.t}}),Object.defineProperty(exports,"net",{enumerable:!0,get:function(){return i.t}}),exports.quota=t.r;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./proxy-_m6Sqcr6.cjs"),t=require("./cloud-DHuqVKrl.cjs"),n=require("./dns.cjs"),r=require("./cloud/fs.cjs"),i=require("./net.cjs"),a=require("./dgram.cjs"),o=require("./http.cjs");exports.attachFrame=t.i,exports.available=t.t,Object.defineProperty(exports,"dgram",{enumerable:!0,get:function(){return a.t}}),Object.defineProperty(exports,"dns",{enumerable:!0,get:function(){return n.t}}),exports.fetch=e.t,Object.defineProperty(exports,"fs",{enumerable:!0,get:function(){return r.t}}),Object.defineProperty(exports,"http",{enumerable:!0,get:function(){return o.t}}),Object.defineProperty(exports,"net",{enumerable:!0,get:function(){return i.t}}),exports.quota=t.r;
package/cloud.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { t as cloudFetch } from "./proxy-DxiJU5Y_.js";
2
- import { a as attachFrame, i as quota, r as QuotaStatus, t as available } from "./cloud-D0Ebu5bX.js";
1
+ import { t as cloudFetch } from "./proxy-XeHtHIdZ.js";
2
+ import { a as attachFrame, i as quota, r as QuotaStatus, t as available } from "./cloud-C40YCPuv.js";
3
3
  import { t as dns_d_exports } from "./dns.js";
4
4
  import { n as fs_d_exports } from "./fs-CYcErwc4.js";
5
- import { s as net_d_exports } from "./net-BXPEJToS.js";
5
+ import { s as net_d_exports } from "./net-BBtYFEzu.js";
6
6
  import { t as dgram_d_exports } from "./dgram.js";
7
7
  import { t as http_d_exports } from "./http.js";
8
8
  export { type QuotaStatus, attachFrame, available, dgram_d_exports as dgram, dns_d_exports as dns, cloudFetch as fetch, fs_d_exports as fs, http_d_exports as http, net_d_exports as net, quota };
package/cloud.js CHANGED
@@ -1,5 +1,5 @@
1
- import { t as e } from "./proxy-VY0HRl2E.js";
2
- import { i as t, r as n, t as r } from "./cloud-DaVb11IV.js";
1
+ import { t as e } from "./proxy-fXckOcRn.js";
2
+ import { i as t, r as n, t as r } from "./cloud-DBNeXS9R.js";
3
3
  import { t as i } from "./dns.js";
4
4
  import { t as a } from "./cloud/fs.js";
5
5
  import { t as o } from "./net.js";
@@ -65,11 +65,28 @@ type AddressLookupResult = {
65
65
  address: string;
66
66
  family: 0 | 4 | 6;
67
67
  };
68
+ /** @deprecated the pre-category fetch scopes. Still exported so a pinned library keeps compiling; the card maps them to `network`. */
68
69
  type FrameFetchScope = 'frame.fetchRead' | 'frame.fetchWrite';
70
+ /**
71
+ * One row on the cloud consent card.
72
+ *
73
+ * A category asks for every capability in it; a `key` asks for one critical permission's own row,
74
+ * and is refused unless the registry has that key at severity 4. `attach` binds an "Allow once"
75
+ * answer to the attachment that asked, so no other attachment can consume it.
76
+ */
69
77
  type FrameConsentRequest = {
78
+ category: 'interaction' | 'storage' | 'network' | 'evaluation';
79
+ hosts: string[];
80
+ } | {
81
+ key: string;
82
+ hosts: string[];
83
+ attach?: string;
84
+ } | {
70
85
  scope: FrameFetchScope;
71
86
  hosts: string[];
72
87
  };
88
+ /** `'once'` is a critical row answered Allow once, a handoff the middle page takes; `'session'` a row standing for the tab; `false` a refusal. */
89
+ type FrameConsentAnswer = 'once' | 'session' | false;
73
90
  type DisplayCause =
74
91
  /** the frame is not being painted at all, so an ancestor is display:none, visibility:hidden or equivalent */
75
92
  'not-rendered' |
@@ -528,7 +545,10 @@ type Resolvers = {
528
545
  hide: () => void;
529
546
  };
530
547
  frameConsent: {
548
+ /** the legacy single-row entry, kept so a pinned library keeps working */
531
549
  ensure: (request: FrameConsentRequest) => Promise<boolean>;
550
+ /** one card with a row per request; answers in request order */
551
+ request: (requests: FrameConsentRequest[]) => Promise<FrameConsentAnswer[]>;
532
552
  };
533
553
  connect: {
534
554
  prompt: (consumerOrigin: string) => Promise<boolean>;
@@ -599,4 +619,4 @@ type Resolvers = {
599
619
  hideInstallPrompt: () => void;
600
620
  };
601
621
  //#endregion
602
- export { SurfaceRect as $, ProxyFetchInit as A, RoomHandle as B, PackageQuery as C, PickOptions as D, PackagesFail as E, RoomBacklog as F, RoomOpenOptions as G, RoomMailbox as H, RoomCreateOptions as I, RoomsErrorCode as J, RoomPermission as K, RoomDefaults as L, Quota as M, Radii as N, Placement as O, Resolvers as P, StorageQuota as Q, RoomEnd as R, OverlayState as S, PackagesErrorCode as T, RoomMember as U, RoomJoinOptions as V, RoomMessage as W, SetOverlayHost as X, RoomsFail as Y, StorageEntry as Z, InstallOptions as _, ConflictChoice as a, UdpSocketOptions as at, MountDescriptor as b, ConnectAvailability as c, DisplayLevel as d, TcpSocketListenerOptions as et, DnsLookup as f, HiddenSurface as g, FrameFetchScope as h, AdoptState as i, UdpDatagram as it, ProxyFetchInput as j, ProxyFetch as k, ConnectOptions as l, FrameConsentRequest as m, AddressLookupResult as n, TcpSocketOptions as nt, ConflictRequest as o, UdpSocketResult as ot, EncryptionState as p, RoomPermissions as q, AdoptRequest as r, TcpSocketResult as rt, ConflictSide as s, WriteData as st, Account as t, TcpSocketListenerResult as tt, DisplayCause as u, InstalledPackage as v, PackageResult as w, OverlayRect as x, IpFamily as y, RoomEvent as z };
622
+ export { StorageQuota as $, ProxyFetch as A, RoomEvent as B, OverlayState as C, PackagesFail as D, PackagesErrorCode as E, Resolvers as F, RoomMessage as G, RoomJoinOptions as H, RoomBacklog as I, RoomPermissions as J, RoomOpenOptions as K, RoomCreateOptions as L, ProxyFetchInput as M, Quota as N, PickOptions as O, Radii as P, StorageEntry as Q, RoomDefaults as R, OverlayRect as S, PackageResult as T, RoomMailbox as U, RoomHandle as V, RoomMember as W, RoomsFail as X, RoomsErrorCode as Y, SetOverlayHost as Z, HiddenSurface as _, ConflictChoice as a, UdpDatagram as at, IpFamily as b, ConnectAvailability as c, WriteData as ct, DisplayLevel as d, SurfaceRect as et, DnsLookup as f, FrameFetchScope as g, FrameConsentRequest as h, AdoptState as i, TcpSocketResult as it, ProxyFetchInit as j, Placement as k, ConnectOptions as l, FrameConsentAnswer as m, AddressLookupResult as n, TcpSocketListenerResult as nt, ConflictRequest as o, UdpSocketOptions as ot, EncryptionState as p, RoomPermission as q, AdoptRequest as r, TcpSocketOptions as rt, ConflictSide as s, UdpSocketResult as st, Account as t, TcpSocketListenerOptions as tt, DisplayCause as u, InstallOptions as v, PackageQuery as w, MountDescriptor as x, InstalledPackage as y, RoomEnd as z };
package/contract.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { o as TcpSocketOption, v as UdpSocketOption } from "./wire-Gbo-D74t.js";
2
- import { $ as SurfaceRect, A as ProxyFetchInit, B as RoomHandle, C as PackageQuery, D as PickOptions, E as PackagesFail, F as RoomBacklog, G as RoomOpenOptions, H as RoomMailbox, I as RoomCreateOptions, J as RoomsErrorCode, K as RoomPermission, L as RoomDefaults, M as Quota, N as Radii, O as Placement, P as Resolvers, Q as StorageQuota, R as RoomEnd, S as OverlayState, T as PackagesErrorCode, U as RoomMember, V as RoomJoinOptions, W as RoomMessage, X as SetOverlayHost, Y as RoomsFail, Z as StorageEntry, _ as InstallOptions, a as ConflictChoice, at as UdpSocketOptions, b as MountDescriptor, c as ConnectAvailability, d as DisplayLevel, et as TcpSocketListenerOptions, f as DnsLookup, g as HiddenSurface, h as FrameFetchScope, i as AdoptState, it as UdpDatagram, j as ProxyFetchInput, k as ProxyFetch, l as ConnectOptions, m as FrameConsentRequest, n as AddressLookupResult, nt as TcpSocketOptions, o as ConflictRequest, ot as UdpSocketResult, p as EncryptionState, q as RoomPermissions, r as AdoptRequest, rt as TcpSocketResult, s as ConflictSide, st as WriteData, t as Account, tt as TcpSocketListenerResult, u as DisplayCause, v as InstalledPackage, w as PackageResult, x as OverlayRect, y as IpFamily, z as RoomEvent } from "./contract-CahPObYc.js";
3
- export { Account, AddressLookupResult, AdoptRequest, AdoptState, ConflictChoice, ConflictRequest, ConflictSide, ConnectAvailability, ConnectOptions, DisplayCause, DisplayLevel, DnsLookup, EncryptionState, FrameConsentRequest, FrameFetchScope, HiddenSurface, InstallOptions, InstalledPackage, IpFamily, MountDescriptor, OverlayRect, OverlayState, PackageQuery, PackageResult, PackagesErrorCode, PackagesFail, PickOptions, Placement, ProxyFetch, ProxyFetchInit, ProxyFetchInput, Quota, Radii, Resolvers, RoomBacklog, RoomCreateOptions, RoomDefaults, RoomEnd, RoomEvent, RoomHandle, RoomJoinOptions, RoomMailbox, RoomMember, RoomMessage, RoomOpenOptions, RoomPermission, RoomPermissions, RoomsErrorCode, RoomsFail, SetOverlayHost, StorageEntry, StorageQuota, SurfaceRect, TcpSocketListenerOptions, TcpSocketListenerResult, type TcpSocketOption, TcpSocketOptions, TcpSocketResult, UdpDatagram, type UdpSocketOption, UdpSocketOptions, UdpSocketResult, WriteData };
2
+ import { $ as StorageQuota, A as ProxyFetch, B as RoomEvent, C as OverlayState, D as PackagesFail, E as PackagesErrorCode, F as Resolvers, G as RoomMessage, H as RoomJoinOptions, I as RoomBacklog, J as RoomPermissions, K as RoomOpenOptions, L as RoomCreateOptions, M as ProxyFetchInput, N as Quota, O as PickOptions, P as Radii, Q as StorageEntry, R as RoomDefaults, S as OverlayRect, T as PackageResult, U as RoomMailbox, V as RoomHandle, W as RoomMember, X as RoomsFail, Y as RoomsErrorCode, Z as SetOverlayHost, _ as HiddenSurface, a as ConflictChoice, at as UdpDatagram, b as IpFamily, c as ConnectAvailability, ct as WriteData, d as DisplayLevel, et as SurfaceRect, f as DnsLookup, g as FrameFetchScope, h as FrameConsentRequest, i as AdoptState, it as TcpSocketResult, j as ProxyFetchInit, k as Placement, l as ConnectOptions, m as FrameConsentAnswer, n as AddressLookupResult, nt as TcpSocketListenerResult, o as ConflictRequest, ot as UdpSocketOptions, p as EncryptionState, q as RoomPermission, r as AdoptRequest, rt as TcpSocketOptions, s as ConflictSide, st as UdpSocketResult, t as Account, tt as TcpSocketListenerOptions, u as DisplayCause, v as InstallOptions, w as PackageQuery, x as MountDescriptor, y as InstalledPackage, z as RoomEnd } from "./contract-Gd543I6m.js";
3
+ export { Account, AddressLookupResult, AdoptRequest, AdoptState, ConflictChoice, ConflictRequest, ConflictSide, ConnectAvailability, ConnectOptions, DisplayCause, DisplayLevel, DnsLookup, EncryptionState, FrameConsentAnswer, FrameConsentRequest, FrameFetchScope, HiddenSurface, InstallOptions, InstalledPackage, IpFamily, MountDescriptor, OverlayRect, OverlayState, PackageQuery, PackageResult, PackagesErrorCode, PackagesFail, PickOptions, Placement, ProxyFetch, ProxyFetchInit, ProxyFetchInput, Quota, Radii, Resolvers, RoomBacklog, RoomCreateOptions, RoomDefaults, RoomEnd, RoomEvent, RoomHandle, RoomJoinOptions, RoomMailbox, RoomMember, RoomMessage, RoomOpenOptions, RoomPermission, RoomPermissions, RoomsErrorCode, RoomsFail, SetOverlayHost, StorageEntry, StorageQuota, SurfaceRect, TcpSocketListenerOptions, TcpSocketListenerResult, type TcpSocketOption, TcpSocketOptions, TcpSocketResult, UdpDatagram, type UdpSocketOption, UdpSocketOptions, UdpSocketResult, WriteData };
package/dgram.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-Beky02FK.cjs"),n=require("./busy-Dv8wzE5M.cjs"),r=require("./utils-BvgGdrgN.cjs");require("./wire.cjs");let i=require("buffer"),a=require("events"),o=require("ip-address");var s=e.t({Socket:()=>c,createSocket:()=>m,default:()=>h}),c=class extends a.EventEmitter{_type;_localAddress;_remoteAddress;_connectedLocally;_connectGeneration=0;_destroyed=!1;_busyRelease;_webVPNUdpSocketPromise;_dataPort;_socketId;_sendQueue=[];_sendQueueBytes=0;_sendFlushScheduled=!1;_peerTailCache=new Map;constructor(e){if(super(e),!e)throw Error(`Missing options`);this._type=e.type,e.connection&&this.__webvpn_udp_socket_init__(e.connection)}_lastRecvBufferSize=0;_lastSendBufferSize=0;_lastTtl=64;_lastMulticastTtl=1;_lastMulticastLoopback=!0;_setUdpOption(e){if(!this._webVPNUdpSocketPromise){this.emit(`error`,Error(`Cannot set socket option before bind`));return}this._webVPNUdpSocketPromise.then(async t=>{if(t)try{await t.setOption(e)}catch(e){this.emit(`error`,e)}})}_dataPortAcks=!1;_dataPortConsumedBytes=0;_dataPortAckedBytes=0;_ackDataPortBatch(e){if(!this._dataPortAcks||!this._dataPort||(this._dataPortConsumedBytes+=e,this._dataPortAckedBytes!==0&&this._dataPortConsumedBytes-this._dataPortAckedBytes<524288))return;this._dataPortAckedBytes=this._dataPortConsumedBytes;let t={type:r.n,consumedBytes:this._dataPortConsumedBytes};this._dataPort.postMessage(t)}_onTransportClosed(e){this._destroyed||(this._destroyed=!0,this._busyRelease?.(),this._dataPort?.close(),this._dataPort=void 0,this.listenerCount(`error`)>0&&this.emit(`error`,Error(e||`WebVPN session closed`)),this.emit(`close`))}_onDataPortBatch(e){let t=new DataView(e),n=!1,r,a=0;for(;a+4<=e.byteLength;){let o=t.getUint32(a);a+=4;let s=a+o;if(s>e.byteLength)break;let c=a+4,l=t.getUint8(c);c+=1;let u,d,p;if(l===2){if(!this._remoteAddress){a=s;continue}u=this._remoteAddress.address,d=this._remoteAddress.family,p=this._remoteAddress.port}else{let n=new Uint8Array(e,c,l===0?4:16);l===0?(d=`IPv4`,u=`${n[0]}.${n[1]}.${n[2]}.${n[3]}`):(d=`IPv6`,u=f(n)),c+=n.byteLength,p=t.getUint16(c),c+=2}let m=t.getUint32(c);c+=4;try{this.emit(`message`,i.Buffer.from(e.slice(c,c+m)),{address:u,family:d,port:p,size:m})}catch(e){n||(n=!0,r=e)}a=s}if(n)throw r}_peerTail(e,t){if(e===void 0||t===void 0)return l;let n=`${e}|${t}`,r=this._peerTailCache.get(n);if(r)return r;let i=o.Address4.isValid(e)?d(e):p(e),a=new Uint8Array(1+i.byteLength+2);return a[0]=i.byteLength===4?0:1,a.set(i,1),new DataView(a.buffer).setUint16(1+i.byteLength,t),this._peerTailCache.size>=4096&&this._peerTailCache.clear(),this._peerTailCache.set(n,a),a}_portSend(e,t,n){let r=this._peerTail(t,n),i=new Uint8Array(8+r.byteLength+4+e.byteLength),a=new DataView(i.buffer);a.setUint32(0,i.byteLength-4),a.setUint32(4,this._socketId),i.set(r,8),a.setUint32(8+r.byteLength,e.byteLength),i.set(e,12+r.byteLength),this._sendQueue.push(i),this._sendQueueBytes+=i.byteLength,!this._sendFlushScheduled&&(this._sendFlushScheduled=!0,queueMicrotask(()=>{this._sendFlushScheduled=!1;let e=this._sendQueue,t=this._sendQueueBytes;if(this._sendQueue=[],this._sendQueueBytes=0,!e.length||!this._dataPort)return;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;this._dataPort.postMessage(n.buffer,[n.buffer])}))}addMembership(e,t){if(o.Address4.isValid(e)){let n=d(e),r=t&&o.Address4.isValid(t)?d(t):new Uint8Array([0,0,0,0]);this._setUdpOption({type:5,group:n,interface:r})}else if(o.Address6.isValid(e)){let t=p(e);this._setUdpOption({type:7,group:t,ifIndex:0})}else this.emit(`error`,Error(`Invalid multicast address: ${e}`))}address(){if(!this._localAddress)throw Error(`EBADF`);return this._localAddress}bind(...e){let n=r.o(...e),i=this._type===`udp6`?`::`:`0.0.0.0`,a=this.__webvpn_udp_socket_init__(t.o(`a udp socket`).then(e=>e.cloud.webvpn.udpSocket({type:this._type,address:n.address??i,port:n.port,dataPort:!0})));return n.callback&&a.then(e=>{e&&n.callback.call(this)}),this}__webvpn_udp_socket_init__(e,t){return t&&(this._localAddress={address:t.localAddress,family:t.localFamily,port:t.localPort}),this._busyRelease??=n.t(`udp socket`),this._webVPNUdpSocketPromise=e.then(e=>{if(e.dataPort)this._socketId=e.socketId,this._dataPort=e.dataPort,this._dataPortAcks=e.dataPortAcks===!0,this._dataPort.onmessage=e=>{try{this._onDataPortBatch(e.data)}finally{this._ackDataPortBatch(e.data.byteLength)}};else{let t=e.dataReadableStream.getReader();(async()=>{for(;;){let{value:e,done:n}=await t.read();if(n)return;this.emit(`message`,i.Buffer.from(e.data),{address:e.address,family:e.family,port:e.port,size:e.size})}})().catch(e=>this._onTransportClosed(e instanceof Error?e.message:void 0))}return e.closed?.then(e=>this._onTransportClosed(e?.reason)).catch(()=>{}),this._localAddress={address:e.localAddress,family:e.localFamily,port:e.localPort},e}).catch(e=>{this.emit(`error`,e)}),this._webVPNUdpSocketPromise.then(e=>{if(!e){this._busyRelease?.();return}this.emit(`listening`)}),this._webVPNUdpSocketPromise}close(e){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);return this._webVPNUdpSocketPromise.then(async t=>{if(!t)throw Error(`Socket not bound`);let n=this._destroyed;this._destroyed=!0,this._busyRelease?.(),this._dataPort?.close(),this._dataPort=void 0;try{await t.close()}finally{try{e&&e()}finally{n||this.emit(`close`)}}}).catch(()=>{}),this}connect(...e){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);this._webVPNUdpSocketPromise.then(async t=>{if(!t)throw Error(`Socket not bound`);let n=e[0],r=this._type===`udp6`?`::1`:`127.0.0.1`,i=typeof e[1]==`string`?e[1]:r,a=typeof e.at(-1)==`function`?e.at(-1):void 0,o=await t.connect({remotePort:n,remoteAddress:i});this._connectedLocally=o?.local===!0,this._remoteAddress=o?.address?{address:o.address,family:o.family,port:o.port}:{address:i,family:this._type===`udp6`?`IPv6`:`IPv4`,port:n},this._connectGeneration+=1,a&&a()}).catch(e=>{this.emit(`error`,e)})}disconnect(){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);if(!this._remoteAddress)throw Error(`ERR_SOCKET_DGRAM_NOT_CONNECTED`);let e=this._remoteAddress,t=this._connectedLocally,n=this._connectGeneration;this._remoteAddress=void 0,this._connectedLocally=void 0,this._webVPNUdpSocketPromise.then(e=>e?.disconnect?.()).catch(r=>{this._connectGeneration===n&&(this._remoteAddress=e,this._connectedLocally=t),this.emit(`error`,r)})}dropMembership(e,t){if(o.Address4.isValid(e)){let n=d(e),r=t&&o.Address4.isValid(t)?d(t):new Uint8Array([0,0,0,0]);this._setUdpOption({type:6,group:n,interface:r})}else if(o.Address6.isValid(e)){let t=p(e);this._setUdpOption({type:8,group:t,ifIndex:0})}else this.emit(`error`,Error(`Invalid multicast address: ${e}`))}getRecvBufferSize(){return this._lastRecvBufferSize}getSendBufferSize(){return this._lastSendBufferSize}getSendQueueSize(){return 0}getSendQueueCount(){return 0}ref(){return this}remoteAddress(){if(!this._remoteAddress)throw Error(`ERR_SOCKET_DGRAM_NOT_CONNECTED`);return{address:this._remoteAddress.address,family:this._remoteAddress.family,port:this._remoteAddress.port}}send(...e){this._webVPNUdpSocketPromise||this.bind();let t=r.s(...e),n=u(t.message),i=n;if(t.hasRange){let{offset:e,length:r}=t;if(!Number.isInteger(e)||e<0||e>n.byteLength)throw Object.assign(RangeError(`"offset" is outside of buffer bounds`),{code:`ERR_BUFFER_OUT_OF_BOUNDS`});if(!Number.isInteger(r)||r<0||r>n.byteLength-e)throw Object.assign(RangeError(`"length" is outside of buffer bounds`),{code:`ERR_BUFFER_OUT_OF_BOUNDS`});i=n.subarray(e,e+r)}let a=this._type===`udp6`?`::1`:`127.0.0.1`;if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);this._webVPNUdpSocketPromise.then(e=>{if(!e)throw Error(`Socket not bound`);let n=t.callback,r=t.address??a,s=this._remoteAddress!==void 0&&t.address===void 0;if(this._dataPort&&(s||o.Address4.isValid(r)||o.Address6.isValid(r))){this._portSend(i,s?void 0:r,s?void 0:t.port),n?.call(this,null,i.byteLength);return}e.send({port:t.port,address:r,message:i.byteOffset===0&&i.byteLength===i.buffer.byteLength?i.buffer:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength)}).then(()=>n?.call(this,null,i.byteLength),e=>n?n.call(this,e,0):this.emit(`error`,e))})}setBroadcast(e){this._setUdpOption({type:0,value:e})}setMulticastInterface(e){}setMulticastLoopback(e){return this._setUdpOption({type:3,value:e}),this._setUdpOption({type:4,value:e}),this._lastMulticastLoopback=e,e}setMulticastTTL(e){return this._setUdpOption({type:2,value:e}),this._lastMulticastTtl=e,e}setRecvBufferSize(e){this._setUdpOption({type:10,value:e}),this._lastRecvBufferSize=e}setSendBufferSize(e){this._setUdpOption({type:9,value:e}),this._lastSendBufferSize=e}setTTL(e){return this._setUdpOption({type:1,value:e}),this._lastTtl=e,e}unref(){return this}addSourceSpecificMembership(e,t,n){}dropSourceSpecificMembership(e,t,n){}async[Symbol.asyncDispose](){await new Promise(e=>{this.close(e)})}},l=new Uint8Array([2]),u=e=>{if(typeof e==`string`)return r.l.encode(e);if(e instanceof Uint8Array)return e;if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);if(Array.isArray(e)){let t=e.map(u),n=new Uint8Array(t.reduce((e,t)=>e+t.byteLength,0)),r=0;for(let e of t)n.set(e,r),r+=e.byteLength;return n}return new Uint8Array(e)},d=e=>{let t=e.split(`.`).map(e=>parseInt(e,10));if(t.length!==4||t.some(e=>Number.isNaN(e)||e<0||e>255))throw Error(`Invalid IPv4 address: ${e}`);return new Uint8Array(t)},f=e=>{let t=[];for(let n=0;n<16;n+=2)t.push(e[n]<<8|e[n+1]);let n=-1,r=1;for(let e=0;e<8;){if(t[e]!==0){e++;continue}let i=e;for(;i<8&&t[i]===0;)i++;i-e>r&&(n=e,r=i-e),e=i}return n===-1?t.map(e=>e.toString(16)).join(`:`):`${t.slice(0,n).map(e=>e.toString(16)).join(`:`)}::${t.slice(n+r).map(e=>e.toString(16)).join(`:`)}`},p=e=>{let t=new o.Address6(e).getBitsBase16(0,128).match(/.{2}/g);if(!t||t.length!==16)throw Error(`Invalid IPv6 address: ${e}`);return new Uint8Array(t.map(e=>parseInt(e,16)))},m=(e,t)=>{let n=new c(typeof e==`string`?{type:e}:e);return t&&n.on(`message`,t),n},h={Socket:c,createSocket:m};exports.Socket=c,exports.createSocket=m,exports.default=h,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return s}});
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-MW-Lm0u8.cjs"),n=require("./busy-Dv8wzE5M.cjs"),r=require("./utils-BvgGdrgN.cjs");require("./wire.cjs");let i=require("buffer"),a=require("events"),o=require("ip-address");var s=e.t({Socket:()=>c,createSocket:()=>m,default:()=>h}),c=class extends a.EventEmitter{_type;_localAddress;_remoteAddress;_connectedLocally;_connectGeneration=0;_destroyed=!1;_busyRelease;_webVPNUdpSocketPromise;_dataPort;_socketId;_sendQueue=[];_sendQueueBytes=0;_sendFlushScheduled=!1;_peerTailCache=new Map;constructor(e){if(super(e),!e)throw Error(`Missing options`);this._type=e.type,e.connection&&this.__webvpn_udp_socket_init__(e.connection)}_lastRecvBufferSize=0;_lastSendBufferSize=0;_lastTtl=64;_lastMulticastTtl=1;_lastMulticastLoopback=!0;_setUdpOption(e){if(!this._webVPNUdpSocketPromise){this.emit(`error`,Error(`Cannot set socket option before bind`));return}this._webVPNUdpSocketPromise.then(async t=>{if(t)try{await t.setOption(e)}catch(e){this.emit(`error`,e)}})}_dataPortAcks=!1;_dataPortConsumedBytes=0;_dataPortAckedBytes=0;_ackDataPortBatch(e){if(!this._dataPortAcks||!this._dataPort||(this._dataPortConsumedBytes+=e,this._dataPortAckedBytes!==0&&this._dataPortConsumedBytes-this._dataPortAckedBytes<524288))return;this._dataPortAckedBytes=this._dataPortConsumedBytes;let t={type:r.n,consumedBytes:this._dataPortConsumedBytes};this._dataPort.postMessage(t)}_onTransportClosed(e){this._destroyed||(this._destroyed=!0,this._busyRelease?.(),this._dataPort?.close(),this._dataPort=void 0,this.listenerCount(`error`)>0&&this.emit(`error`,Error(e||`WebVPN session closed`)),this.emit(`close`))}_onDataPortBatch(e){let t=new DataView(e),n=!1,r,a=0;for(;a+4<=e.byteLength;){let o=t.getUint32(a);a+=4;let s=a+o;if(s>e.byteLength)break;let c=a+4,l=t.getUint8(c);c+=1;let u,d,p;if(l===2){if(!this._remoteAddress){a=s;continue}u=this._remoteAddress.address,d=this._remoteAddress.family,p=this._remoteAddress.port}else{let n=new Uint8Array(e,c,l===0?4:16);l===0?(d=`IPv4`,u=`${n[0]}.${n[1]}.${n[2]}.${n[3]}`):(d=`IPv6`,u=f(n)),c+=n.byteLength,p=t.getUint16(c),c+=2}let m=t.getUint32(c);c+=4;try{this.emit(`message`,i.Buffer.from(e.slice(c,c+m)),{address:u,family:d,port:p,size:m})}catch(e){n||(n=!0,r=e)}a=s}if(n)throw r}_peerTail(e,t){if(e===void 0||t===void 0)return l;let n=`${e}|${t}`,r=this._peerTailCache.get(n);if(r)return r;let i=o.Address4.isValid(e)?d(e):p(e),a=new Uint8Array(1+i.byteLength+2);return a[0]=i.byteLength===4?0:1,a.set(i,1),new DataView(a.buffer).setUint16(1+i.byteLength,t),this._peerTailCache.size>=4096&&this._peerTailCache.clear(),this._peerTailCache.set(n,a),a}_portSend(e,t,n){let r=this._peerTail(t,n),i=new Uint8Array(8+r.byteLength+4+e.byteLength),a=new DataView(i.buffer);a.setUint32(0,i.byteLength-4),a.setUint32(4,this._socketId),i.set(r,8),a.setUint32(8+r.byteLength,e.byteLength),i.set(e,12+r.byteLength),this._sendQueue.push(i),this._sendQueueBytes+=i.byteLength,!this._sendFlushScheduled&&(this._sendFlushScheduled=!0,queueMicrotask(()=>{this._sendFlushScheduled=!1;let e=this._sendQueue,t=this._sendQueueBytes;if(this._sendQueue=[],this._sendQueueBytes=0,!e.length||!this._dataPort)return;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;this._dataPort.postMessage(n.buffer,[n.buffer])}))}addMembership(e,t){if(o.Address4.isValid(e)){let n=d(e),r=t&&o.Address4.isValid(t)?d(t):new Uint8Array([0,0,0,0]);this._setUdpOption({type:5,group:n,interface:r})}else if(o.Address6.isValid(e)){let t=p(e);this._setUdpOption({type:7,group:t,ifIndex:0})}else this.emit(`error`,Error(`Invalid multicast address: ${e}`))}address(){if(!this._localAddress)throw Error(`EBADF`);return this._localAddress}bind(...e){let n=r.o(...e),i=this._type===`udp6`?`::`:`0.0.0.0`,a=this.__webvpn_udp_socket_init__(t.o(`a udp socket`).then(e=>e.cloud.webvpn.udpSocket({type:this._type,address:n.address??i,port:n.port,dataPort:!0})));return n.callback&&a.then(e=>{e&&n.callback.call(this)}),this}__webvpn_udp_socket_init__(e,t){return t&&(this._localAddress={address:t.localAddress,family:t.localFamily,port:t.localPort}),this._busyRelease??=n.t(`udp socket`),this._webVPNUdpSocketPromise=e.then(e=>{if(e.dataPort)this._socketId=e.socketId,this._dataPort=e.dataPort,this._dataPortAcks=e.dataPortAcks===!0,this._dataPort.onmessage=e=>{try{this._onDataPortBatch(e.data)}finally{this._ackDataPortBatch(e.data.byteLength)}};else{let t=e.dataReadableStream.getReader();(async()=>{for(;;){let{value:e,done:n}=await t.read();if(n)return;this.emit(`message`,i.Buffer.from(e.data),{address:e.address,family:e.family,port:e.port,size:e.size})}})().catch(e=>this._onTransportClosed(e instanceof Error?e.message:void 0))}return e.closed?.then(e=>this._onTransportClosed(e?.reason)).catch(()=>{}),this._localAddress={address:e.localAddress,family:e.localFamily,port:e.localPort},e}).catch(e=>{this.emit(`error`,e)}),this._webVPNUdpSocketPromise.then(e=>{if(!e){this._busyRelease?.();return}this.emit(`listening`)}),this._webVPNUdpSocketPromise}close(e){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);return this._webVPNUdpSocketPromise.then(async t=>{if(!t)throw Error(`Socket not bound`);let n=this._destroyed;this._destroyed=!0,this._busyRelease?.(),this._dataPort?.close(),this._dataPort=void 0;try{await t.close()}finally{try{e&&e()}finally{n||this.emit(`close`)}}}).catch(()=>{}),this}connect(...e){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);this._webVPNUdpSocketPromise.then(async t=>{if(!t)throw Error(`Socket not bound`);let n=e[0],r=this._type===`udp6`?`::1`:`127.0.0.1`,i=typeof e[1]==`string`?e[1]:r,a=typeof e.at(-1)==`function`?e.at(-1):void 0,o=await t.connect({remotePort:n,remoteAddress:i});this._connectedLocally=o?.local===!0,this._remoteAddress=o?.address?{address:o.address,family:o.family,port:o.port}:{address:i,family:this._type===`udp6`?`IPv6`:`IPv4`,port:n},this._connectGeneration+=1,a&&a()}).catch(e=>{this.emit(`error`,e)})}disconnect(){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);if(!this._remoteAddress)throw Error(`ERR_SOCKET_DGRAM_NOT_CONNECTED`);let e=this._remoteAddress,t=this._connectedLocally,n=this._connectGeneration;this._remoteAddress=void 0,this._connectedLocally=void 0,this._webVPNUdpSocketPromise.then(e=>e?.disconnect?.()).catch(r=>{this._connectGeneration===n&&(this._remoteAddress=e,this._connectedLocally=t),this.emit(`error`,r)})}dropMembership(e,t){if(o.Address4.isValid(e)){let n=d(e),r=t&&o.Address4.isValid(t)?d(t):new Uint8Array([0,0,0,0]);this._setUdpOption({type:6,group:n,interface:r})}else if(o.Address6.isValid(e)){let t=p(e);this._setUdpOption({type:8,group:t,ifIndex:0})}else this.emit(`error`,Error(`Invalid multicast address: ${e}`))}getRecvBufferSize(){return this._lastRecvBufferSize}getSendBufferSize(){return this._lastSendBufferSize}getSendQueueSize(){return 0}getSendQueueCount(){return 0}ref(){return this}remoteAddress(){if(!this._remoteAddress)throw Error(`ERR_SOCKET_DGRAM_NOT_CONNECTED`);return{address:this._remoteAddress.address,family:this._remoteAddress.family,port:this._remoteAddress.port}}send(...e){this._webVPNUdpSocketPromise||this.bind();let t=r.s(...e),n=u(t.message),i=n;if(t.hasRange){let{offset:e,length:r}=t;if(!Number.isInteger(e)||e<0||e>n.byteLength)throw Object.assign(RangeError(`"offset" is outside of buffer bounds`),{code:`ERR_BUFFER_OUT_OF_BOUNDS`});if(!Number.isInteger(r)||r<0||r>n.byteLength-e)throw Object.assign(RangeError(`"length" is outside of buffer bounds`),{code:`ERR_BUFFER_OUT_OF_BOUNDS`});i=n.subarray(e,e+r)}let a=this._type===`udp6`?`::1`:`127.0.0.1`;if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);this._webVPNUdpSocketPromise.then(e=>{if(!e)throw Error(`Socket not bound`);let n=t.callback,r=t.address??a,s=this._remoteAddress!==void 0&&t.address===void 0;if(this._dataPort&&(s||o.Address4.isValid(r)||o.Address6.isValid(r))){this._portSend(i,s?void 0:r,s?void 0:t.port),n?.call(this,null,i.byteLength);return}e.send({port:t.port,address:r,message:i.byteOffset===0&&i.byteLength===i.buffer.byteLength?i.buffer:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength)}).then(()=>n?.call(this,null,i.byteLength),e=>n?n.call(this,e,0):this.emit(`error`,e))})}setBroadcast(e){this._setUdpOption({type:0,value:e})}setMulticastInterface(e){}setMulticastLoopback(e){return this._setUdpOption({type:3,value:e}),this._setUdpOption({type:4,value:e}),this._lastMulticastLoopback=e,e}setMulticastTTL(e){return this._setUdpOption({type:2,value:e}),this._lastMulticastTtl=e,e}setRecvBufferSize(e){this._setUdpOption({type:10,value:e}),this._lastRecvBufferSize=e}setSendBufferSize(e){this._setUdpOption({type:9,value:e}),this._lastSendBufferSize=e}setTTL(e){return this._setUdpOption({type:1,value:e}),this._lastTtl=e,e}unref(){return this}addSourceSpecificMembership(e,t,n){}dropSourceSpecificMembership(e,t,n){}async[Symbol.asyncDispose](){await new Promise(e=>{this.close(e)})}},l=new Uint8Array([2]),u=e=>{if(typeof e==`string`)return r.l.encode(e);if(e instanceof Uint8Array)return e;if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);if(Array.isArray(e)){let t=e.map(u),n=new Uint8Array(t.reduce((e,t)=>e+t.byteLength,0)),r=0;for(let e of t)n.set(e,r),r+=e.byteLength;return n}return new Uint8Array(e)},d=e=>{let t=e.split(`.`).map(e=>parseInt(e,10));if(t.length!==4||t.some(e=>Number.isNaN(e)||e<0||e>255))throw Error(`Invalid IPv4 address: ${e}`);return new Uint8Array(t)},f=e=>{let t=[];for(let n=0;n<16;n+=2)t.push(e[n]<<8|e[n+1]);let n=-1,r=1;for(let e=0;e<8;){if(t[e]!==0){e++;continue}let i=e;for(;i<8&&t[i]===0;)i++;i-e>r&&(n=e,r=i-e),e=i}return n===-1?t.map(e=>e.toString(16)).join(`:`):`${t.slice(0,n).map(e=>e.toString(16)).join(`:`)}::${t.slice(n+r).map(e=>e.toString(16)).join(`:`)}`},p=e=>{let t=new o.Address6(e).getBitsBase16(0,128).match(/.{2}/g);if(!t||t.length!==16)throw Error(`Invalid IPv6 address: ${e}`);return new Uint8Array(t.map(e=>parseInt(e,16)))},m=(e,t)=>{let n=new c(typeof e==`string`?{type:e}:e);return t&&n.on(`message`,t),n},h={Socket:c,createSocket:m};exports.Socket=c,exports.createSocket=m,exports.default=h,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return s}});
package/dgram.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { v as UdpSocketOption } from "./wire-Gbo-D74t.js";
2
- import { P as Resolvers, ot as UdpSocketResult } from "./contract-CahPObYc.js";
3
- import "./api-Cc5qxCHP.js";
2
+ import { F as Resolvers, st as UdpSocketResult } from "./contract-Gd543I6m.js";
3
+ import "./api-Bgsg9t9D.js";
4
4
  import { Buffer } from "buffer";
5
5
  import { AddressInfo } from "net";
6
6
  import { EventEmitter } from "events";
package/dgram.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
2
- import { o as t } from "./api-BlAtp6lc.js";
2
+ import { o as t } from "./api-BdTgLphT.js";
3
3
  import { t as n } from "./busy-B189uX--.js";
4
4
  import { l as r, n as i, o as a, s as o } from "./utils-C-cAd4r4.js";
5
5
  import "./wire.js";
package/dns.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-Beky02FK.cjs");var n=e.t({lookup:()=>r}),r=(e,n)=>t.a.then(t=>t.cloud.dns.lookup(e,n));exports.lookup=r,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return n}});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-MW-Lm0u8.cjs");var n=e.t({lookup:()=>r}),r=(e,n)=>t.a.then(t=>t.cloud.dns.lookup(e,n));exports.lookup=r,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return n}});
package/dns.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as AddressLookupResult } from "./contract-CahPObYc.js";
1
+ import { n as AddressLookupResult } from "./contract-Gd543I6m.js";
2
2
  declare namespace dns_d_exports {
3
3
  export { AddressLookupResult, lookup };
4
4
  }
package/dns.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
2
- import { a as t } from "./api-BlAtp6lc.js";
2
+ import { a as t } from "./api-BdTgLphT.js";
3
3
  //#region src/dns.ts
4
4
  var n = /* @__PURE__ */ e({ lookup: () => r }), r = (e, n) => t.then((t) => t.cloud.dns.lookup(e, n));
5
5
  //#endregion