diff --git a/packages/api-client/src/client.ts b/packages/api-client/src/client.ts index d55141e5..82309665 100644 --- a/packages/api-client/src/client.ts +++ b/packages/api-client/src/client.ts @@ -42,9 +42,10 @@ export function createApiClient(config: ApiClientConfig): ApiClient { function buildHeaders(options?: RequestInit): HeadersInit { const headers: Record = { '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); + const extra: Record = {}; + 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); }