@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.
package/dist/index.cjs CHANGED
@@ -18513,7 +18513,7 @@ var _TinyCloudNode = class _TinyCloudNode {
18513
18513
  throw new Error("Manifest registry write requires wallet mode");
18514
18514
  }
18515
18515
  const accountSpaceId = this.ownedSpaceId(import_sdk_core4.ACCOUNT_REGISTRY_SPACE);
18516
- await this.auth.hostOwnedSpace(accountSpaceId);
18516
+ await this.ensureOwnedSpaceHosted(accountSpaceId);
18517
18517
  const accountKV = this.spaces.get(accountSpaceId).kv;
18518
18518
  for (const record of request.registryRecords) {
18519
18519
  const result = await accountKV.put(record.key, {
@@ -18528,6 +18528,39 @@ var _TinyCloudNode = class _TinyCloudNode {
18528
18528
  }
18529
18529
  }
18530
18530
  }
18531
+ async ensureOwnedSpaceHosted(spaceId) {
18532
+ if (!this.auth) {
18533
+ throw new Error("Owned space hosting requires wallet mode");
18534
+ }
18535
+ const session = this.auth.tinyCloudSession;
18536
+ if (!session) {
18537
+ throw new Error("Owned space hosting requires an active session");
18538
+ }
18539
+ const host = this.hosts[0] ?? this.config.host;
18540
+ if (!host) {
18541
+ throw new Error("Owned space hosting requires a TinyCloud host");
18542
+ }
18543
+ const activation = await (0, import_sdk_core4.activateSessionWithHost)(host, session.delegationHeader);
18544
+ if (activation.success && !activation.skipped?.includes(spaceId)) {
18545
+ return;
18546
+ }
18547
+ if (!activation.success && activation.status !== 404) {
18548
+ throw new Error(
18549
+ `Failed to check owned space ${spaceId}: ${activation.error ?? activation.status}`
18550
+ );
18551
+ }
18552
+ const created = await this.auth.hostOwnedSpace(spaceId);
18553
+ if (!created) {
18554
+ throw new Error(`Failed to create owned space: ${spaceId}`);
18555
+ }
18556
+ await new Promise((resolve) => setTimeout(resolve, 100));
18557
+ const retry = await (0, import_sdk_core4.activateSessionWithHost)(host, session.delegationHeader);
18558
+ if (!retry.success || retry.skipped?.includes(spaceId)) {
18559
+ throw new Error(
18560
+ `Failed to activate session after creating owned space ${spaceId}: ${retry.error ?? "space was skipped"}`
18561
+ );
18562
+ }
18563
+ }
18531
18564
  /**
18532
18565
  * Restore a previously established session from stored delegation data.
18533
18566
  *