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
@@ -0,0 +1,598 @@
1
+ import { S as Sensitive } from './sensitive-BC_s7Rrd.cjs';
2
+ import { S as SharedSession } from './session-BWUWhhyB.cjs';
3
+ import { a as IdTokenClaims } from './jwks-BgojMGC5.cjs';
4
+
5
+ /**
6
+ * The OIDC Discovery 1.0 metadata document served by
7
+ * `GET /.well-known/openid-configuration` (wire schema
8
+ * `OidcDiscoveryDocument`). Every field is required by the server's schema.
9
+ *
10
+ * @remarks
11
+ * `issuer` is the **authoritative** issuer for ID-token validation
12
+ * (CONTRACT.md §12.4 rule 3). It may legitimately differ from the client's
13
+ * `baseUrl` when AXIAM runs behind a proxy, so this SDK never rejects a
14
+ * document on an issuer/base-URL mismatch (§12.3 rule 6). Likewise `jwks_uri`
15
+ * is read from here rather than hardcoded.
16
+ */
17
+ interface OidcConfiguration {
18
+ /** The authorization server's issuer identifier — the value an ID token's `iss` claim must equal exactly. */
19
+ issuer: string;
20
+ /** The authorization endpoint `oidcBegin` builds its redirect URL from. */
21
+ authorization_endpoint: string;
22
+ /** The token endpoint used by `oidcExchange`, `oidcRefresh` and `loginClientCredentials`. */
23
+ token_endpoint: string;
24
+ /** The userinfo endpoint. Advertised by the server but deliberately NOT called by any SDK (§12.3 rule 5). */
25
+ userinfo_endpoint: string;
26
+ /** URI of the JWKS document whose keys verify ID-token signatures (§12.4 rule 2). */
27
+ jwks_uri: string;
28
+ /** The RFC 7009 revocation endpoint used by `revoke`. */
29
+ revocation_endpoint: string;
30
+ /** The RFC 7662 introspection endpoint used by `introspect`. */
31
+ introspection_endpoint: string;
32
+ /** OAuth2 `response_type` values the server supports. */
33
+ response_types_supported: string[];
34
+ /** Subject identifier types the server supports. */
35
+ subject_types_supported: string[];
36
+ /** ID-token signing algorithms the server advertises. Informational only: §12.4 rule 1 pins verification to `EdDSA` regardless of what appears here. */
37
+ id_token_signing_alg_values_supported: string[];
38
+ /** Scopes the server supports. */
39
+ scopes_supported: string[];
40
+ /** Client-authentication methods the token endpoint supports (`client_secret_post`, §12.1 note 3). */
41
+ token_endpoint_auth_methods_supported: string[];
42
+ /** Claims the server may include in an ID token. */
43
+ claims_supported: string[];
44
+ /** Grant types the token endpoint supports. */
45
+ grant_types_supported: string[];
46
+ }
47
+ /**
48
+ * The result of `oidcBegin` — everything the caller needs to start an
49
+ * authorization-code + PKCE login (CONTRACT.md §12.1).
50
+ *
51
+ * @remarks
52
+ * **The caller owns this state** (§12.3 rule 1). The SDK stores nothing: it
53
+ * keeps no copy of `state`, `nonce` or `codeVerifier` in process-global state
54
+ * or any implicit cache. Persist all three in your own HTTP session (or in an
55
+ * {@link OidcStateStore}), redirect the browser to {@link url}, and pass
56
+ * `nonce` + `codeVerifier` back into `oidcExchange` when the code arrives.
57
+ */
58
+ interface AuthorizationRequest {
59
+ /** The fully-built authorization URL to redirect the browser to. */
60
+ url: string;
61
+ /** CSPRNG CSRF value (≥128 bits, base64url unpadded) to compare against the `state` the IdP returns. Not a secret (§12.3 rule 2). */
62
+ state: string;
63
+ /** CSPRNG replay-protection value (≥128 bits) that must equal the ID token's `nonce` claim. Not a secret (§12.3 rule 2). */
64
+ nonce: string;
65
+ /** The PKCE verifier, secret for its whole lifetime (§12.5). Pass it back into `oidcExchange`. */
66
+ codeVerifier: Sensitive<string>;
67
+ }
68
+ /** Arguments to `oidcBegin` (pure local computation — no network I/O). */
69
+ interface OidcBeginParams {
70
+ /** The discovery document, as returned by `oidcDiscover`. `authorization_endpoint` is taken from it and never hardcoded (§12.1 rule 5). */
71
+ configuration: OidcConfiguration;
72
+ /** The relying party's redirect URI, echoed back into `oidcExchange` unchanged. */
73
+ redirectUri: string;
74
+ /** Requested scope, as a string or an array. `openid` is added automatically when absent (§12.1 rule 4). Defaults to `openid`. */
75
+ scope?: string | string[];
76
+ /**
77
+ * Extra authorization-request parameters (e.g. `prompt`, `login_hint`,
78
+ * `ui_locales`). §12.1 rule 5 allows caller-supplied additions but forbids
79
+ * the SDK from adding any of its own beyond the mandated eight, so
80
+ * attempting to override one of those eight throws.
81
+ */
82
+ extraParams?: Record<string, string>;
83
+ }
84
+ /**
85
+ * A token set returned by the OAuth2 token endpoint (wire schema
86
+ * `TokenResponse`), returned by `oidcExchange`, `oidcRefresh` and
87
+ * `loginClientCredentials`.
88
+ *
89
+ * @remarks
90
+ * `accessToken`, `refreshToken` and `idToken` are {@link Sensitive} (§12.5):
91
+ * `toString()`, `JSON.stringify()` and `console.log`/`util.inspect` all
92
+ * redact them to `[SENSITIVE]`, and the raw value is reachable only through
93
+ * the documented-`@internal` `expose()` accessor.
94
+ *
95
+ * `idClaims` is present exactly when `idToken` is, and holds the
96
+ * **already-validated** claim set (§12.4) — validation happens before this
97
+ * object is ever constructed, so an `OidcTokenSet` in your hands is never
98
+ * partially trusted (§12.4 rule 7).
99
+ */
100
+ interface OidcTokenSet {
101
+ /** The OAuth2 access token (§12.5 secret). */
102
+ accessToken: Sensitive<string>;
103
+ /** The token type the server issued (`Bearer`). */
104
+ tokenType: string;
105
+ /** Access-token lifetime in seconds from the time of the response. */
106
+ expiresIn: number;
107
+ /** Granted scope, when the server narrowed or echoed it. */
108
+ scope?: string;
109
+ /** The refresh token, when the grant issued one (§12.5 secret). */
110
+ refreshToken?: Sensitive<string>;
111
+ /** The raw ID token, when the grant issued one (§12.5 secret). */
112
+ idToken?: Sensitive<string>;
113
+ /** The validated ID-token claims — present exactly when {@link idToken} is (§12.1, §12.4). */
114
+ idClaims?: IdTokenClaims;
115
+ }
116
+ /** Arguments to `oidcExchange` (`grant_type=authorization_code`). */
117
+ interface OidcExchangeParams {
118
+ /** The authorization code the IdP redirected back with. */
119
+ code: string;
120
+ /** The verifier from the matching {@link AuthorizationRequest}. Accepts the `Sensitive` wrapper or a bare string (e.g. rehydrated from your own session store). */
121
+ codeVerifier: Sensitive<string> | string;
122
+ /** The same `redirect_uri` that was sent on the authorization request. */
123
+ redirectUri: string;
124
+ /** The `nonce` from the matching {@link AuthorizationRequest}. MANDATORY — §12.4 rule 6 is not optional for this grant. */
125
+ nonce: string;
126
+ /** Tenant UUID for the token endpoint's required `tenant_id` query parameter. Defaults to the client's configured `tenantId` when it was built in UUID form (§12.3 rule 4). */
127
+ tenantId?: string;
128
+ /** A pre-fetched discovery document, to avoid re-reading the (cached) one. Fetched via `oidcDiscover` when omitted. */
129
+ configuration?: OidcConfiguration;
130
+ }
131
+ /** Arguments to `oidcRefresh` (`grant_type=refresh_token`). */
132
+ interface OidcRefreshParams {
133
+ /** The refresh token to redeem. Accepts the `Sensitive` wrapper or a bare string. */
134
+ refreshToken: Sensitive<string> | string;
135
+ /** Optional narrowed scope to request. Omitted from the form body when absent. */
136
+ scope?: string;
137
+ /** Tenant UUID for the `tenant_id` query parameter (§12.3 rule 4). */
138
+ tenantId?: string;
139
+ /** A pre-fetched discovery document. Fetched via `oidcDiscover` when omitted. */
140
+ configuration?: OidcConfiguration;
141
+ }
142
+ /** Arguments to `loginClientCredentials` (`grant_type=client_credentials`). */
143
+ interface LoginClientCredentialsParams {
144
+ /** Optional scope to request. This grant requests no `openid` scope and the response carries no `id_token` (§12.1). */
145
+ scope?: string;
146
+ /** Tenant UUID for the `tenant_id` query parameter (§12.3 rule 4). */
147
+ tenantId?: string;
148
+ /** A pre-fetched discovery document. Fetched via `oidcDiscover` when omitted. */
149
+ configuration?: OidcConfiguration;
150
+ /**
151
+ * Adopt the returned `access_token` as this client's bearer credential for
152
+ * subsequent REST calls on the same session — the §12.1
153
+ * "`login_client_credentials` as a credential source" allowance (a **MAY**,
154
+ * hence opt-in and `false` by default).
155
+ *
156
+ * When `true` the token is held behind {@link Sensitive} inside a request
157
+ * interceptor closure and emitted as `Authorization: Bearer …`; it is never
158
+ * written to `axios.defaults`, a public property, or the cookie jar, so it
159
+ * stays unreachable through any public getter (§12.3 rule 2).
160
+ */
161
+ adoptAsCredential?: boolean;
162
+ }
163
+ /** Arguments to `introspect` (RFC 7662). Requires confidential-client credentials (§12.1 note 4). */
164
+ interface IntrospectParams {
165
+ /** The token to introspect. Accepts the `Sensitive` wrapper or a bare string. */
166
+ token: Sensitive<string> | string;
167
+ /** Optional RFC 7662 `token_type_hint` (`access_token` / `refresh_token`). */
168
+ tokenTypeHint?: string;
169
+ /** Tenant UUID for the `tenant_id` query parameter (§12.3 rule 4). */
170
+ tenantId?: string;
171
+ /** A pre-fetched discovery document. Fetched via `oidcDiscover` when omitted. */
172
+ configuration?: OidcConfiguration;
173
+ }
174
+ /** Arguments to `revoke` (RFC 7009). Requires confidential-client credentials (§12.1 note 4). */
175
+ interface RevokeParams {
176
+ /** The token to revoke. Accepts the `Sensitive` wrapper or a bare string. */
177
+ token: Sensitive<string> | string;
178
+ /** Optional RFC 7009 `token_type_hint`. */
179
+ tokenTypeHint?: string;
180
+ /** Tenant UUID for the `tenant_id` query parameter (§12.3 rule 4). */
181
+ tenantId?: string;
182
+ /** A pre-fetched discovery document. Fetched via `oidcDiscover` when omitted. */
183
+ configuration?: OidcConfiguration;
184
+ }
185
+ /**
186
+ * The RFC 7662 introspection result (wire schema `IntrospectionResponse`).
187
+ * Only `active` is guaranteed; the server omits the metadata fields for an
188
+ * inactive token.
189
+ */
190
+ interface IntrospectionResult {
191
+ /** Whether the token is currently active. */
192
+ active: boolean;
193
+ /** Subject the token was issued to. */
194
+ sub?: string;
195
+ /** Client the token was issued to. */
196
+ clientId?: string;
197
+ /** Scope granted to the token. */
198
+ scope?: string;
199
+ /** Token type (`Bearer`). */
200
+ tokenType?: string;
201
+ /** Expiry time, epoch seconds. */
202
+ exp?: number;
203
+ /** Issued-at time, epoch seconds. */
204
+ iat?: number;
205
+ }
206
+ /** Arguments to `ssoStart` (`POST /api/v1/auth/federation/oidc/start`). */
207
+ interface SsoStartParams {
208
+ /** UUID of the server-side federation configuration identifying the upstream IdP. */
209
+ federationConfigId: string;
210
+ /** Post-login destination, stored server-side and echoed back by `ssoComplete`. */
211
+ redirectUri: string;
212
+ /** Tenant UUID. One tenant form (`tenantId` or `tenantSlug`) is required; defaults to the client's configuration (§5.1). */
213
+ tenantId?: string;
214
+ /** Tenant slug. Alternative to {@link tenantId}. */
215
+ tenantSlug?: string;
216
+ /** Organization UUID. One org form (`orgId` or `orgSlug`) is required; defaults to the client's configuration (§5.1). */
217
+ orgId?: string;
218
+ /** Organization slug. Alternative to {@link orgId}. */
219
+ orgSlug?: string;
220
+ }
221
+ /**
222
+ * The result of `ssoStart` (wire schema `OidcStartResponse`).
223
+ *
224
+ * @remarks
225
+ * There is deliberately **no nonce**: on the federation path the nonce never
226
+ * leaves the server (§12.1 note 7). Round-trip {@link state} into
227
+ * `ssoComplete` unmodified — the server stores it single-use with a 10-minute
228
+ * TTL and recovers the whole login context from it.
229
+ */
230
+ interface SsoStartResult {
231
+ /** The upstream IdP authorization URL to redirect the browser to. */
232
+ authorizeUrl: string;
233
+ /** Single-use CSRF state to round-trip back into `ssoComplete` unmodified. */
234
+ state: string;
235
+ /** Remaining TTL of the server-side state row, in seconds (600 = 10 min). */
236
+ expiresInSecs: number;
237
+ }
238
+ /** Arguments to `ssoComplete` (`POST /api/v1/auth/federation/oidc/callback`). */
239
+ interface SsoCompleteParams {
240
+ /** The `state` value the IdP redirected back with — must be the one `ssoStart` returned. */
241
+ state: string;
242
+ /** The authorization code the IdP redirected back with. */
243
+ code: string;
244
+ }
245
+ /**
246
+ * The result of `ssoComplete` (wire schema `SsoLoginSuccessResponse`).
247
+ *
248
+ * @remarks
249
+ * Carries **no token material** — the session arrives as `Set-Cookie`, so the
250
+ * §4 cookie jar is what actually captures it (§12.1 note 6). Use a Node
251
+ * session (`createNodeSession`) or the session is silently lost.
252
+ */
253
+ interface SsoCompleteResult {
254
+ /** The provisioned/linked user's UUID. */
255
+ userId: string;
256
+ /** The established session's UUID. */
257
+ sessionId: string;
258
+ /** Session/access-token lifetime in seconds. */
259
+ expiresIn: number;
260
+ /** The post-login destination that was stored during `ssoStart`. */
261
+ redirectUri: string;
262
+ }
263
+
264
+ /** Path of the OIDC discovery document, relative to the client base URL. */
265
+ declare const DISCOVERY_PATH = "/.well-known/openid-configuration";
266
+ /** Path of the federation SSO step-1 endpoint. */
267
+ declare const SSO_START_PATH = "/api/v1/auth/federation/oidc/start";
268
+ /** Path of the federation SSO step-2 (callback) endpoint. */
269
+ declare const SSO_CALLBACK_PATH = "/api/v1/auth/federation/oidc/callback";
270
+ /**
271
+ * Minimum — and default — discovery-cache TTL. CONTRACT.md §12.3 rule 6 sets
272
+ * a floor of 5 minutes; a smaller configured value is raised to it.
273
+ */
274
+ declare const MIN_DISCOVERY_TTL_MS = 300000;
275
+ /** Configuration for {@link OidcClient}. */
276
+ interface OidcClientOptions {
277
+ /**
278
+ * The relying party's OAuth2 `client_id`. Used on every grant and matched
279
+ * against the ID token's `aud`/`azp` (§12.4 rule 4).
280
+ */
281
+ clientId: string;
282
+ /**
283
+ * The `client_secret` for a confidential client, held behind
284
+ * {@link Sensitive} (§12.5). Omit for a public client — then it is never
285
+ * added to a form body (§12.1 "MUST omit rather than send empty/null").
286
+ *
287
+ * `introspect` and `revoke` REQUIRE it: the server marks `client_secret`
288
+ * non-nullable on both, so a public client cannot call them (§12.1 note 4).
289
+ */
290
+ clientSecret?: Sensitive<string> | string;
291
+ /**
292
+ * Default tenant UUID for the `tenant_id` query parameter the token,
293
+ * introspection and revocation endpoints require. Falls back to the
294
+ * session's configured `tenantId` when it was built in UUID form; a
295
+ * slug-only client must pass `tenantId` per call (§12.3 rule 4).
296
+ */
297
+ tenantId?: string;
298
+ /**
299
+ * Discovery-cache TTL in milliseconds. Defaults to (and is floored at)
300
+ * {@link MIN_DISCOVERY_TTL_MS} — §12.3 rule 6 forbids a TTL under 5 minutes.
301
+ */
302
+ discoveryTtlMs?: number;
303
+ /**
304
+ * Permitted ID-token clock skew in seconds. Defaults to 60 and is clamped to
305
+ * 60 — §12.4 rule 5 forbids configuring it higher.
306
+ */
307
+ clockSkewSec?: number;
308
+ }
309
+ /**
310
+ * Normalize a URL to its cache key: lowercased scheme and host with the port
311
+ * always explicit (§12.3 rule 6). `https://IAM.example.com/` and
312
+ * `https://iam.example.com:443/x` therefore share one key, while
313
+ * `http://iam.example.com` gets its own.
314
+ */
315
+ declare function normalizeOrigin(url: string): string;
316
+ /**
317
+ * The OIDC / SSO relying-party client (CONTRACT.md §12).
318
+ *
319
+ * @remarks
320
+ * Build one with {@link createOidcClient}, passing the same session your
321
+ * `AxiamClient` uses so the cookie jar (§4), TLS configuration (§6), tenant
322
+ * header (§5) and single-flight refresh guard (§9) are shared rather than
323
+ * duplicated.
324
+ *
325
+ * **The caller owns the login state.** `oidcBegin` returns `state`, `nonce`
326
+ * and `codeVerifier`; this class stores none of them (§12.3 rule 1). Keep them
327
+ * in your own HTTP session — or use {@link MemoryOidcStateStore} together with
328
+ * the `oidcLoginHandlers` glue from `axiam-sdk/middleware`, which does that
329
+ * bookkeeping for you.
330
+ *
331
+ * @example
332
+ * ```ts
333
+ * const session = createNodeSession({ baseUrl, tenantId });
334
+ * const oidc = createOidcClient(session, { clientId: 'my-app', clientSecret: secret });
335
+ *
336
+ * // 1. redirect the browser
337
+ * const configuration = await oidc.oidcDiscover();
338
+ * const request = oidc.oidcBegin({ configuration, redirectUri, scope: 'openid profile' });
339
+ * // …store request.state / request.nonce / request.codeVerifier in your session…
340
+ * res.redirect(request.url);
341
+ *
342
+ * // 2. on the callback, having checked the returned `state` matches
343
+ * const tokens = await oidc.oidcExchange({
344
+ * code, codeVerifier: request.codeVerifier, nonce: request.nonce, redirectUri,
345
+ * });
346
+ * console.log(tokens.idClaims?.sub); // validated ID-token subject
347
+ * ```
348
+ */
349
+ declare class OidcClient {
350
+ #private;
351
+ constructor(session: SharedSession, options: OidcClientOptions);
352
+ /**
353
+ * `GET /.well-known/openid-configuration` (§12.1) — fetch the OIDC discovery
354
+ * document, cached per origin with a ≥5-minute TTL and single-flight
355
+ * de-duplication of concurrent calls (§12.3 rule 6).
356
+ *
357
+ * The document's own `issuer` is authoritative for ID-token validation and
358
+ * may legitimately differ from `baseUrl` behind a proxy, so a mismatch is
359
+ * never treated as an error.
360
+ */
361
+ oidcDiscover(): Promise<OidcConfiguration>;
362
+ /**
363
+ * Build an authorization request (§12.1) — **pure local computation, no
364
+ * network I/O**.
365
+ *
366
+ * Generates a 32-byte CSPRNG `state` and `nonce` (base64url, unpadded) and a
367
+ * fresh PKCE verifier/challenge pair using **S256 only** — `plain` is not
368
+ * implemented anywhere in this SDK. The URL is built from the discovery
369
+ * document's `authorization_endpoint` with exactly the eight parameters
370
+ * §12.1 rule 5 mandates, plus any `extraParams` the caller adds.
371
+ *
372
+ * Nothing is stored: persist the returned `state`, `nonce` and
373
+ * `codeVerifier` yourself (§12.3 rule 1).
374
+ *
375
+ * @throws Error when `extraParams` tries to override one of the eight
376
+ * SDK-owned parameters — a programming error, caught at call time.
377
+ */
378
+ oidcBegin(params: OidcBeginParams): AuthorizationRequest;
379
+ /**
380
+ * `POST /oauth2/token` with `grant_type=authorization_code` (§12.1) —
381
+ * exchange an authorization code for a token set, validating the returned
382
+ * ID token in full before returning.
383
+ *
384
+ * The `nonce` argument is mandatory: this grant always requests the `openid`
385
+ * scope, so §12.4 rule 6 always applies. If **any** §12.4 rule fails, the
386
+ * whole token set is discarded and `AuthError` is raised with the matching
387
+ * reason code — the access and refresh tokens from the same response are
388
+ * never returned (§12.4 rule 7).
389
+ */
390
+ oidcExchange(params: OidcExchangeParams): Promise<OidcTokenSet>;
391
+ /**
392
+ * `POST /oauth2/token` with `grant_type=refresh_token` (§12.1) — refresh an
393
+ * {@link OidcTokenSet}, under the §9 single-flight refresh guard.
394
+ *
395
+ * @remarks
396
+ * This is a **distinct operation** from `AxiamClient.refresh()`, which drives
397
+ * the cookie/opaque-token session path at `POST /api/v1/auth/refresh`. The
398
+ * two are never merged or aliased and neither falls back to the other
399
+ * (§12.1). They do share the session's §9 guard, so at most one refresh of
400
+ * either kind is ever in flight for a session.
401
+ *
402
+ * Concurrent `oidcRefresh` calls collapse into one HTTP request and all
403
+ * receive the same token set — §9 rule 2's result sharing.
404
+ *
405
+ * An `id_token` in the response is validated against §12.4 rules 1–5 and 7;
406
+ * rule 6 (nonce) is skipped, since OIDC Core §12.2 does not require a nonce
407
+ * in a refresh-issued ID token.
408
+ */
409
+ oidcRefresh(params: OidcRefreshParams): Promise<OidcTokenSet>;
410
+ /**
411
+ * `POST /oauth2/token` with `grant_type=client_credentials` (§12.1) —
412
+ * service-account machine-to-machine login.
413
+ *
414
+ * Requests no `openid` scope, so the response carries no `id_token`. Pass
415
+ * `adoptAsCredential: true` to additionally use the returned access token as
416
+ * this session's bearer credential for subsequent REST calls (§12.1, a MAY).
417
+ *
418
+ * @throws AuthError when no `clientSecret` is configured — this grant cannot
419
+ * be performed by a public client.
420
+ */
421
+ loginClientCredentials(params?: LoginClientCredentialsParams): Promise<OidcTokenSet>;
422
+ /**
423
+ * `POST /oauth2/introspect` (RFC 7662, §12.1) — ask the server whether a
424
+ * token is active and, if so, for its metadata.
425
+ *
426
+ * Requires confidential-client credentials (§12.1 note 4). A `401` here is a
427
+ * *client-credential* failure surfaced as `OAuthProtocolError`; it never
428
+ * enters the §9 refresh guard, because refreshing the user session cannot
429
+ * fix a bad `client_secret` (§12.3 rule 3).
430
+ *
431
+ * @throws AuthError when no `clientSecret` is configured.
432
+ */
433
+ introspect(params: IntrospectParams): Promise<IntrospectionResult>;
434
+ /**
435
+ * `POST /oauth2/revoke` (RFC 7009, §12.1) — revoke an access or refresh
436
+ * token. Returns nothing.
437
+ *
438
+ * Per RFC 7009 the server answers `200` for unknown, expired and
439
+ * already-revoked tokens alike, so revocation is **idempotent**: any `200`
440
+ * is success and no error is raised for a token the server has never seen.
441
+ * Only a `401` (client authentication failed) is an error, surfaced as
442
+ * `OAuthProtocolError` (§12.1 note 5, §12.3 rule 3).
443
+ *
444
+ * @throws AuthError when no `clientSecret` is configured.
445
+ */
446
+ revoke(params: RevokeParams): Promise<void>;
447
+ /**
448
+ * `POST /api/v1/auth/federation/oidc/start` (§12.1) — step 1 of first-time
449
+ * SSO against an **upstream** IdP. No JWT required.
450
+ *
451
+ * One tenant form (`tenantId` or `tenantSlug`) and one org form (`orgId` or
452
+ * `orgSlug`) must be resolvable, from the arguments or from the session's
453
+ * construction options (§5.1). Redirect the browser to the returned
454
+ * `authorizeUrl` and round-trip `state` back into {@link ssoComplete}
455
+ * unmodified — the server keeps the nonce to itself (§12.1 note 7).
456
+ *
457
+ * @throws AuthError client-side, without a wire call, when tenant or org
458
+ * context cannot be resolved.
459
+ */
460
+ ssoStart(params: SsoStartParams): Promise<SsoStartResult>;
461
+ /**
462
+ * `POST /api/v1/auth/federation/oidc/callback` (§12.1) — step 2 of upstream
463
+ * SSO: consumes the single-use `state`, provisions or links the user, and
464
+ * establishes the session.
465
+ *
466
+ * @remarks
467
+ * The session arrives as **`Set-Cookie`**, not in the response body
468
+ * (§12.1 note 6), so this call must go through the §4 cookie jar: use a
469
+ * `NodeSession` (`createNodeSession`/`createNodeClient`) or the session is
470
+ * silently lost. On success the session is marked authenticated and its
471
+ * post-authentication hook runs, syncing the CSRF token and cached access
472
+ * token out of the jar exactly as `login()` does.
473
+ *
474
+ * §12.4 does not apply here — no ID token ever reaches the SDK on the
475
+ * federation path.
476
+ */
477
+ ssoComplete(params: SsoCompleteParams): Promise<SsoCompleteResult>;
478
+ }
479
+ /**
480
+ * Build an {@link OidcClient} on an existing session (CONTRACT.md §12).
481
+ *
482
+ * @param session the session the rest of the SDK already uses — normally a
483
+ * `NodeSession` from `createNodeSession`, so the §4 cookie jar is in place
484
+ * for `ssoComplete` (its session arrives as `Set-Cookie`).
485
+ * @param options the relying party's `clientId`, optional `clientSecret`, and
486
+ * optional tenant/TTL/skew overrides.
487
+ *
488
+ * @example
489
+ * ```ts
490
+ * import { createNodeSession, createOidcClient } from 'axiam-sdk/node';
491
+ *
492
+ * const session = createNodeSession({ baseUrl, tenantId, orgId });
493
+ * const oidc = createOidcClient(session, {
494
+ * clientId: process.env.AXIAM_CLIENT_ID!,
495
+ * clientSecret: process.env.AXIAM_CLIENT_SECRET,
496
+ * });
497
+ * ```
498
+ */
499
+ declare function createOidcClient(session: SharedSession, options: OidcClientOptions): OidcClient;
500
+
501
+ /**
502
+ * The tuple an {@link OidcStateStore} holds for one in-flight login.
503
+ *
504
+ * @remarks
505
+ * `codeVerifier` stays {@link Sensitive} while stored (§12.5: the verifier is
506
+ * secret for its whole lifetime, "including … in any `OidcStateStore` entry"),
507
+ * so `JSON.stringify()`ing an entry — e.g. into a Redis-backed store — emits
508
+ * `"[SENSITIVE]"` rather than the verifier. A store implementation that needs
509
+ * to persist the value must call `expose()` explicitly and is then responsible
510
+ * for protecting it at rest.
511
+ */
512
+ interface OidcStateEntry {
513
+ /** The `state` value this entry is keyed by. Not a secret (§12.3 rule 2). */
514
+ state: string;
515
+ /** The `nonce` to check the ID token's `nonce` claim against. Not a secret (§12.3 rule 2). */
516
+ nonce: string;
517
+ /** The PKCE verifier for the matching authorization request (§12.5 secret). */
518
+ codeVerifier: Sensitive<string>;
519
+ /** The `redirect_uri` that was sent on the authorization request and must be replayed on exchange. */
520
+ redirectUri: string;
521
+ /** Optional application-owned data, e.g. the page the user was heading to before login. */
522
+ returnTo?: string;
523
+ }
524
+ /**
525
+ * Optional server-side store for in-flight `oidcBegin` state
526
+ * (CONTRACT.md §12.3 rule 1).
527
+ *
528
+ * @remarks
529
+ * Implement this to back the login/callback handlers with your own storage
530
+ * (Redis, a database, an encrypted cookie). Two invariants are normative:
531
+ *
532
+ * 1. **Single-use.** {@link consume} MUST return the entry *and delete it
533
+ * atomically*, so a replayed callback cannot reuse a `state`.
534
+ * 2. **Expiry.** An entry older than 10 minutes MUST NOT be returned.
535
+ */
536
+ interface OidcStateStore {
537
+ /** Persist an entry, keyed by its `state`, starting its TTL now. */
538
+ save(entry: OidcStateEntry): Promise<void>;
539
+ /**
540
+ * Atomically fetch **and remove** the entry for `state`. Returns
541
+ * `undefined` when the state is unknown, already consumed, or expired —
542
+ * three cases a caller MUST treat identically (as a failed login), because
543
+ * distinguishing them leaks whether a `state` ever existed.
544
+ */
545
+ consume(state: string): Promise<OidcStateEntry | undefined>;
546
+ }
547
+ /**
548
+ * The contract-mandated TTL for stored login state: 10 minutes, matching the
549
+ * server's `federation_login_state` row lifetime (D-22, §12.3 rule 1).
550
+ */
551
+ declare const OIDC_STATE_TTL_MS = 600000;
552
+ /**
553
+ * In-memory reference implementation of {@link OidcStateStore} (§12.3 rule 1).
554
+ *
555
+ * @remarks
556
+ * Per-instance (never process-global), single-use, 10-minute TTL. Expired
557
+ * entries are dropped lazily on {@link consume} and swept opportunistically on
558
+ * {@link save}, so no timer is held and the store needs no shutdown hook — a
559
+ * long-lived `setInterval` would keep a Node process alive and would be a
560
+ * surprising side effect for a library.
561
+ *
562
+ * Suitable for a single-process app and for tests. A multi-instance deployment
563
+ * needs a shared store (Redis, database) — implement {@link OidcStateStore}
564
+ * yourself for that; nothing in the SDK assumes this class.
565
+ *
566
+ * @example
567
+ * ```ts
568
+ * const store = new MemoryOidcStateStore();
569
+ * await store.save({ state, nonce, codeVerifier, redirectUri });
570
+ * const entry = await store.consume(state); // returns the entry
571
+ * const again = await store.consume(state); // undefined — single-use
572
+ * ```
573
+ */
574
+ declare class MemoryOidcStateStore implements OidcStateStore {
575
+ #private;
576
+ /**
577
+ * @param ttlMs entry lifetime in milliseconds. Defaults to
578
+ * {@link OIDC_STATE_TTL_MS} (10 minutes) and is **clamped to it**: a
579
+ * shorter TTL is honoured (useful in tests), a longer one is reduced,
580
+ * because §12.3 rule 1 fixes 10 minutes as the maximum.
581
+ */
582
+ constructor(ttlMs?: number);
583
+ /** Number of unexpired entries currently held. Intended for tests and metrics. */
584
+ get size(): number;
585
+ /** Persist `entry` under its own `state`, expiring `ttlMs` from now. */
586
+ save(entry: OidcStateEntry): Promise<void>;
587
+ /**
588
+ * Atomically return and delete the entry for `state`. Deletion happens
589
+ * before the expiry check, so even an expired hit is removed rather than
590
+ * left to accumulate — and a second call can never return the same entry
591
+ * twice regardless of timing (JavaScript's single-threaded event loop makes
592
+ * this get-then-delete pair genuinely atomic; a store backed by real
593
+ * concurrency must use an atomic primitive such as Redis `GETDEL`).
594
+ */
595
+ consume(state: string): Promise<OidcStateEntry | undefined>;
596
+ }
597
+
598
+ export { type AuthorizationRequest as A, DISCOVERY_PATH as D, type IntrospectParams as I, type LoginClientCredentialsParams as L, MIN_DISCOVERY_TTL_MS as M, OIDC_STATE_TTL_MS as O, type RevokeParams as R, SSO_CALLBACK_PATH as S, type IntrospectionResult as a, MemoryOidcStateStore as b, type OidcBeginParams as c, OidcClient as d, type OidcClientOptions as e, type OidcConfiguration as f, type OidcExchangeParams as g, type OidcRefreshParams as h, type OidcStateEntry as i, type OidcStateStore as j, type OidcTokenSet as k, SSO_START_PATH as l, type SsoCompleteParams as m, type SsoCompleteResult as n, type SsoStartParams as o, type SsoStartResult as p, createOidcClient as q, normalizeOrigin as r };