import {z} from 'zod' export type CreateApiPayrollsArgs = {include_items?: boolean | undefined, include_contractor_payments?: boolean | undefined, body: {company: string, period_start: string, period_end: string, payday: string, processing_period?: string | undefined, correction?: string | undefined, type?: string | undefined, pay_frequency?: string | undefined, funding_payment_method?: string | undefined, pay_schedule?: string | undefined, off_cycle_options?: ({force_supplemental_withholding?: boolean | undefined, apply_benefits?: boolean | undefined, apply_post_tax_deductions?: boolean | undefined}) | undefined, items?: (Array<{employee: string, payment_method?: string | undefined, earnings?: (Array<{type?: string | undefined, workplace: string, earning_code?: string | undefined, description?: string | undefined, earning_rate?: string | undefined, amount?: string | undefined, 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, metadata?: unknown | undefined}>) | undefined, contractor_payments?: (Array<{contractor: string, payment_method?: string | undefined, amount?: string | undefined, reimbursement_amount?: string | undefined, paper_check_number?: string | undefined, workplace?: string | undefined}>) | undefined, metadata?: unknown | undefined, bank_account?: string | undefined}}; export type CreateApiPayrollsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiPayrollsResponse = z.object({id: z.string().optional(), company: z.string().optional(), period_start: z.string().optional(), period_end: z.string().optional(), approval_deadline: z.string().optional(), approved_at: z.string().optional(), payday: z.string().optional(), status: z.string().optional(), type: z.string().optional(), pay_frequency: z.string().optional(), funding_payment_method: z.string().optional(), processing_period: z.string().optional(), off_cycle_options: z.unknown(), managed: z.boolean().optional(), totals: z.object({employee_gross: z.string().optional(), employee_reimbursements: z.string().optional(), employee_taxes: z.string().optional(), employee_benefits: z.string().optional(), post_tax_deductions: z.string().optional(), employee_net: z.string().optional(), contractor_gross: z.string().optional(), contractor_reimbursements: z.string().optional(), contractor_net: z.string().optional(), company_taxes: z.string().optional(), company_benefits: z.string().optional(), liability: z.string().optional(), cash_requirement: z.string().optional()}).optional(), items: z.array(z.object({id: z.string().optional(), payroll: z.string().optional(), employee: z.string().optional(), payment_method: z.string().optional(), net_pay: z.string().optional(), earnings: z.array(z.object({amount: z.string().optional(), hours: z.number().int().optional(), type: z.string().optional(), workplace: z.string().optional(), code: z.unknown(), description: z.unknown()})).optional(), reimbursements: z.array(z.unknown()).optional(), taxes: z.array(z.object({tax: z.string().optional(), description: z.string().optional(), amount: z.string().optional(), payer: z.string().optional()})).optional(), benefits: z.array(z.unknown()).optional(), benefit_overrides: z.array(z.unknown()).optional(), post_tax_deductions: z.array(z.unknown()).optional(), post_tax_deduction_overrides: z.array(z.unknown()).optional(), tax_overrides: z.array(z.unknown()).optional(), warnings: z.array(z.unknown()).optional()})).optional(), contractor_payments: z.array(z.object({contractor: z.string().optional(), payment_method: z.string().optional(), amount: z.string().optional(), reimbursement_amount: z.string().optional()})).optional(), correction: z.string().nullable().optional(), is_void: z.boolean().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 }; /** * Create a payroll * * POST /payrolls */ export const createApiPayrolls = async (args: CreateApiPayrollsArgs, options?: CreateApiPayrollsOptions) => { 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 (args.include_items != null) query.append("include_items", String(args.include_items)) if (args.include_contractor_payments != null) query.append("include_contractor_payments", String(args.include_contractor_payments)) if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/payrolls${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiPayrollsResponse, await res.json()) };