@vzeta/camunda-api-zod-schemas
Version:
Zod schemas and TypeScript types for Camunda 8 unified API
114 lines (113 loc) • 3.34 kB
JavaScript
import { z } from "zod";
import { getQueryRequestBodySchema, getQueryResponseBodySchema, API_VERSION } from "../common.js";
const permissionTypeSchema = z.enum([
"ACCESS",
"CREATE",
"CREATE_BATCH_OPERATION_CANCEL_PROCESS_INSTANCE",
"CREATE_BATCH_OPERATION_DELETE_PROCESS_INSTANCE",
"CREATE_BATCH_OPERATION_MIGRATE_PROCESS_INSTANCE",
"CREATE_BATCH_OPERATION_MODIFY_PROCESS_INSTANCE",
"CREATE_BATCH_OPERATION_RESOLVE_INCIDENT",
"CREATE_BATCH_OPERATION_DELETE_DECISION_INSTANCE",
"CREATE_BATCH_OPERATION_DELETE_DECISION_DEFINITION",
"CREATE_BATCH_OPERATION_DELETE_PROCESS_DEFINITION",
"CREATE_PROCESS_INSTANCE",
"CREATE_DECISION_INSTANCE",
"READ",
"READ_PROCESS_INSTANCE",
"READ_USER_TASK",
"READ_DECISION_INSTANCE",
"READ_PROCESS_DEFINITION",
"READ_DECISION_DEFINITION",
"UPDATE",
"UPDATE_PROCESS_INSTANCE",
"UPDATE_USER_TASK",
"DELETE",
"DELETE_PROCESS",
"DELETE_DRD",
"DELETE_FORM",
"DELETE_RESOURCE",
"DELETE_PROCESS_INSTANCE",
"DELETE_DECISION_INSTANCE"
]);
const resourceTypeSchema = z.enum([
"AUTHORIZATION",
"MAPPING_RULE",
"MESSAGE",
"BATCH",
"BATCH_OPERATION",
"APPLICATION",
"SYSTEM",
"TENANT",
"RESOURCE",
"PROCESS_DEFINITION",
"DECISION_REQUIREMENTS_DEFINITION",
"DECISION_DEFINITION",
"GROUP",
"USER",
"ROLE"
]);
const ownerTypeSchema = z.enum(["USER", "CLIENT", "ROLE", "GROUP", "MAPPING", "UNSPECIFIED"]);
const authorizationSchema = z.object({
ownerId: z.string(),
ownerType: ownerTypeSchema,
resourceType: resourceTypeSchema,
resourceId: z.string(),
permissionTypes: z.array(permissionTypeSchema),
authorizationKey: z.string()
});
const createAuthorizationRequestBodySchema = authorizationSchema.pick({
ownerId: true,
ownerType: true,
resourceType: true,
resourceId: true,
permissionTypes: true
});
const updateAuthorizationRequestBodySchema = createAuthorizationRequestBodySchema.partial();
const queryAuthorizationsRequestBodySchema = getQueryRequestBodySchema({
sortFields: ["ownerId", "ownerType", "resourceId", "resourceType"],
filter: z.object({
resourceId: z.array(z.string()),
...authorizationSchema.pick({
ownerId: true,
ownerType: true,
resourceType: true
}).shape
}).partial()
});
const queryAuthorizationsResponseBodySchema = getQueryResponseBodySchema(authorizationSchema);
const createAuthorization = {
method: "POST",
getUrl: () => `/${API_VERSION}/authorizations`
};
const updateAuthorization = {
method: "PUT",
getUrl: ({ authorizationKey }) => `/${API_VERSION}/authorizations/${authorizationKey}`
};
const getAuthorization = {
method: "GET",
getUrl: ({ authorizationKey }) => `/${API_VERSION}/authorizations/${authorizationKey}`
};
const deleteAuthorization = {
method: "DELETE",
getUrl: ({ authorizationKey }) => `/${API_VERSION}/authorizations/${authorizationKey}`
};
const queryAuthorizations = {
method: "POST",
getUrl: () => `/${API_VERSION}/authorizations/search`
};
export {
authorizationSchema,
createAuthorization,
createAuthorizationRequestBodySchema,
deleteAuthorization,
getAuthorization,
ownerTypeSchema,
permissionTypeSchema,
queryAuthorizations,
queryAuthorizationsRequestBodySchema,
queryAuthorizationsResponseBodySchema,
resourceTypeSchema,
updateAuthorization,
updateAuthorizationRequestBodySchema
};