import {z} from 'zod' export type GetApiV1DomeConfigsArgs = {team_id: string, agent_id?: (string | null) | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiV1DomeConfigsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const domeConfigResponse = z.object({id: z.string(), status: z.string().optional(), agent_id: z.string().nullable().optional(), config_body: z.record(z.string(), z.unknown()).optional(), dome_instance_url: z.string().nullable().optional(), created_at: z.number().int(), created_by: z.string(), updated_at: z.number().int().nullable().optional(), updated_by: z.string().nullable().optional()}); export const domeConfigListResponse = z.object({dome_configs: z.array(domeConfigResponse), count: z.number().int()}); 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 Dome Configs * * GET /v1/dome-configs */ export const getApiV1DomeConfigs = async (args: GetApiV1DomeConfigsArgs, options: GetApiV1DomeConfigsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = 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.agent_id != null) query.append("agent_id", String(args.agent_id)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/dome-configs${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(domeConfigListResponse, await res.json()) };