@tinycloud/node-sdk 2.2.0-beta.4 → 2.2.0-beta.5

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.
@@ -877,6 +877,7 @@ declare class TinyCloudNode {
877
877
  signIn(options?: SignInOptions): Promise<void>;
878
878
  private ownedSpaceId;
879
879
  private writeManifestRegistryRecords;
880
+ private ensureOwnedSpaceHosted;
880
881
  /**
881
882
  * Restore a previously established session from stored delegation data.
882
883
  *
@@ -877,6 +877,7 @@ declare class TinyCloudNode {
877
877
  signIn(options?: SignInOptions): Promise<void>;
878
878
  private ownedSpaceId;
879
879
  private writeManifestRegistryRecords;
880
+ private ensureOwnedSpaceHosted;
880
881
  /**
881
882
  * Restore a previously established session from stored delegation data.
882
883
  *
package/dist/core.cjs CHANGED
@@ -1528,7 +1528,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1528
1528
  throw new Error("Manifest registry write requires wallet mode");
1529
1529
  }
1530
1530
  const accountSpaceId = this.ownedSpaceId(import_sdk_core5.ACCOUNT_REGISTRY_SPACE);
1531
- await this.auth.hostOwnedSpace(accountSpaceId);
1531
+ await this.ensureOwnedSpaceHosted(accountSpaceId);
1532
1532
  const accountKV = this.spaces.get(accountSpaceId).kv;
1533
1533
  for (const record of request.registryRecords) {
1534
1534
  const result = await accountKV.put(record.key, {
@@ -1543,6 +1543,39 @@ var _TinyCloudNode = class _TinyCloudNode {
1543
1543
  }
1544
1544
  }
1545
1545
  }
1546
+ async ensureOwnedSpaceHosted(spaceId) {
1547
+ if (!this.auth) {
1548
+ throw new Error("Owned space hosting requires wallet mode");
1549
+ }
1550
+ const session = this.auth.tinyCloudSession;
1551
+ if (!session) {
1552
+ throw new Error("Owned space hosting requires an active session");
1553
+ }
1554
+ const host = this.hosts[0] ?? this.config.host;
1555
+ if (!host) {
1556
+ throw new Error("Owned space hosting requires a TinyCloud host");
1557
+ }
1558
+ const activation = await (0, import_sdk_core5.activateSessionWithHost)(host, session.delegationHeader);
1559
+ if (activation.success && !activation.skipped?.includes(spaceId)) {
1560
+ return;
1561
+ }
1562
+ if (!activation.success && activation.status !== 404) {
1563
+ throw new Error(
1564
+ `Failed to check owned space ${spaceId}: ${activation.error ?? activation.status}`
1565
+ );
1566
+ }
1567
+ const created = await this.auth.hostOwnedSpace(spaceId);
1568
+ if (!created) {
1569
+ throw new Error(`Failed to create owned space: ${spaceId}`);
1570
+ }
1571
+ await new Promise((resolve) => setTimeout(resolve, 100));
1572
+ const retry = await (0, import_sdk_core5.activateSessionWithHost)(host, session.delegationHeader);
1573
+ if (!retry.success || retry.skipped?.includes(spaceId)) {
1574
+ throw new Error(
1575
+ `Failed to activate session after creating owned space ${spaceId}: ${retry.error ?? "space was skipped"}`
1576
+ );
1577
+ }
1578
+ }
1546
1579
  /**
1547
1580
  * Restore a previously established session from stored delegation data.
1548
1581
  *