import {z} from 'zod' export type GetApiEmployeesEmployeePaystubsCOPYArgs = {employee: string, payroll?: string | undefined, limit?: number | undefined, status?: string | undefined, start?: string | undefined, end?: string | undefined}; export type GetApiEmployeesEmployeePaystubsCOPYOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiEmployeesEmployeePaystubsCOPYResponse = z.object({next: z.unknown(), previous: z.unknown(), results: z.array(z.object({payroll: z.string().optional(), payday: z.string().optional(), period_start: z.string().optional(), period_end: z.string().optional(), company: z.object({trade_name: z.unknown(), legal_name: z.string().optional(), address: z.object({line1: z.string().optional(), line2: z.unknown(), city: z.string().optional(), state: z.string().optional(), postal_code: z.string().optional(), country: z.string().optional()}).optional(), phone: z.string().optional()}).optional(), void_of: z.unknown(), voided_by: z.unknown(), employee: z.object({first_name: z.string().optional(), middle_name: z.unknown(), last_name: z.string().optional(), residence: z.object({line1: z.string().optional(), line2: z.unknown(), city: z.string().optional(), state: z.string().optional(), postal_code: z.string().optional(), country: z.string().optional()}).optional(), ssn_last_four: z.unknown()}).optional(), earnings: z.array(z.object({type: z.string().optional(), code: z.unknown(), earning_code: z.unknown(), amount: z.string().optional(), amount_ytd: z.string().optional(), hours: z.number().int().optional(), hours_ytd: z.number().int().optional(), name: z.string().optional(), current_earnings: z.array(z.object({description: z.string().optional(), amount: z.string().optional(), hours: z.number().int().optional(), workplace: z.string().optional(), rate: z.string().optional()})).optional()})).optional(), reimbursements: z.array(z.unknown()).optional(), employee_taxes: z.array(z.object({amount: z.string().optional(), amount_ytd: z.string().optional(), description: z.string().optional()})).optional(), company_taxes: z.array(z.object({amount: z.string().optional(), amount_ytd: z.string().optional(), description: z.string().optional()})).optional(), employee_benefit_contributions: z.array(z.unknown()).optional(), company_benefit_contributions: z.array(z.unknown()).optional(), post_tax_deductions: z.array(z.unknown()).optional(), summary: z.object({earnings: z.string().optional(), earnings_ytd: z.string().optional(), reimbursements: z.string().optional(), reimbursements_ytd: z.string().optional(), employee_taxes: z.string().optional(), employee_taxes_ytd: z.string().optional(), company_taxes: z.string().optional(), company_taxes_ytd: z.string().optional(), employee_benefit_contributions: z.string().optional(), employee_benefit_contributions_ytd: z.string().optional(), company_benefit_contributions: z.string().optional(), company_benefit_contributions_ytd: z.string().optional(), post_tax_deductions: z.string().optional(), post_tax_deductions_ytd: z.string().optional(), net_pay: z.string().optional(), net_pay_ytd: z.string().optional()}).optional(), time_off_balances: z.object({pto_balance_hours: z.unknown(), sick_balance_hours: z.unknown(), state_covid_sick_balance_hours: z.unknown()}).optional()})).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 }; /** * List employee paystubs * * GET /employees/{employee}/paystubs (COPY) */ export const getApiEmployeesEmployeePaystubsCOPY = async (args: GetApiEmployeesEmployeePaystubsCOPYArgs, options?: GetApiEmployeesEmployeePaystubsCOPYOptions) => { const {baseUrl = "https://sandbox.checkhq.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.payroll != null) query.append("payroll", String(args.payroll)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.status != null) query.append("status", String(args.status)) if (args.start != null) query.append("start", String(args.start)) if (args.end != null) query.append("end", String(args.end)) if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/employees/${encodeURIComponent(String(args.employee))}/paystubs (COPY)${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiEmployeesEmployeePaystubsCOPYResponse, await res.json()) };