import {z} from 'zod' export type PatchApiSimulationsSimulationReferenceSchedulesSchedulerReferenceArgs = {projectId: string, simulationReference: string, schedulerReference: string, body: {runConfig?: ({flowReferenceId?: string | undefined, localeReferenceId?: string | undefined, entrypoint?: string | undefined, largeLanguageModelReferenceId?: string | undefined, userId?: string | undefined, finalPing?: number | undefined, data?: {[key: string]: unknown} | undefined, enableMocking?: boolean | undefined}) | undefined, enableSchedule?: boolean | undefined, frequency?: ('daily' | 'every three days' | 'weekly' | 'biweekly' | 'monthly') | undefined, time?: string | undefined, numberOfRuns?: number | undefined, nextScheduledRun?: string | undefined, emailNotifications?: Array | undefined, scenarioName?: string | undefined, runName?: string | undefined, simulationReference?: string | undefined, endDate?: string | undefined}}; export type PatchApiSimulationsSimulationReferenceSchedulesSchedulerReferenceOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiSimulationsSimulationReferenceSchedulesSchedulerReferenceResponse = z.object({scheduler: z.object({id: z.string().optional(), simulationReference: z.string().optional(), projectReference: z.string().optional(), organisationReference: z.string().optional(), runConfig: z.object({flowReferenceId: z.string().optional(), localeReferenceId: z.string().optional(), entrypoint: z.string().optional(), largeLanguageModelReferenceId: z.string().optional(), userId: z.string().optional(), finalPing: z.number().optional(), data: z.record(z.string(), z.unknown()).optional(), enableMocking: z.boolean().optional()}).optional(), enableSchedule: z.boolean().optional(), frequency: z.enum(["daily", "every three days", "weekly", "biweekly", "monthly"]).optional(), time: z.string().optional(), numberOfRuns: z.number().int().optional(), nextScheduledRun: z.string().optional(), emailNotifications: z.array(z.string()).optional(), scenarioName: z.string().optional(), runName: z.string().optional(), endDate: z.string().optional(), createdAt: z.number().int().optional(), lastChanged: z.number().int().optional(), createdBy: z.string().optional(), lastChangedBy: z.string().optional(), cronScheduler: z.string().optional(), timezone: z.string().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 }; /** * Update a scheduler by reference * * PATCH /simulations/{simulationReference}/schedules/{schedulerReference} * * Also accepts auth: apiKeyAuth */ export const patchApiSimulationsSimulationReferenceSchedulesSchedulerReference = async (args: PatchApiSimulationsSimulationReferenceSchedulesSchedulerReferenceArgs, options?: PatchApiSimulationsSimulationReferenceSchedulesSchedulerReferenceOptions) => { const {baseUrl = "https://api-trial.cognigy.ai/testing", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.projectId != null) query.append("projectId", String(args.projectId)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/simulations/${encodeURIComponent(String(args.simulationReference))}/schedules/${encodeURIComponent(String(args.schedulerReference))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(patchApiSimulationsSimulationReferenceSchedulesSchedulerReferenceResponse, await res.json()) };