import {z} from 'zod' export type GetApiReportsReportIdArgs = {accept?: ('application/json' | 'application/pdf') | undefined}; export type GetApiReportsReportIdOptions = {baseUrl?: string | undefined, oauthClientCredentials?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiReportsReportIdResponse = z.union([z.object({id: z.string(), created_at: z.string(), user_id: z.string(), type: z.enum(["ACCOUNT_CLOSING", "ACCOUNT_OPENING", "AD_HOC_ACCOUNT_STATEMENT", "ANNUAL_INCOME_STATEMENT", "ANNUAL_TAX_STATEMENT", "BANK_ACCOUNT_CONNECTED", "BUY_ORDER", "CANCELLED_ORDER", "CORPORATE_ACTION_CASH_TRANSACTION", "CORPORATE_ACTION_SECURITY_TRANSACTION", "DIRECT_DEBIT_MANDATE", "EX_POST_COST", "FEE_COLLECTION", "FRENCH_IFU", "GENERIC_COMMUNICATION", "INCOME_DISTRIBUTION", "LOSS_THRESHOLD", "MONTHLY_BILLING_STATEMENT", "ORDER_EX_ANTE_COST", "ORDER_EX_ANTE_COST_SAVINGS_PLAN", "QUARTERLY_ACCOUNT_STATEMENT", "REVOKED_ORDER", "SECURITIES_TRANSFER_INCOMING", "SECURITIES_TRANSFER_OUTGOING", "SELL_ORDER", "TAX_CONSOLIDATED_CERTIFICATE_UK", "TAX_PAYMENT", "TAX_PREPAYMENT_DE", "TAX_PREPAYMENT_DE_CANCELLATION", "TAX_REFUND"]), substituted_report_id: z.string(), data: z.object({account: z.object({id: z.string().optional()}).optional(), references: z.array(z.object({id: z.string().optional(), type: z.enum(["CORPORATE_ACTION_TRANSACTION_ID", "ACCOUNT_GROUP_ID", "ACCOUNT_ID", "ORDER_ID"]).optional()})).optional()}).optional()}), z.object({id: z.string(), created_at: z.string(), business_id: z.string(), type: z.enum(["ACCOUNT_CLOSING", "ACCOUNT_OPENING", "AD_HOC_ACCOUNT_STATEMENT", "ANNUAL_INCOME_STATEMENT", "ANNUAL_TAX_STATEMENT", "BANK_ACCOUNT_CONNECTED", "BUY_ORDER", "CANCELLED_ORDER", "CORPORATE_ACTION_CASH_TRANSACTION", "CORPORATE_ACTION_SECURITY_TRANSACTION", "DIRECT_DEBIT_MANDATE", "EX_POST_COST", "FEE_COLLECTION", "FRENCH_IFU", "GENERIC_COMMUNICATION", "INCOME_DISTRIBUTION", "LOSS_THRESHOLD", "MONTHLY_BILLING_STATEMENT", "ORDER_EX_ANTE_COST", "ORDER_EX_ANTE_COST_SAVINGS_PLAN", "QUARTERLY_ACCOUNT_STATEMENT", "REVOKED_ORDER", "SECURITIES_TRANSFER_INCOMING", "SECURITIES_TRANSFER_OUTGOING", "SELL_ORDER", "TAX_CONSOLIDATED_CERTIFICATE_UK", "TAX_PAYMENT", "TAX_PREPAYMENT_DE", "TAX_PREPAYMENT_DE_CANCELLATION", "TAX_REFUND"]), substituted_report_id: z.string(), data: z.object({account: z.object({id: z.string().optional()}).optional(), references: z.array(z.object({id: z.string().optional(), type: z.enum(["CORPORATE_ACTION_TRANSACTION_ID", "ACCOUNT_GROUP_ID", "ACCOUNT_ID", "ORDER_ID"]).optional()})).optional()}).optional()}), z.object({id: z.string(), created_at: z.string(), user_id: z.string(), type: z.enum(["ORDER_EX_ANTE_COST", "ORDER_EX_ANTE_COST_SAVINGS_PLAN"]), substituted_report_id: z.string(), data: z.object({holding_period: z.object({unit: z.literal("YEAR").optional(), quantity: z.number().int().optional()}).optional(), instrument: z.object({isin: z.string().optional(), short_name: z.string().max(100).optional()}).optional(), venue: z.object({name: z.string().max(100).optional()}).optional(), account: z.object({id: z.string().optional(), account_number: z.number().int().gte(1).optional()}).optional(), account_group: z.object({id: z.string().optional(), securities_account_number: z.string().optional()}).optional(), user: z.object({first_name: z.string().min(2).max(100).optional(), last_name: z.string().min(2).max(100).optional(), salutation: z.enum(["", "SALUTATION_MALE", "SALUTATION_FEMALE", "SALUTATION_FEMALE_MARRIED", "SALUTATION_DIVERSE"]).optional(), title: z.enum(["", "DR", "PROF", "PROF_DR", "DIPL_ING", "MAGISTER"]).optional(), address: z.object({address_line1: z.string().max(100).optional(), address_line2: z.string().max(100).optional(), postcode: z.string().optional(), country: z.string().optional(), state: z.string().max(50).optional(), city: z.string().min(1).max(85).optional()}).optional()}), order: z.object({user_id: z.string().optional(), account_id: z.string().optional(), cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), side: z.enum(["BUY", "SELL"]).optional(), instrument_id: z.string().optional(), instrument_id_type: z.literal("ISIN").optional(), order_type: z.enum(["MARKET", "LIMIT", "STOP"]).optional(), quantity: z.string().optional(), limit_price: z.string().optional(), stop_price: z.string().optional(), price: z.string().optional()}).optional(), return_impact: z.object({year_one: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional(), details: z.array(z.object({type: z.enum(["ENTRY", "ONGOING", "EXIT"]), cash_amount: z.string(), currency: z.enum(["EUR", "GBP"]), as_percentage: z.string()})).optional()}).optional(), year_two: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional(), details: z.array(z.object({type: z.enum(["ENTRY", "ONGOING", "EXIT"]), cash_amount: z.string(), currency: z.enum(["EUR", "GBP"]), as_percentage: z.string()})).optional()}).optional(), year_three: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional(), details: z.array(z.object({type: z.enum(["ENTRY", "ONGOING", "EXIT"]), cash_amount: z.string(), currency: z.enum(["EUR", "GBP"]), as_percentage: z.string()})).optional()}).optional()}).optional(), total_cost: z.object({product: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), service: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), third_party: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), total: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional()}).optional(), product_cost: z.object({one_off: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), ongoing: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), transaction: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), incidental: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), total: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional()}).optional(), service_cost: z.object({one_off: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), ongoing: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), transaction: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), ancillary: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), incidental: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), total: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional()}).optional(), third_party_payments: z.object({total: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), received_by_client: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), received_by_upvest: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional()}).optional()}).optional()}), z.object({id: z.string(), created_at: z.string(), business_id: z.string(), type: z.literal("ORDER_EX_ANTE_COST"), substituted_report_id: z.string(), data: z.object({holding_period: z.object({unit: z.literal("YEAR").optional(), quantity: z.number().int().optional()}).optional(), instrument: z.object({isin: z.string().optional(), short_name: z.string().max(100).optional()}).optional(), venue: z.object({name: z.string().max(100).optional()}).optional(), account: z.object({id: z.string().optional(), account_number: z.number().int().gte(1).optional()}).optional(), account_group: z.object({id: z.string().optional(), securities_account_number: z.string().optional()}).optional(), business: z.object({company_name: z.string().optional(), address: z.object({address_line1: z.string().max(100), address_line2: z.string().max(100).optional(), postcode: z.string(), country: z.enum(["AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "XK", "YE", "YT", "ZA", "ZM", "ZW"]), state: z.string().max(50).optional(), city: z.string().min(1).max(85)}).optional()}), order: z.object({business_id: z.string().optional(), account_id: z.string().optional(), cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), side: z.enum(["BUY", "SELL"]).optional(), instrument_id: z.string().optional(), instrument_id_type: z.literal("ISIN").optional(), order_type: z.enum(["MARKET", "LIMIT", "STOP"]).optional(), quantity: z.string().optional(), limit_price: z.string().optional(), stop_price: z.string().optional(), price: z.string().optional()}).optional(), return_impact: z.object({year_one: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional(), details: z.array(z.object({type: z.enum(["ENTRY", "ONGOING", "EXIT"]), cash_amount: z.string(), currency: z.enum(["EUR", "GBP"]), as_percentage: z.string()})).optional()}).optional(), year_two: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional(), details: z.array(z.object({type: z.enum(["ENTRY", "ONGOING", "EXIT"]), cash_amount: z.string(), currency: z.enum(["EUR", "GBP"]), as_percentage: z.string()})).optional()}).optional(), year_three: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional(), details: z.array(z.object({type: z.enum(["ENTRY", "ONGOING", "EXIT"]), cash_amount: z.string(), currency: z.enum(["EUR", "GBP"]), as_percentage: z.string()})).optional()}).optional()}).optional(), total_cost: z.object({product: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), service: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), third_party: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), total: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional()}).optional(), product_cost: z.object({one_off: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), ongoing: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), transaction: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), incidental: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), total: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional()}).optional(), service_cost: z.object({one_off: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), ongoing: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), transaction: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), ancillary: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), incidental: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), total: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional()}).optional(), third_party_payments: z.object({total: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), received_by_client: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional(), received_by_upvest: z.object({cash_amount: z.string().optional(), currency: z.enum(["EUR", "GBP"]).optional(), as_percentage: z.string().optional()}).optional()}).optional()}).optional()}), z.object({id: z.string(), created_at: z.string(), user_id: z.string(), type: z.enum(["BUY_ORDER", "CANCELLED_ORDER", "REVOKED_ORDER", "SELL_ORDER"]), substituted_report_id: z.string(), data: z.object({account: z.object({id: z.string().optional()}).optional(), references: z.array(z.object({id: z.string().optional(), type: z.enum(["CORPORATE_ACTION_TRANSACTION_ID", "ACCOUNT_GROUP_ID", "ACCOUNT_ID", "ORDER_ID"]).optional()})).optional(), instrument: z.object({isin: z.string().optional(), short_name: z.string().max(100).optional()}).optional()}).optional()}), z.object({id: z.string(), created_at: z.string(), business_id: z.string(), type: z.enum(["BUY_ORDER", "CANCELLED_ORDER", "REVOKED_ORDER", "SELL_ORDER"]), substituted_report_id: z.string(), data: z.object({account: z.object({id: z.string().optional()}).optional(), references: z.array(z.object({id: z.string().optional(), type: z.enum(["CORPORATE_ACTION_TRANSACTION_ID", "ACCOUNT_GROUP_ID", "ACCOUNT_ID", "ORDER_ID"]).optional()})).optional(), instrument: z.object({isin: z.string().optional(), short_name: z.string().max(100).optional()}).optional()}).optional()}), z.object({id: z.string(), created_at: z.string(), user_id: z.string(), type: z.literal("INCOME_DISTRIBUTION"), substituted_report_id: z.string(), data: z.object({account: z.object({id: z.string().optional()}).optional(), references: z.array(z.object({id: z.string().optional(), type: z.enum(["CORPORATE_ACTION_TRANSACTION_ID", "ACCOUNT_GROUP_ID", "ACCOUNT_ID", "ORDER_ID"]).optional()})).optional(), instrument: z.object({isin: z.string().optional(), short_name: z.string().max(100).optional()}).optional()}).optional()}), z.object({id: z.string(), created_at: z.string(), business_id: z.string(), type: z.literal("INCOME_DISTRIBUTION"), substituted_report_id: z.string(), data: z.object({account: z.object({id: z.string().optional()}).optional(), references: z.array(z.object({id: z.string().optional(), type: z.enum(["CORPORATE_ACTION_TRANSACTION_ID", "ACCOUNT_GROUP_ID", "ACCOUNT_ID", "ORDER_ID"]).optional()})).optional(), instrument: z.object({isin: z.string().optional(), short_name: z.string().max(100).optional()}).optional()}).optional()}), z.object({id: z.string(), created_at: z.string(), user_id: z.string(), type: z.enum(["CORPORATE_ACTION_CASH_TRANSACTION", "CORPORATE_ACTION_SECURITY_TRANSACTION"]), substituted_report_id: z.string(), data: z.object({account: z.object({id: z.string().optional()}).optional(), references: z.array(z.object({id: z.string().optional(), type: z.enum(["CORPORATE_ACTION_TRANSACTION_ID", "ACCOUNT_GROUP_ID", "ACCOUNT_ID", "ORDER_ID"]).optional()})).optional(), instrument: z.object({isin: z.string().optional(), short_name: z.string().max(100).optional()}).optional()}).optional()}), z.object({id: z.string(), created_at: z.string(), user_id: z.string(), type: z.enum(["SECURITIES_TRANSFER_INCOMING", "SECURITIES_TRANSFER_OUTGOING"]), substituted_report_id: z.string(), data: z.object({account: z.object({id: z.string().optional()}).optional(), references: z.array(z.object({id: z.string().optional(), type: z.enum(["CORPORATE_ACTION_TRANSACTION_ID", "ACCOUNT_GROUP_ID", "ACCOUNT_ID", "ORDER_ID"]).optional()})).optional(), instrument: z.object({isin: z.string().optional(), short_name: z.string().max(100).optional()}).optional()}).optional()}), z.object({id: z.string(), created_at: z.string(), business_id: z.string(), type: z.enum(["SECURITIES_TRANSFER_INCOMING", "SECURITIES_TRANSFER_OUTGOING"]), substituted_report_id: z.string(), data: z.object({account: z.object({id: z.string().optional()}).optional(), references: z.array(z.object({id: z.string().optional(), type: z.enum(["CORPORATE_ACTION_TRANSACTION_ID", "ACCOUNT_GROUP_ID", "ACCOUNT_ID", "ORDER_ID"]).optional()})).optional(), instrument: z.object({isin: z.string().optional(), short_name: z.string().max(100).optional()}).optional()}).optional()})]); 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 }; /** * Retrieve a report * * GET /reports/{report_id} */ export const getApiReportsReportId = async (args: GetApiReportsReportIdArgs, options?: GetApiReportsReportIdOptions) => { const {baseUrl = "https://sandbox.upvest.co", fetch: fetchFn = fetch, oauthClientCredentials} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.accept != null) headers.set("accept", String(args.accept)) if (oauthClientCredentials !== undefined) headers.set('authorization', `Bearer ${oauthClientCredentials}`) const url = `${baseUrl.replace(/\/+$/, '')}/reports/${encodeURIComponent(String(args.report_id))}${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(getApiReportsReportIdResponse, await res.json()) };