import {z} from 'zod' export type ExternalAccountsStatus = 'pending_approval' | 'approved' | 'denied' | 'disabled'; export type GetApiExternalAccountsArgs = {limit?: number | undefined, starting_after?: string | undefined, sort_order?: ('asc' | 'desc') | undefined, start_date?: string | undefined, end_date?: string | undefined, holder_name?: string | undefined, account_number?: string | undefined, bank_code?: string | undefined, country?: string | undefined, status?: ExternalAccountsStatus | undefined}; export type GetApiExternalAccountsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const externalAccountsOrganizationIdentification = z.object({legal_entity_identifier: z.string().min(20).max(20).optional(), business_identification_code: z.string().min(8).max(11).optional(), default_other_identifier_type: z.enum(["bank_identification", "central_bank_identification", "clearing_house_identification", "company_incorporation_number", "company_identification", "customer_number", "duns_number", "employee_number", "global_location_number", "siren", "siret", "tax_number", "telephone_number", "business_domain_identification", "other_identification"]).optional(), others: z.array(z.object({type: z.enum(["bank_identification", "central_bank_identification", "clearing_house_identification", "company_incorporation_number", "company_identification", "customer_number", "duns_number", "employee_number", "global_location_number", "siren", "siret", "tax_number", "telephone_number", "business_domain_identification", "other_identification"]), value: z.string()})).optional()}); export const externalAccountsHolderAddress = z.object({line_1: z.string().optional(), line_2: z.string().optional(), building_number: z.string().optional(), street_name: z.string().optional(), postal_code: z.string().optional(), region_state: z.string().optional(), city: z.string().optional(), country: z.string().optional()}); export const commonAddress = z.object({line_1: z.string().optional(), line_2: z.string().optional(), building_number: z.string().optional(), street_name: z.string().optional(), postal_code: z.string().optional(), region_state: z.string().optional(), city: z.string().optional(), country: z.string().optional(), department: z.string().nullable().optional(), sub_department: z.string().nullable().optional(), building_name: z.string().nullable().optional(), floor: z.string().nullable().optional(), postal_box: z.string().nullable().optional(), room: z.string().nullable().optional(), city_location_name: z.string().nullable().optional(), district_name: z.string().nullable().optional()}); export const externalAccountsStatus = z.enum(["pending_approval", "approved", "denied", "disabled"]); export const externalAccountsAccountVerificationItemDetails = z.object({reason: z.string().optional(), expected_value: z.string().optional(), message: z.string().optional()}); export const externalAccountsAccountVerificationItem = z.object({result: z.enum(["valid", "invalid", "impossible_to_verify", "not_verified"]), details: externalAccountsAccountVerificationItemDetails.optional()}); export const externalAccountsAccountVerification = z.object({result: z.enum(["valid", "invalid", "pending_verification"]), created_at: z.string().optional(), valid_account_number: externalAccountsAccountVerificationItem.optional(), matching_account_number_and_bank_code: externalAccountsAccountVerificationItem.optional(), matching_account_holder: externalAccountsAccountVerificationItem.optional(), active_account: externalAccountsAccountVerificationItem.optional()}); export const commonCustomFields = z.object({}); export const externalAccountsExternalAccount = z.object({id: z.string(), object: z.string(), type: z.enum(["individual", "legal_entity"]).optional(), name: z.string().optional(), holder_name: z.string(), account_number: z.string(), account_number_format: z.enum(["iban", "uk_account_number", "us_account_number", "tokenized", "other"]).optional(), account_holder_id: z.string(), organization_identification: externalAccountsOrganizationIdentification.optional(), company_registration_number: z.string().optional(), company_registration_number_type: z.enum(["eu_vat", "fr_siren", "fr_siret", "nl_kvk", "nl_kvk_branch", "other", "uk_crn"]).optional(), bank_code: z.string(), bank_code_format: z.enum(["bic", "uk_sorting_code", "us_aba_routing_number", "tokenized", "other"]).optional(), holder_address: externalAccountsHolderAddress, bank_name: z.string().optional(), bank_address: commonAddress.optional(), status: externalAccountsStatus, status_details: z.string(), account_verification: externalAccountsAccountVerification.optional(), created_at: z.string(), disabled_at: z.string().optional(), metadata: z.object({}).optional(), custom_fields: commonCustomFields}); export const externalAccountsSearchResult = z.object({records: z.array(externalAccountsExternalAccount).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 external accounts * * GET /external_accounts */ export const getApiExternalAccounts = async (args: GetApiExternalAccountsArgs, options?: GetApiExternalAccountsOptions) => { const {baseUrl = "https://sandbox.numeral.io/v1", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.starting_after != null) query.append("starting_after", String(args.starting_after)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.holder_name != null) query.append("holder_name", String(args.holder_name)) if (args.account_number != null) query.append("account_number", String(args.account_number)) if (args.bank_code != null) query.append("bank_code", String(args.bank_code)) if (args.country != null) query.append("country", String(args.country)) if (args.status != null) query.append("status", String(args.status)) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/external_accounts${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(externalAccountsSearchResult, await res.json()) };