import {z} from 'zod' export type GetApiApiPreviewTypesArgs = {detail?: ('summary' | 'full' | 'protection') | undefined, projectId?: string | undefined, ws?: string | undefined, updated_within?: string | undefined, updated_period?: ('today' | 'yesterday' | 'this_week' | 'last_week' | 'this_month' | 'last_month' | 'this_year') | undefined, updated_after?: string | undefined, updated_before?: string | undefined, guidance_updated_within?: string | undefined, guidance_updated_period?: ('today' | 'yesterday' | 'this_week' | 'last_week' | 'this_month' | 'last_month' | 'this_year') | undefined, guidance_updated_after?: string | undefined, guidance_updated_before?: string | undefined, tz?: string | undefined}; export type GetApiApiPreviewTypesOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiPreviewTypesResponse = z.array(z.record(z.string(), z.unknown())); 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 types visible to the caller * * GET /api/preview/types * * Also accepts auth: cookieAuth, oauth2 */ export const getApiApiPreviewTypes = async (args: GetApiApiPreviewTypesArgs, options: GetApiApiPreviewTypesOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.detail != null) query.append("detail", String(args.detail)) if (args.projectId != null) query.append("projectId", String(args.projectId)) if (args.ws != null) query.append("ws", String(args.ws)) if (args.updated_within != null) query.append("updated_within", String(args.updated_within)) if (args.updated_period != null) query.append("updated_period", String(args.updated_period)) if (args.updated_after != null) query.append("updated_after", String(args.updated_after)) if (args.updated_before != null) query.append("updated_before", String(args.updated_before)) if (args.guidance_updated_within != null) query.append("guidance_updated_within", String(args.guidance_updated_within)) if (args.guidance_updated_period != null) query.append("guidance_updated_period", String(args.guidance_updated_period)) if (args.guidance_updated_after != null) query.append("guidance_updated_after", String(args.guidance_updated_after)) if (args.guidance_updated_before != null) query.append("guidance_updated_before", String(args.guidance_updated_before)) if (args.tz != null) query.append("tz", String(args.tz)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/preview/types${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(getApiApiPreviewTypesResponse, await res.json()) };