@tinycloud/operations 0.7.0-beta.32 → 0.7.0-beta.33

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
@@ -5847,17 +5847,47 @@ var init_rules_generated = __esm({
5847
5847
  }
5848
5848
  });
5849
5849
 
5850
+ // src/revoked-grant.ts
5851
+ function isRevokedGrantRefusal(error) {
5852
+ if ((0, import_sdk_services2.authorizationVerdictOf)(error) !== "unauthenticated") return false;
5853
+ const seen = /* @__PURE__ */ new Set();
5854
+ let node = error;
5855
+ for (let depth = 0; depth < MAX_CAUSE_DEPTH && typeof node === "object" && node !== null && !seen.has(node); depth += 1) {
5856
+ seen.add(node);
5857
+ const { code, message, cause } = node;
5858
+ if (REVOKED_GRANT_CODES.has(code)) return true;
5859
+ if (typeof message === "string" && REVOKED_GRANT_BODY.test(message)) return true;
5860
+ node = cause;
5861
+ }
5862
+ return false;
5863
+ }
5864
+ var import_sdk_services2, MAX_CAUSE_DEPTH, REVOKED_GRANT_BODY, REVOKED_GRANT_CODES, REVOKED_GRANT_MESSAGE;
5865
+ var init_revoked_grant = __esm({
5866
+ "src/revoked-grant.ts"() {
5867
+ "use strict";
5868
+ import_sdk_services2 = require("@tinycloud/sdk-services");
5869
+ init_cli_name();
5870
+ MAX_CAUSE_DEPTH = 8;
5871
+ REVOKED_GRANT_BODY = /\b401 - (?:Invalid invocation: )?delegation-(?:revoked: [A-Za-z0-9]+|ancestor-revoked: ancestor=[A-Za-z0-9]+ invoked=[A-Za-z0-9]+)\s*$/;
5872
+ REVOKED_GRANT_CODES = /* @__PURE__ */ new Set(["AUTH_DELEGATION_REVOKED", "AUTH_DELEGATION_ANCESTOR_REVOKED"]);
5873
+ REVOKED_GRANT_MESSAGE = `This grant was revoked. Ask the owner for a new grant (\`${CLI_NAME} auth request ...\`).`;
5874
+ }
5875
+ });
5876
+
5850
5877
  // src/kv-failure.ts
5851
5878
  function kvRefusal(error) {
5852
- const verdict = (0, import_sdk_services2.authorizationVerdictOf)(error);
5879
+ const verdict = (0, import_sdk_services3.authorizationVerdictOf)(error);
5853
5880
  if (verdict === "unauthenticated") {
5854
- return (0, import_sdk_services2.validatedCapabilityOf)(error) === void 0 ? "auth_required" : "permission_denied";
5881
+ return (0, import_sdk_services3.validatedCapabilityOf)(error) === void 0 ? "auth_required" : "permission_denied";
5855
5882
  }
5856
5883
  return verdict === "forbidden" ? "permission_denied" : void 0;
5857
5884
  }
5858
5885
  function authorizationFailure(error, action) {
5859
5886
  switch (kvRefusal(error)) {
5860
5887
  case "auth_required":
5888
+ if (isRevokedGrantRefusal(error)) {
5889
+ return { status: "error", error: operationError("AUTH_REQUIRED", REVOKED_GRANT_MESSAGE) };
5890
+ }
5861
5891
  return { status: "error", error: operationError("AUTH_REQUIRED", `Authentication is required to ${action}.`) };
5862
5892
  case "permission_denied":
5863
5893
  return { status: "error", error: operationError("PERMISSION_DENIED", `Permission is denied to ${action}.`) };
@@ -5865,12 +5895,13 @@ function authorizationFailure(error, action) {
5865
5895
  return void 0;
5866
5896
  }
5867
5897
  }
5868
- var import_sdk_services2;
5898
+ var import_sdk_services3;
5869
5899
  var init_kv_failure = __esm({
5870
5900
  "src/kv-failure.ts"() {
5871
5901
  "use strict";
5872
- import_sdk_services2 = require("@tinycloud/sdk-services");
5902
+ import_sdk_services3 = require("@tinycloud/sdk-services");
5873
5903
  init_errors2();
5904
+ init_revoked_grant();
5874
5905
  }
5875
5906
  });
5876
5907