diff --git a/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte b/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte index fd235a70f2..133d5c9eb1 100644 --- a/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte +++ b/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte @@ -98,9 +98,7 @@ async function generateAICronExpression() { loadingAICronExpression = true try { - const response = await API.generateCronExpression({ - prompt: aiCronPrompt, - }) + const response = await API.generateCronExpression(aiCronPrompt) cronExpression = response.message dispatch("change", response.message) } catch (err) { diff --git a/packages/frontend-core/src/api/ai.js b/packages/frontend-core/src/api/ai.js deleted file mode 100644 index 7fa756a19e..0000000000 --- a/packages/frontend-core/src/api/ai.js +++ /dev/null @@ -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 }, - }) - }, -}) diff --git a/packages/frontend-core/src/api/ai.ts b/packages/frontend-core/src/api/ai.ts new file mode 100644 index 0000000000..c6adb45b3c --- /dev/null +++ b/packages/frontend-core/src/api/ai.ts @@ -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 }, + }) + }, +}) diff --git a/packages/frontend-core/src/api/analytics.js b/packages/frontend-core/src/api/analytics.js deleted file mode 100644 index df56bc938e..0000000000 --- a/packages/frontend-core/src/api/analytics.js +++ /dev/null @@ -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 }, - }) - }, -}) diff --git a/packages/frontend-core/src/api/analytics.ts b/packages/frontend-core/src/api/analytics.ts new file mode 100644 index 0000000000..fb97599b6e --- /dev/null +++ b/packages/frontend-core/src/api/analytics.ts @@ -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 +} + +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 }, + }) + }, +}) diff --git a/packages/frontend-core/src/api/app.ts b/packages/frontend-core/src/api/app.ts index b884f618bb..12e1500cfe 100644 --- a/packages/frontend-core/src/api/app.ts +++ b/packages/frontend-core/src/api/app.ts @@ -11,7 +11,7 @@ import { UpdateAppResponse, } from "@budibase/types" -export type AppEndpoints = { +export interface AppEndpoints { fetchAppPackage: (appId: string) => Promise saveAppMetadata: ( appId: string, @@ -40,7 +40,7 @@ export type AppEndpoints = { ) => Promise addSampleData: (appId: string) => Promise - // Untyped - TODO: + // TODO publishAppChanges: (appId: string) => Promise revertAppChanges: (appId: string) => Promise updateAppClientVersion: (appId: string) => Promise diff --git a/packages/frontend-core/src/api/types.ts b/packages/frontend-core/src/api/types.ts index a5f702053c..257e34d3a3 100644 --- a/packages/frontend-core/src/api/types.ts +++ b/packages/frontend-core/src/api/types.ts @@ -1,3 +1,5 @@ +import { AIEndpoints } from "./ai" +import { AnalyticsEndpoints } from "./analytics" import { AppEndpoints } from "./app" export enum HTTPMethod { @@ -41,4 +43,7 @@ export type BaseAPIClient = { getAppID: () => string } -export type APIClient = BaseAPIClient & AppEndpoints & { [key: string]: any } +export type APIClient = BaseAPIClient & + AIEndpoints & + AnalyticsEndpoints & + AppEndpoints & { [key: string]: any }