From 6c98509fd65f04216cf915ec0f766dc248dc6f5c Mon Sep 17 00:00:00 2001 From: Anxo Rodriguez Date: Wed, 8 May 2024 15:31:28 +0300 Subject: [PATCH] Allow to set your own headers and your API KEY (#25) --- src/lib.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib.ts b/src/lib.ts index 23612fc..c79a212 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -5,14 +5,28 @@ import type { paths } from "./gen/types"; export interface CmsClientOptions { url?: string; + apiKey?: string; + headers?: Record; } /** * Open API Fetch client. See docs for usage https://openapi-ts.pages.dev/openapi-fetch/ */ export function CmsClient(options: CmsClientOptions = {}) { - const { url = "https://cms.cow.fi/api" } = options; + const { + url = "https://cms.cow.fi/api", + headers: baseHeaders = {}, + apiKey, + } = options; return createClient({ baseUrl: url, + headers: { + ...baseHeaders, + ...(apiKey + ? { + Authorization: "Bearer " + apiKey, + } + : {}), + }, }); }