import {z} from 'zod' export type GetApiV1BugsArgs = {source?: (string | null) | undefined, status?: ('open' | 'in_progress' | 'fixed' | 'wont_fix' | null) | undefined, failure_classification?: ('app_bug' | 'setup_issue' | null) | undefined, app?: (string | null) | undefined, app_file_id?: (string | null) | undefined, test_run_id?: (string | null) | undefined, test_case_id?: (string | null) | undefined, limit?: number | undefined, 'x-api-key'?: string | undefined}; export type GetApiV1BugsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1BugsResponse = 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 bugs in your organization * * GET /v1/bugs */ export const getApiV1Bugs = async (args: GetApiV1BugsArgs, options?: GetApiV1BugsOptions) => { const {baseUrl = "https://api.qualgent.ai", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.source != null) query.append("source", String(args.source)) if (args.status != null) query.append("status", String(args.status)) if (args.failure_classification != null) query.append("failure_classification", String(args.failure_classification)) if (args.app != null) query.append("app", String(args.app)) if (args.app_file_id != null) query.append("app_file_id", String(args.app_file_id)) if (args.test_run_id != null) query.append("test_run_id", String(args.test_run_id)) if (args.test_case_id != null) query.append("test_case_id", String(args.test_case_id)) if (args.limit != null) query.append("limit", String(args.limit)) if (args['x-api-key'] != null) headers.set("x-api-key", String(args['x-api-key'])) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/bugs${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(getApiV1BugsResponse, await res.json()) };