@tinycloud/sdk-core 3.2.6-beta.2 → 3.3.0-beta.7

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
@@ -6917,6 +6917,8 @@ var DelegationManagerConfigSchema = import_zod4.z.object({
6917
6917
  (val) => val === void 0 || typeof val === "function",
6918
6918
  { message: "Expected an invokeAny function or undefined" }
6919
6919
  ).optional(),
6920
+ /** Optional owner-signed authorization for direct CID revocation */
6921
+ signOwnerRevocation: import_zod4.z.custom().optional(),
6920
6922
  /** Optional custom fetch implementation */
6921
6923
  fetch: import_zod4.z.unknown().refine(
6922
6924
  (val) => val === void 0 || typeof val === "function",
@@ -7056,6 +7058,7 @@ var DelegationManager = class {
7056
7058
  this.session = config.session;
7057
7059
  this.invoke = config.invoke;
7058
7060
  this.invokeAny = config.invokeAny;
7061
+ this.signOwnerRevocation = config.signOwnerRevocation;
7059
7062
  this.fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);
7060
7063
  this.accountSpaceId = config.accountSpaceId;
7061
7064
  }
@@ -7198,6 +7201,9 @@ var DelegationManager = class {
7198
7201
  * Once revoked, the delegation can no longer be used to access resources.
7199
7202
  * This also invalidates any sub-delegations derived from this delegation.
7200
7203
  *
7204
+ * Explicit target-space or authority options keep the delegated session
7205
+ * signing path even when an owner signer is available.
7206
+ *
7201
7207
  * @param cid - The CID of the delegation to revoke
7202
7208
  * @returns Result indicating success or an error
7203
7209
  *
@@ -7220,29 +7226,35 @@ var DelegationManager = class {
7220
7226
  };
7221
7227
  }
7222
7228
  try {
7223
- if (!this.invokeAny) {
7229
+ const ownerSigner = options2?.targetSpaceId === void 0 && options2?.authorityCid === void 0 ? this.signOwnerRevocation : void 0;
7230
+ if (!ownerSigner && !this.invokeAny) {
7224
7231
  return {
7225
7232
  ok: false,
7226
7233
  error: createError(
7227
7234
  DelegationErrorCodes.NOT_INITIALIZED,
7228
- "Revocation requires an invokeAny function that can sign the target CID"
7235
+ "Revocation requires an owner signer or invokeAny function that can sign the target CID"
7229
7236
  )
7230
7237
  };
7231
7238
  }
7232
- const entry = {
7233
- resource: `urn:cid:${cid2}`,
7234
- ...options2?.targetSpaceId === void 0 ? {} : { spaceId: options2.targetSpaceId },
7235
- service: "delegation",
7236
- path: "",
7237
- action: DelegationAction.REVOKE
7238
- };
7239
- if (options2?.authorityCid !== void 0) {
7240
- Object.defineProperty(entry, "revokeAuthorityCid", {
7241
- value: options2.authorityCid,
7242
- enumerable: false
7243
- });
7239
+ let headers;
7240
+ if (ownerSigner) {
7241
+ headers = { Authorization: await ownerSigner(cid2) };
7242
+ } else {
7243
+ const entry = {
7244
+ resource: `urn:cid:${cid2}`,
7245
+ ...options2?.targetSpaceId === void 0 ? {} : { spaceId: options2.targetSpaceId },
7246
+ service: "delegation",
7247
+ path: "",
7248
+ action: DelegationAction.REVOKE
7249
+ };
7250
+ if (options2?.authorityCid !== void 0) {
7251
+ Object.defineProperty(entry, "revokeAuthorityCid", {
7252
+ value: options2.authorityCid,
7253
+ enumerable: false
7254
+ });
7255
+ }
7256
+ headers = this.invokeAny(this.session, [entry]);
7244
7257
  }
7245
- const headers = this.invokeAny(this.session, [entry]);
7246
7258
  const response = await this.fetchFn(`${this.host}/revoke`, {
7247
7259
  method: "POST",
7248
7260
  headers
@@ -9972,7 +9984,9 @@ function redactedCode(error) {
9972
9984
  if (error instanceof ShareConflict) return error.code;
9973
9985
  const code3 = error && typeof error === "object" && "code" in error ? error.code : void 0;
9974
9986
  if (typeof code3 !== "string") return "SHARE_INVALID";
9975
- if (code3 === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || code3 === import_sdk_services3.ErrorCodes.KV_CONFLICT || code3 === "412") return "SHARE_CONFLICT";
9987
+ if (code3 === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || code3 === "412") return "SHARE_CONFLICT";
9988
+ if (code3 === import_sdk_services3.ErrorCodes.NODE_BUSY || code3 === import_sdk_services3.ErrorCodes.REQUEST_TIMEOUT) return "SHARE_OFFLINE";
9989
+ if (code3 === import_sdk_services3.ErrorCodes.OUTCOME_UNKNOWN) return "SHARE_WRITE_FAILED";
9976
9990
  if (code3 === "KV_NOT_FOUND" || code3 === "NOT_FOUND" || code3 === "404") return "SHARE_NOT_FOUND";
9977
9991
  if (code3.includes("EXPIRED") || code3 === "expired") return "SHARE_EXPIRED";
9978
9992
  if (code3.includes("REVOK")) return "SHARE_REVOKED";
@@ -10211,7 +10225,7 @@ var ShareRecipientClient = class {
10211
10225
  if (portableDelegation !== void 0 && kv !== void 0) {
10212
10226
  const result2 = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
10213
10227
  if (!result2.ok) {
10214
- if (result2.error.code === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || result2.error.code === import_sdk_services3.ErrorCodes.KV_CONFLICT) throw new ShareConflict(resolvedPath, result2.error.meta?.etag);
10228
+ if (result2.error.code === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED) throw new ShareConflict(resolvedPath, result2.error.meta?.etag);
10215
10229
  throw result2.error;
10216
10230
  }
10217
10231
  return { etag: result2.data.headers.etag };
@@ -10219,7 +10233,7 @@ var ShareRecipientClient = class {
10219
10233
  if (policySession !== void 0) return this.nativeSave(envelope, policySession, resolvedPath, bytes2, input);
10220
10234
  const result = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
10221
10235
  if (!result.ok) {
10222
- if (result.error.code === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || result.error.code === import_sdk_services3.ErrorCodes.KV_CONFLICT) throw new ShareConflict(resolvedPath, result.error.meta?.etag);
10236
+ if (result.error.code === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED) throw new ShareConflict(resolvedPath, result.error.meta?.etag);
10223
10237
  throw result.error;
10224
10238
  }
10225
10239
  return { etag: result.data.headers.etag };
@@ -12842,7 +12856,16 @@ var PersistedSessionDataSchema = import_zod8.z.object({
12842
12856
  * for backward compatibility with sessions persisted before this field
12843
12857
  * existed — those restore and lazily re-resolve their hosts.
12844
12858
  */
12845
- tinycloudHosts: import_zod8.z.array(import_zod8.z.string()).optional()
12859
+ tinycloudHosts: import_zod8.z.array(import_zod8.z.string()).optional(),
12860
+ /**
12861
+ * Replica gate stamp from a fresh sign-in (`establishSessionStamp`). Restore validates it with
12862
+ * `restoreSessionStamp` and never re-establishes it. Absent for sessions persisted before
12863
+ * replication existed; restore treats that as `not_established`.
12864
+ */
12865
+ replicaStamp: import_zod8.z.object({
12866
+ incarnation: import_zod8.z.string().min(1),
12867
+ lifecycleEpoch: import_zod8.z.number().int().nonnegative()
12868
+ }).strict().optional()
12846
12869
  });
12847
12870
  var TinyCloudSessionSchema = import_zod8.z.object({
12848
12871
  /** User's Ethereum address */