axiam-sdk 1.0.0-beta16 → 1.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 (66) hide show
  1. package/README.md +546 -27
  2. package/dist/amqp/index.d.cts +1 -1
  3. package/dist/amqp/index.d.ts +1 -1
  4. package/dist/amqp/index.js +6 -1
  5. package/dist/amqp/index.js.map +1 -1
  6. package/dist/amqp/index.mjs +6 -1
  7. package/dist/amqp/index.mjs.map +1 -1
  8. package/dist/{authzCore-DJmDAAtw.d.cts → authzCore-BQfX9qxN.d.cts} +33 -6
  9. package/dist/{authzCore-0fObXIqB.d.ts → authzCore-BlSHwGnW.d.ts} +33 -6
  10. package/dist/browser/index.d.cts +3 -3
  11. package/dist/browser/index.d.ts +3 -3
  12. package/dist/{client-BstRBtp8.d.ts → client-0WJkblDE.d.ts} +2536 -182
  13. package/dist/{client-Dd_XaOtg.d.cts → client-yD0eMwHQ.d.cts} +2536 -182
  14. package/dist/{cookieJar-Dvb1Gnwm.d.cts → cookieJar-CTD5jOmd.d.cts} +3 -3
  15. package/dist/{cookieJar-D0FxzBQG.d.ts → cookieJar-hWRmZkhe.d.ts} +3 -3
  16. package/dist/errors-CmBvsxV0.d.ts +79 -0
  17. package/dist/errors-DMIlw2lN.d.cts +101 -0
  18. package/dist/errors-DMIlw2lN.d.ts +101 -0
  19. package/dist/errors-m0Tue_pE.d.cts +79 -0
  20. package/dist/grpc/index.d.cts +219 -12
  21. package/dist/grpc/index.d.ts +219 -12
  22. package/dist/grpc/index.js +4178 -1965
  23. package/dist/grpc/index.js.map +1 -1
  24. package/dist/grpc/index.mjs +4177 -1966
  25. package/dist/grpc/index.mjs.map +1 -1
  26. package/dist/index.d.cts +6 -5
  27. package/dist/index.d.ts +6 -5
  28. package/dist/index.js +4097 -1940
  29. package/dist/index.js.map +1 -1
  30. package/dist/index.mjs +4059 -1941
  31. package/dist/index.mjs.map +1 -1
  32. package/dist/{jwks-CSXHo3DS.d.cts → jwks-BR55d7-Z.d.cts} +36 -13
  33. package/dist/{jwks-CSXHo3DS.d.ts → jwks-BR55d7-Z.d.ts} +36 -13
  34. package/dist/middleware/index.d.cts +50 -9
  35. package/dist/middleware/index.d.ts +50 -9
  36. package/dist/middleware/index.js +623 -31
  37. package/dist/middleware/index.js.map +1 -1
  38. package/dist/middleware/index.mjs +621 -33
  39. package/dist/middleware/index.mjs.map +1 -1
  40. package/dist/nestjs/index.d.cts +2 -2
  41. package/dist/nestjs/index.d.ts +2 -2
  42. package/dist/nestjs/index.js +6 -1
  43. package/dist/nestjs/index.js.map +1 -1
  44. package/dist/nestjs/index.mjs +6 -1
  45. package/dist/nestjs/index.mjs.map +1 -1
  46. package/dist/node/index.d.cts +307 -7
  47. package/dist/node/index.d.ts +307 -7
  48. package/dist/node/index.js +4681 -1644
  49. package/dist/node/index.js.map +1 -1
  50. package/dist/node/index.mjs +4668 -1646
  51. package/dist/node/index.mjs.map +1 -1
  52. package/dist/{oidcState-CffZ6PkC.d.ts → oidcState-DOSCgnMG.d.ts} +382 -9
  53. package/dist/{oidcState-CSi4DY8h.d.cts → oidcState-mQLVn3-A.d.cts} +382 -9
  54. package/dist/rest/index.d.cts +80 -11
  55. package/dist/rest/index.d.ts +80 -11
  56. package/dist/rest/index.js +4097 -1940
  57. package/dist/rest/index.js.map +1 -1
  58. package/dist/rest/index.mjs +4059 -1941
  59. package/dist/rest/index.mjs.map +1 -1
  60. package/dist/{session-oiuBA1ZA.d.cts → session-BmjEMowX.d.cts} +216 -2
  61. package/dist/{session-ymrHvMuJ.d.ts → session-CeG6P9GO.d.ts} +216 -2
  62. package/dist/{telemetry-DrGqL4kb.d.cts → telemetry--0DwnNjV.d.cts} +24 -2
  63. package/dist/{telemetry-DrGqL4kb.d.ts → telemetry--0DwnNjV.d.ts} +24 -2
  64. package/package.json +6 -3
  65. package/dist/errors-CxqAZsex.d.cts +0 -168
  66. package/dist/errors-CxqAZsex.d.ts +0 -168
package/README.md CHANGED
@@ -1,13 +1,8 @@
1
1
  # axiam-sdk (TypeScript/JavaScript)
2
2
 
3
- <!-- Track the CURRENT channel's dist-tag, not `latest`: releases are prereleases and
4
- the publish job keeps those off `latest` (see "Release / versioning"), so a plain
5
- `npm/v/axiam-sdk` badge reports whatever was last published to `latest` — today
6
- 1.0.0-alpha28, dozens of releases stale. Move `beta` below to `rc`, then drop it
7
- entirely, as the channel advances. -->
8
3
  [![CI](https://github.com/ilpanich/axiam-typescript-sdk/actions/workflows/sdk-ci-typescript.yml/badge.svg?branch=main)](https://github.com/ilpanich/axiam-typescript-sdk/actions/workflows/sdk-ci-typescript.yml)
9
4
  [![Coverage Status](https://coveralls.io/repos/github/ilpanich/axiam-typescript-sdk/badge.svg?branch=main)](https://coveralls.io/github/ilpanich/axiam-typescript-sdk?branch=main)
10
- [![npm](https://img.shields.io/npm/v/axiam-sdk/beta?label=npm%20beta)](https://www.npmjs.com/package/axiam-sdk)
5
+ [![npm](https://img.shields.io/npm/v/axiam-sdk)](https://www.npmjs.com/package/axiam-sdk)
11
6
  [![Docs](https://img.shields.io/badge/docs-TypeDoc-blue.svg)](https://ilpanich.github.io/axiam-typescript-sdk/)
12
7
  [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
13
8
 
@@ -18,26 +13,103 @@ Official TypeScript/JavaScript client SDK for [AXIAM](https://github.com/ilpanic
18
13
  ## Package identity
19
14
 
20
15
  - **npm package:** `axiam-sdk`
21
- - **Registry:** [npmjs.com/package/axiam-sdk](https://www.npmjs.com/package/axiam-sdk) — published as prereleases, under the `alpha`/`beta` dist-tags
16
+ - **Registry:** [npmjs.com/package/axiam-sdk](https://www.npmjs.com/package/axiam-sdk) — stable releases on the `latest` dist-tag, following [semantic versioning](https://semver.org/)
22
17
  - **Source:** [github.com/ilpanich/axiam-typescript-sdk](https://github.com/ilpanich/axiam-typescript-sdk)
23
18
  - **License:** Apache-2.0
24
19
  - **Node:** `>=22` — see [Supported Node versions](#supported-node-versions)
25
20
 
26
21
  ## Contract conformance
27
22
 
28
- This SDK conforms to **contract 1.50**: CONTRACT.md §1–§13 and §12.7, §14, §15, §17, §19,
29
- §20, §21, §22, §23, §24, §25, §26, §27, §28 (including §6.1 mTLS client certificates, the
23
+ This SDK conforms to **contract 1.60**: CONTRACT.md §1–§13 and §12.7, §14, §15, §17, §19,
24
+ §20, §21, §22, §23, §24, §25, §26, §27, §28, §28.12, §29, §30, §31, §32 and §33, with §32.7 and
25
+ §33.2 signed (including §6.1 mTLS client certificates, the
30
26
  §10.1 minimum local-verification set, the §12 OIDC/SSO relying-party helpers, and the §13
31
27
  `verifyWebhook` signature verifier). §12 is implemented in full at its 1.38 shape: all
32
28
  **thirteen** operations, including the four public "Sign in with X" entry points.
33
29
 
30
+ ### Contract 1.60 — the answers to #588 and the release wave (§34.4)
31
+
32
+ Contract 1.60 changes no route; it answers the questions the 1.59 ports raised (§34.4
33
+ A1 – B9, C-1 – C-16) and adds the 1.0.0 release wave's members. Every §34.4 row assigned to
34
+ TypeScript:
35
+
36
+ | Row | Rule | What this SDK does |
37
+ |---|---|---|
38
+ | A3 | §32.7 step 4, P6 | A failed cold-cache fill and a failed expiry refresh of the SSF key cache count toward the once-a-minute limit; the cache expires after ten minutes (`JWKS_CACHE_MAX_AGE_MS`). |
39
+ | B1, C-1 | §32.7 step 9, P3, P4 | A replay store that cannot answer (a throw, a rejection, any answer but `true`/`false`) gives no verdict: `verifySet` raises `NetworkError`, the store's failure on `cause`, and `poll` leaves the SET unjudged. A `SetRefusedError` thrown from inside a store is wrapped too, so no store failure carries a reason code. |
40
+ | C-3, C-4 | P1, §19.1 | After the replay store fails in a `poll` batch it is not asked again: every later SET that verifies is unjudged, one that fails verification is still refused. A `poll` that returns with SETs unjudged emits the §19 `ssfUnjudged` event (count and category, `key_fetch` or `replay_store`; no `jti`). |
41
+ | §15.2 rule 9 | §15 | The `actor_token` is the same client's `client_credentials` token. |
42
+ | §8 minimal profile | §8 | A broker confirm is not evidence that AXIAM saw a message. |
43
+ | §31 `expected_updated_at` | §31.3 rule 4 | On `ScimTargetInput`, sent exactly as given and only when set; `scimTargetInputFrom` carries the read's `updated_at`, so a read-modify-write of a target written since is `409`. |
44
+ | §27.15 `window_minutes` | §27.15 note 1 | On the `notificationRules` models, sent as given (never clamped) and only when set. |
45
+ | §27.15 `allow_sha1_signatures`, `idp_metadata_signing_cert_pem` | notes 6, 7 | On the three federation configuration models, sent only when set; a response without `allow_sha1_signatures` (a server before 1.0.0) reads `false`. |
46
+ | §27.15 note 8 | §27.4 rule 5 | `federation.updateConfig`: each of the ten nullable members of `UpdateFederationConfigRequest` is cleared by `null` and left unchanged when `undefined`, and the body carries exactly the members you set. |
47
+ | §12.1 refresh `scope` | §12.1 | An `oidcRefresh` result's `scope` is the refresh response's, which may be narrower than the grant's. |
48
+ | §21.5 discovery | §21.5, §12.1 | `OidcConfiguration` carries the four revocation and introspection auth members, all optional; a document without them decodes. |
49
+
50
+ ### Contract 1.59 — the Phase 23 ports review (§34)
51
+
52
+ Contract 1.59 changes no wire shape; it clarifies §28.12 and §29 – §33 (§34.2 P1 – P12) and
53
+ lists what the review of this SDK found (follow-up F-59-02). What changed here:
54
+
55
+ | Row | Rule | What changed |
56
+ |---|---|---|
57
+ | R-18 | §30.5, §31.5, §32.5, §7 rule 1 | A management write that fails with a `5xx` or a transport error no longer carries its request — and so its `bind_secret`, `credential`, `authorization_header`, or §27.5 secret — in `NetworkError.cause`: the cause is rebuilt from an allow-list of diagnostics. |
58
+ | R-1 | §32.7, P1 | `SsfReceiver.poll` returns the SETs it judged and leaves one it could not judge unrecorded, listed in `unjudged`; it never keeps a `jti` it does not return. |
59
+ | R-7 | §32.7, P7 | The SSF section says `poll` is retried on `408` and `429`, as it always was. |
60
+ | R-20 | §29.5, §31.2, P12.1 | Every `directory`, `saml`, `scimTargets` and `ssf` response keeps only the members its type declares, at every depth; an unknown union arm keeps only its `type`. |
61
+ | R-23 | §28.12.2 rule 4, P12.4 | `updateClientRegistration` sends no list the read lacked, and a list of an unexpected shape as read; `redirect_uris`, `grant_types` and `response_types` are optional on `ClientRegistration`. |
62
+ | R-28 | §27.4 rule 5, §29.2, §21.3.1 | Generated docs no longer call every replacement body all-required or every all-optional type sparse; seven mTLS aliases, not six. |
63
+ | §33.8 t8 | §33.7 rule 5, P8 | `cibaPoll` retries a `5xx` whatever its body, `500 {"error":"server_error"}` included. |
64
+
65
+ The choice P1 leaves open: `poll` takes the second form — return what was judged, leave the
66
+ unjudged unrecorded and list their `jti`s — and, when it accepted nothing, records nothing and
67
+ throws the failure (the first form's outcome).
68
+
69
+ ### Contracts 1.53 – 1.58
70
+
71
+ | Section | What ships | Where |
72
+ |---|---|---|
73
+ | §28.12 RFC 7592 client configuration (1.53) | `readClientRegistration`, `updateClientRegistration`, `deleteClientRegistration`, `ClientRegistration` | `AxiamClient` (see [below](#rfc-7592-client-configuration-contract-153-2812)) |
74
+ | §30 directory configuration (1.54) | the `directory` namespace, explicit-`null` sparse update, `setDirectoryConfigFrom` | `client.directory` |
75
+ | §29 SAML service-provider registration (1.55) | the `saml` namespace, `parseSpMetadataFromUrl` / `FromXml`, `samlServiceProviderInputFrom` | `client.saml` |
76
+ | §32 SSF stream registration (1.56) | the `ssf` namespace, `ssfStreamInputFrom` | `client.ssf` |
77
+ | §32.7 SSF receiver helper (1.56) | `SsfReceiver.verifySet` / `.poll` | `axiam-sdk/node` |
78
+ | §31 outbound SCIM targets (1.57) | the `scim_targets` namespace, `scimTargetInputFrom` | `client.scimTargets` |
79
+ | §33 CIBA, and §33.2's signed form (1.58) | `cibaInitiate`, `cibaPoll`, `cibaAwait`, `cibaHandlePing`, `CibaRequestSigner` (PS256, ES256, EdDSA) | `OidcClient` (`axiam-sdk/node`) |
80
+ | §21.3.1 vector A amended (1.58) | `mtls_endpoint_aliases.backchannel_authentication_endpoint`, the seventh alias | `OidcConfiguration` |
81
+
82
+ **Not shipped, and why:** nothing in these sections is declined. Two placement notes:
83
+ `SsfReceiver` is Node-only (it verifies Ed25519 signatures with `node:crypto`), and the CIBA
84
+ helpers live on the Node-only `OidcClient` with the rest of §12, as §33.6 asks ("the handle
85
+ that already carries `oidc_exchange` and `device_authorize`"). A CIBA client authenticates
86
+ by `clientSecret` (`client_secret_post`) or by the session's §6.1 client certificate
87
+ (`tls_client_auth`); this SDK has no `private_key_jwt` client authentication (§21.8 is
88
+ informative), so a CIBA client registered for `private_key_jwt` cannot use these helpers.
89
+
90
+ ### Contract 1.51 — the dogfooding remediation
91
+
92
+ | Item | Status |
93
+ |---|---|
94
+ | §5.2 rule 1 — the acting tenant, `X-Axiam-Tenant` (`AxiamClientOptions.actingTenantId`, `client.actingTenant()`/`.clearActingTenant()`) | Shipped |
95
+ | §6.1 rules 6–10 — `authenticateDevice()`, the mTLS device login | Shipped |
96
+ | §1.1.1 / §10.3 — `TokenGrpcClient.validateToken`/`.introspectToken` | Shipped |
97
+ | §10.1 rule 9 at the default middleware entry point | **Fixed a real defect** — see the §10.1 section below and the CHANGELOG's `[Unreleased]` Breaking entry |
98
+ | §10.1 rule 9 at `Verifier.verifyAccessToken` itself | **Fixed a real defect** — see the §10.1 section below and the CHANGELOG's `[Unreleased]` Breaking entry |
99
+ | §27.6.1 — manifest `resources[].metadata`, the two-shape role binding, `serviceAccounts` | Shipped |
100
+ | §27.6.1 — manifest `webhooks` | **Declined** — named by the contract without being specified, and no consumer has asked for it |
101
+ | §6.1 rule 7 as a typestate | **Declined** — the client-side `AuthError` the rule itself names as conforming is what this SDK ships; a typestate would make `AxiamClient` generic in every caller for the sake of one operation |
102
+
103
+ See each linked section below for the full behaviour, and CHANGELOG.md's `[Unreleased]`
104
+ section for the complete Added/Changed/Fixed/Breaking list.
105
+
34
106
  **§12's operations live on `OidcClient`, not on `AxiamClient`** — the separate host §12.2
35
107
  permits where a packaging constraint requires one, which here is CI's proof that a `/rest`
36
108
  browser bundle pulls in no Node-only code. §12.2 forbids splitting them across two hosts, so
37
109
  the four operations contract 1.38 adds are on `OidcClient` too, with the nine that preceded
38
110
  them, even though three of them need no Node-only code at all.
39
111
 
40
- §27 is implemented **in full**, both halves: the 160-operation imperative surface *and*
112
+ §27 is implemented **in full**, both halves: the 190-operation imperative surface *and*
41
113
  the §27.6 declarative manifest with its §27.7 `defineManifest` and decorator forms. The
42
114
  contract asks an SDK that ships only one half to say which; this one ships both.
43
115
 
@@ -46,10 +118,10 @@ Express middleware and the Fastify plugin — with all three operations, the
46
118
  `resourceMetadataUrl` guard option and §28.9's five required tests. This SDK is §28.10's
47
119
  reference implementation: it lands first and the ten ports are read against it.
48
120
 
49
- §12.7, §14, §15, §22, §24, §25, §26, §27 and §28 are named rather than folded into the
50
- range because they landed after this SDK already claimed §1–§13: widening the range
51
- silently would turn a statement that was true when written into a different claim without
52
- anyone editing it.
121
+ §12.7, §14, §15, §17, §19, §20, §21, §22, §23, §24, §25, §26, §27, §28, §28.12, §29, §30,
122
+ §31, §32, §32.7, §33 and §33.2 signed are named rather than folded into the range because they landed after this SDK already claimed §1–§13:
123
+ widening the range silently would turn a statement that was true when written into a
124
+ different claim without anyone editing it.
53
125
 
54
126
  ### §10.1 minimum local-verification set
55
127
 
@@ -59,7 +131,32 @@ rule on every inbound token: EdDSA `alg` pinned before the JWKS is consulted, a
59
131
  `exp` (`jose` only checks `exp` *if present*, so `requiredClaims: ['exp']` is passed
60
132
  explicitly), `nbf` honoured when present, `tenant_id` asserted against the session's
61
133
  configured tenant, `iss`/`aud` checked when configured, all under a named 60-second
62
- `CLOCK_SKEW_LEEWAY_SEC`.
134
+ `CLOCK_SKEW_LEEWAY_SEC` — **and, since contract 1.51, rule 9**: a token carrying `cnf` is
135
+ refused unless transport evidence backs it. `axiamMiddleware`/`axiamPlugin` derive that
136
+ evidence automatically from the request's own raw socket (the peer certificate the TLS
137
+ layer verified for *this* connection, when Node itself terminates TLS) via the new
138
+ `certificateProofFromSocket`; a deployment behind a proxy that forwards nothing still
139
+ refuses a bound token, correctly, rather than silently accepting it. **This closes a real
140
+ defect**: before 1.51 `authenticateRequest` applied no rule-9 check at all, so a `cnf`-bound
141
+ device token (every token `authenticateDevice()`, §6.1, mints) passed through as an
142
+ ordinary bearer credential. See the CHANGELOG's `[Unreleased]` Breaking entry.
143
+
144
+ **A second, independent defect in the same rule closed alongside it:**
145
+ `Verifier.verifyAccessToken` — the SDK's own documented "anything guarding a
146
+ route MUST use this" entry point (see `verifySignatureOnlyUnchecked`'s doc) —
147
+ applied rules 1–8 only and never read `cnf` at all, because it had no
148
+ transport to ask for a peer certificate. A guard written directly on it, per
149
+ that doc, therefore accepted a certificate- or DPoP-bound token — a device
150
+ token from `authenticateDevice()` among them — as an ordinary bearer
151
+ credential, even though `authenticateRequest` (and so `axiamMiddleware`/
152
+ `axiamPlugin`) was by then already safe. `verifyAccessToken` now takes an
153
+ optional third `proofs` argument — the same shape `authenticateRequest`
154
+ takes and forwards straight through — and defaults it to `{}` (no evidence),
155
+ so a bound token is refused unless the caller supplies matching evidence.
156
+ Internally it reuses `verifyTokenBinding`, the same function
157
+ `authenticateRequest` and a hand-rolled guard call, so local verification
158
+ never disagrees with itself about whether a token is a bearer token. See the
159
+ CHANGELOG's `[Unreleased]` Breaking entry.
63
160
 
64
161
  Because the `/oauth2/jwks` trust anchor is **organization-wide**, the session guarding a
65
162
  resource server must be configured with the tenant **UUID** (`tenantId`), since that is
@@ -84,13 +181,12 @@ See [`CONTRACT.md`](./CONTRACT.md) for the full cross-language behavioral contra
84
181
  ## Install
85
182
 
86
183
  ```bash
87
- npm install axiam-sdk@beta
184
+ npm install axiam-sdk@^1.0.0
88
185
  ```
89
186
 
90
- Every release so far is a prerelease, and the publish job files each one under its
91
- channel's dist-tag (`beta` today) rather than `latest` — so name the channel, or pin an
92
- exact version. A bare `npm install axiam-sdk` resolves `latest`, which no prerelease
93
- moves.
187
+ From 1.0.0 the SDK is stable and follows semantic versioning: a breaking change to its
188
+ public API waits for the next major version. Releases are published on npm's `latest`
189
+ dist-tag, so a bare `npm install axiam-sdk` resolves the newest one.
94
190
 
95
191
  ## Supported Node versions
96
192
 
@@ -195,6 +291,54 @@ const client = new AxiamClient({
195
291
  browser build validates the PEM shape then ignores `clientCert`/`clientKey` — exactly as
196
292
  it already ignores `customCa`.
197
293
 
294
+ #### The mTLS device login, `authenticateDevice()` (§6.1 rules 6–10, contract 1.51)
295
+
296
+ A client built with `clientCert`/`clientKey` above authenticates by presenting that
297
+ certificate, rather than a username and password:
298
+
299
+ ```ts
300
+ const device = new AxiamClient({
301
+ baseUrl: 'https://iam.example.com',
302
+ tenantSlug: 'acme',
303
+ clientCert: readFileSync('device.crt', 'utf8'),
304
+ clientKey: readFileSync('device.key', 'utf8'),
305
+ });
306
+
307
+ const token = await device.authenticateDevice(); // POST /api/v1/auth/device, no body
308
+ // token.accessToken: Sensitive<string>, token.tokenType === 'Bearer', token.expiresIn
309
+ await device.management.serviceAccounts.list(); // adopted: carries Authorization: Bearer
310
+ ```
311
+
312
+ - **Reachable only on a client built with a certificate.** Calling it on one that was not
313
+ fails client-side with `AuthError` and **zero wire calls** — the server would answer
314
+ `401` in any case, so going to the wire earns nothing.
315
+ - **Adopted like a `login()` result.** Every subsequent same-origin request carries the
316
+ token as `Authorization: Bearer`, and withholds any cookie a previous session on the same
317
+ client left behind — the server reads the `axiam_access` cookie *before* the
318
+ `Authorization` header, so a stale one would otherwise silently win.
319
+ - **There is no refresh token.** A device re-authenticates by calling
320
+ `authenticateDevice()` again — one TLS handshake. A later `401` on the adopted token
321
+ surfaces as `AuthError` without a refresh attempt, on REST and gRPC alike — gRPC calls
322
+ send the device token too (not the cookie-jar-synced one) once it is adopted.
323
+ - **Held until replaced.** `logout()` clears it; `refresh()` does not. Any later
324
+ session-establishing call replaces it with its own session: `login()`, `verifyMfa()`,
325
+ `loginOpaque()`, a WebAuthn authentication, an SSO/federation completion,
326
+ `loginClientCredentials({ adoptAsCredential: true })`, or another `authenticateDevice()`
327
+ call. A **refused** re-authentication over `authenticateDevice()` leaves the previously
328
+ adopted device credential exactly as it was — it does not fail into "no credential at
329
+ all".
330
+ - **Every refusal is a `401`** — unknown, untrusted, expired, revoked or unbound
331
+ certificate, or a `Server`-type certificate — mapped to `AuthError` verbatim. The route is
332
+ rate-limited per client IP; a `429` maps to `NetworkError`, not `AuthError`, and is never
333
+ retried.
334
+ - **The token is certificate-bound** (`cnf.x5t#S256`) — see the §10.1 rule 9 section below
335
+ for what that means for anything that verifies it.
336
+
337
+ `examples/device_login.rs`-style RFC 8628 device-code polling
338
+ (`axiam-sdk/node`'s `deviceLogin`/`deviceAuthorize`, CONTRACT.md §14) is a completely
339
+ different flow — a *human* completes it on a second screen. This is the machine-only mTLS
340
+ login; the two are unrelated beyond sharing the word "device".
341
+
198
342
  #### RFC 8705 §5 `mtls_endpoint_aliases` (contract 1.40, CONTRACT.md §21.3 rule 2)
199
343
 
200
344
  A TLS listener decides whether to ask for a client certificate during the handshake,
@@ -214,6 +358,7 @@ name wherever the document publishes one:
214
358
  | `revoke` | `revocation_endpoint` |
215
359
  | `deviceAuthorize` | `device_authorization_endpoint` |
216
360
  | `oidcPar` | `pushed_authorization_request_endpoint` |
361
+ | `cibaInitiate` | `backchannel_authentication_endpoint` |
217
362
 
218
363
  Three things this deliberately does **not** do:
219
364
 
@@ -221,8 +366,11 @@ Three things this deliberately does **not** do:
221
366
  terminates mutual TLS on the issuer's own host", so the conventional endpoints keep
222
367
  being used. A deployment running `client_auth = optional` on one listener serves both
223
368
  populations there and correctly publishes nothing.
224
- - **No alias is ever synthesised.** Only the six endpoints RFC 8705 §5 lists can be
225
- aliased — never `authorization_endpoint`, `end_session_endpoint` or `jwks_uri`. The
369
+ - **No alias is ever synthesised.** Only the seven endpoints CONTRACT.md §21.3.1's vector
370
+ aliases can be — `token_endpoint`, `introspection_endpoint`, `revocation_endpoint`,
371
+ `device_authorization_endpoint`, `pushed_authorization_request_endpoint`,
372
+ `userinfo_endpoint` and CIBA's `backchannel_authentication_endpoint` — never
373
+ `authorization_endpoint`, `end_session_endpoint` or `jwks_uri`. The
226
374
  first two are front-channel and the third is public key material; sending a browser to
227
375
  an mTLS host raises a native certificate-chooser dialog most users cannot answer.
228
376
  - **`issuer` does not move.** It is an identifier, not an endpoint. §12.4 rule 3 still
@@ -372,6 +520,42 @@ Calling `getUserInfo()` with no token present raises `AuthError` client-side, wi
372
520
  call (CONTRACT.md §1.1). A `UNAUTHENTICATED` response drives exactly one refresh + one retry,
373
521
  identical to `checkAccess`.
374
522
 
523
+ #### gRPC token validation (`TokenGrpcClient`, CONTRACT.md §1.1.1, §10.3, contract 1.51)
524
+
525
+ `validateToken`/`introspectToken` wrap `axiam.v1.TokenService`, the operations §10.3
526
+ requires so an SDK validating a token over gRPC has somewhere to read `cnf` from at all.
527
+ Same channel/interceptor/refresh machinery as `AuthzGrpcClient`/`UserInfoGrpcClient`:
528
+
529
+ ```typescript
530
+ import { TokenGrpcClient, createNodeSession } from 'axiam-sdk/grpc';
531
+ import { verifyTokenBinding } from 'axiam-sdk/node';
532
+
533
+ const session = createNodeSession({ baseUrl: 'https://iam.example.com', tenantSlug: 'acme' });
534
+ // ... after a successful login() on an AxiamClient sharing this session ...
535
+ const tokenClient = new TokenGrpcClient(session, { baseUrl: 'https://iam.example.com' });
536
+
537
+ const result = await tokenClient.validateToken(inspectedToken); // Sensitive<string> | string
538
+ if (result.valid) {
539
+ // §10.3 rule 2: valid: true is NOT "usable as presented" — verify possession
540
+ // against THIS caller's own connection before treating it as usable.
541
+ verifyTokenBinding({ cnf: result.cnf }, { certificateThumbprint: peerCertThumbprint });
542
+ }
543
+
544
+ tokenClient.close();
545
+ ```
546
+
547
+ - **Two tokens, kept apart.** The caller's own token authenticates the call, through the
548
+ interceptor, exactly as `checkAccess`/`getUserInfo` do. The token being inspected travels
549
+ in the request message and is a required argument — it can never silently fall back to
550
+ the caller's own.
551
+ - **`cnf` converts to the same `CnfClaim` the REST §10 middleware uses** —
552
+ `result.cnf`/`introspectToken`'s result feed directly into `verifyTokenBinding`/
553
+ `verifyCertificateBinding`, so gRPC validation and local REST verification cannot
554
+ disagree about whether a token is a bearer token (§10.3 rule 1).
555
+ - **Boundness comes from `cnf` alone, never `token_type`** — a certificate-bound token is
556
+ reported `"Bearer"` too.
557
+ - With no caller token, both calls raise `AuthError` client-side, with zero wire calls.
558
+
375
559
  ### Node — AMQP consumer (`axiam-sdk/amqp`)
376
560
 
377
561
  ```typescript
@@ -416,6 +600,16 @@ into production, where it turns TLS into an expensive no-op against precisely
416
600
  the attacker TLS exists to stop. `caCert` covers the legitimate reason people
417
601
  reach for one.
418
602
 
603
+ #### Minimal profile (contract 1.60, §8)
604
+
605
+ A server running in the **minimal profile** (`AXIAM__AMQP__ENABLED=false`) reads no AMQP
606
+ queue: it does not consume `axiam.authz.request` or `axiam.audit.events`, whatever a broker
607
+ holds. **A broker confirm is not evidence that AXIAM saw a message** — a publisher confirm, or
608
+ the broker's `basic.ack` of a publish, means only that the broker accepted it, never that
609
+ AXIAM decided the request or recorded the event. This SDK does not treat one as such. Against
610
+ a minimal-profile server use REST or gRPC; `GET /health` reports `profile: minimal` and lists
611
+ `amqp_authz` and `amqp_audit_ingestion` under `unavailable`.
612
+
419
613
  ### Node — reactors, AMQP extension actors (`axiam-sdk/amqp`, CONTRACT.md §22)
420
614
 
421
615
  A **reactor** is an external process that subscribes to named hook events on the AMQP bus and
@@ -1340,6 +1534,55 @@ produces a `403` — so a UI that offers the switch to everyone has turned a
1340
1534
  distinction the server made into a failure the user discovers. `false` against a
1341
1535
  server older than contract 1.31, which is the safe reading of absent.
1342
1536
 
1537
+ #### Acting on another tenant (§5.2 rule 1, contract 1.51)
1538
+
1539
+ An organization-level principal switches which tenant it acts on with
1540
+ `client.actingTenant(tenantId)` — no re-login, since it already is a principal
1541
+ of every tenant in its organization:
1542
+
1543
+ ```ts
1544
+ const acting = client.actingTenant('99999999-9999-4999-8999-999999999999');
1545
+ await acting.management.groups.list(); // carries X-Axiam-Tenant
1546
+ await client.management.groups.list(); // unaffected — the original handle
1547
+ ```
1548
+
1549
+ `actingTenant()` returns a **new handle** over the same session (§9's refresh
1550
+ guard, §17's decision memo, the cookie jar all stay shared); `client` itself is
1551
+ unchanged. That is what lets a provisioning task hold one login result while
1552
+ acting on several tenants concurrently, without two calls racing to rewrite one
1553
+ shared header. `client.clearActingTenant()` returns a handle that sends none —
1554
+ the inverse. The same option is available at construction,
1555
+ `new AxiamClient({ ..., actingTenantId })`, for a client built to act on another
1556
+ tenant from the start; the construction-time form cannot gate on
1557
+ `organizationLevel` (it precedes the login that would reveal it), so `403` from
1558
+ the server is the answer there.
1559
+
1560
+ `tenantId` must be a UUID — checked client-side, with no wire call, because the
1561
+ server silently ignores a value that fails to parse and answers for the
1562
+ caller's own tenant. Once a login result is held, `actingTenant()` also refuses
1563
+ client-side (`AuthzError`, zero wire calls) for a non-organization-level
1564
+ principal, and for a tenant outside `reachableTenantIds` when the login
1565
+ response narrowed it (§5.2.3) — compared as UUIDs (case- and
1566
+ formatting-insensitive), never as raw strings, so an upper-case `tenantId`
1567
+ still matches a `reachableTenantIds` entry the server reported in its own
1568
+ lower-case canonical form. A login result is held after `login`,
1569
+ `verifyMfa`, OPAQUE login and the MFA and WebAuthn setup completions, whose
1570
+ responses carry the user object. A WebAuthn authentication, any SSO/federation
1571
+ completion (`ssoComplete`, `ssoCompleteOauth2`, `ssoCompleteHandoff`) or the
1572
+ device login resets it, so the header is sent and the server decides.
1573
+
1574
+ `client.logout()` does **not** clear an acting tenant a handle was built with —
1575
+ the handle's `#actingTenantId` is untouched, so a handle returned by
1576
+ `client.actingTenant(id)` still sends `X-Axiam-Tenant: id` on any call made
1577
+ through it after `logout()`, and the server's session-based rejection (no
1578
+ session, no wire call — §27.4 rule 1) is what stops the request, not this
1579
+ header. Only `clearActingTenant()` (or building a fresh handle) removes it.
1580
+
1581
+ **REST-only.** The gRPC interceptor reads no acting-tenant metadata — a gRPC
1582
+ call through any handle still acts on the token's own tenant. `X-Tenant-ID` and
1583
+ a management route's `{tenant_id}` path default (§27.4 rule 3) are unaffected
1584
+ either way; the acting tenant is a different mechanism from both.
1585
+
1343
1586
  #### Signing one in (§5.2.1)
1344
1587
 
1345
1588
  The reserved tenant has a fixed slug, `organization`, the same in every
@@ -1431,9 +1674,13 @@ RFC 8693 — a service holding a user's token exchanging it for a *narrower* one
1431
1674
  calling the next service.
1432
1675
 
1433
1676
  ```ts
1677
+ // Delegation: the actor token is THIS client's own client_credentials token (§15.2 rule 9).
1678
+ const actor = await oidc.loginClientCredentials();
1679
+
1434
1680
  const exchanged = await oidc.tokenExchange({
1435
1681
  subjectToken: new Sensitive(userToken),
1436
1682
  subjectTokenType: ACCESS_TOKEN_TYPE, // required (§15.1), no default
1683
+ actorToken: actor.accessToken, // omit it and you ask for impersonation instead
1437
1684
  scopes: ['orders:read'],
1438
1685
  audience: 'orders-service',
1439
1686
  });
@@ -1443,6 +1690,14 @@ Most of what this method does is refuse to be helpful, and each refusal is delib
1443
1690
 
1444
1691
  - **No default `actorToken`.** Omitting it asks for *impersonation*; the SDK will not
1445
1692
  quietly substitute the client's own session token and turn that into a delegation.
1693
+ - **The actor token must have been issued to the exchanging client** (contract 1.60,
1694
+ §15.2 rule 9). The usual actor is the exchanging client's own `client_credentials` token
1695
+ (`loginClientCredentials()` above): its `sub` — and so the issued token's `act.sub` — is
1696
+ the client's `client_id`. One issued to another client, a console sign-in or a service
1697
+ account is answered `400 invalid_request` (`actor_token was not issued to the exchanging
1698
+ client`), which the SDK surfaces unchanged: no retry, no dropping the actor token to
1699
+ impersonate instead, no substituting a token of its own. You obtain and pass the actor
1700
+ token; the SDK supplies none.
1446
1701
  - **No auto-narrowing after `invalid_scope`.** The server refuses rather than silently
1447
1702
  narrowing precisely so the caller finds out here.
1448
1703
  - **No refresh token, ever** — `ExchangedToken` has no such field, so there is nothing to
@@ -1925,6 +2180,219 @@ just failed to authenticate, so both must stay readable. The corollary is the on
1925
2180
  matters — **no part of the presented credential reaches either of them**, in any parameter,
1926
2181
  any header, any body or any log line the guard writes on the 401 path.
1927
2182
 
2183
+ ## RFC 7592 client configuration (contract 1.53, §28.12)
2184
+
2185
+ A client that registered itself through `POST /oauth2/register` (RFC 7591) received, once,
2186
+ a `registration_client_uri` and a `registration_access_token`. With them it reads, replaces
2187
+ and deletes **its own** registration:
2188
+
2189
+ ```ts
2190
+ const token = new Sensitive(storedRegistrationToken);
2191
+ const current = await client.readClientRegistration(registrationClientUri, token);
2192
+
2193
+ // An update is a FULL replacement: start from the read, change what you mean.
2194
+ current.client_name = 'Agent v2';
2195
+ const updated = await client.updateClientRegistration(registrationClientUri, token, current);
2196
+ await persist(updated.registration_access_token!); // the ONLY valid token from now on
2197
+
2198
+ await client.deleteClientRegistration(registrationClientUri, updated.registration_access_token!);
2199
+ ```
2200
+
2201
+ - The URI is used **verbatim** (its `tenant_id` query included), and only at this client's
2202
+ configured origin: another scheme, host or port — or `http` unless `baseUrl` is `http` on a
2203
+ loopback host — is refused locally with a `ValidationError` before any request.
2204
+ - The token travels in `Authorization: Bearer` only, on a session-free transport: no SDK
2205
+ cookie, access token or CSRF header rides along, redirects are not followed, and a `401`
2206
+ never refreshes the SDK's session. (A browser follows redirects itself; use these
2207
+ server-side.)
2208
+ - `ClientRegistration` keeps every member it does not model in `extra`, so a read passed to
2209
+ an update round-trips them; the SDK drops `registration_access_token`,
2210
+ `registration_client_uri`, `client_secret_expires_at`, `client_id_issued_at` and
2211
+ `client_secret` from the body and sets `client_id`. Both secrets are `Sensitive`.
2212
+ - **Update and delete are never retried**; persist the rotated token before anything else.
2213
+ The read follows §16, but never retries a `4xx` other than `408`/`429`.
2214
+ - A body with `error` is an `OAuthProtocolError` at any status (`invalid_token`,
2215
+ `invalid_client_metadata`, …); a `204` on delete resolves.
2216
+
2217
+ ## Directory, SAML, SSF and SCIM targets (§29 – §32)
2218
+
2219
+ Four management namespaces, generated like every other (§27), with the call-site rules the
2220
+ contract makes an SDK repeat in their TSDoc. Every write is issued once; reads retry.
2221
+
2222
+ ```ts
2223
+ import { Sensitive, setDirectoryConfigFrom, parseSpMetadataFromUrl,
2224
+ samlServiceProviderInputFrom, ssfStreamInputFrom, scimTargetInputFrom } from 'axiam-sdk';
2225
+
2226
+ // §30 directory — a sparse update: undefined keeps, null CLEARS.
2227
+ await client.directory.update({ group_filter: null }); // sends {"group_filter":null}
2228
+ await client.directory.update({ enabled: false }); // sends {"enabled":false}
2229
+ // Moving the connection (url, start_tls, bind_dn, trust_anchors_pem) requires the secret
2230
+ // again — the SDK holds no copy (§30.3 rule 2).
2231
+ await client.directory.update({ url: 'ldaps://dc2.corp.example', bind_secret: new Sensitive(secret) });
2232
+ // set() is a replacement: start from a read (bind_secret absent keeps the stored one).
2233
+ const config = setDirectoryConfigFrom(await client.directory.get());
2234
+ await client.directory.set({ ...config, sync_interval_secs: 900 });
2235
+
2236
+ // §29 SAML — parse a draft (stores nothing), review it, create from it.
2237
+ const draft = await client.saml.parseSpMetadata(parseSpMetadataFromUrl('https://sp.example/metadata'));
2238
+ const sp = await client.saml.createServiceProvider(draft.service_provider);
2239
+ const body = samlServiceProviderInputFrom(await client.saml.getServiceProvider(sp.id));
2240
+ await client.saml.updateServiceProvider(sp.id, { ...body, display_name: 'Payroll (EU)' });
2241
+
2242
+ // §32 SSF and §31 SCIM targets — read-modify-write; the secret is left absent (kept).
2243
+ const stream = ssfStreamInputFrom(await client.ssf.getStream(streamId));
2244
+ await client.ssf.updateStream(streamId, { ...stream, description: 'rotated' });
2245
+ const target = scimTargetInputFrom(await client.scimTargets.get(targetId));
2246
+ await client.scimTargets.update(targetId, { ...target, push_groups: true });
2247
+ ```
2248
+
2249
+ - `bind_secret`, `authorization_header` and `credential` are `Sensitive` and write-only. A
2250
+ response that (wrongly) carries one of them — or `private_key_pem` on a SAML credential —
2251
+ has it dropped before it reaches you, so it surfaces in no rendering.
2252
+ - `parseSpMetadata` needs **exactly one** of `metadata_url` / `metadata_xml`: both or
2253
+ neither is a local `ValidationError`.
2254
+ - Enums and the `ScimTargetAuth` / `ScimTargetScope` unions are open: an unknown value
2255
+ decodes. An unknown `auth.type` / `scope.type` is refused before it is sent back.
2256
+ - `getIdp` is never cached: readiness changes with every credential write.
2257
+
2258
+ ## SSF receiver (`axiam-sdk/node`, contract 1.56, §32.7)
2259
+
2260
+ For a relying party that **receives** AXIAM's Security Event Tokens. Node-only.
2261
+
2262
+ ```ts
2263
+ import { SsfReceiver, SetRefusedError, setErrFromReason, createOidcClient } from 'axiam-sdk/node';
2264
+
2265
+ const receiver = new SsfReceiver(client, {
2266
+ issuer: 'https://iam.example.com/t/<tenant-uuid>',
2267
+ audience: 'https://rp.example.com',
2268
+ jwksUri: 'https://iam.example.com/oauth2/jwks', // or discoveryUrl
2269
+ accessTokenProvider: async () =>
2270
+ (await oidc.loginClientCredentials({ scope: 'ssf.manage' })).accessToken,
2271
+ // replayWindowMs defaults to (and may not go below) seven days; replayStore is pluggable.
2272
+ });
2273
+
2274
+ // Push (RFC 8935): verify, then answer 202 — or 400 {"err": …} on a refusal.
2275
+ try {
2276
+ handle(await receiver.verifySet(rawBody));
2277
+ res.status(202).end();
2278
+ } catch (e) {
2279
+ if (e instanceof SetRefusedError) res.status(400).json(setErrFromReason(e.reason));
2280
+ else throw e; // a NetworkError: the JWKS could not be fetched — not a verdict on the SET
2281
+ }
2282
+
2283
+ // Poll (RFC 8936): acknowledge what you processed, refuse what failed, on the NEXT call.
2284
+ let ack: string[] = [];
2285
+ let setErrs = {};
2286
+ for (;;) {
2287
+ const { events, refused, moreAvailable } = await receiver.poll(streamId, { ack, setErrs });
2288
+ for (const event of events) await handle(event);
2289
+ // A `replayed` SET was accepted earlier: acknowledge it, do not report it (§34.2 P2).
2290
+ ack = [...events.map((e) => e.jti), ...refused.filter((r) => r.reason === 'replayed').map((r) => r.jti)];
2291
+ setErrs = Object.fromEntries(
2292
+ refused.filter((r) => r.reason !== 'replayed').map((r) => [r.jti, setErrFromReason(r.reason)]),
2293
+ );
2294
+ // `unjudged` SETs are neither: the transmitter offers them again.
2295
+ if (!moreAvailable) await sleep(1000);
2296
+ }
2297
+ ```
2298
+
2299
+ `verifySet` checks, in order: three base64url parts, `typ` `secevent+jwt`, `alg` `EdDSA`, the
2300
+ `kid` in the configured JWKS (one forced refetch on a miss, at most once a minute), the
2301
+ signature, `iss`, `aud`, the SET claim rules (no `exp`/`sub`; `jti`, `iat`, `sub_id`; one
2302
+ event) and replay. A refusal is a `SetRefusedError` (an `AuthError`) with a typed `reason`;
2303
+ `pushErrorCode` maps `malformed`, `invalid_type` and `replayed` to `invalid_request`, the
2304
+ others to themselves. **A SET that verifies has been recorded**: acknowledge it once
2305
+ processed, or a re-offer reads as `replayed`. **`poll` never keeps a `jti` it does not
2306
+ return** (contract 1.59, §34.2 P1): a SET it cannot judge — the JWKS or discovery fetch
2307
+ failed, or the replay store threw — is left unrecorded and listed by `jti` in `unjudged`
2308
+ (neither acknowledge nor refuse it; the transmitter offers it again), while the SETs judged
2309
+ in the same batch are returned as usual. When a poll accepts no SET at all it records
2310
+ nothing and throws that failure instead. Once the replay store fails in a batch it is not
2311
+ asked again for that batch: every later SET that verifies is unjudged as well, and `poll`
2312
+ emits the §19 `ssfUnjudged` telemetry event when it returns with any SET unjudged
2313
+ (contract 1.60). The default `MemoryReplayStore` is per process and
2314
+ **unbounded in count** — an entry leaves only when its window expires (§34.2 P4); a
2315
+ `ReplayStore` has three answers — `true` (not seen, now recorded), `false` (seen) and
2316
+ **cannot answer**, which is a throw or a rejection (contract 1.60, §34.2 P4). A store that
2317
+ cannot answer gives **no verdict**: `verifySet` raises a `NetworkError` with no reason code
2318
+ (it is never a `SetRefusedError`, and never read as `replayed`, which `poll` would have you
2319
+ acknowledge), and `poll` lists the SET in `unjudged`, records nothing for it and does not
2320
+ acknowledge it, so the transmitter offers it again. Never answer `false` for "I do not know";
2321
+ an answer that is neither `true` nor `false` is treated as cannot-answer. The key set is
2322
+ cached for ten minutes (`JWKS_CACHE_MAX_AGE_MS`; contract 1.60 requires no more than ten), so a key
2323
+ the transmitter removed stops verifying; filling an empty or expired cache is not a refetch,
2324
+ but a **failed** fetch counts toward the once-a-minute limit: after a failed fill a SET inside
2325
+ the minute makes no fetch and is left unjudged (§34.2 P6). A SET refused as `replayed` was accepted by this
2326
+ receiver on an earlier poll: acknowledge it in `ack` rather than reporting it in `setErrs`
2327
+ (§34.2 P2). `poll` never acknowledges anything itself, is not retried on a `4xx` other than
2328
+ `408` and `429` — which §16 retries, as it does a transport failure and a `5xx` — and sends
2329
+ no SDK cookie or session token.
2330
+
2331
+ ## CIBA (`axiam-sdk/node`, contract 1.58, §33)
2332
+
2333
+ Client-initiated backchannel authentication: ask AXIAM to authenticate a user **on another
2334
+ device**, then collect the tokens. On `OidcClient`; the client always authenticates, by
2335
+ `clientSecret` or a §6.1 client certificate.
2336
+
2337
+ ```ts
2338
+ import { createOidcClient, isAccessDenied, isExpiredToken, CibaRequestSigner } from 'axiam-sdk/node';
2339
+
2340
+ // Poll mode.
2341
+ const initiated = await oidc.cibaInitiate({
2342
+ scope: 'openid profile',
2343
+ loginHint: 'ada@example.com', // exactly one of loginHint / idTokenHint
2344
+ bindingMessage: 'W4SCT', // show the same code to your user
2345
+ });
2346
+ try {
2347
+ const tokens = await oidc.cibaAwait(initiated); // honours interval and slow_down; stops at expires_in
2348
+ } catch (e) {
2349
+ if (isAccessDenied(e)) { /* the user refused */ }
2350
+ else if (isExpiredToken(e)) { /* nobody answered in time */ }
2351
+ else throw e;
2352
+ }
2353
+ ```
2354
+
2355
+ **Ping mode** — AXIAM calls your notification endpoint; answer at once, then poll once:
2356
+
2357
+ ```ts
2358
+ const notificationToken = new Sensitive(randomBytes(32).toString('base64url'));
2359
+ const initiated = await oidc.cibaInitiate({
2360
+ scope: 'openid', loginHint: 'ada', delivery: { mode: 'ping', clientNotificationToken: notificationToken },
2361
+ });
2362
+
2363
+ app.post('/ciba/notify', express.raw({ type: '*/*' }), async (req, res) => {
2364
+ let authReqId;
2365
+ try {
2366
+ authReqId = oidc.cibaHandlePing(req.rawHeaders, req.body, notificationToken); // no I/O
2367
+ } catch {
2368
+ return res.status(401).end();
2369
+ }
2370
+ res.status(204).end(); // answer first: AXIAM retries a slow ping
2371
+ const tokens = await oidc.cibaPoll({ authReqId }); // the outcome: tokens, access_denied, expired_token
2372
+ });
2373
+ // No ping after expires_in / 2? Fall back to oidc.cibaAwait(initiated).
2374
+ ```
2375
+
2376
+ **Signed form** (a client registered with `backchannel_authentication_request_signing_alg`;
2377
+ required of a `fapi2` CIBA client):
2378
+
2379
+ ```ts
2380
+ const signer = await CibaRequestSigner.create('EdDSA', new Sensitive(privateKeyPkcs8Pem), 'key-1');
2381
+ await oidc.cibaInitiate({ scope: 'openid', loginHint: 'ada', bindingMessage: 'W4SCT', signer });
2382
+ // The form carries client authentication and `request` only; every member is inside the JWT.
2383
+ ```
2384
+
2385
+ - `cibaInitiate` is **never retried** — each accepted call may notify a person. A success
2386
+ proves nothing about the user: AXIAM answers an unknown, locked and real user alike.
2387
+ - `cibaPoll` surfaces every protocol answer as an `OAuthProtocolError` and retries only
2388
+ transport failures, `408`, a bodiless `429` and a `5xx` — whatever its body, so the server's
2389
+ own `500 {"error":"server_error"}` is retried and never ends `cibaAwait` (§34.2 P8). Store its tokens before anything else:
2390
+ a request is redeemed once. Neither helper adopts the tokens as the client's credential.
2391
+ - `authReqId`, `clientNotificationToken`, the signing key and the `request` JWT are
2392
+ `Sensitive` / never rendered. `CibaRequestSigner` supports PS256, ES256 and EdDSA, signs
2393
+ under exactly the algorithm given, and refuses a key that cannot (a probe signature).
2394
+ - `cibaAwait` takes an injectable `clock` (`{ now(), sleep(ms) }`) for tests.
2395
+
1928
2396
  ## Client quality-of-life (CONTRACT.md §16–§19)
1929
2397
 
1930
2398
  ### Retry policy (§16)
@@ -1987,7 +2455,9 @@ const client = new AxiamClient({
1987
2455
  - **Path templates, not URLs**, so a metric label cannot become a cardinality bomb.
1988
2456
 
1989
2457
  One `requestStart`/`requestEnd` pair is emitted **per attempt**, so you can count real wire
1990
- calls. See [`examples/telemetry-hook.ts`](examples/telemetry-hook.ts), including the
2458
+ calls. `SsfReceiver.poll` also emits `ssfUnjudged` when it returns leaving SETs unjudged
2459
+ (contract 1.60), one per failure category with a count, so an outage it cannot raise is
2460
+ still visible. See [`examples/telemetry-hook.ts`](examples/telemetry-hook.ts), including the
1991
2461
  OpenTelemetry mapping.
1992
2462
 
1993
2463
  ### Decision memo (§17) — opt-in, off by default
@@ -2022,7 +2492,7 @@ entries are keyed by subject rather than by session.
2022
2492
  Everything above assumes a populated tenant. `login` signs a user in,
2023
2493
  `checkAccess` asks about a resource, `verifyWebhook` checks a delivery signature — and
2024
2494
  none of them can create the user, declare the resource or register the webhook. The
2025
- management surface is the part that can: **160 operations across 24 namespaces**,
2495
+ management surface is the part that can: **190 operations across 28 namespaces**,
2026
2496
  generated from `management-registry.json`, which is the whole server API minus what other
2027
2497
  contract sections own and minus organization creation and deletion (§27.0 keeps those out
2028
2498
  of reach of a client library on purpose).
@@ -2035,8 +2505,8 @@ const role = await client.roles.get(roleId);
2035
2505
  await client.roles.assignToUser(roleId, { user_id: userId });
2036
2506
  ```
2037
2507
 
2038
- Operations hang off **namespace handles** rather than the client. Twenty namespaces have a
2039
- `list` and fourteen a `get`, so flattening them would need a disambiguating prefix invented
2508
+ Operations hang off **namespace handles** rather than the client. Nineteen namespaces have a
2509
+ `list` and nineteen a `get`, so flattening them would need a disambiguating prefix invented
2040
2510
  once per operation — and would bury the eight §1 methods most callers want under five times
2041
2511
  as many they do not. Acquiring a handle performs no I/O. `client.management.users` is the
2042
2512
  same handle as `client.users`, for call sites that read better with the namespace spelled
@@ -2133,7 +2603,7 @@ back.
2133
2603
 
2134
2604
  ### Declarative manifests (§27.6, §27.7)
2135
2605
 
2136
- Calling 160 operations one at a time is rarely what an application wants. What it does at
2606
+ Calling 190 operations one at a time is rarely what an application wants. What it does at
2137
2607
  start-up, in a migration, or in a test fixture is assert a shape:
2138
2608
 
2139
2609
  ```ts
@@ -2176,6 +2646,53 @@ actions that would reconcile the tenant.
2176
2646
  which, execution stops rather than continuing blindly, and there is no `rollback` —
2177
2647
  because this SDK could not honour one.
2178
2648
 
2649
+ #### Metadata, resource-scoped bindings, and service accounts (§27.6.1, contract 1.51)
2650
+
2651
+ ```ts
2652
+ const desired = defineManifest({
2653
+ resources: [
2654
+ { key: 'site1', name: 'site-1', resourceType: 'site', metadata: { owner: 'ops' } },
2655
+ ],
2656
+ roles: [{ key: 'concierge', name: 'Concierge', description: 'Concierge' }],
2657
+ users: [
2658
+ {
2659
+ key: 'ann', username: 'ann', email: 'ann@example.com',
2660
+ initialPassword: new Sensitive(pw),
2661
+ // A role key is still plain — this keeps compiling and meaning what it
2662
+ // always meant. The scoped shape is a resource-scoped object instead.
2663
+ roles: [{ role: 'concierge', resource: 'site1', inherit: false }],
2664
+ },
2665
+ ],
2666
+ serviceAccounts: [
2667
+ { key: 'fleet', name: 'device-fleet', roles: ['concierge'] },
2668
+ ],
2669
+ });
2670
+
2671
+ const report = await client.manifest.apply(desired);
2672
+ const created = report.steps.find((s) => s.action.target === 'service-account')!;
2673
+ if (created.outcome.status === 'created' && created.outcome.serviceAccountSecret) {
2674
+ // The ONLY place this manifest ever surfaces a service account's secret —
2675
+ // apply() never rotates one to reconcile anything. Store it now.
2676
+ saveSecret(created.outcome.serviceAccountSecret.expose());
2677
+ }
2678
+ ```
2679
+
2680
+ - **`resources[].metadata`** drifts by JSON equality of the whole object, independent of
2681
+ key order, never a key-by-key merge; an unstated `metadata` is silent, and a stated
2682
+ `{}` matches what the server holds for none.
2683
+ - **A role binding takes either shape** — a plain key (as before 1.51) or
2684
+ `{ role, resource?, inherit? }`. `inherit` reaches the wire only as `false`. Changing a
2685
+ binding's resource or `inherit` is `unassign` then `assign` (there is no update
2686
+ endpoint); the server's existing `tenant_scope` carries across unchanged, and a failed
2687
+ re-assign restores the previous binding, reporting both outcomes as a `'rebind-failed'`
2688
+ step. One role bound twice to one subject — plain and scoped combined — is refused
2689
+ before any request; so is a global role bound here with `inherit: false`.
2690
+ - **`serviceAccounts`** reconciles by `name`, which the server does not enforce as unique —
2691
+ `plan()` fails client-side, before any write, if more than one existing account matches.
2692
+ Only `description` is reconciled by `Update`.
2693
+ - **Declines.** `webhooks` is not a manifest namespace in this SDK — the contract names it
2694
+ without specifying it, and no consumer has asked for it.
2695
+
2179
2696
  Codebases that already declare their domain with classes get decorators instead:
2180
2697
 
2181
2698
  ```ts
@@ -2194,6 +2711,8 @@ TypeScript has two decorator dialects and this SDK's own `tsconfig.json` deliber
2194
2711
  enables neither — so these are dual-protocol plain functions that work under both, and
2195
2712
  under neither: `AxiamResource(spec)(Documents)` is exactly what the `@` syntax desugars to.
2196
2713
 
2714
+ `@AxiamServiceAccount({ key, name, roles })` (contract 1.51) joins the set the same way.
2715
+
2197
2716
  ### Examples
2198
2717
 
2199
2718
  - [`examples/management-basics.ts`](examples/management-basics.ts) — the imperative surface