@tinycloud/sdk-core 3.0.0-beta.17 → 3.0.0-beta.18

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
@@ -11150,11 +11150,11 @@ var SharingService = class {
11150
11150
  }
11151
11151
  return result;
11152
11152
  };
11153
- const canSatisfyFromRegistry = this.findSuitableKeyForDelegation(
11153
+ const canSatisfyFromRegistry = this.classifyDelegationAuthority(
11154
11154
  fullPath,
11155
11155
  actions,
11156
11156
  requestedExpiry
11157
- );
11157
+ ) === "ok";
11158
11158
  if (canSatisfyFromRegistry) {
11159
11159
  const delegationResult = await this.createSessionDelegation(plainDID, fullPath, actions, expiry);
11160
11160
  const childDelegationActiveError = this.retiredGraphError();
@@ -11224,49 +11224,58 @@ var SharingService = class {
11224
11224
  return { ok: true, data: shareLink };
11225
11225
  }
11226
11226
  /**
11227
- * Check if any key in the registry can satisfy the delegation request.
11228
- * A key can satisfy if it has a delegation that:
11229
- * 1. Covers the required path (exact match or parent path)
11230
- * 2. Has all required actions
11231
- * 3. Has sufficient expiry (delegation.expiry >= requestedExpiry)
11232
- * 4. Allows sub-delegation
11227
+ * Report, without side effects, whether this session's registry authority
11228
+ * can issue the child delegation {@link generate} would create for the same
11229
+ * `path`, `actions` and `expiry` (defaults and `pathPrefix` applied the
11230
+ * same way):
11231
+ *
11232
+ * - `"ok"`: an uncaveated entry covers it.
11233
+ * - `"caveated"`: only caveated entries cover it. SharingService cannot
11234
+ * carry signed ReCap caveats into a child delegation.
11235
+ * - `"not-covered"`: no entry covers it, or there is no session.
11236
+ *
11237
+ * It does not consult `onRootDelegationNeeded`, so a signer-backed session
11238
+ * may still generate when this is not `"ok"`.
11239
+ */
11240
+ preflightGenerate(params) {
11241
+ if (!this.session || !params.path) return "not-covered";
11242
+ const fullPath = this.pathPrefix ? `${this.pathPrefix}/${params.path}`.replace(/\/+/g, "/") : params.path;
11243
+ return this.classifyDelegationAuthority(
11244
+ fullPath,
11245
+ params.actions ?? DEFAULT_READ_ACTIONS,
11246
+ params.expiry ?? new Date(Date.now() + DEFAULT_EXPIRY_MS)
11247
+ );
11248
+ }
11249
+ /**
11250
+ * Classify the registry's authority for a child delegation. An entry
11251
+ * satisfies it when it is in the session space, valid, lasts at least until
11252
+ * `requestedExpiry`, allows sub-delegation, covers `path` (exact or parent)
11253
+ * and grants every action. Satisfying entries with caveats are unusable.
11233
11254
  * @internal
11234
11255
  */
11235
- findSuitableKeyForDelegation(path, actions, requestedExpiry) {
11236
- const allKeys = this.registry.getAllKeys();
11237
- for (const key of allKeys) {
11238
- const delegations = this.registry.getDelegationsForKey(key.id);
11239
- for (const delegation of delegations) {
11256
+ classifyDelegationAuthority(path, actions, requestedExpiry) {
11257
+ let coveredOnlyByCaveated = false;
11258
+ for (const key of this.registry.getAllKeys()) {
11259
+ for (const delegation of this.registry.getDelegationsForKey(key.id)) {
11240
11260
  if (delegation.spaceId === void 0 || !spaceIdsEqual(delegation.spaceId, this.session?.spaceId ?? "")) {
11241
11261
  continue;
11242
11262
  }
11243
- if ((delegation.caveats?.length ?? 0) > 0) {
11244
- continue;
11245
- }
11246
- if (!this.registry.isDelegationValid(delegation)) {
11247
- continue;
11248
- }
11249
- if (delegation.expiry < requestedExpiry) {
11250
- continue;
11251
- }
11252
- if (delegation.allowSubDelegation === false) {
11253
- continue;
11254
- }
11255
- const delegationPath = delegation.path || "";
11256
- if (!this.pathMatches(delegationPath, path)) {
11263
+ if (!this.registry.isDelegationValid(delegation)) continue;
11264
+ if (delegation.expiry < requestedExpiry) continue;
11265
+ if (delegation.allowSubDelegation === false) continue;
11266
+ if (!this.pathMatches(delegation.path || "", path)) continue;
11267
+ const delegationActions = delegation.actions || [];
11268
+ if (!actions.every((action) => delegationActions.includes(action) || delegationActions.includes("*"))) {
11257
11269
  continue;
11258
11270
  }
11259
- const delegationActions = delegation.actions || [];
11260
- const hasAllActions = actions.every(
11261
- (action) => delegationActions.includes(action) || delegationActions.includes("*")
11262
- );
11263
- if (!hasAllActions) {
11271
+ if ((delegation.caveats?.length ?? 0) > 0) {
11272
+ coveredOnlyByCaveated = true;
11264
11273
  continue;
11265
11274
  }
11266
- return true;
11275
+ return "ok";
11267
11276
  }
11268
11277
  }
11269
- return false;
11278
+ return coveredOnlyByCaveated ? "caveated" : "not-covered";
11270
11279
  }
11271
11280
  retiredGraphError() {
11272
11281
  try {