From 2b44a94e3e86f92b52fa0566b1138a05cb28c04c Mon Sep 17 00:00:00 2001 From: geobelsky Date: Fri, 10 Apr 2026 10:37:18 +0000 Subject: [PATCH] feat: send X-Axme-Client header on every request Adds X-Axme-Client: axme-sdk-typescript/ header to all outgoing HTTP requests, enabling AXME platform admin analytics to identify which SDK generated the traffic. - New src/version.ts with SDK_VERSION constant (kept in sync with package.json) - buildHeaders() now includes X-Axme-Client built from SDK_VERSION - SDK_VERSION re-exported from index.ts for consumer access - Test verifies the header is set on outgoing requests --- src/client.ts | 2 ++ src/index.ts | 1 + src/version.ts | 3 +++ test/client.test.ts | 13 +++++++++++++ 4 files changed, 19 insertions(+) create mode 100644 src/version.ts diff --git a/src/client.ts b/src/client.ts index 9ab28cf..fb12cb1 100644 --- a/src/client.ts +++ b/src/client.ts @@ -6,6 +6,7 @@ import { AxmeValidationError, } from "./errors.js"; import { MeshClient } from "./mesh.js"; +import { SDK_VERSION } from "./version.js"; export type AxmeClientConfig = { baseUrl?: string; @@ -1921,6 +1922,7 @@ export class AxmeClient { const headers: Record = { "x-api-key": this.apiKey, "Content-Type": "application/json", + "X-Axme-Client": `axme-sdk-typescript/${SDK_VERSION}`, }; if (this.actorToken) { headers.Authorization = `Bearer ${this.actorToken}`; diff --git a/src/index.ts b/src/index.ts index 55856bc..ddb8b34 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +export { SDK_VERSION } from "./version.js"; export { AxmeClient, type AxmeClientConfig, diff --git a/src/version.ts b/src/version.ts new file mode 100644 index 0000000..f082305 --- /dev/null +++ b/src/version.ts @@ -0,0 +1,3 @@ +// Single source of truth for the SDK version sent in X-Axme-Client header. +// Keep in sync with package.json version field on every release. +export const SDK_VERSION = "0.2.0"; diff --git a/test/client.test.ts b/test/client.test.ts index a4e1002..f0c4141 100644 --- a/test/client.test.ts +++ b/test/client.test.ts @@ -50,6 +50,19 @@ test("health returns parsed payload", async () => { assert.deepEqual(await client.health(), { ok: true }); }); +test("health sends X-Axme-Client header", async () => { + const { SDK_VERSION } = await import("../src/version.js"); + const client = new AxmeClient( + { baseUrl: "https://api.axme.test", apiKey: "token" }, + async (_input, init) => { + const headers = init?.headers as Record; + assert.equal(headers["X-Axme-Client"], `axme-sdk-typescript/${SDK_VERSION}`); + return new Response(JSON.stringify({ ok: true }), { status: 200 }); + }, + ); + await client.health(); +}); + test("health includes actor token authorization when configured", async () => { const client = new AxmeClient( {