@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.
Files changed (35) hide show
  1. package/dist/NodeUserAuthorization-BtoDI9in.d.cts +900 -0
  2. package/dist/NodeUserAuthorization-BtoDI9in.d.ts +900 -0
  3. package/dist/{TinyCloudNode-AUotFGzy.d.ts → TinyCloudNode-C24728N_.d.cts} +30 -875
  4. package/dist/{TinyCloudNode-BmpjkpWR.d.cts → TinyCloudNode-DLrINr98.d.ts} +30 -875
  5. package/dist/{authority-dRnJD4iL.d.ts → authority-BQN2Z3st.d.ts} +1 -1
  6. package/dist/{authority-BYSEyjDI.d.cts → authority-DDdheOL6.d.cts} +1 -1
  7. package/dist/core.cjs +145 -90
  8. package/dist/core.cjs.map +1 -1
  9. package/dist/core.d.cts +5 -4
  10. package/dist/core.d.ts +5 -4
  11. package/dist/core.js +145 -90
  12. package/dist/core.js.map +1 -1
  13. package/dist/credentials-core.d.cts +1 -1
  14. package/dist/credentials-core.d.ts +1 -1
  15. package/dist/credentials.d.cts +1 -1
  16. package/dist/credentials.d.ts +1 -1
  17. package/dist/{delegation-Ckc3UETl.d.cts → delegation-BQbAuKad.d.cts} +1 -1
  18. package/dist/{delegation-Ckc3UETl.d.ts → delegation-BQbAuKad.d.ts} +1 -1
  19. package/dist/encryption-keys.d.cts +3 -2
  20. package/dist/encryption-keys.d.ts +3 -2
  21. package/dist/index.cjs +145 -90
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +4 -3
  24. package/dist/index.d.ts +4 -3
  25. package/dist/index.js +145 -90
  26. package/dist/index.js.map +1 -1
  27. package/dist/replication/authority.d.cts +4 -3
  28. package/dist/replication/authority.d.ts +4 -3
  29. package/dist/space-hosting.cjs +141 -0
  30. package/dist/space-hosting.cjs.map +1 -0
  31. package/dist/space-hosting.d.cts +69 -0
  32. package/dist/space-hosting.d.ts +69 -0
  33. package/dist/space-hosting.js +115 -0
  34. package/dist/space-hosting.js.map +1 -0
  35. package/package.json +11 -1
@@ -1,5 +1,5 @@
1
1
  import { CredentialFlowDescriptor, CredentialRequirement, CredentialHolderBinding, IssuedCredentialEnvelope, CredentialIssuerMetadata, ClientSession, IKVService, StoredCredentialRecord, VerifiedCredential, CredentialProgressEvent, CredentialStorageReceipt, UnifiedPolicyV2, UnifiedPolicyCapability, PolicyCredentialAdmissionV3 } from '@tinycloud/sdk-core';
2
- import { V as ValidatedRuntimeDelegation } from './delegation-Ckc3UETl.cjs';
2
+ import { V as ValidatedRuntimeDelegation } from './delegation-BQbAuKad.cjs';
3
3
 
4
4
  interface CredentialClient {
5
5
  readonly sessionDid: string;
@@ -1,5 +1,5 @@
1
1
  import { CredentialFlowDescriptor, CredentialRequirement, CredentialHolderBinding, IssuedCredentialEnvelope, CredentialIssuerMetadata, ClientSession, IKVService, StoredCredentialRecord, VerifiedCredential, CredentialProgressEvent, CredentialStorageReceipt, UnifiedPolicyV2, UnifiedPolicyCapability, PolicyCredentialAdmissionV3 } from '@tinycloud/sdk-core';
2
- import { V as ValidatedRuntimeDelegation } from './delegation-Ckc3UETl.js';
2
+ import { V as ValidatedRuntimeDelegation } from './delegation-BQbAuKad.js';
3
3
 
4
4
  interface CredentialClient {
5
5
  readonly sessionDid: string;
@@ -1,7 +1,7 @@
1
1
  export { CredentialAcquisitionTheme, CredentialAcquisitionTransport, CredentialBrowserInteractionAdapter, CredentialClient, CredentialInlineInteractionAdapter, CredentialInputRequest, CredentialInteractionAdapter, CredentialInteractionKind, CredentialInteractionSurface, CredentialProofSubject, CredentialRedirectResumeState, CredentialRedirectStore, CredentialRequestState, CredentialSigningAdapter, CredentialsAcquireOptions, CredentialsEnsureOptions, CredentialsEnsureResult, CredentialsOperationOptions, CredentialsPolicyAdmissionOptions, CredentialsPolicyAdmissionResult, HolderSignatureKey, InlineCredentialProofHandler, InlineCredentialProofRequest, OpenCredentialsHttpTransport, PrimitiveStepHandler, PrimitiveStepResult, ReceiverCredentialCustody, interpretCredentialFlow, mailboxSubject } from './credentials-core.cjs';
2
2
  export { D as DEFAULT_EMAIL_PROOF_PROFILE, b as EMAIL_PROOF_CREDENTIAL_TYPE, c as EMAIL_PROOF_PENDING_MAX_MS, d as EmailProofAcquireInput, e as EmailProofAcquisition, f as EmailProofError, g as EmailProofErrorCode, h as EmailProofOptions, a as EmailProofPending, E as EmailProofPendingStore, i as EmailProofProfileId, j as EmailProofRequestInput, k as EmailProofResult, l as EmailProofStep, H as HolderAlgorithm, m as HolderSigner, S as StoredEmailProofInput, n as StoredEmailProofRecord, o as acquireEmailProof, p as completeEmailProof, q as createEd25519HolderSigner, r as createMemoryEmailProofPendingStore, s as emailProofRequirement, t as isTicketEmailProofResult, u as requestEmailProofCode, v as verifyStoredEmailProof } from './email-proof-B4DRizIL.cjs';
3
3
  import '@tinycloud/sdk-core';
4
- import './delegation-Ckc3UETl.cjs';
4
+ import './delegation-BQbAuKad.cjs';
5
5
  import '@tinycloud/sdk-core/held-credentials';
6
6
 
7
7
  /** Production pins. Credentials verify only against these values. Tests pin them literally. */
@@ -1,7 +1,7 @@
1
1
  export { CredentialAcquisitionTheme, CredentialAcquisitionTransport, CredentialBrowserInteractionAdapter, CredentialClient, CredentialInlineInteractionAdapter, CredentialInputRequest, CredentialInteractionAdapter, CredentialInteractionKind, CredentialInteractionSurface, CredentialProofSubject, CredentialRedirectResumeState, CredentialRedirectStore, CredentialRequestState, CredentialSigningAdapter, CredentialsAcquireOptions, CredentialsEnsureOptions, CredentialsEnsureResult, CredentialsOperationOptions, CredentialsPolicyAdmissionOptions, CredentialsPolicyAdmissionResult, HolderSignatureKey, InlineCredentialProofHandler, InlineCredentialProofRequest, OpenCredentialsHttpTransport, PrimitiveStepHandler, PrimitiveStepResult, ReceiverCredentialCustody, interpretCredentialFlow, mailboxSubject } from './credentials-core.js';
2
2
  export { D as DEFAULT_EMAIL_PROOF_PROFILE, b as EMAIL_PROOF_CREDENTIAL_TYPE, c as EMAIL_PROOF_PENDING_MAX_MS, d as EmailProofAcquireInput, e as EmailProofAcquisition, f as EmailProofError, g as EmailProofErrorCode, h as EmailProofOptions, a as EmailProofPending, E as EmailProofPendingStore, i as EmailProofProfileId, j as EmailProofRequestInput, k as EmailProofResult, l as EmailProofStep, H as HolderAlgorithm, m as HolderSigner, S as StoredEmailProofInput, n as StoredEmailProofRecord, o as acquireEmailProof, p as completeEmailProof, q as createEd25519HolderSigner, r as createMemoryEmailProofPendingStore, s as emailProofRequirement, t as isTicketEmailProofResult, u as requestEmailProofCode, v as verifyStoredEmailProof } from './email-proof-B4DRizIL.js';
3
3
  import '@tinycloud/sdk-core';
4
- import './delegation-Ckc3UETl.js';
4
+ import './delegation-BQbAuKad.js';
5
5
  import '@tinycloud/sdk-core/held-credentials';
6
6
 
7
7
  /** Production pins. Credentials verify only against these values. Tests pin them literally. */
@@ -248,4 +248,4 @@ declare function serializeDelegation(delegation: PortableDelegation): string;
248
248
  */
249
249
  declare function deserializeDelegation(data: string): PortableDelegation;
250
250
 
251
- export { type AuthDelegationArtifact as A, type CompactRuntimeDelegationInput as C, type DelegationAuthority as D, type PortableDelegation as P, RuntimeDelegationRejectedError as R, type SessionGrantProof as S, type ValidatedRuntimeDelegation as V, type RuntimeDelegationRejection as a, activateCompactRuntimeDelegation as b, activateValidatedRuntimeDelegation as c, deserializeDelegation as d, type AuthRequestArtifact as e, RUNTIME_DELEGATION_REJECTIONS as f, type RuntimeDelegationActivator as g, type VerifiedSessionGrant as h, grantAuthRequest as i, signedCompactUcanExpiry as j, siweRuntimeDelegation as k, serializeDelegation as s };
251
+ export { type AuthDelegationArtifact as A, type CompactRuntimeDelegationInput as C, type DelegationAuthority as D, type PortableDelegation as P, RuntimeDelegationRejectedError as R, type SessionGrantProof as S, type ValidatedRuntimeDelegation as V, type RuntimeDelegationRejection as a, activateCompactRuntimeDelegation as b, activateValidatedRuntimeDelegation as c, deserializeDelegation as d, type VerifiedSessionGrant as e, type AuthRequestArtifact as f, RUNTIME_DELEGATION_REJECTIONS as g, type RuntimeDelegationActivator as h, grantAuthRequest as i, signedCompactUcanExpiry as j, siweRuntimeDelegation as k, serializeDelegation as s };
@@ -248,4 +248,4 @@ declare function serializeDelegation(delegation: PortableDelegation): string;
248
248
  */
249
249
  declare function deserializeDelegation(data: string): PortableDelegation;
250
250
 
251
- export { type AuthDelegationArtifact as A, type CompactRuntimeDelegationInput as C, type DelegationAuthority as D, type PortableDelegation as P, RuntimeDelegationRejectedError as R, type SessionGrantProof as S, type ValidatedRuntimeDelegation as V, type RuntimeDelegationRejection as a, activateCompactRuntimeDelegation as b, activateValidatedRuntimeDelegation as c, deserializeDelegation as d, type AuthRequestArtifact as e, RUNTIME_DELEGATION_REJECTIONS as f, type RuntimeDelegationActivator as g, type VerifiedSessionGrant as h, grantAuthRequest as i, signedCompactUcanExpiry as j, siweRuntimeDelegation as k, serializeDelegation as s };
251
+ export { type AuthDelegationArtifact as A, type CompactRuntimeDelegationInput as C, type DelegationAuthority as D, type PortableDelegation as P, RuntimeDelegationRejectedError as R, type SessionGrantProof as S, type ValidatedRuntimeDelegation as V, type RuntimeDelegationRejection as a, activateCompactRuntimeDelegation as b, activateValidatedRuntimeDelegation as c, deserializeDelegation as d, type VerifiedSessionGrant as e, type AuthRequestArtifact as f, RUNTIME_DELEGATION_REJECTIONS as g, type RuntimeDelegationActivator as h, grantAuthRequest as i, signedCompactUcanExpiry as j, siweRuntimeDelegation as k, serializeDelegation as s };
@@ -1,11 +1,12 @@
1
1
  import { NamedKeyClient } from '@tinycloud/sdk-services/encryption/named-keys';
2
2
  export { DecryptManyResult, KeyCallOptions, KeyDescriptor, KeyEncryptOptions, NamedKeyClient, NamedKeyEnvelope, NamedKeyError, NamedKeyErrorCode, PublicKeyDescriptor, buildKeyAdminFacts, buildKeyDescribeFacts } from '@tinycloud/sdk-services/encryption/named-keys';
3
- import { T as TinyCloudNode } from './TinyCloudNode-BmpjkpWR.cjs';
3
+ import { T as TinyCloudNode } from './TinyCloudNode-C24728N_.cjs';
4
4
  import '@tinycloud/sdk-core';
5
5
  import '@tinycloud/sdk-services/kv/replication';
6
6
  import '@tinycloud/sdk-services';
7
+ import './NodeUserAuthorization-BtoDI9in.cjs';
7
8
  import 'events';
8
- import './delegation-Ckc3UETl.cjs';
9
+ import './delegation-BQbAuKad.cjs';
9
10
 
10
11
  /**
11
12
  * Named encryption keys for a signed-in {@link TinyCloudNode}.
@@ -1,11 +1,12 @@
1
1
  import { NamedKeyClient } from '@tinycloud/sdk-services/encryption/named-keys';
2
2
  export { DecryptManyResult, KeyCallOptions, KeyDescriptor, KeyEncryptOptions, NamedKeyClient, NamedKeyEnvelope, NamedKeyError, NamedKeyErrorCode, PublicKeyDescriptor, buildKeyAdminFacts, buildKeyDescribeFacts } from '@tinycloud/sdk-services/encryption/named-keys';
3
- import { T as TinyCloudNode } from './TinyCloudNode-AUotFGzy.js';
3
+ import { T as TinyCloudNode } from './TinyCloudNode-DLrINr98.js';
4
4
  import '@tinycloud/sdk-core';
5
5
  import '@tinycloud/sdk-services/kv/replication';
6
6
  import '@tinycloud/sdk-services';
7
+ import './NodeUserAuthorization-BtoDI9in.js';
7
8
  import 'events';
8
- import './delegation-Ckc3UETl.js';
9
+ import './delegation-BQbAuKad.js';
9
10
 
10
11
  /**
11
12
  * Named encryption keys for a signed-in {@link TinyCloudNode}.
package/dist/index.cjs CHANGED
@@ -19073,6 +19073,8 @@ var NodeUserAuthorization = class {
19073
19073
  * delegation lists them: the node answers a repeat with empty lists.
19074
19074
  */
19075
19075
  this._lastActivationActivatedSpaceIds = [];
19076
+ /** See {@link spaceHosting}. Written only from node answers. */
19077
+ this._spaceHosting = "unknown";
19076
19078
  this.wasm = config.wasmBindings;
19077
19079
  this.signer = config.signer;
19078
19080
  this.signStrategy = config.signStrategy ?? defaultSignStrategy;
@@ -19232,6 +19234,7 @@ var NodeUserAuthorization = class {
19232
19234
  this.registryVerdict = void 0;
19233
19235
  this._lastActivationSkippedSpaceIds = [];
19234
19236
  this._lastActivationActivatedSpaceIds = [];
19237
+ this._spaceHosting = "unknown";
19235
19238
  if (!session) {
19236
19239
  this._session = void 0;
19237
19240
  this._tinyCloudSession = void 0;
@@ -19372,6 +19375,18 @@ var NodeUserAuthorization = class {
19372
19375
  get lastActivationActivatedSpaceIds() {
19373
19376
  return [...this._lastActivationActivatedSpaceIds];
19374
19377
  }
19378
+ /**
19379
+ * The node's last answer for whether this session's primary space is hosted:
19380
+ * recorded from the sign-in activation, or by {@link noteSpaceHosting}.
19381
+ * `unknown` until one of them answers, and after a restore.
19382
+ */
19383
+ get spaceHosting() {
19384
+ return this._spaceHosting;
19385
+ }
19386
+ /** @internal Record the hosting probe's answer for the primary space. */
19387
+ noteSpaceHosting(hosting) {
19388
+ this._spaceHosting = hosting;
19389
+ }
19375
19390
  /**
19376
19391
  * Compute the `abilities` map the WASM `prepareSession` call should
19377
19392
  * see at sign-in time.
@@ -19832,103 +19847,55 @@ var NodeUserAuthorization = class {
19832
19847
  this._tinyCloudSession.delegationHeader
19833
19848
  );
19834
19849
  this.recordActivationSkippedSpaces(result, primarySpaceId);
19850
+ if (!result.success && result.status !== 404) {
19851
+ throw Object.assign(
19852
+ new Error(`Failed to activate session: ${describeHostFailure(result)}`),
19853
+ { cause: result }
19854
+ );
19855
+ }
19856
+ await this.ensurePrimarySpaceHosted(this._spaceHosting);
19857
+ }
19858
+ /**
19859
+ * The create step of {@link ensureSpaceExists}: given the node's answer for
19860
+ * the primary space, host it through the space creation handler when it is
19861
+ * `not-hosted`. Any other answer, and a missing handler, change nothing. The
19862
+ * caller supplies the answer (sign-in's activation, or the hosting probe);
19863
+ * an empty activation list is never one.
19864
+ *
19865
+ * @throws Error if the creation handler fails or times out, or hosting fails
19866
+ */
19867
+ async ensurePrimarySpaceHosted(hosting) {
19868
+ if (hosting !== "not-hosted") {
19869
+ return;
19870
+ }
19871
+ const session = this._tinyCloudSession;
19872
+ if (!session) {
19873
+ throw new Error("Must be signed in to host the primary space");
19874
+ }
19835
19875
  const handler = this.spaceCreationHandler ?? (this.autoCreateSpace ? new import_sdk_core5.AutoApproveSpaceCreationHandler() : void 0);
19876
+ if (!handler) {
19877
+ return;
19878
+ }
19879
+ await this.ensureTinyCloudHosts();
19880
+ const host = this.primaryTinyCloudHost;
19881
+ const primarySpaceId = session.spaceId;
19836
19882
  const creationContext = {
19837
19883
  spaceId: primarySpaceId,
19838
19884
  address: this._address,
19839
19885
  chainId: this._chainId,
19840
19886
  host
19841
19887
  };
19842
- if (result.success) {
19843
- const primarySkipped = result.skipped?.includes(primarySpaceId);
19844
- if (!primarySkipped) {
19845
- return;
19846
- }
19847
- if (!handler) {
19848
- return;
19849
- }
19850
- await this.guardSpaceCreation(handler, creationContext);
19851
- const confirmed = await handler.confirmSpaceCreation(creationContext);
19852
- if (!confirmed) {
19853
- return;
19854
- }
19855
- try {
19856
- const created = await this.hostSpace();
19857
- if (!created.success) {
19858
- const err2 = Object.assign(
19859
- new Error(`Failed to create space ${primarySpaceId}: ${describeHostFailure(created)}`),
19860
- { cause: created }
19861
- );
19862
- throw err2;
19863
- }
19864
- } catch (error) {
19865
- handler.onSpaceCreationFailed?.(
19866
- creationContext,
19867
- error instanceof Error ? error : new Error(String(error))
19868
- );
19869
- throw error;
19870
- }
19871
- await new Promise((resolve2) => setTimeout(resolve2, 100));
19872
- const retryResult = await (0, import_sdk_core5.activateSessionWithHost)(
19873
- host,
19874
- this._tinyCloudSession.delegationHeader
19875
- );
19876
- if (!retryResult.success) {
19877
- const err2 = Object.assign(
19878
- new Error(`Failed to activate session after creating space: ${describeHostFailure(retryResult)}`),
19879
- { cause: retryResult }
19880
- );
19881
- handler.onSpaceCreationFailed?.(creationContext, err2);
19882
- throw err2;
19883
- }
19884
- handler.onSpaceCreated?.(creationContext);
19885
- return;
19886
- }
19887
- if (result.status === 404) {
19888
- if (!handler) {
19889
- return;
19890
- }
19891
- await this.guardSpaceCreation(handler, creationContext);
19892
- const confirmed = await handler.confirmSpaceCreation(creationContext);
19893
- if (!confirmed) {
19894
- return;
19895
- }
19896
- try {
19897
- const created = await this.hostSpace();
19898
- if (!created.success) {
19899
- const err2 = Object.assign(
19900
- new Error(`Failed to create space ${primarySpaceId}: ${describeHostFailure(created)}`),
19901
- { cause: created }
19902
- );
19903
- throw err2;
19904
- }
19905
- } catch (error) {
19906
- handler.onSpaceCreationFailed?.(
19907
- creationContext,
19908
- error instanceof Error ? error : new Error(String(error))
19909
- );
19910
- throw error;
19911
- }
19912
- await new Promise((resolve2) => setTimeout(resolve2, 100));
19913
- const retryResult = await (0, import_sdk_core5.activateSessionWithHost)(
19914
- host,
19915
- this._tinyCloudSession.delegationHeader
19916
- );
19917
- if (!retryResult.success) {
19918
- const err2 = Object.assign(
19919
- new Error(`Failed to activate session after creating space: ${describeHostFailure(retryResult)}`),
19920
- { cause: retryResult }
19921
- );
19922
- handler.onSpaceCreationFailed?.(creationContext, err2);
19923
- throw err2;
19924
- }
19925
- handler.onSpaceCreated?.(creationContext);
19926
- return;
19927
- }
19928
- throw Object.assign(
19929
- new Error(`Failed to activate session: ${describeHostFailure(result)}`),
19930
- { cause: result }
19931
- );
19888
+ const { createPrimarySpace } = await import("./space-hosting.cjs");
19889
+ await createPrimarySpace({
19890
+ handler,
19891
+ context: creationContext,
19892
+ guard: () => this.guardSpaceCreation(handler, creationContext),
19893
+ host: () => this.hostSpace(primarySpaceId),
19894
+ onHosted: () => {
19895
+ this._spaceHosting = "hosted";
19896
+ },
19897
+ activate: () => (0, import_sdk_core5.activateSessionWithHost)(host, session.delegationHeader)
19898
+ });
19932
19899
  }
19933
19900
  /** {@link assertMayCreateSpace}, reporting a refusal to the creation handler before rethrowing it. */
19934
19901
  async guardSpaceCreation(handler, context) {
@@ -19944,10 +19911,12 @@ var NodeUserAuthorization = class {
19944
19911
  if (result.success) {
19945
19912
  this._lastActivationSkippedSpaceIds = result.skipped ?? [];
19946
19913
  this._lastActivationActivatedSpaceIds = result.activated ?? [];
19914
+ this._spaceHosting = this._lastActivationSkippedSpaceIds.includes(primarySpaceId) ? "not-hosted" : this._lastActivationActivatedSpaceIds.includes(primarySpaceId) ? "hosted" : "unknown";
19947
19915
  return;
19948
19916
  }
19949
19917
  this._lastActivationActivatedSpaceIds = [];
19950
19918
  this._lastActivationSkippedSpaceIds = result.status === 404 ? [primarySpaceId] : [];
19919
+ this._spaceHosting = result.status === 404 ? "not-hosted" : "unknown";
19951
19920
  }
19952
19921
  async createBootstrapSession(options) {
19953
19922
  refuseCaveated(options.capabilityRequest.manifests);
@@ -21886,6 +21855,8 @@ var _TinyCloudNode = class _TinyCloudNode {
21886
21855
  * hosting is confirmed against the session that was active at the time.
21887
21856
  */
21888
21857
  this.confirmedHostedSpaceIds = /* @__PURE__ */ new Set();
21858
+ /** The primary space's hosting answer when no authorization layer holds it (a session-only restore). */
21859
+ this._restoredSpaceHosting = "unknown";
21889
21860
  /**
21890
21861
  * Owned space ids known to be hosted for the current session: the sign-in
21891
21862
  * activation listed them as `activated`, or this session hosted them. Unlike
@@ -22224,6 +22195,84 @@ var _TinyCloudNode = class _TinyCloudNode {
22224
22195
  ));
22225
22196
  }
22226
22197
  }
22198
+ /**
22199
+ * Whether the TinyCloud node hosts the primary space (the default) or a named
22200
+ * or full-id space: `"hosted"`, `"not-hosted"`, or `"unknown"` when the node
22201
+ * cannot say.
22202
+ *
22203
+ * Sends one authorized read the session already holds on that space (a kv
22204
+ * list under a granted prefix, else kv metadata, `tinycloud.space/info`, or
22205
+ * a kv get of a key that does not exist), signed for that space. A session
22206
+ * with no such read sends nothing and answers `unknown`. A 401/403 registers
22207
+ * the session delegation with the node once and asks again once. Network
22208
+ * failures, 5xx and a 5 s timeout answer `unknown`; this never throws.
22209
+ *
22210
+ * `hosted` is remembered for the session and `not-hosted` never is. The
22211
+ * answer for the primary space is also what {@link spaceHosting} reports; a
22212
+ * `unknown` answer leaves the previous one in place.
22213
+ */
22214
+ async checkSpaceHosting(space) {
22215
+ try {
22216
+ return await this.probeSpaceHosting(space);
22217
+ } catch {
22218
+ return "unknown";
22219
+ }
22220
+ }
22221
+ /**
22222
+ * The node's last answer for the primary space: recorded at sign-in from the
22223
+ * activation, or by {@link checkSpaceHosting}. `unknown` after a restore until
22224
+ * something asks.
22225
+ */
22226
+ get spaceHosting() {
22227
+ return this.auth ? this.auth.spaceHosting : this._restoredSpaceHosting;
22228
+ }
22229
+ async probeSpaceHosting(space) {
22230
+ const context = this._serviceContext;
22231
+ const session = context?.session;
22232
+ const host = context?.hosts[0];
22233
+ if (!context || !session || !host) {
22234
+ return "unknown";
22235
+ }
22236
+ const spaceId = space === void 0 ? session.spaceId : space.startsWith("tinycloud:") ? space : this.ownedSpaceId(space);
22237
+ const graph = this._serviceGraph;
22238
+ const epoch = this.sessionEpoch;
22239
+ const assertCurrent = () => {
22240
+ graph.assertActive();
22241
+ if (epoch !== this.sessionEpoch || graph !== this._serviceGraph || this._serviceContext !== context) {
22242
+ throw new Error("The session changed during the hosting check.");
22243
+ }
22244
+ };
22245
+ const { askSpaceHosting } = await import("./space-hosting.cjs");
22246
+ assertCurrent();
22247
+ this.pruneExpiredRuntimePermissionGrants();
22248
+ const primary = this.currentTinyCloudSession();
22249
+ const answer = await askSpaceHosting({
22250
+ spaceId,
22251
+ operations: [
22252
+ ...this.runtimePermissionGrants.flatMap((grant) => grant.operations),
22253
+ ...primary ? this.recapOperationsFromSession(primary) : []
22254
+ ],
22255
+ covers: (granted, requested) => this.operationCovers(granted, requested),
22256
+ scope: context,
22257
+ host,
22258
+ fetch: unrecordedFetchOf(context),
22259
+ sign: (entries) => {
22260
+ assertCurrent();
22261
+ return graph.invokeAny({ ...session, spaceId }, entries);
22262
+ },
22263
+ // A session saved but never registered on this node is refused: it registers once.
22264
+ activate: (signal) => {
22265
+ assertCurrent();
22266
+ return (0, import_sdk_core10.activateSessionWithHost)(host, session.delegationHeader, AbortSignal.any([signal, graph.signal]));
22267
+ }
22268
+ });
22269
+ assertCurrent();
22270
+ if (answer !== "unknown" && this.spaceIdsEqual(spaceId, session.spaceId)) {
22271
+ if (this.auth) this.auth.noteSpaceHosting(answer);
22272
+ else this._restoredSpaceHosting = answer;
22273
+ }
22274
+ return answer;
22275
+ }
22227
22276
  get nodeFeatures() {
22228
22277
  return this.auth?.nodeFeatures ?? this._restoredNodeFeatures ?? [];
22229
22278
  }
@@ -22715,6 +22764,7 @@ var _TinyCloudNode = class _TinyCloudNode {
22715
22764
  this._spaceService = void 0;
22716
22765
  this.runtimePermissionGrants = [];
22717
22766
  this._recapOperationsCache = void 0;
22767
+ this._restoredSpaceHosting = "unknown";
22718
22768
  this.confirmedHostedSpaceIds.clear();
22719
22769
  this.hostedOwnedSpaceIds.clear();
22720
22770
  this.cancelOwnedSpaceHosts();
@@ -22908,6 +22958,10 @@ var _TinyCloudNode = class _TinyCloudNode {
22908
22958
  const primarySession = this.currentTinyCloudSession();
22909
22959
  if (primarySession) {
22910
22960
  this.registerPrimarySessionGrant(primarySession);
22961
+ if (this.auth?.spaceHosting === "unknown") {
22962
+ await this.checkSpaceHosting();
22963
+ this.assertSessionEpoch(epoch, "Sign-in");
22964
+ }
22911
22965
  }
22912
22966
  const bootstrapped = await this.bootstrapAccountIfNeeded();
22913
22967
  this.assertSessionEpoch(epoch, "Sign-in");
@@ -24287,6 +24341,7 @@ var _TinyCloudNode = class _TinyCloudNode {
24287
24341
  this.tc = stagedGraph.core;
24288
24342
  this._recapOperationsCache = stagedPrimary.cache;
24289
24343
  this.runtimePermissionGrants = stagedPrimary.grants;
24344
+ this._restoredSpaceHosting = "unknown";
24290
24345
  this.confirmedHostedSpaceIds.clear();
24291
24346
  this.hostedOwnedSpaceIds.clear();
24292
24347
  this.cancelOwnedSpaceHosts();