@fkn/lib 0.9.63 → 0.9.65

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 (169) hide show
  1. package/README.md +34 -0
  2. package/account-Bm7uIcQo.d.ts +39 -0
  3. package/account-Uh0-1Cbp.js +22 -0
  4. package/{account-generation-B0cJrpDx.cjs → account-generation-ACCBzaI-.cjs} +1 -1
  5. package/{account-generation-u31dhamM.js → account-generation-BKHNe-jL.js} +2 -3
  6. package/account-m2iCmNui.cjs +1 -0
  7. package/{account-storage-ZkzqZp3A.js → account-storage-BmCVutNL.js} +4 -5
  8. package/{account-storage-Co9IvkPr.d.ts → account-storage-UmSfF63A.d.ts} +1 -66
  9. package/{account-storage-BnohkyMJ.cjs → account-storage-dYWDpqsr.cjs} +1 -1
  10. package/account.cjs +1 -1
  11. package/account.d.ts +3 -40
  12. package/account.js +1 -23
  13. package/{api-xh6lzApn.d.ts → api-0Yp9uZcV.d.ts} +3 -7
  14. package/{api-Di2Ff3jS.js → api-DRglK7ft.js} +115 -156
  15. package/api-DrvhPN56.cjs +3 -0
  16. package/api.cjs +1 -1
  17. package/api.d.ts +2 -2
  18. package/api.js +1 -2
  19. package/attach-policy.d.ts +0 -4
  20. package/attach-policy.js +2 -3
  21. package/broker-frame-CF4-yXtj.cjs +9 -0
  22. package/broker-frame-vjSpBa8d.js +51 -0
  23. package/broker-frame.cjs +1 -0
  24. package/broker-frame.d.ts +12 -0
  25. package/broker-frame.js +1 -0
  26. package/{busy-DsMWrSzc.js → busy-C1JPjoZ_.js} +1 -2
  27. package/cloud/dgram.cjs +1 -1
  28. package/cloud/dgram.d.ts +1 -1
  29. package/cloud/dgram.js +1 -2
  30. package/cloud/dns.cjs +1 -1
  31. package/cloud/dns.d.ts +2 -2
  32. package/cloud/dns.js +1 -2
  33. package/cloud/fetch.cjs +1 -1
  34. package/cloud/fetch.d.ts +1 -1
  35. package/cloud/fetch.js +1 -2
  36. package/cloud/fs/promises.cjs +1 -1
  37. package/cloud/fs/promises.d.ts +3 -5
  38. package/cloud/fs/promises.js +2 -3
  39. package/cloud/fs.cjs +1 -1
  40. package/cloud/fs.d.ts +4 -4
  41. package/cloud/fs.js +4 -34
  42. package/cloud/http.cjs +1 -1
  43. package/cloud/http.d.ts +1 -1
  44. package/cloud/http.js +1 -2
  45. package/cloud/net.cjs +1 -1
  46. package/cloud/net.d.ts +1 -1
  47. package/cloud/net.js +3 -3
  48. package/{cloud-CI7FFRMC.d.ts → cloud-BoH54gaM.d.ts} +7 -11
  49. package/{cloud-C6rG_aod.js → cloud-C7StNncS.js} +17 -17
  50. package/cloud-TN0eDUy3.cjs +1 -0
  51. package/cloud.cjs +1 -1
  52. package/cloud.d.ts +7 -7
  53. package/cloud.js +7 -7
  54. package/connect-button-2FmOM8ai.d.ts +2 -0
  55. package/{connect-button-DtsN3X1J.js → connect-button-C1wKkIhh.js} +1 -2
  56. package/{contract-BGMJVvTg.d.ts → contract-0rua6Wsh.d.ts} +11 -6
  57. package/contract.d.ts +3 -3
  58. package/contract.js +1 -2
  59. package/desktop-DOubT4ES.d.ts +57 -0
  60. package/desktop-vXKU4wEK.cjs +1 -0
  61. package/desktop-xTT7ciGX.js +50 -0
  62. package/desktop.cjs +1 -1
  63. package/desktop.d.ts +2 -58
  64. package/desktop.js +1 -51
  65. package/dgram-BBbLokVF.js +397 -0
  66. package/dgram-BYk-QDHW.d.ts +118 -0
  67. package/dgram-D9ljiUFh.cjs +1 -0
  68. package/dgram.cjs +1 -1
  69. package/dgram.d.ts +2 -119
  70. package/dgram.js +1 -410
  71. package/dns-2v96zoEh.cjs +1 -0
  72. package/dns-DyB4K2oE.d.ts +9 -0
  73. package/dns-o8DLFjP1.js +5 -0
  74. package/dns.cjs +1 -1
  75. package/dns.d.ts +3 -10
  76. package/dns.js +1 -6
  77. package/extension-BXBjpypy.cjs +1 -0
  78. package/{extension-C3_aJX7C.js → extension-D5UMnEmQ.js} +11 -12
  79. package/{extension-C1bcizcn.d.ts → extension-D98KM8W7.d.ts} +1 -27
  80. package/extension.cjs +1 -1
  81. package/extension.d.ts +2 -2
  82. package/extension.js +2 -2
  83. package/fs/promises.cjs +1 -1
  84. package/fs/promises.d.ts +2 -4
  85. package/fs/promises.js +2 -3
  86. package/fs--MLHvMW-.cjs +1 -0
  87. package/fs-BX_ghRy0.cjs +1 -0
  88. package/fs-BnWXGRik.js +33 -0
  89. package/{fs-DCJAYoYy.d.ts → fs-ChOYC6VD.d.ts} +3 -4
  90. package/{fs-DgdN2HPt.js → fs-Cw7CcUhx.js} +17 -41
  91. package/fs.cjs +1 -1
  92. package/fs.d.ts +4 -4
  93. package/fs.js +2 -2
  94. package/{hosts-t7CKGTRz.js → hosts-HUfgMimI.js} +1 -2
  95. package/http-BE3UBktN.cjs +9 -0
  96. package/http-CDhG4bUc.d.ts +187 -0
  97. package/http-DIDjdm08.js +523 -0
  98. package/http.cjs +1 -9
  99. package/http.d.ts +2 -188
  100. package/http.js +1 -542
  101. package/index-CUWTpQKP.d.ts +87 -0
  102. package/{index-BQgZVQl7.d.ts → index-CcVwh9yz.d.ts} +0 -2
  103. package/{index-C5DdoMGo.d.ts → index-Cu5EcdK0.d.ts} +0 -59
  104. package/{index-57lTXnoe.d.ts → index-D6GPJ4Ow.d.ts} +29 -26
  105. package/index.cjs +1 -1
  106. package/index.d.ts +17 -25
  107. package/index.js +22 -27
  108. package/lib-Bs-g5jyp.cjs +53 -0
  109. package/{lib-BrsqpUkv.js → lib-CtJaID_y.js} +7 -31
  110. package/{messages-AdPfdoLV.d.ts → messages-B9dOXntM.d.ts} +0 -2
  111. package/messages.d.ts +1 -1
  112. package/messages.js +1 -2
  113. package/net-COkJw8lV.js +286 -0
  114. package/net-Dk2kqtgE.cjs +1 -0
  115. package/{net-BpyIeQ8r.d.ts → net-mVAYXs8e.d.ts} +5 -7
  116. package/net.cjs +1 -1
  117. package/net.d.ts +1 -1
  118. package/net.js +3 -323
  119. package/{node-fs-DY2fO5zd.js → node-fs-B4pY08Kc.js} +3 -10
  120. package/node-fs-DN0ejGTL.cjs +1 -0
  121. package/opfs/promises.cjs +1 -1
  122. package/opfs/promises.d.ts +2 -4
  123. package/opfs/promises.js +2 -3
  124. package/{opfs-D0goLAQW.js → opfs-CzCfVam3.js} +2 -3
  125. package/opfs-D3pYzYRc.js +35 -0
  126. package/opfs-DuXvTgIl.cjs +1 -0
  127. package/opfs.cjs +1 -1
  128. package/opfs.d.ts +3 -88
  129. package/opfs.js +1 -36
  130. package/package.json +6 -1
  131. package/packages-BEadIy_h.d.ts +155 -0
  132. package/packages-Cws_rcgf.js +346 -0
  133. package/packages-DT8vPB5_.cjs +1 -0
  134. package/packages.cjs +1 -1
  135. package/packages.d.ts +3 -156
  136. package/packages.js +1 -347
  137. package/{proxy-tsVhjcl-.js → proxy-BBAQxJmP.js} +13 -13
  138. package/{proxy-Dz60YyYy.d.ts → proxy-BP40IXYD.d.ts} +2 -4
  139. package/proxy-DVgGp6A8.cjs +1 -0
  140. package/react.cjs +1 -1
  141. package/react.d.ts +16 -4
  142. package/react.js +96 -7
  143. package/{relay-choice-BGwXRC5d.js → relay-choice-Bb3oP2gw.js} +1 -2
  144. package/{relay-choice-5yUPI-tJ.d.ts → relay-choice-DOUttUnL.d.ts} +2 -4
  145. package/{rolldown-runtime-Dy4uBu1J.js → rolldown-runtime-CGnMp29N.js} +1 -2
  146. package/rooms-C6mbannC.d.ts +227 -0
  147. package/rooms-DHFS9cwA.cjs +1 -0
  148. package/rooms-DP5stTEr.js +300 -0
  149. package/rooms.cjs +1 -1
  150. package/rooms.d.ts +3 -228
  151. package/rooms.js +1 -301
  152. package/storage-BCjYihUO.cjs +1 -0
  153. package/storage-BhfImh_2.js +136 -0
  154. package/storage-DpCLksAa.d.ts +68 -0
  155. package/storage.cjs +1 -1
  156. package/storage.d.ts +3 -69
  157. package/storage.js +1 -137
  158. package/{utils-Cyq8uJiy.js → utils-DtWP-E9x.js} +1 -2
  159. package/{wire-Fk5pJaoy.d.ts → wire-DhmLnYEU.d.ts} +0 -2
  160. package/wire.d.ts +1 -1
  161. package/wire.js +1 -2
  162. package/api-BSk3dc_X.cjs +0 -3
  163. package/cloud-BoiHKoRZ.cjs +0 -1
  164. package/connect-button-Cp0NS95-.d.ts +0 -4
  165. package/extension-Crv4aUAm.cjs +0 -1
  166. package/fs-CjQTj3FA.cjs +0 -1
  167. package/lib-C_X3WR4G.cjs +0 -53
  168. package/node-fs-vsWuoMGa.cjs +0 -1
  169. package/proxy-BA92hkId.cjs +0 -1
package/react.js CHANGED
@@ -1,7 +1,79 @@
1
- import { t as e } from "./connect-button-DtsN3X1J.js";
2
- import { createElement as t } from "react";
3
- //#region src/react.ts
4
- var n = ({ className: n, style: r } = {}) => t("iframe", {
1
+ import { t as e } from "./connect-button-C1wKkIhh.js";
2
+ import { createElement as t, useEffect as n, useRef as r } from "react";
3
+ var i = 6, a = 8, o = (e, t, n) => (r) => `var(--fkn-powered-by-${e}, ${r ? `light-dark(${t}, ${n})` : n})`, s = o("card", "#ffffff", "#1d1e23"), c = o("border", "#e5e6ea", "#2a2c33"), l = o("ink", "#191b1f", "#ecedf0"), u = o("link", "#3a629e", "#8db0de"), d = o("shadow", "rgba(16, 18, 22, .05)", "rgba(0, 0, 0, .4)"), f = [
4
+ ["M198.4,0.1L365,288.6H162.3l-31.8,55l331.4-0.2L263.6,0L198.4,0.1z", o("mark-app", "#8f5a0e", "#f9aa40")],
5
+ ["M198.3,0L0,343.6l32.6,56.5l165.1-285.9l100.7,174.4h66.5L198.3,0z", o("mark-plat", "#3a629e", "#4572b5")],
6
+ ["M197.7,114.2l32.6,56.5l-99.8,172.9h331.4l-32.6,56.5H32.6L197.7,114.2z", o("mark-acct", "#2a7c58", "#51bb8d")]
7
+ ], p = "http://www.w3.org/2000/svg", m = 0, h = ({ label: e = "Powered by FKN", linkLabel: t = "How it works", href: n = "https://docs.fkn.dev/" } = {}) => {
8
+ let r = `fkn-powered-by-${++m}`, o = document.createElement("span"), h = document.createElement("button");
9
+ h.type = "button", h.title = e, h.setAttribute("aria-label", e), h.setAttribute("aria-expanded", "false"), h.setAttribute("aria-controls", r), h.style.cssText = "padding:4px;margin:-4px;border:none;border-radius:4px;background:none;font:inherit;color:inherit;cursor:pointer";
10
+ let g = CSS.supports("color", "light-dark(red, red)"), _ = document.createElementNS(p, "svg");
11
+ _.setAttribute("viewBox", "0 0 461.9 400.1"), _.setAttribute("aria-hidden", "true"), _.style.cssText = `height:${CSS.supports("height", "1cap") ? "1cap" : ".7em"};width:auto`;
12
+ for (let [e, t] of f) {
13
+ let n = document.createElementNS(p, "path");
14
+ n.setAttribute("d", e), n.style.fill = t(g), _.append(n);
15
+ }
16
+ h.append(_);
17
+ let v = document.createElement("div");
18
+ v.id = r, v.popover = "manual", v.setAttribute("role", "group"), v.setAttribute("aria-labelledby", `${r}-title`), v.tabIndex = -1, v.style.cssText = `inset:auto;margin:0;padding:${i}px 0 0;border:none;background:transparent;overflow:visible;width:max-content;max-width:min(280px, calc(100vw - 16px));outline:none;cursor:default;user-select:text`;
19
+ let y = document.createElement("div");
20
+ y.style.cssText = `display:flex;flex-direction:column;gap:8px;box-sizing:border-box;overflow-y:auto;overflow-wrap:anywhere;padding:12px 14px;font-size:13px;font-weight:400;font-style:normal;line-height:1.4;letter-spacing:normal;text-transform:none;text-shadow:none;text-align:start;white-space:normal;color:${l(g)};background:${s(g)};border:1px solid ${c(g)};border-radius:10px;box-shadow:0 1px 2px ${d(g)}`;
21
+ let b = document.createElement("div");
22
+ b.id = `${r}-title`, b.textContent = e, b.style.fontWeight = "600";
23
+ let x = document.createElement("a");
24
+ x.href = n, x.target = "_blank", x.rel = "noreferrer", x.textContent = t, x.style.cssText = `align-self:flex-start;color:${u(g)};font-weight:600;text-decoration:underline;text-underline-offset:2px;border-radius:4px`, y.append(b, x), v.append(y), o.append(h, v);
25
+ let S = /* @__PURE__ */ new Set(), C, w, T = () => {
26
+ let e = h.getBoundingClientRect(), { width: t } = v.getBoundingClientRect(), n = document.documentElement.clientWidth;
27
+ v.style.left = `${Math.min(Math.max(a, e.left + e.width / 2 - t / 2), n - t - a)}px`, v.style.top = `${e.bottom}px`, y.style.maxHeight = `${Math.max(0, innerHeight - e.bottom - i - a)}px`;
28
+ }, E = () => {
29
+ o.isConnected || S.clear();
30
+ let e = S.size > 0;
31
+ if (e === (w !== void 0)) return;
32
+ if (h.setAttribute("aria-expanded", String(e)), !e) {
33
+ w.abort(), w = void 0, v.matches(":popover-open") && v.hidePopover();
34
+ return;
35
+ }
36
+ v.showPopover(), T(), w = new AbortController();
37
+ let { signal: t } = w;
38
+ document.addEventListener("keydown", A, { signal: t }), document.addEventListener("pointerdown", (e) => {
39
+ e.composedPath().includes(o) || k();
40
+ }, {
41
+ capture: !0,
42
+ signal: t
43
+ }), window.addEventListener("blur", () => k(), { signal: t }), window.addEventListener("scroll", T, {
44
+ capture: !0,
45
+ passive: !0,
46
+ signal: t
47
+ }), window.addEventListener("resize", T, { signal: t });
48
+ }, D = () => {
49
+ clearTimeout(C), C = void 0;
50
+ }, O = !1, k = (e = !1) => {
51
+ D(), S.clear(), E(), e && (O = !0, h.focus(), O = !1);
52
+ }, A = (e) => {
53
+ if (e.key !== "Escape") return;
54
+ let t = o.contains(document.activeElement);
55
+ t && (e.preventDefault(), e.stopPropagation()), k(t);
56
+ }, j = (e) => e.pointerType === "mouse" || e.pointerType === "pen";
57
+ return o.addEventListener("pointerenter", (e) => {
58
+ j(e) && (D(), S.add("hover"), E());
59
+ }), o.addEventListener("pointerleave", (e) => {
60
+ j(e) && S.has("hover") && (D(), C = setTimeout(() => {
61
+ C = void 0, S.delete("hover"), E();
62
+ }, 300));
63
+ }), h.addEventListener("click", () => {
64
+ if (S.has("pinned")) return k();
65
+ S.add("pinned"), E();
66
+ }), h.addEventListener("focusin", () => {
67
+ !O && h.matches(":focus-visible") && (S.add("focus"), E());
68
+ }), o.addEventListener("focusout", () => setTimeout(() => {
69
+ o.contains(document.activeElement) || (S.delete("focus"), S.delete("pinned"), E());
70
+ }, 0)), {
71
+ element: o,
72
+ destroy: () => {
73
+ k(), o.remove();
74
+ }
75
+ };
76
+ }, g = ({ className: n, style: r } = {}) => t("iframe", {
5
77
  src: e(),
6
78
  title: "Sign in to FKN",
7
79
  className: n,
@@ -13,6 +85,23 @@ var n = ({ className: n, style: r } = {}) => t("iframe", {
13
85
  colorScheme: "normal",
14
86
  ...r
15
87
  }
16
- });
17
- //#endregion
18
- export { n as ConnectButton, e as connectButtonUrl };
88
+ }), _ = ({ className: e, style: i, label: a, linkLabel: o, href: s }) => {
89
+ let c = r(null);
90
+ return n(() => {
91
+ let e = h({
92
+ label: a,
93
+ linkLabel: o,
94
+ href: s
95
+ });
96
+ return c.current.append(e.element), e.destroy;
97
+ }, [
98
+ a,
99
+ o,
100
+ s
101
+ ]), t("span", {
102
+ ref: c,
103
+ className: e,
104
+ style: i
105
+ });
106
+ };
107
+ export { g as ConnectButton, _ as PoweredByFkn, e as connectButtonUrl };
@@ -1,5 +1,5 @@
1
1
  import { RELAY_CHOICE_UNSUPPORTED as e, RELAY_UNAVAILABLE as t } from "./contract.js";
2
- //#region src/relay-choice.ts
2
+ // src/relay-choice.ts
3
3
  var n = (e) => Object.assign(Error(e), { name: t }), r = (e) => typeof e == "object" && !!e && e.name === "RelayUnavailableError", i = (t, r) => {
4
4
  if (typeof t.relay?.resolve != "function") throw n(`${r}: ${e}`);
5
5
  }, a = /* @__PURE__ */ new WeakMap(), o = (e, t) => {
@@ -10,5 +10,4 @@ var n = (e) => Object.assign(Error(e), { name: t }), r = (e) => typeof e == "obj
10
10
  let n = e.headers;
11
11
  return n instanceof Headers ? n.get("fkn-relay") ?? void 0 : e._relay;
12
12
  };
13
- //#endregion
14
13
  export { o as a, n as i, r as n, s as r, i as t };
@@ -1,8 +1,7 @@
1
- import { D as RelayChoice, f as Frame } from "./index-C5DdoMGo.js";
2
- import { K as RELAY_UNAVAILABLE } from "./contract-BGMJVvTg.js";
1
+ import { D as RelayChoice, f as Frame } from "./index-Cu5EcdK0.js";
2
+ import { K as RELAY_UNAVAILABLE } from "./contract-0rua6Wsh.js";
3
3
  import { Server, Socket } from "net";
4
4
  import { Socket as Socket$1 } from "dgram";
5
- //#region src/relay-choice.d.ts
6
5
  /** What `net.connect`, `net.createServer`, `dgram.createSocket` and `http.request` take beside Node's own options; Node ignores it. */
7
6
  type RelayOption = {
8
7
  relay?: RelayChoice;
@@ -24,5 +23,4 @@ declare const isRelayUnavailable: (error: unknown) => error is RelayUnavailableE
24
23
  * the broker has named it, normally before the attach resolves.
25
24
  */
26
25
  declare const relayOf: (served: Response | Socket | Server | Socket$1 | Frame) => string | undefined;
27
- //#endregion
28
26
  export { relayOf as i, RelayUnavailableError as n, isRelayUnavailable as r, RelayOption as t };
@@ -1,4 +1,4 @@
1
- //#region \0rolldown/runtime.js
1
+ // \0rolldown/runtime.js
2
2
  var e = Object.defineProperty, t = (t, n) => {
3
3
  let r = {};
4
4
  for (var i in t) e(r, i, {
@@ -7,5 +7,4 @@ var e = Object.defineProperty, t = (t, n) => {
7
7
  });
8
8
  return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
9
9
  };
10
- //#endregion
11
10
  export { t };
@@ -0,0 +1,227 @@
1
+ import { $ as RoomCreateOptions, Q as RoomClaimOptions, Z as RoomBacklog, at as RoomJoinOptions, ct as RoomMember, dt as RoomPermission, et as RoomDefaults, ft as RoomPermissions, ht as RoomsErrorCode, lt as RoomMessage, mt as RoomType, nt as RoomEnvelope, ot as RoomJson, pt as RoomSchema, rt as RoomEvent, st as RoomMailbox, tt as RoomEnd, ut as RoomOpenOptions } from "./contract-0rua6Wsh.js";
2
+ declare namespace rooms_d_exports {
3
+ export { RoomClaimOptions as ClaimOptions, RoomCreateOptions as CreateOptions, RoomJoinOptions as JoinOptions, RoomOpenOptions as OpenOptions, Room, RoomBacklog, RoomDefaults, RoomEnd, RoomEnvelope, RoomEvent, RoomJson, RoomMailbox, RoomMember, RoomMessage, RoomPermission, RoomPermissions, RoomSchema, RoomType, RoomsError, RoomsErrorCode, available, create, join, open };
4
+ }
5
+ /** Thrown by every member of this namespace. Match on `code`, never on the message. */
6
+ type RoomsError = Error & {
7
+ code: RoomsErrorCode;
8
+ };
9
+ /**
10
+ * A joined room. The same object survives a broker replacement, so it is safe to hold for as long
11
+ * as the chat lasts.
12
+ */
13
+ type Room = {
14
+ /** `<scope>/<name>`: the name under this app's own scope, or under `global` */
15
+ readonly id: string;
16
+ readonly name: string;
17
+ /** the room key, base64url. The server never sees it. Anyone holding it and the id can join. */
18
+ readonly key: string;
19
+ /** `key` and `id` as one string, the thing to put in a link */
20
+ readonly invite: string;
21
+ /** this app's member record, as this room sees it. The id is fresh in every room. */
22
+ readonly self: RoomMember;
23
+ /** the owner's member id, or '' while a claimed room's owner has never joined */
24
+ readonly owner: string;
25
+ /** whether an account keeps this name. Whether it keeps the messages too is `mailbox`. */
26
+ readonly claimed: boolean;
27
+ /**
28
+ * what the mailbox holds, as the room last said. Null while the room keeps no messages: nobody has
29
+ * claimed it, or its claim keeps none. The account can clear the room, unclaim it, turn its messages
30
+ * off or on, or set a lower `cap` from its fkn.app settings, which the app hears as a `deleted` or a
31
+ * `claim` event; `usage()` reads the figures again.
32
+ */
33
+ readonly mailbox: RoomMailbox | null;
34
+ defaults: () => RoomDefaults;
35
+ members: () => Promise<RoomMember[]>;
36
+ /** the room's schema as the room last said, null for a room without one */
37
+ schema: () => RoomSchema | null;
38
+ /**
39
+ * `text` is sealed before it leaves the browser. Rejects `too-large` past `self.maxMessageBytes` on the
40
+ * wire, never truncates.
41
+ *
42
+ * In a room with a schema `envelope` is required: it goes in plain beside the sealed text, which may be
43
+ * empty, and the sealed text opens only under it. The app chooses what is sealed at each send: put in
44
+ * the envelope only what every member and FKN may read, and the rest in `text`. The lib writes it with
45
+ * `JSON.stringify` and refuses `invalid` (`rooms: the message does not fit the room's schema`), with
46
+ * nothing sent, one that is not a JSON object with a string `type` or is past 2,048 characters; the room
47
+ * refuses the same for an envelope that does not fit its type, or a send without one. The size counted
48
+ * is the envelope's text and the sealed text together, against `self.maxMessageBytes` and the type's
49
+ * `maxBytes`. The type's sender rule refuses `denied` (`rooms: only the owner sends this type`, `rooms:
50
+ * sending this needs an account`), its per-account limit `full` (`rooms: you have as many of these
51
+ * here as the room allows`), and the room's cap `storage` (`rooms: the mailbox is full`).
52
+ *
53
+ * Without a schema an envelope is refused `invalid` (`rooms: the room has no schema`). An fkn.app older
54
+ * than room schemas refuses one `unavailable` (`rooms: room schemas are not available`) with nothing
55
+ * sent; a send without one goes as before.
56
+ */
57
+ send: (text: string, envelope?: RoomEnvelope) => Promise<void>;
58
+ /**
59
+ * replaces a stored message's text: one of your own, or any as the owner. Checked exactly as a send is,
60
+ * `send` and the rate limits included; in a room with a schema `envelope` is required and names the
61
+ * message's own type, so a message stored before the room had a schema is deleted rather than edited.
62
+ * On a room claimed under an app's scope, from another app of the claim's account, it is refused
63
+ * `denied` (`rooms: only the app that claimed the room can change it`), the account's own messages
64
+ * included, as `claim` says.
65
+ */
66
+ edit: (seq: number, text: string, envelope?: RoomEnvelope) => Promise<void>;
67
+ /**
68
+ * replaces the room's schema with one of a higher `version`, from the next send on; everyone present
69
+ * hears a `schema` event. The same schema at the same `version` resolves and changes nothing, so set it
70
+ * on every open. A lower `version`, or another schema at the same one, is refused `invalid` (`rooms: the
71
+ * room holds a newer schema`), and one the room cannot take `invalid` (`rooms: the schema is not one a
72
+ * room can take`). From the owner only (`denied`, `rooms: not the room owner`), and on a room claimed
73
+ * under an app's scope only through the app that claimed it (`denied`, `rooms: only the app that
74
+ * claimed the room can change it`), as `claim` says. A schema is never removed. An fkn.app older than
75
+ * room schemas refuses it `unavailable` (`rooms: room schemas are not available`).
76
+ */
77
+ setSchema: (schema: RoomSchema) => Promise<void>;
78
+ /**
79
+ * drops stored messages: one of your own, or any range as the owner. On a room claimed under an app's
80
+ * scope, from another app of the claim's account, it is refused `denied` (`rooms: only the app that
81
+ * claimed the room can change it`), the account's own messages included, as `claim` says.
82
+ */
83
+ delete: (from: number, to?: number) => Promise<void>;
84
+ /**
85
+ * replays the stored messages above `after` as `message` events, one page at a time: at most `limit` messages and
86
+ * never more than 200 or 64 KiB, though a page holds one while any is left. They come in seq order, all of them
87
+ * before the call resolves, so a list built from them is whole once it does. `replayed` marks the ones that predate
88
+ * this connection, so one sent since comes again unmarked: key a list by seq. A message that does not open under the
89
+ * room's key is skipped. `last` is the seq the next page starts after, and `more` whether the room holds messages
90
+ * past it. Refused `denied` (`rooms: permission denied`) without `receive`.
91
+ */
92
+ backlog: (after: number, limit?: number) => Promise<RoomBacklog>;
93
+ /**
94
+ * whether a member with no override may send or receive, from the owner only (`denied`, `rooms: not
95
+ * the room owner`). On a room claimed under an app's scope, from another app of the claim's account,
96
+ * it is refused `denied` (`rooms: only the app that claimed the room can change it`), as `claim` says.
97
+ */
98
+ setDefault: (permission: 'send' | 'receive', value: boolean) => Promise<void>;
99
+ /**
100
+ * the message size cap, from 1 to 31,457,280 (30 MiB). With no id it sets the room default, which is
101
+ * always a number. With an id it sets that member's override, and null clears the override. From the
102
+ * owner only (`denied`, `rooms: not the room owner`); on a room claimed under an app's scope, from
103
+ * another app of the claim's account, it is refused `denied` (`rooms: only the app that claimed the
104
+ * room can change it`), as `claim` says.
105
+ */
106
+ limit: {
107
+ (maxMessageBytes: number, id?: string): Promise<void>;
108
+ (maxMessageBytes: number | null, id: string): Promise<void>;
109
+ };
110
+ /**
111
+ * gives a member a permission over the room default, from the owner only (`denied`, `rooms: not the
112
+ * room owner`). On a room claimed under an app's scope, from another app of the claim's account, it is
113
+ * refused `denied` (`rooms: only the app that claimed the room can change it`), as `claim` says.
114
+ */
115
+ grant: (id: string, permission: RoomPermission) => Promise<void>;
116
+ /**
117
+ * takes a permission from a member over the room default, from the owner only (`denied`, `rooms: not
118
+ * the room owner`). On a room claimed under an app's scope, from another app of the claim's account, it
119
+ * is refused `denied` (`rooms: only the app that claimed the room can change it`), as `claim` says.
120
+ */
121
+ revoke: (id: string, permission: RoomPermission) => Promise<void>;
122
+ /**
123
+ * sends a member out of the room, which they may join again, with the `remove` permission (`denied`,
124
+ * `rooms: permission denied`). On a room claimed under an app's scope, from another app of the claim's
125
+ * account, it is refused `denied` (`rooms: only the app that claimed the room can change it`), as
126
+ * `claim` says.
127
+ */
128
+ remove: (id: string) => Promise<void>;
129
+ /**
130
+ * sends a member out of the room and keeps them out, with the `block` permission (`denied`, `rooms:
131
+ * permission denied`). On a room claimed under an app's scope, from another app of the claim's account,
132
+ * it is refused `denied` (`rooms: only the app that claimed the room can change it`), as `claim` says.
133
+ */
134
+ block: (id: string) => Promise<void>;
135
+ /**
136
+ * lets a blocked member join again, with the `block` permission (`denied`, `rooms: permission denied`).
137
+ * On a room claimed under an app's scope, from another app of the claim's account, it is refused
138
+ * `denied` (`rooms: only the app that claimed the room can change it`), as `claim` says.
139
+ */
140
+ unblock: (id: string) => Promise<void>;
141
+ /**
142
+ * keeps the name for the signed-in account, and a mailbox unless asked not to. A free account holds 5
143
+ * claims and a premium one 10, in any scope, `global` included; once premium lapses the account keeps its
144
+ * 5 oldest claims and the others are released 30 days later. `description`
145
+ * says what the room is for, shown to the account in its fkn.app settings; a permanent claim with an
146
+ * unchanged one on every open is free. Claiming on every open also claims the room again after the
147
+ * account unclaims it from fkn.app, so claim when the person wants the room kept, or make it `temporary`.
148
+ *
149
+ * `temporary` makes the claim end by itself, in milliseconds (`true` is 7 days), that long after its
150
+ * last claim: a temporary claim goes to the account's ledger every time, which is what restarts its
151
+ * clock. When it ends the app hears a `claim` event with `claimed: false`, exactly as for an Unclaim
152
+ * from fkn.app, and the stored messages are gone. A broker too old to carry it refuses the call
153
+ * `unavailable` (`rooms: temporary claims are not available`) rather than make the claim permanent.
154
+ *
155
+ * `mailbox: false` keeps the name and stores nothing: the room relays as an unclaimed one does. It is
156
+ * read only when the call starts the claim and ignored on a room the account already holds, so claiming
157
+ * on every open never undoes the owner's choice.
158
+ *
159
+ * Who changes a claimed room depends on its scope. A room under an app's scope, which is every room
160
+ * but a `global` one, is changed by the claim's account only through the app that claimed it (the
161
+ * same app once it is verified): from another app of the account `setDefault`, `limit`, `grant`,
162
+ * `revoke`, `remove`, `block`, `unblock`, `setMailbox`, `edit` and `delete` are refused `denied`
163
+ * (`rooms: only the app that claimed the room can change it`), the account's own messages included,
164
+ * and nothing changes. That other app, which reaches the room through its invite, still joins, reads
165
+ * and sends. A claimed `global` room is changed by any app of the account, which also describes it,
166
+ * sets its `temporary` and releases it. The account changes every room it claimed
167
+ * from its fkn.app settings, whichever app claimed it, and members of other accounts are answered as
168
+ * in any room. While the room cannot tell whether two apps are one, such a change is refused
169
+ * `unavailable` (`rooms: rooms are unavailable`) and can be sent again.
170
+ *
171
+ * Past the account's room limit the call waits while fkn.app shows the person their claimed rooms over
172
+ * your app, with Unclaim on each: it resolves once one is unclaimed and this claim is made, and rejects
173
+ * `full` (`rooms: too many claims`) when they close the card or when fkn.app cannot show it. Nothing
174
+ * about the account's other rooms reaches your app.
175
+ */
176
+ claim: (options?: RoomClaimOptions) => Promise<void>;
177
+ /**
178
+ * turns a claimed room's mailbox off or on, from the room's owner only, which in a claimed room is the
179
+ * claim's account. Off deletes every stored message at once, the archive included, and the room then
180
+ * relays as an unclaimed one does while keeping its claim; whoever is present hears a `claim` event
181
+ * with `mailbox: false` and no `deleted`, so what an app shows stays. On starts an empty mailbox that
182
+ * keeps messages from the next `seq`, and nothing deleted comes back. Neither way needs premium.
183
+ * Setting what it already is changes nothing. Resolves once the room answered, with `mailbox` reading the
184
+ * new state, or a newer one when a release or the account's own switch landed before the answer.
185
+ *
186
+ * Refused `invalid` (`rooms: the room is not claimed`) on an unclaimed room, `denied` (`rooms: not the
187
+ * room owner`) from anyone else, `denied` (`rooms: only the app that claimed the room can change it`)
188
+ * from another app of the claim's account on a room claimed under an app's scope, as `claim` says, and
189
+ * `invalid` (`rooms: malformed frame`) for anything but a boolean. A broker too old to carry it refuses
190
+ * `unavailable` (`rooms: the mailbox switch is not available`). The account can do the same from its
191
+ * fkn.app settings, whichever app claimed the room.
192
+ */
193
+ setMailbox: (on: boolean) => Promise<void>;
194
+ /**
195
+ * gives the claim back: the mailbox is deleted and whoever is present stays in an ordinary room. On a
196
+ * room under an app's scope, the app that claimed it only (the same app once it is verified), and from
197
+ * another app it is refused `denied` (`rooms: only the app that claimed the room can release it`); on a
198
+ * `global` room, any app of the account. The account can also unclaim it from its fkn.app settings.
199
+ */
200
+ release: () => Promise<void>;
201
+ usage: () => Promise<RoomMailbox | null>;
202
+ /** Await the returned unsubscribe in cleanup, the `account.onChange` shape. */
203
+ on: (listener: (event: RoomEvent) => void) => Promise<() => void>;
204
+ /**
205
+ * ends this `Room`: `closed` settles with `left`, and later requests are refused `closed` (`rooms: the room has
206
+ * ended`). The room counts members, not `Room`s: an account whose key this device holds is one member in all of its
207
+ * tabs, apps and devices, and a guest, or a tab without the account's key, is one member in that tab and in any tab
208
+ * duplicated from it. While another `Room` of the same member is open the member stays and nobody present hears a
209
+ * thing; the last one's leave is the departure, a `left` event with reason `left` for everyone else.
210
+ */
211
+ leave: () => Promise<void>;
212
+ /** Settles once, when the room ends for this app. Never rejects. */
213
+ readonly closed: Promise<RoomEnd>;
214
+ };
215
+ /** Whether this realm can join a room: false in Node, false in a worker nothing bridged, false against a shell older than named rooms. Answers rather than rejecting. */
216
+ declare const available: () => Promise<boolean>;
217
+ /**
218
+ * Open a room by name: a name under this app's own scope, or `global/<name>` for the shared one.
219
+ * Nobody there means the room comes into being with you as its owner; somebody there means you join
220
+ * them, and the key has to match theirs. Share `room.invite` to let anyone else in.
221
+ */
222
+ declare const open: (name: string, options?: RoomOpenOptions) => Promise<Room>;
223
+ /** Open a room under a random name and become its owner. Share `room.invite` to let anyone else in. */
224
+ declare const create: (options?: RoomCreateOptions) => Promise<Room>;
225
+ /** `invite` is `room.invite`: a key and a room id joined by a dot. */
226
+ declare const join: (invite: string, options?: RoomJoinOptions) => Promise<Room>;
227
+ export { join as a, create as i, RoomsError as n, open as o, available as r, rooms_d_exports as s, Room as t };
@@ -0,0 +1 @@
1
+ const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-DrvhPN56.cjs"),n=require("./busy-BXbVH595.cjs"),r=require("./contract.cjs");var i=e.t({available:()=>S,create:()=>T,join:()=>E,open:()=>w}),a={wrongKey:`rooms: wrong room key`,inviteNoKey:`rooms: the invite carries no key`,badName:`rooms: the name is not one a room can have`,badKeyOption:`rooms: the key is not 32 bytes base64url`,noSuchMember:`rooms: no such member`,noSuchMessage:`rooms: no such message`,roomFull:`rooms: the room is full`,tooManyConnections:`rooms: too many connections`,tooManyBlocks:`rooms: too many blocks`,tooManyClaims:`rooms: too many claims`,mailboxFull:`rooms: the mailbox is full`,outOfStorage:`rooms: the owner is out of storage`,outOfQuota:`rooms: out of daily bandwidth`,blocked:`rooms: you are blocked from this room`,cannotSend:`rooms: you cannot send here`,permissionDenied:`rooms: permission denied`,notOwner:`rooms: not the room owner`,ownerNotRemovable:`rooms: the owner cannot be removed`,ownerKeepsEvery:`rooms: the owner keeps every permission`,removeYourself:`rooms: you cannot remove yourself`,needsAccount:`rooms: claiming needs an account`,nameClaimed:`rooms: the name is claimed`,notClaimed:`rooms: the room is not claimed`,noMailbox:`rooms: the room keeps no messages`,badLimit:`rooms: the limit is out of range`,badDescription:`rooms: the description is not one a claim can carry`,notClaimer:`rooms: only the app that claimed the room can describe it`,notReleaser:`rooms: only the app that claimed the room can release it`,notClaimingApp:`rooms: only the app that claimed the room can change it`,badTemporary:`rooms: the temporary duration is not one a claim can carry`,notTemporaryClaimer:`rooms: only the app that claimed the room can set when it expires`,temporaryUnavailable:`rooms: temporary claims are not available`,mailboxUnavailable:`rooms: the mailbox switch is not available`,guestUnavailable:`rooms: guest joins are not available`,schemasUnavailable:`rooms: room schemas are not available`,badSchema:`rooms: the schema is not one a room can take`,newerSchema:`rooms: the room holds a newer schema`,noSchema:`rooms: the room has no schema`,misfit:`rooms: the message does not fit the room's schema`,ownerSends:`rooms: only the owner sends this type`,accountSends:`rooms: sending this needs an account`,perAccount:`rooms: you have as many of these here as the room allows`,tooFast:`rooms: sending too fast`,tooLarge:`rooms: the message is too large`,unavailable:`rooms: rooms are unavailable`,notEnabled:`rooms: rooms are not available`,alreadyJoined:`rooms: already joined`,notJoined:`rooms: not joined`,malformed:`rooms: malformed frame`,ended:`rooms: the room has ended`},o=(e,t)=>Object.assign(Error(t),{code:e}),s=e=>e instanceof Error&&typeof e.code==`string`,c={send:!0,receive:!0,maxMessageBytes:262144},l=2048,u=()=>({messages:0,bytes:0,cap:5e8,archived:!1}),d=async()=>{if(!t.l)return;let e=(await t.s(`a room`).catch(()=>void 0))?.rooms;return typeof e?.open==`function`?e:void 0},f=()=>{throw o(`unavailable`,a.unavailable)},p=e=>e===`blocked`?`blocked`:e===`not-found`?`ended`:`unavailable`,m=e=>{if(e!==void 0&&e!==!1)return e===!0?r.ROOM_TEMPORARY_MS.default:typeof e!=`number`||!Number.isInteger(e)?null:e>=r.ROOM_TEMPORARY_MS.min&&e<=r.ROOM_TEMPORARY_MS.max?e:null},h=(e,t)=>{let n=t?e?.guest:e;return typeof n?.join==`function`?n:void 0},g=e=>{let t;try{t=JSON.stringify(e)}catch{}let n=t===void 0?void 0:JSON.parse(t),r=typeof n==`object`&&!!n&&!Array.isArray(n)&&typeof n.type==`string`;if(t===void 0||!r||t.length>l)throw o(`invalid`,a.misfit);return t},_=e=>{let t;try{t=JSON.parse(JSON.stringify(e))}catch{}if(typeof t!=`object`||!t||Array.isArray(t))throw o(`invalid`,a.badSchema);return t},v=e=>e?.schema===void 0?e:{...e,schema:_(e.schema)},y=e=>{if(e.schemas!==!0)throw o(`unavailable`,a.schemasUnavailable);return e},b=e=>{let t=e?.guest;if(t!==void 0&&typeof t!=`boolean`)throw o(`invalid`,a.malformed);return t===!0},x=async(e,r)=>{let i=e.invite,l=e,d=0,f=e.self,v=e.owner,b=e.claimed,x=e.mailbox,S=0,C=await e.defaults().catch(()=>c),w=e.schemas===!0?await Promise.resolve(e.schema()).catch(()=>null):null,T=0,E=!1,D=new Set,O=new Set,k=n.t(`room`),A=()=>{},j=()=>{},M=new Promise(e=>{j=e}),N=e=>{let t=[...O];O.clear();for(let n of t)try{n(e)}catch{}},P=e=>{E||(E=!0,A(),D.clear(),k(),N(o(`closed`,a.ended)),j({reason:e}))},F=e=>{if(E)return;let t=e;if(t.type===`defaults`&&(C=t.defaults),t.type===`schema`&&(T+=1,w=t.schema),t.type===`message`||t.type===`edited`){let e={...t.message,envelope:t.message.envelope??null};t=t.type===`message`?{...t,message:e}:{type:`edited`,message:e}}if(t.type===`permissions`&&t.id===f.id&&(f={id:f.id,permissions:t.permissions,maxMessageBytes:t.maxMessageBytes}),t.type===`claim`){S+=1;let e=t.claimed&&t.mailbox!==!1;t={type:`claim`,claimed:t.claimed,owner:t.owner,mailbox:e},b=t.claimed,v=t.owner,x=e?u():null}for(let e of[...D])try{e(t)}catch{}},I=(e,t)=>{Promise.resolve(e.on(F)).catch(()=>{}),Promise.resolve(e.closed).then(e=>{t===d&&P(e.reason)},()=>{})},L=async(e,t)=>{let n=h(e,r);if(!n)return P(`unavailable`);let a=await n.join(i).catch(()=>void 0);if(E||t!==d)return;if(!a)return P(`unavailable`);if(`error`in a)return P(p(a.error));if(a.self.id!==f.id)return Promise.resolve(a.leave()).catch(()=>{}),P(`unavailable`);l=a,f=a.self,v=a.owner,b=a.claimed,x=a.mailbox,I(a,t);let o=await a.defaults().catch(()=>void 0);if(o&&!E&&t===d&&(C=o),a.schemas!==!0)return;let s=await Promise.resolve(a.schema()).catch(()=>void 0);s!==void 0&&!E&&t===d&&(w=s)};A=t.u((e,t)=>{let n=d;d=t,!(E||n===0||n===t)&&(N(o(`unavailable`,a.unavailable)),L(e.rooms,t))}),I(e,d);let R=async e=>{if(E)throw o(`closed`,a.ended);let t=()=>{},n=new Promise((e,n)=>{t=n});O.add(t);try{return await Promise.race([Promise.resolve(e(l)),n])}catch(e){throw s(e)?e:o(`unavailable`,a.unavailable)}finally{O.delete(t)}},z=async e=>{let t=await R(e);if(`error`in t)throw o(t.error,t.message)},B=async e=>{let t=await R(e);if(typeof t==`object`&&t&&`error`in t)throw o(t.error,t.message);return t};return{id:e.id,name:e.name,key:e.key,invite:i,get self(){return f},get owner(){return v},get claimed(){return b},get mailbox(){return x},defaults:()=>C,members:()=>R(e=>e.members()),schema:()=>w,send:async(e,t)=>{if(t===void 0)return z(t=>t.send(e));let n=g(t);return z(t=>y(t).send(e,n))},edit:async(e,t,n)=>{if(n===void 0)return z(n=>n.edit(e,t));let r=g(n);return z(n=>y(n).edit(e,t,r))},setSchema:async e=>{let t=_(e),n=T;await z(e=>y(e).setSchema(t)),T===n&&(w=t)},delete:(e,t)=>z(n=>n.delete(e,t)),backlog:(e,t)=>B(n=>n.backlog(e,t)),setDefault:(e,t)=>z(n=>n.setDefault(e,t)),limit:(e,t)=>z(n=>n.limit(e,t)),grant:(e,t)=>z(n=>n.grant(e,t)),revoke:(e,t)=>z(n=>n.revoke(e,t)),remove:e=>z(t=>t.remove(e)),block:e=>z(t=>t.block(e)),unblock:e=>z(t=>t.unblock(e)),claim:async e=>{let t=e?.description;if(t!==void 0&&typeof t!=`string`)throw o(`invalid`,a.badDescription);let n=m(e?.temporary);if(n===null)throw o(`invalid`,a.badTemporary);let r=e?.mailbox;if(r!==void 0&&typeof r!=`boolean`)throw o(`invalid`,a.malformed);let i={...t===void 0?{}:{description:t},...n===void 0?{}:{temporary:n},...r===void 0?{}:{mailbox:r}};return Object.keys(i).length===0?z(e=>e.claim()):z(e=>{if(n!==void 0&&e.temporaryClaims!==!0)throw o(`unavailable`,a.temporaryUnavailable);if(r===!1&&e.mailboxSwitch!==!0)throw o(`unavailable`,a.mailboxUnavailable);return e.claim(i)})},setMailbox:async e=>{if(typeof e!=`boolean`)throw o(`invalid`,a.malformed);let t=S;await z(t=>{if(t.mailboxSwitch!==!0)throw o(`unavailable`,a.mailboxUnavailable);return t.setMailbox(e)}),S===t&&(e?x===null&&(x=u()):x=null)},release:()=>z(e=>e.release()),usage:async()=>{let e=await B(e=>e.usage());return x=e,e},on:async e=>E?()=>{}:(D.add(e),()=>{D.delete(e)}),leave:async()=>{await Promise.resolve(l.leave()).catch(()=>{}),P(`left`)},closed:M}},S=async()=>{let e=await d();return e?e.available().catch(()=>!1):!1},C=async(e,t,n)=>{let r=await d();if(!r)throw o(`unavailable`,a.unavailable);let i=h(r,e);if(!i)throw o(`unavailable`,a.guestUnavailable);let s=await n(i).catch(f);if(`error`in s)throw o(s.error,s.message);if(t?.schema!==void 0&&s.schemas!==!0)throw await Promise.resolve(s.leave()).catch(()=>{}),o(`unavailable`,a.schemasUnavailable);return x(s,e)},w=async(e,t)=>{if(typeof e!=`string`||e.length===0||e.length>72)throw o(`invalid`,a.badName);let n=b(t),r=v(t);return C(n,r,t=>t.open(e,r))},T=async e=>{let t=b(e),n=v(e);return C(t,n,e=>e.create(n))},E=async(e,t)=>{let n=typeof e==`string`?e.indexOf(`.`):-1;if(n<=0||n===e.length-1)throw o(`invalid`,a.inviteNoKey);return C(b(t),void 0,n=>n.join(e,t))};Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return S}});