@vzeta/camunda-api-zod-schemas
Version:
Zod schemas and TypeScript types for Camunda 8 unified API
92 lines (91 loc) • 2.6 kB
JavaScript
import { z } from "zod";
import { getQueryRequestBodySchema, getEnumFilterSchema, advancedDateTimeFilterSchema, getQueryResponseBodySchema, API_VERSION } from "../common.js";
const incidentErrorTypeSchema = z.enum([
"UNSPECIFIED",
"UNKNOWN",
"IO_MAPPING_ERROR",
"JOB_NO_RETRIES",
"EXECUTION_LISTENER_NO_RETRIES",
"TASK_LISTENER_NO_RETRIES",
"CONDITION_ERROR",
"EXTRACT_VALUE_ERROR",
"CALLED_ELEMENT_ERROR",
"UNHANDLED_ERROR_EVENT",
"MESSAGE_SIZE_EXCEEDED",
"CALLED_DECISION_ERROR",
"DECISION_EVALUATION_ERROR",
"FORM_NOT_FOUND",
"RESOURCE_NOT_FOUND"
]);
const incidentStateSchema = z.enum(["ACTIVE", "MIGRATED", "RESOLVED", "PENDING"]);
const incidentSchema = z.object({
processDefinitionId: z.string(),
errorType: incidentErrorTypeSchema,
errorMessage: z.string(),
elementId: z.string(),
creationTime: z.string(),
state: incidentStateSchema,
tenantId: z.string(),
incidentKey: z.string(),
processDefinitionKey: z.string(),
processInstanceKey: z.string(),
elementInstanceKey: z.string(),
jobKey: z.string()
});
const resolveIncident = {
method: "POST",
getUrl: ({ incidentKey }) => `/${API_VERSION}/incidents/${incidentKey}/resolution`
};
const getIncident = {
method: "GET",
getUrl: ({ incidentKey }) => `/${API_VERSION}/incidents/${incidentKey}`
};
const getIncidentResponseBodySchema = incidentSchema;
const queryIncidentsRequestBodySchema = getQueryRequestBodySchema({
sortFields: [
"incidentKey",
"processDefinitionKey",
"processDefinitionId",
"processInstanceKey",
"errorType",
"errorMessage",
"elementId",
"elementInstanceKey",
"creationTime",
"state",
"jobKey",
"tenantId"
],
filter: z.object({
errorType: getEnumFilterSchema(incidentErrorTypeSchema),
creationTime: advancedDateTimeFilterSchema,
state: getEnumFilterSchema(incidentStateSchema),
...incidentSchema.pick({
processDefinitionId: true,
errorMessage: true,
elementId: true,
tenantId: true,
incidentKey: true,
processDefinitionKey: true,
processInstanceKey: true,
elementInstanceKey: true,
jobKey: true
}).shape
}).partial()
});
const queryIncidentsResponseBodySchema = getQueryResponseBodySchema(incidentSchema);
const queryIncidents = {
method: "POST",
getUrl: () => `/${API_VERSION}/incidents/search`
};
export {
getIncident,
getIncidentResponseBodySchema,
incidentErrorTypeSchema,
incidentSchema,
incidentStateSchema,
queryIncidents,
queryIncidentsRequestBodySchema,
queryIncidentsResponseBodySchema,
resolveIncident
};