@tinycloud/web-sdk 3.8.0-beta.2 → 3.8.0-beta.21
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.
- package/README.md +4 -0
- package/dist/adapters/BrowserSessionStorage.d.ts +17 -0
- package/dist/credentials.cjs +1 -1
- package/dist/credentials.mjs +1 -1
- package/dist/delegations-issued-entry.d.ts +3 -0
- package/dist/delegations-issued.cjs +1 -0
- package/dist/delegations-issued.mjs +1 -0
- package/dist/encryption-keys-entry.d.ts +3 -0
- package/dist/encryption-keys.cjs +2 -0
- package/dist/encryption-keys.cjs.LICENSE.txt +1 -0
- package/dist/encryption-keys.mjs +2 -0
- package/dist/encryption-keys.mjs.LICENSE.txt +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1 -1
- package/dist/modules/Storage/tinycloud/types.schema.d.ts +2 -2
- package/dist/modules/requestPermissionsCore.d.ts +8 -1
- package/dist/modules/runtimeGrantPersistence.d.ts +41 -0
- package/dist/modules/tcw.d.ts +30 -1
- package/dist/panel-data.cjs +1 -1
- package/dist/panel-data.mjs +1 -1
- package/dist/panel.cjs +1 -1
- package/dist/panel.mjs +1 -1
- package/dist/replica.cjs +1 -1
- package/dist/replica.mjs +1 -1
- package/dist/ui/api.d.ts +8 -0
- package/dist/ui/client.d.ts +14 -2
- package/dist/ui/config.d.ts +9 -0
- package/dist/ui/data/authority.d.ts +26 -0
- package/dist/ui/data.d.ts +10 -1
- package/dist/ui/host.d.ts +2 -0
- package/dist/ui/panel-styles.d.ts +1 -1
- package/dist/ui/pending.d.ts +1 -1
- package/dist/ui/sections/delegations.strings.d.ts +5 -0
- package/dist/ui/slots.d.ts +13 -1
- package/dist/ui/styles.d.ts +1 -1
- package/package.json +6 -6
|
@@ -36,10 +36,10 @@ export declare const SessionConfigSchema: z.ZodObject<{
|
|
|
36
36
|
domain?: string;
|
|
37
37
|
actions?: Record<string, Record<string, string[]>>;
|
|
38
38
|
spaceId?: string;
|
|
39
|
+
jwk?: Record<string, unknown>;
|
|
39
40
|
address?: string;
|
|
40
41
|
chainId?: number;
|
|
41
42
|
issuedAt?: string;
|
|
42
|
-
jwk?: Record<string, unknown>;
|
|
43
43
|
notBefore?: string;
|
|
44
44
|
expirationTime?: string;
|
|
45
45
|
parents?: string[];
|
|
@@ -47,10 +47,10 @@ export declare const SessionConfigSchema: z.ZodObject<{
|
|
|
47
47
|
domain?: string;
|
|
48
48
|
actions?: Record<string, Record<string, string[]>>;
|
|
49
49
|
spaceId?: string;
|
|
50
|
+
jwk?: Record<string, unknown>;
|
|
50
51
|
address?: string;
|
|
51
52
|
chainId?: number;
|
|
52
53
|
issuedAt?: string;
|
|
53
|
-
jwk?: Record<string, unknown>;
|
|
54
54
|
notBefore?: string;
|
|
55
55
|
expirationTime?: string;
|
|
56
56
|
parents?: string[];
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @packageDocumentation
|
|
12
12
|
*/
|
|
13
|
-
import type
|
|
13
|
+
import { type Manifest, type PermissionEntry } from "@tinycloud/sdk-core";
|
|
14
14
|
import type { PortableDelegation } from "@tinycloud/node-sdk/core";
|
|
15
15
|
export interface RequestPermissionsCoreDeps {
|
|
16
16
|
/** Current stored manifest. Must be defined — caller validates first. */
|
|
17
17
|
manifest: Manifest;
|
|
18
|
+
/** Authenticated owner from the current node, never from a requested resource. */
|
|
19
|
+
ownerDid?: string;
|
|
18
20
|
/**
|
|
19
21
|
* Show the permission request modal. Resolves with `{ approved }`
|
|
20
22
|
* once the user interacts. In tests this is a stub; in production it
|
|
@@ -49,6 +51,11 @@ export interface RequestPermissionsOptions {
|
|
|
49
51
|
* the same error text.
|
|
50
52
|
*/
|
|
51
53
|
export declare function validateAdditionalPermissions(additional: PermissionEntry[]): void;
|
|
54
|
+
/**
|
|
55
|
+
* Normalize only encryption key creation here. Other runtime entries retain
|
|
56
|
+
* their existing Web consent representation; the node validates them.
|
|
57
|
+
*/
|
|
58
|
+
export declare function normalizeRuntimeKeyCreatePermissions(additional: PermissionEntry[], ownerDid?: string): PermissionEntry[];
|
|
52
59
|
/**
|
|
53
60
|
* Core escalation flow. See the TinyCloudWeb.requestPermissions JSDoc
|
|
54
61
|
* for the full spec-level description — this function is the plumbing.
|
|
@@ -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
|
package/dist/modules/tcw.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @packageDocumentation
|
|
11
11
|
*/
|
|
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";
|
|
12
|
+
import { TinyCloudNode, TinyCloudNodeConfig, type OpenKeyAuthorizeTinyCloud, 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
13
|
import { type LocalCopyPurgeFailedEvent } from "./replica-wiring";
|
|
14
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";
|
|
15
15
|
import { type RequestPermissionsOptions } from "./requestPermissionsCore";
|
|
@@ -31,6 +31,11 @@ declare global {
|
|
|
31
31
|
* Extends ClientConfig with browser-specific options.
|
|
32
32
|
*/
|
|
33
33
|
export interface Config extends ClientConfig {
|
|
34
|
+
/** OpenKey authorize-sign client. Requires @openkey/sdk >=0.12.2; popup is the default mode. */
|
|
35
|
+
openkey?: {
|
|
36
|
+
client: OpenKeyAuthorizeTinyCloud;
|
|
37
|
+
mode?: "iframe" | "popup" | "redirect";
|
|
38
|
+
};
|
|
34
39
|
/** Notifications. `throwErrors` rethrows each error's raw message asynchronously, once per burst of identical errors (200 ms window). It applies unless `ui: false` or `ui.toasts: false`, which turn off toasts and throws together, as the old `popups: false` did; `ui.button: false` leaves throws on. Toast placement and visibility are set through `ui`. */
|
|
35
40
|
notifications?: NotificationConfig;
|
|
36
41
|
/** Optional prefix for KV service keys */
|
|
@@ -170,6 +175,10 @@ export interface ShareReceiveResult<T = unknown> {
|
|
|
170
175
|
host: string;
|
|
171
176
|
}
|
|
172
177
|
export declare class TinyCloudWeb {
|
|
178
|
+
private openkeySignInInFlight;
|
|
179
|
+
private prepareSignInToken;
|
|
180
|
+
private preparedSignIn?;
|
|
181
|
+
private invalidatePreparedSignIn;
|
|
173
182
|
/** The connected wallet's raw EIP-1193 provider. */
|
|
174
183
|
provider: BrowserProvider;
|
|
175
184
|
/** The normalized EIP-1193 provider used by the SDK. */
|
|
@@ -288,6 +297,8 @@ export declare class TinyCloudWeb {
|
|
|
288
297
|
get duckdb(): IDuckDbService;
|
|
289
298
|
get hooks(): IHooksService;
|
|
290
299
|
get encryption(): IEncryptionService;
|
|
300
|
+
/** Named keys bound to the signed-in session. */
|
|
301
|
+
get keys(): import("node-sdk/dist/encryption-keys").NamedKeyClient;
|
|
291
302
|
get vault(): IDataVaultService;
|
|
292
303
|
get secrets(): ISecretsService;
|
|
293
304
|
secretsForSpace(spaceId: string): ISecretsService;
|
|
@@ -346,7 +357,15 @@ export declare class TinyCloudWeb {
|
|
|
346
357
|
restoreSession(address?: string): Promise<SessionRestoreResult>;
|
|
347
358
|
clearPersistedSession(address?: string): Promise<void>;
|
|
348
359
|
private configuredManifestPermissions;
|
|
360
|
+
/**
|
|
361
|
+
* Prepare an OpenKey SIWE before showing an approval button. Call after
|
|
362
|
+
* OpenKey connect(), then call signIn() from the button's click handler.
|
|
363
|
+
* A prepared request is single-use and valid for five minutes; call this
|
|
364
|
+
* method again if the approval button remains visible longer.
|
|
365
|
+
*/
|
|
366
|
+
prepareSignIn(): Promise<void>;
|
|
349
367
|
signIn: (options?: SignInOptions) => Promise<ClientSession>;
|
|
368
|
+
private performSignIn;
|
|
350
369
|
/**
|
|
351
370
|
* Sign out: end the session on this instance and clear the persisted
|
|
352
371
|
* session. Afterwards accessors return `undefined` and service calls remain
|
|
@@ -444,6 +463,8 @@ export declare class TinyCloudWeb {
|
|
|
444
463
|
* On approve, this does not mutate the manifest or force a new sign-in.
|
|
445
464
|
* The underlying node creates a secondary delegation to the current
|
|
446
465
|
* session key and records it in the invocation permission map.
|
|
466
|
+
* Exact current-owner `default/share/<id>` key creation is bound to this
|
|
467
|
+
* live signed session across consent. Native shells cannot request it.
|
|
447
468
|
*
|
|
448
469
|
* `options.expiryMs` sets the requested lifetime of the issued step-up
|
|
449
470
|
* delegation, in milliseconds. Omitted, the node's default applies. The
|
|
@@ -454,6 +475,14 @@ export declare class TinyCloudWeb {
|
|
|
454
475
|
* `expiryMs` does not apply to them.
|
|
455
476
|
*/
|
|
456
477
|
requestPermissions(additional: PermissionEntry[], options?: RequestPermissionsOptions): Promise<RequestPermissionsResult>;
|
|
478
|
+
/** True when the panel may ask for a permission: a manifest, a page signer and a live session exist. */
|
|
479
|
+
private canRequestPanelPermissions;
|
|
480
|
+
/**
|
|
481
|
+
* The panel's request for one tab's entry. A grant is kept with the stored session record so it survives a reload;
|
|
482
|
+
* the entry is not stored when the user signed out while the prompt was open.
|
|
483
|
+
*/
|
|
484
|
+
private requestPanelPermissions;
|
|
485
|
+
private runtimeGrantStore;
|
|
457
486
|
getRuntimePermissionDelegations(permissions?: PermissionEntry[]): readonly PortableDelegation[];
|
|
458
487
|
useRuntimeDelegation(delegation: PortableDelegation): Promise<void>;
|
|
459
488
|
useDelegation(delegation: PortableDelegation): Promise<DelegatedAccess>;
|
package/dist/panel-data.cjs
CHANGED
|
@@ -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:()=>
|
|
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})();
|
package/dist/panel-data.mjs
CHANGED
|
@@ -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
|
|
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};
|