From 63b4ec2bf282ecededb59cf8c21bbffa9e5a86a8 Mon Sep 17 00:00:00 2001 From: Cal Courtney Date: Tue, 17 Mar 2026 12:07:45 +0000 Subject: [PATCH 1/3] feat: add agent override for react and react-native SDKs --- src/components/SDKProvider/SDKProvider.tsx | 14 +++- src/types.ts | 1 + tests/SDKProvider.test.tsx | 78 +++++++++++++++++++++- 3 files changed, 89 insertions(+), 4 deletions(-) diff --git a/src/components/SDKProvider/SDKProvider.tsx b/src/components/SDKProvider/SDKProvider.tsx index 55ff8ea..3f6f0d8 100644 --- a/src/components/SDKProvider/SDKProvider.tsx +++ b/src/components/SDKProvider/SDKProvider.tsx @@ -11,6 +11,13 @@ import { SDKOptionsType, } from "../../types"; +const isReactNative = + typeof navigator !== "undefined" && navigator.product === "ReactNative"; + +const SDK_AGENT = isReactNative + ? "absmartly-react-native-sdk" + : "absmartly-react-sdk"; + type SDKProviderNoContext = { sdkOptions: SDKOptionsType; context?: never; @@ -35,7 +42,12 @@ export const SDKProvider: FC = ({ }) => { const sdk = context ? context["_sdk"] - : new absmartly.SDK({ retries: 5, timeout: 3000, ...sdkOptions }); + : new absmartly.SDK({ + agent: SDK_AGENT, + retries: 5, + timeout: 3000, + ...sdkOptions, + }); const [providedContext, setProvidedContext] = useState( context ? context : sdk.createContext(contextOptions), diff --git a/src/types.ts b/src/types.ts index c23492b..1cc7a5c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,6 +7,7 @@ export type SDKOptionsType = { apiKey: string; environment: string; application: string; + agent?: string; retries?: number; timeout?: number; eventLogger?: (context: Context, eventName: EventNameType, data: any) => void; diff --git a/tests/SDKProvider.test.tsx b/tests/SDKProvider.test.tsx index 698c144..4c6f1dc 100644 --- a/tests/SDKProvider.test.tsx +++ b/tests/SDKProvider.test.tsx @@ -78,8 +78,8 @@ describe("SDKProvider", () => { apiKey: "salkjdhclkjsdbca", application: "www", environment: "Environment 5", - retries: 5, - timeout: 3000, + retries: 10, + timeout: 5000, overrides: overrides, attributes: attrs, data: mockContextData, @@ -101,12 +101,40 @@ describe("SDKProvider", () => { ); expect(SDK).toHaveBeenCalledTimes(1); - expect(SDK).toHaveBeenLastCalledWith(sdkOptions); + expect(SDK).toHaveBeenLastCalledWith({ + agent: "absmartly-react-sdk", + retries: 10, + timeout: 5000, + ...sdkOptions, + }); expect(mockCreateContext).toHaveBeenCalledTimes(1); expect(mockCreateContext).toHaveBeenLastCalledWith(contextOptions); }); + it("should allow the user to override the agent", async () => { + const customSdkOptions = { + ...sdkOptions, + agent: "custom-agent", + }; + + render( + + + , + ); + + expect(SDK).toHaveBeenCalledTimes(1); + expect(SDK).toHaveBeenLastCalledWith( + expect.objectContaining({ + agent: "custom-agent", + }), + ); + }); + it("Whether it will create an SDK instance with a context that has prefetched context data", async () => { render( @@ -177,3 +205,47 @@ describe("SDKProvider", () => { ); }); }); + +describe("SDKProvider React Native agent", () => { + const originalProduct = navigator.product; + + afterEach(() => { + Object.defineProperty(navigator, "product", { + value: originalProduct, + configurable: true, + }); + }); + + it("should use absmartly-react-native-sdk agent when navigator.product is ReactNative", async () => { + Object.defineProperty(navigator, "product", { + value: "ReactNative", + configurable: true, + }); + + vi.resetModules(); + + const { SDKProvider: RNSDKProvider } = await import( + "../src/components/SDKProvider" + ); + + render( + +
+ , + ); + + expect(SDK).toHaveBeenLastCalledWith( + expect.objectContaining({ + agent: "absmartly-react-native-sdk", + }), + ); + }); +}); From adfb82b54ddeb8b6c23b36144b401bd50b89cea8 Mon Sep 17 00:00:00 2001 From: Cal Courtney Date: Tue, 17 Mar 2026 12:08:45 +0000 Subject: [PATCH 2/3] chore: bump version to v1.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9fbcef7..8b09646 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@absmartly/react-sdk", - "version": "1.4.0", + "version": "1.4.1", "homepage": "https://github.com/absmartly/react-sdk#README.md", "bugs": "https://github.com/absmartly/react-sdk/issues", "keywords": [ From 1807fc8f98edefc8f2a4d9ee123c60f86ca39b76 Mon Sep 17 00:00:00 2001 From: Cal Courtney Date: Tue, 17 Mar 2026 12:48:19 +0000 Subject: [PATCH 3/3] chore: update js-sdk to v1.13.4 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 8b09646..ca6629b 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "react-dom": ">=16.8.0" }, "dependencies": { - "@absmartly/javascript-sdk": "^1.13.0", + "@absmartly/javascript-sdk": "^1.13.4", "core-js": "^3.26.0" }, "publishConfig": { diff --git a/yarn.lock b/yarn.lock index d14e4c8..2fbee69 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@absmartly/javascript-sdk@^1.13.0": - version "1.13.1" - resolved "https://registry.yarnpkg.com/@absmartly/javascript-sdk/-/javascript-sdk-1.13.1.tgz#1ab36024b7c3b95a3a3314784e3d47dbebfcae2c" - integrity sha512-u6Ga8QFZ2tTElj7Picrm8ZAONog9E8X0fW2Mdl+ep9O/y2x2KmAKioVikvAx9NQH4vTTkFAetcvidWJgxhu9nA== +"@absmartly/javascript-sdk@^1.13.4": + version "1.13.4" + resolved "https://registry.yarnpkg.com/@absmartly/javascript-sdk/-/javascript-sdk-1.13.4.tgz#83847f54bb2bf4d414e0530b2b47c1ffb62c2960" + integrity sha512-uNENphAJQ2iq8J1U8Eanf/rMeQ9p7DvnEWlHPr4doWWLRoaLiWRo4Ke9j9oO0WTsVt+Lz3r/HCEkyqVP6Q9BHQ== dependencies: core-js "^3.20.0" node-fetch "^2.6.7"