import {z} from 'zod' export type GetApiApiOrgIdOncallResponsesArgs = {org_id: string, team_id?: string | undefined, include_resolved?: boolean | undefined, source_id?: string | undefined, subject_type?: string | undefined, ownership_path?: string | undefined, cause?: string | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiApiOrgIdOncallResponsesOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiOrgIdOncallResponsesResponse = z.array(z.object({})); 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 open response records * * GET /api/{org_id}/oncall/responses */ export const getApiApiOrgIdOncallResponses = async (args: GetApiApiOrgIdOncallResponsesArgs, options: GetApiApiOrgIdOncallResponsesOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.team_id != null) query.append("team_id", String(args.team_id)) if (args.include_resolved != null) query.append("include_resolved", String(args.include_resolved)) if (args.source_id != null) query.append("source_id", String(args.source_id)) if (args.subject_type != null) query.append("subject_type", String(args.subject_type)) if (args.ownership_path != null) query.append("ownership_path", String(args.ownership_path)) if (args.cause != null) query.append("cause", String(args.cause)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/oncall/responses${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(getApiApiOrgIdOncallResponsesResponse, await res.json()) };