import {z} from 'zod' export type GetApiInternalAccountsArgs = {limit?: number | undefined, starting_after?: string | undefined, sort_order?: ('asc' | 'desc') | undefined, start_date?: string | undefined, end_date?: string | undefined, connected_account_id?: string | undefined, name?: string | undefined, type?: ('own' | 'virtual') | undefined, account_number?: string | undefined, bank_code?: string | undefined, creditor_identifier?: string | undefined, account_holder_id?: string | undefined, holder_name?: string | undefined, status?: ('active' | 'blocked' | 'disabled') | undefined}; export type GetApiInternalAccountsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const internalAccountsOrganizationIdentification = 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 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 commonCustomFields = z.object({}); export const internalAccountsInternalAccount = z.object({id: z.string(), object: z.literal("internal_account"), status: z.enum(["pending_creation", "creation_rejected", "active", "blocked", "disabled"]), connected_account_ids: z.array(z.unknown()).optional(), type: z.enum(["own", "virtual"]), name: z.string().max(100), account_number: z.string(), account_number_format: z.enum(["iban", "uk_account_number", "us_account_number", "tokenized", "other"]).optional(), bank_code: z.string().optional(), bank_code_format: z.enum(["bic", "uk_sorting_code", "us_aba_routing_number", "tokenized", "other"]).optional(), organization_identification: internalAccountsOrganizationIdentification.optional(), holder_name: z.string().max(100), alternative_holder_names: z.array(z.string()).optional(), account_holder_id: z.string().nullable().optional(), holder_address: commonAddress.optional(), bank_name: z.string().optional(), bank_address: commonAddress.optional(), creditor_identifier: z.string().optional(), custom_fields: commonCustomFields.optional(), bank_data: z.object({message_id: z.string().optional(), file_id: z.string().optional()}).optional(), metadata: z.object({}).optional(), created_at: z.string(), cbs_source: z.literal("mambu").optional(), cbs_account_id: z.string().max(100).optional(), cbs_account_type: z.literal("deposit").optional(), currencies: z.array(z.string()).optional(), customer_bic: z.string().optional(), distinguished_name: z.string().optional()}); export const internalAccountsSearchResult = z.object({records: z.array(internalAccountsInternalAccount)}); 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 internal accounts * * GET /internal_accounts */ export const getApiInternalAccounts = async (args: GetApiInternalAccountsArgs, options?: GetApiInternalAccountsOptions) => { 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.connected_account_id != null) query.append("connected_account_id", String(args.connected_account_id)) if (args.name != null) query.append("name", String(args.name)) if (args.type != null) query.append("type", String(args.type)) 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.creditor_identifier != null) query.append("creditor_identifier", String(args.creditor_identifier)) if (args.account_holder_id != null) query.append("account_holder_id", String(args.account_holder_id)) if (args.holder_name != null) query.append("holder_name", String(args.holder_name)) if (args.status != null) query.append("status", String(args.status)) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/internal_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(internalAccountsSearchResult, await res.json()) };