@tinycloud/node-sdk 2.4.0-beta.6 → 2.4.0-beta.7

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
@@ -18975,7 +18975,7 @@ var _TinyCloudNode = class _TinyCloudNode {
18975
18975
  if (this.config.manifest === void 0 && this.config.capabilityRequest === void 0) {
18976
18976
  await this.ensureOwnedSpaceHosted(this.ownedSpaceId("secrets"));
18977
18977
  }
18978
- await this.writeManifestRegistryRecords();
18978
+ this.scheduleAccountRegistrySync();
18979
18979
  this.notificationHandler.success("Successfully signed in");
18980
18980
  }
18981
18981
  ownedSpaceId(name) {
@@ -18994,19 +18994,40 @@ var _TinyCloudNode = class _TinyCloudNode {
18994
18994
  }
18995
18995
  const accountSpaceId = this.ownedSpaceId(import_sdk_core6.ACCOUNT_REGISTRY_SPACE);
18996
18996
  await this.ensureOwnedSpaceHosted(accountSpaceId);
18997
- const accountKV = this.spaces.get(accountSpaceId).kv;
18998
- for (const record of request.registryRecords) {
18999
- const result = await accountKV.put(record.key, {
19000
- app_id: record.app_id,
19001
- manifests: record.manifests,
19002
- updated_at: (/* @__PURE__ */ new Date()).toISOString()
19003
- });
19004
- if (!result.ok) {
19005
- throw new Error(
19006
- `Failed to write manifest registry record ${record.key}: ${result.error.message}`
19007
- );
18997
+ const result = await this.account.applications.register(request.manifests);
18998
+ if (!result.ok) {
18999
+ throw new Error(
19000
+ `Failed to write manifest registry records: ${result.error.message}`
19001
+ );
19002
+ }
19003
+ }
19004
+ scheduleAccountRegistrySync() {
19005
+ void this.withAccountRegistryRetry(async () => {
19006
+ await this.writeManifestRegistryRecords();
19007
+ const spaces = await this.account.spaces.syncAccessible();
19008
+ if (!spaces.ok) {
19009
+ throw new Error(`Failed to sync account spaces: ${spaces.error.message}`);
19010
+ }
19011
+ });
19012
+ }
19013
+ async withAccountRegistryRetry(task) {
19014
+ const delays = [250, 1e3, 3e3];
19015
+ let lastError;
19016
+ for (let attempt = 0; attempt < delays.length; attempt += 1) {
19017
+ try {
19018
+ await task();
19019
+ return;
19020
+ } catch (error) {
19021
+ lastError = error;
19022
+ if (attempt < delays.length - 1) {
19023
+ await new Promise((resolve) => setTimeout(resolve, delays[attempt]));
19024
+ }
19008
19025
  }
19009
19026
  }
19027
+ console.warn(
19028
+ "TinyCloud account registry sync failed after retries",
19029
+ lastError
19030
+ );
19010
19031
  }
19011
19032
  requestedEncryptionNetworkIds() {
19012
19033
  const request = this.capabilityRequest;
@@ -19110,6 +19131,15 @@ var _TinyCloudNode = class _TinyCloudNode {
19110
19131
  `Failed to activate session for owned space ${spaceId}: ${activation.error ?? "space was skipped"}`
19111
19132
  );
19112
19133
  }
19134
+ void this.account.spaces.register({
19135
+ spaceId,
19136
+ name,
19137
+ ownerDid: this.did,
19138
+ type: "owned",
19139
+ permissions: ["*"],
19140
+ status: "active"
19141
+ }).catch(() => {
19142
+ });
19113
19143
  return spaceId;
19114
19144
  }
19115
19145
  /**
@@ -19727,6 +19757,9 @@ var _TinyCloudNode = class _TinyCloudNode {
19727
19757
  }
19728
19758
  };
19729
19759
  }
19760
+ },
19761
+ onSpaceRegistered: async (space) => {
19762
+ await this.account.spaces.register(space);
19730
19763
  }
19731
19764
  });
19732
19765
  this._sharingService.updateConfig({