feat(iios-kernel-client): per-request header factory → 0.1.4

RestConfig.headers now accepts a function, invoked once per request, so a caller can
mint a FRESH context attestation (new single-use nonce) each call. A static header was
replay-rejected on the 2nd request of a multi-call operation. Published 0.1.4.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-13 23:26:33 +05:30
parent 3e66c7a5db
commit 85a78eb21e
2 changed files with 10 additions and 4 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@insignia/iios-kernel-client", "name": "@insignia/iios-kernel-client",
"version": "0.1.3", "version": "0.1.4",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",
"module": "dist/index.js", "module": "dist/index.js",
+9 -3
View File
@@ -4,8 +4,13 @@ import type { Message, InboxItem, InboxState, Ticket, TicketState, CallbackReque
export interface RestConfig { export interface RestConfig {
serviceUrl: string; serviceUrl: string;
token?: string; token?: string;
/** Extra headers sent on every request — e.g. `x-context-attestation` (the July 12 trust proof). */ /**
headers?: Record<string, string>; * Extra headers for every request — e.g. `x-context-attestation` (the July 12 trust proof).
* Pass a FUNCTION to mint fresh headers per request: a context attestation carries a single-use
* nonce, so a static header would be replay-rejected on the 2nd call. The function is invoked
* once per request.
*/
headers?: Record<string, string> | (() => Record<string, string>);
} }
/** REST/polling client for kernel reads and the native-send fallback. */ /** REST/polling client for kernel reads and the native-send fallback. */
@@ -17,7 +22,8 @@ export class RestClient {
} }
private headers(extra: Record<string, string> = {}): Record<string, string> { private headers(extra: Record<string, string> = {}): Record<string, string> {
const h: Record<string, string> = { 'content-type': 'application/json', ...this.config.headers, ...extra }; const custom = typeof this.config.headers === 'function' ? this.config.headers() : this.config.headers;
const h: Record<string, string> = { 'content-type': 'application/json', ...custom, ...extra };
if (this.config.token) h.authorization = `Bearer ${this.config.token}`; if (this.config.token) h.authorization = `Bearer ${this.config.token}`;
return h; return h;
} }