import {z} from 'zod' export type GetApiIdentitiesArgs = {'Finix-Version'?: string | undefined, after_cursor?: string | undefined, before_cursor?: string | undefined, business_name?: string | undefined, business_type?: ('INDIVIDUAL_SOLE_PROPRIETORSHIP' | 'CORPORATION' | 'LIMITED_LIABILITY_COMPANY' | 'PARTNERSHIP' | 'LIMITED_PARTNERSHIP' | 'GENERAL_PARTNERSHIP' | 'ASSOCIATION_ESTATE_TRUST' | 'TAX_EXEMPT_ORGANIZATION' | 'GOVERNMENT_AGENCY') | undefined, 'created_at.gte'?: string | undefined, 'created_at.lte'?: string | undefined, default_statement_descriptor?: string | undefined, email?: string | undefined, first_name?: string | undefined, id?: string | undefined, identity_role?: ('APPLICATION_OWNER' | 'BENEFICIAL_OWNER' | 'BUYER' | 'PLATFORM_OWNER' | 'RECIPIENT' | 'SELLER' | 'SENDER') | undefined, last_name?: string | undefined, limit?: number | undefined, 'tags.key'?: string | undefined, 'tags.value'?: string | undefined, title?: string | undefined, type?: ('BUSINESS' | 'PERSONAL') | undefined, 'updated_at.gte'?: string | undefined, 'updated_at.lte'?: string | undefined}; export type GetApiIdentitiesOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const page = z.object({limit: z.number().int().optional(), next_cursor: z.string().nullable().optional()}); export const id = z.string().min(1); export const createdAt = z.string(); export const updatedAt = z.string(); export const additionalUnderwritingData = z.object({annual_ach_volume: z.number().int().optional(), annual_card_volume: z.number().int().optional(), average_ach_transfer_amount: z.number().int().optional(), average_card_transfer_amount: z.number().int().optional(), business_description: z.string().min(1).optional(), card_volume_distribution: z.object({card_present_percentage: z.number().int().optional(), ecommerce_percentage: z.number().int().optional(), mail_order_telephone_order_percentage: z.number().int().optional()}).nullable().optional(), credit_check_allowed: z.boolean().optional(), credit_check_ip_address: z.string().min(1).optional(), credit_check_timestamp: z.string().min(1).optional(), credit_check_user_agent: z.string().min(1).optional(), merchant_agreement_accepted: z.boolean().optional(), merchant_agreement_ip_address: z.string().min(1).optional(), merchant_agreement_timestamp: z.string().min(1).optional(), merchant_agreement_user_agent: z.string().min(1).optional(), refund_policy: z.enum(["NO_REFUNDS", "MERCHANDISE_EXCHANGE_ONLY", "WITHIN_30_DAYS", "OTHER"]).min(1).optional(), volume_distribution_by_business_type: z.object({business_to_business_volume_percentage: z.number().int().optional(), business_to_consumer_volume_percentage: z.number().int().optional(), consumer_to_consumer_volume_percentage: z.number().int().optional(), other_volume_percentage: z.number().int().optional(), person_to_person_volume_percentage: z.number().int().optional()}).nullable().optional()}); export const statementDescriptor = z.string().max(20).nullable(); export const country = z.enum(["ABW", "AFG", "AGO", "AIA", "ALA", "ALB", "AND", "ARE", "ARG", "ARM", "ASM", "ATA", "ATF", "ATG", "AUS", "AUT", "AZE", "BDI", "BEL", "BEN", "BES", "BFA", "BGD", "BGR", "BHR", "BHS", "BIH", "BLM", "BLR", "BLZ", "BMU", "BOL", "BRA", "BRB", "BRN", "BTN", "BVT", "BWA", "CAF", "CAN", "CCK", "CHE", "CHL", "CHN", "CIV", "CMR", "COD", "COG", "COK", "COL", "COM", "CPV", "CRI", "CUB", "CUW", "CXR", "CYM", "CYP", "CZE", "DEU", "DJI", "DMA", "DNK", "DOM", "DZA", "ECU", "EGY", "ERI", "ESH", "ESP", "EST", "ETH", "FIN", "FJI", "FLK", "FRA", "FRO", "FSM", "GAB", "GBR", "GEO", "GGY", "GHA", "GIB", "GIN", "GLP", "GMB", "GNB", "GNQ", "GRC", "GRD", "GRL", "GTM", "GUF", "GUM", "GUY", "HKG", "HMD", "HND", "HRV", "HTI", "HUN", "IDN", "IMN", "IND", "IOT", "IRL", "IRN", "IRQ", "ISL", "ISR", "ITA", "JAM", "JEY", "JOR", "JPN", "KAZ", "KEN", "KGZ", "KHM", "KIR", "KNA", "KOR", "KWT", "LAO", "LBN", "LBR", "LBY", "LCA", "LIE", "LKA", "LSO", "LTU", "LUX", "LVA", "MAC", "MAF", "MAR", "MCO", "MDA", "MDG", "MDV", "MEX", "MHL", "MKD", "MLI", "MLT", "MMR", "MNE", "MNG", "MNP", "MRT", "MSR", "MTQ", "MUS", "MWI", "MYS", "MYT", "NAM", "NCL", "NER", "NFK", "NGA", "NIC", "NIU", "NLD", "NOR", "NPL", "NRU", "NZL", "OMN", "PAK", "PAN", "PCN", "PER", "PHL", "PLW", "PNG", "POL", "PRI", "PRK", "PRT", "PRY", "PSE", "PYF", "QAT", "REU", "ROU", "RUS", "RWA", "SAU", "SDN", "SEN", "SGP", "SGS", "SHN", "SJM", "SLB", "SLE", "SLV", "SMR", "SOM", "SPM", "SRB", "SSD", "STP", "SUR", "SVK", "SVN", "SWE", "SWZ", "SXM", "SYC", "SYR", "TCA", "TCD", "TGO", "THA", "TJK", "TKL", "TKM", "TLS", "TON", "TTO", "TUN", "TUR", "TUV", "TWN", "TZA", "UGA", "UKR", "UMI", "URY", "USA", "UZB", "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF", "WSM", "XKX", "YEM", "ZAF", "ZMB", "ZWE"]).nullable(); export const entity = z.object({amex_mid: z.number().int().nullable().optional(), annual_card_volume: z.number().int().nullable().optional(), business_address: z.object({line1: z.string().min(1).nullable().optional(), line2: z.string().min(1).nullable().optional(), city: z.string().min(1).nullable().optional(), region: z.string().min(1).nullable().optional(), postal_code: z.string().min(1).nullable().optional(), country: z.string().min(1).nullable().optional()}).nullable().optional(), business_name: z.string().min(1).nullable().optional(), business_phone: z.string().min(1).nullable().optional(), business_tax_id: z.string().optional(), business_tax_id_fingerprint: z.string().nullable().optional(), business_tax_id_provided: z.boolean().optional(), business_type: z.enum(["INDIVIDUAL_SOLE_PROPRIETORSHIP", "CORPORATION", "LIMITED_LIABILITY_COMPANY", "PARTNERSHIP", "LIMITED_PARTNERSHIP", "GENERAL_PARTNERSHIP", "ASSOCIATION_ESTATE_TRUST", "TAX_EXEMPT_ORGANIZATION", "GOVERNMENT_AGENCY"]).nullable().optional(), default_statement_descriptor: statementDescriptor.optional(), discover_mid: z.number().int().nullable().optional(), dob: z.object({day: z.number().int().gte(1).optional(), month: z.number().int().gte(1).optional(), year: z.number().int().gte(1900).optional()}).nullable().optional(), doing_business_as: z.string().min(1).nullable().optional(), email: z.string().min(1).nullable().optional(), first_name: z.string().min(1).nullable().optional(), has_accepted_credit_cards_previously: z.boolean().optional(), incorporation_date: z.object({day: z.number().int().optional(), month: z.number().int().optional(), year: z.number().int().optional()}).nullable().optional(), last_name: z.string().min(1).nullable().optional(), max_transaction_amount: z.number().int().nullable().optional(), ach_max_transaction_amount: z.number().int().nullable().optional(), mcc: z.string().min(1).nullable().optional(), ownership_type: z.enum(["PUBLIC", "PRIVATE"]).min(1).nullable().optional(), personal_address: z.object({line1: z.string().min(1).nullable(), line2: z.string().min(1).nullable().optional(), city: z.string().min(1).nullable(), region: z.string().min(1).nullable(), postal_code: z.string().min(1).nullable(), country: country}).nullable().optional(), phone: z.string().min(1).nullable().optional(), principal_percentage_ownership: z.number().int().nullable().optional(), short_business_name: z.string().nullable().optional(), tax_authority: z.string().nullable().optional(), tax_id: z.string().nullable().optional(), tax_id_fingerprint: z.string().nullable().optional(), tax_id_provided: z.boolean().optional(), title: z.string().min(1).nullable().optional(), url: z.string().min(1).nullable().optional()}); export const identityRoles = z.array(z.enum(["APPLICATION_OWNER", "BENEFICIAL_OWNER", "BUYER", "PLATFORM_OWNER", "RECIPIENT", "SELLER", "SENDER"])); export const tags = z.record(z.string(), z.unknown()).nullable(); export const self = z.object({href: z.string().min(1).optional()}); export const verifications = z.object({href: z.string().min(1).optional()}); export const merchants = z.object({href: z.string().min(1).optional()}); export const settlements = z.object({href: z.string().min(1).optional()}); export const authorizations = z.object({href: z.string().min(1).optional()}); export const transfers = z.object({href: z.string().min(1).optional()}); export const paymentInstruments = z.object({href: z.string().min(1).optional()}); export const associatedIdentities = z.object({href: z.string().min(1).optional()}); export const disputes = z.object({href: z.string().min(1).optional()}); export const applicationLink = z.object({href: z.string().min(1).optional()}); export const identity = z.object({id: id.optional(), created_at: createdAt.optional(), updated_at: updatedAt.optional(), additional_underwriting_data: additionalUnderwritingData.optional(), application: z.string().min(1).optional(), entity: entity.optional(), identity_roles: identityRoles.optional(), type: z.enum(["PERSONAL", "BUSINESS"]).optional(), tags: tags.optional(), _links: z.object({self: self.optional(), verifications: verifications.optional(), merchants: merchants.optional(), settlements: settlements.optional(), authorizations: authorizations.optional(), transfers: transfers.optional(), payment_instruments: paymentInstruments.optional(), associated_identities: associatedIdentities.optional(), disputes: disputes.optional(), application: applicationLink.optional()}).optional()}); export const next = z.object({href: z.string().optional()}); export const getApiIdentitiesResponse = z.object({page: page.optional(), _embedded: z.object({identities: z.array(identity).optional()}).optional(), _links: z.object({self: self.optional(), next: next.optional()}).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 Identities * * GET /identities */ export const getApiIdentities = async (args: GetApiIdentitiesArgs, options?: GetApiIdentitiesOptions) => { const {baseUrl = "https://finix.sandbox-payments-api.com", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Finix-Version'] != null) headers.set("Finix-Version", String(args['Finix-Version'])) if (args.after_cursor != null) query.append("after_cursor", String(args.after_cursor)) if (args.before_cursor != null) query.append("before_cursor", String(args.before_cursor)) if (args.business_name != null) query.append("business_name", String(args.business_name)) if (args.business_type != null) query.append("business_type", String(args.business_type)) if (args['created_at.gte'] != null) query.append("created_at.gte", String(args['created_at.gte'])) if (args['created_at.lte'] != null) query.append("created_at.lte", String(args['created_at.lte'])) if (args.default_statement_descriptor != null) query.append("default_statement_descriptor", String(args.default_statement_descriptor)) if (args.email != null) query.append("email", String(args.email)) if (args.first_name != null) query.append("first_name", String(args.first_name)) if (args.id != null) query.append("id", String(args.id)) if (args.identity_role != null) query.append("identity_role", String(args.identity_role)) if (args.last_name != null) query.append("last_name", String(args.last_name)) if (args.limit != null) query.append("limit", String(args.limit)) if (args['tags.key'] != null) query.append("tags.key", String(args['tags.key'])) if (args['tags.value'] != null) query.append("tags.value", String(args['tags.value'])) if (args.title != null) query.append("title", String(args.title)) if (args.type != null) query.append("type", String(args.type)) if (args['updated_at.gte'] != null) query.append("updated_at.gte", String(args['updated_at.gte'])) if (args['updated_at.lte'] != null) query.append("updated_at.lte", String(args['updated_at.lte'])) if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/identities${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(getApiIdentitiesResponse, await res.json()) };