:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { apiMutator } from '../../../../frontend/src/lib/api-orval-mutator'
/**
* Auto-generated from the Django backend OpenAPI schema.
* To modify these types, update the Django serializers or views, then run:
* hogli build:openapi
* Questions or issues? #team-devex on Slack
*
* PostHog API - generated
* OpenAPI spec version: 1.0.0
*/
import type {
AlertApi,
AlertCreateDestinationApi,
AlertDeleteDestinationApi,
AlertDestinationResponseApi,
AlertSimulateApi,
AlertSimulateResponseApi,
AlertTestDeliveryResponseApi,
AlertsListParams,
AlertsRetrieveParams,
InsightsThresholdsListParams,
PaginatedAlertListApi,
PaginatedThresholdWithAlertListApi,
PatchedAlertApi,
ThresholdWithAlertApi,
} from './api.schemas'
// https://stackoverflow.com/questions/49579094/typescript-conditional-types-filter-out-readonly-properties-pick-only-requir/49579497#49579497
type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B
type WritableKeys<T> = {
[P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, P>
}[keyof T]
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
type DistributeReadOnlyOverUnions<T> = T extends any ? NonReadonly<T> : never
type Writable<T> = Pick<T, WritableKeys<T>>
type NonReadonly<T> = [T] extends [UnionToIntersection<T>]
? {
[P in keyof Writable<T>]: T[P] extends object ? NonReadonly<NonNullable<T[P]>> : T[P]
}
: DistributeReadOnlyOverUnions<T>
export const getAlertsListUrl = (projectId: string, params?: AlertsListParams) => {
const normalizedParams = new URLSearchParams()
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? 'null' : String(value))
}
})
const stringifiedParams = normalizedParams.toString()
return stringifiedParams.length > 0
? `/api/projects/${projectId}/alerts/?${stringifiedParams}`
: `/api/projects/${projectId}/alerts/`
}
export const alertsList = async (
projectId: string,
params?: AlertsListParams,
options?: RequestInit
): Promise<PaginatedAlertListApi> => {
return apiMutator<PaginatedAlertListApi>(getAlertsListUrl(projectId, params), {
...options,
method: 'GET',
})
}
export const getAlertsCreateUrl = (projectId: string) => {
return `/api/projects/${projectId}/alerts/`
}
export const alertsCreate = async (
projectId: string,
alertApi: NonReadonly<AlertApi>,
options?: RequestInit
): Promise<AlertApi> => {
return apiMutator<AlertApi>(getAlertsCreateUrl(projectId), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(alertApi),
})
}
export const getAlertsRetrieveUrl = (projectId: string, id: string, params?: AlertsRetrieveParams) => {
const normalizedParams = new URLSearchParams()
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? 'null' : String(value))
}
})
const stringifiedParams = normalizedParams.toString()
return stringifiedParams.length > 0
? `/api/projects/${projectId}/alerts/${id}/?${stringifiedParams}`
: `/api/projects/${projectId}/alerts/${id}/`
}
export const alertsRetrieve = async (
projectId: string,
id: string,
params?: AlertsRetrieveParams,
options?: RequestInit
): Promise<AlertApi> => {
return apiMutator<AlertApi>(getAlertsRetrieveUrl(projectId, id, params), {
...options,
method: 'GET',
})
}
export const getAlertsUpdateUrl = (projectId: string, id: string) => {
return `/api/projects/${projectId}/alerts/${id}/`
}
export const alertsUpdate = async (
projectId: string,
id: string,
alertApi: NonReadonly<AlertApi>,
options?: RequestInit
): Promise<AlertApi> => {
return apiMutator<AlertApi>(getAlertsUpdateUrl(projectId, id), {
...options,
method: 'PUT',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(alertApi),
})
}
export const getAlertsPartialUpdateUrl = (projectId: string, id: string) => {
return `/api/projects/${projectId}/alerts/${id}/`
}
export const alertsPartialUpdate = async (
projectId: string,
id: string,
patchedAlertApi?: NonReadonly<PatchedAlertApi>,
options?: RequestInit
): Promise<AlertApi> => {
return apiMutator<AlertApi>(getAlertsPartialUpdateUrl(projectId, id), {
...options,
method: 'PATCH',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(patchedAlertApi),
})
}
export const getAlertsDestroyUrl = (projectId: string, id: string) => {
return `/api/projects/${projectId}/alerts/${id}/`
}
export const alertsDestroy = async (projectId: string, id: string, options?: RequestInit): Promise<void> => {
return apiMutator<void>(getAlertsDestroyUrl(projectId, id), {
...options,
method: 'DELETE',
})
}
export const getAlertsDestinationsCreateUrl = (projectId: string, id: string) => {
return `/api/projects/${projectId}/alerts/${id}/destinations/`
}
/**
* Send this alert to a Slack channel as well as by email. The workspace must already be connected to the project. The returned IDs identify the destination.
*/
export const alertsDestinationsCreate = async (
projectId: string,
id: string,
alertCreateDestinationApi: AlertCreateDestinationApi,
options?: RequestInit
): Promise<AlertDestinationResponseApi> => {
return apiMutator<AlertDestinationResponseApi>(getAlertsDestinationsCreateUrl(projectId, id), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(alertCreateDestinationApi),
})
}
export const getAlertsDestinationsDeleteCreateUrl = (projectId: string, id: string) => {
return `/api/projects/${projectId}/alerts/${id}/destinations/delete/`
}
/**
* Stop sending this alert to a destination. The alert keeps its email recipients.
*/
export const alertsDestinationsDeleteCreate = async (
projectId: string,
id: string,
alertDeleteDestinationApi: AlertDeleteDestinationApi,
options?: RequestInit
): Promise<void> => {
return apiMutator<void>(getAlertsDestinationsDeleteCreateUrl(projectId, id), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(alertDeleteDestinationApi),
})
}
export const getAlertsTakeOwnershipCreateUrl = (projectId: string, id: string) => {
return `/api/projects/${projectId}/alerts/${id}/take_ownership/`
}
/**
* Make the requesting user the owner of this alert and enable it. Checks run with the owner's access, so this is how an alert continues after its owner left.
*/
export const alertsTakeOwnershipCreate = async (
projectId: string,
id: string,
options?: RequestInit
): Promise<AlertApi> => {
return apiMutator<AlertApi>(getAlertsTakeOwnershipCreateUrl(projectId, id), {
...options,
method: 'POST',
})
}
export const getAlertsTestDeliveryCreateUrl = (projectId: string, id: string) => {
return `/api/projects/${projectId}/alerts/${id}/test-delivery/`
}
/**
* Send a synthetic test notification to subscribed users and every active destination on this alert.
*/
export const alertsTestDeliveryCreate = async (
projectId: string,
id: string,
options?: RequestInit
): Promise<AlertTestDeliveryResponseApi> => {
return apiMutator<AlertTestDeliveryResponseApi>(getAlertsTestDeliveryCreateUrl(projectId, id), {
...options,
method: 'POST',
})
}
export const getAlertsSimulateCreateUrl = (projectId: string) => {
return `/api/projects/${projectId}/alerts/simulate/`
}
/**
* Simulate a detector on an insight's historical data. No AlertCheck records are created. The AI detector makes a real model call, so that mode needs the 'alert:write' scope.
*/
export const alertsSimulateCreate = async (
projectId: string,
alertSimulateApi: AlertSimulateApi,
options?: RequestInit
): Promise<AlertSimulateResponseApi> => {
return apiMutator<AlertSimulateResponseApi>(getAlertsSimulateCreateUrl(projectId), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(alertSimulateApi),
})
}
export const getInsightsThresholdsListUrl = (
projectId: string,
insightId: number,
params?: InsightsThresholdsListParams
) => {
const normalizedParams = new URLSearchParams()
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? 'null' : String(value))
}
})
const stringifiedParams = normalizedParams.toString()
return stringifiedParams.length > 0
? `/api/projects/${projectId}/insights/${insightId}/thresholds/?${stringifiedParams}`
: `/api/projects/${projectId}/insights/${insightId}/thresholds/`
}
export const insightsThresholdsList = async (
projectId: string,
insightId: number,
params?: InsightsThresholdsListParams,
options?: RequestInit
): Promise<PaginatedThresholdWithAlertListApi> => {
return apiMutator<PaginatedThresholdWithAlertListApi>(getInsightsThresholdsListUrl(projectId, insightId, params), {
...options,
method: 'GET',
})
}
export const getInsightsThresholdsRetrieveUrl = (projectId: string, insightId: number, id: string) => {
return `/api/projects/${projectId}/insights/${insightId}/thresholds/${id}/`
}
export const insightsThresholdsRetrieve = async (
projectId: string,
insightId: number,
id: string,
options?: RequestInit
): Promise<ThresholdWithAlertApi> => {
return apiMutator<ThresholdWithAlertApi>(getInsightsThresholdsRetrieveUrl(projectId, insightId, id), {
...options,
method: 'GET',
})
}