Skip to content

: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.

9.0 KB
Raw Blame
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 {
    DraftStatusResponseApi,
    GenerateRequestApi,
    GenerateResponseApi,
    PaginatedProductTourListApi,
    PatchedProductTourSerializerCreateUpdateOnlyApi,
    ProductTourApi,
    ProductTourSerializerCreateUpdateOnlyApi,
    ProductToursListParams,
} 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 getProductToursListUrl = (projectId: string, params?: ProductToursListParams) => {
    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}/product_tours/?${stringifiedParams}`
        : `/api/projects/${projectId}/product_tours/`
}

/**
 * Create, read, update, and manage product tours and their targeting.
 */
export const productToursList = async (
    projectId: string,
    params?: ProductToursListParams,
    options?: RequestInit
): Promise<PaginatedProductTourListApi> => {
    return apiMutator<PaginatedProductTourListApi>(getProductToursListUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getProductToursCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/product_tours/`
}

/**
 * Create, read, update, and manage product tours and their targeting.
 */
export const productToursCreate = async (
    projectId: string,
    productTourSerializerCreateUpdateOnlyApi: NonReadonly<ProductTourSerializerCreateUpdateOnlyApi>,
    options?: RequestInit
): Promise<ProductTourSerializerCreateUpdateOnlyApi> => {
    return apiMutator<ProductTourSerializerCreateUpdateOnlyApi>(getProductToursCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(productTourSerializerCreateUpdateOnlyApi),
    })
}

export const getProductToursRetrieveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/product_tours/${id}/`
}

/**
 * Create, read, update, and manage product tours and their targeting.
 */
export const productToursRetrieve = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ProductTourApi> => {
    return apiMutator<ProductTourApi>(getProductToursRetrieveUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getProductToursUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/product_tours/${id}/`
}

/**
 * Create, read, update, and manage product tours and their targeting.
 */
export const productToursUpdate = async (
    projectId: string,
    id: string,
    productTourApi: NonReadonly<ProductTourApi>,
    options?: RequestInit
): Promise<ProductTourApi> => {
    return apiMutator<ProductTourApi>(getProductToursUpdateUrl(projectId, id), {
        ...options,
        method: 'PUT',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(productTourApi),
    })
}

export const getProductToursPartialUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/product_tours/${id}/`
}

/**
 * Create, read, update, and manage product tours and their targeting.
 */
export const productToursPartialUpdate = async (
    projectId: string,
    id: string,
    patchedProductTourSerializerCreateUpdateOnlyApi?: NonReadonly<PatchedProductTourSerializerCreateUpdateOnlyApi>,
    options?: RequestInit
): Promise<ProductTourSerializerCreateUpdateOnlyApi> => {
    return apiMutator<ProductTourSerializerCreateUpdateOnlyApi>(getProductToursPartialUpdateUrl(projectId, id), {
        ...options,
        method: 'PATCH',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(patchedProductTourSerializerCreateUpdateOnlyApi),
    })
}

export const getProductToursDestroyUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/product_tours/${id}/`
}

/**
 * Create, read, update, and manage product tours and their targeting.
 */
export const productToursDestroy = async (projectId: string, id: string, options?: RequestInit): Promise<void> => {
    return apiMutator<void>(getProductToursDestroyUrl(projectId, id), {
        ...options,
        method: 'DELETE',
    })
}

export const getProductToursDiscardDraftDestroyUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/product_tours/${id}/discard_draft/`
}

/**
 * Discard draft content.
 */
export const productToursDiscardDraftDestroy = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ProductTourApi> => {
    return apiMutator<ProductTourApi>(getProductToursDiscardDraftDestroyUrl(projectId, id), {
        ...options,
        method: 'DELETE',
    })
}

export const getProductToursDraftPartialUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/product_tours/${id}/draft/`
}

/**
 * Save draft content (server-side merge). No side effects triggered.
 */
export const productToursDraftPartialUpdate = async (
    projectId: string,
    id: string,
    patchedProductTourSerializerCreateUpdateOnlyApi?: NonReadonly<PatchedProductTourSerializerCreateUpdateOnlyApi>,
    options?: RequestInit
): Promise<ProductTourApi> => {
    return apiMutator<ProductTourApi>(getProductToursDraftPartialUpdateUrl(projectId, id), {
        ...options,
        method: 'PATCH',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(patchedProductTourSerializerCreateUpdateOnlyApi),
    })
}

export const getProductToursDraftStatusRetrieveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/product_tours/${id}/draft_status/`
}

/**
 * Lightweight polling endpoint for draft change detection.
 */
export const productToursDraftStatusRetrieve = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<DraftStatusResponseApi> => {
    return apiMutator<DraftStatusResponseApi>(getProductToursDraftStatusRetrieveUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getProductToursGenerateCreateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/product_tours/${id}/generate/`
}

/**
 * Generate tour step content using AI.
 */
export const productToursGenerateCreate = async (
    projectId: string,
    id: string,
    generateRequestApi?: GenerateRequestApi,
    options?: RequestInit
): Promise<GenerateResponseApi> => {
    return apiMutator<GenerateResponseApi>(getProductToursGenerateCreateUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(generateRequestApi),
    })
}

export const getProductToursPublishDraftCreateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/product_tours/${id}/publish_draft/`
}

/**
 * Commit draft to live tour. Runs full validation and triggers side effects.
 *
 * Accepts an optional body payload. If provided, merges it into the draft
 * before publishing so the caller can save + publish in a single request.
 */
export const productToursPublishDraftCreate = async (
    projectId: string,
    id: string,
    productTourSerializerCreateUpdateOnlyApi: NonReadonly<ProductTourSerializerCreateUpdateOnlyApi>,
    options?: RequestInit
): Promise<ProductTourApi> => {
    return apiMutator<ProductTourApi>(getProductToursPublishDraftCreateUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(productTourSerializerCreateUpdateOnlyApi),
    })
}