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

508 lines
19 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 {
GenerateSurveyTranslationsRequestApi,
GenerateSurveyTranslationsResponseApi,
PaginatedSurveyListApi,
PatchedSurveySerializerCreateUpdateOnlySchemaApi,
SurveyApi,
SurveyGlobalStatsResponseApi,
SurveyQuestionLabelsResponseApi,
SurveyResponsesListApi,
SurveySerializerCreateUpdateOnlyApi,
SurveySerializerCreateUpdateOnlySchemaApi,
SurveyStatsResponseApi,
SurveySummarizeRequestApi,
SurveysGlobalStatsRetrieveParams,
SurveysListParams,
SurveysResponsesListParams,
SurveysStatsRetrieveParams,
SurveysSummarizeResponsesCreateParams,
} 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 getSurveysListUrl = (projectId: string, params?: SurveysListParams) => {
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}/surveys/?${stringifiedParams}`
: `/v1/projects/${projectId}/surveys/`
}
export const surveysList = async (
projectId: string,
params?: SurveysListParams,
options?: RequestInit
): Promise<PaginatedSurveyListApi> => {
return apiMutator<PaginatedSurveyListApi>(getSurveysListUrl(projectId, params), {
...options,
method: 'GET',
})
}
export const getSurveysCreateUrl = (projectId: string) => {
return `/v1/projects/${projectId}/surveys/`
}
export const surveysCreate = async (
projectId: string,
surveySerializerCreateUpdateOnlySchemaApi: NonReadonly<SurveySerializerCreateUpdateOnlySchemaApi>,
options?: RequestInit
): Promise<SurveySerializerCreateUpdateOnlyApi> => {
return apiMutator<SurveySerializerCreateUpdateOnlyApi>(getSurveysCreateUrl(projectId), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(surveySerializerCreateUpdateOnlySchemaApi),
})
}
export const getSurveysRetrieveUrl = (projectId: string, id: string) => {
return `/v1/projects/${projectId}/surveys/${id}/`
}
export const surveysRetrieve = async (projectId: string, id: string, options?: RequestInit): Promise<SurveyApi> => {
return apiMutator<SurveyApi>(getSurveysRetrieveUrl(projectId, id), {
...options,
method: 'GET',
})
}
export const getSurveysUpdateUrl = (projectId: string, id: string) => {
return `/v1/projects/${projectId}/surveys/${id}/`
}
export const surveysUpdate = async (
projectId: string,
id: string,
surveyApi: NonReadonly<SurveyApi>,
options?: RequestInit
): Promise<SurveyApi> => {
return apiMutator<SurveyApi>(getSurveysUpdateUrl(projectId, id), {
...options,
method: 'PUT',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(surveyApi),
})
}
export const getSurveysPartialUpdateUrl = (projectId: string, id: string) => {
return `/v1/projects/${projectId}/surveys/${id}/`
}
export const surveysPartialUpdate = async (
projectId: string,
id: string,
patchedSurveySerializerCreateUpdateOnlySchemaApi?: NonReadonly<PatchedSurveySerializerCreateUpdateOnlySchemaApi>,
options?: RequestInit
): Promise<SurveySerializerCreateUpdateOnlyApi> => {
return apiMutator<SurveySerializerCreateUpdateOnlyApi>(getSurveysPartialUpdateUrl(projectId, id), {
...options,
method: 'PATCH',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(patchedSurveySerializerCreateUpdateOnlySchemaApi),
})
}
export const getSurveysDestroyUrl = (projectId: string, id: string) => {
return `/v1/projects/${projectId}/surveys/${id}/`
}
export const surveysDestroy = async (projectId: string, id: string, options?: RequestInit): Promise<void> => {
return apiMutator<void>(getSurveysDestroyUrl(projectId, id), {
...options,
method: 'DELETE',
})
}
export const getSurveysActivityRetrieveUrl = (projectId: string, id: string) => {
return `/v1/projects/${projectId}/surveys/${id}/activity/`
}
export const surveysActivityRetrieve = async (projectId: string, id: string, options?: RequestInit): Promise<void> => {
return apiMutator<void>(getSurveysActivityRetrieveUrl(projectId, id), {
...options,
method: 'GET',
})
}
export const getSurveysArchivedResponseUuidsRetrieveUrl = (projectId: string, id: string) => {
return `/v1/projects/${projectId}/surveys/${id}/archived-response-uuids/`
}
/**
* Get list of archived response UUIDs for InsightsQL filtering.
*
* Returns list of UUIDs that the frontend can use to filter out archived responses
* in InsightsQL queries.
*/
export const surveysArchivedResponseUuidsRetrieve = async (
projectId: string,
id: string,
options?: RequestInit
): Promise<void> => {
return apiMutator<void>(getSurveysArchivedResponseUuidsRetrieveUrl(projectId, id), {
...options,
method: 'GET',
})
}
export const getSurveysDuplicateToProjectsCreateUrl = (projectId: string, id: string) => {
return `/v1/projects/${projectId}/surveys/${id}/duplicate_to_projects/`
}
/**
* Duplicate a survey to multiple projects in a single transaction.
*
* Accepts a list of target team IDs and creates a copy of the survey in each project.
* Uses an all-or-nothing approach - if any duplication fails, all changes are rolled back.
*/
export const surveysDuplicateToProjectsCreate = async (
projectId: string,
id: string,
surveySerializerCreateUpdateOnlyApi: NonReadonly<SurveySerializerCreateUpdateOnlyApi>,
options?: RequestInit
): Promise<void> => {
return apiMutator<void>(getSurveysDuplicateToProjectsCreateUrl(projectId, id), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(surveySerializerCreateUpdateOnlyApi),
})
}
export const getSurveysGenerateTranslationsCreateUrl = (projectId: string, id: string) => {
return `/v1/projects/${projectId}/surveys/${id}/generate_translations/`
}
export const surveysGenerateTranslationsCreate = async (
projectId: string,
id: string,
generateSurveyTranslationsRequestApi: GenerateSurveyTranslationsRequestApi,
options?: RequestInit
): Promise<GenerateSurveyTranslationsResponseApi> => {
return apiMutator<GenerateSurveyTranslationsResponseApi>(getSurveysGenerateTranslationsCreateUrl(projectId, id), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(generateSurveyTranslationsRequestApi),
})
}
export const getSurveysLaunchUrl = (projectId: string, id: string) => {
return `/v1/projects/${projectId}/surveys/${id}/launch/`
}
/**
* Launch a survey by setting `start_date` to the current time. No-op if the survey is already launched (start_date set in the past) — returns the existing state unchanged. Does not affect archived surveys or surveys with an end_date in the past; unarchive or extend the end_date first.
*/
export const surveysLaunch = async (projectId: string, id: string, options?: RequestInit): Promise<SurveyApi> => {
return apiMutator<SurveyApi>(getSurveysLaunchUrl(projectId, id), {
...options,
method: 'POST',
})
}
export const getSurveysResponsesListUrl = (projectId: string, id: string, params?: SurveysResponsesListParams) => {
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}/surveys/${id}/responses/?${stringifiedParams}`
: `/v1/projects/${projectId}/surveys/${id}/responses/`
}
/**
* List survey responses for a specific survey, with question text resolved server-side so callers do not have to map opaque `$survey_response_<id>` keys. Each row carries `distinct_id`, `session_id`, `submitted_at`, and an `extra` block (device, browser, OS, geoip, current_url, iteration) so agents can cross-pivot to recordings, persons, or paths in a single follow-up call. For person properties at event time, follow up with `persons-get` using the returned `distinct_id` — keeps scopes scoped. Use `question_id` + `score_lte` to fetch NPS detractors and similar score-filtered cohorts.
*/
export const surveysResponsesList = async (
projectId: string,
id: string,
params?: SurveysResponsesListParams,
options?: RequestInit
): Promise<SurveyResponsesListApi> => {
return apiMutator<SurveyResponsesListApi>(getSurveysResponsesListUrl(projectId, id, params), {
...options,
method: 'GET',
})
}
export const getSurveysResponsesArchiveCreateUrl = (projectId: string, id: string, responseUuid: string) => {
return `/v1/projects/${projectId}/surveys/${id}/responses/${responseUuid}/archive/`
}
/**
* Archive a single survey response.
*/
export const surveysResponsesArchiveCreate = async (
projectId: string,
id: string,
responseUuid: string,
surveySerializerCreateUpdateOnlyApi: NonReadonly<SurveySerializerCreateUpdateOnlyApi>,
options?: RequestInit
): Promise<void> => {
return apiMutator<void>(getSurveysResponsesArchiveCreateUrl(projectId, id, responseUuid), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(surveySerializerCreateUpdateOnlyApi),
})
}
export const getSurveysResponsesUnarchiveCreateUrl = (projectId: string, id: string, responseUuid: string) => {
return `/v1/projects/${projectId}/surveys/${id}/responses/${responseUuid}/unarchive/`
}
/**
* Unarchive a single survey response.
*/
export const surveysResponsesUnarchiveCreate = async (
projectId: string,
id: string,
responseUuid: string,
surveySerializerCreateUpdateOnlyApi: NonReadonly<SurveySerializerCreateUpdateOnlyApi>,
options?: RequestInit
): Promise<void> => {
return apiMutator<void>(getSurveysResponsesUnarchiveCreateUrl(projectId, id, responseUuid), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(surveySerializerCreateUpdateOnlyApi),
})
}
export const getSurveysStatsRetrieveUrl = (projectId: string, id: string, params?: SurveysStatsRetrieveParams) => {
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}/surveys/${id}/stats/?${stringifiedParams}`
: `/v1/projects/${projectId}/surveys/${id}/stats/`
}
/**
* Get survey response statistics for a specific survey.
*
* Args:
* date_from: Optional ISO timestamp for start date (e.g. 2024-01-01T00:00:00Z)
* date_to: Optional ISO timestamp for end date (e.g. 2024-01-31T23:59:59Z)
* exclude_archived: Optional boolean to exclude archived responses (default: false, includes archived)
* include_per_question_stats: Optional boolean to include per-question response counts and distributions
*
* Returns:
* Survey statistics including event counts, unique respondents, and conversion rates
*/
export const surveysStatsRetrieve = async (
projectId: string,
id: string,
params?: SurveysStatsRetrieveParams,
options?: RequestInit
): Promise<SurveyStatsResponseApi> => {
return apiMutator<SurveyStatsResponseApi>(getSurveysStatsRetrieveUrl(projectId, id, params), {
...options,
method: 'GET',
})
}
export const getSurveysStopUrl = (projectId: string, id: string) => {
return `/v1/projects/${projectId}/surveys/${id}/stop/`
}
/**
* Stop a survey by setting `end_date` to the current time. No new responses are accepted after this; existing responses remain available. No-op if the survey already has an end_date in the past.
*/
export const surveysStop = async (projectId: string, id: string, options?: RequestInit): Promise<SurveyApi> => {
return apiMutator<SurveyApi>(getSurveysStopUrl(projectId, id), {
...options,
method: 'POST',
})
}
export const getSurveysSummarizeResponsesCreateUrl = (
projectId: string,
id: string,
params?: SurveysSummarizeResponsesCreateParams
) => {
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}/surveys/${id}/summarize_responses/?${stringifiedParams}`
: `/v1/projects/${projectId}/surveys/${id}/summarize_responses/`
}
/**
* Summarize survey responses. When `question_index` or `question_id` is provided, returns a per-question theme summary using cached `survey.question_summaries` when fresh. When neither is provided, returns the survey-wide headline summary (delegates to summary_headline). Pass `force_refresh=true` in the body to bypass caches.
*/
export const surveysSummarizeResponsesCreate = async (
projectId: string,
id: string,
surveySummarizeRequestApi?: SurveySummarizeRequestApi,
params?: SurveysSummarizeResponsesCreateParams,
options?: RequestInit
): Promise<void> => {
return apiMutator<void>(getSurveysSummarizeResponsesCreateUrl(projectId, id, params), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(surveySummarizeRequestApi),
})
}
export const getSurveysSummaryHeadlineCreateUrl = (projectId: string, id: string) => {
return `/v1/projects/${projectId}/surveys/${id}/summary_headline/`
}
export const surveysSummaryHeadlineCreate = async (
projectId: string,
id: string,
surveySerializerCreateUpdateOnlyApi: NonReadonly<SurveySerializerCreateUpdateOnlyApi>,
options?: RequestInit
): Promise<void> => {
return apiMutator<void>(getSurveysSummaryHeadlineCreateUrl(projectId, id), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(surveySerializerCreateUpdateOnlyApi),
})
}
export const getSurveysAllActivityRetrieveUrl = (projectId: string) => {
return `/v1/projects/${projectId}/surveys/activity/`
}
export const surveysAllActivityRetrieve = async (projectId: string, options?: RequestInit): Promise<void> => {
return apiMutator<void>(getSurveysAllActivityRetrieveUrl(projectId), {
...options,
method: 'GET',
})
}
export const getSurveysQuestionLabelsUrl = (projectId: string) => {
return `/v1/projects/${projectId}/surveys/question_labels/`
}
/**
* Return a slim list of question labels for the team's surveys. Used by the frontend to resolve `$survey_response_<question_id>` property keys into human-readable question text without loading the full survey payload.
*/
export const surveysQuestionLabels = async (
projectId: string,
options?: RequestInit
): Promise<SurveyQuestionLabelsResponseApi> => {
return apiMutator<SurveyQuestionLabelsResponseApi>(getSurveysQuestionLabelsUrl(projectId), {
...options,
method: 'GET',
})
}
export const getSurveysResponsesCountRetrieveUrl = (projectId: string) => {
return `/v1/projects/${projectId}/surveys/responses_count/`
}
/**
* Get response counts for all surveys.
*
* Args:
* exclude_archived: Optional boolean to exclude archived responses (default: false, includes archived)
* survey_ids: Optional comma-separated list of survey IDs to filter by
*
* Returns:
* Dictionary mapping survey IDs to response counts
*/
export const surveysResponsesCountRetrieve = async (projectId: string, options?: RequestInit): Promise<void> => {
return apiMutator<void>(getSurveysResponsesCountRetrieveUrl(projectId), {
...options,
method: 'GET',
})
}
export const getSurveysGlobalStatsRetrieveUrl = (projectId: string, params?: SurveysGlobalStatsRetrieveParams) => {
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}/surveys/stats/?${stringifiedParams}`
: `/v1/projects/${projectId}/surveys/stats/`
}
/**
* Get aggregated response statistics across all surveys.
*
* Args:
* date_from: Optional ISO timestamp for start date (e.g. 2024-01-01T00:00:00Z)
* date_to: Optional ISO timestamp for end date (e.g. 2024-01-31T23:59:59Z)
*
* Returns:
* Aggregated statistics across all surveys including total counts and rates
*/
export const surveysGlobalStatsRetrieve = async (
projectId: string,
params?: SurveysGlobalStatsRetrieveParams,
options?: RequestInit
): Promise<SurveyGlobalStatsResponseApi> => {
return apiMutator<SurveyGlobalStatsResponseApi>(getSurveysGlobalStatsRetrieveUrl(projectId, params), {
...options,
method: 'GET',
})
}