Add better typing for headers
This commit is contained in:
parent
bac341fdca
commit
2c40b9a6b2
|
@ -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]
|
||||
},
|
||||
|
|
|
@ -8,9 +8,11 @@ export enum HTTPMethod {
|
|||
DELETE = "DELETE",
|
||||
}
|
||||
|
||||
export type Headers = Record<string, string>
|
||||
|
||||
export type APIClientConfig = {
|
||||
enableCaching?: boolean
|
||||
attachHeaders?: (headers: Record<string, string>) => void
|
||||
attachHeaders?: (headers: Headers) => void
|
||||
onError?: (error: any) => void
|
||||
onMigrationDetected?: (migration: string) => void
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue