@fkn/lib 0.9.33 → 0.9.35

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 (96) hide show
  1. package/account.cjs +1 -1
  2. package/account.d.ts +6 -6
  3. package/account.js +3 -3
  4. package/{api-Cc5qxCHP.d.ts → api-CfmRAze5.d.ts} +3 -1
  5. package/{api-BlAtp6lc.js → api-CtiKFcK3.js} +62 -47
  6. package/api-Djf-XdZ4.cjs +3 -0
  7. package/api.cjs +1 -1
  8. package/api.d.ts +2 -2
  9. package/api.js +1 -1
  10. package/attach-policy.cjs +1 -1
  11. package/attach-policy.d.ts +32 -7
  12. package/attach-policy.js +16 -18
  13. package/cloud/dns.d.ts +1 -1
  14. package/cloud/fetch.cjs +1 -1
  15. package/cloud/fetch.d.ts +1 -1
  16. package/cloud/fetch.js +1 -1
  17. package/cloud/fs/promises.d.ts +3 -4
  18. package/cloud/fs.cjs +1 -1
  19. package/cloud/fs.d.ts +2 -2
  20. package/cloud/fs.js +2 -2
  21. package/cloud/net.d.ts +1 -1
  22. package/cloud-B9Sd7V1g.js +422 -0
  23. package/cloud-DCWD_0sd.cjs +1 -0
  24. package/{cloud-D0Ebu5bX.d.ts → cloud-DxitkM7z.d.ts} +9 -5
  25. package/cloud.cjs +1 -1
  26. package/cloud.d.ts +4 -4
  27. package/cloud.js +2 -2
  28. package/{contract-CahPObYc.d.ts → contract-D37GGkou.d.ts} +146 -1
  29. package/contract.cjs +1 -0
  30. package/contract.d.ts +2 -2
  31. package/contract.js +28 -0
  32. package/desktop.d.ts +7 -7
  33. package/dgram.cjs +1 -1
  34. package/dgram.d.ts +5 -5
  35. package/dgram.js +1 -1
  36. package/dns.cjs +1 -1
  37. package/dns.d.ts +3 -3
  38. package/dns.js +1 -1
  39. package/extension-DJQ0oYdk.js +89 -0
  40. package/extension-DSrUjoLw.cjs +1 -0
  41. package/{extension-DNkuFy1Y.d.ts → extension-TRYu_aG-.d.ts} +36 -157
  42. package/extension.cjs +1 -1
  43. package/extension.d.ts +3 -3
  44. package/extension.js +3 -3
  45. package/fs/promises.cjs +1 -1
  46. package/fs/promises.d.ts +3 -3
  47. package/fs/promises.js +1 -1
  48. package/{fs-CYcErwc4.d.ts → fs--NhtUyYa.d.ts} +1 -1
  49. package/{fs-BSsWw8HM.js → fs-BvNZePtN.js} +4 -4
  50. package/{fs-DxDxbvRS.cjs → fs-D8RCGFNc.cjs} +1 -1
  51. package/fs.cjs +1 -1
  52. package/fs.d.ts +2 -2
  53. package/fs.js +1 -1
  54. package/hosts-C4-8lWwz.js +161 -0
  55. package/hosts-DD4rDeQH.cjs +1 -0
  56. package/http.d.ts +20 -20
  57. package/{index-DH3_12nU.d.ts → index-C_Lqta5o.d.ts} +385 -7
  58. package/{index-Cg6y_FTi.d.ts → index-kuPqkS_-.d.ts} +26 -3
  59. package/index.cjs +1 -1
  60. package/index.d.ts +25 -10
  61. package/index.js +68 -62
  62. package/{lib-duLPF_WZ.js → lib-B-jGWfsv.js} +597 -396
  63. package/lib-Cjd91q7g.cjs +53 -0
  64. package/{net-BXPEJToS.d.ts → net-0SlODFSM.d.ts} +2 -2
  65. package/net.cjs +1 -1
  66. package/net.d.ts +1 -1
  67. package/net.js +1 -1
  68. package/node-fs-BNTPsX5c.cjs +1 -0
  69. package/{node-fs-C9ECR_9H.js → node-fs-BZy9bzKd.js} +2 -2
  70. package/opfs/promises.d.ts +2 -2
  71. package/opfs.cjs +1 -1
  72. package/opfs.d.ts +2 -2
  73. package/opfs.js +1 -1
  74. package/package.json +1 -1
  75. package/packages.cjs +1 -1
  76. package/packages.d.ts +27 -27
  77. package/packages.js +1 -1
  78. package/{proxy-DxiJU5Y_.d.ts → proxy-Bmb2wxG1.d.ts} +2 -2
  79. package/proxy-CYcaW5ew.cjs +1 -0
  80. package/proxy-DDwY3AVG.js +60 -0
  81. package/react.d.ts +3 -3
  82. package/rooms.cjs +1 -1
  83. package/rooms.d.ts +8 -8
  84. package/rooms.js +1 -1
  85. package/{storage-Bo01npo9.js → storage-BbcnDCnc.js} +1 -1
  86. package/{storage-WZEvw3KN.d.ts → storage-ZrY4Y4L5.d.ts} +21 -2
  87. package/{storage-DEjjVCT2.cjs → storage-dSi2dUKx.cjs} +1 -1
  88. package/api-Beky02FK.cjs +0 -3
  89. package/cloud-BZmduWyX.cjs +0 -1
  90. package/cloud-DaVb11IV.js +0 -174
  91. package/extension-D70dtUvW.cjs +0 -1
  92. package/extension-DdXNlt9_.js +0 -84
  93. package/lib-DLM2M3_i.cjs +0 -53
  94. package/node-fs-DZPGCYWg.cjs +0 -1
  95. package/proxy-DexG-Wmk.cjs +0 -1
  96. package/proxy-VY0HRl2E.js +0 -75
@@ -0,0 +1,422 @@
1
+ import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
2
+ import { b as t, c as n, d as r, et as i, f as a, g as o, l as s, m as c, o as l, s as u, u as d, w as f, x as p } from "./lib-B-jGWfsv.js";
3
+ import { f as m, s as h, t as g } from "./hosts-C4-8lWwz.js";
4
+ import { a as _, c as v, n as y, o as b } from "./api-CtiKFcK3.js";
5
+ import { t as x } from "./busy-B189uX--.js";
6
+ import { t as S } from "./proxy-DDwY3AVG.js";
7
+ import { frameFetchVerdict as C } from "./attach-policy.js";
8
+ import { ATTACH_FRAME_KEY as w, ATTACH_WINDOW_KEY as T, ATTACH_WINDOW_MESSAGE as E, WINDOW_HANDSHAKE_TIMEOUT_MS as ee } from "./contract.js";
9
+ import { t as D } from "./dns.js";
10
+ import { t as O } from "./cloud/fs.js";
11
+ import { t as k } from "./net.js";
12
+ import { t as A } from "./dgram.js";
13
+ import { t as j } from "./http.js";
14
+ import { expose as M } from "osra";
15
+ //#region src/cloud/frame-broker.ts
16
+ var N = async () => {
17
+ let e = () => b("frame consent");
18
+ try {
19
+ let t = await e();
20
+ return {
21
+ request: typeof t.frameConsent.request == "function" ? t.frameConsent.request : void 0,
22
+ ensure: t.frameConsent.ensure
23
+ };
24
+ } catch (t) {
25
+ if (!(t instanceof y)) throw t;
26
+ return {
27
+ request: void 0,
28
+ ensure: (t) => e().then((e) => e.frameConsent.ensure(t))
29
+ };
30
+ }
31
+ }, P = "frame: this frame no longer holds the document the app attached it to", F = !1, te = () => {
32
+ F || (F = !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."));
33
+ }, ne = (e) => [...e].flatMap((e) => {
34
+ try {
35
+ return [new URL(e).hostname];
36
+ } catch {
37
+ return [];
38
+ }
39
+ }), I = (e, t, n) => n === null ? `frame.${e}: the user did not grant ${t} here` : `frame.${e}: the user did not grant ${t} on ${n}`, re = (e) => {
40
+ let { assertLive: t, attach: r, current: i, declaredHosts: a, documentHost: o, ensure: c, request: l, session: u, approvedOrigins: p } = e, _ = /* @__PURE__ */ new Set(), v = async () => o ? await o() : (() => {
41
+ try {
42
+ return new URL(i()).hostname;
43
+ } catch {
44
+ return "";
45
+ }
46
+ })(), y = () => g([...a, ...ne(p)]), b = async (e) => (await l([e]))[0] ?? !1;
47
+ return {
48
+ gate: async ({ operation: e, args: n, phase: i }) => {
49
+ t();
50
+ let o = m(e, n);
51
+ if (o === null) return;
52
+ let x = d(o);
53
+ if (x === void 0 || x === "auto") return;
54
+ if (e === "fetch") {
55
+ let e = C({
56
+ session: u,
57
+ declaredHosts: a,
58
+ approvedOrigins: p
59
+ }, i === "ensure" ? void 0 : n[0], { classifier: "fetchTarget" });
60
+ if (i === "ensure" && !u) throw f(e.kind === "refuse" ? e.reason : "", "fetch");
61
+ if (i !== "ensure" && e.kind === "refuse") throw f(e.reason, "fetch");
62
+ if (!l) {
63
+ if (e.kind === "refuse") throw f(e.reason, "fetch");
64
+ if (!await c({
65
+ scope: h(n[0], n[1]).scope,
66
+ hosts: e.promptHosts
67
+ })) throw f("frame.fetch: the user did not grant this", "fetch");
68
+ return;
69
+ }
70
+ let t = e.kind === "consent" ? e.targetHost : await v(), r = g([t, ...a]);
71
+ if (!r.length) throw f("frame: navigate the frame before fetch", "fetch");
72
+ if (await b({
73
+ category: "network",
74
+ hosts: r
75
+ }) === !1) throw f(I("fetch", "network", t || null), "fetch");
76
+ return;
77
+ }
78
+ let S = await v();
79
+ if (!S) throw f(`frame: navigate the frame before ${e}`, e);
80
+ if (!y().includes(S)) throw f(P, e);
81
+ if (!l) return;
82
+ let w = s(o);
83
+ if (w === void 0 || x === "critical" && _.has(`${o} ${S}`)) return;
84
+ let T = g([S, ...a]), E = await b(x === "critical" ? {
85
+ key: o,
86
+ hosts: T,
87
+ attach: r
88
+ } : {
89
+ category: w,
90
+ hosts: T
91
+ });
92
+ if (E === !1) throw f(I(e, w, null), e);
93
+ if (E === "once" && i !== "ensure") for (let e of T) _.add(`${o} ${e}`);
94
+ },
95
+ requestCategories: async (e) => {
96
+ t();
97
+ let i = await v(), o = g(i ? [i, ...a] : a);
98
+ if (!o.length) throw TypeError("frame.request: navigate the frame or declare domains first");
99
+ let s = e.map((e) => {
100
+ let t = e.key;
101
+ return {
102
+ named: t,
103
+ critical: t !== void 0 && d(t) === "critical",
104
+ category: e.category ?? (t === void 0 ? void 0 : n(t)) ?? "interaction"
105
+ };
106
+ }), c = ({ named: e, critical: t, category: n }, r) => ({
107
+ category: n,
108
+ ...t ? { key: e } : {},
109
+ hosts: o,
110
+ allow: r
111
+ });
112
+ if (!l) return te(), s.map((e) => c(e, !1));
113
+ let u = await l(s.map(({ named: e, critical: t, category: n }) => t ? {
114
+ key: e,
115
+ hosts: o,
116
+ attach: r
117
+ } : {
118
+ category: n,
119
+ hosts: o
120
+ }));
121
+ return s.map((e, t) => c(e, u[t] !== void 0 && u[t] !== !1));
122
+ }
123
+ };
124
+ }, L = (e) => e, ie = 5e3, ae = /* @__PURE__ */ new Set([]), R = () => "https://fkn.app", z = (e) => e ? "" : `incognito-${crypto.randomUUID()}`, B = (e, t, n) => {
125
+ let r, i = new Promise((e, i) => {
126
+ r = setTimeout(() => i(Error(n)), t);
127
+ });
128
+ return Promise.race([e, i]).finally(() => clearTimeout(r));
129
+ }, V = (e) => Object.assign(Error(e), { name: t }), H = ({ control: e, target: t, session: n, declaredHosts: r, approvedOrigins: i, attach: a, assertLive: o, guard: s, consent: l, onNavigated: u }) => {
130
+ let d = t, { gate: f, requestCategories: m } = re({
131
+ session: n,
132
+ declaredHosts: r,
133
+ approvedOrigins: i,
134
+ attach: a,
135
+ assertLive: o,
136
+ documentHost: typeof e.documentHost == "function" ? () => s(() => e.documentHost()) : void 0,
137
+ current: () => d,
138
+ ...l
139
+ });
140
+ return c({
141
+ executor: {
142
+ execute: (t, n, r) => ae.has(n) ? Promise.reject(p(n, "cloud")) : (o(), s(() => e.executeLocator(t, n, r))),
143
+ highlight: async () => {}
144
+ },
145
+ gate: f,
146
+ request: m,
147
+ goto: async (t, n = {}) => {
148
+ let r = new URL(t, location.href).href;
149
+ o();
150
+ let { timeoutMs: a } = n, c = (() => {
151
+ try {
152
+ return new URL(r).origin;
153
+ } catch {
154
+ return "";
155
+ }
156
+ })(), l = c !== "" && !i.has(c);
157
+ l && i.add(c);
158
+ try {
159
+ await B(s(() => e.goto(r, n)), (a ?? 3e4) + ie, "cloud.attachFrame: the render proxy did not answer goto; the frame may have been detached or its page reloaded");
160
+ } catch (e) {
161
+ throw l && i.delete(c), e;
162
+ }
163
+ d = r, u();
164
+ },
165
+ url: () => d
166
+ });
167
+ }, oe = 250, U = 500, W = 65e3, G = 2e3, K = 2e3, se = 2, ce = 2e3, le = 2e3, ue = ({ origin: e, target: t, session: n, domains: r, attach: i }) => {
168
+ let a = new URL("/attach-window", e);
169
+ return a.searchParams.set("attach", i), t && a.searchParams.set("url", t), n && a.searchParams.set("session", n), r.length && a.searchParams.set("domains", r.join(",")), a.href;
170
+ }, de = (e, t) => {
171
+ let n = document.createElement("iframe"), r = new URL("/attach-jar", e);
172
+ return r.searchParams.set("attach", t), n.src = r.href, n.tabIndex = -1, n.setAttribute("aria-hidden", "true"), n.setAttribute("style", "display:none"), (document.body ?? document.documentElement).appendChild(n), n;
173
+ }, fe = (e, t) => {
174
+ let n = new MutationObserver(() => {
175
+ e.isConnected || t.aborted || (n.disconnect(), console.warn("cloud.attachFrame: the window's jar anchor was removed from this page, so a sign-in in the window no longer reaches this app's cookie jar"));
176
+ });
177
+ e.parentNode && n.observe(e.parentNode, { childList: !0 }), n.observe(document.documentElement, { childList: !0 }), t.addEventListener("abort", () => n.disconnect(), { once: !0 });
178
+ }, q = () => V("cloud.attachFrame: the attached window closed, reloaded or left the page FKN attached; attach a fresh window"), J = () => V("cloud.attachFrame: the attached window stopped answering; attach a fresh window"), pe = () => V("cloud.attachFrame: the window went away before it connected; attach a fresh window"), me = () => V("cloud.attachFrame: the window closed before it connected. Either the user closed it, or this page's Cross-Origin-Opener-Policy cut its link to the window"), he = async (e) => {
179
+ if (typeof window > "u") throw Error("cloud.attachFrame needs a window realm");
180
+ let { domains: t = [], syncCookies: n = !0, permissions: o } = e, { url: s, width: c, height: l } = u(e.window);
181
+ if (window.origin === "null") throw new a("opaque-opener");
182
+ let d = R(), f = crypto.randomUUID(), p = z(n), m = g(t), h = /* @__PURE__ */ new Set();
183
+ s && h.add(new URL(s).origin);
184
+ let _ = n ? de(d, f) : null, v = window.open(ue({
185
+ origin: d,
186
+ target: s,
187
+ session: p,
188
+ domains: m,
189
+ attach: f
190
+ }), "_blank", `popup,width=${c},height=${l}`);
191
+ if (!v) throw _?.remove(), new r();
192
+ let y = new AbortController(), b = !1, S = null, C = (e, t = !1) => {
193
+ if (S === null) {
194
+ S = e, y.abort(t ? J() : q());
195
+ try {
196
+ v.closed || v.postMessage({
197
+ type: E.detach,
198
+ attach: f,
199
+ ...t ? { unanswered: t } : {}
200
+ }, d);
201
+ } catch {}
202
+ _ && setTimeout(() => _.remove(), le);
203
+ }
204
+ };
205
+ _ && fe(_, y.signal);
206
+ let w = new Promise((e, t) => {
207
+ y.signal.addEventListener("abort", () => t(y.signal.reason), { once: !0 });
208
+ });
209
+ w.catch(() => {});
210
+ let D = w.then(() => {}, () => {}), O = () => {
211
+ if (y.signal.aborted) throw y.signal.reason;
212
+ }, k = (e) => y.signal.aborted ? Promise.reject(y.signal.reason) : Promise.race([e(), w]), A = (e) => e.source === v && e.origin === d;
213
+ window.addEventListener("message", (e) => {
214
+ if (!A(e)) return;
215
+ let t = e.data;
216
+ typeof t == "object" && t && t.attach === f && (t.type === E.refused ? C(new a(t.reason)) : t.type === E.gone && C(b ? q() : pe()));
217
+ }, { signal: y.signal }), window.addEventListener("pagehide", () => C(q()), { signal: y.signal });
218
+ let j = () => {
219
+ try {
220
+ v.postMessage({
221
+ type: E.hello,
222
+ attach: f
223
+ }, d);
224
+ } catch {}
225
+ };
226
+ j();
227
+ let N = setInterval(j, oe), P = setInterval(() => {
228
+ v.closed && C(b ? q() : me());
229
+ }, U);
230
+ y.signal.addEventListener("abort", () => {
231
+ clearInterval(N), clearInterval(P);
232
+ }, { once: !0 });
233
+ let F = async (e) => {
234
+ try {
235
+ return await Promise.race([e, w]);
236
+ } catch (e) {
237
+ throw S ?? e;
238
+ }
239
+ };
240
+ try {
241
+ let e = await F(B(M({}, {
242
+ key: T,
243
+ transport: {
244
+ emit: (e, t) => v.postMessage(e, d, t ?? []),
245
+ receive: (e) => {
246
+ let t = (t) => {
247
+ A(t) && e(t.data, {
248
+ source: t.source,
249
+ origin: t.origin
250
+ });
251
+ };
252
+ return window.addEventListener("message", t), () => window.removeEventListener("message", t);
253
+ }
254
+ },
255
+ unregisterSignal: y.signal,
256
+ revivableModules: L(i)
257
+ }), ee, "cloud.attachFrame: timed out connecting to the window"));
258
+ b = !0, clearInterval(N);
259
+ let t = 0, n = setInterval(() => {
260
+ B(k(() => e.ping()), K, "ping").then(() => {
261
+ t = 0;
262
+ }, () => {
263
+ y.signal.aborted || (document.visibilityState === "hidden" ? t = 0 : ++t >= se && C(J(), !0));
264
+ });
265
+ }, G);
266
+ y.signal.addEventListener("abort", () => clearInterval(n), { once: !0 }), await F(B(e.ready(), W, "cloud.attachFrame: the window never became ready"));
267
+ let r = x("attached frame");
268
+ y.signal.aborted ? r() : y.signal.addEventListener("abort", r, { once: !0 });
269
+ let a = H({
270
+ control: e,
271
+ target: s,
272
+ session: p,
273
+ declaredHosts: m,
274
+ approvedOrigins: h,
275
+ attach: f,
276
+ assertLive: O,
277
+ guard: k,
278
+ consent: {
279
+ request: (t) => k(() => e.requestConsent(t)),
280
+ ensure: (t) => k(() => e.requestConsent([t])).then(([e]) => e !== void 0 && e !== !1)
281
+ },
282
+ onNavigated: () => {}
283
+ }), c = null, l = () => c ??= (async () => {
284
+ y.signal.aborted || await B(Promise.allSettled([k(() => e.flushCookies()), k(() => e.sweepStorage())]), ce, "close").catch(() => {});
285
+ try {
286
+ v.close();
287
+ } catch {}
288
+ C(q());
289
+ })(), u = {
290
+ ...a,
291
+ close: l,
292
+ closed: D
293
+ };
294
+ return o?.length && await F(u.request(o)), u;
295
+ } catch (e) {
296
+ let t = S ?? e;
297
+ if (!(t instanceof a)) try {
298
+ v.close();
299
+ } catch {}
300
+ throw C(t), t;
301
+ }
302
+ }, ge = "autoplay; fullscreen; encrypted-media; picture-in-picture; clipboard-read; clipboard-write", _e = 2e4, ve = 65e3, ye = (e) => !e || e === "about:blank", be = ({ target: e, session: t, domains: n, attach: r }) => {
303
+ let i = new URL("/attach-frame", R());
304
+ 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;
305
+ }, xe = (e, t) => {
306
+ let n = () => {
307
+ a(), t();
308
+ }, r = e.parentNode, i = new MutationObserver(() => {
309
+ (!e.isConnected || e.parentNode !== r) && (a(), t());
310
+ }), a = () => {
311
+ window.removeEventListener("pagehide", n), i.disconnect();
312
+ };
313
+ window.addEventListener("pagehide", n, { once: !0 }), r && i.observe(r, { childList: !0 }), e.isConnected || (a(), t());
314
+ }, Se = () => V("cloud.attachFrame: the attached iframe left the document or was reloaded; attach a fresh iframe"), Ce = (e, t) => {
315
+ let n = [...e.split(";"), ...t.split(";")].map((e) => e.trim()).filter(Boolean);
316
+ return [...new Set(n)].join("; ");
317
+ }, Y = [
318
+ 300,
319
+ 1200,
320
+ 4e3
321
+ ], X = (e) => {
322
+ let t = () => {
323
+ if (!e.isConnected) return;
324
+ let t = e.style.height, n = e.getBoundingClientRect();
325
+ n.height && (e.style.height = `${n.height - 1}px`, setTimeout(() => {
326
+ e.style.height = t;
327
+ }, 50));
328
+ };
329
+ t();
330
+ for (let e of Y) setTimeout(t, e);
331
+ }, we = (e) => {
332
+ let t = e.getAttribute("sandbox");
333
+ if (t === null) return;
334
+ let n = new Set(t.toLowerCase().split(/\s+/).filter(Boolean)), r = ["allow-scripts", "allow-same-origin"].filter((e) => !n.has(e));
335
+ if (r.length) throw Error(`cloud.attachFrame: the iframe's sandbox attribute must include ${r.join(" and ")} for the render proxy to load`);
336
+ }, Te = async ({ iframe: e, domains: t = [], syncCookies: n = !0, lockdown: r = !1, permissions: a }) => {
337
+ if (typeof window > "u") throw Error("cloud.attachFrame needs a window realm");
338
+ if (r) throw Error("cloud.attachFrame does not support lockdown; use the extension backend for a sealed frame");
339
+ if (!e.isConnected) throw Error("cloud.attachFrame: the iframe must be connected to the document before attaching");
340
+ we(e);
341
+ let s = e.getAttribute("src") ?? "", c = (() => {
342
+ if (ye(s)) return null;
343
+ try {
344
+ return new URL(e.src || s, location.href);
345
+ } catch {
346
+ throw Error(`cloud.attachFrame: the iframe src is not a valid URL: ${s}`);
347
+ }
348
+ })();
349
+ if (c) {
350
+ let e = new URL("/attach-frame", R());
351
+ if (c.origin === e.origin && c.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");
352
+ }
353
+ let l = c?.href ?? "";
354
+ l && o(l);
355
+ let u = z(n), d = g(t), f = /* @__PURE__ */ new Set();
356
+ try {
357
+ f.add(new URL(l).origin);
358
+ } catch {}
359
+ let p = new AbortController(), m = e.referrerPolicy, h = e.allow, _ = crypto.randomUUID();
360
+ if (e.referrerPolicy = "origin", e.allow = Ce(ge, e.allow), e.src = be({
361
+ target: l,
362
+ session: u,
363
+ domains: d,
364
+ attach: _
365
+ }), !e.contentWindow) throw Error("cloud.attachFrame: the iframe window is not available");
366
+ try {
367
+ let t = await B(M({}, {
368
+ key: w,
369
+ origin: R(),
370
+ transport: {
371
+ receive: window,
372
+ emit: e.contentWindow
373
+ },
374
+ unregisterSignal: p.signal,
375
+ revivableModules: L(i)
376
+ }), _e, "cloud.attachFrame: timed out connecting to the render proxy page");
377
+ await B(t.ready(), ve, "cloud.attachFrame: the render proxy never became ready"), l && X(e), xe(e, () => p.abort());
378
+ let n = x("attached frame");
379
+ p.signal.aborted ? n() : p.signal.addEventListener("abort", n, { once: !0 });
380
+ let r = e.contentWindow, o = H({
381
+ control: t,
382
+ target: l,
383
+ session: u,
384
+ declaredHosts: d,
385
+ approvedOrigins: f,
386
+ attach: _,
387
+ assertLive: () => {
388
+ if (p.signal.aborted || !e.isConnected || e.contentWindow !== r) throw p.abort(), Se();
389
+ },
390
+ guard: (e) => e(),
391
+ consent: await N(),
392
+ onNavigated: () => X(e)
393
+ });
394
+ return a?.length && await o.request(a), o;
395
+ } catch (t) {
396
+ throw p.abort(), e.referrerPolicy = m, e.allow = h, e.src = l || "about:blank", t;
397
+ }
398
+ }, Z = (async (e) => l(e) === "window" ? he(e) : Te(e)), Ee = () => typeof window < "u" && !0, Q = async () => {
399
+ let e = await _.then((e) => e.cloud.quota());
400
+ return {
401
+ premium: e.premium,
402
+ overQuota: e.overQuota,
403
+ throttled: e.overQuota && !e.premium,
404
+ usedBytes: e.usedBytes,
405
+ limitBytes: e.limitBytes,
406
+ remainingBytes: e.remaining,
407
+ bytesPerSecond: e.bytesPerSecond,
408
+ bitsPerSecond: e.bytesPerSecond * 8
409
+ };
410
+ }, De = /* @__PURE__ */ e({
411
+ attachFrame: () => Z,
412
+ available: () => $,
413
+ dgram: () => A,
414
+ dns: () => D,
415
+ fetch: () => S,
416
+ fs: () => O,
417
+ http: () => j,
418
+ net: () => k,
419
+ quota: () => Q
420
+ }), $ = () => v;
421
+ //#endregion
422
+ export { Ee as a, Z as i, De as n, Q as r, $ as t };
@@ -0,0 +1 @@
1
+ const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./lib-Cjd91q7g.cjs"),n=require("./hosts-DD4rDeQH.cjs"),r=require("./api-Djf-XdZ4.cjs"),i=require("./busy-Dv8wzE5M.cjs"),a=require("./proxy-CYcaW5ew.cjs"),o=require("./attach-policy.cjs"),s=require("./contract.cjs"),c=require("./dns.cjs"),l=require("./cloud/fs.cjs"),u=require("./net.cjs"),d=require("./dgram.cjs"),f=require("./http.cjs");let p=require("osra");var m=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))}}},h=`frame: this frame no longer holds the document the app attached it to`,g=!1,_=()=>{g||(g=!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.`))},v=e=>[...e].flatMap(e=>{try{return[new URL(e).hostname]}catch{return[]}}),y=(e,t,n)=>n===null?`frame.${e}: the user did not grant ${t} here`:`frame.${e}: the user did not grant ${t} on ${n}`,b=e=>{let{assertLive:r,attach:i,current:a,declaredHosts:s,documentHost:c,ensure:l,request:u,session:d,approvedOrigins:f}=e,p=new Set,m=async()=>c?await c():(()=>{try{return new URL(a()).hostname}catch{return``}})(),g=()=>n.t([...s,...v(f)]),b=async e=>(await u([e]))[0]??!1;return{gate:async({operation:e,args:a,phase:c})=>{r();let _=n.f(e,a);if(_===null)return;let v=t.u(_);if(v===void 0||v===`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.w(e.kind===`refuse`?e.reason:``,`fetch`);if(c!==`ensure`&&e.kind===`refuse`)throw t.w(e.reason,`fetch`);if(!u){if(e.kind===`refuse`)throw t.w(e.reason,`fetch`);if(!await l({scope:n.s(a[0],a[1]).scope,hosts:e.promptHosts}))throw t.w(`frame.fetch: the user did not grant this`,`fetch`);return}let r=e.kind===`consent`?e.targetHost:await m(),i=n.t([r,...s]);if(!i.length)throw t.w(`frame: navigate the frame before fetch`,`fetch`);if(await b({category:`network`,hosts:i})===!1)throw t.w(y(`fetch`,`network`,r||null),`fetch`);return}let x=await m();if(!x)throw t.w(`frame: navigate the frame before ${e}`,e);if(!g().includes(x))throw t.w(h,e);if(!u)return;let S=t.l(_);if(S===void 0||v===`critical`&&p.has(`${_} ${x}`))return;let C=n.t([x,...s]),w=await b(v===`critical`?{key:_,hosts:C,attach:i}:{category:S,hosts:C});if(w===!1)throw t.w(y(e,S,null),e);if(w===`once`&&c!==`ensure`)for(let e of C)p.add(`${_} ${e}`)},requestCategories:async e=>{r();let a=await m(),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.u(n)===`critical`,category:e.category??(n===void 0?void 0:t.c(n))??`interaction`}}),l=({named:e,critical:t,category:n},r)=>({category:n,...t?{key:e}:{},hosts:o,allow:r});if(!u)return _(),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))}}},x=e=>e,S=5e3,C=new Set([]),w=()=>`https://fkn.app`,T=e=>e?``:`incognito-${crypto.randomUUID()}`,E=(e,t,n)=>{let r,i=new Promise((e,i)=>{r=setTimeout(()=>i(Error(n)),t)});return Promise.race([e,i]).finally(()=>clearTimeout(r))},D=e=>Object.assign(Error(e),{name:t.b}),O=({control:e,target:n,session:r,declaredHosts:i,approvedOrigins:a,attach:o,assertLive:s,guard:c,consent:l,onNavigated:u})=>{let d=n,{gate:f,requestCategories:p}=b({session:r,declaredHosts:i,approvedOrigins:a,attach:o,assertLive:s,documentHost:typeof e.documentHost==`function`?()=>c(()=>e.documentHost()):void 0,current:()=>d,...l});return t.m({executor:{execute:(n,r,i)=>C.has(r)?Promise.reject(t.x(r,`cloud`)):(s(),c(()=>e.executeLocator(n,r,i))),highlight:async()=>{}},gate:f,request:p,goto:async(t,n={})=>{let r=new URL(t,location.href).href;s();let{timeoutMs:i}=n,o=(()=>{try{return new URL(r).origin}catch{return``}})(),l=o!==``&&!a.has(o);l&&a.add(o);try{await E(c(()=>e.goto(r,n)),(i??3e4)+S,`cloud.attachFrame: the render proxy did not answer goto; the frame may have been detached or its page reloaded`)}catch(e){throw l&&a.delete(o),e}d=r,u()},url:()=>d})},ee=250,te=500,k=65e3,A=2e3,j=2e3,M=2,N=2e3,P=2e3,F=({origin:e,target:t,session:n,domains:r,attach:i})=>{let a=new URL(`/attach-window`,e);return a.searchParams.set(`attach`,i),t&&a.searchParams.set(`url`,t),n&&a.searchParams.set(`session`,n),r.length&&a.searchParams.set(`domains`,r.join(`,`)),a.href},I=(e,t)=>{let n=document.createElement(`iframe`),r=new URL(`/attach-jar`,e);return r.searchParams.set(`attach`,t),n.src=r.href,n.tabIndex=-1,n.setAttribute(`aria-hidden`,`true`),n.setAttribute(`style`,`display:none`),(document.body??document.documentElement).appendChild(n),n},L=(e,t)=>{let n=new MutationObserver(()=>{e.isConnected||t.aborted||(n.disconnect(),console.warn(`cloud.attachFrame: the window's jar anchor was removed from this page, so a sign-in in the window no longer reaches this app's cookie jar`))});e.parentNode&&n.observe(e.parentNode,{childList:!0}),n.observe(document.documentElement,{childList:!0}),t.addEventListener(`abort`,()=>n.disconnect(),{once:!0})},R=()=>D(`cloud.attachFrame: the attached window closed, reloaded or left the page FKN attached; attach a fresh window`),z=()=>D(`cloud.attachFrame: the attached window stopped answering; attach a fresh window`),B=()=>D(`cloud.attachFrame: the window went away before it connected; attach a fresh window`),V=()=>D(`cloud.attachFrame: the window closed before it connected. Either the user closed it, or this page's Cross-Origin-Opener-Policy cut its link to the window`),H=async e=>{if(typeof window>`u`)throw Error(`cloud.attachFrame needs a window realm`);let{domains:r=[],syncCookies:a=!0,permissions:o}=e,{url:c,width:l,height:u}=t.s(e.window);if(window.origin===`null`)throw new t.f(`opaque-opener`);let d=w(),f=crypto.randomUUID(),m=T(a),h=n.t(r),g=new Set;c&&g.add(new URL(c).origin);let _=a?I(d,f):null,v=window.open(F({origin:d,target:c,session:m,domains:h,attach:f}),`_blank`,`popup,width=${l},height=${u}`);if(!v)throw _?.remove(),new t.d;let y=new AbortController,b=!1,S=null,C=(e,t=!1)=>{if(S===null){S=e,y.abort(t?z():R());try{v.closed||v.postMessage({type:s.ATTACH_WINDOW_MESSAGE.detach,attach:f,...t?{unanswered:t}:{}},d)}catch{}_&&setTimeout(()=>_.remove(),P)}};_&&L(_,y.signal);let D=new Promise((e,t)=>{y.signal.addEventListener(`abort`,()=>t(y.signal.reason),{once:!0})});D.catch(()=>{});let H=D.then(()=>{},()=>{}),U=()=>{if(y.signal.aborted)throw y.signal.reason},W=e=>y.signal.aborted?Promise.reject(y.signal.reason):Promise.race([e(),D]),G=e=>e.source===v&&e.origin===d;window.addEventListener(`message`,e=>{if(!G(e))return;let n=e.data;typeof n==`object`&&n&&n.attach===f&&(n.type===s.ATTACH_WINDOW_MESSAGE.refused?C(new t.f(n.reason)):n.type===s.ATTACH_WINDOW_MESSAGE.gone&&C(b?R():B()))},{signal:y.signal}),window.addEventListener(`pagehide`,()=>C(R()),{signal:y.signal});let K=()=>{try{v.postMessage({type:s.ATTACH_WINDOW_MESSAGE.hello,attach:f},d)}catch{}};K();let q=setInterval(K,ee),J=setInterval(()=>{v.closed&&C(b?R():V())},te);y.signal.addEventListener(`abort`,()=>{clearInterval(q),clearInterval(J)},{once:!0});let Y=async e=>{try{return await Promise.race([e,D])}catch(e){throw S??e}};try{let e=await Y(E((0,p.expose)({},{key:s.ATTACH_WINDOW_KEY,transport:{emit:(e,t)=>v.postMessage(e,d,t??[]),receive:e=>{let t=t=>{G(t)&&e(t.data,{source:t.source,origin:t.origin})};return window.addEventListener(`message`,t),()=>window.removeEventListener(`message`,t)}},unregisterSignal:y.signal,revivableModules:x(t.et)}),s.WINDOW_HANDSHAKE_TIMEOUT_MS,`cloud.attachFrame: timed out connecting to the window`));b=!0,clearInterval(q);let n=0,r=setInterval(()=>{E(W(()=>e.ping()),j,`ping`).then(()=>{n=0},()=>{y.signal.aborted||(document.visibilityState===`hidden`?n=0:++n>=M&&C(z(),!0))})},A);y.signal.addEventListener(`abort`,()=>clearInterval(r),{once:!0}),await Y(E(e.ready(),k,`cloud.attachFrame: the window never became ready`));let a=i.t(`attached frame`);y.signal.aborted?a():y.signal.addEventListener(`abort`,a,{once:!0});let l=O({control:e,target:c,session:m,declaredHosts:h,approvedOrigins:g,attach:f,assertLive:U,guard:W,consent:{request:t=>W(()=>e.requestConsent(t)),ensure:t=>W(()=>e.requestConsent([t])).then(([e])=>e!==void 0&&e!==!1)},onNavigated:()=>{}}),u=null,_=()=>u??=(async()=>{y.signal.aborted||await E(Promise.allSettled([W(()=>e.flushCookies()),W(()=>e.sweepStorage())]),N,`close`).catch(()=>{});try{v.close()}catch{}C(R())})(),S={...l,close:_,closed:H};return o?.length&&await Y(S.request(o)),S}catch(e){let n=S??e;if(!(n instanceof t.f))try{v.close()}catch{}throw C(n),n}},U=`autoplay; fullscreen; encrypted-media; picture-in-picture; clipboard-read; clipboard-write`,W=2e4,G=65e3,K=e=>!e||e===`about:blank`,q=({target:e,session:t,domains:n,attach:r})=>{let i=new URL(`/attach-frame`,w());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)=>{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())},Y=()=>D(`cloud.attachFrame: the attached iframe left the document or was reloaded; attach a fresh iframe`),ne=(e,t)=>{let n=[...e.split(`;`),...t.split(`;`)].map(e=>e.trim()).filter(Boolean);return[...new Set(n)].join(`; `)},re=[300,1200,4e3],X=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 re)setTimeout(t,e)},ie=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`)},ae=async({iframe:e,domains:r=[],syncCookies:a=!0,lockdown:o=!1,permissions:c})=>{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`);ie(e);let l=e.getAttribute(`src`)??``,u=(()=>{if(K(l))return null;try{return new URL(e.src||l,location.href)}catch{throw Error(`cloud.attachFrame: the iframe src is not a valid URL: ${l}`)}})();if(u){let e=new URL(`/attach-frame`,w());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`)}let d=u?.href??``;d&&t.g(d);let f=T(a),h=n.t(r),g=new Set;try{g.add(new URL(d).origin)}catch{}let _=new AbortController,v=e.referrerPolicy,y=e.allow,b=crypto.randomUUID();if(e.referrerPolicy=`origin`,e.allow=ne(U,e.allow),e.src=q({target:d,session:f,domains:h,attach:b}),!e.contentWindow)throw Error(`cloud.attachFrame: the iframe window is not available`);try{let n=await E((0,p.expose)({},{key:s.ATTACH_FRAME_KEY,origin:w(),transport:{receive:window,emit:e.contentWindow},unregisterSignal:_.signal,revivableModules:x(t.et)}),W,`cloud.attachFrame: timed out connecting to the render proxy page`);await E(n.ready(),G,`cloud.attachFrame: the render proxy never became ready`),d&&X(e),J(e,()=>_.abort());let r=i.t(`attached frame`);_.signal.aborted?r():_.signal.addEventListener(`abort`,r,{once:!0});let a=e.contentWindow,o=O({control:n,target:d,session:f,declaredHosts:h,approvedOrigins:g,attach:b,assertLive:()=>{if(_.signal.aborted||!e.isConnected||e.contentWindow!==a)throw _.abort(),Y()},guard:e=>e(),consent:await m(),onNavigated:()=>X(e)});return c?.length&&await o.request(c),o}catch(t){throw _.abort(),e.referrerPolicy=v,e.allow=y,e.src=d||`about:blank`,t}},Z=(async e=>t.o(e)===`window`?H(e):ae(e)),oe=()=>typeof window<`u`&&!0,Q=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}},se=e.t({attachFrame:()=>Z,available:()=>$,dgram:()=>d.t,dns:()=>c.t,fetch:()=>a.t,fs:()=>l.t,http:()=>f.t,net:()=>u.t,quota:()=>Q}),$=()=>r.c;Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return se}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return $}});
@@ -1,12 +1,16 @@
1
- import { t as cloudFetch } from "./proxy-DxiJU5Y_.js";
2
- import { i as Frame, r as AttachFrameOptions } from "./index-DH3_12nU.js";
1
+ import { r as AttachFrameFunction } from "./index-C_Lqta5o.js";
2
+ import { t as cloudFetch } from "./proxy-Bmb2wxG1.js";
3
3
  import { t as dns_d_exports } from "./dns.js";
4
- import { n as fs_d_exports } from "./fs-CYcErwc4.js";
5
- import { s as net_d_exports } from "./net-BXPEJToS.js";
4
+ import { n as fs_d_exports } from "./fs--NhtUyYa.js";
5
+ import { s as net_d_exports } from "./net-0SlODFSM.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
  //#region src/cloud/frame.d.ts
9
- declare const attachFrame: ({ iframe, domains, syncCookies, lockdown }: AttachFrameOptions) => Promise<Frame>;
9
+ /**
10
+ * Attaches the render proxy to an iframe the app mounted, or opens it in a window of its own with
11
+ * `{ window }`. A window opens before the first await, so call this directly in a click handler.
12
+ */
13
+ declare const attachFrame: AttachFrameFunction;
10
14
  //#endregion
11
15
  //#region src/quota.d.ts
12
16
  type QuotaStatus = {
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-CYcaW5ew.cjs"),t=require("./cloud-DCWD_0sd.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-Bmb2wxG1.js";
2
+ import { a as attachFrame, i as quota, r as QuotaStatus, t as available } from "./cloud-DxitkM7z.js";
3
3
  import { t as dns_d_exports } from "./dns.js";
4
- import { n as fs_d_exports } from "./fs-CYcErwc4.js";
5
- import { s as net_d_exports } from "./net-BXPEJToS.js";
4
+ import { n as fs_d_exports } from "./fs--NhtUyYa.js";
5
+ import { s as net_d_exports } from "./net-0SlODFSM.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-DDwY3AVG.js";
2
+ import { i as t, r as n, t as r } from "./cloud-B9Sd7V1g.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";