import {z} from 'zod' export type WorkflowScheme = {id?: string | undefined, creationDate?: string | undefined, name?: string | undefined, variableName?: string | undefined, description?: string | undefined, archived?: boolean | undefined, mandatory?: boolean | undefined, defaultScheme?: boolean | undefined, modDate?: string | undefined, entryActionId?: string | undefined, system?: boolean | undefined}; export type WorkflowStep = {id?: string | undefined, creationDate?: string | undefined, name?: string | undefined, schemeId?: string | undefined, myOrder?: number | undefined, resolved?: boolean | undefined, enableEscalation?: boolean | undefined, escalationAction?: string | undefined, escalationTime?: number | undefined}; export type WorkflowAction = {id?: string | undefined, name?: string | undefined, schemeId?: string | undefined, condition?: string | undefined, nextStep?: string | undefined, nextAssign?: string | undefined, icon?: string | undefined, roleHierarchyForAssign?: boolean | undefined, assignable?: boolean | undefined, commentable?: boolean | undefined, order?: number | undefined, saveActionlet?: boolean | undefined, publishActionlet?: boolean | undefined, unpublishActionlet?: boolean | undefined, archiveActionlet?: boolean | undefined, pushPublishActionlet?: boolean | undefined, onlyBatchActionlet?: boolean | undefined, unarchiveActionlet?: boolean | undefined, deleteActionlet?: boolean | undefined, destroyActionlet?: boolean | undefined, moveActionlet?: boolean | undefined, commentActionlet?: boolean | undefined, metadata?: {[key: string]: Record} | undefined, resetable?: boolean | undefined, nextStepCurrentStep?: boolean | undefined, moveActionletHashPath?: boolean | undefined, owner?: string | undefined, showOn?: (Array<'NEW' | 'LOCKED' | 'UNLOCKED' | 'PUBLISHED' | 'UNPUBLISHED' | 'ARCHIVED' | 'LISTING' | 'EDITING'>) | undefined, hasOnlyBatchActionlet?: boolean | undefined, hasSaveActionlet?: boolean | undefined, hasDeleteActionlet?: boolean | undefined, hasResetActionlet?: boolean | undefined, hasPublishActionlet?: boolean | undefined, hasUnpublishActionlet?: boolean | undefined, hasArchiveActionlet?: boolean | undefined, hasPushPublishActionlet?: boolean | undefined, hasUnarchiveActionlet?: boolean | undefined, hasDestroyActionlet?: boolean | undefined, hasCommentActionlet?: boolean | undefined, hasMoveActionletHasPathActionlet?: boolean | undefined, hasMoveActionletActionlet?: boolean | undefined}; export type WorkflowActionletParameter = {displayName?: string | undefined, key?: string | undefined, defaultValue?: string | undefined, required?: boolean | undefined}; export type WorkFlowActionlet = {howTo?: string | undefined, localizedHowto?: string | undefined, actionClass?: string | undefined, localizedName?: string | undefined, name?: string | undefined, parameters?: Array | undefined}; export type WorkflowActionClass = {id?: string | undefined, actionId?: string | undefined, name?: string | undefined, order?: number | undefined, clazz?: string | undefined, actionlet?: WorkFlowActionlet | undefined}; export type WorkflowActionClassParameter = {id?: string | undefined, actionClassId?: string | undefined, key?: string | undefined, value?: string | undefined}; export type SystemActionWorkflowActionMapping = {identifier?: string | undefined, systemAction?: ('NEW' | 'EDIT' | 'PUBLISH' | 'UNPUBLISH' | 'ARCHIVE' | 'UNARCHIVE' | 'DELETE' | 'DESTROY' | 'LOCK' | 'UNLOCK') | undefined, workflowAction?: WorkflowAction | undefined, owner?: Record | undefined, ownerContentType?: boolean | undefined, ownerScheme?: boolean | undefined}; export type WorkflowSchemeImportExportObjectView = {version?: string | undefined, schemes?: Array | undefined, steps?: Array | undefined, actions?: Array | undefined, actionSteps?: Array<{[key: string]: string}> | undefined, actionClasses?: Array | undefined, actionClassParams?: Array | undefined, schemeSystemActionWorkflowActionMappings?: Array | undefined}; export type Permission = {id?: number | undefined, inode?: string | undefined, permission?: number | undefined, type?: string | undefined, bitPermission?: boolean | undefined, individualPermission?: boolean | undefined, roleId?: string | undefined}; export type WorkflowSchemeImportObjectForm = {workflowObject?: WorkflowSchemeImportExportObjectView | undefined, permissions?: Array | undefined}; export type CreateApiApiV1WorkflowSchemesImportArgs = {body: WorkflowSchemeImportObjectForm}; export type CreateApiApiV1WorkflowSchemesImportOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const errorEntity = z.object({errorCode: z.string().optional(), message: z.string().optional(), fieldName: z.string().optional()}); export const messageEntity = z.object({message: z.string().optional()}); export const pagination = z.object({currentPage: z.number().int().optional(), perPage: z.number().int().optional(), totalEntries: z.number().int().optional()}); export const responseEntityStringView = z.object({errors: z.array(errorEntity).optional(), entity: z.string().optional(), messages: z.array(messageEntity).optional(), i18nMessagesMap: z.record(z.string(), z.string()).optional(), permissions: z.array(z.string()).optional(), pagination: pagination.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 }; /** * Import a workflow scheme * * POST /api/v1/workflow/schemes/import */ export const createApiApiV1WorkflowSchemesImport = async (args: CreateApiApiV1WorkflowSchemesImportArgs, options: CreateApiApiV1WorkflowSchemesImportOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/workflow/schemes/import${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(responseEntityStringView, await res.json()) };