Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1921,6 +1922,7 @@ export class AxmeClient {
const headers: Record<string, string> = {
"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}`;
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { SDK_VERSION } from "./version.js";
export {
AxmeClient,
type AxmeClientConfig,
Expand Down
3 changes: 3 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -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";
13 changes: 13 additions & 0 deletions test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
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(
{
Expand Down
Loading