@tinycloud/sdk-core 3.1.0-beta.10 → 3.1.0-beta.11

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
@@ -43,6 +43,7 @@ __export(index_exports, {
43
43
  ACCOUNT_MANIFEST_PERMISSIONS: () => import_bootstrap4.ACCOUNT_MANIFEST_PERMISSIONS,
44
44
  ACCOUNT_REGISTRY_PATH: () => ACCOUNT_REGISTRY_PATH,
45
45
  ACCOUNT_REGISTRY_SPACE: () => ACCOUNT_REGISTRY_SPACE,
46
+ AGENTS_SPACE: () => import_bootstrap4.AGENTS_SPACE,
46
47
  ATTESTED_ENFORCER_BINDING_V2_SCHEMA: () => ATTESTED_ENFORCER_BINDING_V2_SCHEMA,
47
48
  AccountService: () => AccountService,
48
49
  AutoApproveSpaceCreationHandler: () => AutoApproveSpaceCreationHandler,
@@ -215,6 +216,7 @@ __export(index_exports, {
215
216
  SpaceErrorCodes: () => SpaceErrorCodes,
216
217
  SpaceService: () => SpaceService,
217
218
  TINYCLOUD_ACCOUNT_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_ACCOUNT_SPACE_MANIFEST,
219
+ TINYCLOUD_AGENTS_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_AGENTS_SPACE_MANIFEST,
218
220
  TINYCLOUD_APPLICATIONS_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_APPLICATIONS_SPACE_MANIFEST,
219
221
  TINYCLOUD_CANONICAL_IDENTITY_CLAIM: () => TINYCLOUD_CANONICAL_IDENTITY_CLAIM,
220
222
  TINYCLOUD_DEFAULT_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_DEFAULT_SPACE_MANIFEST,
@@ -14408,6 +14410,56 @@ var AccountService = class {
14408
14410
  await this.upsertSpacesIndexQuietly(registered);
14409
14411
  return (0, import_sdk_services7.ok)({ spaces: registered, recoveredFromBatchError: batchResult.error });
14410
14412
  },
14413
+ /**
14414
+ * Register only spaces without a registry record (TC-800). Existing
14415
+ * records, including renamed or archived ones, are kept byte-for-byte.
14416
+ * Bootstrap repair uses this on populated accounts.
14417
+ */
14418
+ registerMissing: async (spaces) => {
14419
+ if (spaces.length === 0) return (0, import_sdk_services7.ok)([]);
14420
+ await this.config.ensureAccountSpaceHosted?.();
14421
+ const kvResult = this.accountKV();
14422
+ if (!kvResult.ok) return kvResult;
14423
+ const kv = kvResult.data;
14424
+ const stored = spaces.map((space) => spaceRecordFromInput(space));
14425
+ const keys = stored.map((record2) => spaceKey(record2.space_id));
14426
+ const read2 = await kv.batchGet(keys);
14427
+ if (!read2.ok) return accountErr(read2.error);
14428
+ const byKey = new Map(read2.data.results.map((result) => [result.key, result.result]));
14429
+ const final = new Array(keys.length);
14430
+ const missing = [];
14431
+ for (let i = 0; i < keys.length; i++) {
14432
+ const key = keys[i];
14433
+ const result = byKey.get(key);
14434
+ if (!result) {
14435
+ return (0, import_sdk_services7.err)((0, import_sdk_services7.serviceError)(
14436
+ import_sdk_services7.ErrorCodes.NETWORK_ERROR,
14437
+ `KV batch read omitted requested key ${JSON.stringify(key)}`,
14438
+ SERVICE_NAME2
14439
+ ));
14440
+ }
14441
+ if (result.ok) {
14442
+ final[i] = spaceFromRecord(key, result.data.data);
14443
+ } else if (result.error.code === import_sdk_services7.ErrorCodes.KV_NOT_FOUND) {
14444
+ missing.push({ index: i, key, record: stored[i] });
14445
+ } else {
14446
+ return accountErr(result.error);
14447
+ }
14448
+ }
14449
+ const creates = await Promise.all(missing.map(async ({ index, key, record: record2 }) => {
14450
+ const written = await kv.put(key, record2, { ifNoneMatch: "*" });
14451
+ if (written.ok) return { index, result: (0, import_sdk_services7.ok)(spaceFromRecord(key, record2)) };
14452
+ const raced = await kv.get(key);
14453
+ if (raced.ok) return { index, result: (0, import_sdk_services7.ok)(spaceFromRecord(key, raced.data.data)) };
14454
+ return { index, result: (0, import_sdk_services7.err)(written.error) };
14455
+ }));
14456
+ for (const { index, result } of creates) {
14457
+ if (!result.ok) return accountErr(result.error);
14458
+ final[index] = result.data;
14459
+ }
14460
+ await this.upsertSpacesIndexQuietly(final);
14461
+ return (0, import_sdk_services7.ok)(final);
14462
+ },
14411
14463
  syncAccessible: async () => {
14412
14464
  const synced = await this.syncAccessibleSpaces({ tolerateStorageFull: false });
14413
14465
  return synced.ok ? (0, import_sdk_services7.ok)(synced.data.spaces) : synced;