import {z} from 'zod' export type ExternalAccountsOrganizationIdentification = {legal_entity_identifier?: string | undefined, business_identification_code?: string | undefined, default_other_identifier_type?: ('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') | undefined, others?: (Array<{type: '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: string}>) | undefined}; export type ExternalAccountsHolderAddress = {line_1?: string | undefined, line_2?: string | undefined, building_number?: string | undefined, street_name?: string | undefined, postal_code?: string | undefined, region_state?: string | undefined, city?: string | undefined, country?: string | undefined}; export type CommonAddress = {line_1?: string | undefined, line_2?: string | undefined, building_number?: string | undefined, street_name?: string | undefined, postal_code?: string | undefined, region_state?: string | undefined, city?: string | undefined, country?: string | undefined, department?: (string | null) | undefined, sub_department?: (string | null) | undefined, building_name?: (string | null) | undefined, floor?: (string | null) | undefined, postal_box?: (string | null) | undefined, room?: (string | null) | undefined, city_location_name?: (string | null) | undefined, district_name?: (string | null) | undefined}; export type CommonCustomFields = Record; export type ExternalAccountsCreateExternalAccount = {type?: ('individual' | 'legal_entity') | undefined, name?: string | undefined, holder_name: string, account_number: string, account_number_format?: ('iban' | 'uk_account_number' | 'us_account_number' | 'tokenized' | 'other') | undefined, bank_code: string, bank_code_format?: ('bic' | 'uk_sorting_code' | 'us_aba_routing_number' | 'tokenized' | 'other') | undefined, account_holder_id?: string | undefined, organization_identification?: ExternalAccountsOrganizationIdentification | undefined, company_registration_number?: string | undefined, company_registration_number_type?: ('eu_vat' | 'fr_siren' | 'fr_siret' | 'nl_kvk' | 'nl_kvk_branch' | 'other' | 'uk_crn') | undefined, holder_address?: ExternalAccountsHolderAddress | undefined, bank_name?: string | undefined, bank_address?: CommonAddress | undefined, accept_duplicate_account_number?: boolean | undefined, metadata?: Record | undefined, custom_fields?: CommonCustomFields | undefined}; export type CreateApiExternalAccountsArgs = {body: ExternalAccountsCreateExternalAccount}; export type CreateApiExternalAccountsOptions = {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 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 external account * * POST /external_accounts */ export const createApiExternalAccounts = async (args: CreateApiExternalAccountsArgs, options?: CreateApiExternalAccountsOptions) => { const {baseUrl = "https://sandbox.numeral.io/v1", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") 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: "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(externalAccountsExternalAccount, await res.json()) };