axiam-sdk 1.0.0-alpha25 → 1.0.0-alpha28

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.
package/README.md CHANGED
@@ -221,14 +221,43 @@ import { consume, Sensitive } from 'axiam-sdk/amqp';
221
221
 
222
222
  const signingKey = new Sensitive(Buffer.from(process.env.AXIAM_AMQP_SIGNING_KEY ?? '', 'hex'));
223
223
 
224
- await consume('amqp://localhost:5672', 'axiam.audit.events', signingKey, async (event) => {
225
- // Only a verified event ever reaches this closure — HMAC-SHA256
226
- // signature checked and stripped by the SDK before your handler runs
227
- // (CONTRACT.md §8). Verification failures are nacked-without-requeue.
228
- console.log('verified audit event:', event);
229
- });
224
+ await consume(
225
+ // §8b: amqps:// only, enforced — a plaintext URL is refused before a socket
226
+ // opens, and there is no fallback for it to take.
227
+ 'amqps://localhost:5671',
228
+ 'axiam.audit.events',
229
+ signingKey,
230
+ async (event) => {
231
+ // Only a verified event ever reaches this closure — HMAC-SHA256
232
+ // signature checked and stripped by the SDK before your handler runs
233
+ // (CONTRACT.md §8). Verification failures are nacked-without-requeue.
234
+ console.log('verified audit event:', event);
235
+ },
236
+ // Optional. The PEM bundle for a privately issued broker certificate — the
237
+ // common in-cluster case (§8b rule 2), and the only TLS knob this SDK has.
238
+ { tls: { caCert: readFileSync('/etc/axiam/broker-ca.pem', 'utf8') } },
239
+ );
230
240
  ```
231
241
 
242
+ #### Transport security (§8b)
243
+
244
+ `consume()` and `reactorServe()` both require `amqps://` and enforce it before
245
+ any socket is opened. HMAC signing (§8) gives authenticity and replay
246
+ protection across broker hops; TLS gives confidentiality. Both are required and
247
+ neither substitutes for the other — a signed `AuthzRequest` still names its
248
+ subject, resource and action in cleartext on an unencrypted wire.
249
+
250
+ | Option | Meaning |
251
+ |---|---|
252
+ | `tls.caCert` | PEM bundle for a privately issued broker certificate. Omit for a publicly issued one (Node's bundled roots verify it). |
253
+ | `tls.clientCert` + `tls.clientKey` | Mutual TLS toward the broker. All-or-nothing: half an identity is rejected before dialling. |
254
+
255
+ There is deliberately no verification-skip option, under any name (§8b rule 4).
256
+ A switch like that appears in a dev compose file, works, and travels unchanged
257
+ into production, where it turns TLS into an expensive no-op against precisely
258
+ the attacker TLS exists to stop. `caCert` covers the legitimate reason people
259
+ reach for one.
260
+
232
261
  ### Node — reactors, AMQP extension actors (`axiam-sdk/amqp`, CONTRACT.md §22)
233
262
 
234
263
  A **reactor** is an external process that subscribes to named hook events on the AMQP bus and
@@ -266,6 +295,42 @@ await reactorServe(
266
295
  );
267
296
  ```
268
297
 
298
+ #### Binding handlers per event (§22.14)
299
+
300
+ The `switch` above is the shape every multi-event reactor grows, and its `default:` arm —
301
+ `return allow()` — answers on behalf of code that never ran. That is the defect §22.10
302
+ rule 2 forbids the *runtime* from committing, relocated into your file where the rule does
303
+ not reach it: an operator who set `fail_closed` on the registration has it defeated there.
304
+
305
+ `reactorHandlers` is §22.14's declarative form, in the spirit of the §11 declarative
306
+ authorization helpers:
307
+
308
+ ```typescript
309
+ import { REACTOR_EVENTS, reactorHandlers, reactorServe } from 'axiam-sdk/amqp';
310
+
311
+ await reactorServe(
312
+ options,
313
+ reactorHandlers({
314
+ [REACTOR_EVENTS.TOKEN_PRE_ISSUE]: (event) => mutate({ 'ext.cost_center': '42' }),
315
+ [REACTOR_EVENTS.LOGIN_POST_AUTH]: async (event) => deny('embargoed region'),
316
+ }),
317
+ );
318
+ ```
319
+
320
+ - **A misspelled event is a compile error**, because the map's key type is
321
+ `ReactorEventName` — and it is re-checked at runtime for JavaScript callers, who get no
322
+ such help. That runtime check is also how the three hot-path operations §22.7 excludes are
323
+ refused: they are in no registry row.
324
+ - **An unbound event abstains** — no reply, and the registration's `failure_policy` decides
325
+ (§22.8), exactly as it decides a timeout. Never a synthesized `allow`.
326
+ - Several maps may be passed (`reactorHandlers(tokenHandlers, loginHandlers)`) so handlers
327
+ can be split across modules; binding the same event twice throws rather than silently
328
+ overwriting.
329
+
330
+ It is pure sugar: the value it produces is exactly the `ReactorHandler` `reactorServe`
331
+ already takes. It opens nothing, verifies nothing, signs nothing, does not filter a patch,
332
+ and a handler's own rejection reaches the runtime unchanged so nothing is published.
333
+
269
334
  See [`examples/reactor/index.ts`](examples/reactor/index.ts) for a complete three-hook reactor
270
335
  with graceful shutdown and a telemetry hook.
271
336
 
@@ -1,5 +1,6 @@
1
1
  import { S as Sensitive } from '../sensitive-BC_s7Rrd.cjs';
2
2
  import { ConsumeMessage } from 'amqplib';
3
+ import { ConnectionOptions } from 'node:tls';
3
4
  import { T as TelemetryHook, a as TelemetryDispatcher } from '../telemetry-DrGqL4kb.cjs';
4
5
 
5
6
  /**
@@ -142,6 +143,94 @@ interface NotificationEvent {
142
143
  declare const HMAC_SIGNED_MESSAGE_TYPES: readonly ["AuthzRequest", "AuditEventMessage"];
143
144
  type HmacSignedMessageType = (typeof HMAC_SIGNED_MESSAGE_TYPES)[number];
144
145
 
146
+ /**
147
+ * TLS material for an `amqps://` broker connection (§8b).
148
+ *
149
+ * Every field is optional: with none set, an `amqps://` URL still connects and
150
+ * still verifies, against Node's bundled root store. The fields exist for the
151
+ * two cases that store cannot serve — a privately-issued broker certificate,
152
+ * and mutual TLS toward the broker.
153
+ *
154
+ * # There is deliberately no verification-skip option
155
+ *
156
+ * Not as an omission to be filled in later. §8b rule 4 forbids surfacing one
157
+ * under any name, and the reasoning is that such a switch is the single most
158
+ * reliably misused option in TLS: it appears in a dev compose file, it works,
159
+ * and it travels unchanged into production, where it turns TLS into an
160
+ * expensive no-op against precisely the attacker TLS exists to stop.
161
+ * {@link caCert} covers the legitimate reason people reach for it (rule 2)
162
+ * without covering the rest.
163
+ *
164
+ * This paragraph names no concrete bypass flag, and that is not squeamishness:
165
+ * CI greps `src/` for the literal disabling forms and fails the build on a hit.
166
+ * A comment explaining why the SDK does not do the thing would trip the same
167
+ * grep as code doing it — the check cannot tell prose from an assignment — so
168
+ * the prose stays abstract and the check stays blunt. Both are better that way.
169
+ *
170
+ * `amqplib` would happily accept `rejectUnauthorized` in its socket options,
171
+ * which is exactly why {@link buildAmqpConnectOptions} constructs that object
172
+ * itself from these three fields rather than accepting a caller-supplied one.
173
+ */
174
+ interface AmqpTlsOptions {
175
+ /**
176
+ * PEM bundle of the CA(s) that issued the broker's certificate (§8b rule 2).
177
+ *
178
+ * Unset = verify against Node's bundled roots. Set this when the broker
179
+ * certificate comes from a private CA — including one issued by AXIAM's own
180
+ * organization CA, which is the recommended dogfooding path.
181
+ *
182
+ * Unlike the server's own `AXIAM__AMQP__TLS__CA_CERT_PATH`, this **replaces**
183
+ * the trust set rather than adding to it: Node's `tls.connect` treats `ca` as
184
+ * the complete root list. Supplying your broker's CA here therefore does
185
+ * narrow trust to it, which is usually what someone setting this actually
186
+ * wants.
187
+ */
188
+ readonly caCert?: string;
189
+ /**
190
+ * PEM client certificate chain, for mutual TLS toward the broker (§8b
191
+ * rule 3).
192
+ *
193
+ * Must be supplied together with {@link clientKey}. Half a client identity is
194
+ * never what anyone meant, and connecting anyway would silently drop the
195
+ * mutual half of mutual TLS — so it is rejected before dialling.
196
+ */
197
+ readonly clientCert?: string;
198
+ /** PEM private key matching {@link clientCert}. Secret material (§7). */
199
+ readonly clientKey?: string;
200
+ }
201
+ /**
202
+ * Reject any broker URL that is not `amqps://` (§8b rules 1 and 5).
203
+ *
204
+ * A plaintext URL is refused here rather than downgraded, and there is no
205
+ * fallback path for it to take — rule 5 exists because a fallback that works
206
+ * is a fallback that gets used, and the failure it produces is invisible
207
+ * exactly when it matters.
208
+ *
209
+ * The `://` separator is load-bearing: matching on `amqps` alone would let a
210
+ * hypothetical `amqpsomething://` through.
211
+ *
212
+ * @throws {NetworkError} when `url` is not an `amqps://` URL.
213
+ */
214
+ declare function assertAmqpsUrl(url: string, what?: string): void;
215
+ /**
216
+ * Validate `url` and build the socket options `amqplib.connect` should dial
217
+ * with (§8b).
218
+ *
219
+ * `amqplib` forwards its second argument to `tls.connect` for an `amqps://`
220
+ * URL, so the returned object is a `tls.ConnectionOptions` carrying at most
221
+ * `ca`, `cert` and `key`. It never carries `rejectUnauthorized`, which leaves
222
+ * Node's strict default (`true`) in force — see {@link AmqpTlsOptions}.
223
+ *
224
+ * The certificate/key pairing is validated by `resolveClientIdentity`, the same
225
+ * §6.1 helper the REST and gRPC transports use, so mutual TLS is validated
226
+ * identically on every transport this SDK speaks rather than once per protocol.
227
+ *
228
+ * @throws {NetworkError} when `url` is not `amqps://`.
229
+ * @throws {Error} when the TLS material is internally inconsistent (a client
230
+ * certificate without its key, or PEM that is not PEM).
231
+ */
232
+ declare function buildAmqpConnectOptions(url: string, tls?: AmqpTlsOptions, what?: string): ConnectionOptions | undefined;
233
+
145
234
  /**
146
235
  * Default freshness skew for `issued_at` acceptance (NEW-4): a message is
147
236
  * accepted only when its `issued_at` lies within ±5 minutes of the
@@ -215,6 +304,16 @@ interface ConsumeOptions {
215
304
  * must pass the same store explicitly for dedup to take effect.
216
305
  */
217
306
  nonceStore?: NonceStore;
307
+ /**
308
+ * TLS material for the `amqps://` broker connection (CONTRACT.md §8b).
309
+ *
310
+ * Optional, and omitting it does not weaken anything: the URL must be
311
+ * `amqps://` either way, and with no material supplied the broker is verified
312
+ * against Node's bundled roots. Set {@link AmqpTlsOptions.caCert} when the
313
+ * broker certificate comes from a private CA — the common case for an
314
+ * in-cluster broker, and the reason §8b rule 2 is a MUST.
315
+ */
316
+ tls?: AmqpTlsOptions;
218
317
  }
219
318
  /**
220
319
  * Verify a single delivery's HMAC signature (CONTRACT.md §8 steps a-g) and,
@@ -241,6 +340,11 @@ declare function verifyAndDispatch(channel: ConsumeChannel, msg: ConsumeMessage,
241
340
  *
242
341
  * This function owns the full ack/nack loop; `handler` MUST NOT itself call
243
342
  * ack/nack (there is no delivery handle exposed to it).
343
+ *
344
+ * `amqpUrl` MUST be `amqps://` (CONTRACT.md §8b). It is checked before any
345
+ * socket is opened, so a plaintext URL fails with a message naming the rule
346
+ * rather than connecting and quietly putting signed-but-readable authorization
347
+ * requests and audit events on the wire.
244
348
  */
245
349
  declare function consume(amqpUrl: string, queue: string, signingKey: Sensitive<Buffer>, handler: (event: Record<string, unknown>) => Promise<void>, options?: ConsumeOptions): Promise<void>;
246
350
 
@@ -751,10 +855,22 @@ declare function dispatchReactorDelivery(channel: ReactorChannel, msg: ConsumeMe
751
855
  /** How to reach the broker and which reactor this process is (§22.1, §22.9). */
752
856
  interface ReactorConfig {
753
857
  /**
754
- * Broker URL. Must be `amqps://` for any routable host (§8b) — there is no
755
- * verification-skip switch and no plaintext fallback.
858
+ * Broker URL. Must be `amqps://` (§8b rules 1 and 5) — there is no
859
+ * verification-skip switch and no plaintext fallback, and this is now
860
+ * *enforced* before the socket opens rather than merely stated here.
756
861
  */
757
862
  readonly amqpUrl: string;
863
+ /**
864
+ * TLS material for {@link amqpUrl} (§8b).
865
+ *
866
+ * Optional. With none supplied the broker is verified against Node's bundled
867
+ * roots, which is correct for a publicly-issued broker certificate. Set
868
+ * {@link AmqpTlsOptions.caCert} for a privately-issued one — the common case
869
+ * for an in-cluster broker, and why §8b rule 2 is a MUST — and
870
+ * `clientCert`/`clientKey` together for mutual TLS toward the broker
871
+ * (rule 3).
872
+ */
873
+ readonly tls?: AmqpTlsOptions;
758
874
  /** The tenant this reactor is registered in. */
759
875
  readonly tenantId: string;
760
876
  /**
@@ -847,4 +963,51 @@ interface ReactorConfig {
847
963
  */
848
964
  declare function reactorServe(config: ReactorConfig, handler: ReactorHandler): Promise<void>;
849
965
 
850
- export { type AuditEventMessage, type AuthzRequest, type AuthzResponse, type ConsumeChannel, type ConsumeLogger, type ConsumeOptions, DEFAULT_REACTOR_MAX_IN_FLIGHT, DEFAULT_REACTOR_TIMEOUT_MS, DEFAULT_REPLAY_SKEW_MS, EVENT_REGISTRY, type EventRejection, type FailurePolicy, HMAC_SIGNED_MESSAGE_TYPES, type HmacSignedMessageType, InMemoryNonceStore, MAX_REACTOR_TIMEOUT_MS, MIN_REACTOR_TIMEOUT_MS, type NonceStore, type NotificationEvent, REACTOR_EVENTS, REACTOR_EXCHANGE, REACTOR_FRESHNESS_SKEW_MS, REACTOR_KEY_VERSION, type ReactorChannel, type ReactorConfig, type ReactorDecision, type ReactorDispatchContext, type ReactorEvent, type ReactorEventName, type ReactorEventSpec, type ReactorHandler, type ReactorLogger, type ReactorMode, type ReactorReply, type ReplyDecision, type ReplyInput, type ReplyRejection, Sensitive, type VerifyEventResult, abstain, allow, buildReactorReply, canonicalEventBytes, canonicalReplyBytes, chainedPatch, consume, defaultFailurePolicyFor, deny, dispatchReactorDelivery, eventSpec, isFresh, mutate, patchFieldAllowed, reactorQueueName, reactorReplySignatureValid, reactorRoutingKey, reactorServe, requireStepUp, signPayload, signReactorReply, signingKeyFingerprint, specForEvent, toChronoRfc3339, verifyAndDispatch, verifyEvent, verifyPayload };
966
+ /**
967
+ * One handler per hook event.
968
+ *
969
+ * The key type is {@link ReactorEventName}, so a misspelled event is a
970
+ * **compile-time** error in TypeScript — and `reactorHandlers` re-checks at
971
+ * runtime for JavaScript callers, who get no such help. Duplicate keys within a
972
+ * single object literal are a compile-time error too (TS1117), which is §22.14
973
+ * rule 3 enforced by the language; passing two groups that both bind the same
974
+ * event is the case the runtime check exists for.
975
+ */
976
+ type ReactorHandlerMap = Partial<Record<ReactorEventName, ReactorHandler>>;
977
+ /**
978
+ * The event names `reactorHandlers` accepts, sorted.
979
+ *
980
+ * Built from what IS hookable, deliberately: §22.13 requires the three hot-path
981
+ * operations to be absent from every event constant this SDK exposes, so a list
982
+ * naming them — even only to say they are refused — is the thing that would
983
+ * break it (§22.14 rule 2).
984
+ */
985
+ declare function hookableEvents(): readonly string[];
986
+ /**
987
+ * Compose one handler per event into the single handler `reactorServe` takes
988
+ * (CONTRACT.md §22.14).
989
+ *
990
+ * ```ts
991
+ * await reactorServe(options, reactorHandlers({
992
+ * [REACTOR_EVENTS.TOKEN_PRE_ISSUE]: enrichToken,
993
+ * [REACTOR_EVENTS.LOGIN_POST_AUTH]: screenLogin,
994
+ * }));
995
+ * ```
996
+ *
997
+ * Several groups may be passed, so handlers can be split across modules and
998
+ * merged here:
999
+ *
1000
+ * ```ts
1001
+ * reactorHandlers(tokenHandlers, loginHandlers)
1002
+ * ```
1003
+ *
1004
+ * @param groups one or more event → handler maps.
1005
+ * @returns the `ReactorHandler` `reactorServe` accepts.
1006
+ * @throws TypeError if a key is outside the §22.5 registry — which is also how
1007
+ * §22.7's three hot-path operations are refused, since they are in no registry
1008
+ * row — if a value is not a function, if two groups bind the same event, or if
1009
+ * nothing is bound at all.
1010
+ */
1011
+ declare function reactorHandlers(...groups: readonly ReactorHandlerMap[]): ReactorHandler;
1012
+
1013
+ export { type AmqpTlsOptions, type AuditEventMessage, type AuthzRequest, type AuthzResponse, type ConsumeChannel, type ConsumeLogger, type ConsumeOptions, DEFAULT_REACTOR_MAX_IN_FLIGHT, DEFAULT_REACTOR_TIMEOUT_MS, DEFAULT_REPLAY_SKEW_MS, EVENT_REGISTRY, type EventRejection, type FailurePolicy, HMAC_SIGNED_MESSAGE_TYPES, type HmacSignedMessageType, InMemoryNonceStore, MAX_REACTOR_TIMEOUT_MS, MIN_REACTOR_TIMEOUT_MS, type NonceStore, type NotificationEvent, REACTOR_EVENTS, REACTOR_EXCHANGE, REACTOR_FRESHNESS_SKEW_MS, REACTOR_KEY_VERSION, type ReactorChannel, type ReactorConfig, type ReactorDecision, type ReactorDispatchContext, type ReactorEvent, type ReactorEventName, type ReactorEventSpec, type ReactorHandler, type ReactorHandlerMap, type ReactorLogger, type ReactorMode, type ReactorReply, type ReplyDecision, type ReplyInput, type ReplyRejection, Sensitive, type VerifyEventResult, abstain, allow, assertAmqpsUrl, buildAmqpConnectOptions, buildReactorReply, canonicalEventBytes, canonicalReplyBytes, chainedPatch, consume, defaultFailurePolicyFor, deny, dispatchReactorDelivery, eventSpec, hookableEvents, isFresh, mutate, patchFieldAllowed, reactorHandlers, reactorQueueName, reactorReplySignatureValid, reactorRoutingKey, reactorServe, requireStepUp, signPayload, signReactorReply, signingKeyFingerprint, specForEvent, toChronoRfc3339, verifyAndDispatch, verifyEvent, verifyPayload };
@@ -1,5 +1,6 @@
1
1
  import { S as Sensitive } from '../sensitive-BC_s7Rrd.js';
2
2
  import { ConsumeMessage } from 'amqplib';
3
+ import { ConnectionOptions } from 'node:tls';
3
4
  import { T as TelemetryHook, a as TelemetryDispatcher } from '../telemetry-DrGqL4kb.js';
4
5
 
5
6
  /**
@@ -142,6 +143,94 @@ interface NotificationEvent {
142
143
  declare const HMAC_SIGNED_MESSAGE_TYPES: readonly ["AuthzRequest", "AuditEventMessage"];
143
144
  type HmacSignedMessageType = (typeof HMAC_SIGNED_MESSAGE_TYPES)[number];
144
145
 
146
+ /**
147
+ * TLS material for an `amqps://` broker connection (§8b).
148
+ *
149
+ * Every field is optional: with none set, an `amqps://` URL still connects and
150
+ * still verifies, against Node's bundled root store. The fields exist for the
151
+ * two cases that store cannot serve — a privately-issued broker certificate,
152
+ * and mutual TLS toward the broker.
153
+ *
154
+ * # There is deliberately no verification-skip option
155
+ *
156
+ * Not as an omission to be filled in later. §8b rule 4 forbids surfacing one
157
+ * under any name, and the reasoning is that such a switch is the single most
158
+ * reliably misused option in TLS: it appears in a dev compose file, it works,
159
+ * and it travels unchanged into production, where it turns TLS into an
160
+ * expensive no-op against precisely the attacker TLS exists to stop.
161
+ * {@link caCert} covers the legitimate reason people reach for it (rule 2)
162
+ * without covering the rest.
163
+ *
164
+ * This paragraph names no concrete bypass flag, and that is not squeamishness:
165
+ * CI greps `src/` for the literal disabling forms and fails the build on a hit.
166
+ * A comment explaining why the SDK does not do the thing would trip the same
167
+ * grep as code doing it — the check cannot tell prose from an assignment — so
168
+ * the prose stays abstract and the check stays blunt. Both are better that way.
169
+ *
170
+ * `amqplib` would happily accept `rejectUnauthorized` in its socket options,
171
+ * which is exactly why {@link buildAmqpConnectOptions} constructs that object
172
+ * itself from these three fields rather than accepting a caller-supplied one.
173
+ */
174
+ interface AmqpTlsOptions {
175
+ /**
176
+ * PEM bundle of the CA(s) that issued the broker's certificate (§8b rule 2).
177
+ *
178
+ * Unset = verify against Node's bundled roots. Set this when the broker
179
+ * certificate comes from a private CA — including one issued by AXIAM's own
180
+ * organization CA, which is the recommended dogfooding path.
181
+ *
182
+ * Unlike the server's own `AXIAM__AMQP__TLS__CA_CERT_PATH`, this **replaces**
183
+ * the trust set rather than adding to it: Node's `tls.connect` treats `ca` as
184
+ * the complete root list. Supplying your broker's CA here therefore does
185
+ * narrow trust to it, which is usually what someone setting this actually
186
+ * wants.
187
+ */
188
+ readonly caCert?: string;
189
+ /**
190
+ * PEM client certificate chain, for mutual TLS toward the broker (§8b
191
+ * rule 3).
192
+ *
193
+ * Must be supplied together with {@link clientKey}. Half a client identity is
194
+ * never what anyone meant, and connecting anyway would silently drop the
195
+ * mutual half of mutual TLS — so it is rejected before dialling.
196
+ */
197
+ readonly clientCert?: string;
198
+ /** PEM private key matching {@link clientCert}. Secret material (§7). */
199
+ readonly clientKey?: string;
200
+ }
201
+ /**
202
+ * Reject any broker URL that is not `amqps://` (§8b rules 1 and 5).
203
+ *
204
+ * A plaintext URL is refused here rather than downgraded, and there is no
205
+ * fallback path for it to take — rule 5 exists because a fallback that works
206
+ * is a fallback that gets used, and the failure it produces is invisible
207
+ * exactly when it matters.
208
+ *
209
+ * The `://` separator is load-bearing: matching on `amqps` alone would let a
210
+ * hypothetical `amqpsomething://` through.
211
+ *
212
+ * @throws {NetworkError} when `url` is not an `amqps://` URL.
213
+ */
214
+ declare function assertAmqpsUrl(url: string, what?: string): void;
215
+ /**
216
+ * Validate `url` and build the socket options `amqplib.connect` should dial
217
+ * with (§8b).
218
+ *
219
+ * `amqplib` forwards its second argument to `tls.connect` for an `amqps://`
220
+ * URL, so the returned object is a `tls.ConnectionOptions` carrying at most
221
+ * `ca`, `cert` and `key`. It never carries `rejectUnauthorized`, which leaves
222
+ * Node's strict default (`true`) in force — see {@link AmqpTlsOptions}.
223
+ *
224
+ * The certificate/key pairing is validated by `resolveClientIdentity`, the same
225
+ * §6.1 helper the REST and gRPC transports use, so mutual TLS is validated
226
+ * identically on every transport this SDK speaks rather than once per protocol.
227
+ *
228
+ * @throws {NetworkError} when `url` is not `amqps://`.
229
+ * @throws {Error} when the TLS material is internally inconsistent (a client
230
+ * certificate without its key, or PEM that is not PEM).
231
+ */
232
+ declare function buildAmqpConnectOptions(url: string, tls?: AmqpTlsOptions, what?: string): ConnectionOptions | undefined;
233
+
145
234
  /**
146
235
  * Default freshness skew for `issued_at` acceptance (NEW-4): a message is
147
236
  * accepted only when its `issued_at` lies within ±5 minutes of the
@@ -215,6 +304,16 @@ interface ConsumeOptions {
215
304
  * must pass the same store explicitly for dedup to take effect.
216
305
  */
217
306
  nonceStore?: NonceStore;
307
+ /**
308
+ * TLS material for the `amqps://` broker connection (CONTRACT.md §8b).
309
+ *
310
+ * Optional, and omitting it does not weaken anything: the URL must be
311
+ * `amqps://` either way, and with no material supplied the broker is verified
312
+ * against Node's bundled roots. Set {@link AmqpTlsOptions.caCert} when the
313
+ * broker certificate comes from a private CA — the common case for an
314
+ * in-cluster broker, and the reason §8b rule 2 is a MUST.
315
+ */
316
+ tls?: AmqpTlsOptions;
218
317
  }
219
318
  /**
220
319
  * Verify a single delivery's HMAC signature (CONTRACT.md §8 steps a-g) and,
@@ -241,6 +340,11 @@ declare function verifyAndDispatch(channel: ConsumeChannel, msg: ConsumeMessage,
241
340
  *
242
341
  * This function owns the full ack/nack loop; `handler` MUST NOT itself call
243
342
  * ack/nack (there is no delivery handle exposed to it).
343
+ *
344
+ * `amqpUrl` MUST be `amqps://` (CONTRACT.md §8b). It is checked before any
345
+ * socket is opened, so a plaintext URL fails with a message naming the rule
346
+ * rather than connecting and quietly putting signed-but-readable authorization
347
+ * requests and audit events on the wire.
244
348
  */
245
349
  declare function consume(amqpUrl: string, queue: string, signingKey: Sensitive<Buffer>, handler: (event: Record<string, unknown>) => Promise<void>, options?: ConsumeOptions): Promise<void>;
246
350
 
@@ -751,10 +855,22 @@ declare function dispatchReactorDelivery(channel: ReactorChannel, msg: ConsumeMe
751
855
  /** How to reach the broker and which reactor this process is (§22.1, §22.9). */
752
856
  interface ReactorConfig {
753
857
  /**
754
- * Broker URL. Must be `amqps://` for any routable host (§8b) — there is no
755
- * verification-skip switch and no plaintext fallback.
858
+ * Broker URL. Must be `amqps://` (§8b rules 1 and 5) — there is no
859
+ * verification-skip switch and no plaintext fallback, and this is now
860
+ * *enforced* before the socket opens rather than merely stated here.
756
861
  */
757
862
  readonly amqpUrl: string;
863
+ /**
864
+ * TLS material for {@link amqpUrl} (§8b).
865
+ *
866
+ * Optional. With none supplied the broker is verified against Node's bundled
867
+ * roots, which is correct for a publicly-issued broker certificate. Set
868
+ * {@link AmqpTlsOptions.caCert} for a privately-issued one — the common case
869
+ * for an in-cluster broker, and why §8b rule 2 is a MUST — and
870
+ * `clientCert`/`clientKey` together for mutual TLS toward the broker
871
+ * (rule 3).
872
+ */
873
+ readonly tls?: AmqpTlsOptions;
758
874
  /** The tenant this reactor is registered in. */
759
875
  readonly tenantId: string;
760
876
  /**
@@ -847,4 +963,51 @@ interface ReactorConfig {
847
963
  */
848
964
  declare function reactorServe(config: ReactorConfig, handler: ReactorHandler): Promise<void>;
849
965
 
850
- export { type AuditEventMessage, type AuthzRequest, type AuthzResponse, type ConsumeChannel, type ConsumeLogger, type ConsumeOptions, DEFAULT_REACTOR_MAX_IN_FLIGHT, DEFAULT_REACTOR_TIMEOUT_MS, DEFAULT_REPLAY_SKEW_MS, EVENT_REGISTRY, type EventRejection, type FailurePolicy, HMAC_SIGNED_MESSAGE_TYPES, type HmacSignedMessageType, InMemoryNonceStore, MAX_REACTOR_TIMEOUT_MS, MIN_REACTOR_TIMEOUT_MS, type NonceStore, type NotificationEvent, REACTOR_EVENTS, REACTOR_EXCHANGE, REACTOR_FRESHNESS_SKEW_MS, REACTOR_KEY_VERSION, type ReactorChannel, type ReactorConfig, type ReactorDecision, type ReactorDispatchContext, type ReactorEvent, type ReactorEventName, type ReactorEventSpec, type ReactorHandler, type ReactorLogger, type ReactorMode, type ReactorReply, type ReplyDecision, type ReplyInput, type ReplyRejection, Sensitive, type VerifyEventResult, abstain, allow, buildReactorReply, canonicalEventBytes, canonicalReplyBytes, chainedPatch, consume, defaultFailurePolicyFor, deny, dispatchReactorDelivery, eventSpec, isFresh, mutate, patchFieldAllowed, reactorQueueName, reactorReplySignatureValid, reactorRoutingKey, reactorServe, requireStepUp, signPayload, signReactorReply, signingKeyFingerprint, specForEvent, toChronoRfc3339, verifyAndDispatch, verifyEvent, verifyPayload };
966
+ /**
967
+ * One handler per hook event.
968
+ *
969
+ * The key type is {@link ReactorEventName}, so a misspelled event is a
970
+ * **compile-time** error in TypeScript — and `reactorHandlers` re-checks at
971
+ * runtime for JavaScript callers, who get no such help. Duplicate keys within a
972
+ * single object literal are a compile-time error too (TS1117), which is §22.14
973
+ * rule 3 enforced by the language; passing two groups that both bind the same
974
+ * event is the case the runtime check exists for.
975
+ */
976
+ type ReactorHandlerMap = Partial<Record<ReactorEventName, ReactorHandler>>;
977
+ /**
978
+ * The event names `reactorHandlers` accepts, sorted.
979
+ *
980
+ * Built from what IS hookable, deliberately: §22.13 requires the three hot-path
981
+ * operations to be absent from every event constant this SDK exposes, so a list
982
+ * naming them — even only to say they are refused — is the thing that would
983
+ * break it (§22.14 rule 2).
984
+ */
985
+ declare function hookableEvents(): readonly string[];
986
+ /**
987
+ * Compose one handler per event into the single handler `reactorServe` takes
988
+ * (CONTRACT.md §22.14).
989
+ *
990
+ * ```ts
991
+ * await reactorServe(options, reactorHandlers({
992
+ * [REACTOR_EVENTS.TOKEN_PRE_ISSUE]: enrichToken,
993
+ * [REACTOR_EVENTS.LOGIN_POST_AUTH]: screenLogin,
994
+ * }));
995
+ * ```
996
+ *
997
+ * Several groups may be passed, so handlers can be split across modules and
998
+ * merged here:
999
+ *
1000
+ * ```ts
1001
+ * reactorHandlers(tokenHandlers, loginHandlers)
1002
+ * ```
1003
+ *
1004
+ * @param groups one or more event → handler maps.
1005
+ * @returns the `ReactorHandler` `reactorServe` accepts.
1006
+ * @throws TypeError if a key is outside the §22.5 registry — which is also how
1007
+ * §22.7's three hot-path operations are refused, since they are in no registry
1008
+ * row — if a value is not a function, if two groups bind the same event, or if
1009
+ * nothing is bound at all.
1010
+ */
1011
+ declare function reactorHandlers(...groups: readonly ReactorHandlerMap[]): ReactorHandler;
1012
+
1013
+ export { type AmqpTlsOptions, type AuditEventMessage, type AuthzRequest, type AuthzResponse, type ConsumeChannel, type ConsumeLogger, type ConsumeOptions, DEFAULT_REACTOR_MAX_IN_FLIGHT, DEFAULT_REACTOR_TIMEOUT_MS, DEFAULT_REPLAY_SKEW_MS, EVENT_REGISTRY, type EventRejection, type FailurePolicy, HMAC_SIGNED_MESSAGE_TYPES, type HmacSignedMessageType, InMemoryNonceStore, MAX_REACTOR_TIMEOUT_MS, MIN_REACTOR_TIMEOUT_MS, type NonceStore, type NotificationEvent, REACTOR_EVENTS, REACTOR_EXCHANGE, REACTOR_FRESHNESS_SKEW_MS, REACTOR_KEY_VERSION, type ReactorChannel, type ReactorConfig, type ReactorDecision, type ReactorDispatchContext, type ReactorEvent, type ReactorEventName, type ReactorEventSpec, type ReactorHandler, type ReactorHandlerMap, type ReactorLogger, type ReactorMode, type ReactorReply, type ReplyDecision, type ReplyInput, type ReplyRejection, Sensitive, type VerifyEventResult, abstain, allow, assertAmqpsUrl, buildAmqpConnectOptions, buildReactorReply, canonicalEventBytes, canonicalReplyBytes, chainedPatch, consume, defaultFailurePolicyFor, deny, dispatchReactorDelivery, eventSpec, hookableEvents, isFresh, mutate, patchFieldAllowed, reactorHandlers, reactorQueueName, reactorReplySignatureValid, reactorRoutingKey, reactorServe, requireStepUp, signPayload, signReactorReply, signingKeyFingerprint, specForEvent, toChronoRfc3339, verifyAndDispatch, verifyEvent, verifyPayload };