@tumbaland/frontend-core 1.3.3 → 1.4.0
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.
|
@@ -5,6 +5,26 @@ export interface MonitoringConfig {
|
|
|
5
5
|
elkUrl?: string;
|
|
6
6
|
captureConsoleLevels?: ('debug' | 'info' | 'warn' | 'error')[];
|
|
7
7
|
}
|
|
8
|
+
export type MonitoringLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
9
|
+
export type MonitoringContext = Record<string, unknown>;
|
|
10
|
+
export interface MonitoringLog {
|
|
11
|
+
timestamp?: string;
|
|
12
|
+
level?: MonitoringLevel | string;
|
|
13
|
+
service?: string;
|
|
14
|
+
component?: string;
|
|
15
|
+
message?: string;
|
|
16
|
+
url?: string;
|
|
17
|
+
userAgent?: string;
|
|
18
|
+
context?: MonitoringContext;
|
|
19
|
+
correlationId?: string;
|
|
20
|
+
sessionId?: string;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
declare global {
|
|
24
|
+
interface Window {
|
|
25
|
+
_monitoringInterceptingConsole?: boolean;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
8
28
|
export declare const isInterceptingConsole: () => boolean;
|
|
9
29
|
export declare const getMonitoringConfig: () => MonitoringConfig;
|
|
10
30
|
export declare const updateMonitoringConfig: (config: Partial<MonitoringConfig>) => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { MonitoringContext, MonitoringLevel } from './config';
|
|
2
|
+
type CaptureMessageFn = (message: string, level: MonitoringLevel, context?: MonitoringContext) => void;
|
|
3
|
+
export declare const initConsoleInterception: (captureConsoleLevels?: MonitoringLevel[], captureMessageFn?: CaptureMessageFn) => void;
|
|
3
4
|
export {};
|
|
@@ -10,7 +10,7 @@ export const initConsoleInterception = (captureConsoleLevels = ['error', 'warn']
|
|
|
10
10
|
if (!captureConsoleLevels.includes(level))
|
|
11
11
|
return;
|
|
12
12
|
const originalMethod = console[methodName];
|
|
13
|
-
console[methodName] = (...args) => {
|
|
13
|
+
console[methodName] = ((...args) => {
|
|
14
14
|
// Call original console method
|
|
15
15
|
originalMethod.apply(console, args);
|
|
16
16
|
// Prevent recursive interception by checking the global flag
|
|
@@ -29,7 +29,7 @@ export const initConsoleInterception = (captureConsoleLevels = ['error', 'warn']
|
|
|
29
29
|
finally {
|
|
30
30
|
window._monitoringInterceptingConsole = false;
|
|
31
31
|
}
|
|
32
|
-
};
|
|
32
|
+
});
|
|
33
33
|
};
|
|
34
34
|
// Intercept console methods based on configuration
|
|
35
35
|
interceptConsole('error', 'error');
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { MonitoringContext, MonitoringLevel } from './config';
|
|
2
|
+
export declare const captureException: (error: Error, context?: MonitoringContext, options?: {
|
|
2
3
|
isDevelopment?: boolean;
|
|
3
4
|
service?: string;
|
|
4
5
|
component?: string;
|
|
5
6
|
elkUrl?: string;
|
|
6
7
|
}) => Promise<void>;
|
|
7
|
-
export declare const captureMessage: (message: string, level?:
|
|
8
|
+
export declare const captureMessage: (message: string, level?: MonitoringLevel, context?: MonitoringContext, options?: {
|
|
8
9
|
isDevelopment?: boolean;
|
|
9
10
|
service?: string;
|
|
10
11
|
component?: string;
|
|
@@ -98,10 +98,13 @@ export const initWebVitals = async (options = {}) => {
|
|
|
98
98
|
const webVitalsModule = await import('web-vitals');
|
|
99
99
|
webVitals = webVitalsModule;
|
|
100
100
|
// Use the new web-vitals API (v5+)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
webVitals.
|
|
101
|
+
const reportMetric = (name, metric, unit) => {
|
|
102
|
+
recordMetric(name, metric, unit, { isDevelopment: config.isDevelopment });
|
|
103
|
+
};
|
|
104
|
+
webVitals.onCLS((metric) => reportMetric('CLS', metric, 'unitless'));
|
|
105
|
+
webVitals.onFCP((metric) => reportMetric('FCP', metric, 'ms'));
|
|
106
|
+
webVitals.onLCP((metric) => reportMetric('LCP', metric, 'ms'));
|
|
107
|
+
webVitals.onTTFB((metric) => reportMetric('TTFB', metric, 'ms'));
|
|
105
108
|
// Note: FID is deprecated in web-vitals v5
|
|
106
109
|
}
|
|
107
110
|
catch (e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tumbaland/frontend-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Shared frontend auth/group/API-client logic for Tumbaland frontends",
|
|
5
5
|
"author": "Tumbaland",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"lint": "eslint .",
|
|
19
19
|
"typecheck": "tsc --noEmit"
|
|
20
20
|
},
|
|
21
|
+
"standard-version": {
|
|
22
|
+
"tagPrefix": "frontend-core-v"
|
|
23
|
+
},
|
|
21
24
|
"dependencies": {
|
|
22
25
|
"web-vitals": "^5.3.0"
|
|
23
26
|
},
|