import {z} from 'zod' export type SimulatorV2IncomingPaymentsRequest = Array<{type?: ('sepa' | 'sepa_instant' | 'swift') | undefined, direction?: ('credit' | 'debit') | undefined, amount?: number | undefined, currency?: string | undefined, reference?: string | undefined, requested_execution_date?: string | undefined, fee_options?: ('originator' | 'receiver' | 'shared') | undefined, purpose?: string | undefined, category_purpose_code?: string | undefined, bank_data?: ({message_id?: string | undefined, transaction_id?: string | undefined, end_to_end_id?: string | undefined, instruction_id?: string | undefined}) | undefined, originating_account?: ({account_number?: string | undefined, bank_code?: string | undefined, holder_name?: string | undefined, holder_address?: ({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}) | undefined, creditor_identifier?: string | undefined, organization_identification?: ({legal_entity_identifier?: string | undefined}) | undefined}) | undefined, receiving_account?: ({creditor_identifier?: string | undefined, account_number?: string | undefined, bank_code?: string | undefined, holder_name?: string | undefined, holder_address?: ({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}) | undefined, organization_identification?: ({legal_entity_identifier?: string | undefined}) | undefined}) | undefined, direct_debit_mandate?: ({reference: string, signature_date: string, type: 'sepa_core' | 'sepa_b2b' | 'bacs_debit', sequence?: ('one_off' | 'recurring') | undefined, frequency?: ('one_off' | 'recurring') | undefined} | null) | undefined, intermediary_agents?: (Array<{financial_institution_identification: {swift_code?: string | undefined, bank_code?: string | undefined, bank_code_format?: ('bic' | 'uk_sorting_code' | 'us_aba_routing_number' | 'tokenized' | 'other') | undefined, name?: string | undefined, legal_entity_identifier?: string | undefined, postal_address?: ({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}) | undefined, other?: ({identification?: string | undefined, identification_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' | 'unknown') | undefined, custom_identification_type?: string | undefined, identification_issuer?: string | undefined}) | undefined}, account_number?: string | undefined, account_number_format?: string | undefined}>) | undefined}>; export type CreateApiSimulatorConnectedAccountIdIncomingPaymentsArgs = {connected_account_id: string, body: SimulatorV2IncomingPaymentsRequest}; export type CreateApiSimulatorConnectedAccountIdIncomingPaymentsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const simulatorV2Response = z.object({files: z.array(z.object({file_id: z.string().optional(), file_name: z.string(), created_at: z.string()}))}); 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 incoming payment * * POST /simulator/{connected_account_id}/incoming_payments */ export const createApiSimulatorConnectedAccountIdIncomingPayments = async (args: CreateApiSimulatorConnectedAccountIdIncomingPaymentsArgs, options?: CreateApiSimulatorConnectedAccountIdIncomingPaymentsOptions) => { 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(/\/+$/, '')}/simulator/${encodeURIComponent(String(args.connected_account_id))}/incoming_payments${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(simulatorV2Response, await res.json()) };