Files
zooqueen 252e1cb076 Generated clients call the API where it is mounted
`insights/mount.py` is explicit: `/v1/` is the mount and `/api/` is the older
spelling, kept on the wire for released CLI builds and personal-API-key
holders and rewritten once at the edge by `ApiRewriteMiddleware`. Our own
frontend was still on the older spelling: the orval clients were generated
two days before the mount moved and the move did not regenerate them, so 70
files and 2323 paths said `/api/`.

That is not only a spelling. `prepareUrl` in `lib/api.ts` rewrites `/v1/*` to
the selected region's host in OAuth mode and nothing else, because that is
what the cloud CORS allowlist covers — so every generated call quietly stayed
same-origin, and `getExportsContentRetrieveUrl` builds an `<img src>` that
never reaches `lib/api.ts` at all.

The clients are regenerated from a spec that needs postgres, the datastore and
Django, so this is the path strings only, which is the whole of what the mount
move changes in them: orval copies paths verbatim from the spec, and the spec
takes them from the URLconf. Doc comments carried the same stale prefix and
move with them; their Python docstrings already say `/v1/`. The two frozen
OAuth client-metadata paths are identifiers rather than API surface and appear
in none of these files.

The Slack task prompt told the agent to POST to
`$INSIGHTS_API_URL/api/projects/...`, which is a live request path, not prose.
2026-08-24 23:13:08 -07:00

246 lines
7.8 KiB
TypeScript
Generated

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:
* insightscli build:openapi
* Questions or issues? #team-devex on Slack
*
* Insights API - generated
* OpenAPI spec version: 1.0.0
*/
import type {
AlertApi,
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
? `/v1/projects/${projectId}/alerts/?${stringifiedParams}`
: `/v1/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 `/v1/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
? `/v1/projects/${projectId}/alerts/${id}/?${stringifiedParams}`
: `/v1/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 `/v1/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 `/v1/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 `/v1/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 getAlertsTestDeliveryCreateUrl = (projectId: string, id: string) => {
return `/v1/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 `/v1/projects/${projectId}/alerts/simulate/`
}
/**
* Simulate a detector on an insight's historical data. Read-only — no AlertCheck records are created.
*/
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
? `/v1/projects/${projectId}/insights/${insightId}/thresholds/?${stringifiedParams}`
: `/v1/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 `/v1/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',
})
}