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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@absmartly/react-sdk",
"version": "1.4.0",
"version": "1.4.1",
Copy link

@coderabbitai coderabbitai bot Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Version bump should reflect a feature release.

This change introduces new SDK behaviour, so a minor SemVer bump is more appropriate than a patch bump.

Suggested change
-  "version": "1.4.1",
+  "version": "1.5.0",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"version": "1.4.1",
"version": "1.5.0",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` at line 3, Update the package.json "version" value to reflect a
minor feature release instead of a patch; change the "version" field currently
set as "1.4.1" to "1.5.0" so the SemVer bump correctly indicates new SDK
behavior (edit the "version" key in package.json).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this was a bug. It should have been like this already. I don't see a need to bump a minor version for this small change

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@calthejuggler, that's a fair point! If the agent identifier was simply incorrect from the start and this is correcting the expected behaviour, a patch bump is perfectly appropriate under SemVer. Happy to defer to your judgement here.

"homepage": "https://github.com/absmartly/react-sdk#README.md",
"bugs": "https://github.com/absmartly/react-sdk/issues",
"keywords": [
Expand Down Expand Up @@ -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": {
Expand Down
14 changes: 13 additions & 1 deletion src/components/SDKProvider/SDKProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,7 +42,12 @@ export const SDKProvider: FC<SDKProviderProps> = ({
}) => {
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),
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
78 changes: 75 additions & 3 deletions tests/SDKProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
<SDKProvider
sdkOptions={customSdkOptions}
contextOptions={contextOptions}
>
<TestComponent />
</SDKProvider>,
);

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(
<SDKProvider context={mockContext}>
Expand Down Expand Up @@ -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"
);
Comment on lines +227 to +229
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because isReactNative is a top-level const, we need to import this dynamically, after setting the navigator.product.value


render(
<RNSDKProvider
sdkOptions={{
endpoint: "https://sandbox.absmartly.io/v1",
apiKey: "test",
application: "www",
environment: "test",
}}
contextOptions={{ units: { user_id: "test" } }}
>
<div />
</RNSDKProvider>,
);

expect(SDK).toHaveBeenLastCalledWith(
expect.objectContaining({
agent: "absmartly-react-native-sdk",
}),
);
});
});
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading