import {z} from 'zod' export type GetApiCompaniesCompanyArgs = {company: string}; export type GetApiCompaniesCompanyOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiCompaniesCompanyResponse = z.object({id: z.string().optional(), legal_name: z.string().optional(), trade_name: z.string().optional(), other_business_name: z.string().optional(), business_type: z.string().optional(), industry_type: z.string().optional(), website: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), pay_frequency: z.string().optional(), bank_accounts: z.array(z.string()).optional(), statement_descriptor: z.string().optional(), active: z.boolean().optional(), address: z.object({line1: z.string().optional(), line2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), postal_code: z.string().optional(), country: z.string().optional()}).optional(), principal_place_of_business: z.string().optional(), onboard: z.object({status: z.string().optional(), blocking_steps: z.array(z.object({})).optional(), remaining_steps: z.array(z.object({})).optional()}).optional(), implementation: z.object({status: z.string().optional(), remaining_steps: z.object({kyb: z.object({status: z.string().optional()}).optional()}).optional()}).optional(), in_good_standing: z.boolean().optional(), processing_period: z.string().optional(), start_date: z.string().optional(), metadata: z.object({}).optional(), employee_w2_delivery_method: z.string().optional(), contractor_1099_delivery_method: z.string().optional(), processing_period_eligibility: z.array(z.enum(["three_day", "two_day", "one_day"])).nullable().optional(), default_bank_account: 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 }; /** * Get a company * * GET /companies/{company} */ export const getApiCompaniesCompany = async (args: GetApiCompaniesCompanyArgs, options?: GetApiCompaniesCompanyOptions) => { 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 (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/companies/${encodeURIComponent(String(args.company))}${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(getApiCompaniesCompanyResponse, await res.json()) };