Skip to content
Open
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
16 changes: 1 addition & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
},
"dependencies": {
"axios": "^1.17.0",
"socket.io-client": "^4.8.3",
"uuid": "^13.0.2"
"socket.io-client": "^4.8.3"
},
"devDependencies": {
"@types/hast": "^3.0.4",
Expand Down
8 changes: 5 additions & 3 deletions src/utils/axios-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import axios from "axios";
import { isInIFrame } from "./common.js";
import { v4 as uuidv4 } from "uuid";
import { isInIFrame, generateUuid } from "./common.js";
import { getAnalyticsSessionId } from "../modules/analytics.js";
import type { Base44ErrorJSON } from "./axios-client.types.js";

Expand Down Expand Up @@ -186,7 +185,10 @@ export function createAxiosClient({
config.headers.set("X-Base44-Anonymous-Id", getAnalyticsSessionId());
}
}
const requestId = uuidv4();
// Correlation id for the in-iframe request logging below; only needs to be
// unique, not cryptographically random. `uuid` would pull in
// `crypto.getRandomValues`, which React Native lacks, so use `generateUuid`.
const requestId = generateUuid();
(config as any).requestId = requestId;
if (isInIFrame) {
try {
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/react-native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,26 @@ describe("React Native environment", () => {
expect(isNode).toBe(false);
expect(isReactNative).toBe(true);
});

test("requests succeed without crypto.getRandomValues", async () => {
stubReactNativeGlobals();
// React Native (Hermes) has no `crypto.getRandomValues`; the request
// interceptor's correlation id must not depend on it (the `uuid` lib does).
vi.stubGlobal("crypto", undefined);
vi.resetModules();
const { createAxiosClient } = await import(
"../../src/utils/axios-client.ts"
);

const client = createAxiosClient({ baseURL: "https://api.base44.com" });
let captured: any;
client.defaults.adapter = async (config) => {
captured = config;
return { data: {}, status: 200, statusText: "OK", headers: {}, config };
};

await expect(client.get("/health")).resolves.toBeDefined();
// The interceptor still attaches a unique correlation id.
expect(captured.requestId).toBeTruthy();
});
});
Loading