From c1db2c582c2e4daf61b57a1f3d438d296af2291c Mon Sep 17 00:00:00 2001 From: Cal Courtney Date: Tue, 17 Mar 2026 12:19:38 +0000 Subject: [PATCH 1/2] fix: allow updating of agent value --- package.json | 2 +- src/__tests__/client.test.js | 33 +++++++++++++++++++++++++++++++++ src/client.ts | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1c259e7..07ea94e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@absmartly/javascript-sdk", - "version": "1.13.3", + "version": "1.13.4", "description": "A/B Smartly Javascript SDK", "homepage": "https://github.com/absmartly/javascript-sdk#README.md", "bugs": "https://github.com/absmartly/javascript-sdk/issues", diff --git a/src/__tests__/client.test.js b/src/__tests__/client.test.js index 05b6615..5d0d3b6 100644 --- a/src/__tests__/client.test.js +++ b/src/__tests__/client.test.js @@ -939,6 +939,39 @@ describe("Client", () => { }); }); + it("constructor() should accept custom agent string", (done) => { + fetch.mockResolvedValueOnce(responseMock(200, "OK", defaultMockResponse)); + + const customAgent = "custom-agent"; + const client = new Client({ ...clientOptions, agent: customAgent }); + + client + .request({ + auth: true, + method: "PUT", + path: "/context", + }) + .then(() => { + expect(fetch).toHaveBeenCalledTimes(1); + expect(fetch).toHaveBeenCalledWith(`${endpoint}/context`, { + method: "PUT", + headers: { + "Content-Type": "application/json", + "X-API-Key": apiKey, + "X-Agent": customAgent, + "X-Environment": "test", + "X-Application": "test_app", + "X-Application-Version": 1000000, + }, + body: undefined, + keepalive: true, + signal: expect.any(Object), + }); + + done(); + }); + }); + it("publish() should not have the keepalive flag if specified", (done) => { fetch.mockResolvedValueOnce(responseMock(200, "OK", defaultMockResponse)); diff --git a/src/client.ts b/src/client.ts index 2a1325f..6afdf66 100644 --- a/src/client.ts +++ b/src/client.ts @@ -28,7 +28,7 @@ export type ClientRequestOptions = { }; export type ClientOptions = { - agent?: "javascript-client"; + agent?: string; apiKey: string; application: string | { name: string; version: number }; endpoint: string; From 104d9debc50918eae0e7ca309e3139c93d848c78 Mon Sep 17 00:00:00 2001 From: Cal Courtney Date: Tue, 17 Mar 2026 12:25:45 +0000 Subject: [PATCH 2/2] test: add test for setting agent at the sdkOptions level --- src/__tests__/sdk.test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/__tests__/sdk.test.js b/src/__tests__/sdk.test.js index 103de2e..3dc75de 100644 --- a/src/__tests__/sdk.test.js +++ b/src/__tests__/sdk.test.js @@ -80,6 +80,26 @@ describe("SDK", () => { done(); }); + it("should pass custom agent to client", (done) => { + const customAgent = "my-custom-agent"; + const options = { + ...sdkOptions, + agent: customAgent, + }; + + const sdk = new SDK(options); + + expect(sdk).toBeInstanceOf(SDK); + expect(Client).toHaveBeenCalledTimes(1); + expect(Client).toHaveBeenCalledWith( + expect.objectContaining({ + agent: customAgent, + }) + ); + + done(); + }); + it("should set default values for unspecified client options", (done) => { const options = { application: "application",