import {z} from 'zod' export type StatementPeriodType = 'EODY' | 'NONE'; export type Date = string; export type StatementPeriodInput = {type: StatementPeriodType, localDate: Date}; export type MarketCode = string; export type Timezone = string; export type CurrencyCode = string; export type AccountIdentifierType = 'IBAN' | 'NUMBER' | 'ADYEN' | 'AU_BPAY_BILLER_CODE' | 'DK_FIK' | 'INVESTMENT_NUMBER' | 'MY_JOMPAY_BILLER_CODE' | 'NATIONAL_ID_NUMBER' | 'PAYPAL' | 'PROPRIETARY' | 'SE_BANKGIRO' | 'SE_PLUSGIRO' | 'SOLDO' | 'WALLET_ADYEN_BALANCE_PLATFORM' | 'WALLET_AIRWALLEX' | 'WALLET_AIRWALLEX_NUMBER' | 'WALLET_CURRENCYCLOUD' | 'WALLET_FLASH_PAYMENTS' | 'WALLET_FREEMARKET' | 'WALLET_HYPERWALLET' | 'WALLET_INPAY' | 'WALLET_LEAD' | 'WALLET_MERCURY' | 'WALLET_MONEYCORP' | 'WALLET_PAYHAWK' | 'WALLET_REVOLUT' | 'WALLET_SKRILL' | 'WALLET_STRIPE' | 'WALLET_SWISSQUOTE' | 'WALLET_UNIT'; export type AccountIdentifier = {type: AccountIdentifierType, market: MarketCode, number: string, invalid?: boolean | undefined}; export type RoutingIdentifierType = 'BIC' | 'AT_BLZ' | 'AU_BSB' | 'BD_BRN' | 'BR_BRANCH' | 'BR_COMPE' | 'BR_ISP' | 'CA_CPA' | 'CH_BCC' | 'CH_SIC' | 'CL_SBIF' | 'CN_APS' | 'CZ_NBC' | 'DE_BLZ' | 'ES_NCC' | 'GB_DSC' | 'GR_BIC' | 'HK_NCC' | 'IE_NCC' | 'IL_NCC' | 'IN_FSC' | 'IT_NCC' | 'JP_ZGN' | 'KR_BOK' | 'KR_KFTC' | 'MX_ABM' | 'MY_NCC' | 'NZ_NCC' | 'PH_BRSTN' | 'PL_KNR' | 'PT_NCC' | 'RU_CBC' | 'SE_SBA' | 'SG_IBG' | 'TH_CBC' | 'TW_NCC' | 'US_ABA' | 'US_PID' | 'VN_CITAD' | 'ZA_NCC'; export type RoutingConstraints = {accountNumberType?: AccountIdentifierType | undefined, scheme?: string | undefined}; export type RoutingIdentifier = {type: RoutingIdentifierType, number: string, invalid?: boolean | undefined, constraints?: RoutingConstraints | undefined}; export type BankAccountType = 'WALLET' | 'SAVINGS' | 'CHECKING' | 'INVESTMENT'; export type StatementAccountInput = {market: MarketCode, timezone?: Timezone | undefined, currency: CurrencyCode, identifiers: Array, routing?: Array | undefined, name?: string | undefined, type?: BankAccountType | undefined, fictive?: boolean | undefined}; export type PartyType = 'INDIVIDUAL' | 'COMPANY'; export type CountryCode = string; export type CountrySubdivision = string; export type Address = {country?: CountryCode | undefined, countrySubdivision?: CountrySubdivision | undefined, city?: string | undefined, postalCode?: string | undefined, streetName?: string | undefined, streetNumber?: string | undefined}; export type NationalIdentifier = {type: 'CIVIC' | 'COMPANY', market: MarketCode, number: string}; export type ConnAccountHolderInput = {legalName: string, partyType?: PartyType | undefined, address?: Address | undefined, nationalIdentifier?: NationalIdentifier | undefined, email?: string | undefined, phone?: string | undefined}; export type AmountIntegerValueInput = {currency: CurrencyCode, value: number}; export type AmountStringValueInput = {currency: CurrencyCode, stringValue: string}; export type AmountInput = AmountIntegerValueInput | AmountStringValueInput; export type ConnBalanceInput = {amount: AmountInput, type: 'BOOKED' | 'BOOKED_ADJUSTED' | 'AVAILABLE', reportedType: 'OPEN' | 'CLOSE', localDate: Date}; export type ReferencedParty = {legalName: string, partyType?: PartyType | undefined, address?: Address | undefined, nationalIdentifier?: NationalIdentifier | undefined, rawAddressLines?: Array | undefined}; export type ReferencedAccount = {rawIdentifierNumber: string, market?: MarketCode | undefined, currency?: CurrencyCode | undefined, identifiers?: Array | undefined, routing?: Array | undefined}; export type TransactionCounterparty = {holder?: ReferencedParty | undefined, account?: ReferencedAccount | undefined}; export type ProprietaryBankTransactionCode = {code?: (string | null) | undefined, issuer?: (string | null) | undefined}; export type BankTransactionCode = {domain: string, family?: (string | null) | undefined, subfamily?: (string | null) | undefined, proprietary?: ProprietaryBankTransactionCode | undefined, description?: (string | null) | undefined}; export type ConnTransactionInput = {uniqueID: string, amount: AmountInput, bookedDate: Date, valueDate?: Date | undefined, description: string, status: 'BOOKED', counterparty?: TransactionCounterparty | undefined, instructedAmount?: AmountInput | undefined, references?: {[key: string]: string} | undefined, bankTransactionCode?: BankTransactionCode | undefined}; export type CreateStatementRequest = {type: 'BOOKED', period: StatementPeriodInput, account: StatementAccountInput, holder: ConnAccountHolderInput, balances: Array, transactions?: Array | undefined}; export type CreateConnectionReportRequest = {statements: Array}; export type CreateApiConnectivityV2betaConnectionsCidReportsArgs = {cid: string, body: CreateConnectionReportRequest}; export type CreateApiConnectivityV2betaConnectionsCidReportsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const organizationID = z.string(); export const resourceID = z.string().min(32).max(64); export const reportType = z.enum(["STATEMENT", "INVESTMENT", "ACCOUNTING", "FX_RATES", "PAYMENT_STATUS", "BENCHMARK_RATES", "INSTRUMENT_PRODUCTS", "ACCOUNTS", "OTHER"]); export const statementType = z.enum(["BOOKED", "PENDING"]); export const connectionReportDetails = z.object({type: reportType, statementType: statementType}); export const contentType = z.enum(["application/vnd.iso20022.pain.001.001.03+xml", "application/vnd.iso20022.pain.001.001.03.ch.02+xml", "application/vnd.iso20022.pain.001.001.09+xml", "application/vnd.iso20022.pain.001.001.09.ch.03+xml", "application/vnd.iso20022.pain.002.001.03+xml", "application/vnd.iso20022.pain.002.001.10+xml", "application/vnd.iso20022.pain.008.001.02+xml", "application/vnd.iso20022.pain.008.001.02.ch.03+xml", "application/vnd.iso20022.pain.008.001.03+xml", "application/vnd.iso20022.pain.008.001.08+xml", "application/vnd.iso20022.camt.052.001.02+xml", "application/vnd.iso20022.camt.052.001.03+xml", "application/vnd.iso20022.camt.052.001.04+xml", "application/vnd.iso20022.camt.052.001.08+xml", "application/vnd.iso20022.camt.053.001.02+xml", "application/vnd.iso20022.camt.053.001.03+xml", "application/vnd.iso20022.camt.053.001.04+xml", "application/vnd.iso20022.camt.053.001.08+xml", "application/vnd.iso20022.camt.053.001.10+xml", "application/vnd.iso20022.camt.053.001.11+xml", "application/vnd.iso20022.camt.053.001.12+xml", "application/vnd.iso20022.camt.054.001.02+xml", "application/vnd.iso20022.pacs.002.001.10+xml", "application/vnd.iso20022.pacs.008.001.02+xml", "application/vnd.iso20022.pacs.008.001.08+xml", "application/vnd.swift.mt.101", "application/vnd.swift.mt.103", "application/vnd.swift.mt.900", "application/vnd.swift.mt.940", "application/vnd.swift.mt.942", "application/vnd.bai.bai2", "application/vnd.bgc.autogiro.payee", "application/vnd.bgc.autogiro.payments.rejected", "application/vnd.bgc.autogiro.payments.spec", "application/vnd.bgc.autogiro.mandate", "application/vnd.bgc.payins.bgmax", "application/vnd.nacha.ach", "application/vnd.atlar.testbank.mandate+json", "application/vnd.atlar.testbank.transaction+json", "application/vnd.atlar.connectivity.proprietary", "application/vnd.atlar.connectivity.proprietary+json", "application/vnd.atlar.connectivity.proprietary+xml", "application/vnd.atlar.connectivity.proprietary+csv", "application/vnd.atlar.connectivity.v2.investment-statement+json", "application/vnd.atlar.connectivity.v2.accounting-statement+json", "application/vnd.atlar.connectivity.v2.fx-rate-statement+json", "application/vnd.atlar.connectivity.v2.benchmark-rate-statement+json", "application/vnd.atlar.connectivity.v2.instrument-product-statement+json", "application/vnd.atlar.connectivity.v2.statement+json", "application/vnd.atlar.connectivity.v2.statement+csv", "application/vnd.deutsche.wealth-online+csv", "application/vnd.m2.m006.m001+xml", "application/vnd.m2.m006.m005+xml", "application/vnd.ebics.htd.v30+xml", "application/vnd.ebics.hac.v25+xml", "application/vnd.ebics.hac.v30+xml", "application/vnd.jpm.daily-feed+zip", "application/vnd.jpm.morgan-money.balance-report+csv", "application/vnd.jpm.morgan-money.transaction-report+csv", "application/vnd.jpm.soci.holdings+csv", "application/vnd.jpm.soci.transactions+csv", "application/vnd.jpm.soci.cash-balance+csv", "application/vnd.nordea.investments.abasec.pos+csv", "application/vnd.nordea.investments.abasec.tra+csv", "application/vnd.blackrock.cachematrix.balance+csv", "application/vnd.blackrock.cachematrix.transactions+csv", "application/vnd.adyen.balance-platform.statement-report+csv", "application/vnd.ms-excel", "application/x-ofx", "application/json", "application/zip", "application/pdf", "text/plain", "text/csv", "application/vnd.edi.820", "application/vnd.edi.824", "application/vnd.edi.997"]); export const contentMetadata = z.object({contentType: contentType, size: z.number().int(), checksum: z.string(), name: z.string()}); export const metadata = z.record(z.string(), z.string()).nullable(); export const resourceVersion = z.number().int().gte(1); export const eTag = z.string(); export const createdTimestamp = z.string(); export const updatedTimestamp = z.string(); export const connectionReport = z.object({organizationId: organizationID, connectionId: resourceID, id: resourceID, details: connectionReportDetails, content: contentMetadata, converted: z.boolean(), thirdPartyCodes: z.array(z.string()).optional(), metadata: metadata.optional(), version: resourceVersion, etag: eTag, created: createdTimestamp, updated: updatedTimestamp}); 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 report * * POST /connectivity/v2beta/connections/{cid}/reports */ export const createApiConnectivityV2betaConnectionsCidReports = async (args: CreateApiConnectivityV2betaConnectionsCidReportsArgs, options?: CreateApiConnectivityV2betaConnectionsCidReportsOptions) => { const {baseUrl = "https://api.atlar.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/connectivity/v2beta/connections/${encodeURIComponent(String(args.cid))}/reports${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(connectionReport, await res.json()) };