import {z} from 'zod' export type IsoCountryCodeAll = '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'; export type TaxFormsForeignGovernmentId = {type?: (string | null) | undefined, value: string}; export type IsoCountryCode = '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'; export type SharedAddress = {address_line_1: string, address_line_2?: (string | null) | undefined, city: string, country: IsoCountryCode, postal_code: string, state?: string | undefined}; export type TaxFormsTreatyBenefitsW8BEN = {article_and_paragraph: string | null, type_of_income: string | null, withholding_rate: unknown | null}; export type TaxFormsUSGovernmentIDPersonal = {type: 'ssn' | 'itin', value: string}; export type TaxFormsUploadedForm = {data_uri: string, name: string, signed_on: string}; export type TaxFormsGIIN = string; export type TaxFormsTreatyBenefitsW8BENE = {article_and_paragraph: string | null, limitation_on_benefits?: ('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' | null) | undefined, type_of_income: string | null, withholding_rate: unknown | null}; export type TaxFormsUSGovernmentIDCompany = {type?: 'tin' | undefined, value?: string | undefined}; export type SharedBusinessEntityType = 'c_corporation' | 'llc_c_corp' | 'llc_partnership' | 'llc_s_corp' | 'llc_single_member' | 'llc_trust_estate' | 'other' | 'partnership' | 's_corporation' | 'sole_proprietorship' | 'trust_estate' | null; export type TaxFormsExemptionFatcaCode = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | null; export type TaxFormsExemptionPayeeCode = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | null; export type CompaniesUSGovernmentId = {type: 'ein' | 'ssn', value: string}; export type TaxFormsNewCompanyTaxForm = {acting_team_member: string, country_code: IsoCountryCodeAll, government_id?: TaxFormsForeignGovernmentId | undefined, legal_name: string, mailing_address?: SharedAddress | undefined, residence_address: SharedAddress, signature?: string | undefined, treaty_benefits?: TaxFormsTreatyBenefitsW8BEN | undefined, type?: 'w8ben' | undefined, us_government_id?: TaxFormsUSGovernmentIDPersonal | undefined, uploaded_form?: TaxFormsUploadedForm | undefined} | {acting_team_member: string, chapter_three_status: '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', chapter_four_status?: ('501c' | 'active_nffe' | 'passive_nffe' | 'publicly_traded_nffe') | undefined, country_code: IsoCountryCodeAll, government_id?: TaxFormsForeignGovernmentId | undefined, giin?: TaxFormsGIIN | undefined, legal_name: string, mailing_address?: SharedAddress | undefined, payment_received_by_intermediary?: boolean | undefined, residence_address: SharedAddress, treaty_benefits?: TaxFormsTreatyBenefitsW8BENE | undefined, type?: 'w8ben_e' | undefined, us_government_id?: TaxFormsUSGovernmentIDCompany | undefined, uploaded_form: TaxFormsUploadedForm} | {acting_team_member: string, business_name?: string | undefined, business_entity_type?: SharedBusinessEntityType | undefined, business_entity_type_other_description?: string | undefined, display_name?: string | undefined, exemption_fatca_code?: TaxFormsExemptionFatcaCode | undefined, exemption_payee_code?: TaxFormsExemptionPayeeCode | undefined, government_id: CompaniesUSGovernmentId, legal_first_name?: string | undefined, legal_last_name?: string | undefined, mailing_address: SharedAddress, signature?: string | undefined, type?: 'w9' | undefined, uploaded_form?: TaxFormsUploadedForm | undefined}; export type CreateApiV1CompaniesCompanyIdTaxFormsArgs = {company_id: string, body: TaxFormsNewCompanyTaxForm}; export type CreateApiV1CompaniesCompanyIdTaxFormsOptions = {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 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 Company Tax Form * * POST /v1/companies/{company_id}/tax-forms */ export const createApiV1CompaniesCompanyIdTaxForms = async (args: CreateApiV1CompaniesCompanyIdTaxFormsArgs, options?: CreateApiV1CompaniesCompanyIdTaxFormsOptions) => { const {baseUrl = "https://api.routable.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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: "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(taxFormsTaxForm, await res.json()) };