Package Exports
- @cranberry-money/shared-constants
Readme
@cranberry-money/shared-constants
Part of the Cranberry monorepo, this package contains all shared constants for the MyPortfolio platform.
Installation
npm install @cranberry-money/shared-constantsUsage
Constants are organized by category:
import {
WITHDRAWAL_STATUS,
CURRENCY_CODES,
HTTP_STATUS,
CHART_COLORS
} from '@cranberry-money/shared-constants';
// Use status constants
if (status === WITHDRAWAL_STATUS.APPROVED) {
// Handle approved withdrawal
}
// Use currency constants
const symbol = CURRENCY_SYMBOLS[CURRENCY_CODES.AUD]; // '$'
// Use chart colors
const color = getChartColor(0); // Returns first color in paletteAvailable Categories
API Constants (/api)
- Endpoints: All API endpoint definitions with factory functions
PORTFOLIO_ENDPOINTS,TRADE_ENDPOINTS, etc.- Factory functions:
PORTFOLIO_ENDPOINTS.DETAIL(uuid)
- HTTP: Status codes, headers, content types, methods
HTTP_STATUS,HTTP_HEADERS,CONTENT_TYPES
- Config: Timeouts, retries, error codes
API_CONFIG,API_ERROR_CODES
Business Constants (/business)
- Status: All domain status values
WITHDRAWAL_STATUS,TRADE_STATUS,DOCUMENT_STATUS, etc.- Includes corresponding label mappings
- Accounts: Account types, source of funds
ACCOUNT_TYPE,SOURCE_OF_FUNDS
- Documents: Document types, categories, formats
DOCUMENT_TYPE,DOCUMENT_CATEGORY
- Investments: Risk tolerance, horizons, experience levels
RISK_TOLERANCE,INVESTMENT_HORIZON,INVESTMENT_EXPERIENCE
- Banking: Bank types, institutions, verification methods
BANK_ACCOUNT_TYPE,BANKING_INSTITUTION
- Trading: Execution venues, settlement cycles, fees
EXECUTION_VENUE,TRADE_FEE_TYPE
Financial Constants (/financial)
- Currency: ISO codes, symbols, decimal places
CURRENCY_CODES,CURRENCY_SYMBOLS,CURRENCY_NAMES
- Instruments: Asset types, classes, market identifiers
INSTRUMENT_TYPE,ASSET_CLASS,MARKET_IDENTIFIER
- Formatting: Number formats, locales, thresholds
NUMBER_FORMATS,FORMATTING_OPTIONS
UI Constants (/ui)
- Colors: Chart palettes, status colors, semantic colors
CHART_COLORS,STATUS_COLORS,PERFORMANCE_COLORS
- Display: Loading states, view types, date ranges
LOADING_STATES,DISPLAY_MODE,DATE_RANGE_PRESET
- Labels: All human-readable labels (re-exported from business)
- All
*_LABELSconstants from business domains
- All
Utility Constants (/utilities)
- Time: Milliseconds conversions, date formats, time zones
MILLISECONDS,DATE_FORMATS,TIME_ZONES
- Defaults: Default values, pagination, thresholds
DEFAULT_VALUES,PAGINATION_DEFAULTS,THRESHOLDS
- Sorting: Sort directions and fields
SORT_DIRECTION,SORT_FIELDS
- Validation: Regex patterns, validation rules, error messages
REGEX_PATTERNS,VALIDATION_RULES,VALIDATION_ERRORS
Type Safety
All constants use TypeScript's as const assertion for type safety and include corresponding type exports:
export const TRADE_STATUS = {
PENDING: 'PENDING',
EXECUTED: 'EXECUTED',
// ...
} as const;
export type TradeStatus = typeof TRADE_STATUS[keyof typeof TRADE_STATUS];Form Options
Many constants include pre-built options arrays for form dropdowns:
import { RISK_TOLERANCE_OPTIONS } from '@cranberry-money/shared-constants';
// Use directly in select/dropdown components
<Select options={RISK_TOLERANCE_OPTIONS} />Synchronization with Backend
Many constants are synchronized with the backend (bilberry). Comments indicate which constants must match backend values:
/**
* Trade status constants
* These constants should match the backend constants in bilberry/trades/constants.py
*/Platform Compatibility
This package is designed to work across:
- Web applications (React/Vue/Angular)
- Mobile applications (React Native)
- Node.js environments
- TypeScript and JavaScript projects
Development
# Build the package
npm run build
# Watch for changes
npm run dev
# Type check
npm run typecheckLicense
MIT