@finatic/client 0.0.140 → 0.0.142

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.
@@ -2,6 +2,18 @@
2
2
  * Broker filtering utility functions
3
3
  */
4
4
 
5
+ import { setupLogger, buildLoggerExtra, LoggerExtra } from '../lib/logger';
6
+
7
+ const brokerLogger = setupLogger('FinaticClientSDK.BrokerUtils', undefined, {
8
+ codebase: 'FinaticClientSDK',
9
+ });
10
+
11
+ const buildBrokerExtra = (functionName: string, metadata?: Record<string, unknown>): LoggerExtra => ({
12
+ module: 'BrokerUtils',
13
+ function: functionName,
14
+ ...(metadata ? buildLoggerExtra(metadata) : {}),
15
+ });
16
+
5
17
  // Supported broker names and their corresponding IDs (including aliases)
6
18
  const SUPPORTED_BROKERS: Record<string, string> = {
7
19
  'alpaca': 'alpaca',
@@ -52,7 +64,11 @@ export function appendBrokerFilterToURL(baseUrl: string, brokerNames?: string[])
52
64
  const { brokerIds, warnings } = convertBrokerNamesToIds(brokerNames);
53
65
 
54
66
  // Log warnings for unsupported broker names
55
- warnings.forEach(warning => console.warn(`[FinaticConnect] ${warning}`));
67
+ warnings.forEach(warning =>
68
+ brokerLogger.warn('Unsupported broker name provided', buildBrokerExtra('appendBrokerFilterToURL', {
69
+ warning,
70
+ })),
71
+ );
56
72
 
57
73
  // Only add broker filter if we have valid broker IDs
58
74
  if (brokerIds.length > 0) {
@@ -62,7 +78,10 @@ export function appendBrokerFilterToURL(baseUrl: string, brokerNames?: string[])
62
78
 
63
79
  return url.toString();
64
80
  } catch (error) {
65
- console.error('Failed to append broker filter to URL:', error);
81
+ brokerLogger.exception('Failed to append broker filter to URL', error, buildBrokerExtra('appendBrokerFilterToURL', {
82
+ base_url: baseUrl,
83
+ brokers_count: brokerNames?.length ?? 0,
84
+ }));
66
85
  return baseUrl;
67
86
  }
68
87
  }
@@ -1,5 +1,11 @@
1
+ import { setupLogger, buildLoggerExtra } from '../lib/logger';
2
+
1
3
  type EventCallback = (...args: any[]) => void;
2
4
 
5
+ const eventsLogger = setupLogger('FinaticClientSDK.Events', undefined, {
6
+ codebase: 'FinaticClientSDK',
7
+ });
8
+
3
9
  export class EventEmitter {
4
10
  private events: Map<string, Set<EventCallback>> = new Map();
5
11
 
@@ -30,7 +36,13 @@ export class EventEmitter {
30
36
  try {
31
37
  callback(...args);
32
38
  } catch (error) {
33
- console.error(`Error in event handler for ${event}:`, error);
39
+ eventsLogger.exception('Error in event handler', error, {
40
+ module: 'EventEmitter',
41
+ function: 'emit',
42
+ ...buildLoggerExtra({
43
+ event_name: event,
44
+ }),
45
+ });
34
46
  }
35
47
  });
36
48
  }
@@ -1,5 +1,16 @@
1
1
  import { PortalTheme, PortalThemeConfig } from '../types/portal';
2
2
  import { portalThemePresets } from '../themes/portalPresets';
3
+ import { setupLogger, buildLoggerExtra, LoggerExtra } from '../lib/logger';
4
+
5
+ const themeLogger = setupLogger('FinaticClientSDK.ThemeUtils', undefined, {
6
+ codebase: 'FinaticClientSDK',
7
+ });
8
+
9
+ const buildThemeExtra = (functionName: string, metadata?: Record<string, unknown>): LoggerExtra => ({
10
+ module: 'ThemeUtils',
11
+ function: functionName,
12
+ ...(metadata ? buildLoggerExtra(metadata) : {}),
13
+ });
3
14
 
4
15
  /**
5
16
  * Generate a portal URL with theme parameters
@@ -27,7 +38,10 @@ export function generatePortalThemeURL(baseUrl: string, theme?: PortalTheme): st
27
38
 
28
39
  return url.toString();
29
40
  } catch (error) {
30
- console.error('Failed to generate theme URL:', error);
41
+ themeLogger.exception('Failed to generate theme URL', error, buildThemeExtra('generatePortalThemeURL', {
42
+ base_url: baseUrl,
43
+ has_theme: Boolean(theme),
44
+ }));
31
45
  return baseUrl;
32
46
  }
33
47
  }
@@ -58,7 +72,10 @@ export function appendThemeToURL(baseUrl: string, theme?: PortalTheme): string {
58
72
 
59
73
  return url.toString();
60
74
  } catch (error) {
61
- console.error('Failed to append theme to URL:', error);
75
+ themeLogger.exception('Failed to append theme to URL', error, buildThemeExtra('appendThemeToURL', {
76
+ base_url: baseUrl,
77
+ has_theme: Boolean(theme),
78
+ }));
62
79
  return baseUrl;
63
80
  }
64
81
  }
@@ -118,7 +135,7 @@ export function validateCustomTheme(theme: PortalThemeConfig): boolean {
118
135
 
119
136
  return true;
120
137
  } catch (error) {
121
- console.error('Theme validation error:', error);
138
+ themeLogger.exception('Theme validation error', error, buildThemeExtra('validateCustomTheme'));
122
139
  return false;
123
140
  }
124
141
  }
@@ -135,7 +152,9 @@ export function createCustomThemeFromPreset(
135
152
  ): PortalThemeConfig | null {
136
153
  const baseTheme = getThemePreset(preset);
137
154
  if (!baseTheme) {
138
- console.error(`Preset theme '${preset}' not found`);
155
+ themeLogger.warn('Preset theme not found', buildThemeExtra('createCustomThemeFromPreset', {
156
+ preset,
157
+ }));
139
158
  return null;
140
159
  }
141
160