import {z} from 'zod' export type GetApiCmmnRuntimeTasksArgs = {taskId?: string | undefined, name?: string | undefined, nameLike?: string | undefined, nameLikeIgnoreCase?: string | undefined, description?: string | undefined, priority?: string | undefined, minimumPriority?: string | undefined, maximumPriority?: string | undefined, assignee?: string | undefined, assigneeLike?: string | undefined, owner?: string | undefined, ownerLike?: string | undefined, unassigned?: string | undefined, delegationState?: string | undefined, candidateUser?: string | undefined, candidateGroup?: string | undefined, candidateGroups?: string | undefined, involvedUser?: string | undefined, taskDefinitionKey?: string | undefined, taskDefinitionKeyLike?: string | undefined, caseInstanceId?: string | undefined, caseInstanceIdWithChildren?: string | undefined, caseDefinitionId?: string | undefined, caseDefinitionKey?: string | undefined, caseDefinitionKeyLike?: string | undefined, caseDefinitionKeyLikeIgnoreCase?: string | undefined, planItemInstanceId?: string | undefined, propagatedStageInstanceId?: string | undefined, scopeId?: string | undefined, scopeIds?: string | undefined, withoutScopeId?: boolean | undefined, subScopeId?: string | undefined, scopeType?: string | undefined, createdOn?: string | undefined, createdBefore?: string | undefined, createdAfter?: string | undefined, dueOn?: string | undefined, dueBefore?: string | undefined, dueAfter?: string | undefined, withoutDueDate?: boolean | undefined, excludeSubTasks?: boolean | undefined, active?: boolean | undefined, includeTaskLocalVariables?: boolean | undefined, includeProcessVariables?: boolean | undefined, tenantId?: string | undefined, tenantIdLike?: string | undefined, withoutTenantId?: boolean | undefined, withoutProcessInstanceId?: boolean | undefined, candidateOrAssigned?: string | undefined, category?: string | undefined, categoryIn?: string | undefined, categoryNotIn?: string | undefined, withoutCategory?: string | undefined, rootScopeId?: string | undefined, parentScopeId?: string | undefined}; export type GetApiCmmnRuntimeTasksOptions = {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 taskResponse = z.object({id: z.string().optional(), url: z.string().optional(), owner: z.string().optional(), assignee: z.string().optional(), delegationState: z.string().optional(), name: z.string().optional(), description: z.string().optional(), createTime: z.string().optional(), dueDate: z.string().optional(), priority: z.number().int().optional(), suspended: z.boolean().optional(), claimTime: z.string().optional(), taskDefinitionKey: z.string().optional(), scopeDefinitionId: z.string().optional(), scopeId: z.string().optional(), subScopeId: z.string().optional(), scopeType: z.string().optional(), propagatedStageInstanceId: z.string().optional(), tenantId: z.string().optional(), category: z.string().optional(), formKey: z.string().optional(), caseInstanceId: z.string().optional(), caseInstanceUrl: z.string().optional(), caseDefinitionId: z.string().optional(), caseDefinitionUrl: z.string().optional(), parentTaskId: z.string().optional(), parentTaskUrl: z.string().optional(), executionId: z.string().optional(), processInstanceId: z.string().optional(), processDefinitionId: z.string().optional(), variables: z.array(restVariable).optional()}); export const dataResponseTaskResponse = z.object({data: z.array(taskResponse).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 of tasks * * GET /cmmn-runtime/tasks */ export const getApiCmmnRuntimeTasks = async (args: GetApiCmmnRuntimeTasksArgs, options: GetApiCmmnRuntimeTasksOptions) => { 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.name != null) query.append("name", String(args.name)) if (args.nameLike != null) query.append("nameLike", String(args.nameLike)) if (args.nameLikeIgnoreCase != null) query.append("nameLikeIgnoreCase", String(args.nameLikeIgnoreCase)) if (args.description != null) query.append("description", String(args.description)) if (args.priority != null) query.append("priority", String(args.priority)) if (args.minimumPriority != null) query.append("minimumPriority", String(args.minimumPriority)) if (args.maximumPriority != null) query.append("maximumPriority", String(args.maximumPriority)) if (args.assignee != null) query.append("assignee", String(args.assignee)) if (args.assigneeLike != null) query.append("assigneeLike", String(args.assigneeLike)) if (args.owner != null) query.append("owner", String(args.owner)) if (args.ownerLike != null) query.append("ownerLike", String(args.ownerLike)) if (args.unassigned != null) query.append("unassigned", String(args.unassigned)) if (args.delegationState != null) query.append("delegationState", String(args.delegationState)) if (args.candidateUser != null) query.append("candidateUser", String(args.candidateUser)) if (args.candidateGroup != null) query.append("candidateGroup", String(args.candidateGroup)) if (args.candidateGroups != null) query.append("candidateGroups", String(args.candidateGroups)) if (args.involvedUser != null) query.append("involvedUser", String(args.involvedUser)) if (args.taskDefinitionKey != null) query.append("taskDefinitionKey", String(args.taskDefinitionKey)) if (args.taskDefinitionKeyLike != null) query.append("taskDefinitionKeyLike", String(args.taskDefinitionKeyLike)) 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.caseDefinitionKey != null) query.append("caseDefinitionKey", String(args.caseDefinitionKey)) if (args.caseDefinitionKeyLike != null) query.append("caseDefinitionKeyLike", String(args.caseDefinitionKeyLike)) if (args.caseDefinitionKeyLikeIgnoreCase != null) query.append("caseDefinitionKeyLikeIgnoreCase", String(args.caseDefinitionKeyLikeIgnoreCase)) if (args.planItemInstanceId != null) query.append("planItemInstanceId", String(args.planItemInstanceId)) if (args.propagatedStageInstanceId != null) query.append("propagatedStageInstanceId", String(args.propagatedStageInstanceId)) if (args.scopeId != null) query.append("scopeId", String(args.scopeId)) if (args.scopeIds != null) query.append("scopeIds", String(args.scopeIds)) if (args.withoutScopeId != null) query.append("withoutScopeId", String(args.withoutScopeId)) if (args.subScopeId != null) query.append("subScopeId", String(args.subScopeId)) if (args.scopeType != null) query.append("scopeType", String(args.scopeType)) if (args.createdOn != null) query.append("createdOn", String(args.createdOn)) if (args.createdBefore != null) query.append("createdBefore", String(args.createdBefore)) if (args.createdAfter != null) query.append("createdAfter", String(args.createdAfter)) if (args.dueOn != null) query.append("dueOn", String(args.dueOn)) if (args.dueBefore != null) query.append("dueBefore", String(args.dueBefore)) if (args.dueAfter != null) query.append("dueAfter", String(args.dueAfter)) if (args.withoutDueDate != null) query.append("withoutDueDate", String(args.withoutDueDate)) if (args.excludeSubTasks != null) query.append("excludeSubTasks", String(args.excludeSubTasks)) if (args.active != null) query.append("active", String(args.active)) 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.candidateOrAssigned != null) query.append("candidateOrAssigned", String(args.candidateOrAssigned)) if (args.category != null) query.append("category", String(args.category)) if (args.categoryIn != null) query.append("categoryIn", String(args.categoryIn)) if (args.categoryNotIn != null) query.append("categoryNotIn", String(args.categoryNotIn)) if (args.withoutCategory != null) query.append("withoutCategory", String(args.withoutCategory)) 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-runtime/tasks${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(dataResponseTaskResponse, await res.json()) };