import {z} from 'zod' export type GetApiAgentManagementJobsArgs = {id?: string | undefined, scopeId?: string | undefined, withoutScopeId?: boolean | undefined, subScopeId?: string | undefined, scopeDefinitionId?: string | undefined, scopeType?: string | undefined, elementId?: string | undefined, elementName?: string | undefined, timersOnly?: boolean | undefined, messagesOnly?: boolean | undefined, withException?: boolean | undefined, dueBefore?: string | undefined, dueAfter?: string | undefined, exceptionMessage?: string | undefined, tenantId?: string | undefined, tenantIdLike?: string | undefined, withoutTenantId?: boolean | undefined, locked?: boolean | undefined, unlocked?: boolean | undefined, withoutProcessInstanceId?: boolean | undefined, sort?: ('id' | 'dueDate' | 'executionId' | 'processInstanceId' | 'retries' | 'tenantId') | undefined}; export type GetApiAgentManagementJobsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const jobResponse = z.object({id: z.string().optional(), url: z.string().optional(), elementId: z.string().optional(), elementName: z.string().optional(), scopeId: z.string().optional(), subScopeId: z.string().optional(), scopeDefinitionId: z.string().optional(), scopeType: z.string().optional(), handlerType: z.string().optional(), retries: z.number().int().optional(), exceptionMessage: z.string().optional(), dueDate: z.string().optional(), createTime: z.string().optional(), lockOwner: z.string().optional(), lockExpirationTime: z.string().optional(), tenantId: z.string().optional()}); export const dataResponseJobResponse = z.object({data: z.array(jobResponse).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 jobs * * GET /agent-management/jobs */ export const getApiAgentManagementJobs = async (args: GetApiAgentManagementJobsArgs, options?: GetApiAgentManagementJobsOptions) => { const {baseUrl = "http://localhost:8090/agent-api", 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.scopeId != null) query.append("scopeId", String(args.scopeId)) if (args.withoutScopeId != null) query.append("withoutScopeId", String(args.withoutScopeId)) if (args.subScopeId != null) query.append("subScopeId", String(args.subScopeId)) if (args.scopeDefinitionId != null) query.append("scopeDefinitionId", String(args.scopeDefinitionId)) if (args.scopeType != null) query.append("scopeType", String(args.scopeType)) if (args.elementId != null) query.append("elementId", String(args.elementId)) if (args.elementName != null) query.append("elementName", String(args.elementName)) if (args.timersOnly != null) query.append("timersOnly", String(args.timersOnly)) if (args.messagesOnly != null) query.append("messagesOnly", String(args.messagesOnly)) if (args.withException != null) query.append("withException", String(args.withException)) if (args.dueBefore != null) query.append("dueBefore", String(args.dueBefore)) if (args.dueAfter != null) query.append("dueAfter", String(args.dueAfter)) if (args.exceptionMessage != null) query.append("exceptionMessage", String(args.exceptionMessage)) 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.locked != null) query.append("locked", String(args.locked)) if (args.unlocked != null) query.append("unlocked", String(args.unlocked)) if (args.withoutProcessInstanceId != null) query.append("withoutProcessInstanceId", String(args.withoutProcessInstanceId)) if (args.sort != null) query.append("sort", String(args.sort)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/agent-management/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(dataResponseJobResponse, await res.json()) };