import {z} from 'zod' export type CompaniesGovernmentId = {type: 'curp' | 'rfc', value: string} | null; 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 CompaniesUpdateRegisteredAddress = {id?: string | undefined, address_line_1?: string | undefined, address_line_2?: (string | null) | undefined, city?: string | undefined, country?: IsoCountryCode | undefined, postal_code?: string | undefined, state?: string | undefined} | null; export type CompaniesUpdateCompany = {acting_team_member: string, collect_tax_form?: boolean | undefined, display_name?: string | undefined, external_id?: string | undefined, government_id?: CompaniesGovernmentId | undefined, ledger_name?: string | undefined, registered_address?: CompaniesUpdateRegisteredAddress | undefined, business_name?: string | undefined} | {acting_team_member: string, collect_tax_form?: boolean | undefined, display_name?: string | undefined, external_id?: string | undefined, government_id?: CompaniesGovernmentId | undefined, ledger_name?: string | undefined, registered_address?: CompaniesUpdateRegisteredAddress | undefined, business_contact_first_name?: string | undefined, business_contact_last_name?: string | undefined}; export type PatchApiV1CompaniesCompanyIdArgs = {company_id: string, body: CompaniesUpdateCompany}; export type PatchApiV1CompaniesCompanyIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const sharedSelfLink = z.string(); export const sharedListLinks = z.object({self: sharedSelfLink, next: z.string().nullable().optional(), prev: z.string().nullable().optional()}); export const sharedPhoneNumber = z.string().min(6).max(16); 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 contactsContactLinks = z.object({company: z.string(), invitation_url: z.string().optional(), self: sharedSelfLink}); export const contactsContact = z.object({object: z.literal("Contact"), id: z.string(), default_contact_for_company_management: z.enum(["actionable", "read_only", "none", "", "self_managed"]), default_contact_for_payable_and_receivable: z.enum(["actionable", "read_only", "none", "", "self_managed"]), email: z.string().nullable().optional(), first_name: z.string().optional(), is_archived: z.boolean(), last_email_delivery_problem: z.enum(["auto_responder", "hard_bounce", "refused", "soft_bounce", "spam_complaint", "spam_notification", "transient", "unknown"]).nullable().optional(), last_name: z.string().optional(), phone_number: sharedPhoneNumber.nullable(), phone_number_country: isoCountryCodeAll.nullable(), links: contactsContactLinks}); export const contactsContactList = z.object({object: z.literal("List"), links: sharedListLinks, results: z.array(contactsContact)}); 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 companiesCompanyLedgerMeta = z.object({customer_id: z.string().nullable().optional(), vendor_id: z.string().nullable().optional()}); export const companiesRegisteredAddress = 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(), object: z.literal("Address"), id: z.string()}).nullable(); export const complianceChecksComplianceStatus = z.enum(["cant_validate", "dismissed", "not_evaluated", "outdated", "passed", "queued", "review_required"]); export const companiesStatus = z.enum(["accepted", "added", "invited"]); export const sharedTaxFormStatus = z.enum(["archived", "completed", "expired", "none"]); export const sharedCompanyType = z.enum(["business", "personal"]); export const companiesCompanyLinks = z.object({self: sharedSelfLink, compliance_checks: z.string(), contacts: z.string(), payables: z.string(), payment_methods: z.string(), receivables: z.string(), tax_forms: z.string()}); export const companiesCompany = z.object({object: z.literal("Company"), id: z.string(), business_name: z.string(), collect_tax_form: z.boolean().optional(), contacts: contactsContactList.optional(), country_code: isoCountryCode.optional(), created_at: z.string(), display_name: z.string(), external_id: z.string().nullable(), is_archived: z.boolean().optional(), is_customer: z.boolean(), is_vendor: z.boolean(), ledger: companiesCompanyLedgerMeta, registered_address: z.union([companiesRegisteredAddress, z.object({}).nullable()]).optional(), risk_summary: complianceChecksComplianceStatus.optional(), status: companiesStatus, tax_form_status: sharedTaxFormStatus, tax_form_type: z.enum(["w9", "w8ben", "w8ben_e"]).nullable().optional(), type: sharedCompanyType, links: companiesCompanyLinks}); 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 }; /** * Update a Company * * PATCH /v1/companies/{company_id} */ export const patchApiV1CompaniesCompanyId = async (args: PatchApiV1CompaniesCompanyIdArgs, options?: PatchApiV1CompaniesCompanyIdOptions) => { 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))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(companiesCompany, await res.json()) };