@fkn/lib 0.9.47 → 0.9.48

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.
@@ -1527,7 +1527,7 @@ var Et = class {
1527
1527
  if (r?.display === "none" || r?.visibility === "hidden") return !1;
1528
1528
  let i = n.getBoundingClientRect();
1529
1529
  return i.width > 0 && i.height > 0;
1530
- } }, dn = { resolve: (e, t = {}) => e.elements.length }, fn = { resolve: (e, t = {}) => e.elements.length > 0 }, q = (e, t) => e.elements.flatMap((e) => [...e.querySelectorAll(t)]), pn = (e) => e.replaceAll("\"", "\\\""), mn = {
1530
+ } }, dn = { resolve: (e, t = {}) => e.elements.length }, fn = { resolve: (e, t = {}) => e.elements.length > 0 }, q = (e, t) => (e.topLevel ? [e.document] : e.elements).flatMap((e) => [...e.querySelectorAll(t)]), pn = (e) => e.replaceAll("\"", "\\\""), mn = {
1531
1531
  to: "element",
1532
1532
  css: !0,
1533
1533
  resolve: (e, t) => q(e, t),
@@ -2258,15 +2258,9 @@ var Er = 3e4, Dr = `frame.evaluate: the code did not settle within ${Er}ms`, Or
2258
2258
  cookies: t,
2259
2259
  storageState: n
2260
2260
  };
2261
- }, qr = (e) => {
2262
- try {
2263
- return new URL(e).hostname;
2264
- } catch {
2265
- return "";
2266
- }
2267
- }, Jr = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", Yr = !1, Xr = () => {
2268
- Yr || (Yr = !0, console.warn("[fkn-frame] the installed FKN WebExtension is too old to ask for permission categories upfront, so each capability will be asked for as it is first used. Updating the extension fixes this."));
2269
- }, Zr = "frame: this frame no longer holds the document the app attached it to", Qr = "frame.postMessage: '*' is not served on the extension yet, since this extension does not report the frame's origin; pass the page's origin as targetOrigin", $r = () => {
2261
+ }, qr = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", Jr = !1, Yr = () => {
2262
+ Jr || (Jr = !0, console.warn("[fkn-frame] the installed FKN WebExtension is too old to ask for permission categories upfront, so each capability will be asked for as it is first used. Updating the extension fixes this."));
2263
+ }, Xr = "frame: this frame no longer holds the document the app attached it to", Zr = "frame.postMessage: '*' is not served on the extension yet, since this extension does not report the frame's origin; pass the page's origin as targetOrigin", Qr = () => {
2270
2264
  let e = E();
2271
2265
  if (e.status === "ok" && e.abi >= 1) return;
2272
2266
  let t = e.status === "absent" ? 0 : e.abi;
@@ -2280,8 +2274,8 @@ var Er = 3e4, Dr = `frame.evaluate: the code did not settle within ${Er}ms`, Or
2280
2274
  }, $ = () => {
2281
2275
  let e = E();
2282
2276
  return e.status === "absent" ? 0 : e.abi;
2283
- }, ei = "attachFrame: a blank page is served by the cloud render proxy only; call cloud.attachFrame", ti = "frame.addScriptTag: an extension frame does not run scripts through mirage yet; attach with cloud.attachFrame", ni = "frame.clearCookies: an extension frame runs on the browser's own cookies (cookies: 'native'), which FKN does not clear; attach with cookies: 'persistent' to clear the app's jar", ri = ({ executeLocator: e, highlightLocator: t, ensureLocatorPermission: n, requestCategories: r, evaluateFrame: i, goto: a }, { hosts: o, url: s, page: c, unreachable: l, documents: u, navigated: d }) => {
2284
- let f = new Set(p(o, { ipv6: !0 })), m = (e) => f.has(p([qr(e)], { ipv6: !0 })[0] ?? "");
2277
+ }, $r = "attachFrame: a blank page is served by the cloud render proxy only; call cloud.attachFrame", ei = "frame.addScriptTag: an extension frame does not run scripts through mirage yet; attach with cloud.attachFrame", ti = "frame.clearCookies: an extension frame runs on the browser's own cookies (cookies: 'native'), which FKN does not clear; attach with cookies: 'persistent' to clear the app's jar", ni = ({ executeLocator: e, highlightLocator: t, ensureLocatorPermission: n, requestCategories: r, evaluateFrame: i, goto: a }, { hosts: o, url: s, page: c, unreachable: l, documents: u, navigated: d }) => {
2278
+ let f = new Set(p(o, { ipv6: !0 })), m = (e) => f.has(p([ht(e)], { ipv6: !0 })[0] ?? "");
2285
2279
  return ar({
2286
2280
  backend: "extension",
2287
2281
  executor: {
@@ -2303,14 +2297,14 @@ var Er = 3e4, Dr = `frame.evaluate: the code did not settle within ${Er}ms`, Or
2303
2297
  });
2304
2298
  },
2305
2299
  addScriptTag: async () => {
2306
- throw new T("addScriptTag", $(), ti);
2300
+ throw new T("addScriptTag", $(), ei);
2307
2301
  },
2308
2302
  clearCookies: async () => {
2309
- throw new T("clearCookies", $(), ni);
2303
+ throw new T("clearCookies", $(), ti);
2310
2304
  },
2311
2305
  postMessage: (e, t, n) => {
2312
- if (t === "*") throw I(Qr, "postMessage", "extension");
2313
- if (!m(t)) throw L(Zr, "postMessage");
2306
+ if (t === "*") throw I(Zr, "postMessage", "extension");
2307
+ if (!m(t)) throw L(Xr, "postMessage");
2314
2308
  let r = l();
2315
2309
  if (r) throw r;
2316
2310
  return c().postMessage(e, t, n), Promise.resolve();
@@ -2347,16 +2341,16 @@ var Er = 3e4, Dr = `frame.evaluate: the code did not settle within ${Er}ms`, Or
2347
2341
  },
2348
2342
  url: s
2349
2343
  });
2350
- }, ii = async ({ iframe: e, domains: t = [], lockdown: n = !1, permissions: r, blank: i }) => {
2351
- if (i !== void 0) throw new T("blank", $(), ei);
2344
+ }, ri = async ({ iframe: e, domains: t = [], lockdown: n = !1, permissions: r, blank: i }) => {
2345
+ if (i !== void 0) throw new T("blank", $(), $r);
2352
2346
  let a = crypto.randomUUID();
2353
2347
  if (J(e.src), Bn({
2354
2348
  src: e.src,
2355
2349
  domains: t,
2356
2350
  lockdown: n
2357
- }), j("attachFrame", t), await D(), n && $r(), !e.isConnected) throw Error("attachFrame: the iframe must be connected to the document before attaching");
2358
- e.dispatchEvent(new CustomEvent(Jr, { detail: a }));
2359
- let o = ri(await O.attachFrame({
2351
+ }), j("attachFrame", t), await D(), n && Qr(), !e.isConnected) throw Error("attachFrame: the iframe must be connected to the document before attaching");
2352
+ e.dispatchEvent(new CustomEvent(qr, { detail: a }));
2353
+ let o = ni(await O.attachFrame({
2360
2354
  marker: a,
2361
2355
  domains: t,
2362
2356
  syncCookies: !0,
@@ -2368,12 +2362,12 @@ var Er = 3e4, Dr = `frame.evaluate: the code did not settle within ${Er}ms`, Or
2368
2362
  unreachable: () => e.contentWindow === null ? L("frame: navigate the frame before postMessage", "postMessage") : void 0,
2369
2363
  documents: (t) => (e.addEventListener("load", t), () => e.removeEventListener("load", t))
2370
2364
  });
2371
- return r?.length && (kn() ? await o.requestPermissions(r) : Xr()), o;
2372
- }, ai = "attachFrame: a window on cookies: 'native' needs the FKN WebExtension, which is not on this page", oi = "frame.postMessage: this window's page no longer keeps a link to the app's page, so a message cannot reach it", si = "extension.attachFrame: the attached window closed; attach a fresh window", ci = (e) => `attachFrame: cookies: '${e}' runs on the cloud render proxy; call cloud.attachFrame or the top-level attachFrame`, li = async (e) => {
2365
+ return r?.length && (kn() ? await o.requestPermissions(r) : Yr()), o;
2366
+ }, ii = "attachFrame: a window on cookies: 'native' needs the FKN WebExtension, which is not on this page", ai = "frame.postMessage: this window's page no longer keeps a link to the app's page, so a message cannot reach it", oi = "extension.attachFrame: the attached window closed; attach a fresh window", si = (e) => `attachFrame: cookies: '${e}' runs on the cloud render proxy; call cloud.attachFrame or the top-level attachFrame`, ci = async (e) => {
2373
2367
  let { domains: t = [], permissions: n } = e, { url: r, width: i, height: a } = Pr(e.window);
2374
2368
  j("attachFrame", t);
2375
2369
  let o = E();
2376
- if (!Re(o, "attachWindow")) throw o.status === "absent" ? new T("attachWindow", 0, ai) : new T("attachWindow", o.abi);
2370
+ if (!Re(o, "attachWindow")) throw o.status === "absent" ? new T("attachWindow", 0, ii) : new T("attachWindow", o.abi);
2377
2371
  let s = window.open(r || "about:blank", "_blank", `popup,width=${i},height=${a}`);
2378
2372
  if (!s) throw new Gn();
2379
2373
  let c;
@@ -2392,11 +2386,11 @@ var Er = 3e4, Dr = `frame.evaluate: the code did not settle within ${Er}ms`, Or
2392
2386
  u = !0;
2393
2387
  }, () => {
2394
2388
  u = !0;
2395
- }), f = r, p = ri(c, {
2389
+ }), f = r, p = ni(c, {
2396
2390
  hosts: r ? [...t, Q(r)] : t,
2397
2391
  url: () => f,
2398
2392
  page: () => s,
2399
- unreachable: () => u ? I(si, "postMessage", "extension") : s.closed ? L(oi, "postMessage") : void 0,
2393
+ unreachable: () => u ? I(oi, "postMessage", "extension") : s.closed ? L(ai, "postMessage") : void 0,
2400
2394
  documents: (e) => {
2401
2395
  let t = !0;
2402
2396
  return (async () => {
@@ -2429,11 +2423,11 @@ var Er = 3e4, Dr = `frame.evaluate: the code did not settle within ${Er}ms`, Or
2429
2423
  throw await h(), e;
2430
2424
  }
2431
2425
  return g;
2432
- }, ui = (async (e) => {
2426
+ }, li = (async (e) => {
2433
2427
  let { kind: t, cookies: n } = Kr(e);
2434
- if (n !== "native") throw new T("cookies", $(), ci(n));
2435
- return t === "window" ? li(e) : ii(e);
2436
- }), di = "permissions.request: pass hosts, the sites the grant applies to", fi = { request: async (e) => {
2428
+ if (n !== "native") throw new T("cookies", $(), si(n));
2429
+ return t === "window" ? ci(e) : ri(e);
2430
+ }), ui = "permissions.request: pass hosts, the sites the grant applies to", di = { request: async (e) => {
2437
2431
  let t = e.map((e) => {
2438
2432
  let { category: t, key: n, scope: r, reason: i, hosts: a } = e;
2439
2433
  if (!("hosts" in e) && !("category" in e)) return { legacy: {
@@ -2442,7 +2436,7 @@ var Er = 3e4, Dr = `frame.evaluate: the code did not settle within ${Er}ms`, Or
2442
2436
  reason: i
2443
2437
  } };
2444
2438
  let o = p(a ?? [], { ipv6: !0 });
2445
- if (!o.length) throw TypeError(di);
2439
+ if (!o.length) throw TypeError(ui);
2446
2440
  return mt("permissions.request", o), { ask: {
2447
2441
  category: t,
2448
2442
  key: n,
@@ -2453,6 +2447,6 @@ var Er = 3e4, Dr = `frame.evaluate: the code did not settle within ${Er}ms`, Or
2453
2447
  _r("permissions.request", n), n.length && await An();
2454
2448
  let { items: r, answer: i } = vr(n), a = t.flatMap((e) => "legacy" in e ? [e.legacy] : []), o = [...r, ...a], s = o.length ? await O.requestPermissions(o) : [], c = i(s.slice(0, r.length)), l = s.slice(r.length), u = 0, d = 0;
2455
2449
  return t.map((e) => "ask" in e ? c[u++] : l[d++]);
2456
- } }, pi = "PermissionDeniedError", mi = (e) => e instanceof Error ? e.name === pi : yr(e) && e.name === "PermissionDeniedError";
2450
+ } }, fi = "PermissionDeniedError", pi = (e) => e instanceof Error ? e.name === fi : yr(e) && e.name === "PermissionDeniedError";
2457
2451
  //#endregion
2458
- export { Be as $, It as A, _t as B, zn as C, Rt as D, Mt as E, zt as F, rt as G, st as H, Pt as I, at as J, tt as K, vt as L, I as M, B as N, L as O, jt as P, qe as Q, bt as R, Bn as S, R as T, lt as U, gt as V, nt as W, Xe as X, k as Y, Je as Z, qn as _, ui as a, T as at, Hn as b, jr as c, Le as ct, yr as d, _e as dt, Ve as et, _r as f, ve as ft, Gn as g, pr as h, Jr as i, Oe as it, z as j, Nt as k, Er as l, De as lt, mr as m, S as mt, mi as n, Ue as nt, Kr as o, w as ot, fr as p, be as pt, ot as q, fi as r, D as rt, Pr as s, ke as st, pi as t, E as tt, Or as u, ye as ut, Vn as v, Nn as w, J as x, ar as y, yt as z };
2452
+ export { Be as $, It as A, _t as B, zn as C, Rt as D, Mt as E, zt as F, rt as G, st as H, Pt as I, at as J, tt as K, vt as L, I as M, B as N, L as O, jt as P, qe as Q, bt as R, Bn as S, R as T, lt as U, gt as V, nt as W, Xe as X, k as Y, Je as Z, qn as _, li as a, T as at, Hn as b, jr as c, Le as ct, yr as d, _e as dt, Ve as et, _r as f, ve as ft, Gn as g, pr as h, qr as i, Oe as it, z as j, Nt as k, Er as l, De as lt, mr as m, S as mt, pi as n, Ue as nt, Kr as o, w as ot, fr as p, be as pt, ot as q, di as r, D as rt, Pr as s, ke as st, fi as t, E as tt, Or as u, ye as ut, Vn as v, Nn as w, J as x, ar as y, yt as z };
package/links.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-DMnVye0K.cjs"),n=require("./contract.cjs"),r=require("./account-generation-9VhfEDoW.cjs"),i=require("./storage-DmRIhg1P.cjs");var a=e.t({LINK_EXPIRES_MS:()=>n.LINK_EXPIRES_MS,available:()=>_,create:()=>v,list:()=>x,open:()=>b,revoke:()=>S}),o={notALink:`links: the link is not one fkn.app made`,badExpiry:`links: the expiry is not one a link can carry`,notAFile:`links: the file is not a Blob or a ReadableStream`,badSize:`links: a stream needs the size it will deliver, a whole number of bytes`,badName:`links: the name or type is not one a link can carry`,tooLarge:`links: the file is too large for a link`,shortStream:`links: the stream did not deliver the size it declared`,badKey:`links: the key is not 32 bytes base64url`,keyTaken:`links: the key already names a link`,gone:`links: the link is no longer available`,integrity:`links: the file does not match its link`,needsAccount:`links: making a link needs an account`,notCreator:`links: only the app that made the link can revoke it`,quota:`links: storage quota exceeded`,tooMany:`links: too many links`,tooManyThisHour:`links: too many links made this hour, try again later`,rateLimited:`links: this link is opened too often, try again later`,accountChanged:`links: the signed-in account changed`,unavailable:`links: links are unavailable`},s=new Map([[o.notALink,`invalid`],[o.badExpiry,`invalid`],[o.notAFile,`invalid`],[o.badSize,`invalid`],[o.badName,`invalid`],[o.tooLarge,`invalid`],[o.shortStream,`invalid`],[o.badKey,`invalid`],[o.keyTaken,`invalid`],[o.gone,`not-found`],[o.integrity,`integrity`],[o.needsAccount,`denied`],[o.notCreator,`denied`],[o.quota,`quota`],[o.tooMany,`too-many`],[o.tooManyThisHour,`too-many`],[o.rateLimited,`rate-limited`],[o.accountChanged,`account-changed`],[o.unavailable,`unavailable`]]),c=new Set(s.values()),l=(e,t)=>Object.assign(Error(t),{code:e}),u=e=>e instanceof Error&&c.has(e.code),d=e=>{if(u(e))return e;let t=e instanceof Error?e.message:``,n=s.get(t);return n?l(n,t):l(`unavailable`,o.unavailable)},f=async()=>{if(!t.l)return;let e=(await t.s(`a link`).catch(()=>void 0))?.links;return typeof e?.create==`function`?e:void 0},p=()=>{throw l(`unavailable`,o.unavailable)},m=e=>typeof e==`object`&&!!e&&typeof e.error==`string`&&typeof e.message==`string`,h=(e,t,n)=>{throw e.error===`aborted`?t?.reason??new DOMException(`The operation was aborted.`,`AbortError`):(e.error===`account-changed`&&n&&r.r(n.generation),c.has(e.error)?l(e.error,e.message):l(`unavailable`,o.unavailable))},g=async e=>{try{return await i.p(e)}catch(e){throw i.c(e)?l(`account-changed`,o.accountChanged):e instanceof Error&&/not connected|not signed in/i.test(e.message)?l(`denied`,o.needsAccount):l(`unavailable`,o.unavailable)}},_=async()=>{let e=await f();return e?Promise.resolve(e.available()).catch(()=>!1):!1},v=async(e,t={})=>{let r=i.o(),a=Date.now(),{signal:s,onProgress:c,key:u}=t;s?.throwIfAborted();let d=typeof Blob<`u`&&e instanceof Blob,_=typeof ReadableStream<`u`&&e instanceof ReadableStream;if(!d&&!_)throw l(`invalid`,o.notAFile);let v=d?e.size:t.size;if(typeof v!=`number`||!Number.isSafeInteger(v)||v<0||d&&t.size!==void 0&&t.size!==v)throw l(`invalid`,o.badSize);let y=t.name??(typeof File<`u`&&e instanceof File?e.name:``),b=t.type??(d?e.type:``);if(typeof y!=`string`||typeof b!=`string`)throw l(`invalid`,o.badName);let x=typeof File<`u`&&e instanceof File?e.lastModified:a,S=t.expires,C;if(S!=null&&(typeof S!=`number`||!Number.isFinite(S)||(C=Math.round(S-a),C<n.LINK_EXPIRES_MS.min||C>n.LINK_EXPIRES_MS.max)))throw l(`invalid`,o.badExpiry);if(c!==void 0&&typeof c!=`function`)throw l(`invalid`,o.notAFile);let w=await f();if(!w)throw l(`unavailable`,o.unavailable);let T=await g(r);s?.throwIfAborted();let E=Promise.resolve(w.create(e,{name:y,type:b,lastModified:x,size:v,...C===void 0?{}:{expiresIn:C},...u===void 0?{}:{key:u},accountPin:T,...s?{signal:s}:{},...c?{onProgress:e=>{try{c(e)}catch{}}}:{}})).catch(p);E.catch(()=>{});let D=s?await Promise.race([E,new Promise((e,t)=>s.addEventListener(`abort`,()=>t(s.reason),{once:!0}))]):await E;return m(D)?h(D,s,r):D},y=(e,t,n)=>{let r=(t,n)=>{if(t===void 0)return n;let r=Math.trunc(Number.isFinite(t)?t:t>0?e:-e);return r<0?Math.max(e+r,0):Math.min(r,e)},i=r(t,0);return{from:i,to:Math.max(i,r(n,e))}},b=async(e,n={})=>{if(typeof e!=`string`)throw l(`invalid`,o.notALink);let{signal:r}=n;r?.throwIfAborted();let i=async()=>{let n=await f();if(!n)throw l(`unavailable`,o.unavailable);let i=t.c()?.epoch,a=await Promise.resolve(n.open(e,r?{signal:r}:void 0)).catch(p);return m(a)?h(a,r):{handle:a,epoch:i}},a=await i(),s=async()=>{let e=t.c()?.epoch;return a.epoch!==void 0&&e!==void 0&&e!==a.epoch&&(a=await i()),a.handle},{name:c,type:u,size:g,lastModified:_}=a.handle,v=(e,t)=>{let n;return new ReadableStream({pull:async r=>{try{if(!n){let r=await s(),i=await Promise.resolve(r.read(e,t)).catch(p);if(m(i))return h(i);n=i.getReader()}let{value:i,done:a}=await n.read();a?r.close():r.enqueue(i)}catch(e){throw d(e)}},cancel:e=>n?.cancel(e)},{highWaterMark:0})},b=(e,t)=>({name:c,type:u,size:t-e,lastModified:_,stream:()=>v(e,t),arrayBuffer:async()=>{let n=new Uint8Array(t-e),r=v(e,t).getReader(),i=0;for(;;){let{value:e,done:t}=await r.read();if(t)break;n.set(e,i),i+=e.length}return n.buffer},slice:(n,r)=>{let i=y(t-e,n,r);return b(e+i.from,e+i.to)}});return b(0,g)},x=async()=>{let e=i.o(),t=await f();if(!t)throw l(`unavailable`,o.unavailable);let n=await g(e),r=await Promise.resolve(t.list({accountPin:n})).catch(p);return m(r)?h(r,void 0,e):r.links},S=async e=>{let t=i.o();if(typeof e!=`string`||!e)throw l(`invalid`,o.notALink);let n=await f();if(!n)throw l(`unavailable`,o.unavailable);let r=await g(t),a=await Promise.resolve(n.revoke(e,{accountPin:r})).catch(p);m(a)&&h(a,void 0,t)};exports.LINK_EXPIRES_MS=n.LINK_EXPIRES_MS,exports.available=_,exports.create=v,exports.list=x,exports.open=b,exports.revoke=S,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return a}});
package/links.d.ts ADDED
@@ -0,0 +1,65 @@
1
+ import { A as Link, F as LinksErrorCode, L as ListedLink, P as LinkProgress, j as LinkCreateOptions, k as LINK_EXPIRES_MS } from "./contract-XlEPwc7b.js";
2
+ declare namespace links_d_exports {
3
+ export { LINK_EXPIRES_MS, Link, LinkCreateOptions, LinkProgress, LinkedFile, LinksError, LinksErrorCode, ListedLink, available, create, list, open, revoke };
4
+ }
5
+ /** Thrown by every member of this namespace except on an aborted signal. Match on `code`, never on the message. */
6
+ export type LinksError = Error & {
7
+ code: LinksErrorCode;
8
+ };
9
+ /**
10
+ * The file an opened link names, shaped like a `File`: the same four fields, `stream`, `arrayBuffer`
11
+ * and `slice`. Every read is by range and each 1 MiB record is checked before it is handed over, so a
12
+ * `slice` near the end of a large file fetches only that end.
13
+ */
14
+ export type LinkedFile = {
15
+ name: string;
16
+ type: string;
17
+ size: number;
18
+ lastModified: number;
19
+ /** errors with `integrity` on the first record that is not what the link sealed */
20
+ stream: () => ReadableStream<Uint8Array>;
21
+ arrayBuffer: () => Promise<ArrayBuffer>;
22
+ /** `Blob.slice`'s arguments, negative ones counted from the end, and the same shape back */
23
+ slice: (start?: number, end?: number) => LinkedFile;
24
+ };
25
+ /** Whether a link can be made here now. Opening needs no account and does not depend on this. Answers rather than rejecting. */
26
+ export declare const available: () => Promise<boolean>;
27
+ /**
28
+ * Seals a file in the broker and uploads it, then answers its link. Needs a signed-in account, and
29
+ * counts the sealed size (28 bytes more per 1 MiB) against the account's storage from the moment it
30
+ * starts until the link is revoked, expires or the upload is aborted. The account the call belongs to
31
+ * is the one this page is on when it is made, as for every storage call.
32
+ *
33
+ * `data` is a `Blob` (a `File` included) or a `ReadableStream<Uint8Array>` with its `size`. An upload
34
+ * survives the network dropping a part, not a reload: a reload starts the file again, and the upload
35
+ * left behind stops counting within the hour, or at once from `revoke` or the account's settings.
36
+ *
37
+ * Refused `invalid` for an expiry outside `LINK_EXPIRES_MS`, a stream without its size or one that
38
+ * delivers another, a file past the service's part ceiling, a `key` that is not 32 bytes base64url or
39
+ * one that already names a link; `denied` with no account; `quota`; `too-many` past the account's live
40
+ * links or this hour's creations; `account-changed`.
41
+ */
42
+ export declare const create: (data: Blob | ReadableStream<Uint8Array>, options?: LinkCreateOptions) => Promise<Link>;
43
+ /**
44
+ * Opens a link made by any app, with no account: the broker reads the key from the link and fetches
45
+ * the sealed file by range. Refused `invalid` for a link fkn.app did not make, `not-found` for one
46
+ * that is missing, revoked, expired, still uploading or turned off (one answer for all of them),
47
+ * `integrity` when the file does not match its link, `rate-limited` past the link's daily opens.
48
+ *
49
+ * Opening counts once per viewer per link per day; reading the same opened file again, by `slice` or
50
+ * a second `stream()`, counts nothing more. A broker replaced while the file is held is asked to open
51
+ * it again on the next read.
52
+ */
53
+ export declare const open: (url: string, options?: {
54
+ signal?: AbortSignal;
55
+ }) => Promise<LinkedFile>;
56
+ /** This app's links, newest first, uploads in progress included, as the service holds them: no name and no url. */
57
+ export declare const list: () => Promise<ListedLink[]>;
58
+ /**
59
+ * Revokes a link by its url or its id: every copy of the link stops opening, and an upload in
60
+ * progress is aborted and stops counting. Only the app that made the link (the same app once it is
61
+ * verified) revokes it, `denied` otherwise. A link already gone resolves.
62
+ */
63
+ export declare const revoke: (target: string) => Promise<void>;
64
+ //#endregion
65
+ export { LINK_EXPIRES_MS, type Link, type LinkCreateOptions, type LinkProgress, type LinksErrorCode, type ListedLink, links_d_exports as t };
package/links.js ADDED
@@ -0,0 +1,187 @@
1
+ import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
2
+ import { c as t, l as n, s as r } from "./api-ySazPAwN.js";
3
+ import { LINK_EXPIRES_MS as i } from "./contract.js";
4
+ import { r as a } from "./account-generation-hUekEHGW.js";
5
+ import { c as o, o as s, p as c } from "./storage-C6F9SnDM.js";
6
+ //#region src/links.ts
7
+ var l = /* @__PURE__ */ e({
8
+ LINK_EXPIRES_MS: () => i,
9
+ available: () => x,
10
+ create: () => S,
11
+ list: () => T,
12
+ open: () => w,
13
+ revoke: () => E
14
+ }), u = {
15
+ notALink: "links: the link is not one fkn.app made",
16
+ badExpiry: "links: the expiry is not one a link can carry",
17
+ notAFile: "links: the file is not a Blob or a ReadableStream",
18
+ badSize: "links: a stream needs the size it will deliver, a whole number of bytes",
19
+ badName: "links: the name or type is not one a link can carry",
20
+ tooLarge: "links: the file is too large for a link",
21
+ shortStream: "links: the stream did not deliver the size it declared",
22
+ badKey: "links: the key is not 32 bytes base64url",
23
+ keyTaken: "links: the key already names a link",
24
+ gone: "links: the link is no longer available",
25
+ integrity: "links: the file does not match its link",
26
+ needsAccount: "links: making a link needs an account",
27
+ notCreator: "links: only the app that made the link can revoke it",
28
+ quota: "links: storage quota exceeded",
29
+ tooMany: "links: too many links",
30
+ tooManyThisHour: "links: too many links made this hour, try again later",
31
+ rateLimited: "links: this link is opened too often, try again later",
32
+ accountChanged: "links: the signed-in account changed",
33
+ unavailable: "links: links are unavailable"
34
+ }, d = /* @__PURE__ */ new Map([
35
+ [u.notALink, "invalid"],
36
+ [u.badExpiry, "invalid"],
37
+ [u.notAFile, "invalid"],
38
+ [u.badSize, "invalid"],
39
+ [u.badName, "invalid"],
40
+ [u.tooLarge, "invalid"],
41
+ [u.shortStream, "invalid"],
42
+ [u.badKey, "invalid"],
43
+ [u.keyTaken, "invalid"],
44
+ [u.gone, "not-found"],
45
+ [u.integrity, "integrity"],
46
+ [u.needsAccount, "denied"],
47
+ [u.notCreator, "denied"],
48
+ [u.quota, "quota"],
49
+ [u.tooMany, "too-many"],
50
+ [u.tooManyThisHour, "too-many"],
51
+ [u.rateLimited, "rate-limited"],
52
+ [u.accountChanged, "account-changed"],
53
+ [u.unavailable, "unavailable"]
54
+ ]), f = new Set(d.values()), p = (e, t) => Object.assign(Error(t), { code: e }), m = (e) => e instanceof Error && f.has(e.code), h = (e) => {
55
+ if (m(e)) return e;
56
+ let t = e instanceof Error ? e.message : "", n = d.get(t);
57
+ return n ? p(n, t) : p("unavailable", u.unavailable);
58
+ }, g = async () => {
59
+ if (!n) return;
60
+ let e = (await r("a link").catch(() => void 0))?.links;
61
+ return typeof e?.create == "function" ? e : void 0;
62
+ }, _ = () => {
63
+ throw p("unavailable", u.unavailable);
64
+ }, v = (e) => typeof e == "object" && !!e && typeof e.error == "string" && typeof e.message == "string", y = (e, t, n) => {
65
+ throw e.error === "aborted" ? t?.reason ?? new DOMException("The operation was aborted.", "AbortError") : (e.error === "account-changed" && n && a(n.generation), f.has(e.error) ? p(e.error, e.message) : p("unavailable", u.unavailable));
66
+ }, b = async (e) => {
67
+ try {
68
+ return await c(e);
69
+ } catch (e) {
70
+ throw o(e) ? p("account-changed", u.accountChanged) : e instanceof Error && /not connected|not signed in/i.test(e.message) ? p("denied", u.needsAccount) : p("unavailable", u.unavailable);
71
+ }
72
+ }, x = async () => {
73
+ let e = await g();
74
+ return e ? Promise.resolve(e.available()).catch(() => !1) : !1;
75
+ }, S = async (e, t = {}) => {
76
+ let n = s(), r = Date.now(), { signal: a, onProgress: o, key: c } = t;
77
+ a?.throwIfAborted();
78
+ let l = typeof Blob < "u" && e instanceof Blob, d = typeof ReadableStream < "u" && e instanceof ReadableStream;
79
+ if (!l && !d) throw p("invalid", u.notAFile);
80
+ let f = l ? e.size : t.size;
81
+ if (typeof f != "number" || !Number.isSafeInteger(f) || f < 0 || l && t.size !== void 0 && t.size !== f) throw p("invalid", u.badSize);
82
+ let m = t.name ?? (typeof File < "u" && e instanceof File ? e.name : ""), h = t.type ?? (l ? e.type : "");
83
+ if (typeof m != "string" || typeof h != "string") throw p("invalid", u.badName);
84
+ let x = typeof File < "u" && e instanceof File ? e.lastModified : r, S = t.expires, C;
85
+ if (S != null && (typeof S != "number" || !Number.isFinite(S) || (C = Math.round(S - r), C < i.min || C > i.max))) throw p("invalid", u.badExpiry);
86
+ if (o !== void 0 && typeof o != "function") throw p("invalid", u.notAFile);
87
+ let w = await g();
88
+ if (!w) throw p("unavailable", u.unavailable);
89
+ let T = await b(n);
90
+ a?.throwIfAborted();
91
+ let E = Promise.resolve(w.create(e, {
92
+ name: m,
93
+ type: h,
94
+ lastModified: x,
95
+ size: f,
96
+ ...C === void 0 ? {} : { expiresIn: C },
97
+ ...c === void 0 ? {} : { key: c },
98
+ accountPin: T,
99
+ ...a ? { signal: a } : {},
100
+ ...o ? { onProgress: (e) => {
101
+ try {
102
+ o(e);
103
+ } catch {}
104
+ } } : {}
105
+ })).catch(_);
106
+ E.catch(() => {});
107
+ let D = a ? await Promise.race([E, new Promise((e, t) => a.addEventListener("abort", () => t(a.reason), { once: !0 }))]) : await E;
108
+ return v(D) ? y(D, a, n) : D;
109
+ }, C = (e, t, n) => {
110
+ let r = (t, n) => {
111
+ if (t === void 0) return n;
112
+ let r = Math.trunc(Number.isFinite(t) ? t : t > 0 ? e : -e);
113
+ return r < 0 ? Math.max(e + r, 0) : Math.min(r, e);
114
+ }, i = r(t, 0);
115
+ return {
116
+ from: i,
117
+ to: Math.max(i, r(n, e))
118
+ };
119
+ }, w = async (e, n = {}) => {
120
+ if (typeof e != "string") throw p("invalid", u.notALink);
121
+ let { signal: r } = n;
122
+ r?.throwIfAborted();
123
+ let i = async () => {
124
+ let n = await g();
125
+ if (!n) throw p("unavailable", u.unavailable);
126
+ let i = t()?.epoch, a = await Promise.resolve(n.open(e, r ? { signal: r } : void 0)).catch(_);
127
+ return v(a) ? y(a, r) : {
128
+ handle: a,
129
+ epoch: i
130
+ };
131
+ }, a = await i(), o = async () => {
132
+ let e = t()?.epoch;
133
+ return a.epoch !== void 0 && e !== void 0 && e !== a.epoch && (a = await i()), a.handle;
134
+ }, { name: s, type: c, size: l, lastModified: d } = a.handle, f = (e, t) => {
135
+ let n;
136
+ return new ReadableStream({
137
+ pull: async (r) => {
138
+ try {
139
+ if (!n) {
140
+ let r = await o(), i = await Promise.resolve(r.read(e, t)).catch(_);
141
+ if (v(i)) return y(i);
142
+ n = i.getReader();
143
+ }
144
+ let { value: i, done: a } = await n.read();
145
+ a ? r.close() : r.enqueue(i);
146
+ } catch (e) {
147
+ throw h(e);
148
+ }
149
+ },
150
+ cancel: (e) => n?.cancel(e)
151
+ }, { highWaterMark: 0 });
152
+ }, m = (e, t) => ({
153
+ name: s,
154
+ type: c,
155
+ size: t - e,
156
+ lastModified: d,
157
+ stream: () => f(e, t),
158
+ arrayBuffer: async () => {
159
+ let n = new Uint8Array(t - e), r = f(e, t).getReader(), i = 0;
160
+ for (;;) {
161
+ let { value: e, done: t } = await r.read();
162
+ if (t) break;
163
+ n.set(e, i), i += e.length;
164
+ }
165
+ return n.buffer;
166
+ },
167
+ slice: (n, r) => {
168
+ let i = C(t - e, n, r);
169
+ return m(e + i.from, e + i.to);
170
+ }
171
+ });
172
+ return m(0, l);
173
+ }, T = async () => {
174
+ let e = s(), t = await g();
175
+ if (!t) throw p("unavailable", u.unavailable);
176
+ let n = await b(e), r = await Promise.resolve(t.list({ accountPin: n })).catch(_);
177
+ return v(r) ? y(r, void 0, e) : r.links;
178
+ }, E = async (e) => {
179
+ let t = s();
180
+ if (typeof e != "string" || !e) throw p("invalid", u.notALink);
181
+ let n = await g();
182
+ if (!n) throw p("unavailable", u.unavailable);
183
+ let r = await b(t), i = await Promise.resolve(n.revoke(e, { accountPin: r })).catch(_);
184
+ v(i) && y(i, void 0, t);
185
+ };
186
+ //#endregion
187
+ export { i as LINK_EXPIRES_MS, x as available, S as create, T as list, w as open, E as revoke, l as t };
@@ -1,6 +1,6 @@
1
- import { Ct as TcpSocketListenerResult, K as Resolvers, Tt as TcpSocketResult } from "./contract-LOcbTDjP.js";
1
+ import { Mt as TcpSocketListenerResult, Pt as TcpSocketResult, tt as Resolvers } from "./contract-XlEPwc7b.js";
2
2
  import { o as TcpSocketOption } from "./wire-Fk5pJaoy.js";
3
- import "./api-DIBhBtcU.js";
3
+ import "./api-Cpi-qz1j.js";
4
4
  import { AddressInfo, ListenOptions, Server, ServerOpts, Socket, SocketConnectOpts, SocketConstructorOpts } from "net";
5
5
  import { DuplexOptions, Stream } from "stream";
6
6
  import { EventEmitter } from "events";
package/net.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as createConnection, c as isIP, i as connect, l as isIPv4, n as Socket, o as createServer, r as _default, t as Server, u as isIPv6 } from "./net-taIhsmvu.js";
1
+ import { a as createConnection, c as isIP, i as connect, l as isIPv4, n as Socket, o as createServer, r as _default, t as Server, u as isIPv6 } from "./net-C2Yz0job.js";
2
2
  export { Server, Socket, _default, _default as default, connect, createConnection, createServer, isIP, isIPv4, isIPv6 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fkn/lib",
3
- "version": "0.9.47",
3
+ "version": "0.9.48",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "type": "module",
@@ -115,6 +115,11 @@
115
115
  "import": "./rooms.js",
116
116
  "require": "./rooms.cjs"
117
117
  },
118
+ "./links": {
119
+ "types": "./links.d.ts",
120
+ "import": "./links.js",
121
+ "require": "./links.cjs"
122
+ },
118
123
  "./react": {
119
124
  "types": "./react.d.ts",
120
125
  "import": "./react.js",
package/packages.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { E as InstalledPackage, F as PackageResult, G as Radii, I as PackagesErrorCode, P as PackageQuery, R as PickOptions, T as InstallOptions, m as ConnectOptions, xt as SurfaceRect, z as Placement } from "./contract-LOcbTDjP.js";
1
+ import { At as SurfaceRect, E as InstalledPackage, G as PackagesErrorCode, J as Placement, T as InstallOptions, U as PackageQuery, W as PackageResult, et as Radii, m as ConnectOptions, q as PickOptions } from "./contract-XlEPwc7b.js";
2
2
  import { Remote } from "osra";
3
3
  declare namespace packages_d_exports {
4
4
  export { AppConnectOptions, Connect, ConnectOptions, ConnectPayload, IncomingConnection, IncomingConnectionInfo, InstallOptions, InstalledPackage, MountOptions, MountedPackage, PackageConnection, PackageQuery, PackageResult, PackageView, PackagesError, PackagesErrorCode, PickOptions, Placement, Radii, RawPackageConnection, ShowOptions, SurfaceRect, attach, connect, hide, install, isVisible, list, mount, onConnect, onVisibilityChange, pick, search, show, uninstall };
@@ -1,5 +1,5 @@
1
- import { K as Resolvers } from "./contract-LOcbTDjP.js";
2
- import "./api-DIBhBtcU.js";
1
+ import { tt as Resolvers } from "./contract-XlEPwc7b.js";
2
+ import "./api-Cpi-qz1j.js";
3
3
  //#region src/proxy.d.ts
4
4
  type ProxyFetch = Resolvers['cloud']['fetch'];
5
5
  type FetchParameters = Parameters<ProxyFetch>;
package/rooms.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { J as RoomClaimOptions, Q as RoomEvent, X as RoomDefaults, Y as RoomCreateOptions, Z as RoomEnd, at as RoomPermission, et as RoomJoinOptions, it as RoomOpenOptions, nt as RoomMember, ot as RoomPermissions, q as RoomBacklog, rt as RoomMessage, st as RoomsErrorCode, tt as RoomMailbox } from "./contract-LOcbTDjP.js";
1
+ import { at as RoomDefaults, dt as RoomMember, ft as RoomMessage, gt as RoomsErrorCode, ht as RoomPermissions, it as RoomCreateOptions, lt as RoomJoinOptions, mt as RoomPermission, nt as RoomBacklog, ot as RoomEnd, pt as RoomOpenOptions, rt as RoomClaimOptions, st as RoomEvent, ut as RoomMailbox } from "./contract-XlEPwc7b.js";
2
2
  declare namespace rooms_d_exports {
3
3
  export { RoomClaimOptions as ClaimOptions, RoomCreateOptions as CreateOptions, RoomJoinOptions as JoinOptions, RoomOpenOptions as OpenOptions, Room, RoomBacklog, RoomDefaults, RoomEnd, RoomEvent, RoomMailbox, RoomMember, RoomMessage, RoomPermission, RoomPermissions, RoomsError, RoomsErrorCode, available, create, join, open };
4
4
  }