import {z} from 'zod' export type GetApiV1TeamsTeamIdScreensPressesArgs = {team_id: string, screen: string, authorization?: (string | null) | undefined, 'x-darwin-token'?: (string | null) | undefined}; export type GetApiV1TeamsTeamIdScreensPressesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const sentLine = z.object({to: z.string(), channel: z.string().optional(), status: z.string().optional(), id: z.string().nullable().optional(), at: z.string().nullable().optional(), error: z.string().nullable().optional()}); export const screenPress = z.object({control_key: z.string(), run_id: z.string(), status: z.string(), outcome: z.enum(["done", "failed", "running"]), goal: z.string().nullable().optional(), error: z.string().nullable().optional(), created_at: z.string().nullable().optional(), finished_at: z.string().nullable().optional(), sent: z.array(sentLine).optional()}); export const screenPressesResponse = z.object({screen: z.string(), presses: z.array(screenPress).optional()}); 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 Screen Presses * * GET /v1/teams/{team_id}/screens/presses */ export const getApiV1TeamsTeamIdScreensPresses = async (args: GetApiV1TeamsTeamIdScreensPressesArgs, options: GetApiV1TeamsTeamIdScreensPressesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.screen != null) query.append("screen", String(args.screen)) if (args.authorization != null) headers.set("authorization", String(args.authorization)) if (args['x-darwin-token'] != null) headers.set("x-darwin-token", String(args['x-darwin-token'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/teams/${encodeURIComponent(String(args.team_id))}/screens/presses${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(screenPressesResponse, await res.json()) };