@tinycloud/node-sdk 3.11.1-beta.0 → 3.12.0-beta.1
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/NodeUserAuthorization-BtoDI9in.d.cts +900 -0
- package/dist/NodeUserAuthorization-BtoDI9in.d.ts +900 -0
- package/dist/{TinyCloudNode-AUotFGzy.d.ts → TinyCloudNode-C24728N_.d.cts} +30 -875
- package/dist/{TinyCloudNode-BmpjkpWR.d.cts → TinyCloudNode-DLrINr98.d.ts} +30 -875
- package/dist/{authority-dRnJD4iL.d.ts → authority-BQN2Z3st.d.ts} +1 -1
- package/dist/{authority-BYSEyjDI.d.cts → authority-DDdheOL6.d.cts} +1 -1
- package/dist/core.cjs +145 -90
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +5 -4
- package/dist/core.d.ts +5 -4
- package/dist/core.js +145 -90
- package/dist/core.js.map +1 -1
- package/dist/credentials-core.d.cts +1 -1
- package/dist/credentials-core.d.ts +1 -1
- package/dist/credentials.d.cts +1 -1
- package/dist/credentials.d.ts +1 -1
- package/dist/{delegation-Ckc3UETl.d.cts → delegation-BQbAuKad.d.cts} +1 -1
- package/dist/{delegation-Ckc3UETl.d.ts → delegation-BQbAuKad.d.ts} +1 -1
- package/dist/encryption-keys.d.cts +3 -2
- package/dist/encryption-keys.d.ts +3 -2
- package/dist/index.cjs +145 -90
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +145 -90
- package/dist/index.js.map +1 -1
- package/dist/replication/authority.d.cts +4 -3
- package/dist/replication/authority.d.ts +4 -3
- package/dist/space-hosting.cjs +141 -0
- package/dist/space-hosting.cjs.map +1 -0
- package/dist/space-hosting.d.cts +69 -0
- package/dist/space-hosting.d.ts +69 -0
- package/dist/space-hosting.js +115 -0
- package/dist/space-hosting.js.map +1 -0
- package/package.json +11 -1
package/dist/core.d.cts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { ReplicationOptions, Manifest, PermissionEntry } from '@tinycloud/sdk-core';
|
|
2
2
|
export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AccountApplication, AccountApplicationListOptions, AccountApplicationRegisterOptions, AccountDelegation, AccountDelegationListOptions, AccountDelegationRevokeOptions, AccountIndexEnsureResult, AccountIndexRebuildResult, AccountIndexStatus, AccountIndexedReadOptions, AccountService, AccountServiceConfig, AccountSpace, AccountSpaceListOptions, AccountStatus, AuthorityRefusal, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CanonicalAddress, CanonicalParsedNetworkId, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, CaveatedDelegationUnsupportedError, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DataVaultConfig, DataVaultService, DatabaseHandle, DelegateReceivedShareParams, DelegatedShareAccess, 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, KVBatchReadResponse, KVCreateSignedReadUrlOptions, KVListPage, KVReadThrough, KVReplicaHandle, KVReplicaSpec, KVReplicaStorage, KVReplicationController, KVReplicationDeps, KVResponse, KVService, KVServiceConfig, KVSignedReadUrlResponse, KeyInfo, KeyProvider, KeyType, LocalGetResult, LocalListResult, LocalReadMeta, LocalReplicaStatus, LocalSyncResult, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, OpenKeyCallbackStrategy, OpenKeySigningRequestBody, OpenKeySigningResponseBody, OpenKeySigningStrategyOptions, ParsedSecretCatalogKey, PendingWriteRecord, PendingWriteState, PendingWriteStore, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PinnedKey, PkhDidParts, PrefixedKVService, ProtocolMismatchError, PurgeTarget, QueryOptions, QueryResponse, ReceiveOptions, RegisterBatchSuccess, RegisterPolicyV3Input, RegisterPolicyV3Receipt, ReplicaAuthorityState, ReplicaCoverage, ReplicaDevice, ReplicaGatedHandle, ReplicaGrantInfo, ReplicaInspectedStatus, ReplicaState, ReplicaStatusEntry, ReplicationAuthority, ReplicationControl, ReplicationEvent, ReplicationIdentity, ReplicationOptions, ReplicationPurgeReport, ReplicationReason, ReplicationScheduler, ResolvedCapabilities, ResolvedDelegate, ResolvedReplicationOptions, ResolvedSecretPath, ResourceCapability, SECRET_NAME_RE, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretCatalogEntry, 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, TinyCloudDebugEnableOptions, TinyCloudDebugEvent, TinyCloudDebugLevel, TinyCloudDebugLogger, TinyCloudDebugTimer, TinyCloudSession, UnsupportedFeatureError, VAULT_PERMISSION_SERVICE, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultNetworkReadResult, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, addressStorageKey, buildSpaceUri, canonicalizeAddress, canonicalizeDid, canonicalizeDidUrl, canonicalizeNetworkId, canonicalizeSecretScope, checkNodeInfo, clearTinyCloudDebugLogs, composeManifestRequest, createCapabilityKeyRegistry, createOpenKeyCallbackSigningStrategy, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, didCacheKey, didEquals, disableTinyCloudDebug, enableTinyCloudDebug, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, getTinyCloudDebugLogs, installTinyCloudDebugGlobals, isCapabilitySubset, isEvmAddress, loadManifest, makePkhSpaceId, makePublicSpaceId, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseSecretCatalogKey, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, tinyCloudDebugLogger, validateManifest } from '@tinycloud/sdk-core';
|
|
3
3
|
import { _ as __gated_network } from './gated-network-BEF2XSTC.cjs';
|
|
4
|
-
import { _ as __authority } from './authority-
|
|
4
|
+
import { _ as __authority } from './authority-DDdheOL6.cjs';
|
|
5
5
|
import { _ as __runtime } from './runtime-mRhSu-vJ.cjs';
|
|
6
6
|
import { ReplicaDenyInput } from '@tinycloud/sdk-services/kv/replication';
|
|
7
7
|
export { F as FileSessionStorage, M as MemorySessionStorage, W as WasmKeyProvider, a as WasmKeyProviderConfig, c as createWasmKeyProvider, i as isAppKeyHostBound } from './WasmKeyProvider-OA0LqmTg.cjs';
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
8
|
+
export { N as NodeEventEmitterStrategy, a as NodeUserAuthorization, b as NodeUserAuthorizationConfig, O as OpenKeyAuthorizeTinyCloud, P as PreparedOpenKeyAuthorization, c as SignStrategy, S as SpaceHosting, d as defaultSignStrategy, w as wireOpenKeyAuthorize } from './NodeUserAuthorization-BtoDI9in.cjs';
|
|
9
|
+
export { B as BootstrapWarning, C as CreateOwnerDelegationParams, D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, E as EnsureEncryptionNetworkOptions, I as InvalidRestoredSessionError, O as OwnerDelegationReceipt, R as RuntimePermissionGrantOptions, S as SecretPermissionHint, c as SecretReadInput, d as SecretReadResult, T as TinyCloudNode, e as TinyCloudNodeConfig, U as UnifiedOwnerRootInput, f as UnifiedOwnerRootReceipt, g as UnsupportedSessionRestoreError } from './TinyCloudNode-C24728N_.cjs';
|
|
10
|
+
export { C as CompactRuntimeDelegationInput, P as PortableDelegation, R as RuntimeDelegationRejectedError, a as RuntimeDelegationRejection, V as ValidatedRuntimeDelegation, b as activateCompactRuntimeDelegation, c as activateValidatedRuntimeDelegation, d as deserializeDelegation, s as serializeDelegation } from './delegation-BQbAuKad.cjs';
|
|
10
11
|
import '@tinycloud/sdk-services';
|
|
11
|
-
import '@tinycloud/sdk-services/encryption/named-keys';
|
|
12
12
|
import 'events';
|
|
13
|
+
import '@tinycloud/sdk-services/encryption/named-keys';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* The `@tinycloud/replica/profile-gate` members the node adapter uses, typed structurally: node-sdk
|
package/dist/core.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { ReplicationOptions, Manifest, PermissionEntry } from '@tinycloud/sdk-core';
|
|
2
2
|
export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AccountApplication, AccountApplicationListOptions, AccountApplicationRegisterOptions, AccountDelegation, AccountDelegationListOptions, AccountDelegationRevokeOptions, AccountIndexEnsureResult, AccountIndexRebuildResult, AccountIndexStatus, AccountIndexedReadOptions, AccountService, AccountServiceConfig, AccountSpace, AccountSpaceListOptions, AccountStatus, AuthorityRefusal, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CanonicalAddress, CanonicalParsedNetworkId, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, CaveatedDelegationUnsupportedError, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DataVaultConfig, DataVaultService, DatabaseHandle, DelegateReceivedShareParams, DelegatedShareAccess, 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, KVBatchReadResponse, KVCreateSignedReadUrlOptions, KVListPage, KVReadThrough, KVReplicaHandle, KVReplicaSpec, KVReplicaStorage, KVReplicationController, KVReplicationDeps, KVResponse, KVService, KVServiceConfig, KVSignedReadUrlResponse, KeyInfo, KeyProvider, KeyType, LocalGetResult, LocalListResult, LocalReadMeta, LocalReplicaStatus, LocalSyncResult, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, OpenKeyCallbackStrategy, OpenKeySigningRequestBody, OpenKeySigningResponseBody, OpenKeySigningStrategyOptions, ParsedSecretCatalogKey, PendingWriteRecord, PendingWriteState, PendingWriteStore, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PinnedKey, PkhDidParts, PrefixedKVService, ProtocolMismatchError, PurgeTarget, QueryOptions, QueryResponse, ReceiveOptions, RegisterBatchSuccess, RegisterPolicyV3Input, RegisterPolicyV3Receipt, ReplicaAuthorityState, ReplicaCoverage, ReplicaDevice, ReplicaGatedHandle, ReplicaGrantInfo, ReplicaInspectedStatus, ReplicaState, ReplicaStatusEntry, ReplicationAuthority, ReplicationControl, ReplicationEvent, ReplicationIdentity, ReplicationOptions, ReplicationPurgeReport, ReplicationReason, ReplicationScheduler, ResolvedCapabilities, ResolvedDelegate, ResolvedReplicationOptions, ResolvedSecretPath, ResourceCapability, SECRET_NAME_RE, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretCatalogEntry, 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, TinyCloudDebugEnableOptions, TinyCloudDebugEvent, TinyCloudDebugLevel, TinyCloudDebugLogger, TinyCloudDebugTimer, TinyCloudSession, UnsupportedFeatureError, VAULT_PERMISSION_SERVICE, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultNetworkReadResult, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, addressStorageKey, buildSpaceUri, canonicalizeAddress, canonicalizeDid, canonicalizeDidUrl, canonicalizeNetworkId, canonicalizeSecretScope, checkNodeInfo, clearTinyCloudDebugLogs, composeManifestRequest, createCapabilityKeyRegistry, createOpenKeyCallbackSigningStrategy, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, didCacheKey, didEquals, disableTinyCloudDebug, enableTinyCloudDebug, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, getTinyCloudDebugLogs, installTinyCloudDebugGlobals, isCapabilitySubset, isEvmAddress, loadManifest, makePkhSpaceId, makePublicSpaceId, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseSecretCatalogKey, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, tinyCloudDebugLogger, validateManifest } from '@tinycloud/sdk-core';
|
|
3
3
|
import { _ as __gated_network } from './gated-network-BEF2XSTC.js';
|
|
4
|
-
import { _ as __authority } from './authority-
|
|
4
|
+
import { _ as __authority } from './authority-BQN2Z3st.js';
|
|
5
5
|
import { _ as __runtime } from './runtime-CO4VXnPq.js';
|
|
6
6
|
import { ReplicaDenyInput } from '@tinycloud/sdk-services/kv/replication';
|
|
7
7
|
export { F as FileSessionStorage, M as MemorySessionStorage, W as WasmKeyProvider, a as WasmKeyProviderConfig, c as createWasmKeyProvider, i as isAppKeyHostBound } from './WasmKeyProvider-OA0LqmTg.js';
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
8
|
+
export { N as NodeEventEmitterStrategy, a as NodeUserAuthorization, b as NodeUserAuthorizationConfig, O as OpenKeyAuthorizeTinyCloud, P as PreparedOpenKeyAuthorization, c as SignStrategy, S as SpaceHosting, d as defaultSignStrategy, w as wireOpenKeyAuthorize } from './NodeUserAuthorization-BtoDI9in.js';
|
|
9
|
+
export { B as BootstrapWarning, C as CreateOwnerDelegationParams, D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, E as EnsureEncryptionNetworkOptions, I as InvalidRestoredSessionError, O as OwnerDelegationReceipt, R as RuntimePermissionGrantOptions, S as SecretPermissionHint, c as SecretReadInput, d as SecretReadResult, T as TinyCloudNode, e as TinyCloudNodeConfig, U as UnifiedOwnerRootInput, f as UnifiedOwnerRootReceipt, g as UnsupportedSessionRestoreError } from './TinyCloudNode-DLrINr98.js';
|
|
10
|
+
export { C as CompactRuntimeDelegationInput, P as PortableDelegation, R as RuntimeDelegationRejectedError, a as RuntimeDelegationRejection, V as ValidatedRuntimeDelegation, b as activateCompactRuntimeDelegation, c as activateValidatedRuntimeDelegation, d as deserializeDelegation, s as serializeDelegation } from './delegation-BQbAuKad.js';
|
|
10
11
|
import '@tinycloud/sdk-services';
|
|
11
|
-
import '@tinycloud/sdk-services/encryption/named-keys';
|
|
12
12
|
import 'events';
|
|
13
|
+
import '@tinycloud/sdk-services/encryption/named-keys';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* The `@tinycloud/replica/profile-gate` members the node adapter uses, typed structurally: node-sdk
|
package/dist/core.js
CHANGED
|
@@ -500,6 +500,8 @@ var NodeUserAuthorization = class {
|
|
|
500
500
|
* delegation lists them: the node answers a repeat with empty lists.
|
|
501
501
|
*/
|
|
502
502
|
this._lastActivationActivatedSpaceIds = [];
|
|
503
|
+
/** See {@link spaceHosting}. Written only from node answers. */
|
|
504
|
+
this._spaceHosting = "unknown";
|
|
503
505
|
this.wasm = config.wasmBindings;
|
|
504
506
|
this.signer = config.signer;
|
|
505
507
|
this.signStrategy = config.signStrategy ?? defaultSignStrategy;
|
|
@@ -659,6 +661,7 @@ var NodeUserAuthorization = class {
|
|
|
659
661
|
this.registryVerdict = void 0;
|
|
660
662
|
this._lastActivationSkippedSpaceIds = [];
|
|
661
663
|
this._lastActivationActivatedSpaceIds = [];
|
|
664
|
+
this._spaceHosting = "unknown";
|
|
662
665
|
if (!session) {
|
|
663
666
|
this._session = void 0;
|
|
664
667
|
this._tinyCloudSession = void 0;
|
|
@@ -799,6 +802,18 @@ var NodeUserAuthorization = class {
|
|
|
799
802
|
get lastActivationActivatedSpaceIds() {
|
|
800
803
|
return [...this._lastActivationActivatedSpaceIds];
|
|
801
804
|
}
|
|
805
|
+
/**
|
|
806
|
+
* The node's last answer for whether this session's primary space is hosted:
|
|
807
|
+
* recorded from the sign-in activation, or by {@link noteSpaceHosting}.
|
|
808
|
+
* `unknown` until one of them answers, and after a restore.
|
|
809
|
+
*/
|
|
810
|
+
get spaceHosting() {
|
|
811
|
+
return this._spaceHosting;
|
|
812
|
+
}
|
|
813
|
+
/** @internal Record the hosting probe's answer for the primary space. */
|
|
814
|
+
noteSpaceHosting(hosting) {
|
|
815
|
+
this._spaceHosting = hosting;
|
|
816
|
+
}
|
|
802
817
|
/**
|
|
803
818
|
* Compute the `abilities` map the WASM `prepareSession` call should
|
|
804
819
|
* see at sign-in time.
|
|
@@ -1259,103 +1274,55 @@ var NodeUserAuthorization = class {
|
|
|
1259
1274
|
this._tinyCloudSession.delegationHeader
|
|
1260
1275
|
);
|
|
1261
1276
|
this.recordActivationSkippedSpaces(result, primarySpaceId);
|
|
1277
|
+
if (!result.success && result.status !== 404) {
|
|
1278
|
+
throw Object.assign(
|
|
1279
|
+
new Error(`Failed to activate session: ${describeHostFailure(result)}`),
|
|
1280
|
+
{ cause: result }
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
await this.ensurePrimarySpaceHosted(this._spaceHosting);
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* The create step of {@link ensureSpaceExists}: given the node's answer for
|
|
1287
|
+
* the primary space, host it through the space creation handler when it is
|
|
1288
|
+
* `not-hosted`. Any other answer, and a missing handler, change nothing. The
|
|
1289
|
+
* caller supplies the answer (sign-in's activation, or the hosting probe);
|
|
1290
|
+
* an empty activation list is never one.
|
|
1291
|
+
*
|
|
1292
|
+
* @throws Error if the creation handler fails or times out, or hosting fails
|
|
1293
|
+
*/
|
|
1294
|
+
async ensurePrimarySpaceHosted(hosting) {
|
|
1295
|
+
if (hosting !== "not-hosted") {
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
const session = this._tinyCloudSession;
|
|
1299
|
+
if (!session) {
|
|
1300
|
+
throw new Error("Must be signed in to host the primary space");
|
|
1301
|
+
}
|
|
1262
1302
|
const handler = this.spaceCreationHandler ?? (this.autoCreateSpace ? new AutoApproveSpaceCreationHandler() : void 0);
|
|
1303
|
+
if (!handler) {
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
await this.ensureTinyCloudHosts();
|
|
1307
|
+
const host = this.primaryTinyCloudHost;
|
|
1308
|
+
const primarySpaceId = session.spaceId;
|
|
1263
1309
|
const creationContext = {
|
|
1264
1310
|
spaceId: primarySpaceId,
|
|
1265
1311
|
address: this._address,
|
|
1266
1312
|
chainId: this._chainId,
|
|
1267
1313
|
host
|
|
1268
1314
|
};
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
return;
|
|
1281
|
-
}
|
|
1282
|
-
try {
|
|
1283
|
-
const created = await this.hostSpace();
|
|
1284
|
-
if (!created.success) {
|
|
1285
|
-
const err2 = Object.assign(
|
|
1286
|
-
new Error(`Failed to create space ${primarySpaceId}: ${describeHostFailure(created)}`),
|
|
1287
|
-
{ cause: created }
|
|
1288
|
-
);
|
|
1289
|
-
throw err2;
|
|
1290
|
-
}
|
|
1291
|
-
} catch (error) {
|
|
1292
|
-
handler.onSpaceCreationFailed?.(
|
|
1293
|
-
creationContext,
|
|
1294
|
-
error instanceof Error ? error : new Error(String(error))
|
|
1295
|
-
);
|
|
1296
|
-
throw error;
|
|
1297
|
-
}
|
|
1298
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1299
|
-
const retryResult = await activateSessionWithHost(
|
|
1300
|
-
host,
|
|
1301
|
-
this._tinyCloudSession.delegationHeader
|
|
1302
|
-
);
|
|
1303
|
-
if (!retryResult.success) {
|
|
1304
|
-
const err2 = Object.assign(
|
|
1305
|
-
new Error(`Failed to activate session after creating space: ${describeHostFailure(retryResult)}`),
|
|
1306
|
-
{ cause: retryResult }
|
|
1307
|
-
);
|
|
1308
|
-
handler.onSpaceCreationFailed?.(creationContext, err2);
|
|
1309
|
-
throw err2;
|
|
1310
|
-
}
|
|
1311
|
-
handler.onSpaceCreated?.(creationContext);
|
|
1312
|
-
return;
|
|
1313
|
-
}
|
|
1314
|
-
if (result.status === 404) {
|
|
1315
|
-
if (!handler) {
|
|
1316
|
-
return;
|
|
1317
|
-
}
|
|
1318
|
-
await this.guardSpaceCreation(handler, creationContext);
|
|
1319
|
-
const confirmed = await handler.confirmSpaceCreation(creationContext);
|
|
1320
|
-
if (!confirmed) {
|
|
1321
|
-
return;
|
|
1322
|
-
}
|
|
1323
|
-
try {
|
|
1324
|
-
const created = await this.hostSpace();
|
|
1325
|
-
if (!created.success) {
|
|
1326
|
-
const err2 = Object.assign(
|
|
1327
|
-
new Error(`Failed to create space ${primarySpaceId}: ${describeHostFailure(created)}`),
|
|
1328
|
-
{ cause: created }
|
|
1329
|
-
);
|
|
1330
|
-
throw err2;
|
|
1331
|
-
}
|
|
1332
|
-
} catch (error) {
|
|
1333
|
-
handler.onSpaceCreationFailed?.(
|
|
1334
|
-
creationContext,
|
|
1335
|
-
error instanceof Error ? error : new Error(String(error))
|
|
1336
|
-
);
|
|
1337
|
-
throw error;
|
|
1338
|
-
}
|
|
1339
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1340
|
-
const retryResult = await activateSessionWithHost(
|
|
1341
|
-
host,
|
|
1342
|
-
this._tinyCloudSession.delegationHeader
|
|
1343
|
-
);
|
|
1344
|
-
if (!retryResult.success) {
|
|
1345
|
-
const err2 = Object.assign(
|
|
1346
|
-
new Error(`Failed to activate session after creating space: ${describeHostFailure(retryResult)}`),
|
|
1347
|
-
{ cause: retryResult }
|
|
1348
|
-
);
|
|
1349
|
-
handler.onSpaceCreationFailed?.(creationContext, err2);
|
|
1350
|
-
throw err2;
|
|
1351
|
-
}
|
|
1352
|
-
handler.onSpaceCreated?.(creationContext);
|
|
1353
|
-
return;
|
|
1354
|
-
}
|
|
1355
|
-
throw Object.assign(
|
|
1356
|
-
new Error(`Failed to activate session: ${describeHostFailure(result)}`),
|
|
1357
|
-
{ cause: result }
|
|
1358
|
-
);
|
|
1315
|
+
const { createPrimarySpace } = await import("./space-hosting.js");
|
|
1316
|
+
await createPrimarySpace({
|
|
1317
|
+
handler,
|
|
1318
|
+
context: creationContext,
|
|
1319
|
+
guard: () => this.guardSpaceCreation(handler, creationContext),
|
|
1320
|
+
host: () => this.hostSpace(primarySpaceId),
|
|
1321
|
+
onHosted: () => {
|
|
1322
|
+
this._spaceHosting = "hosted";
|
|
1323
|
+
},
|
|
1324
|
+
activate: () => activateSessionWithHost(host, session.delegationHeader)
|
|
1325
|
+
});
|
|
1359
1326
|
}
|
|
1360
1327
|
/** {@link assertMayCreateSpace}, reporting a refusal to the creation handler before rethrowing it. */
|
|
1361
1328
|
async guardSpaceCreation(handler, context) {
|
|
@@ -1371,10 +1338,12 @@ var NodeUserAuthorization = class {
|
|
|
1371
1338
|
if (result.success) {
|
|
1372
1339
|
this._lastActivationSkippedSpaceIds = result.skipped ?? [];
|
|
1373
1340
|
this._lastActivationActivatedSpaceIds = result.activated ?? [];
|
|
1341
|
+
this._spaceHosting = this._lastActivationSkippedSpaceIds.includes(primarySpaceId) ? "not-hosted" : this._lastActivationActivatedSpaceIds.includes(primarySpaceId) ? "hosted" : "unknown";
|
|
1374
1342
|
return;
|
|
1375
1343
|
}
|
|
1376
1344
|
this._lastActivationActivatedSpaceIds = [];
|
|
1377
1345
|
this._lastActivationSkippedSpaceIds = result.status === 404 ? [primarySpaceId] : [];
|
|
1346
|
+
this._spaceHosting = result.status === 404 ? "not-hosted" : "unknown";
|
|
1378
1347
|
}
|
|
1379
1348
|
async createBootstrapSession(options) {
|
|
1380
1349
|
refuseCaveated(options.capabilityRequest.manifests);
|
|
@@ -4116,6 +4085,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4116
4085
|
* hosting is confirmed against the session that was active at the time.
|
|
4117
4086
|
*/
|
|
4118
4087
|
this.confirmedHostedSpaceIds = /* @__PURE__ */ new Set();
|
|
4088
|
+
/** The primary space's hosting answer when no authorization layer holds it (a session-only restore). */
|
|
4089
|
+
this._restoredSpaceHosting = "unknown";
|
|
4119
4090
|
/**
|
|
4120
4091
|
* Owned space ids known to be hosted for the current session: the sign-in
|
|
4121
4092
|
* activation listed them as `activated`, or this session hosted them. Unlike
|
|
@@ -4454,6 +4425,84 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4454
4425
|
));
|
|
4455
4426
|
}
|
|
4456
4427
|
}
|
|
4428
|
+
/**
|
|
4429
|
+
* Whether the TinyCloud node hosts the primary space (the default) or a named
|
|
4430
|
+
* or full-id space: `"hosted"`, `"not-hosted"`, or `"unknown"` when the node
|
|
4431
|
+
* cannot say.
|
|
4432
|
+
*
|
|
4433
|
+
* Sends one authorized read the session already holds on that space (a kv
|
|
4434
|
+
* list under a granted prefix, else kv metadata, `tinycloud.space/info`, or
|
|
4435
|
+
* a kv get of a key that does not exist), signed for that space. A session
|
|
4436
|
+
* with no such read sends nothing and answers `unknown`. A 401/403 registers
|
|
4437
|
+
* the session delegation with the node once and asks again once. Network
|
|
4438
|
+
* failures, 5xx and a 5 s timeout answer `unknown`; this never throws.
|
|
4439
|
+
*
|
|
4440
|
+
* `hosted` is remembered for the session and `not-hosted` never is. The
|
|
4441
|
+
* answer for the primary space is also what {@link spaceHosting} reports; a
|
|
4442
|
+
* `unknown` answer leaves the previous one in place.
|
|
4443
|
+
*/
|
|
4444
|
+
async checkSpaceHosting(space) {
|
|
4445
|
+
try {
|
|
4446
|
+
return await this.probeSpaceHosting(space);
|
|
4447
|
+
} catch {
|
|
4448
|
+
return "unknown";
|
|
4449
|
+
}
|
|
4450
|
+
}
|
|
4451
|
+
/**
|
|
4452
|
+
* The node's last answer for the primary space: recorded at sign-in from the
|
|
4453
|
+
* activation, or by {@link checkSpaceHosting}. `unknown` after a restore until
|
|
4454
|
+
* something asks.
|
|
4455
|
+
*/
|
|
4456
|
+
get spaceHosting() {
|
|
4457
|
+
return this.auth ? this.auth.spaceHosting : this._restoredSpaceHosting;
|
|
4458
|
+
}
|
|
4459
|
+
async probeSpaceHosting(space) {
|
|
4460
|
+
const context = this._serviceContext;
|
|
4461
|
+
const session = context?.session;
|
|
4462
|
+
const host = context?.hosts[0];
|
|
4463
|
+
if (!context || !session || !host) {
|
|
4464
|
+
return "unknown";
|
|
4465
|
+
}
|
|
4466
|
+
const spaceId = space === void 0 ? session.spaceId : space.startsWith("tinycloud:") ? space : this.ownedSpaceId(space);
|
|
4467
|
+
const graph = this._serviceGraph;
|
|
4468
|
+
const epoch = this.sessionEpoch;
|
|
4469
|
+
const assertCurrent = () => {
|
|
4470
|
+
graph.assertActive();
|
|
4471
|
+
if (epoch !== this.sessionEpoch || graph !== this._serviceGraph || this._serviceContext !== context) {
|
|
4472
|
+
throw new Error("The session changed during the hosting check.");
|
|
4473
|
+
}
|
|
4474
|
+
};
|
|
4475
|
+
const { askSpaceHosting } = await import("./space-hosting.js");
|
|
4476
|
+
assertCurrent();
|
|
4477
|
+
this.pruneExpiredRuntimePermissionGrants();
|
|
4478
|
+
const primary = this.currentTinyCloudSession();
|
|
4479
|
+
const answer = await askSpaceHosting({
|
|
4480
|
+
spaceId,
|
|
4481
|
+
operations: [
|
|
4482
|
+
...this.runtimePermissionGrants.flatMap((grant) => grant.operations),
|
|
4483
|
+
...primary ? this.recapOperationsFromSession(primary) : []
|
|
4484
|
+
],
|
|
4485
|
+
covers: (granted, requested) => this.operationCovers(granted, requested),
|
|
4486
|
+
scope: context,
|
|
4487
|
+
host,
|
|
4488
|
+
fetch: unrecordedFetchOf(context),
|
|
4489
|
+
sign: (entries) => {
|
|
4490
|
+
assertCurrent();
|
|
4491
|
+
return graph.invokeAny({ ...session, spaceId }, entries);
|
|
4492
|
+
},
|
|
4493
|
+
// A session saved but never registered on this node is refused: it registers once.
|
|
4494
|
+
activate: (signal) => {
|
|
4495
|
+
assertCurrent();
|
|
4496
|
+
return activateSessionWithHost2(host, session.delegationHeader, AbortSignal.any([signal, graph.signal]));
|
|
4497
|
+
}
|
|
4498
|
+
});
|
|
4499
|
+
assertCurrent();
|
|
4500
|
+
if (answer !== "unknown" && this.spaceIdsEqual(spaceId, session.spaceId)) {
|
|
4501
|
+
if (this.auth) this.auth.noteSpaceHosting(answer);
|
|
4502
|
+
else this._restoredSpaceHosting = answer;
|
|
4503
|
+
}
|
|
4504
|
+
return answer;
|
|
4505
|
+
}
|
|
4457
4506
|
get nodeFeatures() {
|
|
4458
4507
|
return this.auth?.nodeFeatures ?? this._restoredNodeFeatures ?? [];
|
|
4459
4508
|
}
|
|
@@ -4945,6 +4994,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4945
4994
|
this._spaceService = void 0;
|
|
4946
4995
|
this.runtimePermissionGrants = [];
|
|
4947
4996
|
this._recapOperationsCache = void 0;
|
|
4997
|
+
this._restoredSpaceHosting = "unknown";
|
|
4948
4998
|
this.confirmedHostedSpaceIds.clear();
|
|
4949
4999
|
this.hostedOwnedSpaceIds.clear();
|
|
4950
5000
|
this.cancelOwnedSpaceHosts();
|
|
@@ -5138,6 +5188,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5138
5188
|
const primarySession = this.currentTinyCloudSession();
|
|
5139
5189
|
if (primarySession) {
|
|
5140
5190
|
this.registerPrimarySessionGrant(primarySession);
|
|
5191
|
+
if (this.auth?.spaceHosting === "unknown") {
|
|
5192
|
+
await this.checkSpaceHosting();
|
|
5193
|
+
this.assertSessionEpoch(epoch, "Sign-in");
|
|
5194
|
+
}
|
|
5141
5195
|
}
|
|
5142
5196
|
const bootstrapped = await this.bootstrapAccountIfNeeded();
|
|
5143
5197
|
this.assertSessionEpoch(epoch, "Sign-in");
|
|
@@ -6517,6 +6571,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6517
6571
|
this.tc = stagedGraph.core;
|
|
6518
6572
|
this._recapOperationsCache = stagedPrimary.cache;
|
|
6519
6573
|
this.runtimePermissionGrants = stagedPrimary.grants;
|
|
6574
|
+
this._restoredSpaceHosting = "unknown";
|
|
6520
6575
|
this.confirmedHostedSpaceIds.clear();
|
|
6521
6576
|
this.hostedOwnedSpaceIds.clear();
|
|
6522
6577
|
this.cancelOwnedSpaceHosts();
|