Fix some TS errors and type API errors

This commit is contained in:
Andrew Kingston 2024-12-03 07:13:18 +00:00
parent 7a437aad04
commit 20384673f2
No known key found for this signature in database
3 changed files with 21 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import {
APICallConfig, APICallConfig,
BaseAPIClient, BaseAPIClient,
Headers, Headers,
APIError,
} from "./types" } from "./types"
import { Helpers } from "@budibase/bbui" import { Helpers } from "@budibase/bbui"
import { Header } from "@budibase/shared-core" import { Header } from "@budibase/shared-core"
@ -64,7 +65,7 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => {
response: Response, response: Response,
method: HTTPMethod, method: HTTPMethod,
suppressErrors = false suppressErrors = false
) => { ): Promise<APIError> => {
// Try to read a message from the error // Try to read a message from the error
let message = response.statusText let message = response.statusText
let json: any = null let json: any = null
@ -90,7 +91,11 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => {
} }
// Generates an error object from a string // Generates an error object from a string
const makeError = (message: string, url?: string, method?: HTTPMethod) => { const makeError = (
message: string,
url?: string,
method?: HTTPMethod
): APIError => {
return { return {
message, message,
json: null, json: null,
@ -98,6 +103,7 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => {
url: url, url: url,
method: method, method: method,
handled: true, handled: true,
suppressErrors: false,
} }
} }

View File

@ -11,10 +11,10 @@ import { BaseAPIClient } from "./types"
export interface LicensingEndpoints { export interface LicensingEndpoints {
activateLicenseKey: (licenseKey: string) => Promise<void> activateLicenseKey: (licenseKey: string) => Promise<void>
deleteLicenseKey: () => Promise<void> deleteLicenseKey: () => Promise<void>
getLicenseKey: () => Promise<GetLicenseKeyResponse> getLicenseKey: () => Promise<GetLicenseKeyResponse | void>
activateOfflineLicense: (offlineLicenseToken: string) => Promise<void> activateOfflineLicense: (offlineLicenseToken: string) => Promise<void>
deleteOfflineLicense: () => Promise<void> deleteOfflineLicense: () => Promise<void>
getOfflineLicense: () => Promise<GetOfflineLicenseTokenResponse> getOfflineLicense: () => Promise<GetOfflineLicenseTokenResponse | void>
getOfflineLicenseIdentifier: () => Promise<GetOfflineIdentifierResponse> getOfflineLicenseIdentifier: () => Promise<GetOfflineIdentifierResponse>
refreshLicense: () => Promise<void> refreshLicense: () => Promise<void>
getQuotaUsage: () => Promise<QuotaUsage> getQuotaUsage: () => Promise<QuotaUsage>
@ -24,7 +24,6 @@ export const buildLicensingEndpoints = (
API: BaseAPIClient API: BaseAPIClient
): LicensingEndpoints => ({ ): LicensingEndpoints => ({
// LICENSE KEY // LICENSE KEY
activateLicenseKey: async licenseKey => { activateLicenseKey: async licenseKey => {
return API.post<ActivateLicenseKeyRequest>({ return API.post<ActivateLicenseKeyRequest>({
url: `/api/global/license/key`, url: `/api/global/license/key`,
@ -49,7 +48,6 @@ export const buildLicensingEndpoints = (
}, },
// OFFLINE LICENSE // OFFLINE LICENSE
activateOfflineLicense: async offlineLicenseToken => { activateOfflineLicense: async offlineLicenseToken => {
return API.post<ActivateOfflineLicenseTokenRequest>({ return API.post<ActivateOfflineLicenseTokenRequest>({
url: "/api/global/license/offline", url: "/api/global/license/offline",

View File

@ -73,6 +73,16 @@ export type BaseAPIClient = {
getAppID: () => string getAppID: () => string
} }
export type APIError = {
message?: string
json: any
status: number
url: string
method: HTTPMethod
handled: boolean
suppressErrors: boolean
}
export type APIClient = BaseAPIClient & export type APIClient = BaseAPIClient &
AIEndpoints & AIEndpoints &
AnalyticsEndpoints & AnalyticsEndpoints &
@ -89,4 +99,4 @@ export type APIClient = BaseAPIClient &
FlagEndpoints & FlagEndpoints &
GroupEndpoints & GroupEndpoints &
LayoutEndpoints & LayoutEndpoints &
LicensingEndpoints LicensingEndpoints & { [key: string]: any }