import {z} from 'zod' export type GetApiCashFlowConsolidatedArgs = {symbol?: string | undefined, figi?: string | undefined, isin?: string | undefined, cusip?: string | undefined, exchange?: string | undefined, mic_code?: string | undefined, country?: string | undefined, period?: ('annual' | 'quarterly') | undefined, start_date?: string | undefined, end_date?: string | undefined, outputsize?: number | undefined}; export type GetApiCashFlowConsolidatedOptions = {baseUrl?: string | undefined, authorizationHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const cashFlowData = z.object({fiscal_date: z.string(), year: z.number().int().optional(), cash_flow_from_operating_activities: z.object({net_income_from_continuing_operations: z.number().optional(), operating_cash_flow: z.number().optional(), cash_flow_from_continuing_operating_activities: z.number().optional(), cash_from_discontinued_operating_activities: z.number().optional(), cash_flow_from_discontinued_operation: z.number().optional(), free_cash_flow: z.number().optional(), cash_flows_from_used_in_operating_activities_direct: z.number().optional(), taxes_refund_paid: z.number().optional(), taxes_refund_paid_direct: z.number().optional(), interest_received: z.number().optional(), interest_received_direct: z.number().optional(), interest_paid: z.number().optional(), interest_paid_direct: z.number().optional(), dividend_received: z.number().optional(), dividend_received_direct: z.number().optional(), dividend_paid: z.number().optional(), dividend_paid_direct: z.number().optional(), change_in_working_capital: z.number().optional(), change_in_other_working_capital: z.number().optional(), change_in_receivables: z.number().optional(), changes_in_account_receivables: z.number().optional(), change_in_payables_and_accrued_expense: z.number().optional(), change_in_accrued_expense: z.number().optional(), change_in_payable: z.number().optional(), change_in_dividend_payable: z.number().optional(), change_in_account_payable: z.number().optional(), change_in_tax_payable: z.number().optional(), change_in_income_tax_payable: z.number().optional(), change_in_interest_payable: z.number().optional(), change_in_other_current_liabilities: z.number().optional(), change_in_other_current_assets: z.number().optional(), change_in_inventory: z.number().optional(), change_in_prepaid_assets: z.number().optional(), other_non_cash_items: z.number().optional(), excess_tax_benefit_from_stock_based_compensation: z.number().optional(), stock_based_compensation: z.number().optional(), unrealized_gain_loss_on_investment_securities: z.number().optional(), provision_and_write_off_of_assets: z.number().optional(), asset_impairment_charge: z.number().optional(), amortization_of_securities: z.number().optional(), deferred_tax: z.number().optional(), deferred_income_tax: z.number().optional(), depreciation_amortization_depletion: z.number().optional(), depletion: z.number().optional(), depreciation_and_amortization: z.number().optional(), amortization_cash_flow: z.number().optional(), amortization_of_intangibles: z.number().optional(), depreciation: z.number().optional(), operating_gains_losses: z.number().optional(), pension_and_employee_benefit_expense: z.number().optional(), earnings_losses_from_equity_investments: z.number().optional(), gain_loss_on_investment_securities: z.number().optional(), net_foreign_currency_exchange_gain_loss: z.number().optional(), gain_loss_on_sale_of_ppe: z.number().optional(), gain_loss_on_sale_of_business: z.number().optional()}).optional(), cash_flow_from_investing_activities: z.object({investing_cash_flow: z.number().optional(), cash_flow_from_continuing_investing_activities: z.number().optional(), cash_from_discontinued_investing_activities: z.number().optional(), net_other_investing_changes: z.number().optional(), interest_received_cfi: z.number().optional(), dividends_received_cfi: z.number().optional(), net_investment_purchase_and_sale: z.number().optional(), sale_of_investment: z.number().optional(), purchase_of_investment: z.number().optional(), net_investment_properties_purchase_and_sale: z.number().optional(), sale_of_investment_properties: z.number().optional(), purchase_of_investment_properties: z.number().optional(), net_business_purchase_and_sale: z.number().optional(), sale_of_business: z.number().optional(), purchase_of_business: z.number().optional(), net_intangibles_purchase_and_sale: z.number().optional(), sale_of_intangibles: z.number().optional(), purchase_of_intangibles: z.number().optional(), net_ppe_purchase_and_sale: z.number().optional(), sale_of_ppe: z.number().optional(), purchase_of_ppe: z.number().optional(), capital_expenditure_reported: z.number().optional(), capital_expenditure: z.number().optional()}).optional(), cash_flow_from_financing_activities: z.object({financing_cash_flow: z.number().optional(), cash_flow_from_continuing_financing_activities: z.number().optional(), cash_from_discontinued_financing_activities: z.number().optional(), net_other_financing_charges: z.number().optional(), interest_paid_cff: z.number().optional(), proceeds_from_stock_option_exercised: z.number().optional(), cash_dividends_paid: z.number().optional(), preferred_stock_dividend_paid: z.number().optional(), common_stock_dividend_paid: z.number().optional(), net_preferred_stock_issuance: z.number().optional(), preferred_stock_payments: z.number().optional(), preferred_stock_issuance: z.number().optional(), net_common_stock_issuance: z.number().optional(), common_stock_payments: z.number().optional(), common_stock_issuance: z.number().optional(), repurchase_of_capital_stock: z.number().optional(), net_issuance_payments_of_debt: z.number().optional(), net_short_term_debt_issuance: z.number().optional(), short_term_debt_payments: z.number().optional(), short_term_debt_issuance: z.number().optional(), net_long_term_debt_issuance: z.number().optional(), long_term_debt_payments: z.number().optional(), long_term_debt_issuance: z.number().optional(), issuance_of_debt: z.number().optional(), repayment_of_debt: z.number().optional(), issuance_of_capital_stock: z.number().optional()}).optional(), supplemental_data: z.object({interest_paid_supplemental_data: z.number().optional(), income_tax_paid_supplemental_data: z.number().optional()}).optional(), foreign_and_domestic_sales: z.object({foreign_sales: z.number().optional(), domestic_sales: z.number().optional(), adjusted_geography_segment_data: z.number().optional()}).optional(), cash_position: z.object({beginning_cash_position: z.number().optional(), end_cash_position: z.number().optional(), changes_in_cash: z.number().optional(), other_cash_adjustment_outside_change_in_cash: z.number().optional(), other_cash_adjustment_inside_change_in_cash: z.number().optional(), effect_of_exchange_rate_changes: z.number().optional()}).optional(), direct_method_cash_flow: z.object({classes_of_cash_receipts_from_operating_activities: z.number().optional(), other_cash_receipts_from_operating_activities: z.number().optional(), receipts_from_government_grants: z.number().optional(), receipts_from_customers: z.number().optional(), classes_of_cash_payments: z.number().optional(), other_cash_payments_from_operating_activities: z.number().optional(), payments_on_behalf_of_employees: z.number().optional(), payments_to_suppliers_for_goods_and_services: z.number().optional()}).optional()}); export const getApiCashFlowConsolidatedResponse = z.object({cash_flow: z.array(cashFlowData), status: z.string().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 }; /** * Cash flow consolidated * * GET /cash_flow/consolidated * * Also accepts auth: queryParameter */ export const getApiCashFlowConsolidated = async (args: GetApiCashFlowConsolidatedArgs, options?: GetApiCashFlowConsolidatedOptions) => { const {baseUrl = "https://api.twelvedata.com", fetch: fetchFn = fetch, authorizationHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.symbol != null) query.append("symbol", String(args.symbol)) if (args.figi != null) query.append("figi", String(args.figi)) if (args.isin != null) query.append("isin", String(args.isin)) if (args.cusip != null) query.append("cusip", String(args.cusip)) if (args.exchange != null) query.append("exchange", String(args.exchange)) if (args.mic_code != null) query.append("mic_code", String(args.mic_code)) if (args.country != null) query.append("country", String(args.country)) if (args.period != null) query.append("period", String(args.period)) 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.outputsize != null) query.append("outputsize", String(args.outputsize)) if (authorizationHeader !== undefined) headers.set("Authorization", authorizationHeader) const url = `${baseUrl.replace(/\/+$/, '')}/cash_flow/consolidated${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(getApiCashFlowConsolidatedResponse, await res.json()) };