From a585ba1785b7397d0d0fc9aa83d317cd21b86af7 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 3 Dec 2024 12:00:52 +0000 Subject: [PATCH] Type self endpoints --- .../src/api/{self.js => self.ts} | 26 ++++++++++++++++--- packages/frontend-core/src/api/types.ts | 4 ++- 2 files changed, 25 insertions(+), 5 deletions(-) rename packages/frontend-core/src/api/{self.js => self.ts} (58%) diff --git a/packages/frontend-core/src/api/self.js b/packages/frontend-core/src/api/self.ts similarity index 58% rename from packages/frontend-core/src/api/self.js rename to packages/frontend-core/src/api/self.ts index cdd5eaba53..9e8c806b2f 100644 --- a/packages/frontend-core/src/api/self.js +++ b/packages/frontend-core/src/api/self.ts @@ -1,11 +1,30 @@ -export const buildSelfEndpoints = API => ({ +import { + ContextUser, + UpdateSelfRequest, + UpdateSelfResponse, + User, +} from "@budibase/types" +import { BaseAPIClient } from "./types" + +export interface SelfEndpoints { + updateSelf: (user: UpdateSelfRequest) => Promise + + // Missing request or response types + generateAPIKey: () => Promise + fetchDeveloperInfo: () => Promise + + // There are flags and session attributes mixed in to the user + fetchBuilderSelf: () => Promise + fetchSelf: () => Promise<(ContextUser | {}) & { [key: string]: any }> +} + +export const buildSelfEndpoints = (API: BaseAPIClient): SelfEndpoints => ({ /** * Using the logged in user, this will generate a new API key, * assuming the user is a builder. - * @return {Promise} returns the API response, including an API key. */ generateAPIKey: async () => { - const response = await API.post({ + const response = await API.post({ url: "/api/global/self/api_key", }) return response?.apiKey @@ -13,7 +32,6 @@ export const buildSelfEndpoints = API => ({ /** * retrieves the API key for the logged in user. - * @return {Promise} An object containing the user developer information. */ fetchDeveloperInfo: async () => { return API.get({ diff --git a/packages/frontend-core/src/api/types.ts b/packages/frontend-core/src/api/types.ts index 6b87fcd53e..75acab3a66 100644 --- a/packages/frontend-core/src/api/types.ts +++ b/packages/frontend-core/src/api/types.ts @@ -26,6 +26,7 @@ import { RouteEndpoints } from "./routes" import { RowActionEndpoints } from "./rowActions" import { RowEndpoints } from "./rows" import { ScreenEndpoints } from "./screens" +import { SelfEndpoints } from "./self" export enum HTTPMethod { POST = "POST", @@ -122,4 +123,5 @@ export type APIClient = BaseAPIClient & RoleEndpoints & RouteEndpoints & RowEndpoints & - ScreenEndpoints & { rowActions: RowActionEndpoints; [key: string]: any } + ScreenEndpoints & + SelfEndpoints & { rowActions: RowActionEndpoints; [key: string]: any }