Update AI and analytics endpoints to TS

This commit is contained in:
Andrew Kingston 2024-11-26 16:51:02 +00:00
parent d50df9a650
commit 1e535d36b7
No known key found for this signature in database
7 changed files with 60 additions and 34 deletions

View File

@ -98,9 +98,7 @@
async function generateAICronExpression() { async function generateAICronExpression() {
loadingAICronExpression = true loadingAICronExpression = true
try { try {
const response = await API.generateCronExpression({ const response = await API.generateCronExpression(aiCronPrompt)
prompt: aiCronPrompt,
})
cronExpression = response.message cronExpression = response.message
dispatch("change", response.message) dispatch("change", response.message)
} catch (err) { } catch (err) {

View File

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

View File

@ -0,0 +1,17 @@
import { BaseAPIClient } from "./types"
export interface AIEndpoints {
generateCronExpression: (prompt: string) => Promise<{ message: string }>
}
export const buildAIEndpoints = (API: BaseAPIClient): AIEndpoints => ({
/**
* Generates a cron expression from a prompt
*/
generateCronExpression: async (prompt: string) => {
return await API.post({
url: "/api/ai/cron",
body: { prompt },
})
},
})

View File

@ -1,17 +0,0 @@
export const buildAnalyticsEndpoints = API => ({
/**
* Gets the current status of analytics for this environment
*/
getAnalyticsStatus: async () => {
return await API.get({
url: "/api/bbtel",
})
},
analyticsPing: async ({ source, embedded }) => {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
return await API.post({
url: "/api/bbtel/ping",
body: { source, timezone, embedded },
})
},
})

View File

@ -0,0 +1,34 @@
import { BaseAPIClient } from "./types"
type AnalyticsPingRequest = {
source?: string
embedded?: boolean
}
export interface AnalyticsEndpoints {
getAnalyticsStatus: () => Promise<{ enabled: boolean }>
analyticsPing: (payload: AnalyticsPingRequest) => Promise<void>
}
export const buildAnalyticsEndpoints = (
API: BaseAPIClient
): AnalyticsEndpoints => ({
/**
* Gets the current status of analytics for this environment
*/
getAnalyticsStatus: async () => {
return await API.get({
url: "/api/bbtel",
})
},
/**
* Notifies analytics of a certain environment
*/
analyticsPing: async (payload: AnalyticsPingRequest) => {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
return await API.post({
url: "/api/bbtel/ping",
body: { source: payload.source, embedded: payload.embedded, timezone },
})
},
})

View File

@ -11,7 +11,7 @@ import {
UpdateAppResponse, UpdateAppResponse,
} from "@budibase/types" } from "@budibase/types"
export type AppEndpoints = { export interface AppEndpoints {
fetchAppPackage: (appId: string) => Promise<FetchAppPackageResponse> fetchAppPackage: (appId: string) => Promise<FetchAppPackageResponse>
saveAppMetadata: ( saveAppMetadata: (
appId: string, appId: string,
@ -40,7 +40,7 @@ export type AppEndpoints = {
) => Promise<App> ) => Promise<App>
addSampleData: (appId: string) => Promise<void> addSampleData: (appId: string) => Promise<void>
// Untyped - TODO: // TODO
publishAppChanges: (appId: string) => Promise<any> publishAppChanges: (appId: string) => Promise<any>
revertAppChanges: (appId: string) => Promise<any> revertAppChanges: (appId: string) => Promise<any>
updateAppClientVersion: (appId: string) => Promise<any> updateAppClientVersion: (appId: string) => Promise<any>

View File

@ -1,3 +1,5 @@
import { AIEndpoints } from "./ai"
import { AnalyticsEndpoints } from "./analytics"
import { AppEndpoints } from "./app" import { AppEndpoints } from "./app"
export enum HTTPMethod { export enum HTTPMethod {
@ -41,4 +43,7 @@ export type BaseAPIClient = {
getAppID: () => string getAppID: () => string
} }
export type APIClient = BaseAPIClient & AppEndpoints & { [key: string]: any } export type APIClient = BaseAPIClient &
AIEndpoints &
AnalyticsEndpoints &
AppEndpoints & { [key: string]: any }