import {z} from 'zod' export type GetApiApiOrgIdStatusPagesIdDomainsArgs = {org_id: string, id: string}; export type GetApiApiOrgIdStatusPagesIdDomainsOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const domainAdminView = z.object({created_at: z.number().int(), domain: z.string(), id: z.string(), last_checked_at: z.number().int().nullable().optional(), txt_name: z.string().nullable().optional(), verification_failure_reason: z.number().int().nullable().optional(), verification_state: z.number().int(), verification_token: z.string().nullable().optional(), verified_at: z.number().int().nullable().optional()}); export const getApiApiOrgIdStatusPagesIdDomainsResponse = z.array(domainAdminView); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List custom domains of a status page * * GET /api/{org_id}/status_pages/{id}/domains */ export const getApiApiOrgIdStatusPagesIdDomains = async (args: GetApiApiOrgIdStatusPagesIdDomainsArgs, options: GetApiApiOrgIdStatusPagesIdDomainsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/status_pages/${encodeURIComponent(String(args.id))}/domains${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiOrgIdStatusPagesIdDomainsResponse, await res.json()) };