@tinycloud/web-sdk 3.8.0-beta.3 → 3.8.0-beta.5

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.
@@ -288,6 +288,8 @@ export declare class TinyCloudWeb {
288
288
  get duckdb(): IDuckDbService;
289
289
  get hooks(): IHooksService;
290
290
  get encryption(): IEncryptionService;
291
+ /** Named keys bound to the signed-in session. */
292
+ get keys(): import("node-sdk/dist/encryption-keys").NamedKeyClient;
291
293
  get vault(): IDataVaultService;
292
294
  get secrets(): ISecretsService;
293
295
  secretsForSpace(spaceId: string): ISecretsService;
@@ -1 +1 @@
1
- (()=>{"use strict";var e={d:(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(){return new Promise(e=>{"requestIdleCallback"in globalThis?globalThis.requestIdleCallback(()=>e(),{timeout:3e3}):setTimeout(e,2e3)})}function o(e){return{state:"ready",data:e}}function n(e){return{state:"needs-permission",ability:e}}function a(e){return{state:"error",code:e}}e.r(t),e.d(t,{arm:()=>D,livePanelData:()=>S,onLivePanelDataChange:()=>A});const i=864e5;function s(e){const t=e.indexOf("#");return-1!==t&&-1===e.indexOf("#",t+1)?e.slice(0,t):e}function d(e,t){return"received"===e.direction?"received":(r=t,s(e.delegateDid)===s(r)?"this-app":"to-others");var r}function c(e,t){if(!e)return!1;const r=e.getTime()-t;return r>0&&r<=i}const l=5e3,u="SQL_ERROR",f={spaces:/^(?:SQL query failed: 400 - )?SQLite error: no such table:\s*spaces(?![\w$.\-])/i,applications:/^(?:SQL query failed: 400 - )?SQLite error: no such table:\s*applications(?![\w$.\-])/i};function g(e,t){return!0===e.ok?e.data.length:e.error.code===u&&f[t].test(e.error.message??"")?void 0:e.error.code}const v=6e4,p=6e4,y=1e4,h=50,k={account:["overview"],delegations:["delegations"],storage:["storage"]};const b=new WeakMap,w=new WeakMap;function m(e){for(const t of[...w.get(e)??[]])t()}function D(e,t={}){const i=b.get(e);if(i)return void(t.now&&i.prefetch.intent());const{host:s,gate:u}=t;if(!s||!u||!e.signedIn())return;const f=e.data??function(e,t,r){const i=new Set,s=new Map;let u=0;const f=new Set;t.onReset(()=>{for(const e of s.values())clearTimeout(e.retryTimer);u+=1,s.clear(),f.clear()});const b=e=>{let t=s.get(e);return t||(t={at:0,checkedAt:0,refreshing:!1},s.set(e,t)),t},w=e=>{for(const t of k[e])for(const e of i)e(t)};function m(e,t){const r=b(e);if(r.inflight)return r.inflight;const o=u,n=t().catch(()=>a("unavailable")).then(e=>{o===u&&("error"!==e.state||"ready"!==r.value?.state?(r.value=e,r.at=Date.now(),r.lastError=void 0,"ready"===e.state&&(r.retried=!1,clearTimeout(r.retryTimer),r.retryTimer=void 0)):r.lastError=e.code)}).finally(()=>{o===u&&(r.inflight=void 0,r.checkedAt=Date.now(),r.refreshing=!1,w(e),"account"!==e||"error"!==r.value?.state||r.retried||(r.retried=!0,r.retryTimer=setTimeout(()=>{r.retryTimer=void 0,o===u&&m(e,t)},l)))});return r.inflight=n,r.refreshing=!0,w(e),n}function D(e,t){return"ready"!==t.state?t:{...t,freshness:{updatedAt:e.at,refreshing:e.refreshing,lastError:e.lastError}}}async function S(e,t,r,o=!1){const n=b(e);if(void 0===n.value||o){const t=u;return await m(e,r),t!==u||void 0===n.value?{state:"loading"}:D(n,n.value)}return Date.now()-n.checkedAt>t&&m(e,r),D(n,n.value)}async function A(t){const r=u,i=await e.delegations.query({direction:"all",limit:h,...t?{cursor:t}:{}});if(r!==u)return a("stale");if(!1===i.ok)return"PERMISSION_DENIED"===i.error.code?n("delegation/list"):a(i.error.code);const s=Date.now();return i.data.nextCursor&&f.add(i.data.nextCursor),o({rows:i.data.items.map(t=>function(e,t,r){return{source:"real",cid:e.cid,direction:e.direction,status:e.status,group:d(e,t),label:{text:(o=e.delegateDid,o.length<=22?o:`${o.slice(0,14)}…${o.slice(-6)}`),source:"derived"},delegatorDid:e.delegatorDid,delegateDid:e.delegateDid,resources:e.resources.map(e=>({resource:e.resource,actions:e.actions})),parents:e.parents,issuedAt:e.issuedAt,notBefore:e.notBefore,expiresAt:e.expiresAt,expiringSoon:c(e.expiresAt,r),...void 0!==e.revokedAt?{revokedAt:e.revokedAt}:{},...void 0!==e.revokedBy?{revokedBy:e.revokedBy}:{},...void 0!==e.revokedAncestorCid?{revokedAncestorCid:e.revokedAncestorCid}:{}};var o}(t,e.sessionDid,s)),...i.data.nextCursor?{nextCursor:i.data.nextCursor}:{}})}async function T(){const[t,n,i]=await Promise.all([e.account.index.spaces.list(),e.account.index.applications.list(),S("delegations",y,()=>A())]),s=g(t,"spaces");if("string"==typeof s)return a(s);const d=g(n,"applications");if("string"==typeof d)return a(d);const c="ready"===i.state?i.data.rows:void 0,l=c?.filter(e=>"granted"===e.direction).length??0,u=c?.filter(e=>"received"===e.direction).length??0;return o({source:"real",fieldSources:{grantedDelegations:"derived",receivedDelegations:"derived"},did:e.did,host:e.hosts[0]??"",...void 0!==d?{applications:d}:{},...void 0!==s?{spaces:s}:{},grantedDelegations:l,receivedDelegations:u,appName:r})}async function O(){const t=await e.storage.status();return!1===t.ok?"PERMISSION_DENIED"===t.error.code||"AUTH_UNAUTHORIZED"===t.error.code?n("space/info"):a(t.error.code):o({source:"real",...t.data})}return{subscribe:e=>(i.add(e),()=>{i.delete(e)}),account:()=>S("account",v,T),knownDid:()=>0===u?e.did:void 0,async localNode(){const t=u,r=await e.activeNodeIdentity().catch(()=>{});return t!==u?{state:"loading"}:o({source:"real",fieldSources:{connection:"stub",version:"stub"},connection:"unavailable",...r?{identity:r}:{}})},setLocalNodeEnabled:async()=>({ok:!1,code:"unavailable"}),async localCopy(){const e=t.sync;if(!e)return a("unavailable");const{requested:r,effective:n,reason:i}=e.state;return o({source:"real",fieldSources:{lastSyncedAt:"stub",folders:"stub",pending:"stub",bytesOnDevice:"stub"},requested:r,effective:n,...void 0!==i?{reason:i}:{},folders:[],pending:0})},delegations:e=>e?f.has(e)?A(e):Promise.resolve(a("stale")):S("delegations",y,()=>A()),async revoke(t){const r=u,o=await e.delegations.status(t);if(r!==u)return{ok:!1,code:"stale"};if(o.ok&&"revoked"===o.data.status)return{ok:!1,code:"not-revocable"};const n=await e.delegations.revoke(t);if(r!==u)return{ok:!1,code:"stale"};if(!1===n.ok){if("NOT_FOUND"!==n.error.code)return{ok:!1,code:n.error.code};let e;if(b("account").at=0,await m("delegations",async()=>e=await A()),r!==u)return{ok:!1,code:"stale"};const o="ready"===e?.state?e.data:void 0,a=o?.rows.find(e=>e.cid===t);return{ok:!1,code:void 0!==o&&(void 0===a?void 0===o.nextCursor:"revoked"===a.status)?"NOT_FOUND":"REVOCATION_FAILED"}}return b("account").at=0,await m("delegations",()=>A()),r!==u?{ok:!1,code:"stale"}:{ok:!0,cid:t}},async nodes(){const t=u,r=await e.activeNodeIdentity().catch(()=>{});return t!==u?{state:"loading"}:o(e.hosts.map(e=>{const t=void 0!==r&&r.origin===e;return{source:"real",fieldSources:{kind:"stub",status:"stub",spaces:"stub"},origin:e,kind:"hosted",active:t,...t&&r?{nodeDid:r.nodeDid}:{},status:"ok",spaces:[]}}))},storage:e=>S("storage",p,O,!0===e?.fresh)}}(s,e,t.appName?.()??""),w=function(e){let t="waiting";const r=()=>{"waiting"===t&&(t="pulling",Promise.allSettled([e.data.account(),e.data.delegations(),e.data.storage()]).then(()=>{"pulling"===t&&(t="done")}))};Promise.all([e.idle(),e.registrySettled()]).then(r,r);const o=e.onReset(()=>{t="reset",o()});return{intent:r}}({data:f,registrySettled:()=>u.waitForAccountRegistrySync?.()??Promise.resolve(),idle:r,onReset:t=>e.onReset(t)});b.set(e,{source:f,prefetch:w}),e.onReset(()=>{b.delete(e),m(e)}),m(e)}function S(e){return b.get(e)?.source}function A(e,t){let r=w.get(e);return void 0===r&&(r=new Set,w.set(e,r)),r.add(t),()=>{r.delete(t)}}module.exports=t})();
1
+ (()=>{"use strict";var e={d:(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(){return new Promise(e=>{"requestIdleCallback"in globalThis?globalThis.requestIdleCallback(()=>e(),{timeout:3e3}):setTimeout(e,2e3)})}function o(e){return{state:"ready",data:e}}function n(e){return{state:"needs-permission",ability:e}}function a(e){return{state:"error",code:e}}e.r(t),e.d(t,{arm:()=>T,livePanelData:()=>O,onLivePanelDataChange:()=>E});const i={service:"tinycloud.sql",space:"account",path:"account",actions:["tinycloud.sql/read"]};function s(e,t){return void 0===e.hasPermissions||e.hasPermissions([t])}const c=864e5;function d(e){const t=e.indexOf("#");return-1!==t&&-1===e.indexOf("#",t+1)?e.slice(0,t):e}function u(e,t){return"received"===e.direction?"received":(r=t,d(e.delegateDid)===d(r)?"this-app":"to-others");var r}function l(e,t){if(!e)return!1;const r=e.getTime()-t;return r>0&&r<=c}const f=5e3,g="not-granted",v=new Set([g,"AUTH_UNAUTHORIZED","PERMISSION_DENIED"]),p="SQL_ERROR",y={spaces:/^(?:SQL query failed: 400 - )?SQLite error: no such table:\s*spaces(?![\w$.\-])/i,applications:/^(?:SQL query failed: 400 - )?SQLite error: no such table:\s*applications(?![\w$.\-])/i};function h(e,t){return!0===e.ok?e.data.length:e.error.code===p&&y[t].test(e.error.message??"")?void 0:e.error.code}const k=6e4,m=6e4,w=1e4,b=50,D={account:["overview"],delegations:["delegations"],storage:["storage"]};const S=new WeakMap,A=new WeakMap;function I(e){for(const t of[...A.get(e)??[]])t()}function T(e,t={}){const c=S.get(e);if(c)return void(t.now&&c.prefetch.intent());const{host:d,gate:p}=t;if(!d||!p||!e.signedIn())return;const y=e.data??function(e,t,r){const c=new Set,d=new Map;let p=0;const y=new Set;t.onReset(()=>{for(const e of d.values())clearTimeout(e.retryTimer);p+=1,d.clear(),y.clear()});const S=e=>{let t=d.get(e);return t||(t={at:0,checkedAt:0,refreshing:!1},d.set(e,t)),t},A=e=>{for(const t of D[e])for(const e of c)e(t)};function I(e,t){const r=S(e);if(r.inflight)return r.inflight;const o=p,n=t().catch(()=>a("unavailable")).then(e=>{o===p&&("error"!==e.state||"ready"!==r.value?.state?(r.value=e,r.at=Date.now(),r.lastError=void 0,"ready"===e.state&&(r.retried=!1,clearTimeout(r.retryTimer),r.retryTimer=void 0)):r.lastError=e.code)}).finally(()=>{o===p&&(r.inflight=void 0,r.checkedAt=Date.now(),r.refreshing=!1,A(e),"account"!==e||"error"!==r.value?.state||v.has(r.value.code)||r.retried||(r.retried=!0,r.retryTimer=setTimeout(()=>{r.retryTimer=void 0,o===p&&I(e,t)},f)))});return r.inflight=n,r.refreshing=!0,A(e),n}function T(e,t){return"ready"!==t.state?t:{...t,freshness:{updatedAt:e.at,refreshing:e.refreshing,lastError:e.lastError}}}async function O(e,t,r,o=!1){const n=S(e);if(void 0===n.value||o){const t=p;return await I(e,r),t!==p||void 0===n.value?{state:"loading"}:T(n,n.value)}return Date.now()-n.checkedAt>t&&I(e,r),T(n,n.value)}async function E(t){const r=p,i=function(e){if(void 0===e.hasPermissions)return;const t=[];for(const r of[e.accountSpaceId,e.spaceId])void 0===r||t.includes(r)||s(e,{service:"tinycloud.delegation",space:r,path:"",actions:["tinycloud.delegation/list"]})&&t.push(r);return t}(e);if(0===i?.length)return n("delegation/list");const c={direction:"all",limit:b,...t?{cursor:t}:{}},d=await(void 0===i?e.delegations.query(c):e.delegations.query(c,{spaces:i}));if(r!==p)return a("stale");if(!1===d.ok)return"PERMISSION_DENIED"===d.error.code?n("delegation/list"):a(d.error.code);const f=Date.now();return d.data.nextCursor&&y.add(d.data.nextCursor),o({rows:d.data.items.map(t=>function(e,t,r){return{source:"real",cid:e.cid,direction:e.direction,status:e.status,group:u(e,t),label:{text:(o=e.delegateDid,o.length<=22?o:`${o.slice(0,14)}…${o.slice(-6)}`),source:"derived"},delegatorDid:e.delegatorDid,delegateDid:e.delegateDid,resources:e.resources.map(e=>({resource:e.resource,actions:e.actions})),parents:e.parents,issuedAt:e.issuedAt,notBefore:e.notBefore,expiresAt:e.expiresAt,expiringSoon:l(e.expiresAt,r),...void 0!==e.revokedAt?{revokedAt:e.revokedAt}:{},...void 0!==e.revokedBy?{revokedBy:e.revokedBy}:{},...void 0!==e.revokedAncestorCid?{revokedAncestorCid:e.revokedAncestorCid}:{}};var o}(t,e.sessionDid,f)),...d.data.nextCursor?{nextCursor:d.data.nextCursor}:{}})}async function N(){if(!s(e,i))return a(g);const[t,n,c]=await Promise.all([e.account.index.spaces.list(),e.account.index.applications.list(),O("delegations",w,()=>E())]),d=h(t,"spaces");if("string"==typeof d)return a(d);const u=h(n,"applications");if("string"==typeof u)return a(u);const l="ready"===c.state?c.data.rows:void 0,f=l?.filter(e=>"granted"===e.direction).length??0,v=l?.filter(e=>"received"===e.direction).length??0;return o({source:"real",fieldSources:{grantedDelegations:"derived",receivedDelegations:"derived"},did:e.did,host:e.hosts[0]??"",...void 0!==u?{applications:u}:{},...void 0!==d?{spaces:d}:{},grantedDelegations:f,receivedDelegations:v,appName:r})}async function P(){if(void 0!==e.spaceId&&!s(e,(t=e.spaceId,{service:"tinycloud.space",space:t,path:"",actions:["tinycloud.space/info"]})))return n("space/info");var t;const r=await e.storage.status();return!1===r.ok?"PERMISSION_DENIED"===r.error.code||"AUTH_UNAUTHORIZED"===r.error.code?n("space/info"):a(r.error.code):o({source:"real",...r.data})}return{subscribe:e=>(c.add(e),()=>{c.delete(e)}),account:()=>O("account",k,N),knownDid:()=>0===p?e.did:void 0,async localNode(){const t=p,r=await e.activeNodeIdentity().catch(()=>{});return t!==p?{state:"loading"}:o({source:"real",fieldSources:{connection:"stub",version:"stub"},connection:"unavailable",...r?{identity:r}:{}})},setLocalNodeEnabled:async()=>({ok:!1,code:"unavailable"}),async localCopy(){const e=t.sync;if(!e)return a("unavailable");const{requested:r,effective:n,reason:i}=e.state;return o({source:"real",fieldSources:{lastSyncedAt:"stub",folders:"stub",pending:"stub",bytesOnDevice:"stub"},requested:r,effective:n,...void 0!==i?{reason:i}:{},folders:[],pending:0})},delegations:e=>e?y.has(e)?E(e):Promise.resolve(a("stale")):O("delegations",w,()=>E()),async revoke(t){const r=p,o=await e.delegations.status(t);if(r!==p)return{ok:!1,code:"stale"};if(o.ok&&"revoked"===o.data.status)return{ok:!1,code:"not-revocable"};const n=await e.delegations.revoke(t);if(r!==p)return{ok:!1,code:"stale"};if(!1===n.ok){if("NOT_FOUND"!==n.error.code)return{ok:!1,code:n.error.code};let e;if(S("account").at=0,await I("delegations",async()=>e=await E()),r!==p)return{ok:!1,code:"stale"};const o="ready"===e?.state?e.data:void 0,a=o?.rows.find(e=>e.cid===t);return{ok:!1,code:void 0!==o&&(void 0===a?void 0===o.nextCursor:"revoked"===a.status)?"NOT_FOUND":"REVOCATION_FAILED"}}return S("account").at=0,await I("delegations",()=>E()),r!==p?{ok:!1,code:"stale"}:{ok:!0,cid:t}},async nodes(){const t=p,r=await e.activeNodeIdentity().catch(()=>{});return t!==p?{state:"loading"}:o(e.hosts.map(e=>{const t=void 0!==r&&r.origin===e;return{source:"real",fieldSources:{kind:"stub",status:"stub",spaces:"stub"},origin:e,kind:"hosted",active:t,...t&&r?{nodeDid:r.nodeDid}:{},status:"ok",spaces:[]}}))},storage:e=>O("storage",m,P,!0===e?.fresh)}}(d,e,t.appName?.()??""),A=function(e){let t="waiting";const r=()=>{"waiting"===t&&(t="pulling",Promise.allSettled([e.data.account(),e.data.delegations(),e.data.storage()]).then(()=>{"pulling"===t&&(t="done")}))};Promise.all([e.idle(),e.registrySettled()]).then(r,r);const o=e.onReset(()=>{t="reset",o()});return{intent:r}}({data:y,registrySettled:()=>p.waitForAccountRegistrySync?.()??Promise.resolve(),idle:r,onReset:t=>e.onReset(t)});S.set(e,{source:y,prefetch:A}),e.onReset(()=>{S.delete(e),I(e)}),I(e)}function O(e){return S.get(e)?.source}function E(e,t){let r=A.get(e);return void 0===r&&(r=new Set,A.set(e,r)),r.add(t),()=>{r.delete(t)}}module.exports=t})();
@@ -1 +1 @@
1
- var e={};function t(){return new Promise(e=>{"requestIdleCallback"in globalThis?globalThis.requestIdleCallback(()=>e(),{timeout:3e3}):setTimeout(e,2e3)})}function r(e){return{state:"ready",data:e}}function o(e){return{state:"needs-permission",ability:e}}function n(e){return{state:"error",code:e}}function a(e){const t=e.indexOf("#");return-1!==t&&-1===e.indexOf("#",t+1)?e.slice(0,t):e}function i(e,t){return"received"===e.direction?"received":(r=t,a(e.delegateDid)===a(r)?"this-app":"to-others");var r}function s(e,t){if(!e)return!1;const r=e.getTime()-t;return r>0&&r<=864e5}e.d=(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const c={spaces:/^(?:SQL query failed: 400 - )?SQLite error: no such table:\s*spaces(?![\w$.\-])/i,applications:/^(?:SQL query failed: 400 - )?SQLite error: no such table:\s*applications(?![\w$.\-])/i};function d(e,t){return!0===e.ok?e.data.length:"SQL_ERROR"===e.error.code&&c[t].test(e.error.message??"")?void 0:e.error.code}const u={account:["overview"],delegations:["delegations"],storage:["storage"]};const l=new WeakMap,f=new WeakMap;function g(e){for(const t of[...f.get(e)??[]])t()}function v(e,a={}){const c=l.get(e);if(c)return void(a.now&&c.prefetch.intent());const{host:f,gate:v}=a;if(!f||!v||!e.signedIn())return;const p=e.data??function(e,t,a){const c=new Set,l=new Map;let f=0;const g=new Set;t.onReset(()=>{for(const e of l.values())clearTimeout(e.retryTimer);f+=1,l.clear(),g.clear()});const v=e=>{let t=l.get(e);return t||(t={at:0,checkedAt:0,refreshing:!1},l.set(e,t)),t},p=e=>{for(const t of u[e])for(const e of c)e(t)};function y(e,t){const r=v(e);if(r.inflight)return r.inflight;const o=f,a=t().catch(()=>n("unavailable")).then(e=>{o===f&&("error"!==e.state||"ready"!==r.value?.state?(r.value=e,r.at=Date.now(),r.lastError=void 0,"ready"===e.state&&(r.retried=!1,clearTimeout(r.retryTimer),r.retryTimer=void 0)):r.lastError=e.code)}).finally(()=>{o===f&&(r.inflight=void 0,r.checkedAt=Date.now(),r.refreshing=!1,p(e),"account"!==e||"error"!==r.value?.state||r.retried||(r.retried=!0,r.retryTimer=setTimeout(()=>{r.retryTimer=void 0,o===f&&y(e,t)},5e3)))});return r.inflight=a,r.refreshing=!0,p(e),a}function h(e,t){return"ready"!==t.state?t:{...t,freshness:{updatedAt:e.at,refreshing:e.refreshing,lastError:e.lastError}}}async function k(e,t,r,o=!1){const n=v(e);if(void 0===n.value||o){const t=f;return await y(e,r),t!==f||void 0===n.value?{state:"loading"}:h(n,n.value)}return Date.now()-n.checkedAt>t&&y(e,r),h(n,n.value)}async function w(t){const a=f,c=await e.delegations.query({direction:"all",limit:50,...t?{cursor:t}:{}});if(a!==f)return n("stale");if(!1===c.ok)return"PERMISSION_DENIED"===c.error.code?o("delegation/list"):n(c.error.code);const d=Date.now();return c.data.nextCursor&&g.add(c.data.nextCursor),r({rows:c.data.items.map(t=>function(e,t,r){return{source:"real",cid:e.cid,direction:e.direction,status:e.status,group:i(e,t),label:{text:(o=e.delegateDid,o.length<=22?o:`${o.slice(0,14)}…${o.slice(-6)}`),source:"derived"},delegatorDid:e.delegatorDid,delegateDid:e.delegateDid,resources:e.resources.map(e=>({resource:e.resource,actions:e.actions})),parents:e.parents,issuedAt:e.issuedAt,notBefore:e.notBefore,expiresAt:e.expiresAt,expiringSoon:s(e.expiresAt,r),...void 0!==e.revokedAt?{revokedAt:e.revokedAt}:{},...void 0!==e.revokedBy?{revokedBy:e.revokedBy}:{},...void 0!==e.revokedAncestorCid?{revokedAncestorCid:e.revokedAncestorCid}:{}};var o}(t,e.sessionDid,d)),...c.data.nextCursor?{nextCursor:c.data.nextCursor}:{}})}async function b(){const[t,o,i]=await Promise.all([e.account.index.spaces.list(),e.account.index.applications.list(),k("delegations",1e4,()=>w())]),s=d(t,"spaces");if("string"==typeof s)return n(s);const c=d(o,"applications");if("string"==typeof c)return n(c);const u="ready"===i.state?i.data.rows:void 0,l=u?.filter(e=>"granted"===e.direction).length??0,f=u?.filter(e=>"received"===e.direction).length??0;return r({source:"real",fieldSources:{grantedDelegations:"derived",receivedDelegations:"derived"},did:e.did,host:e.hosts[0]??"",...void 0!==c?{applications:c}:{},...void 0!==s?{spaces:s}:{},grantedDelegations:l,receivedDelegations:f,appName:a})}async function m(){const t=await e.storage.status();return!1===t.ok?"PERMISSION_DENIED"===t.error.code||"AUTH_UNAUTHORIZED"===t.error.code?o("space/info"):n(t.error.code):r({source:"real",...t.data})}return{subscribe:e=>(c.add(e),()=>{c.delete(e)}),account:()=>k("account",6e4,b),knownDid:()=>0===f?e.did:void 0,async localNode(){const t=f,o=await e.activeNodeIdentity().catch(()=>{});return t!==f?{state:"loading"}:r({source:"real",fieldSources:{connection:"stub",version:"stub"},connection:"unavailable",...o?{identity:o}:{}})},setLocalNodeEnabled:async()=>({ok:!1,code:"unavailable"}),async localCopy(){const e=t.sync;if(!e)return n("unavailable");const{requested:o,effective:a,reason:i}=e.state;return r({source:"real",fieldSources:{lastSyncedAt:"stub",folders:"stub",pending:"stub",bytesOnDevice:"stub"},requested:o,effective:a,...void 0!==i?{reason:i}:{},folders:[],pending:0})},delegations:e=>e?g.has(e)?w(e):Promise.resolve(n("stale")):k("delegations",1e4,()=>w()),async revoke(t){const r=f,o=await e.delegations.status(t);if(r!==f)return{ok:!1,code:"stale"};if(o.ok&&"revoked"===o.data.status)return{ok:!1,code:"not-revocable"};const n=await e.delegations.revoke(t);if(r!==f)return{ok:!1,code:"stale"};if(!1===n.ok){if("NOT_FOUND"!==n.error.code)return{ok:!1,code:n.error.code};let e;if(v("account").at=0,await y("delegations",async()=>e=await w()),r!==f)return{ok:!1,code:"stale"};const o="ready"===e?.state?e.data:void 0,a=o?.rows.find(e=>e.cid===t);return{ok:!1,code:void 0!==o&&(void 0===a?void 0===o.nextCursor:"revoked"===a.status)?"NOT_FOUND":"REVOCATION_FAILED"}}return v("account").at=0,await y("delegations",()=>w()),r!==f?{ok:!1,code:"stale"}:{ok:!0,cid:t}},async nodes(){const t=f,o=await e.activeNodeIdentity().catch(()=>{});return t!==f?{state:"loading"}:r(e.hosts.map(e=>{const t=void 0!==o&&o.origin===e;return{source:"real",fieldSources:{kind:"stub",status:"stub",spaces:"stub"},origin:e,kind:"hosted",active:t,...t&&o?{nodeDid:o.nodeDid}:{},status:"ok",spaces:[]}}))},storage:e=>k("storage",6e4,m,!0===e?.fresh)}}(f,e,a.appName?.()??""),y=function(e){let t="waiting";const r=()=>{"waiting"===t&&(t="pulling",Promise.allSettled([e.data.account(),e.data.delegations(),e.data.storage()]).then(()=>{"pulling"===t&&(t="done")}))};Promise.all([e.idle(),e.registrySettled()]).then(r,r);const o=e.onReset(()=>{t="reset",o()});return{intent:r}}({data:p,registrySettled:()=>v.waitForAccountRegistrySync?.()??Promise.resolve(),idle:t,onReset:t=>e.onReset(t)});l.set(e,{source:p,prefetch:y}),e.onReset(()=>{l.delete(e),g(e)}),g(e)}function p(e){return l.get(e)?.source}function y(e,t){let r=f.get(e);return void 0===r&&(r=new Set,f.set(e,r)),r.add(t),()=>{r.delete(t)}}export{v as arm,p as livePanelData,y as onLivePanelDataChange};
1
+ var e={};function t(){return new Promise(e=>{"requestIdleCallback"in globalThis?globalThis.requestIdleCallback(()=>e(),{timeout:3e3}):setTimeout(e,2e3)})}function r(e){return{state:"ready",data:e}}function o(e){return{state:"needs-permission",ability:e}}function n(e){return{state:"error",code:e}}e.d=(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const s={service:"tinycloud.sql",space:"account",path:"account",actions:["tinycloud.sql/read"]};function i(e,t){return void 0===e.hasPermissions||e.hasPermissions([t])}function a(e){const t=e.indexOf("#");return-1!==t&&-1===e.indexOf("#",t+1)?e.slice(0,t):e}function c(e,t){return"received"===e.direction?"received":(r=t,a(e.delegateDid)===a(r)?"this-app":"to-others");var r}function d(e,t){if(!e)return!1;const r=e.getTime()-t;return r>0&&r<=864e5}const u="not-granted",l=new Set([u,"AUTH_UNAUTHORIZED","PERMISSION_DENIED"]),f={spaces:/^(?:SQL query failed: 400 - )?SQLite error: no such table:\s*spaces(?![\w$.\-])/i,applications:/^(?:SQL query failed: 400 - )?SQLite error: no such table:\s*applications(?![\w$.\-])/i};function v(e,t){return!0===e.ok?e.data.length:"SQL_ERROR"===e.error.code&&f[t].test(e.error.message??"")?void 0:e.error.code}const g={account:["overview"],delegations:["delegations"],storage:["storage"]};const p=new WeakMap,y=new WeakMap;function h(e){for(const t of[...y.get(e)??[]])t()}function k(e,a={}){const f=p.get(e);if(f)return void(a.now&&f.prefetch.intent());const{host:y,gate:k}=a;if(!y||!k||!e.signedIn())return;const w=e.data??function(e,t,a){const f=new Set,p=new Map;let y=0;const h=new Set;t.onReset(()=>{for(const e of p.values())clearTimeout(e.retryTimer);y+=1,p.clear(),h.clear()});const k=e=>{let t=p.get(e);return t||(t={at:0,checkedAt:0,refreshing:!1},p.set(e,t)),t},w=e=>{for(const t of g[e])for(const e of f)e(t)};function m(e,t){const r=k(e);if(r.inflight)return r.inflight;const o=y,s=t().catch(()=>n("unavailable")).then(e=>{o===y&&("error"!==e.state||"ready"!==r.value?.state?(r.value=e,r.at=Date.now(),r.lastError=void 0,"ready"===e.state&&(r.retried=!1,clearTimeout(r.retryTimer),r.retryTimer=void 0)):r.lastError=e.code)}).finally(()=>{o===y&&(r.inflight=void 0,r.checkedAt=Date.now(),r.refreshing=!1,w(e),"account"!==e||"error"!==r.value?.state||l.has(r.value.code)||r.retried||(r.retried=!0,r.retryTimer=setTimeout(()=>{r.retryTimer=void 0,o===y&&m(e,t)},5e3)))});return r.inflight=s,r.refreshing=!0,w(e),s}function D(e,t){return"ready"!==t.state?t:{...t,freshness:{updatedAt:e.at,refreshing:e.refreshing,lastError:e.lastError}}}async function b(e,t,r,o=!1){const n=k(e);if(void 0===n.value||o){const t=y;return await m(e,r),t!==y||void 0===n.value?{state:"loading"}:D(n,n.value)}return Date.now()-n.checkedAt>t&&m(e,r),D(n,n.value)}async function S(t){const s=y,a=function(e){if(void 0===e.hasPermissions)return;const t=[];for(const r of[e.accountSpaceId,e.spaceId])void 0===r||t.includes(r)||i(e,{service:"tinycloud.delegation",space:r,path:"",actions:["tinycloud.delegation/list"]})&&t.push(r);return t}(e);if(0===a?.length)return o("delegation/list");const u={direction:"all",limit:50,...t?{cursor:t}:{}},l=await(void 0===a?e.delegations.query(u):e.delegations.query(u,{spaces:a}));if(s!==y)return n("stale");if(!1===l.ok)return"PERMISSION_DENIED"===l.error.code?o("delegation/list"):n(l.error.code);const f=Date.now();return l.data.nextCursor&&h.add(l.data.nextCursor),r({rows:l.data.items.map(t=>function(e,t,r){return{source:"real",cid:e.cid,direction:e.direction,status:e.status,group:c(e,t),label:{text:(o=e.delegateDid,o.length<=22?o:`${o.slice(0,14)}…${o.slice(-6)}`),source:"derived"},delegatorDid:e.delegatorDid,delegateDid:e.delegateDid,resources:e.resources.map(e=>({resource:e.resource,actions:e.actions})),parents:e.parents,issuedAt:e.issuedAt,notBefore:e.notBefore,expiresAt:e.expiresAt,expiringSoon:d(e.expiresAt,r),...void 0!==e.revokedAt?{revokedAt:e.revokedAt}:{},...void 0!==e.revokedBy?{revokedBy:e.revokedBy}:{},...void 0!==e.revokedAncestorCid?{revokedAncestorCid:e.revokedAncestorCid}:{}};var o}(t,e.sessionDid,f)),...l.data.nextCursor?{nextCursor:l.data.nextCursor}:{}})}async function A(){if(!i(e,s))return n(u);const[t,o,c]=await Promise.all([e.account.index.spaces.list(),e.account.index.applications.list(),b("delegations",1e4,()=>S())]),d=v(t,"spaces");if("string"==typeof d)return n(d);const l=v(o,"applications");if("string"==typeof l)return n(l);const f="ready"===c.state?c.data.rows:void 0,g=f?.filter(e=>"granted"===e.direction).length??0,p=f?.filter(e=>"received"===e.direction).length??0;return r({source:"real",fieldSources:{grantedDelegations:"derived",receivedDelegations:"derived"},did:e.did,host:e.hosts[0]??"",...void 0!==l?{applications:l}:{},...void 0!==d?{spaces:d}:{},grantedDelegations:g,receivedDelegations:p,appName:a})}async function I(){if(void 0!==e.spaceId&&!i(e,(t=e.spaceId,{service:"tinycloud.space",space:t,path:"",actions:["tinycloud.space/info"]})))return o("space/info");var t;const s=await e.storage.status();return!1===s.ok?"PERMISSION_DENIED"===s.error.code||"AUTH_UNAUTHORIZED"===s.error.code?o("space/info"):n(s.error.code):r({source:"real",...s.data})}return{subscribe:e=>(f.add(e),()=>{f.delete(e)}),account:()=>b("account",6e4,A),knownDid:()=>0===y?e.did:void 0,async localNode(){const t=y,o=await e.activeNodeIdentity().catch(()=>{});return t!==y?{state:"loading"}:r({source:"real",fieldSources:{connection:"stub",version:"stub"},connection:"unavailable",...o?{identity:o}:{}})},setLocalNodeEnabled:async()=>({ok:!1,code:"unavailable"}),async localCopy(){const e=t.sync;if(!e)return n("unavailable");const{requested:o,effective:s,reason:i}=e.state;return r({source:"real",fieldSources:{lastSyncedAt:"stub",folders:"stub",pending:"stub",bytesOnDevice:"stub"},requested:o,effective:s,...void 0!==i?{reason:i}:{},folders:[],pending:0})},delegations:e=>e?h.has(e)?S(e):Promise.resolve(n("stale")):b("delegations",1e4,()=>S()),async revoke(t){const r=y,o=await e.delegations.status(t);if(r!==y)return{ok:!1,code:"stale"};if(o.ok&&"revoked"===o.data.status)return{ok:!1,code:"not-revocable"};const n=await e.delegations.revoke(t);if(r!==y)return{ok:!1,code:"stale"};if(!1===n.ok){if("NOT_FOUND"!==n.error.code)return{ok:!1,code:n.error.code};let e;if(k("account").at=0,await m("delegations",async()=>e=await S()),r!==y)return{ok:!1,code:"stale"};const o="ready"===e?.state?e.data:void 0,s=o?.rows.find(e=>e.cid===t);return{ok:!1,code:void 0!==o&&(void 0===s?void 0===o.nextCursor:"revoked"===s.status)?"NOT_FOUND":"REVOCATION_FAILED"}}return k("account").at=0,await m("delegations",()=>S()),r!==y?{ok:!1,code:"stale"}:{ok:!0,cid:t}},async nodes(){const t=y,o=await e.activeNodeIdentity().catch(()=>{});return t!==y?{state:"loading"}:r(e.hosts.map(e=>{const t=void 0!==o&&o.origin===e;return{source:"real",fieldSources:{kind:"stub",status:"stub",spaces:"stub"},origin:e,kind:"hosted",active:t,...t&&o?{nodeDid:o.nodeDid}:{},status:"ok",spaces:[]}}))},storage:e=>b("storage",6e4,I,!0===e?.fresh)}}(y,e,a.appName?.()??""),m=function(e){let t="waiting";const r=()=>{"waiting"===t&&(t="pulling",Promise.allSettled([e.data.account(),e.data.delegations(),e.data.storage()]).then(()=>{"pulling"===t&&(t="done")}))};Promise.all([e.idle(),e.registrySettled()]).then(r,r);const o=e.onReset(()=>{t="reset",o()});return{intent:r}}({data:w,registrySettled:()=>k.waitForAccountRegistrySync?.()??Promise.resolve(),idle:t,onReset:t=>e.onReset(t)});p.set(e,{source:w,prefetch:m}),e.onReset(()=>{p.delete(e),h(e)}),h(e)}function w(e){return p.get(e)?.source}function m(e,t){let r=y.get(e);return void 0===r&&(r=new Set,y.set(e,r)),r.add(t),()=>{r.delete(t)}}export{k as arm,w as livePanelData,m as onLivePanelDataChange};
@@ -0,0 +1,18 @@
1
+ import type { PermissionEntry } from "@tinycloud/sdk-core";
2
+ import type { PanelDataHost } from "../data";
3
+ /** The account index read: `tinycloud.sql/read` on the `account` database of the account space. */
4
+ export declare const ACCOUNT_INDEX_READ: PermissionEntry;
5
+ /** `tinycloud.space/info` on one space, given by its full space id: the storage status read. */
6
+ export declare function spaceInfoOn(spaceId: string): PermissionEntry;
7
+ /**
8
+ * True when the session holds `entry`. A host that cannot tell (`hasPermissions` absent) answers true,
9
+ * so its reads are sent as before.
10
+ */
11
+ export declare function sessionHolds(host: Pick<PanelDataHost, "hasPermissions">, entry: PermissionEntry): boolean;
12
+ /**
13
+ * The spaces to sign the delegation query for, in the order the SDK tries them (account space, then the
14
+ * session's own space), limited to those the session holds `delegation/list` on. Empty: nothing to send.
15
+ * `undefined`: the host cannot tell, so the SDK picks its own spaces.
16
+ */
17
+ export declare function delegationQuerySpaces(host: Pick<PanelDataHost, "hasPermissions" | "accountSpaceId" | "spaceId">): readonly string[] | undefined;
18
+ //# sourceMappingURL=authority.d.ts.map
package/dist/ui/data.d.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  * Panel code reads these shapes through a `PanelDataSource`. It never reads
14
14
  * TinyCloudWeb directly.
15
15
  */
16
- import type { AccountDelegationRecord, AccountService, AccountStatus, DelegationManager, IStorageService, StorageStatus, StorageUsage } from "@tinycloud/sdk-core";
16
+ import type { AccountDelegationRecord, AccountService, AccountStatus, DelegationManager, IStorageService, PermissionEntry, StorageStatus, StorageUsage } from "@tinycloud/sdk-core";
17
17
  import type { PanelClient, SyncState } from "./slots";
18
18
  export type DataSource = "real" | "stub" | "derived";
19
19
  /** Per-field source for records that mix real and stub fields. */
@@ -213,6 +213,15 @@ export interface PanelDataHost {
213
213
  readonly origin: string;
214
214
  readonly nodeDid: string;
215
215
  }>;
216
+ /**
217
+ * Whether the session or an unexpired runtime grant covers every entry (`tc.hasPermissions`). Never prompts.
218
+ * Absent on a host that cannot tell: panel reads then go out as they always did.
219
+ */
220
+ hasPermissions?(entries: PermissionEntry[]): boolean;
221
+ /** Account space id (`tc.accountSpaceId`). The delegation query signs for it first. */
222
+ readonly accountSpaceId?: string;
223
+ /** The session's own space id (`tc.spaceId`). The delegation query falls back to it. */
224
+ readonly spaceId?: string;
216
225
  }
217
226
  export interface PanelDataSource {
218
227
  /** Fires when any view's data changes (toggle, revoke, stub change). Returns unsubscribe. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinycloud/web-sdk",
3
- "version": "3.8.0-beta.3",
3
+ "version": "3.8.0-beta.5",
4
4
  "description": "A set of tools and utilities to help you build your app with TinyCloud.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -66,9 +66,9 @@
66
66
  "@multiformats/multiaddr": "^13.0.1",
67
67
  "@multiformats/multiaddr-to-uri": "^12.0.0",
68
68
  "@noble/curves": "^1.9.7",
69
- "@tinycloud/node-sdk": "3.8.0-beta.3",
69
+ "@tinycloud/node-sdk": "3.8.0-beta.5",
70
70
  "@tinycloud/replica": "0.4.0-beta.1",
71
- "@tinycloud/sdk-core": "3.8.0-beta.3",
71
+ "@tinycloud/sdk-core": "3.8.0-beta.5",
72
72
  "@tinycloud/share-envelope": "1.3.1-beta.0",
73
73
  "@tinycloud/share-sdk": "1.4.1-beta.0",
74
74
  "@tinycloud/web-sdk-wasm": "1.7.7",