import {z} from 'zod' export type EnvianceRestServicesCommonTimeZoneInfo = {id?: number | undefined, name?: string | undefined, stdOffset?: number | undefined, dstOffset?: number | undefined, currentOffset?: number | undefined}; export type EnvianceRestServicesCommonAssigneeV2 = {userIdOrName?: string | undefined, groupIdOrName?: string | undefined}; export type EnvianceRestServicesVer2TasksSchedulesRecurrenceIntervalInfoExt = Record; export type EnvianceRestServicesVer2TasksSchedulesDayOfMonthInfoExt = Record; export type EnvianceRestServicesVer2TasksSchedulesTaskScheduleInfo = {recurrenceType?: ('Hourly' | 'Daily' | 'Weekly' | 'Monthly' | 'Yearly' | 'AfterLastCompletion') | undefined, startDate?: string | undefined, endDate?: string | undefined, startTime?: string | undefined, endTime?: string | undefined, recurrenceInterval?: EnvianceRestServicesVer2TasksSchedulesRecurrenceIntervalInfoExt | undefined, dayOfMonth?: EnvianceRestServicesVer2TasksSchedulesDayOfMonthInfoExt | undefined, monthOfYear?: number | undefined, TalLogicVersion?: number | undefined}; export type EnvianceRestServicesVer2TasksNotificationsDueDateCondition = {conditionType?: ('IntervalBefore' | 'IntervalAfter' | 'PastDue') | undefined, intervalType?: ('QuarterHour' | 'Hour' | 'Day' | 'Week' | 'Month' | 'Year') | undefined, intervalValue?: number | undefined}; export type EnvianceRestServicesVer2TasksNotificationsCompletionStatusCondition = {completionPercent?: number | undefined, comparisonLogic?: string | undefined, onlyWhenPastDue?: boolean | undefined}; export type EnvianceRestServicesVer2TasksNotificationsNotificationConditions = {immediately?: boolean | undefined, whenDismissed?: boolean | undefined, byDueDate?: EnvianceRestServicesVer2TasksNotificationsDueDateCondition | undefined, byCompletionStatus?: EnvianceRestServicesVer2TasksNotificationsCompletionStatusCondition | undefined}; export type EnvianceRestServicesVer2TasksNotificationsNotificationRecipients = {toAssignees?: boolean | undefined, toAssignor?: boolean | undefined, users?: Array | undefined, groups?: Array | undefined}; export type EnvianceRestServicesVer2TasksNotificationsTaskNotificationInfo = {conditions?: EnvianceRestServicesVer2TasksNotificationsNotificationConditions | undefined, templateIdOrName?: string | undefined, recipients?: EnvianceRestServicesVer2TasksNotificationsNotificationRecipients | undefined, deliveryMethod?: ('Inbox' | 'Email' | 'InboxAndEmail') | undefined, comments?: string | undefined}; export type EnvianceRestServicesVer2TasksTriggeringDueDateInfo = {value: number, hours: string, period: string}; export type EnvianceRestServicesVer2TasksTriggeringTimeToCreateValue = {past?: boolean | undefined, operation?: string | undefined, value?: number | undefined, hours?: string | undefined, period?: string | undefined, percent?: number | undefined, compare?: string | undefined}; export type EnvianceRestServicesVer2TasksTriggeringTimeToCreateInfo = {category: string, value?: EnvianceRestServicesVer2TasksTriggeringTimeToCreateValue | undefined}; export type EnvianceRestServicesVer2TasksTriggeringWorkflowTriggerInfo = {workflowtypeidorname: string, workflowname?: string | undefined, isusetaskname?: boolean | undefined, calendars?: Array | undefined, duedateflags: Array, duedateamount?: EnvianceRestServicesVer2TasksTriggeringDueDateInfo | undefined, timetocreateoptions: Array, assignee?: Array | undefined}; export type EnvianceRestServicesVer2TasksTriggeringTaskWorkflowInfo = {isautoclosetask?: boolean | undefined, workflows?: Array | undefined}; export type EnvianceRestServicesVer2TasksTaskInfo = {id?: unknown | undefined, name?: string | undefined, description?: string | undefined, createdBy?: string | undefined, createdOn?: string | undefined, dueDate?: string | undefined, timeZone?: EnvianceRestServicesCommonTimeZoneInfo | undefined, templateIdOrName?: string | undefined, assignor?: string | undefined, assignees?: Array | undefined, calendars?: Array | undefined, objects?: Array | undefined, documents?: Array | undefined, schedules?: Array | undefined, notifications?: Array | undefined, workflowtrigger?: EnvianceRestServicesVer2TasksTriggeringTaskWorkflowInfo | undefined, suppressNotificationsBefore?: string | undefined}; export type CreateTask = {taskInfo?: EnvianceRestServicesVer2TasksTaskInfo | undefined, copyFrom?: string | undefined}; export type CreateApiVer2TaskServiceSvcTasksArgs = {'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: CreateTask}; export type CreateApiVer2TaskServiceSvcTasksOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createApiVer2TaskServiceSvcTasksResponse = 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/TaskService.svc/tasks */ export const createApiVer2TaskServiceSvcTasks = async (args: CreateApiVer2TaskServiceSvcTasksArgs, options: CreateApiVer2TaskServiceSvcTasksOptions) => { 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/TaskService.svc/tasks${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(createApiVer2TaskServiceSvcTasksResponse, await res.json()) };