@mano8/astro-auth-m8 1.5.0 → 2.0.0

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.
Files changed (84) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/README.md +68 -3
  3. package/dist/src/runtime/api/apiKeys.d.ts +3 -1
  4. package/dist/src/runtime/api/apiKeys.d.ts.map +1 -1
  5. package/dist/src/runtime/api/apiKeys.js +9 -1
  6. package/dist/src/runtime/api/apiKeys.js.map +1 -1
  7. package/dist/src/runtime/api/index.d.ts +1 -0
  8. package/dist/src/runtime/api/index.d.ts.map +1 -1
  9. package/dist/src/runtime/api/index.js +1 -0
  10. package/dist/src/runtime/api/index.js.map +1 -1
  11. package/dist/src/runtime/api/ops.d.ts +2 -1
  12. package/dist/src/runtime/api/ops.d.ts.map +1 -1
  13. package/dist/src/runtime/api/ops.js +6 -1
  14. package/dist/src/runtime/api/ops.js.map +1 -1
  15. package/dist/src/runtime/api/security.d.ts +8 -0
  16. package/dist/src/runtime/api/security.d.ts.map +1 -0
  17. package/dist/src/runtime/api/security.js +23 -0
  18. package/dist/src/runtime/api/security.js.map +1 -0
  19. package/dist/src/runtime/api/users.d.ts +2 -2
  20. package/dist/src/runtime/api/users.d.ts.map +1 -1
  21. package/dist/src/runtime/api/users.js +2 -2
  22. package/dist/src/runtime/api/users.js.map +1 -1
  23. package/dist/src/runtime/authEvents.d.ts +25 -0
  24. package/dist/src/runtime/authEvents.d.ts.map +1 -0
  25. package/dist/src/runtime/authEvents.js +26 -0
  26. package/dist/src/runtime/authEvents.js.map +1 -0
  27. package/dist/src/runtime/authorization.d.ts +80 -0
  28. package/dist/src/runtime/authorization.d.ts.map +1 -0
  29. package/dist/src/runtime/authorization.js +109 -0
  30. package/dist/src/runtime/authorization.js.map +1 -0
  31. package/dist/src/runtime/browserAdapter.d.ts.map +1 -1
  32. package/dist/src/runtime/browserAdapter.js +23 -0
  33. package/dist/src/runtime/browserAdapter.js.map +1 -1
  34. package/dist/src/runtime/compatibility.d.ts +6 -6
  35. package/dist/src/runtime/compatibility.d.ts.map +1 -1
  36. package/dist/src/runtime/compatibility.js +35 -5
  37. package/dist/src/runtime/compatibility.js.map +1 -1
  38. package/dist/src/runtime/errors.d.ts +39 -0
  39. package/dist/src/runtime/errors.d.ts.map +1 -1
  40. package/dist/src/runtime/errors.js +79 -0
  41. package/dist/src/runtime/errors.js.map +1 -1
  42. package/dist/src/runtime/hooks/index.d.ts +1 -0
  43. package/dist/src/runtime/hooks/index.d.ts.map +1 -1
  44. package/dist/src/runtime/hooks/index.js +1 -0
  45. package/dist/src/runtime/hooks/index.js.map +1 -1
  46. package/dist/src/runtime/hooks/useApiKeys.d.ts +69 -0
  47. package/dist/src/runtime/hooks/useApiKeys.d.ts.map +1 -1
  48. package/dist/src/runtime/hooks/useApiKeys.js +38 -1
  49. package/dist/src/runtime/hooks/useApiKeys.js.map +1 -1
  50. package/dist/src/runtime/hooks/useSecurity.d.ts +70 -0
  51. package/dist/src/runtime/hooks/useSecurity.d.ts.map +1 -0
  52. package/dist/src/runtime/hooks/useSecurity.js +60 -0
  53. package/dist/src/runtime/hooks/useSecurity.js.map +1 -0
  54. package/dist/src/runtime/hooks/useUsers.d.ts +4 -15
  55. package/dist/src/runtime/hooks/useUsers.d.ts.map +1 -1
  56. package/dist/src/runtime/hooks/useUsers.js +18 -4
  57. package/dist/src/runtime/hooks/useUsers.js.map +1 -1
  58. package/dist/src/runtime/queryKeys.d.ts +2 -0
  59. package/dist/src/runtime/queryKeys.d.ts.map +1 -1
  60. package/dist/src/runtime/queryKeys.js +3 -1
  61. package/dist/src/runtime/queryKeys.js.map +1 -1
  62. package/dist/src/runtime/react/AuthProvider.d.ts.map +1 -1
  63. package/dist/src/runtime/react/AuthProvider.js +24 -0
  64. package/dist/src/runtime/react/AuthProvider.js.map +1 -1
  65. package/dist/src/runtime/react/RequireRole.d.ts.map +1 -1
  66. package/dist/src/runtime/react/RequireRole.js +3 -2
  67. package/dist/src/runtime/react/RequireRole.js.map +1 -1
  68. package/dist/src/runtime/react/index.d.ts +1 -0
  69. package/dist/src/runtime/react/index.d.ts.map +1 -1
  70. package/dist/src/runtime/react/index.js +4 -0
  71. package/dist/src/runtime/react/index.js.map +1 -1
  72. package/dist/src/runtime/schemas.d.ts +186 -1
  73. package/dist/src/runtime/schemas.d.ts.map +1 -1
  74. package/dist/src/runtime/schemas.js +74 -3
  75. package/dist/src/runtime/schemas.js.map +1 -1
  76. package/package.json +8 -5
  77. package/registry/r/account-crud.json +1 -1
  78. package/registry/r/account-dashboard.json +1 -1
  79. package/registry/r/admin-users-panel.json +1 -1
  80. package/registry/r/api-keys-panel.json +1 -1
  81. package/registry/r/registry.json +6 -0
  82. package/registry/r/security-panel.json +27 -0
  83. package/registry/r/sessions-panel.json +1 -1
  84. package/registry.json +22 -0
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Framework-neutral role/flag authorization primitives.
3
+ *
4
+ * TypeScript mirror of `auth_sdk_m8/authorization.py`, the canonical source.
5
+ * Canonical role/flag truth table (one row per valid state):
6
+ *
7
+ * ```text
8
+ * role is_superuser=false is_superuser=true
9
+ * user valid, non-superuser invalid
10
+ * reader valid, non-superuser invalid
11
+ * writer valid, non-superuser invalid
12
+ * admin valid, non-superuser invalid
13
+ * superadmin invalid valid superuser
14
+ * ```
15
+ *
16
+ * No caller may derive an authorization decision from `role` alone or
17
+ * `is_superuser` alone - the two claims must agree. This module is the single
18
+ * place in the package that encodes the hierarchy and the cross-field
19
+ * invariant, so every consumer (components, hooks, registry skins) shares one
20
+ * implementation.
21
+ *
22
+ * These are client-side display predicates. The backend remains the authority;
23
+ * mirroring its rules here only stops the UI from showing privileged surfaces
24
+ * the server would refuse.
25
+ */
26
+ import { RoleTypeSchema } from "./schemas.js";
27
+ /**
28
+ * Roles ordered from highest to lowest privilege.
29
+ *
30
+ * Sourced from `RoleTypeSchema` so the hierarchy exists as exactly one list in
31
+ * this package, mirroring `RoleType.get_ordered_roles()`. The schema declares
32
+ * its members in descending privilege order; `tests/authorization.test.ts`
33
+ * locks that order in so a reordering of the enum fails loudly instead of
34
+ * silently changing every authorization decision.
35
+ */
36
+ export const ORDERED_ROLES = RoleTypeSchema.options;
37
+ /** The single role that carries superuser authority. */
38
+ const SUPERADMIN_ROLE = "superadmin";
39
+ /**
40
+ * Whether `role` is a role this build recognises.
41
+ *
42
+ * The type system already constrains typed call sites, but this package is
43
+ * published to JavaScript consumers and its claims originate from a backend
44
+ * that may be newer than the client. An unrecognised role is not on the truth
45
+ * table, so it is treated as no privilege at all rather than guessed at.
46
+ */
47
+ function isKnownRole(role) {
48
+ return ORDERED_ROLES.includes(role);
49
+ }
50
+ /**
51
+ * Return whether `currentRole` meets or exceeds `requiredRole`.
52
+ *
53
+ * Canonical role hierarchy check, ordered highest to lowest privilege via
54
+ * {@link ORDERED_ROLES}. This is the single implementation of the hierarchy;
55
+ * no consumer should duplicate a role-ordered list or compare roles by exact
56
+ * membership - exact membership hides an admin surface from a superadmin.
57
+ *
58
+ * Returns `false` for an insufficient or unrecognised role.
59
+ */
60
+ export function hasMinimumRole(currentRole, requiredRole) {
61
+ const current = ORDERED_ROLES.indexOf(currentRole);
62
+ const required = ORDERED_ROLES.indexOf(requiredRole);
63
+ if (current === -1 || required === -1)
64
+ return false;
65
+ return current <= required;
66
+ }
67
+ /**
68
+ * Return whether `role` and `isSuperuser` agree per the truth table.
69
+ *
70
+ * Pure cross-field invariant, independent of any hierarchy comparison:
71
+ *
72
+ * - `superadmin` requires `isSuperuser === true`.
73
+ * - Every other recognised role requires `isSuperuser === false`.
74
+ *
75
+ * Returns `true` only when the pair is one of the five valid rows. The claims
76
+ * are compared strictly (`=== true` / `=== false`) rather than by truthiness,
77
+ * so a JavaScript consumer passing an unparsed value cannot widen the
78
+ * invariant.
79
+ *
80
+ * Deviation from the Python original, deliberate: `auth_sdk_m8` types `role`
81
+ * as a closed enum, so an unrecognised role cannot reach it and the final
82
+ * branch treats every non-superadmin input as valid. Here the claims may come
83
+ * from a backend this build does not know, so an unrecognised role is not one
84
+ * of the five rows and fails closed.
85
+ */
86
+ export function privilegeClaimsAreConsistent(role, isSuperuser) {
87
+ if (!isKnownRole(role))
88
+ return false;
89
+ if (role === SUPERADMIN_ROLE)
90
+ return isSuperuser === true;
91
+ return isSuperuser === false;
92
+ }
93
+ /**
94
+ * Return the exact dual-evidence canonical-superuser predicate.
95
+ *
96
+ * Requires both the consistency invariant and the canonical pair
97
+ * (`role === "superadmin"` and `isSuperuser === true`). Callers must use this
98
+ * instead of reading `is_superuser` or `role` alone - a stray
99
+ * `is_superuser: true` on a non-superadmin role (or vice versa) never grants
100
+ * superuser privileges. Such mismatched pairs are not hypothetical: they exist
101
+ * on rows written before `fa-auth-m8` 2.0.0 added its consistency constraint,
102
+ * for the length of the expand/repair migration window.
103
+ */
104
+ export function hasSuperuserPrivileges(role, isSuperuser) {
105
+ return privilegeClaimsAreConsistent(role, isSuperuser)
106
+ && role === SUPERADMIN_ROLE
107
+ && isSuperuser === true;
108
+ }
109
+ //# sourceMappingURL=authorization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../src/runtime/authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAE7D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,aAAa,GAAwB,cAAc,CAAC,OAAO,CAAC;AAEzE,wDAAwD;AACxD,MAAM,eAAe,GAAa,YAAY,CAAC;AAE/C;;;;;;;GAOG;AACH,SAAS,WAAW,CAAC,IAAc;IACjC,OAAO,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAAC,WAAqB,EAAE,YAAsB;IAC1E,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,WAAW,CAAC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C;AAMF;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,GAAE,OAAO,CAAC,iBAAiB,CAAM,GACtC,oBAAoB,CAkBtB"}
1
+ {"version":3,"file":"browserAdapter.d.ts","sourceRoot":"","sources":["../../../src/runtime/browserAdapter.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGpE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC5D,YAAY,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACpC,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACtC,cAAc,EAAE,MAAM,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAClD,CAAC;AA2BF;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,GAAE,OAAO,CAAC,iBAAiB,CAAM,GACtC,oBAAoB,CAmBtB"}
@@ -1,7 +1,29 @@
1
1
  import { refreshToken } from "./api/auth.js";
2
+ import { getServiceMeta } from "./api/ops.js";
2
3
  import { getProfile } from "./api/profile.js";
4
+ import { getFaAuthM8Compatibility } from "./compatibility.js";
3
5
  import { configureAuth } from "./config.js";
4
6
  import { getToken } from "./tokenStore.js";
7
+ let warnedUnknownCompatibility = false;
8
+ // AA-16/AA-22: warn-not-throw preflight against the released fa-auth-m8
9
+ // contract. Runs once per adapter install and never blocks or fails setup —
10
+ // a GET /meta failure (offline, CORS, an older backend without the route) is
11
+ // swallowed, since this is advisory only. `assertFaAuthM8Compatibility`
12
+ // remains exported, unchanged, for hosts that want to fail closed instead.
13
+ function runCompatibilityPreflight() {
14
+ void getServiceMeta()
15
+ .then((meta) => {
16
+ const compatibility = getFaAuthM8Compatibility(meta);
17
+ if (compatibility.status === "incompatible") {
18
+ console.warn(`[@mano8/astro-auth-m8] ${compatibility.reason}`);
19
+ }
20
+ else if (compatibility.status === "unknown" && !warnedUnknownCompatibility) {
21
+ warnedUnknownCompatibility = true;
22
+ console.warn(`[@mano8/astro-auth-m8] ${compatibility.reason}`);
23
+ }
24
+ })
25
+ .catch(() => { });
26
+ }
5
27
  /**
6
28
  * Expose the auth-owned browser adapter for independently installed plugins.
7
29
  * Plugins consume this browser contract through their local auth adapters;
@@ -9,6 +31,7 @@ import { getToken } from "./tokenStore.js";
9
31
  */
10
32
  export function installFaAuthBrowserAdapter(config = {}) {
11
33
  configureAuth(config);
34
+ runCompatibilityPreflight();
12
35
  const adapter = {
13
36
  getAccessToken: getToken,
14
37
  refresh: async () => (await refreshToken()).access_token,
@@ -1 +1 @@
1
- {"version":3,"file":"browserAdapter.js","sourceRoot":"","sources":["../../../src/runtime/browserAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAA0B,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAkB3C;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CACzC,SAAqC,EAAE;IAEvC,aAAa,CAAC,MAAM,CAAC,CAAC;IAEtB,MAAM,OAAO,GAAyB;QACpC,cAAc,EAAE,QAAQ;QACxB,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,YAAY,EAAE,CAAC,CAAC,YAAY;QACxD,cAAc,EAAE,KAAK,IAAI,EAAE;YACzB,MAAM,IAAI,GAAG,MAAM,UAAU,EAAE,CAAC;YAChC,OAAO;gBACL,EAAE,EAAE,IAAI,CAAC,EAAE;gBACX,IAAI,EAAE,IAAI,CAAC,IAAI;g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AACH,MAAM,UAAU,2BAA2B,CACzC,SAAqC,EAAE;IAEvC,aAAa,CAAC,MAAM,CAAC,CAAC;IACtB,yBAAyB,EAAE,CAAC;IAE5B,MAAM,OAAO,GAAyB;QACpC,cAAc,EAAE,QAAQ;QACxB,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,YAAY,EAAE,CAAC,CAAC,YAAY;QACxD,cAAc,EAAE,KAAK,IAAI,EAAE;YACzB,MAAM,IAAI,GAAG,MAAM,UAAU,EAAE,CAAC;YAChC,OAAO;gBACL,EAAE,EAAE,IAAI,CAAC,EAAE;gBACX,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,YAAY,EAAE,IAAI,CAAC,YAAY;aAChC,CAAC;QACJ,CAAC;KACF,CAAC;IAED,UAAgC,CAAC,sBAAsB,GAAG,OAAO,CAAC;IACnE,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -1,10 +1,10 @@
1
1
  export declare const FA_AUTH_M8_CONTRACT_ID = "fa-auth-m8";
2
- export declare const FA_AUTH_M8_CONTRACT_VERSION = "1.0";
3
- export declare const FA_AUTH_M8_CONTRACT: "fa-auth-m8@1.0";
4
- export declare const FA_AUTH_M8_TESTED_SERVICE_VERSION = "1.1.0";
5
- export declare const FA_AUTH_M8_MIN_SERVICE_VERSION = "1.0.0";
6
- export declare const FA_AUTH_M8_MAX_SERVICE_VERSION_EXCLUSIVE = "2.0.0";
7
- export declare const FA_AUTH_M8_SERVICE_VERSION_RANGE = ">=1.0.0 <2.0.0";
2
+ export declare const FA_AUTH_M8_CONTRACT_VERSION = "2.0";
3
+ export declare const FA_AUTH_M8_CONTRACT: "fa-auth-m8@2.0";
4
+ export declare const FA_AUTH_M8_TESTED_SERVICE_VERSION = "2.0.0";
5
+ export declare const FA_AUTH_M8_MIN_SERVICE_VERSION = "2.0.0";
6
+ export declare const FA_AUTH_M8_MAX_SERVICE_VERSION_EXCLUSIVE = "3.0.0";
7
+ export declare const FA_AUTH_M8_SERVICE_VERSION_RANGE = ">=2.0.0 <3.0.0";
8
8
  export type FaAuthM8CompatibilityStatus = "compatible" | "incompatible" | "unknown";
9
9
  export type FaAuthM8VersionMetadata = {
10
10
  contract?: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"compatibility.d.ts","sourceRoot":"","sources":["../../../src/runtime/compatibility.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,eAAe,CAAC;AACnD,eAAO,MAAM,2BAA2B,QAAQ,CAAC;AACjD,eAAO,MAAM,mBAAmB,kBAAsE,CAAC;AAEvG,eAAO,MAAM,iCAAiC,UAAU,CAAC;AACzD,eAAO,MAAM,8BAA8B,UAAU,CAAC;AACtD,eAAO,MAAM,wCAAwC,UAAU,CAAC;AAChE,eAAO,MAAM,gCAAgC,mBAAqF,CAAC;AAEnI,MAAM,MAAM,2BAA2B,GAAG,YAAY,GAAG,cAAc,GAAG,SAAS,CAAC;AAEpF,MAAM,MAAM,uBAAuB,GAAG;IAGpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,2BAA2B,CAAC;IACpC,gBAAgB,EAAE,OAAO,mBAAmB,CAAC;IAC7C,2BAA2B,EAAE,OAAO,gCAAgC,CAAC;IACrE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,C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A2B,EAAE,OAAO,gCAAgC,CAAC;IACrE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AA+CF,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAI3E;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,GAAE,uBAA4B,GAAG,qBAAqB,CAiEtG;AAED,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,uBAAuB,EAAE,YAAY,UAAO,GAAG,qBAAqB,CAMzH"}
@@ -1,10 +1,10 @@
1
1
  export const FA_AUTH_M8_CONTRACT_ID = "fa-auth-m8";
2
- export const FA_AUTH_M8_CONTRACT_VERSION = "1.0";
2
+ export const FA_AUTH_M8_CONTRACT_VERSION = "2.0";
3
3
  export const FA_AUTH_M8_CONTRACT = `${FA_AUTH_M8_CONTRACT_ID}@${FA_AUTH_M8_CONTRACT_VERSION}`;
4
- // 1.1.0 is the supported fa-auth-m8 service baseline for this plugin.
5
- export const FA_AUTH_M8_TESTED_SERVICE_VERSION = "1.1.0";
6
- export const FA_AUTH_M8_MIN_SERVICE_VERSION = "1.0.0";
7
- export const FA_AUTH_M8_MAX_SERVICE_VERSION_EXCLUSIVE = "2.0.0";
4
+ // 2.0.0 is the supported fa-auth-m8 service baseline for this plugin.
5
+ export const FA_AUTH_M8_TESTED_SERVICE_VERSION = "2.0.0";
6
+ export const FA_AUTH_M8_MIN_SERVICE_VERSION = "2.0.0";
7
+ export const FA_AUTH_M8_MAX_SERVICE_VERSION_EXCLUSIVE = "3.0.0";
8
8
  export const FA_AUTH_M8_SERVICE_VERSION_RANGE = `>=${FA_AUTH_M8_MIN_SERVICE_VERSION} <${FA_AUTH_M8_MAX_SERVICE_VERSION_EXCLUSIVE}`;
9
9
  function stringValue(value) {
10
10
  return typeof value === "string" && value.trim() ? value.trim() : undefined;
@@ -16,6 +16,21 @@ function contractObjectVersion(value) {
16
16
  }
17
17
  return undefined;
18
18
  }
19
+ // Read ``contract.name`` from the GET /meta nested contract object.
20
+ //
21
+ // The flat-string contract forms carry the issuer id inline (``fa-auth-m8@2.0``)
22
+ // and are checked against it, but the nested object splits id and version apart.
23
+ // Without reading ``name`` the version check alone would bless any service whose
24
+ // contract happens to sit at the same version - and ``mount_service_meta`` is a
25
+ // shared auth-sdk-m8 helper, so every M8 service serves this same payload shape
26
+ // at ``{API_PREFIX}/meta``. A host pointed at the wrong sibling is exactly the
27
+ // misconfiguration the preflight exists to name.
28
+ function contractObjectName(value) {
29
+ if (typeof value === "object" && value !== null) {
30
+ return stringValue(value.name);
31
+ }
32
+ return undefined;
33
+ }
19
34
  function parseSemver(version) {
20
35
  const match = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/.exec(version);
21
36
  if (!match)
@@ -50,6 +65,21 @@ export function getFaAuthM8Compatibility(metadata = {}) {
50
65
  const serviceVersion = stringValue(metadata.fa_auth_m8_version)
51
66
  ?? stringValue(metadata.service_version)
52
67
  ?? stringValue(metadata.version);
68
+ // Checked before the version, so a wrong service is reported as a wrong
69
+ // service rather than as a version mismatch. Only applies when the payload
70
+ // names an id at all - a nested contract without a `name` still falls through
71
+ // to the version comparison below.
72
+ const contractName = contractObjectName(metadata.contract);
73
+ if (contractName && contractName !== FA_AUTH_M8_CONTRACT_ID) {
74
+ return {
75
+ status: "incompatible",
76
+ expectedContract: FA_AUTH_M8_CONTRACT,
77
+ expectedServiceVersionRange: FA_AUTH_M8_SERVICE_VERSION_RANGE,
78
+ contractVersion,
79
+ serviceVersion,
80
+ reason: `Expected ${FA_AUTH_M8_CONTRACT}, received the ${contractName} contract - check the configured auth API base`
81
+ };
82
+ }
53
83
  if (contractVersion && contractVersion !== FA_AUTH_M8_CONTRACT_VERSION && contractVersion !== FA_AUTH_M8_CONTRACT) {
54
84
  return {
55
85
  status: "incompatible",
@@ -1 +1 @@
1
- {"version":3,"file":"compatibility.js","sourceRoot":"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kCAAkC,CAAC,cAAc,CAAC,EAAE,CAAC;QAC1E,OAAO;YACL,MAAM,EAAE,cAAc;YACtB,gBAAgB,EAAE,mBAAmB;YACrC,2BAA2B,EAAE,gCAAgC;YAC7D,eAAe;YACf,cAAc;YACd,MAAM,EAAE,uCAAuC,gCAAgC,cAAc,cAAc,EAAE;SAC9G,CAAC;IACJ,CAAC;IAED,IAAI,eAAe,IAAI,cAAc,EAAE,CAAC;QACtC,OAAO;YACL,MAAM,EAAE,YAAY;YACpB,gBAAgB,EAAE,mBAAmB;YACrC,2BAA2B,EAAE,gCAAgC;YAC7D,eAAe;YACf,cAAc;SACf,CAAC;IACJ,CAAC;IAED,OAAO;QACL,MAAM,EAAE,SAAS;QACjB,gBAAgB,EAAE,mBAAmB;QACrC,2BAA2B,EAAE,gCAAgC;QAC7D,MAAM,EAAE,iEAAiE;KAC1E,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,QAAiC,EAAE,YAAY,GAAG,IAAI;IAChG,MAAM,aAAa,GAAG,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IACzD,IAAI,aAAa,CAAC,MAAM,KAAK,cAAc,IAAI,CAAC,YAAY,IAAI,aAAa,CAAC,MAAM,KAAK,SAAS,CAAC,EAAE,CAAC;QACpG,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -17,4 +17,43 @@ export declare class UnauthenticatedError extends ApiError {
17
17
  constructor(message?: string);
18
18
  }
19
19
  export declare function normalizeFastApiError(payload: unknown): unknown;
20
+ /**
21
+ * An operator-facing error presentation: a short labelled `title` plus an
22
+ * optional `description` with more detail. Never contains a raw backend
23
+ * detail token (e.g. `last_superuser_required`) as the `title` - only as a
24
+ * verbatim `description` where the contract guarantees it is free text meant
25
+ * for display (the `400` retention-floor case).
26
+ */
27
+ export interface ApiErrorPresentation {
28
+ title: string;
29
+ description?: string;
30
+ }
31
+ /**
32
+ * Map a `fa-auth-m8` 2.0.0 authorization/rate-limit/retention error to an
33
+ * operator-readable presentation. Covers the role-change error contracts
34
+ * shared by `PATCH /users/update/{id}/` and `DELETE /users/delete/{id}/`
35
+ * (403 self-promotion, 409 `last_superuser_required`) plus the rate-limit and
36
+ * retention-floor contracts every new admin surface (audit log, both purges)
37
+ * shares with them, so callers do not each re-derive these mappings:
38
+ *
39
+ * - `403` - not permitted (e.g. a role change refused as self-promotion, or a
40
+ * privileged read/purge attempted without the tier). Titled by status, since
41
+ * several mapped surfaces produce a `403` and the detail that would tell them
42
+ * apart is not a stable contract; the backend's own readable detail carries
43
+ * the specific cause.
44
+ * - `409` with detail `last_superuser_required` - the raw token is never
45
+ * surfaced; replaced with a labelled explanation.
46
+ * - `429` - rate limited. The action was not attempted; safe to retry later,
47
+ * never automatically.
48
+ * - `503` - fail-closed rate limiting (e.g. Redis unavailable). Unlike `429`,
49
+ * the action's outcome is *unknown* - the message must not imply failure,
50
+ * and callers must not auto-retry (a retry could double an already-applied
51
+ * effect).
52
+ * - `400` - e.g. a purge's retention-floor rejection. The detail is free
53
+ * text (`str(exc)`) and is surfaced verbatim under a labelled heading,
54
+ * never pattern-matched into a token, since it is not a stable contract.
55
+ *
56
+ * Anything else falls back to the error's own message, then `fallback`.
57
+ */
58
+ export declare function describeApiError(error: unknown, fallback: string): ApiErrorPresentation;
20
59
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/runtime/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,YAAY;;iBAEvB,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAarE;AAED,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;gBAEb,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM;CAM9D;AAED,qBAAa,oBAAqB,SAAQ,QAAQ;gBACpC,OAAO,SAA4B;CAIhD;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAG/D"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/runtime/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,YAAY;;iBAEvB,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAarE;AAED,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;gBAEb,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM;CAM9D;AAED,qBAAa,oBAAqB,SAAQ,QAAQ;gBACpC,OAAO,SAA4B;CAIhD;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAG/D;AAED;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAyDD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,oBAAoB,CAYvF"}
@@ -41,4 +41,83 @@ export function normalizeFastApiError(payload) {
41
41
  const parsed = ApiErrorBody.safeParse(payload);
42
42
  return parsed.success ? parsed.data.detail : payload;
43
43
  }
44
+ const LAST_SUPERUSER_REQUIRED = "last_superuser_required";
45
+ /**
46
+ * One entry per mapped status. Kept as a table rather than a chain of `if`s so
47
+ * a new contract is a new row, and so each mapping can be read - and reviewed
48
+ * against the backend route that produces it - on its own.
49
+ */
50
+ const API_ERROR_PRESENTERS = new Map([
51
+ [400, (detail) => (detail ? { title: "Rejected", description: detail } : undefined)],
52
+ // Titled by status, not by cause: every mapped surface can produce a 403
53
+ // (a role change refused as self-promotion, but also an audit-log read or a
54
+ // purge attempted by a principal demoted since the page loaded), and the
55
+ // detail string that would distinguish them is not a stable contract. The
56
+ // backend's own 403 detail is already operator-readable ("A user may not
57
+ // raise their own role"), so it carries the specific cause as the
58
+ // description while the title never asserts one that may be wrong.
59
+ [403, (detail, fallback) => ({ title: "Not permitted", description: detail ?? fallback })],
60
+ [
61
+ 409,
62
+ (detail) => detail === LAST_SUPERUSER_REQUIRED
63
+ ? {
64
+ title: "Last superuser required",
65
+ description: "This is the only remaining superuser account, so it can't be changed or removed."
66
+ }
67
+ : undefined
68
+ ],
69
+ [
70
+ 429,
71
+ () => ({
72
+ title: "Too many requests",
73
+ description: "Try again later - this action was not attempted."
74
+ })
75
+ ],
76
+ [
77
+ 503,
78
+ () => ({
79
+ title: "Temporarily unavailable",
80
+ description: "The outcome of this action is unknown. Do not retry until you've confirmed its status."
81
+ })
82
+ ]
83
+ ]);
84
+ /**
85
+ * Map a `fa-auth-m8` 2.0.0 authorization/rate-limit/retention error to an
86
+ * operator-readable presentation. Covers the role-change error contracts
87
+ * shared by `PATCH /users/update/{id}/` and `DELETE /users/delete/{id}/`
88
+ * (403 self-promotion, 409 `last_superuser_required`) plus the rate-limit and
89
+ * retention-floor contracts every new admin surface (audit log, both purges)
90
+ * shares with them, so callers do not each re-derive these mappings:
91
+ *
92
+ * - `403` - not permitted (e.g. a role change refused as self-promotion, or a
93
+ * privileged read/purge attempted without the tier). Titled by status, since
94
+ * several mapped surfaces produce a `403` and the detail that would tell them
95
+ * apart is not a stable contract; the backend's own readable detail carries
96
+ * the specific cause.
97
+ * - `409` with detail `last_superuser_required` - the raw token is never
98
+ * surfaced; replaced with a labelled explanation.
99
+ * - `429` - rate limited. The action was not attempted; safe to retry later,
100
+ * never automatically.
101
+ * - `503` - fail-closed rate limiting (e.g. Redis unavailable). Unlike `429`,
102
+ * the action's outcome is *unknown* - the message must not imply failure,
103
+ * and callers must not auto-retry (a retry could double an already-applied
104
+ * effect).
105
+ * - `400` - e.g. a purge's retention-floor rejection. The detail is free
106
+ * text (`str(exc)`) and is surfaced verbatim under a labelled heading,
107
+ * never pattern-matched into a token, since it is not a stable contract.
108
+ *
109
+ * Anything else falls back to the error's own message, then `fallback`.
110
+ */
111
+ export function describeApiError(error, fallback) {
112
+ if (error instanceof ApiError) {
113
+ const detail = typeof error.detail === "string" ? error.detail : undefined;
114
+ const presented = API_ERROR_PRESENTERS.get(error.status)?.(detail, fallback);
115
+ if (presented)
116
+ return presented;
117
+ }
118
+ if (error instanceof Error && error.message) {
119
+ return { title: error.message };
120
+ }
121
+ return { title: fallback };
122
+ }
44
123
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/runtime/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;CACpB,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAe;IAC/C,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,EAAE;QAAE,OAAO,MAAM,CAAC;IAC/D,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,MAAM;aACjB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,IAAI,IAAI,OAA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AAyB;YAChC,WAAW,EACT,wFAAwF;SAC3F,CAAC;KACH;CACF,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,QAAgB;IAC/D,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3E,MAAM,SAAS,GAAG,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC7E,IAAI,SAAS;YAAE,OAAO,SAAS,CAAC;IAClC,CAAC;IAED,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAC5C,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAClC,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC7B,CAAC"}
@@ -3,6 +3,7 @@ export * from "./useApiKeys.js";
3
3
  export * from "./useDashboard.js";
4
4
  export * from "./useGoogleLogin.js";
5
5
  export * from "./useProfile.js";
6
+ export * from "./useSecurity.js";
6
7
  export * from "./useSessions.js";
7
8
  export * from "./useUsers.js";
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
@@ -3,6 +3,7 @@ export * from "./useApiKeys.js";
3
3
  export * from "./useDashboard.js";
4
4
  export * from "./useGoogleLogin.js";
5
5
  export * from "./useProfile.js";
6
+ export * from "./useSecurity.js";
6
7
  export * from "./useSessions.js";
7
8
  export * from "./useUsers.js";
8
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtime/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtime/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
@@ -6,6 +6,8 @@ export declare function useApiKeys(load?: boolean): {
6
6
  expires_at: string | null;
7
7
  revoked: boolean;
8
8
  last_used_at: string | null;
9
+ access_mode: "read_only" | "read_write";
10
+ audiences: string[];
9
11
  created_at?: string | undefined;
10
12
  updated_at?: string | undefined;
11
13
  }[];
@@ -15,6 +17,8 @@ export declare function useApiKeys(load?: boolean): {
15
17
  expires_at: string | null;
16
18
  revoked: boolean;
17
19
  last_used_at: string | null;
20
+ access_mode: "read_only" | "read_write";
21
+ audiences: string[];
18
22
  plaintext: string;
19
23
  created_at?: string | undefined;
20
24
  updated_at?: string | undefined;
@@ -27,6 +31,8 @@ export declare function useApiKeys(load?: boolean): {
27
31
  expires_at: string | null;
28
32
  revoked: boolean;
29
33
  last_used_at: string | null;
34
+ access_mode: "read_only" | "read_write";
35
+ audiences: string[];
30
36
  created_at?: string | undefined;
31
37
  updated_at?: string | undefined;
32
38
  }[]>;
@@ -36,6 +42,8 @@ export declare function useApiKeys(load?: boolean): {
36
42
  expires_at: string | null;
37
43
  revoked: boolean;
38
44
  last_used_at: string | null;
45
+ access_mode: "read_only" | "read_write";
46
+ audiences: string[];
39
47
  plaintext: string;
40
48
  created_at?: string | undefined;
41
49
  updated_at?: string | undefined;
@@ -49,12 +57,16 @@ export declare function useApiKeys(load?: boolean): {
49
57
  expires_at: string | null;
50
58
  revoked: boolean;
51
59
  last_used_at: string | null;
60
+ access_mode: "read_only" | "read_write";
61
+ audiences: string[];
52
62
  plaintext: string;
53
63
  created_at?: string | undefined;
54
64
  updated_at?: string | undefined;
55
65
  }, Error, {
56
66
  ttl_hours: number;
67
+ access_mode: "read_only" | "read_write";
57
68
  name?: string | null | undefined;
69
+ audiences?: string[] | null | undefined;
58
70
  }, unknown>;
59
71
  revokeMutation: import("@tanstack/react-query").UseMutationResult<{
60
72
  message: string;
@@ -67,8 +79,65 @@ export declare function useApiKeys(load?: boolean): {
67
79
  expires_at: string | null;
68
80
  revoked: boolean;
69
81
  last_used_at: string | null;
82
+ access_mode: "read_only" | "read_write";
83
+ audiences: string[];
70
84
  created_at?: string | undefined;
71
85
  updated_at?: string | undefined;
72
86
  }[]>, Error>>;
73
87
  };
88
+ export declare function useAdminApiKeys(userId: string, load?: boolean): {
89
+ apiKeys: {
90
+ id: string;
91
+ name: string | null;
92
+ user_id: string;
93
+ revoked: boolean;
94
+ expires_at: string | null;
95
+ last_used_at: string | null;
96
+ created_at: string;
97
+ access_mode: "read_only" | "read_write";
98
+ status: "revoked" | "active" | "expired";
99
+ audiences: string[];
100
+ }[];
101
+ count: number;
102
+ loading: boolean;
103
+ error: Error | null;
104
+ reload: () => Promise<NoInfer<{
105
+ data: {
106
+ id: string;
107
+ name: string | null;
108
+ user_id: string;
109
+ revoked: boolean;
110
+ expires_at: string | null;
111
+ last_used_at: string | null;
112
+ created_at: string;
113
+ access_mode: "read_only" | "read_write";
114
+ status: "revoked" | "active" | "expired";
115
+ audiences: string[];
116
+ }[];
117
+ count: number;
118
+ }> | null>;
119
+ revoke: (keyId: string) => Promise<{
120
+ message: string;
121
+ }>;
122
+ revokeMutation: import("@tanstack/react-query").UseMutationResult<{
123
+ message: string;
124
+ }, Error, string, unknown>;
125
+ isLoading: boolean;
126
+ isFetching: boolean;
127
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<NoInfer<{
128
+ data: {
129
+ id: string;
130
+ name: string | null;
131
+ user_id: string;
132
+ revoked: boolean;
133
+ expires_at: string | null;
134
+ last_used_at: string | null;
135
+ created_at: string;
136
+ access_mode: "read_only" | "read_write";
137
+ status: "revoked" | "active" | "expired";
138
+ audiences: string[];
139
+ }[];
140
+ count: number;
141
+ }>, Error>>;
142
+ };
74
143
  //# sourceMappingURL=useApiKeys.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useApiKeys.d.ts","sourceRoot":"","sources":["../../../../src/runtime/hooks/useApiKeys.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAA+B,MAAM,eAAe,CAAC;AAE/E,wBAAgB,UAAU,CAAC,IAAI,UAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA6BF,YAAY;;;;;;;;;;iBACd,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBvC"}
1
+ {"version":3,"file":"useApiKeys.d.ts","sourceRoot":"","sources":["../../../../src/runtime/hooks/useApiKeys.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAqB,YAAY,EAA+B,MAAM,eAAe,CAAC;AAElG,wBAAgB,UAAU,CAAC,IAAI,UAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA6BF,YAAY;;;;;;;;;;;;iBACd,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBvC;AAKD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,UAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAmBtB,MAAM;;;;;;;;;;;;;;;;;;;;;;;EAkB1C"}
@@ -1,6 +1,6 @@
1
1
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2
2
  import { useCallback, useState } from "react";
3
- import { createApiKey, listApiKeys, revokeApiKey } from "../api/apiKeys.js";
3
+ import { adminListUserApiKeys, adminRevokeApiKey, createApiKey, listApiKeys, revokeApiKey } from "../api/apiKeys.js";
4
4
  import { refetchOrThrow } from "./queryHelpers.js";
5
5
  import { authKeys } from "../queryKeys.js";
6
6
  export function useApiKeys(load = true) {
@@ -48,4 +48,41 @@ export function useApiKeys(load = true) {
48
48
  refetch: apiKeysQuery.refetch
49
49
  };
50
50
  }
51
+ // Superadmin-only surface (AA-13, AA-17): list + revoke another user's keys.
52
+ // Metadata only — never the raw or hashed key — and there is no create/edit
53
+ // path here, unlike the owner-scoped `useApiKeys` above.
54
+ export function useAdminApiKeys(userId, load = true) {
55
+ const queryClient = useQueryClient();
56
+ const adminKeysQuery = useQuery({
57
+ queryKey: authKeys.adminApiKeys(userId),
58
+ queryFn: () => adminListUserApiKeys(userId),
59
+ enabled: load && Boolean(userId),
60
+ staleTime: 30_000
61
+ });
62
+ const revokeMutation = useMutation({
63
+ mutationFn: adminRevokeApiKey,
64
+ onSuccess: async () => {
65
+ await queryClient.invalidateQueries({ queryKey: authKeys.adminApiKeys(userId) });
66
+ }
67
+ });
68
+ const { refetch } = adminKeysQuery;
69
+ const { mutateAsync: revokeApiKeyAsync } = revokeMutation;
70
+ const reload = useCallback(() => refetchOrThrow(refetch, null), [refetch]);
71
+ const revoke = useCallback((keyId) => revokeApiKeyAsync(keyId), [revokeApiKeyAsync]);
72
+ const apiKeys = adminKeysQuery.data?.data ?? [];
73
+ const count = adminKeysQuery.data?.count ?? 0;
74
+ const loading = adminKeysQuery.isLoading || adminKeysQuery.isFetching;
75
+ return {
76
+ apiKeys,
77
+ count,
78
+ loading,
79
+ error: adminKeysQuery.error ?? null,
80
+ reload,
81
+ revoke,
82
+ revokeMutation,
83
+ isLoading: adminKeysQuery.isLoading,
84
+ isFetching: adminKeysQuery.isFetching,
85
+ refetch: adminKeysQuery.refetch
86
+ };
87
+ }
51
88
  //# sourceMappingURL=useApiKeys.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useApiKeys.js","sourceRoot":"","sources":["../../../../src/runtime/hooks/useApiKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,MAAM,UAAU,UAAU,CAAC,IAAI,GAAG,IAAI;IACpC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAuB,IAAI,CAAC,CAAC;IACzE,MAAM,YAAY,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