import {z} from 'zod' export type JobDestinationPublicV2 = {format?: ('jsonl' | 'csv' | 'parquet') | undefined, path: string, type: 'file' | 's3'}; export type JobInputsPublicV2 = {data?: (Array<{[key: string]: unknown}> | null) | undefined, file_path?: (string | null) | undefined, type: 's3' | 'inline' | 'file'}; export type JobSchedulePublicV2 = {cron: string, enabled: boolean}; export type UpdateJobRequestPublicV2 = {description?: (string | null) | undefined, destination?: (JobDestinationPublicV2 | null) | undefined, display_name?: (string | null) | undefined, inputs?: (JobInputsPublicV2 | null) | undefined, schedule?: (JobSchedulePublicV2 | null) | undefined}; export type PatchApiV2JobsJobIdArgs = {job_id: string, body: UpdateJobRequestPublicV2}; export type PatchApiV2JobsJobIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const jobDestinationPublicV2 = z.object({format: z.enum(["jsonl", "csv", "parquet"]).optional(), path: z.string(), type: z.enum(["file", "s3"])}); export const jobInputsPublicV2 = z.object({data: z.array(z.record(z.string(), z.unknown())).nullable().optional(), file_path: z.string().nullable().optional(), type: z.enum(["s3", "inline", "file"])}); export const jobSchedulePublicV2 = z.object({cron: z.string(), enabled: z.boolean()}); export const jobPublicV2 = z.object({created_at: z.string().nullable().optional(), description: z.string().nullable().optional(), destination: jobDestinationPublicV2.nullable().optional(), display_name: z.string().nullable().optional(), extract_template_name: z.string().nullable().optional(), id: z.string(), inputs: jobInputsPublicV2.nullable().optional(), last_run_at: z.string().nullable().optional(), last_run_status: z.enum(["PENDING", "RUNNING", "SUCCESS", "FAILED", "CANCELLED", "TIMEOUT", "WARNING"]).nullable().optional(), name: z.string(), schedule: jobSchedulePublicV2.nullable().optional(), updated_at: z.string().nullable().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 Job * * PATCH /v2/jobs/{job_id} */ export const patchApiV2JobsJobId = async (args: PatchApiV2JobsJobIdArgs, options?: PatchApiV2JobsJobIdOptions) => { const {baseUrl = "https://sdk.nimbleway.com", 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 (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/jobs/${encodeURIComponent(String(args.job_id))}${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(jobPublicV2, await res.json()) };