@c9up/warden 0.1.13 → 0.1.14

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 (96) hide show
  1. package/dist/AuthManager.d.ts +45 -9
  2. package/dist/AuthManager.d.ts.map +1 -1
  3. package/dist/AuthManager.js +75 -23
  4. package/dist/AuthManager.js.map +1 -1
  5. package/dist/Authenticator.d.ts +128 -0
  6. package/dist/Authenticator.d.ts.map +1 -0
  7. package/dist/Authenticator.js +296 -0
  8. package/dist/Authenticator.js.map +1 -0
  9. package/dist/WardenProvider.d.ts.map +1 -1
  10. package/dist/WardenProvider.js +51 -23
  11. package/dist/WardenProvider.js.map +1 -1
  12. package/dist/bouncer/AbilitiesBuilder.d.ts +20 -0
  13. package/dist/bouncer/AbilitiesBuilder.d.ts.map +1 -0
  14. package/dist/bouncer/AbilitiesBuilder.js +32 -0
  15. package/dist/bouncer/AbilitiesBuilder.js.map +1 -0
  16. package/dist/bouncer/AuthorizationResponse.d.ts +18 -8
  17. package/dist/bouncer/AuthorizationResponse.d.ts.map +1 -1
  18. package/dist/bouncer/AuthorizationResponse.js +20 -8
  19. package/dist/bouncer/AuthorizationResponse.js.map +1 -1
  20. package/dist/bouncer/BasePolicy.d.ts +4 -3
  21. package/dist/bouncer/BasePolicy.d.ts.map +1 -1
  22. package/dist/bouncer/BasePolicy.js.map +1 -1
  23. package/dist/bouncer/Bouncer.d.ts +9 -2
  24. package/dist/bouncer/Bouncer.d.ts.map +1 -1
  25. package/dist/bouncer/Bouncer.js +59 -10
  26. package/dist/bouncer/Bouncer.js.map +1 -1
  27. package/dist/bouncer/PolicyAuthorizer.d.ts +2 -1
  28. package/dist/bouncer/PolicyAuthorizer.d.ts.map +1 -1
  29. package/dist/bouncer/PolicyAuthorizer.js +11 -3
  30. package/dist/bouncer/PolicyAuthorizer.js.map +1 -1
  31. package/dist/bouncer/evaluate.d.ts +1 -1
  32. package/dist/bouncer/evaluate.d.ts.map +1 -1
  33. package/dist/bouncer/evaluate.js +3 -2
  34. package/dist/bouncer/evaluate.js.map +1 -1
  35. package/dist/bouncer/types.d.ts +22 -1
  36. package/dist/bouncer/types.d.ts.map +1 -1
  37. package/dist/config.d.ts +34 -3
  38. package/dist/config.d.ts.map +1 -1
  39. package/dist/config.js +15 -0
  40. package/dist/config.js.map +1 -1
  41. package/dist/configure.d.ts.map +1 -1
  42. package/dist/configure.js +15 -13
  43. package/dist/configure.js.map +1 -1
  44. package/dist/errors.d.ts +27 -0
  45. package/dist/errors.d.ts.map +1 -1
  46. package/dist/errors.js +37 -1
  47. package/dist/errors.js.map +1 -1
  48. package/dist/index.d.ts +7 -3
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +4 -2
  51. package/dist/index.js.map +1 -1
  52. package/dist/mfa/OtpProvider.d.ts.map +1 -1
  53. package/dist/mfa/OtpProvider.js +21 -3
  54. package/dist/mfa/OtpProvider.js.map +1 -1
  55. package/dist/mfa/WebauthnProvider.d.ts +24 -2
  56. package/dist/mfa/WebauthnProvider.d.ts.map +1 -1
  57. package/dist/mfa/WebauthnProvider.js +28 -8
  58. package/dist/mfa/WebauthnProvider.js.map +1 -1
  59. package/dist/middleware.d.ts +29 -6
  60. package/dist/middleware.d.ts.map +1 -1
  61. package/dist/middleware.js +85 -166
  62. package/dist/middleware.js.map +1 -1
  63. package/dist/standalone.d.ts.map +1 -1
  64. package/dist/standalone.js +21 -13
  65. package/dist/standalone.js.map +1 -1
  66. package/dist/strategies/ApiKeyStrategy.d.ts.map +1 -1
  67. package/dist/strategies/ApiKeyStrategy.js +4 -1
  68. package/dist/strategies/ApiKeyStrategy.js.map +1 -1
  69. package/dist/strategies/SessionStrategy.js +2 -2
  70. package/dist/strategies/SessionStrategy.js.map +1 -1
  71. package/index.darwin-arm64.node +0 -0
  72. package/index.darwin-x64.node +0 -0
  73. package/index.linux-arm64-gnu.node +0 -0
  74. package/index.linux-x64-gnu.node +0 -0
  75. package/index.win32-x64-msvc.node +0 -0
  76. package/package.json +2 -1
  77. package/src/AuthManager.ts +125 -28
  78. package/src/Authenticator.ts +385 -0
  79. package/src/WardenProvider.ts +51 -25
  80. package/src/bouncer/AbilitiesBuilder.ts +41 -0
  81. package/src/bouncer/AuthorizationResponse.ts +24 -16
  82. package/src/bouncer/BasePolicy.ts +4 -2
  83. package/src/bouncer/Bouncer.ts +77 -14
  84. package/src/bouncer/PolicyAuthorizer.ts +14 -4
  85. package/src/bouncer/evaluate.ts +4 -2
  86. package/src/bouncer/types.ts +24 -1
  87. package/src/config.ts +47 -3
  88. package/src/configure.ts +15 -13
  89. package/src/errors.ts +43 -1
  90. package/src/index.ts +22 -2
  91. package/src/mfa/OtpProvider.ts +31 -3
  92. package/src/mfa/WebauthnProvider.ts +58 -12
  93. package/src/middleware.ts +112 -207
  94. package/src/standalone.ts +22 -14
  95. package/src/strategies/ApiKeyStrategy.ts +4 -1
  96. package/src/strategies/SessionStrategy.ts +2 -2
@@ -0,0 +1,296 @@
1
+ /**
2
+ * Authenticator — a PER-REQUEST authentication contract (AdonisJS
3
+ * `@adonisjs/auth` `Authenticator` parity), attached as `ctx.auth`.
4
+ *
5
+ * Why it exists: before this, `ctx.auth` was a plain data object with no
6
+ * methods, so an INLINE route handler (`router.post('/login', handler)`) had no
7
+ * way to authenticate on demand — only the `@Guard` decorator path worked, and
8
+ * that reads `ctx.route.controller/action`, which inline/functional routes don't
9
+ * expose. This contract makes `await ctx.auth.authenticate()` /
10
+ * `ctx.auth.use('session').login(user)` work anywhere, exactly like Adonis.
11
+ *
12
+ * Warden stays agnostic: the Authenticator is built from the {@link AuthManager}
13
+ * (resolved via `ctx.containerResolver`) + the request `ctx`; it never imports
14
+ * `@c9up/ream`.
15
+ */
16
+ import { sanitizePayload, } from "./AuthManager.js";
17
+ import { E_UNAUTHORIZED_ACCESS, WardenError } from "./errors.js";
18
+ /**
19
+ * Guard names Warden accepts for the API-key / access-tokens driver. AdonisJS
20
+ * names the driver `access_tokens`; the legacy `api-key` spelling stays valid so
21
+ * existing `@Guard('api-key')` routes and configs keep working.
22
+ */
23
+ export const API_KEY_GUARD_NAMES = [
24
+ "access_tokens",
25
+ "api-key",
26
+ ];
27
+ function hasVerifyWithContext(strategy) {
28
+ return (typeof strategy.verifyWithContext === "function");
29
+ }
30
+ /**
31
+ * Resolve the header the API-key guard reads its key from. Prefers the
32
+ * registered guard's `headerName` (under either accepted guard name), else the
33
+ * `x-api-key` default. Never throws.
34
+ */
35
+ function resolveApiKeyHeader(auth) {
36
+ for (const name of API_KEY_GUARD_NAMES) {
37
+ try {
38
+ const s = auth.getStrategy(name);
39
+ const header = "headerName" in s ? s.headerName : undefined;
40
+ if (typeof header === "string" && header.length > 0)
41
+ return header;
42
+ }
43
+ catch {
44
+ // Guard not registered under this name — try the next.
45
+ }
46
+ }
47
+ return "x-api-key";
48
+ }
49
+ /**
50
+ * Extract the request's credentials once — a Bearer token, an API key (read from
51
+ * the configured header, matched case-insensitively), and the session store.
52
+ * Shared by `wardenMiddleware`, `silentAuth`, and the Authenticator so all three
53
+ * read credentials identically.
54
+ */
55
+ export function extractCredentials(ctx, auth) {
56
+ const headers = ctx.request.headers();
57
+ const authHeader = headers.authorization ?? "";
58
+ const bearerToken = authHeader.startsWith("Bearer ")
59
+ ? authHeader.slice(7)
60
+ : "";
61
+ // HTTP header names are case-insensitive; runtimes lowercase incoming keys,
62
+ // so normalise the configured header name before the lookup.
63
+ const apiKey = headers[resolveApiKeyHeader(auth).toLowerCase()] ?? "";
64
+ return { bearerToken, apiKey, session: ctx.session };
65
+ }
66
+ /**
67
+ * Try each declared guard in order — session guards via `verifyWithContext()`,
68
+ * others via `verify(token)` with native-first credential fallback.
69
+ * Distinguishes crashes (strategy threw / `strategyCrash`) from credential
70
+ * rejections so the caller can return 500 vs 401.
71
+ */
72
+ export async function tryAuthenticate(auth, strategies, creds) {
73
+ const { bearerToken, apiKey, session } = creds;
74
+ let result = null;
75
+ let viaGuard;
76
+ let attemptCount = 0;
77
+ let crashCount = 0;
78
+ for (const strategyName of strategies) {
79
+ try {
80
+ let r;
81
+ if (strategyName === "session") {
82
+ const strategy = auth.getStrategy(strategyName);
83
+ const verifyWithContext = strategy && hasVerifyWithContext(strategy)
84
+ ? strategy.verifyWithContext
85
+ : undefined;
86
+ if (verifyWithContext) {
87
+ attemptCount++;
88
+ r = await verifyWithContext.call(strategy, "", { session });
89
+ // The session path bypasses AuthManager.verify(), so apply the
90
+ // same prototype-pollution guard JWT / api-key users get there.
91
+ if (r.user)
92
+ sanitizePayload(r.user);
93
+ }
94
+ else {
95
+ continue;
96
+ }
97
+ }
98
+ else {
99
+ // Native-first credential, other transport as fallback so a
100
+ // single-credential client still authenticates (and an invalid
101
+ // Bearer no longer masks a valid API key for the api-key guard).
102
+ const credential = API_KEY_GUARD_NAMES.includes(strategyName)
103
+ ? apiKey || bearerToken
104
+ : bearerToken || apiKey;
105
+ if (!credential)
106
+ continue;
107
+ attemptCount++;
108
+ r = await auth.verify(credential, strategyName);
109
+ }
110
+ if (r.authenticated) {
111
+ result = r;
112
+ viaGuard = strategyName;
113
+ break;
114
+ }
115
+ if (r.strategyCrash === true) {
116
+ crashCount++;
117
+ console.error(`[warden] strategy '${strategyName}' threw during verify(): ${r.error ?? "unknown error"}`);
118
+ }
119
+ }
120
+ catch (err) {
121
+ // AuthManager rethrows structured WardenError sentinels — treat these
122
+ // as crashes too (config errors, SessionStrategy.USE_LOGIN, etc.).
123
+ crashCount++;
124
+ console.error(`[warden] strategy '${strategyName}' threw during verify():`, err);
125
+ }
126
+ }
127
+ return { result, viaGuard, attemptCount, crashCount };
128
+ }
129
+ /**
130
+ * A named-guard accessor (AdonisJS `auth.use('web')`). Exposes the stateful
131
+ * `login()`/`logout()` for session guards plus per-guard `authenticate()`.
132
+ */
133
+ export class GuardAccessor {
134
+ #ctx;
135
+ #auth;
136
+ #name;
137
+ #parent;
138
+ constructor(ctx, auth, name, parent) {
139
+ this.#ctx = ctx;
140
+ this.#auth = auth;
141
+ this.#name = name;
142
+ this.#parent = parent;
143
+ }
144
+ /** The user, only if the request authenticated via THIS guard. */
145
+ get user() {
146
+ return this.#parent.authenticatedViaGuard === this.#name
147
+ ? this.#parent.user
148
+ : undefined;
149
+ }
150
+ get isAuthenticated() {
151
+ return this.user !== undefined;
152
+ }
153
+ /** Authenticate the request using only this guard (throws on failure). */
154
+ authenticate() {
155
+ return this.#parent.authenticateUsing([this.#name]);
156
+ }
157
+ /** Log a user in through this guard (session guards). */
158
+ login(user) {
159
+ return this.#auth.login(user, this.#requireSession(), this.#name);
160
+ }
161
+ /** Log the current user out of this guard (session guards). */
162
+ logout() {
163
+ return this.#auth.logout(this.#requireSession(), this.#name);
164
+ }
165
+ #requireSession() {
166
+ if (!this.#ctx.session) {
167
+ throw new WardenError("NO_SESSION", `Guard '${this.#name}'.login()/logout() requires a session, but ctx.session is unset. Register the session middleware upstream.`);
168
+ }
169
+ return this.#ctx.session;
170
+ }
171
+ }
172
+ /**
173
+ * Per-request Authenticator attached as `ctx.auth`. Mirrors AdonisJS's
174
+ * `Authenticator` surface: `authenticate` / `check` / `authenticateUsing` /
175
+ * `getUserOrFail` / `use`, plus the `user` / `isAuthenticated` /
176
+ * `authenticationAttempted` / `authenticatedViaGuard` getters.
177
+ */
178
+ export class Authenticator {
179
+ #ctx;
180
+ #auth;
181
+ #user;
182
+ #viaGuard;
183
+ #attempted = false;
184
+ #guardCache = new Map();
185
+ constructor(ctx, auth) {
186
+ this.#ctx = ctx;
187
+ this.#auth = auth;
188
+ }
189
+ /** The authenticated user, or `undefined` for a guest. */
190
+ get user() {
191
+ return this.#user;
192
+ }
193
+ /** Whether the request has an authenticated user (AdonisJS name). */
194
+ get isAuthenticated() {
195
+ return this.#user !== undefined;
196
+ }
197
+ /** Whether `authenticate`/`check`/`authenticateUsing` ran this request. */
198
+ get authenticationAttempted() {
199
+ return this.#attempted;
200
+ }
201
+ /** Name of the guard that authenticated the request, if any. */
202
+ get authenticatedViaGuard() {
203
+ return this.#viaGuard;
204
+ }
205
+ /**
206
+ * Roles of the authenticated user (Ream reads `ctx.auth.roles ??
207
+ * ctx.auth.user.roles`). Warden nests them under `user`; this getter mirrors
208
+ * them at the top level for the host's guard readers.
209
+ */
210
+ get roles() {
211
+ return this.#user?.roles;
212
+ }
213
+ /** Permissions of the authenticated user (see {@link Authenticator.roles}). */
214
+ get permissions() {
215
+ return this.#user?.permissions;
216
+ }
217
+ /** Authenticate via the default guard. Throws `E_UNAUTHORIZED_ACCESS` on failure. */
218
+ authenticate() {
219
+ return this.authenticateUsing([this.#auth.defaultStrategyName]);
220
+ }
221
+ /**
222
+ * Like {@link Authenticator.authenticate} but returns a boolean instead of
223
+ * throwing on a credential rejection. A strategy CRASH / config error still
224
+ * propagates (a server incident must not be silently swallowed as "guest").
225
+ */
226
+ async check() {
227
+ try {
228
+ await this.authenticate();
229
+ return this.isAuthenticated;
230
+ }
231
+ catch (err) {
232
+ if (err instanceof E_UNAUTHORIZED_ACCESS)
233
+ return false;
234
+ throw err;
235
+ }
236
+ }
237
+ /**
238
+ * Authenticate by trying the given guards in order (default: the default
239
+ * guard). Sets the user on the first success; throws `E_UNAUTHORIZED_ACCESS`
240
+ * (401, carrying `redirectTo` for session guards) when all reject, or a
241
+ * `WARDEN_AUTH_STRATEGY_ERROR` (500) when every attempted guard crashed.
242
+ */
243
+ async authenticateUsing(guards, options) {
244
+ this.#attempted = true;
245
+ const names = guards && guards.length > 0 ? guards : [this.#auth.defaultStrategyName];
246
+ const creds = extractCredentials(this.#ctx, this.#auth);
247
+ const hasSessionStrategy = names.includes("session");
248
+ const { result, viaGuard, attemptCount, crashCount } = await tryAuthenticate(this.#auth, names, {
249
+ ...creds,
250
+ hasSessionStrategy,
251
+ });
252
+ if (result?.authenticated && result.user) {
253
+ this.#user = result.user;
254
+ this.#viaGuard = viaGuard;
255
+ return;
256
+ }
257
+ // Every attempted guard crashed → a server-side incident, not a
258
+ // credential rejection. Surface distinctly (mapped to 500 by the caller).
259
+ if (attemptCount > 0 && crashCount === attemptCount) {
260
+ throw new WardenError("AUTH_STRATEGY_ERROR", "Authentication unavailable — one or more strategies failed. Check server logs.", { status: 500 });
261
+ }
262
+ throw new E_UNAUTHORIZED_ACCESS(result?.error ?? "Unauthorized access", {
263
+ guardDriverName: names[0] ?? this.#auth.defaultStrategyName,
264
+ redirectTo: hasSessionStrategy ? options?.loginRoute : undefined,
265
+ });
266
+ }
267
+ /** Return the authenticated user or throw `E_UNAUTHORIZED_ACCESS`. */
268
+ getUserOrFail() {
269
+ if (!this.#user) {
270
+ throw new E_UNAUTHORIZED_ACCESS('Cannot access authenticated user. Call "ctx.auth.authenticate()" first.', { guardDriverName: this.#viaGuard ?? this.#auth.defaultStrategyName });
271
+ }
272
+ return this.#user;
273
+ }
274
+ /** Access a named guard (AdonisJS `auth.use('web')`). Instances are cached per request. */
275
+ use(name) {
276
+ let accessor = this.#guardCache.get(name);
277
+ if (!accessor) {
278
+ accessor = new GuardAccessor(this.#ctx, this.#auth, name, this);
279
+ this.#guardCache.set(name, accessor);
280
+ }
281
+ return accessor;
282
+ }
283
+ /**
284
+ * @internal Seed the Authenticator from a result the enforcing middleware
285
+ * already computed, so `ctx.auth` reflects the authenticated user without a
286
+ * second verify pass.
287
+ */
288
+ adopt(result, viaGuard) {
289
+ this.#attempted = true;
290
+ if (result?.authenticated && result.user) {
291
+ this.#user = result.user;
292
+ this.#viaGuard = viaGuard;
293
+ }
294
+ }
295
+ }
296
+ //# sourceMappingURL=Authenticator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Authenticator.js","sourceRoot":"","sources":["../src/Authenticator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAIN,eAAe,GAEf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAIjE;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAsB;IACrD,eAAe;IACf,SAAS;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,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;YAChE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAyB,EAAE,QAA4B;QAC5D,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,MAAM,EAAE,aAAa,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;YAC1C,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC;YACzB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC3B,CAAC;IACF,CAAC;CACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"WardenProvider.d.ts","sourceRoot":"","sources":["../src/WardenProvider.ts"],"names":[],"mappings":"AAYA,UAAU,eAAe;IACxB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,GAAG,IAAI,CAAC;IACxD,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACjC;AAED,UAAU,iBAAiB;IAC1B,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;CAC7C;AAED,MAAM,WAAW,gBAAgB;IAChC,SAAS,EAAE,eAAe,CAAC;IAC3B,MAAM,EAAE,iBAAiB,CAAC;CAC1B;AAED,MAAM,CAAC,OAAO,OAAO,cAAc;IACtB,SAAS,CAAC,GAAG,EAAE,gBAAgB;gBAArB,GAAG,EAAE,gBAAgB;IAE3C,QAAQ;IAiGF,IAAI;CAGV"}
1
+ {"version":3,"file":"WardenProvider.d.ts","sourceRoot":"","sources":["../src/WardenProvider.ts"],"names":[],"mappings":"AAYA,UAAU,eAAe;IACxB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,GAAG,IAAI,CAAC;IACxD,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACjC;AAED,UAAU,iBAAiB;IAC1B,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;CAC7C;AAED,MAAM,WAAW,gBAAgB;IAChC,SAAS,EAAE,eAAe,CAAC;IAC3B,MAAM,EAAE,iBAAiB,CAAC;CAC1B;AAED,MAAM,CAAC,OAAO,OAAO,cAAc;IACtB,SAAS,CAAC,GAAG,EAAE,gBAAgB;gBAArB,GAAG,EAAE,gBAAgB;IAE3C,QAAQ;IA2HF,IAAI;CAGV"}
@@ -23,29 +23,56 @@ export default class WardenProvider {
23
23
  // AuthManager with `strategies: {}` and `defaultStrategy: 'jwt'`,
24
24
  // passing the (then-permissive) constructor and erroring deep in the
25
25
  // middleware loop.
26
- if (!config?.jwt && !config?.session && !config?.apiKey) {
27
- throw new WardenError("WARDEN_NO_AUTH_CONFIG", `@c9up/warden: no authentication strategies configured. Set at least one of config.warden.auth.jwt / .session / .apiKey in your reamrc.ts before registering WardenProvider.`);
26
+ const hasGuards = config?.guards && Object.keys(config.guards).length > 0;
27
+ if (!hasGuards && !config?.jwt && !config?.session && !config?.apiKey) {
28
+ throw new WardenError("WARDEN_NO_AUTH_CONFIG", `@c9up/warden: no authentication guards configured. Set config.warden.auth.guards (AdonisJS form) or at least one of .jwt / .session / .apiKey in your reamrc.ts before registering WardenProvider.`);
28
29
  }
29
- // Build the strategy table from whatever the app configured. Each strategy
30
- // is also exposed by its class token (mirrors the jwt convention) so apps
31
- // can resolve a specific one. The `revoke()` blacklist flows through
32
- // `config.jwt.blacklist` into JwtStrategy.
30
+ // Build the guard table. Two accepted forms:
31
+ // - AdonisJS: `config.guards` (name AuthStrategy, via *Guard() factories).
32
+ // - Legacy driver-keyed: `config.jwt` / `.session` / `.apiKey`.
33
+ // Each strategy is also exposed by its class token (so apps can resolve a
34
+ // specific one). The `revoke()` blacklist flows through `config.jwt.blacklist`.
33
35
  const strategies = {};
34
- if (config.jwt) {
35
- const jwt = new JwtStrategy(config.jwt);
36
- this.app.container.singleton(JwtStrategy, () => jwt);
37
- strategies.jwt = jwt;
36
+ if (hasGuards && config.guards) {
37
+ for (const [name, strategy] of Object.entries(config.guards)) {
38
+ strategies[name] = strategy;
39
+ // Expose recognised driver instances by their class token too.
40
+ if (strategy instanceof JwtStrategy) {
41
+ this.app.container.singleton(JwtStrategy, () => strategy);
42
+ }
43
+ else if (strategy instanceof SessionStrategy) {
44
+ this.app.container.singleton(SessionStrategy, () => strategy);
45
+ }
46
+ else if (strategy instanceof ApiKeyStrategy) {
47
+ this.app.container.singleton(ApiKeyStrategy, () => strategy);
48
+ }
49
+ }
38
50
  }
39
- if (config.session) {
40
- const session = new SessionStrategy(config.session);
41
- this.app.container.singleton(SessionStrategy, () => session);
42
- strategies.session = session;
43
- }
44
- if (config.apiKey) {
45
- const apiKey = new ApiKeyStrategy(config.apiKey);
46
- this.app.container.singleton(ApiKeyStrategy, () => apiKey);
47
- strategies["api-key"] = apiKey;
51
+ else {
52
+ if (config.jwt) {
53
+ const jwt = new JwtStrategy(config.jwt);
54
+ this.app.container.singleton(JwtStrategy, () => jwt);
55
+ strategies.jwt = jwt;
56
+ }
57
+ if (config.session) {
58
+ const session = new SessionStrategy(config.session);
59
+ this.app.container.singleton(SessionStrategy, () => session);
60
+ strategies.session = session;
61
+ }
62
+ if (config.apiKey) {
63
+ const apiKey = new ApiKeyStrategy(config.apiKey);
64
+ this.app.container.singleton(ApiKeyStrategy, () => apiKey);
65
+ // AdonisJS names this guard driver "access_tokens"; keep "api-key"
66
+ // as an accepted alias so existing `@Guard('api-key')` routes work.
67
+ strategies.access_tokens = apiKey;
68
+ strategies["api-key"] = apiKey;
69
+ }
48
70
  }
71
+ // Login route (session-guard HTML redirect target) — resolved by the
72
+ // enforcing middleware via the "warden:loginRoute" token. Registered even
73
+ // when undefined so the lookup is a clean resolve, not a throw.
74
+ const loginRoute = config.loginRoute;
75
+ this.app.container.singleton("warden:loginRoute", () => loginRoute);
49
76
  // Rights layer (Epic 56): one resolver singleton backs BOTH the coarse
50
77
  // RBAC helpers (injected into AuthManager below) and — once 56.6 lands —
51
78
  // the Bouncer construction, so a coarse question and a policy question
@@ -69,12 +96,13 @@ export default class WardenProvider {
69
96
  resolveScope: config.resolveScope,
70
97
  };
71
98
  this.app.container.singleton("bouncer:registry", () => bouncerRegistry);
72
- // Default to the configured strategy, else the first one registered.
73
- const defaultStrategy = config.defaultStrategy ?? Object.keys(strategies)[0];
99
+ // Default to the configured guard (AdonisJS `default`, then legacy
100
+ // `defaultStrategy`), else the first one registered.
101
+ const defaultGuard = config.default ?? config.defaultStrategy ?? Object.keys(strategies)[0];
74
102
  this.app.container.singleton(AuthManager, () => {
75
103
  return new AuthManager({
76
- defaultStrategy,
77
- strategies,
104
+ default: defaultGuard,
105
+ guards: strategies,
78
106
  rights: rightsResolver,
79
107
  });
80
108
  });
@@ -1 +1 @@
1
- {"version":3,"file":"WardenProvider.js","sourceRoot":"","sources":["../src/WardenProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqB,MAAM,kBAAkB,CAAC;AAElE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAgBlE,MAAM,CAAC,OAAO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onis `AbilitiesBuilder`). Each `.define(...)` delegates to
4
+ * `Bouncer.ability` and stores the result on `.abilities`, returning `this` so
5
+ * calls chain: `new AbilitiesBuilder().define(a).define(b).abilities`.
6
+ */
7
+ import type { UserPayload } from "../AuthManager.js";
8
+ import type { Ability, AbilityOptions, AuthorizerResponse } from "./types.js";
9
+ export declare class AbilitiesBuilder {
10
+ /** The abilities accumulated so far, keyed by name. */
11
+ readonly abilities: Record<string, Ability<never[]>>;
12
+ constructor(abilities?: Record<string, Ability<never[]>>);
13
+ /**
14
+ * Define a named ability (Adonis `.define(name, authorizer, options?)`). The
15
+ * callback receives a non-null user (a guest is denied by the evaluator before
16
+ * it runs); pass `{ allowGuest: true }` to let the callback run for a guest.
17
+ */
18
+ define<Args extends unknown[]>(name: string, authorizer: (user: UserPayload, ...args: Args) => AuthorizerResponse, options?: AbilityOptions): this;
19
+ }
20
+ //# sourceMappingURL=AbilitiesBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbilitiesBuilder.d.ts","sourceRoot":"","sources":["../../src/bouncer/AbilitiesBuilder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAE9E,qBAAa,gBAAgB;IAC5B,uDAAuD;IACvD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBAEzC,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAM;IAI5D;;;;OAIG;IACH,MAAM,CAAC,IAAI,SAAS,OAAO,EAAE,EAC5B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,kBAAkB,EACpE,OAAO,CAAC,EAAE,cAAc,GACtB,IAAI;CAYP"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * AbilitiesBuilder — a chainable builder that fluently assembles an object of
3
+ * named abilities (Adonis `AbilitiesBuilder`). Each `.define(...)` delegates to
4
+ * `Bouncer.ability` and stores the result on `.abilities`, returning `this` so
5
+ * calls chain: `new AbilitiesBuilder().define(a).define(b).abilities`.
6
+ */
7
+ import { Bouncer } from "./Bouncer.js";
8
+ export class AbilitiesBuilder {
9
+ /** The abilities accumulated so far, keyed by name. */
10
+ abilities;
11
+ constructor(abilities = {}) {
12
+ this.abilities = abilities;
13
+ }
14
+ /**
15
+ * Define a named ability (Adonis `.define(name, authorizer, options?)`). The
16
+ * callback receives a non-null user (a guest is denied by the evaluator before
17
+ * it runs); pass `{ allowGuest: true }` to let the callback run for a guest.
18
+ */
19
+ define(name, authorizer, options) {
20
+ // Delegate the callback wrapping to `Bouncer.ability` (guest-denied form),
21
+ // then apply the `allowGuest` option. Store without the `__args` phantom —
22
+ // its concrete-args brand cannot widen to the `never[]` storage slot, while
23
+ // `execute` is already non-generic.
24
+ const built = Bouncer.ability(authorizer);
25
+ this.abilities[name] = {
26
+ allowGuest: options?.allowGuest ?? built.allowGuest,
27
+ execute: built.execute,
28
+ };
29
+ return this;
30
+ }
31
+ }
32
+ //# sourceMappingURL=AbilitiesBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbilitiesBuilder.js","sourceRoot":"","sources":["../../src/bouncer/AbilitiesBuilder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,MAAM,OAAO,gBAAgB;IAC5B,uDAAuD;IAC9C,SAAS,CAAmC;IAErD,YAAY,YAA8C,EAAE;QAC3D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,MAAM,CACL,IAAY,EACZ,UAAoE,EACpE,OAAwB;QAExB,2EAA2E;QAC3E,2EAA2E;QAC3E,4EAA4E;QAC5E,oCAAoC;QACpC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC1C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG;YACtB,UAAU,EAAE,OAAO,EAAE,UAAU,IAAI,KAAK,CAAC,UAAU;YACnD,OAAO,EAAE,KAAK,CAAC,OAAO;SACtB,CAAC;QACF,OAAO,IAAI,CAAC;IACb,CAAC;CACD"}
@@ -3,23 +3,33 @@
3
3
  *
4
4
  * Layer 2 (EVALUATION) of Warden's unified authorization (Epic 56). Faithful
5
5
  * to AdonisJS Bouncer's `AuthorizationResponse`: instances are produced only by
6
- * the `allow()` / `deny()` static constructors (the constructor is private), a
7
- * denial defaults to HTTP 403, and a `translation` field is carried for shape
8
- * parity with Adonis's i18n hook (always `undefined` in 56.2 D6).
6
+ * the `allow()` / `deny()` static constructors (the constructor is private). A
7
+ * denial carries no `status` unless one is passed the HTTP 403 default is
8
+ * applied only at the throw/HTTP boundary (Adonis parity) and a `translation`
9
+ * field carries the i18n binding set via {@link t}.
9
10
  */
10
11
  export declare class AuthorizationResponse {
11
12
  readonly authorized: boolean;
12
- readonly message?: string;
13
- readonly status?: number;
14
- /** Parity placeholder for an i18n binding (always undefined in 56.2 — D6). */
15
- readonly translation?: {
13
+ message?: string;
14
+ status?: number;
15
+ /** i18n binding set via {@link t} (Adonis `AuthorizationResponse.t`). */
16
+ translation?: {
16
17
  identifier: string;
17
18
  data?: Record<string, unknown>;
18
19
  };
19
20
  private constructor();
20
21
  /** Authorized response (no status). */
21
22
  static allow(): AuthorizationResponse;
22
- /** Denied response; `status` defaults to 403 (D6). */
23
+ /**
24
+ * Denied response. `status` is left `undefined` unless passed — the 403
25
+ * default is applied only when the denial is thrown / mapped to HTTP (Adonis
26
+ * parity).
27
+ */
23
28
  static deny(message?: string, status?: number): AuthorizationResponse;
29
+ /**
30
+ * Set the i18n translation binding and return `this` for chaining (Adonis
31
+ * `AuthorizationResponse.t`), e.g. `AuthorizationResponse.deny().t('errors.forbidden')`.
32
+ */
33
+ t(identifier: string, data?: Record<string, unknown>): this;
24
34
  }
25
35
  //# sourceMappingURL=AuthorizationResponse.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AuthorizationResponse.d.ts","sourceRoot":"","sources":["../../src/bouncer/AuthorizationResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,qBAAqB;IACjC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,8EAA8E;IAC9E,QAAQ,CAAC,WAAW,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IAE9E,OAAO;IAYP,uCAAuC;IACvC,MAAM,CAAC,KAAK,IAAI,qBAAqB;IAIrC,sDAAsD;IACtD,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,SAAM,GAAG,qBAAqB;CAGlE"}
1
+ {"version":3,"file":"AuthorizationResponse.d.ts","sourceRoot":"","sources":["../../src/bouncer/AuthorizationResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,qBAAa,qBAAqB;IACjC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,WAAW,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IAErE,OAAO;IAMP,uCAAuC;IACvC,MAAM,CAAC,KAAK,IAAI,qBAAqB;IAIrC;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,qBAAqB;IAIrE;;;OAGG;IACH,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;CAI3D"}
@@ -3,29 +3,41 @@
3
3
  *
4
4
  * Layer 2 (EVALUATION) of Warden's unified authorization (Epic 56). Faithful
5
5
  * to AdonisJS Bouncer's `AuthorizationResponse`: instances are produced only by
6
- * the `allow()` / `deny()` static constructors (the constructor is private), a
7
- * denial defaults to HTTP 403, and a `translation` field is carried for shape
8
- * parity with Adonis's i18n hook (always `undefined` in 56.2 D6).
6
+ * the `allow()` / `deny()` static constructors (the constructor is private). A
7
+ * denial carries no `status` unless one is passed the HTTP 403 default is
8
+ * applied only at the throw/HTTP boundary (Adonis parity) and a `translation`
9
+ * field carries the i18n binding set via {@link t}.
9
10
  */
10
11
  export class AuthorizationResponse {
11
12
  authorized;
12
13
  message;
13
14
  status;
14
- /** Parity placeholder for an i18n binding (always undefined in 56.2 — D6). */
15
+ /** i18n binding set via {@link t} (Adonis `AuthorizationResponse.t`). */
15
16
  translation;
16
- constructor(authorized, message, status, translation) {
17
+ constructor(authorized, message, status) {
17
18
  this.authorized = authorized;
18
19
  this.message = message;
19
20
  this.status = status;
20
- this.translation = translation;
21
21
  }
22
22
  /** Authorized response (no status). */
23
23
  static allow() {
24
24
  return new AuthorizationResponse(true);
25
25
  }
26
- /** Denied response; `status` defaults to 403 (D6). */
27
- static deny(message, status = 403) {
26
+ /**
27
+ * Denied response. `status` is left `undefined` unless passed — the 403
28
+ * default is applied only when the denial is thrown / mapped to HTTP (Adonis
29
+ * parity).
30
+ */
31
+ static deny(message, status) {
28
32
  return new AuthorizationResponse(false, message, status);
29
33
  }
34
+ /**
35
+ * Set the i18n translation binding and return `this` for chaining (Adonis
36
+ * `AuthorizationResponse.t`), e.g. `AuthorizationResponse.deny().t('errors.forbidden')`.
37
+ */
38
+ t(identifier, data) {
39
+ this.translation = { identifier, data };
40
+ return this;
41
+ }
30
42
  }
31
43
  //# sourceMappingURL=AuthorizationResponse.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AuthorizationResponse.js","sourceRoot":"","sources":["../../src/bouncer/AuthorizationResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,qBAAqB;IACxB,UAAU,CAAU;IACpB,OAAO,CAAU;IACjB,MAAM,CAAU;IACzB,8EAA8E;IACrE,WAAW,CAA0D;IAE9E,YACC,UAAmB,EACnB,OAAgB,EAChB,MAAe,EACf,WAAoE;QAEpE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IAChC,CAAC;IAED,uCAAuC;IACvC,MAAM,CAAC,KAAK;QACX,OAAO,IAAI,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED,sDAAsD;IACtD,MAAM,CAAC,IAAI,CAAC,OAAgB,EAAE,MAAM,GAAG,GAAG;QACzC,OAAO,IAAI,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;CACD"}
1
+ {"version":3,"file":"AuthorizationResponse.js","sourceRoot":"","sources":["../../src/bouncer/AuthorizationResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,OAAO,qBAAqB;IACxB,UAAU,CAAU;IAC7B,OAAO,CAAU;IACjB,MAAM,CAAU;IAChB,yEAAyE;IACzE,WAAW,CAA0D;IAErE,YAAoB,UAAmB,EAAE,OAAgB,EAAE,MAAe;QACzE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,uCAAuC;IACvC,MAAM,CAAC,KAAK;QACX,OAAO,IAAI,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,OAAgB,EAAE,MAAe;QAC5C,OAAO,IAAI,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACH,CAAC,CAAC,UAAkB,EAAE,IAA8B;QACnD,IAAI,CAAC,WAAW,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACb,CAAC;CACD"}
@@ -19,10 +19,11 @@ export declare abstract class BasePolicy {
19
19
  before?(user: UserPayload | null, action: string, ...args: unknown[]): HookResponse;
20
20
  /**
21
21
  * Runs after the action (or after a `before` short-circuit), receiving the
22
- * resolved response. A non-`undefined` return overrides it; `undefined`
23
- * keeps it.
22
+ * resolved response and the same resource args passed to the action (Adonis
23
+ * `after(user, action, result, ...args)`). A non-`undefined` return overrides
24
+ * the response; `undefined` keeps it.
24
25
  */
25
- after?(user: UserPayload | null, action: string, result: AuthorizationResponse): HookResponse;
26
+ after?(user: UserPayload | null, action: string, result: AuthorizationResponse, ...args: unknown[]): HookResponse;
26
27
  /**
27
28
  * The Bouncer's active scope for the in-flight check (56.3). Defaults to
28
29
  * `"global"` when the policy is used without a Bouncer context.
@@ -1 +1 @@
1
- {"version":3,"file":"BasePolicy.d.ts","sourceRoot":"","sources":["../../src/bouncer/BasePolicy.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC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ACxB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,qBAAqB,EAC7B,GAAG,IAAI,EAAE,OAAO,EAAE,GAChB,YAAY;IAEf;;;OAGG;IACH,SAAS,KAAK,KAAK,IAAI,KAAK,CAE3B;IAED;;;;OAIG;IACH,SAAS,KAAK,WAAW,IAAI,oBAAoB,CAEhD;IAED;;;;;OAKG;IACH,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,OAAO;CAIrE"}
@@ -1 +1 @@
1
- {"version":3,"file":"BasePolicy.js","sourceRoot":"","sources":["../../src/bouncer/BasePolicy.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGxE,MAAM,OAAgB,UAAU;IAwB/B;;;OAGG;IACH,IAAc,KAAK;QAClB,OAAO,gBAAgB,CAAC,IAAI,CAAC,EAAE,KAAK,IAAI,QAAQ,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACH,IAAc,WAAW;QACxB,OAAO,gBAAgB,CAAC,IAAI,CAAC,EAAE,WAAW,IAAI,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC1E,CAAC;IAED;;;;;OAKG;IACO,UAAU,CAAC,QAAsC;QAC1D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC;IACvE,CAAC;CACD"}
1
+ {"version":3,"file":"BasePolicy.js","sourceRoot":"","sources":["../../src/bouncer/BasePolicy.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGxE,MAAM,OAAgB,UAAU;IA0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