import {z} from 'zod' export type FireActionByNameForm = {comments?: string | undefined, assign?: string | undefined, publishDate?: string | undefined, publishTime?: string | undefined, expireDate?: string | undefined, expireTime?: string | undefined, neverExpire?: string | undefined, whereToSend?: string | undefined, filterKey?: string | undefined, query?: string | undefined, pathToMove?: string | undefined, timezoneId?: string | undefined, individualPermissions?: {[key: string]: Array} | undefined, actionName?: string | undefined, iwantTo?: string | undefined, contentlet?: {[key: string]: Record} | undefined}; export type UpdateApiApiV1WorkflowActionsFireArgs = {inode?: string | undefined, identifier?: string | undefined, indexPolicy?: ('DEFER' | 'WAIT_FOR' | 'FORCE') | undefined, language?: string | undefined, body: FireActionByNameForm}; export type UpdateApiApiV1WorkflowActionsFireOptions = {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 responseEntityMapView = z.object({errors: z.array(errorEntity).optional(), entity: z.record(z.string(), z.object({})).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 }; /** * Fire workflow action by name * * PUT /api/v1/workflow/actions/fire */ export const updateApiApiV1WorkflowActionsFire = async (args: UpdateApiApiV1WorkflowActionsFireArgs, options: UpdateApiApiV1WorkflowActionsFireOptions) => { 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") if (args.inode != null) query.append("inode", String(args.inode)) if (args.identifier != null) query.append("identifier", String(args.identifier)) if (args.indexPolicy != null) query.append("indexPolicy", String(args.indexPolicy)) if (args.language != null) query.append("language", String(args.language)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/workflow/actions/fire${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(responseEntityMapView, await res.json()) };