@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,50 @@
1
+ /**
2
+ * Shared types for Finatic Connect SDK
3
+ */
4
+ export interface Holding {
5
+ symbol: string;
6
+ quantity: number;
7
+ averagePrice: number;
8
+ currentPrice: number;
9
+ marketValue: number;
10
+ unrealizedPnL: number;
11
+ realizedPnL: number;
12
+ costBasis: number;
13
+ currency: string;
14
+ }
15
+ export interface Order {
16
+ symbol: string;
17
+ quantity: number;
18
+ side: 'buy' | 'sell';
19
+ type_: 'market' | 'limit' | 'stop' | 'stop_limit';
20
+ timeInForce: 'day' | 'gtc' | 'opg' | 'cls' | 'ioc' | 'fok';
21
+ price?: number;
22
+ stopPrice?: number;
23
+ }
24
+ export interface Portfolio {
25
+ id: string;
26
+ name: string;
27
+ type: string;
28
+ status: string;
29
+ cash: number;
30
+ buyingPower: number;
31
+ equity: number;
32
+ longMarketValue: number;
33
+ shortMarketValue: number;
34
+ initialMargin: number;
35
+ maintenanceMargin: number;
36
+ lastEquity: number;
37
+ positions: Holding[];
38
+ performance: PerformanceMetrics;
39
+ }
40
+ export interface PerformanceMetrics {
41
+ totalReturn: number;
42
+ dailyReturn: number;
43
+ weeklyReturn: number;
44
+ monthlyReturn: number;
45
+ yearlyReturn: number;
46
+ maxDrawdown: number;
47
+ sharpeRatio: number;
48
+ beta: number;
49
+ alpha: number;
50
+ }
@@ -0,0 +1,101 @@
1
+ export interface Theme {
2
+ mode: 'light' | 'dark';
3
+ primaryColor: string;
4
+ colors: {
5
+ primary: string;
6
+ secondary: string;
7
+ background: {
8
+ primary: string;
9
+ secondary: string;
10
+ tertiary: string;
11
+ };
12
+ text: {
13
+ primary: string;
14
+ secondary: string;
15
+ disabled: string;
16
+ error: string;
17
+ success: string;
18
+ warning: string;
19
+ };
20
+ border: {
21
+ light: string;
22
+ medium: string;
23
+ dark: string;
24
+ };
25
+ status: {
26
+ active: string;
27
+ inactive: string;
28
+ pending: string;
29
+ error: string;
30
+ success: string;
31
+ };
32
+ };
33
+ typography: {
34
+ fontFamily: string;
35
+ fontSize: {
36
+ xs: string;
37
+ sm: string;
38
+ base: string;
39
+ lg: string;
40
+ xl: string;
41
+ '2xl': string;
42
+ };
43
+ fontWeight: {
44
+ light: number;
45
+ normal: number;
46
+ medium: number;
47
+ semibold: number;
48
+ bold: number;
49
+ };
50
+ lineHeight: {
51
+ none: number;
52
+ tight: number;
53
+ normal: number;
54
+ relaxed: number;
55
+ };
56
+ };
57
+ spacing: {
58
+ xs: string;
59
+ sm: string;
60
+ md: string;
61
+ lg: string;
62
+ xl: string;
63
+ '2xl': string;
64
+ };
65
+ animation: {
66
+ duration: {
67
+ fast: string;
68
+ normal: string;
69
+ slow: string;
70
+ };
71
+ easing: {
72
+ linear: string;
73
+ easeIn: string;
74
+ easeOut: string;
75
+ easeInOut: string;
76
+ };
77
+ };
78
+ components: {
79
+ button: {
80
+ borderRadius: string;
81
+ padding: string;
82
+ fontSize: string;
83
+ fontWeight: number;
84
+ };
85
+ input: {
86
+ borderRadius: string;
87
+ padding: string;
88
+ fontSize: string;
89
+ };
90
+ card: {
91
+ borderRadius: string;
92
+ padding: string;
93
+ shadow: string;
94
+ };
95
+ modal: {
96
+ borderRadius: string;
97
+ padding: string;
98
+ backdrop: string;
99
+ };
100
+ };
101
+ }
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Core types for Finatic Connect SDK
3
+ */
4
+ export interface Balance {
5
+ cash: number;
6
+ buyingPower: number;
7
+ equity: number;
8
+ longMarketValue: number;
9
+ shortMarketValue: number;
10
+ initialMargin: number;
11
+ maintenanceMargin: number;
12
+ lastEquity: number;
13
+ }
14
+ export interface Account {
15
+ id: string;
16
+ name: string;
17
+ type_: string;
18
+ status: string;
19
+ balance: Balance | null;
20
+ }
21
+ export interface Holding {
22
+ symbol: string;
23
+ quantity: number;
24
+ averagePrice: number;
25
+ currentPrice: number;
26
+ marketValue: number;
27
+ unrealizedPnl: number;
28
+ }
29
+ export interface Order {
30
+ symbol: string;
31
+ quantity: number;
32
+ side: 'buy' | 'sell';
33
+ type_: 'market' | 'limit' | 'stop' | 'stop_limit';
34
+ timeInForce: 'day' | 'gtc' | 'opg' | 'cls' | 'ioc' | 'fok';
35
+ price?: number;
36
+ stopPrice?: number;
37
+ }
38
+ export interface Portfolio {
39
+ totalValue: number;
40
+ cash: number;
41
+ equity: number;
42
+ positions: Holding[];
43
+ }
44
+ export interface Performance {
45
+ totalReturn: number;
46
+ dailyReturn: number;
47
+ weeklyReturn: number;
48
+ monthlyReturn: number;
49
+ yearlyReturn: number;
50
+ maxDrawdown: number;
51
+ sharpeRatio: number;
52
+ beta: number;
53
+ alpha: number;
54
+ }
55
+ export interface Event {
56
+ id: string;
57
+ type_: string;
58
+ timestamp: string;
59
+ data: string;
60
+ }
61
+ export interface AnalyticsRequest {
62
+ startDate: string;
63
+ endDate: string;
64
+ metrics: string[];
65
+ groupBy?: string;
66
+ }
67
+ export interface AnalyticsResponse {
68
+ data: Record<string, any>;
69
+ metadata: {
70
+ startDate: string;
71
+ endDate: string;
72
+ metrics: string[];
73
+ groupBy?: string;
74
+ };
75
+ }
76
+ export interface ErrorResponse {
77
+ code: string;
78
+ message: string;
79
+ details?: Record<string, any>;
80
+ }
81
+ export interface PaginationParams {
82
+ page?: number;
83
+ limit?: number;
84
+ sortBy?: string;
85
+ sortOrder?: 'asc' | 'desc';
86
+ }
87
+ export interface PaginatedResponse<T> {
88
+ data: T[];
89
+ metadata: {
90
+ total: number;
91
+ page: number;
92
+ limit: number;
93
+ totalPages: number;
94
+ };
95
+ }
96
+ export interface ApiPaginationInfo {
97
+ has_more: boolean;
98
+ next_offset: number;
99
+ current_offset: number;
100
+ limit: number;
101
+ }
102
+ export interface ApiResponse<T> {
103
+ success: boolean;
104
+ response_data: T;
105
+ message: string;
106
+ status_code: number;
107
+ pagination?: ApiPaginationInfo;
108
+ }
109
+ export interface PaginationMetadata {
110
+ hasMore: boolean;
111
+ nextOffset: number;
112
+ currentOffset: number;
113
+ limit: number;
114
+ currentPage: number;
115
+ hasNext: boolean;
116
+ hasPrevious: boolean;
117
+ }
118
+ export declare class PaginatedResult<T> {
119
+ readonly data: T;
120
+ readonly metadata: PaginationMetadata;
121
+ private navigationCallback?;
122
+ constructor(data: T, paginationInfo: ApiPaginationInfo, navigationCallback?: (offset: number, limit: number) => Promise<PaginatedResult<T>>);
123
+ get hasNext(): boolean;
124
+ get hasPrevious(): boolean;
125
+ get currentPage(): number;
126
+ /**
127
+ * Navigate to the next page
128
+ * @returns Promise<PaginatedResult<T> | null> - Next page result or null if no next page
129
+ */
130
+ nextPage(): Promise<PaginatedResult<T> | null>;
131
+ /**
132
+ * Navigate to the previous page
133
+ * @returns Promise<PaginatedResult<T> | null> - Previous page result or null if no previous page
134
+ */
135
+ previousPage(): Promise<PaginatedResult<T> | null>;
136
+ /**
137
+ * Navigate to a specific page
138
+ * @param pageNumber - The page number to navigate to (1-based)
139
+ * @returns Promise<PaginatedResult<T> | null> - Page result or null if page doesn't exist
140
+ */
141
+ goToPage(pageNumber: number): Promise<PaginatedResult<T> | null>;
142
+ /**
143
+ * Get the first page
144
+ * @returns Promise<PaginatedResult<T> | null> - First page result or null if error
145
+ */
146
+ firstPage(): Promise<PaginatedResult<T> | null>;
147
+ /**
148
+ * Get the last page (this is a best effort - we don't know the total count)
149
+ * @returns Promise<PaginatedResult<T> | null> - Last page result or null if error
150
+ */
151
+ lastPage(): Promise<PaginatedResult<T> | null>;
152
+ /**
153
+ * Get pagination info as a string
154
+ * @returns string - Human readable pagination info
155
+ */
156
+ getPaginationInfo(): string;
157
+ }
@@ -0,0 +1,42 @@
1
+ export declare class BaseError extends Error {
2
+ readonly code: string;
3
+ constructor(message: string, code?: string);
4
+ }
5
+ export declare class ApiError extends BaseError {
6
+ readonly status: number;
7
+ readonly details?: Record<string, any> | undefined;
8
+ constructor(status: number, message: string, details?: Record<string, any> | undefined);
9
+ }
10
+ export declare class SessionError extends ApiError {
11
+ constructor(message: string, details?: Record<string, any>);
12
+ }
13
+ export declare class AuthenticationError extends ApiError {
14
+ constructor(message: string, details?: Record<string, any>);
15
+ }
16
+ export declare class AuthorizationError extends ApiError {
17
+ constructor(message: string, details?: Record<string, any>);
18
+ }
19
+ export declare class RateLimitError extends ApiError {
20
+ constructor(message: string, details?: Record<string, any>);
21
+ }
22
+ export declare class TokenError extends BaseError {
23
+ constructor(message: string);
24
+ }
25
+ export declare class ValidationError extends BaseError {
26
+ constructor(message: string);
27
+ }
28
+ export declare class NetworkError extends BaseError {
29
+ constructor(message: string);
30
+ }
31
+ export declare class SecurityError extends BaseError {
32
+ constructor(message: string);
33
+ }
34
+ export declare class CompanyAccessError extends ApiError {
35
+ constructor(message: string, details?: Record<string, any>);
36
+ }
37
+ export declare class OrderError extends ApiError {
38
+ constructor(message: string, details?: Record<string, any>);
39
+ }
40
+ export declare class OrderValidationError extends ApiError {
41
+ constructor(message: string, details?: Record<string, any>);
42
+ }
@@ -0,0 +1,12 @@
1
+ type EventCallback = (...args: any[]) => void;
2
+ export declare class EventEmitter {
3
+ private events;
4
+ on(event: string, callback: EventCallback): void;
5
+ off(event: string, callback: EventCallback): void;
6
+ once(event: string, callback: EventCallback): void;
7
+ emit(event: string, ...args: any[]): void;
8
+ removeAllListeners(event?: string): void;
9
+ listenerCount(event: string): number;
10
+ listeners(event: string): EventCallback[];
11
+ }
12
+ export {};
@@ -0,0 +1,34 @@
1
+ import { PortalTheme, PortalThemeConfig } from '../types/portal';
2
+ /**
3
+ * Generate a portal URL with theme parameters
4
+ * @param baseUrl The base portal URL
5
+ * @param theme The theme configuration
6
+ * @returns The portal URL with theme parameters
7
+ */
8
+ export declare function generatePortalThemeURL(baseUrl: string, theme?: PortalTheme): string;
9
+ /**
10
+ * Generate a portal URL with theme parameters, appending to existing query params
11
+ * @param baseUrl The base portal URL (may already have query parameters)
12
+ * @param theme The theme configuration
13
+ * @returns The portal URL with theme parameters appended
14
+ */
15
+ export declare function appendThemeToURL(baseUrl: string, theme?: PortalTheme): string;
16
+ /**
17
+ * Get a theme configuration by preset name
18
+ * @param preset The preset theme name
19
+ * @returns The theme configuration or undefined if not found
20
+ */
21
+ export declare function getThemePreset(preset: string): PortalThemeConfig | undefined;
22
+ /**
23
+ * Validate a custom theme configuration
24
+ * @param theme The theme configuration to validate
25
+ * @returns True if valid, false otherwise
26
+ */
27
+ export declare function validateCustomTheme(theme: PortalThemeConfig): boolean;
28
+ /**
29
+ * Create a custom theme from a preset with modifications
30
+ * @param preset The base preset theme
31
+ * @param modifications Partial theme modifications
32
+ * @returns The modified theme configuration
33
+ */
34
+ export declare function createCustomThemeFromPreset(preset: string, modifications: Partial<PortalThemeConfig>): PortalThemeConfig | null;
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@finatic/client",
3
+ "version": "0.0.131",
4
+ "description": "Finatic Client SDK for browser integration",
5
+ "type": "module",
6
+ "private": false,
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "main": "./dist/index.js",
11
+ "module": "./dist/index.mjs",
12
+ "types": "./dist/types/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.js",
17
+ "types": "./dist/types/index.d.ts"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "scripts": {
24
+ "build": "rollup -c",
25
+ "clean": "rimraf dist",
26
+ "lint": "eslint src --ext .ts,.tsx",
27
+ "format": "prettier --write src/**/*.{ts,tsx}"
28
+ },
29
+ "dependencies": {
30
+ "crypto-js": "^4.2.0",
31
+ "uuid": "^9.0.1"
32
+ },
33
+ "devDependencies": {
34
+ "@rollup/plugin-commonjs": "^25.0.7",
35
+ "@rollup/plugin-node-resolve": "^15.2.3",
36
+ "@rollup/plugin-typescript": "^11.1.6",
37
+ "@types/crypto-js": "^4.2.1",
38
+ "@types/uuid": "^9.0.7",
39
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
40
+ "@typescript-eslint/parser": "^6.0.0",
41
+ "eslint": "^8.0.0",
42
+ "eslint-config-prettier": "^9.0.0",
43
+ "eslint-plugin-react": "^7.33.0",
44
+ "eslint-plugin-react-hooks": "^4.6.0",
45
+ "prettier": "^3.0.0",
46
+ "rimraf": "^5.0.5",
47
+ "rollup": "^4.9.1",
48
+ "rollup-plugin-dts": "^6.1.0",
49
+ "tslib": "^2.8.1",
50
+ "typescript": "^5.3.3"
51
+ },
52
+ "peerDependencies": {
53
+ "react": ">=16.8.0",
54
+ "react-dom": ">=16.8.0"
55
+ }
56
+ }