chore(api-client): type header merging

Replace the Headers branch's any cast with a typed copy into a Record so the shared API client keeps the same header merge behavior without a no-explicit-any warning.

Verification: pnpm --filter @bytelyst/api-client build; pnpm --filter @bytelyst/api-client test; pnpm --filter @bytelyst/api-client exec eslint . --ext .ts,.tsx; pnpm lint.
This commit is contained in:
Saravana Achu Mac 2026-05-04 15:17:33 -07:00
parent 41af641c54
commit 46900728d3

View File

@ -42,9 +42,10 @@ export function createApiClient(config: ApiClientConfig): ApiClient {
function buildHeaders(options?: RequestInit): HeadersInit {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
'x-request-id': typeof globalThis.crypto?.randomUUID === 'function'
? globalThis.crypto.randomUUID()
: `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,
'x-request-id':
typeof globalThis.crypto?.randomUUID === 'function'
? globalThis.crypto.randomUUID()
: `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,
...defaultHeaders,
};
@ -56,12 +57,16 @@ export function createApiClient(config: ApiClientConfig): ApiClient {
}
if (options?.headers) {
const extra =
options.headers instanceof Headers
? Object.fromEntries(options.headers as any)
: Array.isArray(options.headers)
? Object.fromEntries(options.headers)
: (options.headers as Record<string, string>);
const extra: Record<string, string> = {};
if (options.headers instanceof Headers) {
options.headers.forEach((value, key) => {
extra[key] = value;
});
} else if (Array.isArray(options.headers)) {
Object.assign(extra, Object.fromEntries(options.headers));
} else {
Object.assign(extra, options.headers);
}
Object.assign(headers, extra);
}