@tinycloud/web-sdk 3.8.0-beta.1 → 3.8.0-beta.10

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.
@@ -78,18 +78,18 @@ export declare const SessionSchema: z.ZodObject<{
78
78
  verificationMethod: z.ZodString;
79
79
  }, "strip", z.ZodTypeAny, {
80
80
  spaceId?: string;
81
- jwk?: Record<string, unknown>;
82
81
  delegationHeader?: {
83
82
  Authorization?: string;
84
83
  };
84
+ jwk?: Record<string, unknown>;
85
85
  delegationCid?: string;
86
86
  verificationMethod?: string;
87
87
  }, {
88
88
  spaceId?: string;
89
- jwk?: Record<string, unknown>;
90
89
  delegationHeader?: {
91
90
  Authorization?: string;
92
91
  };
92
+ jwk?: Record<string, unknown>;
93
93
  delegationCid?: string;
94
94
  verificationMethod?: string;
95
95
  }>;
@@ -7,6 +7,8 @@
7
7
  import { type ReplicationModuleLoaders, type TinyCloudNodeConfig } from "@tinycloud/node-sdk/core";
8
8
  import type { BrowserWalletSigner } from "../adapters/BrowserWalletSigner";
9
9
  export { actionContains as __replicaActionContains, KV as __replicaKV, canonicalizeRecapCaveats as __replicaCanonicalizeRecapCaveats, isCapabilitySubset as __replicaIsCapabilitySubset, parsePkhDid as __replicaParsePkhDid, parseSpaceUri as __replicaParseSpaceUri, pkhDid as __replicaPkhDid, principalDid as __replicaPrincipalDid, SiweMessage as __replicaSiweMessage, } from "@tinycloud/sdk-core";
10
+ /** The `replica.purge.failed` event, under a name `tcw.ts` may use (it holds no replica-named identifiers). */
11
+ export type { ReplicaPurgeFailedEvent as LocalCopyPurgeFailedEvent } from "@tinycloud/sdk-core";
10
12
  /** Supplied by the optional web replica entry; importing that entry does not register it. */
11
13
  export interface BrowserReplicaPlugin {
12
14
  readonly loaders: ReplicationModuleLoaders;
@@ -0,0 +1,41 @@
1
+ import type { PortableDelegation } from "@tinycloud/node-sdk/core";
2
+ export interface RuntimeGrantStore {
3
+ loadRuntimeGrants(address: string): Promise<PortableDelegation[]>;
4
+ saveRuntimeGrants(address: string, grants: readonly PortableDelegation[]): Promise<void>;
5
+ }
6
+ /** How long a restore waits for stored grants to be activated before it carries on without them. */
7
+ export declare const RESTORE_GRANT_BUDGET_MS = 4000;
8
+ interface Resource {
9
+ readonly service: string;
10
+ readonly space: string;
11
+ readonly path: string;
12
+ readonly actions: readonly string[];
13
+ readonly caveats?: readonly unknown[] | undefined;
14
+ }
15
+ /**
16
+ * True when `resources` are exactly one tab's entry for this owner: that service, the resolved space, that path,
17
+ * exactly those actions, no caveats. A grant that carries anything more (an app's larger grant) is not a panel grant.
18
+ */
19
+ export declare function isPanelResourceSet(resources: readonly Resource[], owner: {
20
+ readonly address: string;
21
+ readonly chainId: number;
22
+ }): boolean;
23
+ /** True when `grant` is exactly a panel grant of the session owned by `address`. */
24
+ export declare function isPanelGrant(grant: PortableDelegation, address: string): boolean;
25
+ /**
26
+ * Stores the panel's own grants among `grants` for `address`, replacing a stored grant with the same cid. Other
27
+ * delegations (an app's larger grant that already covered the request) are never stored.
28
+ */
29
+ export declare function rememberRuntimeGrants(store: RuntimeGrantStore, address: string, grants: readonly PortableDelegation[]): Promise<void>;
30
+ /**
31
+ * Activates each stored grant through `use` (the SDK's validated activation). A grant refused for good is removed from
32
+ * storage; the others stay, including one whose activation failed for a transient reason. Waits at most `budgetMs`;
33
+ * activations still running then finish in the background. Never throws. `isCurrent` false (signed out meanwhile)
34
+ * stops any write to storage.
35
+ */
36
+ export declare function reuseRuntimeGrants(store: RuntimeGrantStore, address: string, use: (grant: PortableDelegation) => Promise<unknown>, options?: {
37
+ readonly budgetMs?: number;
38
+ readonly isCurrent?: () => boolean;
39
+ }): Promise<void>;
40
+ export {};
41
+ //# sourceMappingURL=runtimeGrantPersistence.d.ts.map
@@ -10,6 +10,7 @@
10
10
  * @packageDocumentation
11
11
  */
12
12
  import { TinyCloudNode, TinyCloudNodeConfig, type BootstrapWarning, type DelegateToOptions, type DelegateToResult, type ISessionStorage, type SignStrategy, type ValidatedRuntimeDelegation, type UnifiedOwnerRootInput, type UnifiedOwnerRootReceipt, type RegisterPolicyV3Input, type RegisterPolicyV3Receipt } from "@tinycloud/node-sdk/core";
13
+ import { type LocalCopyPurgeFailedEvent } from "./replica-wiring";
13
14
  import { IKVService, ISQLService, IDuckDbService, IDataVaultService, ISecretsService, ISpaceService, ISpace, ISharingService, ICapabilityKeyRegistry, IHooksService, IEncryptionService, DelegationManager, Delegation, DelegationRevocationReceipt, Result, DelegationError, ClientSession, Extension, type TelemetryConfig, type RetryPolicy, ISpaceCreationHandler, type Manifest, type ComposedManifestRequest, type AccountService, type ResolvedDelegate, type PermissionEntry, type NetworkDescriptor, type CreateOwnerDelegationParams, type OwnerDelegationReceipt, type LocalNodeIdentityStore, type OnNodeNotFound, type RegistryPolicy, type RegistrySequenceStore, SignInOptions, type StorageFullEvent, type IStorageService } from "@tinycloud/sdk-core";
14
15
  import { type RequestPermissionsOptions } from "./requestPermissionsCore";
15
16
  import { type BrowserProvider, type BrowserWalletProvider } from "../adapters/browserProvider";
@@ -204,6 +205,7 @@ export declare class TinyCloudWeb {
204
205
  private _credentialsService?;
205
206
  private _shareReceiverService?;
206
207
  private readonly storageFullHandlers;
208
+ private readonly purgeFailedHandlers;
207
209
  /** Promise that resolves when WASM + node are ready */
208
210
  private _initPromise;
209
211
  /** User config */
@@ -268,6 +270,13 @@ export declare class TinyCloudWeb {
268
270
  * initialization finishes. Returns the unsubscribe function.
269
271
  */
270
272
  on(event: "storage.full", handler: (event: StorageFullEvent) => void): () => void;
273
+ /**
274
+ * Subscribe to `replica.purge.failed`. It fires when the local copy could not be erased after
275
+ * sign-out or account switch, after the SDK's bounded retries; the event carries the typed
276
+ * reason and `retryNow`. The SDK retries again on the next load; `replication.purgeLocalCopy()`
277
+ * retries now. Safe to call before initialization finishes. Returns the unsubscribe function.
278
+ */
279
+ on(event: "replica.purge.failed", handler: (event: LocalCopyPurgeFailedEvent) => void): () => void;
271
280
  /** The owner's TinyCloud storage; `storage.status()` reads usage and plan from the node. */
272
281
  get storage(): IStorageService;
273
282
  /** Browser UI API: `open`, `close`, `toggle`, `isOpen`, and `available`. Inert when `ui: false` or the page cannot render UI. */
@@ -279,6 +288,8 @@ export declare class TinyCloudWeb {
279
288
  get duckdb(): IDuckDbService;
280
289
  get hooks(): IHooksService;
281
290
  get encryption(): IEncryptionService;
291
+ /** Named keys bound to the signed-in session. */
292
+ get keys(): import("node-sdk/dist/encryption-keys").NamedKeyClient;
282
293
  get vault(): IDataVaultService;
283
294
  get secrets(): ISecretsService;
284
295
  secretsForSpace(spaceId: string): ISecretsService;
@@ -445,6 +456,14 @@ export declare class TinyCloudWeb {
445
456
  * `expiryMs` does not apply to them.
446
457
  */
447
458
  requestPermissions(additional: PermissionEntry[], options?: RequestPermissionsOptions): Promise<RequestPermissionsResult>;
459
+ /** True when the panel may ask for a permission: a manifest, a page signer and a live session exist. */
460
+ private canRequestPanelPermissions;
461
+ /**
462
+ * The panel's request for one tab's entry. A grant is kept with the stored session record so it survives a reload;
463
+ * the entry is not stored when the user signed out while the prompt was open.
464
+ */
465
+ private requestPanelPermissions;
466
+ private runtimeGrantStore;
448
467
  getRuntimePermissionDelegations(permissions?: PermissionEntry[]): readonly PortableDelegation[];
449
468
  useRuntimeDelegation(delegation: PortableDelegation): Promise<void>;
450
469
  useDelegation(delegation: PortableDelegation): Promise<DelegatedAccess>;
@@ -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};