import {z} from 'zod' export type WorkScheduleExclusionId = string; export type WorkScheduleExclusionType = 'PublicHolidays' | 'OtherEvent' | 'AdditionalWorkDays'; export type UpdateApiWorkscheduleExclusionsWorkscheduleExclusionIdArgs = {workscheduleExclusionId: WorkScheduleExclusionId, fromDate?: string | undefined, toDate?: string | undefined, exclusionType?: WorkScheduleExclusionType | undefined}; export type UpdateApiWorkscheduleExclusionsWorkscheduleExclusionIdOptions = {baseUrl?: string | undefined, HTTP?: string | undefined, fetch?: typeof fetch | undefined}; export const responseKind = z.enum(["accounts", "users", "contacts", "assets", "eDiscoveryReport", "folders", "folderTree", "tasks", "taskIds", "timelogs", "timelogCategories", "timelogLockPeriods", "timetrackerTimers", "comments", "attachments", "url", "version", "dataExport", "dataExportSchema", "auditLog", "accessRoles", "stream", "changes", "posts", "mailSettings", "integrationInfo", "gmailIntegrationSettings", "workTypesForIntegrations", "ids", "backups", "domains", "dependencies", "workflows", "workschedules", "workscheduleExclusions", "workscheduleUserExclusions", "customfields", "customfieldIds", "customstatuses", "invitations", "notifications", "jobroles", "placeholders", "groups", "session", "dashboards", "widgets", "taskCreationSettings", "colors", "experiments", "topics", "topicComments", "webhooks", "reviews", "boards", "textSearch", "chatChannels", "chatMessages", "forms", "requestForms", "request", "report", "platformWidgets", "platformWidgetInstances", "spaces", "pdf", "customerSatisfaction", "asyncJob", "approvals", "highlights", "highlightsList", "highlightsSettings", "highlightsCard", "timesheet", "timesheetRow", "timesheetSubmissionRule", "mobileFeatures", "mobileSettings", "folderBlueprintTree", "taskBlueprintTree", "blueprintSearch", "feedback", "timeline_snapshot", "contactIds", "bookings", "integrateThreshold", "hourlyRatesProvision", "hourlyRates", "projectTeamMembers", "contactsHistory", "tasksHistory", "foldersHistory", "activityDigest", "workItemTemplates", "workTemplates", "workItemMetadata", "workItem", "customItemTypes", "verificationCode", "views", "listView", "tableView", "userTypes", "reactions", "externalRequesters", "workscheduleCapacityOverrides", "userCapacityOverrides", "userCapacityExclusions", "rollups", "requestFormPrefill", "mcpFeatures", "attachmentUploadUrl", "userAggregatedCapacity", "cascadingFieldSettings", "recommendResources", "aggregatedAllocatedEffort", "aggregatedTotalUserEffort", "aggregatedTimeSpent", "folderBlueprint", "taskBlueprint"]); export const workScheduleExclusionType = z.enum(["PublicHolidays", "OtherEvent", "AdditionalWorkDays"]); export const workScheduleExclusionId = z.string(); export const workScheduleException = z.object({fromDate: z.string().optional(), isWorkDays: z.boolean().optional(), toDate: z.string().optional(), exclusionType: workScheduleExclusionType.optional(), id: workScheduleExclusionId.optional()}); export const updateApiWorkscheduleExclusionsWorkscheduleExclusionIdResponse = z.object({kind: responseKind.optional(), data: z.array(workScheduleException).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 }; /** * Update Work Schedule exception * * PUT /workschedule_exclusions/{workscheduleExclusionId} */ export const updateApiWorkscheduleExclusionsWorkscheduleExclusionId = async (args: UpdateApiWorkscheduleExclusionsWorkscheduleExclusionIdArgs, options?: UpdateApiWorkscheduleExclusionsWorkscheduleExclusionIdOptions) => { const {baseUrl = "https://www.wrike.com/api/v4", fetch: fetchFn = fetch, HTTP} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.fromDate != null) query.append("fromDate", String(args.fromDate)) if (args.toDate != null) query.append("toDate", String(args.toDate)) if (args.exclusionType != null) query.append("exclusionType", String(args.exclusionType)) if (HTTP !== undefined) headers.set('authorization', `Bearer ${HTTP}`) const url = `${baseUrl.replace(/\/+$/, '')}/workschedule_exclusions/${encodeURIComponent(String(args.workscheduleExclusionId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(updateApiWorkscheduleExclusionsWorkscheduleExclusionIdResponse, await res.json()) };