import {z} from 'zod' export type PatchPayrollRunCollective = {payrollAdministrationId?: string | undefined}; export type PatchApiV2ProvidersEmployersPayrolladministrationsPayrollperiodsPayrollPeriodIdPayrollrunsArgs = {Authorization: string, Accept: string, payrollPeriodId: number, body: Array}; export type PatchApiV2ProvidersEmployersPayrolladministrationsPayrollperiodsPayrollPeriodIdPayrollrunsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const collectiveAction2 = z.object({collectiveActionId: z.string().optional(), collectiveActionParentId: z.string().optional(), employerId: z.string().optional(), payrollAdministrationId: z.string().optional(), submittedByUserId: z.string().optional(), submittedOn: z.string().optional(), status: z.enum(["Completed", "NotStarted", "InProgress"]).optional(), type: z.enum(["Werknemerloket", "Beloning"]).optional(), itemCount: z.object({processedWithError: z.number().int().optional(), processed: z.number().int().optional(), processedWithWarning: z.number().int().optional(), total: z.number().int().optional()}).optional()}); export const patchApiV2ProvidersEmployersPayrolladministrationsPayrollperiodsPayrollPeriodIdPayrollrunsResponse = z.object({content: collectiveAction2.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 payroll run status Collective * * PATCH /v2/providers/employers/payrolladministrations/payrollperiods/{payrollPeriodId}/payrollruns */ export const patchApiV2ProvidersEmployersPayrolladministrationsPayrollperiodsPayrollPeriodIdPayrollruns = async (args: PatchApiV2ProvidersEmployersPayrolladministrationsPayrollperiodsPayrollPeriodIdPayrollrunsArgs, options?: PatchApiV2ProvidersEmployersPayrolladministrationsPayrollperiodsPayrollPeriodIdPayrollrunsOptions) => { 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/payrolladministrations/payrollperiods/${encodeURIComponent(String(args.payrollPeriodId))}/payrollruns${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiV2ProvidersEmployersPayrolladministrationsPayrollperiodsPayrollPeriodIdPayrollrunsResponse, await res.json()) };