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