budibase/packages/frontend-core/src/api/analytics.ts

36 lines
856 B
TypeScript
Raw Normal View History

import { BaseAPIClient } from "./types"
2024-12-02 11:02:30 +01:00
import { AnalyticsPingRequest } from "@budibase/types"
export interface AnalyticsEndpoints {
getAnalyticsStatus: () => Promise<{ enabled: boolean }>
2024-12-02 11:02:30 +01:00
analyticsPing: (
payload: Omit<AnalyticsPingRequest, "timezone">
) => 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",
})
},
2024-12-02 11:02:30 +01:00
/**
* Notifies analytics of a certain environment
*/
2024-12-02 11:02:30 +01:00
analyticsPing: async request => {
return await API.post<AnalyticsPingRequest>({
url: "/api/bbtel/ping",
2024-12-02 11:02:30 +01:00
body: {
...request,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
},
})
},
})