axiam-sdk 1.0.0-alpha2 → 1.0.0-alpha21

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 (64) hide show
  1. package/README.md +219 -8
  2. package/dist/amqp/index.d.cts +1 -1
  3. package/dist/amqp/index.d.ts +1 -1
  4. package/dist/amqp/index.js +4 -0
  5. package/dist/amqp/index.js.map +1 -1
  6. package/dist/amqp/index.mjs +4 -0
  7. package/dist/amqp/index.mjs.map +1 -1
  8. package/dist/{authzCore-xwmCivHH.d.ts → authzCore-DtSN59if.d.ts} +19 -2
  9. package/dist/{authzCore-CV-Td-V1.d.cts → authzCore-DuRI1aJf.d.cts} +19 -2
  10. package/dist/client-B_FqmZ0i.d.cts +72 -0
  11. package/dist/client-Dn1fs5MH.d.ts +72 -0
  12. package/dist/cookieJar-BTDnjjbL.d.cts +122 -0
  13. package/dist/cookieJar-Cl8Lq9dL.d.ts +122 -0
  14. package/dist/grpc/index.d.cts +113 -6
  15. package/dist/grpc/index.d.ts +113 -6
  16. package/dist/grpc/index.js +435 -18
  17. package/dist/grpc/index.js.map +1 -1
  18. package/dist/grpc/index.mjs +434 -19
  19. package/dist/grpc/index.mjs.map +1 -1
  20. package/dist/index.d.cts +4 -2
  21. package/dist/index.d.ts +4 -2
  22. package/dist/index.js +209 -13
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.mjs +204 -14
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/jwks-BgojMGC5.d.cts +152 -0
  27. package/dist/jwks-BgojMGC5.d.ts +152 -0
  28. package/dist/middleware/index.d.cts +208 -8
  29. package/dist/middleware/index.d.ts +208 -8
  30. package/dist/middleware/index.js +1107 -1
  31. package/dist/middleware/index.js.map +1 -1
  32. package/dist/middleware/index.mjs +1100 -3
  33. package/dist/middleware/index.mjs.map +1 -1
  34. package/dist/nestjs/index.d.cts +2 -2
  35. package/dist/nestjs/index.d.ts +2 -2
  36. package/dist/nestjs/index.js +3 -0
  37. package/dist/nestjs/index.js.map +1 -1
  38. package/dist/nestjs/index.mjs +3 -0
  39. package/dist/nestjs/index.mjs.map +1 -1
  40. package/dist/node/index.d.cts +50 -94
  41. package/dist/node/index.d.ts +50 -94
  42. package/dist/node/index.js +1039 -15
  43. package/dist/node/index.js.map +1 -1
  44. package/dist/node/index.mjs +1023 -16
  45. package/dist/node/index.mjs.map +1 -1
  46. package/dist/oidcState-BGxqWUun.d.cts +598 -0
  47. package/dist/oidcState-CkFuCjpM.d.ts +598 -0
  48. package/dist/rest/index.d.cts +107 -5
  49. package/dist/rest/index.d.ts +107 -5
  50. package/dist/rest/index.js +209 -13
  51. package/dist/rest/index.js.map +1 -1
  52. package/dist/rest/index.mjs +204 -14
  53. package/dist/rest/index.mjs.map +1 -1
  54. package/dist/sensitive-BC_s7Rrd.d.cts +39 -0
  55. package/dist/sensitive-BC_s7Rrd.d.ts +39 -0
  56. package/dist/session-BWUWhhyB.d.cts +154 -0
  57. package/dist/session-BWUWhhyB.d.ts +154 -0
  58. package/package.json +2 -2
  59. package/dist/client-BPg9kfKV.d.ts +0 -150
  60. package/dist/client-CAeQw1a-.d.cts +0 -150
  61. package/dist/jwks-CX-nhD6A.d.cts +0 -29
  62. package/dist/jwks-CX-nhD6A.d.ts +0 -29
  63. package/dist/sensitive-CWBH_tHr.d.cts +0 -12
  64. package/dist/sensitive-CWBH_tHr.d.ts +0 -12
@@ -1,11 +1,123 @@
1
1
  import { Request, RequestHandler } from 'express';
2
- import { A as AxiamIdentity, V as VerifiableSession, a as AuthzVerifiableSession, R as ResourceSpec, b as RequireAccessOptions } from '../authzCore-xwmCivHH.js';
3
- export { c as AuthzChecker, d as AuthzLogger, C as CheckOutcome, E as ErrorBody, e as ResourceParamRef, f as ResourceResolutionError, g as ResourceResolver, h as assertAuthzClient, i as authenticateRequest, j as evaluateAccess, k as fromParam, l as hasAnyRole, r as resolveResourceId } from '../authzCore-xwmCivHH.js';
2
+ import { a as AuthzLogger, E as ErrorBody, b as AxiamIdentity, V as VerifiableSession, A as AuthzVerifiableSession, c as ResourceSpec, R as RequireAccessOptions } from '../authzCore-DtSN59if.js';
3
+ export { d as AuthzChecker, C as CheckOutcome, e as ResourceParamRef, f as ResourceResolutionError, g as ResourceResolver, h as assertAuthzClient, i as authenticateRequest, j as evaluateAccess, k as fromParam, l as hasAnyRole, r as resolveResourceId } from '../authzCore-DtSN59if.js';
4
+ import { d as OidcClient, j as OidcStateStore, k as OidcTokenSet, i as OidcStateEntry } from '../oidcState-CkFuCjpM.js';
5
+ export { A as AuthorizationRequest, I as IntrospectParams, a as IntrospectionResult, L as LoginClientCredentialsParams, M as MIN_DISCOVERY_TTL_MS, b as MemoryOidcStateStore, O as OIDC_STATE_TTL_MS, c as OidcBeginParams, e as OidcClientOptions, f as OidcConfiguration, g as OidcExchangeParams, h as OidcRefreshParams, R as RevokeParams, m as SsoCompleteParams, n as SsoCompleteResult, o as SsoStartParams, p as SsoStartResult, q as createOidcClient } from '../oidcState-CkFuCjpM.js';
4
6
  import { FastifyRequest, FastifyReply, FastifyPluginAsync } from 'fastify';
7
+ export { A as AxiamClaims, a as IdTokenClaims, V as Verifier } from '../jwks-BgojMGC5.js';
5
8
  import '../types-BVkMoqLU.js';
6
- import '../jwks-CX-nhD6A.js';
9
+ import '../sensitive-BC_s7Rrd.js';
10
+ import '../session-BWUWhhyB.js';
11
+ import 'axios';
7
12
 
13
+ /** Configuration shared by the login and callback handlers (CONTRACT.md §12). */
14
+ interface OidcLoginOptions {
15
+ /** The relying-party client driving the flow (built with `createOidcClient`). */
16
+ client: OidcClient;
17
+ /**
18
+ * Where in-flight login state is parked between the login redirect and the
19
+ * callback. {@link MemoryOidcStateStore} is a ready single-process
20
+ * implementation; a multi-instance deployment needs a shared one.
21
+ */
22
+ store: OidcStateStore;
23
+ /**
24
+ * The relying party's redirect URI — must be the public URL of the callback
25
+ * route, and is replayed verbatim on the token exchange (the server compares
26
+ * the two).
27
+ */
28
+ redirectUri: string;
29
+ /** Requested scope. `openid` is added automatically when absent (§12.1 rule 4). */
30
+ scope?: string | string[];
31
+ /** Where to send the browser after a successful login. Falls back to the `returnTo` captured at login time, then to a JSON summary. */
32
+ successRedirect?: string;
33
+ /**
34
+ * Called with the validated token set once the exchange succeeds — the hook
35
+ * where an application establishes its OWN session (sign a cookie, write a
36
+ * session row, …). The SDK deliberately does not do this for you: what a
37
+ * session means is the application's decision.
38
+ *
39
+ * Receives the consumed state entry too, so `returnTo` and any other
40
+ * application data captured at login time is available.
41
+ */
42
+ onSuccess?: (tokens: OidcTokenSet, entry: OidcStateEntry) => void | Promise<void>;
43
+ /** Debug-only logger. Receives failure reasons, never token material, `state`, `nonce` or the verifier. */
44
+ logger?: AuthzLogger;
45
+ }
46
+ /**
47
+ * What a login/callback handler should do next — one arm per response shape.
48
+ * Adapters translate this into their framework's API and add nothing of their
49
+ * own, so Express and Fastify cannot drift.
50
+ */
51
+ type OidcLoginOutcome = {
52
+ /** Send a 302 to {@link url}. */
53
+ kind: 'redirect';
54
+ /** Target of the redirect: the IdP authorization URL, or the post-login destination. */
55
+ url: string;
56
+ } | {
57
+ /** Reply `200` with {@link body} — the fallback when no post-login redirect is configured. */
58
+ kind: 'json';
59
+ /** A token-free summary of the established login. */
60
+ body: OidcLoginSuccessBody;
61
+ } | {
62
+ /** Reply {@link status} with the standardized `{ error, message }` body. */
63
+ kind: 'error';
64
+ /** HTTP status: 400 malformed callback, 401 authentication failure, 503 AXIAM unreachable. */
65
+ status: number;
66
+ /** Standardized error body (§10/§11 shape). */
67
+ body: ErrorBody;
68
+ };
69
+ /** The token-free success summary returned when no post-login redirect is configured. */
70
+ interface OidcLoginSuccessBody {
71
+ /** Always `true` — the ID token validated and the login completed. */
72
+ authenticated: true;
73
+ /** The authenticated subject from the validated ID token, when the server issued one. */
74
+ sub?: string;
75
+ /** Access-token lifetime in seconds, for a caller sizing its own session. */
76
+ expiresIn: number;
77
+ }
78
+ /** The callback query parameters the flow reads (RFC 6749 §4.1.2 / §4.1.2.1). */
79
+ interface OidcCallbackQuery {
80
+ /** The `state` the IdP echoed back — matched against the stored entry. */
81
+ state?: string;
82
+ /** The authorization code, on success. */
83
+ code?: string;
84
+ /** An RFC 6749 error code, when the IdP refused instead of issuing a code. */
85
+ error?: string;
86
+ /** The IdP's description of {@link error}. */
87
+ error_description?: string;
88
+ }
89
+ /**
90
+ * Step 1 — build the authorization request, park its state, and hand back the
91
+ * redirect (CONTRACT.md §12.1 `oidc_begin`).
92
+ *
93
+ * Discovery is fetched through `oidcDiscover`, so its per-origin cache and
94
+ * single-flight de-duplication apply and a busy login route does not hammer
95
+ * the discovery endpoint (§12.3 rule 6).
96
+ *
97
+ * @param options the shared login configuration.
98
+ * @param returnTo optional application destination to restore after login;
99
+ * stored with the state entry and used as the post-login redirect when
100
+ * `successRedirect` is unset.
101
+ */
102
+ declare function beginOidcLogin(options: OidcLoginOptions, returnTo?: string): Promise<OidcLoginOutcome>;
103
+ /**
104
+ * Step 2 — validate the callback, consume the stored state, exchange the code,
105
+ * and hand back the post-login response (CONTRACT.md §12.1 `oidc_exchange`).
106
+ *
107
+ * Failure mapping:
108
+ * - IdP returned `error=…` instead of a code → `401 authentication_failed`;
109
+ * - `state` or `code` missing → `400 invalid_request`;
110
+ * - `state` unknown, already consumed, or expired → `401 authentication_failed`
111
+ * (all three are deliberately indistinguishable to the client);
112
+ * - any §12.4 ID-token failure or `OAuthProtocolError` (an `AuthError`
113
+ * sub-type) → `401 authentication_failed`;
114
+ * - `NetworkError` → `503 oidc_unavailable`, never a silent success.
115
+ */
116
+ declare function completeOidcLogin(options: OidcLoginOptions, query: OidcCallbackQuery): Promise<OidcLoginOutcome>;
117
+
118
+ /** An Express `Request` augmented with the AXIAM identity that `axiamMiddleware` injects after §10 verification. */
8
119
  interface AxiamRequest extends Request {
120
+ /** The authenticated identity, present once `axiamMiddleware` (or `requireAuth`) has run; absent on an unauthenticated request. */
9
121
  axiamUser?: AxiamIdentity;
10
122
  }
11
123
  /**
@@ -66,15 +178,62 @@ declare function requireAccess(session: AuthzVerifiableSession, action: string,
66
178
  * coarser than `requireAccess`; NOT a substitute for a resource-level check.
67
179
  */
68
180
  declare function requireRole(session: VerifiableSession, ...roles: string[]): RequestHandler;
181
+ /**
182
+ * `oidcLoginHandlers(options)` (CONTRACT.md §12) — the two Express route
183
+ * handlers an application needs for "Login with AXIAM": a `login` handler that
184
+ * redirects the browser to AXIAM's authorization endpoint, and a `callback`
185
+ * handler that consumes the returned `state`, exchanges the code, and
186
+ * validates the ID token.
187
+ *
188
+ * @remarks
189
+ * Both handlers are thin adapters over {@link beginOidcLogin} /
190
+ * {@link completeOidcLogin}, which the Fastify variant
191
+ * (`oidcLoginPlugin`) also uses — so the two frameworks cannot drift on flow
192
+ * semantics or error mapping.
193
+ *
194
+ * The `login` handler reads an optional `?returnTo=` query parameter and
195
+ * stores it with the login state, so the callback can send the user back where
196
+ * they started. **Validate or allowlist that value in your own application if
197
+ * you accept it from user input** — an unchecked `returnTo` is an open-redirect
198
+ * vector, and the SDK cannot know which destinations your app considers safe.
199
+ *
200
+ * Establishing your application's own session is the `onSuccess` hook's job:
201
+ * the SDK validates the login and hands you the token set, but what a session
202
+ * means (a signed cookie, a database row, a JWT of your own) is your decision.
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * const store = new MemoryOidcStateStore();
207
+ * const oidc = createOidcClient(session, { clientId, clientSecret });
208
+ * const { login, callback } = oidcLoginHandlers({
209
+ * client: oidc,
210
+ * store,
211
+ * redirectUri: 'https://app.example.com/auth/callback',
212
+ * scope: 'openid profile email',
213
+ * onSuccess: (tokens) => { myAppSession.establish(tokens.idClaims!.sub); },
214
+ * });
215
+ *
216
+ * app.get('/auth/login', login);
217
+ * app.get('/auth/callback', callback);
218
+ * ```
219
+ */
220
+ declare function oidcLoginHandlers(options: OidcLoginOptions): {
221
+ /** `GET` handler that redirects the browser to the AXIAM authorization endpoint. */
222
+ login: RequestHandler;
223
+ /** `GET` handler for the redirect URI: consumes `state`, exchanges `code`, validates the ID token. */
224
+ callback: RequestHandler;
225
+ };
69
226
 
227
+ /** A Fastify `FastifyRequest` augmented with the AXIAM identity that `axiamPlugin` injects after §10 verification. */
70
228
  interface AxiamFastifyRequest extends FastifyRequest {
229
+ /** The authenticated identity, present once `axiamPlugin` (or `requireAuthHook`) has run; absent on an unauthenticated request. */
71
230
  axiamUser?: AxiamIdentity;
72
231
  }
73
232
  /** A Fastify `preHandler`-compatible hook function (CONTRACT.md §11) — usable both via `fastify.addHook('preHandler', ...)` and per-route as `{ preHandler: hook }`. */
74
233
  type PreHandlerHook = (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
75
234
  /**
76
- * `axiamPlugin(session)` — a `FastifyPluginAsync` registering
77
- * {@link buildAuthHook}'s `preHandler` hook globally (D-27, CONTRACT.md
235
+ * `axiamPlugin(session)` — a `FastifyPluginAsync` registering the shared
236
+ * auth `preHandler` hook globally (D-27, CONTRACT.md
78
237
  * §10). Marked with fastify's own `skip-override` plugin symbol (the same
79
238
  * mechanism the `fastify-plugin` package wraps) so the `preHandler` hook
80
239
  * applies to routes registered as siblings of this plugin rather than
@@ -88,8 +247,8 @@ declare const axiamPlugin: (session: VerifiableSession) => FastifyPluginAsync;
88
247
  * `preHandler` function usable per-route:
89
248
  * `fastify.get('/x', { preHandler: requireAuthHook(session) }, handler)`,
90
249
  * rather than registered globally via `fastify.register(axiamPlugin(session))`.
91
- * Pure sugar: it performs no verification of its own beyond what
92
- * {@link buildAuthHook} (shared with `axiamPlugin`) already does.
250
+ * Pure sugar: it performs no verification of its own beyond what the shared
251
+ * auth `preHandler` hook (also used by `axiamPlugin`) already does.
93
252
  */
94
253
  declare function requireAuthHook(session: VerifiableSession): PreHandlerHook;
95
254
  /**
@@ -109,6 +268,41 @@ declare function requireAccessHook(session: AuthzVerifiableSession, action: stri
109
268
  * `requireAuthHook`/`requireAccessHook` — this check never dereferences it.
110
269
  */
111
270
  declare function requireRoleHook(session: VerifiableSession, ...roles: string[]): PreHandlerHook;
271
+ /** Route paths the {@link oidcLoginPlugin} registers, relative to where it is registered. */
272
+ interface OidcLoginRoutePaths {
273
+ /** Path of the login-redirect route. Defaults to `/auth/login`. */
274
+ loginPath?: string;
275
+ /** Path of the callback route — must match the public URL in `redirectUri`. Defaults to `/auth/callback`. */
276
+ callbackPath?: string;
277
+ }
278
+ /**
279
+ * `oidcLoginPlugin(options)` (CONTRACT.md §12) — a `FastifyPluginAsync`
280
+ * registering the two "Login with AXIAM" routes: a login-redirect route and
281
+ * the callback route that consumes `state`, exchanges the code, and validates
282
+ * the ID token.
283
+ *
284
+ * @remarks
285
+ * The Fastify counterpart of Express's `oidcLoginHandlers`, built on the same
286
+ * {@link beginOidcLogin} / {@link completeOidcLogin} core, so the two
287
+ * frameworks cannot drift on flow semantics or error mapping. See
288
+ * `oidcLoginHandlers` for the `returnTo` open-redirect caveat and the
289
+ * `onSuccess` session-establishment contract, which apply identically here.
290
+ *
291
+ * Unlike `axiamPlugin` this plugin is deliberately **encapsulated** (no
292
+ * `skip-override` marker): it registers routes rather than a hook, so there is
293
+ * nothing that needs to escape its own context.
294
+ *
295
+ * @example
296
+ * ```ts
297
+ * await fastify.register(oidcLoginPlugin({
298
+ * client: oidc,
299
+ * store: new MemoryOidcStateStore(),
300
+ * redirectUri: 'https://app.example.com/auth/callback',
301
+ * onSuccess: (tokens) => { myAppSession.establish(tokens.idClaims!.sub); },
302
+ * }));
303
+ * ```
304
+ */
305
+ declare const oidcLoginPlugin: (options: OidcLoginOptions & OidcLoginRoutePaths) => FastifyPluginAsync;
112
306
 
113
307
  /**
114
308
  * Parse a raw `Cookie` request header into a name -> value map.
@@ -116,6 +310,7 @@ declare function requireRoleHook(session: VerifiableSession, ...roles: string[])
116
310
  * `=` only (cookie values may themselves contain `=`, e.g. base64/JWT).
117
311
  */
118
312
  declare function parseCookieHeader(header: string | undefined): Record<string, string>;
313
+ /** Name of the cookie carrying the AXIAM access token (`axiam_access`). */
119
314
  declare const ACCESS_COOKIE_NAME = "axiam_access";
120
315
  /**
121
316
  * Where an extracted bearer credential came from. Load-bearing for the CSRF
@@ -126,8 +321,11 @@ declare const ACCESS_COOKIE_NAME = "axiam_access";
126
321
  * set arbitrary request headers, but the browser will still send cookies.
127
322
  */
128
323
  type CredentialSource = 'cookie' | 'header';
324
+ /** A bearer credential together with where it was read from. */
129
325
  interface ExtractedCredential {
326
+ /** The raw bearer token value. */
130
327
  token: string;
328
+ /** Whether the token came from the `axiam_access` cookie or the `Authorization` header — load-bearing for the CSRF gate (§3). */
131
329
  source: CredentialSource;
132
330
  }
133
331
  /**
@@ -144,7 +342,9 @@ declare function extractCredential(cookieHeader: string | undefined, authHeader:
144
342
  * {@link extractCredential} directly.
145
343
  */
146
344
  declare function extractToken(cookieHeader: string | undefined, authHeader: string | undefined): string | undefined;
345
+ /** Name of the double-submit CSRF cookie (`axiam_csrf`). */
147
346
  declare const CSRF_COOKIE_NAME = "axiam_csrf";
347
+ /** Name of the CSRF request header (`x-csrf-token`) matched against {@link CSRF_COOKIE_NAME}. */
148
348
  declare const CSRF_HEADER_NAME = "x-csrf-token";
149
349
  /**
150
350
  * Whether `method` is a "safe" (non-state-changing) HTTP method per
@@ -172,4 +372,4 @@ declare function isSafeMethod(method: string | undefined): boolean;
172
372
  */
173
373
  declare function isCsrfValid(cookieHeader: string | undefined, csrfHeaderValue: string | undefined): boolean;
174
374
 
175
- export { ACCESS_COOKIE_NAME, AuthzVerifiableSession, type AxiamFastifyRequest, AxiamIdentity, type AxiamRequest, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, type CredentialSource, type ExtractedCredential, type PreHandlerHook, RequireAccessOptions, ResourceSpec, VerifiableSession, axiamMiddleware, axiamPlugin, extractCredential, extractToken, isCsrfValid, isSafeMethod, parseCookieHeader, requireAccess, requireAccessHook, requireAuth, requireAuthHook, requireRole, requireRoleHook };
375
+ export { ACCESS_COOKIE_NAME, AuthzLogger, AuthzVerifiableSession, type AxiamFastifyRequest, AxiamIdentity, type AxiamRequest, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, type CredentialSource, ErrorBody, type ExtractedCredential, type OidcCallbackQuery, OidcClient, type OidcLoginOptions, type OidcLoginOutcome, type OidcLoginRoutePaths, type OidcLoginSuccessBody, OidcStateEntry, OidcStateStore, OidcTokenSet, type PreHandlerHook, RequireAccessOptions, ResourceSpec, VerifiableSession, axiamMiddleware, axiamPlugin, beginOidcLogin, completeOidcLogin, extractCredential, extractToken, isCsrfValid, isSafeMethod, oidcLoginHandlers, oidcLoginPlugin, parseCookieHeader, requireAccess, requireAccessHook, requireAuth, requireAuthHook, requireRole, requireRoleHook };