@tinycloud/node-sdk 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
@@ -20218,12 +20218,13 @@ var _TinyCloudNode = class _TinyCloudNode {
20218
20218
  if (!auth) {
20219
20219
  throw new Error("Account bootstrap requires an active wallet session");
20220
20220
  }
20221
+ const accountSpaceId = this.ownedSpaceId(import_sdk_core7.ACCOUNT_REGISTRY_SPACE);
20221
20222
  const skipped = auth.lastActivationSkippedSpaceIds;
20223
+ if (skipped.includes(accountSpaceId)) return { action: "run", mode: "fresh" };
20222
20224
  if (skipped.some((spaceId) => enshrinedSpaceIds.has(spaceId))) {
20223
- return { action: "run", mode: "fresh" };
20225
+ return { action: "run", mode: "repair" };
20224
20226
  }
20225
20227
  try {
20226
- const accountSpaceId = this.ownedSpaceId(import_sdk_core7.ACCOUNT_REGISTRY_SPACE);
20227
20228
  const markerPermission = {
20228
20229
  service: "tinycloud.kv",
20229
20230
  space: accountSpaceId,
@@ -20235,7 +20236,7 @@ var _TinyCloudNode = class _TinyCloudNode {
20235
20236
  }
20236
20237
  const marker = await this.readBootstrapCompletionMarker();
20237
20238
  if (marker.ok) {
20238
- if (this.isAcceptedBootstrapCompletionMarker(marker.data.data)) {
20239
+ if (this.isAcceptedBootstrapCompletionMarker(marker.data.data, steps.map((step) => step.id))) {
20239
20240
  return { action: "skip" };
20240
20241
  }
20241
20242
  return { action: "run", mode: "repair" };
@@ -20285,12 +20286,16 @@ var _TinyCloudNode = class _TinyCloudNode {
20285
20286
  );
20286
20287
  }
20287
20288
  }
20288
- isAcceptedBootstrapCompletionMarker(value) {
20289
+ /**
20290
+ * A marker written before a canonical space was added triggers one bounded repair.
20291
+ */
20292
+ isAcceptedBootstrapCompletionMarker(value, canonicalStepIds) {
20289
20293
  if (typeof value !== "object" || value === null) return false;
20290
20294
  const entries = Object.entries(value);
20291
20295
  const markerValue = (name) => entries.find(([key2]) => key2 === name)?.[1];
20292
20296
  const version23 = markerValue("v");
20293
- return typeof version23 === "number" && Number.isInteger(version23) && ACCEPTED_MARKER_VERSIONS.some((acceptedVersion) => acceptedVersion === version23);
20297
+ const stepIds = markerValue("stepIds");
20298
+ return typeof version23 === "number" && Number.isInteger(version23) && ACCEPTED_MARKER_VERSIONS.some((acceptedVersion) => acceptedVersion === version23) && Array.isArray(stepIds) && canonicalStepIds.every((stepId) => stepIds.includes(stepId));
20294
20299
  }
20295
20300
  markerReadIsUnhostedSpace(meta) {
20296
20301
  return meta?.status === 404;
@@ -20377,30 +20382,39 @@ var _TinyCloudNode = class _TinyCloudNode {
20377
20382
  }
20378
20383
  }
20379
20384
  if (step.kind === "seed-spaces") {
20380
- const registered = await this.account.spaces.registerBatch(
20381
- step.spaces.map((space) => ({
20382
- spaceId: space.spaceId,
20383
- name: space.name,
20384
- ownerDid: this.did,
20385
- type: "owned",
20386
- permissions: ["*"],
20387
- status: "active"
20388
- }))
20389
- );
20390
- if (!registered.ok) {
20391
- throw Object.assign(
20392
- new Error(`Failed to seed account spaces: ${registered.error.message}`),
20393
- { cause: registered.error }
20394
- );
20395
- }
20396
- const batchError = registered.data.recoveredFromBatchError;
20397
- if (batchError) {
20398
- warnings.push({
20399
- stepId: step.id,
20400
- kind: "batch-write-reconciled",
20401
- code: batchError.code,
20402
- message: batchError.message
20403
- });
20385
+ const inputs = step.spaces.map((space) => ({
20386
+ spaceId: space.spaceId,
20387
+ name: space.name,
20388
+ ownerDid: this.did,
20389
+ type: "owned",
20390
+ permissions: ["*"],
20391
+ status: "active"
20392
+ }));
20393
+ if (mode === "fresh") {
20394
+ const registered = await this.account.spaces.registerBatch(inputs);
20395
+ if (!registered.ok) {
20396
+ throw Object.assign(
20397
+ new Error(`Failed to seed account spaces: ${registered.error.message}`),
20398
+ { cause: registered.error }
20399
+ );
20400
+ }
20401
+ const batchError = registered.data.recoveredFromBatchError;
20402
+ if (batchError) {
20403
+ warnings.push({
20404
+ stepId: step.id,
20405
+ kind: "batch-write-reconciled",
20406
+ code: batchError.code,
20407
+ message: batchError.message
20408
+ });
20409
+ }
20410
+ } else {
20411
+ const ensured = await this.account.spaces.registerMissing(inputs);
20412
+ if (!ensured.ok) {
20413
+ throw Object.assign(
20414
+ new Error(`Failed to seed account spaces: ${ensured.error.message}`),
20415
+ { cause: ensured.error }
20416
+ );
20417
+ }
20404
20418
  }
20405
20419
  }
20406
20420
  if (step.kind === "seed-applications") {