import {z} from 'zod' export type CreateApiContractorsArgs = {body: {company: string, type?: string | undefined, first_name?: string | undefined, middle_name?: string | undefined, last_name: string, business_name?: string | undefined, dob?: string | undefined, start_date?: string | undefined, termination_date?: string | undefined, workplaces?: Array | undefined, primary_workplace?: string | undefined, email?: string | undefined, ssn?: string | undefined, ein?: string | undefined, default_net_pay_split?: string | undefined, payment_method_preference?: string | undefined, address?: ({line1: string, line2?: string | undefined, city: string, state: string, postal_code: string, country?: string | undefined}) | undefined, '1099_nec_electronic_consent_provided'?: boolean | undefined, metadata?: unknown | undefined}}; export type CreateApiContractorsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiContractorsResponse = z.object({}); 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 contractor * * POST /contractors */ export const createApiContractors = async (args: CreateApiContractorsArgs, options?: CreateApiContractorsOptions) => { 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(/\/+$/, '')}/contractors${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(createApiContractorsResponse, await res.json()) };