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( {