import {z} from 'zod' export type GetApiV1CompaniesCompanyIdTaxFormsArgs = {company_id: string}; export type GetApiV1CompaniesCompanyIdTaxFormsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const sharedBusinessEntityType = z.enum(["c_corporation", "llc_c_corp", "llc_partnership", "llc_s_corp", "llc_single_member", "llc_trust_estate", "other", "partnership", "s_corporation", "sole_proprietorship", "trust_estate"]).nullable(); export const taxFormsCertifiedVia = z.enum(["pdf_upload", "substitute_form"]); export const sharedCompanyType = z.enum(["business", "personal"]); export const taxFormsExemptionFatcaCode = z.enum(["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"]).nullable(); export const taxFormsExemptionPayeeCode = z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7), z.literal(8), z.literal(9), z.literal(10), z.literal(11), z.literal(12), z.literal(13)]).nullable(); export const isoCountryCode = z.enum(["AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BW", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CL", "CM", "CN", "CO", "CR", "CV", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IQ", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MX", "MW", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RW", "SA", "SB", "SC", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SV", "SX", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VI", "VN", "VU", "XK", "WF", "WS", "XX", "YE", "YT", "ZA", "ZM", "ZW"]).min(2).max(2); export const sharedAddress = z.object({address_line_1: z.string(), address_line_2: z.string().nullable().optional(), city: z.string(), country: isoCountryCode, postal_code: z.string(), state: z.string().optional()}); export const isoCountryCodeAll = z.enum(["AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "XK", "XX", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"]).min(2).max(2); export const taxFormsForeignGovernmentId = z.object({type: z.string().nullable().optional(), value: z.string().max(18)}); export const taxFormsTreatyBenefitsW8BEN = z.object({article_and_paragraph: z.string().max(64).nullable(), type_of_income: z.string().max(128).nullable(), withholding_rate: z.string().nullable()}); export const taxFormsGIIN = z.string().min(16).max(16); export const taxFormsTreatyBenefitsW8BENE = z.object({article_and_paragraph: z.string().max(64).nullable(), limitation_on_benefits: z.enum(["active_trade_or_business_test", "derivative_benefits_test", "discretionary_determination", "government", "no_lob_article", "other_tax_exempt", "other", "ownership_and_base_erosion_test", "publicly_traded_corporation", "publicly_traded_subsidiary", "tax_exempt_pension"]).max(128).nullable().optional(), type_of_income: z.string().max(128).nullable(), withholding_rate: z.string().nullable()}); export const taxFormsTaxForm = z.union([z.object({id: z.string().optional(), object: z.literal("TaxForm").optional(), business_name: z.string().max(128).optional(), business_entity_type: sharedBusinessEntityType.optional(), business_entity_type_other_description: z.string().optional(), certified_via: taxFormsCertifiedVia.optional(), company_type: sharedCompanyType, display_name: z.string().max(128).optional(), expires_on: z.string().optional(), exemption_fatca_code: taxFormsExemptionFatcaCode.optional(), exemption_payee_code: taxFormsExemptionPayeeCode.optional(), government_id: z.object({type: z.enum(["ein", "ssn"]), value: z.string().min(9).max(9)}).nullable().optional(), legal_first_name: z.string().max(128).optional(), legal_last_name: z.string().max(128).optional(), mailing_address: sharedAddress.optional(), signature: z.string().max(64).optional(), status: z.enum(["archived", "completed", "expired", "none"]).optional(), submitted_at: z.string().optional(), submitted_via: z.enum(["api", "dashboard", "invitation"]).optional(), type: z.literal("w9").optional(), uploaded_form: z.object({signed_on: z.string().optional()}).nullable().optional(), links: z.object({self: z.string(), company: z.string()}).optional()}), z.object({id: z.string().optional(), object: z.literal("TaxForm").optional(), certified_via: taxFormsCertifiedVia.optional(), country_code: isoCountryCodeAll, expires_on: z.string().optional(), government_id: taxFormsForeignGovernmentId.optional(), legal_name: z.string().max(128), mailing_address: sharedAddress.optional(), residence_address: sharedAddress, status: z.enum(["archived", "completed", "expired", "none"]).optional(), submitted_at: z.string().optional(), submitted_via: z.enum(["api", "dashboard", "invitation"]).optional(), treaty_benefits: taxFormsTreatyBenefitsW8BEN.optional(), type: z.literal("w8ben").optional(), us_government_id: z.object({type: z.enum(["ssn", "itin"]), value: z.string().min(9).max(9)}).nullable().optional(), links: z.object({self: z.string(), company: z.string()}).optional()}), z.object({id: z.string().optional(), object: z.literal("TaxForm").optional(), certified_via: taxFormsCertifiedVia.optional(), chapter_three_status: z.enum(["central_bank_of_issue", "complex_trust", "corporation", "disregarded_entity", "estate", "foreign_government_controlled_entity", "foreign_government_integral_part", "grantor_trust", "international_organization", "partnership", "private_foundation", "simple_trust", "tax_exempt_organization"]).max(64), chapter_four_status: z.enum(["501c", "active_nffe", "passive_nffe", "publicly_traded_nffe"]).max(120).optional(), country_code: isoCountryCodeAll, expires_on: z.string().optional(), government_id: taxFormsForeignGovernmentId.optional(), giin: taxFormsGIIN.optional(), legal_name: z.string().max(128), mailing_address: sharedAddress.optional(), payment_received_by_intermediary: z.boolean().optional(), residence_address: sharedAddress, status: z.enum(["archived", "completed", "expired", "none"]).optional(), submitted_at: z.string().optional(), submitted_via: z.enum(["api", "dashboard", "invitation"]).optional(), treaty_benefits: taxFormsTreatyBenefitsW8BENE.optional(), type: z.literal("w8ben_e").optional(), us_government_id: z.object({type: z.literal("tin").optional(), value: z.string().min(9).max(9).optional()}).nullable().optional(), links: z.object({self: z.string(), company: z.string()}).optional()})]); export const taxFormsTaxFormList = z.object({object: z.literal("List"), results: z.array(taxFormsTaxForm), links: z.object({self: z.string().optional(), company: 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 Tax Forms (Completed) * * GET /v1/companies/{company_id}/tax-forms */ export const getApiV1CompaniesCompanyIdTaxForms = async (args: GetApiV1CompaniesCompanyIdTaxFormsArgs, options?: GetApiV1CompaniesCompanyIdTaxFormsOptions) => { const {baseUrl = "https://api.routable.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/companies/${encodeURIComponent(String(args.company_id))}/tax-forms${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(taxFormsTaxFormList, await res.json()) };