@tinycloud/node-sdk 3.0.1-beta.0 → 3.1.0-beta.2

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
@@ -17075,6 +17075,8 @@ __export(index_exports, {
17075
17075
  SECRET_NAME_RE: () => import_sdk_core16.SECRET_NAME_RE,
17076
17076
  SQLAction: () => import_sdk_core14.SQLAction,
17077
17077
  SQLService: () => import_sdk_core14.SQLService,
17078
+ STORAGE_FULL_MESSAGE: () => import_sdk_core11.STORAGE_FULL_MESSAGE,
17079
+ STORAGE_WRITE_TOO_LARGE_MESSAGE: () => import_sdk_core11.STORAGE_WRITE_TOO_LARGE_MESSAGE,
17078
17080
  SecretsService: () => import_sdk_core16.SecretsService,
17079
17081
  ServiceContext: () => import_sdk_core23.ServiceContext,
17080
17082
  SessionExpiredError: () => import_sdk_core12.SessionExpiredError,
@@ -17150,6 +17152,7 @@ __export(index_exports, {
17150
17152
  isCapabilitySubset: () => import_sdk_core12.isCapabilitySubset,
17151
17153
  isEvmAddress: () => import_sdk_core11.isEvmAddress,
17152
17154
  isNetworkId: () => import_sdk_core17.isNetworkId,
17155
+ isStorageFullError: () => import_sdk_core11.isStorageFullError,
17153
17156
  loadManifest: () => import_sdk_core12.loadManifest,
17154
17157
  makePkhSpaceId: () => import_sdk_core11.makePkhSpaceId,
17155
17158
  makePublicSpaceId: () => import_sdk_core21.makePublicSpaceId,
@@ -17832,21 +17835,28 @@ var NodeUserAuthorization = class {
17832
17835
  });
17833
17836
  const signature2 = await this.signMessage(siwe, purpose);
17834
17837
  const headers = this.wasm.siweToDelegationHeaders({ siwe, signature: signature2 });
17835
- const result = await (0, import_sdk_core2.submitHostDelegation)(host, headers);
17836
- return result.success;
17838
+ return (0, import_sdk_core2.submitHostDelegation)(host, headers);
17837
17839
  }
17838
17840
  /**
17839
17841
  * Create a specific space on the server via host delegation.
17840
17842
  * Used for lazy creation of additional spaces (e.g., public).
17841
17843
  */
17842
17844
  async hostPublicSpace(spaceId) {
17843
- return this.hostSpace(spaceId);
17845
+ return (await this.hostSpace(spaceId)).success;
17844
17846
  }
17845
17847
  /**
17846
17848
  * Create a specific owned space on the server via host delegation.
17847
17849
  * Used by manifest registry setup for the account space.
17848
17850
  */
17849
17851
  async hostOwnedSpace(spaceId, purpose) {
17852
+ return (await this.hostOwnedSpaceResult(spaceId, purpose)).success;
17853
+ }
17854
+ /**
17855
+ * {@link hostOwnedSpace} with the full host-delegation result, so a failure
17856
+ * keeps its HTTP status (e.g. a typed 401/403) instead of collapsing to
17857
+ * `false`.
17858
+ */
17859
+ async hostOwnedSpaceResult(spaceId, purpose) {
17850
17860
  return this.hostSpace(spaceId, purpose);
17851
17861
  }
17852
17862
  /**
@@ -17889,7 +17899,7 @@ var NodeUserAuthorization = class {
17889
17899
  return;
17890
17900
  }
17891
17901
  try {
17892
- const created = await this.hostSpace();
17902
+ const created = (await this.hostSpace()).success;
17893
17903
  if (!created) {
17894
17904
  const err = new Error(`Failed to create space: ${primarySpaceId}`);
17895
17905
  handler.onSpaceCreationFailed?.(creationContext, err);
@@ -17926,7 +17936,7 @@ var NodeUserAuthorization = class {
17926
17936
  return;
17927
17937
  }
17928
17938
  try {
17929
- const created = await this.hostSpace();
17939
+ const created = (await this.hostSpace()).success;
17930
17940
  if (!created) {
17931
17941
  const err = new Error(`Failed to create space: ${primarySpaceId}`);
17932
17942
  handler.onSpaceCreationFailed?.(creationContext, err);
@@ -19425,6 +19435,10 @@ function persistedExpiry(value) {
19425
19435
  function sameInstant(left, right) {
19426
19436
  return left.getTime() === right.getTime();
19427
19437
  }
19438
+ function describeHostFailure(result) {
19439
+ const text = result.error?.trim();
19440
+ return text ? `${result.status} - ${text}` : `${result.status}`;
19441
+ }
19428
19442
  function ownerDelegationPermissions(params) {
19429
19443
  const hasPermissions = Object.prototype.hasOwnProperty.call(params, "permissions");
19430
19444
  const hasLegacy = Object.prototype.hasOwnProperty.call(params, "path") || Object.prototype.hasOwnProperty.call(params, "actions");
@@ -20538,8 +20552,9 @@ var _TinyCloudNode = class _TinyCloudNode {
20538
20552
  await this.ensureOwnedSpaceHostedById(accountSpaceId);
20539
20553
  const result = await this.account.applications.register(request.manifests);
20540
20554
  if (!result.ok) {
20541
- throw new Error(
20542
- `Failed to write manifest registry records: ${result.error.message}`
20555
+ throw Object.assign(
20556
+ new Error(`Failed to write manifest registry records: ${result.error.message}`),
20557
+ { cause: result.error }
20543
20558
  );
20544
20559
  }
20545
20560
  }
@@ -20564,7 +20579,10 @@ var _TinyCloudNode = class _TinyCloudNode {
20564
20579
  if (this.currentSessionCanListSpaces()) {
20565
20580
  const spaces = await this.account.spaces.syncAccessible();
20566
20581
  if (!spaces.ok) {
20567
- throw new Error(`Failed to sync account spaces: ${spaces.error.message}`);
20582
+ throw Object.assign(
20583
+ new Error(`Failed to sync account spaces: ${spaces.error.message}`),
20584
+ { cause: spaces.error }
20585
+ );
20568
20586
  }
20569
20587
  }
20570
20588
  });
@@ -20619,14 +20637,20 @@ var _TinyCloudNode = class _TinyCloudNode {
20619
20637
  await task();
20620
20638
  return;
20621
20639
  } catch (error) {
20640
+ const verdict = (0, import_sdk_core7.authorizationVerdictOf)(error);
20622
20641
  const message = error instanceof Error ? error.message : String(error);
20623
- if (/Unauthorized Action|\b(?:401|403)\b/.test(message)) {
20642
+ const isAuthorizationVerdict = verdict === void 0 ? /Unauthorized Action|\b(?:401|403)\b/.test(message) : verdict !== "other";
20643
+ if (isAuthorizationVerdict) {
20624
20644
  console.warn(
20625
20645
  "TinyCloud account registry sync stopped: authorization verdict is not retryable",
20626
20646
  error
20627
20647
  );
20628
20648
  return;
20629
20649
  }
20650
+ if ((0, import_sdk_core7.isStorageFullError)(error) || (0, import_sdk_core7.isStorageFullError)(error?.cause) || message.includes(import_sdk_core7.STORAGE_FULL_MESSAGE) || message.includes(import_sdk_core7.STORAGE_WRITE_TOO_LARGE_MESSAGE)) {
20651
+ console.warn("TinyCloud account registry sync stopped: storage is full", error);
20652
+ return;
20653
+ }
20630
20654
  lastError = error;
20631
20655
  if (attempt < delays.length - 1) {
20632
20656
  await new Promise((resolve) => setTimeout(resolve, delays[attempt]));
@@ -20700,19 +20724,26 @@ var _TinyCloudNode = class _TinyCloudNode {
20700
20724
  return;
20701
20725
  }
20702
20726
  if (!activation.success && activation.status !== 404) {
20703
- throw new Error(
20704
- `Failed to check owned space ${spaceId}: ${activation.error ?? activation.status}`
20727
+ throw Object.assign(
20728
+ new Error(`Failed to check owned space ${spaceId}: ${describeHostFailure(activation)}`),
20729
+ { cause: activation }
20705
20730
  );
20706
20731
  }
20707
- const created = await this.auth.hostOwnedSpace(spaceId);
20708
- if (!created) {
20709
- throw new Error(`Failed to create owned space: ${spaceId}`);
20732
+ const created = await this.auth.hostOwnedSpaceResult(spaceId);
20733
+ if (!created.success) {
20734
+ throw Object.assign(
20735
+ new Error(`Failed to create owned space ${spaceId}: ${describeHostFailure(created)}`),
20736
+ { cause: created }
20737
+ );
20710
20738
  }
20711
20739
  await new Promise((resolve) => setTimeout(resolve, 100));
20712
20740
  const retry = await (0, import_sdk_core7.activateSessionWithHost)(host, session.delegationHeader);
20713
20741
  if (!retry.success || retry.skipped?.includes(spaceId)) {
20714
- throw new Error(
20715
- `Failed to activate session after creating owned space ${spaceId}: ${retry.error ?? "space was skipped"}`
20742
+ throw Object.assign(
20743
+ new Error(
20744
+ `Failed to activate session after creating owned space ${spaceId}: ${retry.success ? "space was skipped" : describeHostFailure(retry)}`
20745
+ ),
20746
+ { cause: retry }
20716
20747
  );
20717
20748
  }
20718
20749
  this.confirmedHostedSpaceIds.add(spaceId);
@@ -22260,7 +22291,10 @@ var _TinyCloudNode = class _TinyCloudNode {
22260
22291
  const activation = await (0, import_sdk_core7.activateSessionWithHost)(host, delegationSession.delegationHeader);
22261
22292
  assertOwnerGraphActive();
22262
22293
  if (!activation.success) {
22263
- throw new Error(`Owner delegation import failed: ${activation.status} ${activation.error ?? ""}`.trim());
22294
+ throw Object.assign(
22295
+ new Error(`Owner delegation import failed: ${activation.status} ${activation.error ?? ""}`.trim()),
22296
+ { cause: activation }
22297
+ );
22264
22298
  }
22265
22299
  const delegation = {
22266
22300
  cid: delegationSession.delegationCid,
@@ -25057,6 +25091,8 @@ var import_sdk_core23 = require("@tinycloud/sdk-core");
25057
25091
  SECRET_NAME_RE,
25058
25092
  SQLAction,
25059
25093
  SQLService,
25094
+ STORAGE_FULL_MESSAGE,
25095
+ STORAGE_WRITE_TOO_LARGE_MESSAGE,
25060
25096
  SecretsService,
25061
25097
  ServiceContext,
25062
25098
  SessionExpiredError,
@@ -25132,6 +25168,7 @@ var import_sdk_core23 = require("@tinycloud/sdk-core");
25132
25168
  isCapabilitySubset,
25133
25169
  isEvmAddress,
25134
25170
  isNetworkId,
25171
+ isStorageFullError,
25135
25172
  loadManifest,
25136
25173
  makePkhSpaceId,
25137
25174
  makePublicSpaceId,