@finatic/client 0.0.139 → 0.0.140

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +278 -461
  2. package/dist/index.d.ts +55 -515
  3. package/dist/index.js +326 -456
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +327 -456
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/types/core/client/ApiClient.d.ts +12 -26
  8. package/dist/types/core/client/FinaticConnect.d.ts +20 -103
  9. package/dist/types/index.d.ts +1 -2
  10. package/dist/types/mocks/MockApiClient.d.ts +2 -4
  11. package/dist/types/mocks/utils.d.ts +0 -5
  12. package/dist/types/types/api/auth.d.ts +12 -30
  13. package/dist/types/types/api/broker.d.ts +1 -1
  14. package/package.json +7 -3
  15. package/src/core/client/ApiClient.ts +1721 -0
  16. package/src/core/client/FinaticConnect.ts +1476 -0
  17. package/src/core/portal/PortalUI.ts +300 -0
  18. package/src/index.d.ts +23 -0
  19. package/src/index.ts +87 -0
  20. package/src/mocks/MockApiClient.ts +1032 -0
  21. package/src/mocks/MockDataProvider.ts +986 -0
  22. package/src/mocks/MockFactory.ts +97 -0
  23. package/src/mocks/utils.ts +133 -0
  24. package/src/themes/portalPresets.ts +1307 -0
  25. package/src/types/api/auth.ts +112 -0
  26. package/src/types/api/broker.ts +330 -0
  27. package/src/types/api/core.ts +53 -0
  28. package/src/types/api/errors.ts +35 -0
  29. package/src/types/api/orders.ts +45 -0
  30. package/src/types/api/portfolio.ts +59 -0
  31. package/src/types/common/pagination.ts +138 -0
  32. package/src/types/connect.ts +56 -0
  33. package/src/types/index.ts +25 -0
  34. package/src/types/portal.ts +214 -0
  35. package/src/types/ui/theme.ts +105 -0
  36. package/src/utils/brokerUtils.ts +85 -0
  37. package/src/utils/errors.ts +104 -0
  38. package/src/utils/events.ts +54 -0
  39. package/src/utils/themeUtils.ts +146 -0
package/dist/index.d.ts CHANGED
@@ -85,16 +85,6 @@ interface SessionInitResponse {
85
85
  expires_at: string;
86
86
  };
87
87
  }
88
- interface SessionResponseData {
89
- session_id: string;
90
- company_id: string;
91
- status: 'pending';
92
- expires_at: string;
93
- }
94
- interface SessionStartResponse {
95
- data: SessionResponseData;
96
- message: 'Session started successfully';
97
- }
98
88
  interface OtpRequestResponse {
99
89
  success: boolean;
100
90
  message: string;
@@ -113,17 +103,14 @@ interface OtpVerifyResponse {
113
103
  };
114
104
  }
115
105
  interface UserToken {
116
- accessToken: string;
117
- refreshToken: string;
118
- expiresIn: number;
119
106
  user_id: string;
120
- tokenType: string;
121
- scope: string;
122
107
  }
123
108
  interface SessionValidationResponse {
124
109
  valid: boolean;
125
110
  company_id: string;
126
111
  status: string;
112
+ is_sandbox: boolean;
113
+ environment: string;
127
114
  }
128
115
  interface SessionAuthenticateResponse {
129
116
  success: boolean;
@@ -154,23 +141,18 @@ interface TokenInfo {
154
141
  expiresAt: string;
155
142
  userId?: string;
156
143
  }
144
+ interface SessionResponseData {
145
+ session_id: string;
146
+ company_id: string;
147
+ status: string;
148
+ expires_at: string;
149
+ user_id?: string | null;
150
+ auto_login?: boolean;
151
+ }
157
152
  interface SessionResponse {
158
- data: {
159
- session_id: string;
160
- state: SessionState;
161
- device_info?: Record<string, string>;
162
- company_id?: string;
163
- status?: string;
164
- expires_at?: string;
165
- user_id?: string | null;
166
- auto_login?: boolean;
167
- access_token?: string;
168
- refresh_token?: string;
169
- expires_in?: number;
170
- token_type?: string;
171
- scope?: string;
172
- };
153
+ success: boolean;
173
154
  message: string;
155
+ data: SessionResponseData;
174
156
  }
175
157
  declare enum SessionState {
176
158
  PENDING = "PENDING",
@@ -297,7 +279,7 @@ interface BrokerOrderParams {
297
279
  broker: 'robinhood' | 'tasty_trade' | 'ninja_trader';
298
280
  order_id?: string;
299
281
  orderType: 'Market' | 'Limit' | 'Stop' | 'StopLimit';
300
- assetType: 'Stock' | 'Option' | 'Crypto' | 'Future';
282
+ assetType: 'equity' | 'equity_option' | 'crypto' | 'forex' | 'future' | 'future_option';
301
283
  action: 'Buy' | 'Sell';
302
284
  timeInForce: 'day' | 'gtc' | 'gtd' | 'ioc' | 'fok';
303
285
  accountNumber: string | number;
@@ -306,7 +288,7 @@ interface BrokerOrderParams {
306
288
  price?: number;
307
289
  stopPrice?: number;
308
290
  }
309
- interface BrokerExtras {
291
+ interface BrokerExtras$1 {
310
292
  robinhood?: {
311
293
  extendedHours?: boolean;
312
294
  marketHours?: 'regular_hours' | 'extended_hours';
@@ -1027,9 +1009,6 @@ declare class ApiClient {
1027
1009
  protected currentSessionState: SessionState | null;
1028
1010
  protected currentSessionId: string | null;
1029
1011
  private tradingContext;
1030
- private tokenInfo;
1031
- private refreshPromise;
1032
- private readonly REFRESH_BUFFER_MINUTES;
1033
1012
  private companyId;
1034
1013
  private csrfToken;
1035
1014
  constructor(baseUrl: string, deviceInfo?: DeviceInfo$1);
@@ -1050,33 +1029,24 @@ declare class ApiClient {
1050
1029
  */
1051
1030
  getCurrentCsrfToken(): string | null;
1052
1031
  /**
1053
- * Store tokens after successful authentication
1054
- */
1055
- setTokens(accessToken: string, refreshToken: string, expiresAt: string, userId?: string): void;
1056
- /**
1057
- * Get the current access token, refreshing if necessary
1032
+ * Get a valid access token (session-based auth - no tokens needed)
1058
1033
  */
1059
1034
  getValidAccessToken(): Promise<string>;
1060
1035
  /**
1061
- * Check if the current token is expired or about to expire
1062
- */
1063
- private isTokenExpired;
1064
- /**
1065
- * Refresh the access token using the refresh token
1066
- */
1067
- private refreshTokens;
1068
- /**
1069
- * Perform the actual token refresh request
1036
+ * Perform the actual Supabase session refresh
1070
1037
  */
1071
- private performTokenRefresh;
1072
1038
  /**
1073
- * Clear stored tokens (useful for logout)
1039
+ * Clear session tokens (useful for logout)
1074
1040
  */
1075
1041
  clearTokens(): void;
1076
1042
  /**
1077
- * Get current token info (for debugging/testing)
1043
+ * Get current session info (for debugging/testing) - session-based auth
1078
1044
  */
1079
- getTokenInfo(): TokenInfo | null;
1045
+ getTokenInfo(): {
1046
+ accessToken: string;
1047
+ refreshToken: string;
1048
+ expiresAt: number;
1049
+ } | null;
1080
1050
  /**
1081
1051
  * Make a request to the API.
1082
1052
  */
@@ -1110,23 +1080,21 @@ declare class ApiClient {
1110
1080
  orderQty: number;
1111
1081
  action: 'Buy' | 'Sell';
1112
1082
  orderType: 'Market' | 'Limit' | 'Stop' | 'StopLimit';
1113
- assetType: 'Stock' | 'Option' | 'Crypto' | 'Future';
1114
- }, extras?: BrokerExtras, connection_id?: string): Promise<OrderResponse>;
1083
+ assetType: 'equity' | 'equity_option' | 'crypto' | 'forex' | 'future' | 'future_option';
1084
+ }, extras?: BrokerExtras$1, connection_id?: string): Promise<OrderResponse>;
1115
1085
  cancelBrokerOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any, connection_id?: string): Promise<OrderResponse>;
1116
1086
  modifyBrokerOrder(orderId: string, params: Partial<BrokerOrderParams>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any, connection_id?: string): Promise<OrderResponse>;
1117
1087
  setBroker(broker: 'robinhood' | 'tasty_trade' | 'ninja_trader'): void;
1118
1088
  setAccount(accountNumber: string, accountId?: string): void;
1119
- getTradingContext(): TradingContext;
1120
- clearTradingContext(): void;
1121
- placeStockMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras, connection_id?: string): Promise<OrderResponse>;
1122
- placeStockLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras, connection_id?: string): Promise<OrderResponse>;
1123
- placeStockStopOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', stopPrice: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras, connection_id?: string): Promise<OrderResponse>;
1124
- placeCryptoMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', options?: CryptoOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1125
- placeCryptoLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', options?: CryptoOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1126
- placeOptionsMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', options: OptionsOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1127
- placeOptionsLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, options: OptionsOrderOptions, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1128
- placeFuturesMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1129
- placeFuturesLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1089
+ placeStockMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras$1, connection_id?: string): Promise<OrderResponse>;
1090
+ placeStockLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras$1, connection_id?: string): Promise<OrderResponse>;
1091
+ placeStockStopOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', stopPrice: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras$1, connection_id?: string): Promise<OrderResponse>;
1092
+ placeCryptoMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', options?: CryptoOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras$1): Promise<OrderResponse>;
1093
+ placeCryptoLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', options?: CryptoOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras$1): Promise<OrderResponse>;
1094
+ placeOptionsMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', options: OptionsOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras$1): Promise<OrderResponse>;
1095
+ placeOptionsLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, options: OptionsOrderOptions, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras$1): Promise<OrderResponse>;
1096
+ placeFuturesMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras$1): Promise<OrderResponse>;
1097
+ placeFuturesLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras$1): Promise<OrderResponse>;
1130
1098
  private buildOrderRequestBody;
1131
1099
  private buildModifyRequestBody;
1132
1100
  private applyBrokerDefaults;
@@ -1137,6 +1105,7 @@ declare class ApiClient {
1137
1105
  getCurrentSessionState(): SessionState | null;
1138
1106
  /**
1139
1107
  * Refresh the current session to extend its lifetime
1108
+ * Note: This now uses Supabase session refresh instead of custom endpoint
1140
1109
  */
1141
1110
  refreshSession(): Promise<{
1142
1111
  success: boolean;
@@ -1262,47 +1231,41 @@ declare class FinaticConnect extends EventEmitter {
1262
1231
  private readonly SESSION_REFRESH_BUFFER_HOURS;
1263
1232
  private sessionStartTime;
1264
1233
  constructor(options: FinaticConnectOptions, deviceInfo?: DeviceInfo);
1265
- private handleTokens;
1234
+ private linkUserToSession;
1266
1235
  /**
1267
- * Check if the user is fully authenticated (has userId, access token, and refresh token)
1268
- * @returns True if the user is fully authenticated and ready for API calls
1236
+ * Store user ID for authentication state persistence
1237
+ * @param userId - The user ID to store
1269
1238
  */
1270
- isAuthed(): boolean;
1239
+ private storeUserId;
1271
1240
  /**
1272
- * Check if the client is authenticated (alias for isAuthed for consistency)
1273
- * @returns True if authenticated, false otherwise
1241
+ * Check if the user is fully authenticated (has userId in session context)
1242
+ * @returns True if the user is fully authenticated and ready for API calls
1274
1243
  */
1275
- is_authenticated(): boolean;
1244
+ isAuthenticated(): Promise<boolean>;
1276
1245
  /**
1277
1246
  * Get user's orders with pagination and optional filtering
1278
1247
  * @param params - Query parameters including page, perPage, and filters
1279
1248
  * @returns Promise with paginated result that supports navigation
1280
1249
  */
1281
- getOrders(params?: {
1282
- page?: number;
1283
- perPage?: number;
1284
- filter?: OrdersFilter;
1285
- }): Promise<PaginatedResult<BrokerDataOrder[]>>;
1250
+ getOrders(page?: number, perPage?: number, options?: BrokerDataOptions, filters?: OrdersFilter): Promise<PaginatedResult<BrokerDataOrder[]>>;
1286
1251
  /**
1287
1252
  * Get user's positions with pagination and optional filtering
1288
1253
  * @param params - Query parameters including page, perPage, and filters
1289
1254
  * @returns Promise with paginated result that supports navigation
1290
1255
  */
1291
- getPositions(params?: {
1292
- page?: number;
1293
- perPage?: number;
1294
- filter?: PositionsFilter;
1295
- }): Promise<PaginatedResult<BrokerDataPosition[]>>;
1256
+ getPositions(page?: number, perPage?: number, options?: BrokerDataOptions, filters?: PositionsFilter): Promise<PaginatedResult<BrokerDataPosition[]>>;
1296
1257
  /**
1297
1258
  * Get user's accounts with pagination and optional filtering
1298
1259
  * @param params - Query parameters including page, perPage, and filters
1299
1260
  * @returns Promise with paginated result that supports navigation
1300
1261
  */
1301
- getAccounts(params?: {
1302
- page?: number;
1303
- perPage?: number;
1304
- filter?: AccountsFilter;
1305
- }): Promise<PaginatedResult<BrokerDataAccount[]>>;
1262
+ getAccounts(page?: number, perPage?: number, options?: BrokerDataOptions, filters?: AccountsFilter): Promise<PaginatedResult<BrokerDataAccount[]>>;
1263
+ /**
1264
+ * Get user's balances with pagination and optional filtering
1265
+ * @param params - Query parameters including page, perPage, and filters
1266
+ * @returns Promise with paginated result that supports navigation
1267
+ */
1268
+ getBalances(page?: number, perPage?: number, options?: BrokerDataOptions, filters?: BalancesFilter): Promise<PaginatedResult<BrokerBalance[]>>;
1306
1269
  /**
1307
1270
  * Initialize the Finatic Connect SDK
1308
1271
  * @param token - The portal token from your backend
@@ -1322,7 +1285,6 @@ declare class FinaticConnect extends EventEmitter {
1322
1285
  * Get the user and tokens for a completed session
1323
1286
  * @returns Promise with user information and tokens
1324
1287
  */
1325
- getSessionUser(): Promise<Record<string, any>>;
1326
1288
  private initializeWithUser;
1327
1289
  /**
1328
1290
  * Handle company access error by opening the portal
@@ -1348,20 +1310,7 @@ declare class FinaticConnect extends EventEmitter {
1348
1310
  * Place a new order using the broker order API
1349
1311
  * @param order - Order details with broker context
1350
1312
  */
1351
- placeOrder(order: {
1352
- symbol: string;
1353
- quantity: number;
1354
- side: 'buy' | 'sell';
1355
- orderType: 'market' | 'limit' | 'stop' | 'stop_limit';
1356
- price?: number;
1357
- stopPrice?: number;
1358
- timeInForce: 'day' | 'gtc' | 'gtd' | 'ioc' | 'fok';
1359
- broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader';
1360
- accountNumber?: string;
1361
- assetType?: 'Stock' | 'Option' | 'Crypto' | 'Future';
1362
- order_id?: string;
1363
- connection_id?: string;
1364
- }): Promise<OrderResponse>;
1313
+ placeOrder(order: BrokerOrderParams, extras?: BrokerExtras): Promise<OrderResponse>;
1365
1314
  /**
1366
1315
  * Cancel a broker order
1367
1316
  * @param orderId - The order ID to cancel
@@ -1386,25 +1335,6 @@ declare class FinaticConnect extends EventEmitter {
1386
1335
  side?: 'Buy' | 'Sell';
1387
1336
  order_id?: string;
1388
1337
  }>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', connection_id?: string): Promise<OrderResponse>;
1389
- /**
1390
- * Set the broker context for trading
1391
- * @param broker - The broker to use for trading
1392
- */
1393
- setTradingContextBroker(broker: 'robinhood' | 'tasty_trade' | 'ninja_trader' | 'interactive_brokers' | 'tradestation'): void;
1394
- /**
1395
- * Set the account context for trading
1396
- * @param accountNumber - The account number to use for trading
1397
- * @param accountId - Optional account ID
1398
- */
1399
- setTradingContextAccount(accountNumber: string, accountId?: string): void;
1400
- /**
1401
- * Get the current trading context
1402
- */
1403
- getTradingContext(): TradingContext;
1404
- /**
1405
- * Clear the trading context
1406
- */
1407
- clearTradingContext(): void;
1408
1338
  /**
1409
1339
  * Place a stock market order (convenience method)
1410
1340
  */
@@ -1446,7 +1376,7 @@ declare class FinaticConnect extends EventEmitter {
1446
1376
  * @returns The current user ID or undefined if not authenticated
1447
1377
  * @throws AuthenticationError if user is not authenticated
1448
1378
  */
1449
- getUserId(): string | null;
1379
+ getUserId(): Promise<string | null>;
1450
1380
  /**
1451
1381
  * Get list of supported brokers
1452
1382
  * @returns Promise with array of broker information
@@ -1502,50 +1432,6 @@ declare class FinaticConnect extends EventEmitter {
1502
1432
  * @returns Promise with array of positions for the broker
1503
1433
  */
1504
1434
  getPositionsByBroker(brokerId: string): Promise<BrokerDataPosition[]>;
1505
- /**
1506
- * Get a specific page of orders with pagination metadata
1507
- * @param page - Page number (default: 1)
1508
- * @param perPage - Items per page (default: 100)
1509
- * @param filter - Optional filter parameters
1510
- * @returns Promise with paginated orders result
1511
- */
1512
- getOrdersPage(page?: number, perPage?: number, filter?: OrdersFilter): Promise<PaginatedResult<BrokerDataOrder[]>>;
1513
- /**
1514
- * Get a specific page of positions with pagination metadata
1515
- * @param page - Page number (default: 1)
1516
- * @param perPage - Items per page (default: 100)
1517
- * @param filter - Optional filter parameters
1518
- * @returns Promise with paginated positions result
1519
- */
1520
- getPositionsPage(page?: number, perPage?: number, filter?: PositionsFilter): Promise<PaginatedResult<BrokerDataPosition[]>>;
1521
- /**
1522
- * Get a specific page of accounts with pagination metadata
1523
- * @param page - Page number (default: 1)
1524
- * @param perPage - Items per page (default: 100)
1525
- * @param filter - Optional filter parameters
1526
- * @returns Promise with paginated accounts result
1527
- */
1528
- getAccountsPage(page?: number, perPage?: number, filter?: AccountsFilter): Promise<PaginatedResult<BrokerDataAccount[]>>;
1529
- getBalancesPage(page?: number, perPage?: number, filter?: BalancesFilter): Promise<PaginatedResult<BrokerBalance[]>>;
1530
- /**
1531
- * Get the next page of orders
1532
- * @param previousResult - The previous paginated result
1533
- * @returns Promise with next page of orders or null if no more pages
1534
- */
1535
- getNextOrdersPage(previousResult: PaginatedResult<BrokerDataOrder[]>): Promise<PaginatedResult<BrokerDataOrder[]> | null>;
1536
- /**
1537
- * Get the next page of positions
1538
- * @param previousResult - The previous paginated result
1539
- * @returns Promise with next page of positions or null if no more pages
1540
- */
1541
- getNextPositionsPage(previousResult: PaginatedResult<BrokerDataPosition[]>): Promise<PaginatedResult<BrokerDataPosition[]> | null>;
1542
- /**
1543
- * Get the next page of accounts
1544
- * @param previousResult - The previous paginated result
1545
- * @returns Promise with next page of accounts or null if no more pages
1546
- */
1547
- getNextAccountsPage(previousResult: PaginatedResult<BrokerDataAccount[]>): Promise<PaginatedResult<BrokerDataAccount[]> | null>;
1548
- getNextBalancesPage(previousResult: PaginatedResult<BrokerBalance[]>): Promise<PaginatedResult<BrokerBalance[]> | null>;
1549
1435
  /**
1550
1436
  * Get all orders across all pages (convenience method)
1551
1437
  * @param filter - Optional filter parameters
@@ -1648,351 +1534,5 @@ declare function createCustomThemeFromPreset(preset: string, modifications: Part
1648
1534
 
1649
1535
  declare const portalThemePresets: Record<string, PortalThemeConfig>;
1650
1536
 
1651
- /**
1652
- * Configuration for mock behavior
1653
- */
1654
- interface MockConfig {
1655
- delay?: number;
1656
- scenario?: MockScenario;
1657
- customData?: Record<string, any>;
1658
- mockApiOnly?: boolean;
1659
- }
1660
- /**
1661
- * Different mock scenarios for testing
1662
- */
1663
- type MockScenario = 'success' | 'error' | 'network_error' | 'rate_limit' | 'auth_failure';
1664
- /**
1665
- * Mock data provider for Finatic API endpoints
1666
- */
1667
- declare class MockDataProvider {
1668
- private config;
1669
- private sessionData;
1670
- private userTokens;
1671
- constructor(config?: MockConfig);
1672
- /**
1673
- * Get a random delay between min and max milliseconds
1674
- */
1675
- private getRandomDelay;
1676
- /**
1677
- * Simulate network delay
1678
- */
1679
- simulateDelay(): Promise<void>;
1680
- /**
1681
- * Generate a realistic session ID
1682
- */
1683
- private generateSessionId;
1684
- /**
1685
- * Generate a realistic user ID
1686
- */
1687
- private generateUserId;
1688
- /**
1689
- * Generate a realistic company ID
1690
- */
1691
- private generateCompanyId;
1692
- /**
1693
- * Generate mock tokens
1694
- */
1695
- private generateTokens;
1696
- mockStartSession(token: string, userId?: string): Promise<SessionResponse>;
1697
- mockRequestOtp(sessionId: string, email: string): Promise<OtpRequestResponse>;
1698
- mockVerifyOtp(sessionId: string, otp: string): Promise<OtpVerifyResponse>;
1699
- mockAuthenticateDirectly(sessionId: string, userId: string): Promise<SessionAuthenticateResponse>;
1700
- mockGetPortalUrl(sessionId: string): Promise<PortalUrlResponse>;
1701
- mockValidatePortalSession(sessionId: string, signature: string): Promise<SessionValidationResponse>;
1702
- mockCompletePortalSession(sessionId: string): Promise<PortalUrlResponse>;
1703
- mockRefreshToken(refreshToken: string): Promise<RefreshTokenResponse>;
1704
- mockGetBrokerList(): Promise<{
1705
- _id: string;
1706
- response_data: BrokerInfo[];
1707
- message: string;
1708
- status_code: number;
1709
- warnings: null;
1710
- errors: null;
1711
- }>;
1712
- mockGetBrokerAccounts(): Promise<{
1713
- _id: string;
1714
- response_data: BrokerAccount[];
1715
- message: string;
1716
- status_code: number;
1717
- warnings: null;
1718
- errors: null;
1719
- }>;
1720
- mockGetBrokerConnections(): Promise<{
1721
- _id: string;
1722
- response_data: BrokerConnection[];
1723
- message: string;
1724
- status_code: number;
1725
- warnings: null;
1726
- errors: null;
1727
- }>;
1728
- mockGetOrders(filter?: OrdersFilter): Promise<{
1729
- data: Order[];
1730
- }>;
1731
- mockGetBrokerOrders(filter?: OrdersFilter): Promise<{
1732
- data: BrokerDataOrder[];
1733
- }>;
1734
- mockGetBrokerPositions(filter?: PositionsFilter): Promise<{
1735
- data: BrokerDataPosition[];
1736
- }>;
1737
- mockGetBrokerBalances(filter?: BalancesFilter): Promise<{
1738
- data: BrokerBalance[];
1739
- }>;
1740
- mockGetBrokerDataAccounts(filter?: AccountsFilter): Promise<{
1741
- data: BrokerAccount[];
1742
- }>;
1743
- mockPlaceOrder(order: BrokerOrderParams): Promise<OrderResponse>;
1744
- /**
1745
- * Get stored session data
1746
- */
1747
- getSessionData(sessionId: string): any;
1748
- /**
1749
- * Get stored user token
1750
- */
1751
- getUserToken(sessionId: string): UserToken | undefined;
1752
- /**
1753
- * Clear all stored data
1754
- */
1755
- clearData(): void;
1756
- /**
1757
- * Update configuration
1758
- */
1759
- updateConfig(config: Partial<MockConfig>): void;
1760
- setScenario(scenario: MockScenario): void;
1761
- getScenario(): MockScenario;
1762
- private applyOrderFilters;
1763
- private applyBrokerOrderFilters;
1764
- private applyBrokerPositionFilters;
1765
- private applyBrokerAccountFilters;
1766
- private applyBrokerBalanceFilters;
1767
- /**
1768
- * Generate mock orders with diverse data
1769
- */
1770
- private generateMockOrders;
1771
- /**
1772
- * Generate mock positions with diverse data
1773
- */
1774
- private generateMockPositions;
1775
- /**
1776
- * Generate mock accounts with diverse data
1777
- */
1778
- private generateMockAccounts;
1779
- /**
1780
- * Mock disconnect company method
1781
- * @param connectionId - The connection ID to disconnect
1782
- * @returns Promise with mock disconnect response
1783
- */
1784
- mockDisconnectCompany(connectionId: string): Promise<DisconnectCompanyResponse>;
1785
- }
1786
-
1787
- /**
1788
- * Mock API Client that implements the same interface as the real ApiClient
1789
- * but returns mock data instead of making HTTP requests
1790
- */
1791
- declare class MockApiClient {
1792
- private readonly baseUrl;
1793
- protected readonly deviceInfo?: DeviceInfo$1;
1794
- protected currentSessionState: SessionState | null;
1795
- protected currentSessionId: string | null;
1796
- private tradingContext;
1797
- private tokenInfo;
1798
- private refreshPromise;
1799
- private readonly REFRESH_BUFFER_MINUTES;
1800
- private companyId;
1801
- private csrfToken;
1802
- private mockDataProvider;
1803
- private readonly mockApiOnly;
1804
- constructor(baseUrl: string, deviceInfo?: DeviceInfo$1, mockConfig?: MockConfig);
1805
- /**
1806
- * Store tokens after successful authentication
1807
- */
1808
- setTokens(accessToken: string, refreshToken: string, expiresAt: string, userId?: string): void;
1809
- /**
1810
- * Get the current access token, refreshing if necessary
1811
- */
1812
- getValidAccessToken(): Promise<string>;
1813
- /**
1814
- * Check if the current token is expired or about to expire
1815
- */
1816
- private isTokenExpired;
1817
- /**
1818
- * Refresh the access token using the refresh token
1819
- */
1820
- private refreshTokens;
1821
- /**
1822
- * Perform the actual token refresh request
1823
- */
1824
- private performTokenRefresh;
1825
- /**
1826
- * Clear stored tokens (useful for logout)
1827
- */
1828
- clearTokens(): void;
1829
- /**
1830
- * Get current token info (for debugging/testing)
1831
- */
1832
- getTokenInfo(): TokenInfo | null;
1833
- /**
1834
- * Set session context (session ID, company ID, CSRF token)
1835
- */
1836
- setSessionContext(sessionId: string, companyId: string, csrfToken?: string): void;
1837
- /**
1838
- * Get the current session ID
1839
- */
1840
- getCurrentSessionId(): string | null;
1841
- /**
1842
- * Get the current company ID
1843
- */
1844
- getCurrentCompanyId(): string | null;
1845
- /**
1846
- * Get the current CSRF token
1847
- */
1848
- getCurrentCsrfToken(): string | null;
1849
- startSession(token: string, userId?: string): Promise<SessionResponse>;
1850
- requestOtp(sessionId: string, email: string): Promise<OtpRequestResponse>;
1851
- verifyOtp(sessionId: string, otp: string): Promise<OtpVerifyResponse>;
1852
- authenticateDirectly(sessionId: string, userId: string): Promise<SessionAuthenticateResponse>;
1853
- getPortalUrl(sessionId: string): Promise<PortalUrlResponse>;
1854
- validatePortalSession(sessionId: string, signature: string): Promise<SessionValidationResponse>;
1855
- completePortalSession(sessionId: string): Promise<PortalUrlResponse>;
1856
- getOrders(filter?: OrdersFilter): Promise<{
1857
- data: Order[];
1858
- }>;
1859
- placeOrder(order: BrokerOrderParams): Promise<void>;
1860
- placeBrokerOrder(params: Partial<BrokerOrderParams> & {
1861
- symbol: string;
1862
- orderQty: number;
1863
- action: 'Buy' | 'Sell';
1864
- orderType: 'Market' | 'Limit' | 'Stop' | 'StopLimit';
1865
- assetType: 'Stock' | 'Option' | 'Crypto' | 'Future';
1866
- }, extras?: BrokerExtras, connection_id?: string): Promise<OrderResponse>;
1867
- cancelBrokerOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any, connection_id?: string): Promise<OrderResponse>;
1868
- modifyBrokerOrder(orderId: string, params: Partial<BrokerOrderParams>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any, connection_id?: string): Promise<OrderResponse>;
1869
- setBroker(broker: 'robinhood' | 'tasty_trade' | 'ninja_trader'): void;
1870
- setAccount(accountNumber: string, accountId?: string): void;
1871
- getTradingContext(): TradingContext;
1872
- clearTradingContext(): void;
1873
- placeStockMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1874
- placeStockLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1875
- placeStockStopOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', stopPrice: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1876
- placeCryptoMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', options?: CryptoOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1877
- placeCryptoLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', options?: CryptoOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1878
- placeOptionsMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', options: OptionsOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1879
- placeOptionsLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, options: OptionsOrderOptions, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1880
- placeFuturesMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1881
- placeFuturesLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
1882
- getUserToken(sessionId: string): Promise<UserToken>;
1883
- getCurrentSessionState(): SessionState | null;
1884
- getBrokerList(): Promise<{
1885
- _id: string;
1886
- response_data: BrokerInfo[];
1887
- message: string;
1888
- status_code: number;
1889
- warnings: null;
1890
- errors: null;
1891
- }>;
1892
- getBrokerAccounts(options?: BrokerDataOptions): Promise<{
1893
- _id: string;
1894
- response_data: BrokerAccount[];
1895
- message: string;
1896
- status_code: number;
1897
- warnings: null;
1898
- errors: null;
1899
- }>;
1900
- getBrokerOrders(options?: BrokerDataOptions): Promise<{
1901
- _id: string;
1902
- response_data: BrokerOrder[];
1903
- message: string;
1904
- status_code: number;
1905
- warnings: null;
1906
- errors: null;
1907
- }>;
1908
- getBrokerPositions(options?: BrokerDataOptions): Promise<{
1909
- _id: string;
1910
- response_data: BrokerPosition[];
1911
- message: string;
1912
- status_code: number;
1913
- warnings: null;
1914
- errors: null;
1915
- }>;
1916
- getBrokerOrdersWithFilter(filter?: OrdersFilter): Promise<{
1917
- data: BrokerDataOrder[];
1918
- }>;
1919
- getBrokerPositionsWithFilter(filter?: PositionsFilter): Promise<{
1920
- data: BrokerDataPosition[];
1921
- }>;
1922
- getBrokerBalancesWithFilter(filter?: BalancesFilter): Promise<{
1923
- data: BrokerBalance[];
1924
- }>;
1925
- getBrokerDataAccountsWithFilter(filter?: AccountsFilter): Promise<{
1926
- data: BrokerAccount[];
1927
- }>;
1928
- getBrokerOrdersPage(page?: number, perPage?: number, filters?: OrdersFilter): Promise<PaginatedResult<BrokerDataOrder[]>>;
1929
- getBrokerAccountsPage(page?: number, perPage?: number, filters?: AccountsFilter): Promise<PaginatedResult<BrokerAccount[]>>;
1930
- getBrokerPositionsPage(page?: number, perPage?: number, filters?: PositionsFilter): Promise<PaginatedResult<BrokerDataPosition[]>>;
1931
- getBrokerBalancesPage(page?: number, perPage?: number, filters?: BalancesFilter): Promise<PaginatedResult<BrokerBalance[]>>;
1932
- getBrokerConnections(): Promise<{
1933
- _id: string;
1934
- response_data: BrokerConnection[];
1935
- message: string;
1936
- status_code: number;
1937
- warnings: null;
1938
- errors: null;
1939
- }>;
1940
- /**
1941
- * Mock disconnect company method
1942
- * @param connectionId - The connection ID to disconnect
1943
- * @returns Promise with mock disconnect response
1944
- */
1945
- disconnectCompany(connectionId: string): Promise<DisconnectCompanyResponse>;
1946
- getMockDataProvider(): MockDataProvider;
1947
- clearMockData(): void;
1948
- /**
1949
- * Check if this is a mock client
1950
- * @returns true if this is a mock client
1951
- */
1952
- isMockClient(): boolean;
1953
- }
1954
-
1955
- /**
1956
- * Factory class for creating API clients (real or mock)
1957
- */
1958
- declare class MockFactory {
1959
- /**
1960
- * Create an API client based on environment configuration
1961
- * @param baseUrl - The base URL for the API
1962
- * @param deviceInfo - Optional device information
1963
- * @param mockConfig - Optional mock configuration (only used if mocks are enabled)
1964
- * @returns ApiClient or MockApiClient instance
1965
- */
1966
- static createApiClient(baseUrl: string, deviceInfo?: DeviceInfo$1, mockConfig?: MockConfig): ApiClient | MockApiClient;
1967
- /**
1968
- * Force create a mock API client regardless of environment settings
1969
- * @param baseUrl - The base URL for the API
1970
- * @param deviceInfo - Optional device information
1971
- * @param mockConfig - Optional mock configuration
1972
- * @returns MockApiClient instance
1973
- */
1974
- static createMockApiClient(baseUrl: string, deviceInfo?: DeviceInfo$1, mockConfig?: MockConfig): MockApiClient;
1975
- /**
1976
- * Force create a real API client regardless of environment settings
1977
- * @param baseUrl - The base URL for the API
1978
- * @param deviceInfo - Optional device information
1979
- * @returns ApiClient instance
1980
- */
1981
- static createRealApiClient(baseUrl: string, deviceInfo?: DeviceInfo$1): ApiClient;
1982
- /**
1983
- * Check if mocks are currently enabled
1984
- * @returns boolean indicating if mocks are enabled
1985
- */
1986
- static isMockMode(): boolean;
1987
- /**
1988
- * Get current mock configuration
1989
- * @returns Mock configuration object
1990
- */
1991
- static getMockConfig(): {
1992
- enabled: boolean;
1993
- delay?: number;
1994
- };
1995
- }
1996
-
1997
- export { ApiClient, ApiError, AuthenticationError, AuthorizationError, BaseError, CompanyAccessError, EventEmitter, FinaticConnect, MockFactory, NetworkError, OrderError, OrderValidationError, PaginatedResult, RateLimitError, SecurityError, SessionError, TokenError, TradingNotEnabledError, appendThemeToURL, createCustomThemeFromPreset, generatePortalThemeURL, getThemePreset, portalThemePresets, validateCustomTheme };
1998
- export type { AccountsFilter, ApiConfig, ApiResponse, BalancesFilter, BrokerAccount, BrokerBalance, BrokerConnection, BrokerDataAccount, BrokerDataOptions, BrokerDataOrder, BrokerDataPosition, BrokerExtras, BrokerInfo, BrokerOrder, BrokerOrderParams, BrokerPosition, CryptoOrderOptions, DeviceInfo$1 as DeviceInfo, FilteredAccountsResponse, FilteredBalancesResponse, FilteredOrdersResponse, FilteredPositionsResponse, FinaticConnectOptions, FinaticUserToken, Holding, OptionsOrder, OptionsOrderOptions, Order, OrderNotFoundError, OrderResponse, OrdersFilter, OtpRequestResponse, OtpVerifyResponse, PerformanceMetrics, PortalMessage, PortalProps, PortalResponse, PortalTheme, PortalThemeConfig, PortalThemePreset, PortalUrlResponse, Portfolio, PortfolioSnapshot, PositionsFilter, RefreshTokenRequest, RefreshTokenResponse, RequestHeaders, SessionAuthenticateResponse, SessionInitResponse, SessionResponse, SessionStartResponse, SessionStatus, SessionValidationResponse, TokenInfo, TradeAccessDeniedError, TradingContext, UserToken, ValidationError };
1537
+ export { ApiClient, ApiError, AuthenticationError, AuthorizationError, BaseError, CompanyAccessError, EventEmitter, FinaticConnect, NetworkError, OrderError, OrderValidationError, PaginatedResult, RateLimitError, SecurityError, SessionError, TokenError, TradingNotEnabledError, appendThemeToURL, createCustomThemeFromPreset, generatePortalThemeURL, getThemePreset, portalThemePresets, validateCustomTheme };
1538
+ export type { AccountsFilter, ApiConfig, ApiResponse, BalancesFilter, BrokerAccount, BrokerBalance, BrokerConnection, BrokerDataAccount, BrokerDataOptions, BrokerDataOrder, BrokerDataPosition, BrokerExtras$1 as BrokerExtras, BrokerInfo, BrokerOrder, BrokerOrderParams, BrokerPosition, CryptoOrderOptions, DeviceInfo$1 as DeviceInfo, FilteredAccountsResponse, FilteredBalancesResponse, FilteredOrdersResponse, FilteredPositionsResponse, FinaticConnectOptions, FinaticUserToken, Holding, OptionsOrder, OptionsOrderOptions, Order, OrderNotFoundError, OrderResponse, OrdersFilter, OtpRequestResponse, OtpVerifyResponse, PerformanceMetrics, PortalMessage, PortalProps, PortalResponse, PortalTheme, PortalThemeConfig, PortalThemePreset, PortalUrlResponse, Portfolio, PortfolioSnapshot, PositionsFilter, RefreshTokenRequest, RefreshTokenResponse, RequestHeaders, SessionAuthenticateResponse, SessionInitResponse, SessionResponse, SessionStatus, SessionValidationResponse, TokenInfo, TradeAccessDeniedError, TradingContext, UserToken, ValidationError };