import {z} from 'zod' export type GetApiCmmnHistoryHistoricTaskInstancesArgs = {taskId?: string | undefined, caseInstanceId?: string | undefined, caseInstanceIdWithChildren?: string | undefined, caseDefinitionId?: string | undefined, propagatedStageInstanceId?: string | undefined, withoutScopeId?: boolean | undefined, taskDefinitionKey?: string | undefined, taskName?: string | undefined, taskNameLike?: string | undefined, taskNameLikeIgnoreCase?: string | undefined, taskDescription?: string | undefined, taskDescriptionLike?: string | undefined, taskCategory?: string | undefined, taskCategoryIn?: string | undefined, taskCategoryNotIn?: string | undefined, taskWithoutCategory?: string | undefined, taskDeleteReason?: string | undefined, taskDeleteReasonLike?: string | undefined, taskAssignee?: string | undefined, taskAssigneeLike?: string | undefined, taskOwner?: string | undefined, taskOwnerLike?: string | undefined, taskInvolvedUser?: string | undefined, taskCandidateGroup?: string | undefined, taskPriority?: string | undefined, finished?: boolean | undefined, processFinished?: boolean | undefined, parentTaskId?: string | undefined, dueDate?: string | undefined, dueDateAfter?: string | undefined, dueDateBefore?: string | undefined, withoutDueDate?: boolean | undefined, taskCompletedOn?: string | undefined, taskCompletedAfter?: string | undefined, taskCompletedBefore?: string | undefined, taskCreatedOn?: string | undefined, taskCreatedBefore?: string | undefined, taskCreatedAfter?: string | undefined, includeTaskLocalVariables?: boolean | undefined, includeProcessVariables?: boolean | undefined, tenantId?: string | undefined, tenantIdLike?: string | undefined, withoutTenantId?: boolean | undefined, withoutProcessInstanceId?: boolean | undefined, planItemInstanceId?: string | undefined, rootScopeId?: string | undefined, parentScopeId?: string | undefined}; export type GetApiCmmnHistoryHistoricTaskInstancesOptions = {baseUrl: string, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const restVariable = z.object({name: z.string().optional(), type: z.string().optional(), value: z.object({}).optional(), valueUrl: z.string().optional(), scope: z.string().optional()}); export const historicTaskInstanceResponse = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), deleteReason: z.string().optional(), owner: z.string().optional(), assignee: z.string().optional(), startTime: z.string().optional(), endTime: z.string().optional(), durationInMillis: z.number().int().optional(), workTimeInMillis: z.number().int().optional(), claimTime: z.string().optional(), taskDefinitionKey: z.string().optional(), formKey: z.string().optional(), priority: z.number().int().optional(), dueDate: z.string().optional(), parentTaskId: z.string().optional(), url: z.string().optional(), variables: z.array(restVariable).optional(), tenantId: z.string().optional(), category: z.string().optional(), caseInstanceId: z.string().optional(), caseInstanceUrl: z.string().optional(), caseDefinitionId: z.string().optional(), caseDefinitionUrl: z.string().optional(), scopeDefinitionId: z.string().optional(), scopeId: z.string().optional(), subScopeId: z.string().optional(), scopeType: z.string().optional(), propagatedStageInstanceId: z.string().optional(), executionId: z.string().optional(), processInstanceId: z.string().optional(), processDefinitionId: z.string().optional()}); export const dataResponseHistoricTaskInstanceResponse = z.object({data: z.array(historicTaskInstanceResponse).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 historic task instances * * GET /cmmn-history/historic-task-instances */ export const getApiCmmnHistoryHistoricTaskInstances = async (args: GetApiCmmnHistoryHistoricTaskInstancesArgs, options: GetApiCmmnHistoryHistoricTaskInstancesOptions) => { const {baseUrl, fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.taskId != null) query.append("taskId", String(args.taskId)) if (args.caseInstanceId != null) query.append("caseInstanceId", String(args.caseInstanceId)) if (args.caseInstanceIdWithChildren != null) query.append("caseInstanceIdWithChildren", String(args.caseInstanceIdWithChildren)) if (args.caseDefinitionId != null) query.append("caseDefinitionId", String(args.caseDefinitionId)) if (args.propagatedStageInstanceId != null) query.append("propagatedStageInstanceId", String(args.propagatedStageInstanceId)) if (args.withoutScopeId != null) query.append("withoutScopeId", String(args.withoutScopeId)) if (args.taskDefinitionKey != null) query.append("taskDefinitionKey", String(args.taskDefinitionKey)) if (args.taskName != null) query.append("taskName", String(args.taskName)) if (args.taskNameLike != null) query.append("taskNameLike", String(args.taskNameLike)) if (args.taskNameLikeIgnoreCase != null) query.append("taskNameLikeIgnoreCase", String(args.taskNameLikeIgnoreCase)) if (args.taskDescription != null) query.append("taskDescription", String(args.taskDescription)) if (args.taskDescriptionLike != null) query.append("taskDescriptionLike", String(args.taskDescriptionLike)) if (args.taskCategory != null) query.append("taskCategory", String(args.taskCategory)) if (args.taskCategoryIn != null) query.append("taskCategoryIn", String(args.taskCategoryIn)) if (args.taskCategoryNotIn != null) query.append("taskCategoryNotIn", String(args.taskCategoryNotIn)) if (args.taskWithoutCategory != null) query.append("taskWithoutCategory", String(args.taskWithoutCategory)) if (args.taskDeleteReason != null) query.append("taskDeleteReason", String(args.taskDeleteReason)) if (args.taskDeleteReasonLike != null) query.append("taskDeleteReasonLike", String(args.taskDeleteReasonLike)) if (args.taskAssignee != null) query.append("taskAssignee", String(args.taskAssignee)) if (args.taskAssigneeLike != null) query.append("taskAssigneeLike", String(args.taskAssigneeLike)) if (args.taskOwner != null) query.append("taskOwner", String(args.taskOwner)) if (args.taskOwnerLike != null) query.append("taskOwnerLike", String(args.taskOwnerLike)) if (args.taskInvolvedUser != null) query.append("taskInvolvedUser", String(args.taskInvolvedUser)) if (args.taskCandidateGroup != null) query.append("taskCandidateGroup", String(args.taskCandidateGroup)) if (args.taskPriority != null) query.append("taskPriority", String(args.taskPriority)) if (args.finished != null) query.append("finished", String(args.finished)) if (args.processFinished != null) query.append("processFinished", String(args.processFinished)) if (args.parentTaskId != null) query.append("parentTaskId", String(args.parentTaskId)) if (args.dueDate != null) query.append("dueDate", String(args.dueDate)) if (args.dueDateAfter != null) query.append("dueDateAfter", String(args.dueDateAfter)) if (args.dueDateBefore != null) query.append("dueDateBefore", String(args.dueDateBefore)) if (args.withoutDueDate != null) query.append("withoutDueDate", String(args.withoutDueDate)) if (args.taskCompletedOn != null) query.append("taskCompletedOn", String(args.taskCompletedOn)) if (args.taskCompletedAfter != null) query.append("taskCompletedAfter", String(args.taskCompletedAfter)) if (args.taskCompletedBefore != null) query.append("taskCompletedBefore", String(args.taskCompletedBefore)) if (args.taskCreatedOn != null) query.append("taskCreatedOn", String(args.taskCreatedOn)) if (args.taskCreatedBefore != null) query.append("taskCreatedBefore", String(args.taskCreatedBefore)) if (args.taskCreatedAfter != null) query.append("taskCreatedAfter", String(args.taskCreatedAfter)) if (args.includeTaskLocalVariables != null) query.append("includeTaskLocalVariables", String(args.includeTaskLocalVariables)) if (args.includeProcessVariables != null) query.append("includeProcessVariables", String(args.includeProcessVariables)) 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.withoutProcessInstanceId != null) query.append("withoutProcessInstanceId", String(args.withoutProcessInstanceId)) if (args.planItemInstanceId != null) query.append("planItemInstanceId", String(args.planItemInstanceId)) if (args.rootScopeId != null) query.append("rootScopeId", String(args.rootScopeId)) if (args.parentScopeId != null) query.append("parentScopeId", String(args.parentScopeId)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/cmmn-history/historic-task-instances${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(dataResponseHistoricTaskInstanceResponse, await res.json()) };