@tinycloud/node-sdk 1.2.0 → 1.4.0

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/dist/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
- import * as _tinycloud_sdk_core from '@tinycloud/sdk-core';
2
- import { ISigner, Bytes, ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ClientSession, TinyCloudSession, Extension, Delegation, IKVService, ISQLService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISharingService, CreateDelegationParams, DelegationResult, KeyProvider, JWK } from '@tinycloud/sdk-core';
3
- export { AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, CreateDelegationParams, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDatabaseHandle, IKVService, IPrefixedKVService, ISQLService, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, SQLAction, SQLActionType, SQLService, SQLServiceConfig, ServiceContext, ServiceContextConfig, ServiceSession, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignRequest, SignResponse, Space, SpaceConfig, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TinyCloud, TinyCloudConfig, TinyCloudSession, VersionCheckError, buildSpaceUri, checkNodeVersion, createCapabilityKeyRegistry, createSharingService, createSpaceService, makePublicSpaceId, parseSpaceUri } from '@tinycloud/sdk-core';
1
+ import { ISigner, Bytes, ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ClientSession, TinyCloudSession, Extension, Delegation, IKVService, ISQLService, IDataVaultService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISharingService, CreateDelegationParams, DelegationResult, KeyProvider, JWK } from '@tinycloud/sdk-core';
2
+ export { AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, CreateDelegationParams, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IKVService, IPrefixedKVService, ISQLService, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, SQLAction, SQLActionType, SQLService, SQLServiceConfig, ServiceContext, ServiceContextConfig, ServiceSession, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignRequest, SignResponse, Space, SpaceConfig, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TinyCloud, TinyCloudConfig, TinyCloudSession, VaultAction, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPutOptions, VersionCheckError, WasmVaultFunctions, buildSpaceUri, checkNodeVersion, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, makePublicSpaceId, parseSpaceUri } from '@tinycloud/sdk-core';
4
3
  import { EventEmitter } from 'events';
5
4
  import { TCWSessionManager } from '@tinycloud/node-sdk-wasm';
6
5
 
@@ -237,6 +236,8 @@ interface NodeUserAuthorizationConfig {
237
236
  autoCreateSpace?: boolean;
238
237
  /** TinyCloud server endpoints (default: ["https://node.tinycloud.xyz"]) */
239
238
  tinycloudHosts?: string[];
239
+ /** Whether to include public space capabilities in the session (default: true) */
240
+ enablePublicSpace?: boolean;
240
241
  }
241
242
  /**
242
243
  * Node.js implementation of IUserAuthorization.
@@ -284,6 +285,7 @@ declare class NodeUserAuthorization implements IUserAuthorization {
284
285
  private readonly sessionExpirationMs;
285
286
  private readonly autoCreateSpace;
286
287
  private readonly tinycloudHosts;
288
+ private readonly enablePublicSpace;
287
289
  private sessionManager;
288
290
  private extensions;
289
291
  private _session?;
@@ -313,6 +315,11 @@ declare class NodeUserAuthorization implements IUserAuthorization {
313
315
  * This registers the user as the owner of the space.
314
316
  */
315
317
  private hostSpace;
318
+ /**
319
+ * Create a specific space on the server via host delegation.
320
+ * Used for lazy creation of additional spaces (e.g., public).
321
+ */
322
+ hostPublicSpace(spaceId: string): Promise<boolean>;
316
323
  /**
317
324
  * Ensure the user's space exists on the TinyCloud server.
318
325
  * Creates the space if it doesn't exist and autoCreateSpace is enabled.
@@ -479,6 +486,39 @@ declare class DelegatedAccess {
479
486
  get sql(): ISQLService;
480
487
  }
481
488
 
489
+ /**
490
+ * TinyCloudNode - High-level API for Node.js users.
491
+ *
492
+ * Each user has their own TinyCloudNode instance with their own key.
493
+ * This class provides a simplified interface for:
494
+ * - Signing in and managing sessions
495
+ * - Key-value storage operations on own space
496
+ * - Creating and using delegations
497
+ *
498
+ * @example
499
+ * ```typescript
500
+ * const alice = new TinyCloudNode({
501
+ * privateKey: process.env.ALICE_PRIVATE_KEY,
502
+ * host: "https://node.tinycloud.xyz",
503
+ * prefix: "myapp",
504
+ * });
505
+ *
506
+ * await alice.signIn();
507
+ * await alice.kv.put("greeting", "Hello, world!");
508
+ *
509
+ * // Delegate access to Bob
510
+ * const delegation = await alice.createDelegation({
511
+ * path: "shared/",
512
+ * actions: ["tinycloud.kv/get", "tinycloud.kv/put"],
513
+ * delegateDID: bob.did,
514
+ * });
515
+ *
516
+ * // Bob uses the delegation
517
+ * const access = await bob.useDelegation(delegation);
518
+ * const data = await access.kv.get("shared/data");
519
+ * ```
520
+ */
521
+
482
522
  /**
483
523
  * Configuration for TinyCloudNode.
484
524
  * All fields are optional - TinyCloudNode can work with zero configuration.
@@ -498,6 +538,10 @@ interface TinyCloudNodeConfig {
498
538
  autoCreateSpace?: boolean;
499
539
  /** Custom session storage implementation (default: MemorySessionStorage) */
500
540
  sessionStorage?: ISessionStorage;
541
+ /** Whether to include public space capabilities in the session (default: true).
542
+ * When true, signIn() automatically includes capabilities for the user's public space,
543
+ * accessible via spaces.get('public').kv */
544
+ enablePublicSpace?: boolean;
501
545
  }
502
546
  /**
503
547
  * High-level TinyCloud API for Node.js environments.
@@ -518,6 +562,9 @@ declare class TinyCloudNode {
518
562
  private _serviceContext?;
519
563
  private _kv?;
520
564
  private _sql?;
565
+ private _vault?;
566
+ /** Cached public KV with proper delegation (set by ensurePublicSpace) */
567
+ private _publicKV?;
521
568
  /** Session key ID - always available */
522
569
  private sessionKeyId;
523
570
  /** Session key JWK as object - always available */
@@ -592,6 +639,26 @@ declare class TinyCloudNode {
592
639
  * Requires wallet mode (privateKey in config).
593
640
  */
594
641
  signIn(): Promise<void>;
642
+ /**
643
+ * Restore a previously established session from stored delegation data.
644
+ *
645
+ * This is used by the CLI to restore a session that was created via the
646
+ * browser-based delegation flow (OpenKey `/delegate` page). Instead of
647
+ * signing in with a private key, it injects the delegation data directly.
648
+ *
649
+ * @param sessionData - The stored delegation data from the browser flow
650
+ */
651
+ restoreSession(sessionData: {
652
+ delegationHeader: {
653
+ Authorization: string;
654
+ };
655
+ delegationCid: string;
656
+ spaceId: string;
657
+ jwk: object;
658
+ verificationMethod: string;
659
+ address?: string;
660
+ chainId?: number;
661
+ }): Promise<void>;
595
662
  /**
596
663
  * Connect a wallet to upgrade from session-only mode to wallet mode.
597
664
  *
@@ -655,6 +722,11 @@ declare class TinyCloudNode {
655
722
  * SQL database operations on this user's space.
656
723
  */
657
724
  get sql(): ISQLService;
725
+ /**
726
+ * Data Vault operations - client-side encrypted KV storage.
727
+ * Call `vault.unlock(signer)` after signIn() to derive encryption keys.
728
+ */
729
+ get vault(): IDataVaultService;
658
730
  /**
659
731
  * Get the CapabilityKeyRegistry for managing keys and their capabilities.
660
732
  *
@@ -790,11 +862,12 @@ declare class TinyCloudNode {
790
862
  */
791
863
  get sharingService(): ISharingService;
792
864
  /**
793
- * Ensure the user's public space exists.
794
- * Creates it via spaces.create('public') if it doesn't.
795
- * Requires the user to be signed in.
865
+ * Ensure the user's public space exists and is accessible.
866
+ * Creates the space and activates a session delegation for it.
867
+ * This is the trigger for lazy public space creation — call it
868
+ * before writing to spaces.get('public').kv.
796
869
  */
797
- ensurePublicSpace(): Promise<_tinycloud_sdk_core.Result<void, _tinycloud_sdk_core.ServiceError>>;
870
+ ensurePublicSpace(): Promise<void>;
798
871
  /**
799
872
  * Get a KVService scoped to the user's own public space.
800
873
  * Writes require authentication (owner/delegate).
@@ -865,6 +938,8 @@ declare class TinyCloudNode {
865
938
  disableSubDelegation?: boolean;
866
939
  /** Expiration time in milliseconds from now (default: 1 hour) */
867
940
  expiryMs?: number;
941
+ /** Override space ID (for creating delegations to non-primary spaces like public) */
942
+ spaceIdOverride?: string;
868
943
  }): Promise<PortableDelegation>;
869
944
  /**
870
945
  * Use a delegation received from another user.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import * as _tinycloud_sdk_core from '@tinycloud/sdk-core';
2
- import { ISigner, Bytes, ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ClientSession, TinyCloudSession, Extension, Delegation, IKVService, ISQLService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISharingService, CreateDelegationParams, DelegationResult, KeyProvider, JWK } from '@tinycloud/sdk-core';
3
- export { AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, CreateDelegationParams, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDatabaseHandle, IKVService, IPrefixedKVService, ISQLService, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, SQLAction, SQLActionType, SQLService, SQLServiceConfig, ServiceContext, ServiceContextConfig, ServiceSession, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignRequest, SignResponse, Space, SpaceConfig, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TinyCloud, TinyCloudConfig, TinyCloudSession, VersionCheckError, buildSpaceUri, checkNodeVersion, createCapabilityKeyRegistry, createSharingService, createSpaceService, makePublicSpaceId, parseSpaceUri } from '@tinycloud/sdk-core';
1
+ import { ISigner, Bytes, ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ClientSession, TinyCloudSession, Extension, Delegation, IKVService, ISQLService, IDataVaultService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISharingService, CreateDelegationParams, DelegationResult, KeyProvider, JWK } from '@tinycloud/sdk-core';
2
+ export { AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, CreateDelegationParams, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IKVService, IPrefixedKVService, ISQLService, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, SQLAction, SQLActionType, SQLService, SQLServiceConfig, ServiceContext, ServiceContextConfig, ServiceSession, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignRequest, SignResponse, Space, SpaceConfig, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TinyCloud, TinyCloudConfig, TinyCloudSession, VaultAction, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPutOptions, VersionCheckError, WasmVaultFunctions, buildSpaceUri, checkNodeVersion, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, makePublicSpaceId, parseSpaceUri } from '@tinycloud/sdk-core';
4
3
  import { EventEmitter } from 'events';
5
4
  import { TCWSessionManager } from '@tinycloud/node-sdk-wasm';
6
5
 
@@ -237,6 +236,8 @@ interface NodeUserAuthorizationConfig {
237
236
  autoCreateSpace?: boolean;
238
237
  /** TinyCloud server endpoints (default: ["https://node.tinycloud.xyz"]) */
239
238
  tinycloudHosts?: string[];
239
+ /** Whether to include public space capabilities in the session (default: true) */
240
+ enablePublicSpace?: boolean;
240
241
  }
241
242
  /**
242
243
  * Node.js implementation of IUserAuthorization.
@@ -284,6 +285,7 @@ declare class NodeUserAuthorization implements IUserAuthorization {
284
285
  private readonly sessionExpirationMs;
285
286
  private readonly autoCreateSpace;
286
287
  private readonly tinycloudHosts;
288
+ private readonly enablePublicSpace;
287
289
  private sessionManager;
288
290
  private extensions;
289
291
  private _session?;
@@ -313,6 +315,11 @@ declare class NodeUserAuthorization implements IUserAuthorization {
313
315
  * This registers the user as the owner of the space.
314
316
  */
315
317
  private hostSpace;
318
+ /**
319
+ * Create a specific space on the server via host delegation.
320
+ * Used for lazy creation of additional spaces (e.g., public).
321
+ */
322
+ hostPublicSpace(spaceId: string): Promise<boolean>;
316
323
  /**
317
324
  * Ensure the user's space exists on the TinyCloud server.
318
325
  * Creates the space if it doesn't exist and autoCreateSpace is enabled.
@@ -479,6 +486,39 @@ declare class DelegatedAccess {
479
486
  get sql(): ISQLService;
480
487
  }
481
488
 
489
+ /**
490
+ * TinyCloudNode - High-level API for Node.js users.
491
+ *
492
+ * Each user has their own TinyCloudNode instance with their own key.
493
+ * This class provides a simplified interface for:
494
+ * - Signing in and managing sessions
495
+ * - Key-value storage operations on own space
496
+ * - Creating and using delegations
497
+ *
498
+ * @example
499
+ * ```typescript
500
+ * const alice = new TinyCloudNode({
501
+ * privateKey: process.env.ALICE_PRIVATE_KEY,
502
+ * host: "https://node.tinycloud.xyz",
503
+ * prefix: "myapp",
504
+ * });
505
+ *
506
+ * await alice.signIn();
507
+ * await alice.kv.put("greeting", "Hello, world!");
508
+ *
509
+ * // Delegate access to Bob
510
+ * const delegation = await alice.createDelegation({
511
+ * path: "shared/",
512
+ * actions: ["tinycloud.kv/get", "tinycloud.kv/put"],
513
+ * delegateDID: bob.did,
514
+ * });
515
+ *
516
+ * // Bob uses the delegation
517
+ * const access = await bob.useDelegation(delegation);
518
+ * const data = await access.kv.get("shared/data");
519
+ * ```
520
+ */
521
+
482
522
  /**
483
523
  * Configuration for TinyCloudNode.
484
524
  * All fields are optional - TinyCloudNode can work with zero configuration.
@@ -498,6 +538,10 @@ interface TinyCloudNodeConfig {
498
538
  autoCreateSpace?: boolean;
499
539
  /** Custom session storage implementation (default: MemorySessionStorage) */
500
540
  sessionStorage?: ISessionStorage;
541
+ /** Whether to include public space capabilities in the session (default: true).
542
+ * When true, signIn() automatically includes capabilities for the user's public space,
543
+ * accessible via spaces.get('public').kv */
544
+ enablePublicSpace?: boolean;
501
545
  }
502
546
  /**
503
547
  * High-level TinyCloud API for Node.js environments.
@@ -518,6 +562,9 @@ declare class TinyCloudNode {
518
562
  private _serviceContext?;
519
563
  private _kv?;
520
564
  private _sql?;
565
+ private _vault?;
566
+ /** Cached public KV with proper delegation (set by ensurePublicSpace) */
567
+ private _publicKV?;
521
568
  /** Session key ID - always available */
522
569
  private sessionKeyId;
523
570
  /** Session key JWK as object - always available */
@@ -592,6 +639,26 @@ declare class TinyCloudNode {
592
639
  * Requires wallet mode (privateKey in config).
593
640
  */
594
641
  signIn(): Promise<void>;
642
+ /**
643
+ * Restore a previously established session from stored delegation data.
644
+ *
645
+ * This is used by the CLI to restore a session that was created via the
646
+ * browser-based delegation flow (OpenKey `/delegate` page). Instead of
647
+ * signing in with a private key, it injects the delegation data directly.
648
+ *
649
+ * @param sessionData - The stored delegation data from the browser flow
650
+ */
651
+ restoreSession(sessionData: {
652
+ delegationHeader: {
653
+ Authorization: string;
654
+ };
655
+ delegationCid: string;
656
+ spaceId: string;
657
+ jwk: object;
658
+ verificationMethod: string;
659
+ address?: string;
660
+ chainId?: number;
661
+ }): Promise<void>;
595
662
  /**
596
663
  * Connect a wallet to upgrade from session-only mode to wallet mode.
597
664
  *
@@ -655,6 +722,11 @@ declare class TinyCloudNode {
655
722
  * SQL database operations on this user's space.
656
723
  */
657
724
  get sql(): ISQLService;
725
+ /**
726
+ * Data Vault operations - client-side encrypted KV storage.
727
+ * Call `vault.unlock(signer)` after signIn() to derive encryption keys.
728
+ */
729
+ get vault(): IDataVaultService;
658
730
  /**
659
731
  * Get the CapabilityKeyRegistry for managing keys and their capabilities.
660
732
  *
@@ -790,11 +862,12 @@ declare class TinyCloudNode {
790
862
  */
791
863
  get sharingService(): ISharingService;
792
864
  /**
793
- * Ensure the user's public space exists.
794
- * Creates it via spaces.create('public') if it doesn't.
795
- * Requires the user to be signed in.
865
+ * Ensure the user's public space exists and is accessible.
866
+ * Creates the space and activates a session delegation for it.
867
+ * This is the trigger for lazy public space creation — call it
868
+ * before writing to spaces.get('public').kv.
796
869
  */
797
- ensurePublicSpace(): Promise<_tinycloud_sdk_core.Result<void, _tinycloud_sdk_core.ServiceError>>;
870
+ ensurePublicSpace(): Promise<void>;
798
871
  /**
799
872
  * Get a KVService scoped to the user's own public space.
800
873
  * Writes require authentication (owner/delegate).
@@ -865,6 +938,8 @@ declare class TinyCloudNode {
865
938
  disableSubDelegation?: boolean;
866
939
  /** Expiration time in milliseconds from now (default: 1 hour) */
867
940
  expiryMs?: number;
941
+ /** Override space ID (for creating delegations to non-primary spaces like public) */
942
+ spaceIdOverride?: string;
868
943
  }): Promise<PortableDelegation>;
869
944
  /**
870
945
  * Use a delegation received from another user.