import {z} from 'zod' export type GetApiApiV1ConfigTeamsArgs = {'page.max_size'?: number | undefined, 'page.token'?: string | undefined, slugs?: Array | undefined, names?: Array | undefined}; export type GetApiApiV1ConfigTeamsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const configv1PageResult = z.object({next_token: z.string().optional()}); export const configv1Team = z.object({slug: z.string().optional(), name: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), user_emails: z.array(z.string()).optional(), description: z.string().optional()}); export const configv1ListTeamsResponse = z.object({page: configv1PageResult.optional(), teams: z.array(configv1Team).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 }; /** * GET /api/v1/config/teams */ export const getApiApiV1ConfigTeams = async (args: GetApiApiV1ConfigTeamsArgs, options: GetApiApiV1ConfigTeamsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['page.max_size'] != null) query.append("page.max_size", String(args['page.max_size'])) if (args['page.token'] != null) query.append("page.token", String(args['page.token'])) for (const item of args.slugs ?? []) query.append("slugs", String(item)) for (const item of args.names ?? []) query.append("names", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/config/teams${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(configv1ListTeamsResponse, await res.json()) };