import {z} from 'zod' export type GetApiV1CustomersArgs = {'search.customer_id'?: Array | undefined, 'search.account_number'?: Array | undefined, 'search.parent_customer_id'?: Array | undefined, 'search.is_parent'?: boolean | undefined, 'search.bill_profile_id'?: Array | undefined, 'search.status'?: ('ALL' | 'PROSPECT' | 'PENDING' | 'CLOSED' | 'OPEN') | undefined, 'search.name'?: string | undefined, 'search.created_date_start'?: string | undefined, 'search.created_date_end'?: string | undefined, 'search.agent_id'?: Array | undefined, 'search.updated_date_start'?: string | undefined, 'search.updated_date_end'?: string | undefined, 'search.suspended'?: boolean | undefined, 'search.page_size'?: number | undefined, 'search.page'?: number | undefined, 'search.sort'?: string | undefined}; export type GetApiV1CustomersOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const revAppComponentsLink = z.object({rel: z.string().optional(), href: z.string().optional()}); export const revAppModelsAddress = z.object({address_id: z.number().int().optional(), customer_id: z.number().int().optional(), first_name: z.string().max(255).optional(), middle_initial: z.string().max(10).optional(), last_name: z.string().max(255).optional(), company_name: z.string().max(255).optional(), line_1: z.string().max(500).optional(), line_2: z.string().max(500).optional(), city: z.string().max(255).optional(), state_or_province: z.string().max(50).optional(), postal_code: z.string().max(12).optional(), postal_code_extension: z.string().optional(), country_code: z.enum(["AFG", "ALA", "ALB", "DZA", "ASM", "AND", "AGO", "AIA", "ATA", "ATG", "ARG", "ARM", "ABW", "AUS", "AUT", "AZE", "BHS", "BHR", "BGD", "BRB", "BLR", "BEL", "BLZ", "BEN", "BMU", "BTN", "BOL", "BES", "BIH", "BWA", "BVT", "BRA", "IOT", "BRN", "BGR", "BFA", "BDI", "CPV", "KHM", "CMR", "CAN", "CYM", "CAF", "TCD", "CHL", "CHN", "CXR", "CCK", "COL", "COM", "COG", "COD", "COK", "CRI", "CIV", "HRV", "CUB", "CUW", "CYP", "CZE", "DNK", "DJI", "DMA", "DOM", "ECU", "EGY", "SLV", "GNQ", "ERI", "EST", "ETH", "FLK", "FRO", "FJI", "FIN", "FRA", "GUF", "PYF", "ATF", "GAB", "GMB", "GEO", "DEU", "GHA", "GIB", "GRC", "GRL", "GRD", "GLP", "GUM", "GTM", "GGY", "GIN", "GNB", "GUY", "HTI", "HMD", "VAT", "HND", "HKG", "HUN", "ISL", "IND", "IDN", "IRN", "IRQ", "IRL", "IMN", "ISR", "ITA", "JAM", "JPN", "JEY", "JOR", "KAZ", "KEN", "KIR", "PRK", "KOR", "XKX", "KWT", "KGZ", "LAO", "LVA", "LBN", "LSO", "LBR", "LBY", "LIE", "LTU", "LUX", "MAC", "MKD", "MDG", "MWI", "MYS", "MDV", "MLI", "MLT", "MHL", "MTQ", "MRT", "MUS", "MYT", "MEX", "FSM", "MDA", "MCO", "MNG", "MNE", "MSR", "MAR", "MOZ", "MMR", "NAM", "NRU", "NPL", "NLD", "NCL", "NZL", "NIC", "NER", "NGA", "NIU", "NFK", "MNP", "NOR", "OMN", "PAK", "PLW", "PSE", "PAN", "PNG", "PRY", "PER", "PHL", "PCN", "POL", "PRT", "PRI", "QAT", "REU", "ROU", "RUS", "RWA", "BLM", "SHN", "KNA", "LCA", "MAF", "SPM", "VCT", "WSM", "SMR", "STP", "SAU", "SEN", "SRB", "SYC", "SLE", "SGP", "SXM", "SVK", "SVN", "SLB", "SOM", "ZAF", "SGS", "SSD", "ESP", "LKA", "SDN", "SUR", "SJM", "SWZ", "SWE", "CHE", "SYR", "TWN", "TJK", "TZA", "THA", "TLS", "TGO", "TKL", "TON", "TTO", "TUN", "TUR", "TKM", "TCA", "TUV", "UGA", "UKR", "ARE", "GBR", "USA", "UMI", "URY", "UZB", "VUT", "VEN", "VNM", "VGB", "VIR", "WLF", "ESH", "YEM", "ZMB", "ZWE", "ANT", "SCG", "YUG"]).optional(), created_date: z.string().optional(), modified_date: z.string().optional(), is_provider_validated: z.boolean().optional(), is_USPS_validated: z.boolean().optional(), links: z.array(revAppComponentsLink).optional()}); export const revAppModelsCustomersAutoDebit = z.object({enabled: z.boolean().optional(), day: z.number().int().optional(), payment_account_id: z.number().int().optional()}); export const revAppModelsCustomersFinance = z.object({amount_due: z.number().optional(), amount_overdue: z.number().optional(), bill_profile_id: z.number().int().optional(), billing_method: z.enum(["PRINT_ONLY", "EMAIL_ONLY", "BOTH", "NONE"]).optional(), balance: z.number().optional(), balance_limit: z.number().optional(), balance_limit_enabled: z.boolean().optional(), due_date: z.string().optional(), collection_template_id: z.number().int().gte(0).lte(2147483647).optional(), contract_end_date: z.string().optional(), contract_start_date: z.string().optional(), cycle_date: z.string().optional(), late_fees_enabled: z.boolean().optional(), payment_terms_days: z.number().int().optional(), tax_exempt_enabled: z.boolean().optional(), tax_exempt_types: z.string().max(512).optional(), usage_file_enabled: z.boolean().optional(), usage_file_format: z.enum(["H2O", "EMI", "Reseller"]).optional(), payment_fees_enabled: z.boolean().optional(), links: z.array(revAppComponentsLink).optional()}); export const revAppModelsCustomersProfile = z.object({class: z.enum(["Business", "Residential"]).optional(), date_of_birth: z.string().optional(), language: z.string().max(100).optional(), tax_id: z.string().max(50).optional()}); export const revAppModelsFieldValue = z.object({field_id: z.number().int().optional(), label: z.string().optional(), value: z.string().optional(), links: z.array(revAppComponentsLink).optional()}); export const revAppModelsCustomersCustomer = z.object({billing_address: revAppModelsAddress.optional(), service_address: revAppModelsAddress.optional(), listing_address: revAppModelsAddress.optional(), currency_code: z.enum(["USD", "AFN", "DZD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "THB", "PAB", "BBD", "BYN", "BZD", "BMD", "VEF", "BOB", "BRL", "BND", "BGN", "BIF", "CVE", "CAD", "KYD", "XOF", "XAF", "XPF", "CLP", "COP", "KMF", "CDF", "BAM", "NIO", "CRC", "CUP", "CZK", "GMD", "DKK", "MKD", "DJF", "STD", "DOP", "VND", "XCD", "EGP", "SVC", "ETB", "EUR", "FKP", "FJD", "HUF", "GHS", "GIP", "HTG", "PYG", "GNF", "GYD", "HKD", "UAH", "ISK", "INR", "IRR", "IQD", "JMD", "JOD", "KES", "PGK", "LAK", "HRK", "KWD", "AOA", "MMK", "GEL", "LBP", "ALL", "HNL", "SLL", "LRD", "LYD", "SZL", "LSL", "MGA", "MWK", "MYR", "MUR", "MXN", "MXV", "MDL", "MAD", "MZN", "BOV", "NGN", "ERN", "NAD", "NPR", "ANG", "ILS", "TWD", "NZD", "BTN", "KPW", "NOK", "MRO", "TOP", "PKR", "MOP", "CUC", "UYU", "PHP", "GBP", "BWP", "QAR", "GTQ", "ZAR", "OMR", "KHR", "RON", "MVR", "IDR", "RUB", "RWF", "SHP", "SAR", "RSD", "SCR", "SGD", "PEN", "SBD", "KGS", "SOS", "TJS", "SSP", "LKR", "SDG", "SRD", "SEK", "CHF", "SYP", "BDT", "WST", "TZS", "KZT", "TTD", "MNT", "TND", "TRY", "TMT", "AED", "UGX", "CLF", "COU", "UYI", "USN", "UZS", "VUV", "CHE", "CHW", "KRW", "YER", "JPY", "CNY", "ZMW", "ZWL", "PLN"]).optional(), customer_id: z.number().int().optional(), parent_customer_id: z.number().int().optional(), account_number: z.string().max(25).optional(), activated_date: z.string().optional(), agent_id: z.number().int().optional(), secondary_agent_id: z.number().int().optional(), close_date: z.string().optional(), created_by: z.number().int().optional(), created_date: z.string().optional(), updated_date: z.string().optional(), email: z.string().max(255).optional(), is_parent: z.boolean().optional(), registration_code: z.string().max(20).optional(), security_pin: z.string().max(50).optional(), sold_by: z.number().int().optional(), source: z.string().optional(), status: z.enum(["ALL", "PROSPECT", "PENDING", "CLOSED", "OPEN"]).optional(), auto_debit: revAppModelsCustomersAutoDebit.optional(), finance: revAppModelsCustomersFinance.optional(), profile: revAppModelsCustomersProfile.optional(), fields: z.array(revAppModelsFieldValue).optional(), suspended: z.boolean().optional(), suspended_date: z.string().optional(), culture: z.string().optional(), prevent_closing_for_no_active_service_products: z.boolean().optional(), links: z.array(revAppComponentsLink).optional()}); export const revWebAPIModelsGetOrSearchOfRevAppSearchModelsResponseOfRevAppModelsCustomersCustomer = z.object({ok: z.boolean().optional(), has_more: z.boolean().optional(), record_count: z.number().int().optional(), records: z.array(revAppModelsCustomersCustomer).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 }; /** * Search customers * * GET /v1/Customers */ export const getApiV1Customers = async (args: GetApiV1CustomersArgs, options?: GetApiV1CustomersOptions) => { const {baseUrl = "https://restapi.rev.io", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args['search.customer_id'] ?? []) query.append("search.customer_id", String(item)) for (const item of args['search.account_number'] ?? []) query.append("search.account_number", String(item)) for (const item of args['search.parent_customer_id'] ?? []) query.append("search.parent_customer_id", String(item)) if (args['search.is_parent'] != null) query.append("search.is_parent", String(args['search.is_parent'])) for (const item of args['search.bill_profile_id'] ?? []) query.append("search.bill_profile_id", String(item)) if (args['search.status'] != null) query.append("search.status", String(args['search.status'])) if (args['search.name'] != null) query.append("search.name", String(args['search.name'])) if (args['search.created_date_start'] != null) query.append("search.created_date_start", String(args['search.created_date_start'])) if (args['search.created_date_end'] != null) query.append("search.created_date_end", String(args['search.created_date_end'])) for (const item of args['search.agent_id'] ?? []) query.append("search.agent_id", String(item)) if (args['search.updated_date_start'] != null) query.append("search.updated_date_start", String(args['search.updated_date_start'])) if (args['search.updated_date_end'] != null) query.append("search.updated_date_end", String(args['search.updated_date_end'])) if (args['search.suspended'] != null) query.append("search.suspended", String(args['search.suspended'])) if (args['search.page_size'] != null) query.append("search.page_size", String(args['search.page_size'])) if (args['search.page'] != null) query.append("search.page", String(args['search.page'])) if (args['search.sort'] != null) query.append("search.sort", String(args['search.sort'])) if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Customers${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(revWebAPIModelsGetOrSearchOfRevAppSearchModelsResponseOfRevAppModelsCustomersCustomer, await res.json()) };