import {z} from 'zod' export type GetApiEmployeeTaxStatementsArgs = {employee?: string | undefined, company?: string | undefined, year?: number | undefined, form?: ('fed_w2' | 'vi_w2vi') | undefined, publication_status?: ('draft' | 'published' | 'pending_correction') | undefined, type?: ('original' | 'amendment') | undefined, published_from?: string | undefined}; export type GetApiEmployeeTaxStatementsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiEmployeeTaxStatementsResponse = z.array(z.object({id: z.string().optional(), employee: z.string().optional(), company: z.string().optional(), year: z.number().int().optional(), form: z.enum(["fed_w2", "fed_w2c", "vi_w2vi", "vi_w2vic"]).optional(), amends: z.unknown(), amended_by: z.unknown(), document: z.unknown(), filings: z.array(z.string()).optional(), filed_at: z.unknown(), refreshed_at: z.string().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 tax statements * * GET /employee_tax_statements */ export const getApiEmployeeTaxStatements = async (args: GetApiEmployeeTaxStatementsArgs, options?: GetApiEmployeeTaxStatementsOptions) => { 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.employee != null) query.append("employee", String(args.employee)) if (args.company != null) query.append("company", String(args.company)) if (args.year != null) query.append("year", String(args.year)) if (args.form != null) query.append("form", String(args.form)) if (args.publication_status != null) query.append("publication_status", String(args.publication_status)) if (args.type != null) query.append("type", String(args.type)) if (args.published_from != null) query.append("published_from", String(args.published_from)) if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/employee_tax_statements${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(getApiEmployeeTaxStatementsResponse, await res.json()) };