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