import {z} from 'zod' export type GetApiActionHistoryHistoricActionInstancesArgs = {id?: string | undefined, ids?: string | undefined, name?: string | undefined, nameLike?: string | undefined, actionDefinitionId?: string | undefined, actionDefinitionIdLike?: string | undefined, formKey?: string | undefined, formInstanceId?: string | undefined, executedBy?: string | undefined, executedByLike?: string | undefined, scopeId?: string | undefined, subScopeId?: string | undefined, scopeType?: string | undefined, scopeDefinitionId?: string | undefined, participantUser?: string | undefined, participantUsers?: string | undefined, participantGroup?: string | undefined, participantGroups?: string | undefined, startDate?: string | undefined, startDateBefore?: string | undefined, startDateAfter?: string | undefined, executionDate?: string | undefined, executionDateBefore?: string | undefined, executionDateAfter?: string | undefined, tenantId?: string | undefined, tenantIdLike?: string | undefined, withoutTenantId?: boolean | undefined, sort?: ('startDate' | 'tenantId') | undefined}; export type GetApiActionHistoryHistoricActionInstancesOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const historicActionInstanceResponse = z.object({id: z.string(), actionDefinitionId: z.string(), scopeDefinitionId: z.string().optional(), scopeId: z.string().optional(), scopeType: z.string().optional(), startDate: z.string(), executedBy: z.string().optional(), executionDate: z.string().optional(), formInstanceId: z.string().optional(), priority: z.number().int().optional(), tenantId: z.string().optional()}); export const dataResponseHistoricActionInstanceResponse = z.object({data: z.array(historicActionInstanceResponse).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 }; /** * Query historic action instances * * GET /action-history/historic-action-instances */ export const getApiActionHistoryHistoricActionInstances = async (args: GetApiActionHistoryHistoricActionInstancesArgs, options?: GetApiActionHistoryHistoricActionInstancesOptions) => { const {baseUrl = "http://localhost:8090/action-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.ids != null) query.append("ids", String(args.ids)) if (args.name != null) query.append("name", String(args.name)) if (args.nameLike != null) query.append("nameLike", String(args.nameLike)) if (args.actionDefinitionId != null) query.append("actionDefinitionId", String(args.actionDefinitionId)) if (args.actionDefinitionIdLike != null) query.append("actionDefinitionIdLike", String(args.actionDefinitionIdLike)) if (args.formKey != null) query.append("formKey", String(args.formKey)) if (args.formInstanceId != null) query.append("formInstanceId", String(args.formInstanceId)) if (args.executedBy != null) query.append("executedBy", String(args.executedBy)) if (args.executedByLike != null) query.append("executedByLike", String(args.executedByLike)) if (args.scopeId != null) query.append("scopeId", String(args.scopeId)) if (args.subScopeId != null) query.append("subScopeId", String(args.subScopeId)) if (args.scopeType != null) query.append("scopeType", String(args.scopeType)) if (args.scopeDefinitionId != null) query.append("scopeDefinitionId", String(args.scopeDefinitionId)) if (args.participantUser != null) query.append("participantUser", String(args.participantUser)) if (args.participantUsers != null) query.append("participantUsers", String(args.participantUsers)) if (args.participantGroup != null) query.append("participantGroup", String(args.participantGroup)) if (args.participantGroups != null) query.append("participantGroups", String(args.participantGroups)) if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.startDateBefore != null) query.append("startDateBefore", String(args.startDateBefore)) if (args.startDateAfter != null) query.append("startDateAfter", String(args.startDateAfter)) if (args.executionDate != null) query.append("executionDate", String(args.executionDate)) if (args.executionDateBefore != null) query.append("executionDateBefore", String(args.executionDateBefore)) if (args.executionDateAfter != null) query.append("executionDateAfter", String(args.executionDateAfter)) 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.sort != null) query.append("sort", String(args.sort)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/action-history/historic-action-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(dataResponseHistoricActionInstanceResponse, await res.json()) };