import {z} from 'zod' export type CreateApiExternalAccountsIdVerifyArgs = {id: string}; export type CreateApiExternalAccountsIdVerifyOptions = {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 }; /** * Verify external account * * POST /external_accounts/{id}/verify */ export const createApiExternalAccountsIdVerify = async (args: CreateApiExternalAccountsIdVerifyArgs, options?: CreateApiExternalAccountsIdVerifyOptions) => { 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 (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/external_accounts/${encodeURIComponent(String(args.id))}/verify${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) 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()) };