import {z} from 'zod' export type EnvianceRestServicesCommonCustomFieldInfo = {id?: unknown | undefined, name?: string | undefined}; export type EnvianceRestServicesCommonAssigneeV2 = {userIdOrName?: string | undefined, groupIdOrName?: string | undefined}; export type EnvianceRestServicesVer2WorkflowsWorkflowInfo = {id?: unknown | undefined, uniqueId?: string | undefined, name?: string | undefined, workflowTypeName?: string | undefined, parentUniqueId?: unknown | undefined, parentWorkflowSourceCustomField?: EnvianceRestServicesCommonCustomFieldInfo | undefined, dueDate?: string | undefined, status?: string | undefined, creator?: string | undefined, created?: string | undefined, lastRun?: string | undefined, assignedBy?: string | undefined, assignedTo?: Array | undefined, objects?: Array | undefined, documents?: Array | undefined, calendars?: Array | undefined, comment?: string | undefined, closeDate?: string | undefined, jsonData?: Record | undefined}; export type EnvianceBusinessUdfRestUrlItem = {label?: string | undefined, url?: string | undefined}; export type EnvianceRestServicesUdfsProperty = {name?: string | undefined, urlItems?: Array | undefined, values?: Array | undefined, beginDate?: string | undefined, endDate?: string | undefined, caption?: string | undefined, captionLocalized?: string | undefined}; export type EnvianceRestServicesVer2WorkflowsTransition = {stepActionName?: string | undefined, assignTo?: Array | undefined, dueDate?: string | undefined, closeDate?: string | undefined}; export type EnvianceRestServicesVer2TasksTaskOccurrenceInfo = {statusChangeDate?: string | undefined, objectIdOrPath?: string | undefined, dismissed?: boolean | undefined, percentComplete?: string | undefined, hoursToComplete?: number | undefined, costToComplete?: number | undefined, comment?: string | undefined, eventInstanceId?: unknown | undefined, compliancePeriodStartDate?: string | undefined, compliancePeriodEndDate?: string | undefined, comply?: string | undefined, ObjectId?: unknown | undefined}; export type EnvianceRestServicesVer2WorkflowsWorkflowStepInfo = {id?: unknown | undefined, name?: string | undefined, comment?: string | undefined, fields?: Array | undefined, transition?: EnvianceRestServicesVer2WorkflowsTransition | undefined, taskCompletion?: Array | undefined}; export type CreateWorkflow = {workflowInfo?: EnvianceRestServicesVer2WorkflowsWorkflowInfo | undefined, initStepInfo?: EnvianceRestServicesVer2WorkflowsWorkflowStepInfo | undefined}; export type CreateApiVer2WorkflowServiceSvcWorkflowsArgs = {'EnvApi-Systemid'?: string | undefined, 'EnvApi-Packageid'?: string | undefined, 'EnvApi-Udf-DateTime-Iso-In-CustomFields'?: string | undefined, 'EnvApi-Udf-DateTime-ReadInUserTz'?: string | undefined, 'EnvApi-Udf-Value-Invariant'?: string | undefined, 'EnvApi-Localization-All'?: string | undefined, 'x-client-request-id'?: string | undefined, body: CreateWorkflow}; export type CreateApiVer2WorkflowServiceSvcWorkflowsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createApiVer2WorkflowServiceSvcWorkflowsResponse = z.string(); 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 }; /** * POST /ver2/WorkflowService.svc/workflows */ export const createApiVer2WorkflowServiceSvcWorkflows = async (args: CreateApiVer2WorkflowServiceSvcWorkflowsArgs, options: CreateApiVer2WorkflowServiceSvcWorkflowsOptions) => { 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['EnvApi-Systemid'] != null) headers.set("EnvApi-Systemid", String(args['EnvApi-Systemid'])) if (args['EnvApi-Packageid'] != null) headers.set("EnvApi-Packageid", String(args['EnvApi-Packageid'])) if (args['EnvApi-Udf-DateTime-Iso-In-CustomFields'] != null) headers.set("EnvApi-Udf-DateTime-Iso-In-CustomFields", String(args['EnvApi-Udf-DateTime-Iso-In-CustomFields'])) if (args['EnvApi-Udf-DateTime-ReadInUserTz'] != null) headers.set("EnvApi-Udf-DateTime-ReadInUserTz", String(args['EnvApi-Udf-DateTime-ReadInUserTz'])) if (args['EnvApi-Udf-Value-Invariant'] != null) headers.set("EnvApi-Udf-Value-Invariant", String(args['EnvApi-Udf-Value-Invariant'])) if (args['EnvApi-Localization-All'] != null) headers.set("EnvApi-Localization-All", String(args['EnvApi-Localization-All'])) if (args['x-client-request-id'] != null) headers.set("x-client-request-id", String(args['x-client-request-id'])) const url = `${baseUrl.replace(/\/+$/, '')}/ver2/WorkflowService.svc/workflows${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(createApiVer2WorkflowServiceSvcWorkflowsResponse, await res.json()) };