import {z} from 'zod' export type Id = string; export type AbsenceProgressObject = {id?: Id | undefined, startDate?: string | undefined, endDate?: (string | null) | undefined, incapacityPercentage?: number | undefined, typeOfWorkResumption?: ({key?: number | undefined, value?: string | undefined} | null) | undefined, comments?: (string | null) | undefined}; export type UpdateApiV2ProvidersEmployersEmployeesAbsencesAbsenceprogressAbsenceProgressIdArgs = {absenceProgressId: string, Authorization: string, Accept: string, body: AbsenceProgressObject}; export type UpdateApiV2ProvidersEmployersEmployeesAbsencesAbsenceprogressAbsenceProgressIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const version = z.object({obsoleteDate: z.string().nullable().optional(), resourceVersion: z.string().optional()}); export const messageWarning = z.array(z.object({type: z.string().optional(), description: z.string().optional(), id: z.string().nullable().optional(), code: z.number().int().optional(), properties: z.array(z.string()).optional()})); export const id = z.string(); export const absenceProgressObject = z.object({id: id.optional(), startDate: z.string().optional(), endDate: z.string().nullable().optional(), incapacityPercentage: z.number().int().gte(1).lte(100).optional(), typeOfWorkResumption: z.object({key: z.number().int().optional(), value: z.string().max(50).optional()}).nullable().optional(), comments: z.string().max(4000).nullable().optional()}); export const updateApiV2ProvidersEmployersEmployeesAbsencesAbsenceprogressAbsenceProgressIdResponse = z.object({version: version.optional(), messages: messageWarning.optional(), content: absenceProgressObject.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 }; /** * Edit the details of an absence progress * * PUT /v2/providers/employers/employees/absences/absenceprogress/{absenceProgressId} */ export const updateApiV2ProvidersEmployersEmployeesAbsencesAbsenceprogressAbsenceProgressId = async (args: UpdateApiV2ProvidersEmployersEmployeesAbsencesAbsenceprogressAbsenceProgressIdArgs, options?: UpdateApiV2ProvidersEmployersEmployeesAbsencesAbsenceprogressAbsenceProgressIdOptions) => { const {baseUrl = "https://api.loket.nl", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json;version=2020-03-16") headers.set('accept', "application/json;version=2020-03-16") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.Accept != null) headers.set("Accept", String(args.Accept)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/providers/employers/employees/absences/absenceprogress/${encodeURIComponent(String(args.absenceProgressId))}${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(updateApiV2ProvidersEmployersEmployeesAbsencesAbsenceprogressAbsenceProgressIdResponse, await res.json()) };