diff --git a/packages/frontend-core/src/api/index.ts b/packages/frontend-core/src/api/index.ts index 47900ba029..670d2cb19f 100644 --- a/packages/frontend-core/src/api/index.ts +++ b/packages/frontend-core/src/api/index.ts @@ -5,6 +5,7 @@ import { APIClient, APICallConfig, BaseAPIClient, + Headers, } from "./types" import { Helpers } from "@budibase/bbui" import { Header } from "@budibase/shared-core" @@ -110,7 +111,7 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => { json = json && method !== HTTPMethod.GET // Build headers - let headers = { Accept: "application/json" } + let headers: Headers = { Accept: "application/json" } headers[Header.SESSION_ID] = APISessionID if (!external) { headers[Header.API_VER] = ApiVersion @@ -237,7 +238,7 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => { // Generic utility to extract the current app ID. Assumes that any client // that exists in an app context will be attaching our app ID header. getAppID: (): string => { - let headers = {} + let headers: Headers = {} config?.attachHeaders?.(headers) return headers?.[Header.APP_ID] }, diff --git a/packages/frontend-core/src/api/types.ts b/packages/frontend-core/src/api/types.ts index f083d14dd7..a5f702053c 100644 --- a/packages/frontend-core/src/api/types.ts +++ b/packages/frontend-core/src/api/types.ts @@ -8,9 +8,11 @@ export enum HTTPMethod { DELETE = "DELETE", } +export type Headers = Record + export type APIClientConfig = { enableCaching?: boolean - attachHeaders?: (headers: Record) => void + attachHeaders?: (headers: Headers) => void onError?: (error: any) => void onMigrationDetected?: (migration: string) => void }