@tinycloud/node-sdk 2.4.0-beta.10 → 2.4.0-beta.12

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/core.d.cts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AccountApplication, AccountApplicationListOptions, AccountDelegation, AccountDelegationListOptions, AccountDelegationRevokeOptions, AccountIndexRebuildResult, AccountIndexStatus, AccountIndexedReadOptions, AccountService, AccountServiceConfig, AccountSpace, AccountSpaceListOptions, AccountStatus, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CanonicalAddress, CanonicalParsedNetworkId, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DidCacheKeyOptions, DidEqualsOptions, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISecretsService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IdentityParseError, IngestOptions, InvokeFunction, JWK, KVCreateSignedReadUrlOptions, KVResponse, KVService, KVServiceConfig, KVSignedReadUrlResponse, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PkhDidParts, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResolvedSecretPath, ResourceCapability, SECRET_NAME_RE, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretPayload, SecretScopeOptions, SecretsError, SecretsService, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TableInfo, TelemetryConfig, TelemetryEventHandler, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VAULT_PERMISSION_SERVICE, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, addressStorageKey, buildSpaceUri, canonicalizeAddress, canonicalizeDid, canonicalizeDidUrl, canonicalizeNetworkId, canonicalizeSecretScope, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, didCacheKey, didEquals, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, isCapabilitySubset, isEvmAddress, loadManifest, makePkhSpaceId, makePublicSpaceId, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, validateManifest } from '@tinycloud/sdk-core';
2
- export { D as DelegateToOptions, b as DelegateToResult, c as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, e as NodeUserAuthorization, f as NodeUserAuthorizationConfig, P as PortableDelegation, g as RuntimePermissionGrantOptions, S as SignStrategy, T as TinyCloudNode, h as TinyCloudNodeConfig, W as WasmKeyProvider, i as WasmKeyProviderConfig, j as createWasmKeyProvider, k as defaultSignStrategy, l as deserializeDelegation, s as serializeDelegation } from './core-DiVEwp2P.cjs';
2
+ export { D as DelegateToOptions, b as DelegateToResult, c as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, e as NodeUserAuthorization, f as NodeUserAuthorizationConfig, P as PortableDelegation, g as RuntimePermissionGrantOptions, S as SignStrategy, T as TinyCloudNode, h as TinyCloudNodeConfig, W as WasmKeyProvider, i as WasmKeyProviderConfig, j as createWasmKeyProvider, k as defaultSignStrategy, l as deserializeDelegation, s as serializeDelegation } from './core--mjBU9Jq.cjs';
3
3
  import 'events';
4
4
  import '@tinycloud/sdk-services';
package/dist/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AccountApplication, AccountApplicationListOptions, AccountDelegation, AccountDelegationListOptions, AccountDelegationRevokeOptions, AccountIndexRebuildResult, AccountIndexStatus, AccountIndexedReadOptions, AccountService, AccountServiceConfig, AccountSpace, AccountSpaceListOptions, AccountStatus, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CanonicalAddress, CanonicalParsedNetworkId, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DidCacheKeyOptions, DidEqualsOptions, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISecretsService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IdentityParseError, IngestOptions, InvokeFunction, JWK, KVCreateSignedReadUrlOptions, KVResponse, KVService, KVServiceConfig, KVSignedReadUrlResponse, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PkhDidParts, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResolvedSecretPath, ResourceCapability, SECRET_NAME_RE, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretPayload, SecretScopeOptions, SecretsError, SecretsService, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TableInfo, TelemetryConfig, TelemetryEventHandler, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VAULT_PERMISSION_SERVICE, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, addressStorageKey, buildSpaceUri, canonicalizeAddress, canonicalizeDid, canonicalizeDidUrl, canonicalizeNetworkId, canonicalizeSecretScope, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, didCacheKey, didEquals, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, isCapabilitySubset, isEvmAddress, loadManifest, makePkhSpaceId, makePublicSpaceId, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, validateManifest } from '@tinycloud/sdk-core';
2
- export { D as DelegateToOptions, b as DelegateToResult, c as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, e as NodeUserAuthorization, f as NodeUserAuthorizationConfig, P as PortableDelegation, g as RuntimePermissionGrantOptions, S as SignStrategy, T as TinyCloudNode, h as TinyCloudNodeConfig, W as WasmKeyProvider, i as WasmKeyProviderConfig, j as createWasmKeyProvider, k as defaultSignStrategy, l as deserializeDelegation, s as serializeDelegation } from './core-DiVEwp2P.js';
2
+ export { D as DelegateToOptions, b as DelegateToResult, c as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, e as NodeUserAuthorization, f as NodeUserAuthorizationConfig, P as PortableDelegation, g as RuntimePermissionGrantOptions, S as SignStrategy, T as TinyCloudNode, h as TinyCloudNodeConfig, W as WasmKeyProvider, i as WasmKeyProviderConfig, j as createWasmKeyProvider, k as defaultSignStrategy, l as deserializeDelegation, s as serializeDelegation } from './core--mjBU9Jq.js';
3
3
  import 'events';
4
4
  import '@tinycloud/sdk-services';
package/dist/core.js CHANGED
@@ -374,12 +374,48 @@ var NodeUserAuthorization = class {
374
374
  * `siwe` is the load-bearing one because `extractSiweExpiration` returns
375
375
  * undefined for missing SIWEs and the SDK then treats the session as
376
376
  * expired-at-epoch-zero.
377
+ *
378
+ * @param hosts - The TinyCloud hosts this session was created against,
379
+ * as persisted in {@link PersistedSessionData.tinycloudHosts}. When
380
+ * present (and non-empty) they are adopted directly so the restored
381
+ * session resolves to the same node as the original sign-in without
382
+ * re-running registry/fallback resolution. When absent (old session)
383
+ * hosts are resolved lazily on the first host-needing call via
384
+ * {@link ensureTinyCloudHosts}.
377
385
  */
378
- setRestoredTinyCloudSession(session) {
386
+ setRestoredTinyCloudSession(session, hosts) {
379
387
  const address = canonicalizeAddress(session.address);
380
388
  this._tinyCloudSession = { ...session, address };
381
389
  this._address = address;
382
390
  this._chainId = session.chainId;
391
+ if ((!this.tinycloudHosts || this.tinycloudHosts.length === 0) && hosts && hosts.length > 0) {
392
+ this.tinycloudHosts = [...hosts];
393
+ }
394
+ }
395
+ /**
396
+ * Ensure `tinycloudHosts` are resolved before a host-needing call.
397
+ *
398
+ * Fresh sign-in resolves hosts up front; a restored session may not have
399
+ * (old persisted sessions predate {@link PersistedSessionData.tinycloudHosts}).
400
+ * This guard makes a restored session resolve the node exactly like a fresh
401
+ * sign-in — persisted hosts are preferred (already set by
402
+ * {@link setRestoredTinyCloudSession}), otherwise the registry/fallback
403
+ * resolution runs lazily here. Idempotent: {@link resolveTinyCloudHostsForSignIn}
404
+ * early-returns when hosts are already set.
405
+ *
406
+ * Throws if hosts are unset and the restored session has no address/chainId
407
+ * to resolve from — a real failure that must surface, not be masked.
408
+ */
409
+ async ensureTinyCloudHosts() {
410
+ if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
411
+ return;
412
+ }
413
+ if (this._address === void 0 || this._chainId === void 0) {
414
+ throw new Error(
415
+ "Cannot resolve TinyCloud hosts: no address/chainId available. Sign in or restore a session first."
416
+ );
417
+ }
418
+ await this.resolveTinyCloudHostsForSignIn(this._address, this._chainId);
383
419
  }
384
420
  async resolveTinyCloudHostsForSignIn(address, chainId) {
385
421
  if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
@@ -576,6 +612,7 @@ var NodeUserAuthorization = class {
576
612
  if (!this._tinyCloudSession || !this._address || !this._chainId) {
577
613
  throw new Error("Must be signed in to host space");
578
614
  }
615
+ await this.ensureTinyCloudHosts();
579
616
  const host = this.primaryTinyCloudHost;
580
617
  const spaceId = targetSpaceId ?? this._tinyCloudSession.spaceId;
581
618
  const peerId = await fetchPeerId(host, spaceId);
@@ -618,6 +655,7 @@ var NodeUserAuthorization = class {
618
655
  if (!this._tinyCloudSession) {
619
656
  throw new Error("Must be signed in to ensure space exists");
620
657
  }
658
+ await this.ensureTinyCloudHosts();
621
659
  const host = this.primaryTinyCloudHost;
622
660
  const primarySpaceId = this._tinyCloudSession.spaceId;
623
661
  const result = await activateSessionWithHost(
@@ -799,7 +837,8 @@ var NodeUserAuthorization = class {
799
837
  },
800
838
  expiresAt: expirationTime.toISOString(),
801
839
  createdAt: now.toISOString(),
802
- version: "1.0"
840
+ version: "1.0",
841
+ tinycloudHosts: this.tinycloudHosts
803
842
  };
804
843
  await this.sessionStorage.save(address, persistedData);
805
844
  this._session = clientSession;
@@ -966,7 +1005,8 @@ var NodeUserAuthorization = class {
966
1005
  },
967
1006
  expiresAt,
968
1007
  createdAt,
969
- version: "1.0"
1008
+ version: "1.0",
1009
+ tinycloudHosts: this.tinycloudHosts
970
1010
  };
971
1011
  await this.sessionStorage.save(address, persistedData);
972
1012
  this._session = clientSession;
@@ -1090,6 +1130,7 @@ import {
1090
1130
  verifyDidKeyEd25519Signature,
1091
1131
  canonicalizeAddress as canonicalizeAddress2,
1092
1132
  pkhDid as pkhDid2,
1133
+ resolveTinyCloudHosts as resolveTinyCloudHosts2,
1093
1134
  principalDidEquals as principalDidEquals2,
1094
1135
  parseNetworkId as parseNetworkId2
1095
1136
  } from "@tinycloud/sdk-core";
@@ -2148,6 +2189,14 @@ var _TinyCloudNode = class _TinyCloudNode {
2148
2189
  if (sessionData.chainId) {
2149
2190
  this._chainId = sessionData.chainId;
2150
2191
  }
2192
+ const resolvedHost = await this.resolveRestoredHost(
2193
+ sessionData.tinycloudHosts,
2194
+ restoredAddress,
2195
+ sessionData.chainId
2196
+ );
2197
+ if (resolvedHost) {
2198
+ this.config.host = resolvedHost;
2199
+ }
2151
2200
  this._serviceContext = new ServiceContext2({
2152
2201
  invoke: this.invokeWithRuntimePermissions,
2153
2202
  invokeAny: this.invokeAnyWithRuntimePermissions,
@@ -2193,12 +2242,45 @@ var _TinyCloudNode = class _TinyCloudNode {
2193
2242
  signature: sessionData.signature ?? ""
2194
2243
  };
2195
2244
  if (this.auth) {
2196
- this.auth.setRestoredTinyCloudSession(tcSession);
2245
+ this.auth.setRestoredTinyCloudSession(
2246
+ tcSession,
2247
+ this.config.host ? [this.config.host] : void 0
2248
+ );
2197
2249
  } else {
2198
2250
  this._restoredTcSession = tcSession;
2199
2251
  }
2200
2252
  }
2201
2253
  }
2254
+ /**
2255
+ * Resolve the host a restored session should target.
2256
+ *
2257
+ * Mirrors fresh sign-in host resolution but for the restore path:
2258
+ * an explicit/pinned host always wins, then the hosts the session was
2259
+ * persisted with, then a lazy registry/fallback resolution for sessions
2260
+ * that predate the persisted `tinycloudHosts` field. Returns `undefined`
2261
+ * only when there's nothing to resolve from (no explicit host, no
2262
+ * persisted hosts, and no address/chainId) — in which case the existing
2263
+ * `config.host` (default) is left in place.
2264
+ *
2265
+ * Resolution failures are surfaced, not swallowed: a genuinely broken
2266
+ * registry lookup throws rather than silently falling back to a wrong host.
2267
+ */
2268
+ async resolveRestoredHost(persistedHosts, address, chainId) {
2269
+ if (this.explicitHost) {
2270
+ return this.explicitHost;
2271
+ }
2272
+ if (persistedHosts && persistedHosts.length > 0) {
2273
+ return persistedHosts[0];
2274
+ }
2275
+ if (address === void 0 || chainId === void 0) {
2276
+ return void 0;
2277
+ }
2278
+ const resolved = await resolveTinyCloudHosts2(pkhDid2(address, chainId), {
2279
+ registryUrl: this.config.tinycloudRegistryUrl,
2280
+ fallbackHosts: this.config.tinycloudFallbackHosts
2281
+ });
2282
+ return resolved.hosts[0];
2283
+ }
2202
2284
  /**
2203
2285
  * Resolve the currently-active TinyCloudSession, preferring the auth
2204
2286
  * layer's value (wallet mode) and falling back to the node-level