@tinycloud/sdk-core 3.1.0-beta.1 → 3.1.0-beta.3

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
@@ -185,6 +185,8 @@ __export(index_exports, {
185
185
  SQL: () => import_bootstrap4.SQL,
186
186
  SQLAction: () => import_sdk_services8.SQLAction,
187
187
  SQLService: () => import_sdk_services8.SQLService,
188
+ STORAGE_FULL_MESSAGE: () => import_sdk_services8.STORAGE_FULL_MESSAGE,
189
+ STORAGE_WRITE_TOO_LARGE_MESSAGE: () => import_sdk_services8.STORAGE_WRITE_TOO_LARGE_MESSAGE,
188
190
  SecretsService: () => import_sdk_services8.SecretsService,
189
191
  SenderShareStore: () => SenderShareStore,
190
192
  ServiceContext: () => import_sdk_services8.ServiceContext,
@@ -358,6 +360,7 @@ __export(index_exports, {
358
360
  isEvmAddress: () => isEvmAddress,
359
361
  isNetworkId: () => import_sdk_services8.isNetworkId,
360
362
  isPlausibleOpenKeyActionId: () => isPlausibleOpenKeyActionId,
363
+ isStorageFullError: () => import_sdk_services8.isStorageFullError,
361
364
  isV2ShareLink: () => isV2ShareLink,
362
365
  issuedCredentialEnvelopeFromVerified: () => issuedCredentialEnvelopeFromVerified,
363
366
  jcsCanonicalize: () => jcsCanonicalize,
@@ -4056,6 +4059,9 @@ async function renewPolicyRootStatusV3(input) {
4056
4059
  if (!response.ok) throw new Error(`policy root renewal rejected (${response.status})`);
4057
4060
  return object2(await response.json(), "policy root renewal");
4058
4061
  }
4062
+ function rfc3339Seconds(value) {
4063
+ return new Date(Math.floor(value.getTime() / 1e3) * 1e3).toISOString().replace(/\.000Z$/, "Z");
4064
+ }
4059
4065
  async function revokePolicyRootV3(input) {
4060
4066
  if (input.reason.length === 0) throw new Error("policy root revocation reason is required");
4061
4067
  const unsigned = {
@@ -4064,7 +4070,7 @@ async function revokePolicyRootV3(input) {
4064
4070
  targetRole: input.targetRole,
4065
4071
  ownerDid: input.ownerDid,
4066
4072
  nodeAudience: input.nodeAudience,
4067
- revokedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
4073
+ revokedAt: rfc3339Seconds(input.now ?? /* @__PURE__ */ new Date()),
4068
4074
  reason: input.reason,
4069
4075
  issuerDid: input.issuerDid
4070
4076
  };
@@ -4815,7 +4821,7 @@ function date(value, label) {
4815
4821
  if (!Number.isFinite(Date.parse(text2))) throw new Error(`${label} is invalid`);
4816
4822
  return text2;
4817
4823
  }
4818
- function rfc3339Seconds(value) {
4824
+ function rfc3339Seconds2(value) {
4819
4825
  return new Date(Math.floor(value.getTime() / 1e3) * 1e3).toISOString().replace(/\.000Z$/, "Z");
4820
4826
  }
4821
4827
  function validateUnifiedPolicyV2(value, expectedPolicyCid) {
@@ -4980,8 +4986,8 @@ async function buildPolicyCredentialPresentationV4(input) {
4980
4986
  requirementDigest,
4981
4987
  descriptorDigest: input.credential.descriptorDigest,
4982
4988
  requestedCapabilities: Object.freeze(requestedCapabilities),
4983
- issuedAt: rfc3339Seconds(now),
4984
- expiresAt: rfc3339Seconds(new Date(expiresAtMs))
4989
+ issuedAt: rfc3339Seconds2(now),
4990
+ expiresAt: rfc3339Seconds2(new Date(expiresAtMs))
4985
4991
  }), input.sign);
4986
4992
  }
4987
4993
  async function buildPolicyCredentialPresentationV3(input) {
@@ -5035,8 +5041,8 @@ async function buildPolicyCredentialPresentationV3(input) {
5035
5041
  requirementDigest,
5036
5042
  descriptorDigest: input.credential.descriptorDigest,
5037
5043
  requestedCapabilities: Object.freeze(requestedCapabilities),
5038
- issuedAt: rfc3339Seconds(now),
5039
- expiresAt: rfc3339Seconds(new Date(expiresAtMs))
5044
+ issuedAt: rfc3339Seconds2(now),
5045
+ expiresAt: rfc3339Seconds2(new Date(expiresAtMs))
5040
5046
  });
5041
5047
  const digest4 = (0, import_sha2562.sha256)(
5042
5048
  new TextEncoder().encode(
@@ -14185,10 +14191,10 @@ var AccountService = class {
14185
14191
  * Per-account-space memo for {@link ensureAccountIndex}.
14186
14192
  *
14187
14193
  * Applying the index migration is a no-op once the schema exists, but the
14188
- * SQL service still spends two round trips discovering that (create the
14189
- * migrations table, then read the applied-migration rows). Account bootstrap
14190
- * touches the index eight times, so without a memo that is ~14 wasted
14191
- * requests on the cold sign-in path. The in-flight dedupe inside SQLService
14194
+ * SQL service still spends a round trip discovering that (reading the
14195
+ * applied-migration rows). Account bootstrap touches the index eight times,
14196
+ * so without a memo that is ~7 wasted requests on the cold sign-in path.
14197
+ * The in-flight dedupe inside SQLService
14192
14198
  * never helps here: the node SDK builds a fresh SQLService per
14193
14199
  * `getAccountDb()` call, so its lock map is always empty.
14194
14200
  *
@@ -14286,11 +14292,12 @@ var AccountService = class {
14286
14292
  const indexed = await this.index.spaces.list();
14287
14293
  if (indexed.ok && indexed.data.length > 0) return indexed;
14288
14294
  if (!indexed.ok && !isMissingIndexError(indexed.error)) return indexed;
14289
- const canonical = await this.spaces.syncAccessible();
14290
- if (canonical.ok && options2.refreshIndex !== false) {
14291
- await this.replaceSpacesIndexQuietly(canonical.data);
14295
+ const canonical = await this.syncAccessibleSpaces({ tolerateStorageFull: true });
14296
+ if (!canonical.ok) return canonical;
14297
+ if (canonical.data.allRegistered && options2.refreshIndex !== false) {
14298
+ await this.replaceSpacesIndexQuietly(canonical.data.spaces);
14292
14299
  }
14293
- return canonical;
14300
+ return (0, import_sdk_services6.ok)(canonical.data.spaces);
14294
14301
  }
14295
14302
  const kvResult = this.accountKV();
14296
14303
  if (!kvResult.ok) return kvResult;
@@ -14378,15 +14385,8 @@ var AccountService = class {
14378
14385
  return (0, import_sdk_services6.ok)({ spaces: registered, recoveredFromBatchError: batchResult.error });
14379
14386
  },
14380
14387
  syncAccessible: async () => {
14381
- const listed = await this.config.getSpaces().list();
14382
- if (!listed.ok) return accountErr(listed.error);
14383
- const registered = [];
14384
- for (const space of listed.data) {
14385
- const result = await this.spaces.register(space);
14386
- if (!result.ok) return result;
14387
- registered.push(result.data);
14388
- }
14389
- return (0, import_sdk_services6.ok)(registered);
14388
+ const synced = await this.syncAccessibleSpaces({ tolerateStorageFull: false });
14389
+ return synced.ok ? (0, import_sdk_services6.ok)(synced.data.spaces) : synced;
14390
14390
  },
14391
14391
  remove: async (spaceId) => {
14392
14392
  const kvResult = this.accountKV();
@@ -14818,6 +14818,34 @@ var AccountService = class {
14818
14818
  if (!deleted.ok) return accountErr(deleted.error);
14819
14819
  return (0, import_sdk_services6.ok)(void 0);
14820
14820
  }
14821
+ /**
14822
+ * Register every space the session can reach and return them. With
14823
+ * `tolerateStorageFull`, a full account space stops the registration
14824
+ * writes but not the listing: the remaining spaces are returned as they
14825
+ * would have been registered, and `allRegistered` is false.
14826
+ */
14827
+ async syncAccessibleSpaces(options2) {
14828
+ const listed = await this.config.getSpaces().list();
14829
+ if (!listed.ok) return accountErr(listed.error);
14830
+ const spaces = [];
14831
+ let allRegistered = true;
14832
+ for (const space of listed.data) {
14833
+ if (allRegistered) {
14834
+ const result = await this.spaces.register(space);
14835
+ if (result.ok) {
14836
+ spaces.push(result.data);
14837
+ continue;
14838
+ }
14839
+ if (!options2.tolerateStorageFull || !(0, import_sdk_services6.isStorageFullError)(result.error)) {
14840
+ return result;
14841
+ }
14842
+ allRegistered = false;
14843
+ }
14844
+ const record2 = spaceRecordFromInput(space);
14845
+ spaces.push(spaceFromRecord(spaceKey(record2.space_id), record2));
14846
+ }
14847
+ return (0, import_sdk_services6.ok)({ spaces, allRegistered });
14848
+ }
14821
14849
  async resolveSpace(space) {
14822
14850
  const listed = await this.config.getSpaces().list();
14823
14851
  if (!listed.ok) return accountErr(listed.error);