Strengthen types of some endpoints

This commit is contained in:
Andrew Kingston 2024-12-02 10:02:30 +00:00
parent 417040f2d5
commit 00359d8e06
No known key found for this signature in database
4 changed files with 21 additions and 15 deletions

View File

@ -8,7 +8,7 @@ export const buildAIEndpoints = (API: BaseAPIClient): AIEndpoints => ({
/**
* Generates a cron expression from a prompt
*/
generateCronExpression: async (prompt: string) => {
generateCronExpression: async prompt => {
return await API.post({
url: "/api/ai/cron",
body: { prompt },

View File

@ -1,13 +1,11 @@
import { BaseAPIClient } from "./types"
type AnalyticsPingRequest = {
source?: string
embedded?: boolean
}
import { AnalyticsPingRequest } from "@budibase/types"
export interface AnalyticsEndpoints {
getAnalyticsStatus: () => Promise<{ enabled: boolean }>
analyticsPing: (payload: AnalyticsPingRequest) => Promise<void>
analyticsPing: (
payload: Omit<AnalyticsPingRequest, "timezone">
) => Promise<void>
}
export const buildAnalyticsEndpoints = (
@ -21,14 +19,17 @@ export const buildAnalyticsEndpoints = (
url: "/api/bbtel",
})
},
/**
* Notifies analytics of a certain environment
*/
analyticsPing: async (payload: AnalyticsPingRequest) => {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
return await API.post({
analyticsPing: async request => {
return await API.post<AnalyticsPingRequest>({
url: "/api/bbtel/ping",
body: { source: payload.source, embedded: payload.embedded, timezone },
body: {
...request,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
},
})
},
})

View File

@ -234,7 +234,7 @@ export const buildAppEndpoints = (API: BaseAPIClient): AppEndpoints => ({
/**
* Fetches the definitions for component library components. This includes
* their props and other metadata from components.json.
* @param {string} appId - ID of the currently running app
* @param appId ID of the currently running app
*/
fetchComponentLibDefinitions: async appId => {
return await API.get({

View File

@ -1,3 +1,8 @@
import {
LoginRequest,
PasswordResetRequest,
PasswordResetUpdateRequest,
} from "@budibase/types"
import { BaseAPIClient } from "./types"
export interface AuthEndpoints {
@ -26,7 +31,7 @@ export const buildAuthEndpoints = (API: BaseAPIClient): AuthEndpoints => ({
* @param password the password
*/
logIn: async (tenantId, username, password) => {
return await API.post({
return await API.post<LoginRequest>({
url: `/api/global/auth/${tenantId}/login`,
body: {
username,
@ -70,7 +75,7 @@ export const buildAuthEndpoints = (API: BaseAPIClient): AuthEndpoints => ({
* @param email the email address of the user
*/
requestForgotPassword: async (tenantId, email) => {
return await API.post({
return await API.post<PasswordResetRequest, { message: string }>({
url: `/api/global/auth/${tenantId}/reset`,
body: {
email,
@ -85,7 +90,7 @@ export const buildAuthEndpoints = (API: BaseAPIClient): AuthEndpoints => ({
* @param resetCode the reset code to authenticate the request
*/
resetPassword: async (tenantId, password, resetCode) => {
return await API.post({
return await API.post<PasswordResetUpdateRequest, { message: string }>({
url: `/api/global/auth/${tenantId}/reset/update`,
body: {
password,