import {z} from 'zod' export type CounterpartyAccountsHolderAddress = {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 CommonCustomFields = Record; export type CounterpartyAccountsCreateCounterpartyAccount = {type?: ('individual' | 'legal_entity') | undefined, name?: string | undefined, holder_name: string, account_number: string, bank_code: string, counterparty_id?: string | 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?: CounterpartyAccountsHolderAddress | undefined, metadata?: Record | undefined, custom_fields?: CommonCustomFields | undefined}; export type CreateApiCounterpartyAccountsArgs = {body: CounterpartyAccountsCreateCounterpartyAccount}; export type CreateApiCounterpartyAccountsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const counterpartyAccountsHolderAddress = 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 counterpartyAccountsStatus = z.enum(["pending_approval", "approved", "denied", "disabled"]); export const counterpartyAccountsAccountVerificationItemDetails = z.object({reason: z.string().optional(), expected_value: z.string().optional(), message: z.string().optional()}); export const counterpartyAccountsAccountVerificationItem = z.object({result: z.enum(["valid", "invalid", "impossible_to_verify", "not_verified"]), details: counterpartyAccountsAccountVerificationItemDetails.optional()}); export const counterpartyAccountsAccountVerification = z.object({result: z.enum(["valid", "invalid", "pending_verification"]), created_at: z.string().optional(), valid_account_number: counterpartyAccountsAccountVerificationItem.optional(), matching_account_number_and_bank_code: counterpartyAccountsAccountVerificationItem.optional(), matching_account_holder: counterpartyAccountsAccountVerificationItem.optional(), active_account: counterpartyAccountsAccountVerificationItem.optional()}); export const commonCustomFields = z.object({}); export const counterpartyAccountsCounterpartyAccount = 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(), counterparty_id: z.string(), 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(), holder_address: counterpartyAccountsHolderAddress, status: counterpartyAccountsStatus, status_details: z.string(), account_verification: counterpartyAccountsAccountVerification.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 counterparty account * * POST /counterparty_accounts */ export const createApiCounterpartyAccounts = async (args: CreateApiCounterpartyAccountsArgs, options?: CreateApiCounterpartyAccountsOptions) => { 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(/\/+$/, '')}/counterparty_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(counterpartyAccountsCounterpartyAccount, await res.json()) };