import {z} from 'zod' export type GetApiSimulationsSimulationReferenceBatchesArgs = {projectId: string, simulationReference: string, filter?: string | undefined, limit?: number | undefined, skip?: number | undefined, sort?: string | undefined, next?: string | undefined, previous?: string | undefined, status?: ('STOPPED' | 'IN_PROGRESS' | 'COMPLETED' | 'FAILED') | undefined, timespan?: string | undefined, timezone?: string | undefined, endPointType?: string | undefined}; export type GetApiSimulationsSimulationReferenceBatchesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiSimulationsSimulationReferenceBatchesResponse = z.object({data: z.array(z.object({id: z.string(), referenceId: z.string(), simulationReference: z.string(), status: z.enum(["pending", "running", "completed", "failed", "stopped"]), runs: z.number().int(), completedRuns: z.number().int(), failedRuns: z.number().int(), createdAt: z.number().int(), startedAt: z.number().int().nullable().optional(), completedAt: z.number().int().nullable().optional()})).optional(), pagination: z.object({limit: z.number().int(), skip: z.number().int(), total: z.number().int(), hasNext: z.boolean(), hasPrevious: z.boolean(), next: z.string().nullable().optional(), previous: z.string().nullable().optional()}).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 simulations by scenarios * * GET /simulations/{simulationReference}/batches * * Also accepts auth: apiKeyAuth */ export const getApiSimulationsSimulationReferenceBatches = async (args: GetApiSimulationsSimulationReferenceBatchesArgs, options?: GetApiSimulationsSimulationReferenceBatchesOptions) => { const {baseUrl = "https://api-trial.cognigy.ai/testing", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.projectId != null) query.append("projectId", String(args.projectId)) if (args.filter != null) query.append("filter", String(args.filter)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.skip != null) query.append("skip", String(args.skip)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.next != null) query.append("next", String(args.next)) if (args.previous != null) query.append("previous", String(args.previous)) if (args.status != null) query.append("status", String(args.status)) if (args.timespan != null) query.append("timespan", String(args.timespan)) if (args.timezone != null) query.append("timezone", String(args.timezone)) if (args.endPointType != null) query.append("endPointType", String(args.endPointType)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/simulations/${encodeURIComponent(String(args.simulationReference))}/batches${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(getApiSimulationsSimulationReferenceBatchesResponse, await res.json()) };