import {z} from 'zod' export type Id = string; export type DeclarationObject = {id?: Id | undefined, payrollComponent?: ({key?: number | undefined, description?: string | undefined, deviatingDescription?: (string | null) | undefined, deductionOrPayment?: ({key?: number | undefined, value?: string | undefined} | null) | undefined, routeType?: ({key?: number | undefined, value?: string | undefined} | null) | undefined}) | undefined, calculatedDistanceByRoutingService?: (number | null) | undefined, numberOfUnits?: number | undefined, numberOfUnitsByAnalysis?: (number | null) | undefined, declarationDate?: string | undefined, declarationComment?: (string | null) | undefined, declarationStatus?: ({key?: number | undefined, value?: string | undefined}) | undefined, dateOfSubmissionByEmployee?: string | undefined, dateOfLastChangeByEmployee?: string | undefined, processedInPayrollPeriod?: ({year?: number | undefined, periodNumber?: number | undefined, periodStartDate?: string | undefined, periodEndDate?: string | undefined} | null) | undefined, reasonForDeviatingFromCalculatedDistance?: (string | null) | undefined, route?: (Array<{pointOfInterest?: ({name?: (string | null) | undefined} | null) | undefined, address?: ({freeformAddress?: string | undefined, countryCode?: (string | null) | undefined}) | undefined, position?: ({latitude?: number | undefined, longitude?: number | undefined}) | undefined}> | null) | undefined}; export type UpdateApiV2ProvidersEmployersEmployeesEmploymentsDeclarationsDeclarationIdArgs = {declarationId: string, Authorization: string, Accept: string, body: DeclarationObject}; export type UpdateApiV2ProvidersEmployersEmployeesEmploymentsDeclarationsDeclarationIdOptions = {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 declarationObject = z.object({id: id.optional(), payrollComponent: z.object({key: z.number().int().optional(), description: z.string().max(14).optional(), deviatingDescription: z.string().max(50).nullable().optional(), deductionOrPayment: z.object({key: z.number().int().optional(), value: z.string().optional()}).nullable().optional(), routeType: z.object({key: z.number().int().optional(), value: z.string().optional()}).nullable().optional()}).optional(), calculatedDistanceByRoutingService: z.number().gte(0.01).lte(99999999.99).nullable().optional(), numberOfUnits: z.number().gte(0.01).lte(99999999.99).optional(), numberOfUnitsByAnalysis: z.number().gte(0).lte(99999999.99).nullable().optional(), declarationDate: z.string().optional(), declarationComment: z.string().max(1000).nullable().optional(), declarationStatus: z.object({key: z.number().int().optional(), value: z.string().optional()}).optional(), dateOfSubmissionByEmployee: z.string().optional(), dateOfLastChangeByEmployee: z.string().optional(), processedInPayrollPeriod: z.object({year: z.number().int().gte(2000).lte(9999).optional(), periodNumber: z.number().int().gte(1).lte(53).optional(), periodStartDate: z.string().optional(), periodEndDate: z.string().optional()}).nullable().optional(), reasonForDeviatingFromCalculatedDistance: z.string().max(1000).nullable().optional(), route: z.array(z.object({pointOfInterest: z.object({name: z.string().max(1000).nullable().optional()}).nullable().optional(), address: z.object({freeformAddress: z.string().max(1000).optional(), countryCode: z.string().min(2).max(2).nullable().optional()}).optional(), position: z.object({latitude: z.number().gte(-90).lte(90).optional(), longitude: z.number().gte(-180).lte(180).optional()}).optional()})).nullable().optional()}); export const updateApiV2ProvidersEmployersEmployeesEmploymentsDeclarationsDeclarationIdResponse = z.object({version: version.optional(), messages: messageWarning.optional(), content: declarationObject.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 a declaration for an employment * * PUT /v2/providers/employers/employees/employments/declarations/{declarationId} */ export const updateApiV2ProvidersEmployersEmployeesEmploymentsDeclarationsDeclarationId = async (args: UpdateApiV2ProvidersEmployersEmployeesEmploymentsDeclarationsDeclarationIdArgs, options?: UpdateApiV2ProvidersEmployersEmployeesEmploymentsDeclarationsDeclarationIdOptions) => { 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=2018-01-01") headers.set('accept', "application/json;version=2018-01-01") 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/employments/declarations/${encodeURIComponent(String(args.declarationId))}${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(updateApiV2ProvidersEmployersEmployeesEmploymentsDeclarationsDeclarationIdResponse, await res.json()) };