UNPKG

@cranberry-money/shared-services

Version:

Platform-agnostic API services with pure functions and dependency injection. Includes auth, portfolios, instruments, countries, sectors, and more.

41 lines 1.48 kB
import { CASH_ACCOUNT_ENDPOINTS } from '@cranberry-money/shared-constants'; import { formatBalance } from '@cranberry-money/shared-utils'; let configuredApiClient = null; export const configureCashAccounts = (apiClient) => { configuredApiClient = apiClient; }; const getConfiguredClient = () => { if (!configuredApiClient) { throw new Error('Cash accounts service not configured. Call configureCashAccounts(apiClient) before using cash account functions.'); } return configuredApiClient; }; export const getCashAccounts = (params) => { const queryParams = {}; if (params?.account) { queryParams.account = params.account; } if (params?.currency) { queryParams.currency = params.currency; } if (params?.min_balance !== undefined) { queryParams.min_balance = params.min_balance.toString(); } if (params?.max_balance !== undefined) { queryParams.max_balance = params.max_balance.toString(); } if (params?.order_by) { queryParams.order_by = params.order_by; } return getConfiguredClient().get(CASH_ACCOUNT_ENDPOINTS.BASE, { params: queryParams, }); }; export const getCashAccountByUuid = (uuid) => { return getConfiguredClient().get(`${CASH_ACCOUNT_ENDPOINTS.BASE}${uuid}/`); }; export const getAccountCashAccounts = (accountUuid) => { return getCashAccounts({ account: accountUuid }); }; export { formatBalance }; //# sourceMappingURL=cashAccounts.js.map