@finatic/client 0.0.131

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 (47) hide show
  1. package/README.md +489 -0
  2. package/dist/index.d.ts +2037 -0
  3. package/dist/index.js +4815 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +4787 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/dist/types/client/ApiClient.d.ts +234 -0
  8. package/dist/types/client/FinaticConnect.d.ts +307 -0
  9. package/dist/types/index.d.ts +17 -0
  10. package/dist/types/mocks/MockApiClient.d.ts +228 -0
  11. package/dist/types/mocks/MockDataProvider.d.ts +132 -0
  12. package/dist/types/mocks/MockFactory.d.ts +53 -0
  13. package/dist/types/mocks/index.d.ts +5 -0
  14. package/dist/types/mocks/utils.d.ts +29 -0
  15. package/dist/types/portal/PortalUI.d.ts +38 -0
  16. package/dist/types/security/ApiSecurity.d.ts +24 -0
  17. package/dist/types/security/RuntimeSecurity.d.ts +28 -0
  18. package/dist/types/security/SecurityUtils.d.ts +21 -0
  19. package/dist/types/security/index.d.ts +2 -0
  20. package/dist/types/services/AnalyticsService.d.ts +18 -0
  21. package/dist/types/services/ApiClient.d.ts +121 -0
  22. package/dist/types/services/PortalService.d.ts +24 -0
  23. package/dist/types/services/TradingService.d.ts +55 -0
  24. package/dist/types/services/api.d.ts +23 -0
  25. package/dist/types/services/auth.d.ts +9 -0
  26. package/dist/types/services/index.d.ts +4 -0
  27. package/dist/types/services/portfolio.d.ts +10 -0
  28. package/dist/types/services/trading.d.ts +10 -0
  29. package/dist/types/shared/index.d.ts +2 -0
  30. package/dist/types/shared/themes/index.d.ts +2 -0
  31. package/dist/types/shared/themes/portalPresets.d.ts +8 -0
  32. package/dist/types/shared/themes/presets.d.ts +3 -0
  33. package/dist/types/shared/themes/system.d.ts +2 -0
  34. package/dist/types/shared/types/index.d.ts +110 -0
  35. package/dist/types/types/api.d.ts +486 -0
  36. package/dist/types/types/config.d.ts +12 -0
  37. package/dist/types/types/connect.d.ts +51 -0
  38. package/dist/types/types/errors.d.ts +47 -0
  39. package/dist/types/types/portal.d.ts +75 -0
  40. package/dist/types/types/security.d.ts +35 -0
  41. package/dist/types/types/shared.d.ts +50 -0
  42. package/dist/types/types/theme.d.ts +101 -0
  43. package/dist/types/types.d.ts +157 -0
  44. package/dist/types/utils/errors.d.ts +42 -0
  45. package/dist/types/utils/events.d.ts +12 -0
  46. package/dist/types/utils/themeUtils.d.ts +34 -0
  47. package/package.json +56 -0
@@ -0,0 +1,228 @@
1
+ import { SessionResponse, OtpRequestResponse, OtpVerifyResponse, PortalUrlResponse, SessionValidationResponse, SessionAuthenticateResponse, UserToken, Holding, Order, Portfolio, BrokerInfo, BrokerAccount, BrokerOrder, BrokerPosition, BrokerConnection, BrokerDataOptions, SessionState, BrokerOrderParams, BrokerExtras, CryptoOrderOptions, OptionsOrderOptions, OrderResponse, TradingContext, TokenInfo, OrdersFilter, PositionsFilter, AccountsFilter, BrokerDataOrder, BrokerDataPosition, BrokerDataAccount } from '../types/api';
2
+ import { DeviceInfo } from '../types/api';
3
+ import { PaginatedResult } from '../types';
4
+ import { MockDataProvider, MockConfig } from './MockDataProvider';
5
+ /**
6
+ * Mock API Client that implements the same interface as the real ApiClient
7
+ * but returns mock data instead of making HTTP requests
8
+ */
9
+ export declare class MockApiClient {
10
+ private readonly baseUrl;
11
+ protected readonly deviceInfo?: DeviceInfo;
12
+ protected currentSessionState: SessionState | null;
13
+ protected currentSessionId: string | null;
14
+ private tradingContext;
15
+ private tokenInfo;
16
+ private refreshPromise;
17
+ private readonly REFRESH_BUFFER_MINUTES;
18
+ private companyId;
19
+ private csrfToken;
20
+ private mockDataProvider;
21
+ private readonly mockApiOnly;
22
+ constructor(baseUrl: string, deviceInfo?: DeviceInfo, mockConfig?: MockConfig);
23
+ /**
24
+ * Store tokens after successful authentication
25
+ */
26
+ setTokens(accessToken: string, refreshToken: string, expiresAt: string, userId?: string): void;
27
+ /**
28
+ * Get the current access token, refreshing if necessary
29
+ */
30
+ getValidAccessToken(): Promise<string>;
31
+ /**
32
+ * Check if the current token is expired or about to expire
33
+ */
34
+ private isTokenExpired;
35
+ /**
36
+ * Refresh the access token using the refresh token
37
+ */
38
+ private refreshTokens;
39
+ /**
40
+ * Perform the actual token refresh request
41
+ */
42
+ private performTokenRefresh;
43
+ /**
44
+ * Clear stored tokens (useful for logout)
45
+ */
46
+ clearTokens(): void;
47
+ /**
48
+ * Get current token info (for debugging/testing)
49
+ */
50
+ getTokenInfo(): TokenInfo | null;
51
+ /**
52
+ * Set session context (session ID, company ID, CSRF token)
53
+ */
54
+ setSessionContext(sessionId: string, companyId: string, csrfToken?: string): void;
55
+ /**
56
+ * Get the current session ID
57
+ */
58
+ getCurrentSessionId(): string | null;
59
+ /**
60
+ * Get the current company ID
61
+ */
62
+ getCurrentCompanyId(): string | null;
63
+ /**
64
+ * Get the current CSRF token
65
+ */
66
+ getCurrentCsrfToken(): string | null;
67
+ startSession(token: string, userId?: string): Promise<SessionResponse>;
68
+ requestOtp(sessionId: string, email: string): Promise<OtpRequestResponse>;
69
+ verifyOtp(sessionId: string, otp: string): Promise<OtpVerifyResponse>;
70
+ authenticateDirectly(sessionId: string, userId: string): Promise<SessionAuthenticateResponse>;
71
+ getPortalUrl(sessionId: string): Promise<PortalUrlResponse>;
72
+ validatePortalSession(sessionId: string, signature: string): Promise<SessionValidationResponse>;
73
+ completePortalSession(sessionId: string): Promise<PortalUrlResponse>;
74
+ getHoldings(accessToken: string): Promise<{
75
+ data: Holding[];
76
+ }>;
77
+ getOrders(accessToken: string, filter?: OrdersFilter): Promise<{
78
+ data: Order[];
79
+ }>;
80
+ getPortfolio(accessToken: string): Promise<{
81
+ data: Portfolio;
82
+ }>;
83
+ placeOrder(accessToken: string, order: Order): Promise<void>;
84
+ getHoldingsAuto(): Promise<{
85
+ data: Holding[];
86
+ }>;
87
+ getOrdersAuto(): Promise<{
88
+ data: Order[];
89
+ }>;
90
+ getPortfolioAuto(): Promise<{
91
+ data: Portfolio;
92
+ }>;
93
+ placeOrderAuto(order: Order): Promise<void>;
94
+ placeBrokerOrder(accessToken: string, params: Partial<BrokerOrderParams> & {
95
+ symbol: string;
96
+ orderQty: number;
97
+ action: 'Buy' | 'Sell';
98
+ orderType: 'Market' | 'Limit' | 'Stop' | 'TrailingStop';
99
+ assetType: 'Stock' | 'Option' | 'Crypto' | 'Futures';
100
+ }, extras?: BrokerExtras): Promise<OrderResponse>;
101
+ cancelBrokerOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any): Promise<OrderResponse>;
102
+ modifyBrokerOrder(orderId: string, params: Partial<BrokerOrderParams>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any): Promise<OrderResponse>;
103
+ setBroker(broker: 'robinhood' | 'tasty_trade' | 'ninja_trader'): void;
104
+ setAccount(accountNumber: string, accountId?: string): void;
105
+ getTradingContext(): TradingContext;
106
+ clearTradingContext(): void;
107
+ placeStockMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
108
+ placeStockLimitOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
109
+ placeStockStopOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', stopPrice: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
110
+ placeCryptoMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', options?: CryptoOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
111
+ placeCryptoLimitOrder(accessToken: string, 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>;
112
+ placeOptionsMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', options: OptionsOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
113
+ placeOptionsLimitOrder(accessToken: string, 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>;
114
+ placeFuturesMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
115
+ placeFuturesLimitOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
116
+ revokeToken(accessToken: string): Promise<void>;
117
+ getUserToken(userId: string): Promise<UserToken>;
118
+ getCurrentSessionState(): SessionState | null;
119
+ getBrokerList(accessToken: string): Promise<{
120
+ _id: string;
121
+ response_data: BrokerInfo[];
122
+ message: string;
123
+ status_code: number;
124
+ warnings: null;
125
+ errors: null;
126
+ }>;
127
+ getBrokerAccounts(accessToken: string, options?: BrokerDataOptions): Promise<{
128
+ _id: string;
129
+ response_data: BrokerAccount[];
130
+ message: string;
131
+ status_code: number;
132
+ warnings: null;
133
+ errors: null;
134
+ }>;
135
+ getBrokerOrders(accessToken: string, options?: BrokerDataOptions): Promise<{
136
+ _id: string;
137
+ response_data: BrokerOrder[];
138
+ message: string;
139
+ status_code: number;
140
+ warnings: null;
141
+ errors: null;
142
+ }>;
143
+ getBrokerPositions(accessToken: string, options?: BrokerDataOptions): Promise<{
144
+ _id: string;
145
+ response_data: BrokerPosition[];
146
+ message: string;
147
+ status_code: number;
148
+ warnings: null;
149
+ errors: null;
150
+ }>;
151
+ getBrokerOrdersWithFilter(filter?: OrdersFilter): Promise<{
152
+ data: BrokerDataOrder[];
153
+ }>;
154
+ getBrokerPositionsWithFilter(filter?: PositionsFilter): Promise<{
155
+ data: BrokerDataPosition[];
156
+ }>;
157
+ getBrokerDataAccountsWithFilter(filter?: AccountsFilter): Promise<{
158
+ data: BrokerDataAccount[];
159
+ }>;
160
+ getBrokerOrdersPage(page?: number, perPage?: number, filters?: OrdersFilter): Promise<PaginatedResult<any[]>>;
161
+ getBrokerAccountsPage(page?: number, perPage?: number, filters?: AccountsFilter): Promise<PaginatedResult<any[]>>;
162
+ getBrokerPositionsPage(page?: number, perPage?: number, filters?: PositionsFilter): Promise<PaginatedResult<any[]>>;
163
+ getBrokerConnections(accessToken: string): Promise<{
164
+ _id: string;
165
+ response_data: BrokerConnection[];
166
+ message: string;
167
+ status_code: number;
168
+ warnings: null;
169
+ errors: null;
170
+ }>;
171
+ getBrokerListAuto(): Promise<{
172
+ _id: string;
173
+ response_data: BrokerInfo[];
174
+ message: string;
175
+ status_code: number;
176
+ warnings: null;
177
+ errors: null;
178
+ }>;
179
+ getBrokerAccountsAuto(options?: BrokerDataOptions): Promise<{
180
+ _id: string;
181
+ response_data: BrokerAccount[];
182
+ message: string;
183
+ status_code: number;
184
+ warnings: null;
185
+ errors: null;
186
+ }>;
187
+ getBrokerOrdersAuto(options?: BrokerDataOptions): Promise<{
188
+ _id: string;
189
+ response_data: BrokerOrder[];
190
+ message: string;
191
+ status_code: number;
192
+ warnings: null;
193
+ errors: null;
194
+ }>;
195
+ getBrokerPositionsAuto(options?: BrokerDataOptions): Promise<{
196
+ _id: string;
197
+ response_data: BrokerPosition[];
198
+ message: string;
199
+ status_code: number;
200
+ warnings: null;
201
+ errors: null;
202
+ }>;
203
+ getBrokerConnectionsAuto(): Promise<{
204
+ _id: string;
205
+ response_data: BrokerConnection[];
206
+ message: string;
207
+ status_code: number;
208
+ warnings: null;
209
+ errors: null;
210
+ }>;
211
+ placeBrokerOrderAuto(params: Partial<BrokerOrderParams> & {
212
+ symbol: string;
213
+ orderQty: number;
214
+ action: 'Buy' | 'Sell';
215
+ orderType: 'Market' | 'Limit' | 'Stop' | 'TrailingStop';
216
+ assetType: 'Stock' | 'Option' | 'Crypto' | 'Futures';
217
+ }, extras?: BrokerExtras): Promise<OrderResponse>;
218
+ placeStockMarketOrderAuto(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
219
+ placeStockLimitOrderAuto(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
220
+ placeStockStopOrderAuto(symbol: string, orderQty: number, action: 'Buy' | 'Sell', stopPrice: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
221
+ getMockDataProvider(): MockDataProvider;
222
+ clearMockData(): void;
223
+ /**
224
+ * Check if this is a mock client
225
+ * @returns true if this is a mock client
226
+ */
227
+ isMockClient(): boolean;
228
+ }
@@ -0,0 +1,132 @@
1
+ import { SessionResponse, OtpRequestResponse, OtpVerifyResponse, PortalUrlResponse, SessionValidationResponse, SessionAuthenticateResponse, UserToken, Holding, Order, Portfolio, BrokerInfo, BrokerAccount, BrokerConnection, OrderResponse, RefreshTokenResponse, OrdersFilter, PositionsFilter, AccountsFilter, BrokerDataOrder, BrokerDataPosition, BrokerDataAccount } from '../types/api';
2
+ /**
3
+ * Configuration for mock behavior
4
+ */
5
+ export interface MockConfig {
6
+ delay?: number;
7
+ scenario?: MockScenario;
8
+ customData?: Record<string, any>;
9
+ mockApiOnly?: boolean;
10
+ }
11
+ /**
12
+ * Different mock scenarios for testing
13
+ */
14
+ export type MockScenario = 'success' | 'error' | 'network_error' | 'rate_limit' | 'auth_failure';
15
+ /**
16
+ * Mock data provider for Finatic API endpoints
17
+ */
18
+ export declare class MockDataProvider {
19
+ private config;
20
+ private sessionData;
21
+ private userTokens;
22
+ constructor(config?: MockConfig);
23
+ /**
24
+ * Get a random delay between min and max milliseconds
25
+ */
26
+ private getRandomDelay;
27
+ /**
28
+ * Simulate network delay
29
+ */
30
+ simulateDelay(): Promise<void>;
31
+ /**
32
+ * Generate a realistic session ID
33
+ */
34
+ private generateSessionId;
35
+ /**
36
+ * Generate a realistic user ID
37
+ */
38
+ private generateUserId;
39
+ /**
40
+ * Generate a realistic company ID
41
+ */
42
+ private generateCompanyId;
43
+ /**
44
+ * Generate mock tokens
45
+ */
46
+ private generateTokens;
47
+ mockStartSession(token: string, userId?: string): Promise<SessionResponse>;
48
+ mockRequestOtp(sessionId: string, email: string): Promise<OtpRequestResponse>;
49
+ mockVerifyOtp(sessionId: string, otp: string): Promise<OtpVerifyResponse>;
50
+ mockAuthenticateDirectly(sessionId: string, userId: string): Promise<SessionAuthenticateResponse>;
51
+ mockGetPortalUrl(sessionId: string): Promise<PortalUrlResponse>;
52
+ mockValidatePortalSession(sessionId: string, signature: string): Promise<SessionValidationResponse>;
53
+ mockCompletePortalSession(sessionId: string): Promise<PortalUrlResponse>;
54
+ mockRefreshToken(refreshToken: string): Promise<RefreshTokenResponse>;
55
+ mockGetBrokerList(): Promise<{
56
+ _id: string;
57
+ response_data: BrokerInfo[];
58
+ message: string;
59
+ status_code: number;
60
+ warnings: null;
61
+ errors: null;
62
+ }>;
63
+ mockGetBrokerAccounts(): Promise<{
64
+ _id: string;
65
+ response_data: BrokerAccount[];
66
+ message: string;
67
+ status_code: number;
68
+ warnings: null;
69
+ errors: null;
70
+ }>;
71
+ mockGetBrokerConnections(): Promise<{
72
+ _id: string;
73
+ response_data: BrokerConnection[];
74
+ message: string;
75
+ status_code: number;
76
+ warnings: null;
77
+ errors: null;
78
+ }>;
79
+ mockGetHoldings(): Promise<{
80
+ data: Holding[];
81
+ }>;
82
+ mockGetPortfolio(): Promise<{
83
+ data: Portfolio;
84
+ }>;
85
+ mockGetOrders(filter?: OrdersFilter): Promise<{
86
+ data: Order[];
87
+ }>;
88
+ mockGetBrokerOrders(filter?: OrdersFilter): Promise<{
89
+ data: BrokerDataOrder[];
90
+ }>;
91
+ mockGetBrokerPositions(filter?: PositionsFilter): Promise<{
92
+ data: BrokerDataPosition[];
93
+ }>;
94
+ mockGetBrokerDataAccounts(filter?: AccountsFilter): Promise<{
95
+ data: BrokerDataAccount[];
96
+ }>;
97
+ mockPlaceOrder(order: Order): Promise<OrderResponse>;
98
+ /**
99
+ * Get stored session data
100
+ */
101
+ getSessionData(sessionId: string): any;
102
+ /**
103
+ * Get stored user token
104
+ */
105
+ getUserToken(userId: string): UserToken | undefined;
106
+ /**
107
+ * Clear all stored data
108
+ */
109
+ clearData(): void;
110
+ /**
111
+ * Update configuration
112
+ */
113
+ updateConfig(config: Partial<MockConfig>): void;
114
+ setScenario(scenario: MockScenario): void;
115
+ getScenario(): MockScenario;
116
+ private applyOrderFilters;
117
+ private applyBrokerOrderFilters;
118
+ private applyBrokerPositionFilters;
119
+ private applyBrokerAccountFilters;
120
+ /**
121
+ * Generate mock orders with diverse data
122
+ */
123
+ private generateMockOrders;
124
+ /**
125
+ * Generate mock positions with diverse data
126
+ */
127
+ private generateMockPositions;
128
+ /**
129
+ * Generate mock accounts with diverse data
130
+ */
131
+ private generateMockAccounts;
132
+ }
@@ -0,0 +1,53 @@
1
+ import { ApiClient } from '../client/ApiClient';
2
+ import { MockApiClient } from './MockApiClient';
3
+ import { MockConfig } from './MockDataProvider';
4
+ import { DeviceInfo } from '../types/api';
5
+ /**
6
+ * Factory class for creating API clients (real or mock)
7
+ */
8
+ export declare class MockFactory {
9
+ /**
10
+ * Create an API client based on environment configuration
11
+ * @param baseUrl - The base URL for the API
12
+ * @param deviceInfo - Optional device information
13
+ * @param mockConfig - Optional mock configuration (only used if mocks are enabled)
14
+ * @returns ApiClient or MockApiClient instance
15
+ */
16
+ static createApiClient(baseUrl: string, deviceInfo?: DeviceInfo, mockConfig?: MockConfig): ApiClient | MockApiClient;
17
+ /**
18
+ * Force create a mock API client regardless of environment settings
19
+ * @param baseUrl - The base URL for the API
20
+ * @param deviceInfo - Optional device information
21
+ * @param mockConfig - Optional mock configuration
22
+ * @returns MockApiClient instance
23
+ */
24
+ static createMockApiClient(baseUrl: string, deviceInfo?: DeviceInfo, mockConfig?: MockConfig): MockApiClient;
25
+ /**
26
+ * Force create a real API client regardless of environment settings
27
+ * @param baseUrl - The base URL for the API
28
+ * @param deviceInfo - Optional device information
29
+ * @returns ApiClient instance
30
+ */
31
+ static createRealApiClient(baseUrl: string, deviceInfo?: DeviceInfo): ApiClient;
32
+ /**
33
+ * Check if mocks are currently enabled
34
+ * @returns boolean indicating if mocks are enabled
35
+ */
36
+ static isMockMode(): boolean;
37
+ /**
38
+ * Get current mock configuration
39
+ * @returns Mock configuration object
40
+ */
41
+ static getMockConfig(): {
42
+ enabled: boolean;
43
+ delay?: number;
44
+ };
45
+ }
46
+ /**
47
+ * Convenience function to create an API client
48
+ * @param baseUrl - The base URL for the API
49
+ * @param deviceInfo - Optional device information
50
+ * @param mockConfig - Optional mock configuration
51
+ * @returns ApiClient or MockApiClient instance
52
+ */
53
+ export declare function createMockApiClient(baseUrl: string, deviceInfo?: DeviceInfo, mockConfig?: MockConfig): ApiClient | MockApiClient;
@@ -0,0 +1,5 @@
1
+ export { MockApiClient } from './MockApiClient';
2
+ export { MockDataProvider } from './MockDataProvider';
3
+ export { MockFactory, createMockApiClient } from './MockFactory';
4
+ export type { MockConfig, MockScenario } from './MockDataProvider';
5
+ export { shouldUseMocks, setMockMode, getMockConfig } from './utils';
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Utility functions for mock system environment detection
3
+ */
4
+ declare global {
5
+ var process: {
6
+ env: Record<string, string | undefined>;
7
+ } | undefined;
8
+ }
9
+ /**
10
+ * Check if mocks should be used based on environment variables
11
+ * Supports both browser and Node.js environments
12
+ */
13
+ export declare function shouldUseMocks(): boolean;
14
+ /**
15
+ * Set mock mode in the current environment
16
+ */
17
+ export declare function setMockMode(enabled: boolean): void;
18
+ /**
19
+ * Check if only API should be mocked (but portal should use real URL)
20
+ */
21
+ export declare function shouldMockApiOnly(): boolean;
22
+ /**
23
+ * Get mock configuration from environment
24
+ */
25
+ export declare function getMockConfig(): {
26
+ enabled: boolean;
27
+ delay?: number;
28
+ mockApiOnly?: boolean;
29
+ };
@@ -0,0 +1,38 @@
1
+ import { UserToken } from '../types/api';
2
+ export declare class PortalUI {
3
+ private iframe;
4
+ private container;
5
+ private messageHandler;
6
+ private sessionId;
7
+ private portalOrigin;
8
+ private options?;
9
+ private userToken;
10
+ private originalBodyStyle;
11
+ constructor(portalUrl: string);
12
+ private createContainer;
13
+ /**
14
+ * Lock background scrolling by setting overflow: hidden on body
15
+ */
16
+ private lockScroll;
17
+ /**
18
+ * Unlock background scrolling by restoring original body style
19
+ */
20
+ private unlockScroll;
21
+ show(url: string, sessionId: string, options?: {
22
+ onSuccess?: (userId: string) => void;
23
+ onError?: (error: Error) => void;
24
+ onClose?: () => void;
25
+ onEvent?: (type: string, data: any) => void;
26
+ }): void;
27
+ hide(): void;
28
+ private handleMessage;
29
+ private handlePortalSuccess;
30
+ private handlePortalError;
31
+ private handlePortalClose;
32
+ private handleGenericEvent;
33
+ private handleSuccess;
34
+ private handleError;
35
+ private handleClose;
36
+ private handleResize;
37
+ getTokens(): UserToken | null;
38
+ }
@@ -0,0 +1,24 @@
1
+ export interface SecurityHeaders {
2
+ 'X-Request-ID': string;
3
+ 'X-Request-Timestamp': string;
4
+ 'X-Request-Signature': string;
5
+ 'X-Device-Fingerprint': string;
6
+ 'User-Agent': string;
7
+ }
8
+ export declare class ApiSecurity {
9
+ private static instance;
10
+ private readonly runtimeSecurity;
11
+ private readonly requestTimeout;
12
+ private deviceFingerprint;
13
+ private userAgent;
14
+ private constructor();
15
+ static getInstance(): ApiSecurity;
16
+ generateRequestHeaders(): SecurityHeaders;
17
+ setDeviceFingerprint(fingerprint: string): void;
18
+ private generateDeviceFingerprint;
19
+ private generateRequestSignature;
20
+ validateResponse(): boolean;
21
+ isRequestValid(headers: SecurityHeaders): boolean;
22
+ private validateDeviceFingerprint;
23
+ private validateRequestSignature;
24
+ }
@@ -0,0 +1,28 @@
1
+ export interface IRuntimeSecurity {
2
+ isSecure(): boolean;
3
+ validateEnvironment(): boolean;
4
+ getEnvironmentInfo(): Record<string, any>;
5
+ getClientIp(): string;
6
+ generateFingerprint(): string;
7
+ }
8
+ export declare class RuntimeSecurity implements IRuntimeSecurity {
9
+ private static instance;
10
+ private readonly runtimeKey;
11
+ private readonly integrityChecks;
12
+ private isDebuggerAttached;
13
+ private constructor();
14
+ static getInstance(): RuntimeSecurity;
15
+ private setupAntiDebugging;
16
+ private setupIntegrityChecks;
17
+ addIntegrityCheck(name: string, check: () => boolean): void;
18
+ verifyIntegrity(): boolean;
19
+ signRequest(data: any): string;
20
+ validateEnvironment(): boolean;
21
+ private handleSecurityViolation;
22
+ private clearSensitiveData;
23
+ private reportSecurityViolation;
24
+ isSecure(): boolean;
25
+ getClientIp(): string;
26
+ generateFingerprint(): string;
27
+ getEnvironmentInfo(): Record<string, any>;
28
+ }
@@ -0,0 +1,21 @@
1
+ export interface DeviceFingerprint {
2
+ userAgent: string;
3
+ ip: string;
4
+ screenResolution: string;
5
+ timezone: string;
6
+ language: string;
7
+ platform: string;
8
+ }
9
+ export declare class SecurityUtils {
10
+ private static readonly TOKEN_REGEX;
11
+ static generateDeviceFingerprint(): DeviceFingerprint;
12
+ static validateToken(token: string): boolean;
13
+ static validateDeviceFingerprint(fingerprint: string): boolean;
14
+ static generateRequestSignature(): string;
15
+ static validateResponseSignature(): boolean;
16
+ static secureStorage: {
17
+ set(key: string, value: string): void;
18
+ get(key: string): string | null;
19
+ remove(key: string): void;
20
+ };
21
+ }
@@ -0,0 +1,2 @@
1
+ export { RuntimeSecurity } from './RuntimeSecurity';
2
+ export type { IRuntimeSecurity } from './RuntimeSecurity';
@@ -0,0 +1,18 @@
1
+ import { ApiClient } from './ApiClient';
2
+ import { PerformanceMetrics, PortfolioSnapshot } from '../types/api';
3
+ export interface IAnalyticsService {
4
+ getPerformance(): Promise<PerformanceMetrics>;
5
+ getDailyHistory(): Promise<any[]>;
6
+ getWeeklySnapshots(): Promise<PortfolioSnapshot[]>;
7
+ getPortfolioDeltas(): Promise<any[]>;
8
+ getUserLogs(userId: string): Promise<any[]>;
9
+ }
10
+ export declare class CoreAnalyticsService implements IAnalyticsService {
11
+ private apiClient;
12
+ constructor(apiClient: ApiClient);
13
+ getPerformance(): Promise<PerformanceMetrics>;
14
+ getDailyHistory(): Promise<any[]>;
15
+ getWeeklySnapshots(): Promise<PortfolioSnapshot[]>;
16
+ getPortfolioDeltas(): Promise<any[]>;
17
+ getUserLogs(userId: string): Promise<any[]>;
18
+ }