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

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