@finatic/client 0.0.142 → 0.9.1

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 (64) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +39 -0
  3. package/README.md +54 -425
  4. package/dist/index.d.ts +7329 -1579
  5. package/dist/index.js +8110 -6114
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +8047 -6085
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +77 -33
  10. package/dist/types/core/client/ApiClient.d.ts +0 -270
  11. package/dist/types/core/client/FinaticConnect.d.ts +0 -332
  12. package/dist/types/core/portal/PortalUI.d.ts +0 -37
  13. package/dist/types/index.d.ts +0 -12
  14. package/dist/types/lib/logger/index.d.ts +0 -2
  15. package/dist/types/lib/logger/logger.d.ts +0 -4
  16. package/dist/types/lib/logger/logger.types.d.ts +0 -28
  17. package/dist/types/mocks/MockApiClient.d.ts +0 -171
  18. package/dist/types/mocks/MockDataProvider.d.ts +0 -139
  19. package/dist/types/mocks/MockFactory.d.ts +0 -53
  20. package/dist/types/mocks/utils.d.ts +0 -24
  21. package/dist/types/themes/portalPresets.d.ts +0 -9
  22. package/dist/types/types/api/auth.d.ts +0 -93
  23. package/dist/types/types/api/broker.d.ts +0 -421
  24. package/dist/types/types/api/core.d.ts +0 -46
  25. package/dist/types/types/api/errors.d.ts +0 -31
  26. package/dist/types/types/api/orders.d.ts +0 -39
  27. package/dist/types/types/api/portfolio.d.ts +0 -55
  28. package/dist/types/types/common/pagination.d.ts +0 -33
  29. package/dist/types/types/connect.d.ts +0 -58
  30. package/dist/types/types/index.d.ts +0 -13
  31. package/dist/types/types/portal.d.ts +0 -204
  32. package/dist/types/types/ui/theme.d.ts +0 -104
  33. package/dist/types/utils/brokerUtils.d.ts +0 -30
  34. package/dist/types/utils/errors.d.ts +0 -45
  35. package/dist/types/utils/events.d.ts +0 -12
  36. package/dist/types/utils/themeUtils.d.ts +0 -34
  37. package/src/core/client/ApiClient.ts +0 -2004
  38. package/src/core/client/FinaticConnect.ts +0 -1606
  39. package/src/core/portal/PortalUI.ts +0 -335
  40. package/src/index.d.ts +0 -23
  41. package/src/index.ts +0 -100
  42. package/src/lib/logger/index.ts +0 -3
  43. package/src/lib/logger/logger.ts +0 -332
  44. package/src/lib/logger/logger.types.ts +0 -34
  45. package/src/mocks/MockApiClient.ts +0 -1058
  46. package/src/mocks/MockDataProvider.ts +0 -986
  47. package/src/mocks/MockFactory.ts +0 -97
  48. package/src/mocks/utils.ts +0 -133
  49. package/src/themes/portalPresets.ts +0 -1307
  50. package/src/types/api/auth.ts +0 -112
  51. package/src/types/api/broker.ts +0 -461
  52. package/src/types/api/core.ts +0 -53
  53. package/src/types/api/errors.ts +0 -35
  54. package/src/types/api/orders.ts +0 -45
  55. package/src/types/api/portfolio.ts +0 -59
  56. package/src/types/common/pagination.ts +0 -164
  57. package/src/types/connect.ts +0 -56
  58. package/src/types/index.ts +0 -25
  59. package/src/types/portal.ts +0 -214
  60. package/src/types/ui/theme.ts +0 -105
  61. package/src/utils/brokerUtils.ts +0 -104
  62. package/src/utils/errors.ts +0 -104
  63. package/src/utils/events.ts +0 -66
  64. package/src/utils/themeUtils.ts +0 -165
@@ -1,59 +0,0 @@
1
- /**
2
- * Portfolio-related types
3
- */
4
-
5
- export interface PortfolioSnapshot {
6
- timestamp: string;
7
- totalValue: number;
8
- cash: number;
9
- equity: number;
10
- positions: {
11
- symbol: string;
12
- quantity: number;
13
- averagePrice: number;
14
- currentPrice: number;
15
- marketValue: number;
16
- unrealizedPnL: number;
17
- }[];
18
- }
19
-
20
- export interface PerformanceMetrics {
21
- totalReturn: number;
22
- dailyReturn: number;
23
- weeklyReturn: number;
24
- monthlyReturn: number;
25
- yearlyReturn: number;
26
- maxDrawdown: number;
27
- sharpeRatio: number;
28
- beta: number;
29
- alpha: number;
30
- }
31
-
32
- export interface Holding {
33
- symbol: string;
34
- quantity: number;
35
- averagePrice: number;
36
- currentPrice: number;
37
- marketValue: number;
38
- unrealizedPnL: number;
39
- realizedPnL: number;
40
- costBasis: number;
41
- currency: string;
42
- }
43
-
44
- export interface Portfolio {
45
- id: string;
46
- name: string;
47
- type: string;
48
- status: string;
49
- cash: number;
50
- buyingPower: number;
51
- equity: number;
52
- longMarketValue: number;
53
- shortMarketValue: number;
54
- initialMargin: number;
55
- maintenanceMargin: number;
56
- lastEquity: number;
57
- positions: Holding[];
58
- performance: PerformanceMetrics;
59
- }
@@ -1,164 +0,0 @@
1
- /**
2
- * Pagination-related types and classes
3
- */
4
-
5
- import { setupLogger, buildLoggerExtra, LoggerExtra } from '../../lib/logger';
6
-
7
- const paginationLogger = setupLogger('FinaticClientSDK.Pagination', undefined, {
8
- codebase: 'FinaticClientSDK',
9
- });
10
-
11
- const buildPaginationExtra = (functionName: string, metadata?: Record<string, unknown>): LoggerExtra => ({
12
- module: 'PaginatedResult',
13
- function: functionName,
14
- ...(metadata ? buildLoggerExtra(metadata) : {}),
15
- });
16
-
17
- export interface ApiPaginationInfo {
18
- has_more: boolean;
19
- next_offset: number;
20
- current_offset: number;
21
- limit: number;
22
- }
23
-
24
- export interface PaginationMetadata {
25
- hasMore: boolean;
26
- nextOffset: number;
27
- currentOffset: number;
28
- limit: number;
29
- currentPage: number;
30
- hasNext: boolean;
31
- hasPrevious: boolean;
32
- }
33
-
34
- export class PaginatedResult<T> {
35
- public readonly data: T;
36
- public readonly metadata: PaginationMetadata;
37
- private navigationCallback?: (offset: number, limit: number) => Promise<PaginatedResult<T>>;
38
-
39
- constructor(
40
- data: T,
41
- paginationInfo: ApiPaginationInfo,
42
- navigationCallback?: (offset: number, limit: number) => Promise<PaginatedResult<T>>
43
- ) {
44
- this.data = data;
45
- this.navigationCallback = navigationCallback;
46
- this.metadata = {
47
- hasMore: paginationInfo.has_more,
48
- nextOffset: paginationInfo.next_offset,
49
- currentOffset: paginationInfo.current_offset,
50
- limit: paginationInfo.limit,
51
- currentPage: Math.floor(paginationInfo.current_offset / paginationInfo.limit) + 1,
52
- hasNext: paginationInfo.has_more,
53
- hasPrevious: paginationInfo.current_offset > 0,
54
- };
55
- }
56
-
57
- get hasNext(): boolean {
58
- return this.metadata.hasNext;
59
- }
60
-
61
- get hasPrevious(): boolean {
62
- return this.metadata.hasPrevious;
63
- }
64
-
65
- get currentPage(): number {
66
- return this.metadata.currentPage;
67
- }
68
-
69
- async nextPage(): Promise<PaginatedResult<T> | null> {
70
- if (!this.hasNext || !this.navigationCallback) {
71
- return null;
72
- }
73
-
74
- try {
75
- return await this.navigationCallback(this.metadata.nextOffset, this.metadata.limit);
76
- } catch (error) {
77
- paginationLogger.exception('Error fetching next page', error, buildPaginationExtra('nextPage', {
78
- next_offset: this.metadata.nextOffset,
79
- limit: this.metadata.limit,
80
- }));
81
- return null;
82
- }
83
- }
84
-
85
- async previousPage(): Promise<PaginatedResult<T> | null> {
86
- if (!this.hasPrevious || !this.navigationCallback) {
87
- return null;
88
- }
89
-
90
- const previousOffset = Math.max(0, this.metadata.currentOffset - this.metadata.limit);
91
- try {
92
- return await this.navigationCallback(previousOffset, this.metadata.limit);
93
- } catch (error) {
94
- paginationLogger.exception('Error fetching previous page', error, buildPaginationExtra('previousPage', {
95
- previous_offset: previousOffset,
96
- limit: this.metadata.limit,
97
- }));
98
- return null;
99
- }
100
- }
101
-
102
- async goToPage(pageNumber: number): Promise<PaginatedResult<T> | null> {
103
- if (!this.navigationCallback || pageNumber < 1) {
104
- return null;
105
- }
106
-
107
- const offset = (pageNumber - 1) * this.metadata.limit;
108
- try {
109
- return await this.navigationCallback(offset, this.metadata.limit);
110
- } catch (error) {
111
- paginationLogger.exception('Error fetching page', error, buildPaginationExtra('goToPage', {
112
- page_number: pageNumber,
113
- offset,
114
- limit: this.metadata.limit,
115
- }));
116
- return null;
117
- }
118
- }
119
-
120
- async firstPage(): Promise<PaginatedResult<T> | null> {
121
- if (!this.navigationCallback) {
122
- return null;
123
- }
124
-
125
- try {
126
- return await this.navigationCallback(0, this.metadata.limit);
127
- } catch (error) {
128
- paginationLogger.exception('Error fetching first page', error, buildPaginationExtra('firstPage', {
129
- limit: this.metadata.limit,
130
- }));
131
- return null;
132
- }
133
- }
134
-
135
- async lastPage(): Promise<PaginatedResult<T> | null> {
136
- if (!this.navigationCallback) {
137
- return null;
138
- }
139
-
140
- const findLast = async (page: PaginatedResult<T>): Promise<PaginatedResult<T>> => {
141
- if (!page.hasNext) {
142
- return page;
143
- }
144
- const nextPage = await page.nextPage();
145
- if (!nextPage) {
146
- return page;
147
- }
148
- return findLast(nextPage);
149
- };
150
-
151
- try {
152
- return await findLast(this);
153
- } catch (error) {
154
- paginationLogger.exception('Error fetching last page', error, buildPaginationExtra('lastPage', {
155
- limit: this.metadata.limit,
156
- }));
157
- return null;
158
- }
159
- }
160
-
161
- getPaginationInfo(): string {
162
- return `Page ${this.currentPage} (${this.metadata.currentOffset + 1}-${this.metadata.currentOffset + this.metadata.limit})`;
163
- }
164
- }
@@ -1,56 +0,0 @@
1
- import { Theme } from './ui/theme';
2
- import { UserToken } from './api/auth';
3
- import { PortalTheme } from './portal';
4
-
5
- export interface FinaticConnectOptions {
6
- /** The portal token from your backend */
7
- token: string;
8
- /** Optional base URL for API requests */
9
- baseUrl?: string;
10
- /** Optional origin for the portal */
11
- origin?: string;
12
- /** Callback when user successfully connects */
13
- onSuccess?: (tokens: UserToken) => void;
14
- /** Callback when an error occurs */
15
- onError?: (error: Error) => void;
16
- /** Callback when the portal is closed */
17
- onClose?: () => void;
18
- /** Optional theme configuration */
19
- theme?: Theme;
20
- /** Callback when tokens are received */
21
- onTokensReceived?: (tokens: { access_token?: string; refresh_token?: string }) => void;
22
- }
23
-
24
- export interface FinaticUserToken {
25
- accessToken: string;
26
- refreshToken: string;
27
- userId: string;
28
- companyId: string;
29
- expiresAt: Date;
30
- }
31
-
32
- export interface PortalMessage {
33
- type: 'success' | 'error' | 'close' | 'resize';
34
- userId?: string;
35
- error?: string;
36
- height?: number;
37
- access_token?: string;
38
- refresh_token?: string;
39
- }
40
-
41
- export interface PortalOptions {
42
- /** Callback when user successfully connects */
43
- onSuccess?: (userId: string, tokens?: { access_token?: string; refresh_token?: string }) => void;
44
- /** Callback when an error occurs */
45
- onError?: (error: Error) => void;
46
- /** Callback when the portal is closed */
47
- onClose?: () => void;
48
- /** Callback when portal events occur */
49
- onEvent?: (type: string, data: any) => void;
50
- /** Optional theme configuration for the portal */
51
- theme?: PortalTheme;
52
- /** Optional list of broker names to filter by (only these brokers will be shown) */
53
- brokers?: string[];
54
- /** Optional email address to prefill in the portal */
55
- email?: string;
56
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * Main types barrel export
3
- */
4
-
5
- // Core API types
6
- export * from './api/core';
7
- export * from './api/auth';
8
- export * from './api/broker';
9
- export * from './api/orders';
10
- export * from './api/portfolio';
11
-
12
- // UI types
13
- export * from './ui/theme';
14
-
15
- // Common types
16
- export * from './common/pagination';
17
-
18
- // Connect types
19
- export * from './connect';
20
-
21
- // Re-export DeviceInfo for backward compatibility
22
- export type { DeviceInfo } from './api/auth';
23
-
24
- // Explicit re-export of SessionResponse to ensure it's available
25
- export type { SessionResponse } from './api/auth';
@@ -1,214 +0,0 @@
1
- import { Theme } from './ui/theme';
2
-
3
- export interface PortalConfig {
4
- width?: string;
5
- height?: string;
6
- position?: 'center' | 'top' | 'bottom';
7
- zIndex?: number;
8
- }
9
-
10
- export interface PortalThemeConfig {
11
- mode?: 'dark' | 'light' | 'auto';
12
- colors?: {
13
- background?: {
14
- primary?: string; // Main background color
15
- secondary?: string; // Secondary background color
16
- tertiary?: string; // Tertiary background color
17
- accent?: string; // Accent background color
18
- glass?: string; // Glassmorphism background
19
- };
20
- status?: {
21
- connected?: string; // Connected status color
22
- disconnected?: string; // Disconnected status color
23
- warning?: string; // Warning status color
24
- pending?: string; // Pending status color
25
- error?: string; // Error status color
26
- success?: string; // Success status color
27
- };
28
- text?: {
29
- primary?: string; // Primary text color
30
- secondary?: string; // Secondary text color
31
- muted?: string; // Muted text color
32
- inverse?: string; // Inverse text color
33
- };
34
- border?: {
35
- primary?: string; // Primary border color
36
- secondary?: string; // Secondary border color
37
- hover?: string; // Hover border color
38
- focus?: string; // Focus border color
39
- accent?: string; // Accent border color
40
- };
41
- input?: {
42
- background?: string; // Input background color
43
- border?: string; // Input border color
44
- borderFocus?: string; // Input focus border color
45
- text?: string; // Input text color
46
- placeholder?: string; // Input placeholder color
47
- };
48
- button?: {
49
- primary?: {
50
- background?: string; // Primary button background
51
- text?: string; // Primary button text
52
- hover?: string; // Primary button hover
53
- active?: string; // Primary button active
54
- };
55
- secondary?: {
56
- background?: string; // Secondary button background
57
- text?: string; // Secondary button text
58
- border?: string; // Secondary button border
59
- hover?: string; // Secondary button hover
60
- active?: string; // Secondary button active
61
- };
62
- };
63
- };
64
- typography?: {
65
- fontFamily?: {
66
- primary?: string;
67
- secondary?: string;
68
- };
69
- fontSize?: {
70
- xs?: string;
71
- sm?: string;
72
- base?: string;
73
- lg?: string;
74
- xl?: string;
75
- '2xl'?: string;
76
- '3xl'?: string;
77
- '4xl'?: string;
78
- };
79
- fontWeight?: {
80
- normal?: number;
81
- medium?: number;
82
- semibold?: number;
83
- bold?: number;
84
- extrabold?: number;
85
- };
86
- lineHeight?: {
87
- tight?: string;
88
- normal?: string;
89
- relaxed?: string;
90
- };
91
- };
92
- spacing?: {
93
- xs?: string;
94
- sm?: string;
95
- md?: string;
96
- lg?: string;
97
- xl?: string;
98
- '2xl'?: string;
99
- '3xl'?: string;
100
- };
101
- layout?: {
102
- containerMaxWidth?: string;
103
- gridGap?: string;
104
- cardPadding?: string;
105
- borderRadius?: {
106
- sm?: string;
107
- md?: string;
108
- lg?: string;
109
- xl?: string;
110
- '2xl'?: string;
111
- full?: string;
112
- };
113
- };
114
- components?: {
115
- brokerCard?: {
116
- width?: string;
117
- height?: string;
118
- logoSize?: string;
119
- padding?: string;
120
- };
121
- statusIndicator?: {
122
- size?: string;
123
- glowIntensity?: number;
124
- };
125
- modal?: {
126
- background?: string;
127
- backdrop?: string;
128
- };
129
- brokerCardModern?: {
130
- width?: string;
131
- height?: string;
132
- padding?: string;
133
- logoSize?: string;
134
- statusSize?: string;
135
- };
136
- connectButton?: {
137
- width?: string;
138
- height?: string;
139
- };
140
- themeSwitcher?: {
141
- indicatorSize?: string;
142
- };
143
- };
144
- effects?: {
145
- glassmorphism?: {
146
- enabled?: boolean;
147
- blur?: string;
148
- opacity?: number;
149
- border?: string;
150
- };
151
- animations?: {
152
- enabled?: boolean;
153
- duration?: {
154
- fast?: string;
155
- normal?: string;
156
- slow?: string;
157
- };
158
- easing?: {
159
- default?: string;
160
- smooth?: string;
161
- bounce?: string;
162
- };
163
- };
164
- shadows?: {
165
- sm?: string;
166
- md?: string;
167
- lg?: string;
168
- xl?: string;
169
- card?: string;
170
- cardHover?: string;
171
- glow?: string;
172
- focus?: string;
173
- };
174
- };
175
- branding?: {
176
- logo?: string;
177
- companyName?: string;
178
- favicon?: string;
179
- primaryColor?: string;
180
- };
181
-
182
- // Glow effect customization
183
- glow?: {
184
- primary?: string; // Primary glow color
185
- secondary?: string; // Secondary glow color
186
- card?: string; // Card glow effect
187
- cardHover?: string; // Card hover glow
188
- button?: string; // Button glow effect
189
- focus?: string; // Focus ring glow
190
- scrollbar?: string; // Scrollbar glow
191
- };
192
-
193
- // Gradient customization
194
- gradients?: {
195
- start?: string; // Gradient start color
196
- end?: string; // Gradient end color
197
- hoverStart?: string; // Hover gradient start
198
- hoverEnd?: string; // Hover gradient end
199
- };
200
- }
201
-
202
- export type PortalThemePreset = 'dark' | 'light' | 'corporateBlue' | 'purple' | 'green' | 'orange';
203
-
204
- export interface PortalTheme {
205
- preset?: PortalThemePreset;
206
- custom?: PortalThemeConfig;
207
- }
208
-
209
- export interface PortalProps {
210
- config: PortalConfig;
211
- onClose?: () => void;
212
- onReady?: () => void;
213
- onError?: (error: Error) => void;
214
- }
@@ -1,105 +0,0 @@
1
- /**
2
- * Theme-related types
3
- */
4
-
5
- export interface Theme {
6
- mode: 'light' | 'dark';
7
- primaryColor: string;
8
- colors: {
9
- primary: string;
10
- secondary: string;
11
- background: {
12
- primary: string;
13
- secondary: string;
14
- tertiary: string;
15
- };
16
- text: {
17
- primary: string;
18
- secondary: string;
19
- disabled: string;
20
- error: string;
21
- success: string;
22
- warning: string;
23
- };
24
- border: {
25
- light: string;
26
- medium: string;
27
- dark: string;
28
- };
29
- status: {
30
- active: string;
31
- inactive: string;
32
- pending: string;
33
- error: string;
34
- success: string;
35
- };
36
- };
37
- typography: {
38
- fontFamily: string;
39
- fontSize: {
40
- xs: string;
41
- sm: string;
42
- base: string;
43
- lg: string;
44
- xl: string;
45
- '2xl': string;
46
- };
47
- fontWeight: {
48
- light: number;
49
- normal: number;
50
- medium: number;
51
- semibold: number;
52
- bold: number;
53
- };
54
- lineHeight: {
55
- none: number;
56
- tight: number;
57
- normal: number;
58
- relaxed: number;
59
- };
60
- };
61
- spacing: {
62
- xs: string;
63
- sm: string;
64
- md: string;
65
- lg: string;
66
- xl: string;
67
- '2xl': string;
68
- };
69
- animation: {
70
- duration: {
71
- fast: string;
72
- normal: string;
73
- slow: string;
74
- };
75
- easing: {
76
- linear: string;
77
- easeIn: string;
78
- easeOut: string;
79
- easeInOut: string;
80
- };
81
- };
82
- components: {
83
- button: {
84
- borderRadius: string;
85
- padding: string;
86
- fontSize: string;
87
- fontWeight: number;
88
- };
89
- input: {
90
- borderRadius: string;
91
- padding: string;
92
- fontSize: string;
93
- };
94
- card: {
95
- borderRadius: string;
96
- padding: string;
97
- shadow: string;
98
- };
99
- modal: {
100
- borderRadius: string;
101
- padding: string;
102
- backdrop: string;
103
- };
104
- };
105
- }