import {z} from 'zod' export type PatchApiPayrollItemsArgs = {body: Array<{id: string, payroll?: string | undefined, payment_method?: string | undefined, earnings?: (Array<{type: string, workplace: string, earning_code?: string | undefined, description?: string | undefined, earning_rate?: string | undefined, amount: string, hours?: number | undefined, piece_units?: number | undefined, metadata?: unknown | undefined}>) | undefined, reimbursements?: (Array<{amount: string, description?: string | undefined, code?: string | undefined, metadata?: unknown | undefined}>) | undefined, benefit_overrides?: (Array<{benefit: string, employee_contribution_amount?: string | undefined, company_contribution_amount?: string | undefined}>) | undefined, post_tax_deduction_overrides?: Array<{post_tax_deduction: string, amount: string}> | undefined, tax_overrides?: Array<{tax: string, amount: string}> | undefined, pto_balance_hours?: number | undefined, sick_balance_hours?: number | undefined, state_covid_sick_balance_hours?: number | undefined, supplemental_tax_calc_method?: string | undefined, paper_check_number?: string | undefined, paystub_info?: unknown | undefined, metadata?: unknown | undefined}>}; export type PatchApiPayrollItemsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiPayrollItemsResponse = z.array(z.object({id: z.string().optional(), payroll: z.string().optional(), employee: z.string().optional(), status: z.string().optional(), void_of: z.string().nullable().optional(), voided_by: z.string().nullable().optional(), payment_method: z.string().optional(), supplemental_tax_calc_method: z.string().optional(), net_pay: z.string().nullable().optional(), net_pay_split: z.string().nullable().optional(), pto_balance_hours: z.number().nullable().optional(), sick_balance_hours: z.number().nullable().optional(), state_covid_sick_balance_hours: z.number().nullable().optional(), earnings: z.array(z.object({amount: z.string().optional(), hours: z.number().nullable().optional(), type: z.string().nullable().optional(), code: z.string().nullable().optional(), description: z.string().nullable().optional(), earning_code: z.string().nullable().optional(), earning_rate: z.string().nullable().optional(), workplace: z.string().nullable().optional(), tip_credit_amount: z.string().nullable().optional(), metadata: z.object({}).optional()})).optional(), reimbursements: z.array(z.object({amount: z.string().optional(), code: z.string().nullable().optional(), description: z.string().nullable().optional()})).optional(), taxes: z.array(z.object({tax: z.string().optional(), description: z.string().nullable().optional(), amount: z.string().optional(), payer: z.string().nullable().optional(), remittable: z.boolean().nullable().optional()})).nullable().optional(), benefits: z.array(z.object({})).nullable().optional(), benefit_overrides: z.array(z.object({benefit: z.string().optional(), employee_contribution_amount: z.string().nullable().optional(), company_contribution_amount: z.string().nullable().optional()})).optional(), post_tax_deductions: z.array(z.object({})).nullable().optional(), post_tax_deduction_overrides: z.array(z.object({post_tax_deduction: z.string().optional(), amount: z.string().optional()})).optional(), tax_overrides: z.array(z.object({tax: z.string().optional(), amount: z.string().optional()})).optional(), warnings: z.array(z.object({})).nullable().optional(), paper_check_number: z.string().nullable().optional(), paystub_info: z.object({}).nullable().optional(), metadata: z.object({}).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 }; /** * Copy of Update a payroll item * * PATCH /payroll_items */ export const patchApiPayrollItems = async (args: PatchApiPayrollItemsArgs, options?: PatchApiPayrollItemsOptions) => { const {baseUrl = "https://sandbox.checkhq.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/payroll_items${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(patchApiPayrollItemsResponse, await res.json()) };