import {z} from 'zod' export type GetApiCmmnManagementHistoryJobsArgs = {id?: string | undefined, withException?: boolean | undefined, exceptionMessage?: string | undefined, scopeType?: string | undefined, tenantId?: string | undefined, tenantIdLike?: string | undefined, withoutTenantId?: boolean | undefined, lockOwner?: string | undefined, locked?: boolean | undefined, unlocked?: boolean | undefined, sort?: ('id' | 'retries' | 'tenantId') | undefined, order?: string | undefined, start?: number | undefined, size?: number | undefined}; export type GetApiCmmnManagementHistoryJobsOptions = {baseUrl: string, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const historyJobResponse = z.object({id: z.string().optional(), url: z.string().optional(), scopeType: z.string().optional(), retries: z.number().int().optional(), exceptionMessage: z.string().optional(), jobHandlerType: z.string().optional(), jobHandlerConfiguration: z.string().optional(), advancedJobHandlerConfiguration: z.string().optional(), tenantId: z.string().optional(), customValues: z.string().optional(), createTime: z.string().optional(), lockOwner: z.string().optional(), lockExpirationTime: z.string().optional()}); export const dataResponseHistoryJobResponse = z.object({data: z.array(historyJobResponse).optional(), total: z.number().int().optional(), start: z.number().int().optional(), sort: z.string().optional(), order: z.string().optional(), size: z.number().int().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 }; /** * List history jobs * * GET /cmmn-management/history-jobs */ export const getApiCmmnManagementHistoryJobs = async (args: GetApiCmmnManagementHistoryJobsArgs, options: GetApiCmmnManagementHistoryJobsOptions) => { const {baseUrl, fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.id != null) query.append("id", String(args.id)) if (args.withException != null) query.append("withException", String(args.withException)) if (args.exceptionMessage != null) query.append("exceptionMessage", String(args.exceptionMessage)) if (args.scopeType != null) query.append("scopeType", String(args.scopeType)) if (args.tenantId != null) query.append("tenantId", String(args.tenantId)) if (args.tenantIdLike != null) query.append("tenantIdLike", String(args.tenantIdLike)) if (args.withoutTenantId != null) query.append("withoutTenantId", String(args.withoutTenantId)) if (args.lockOwner != null) query.append("lockOwner", String(args.lockOwner)) if (args.locked != null) query.append("locked", String(args.locked)) if (args.unlocked != null) query.append("unlocked", String(args.unlocked)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.order != null) query.append("order", String(args.order)) if (args.start != null) query.append("start", String(args.start)) if (args.size != null) query.append("size", String(args.size)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/cmmn-management/history-jobs${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(dataResponseHistoryJobResponse, await res.json()) };