@tumbaland/frontend-core 1.3.3 → 1.5.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.
- package/dist/authService.d.ts +15 -0
- package/dist/authService.js +20 -5
- package/dist/groupService.js +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/monitoring/batch.d.ts +2 -1
- package/dist/monitoring/config.d.ts +20 -0
- package/dist/monitoring/config.js +4 -2
- package/dist/monitoring/console.d.ts +3 -2
- package/dist/monitoring/console.js +2 -2
- package/dist/monitoring/errors.d.ts +3 -2
- package/dist/monitoring/performance.js +7 -4
- package/package.json +4 -1
package/dist/authService.d.ts
CHANGED
|
@@ -33,3 +33,18 @@ export declare function createAuthService(config: AuthServiceConfig): {
|
|
|
33
33
|
isAuthenticated(): Promise<boolean>;
|
|
34
34
|
};
|
|
35
35
|
export type AuthService = ReturnType<typeof createAuthService>;
|
|
36
|
+
/** The auth-related keys every front's resolved config exposes. */
|
|
37
|
+
export interface AppAuthConfig {
|
|
38
|
+
AUTH_SERVICE_URL?: string;
|
|
39
|
+
AUTH_FRONT_URL?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Convenience over `createAuthService` for the frontends, which all read the
|
|
43
|
+
* same two auth URLs from their resolved config. Centralizes that key mapping
|
|
44
|
+
* so each app's `services/authService.ts` is just:
|
|
45
|
+
*
|
|
46
|
+
* export const authService = createAppAuthService(getGlobalConfig);
|
|
47
|
+
*
|
|
48
|
+
* instead of repeating the `AUTH_SERVICE_URL` / `AUTH_FRONT_URL` wiring.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createAppAuthService(getGlobalConfig: () => AppAuthConfig): AuthService;
|
package/dist/authService.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCorrelationId, getSessionId } from './monitoring';
|
|
1
|
+
import { getCorrelationId, getSessionId, logger } from './monitoring';
|
|
2
2
|
const AUTH_CACHE_TTL = 5 * 60 * 1000;
|
|
3
3
|
function authHeaders() {
|
|
4
4
|
return {
|
|
@@ -56,7 +56,7 @@ export function createAuthService(config) {
|
|
|
56
56
|
return result;
|
|
57
57
|
}
|
|
58
58
|
catch (error) {
|
|
59
|
-
|
|
59
|
+
logger.error('Auth check failed', error);
|
|
60
60
|
const result = { authenticated: false, user: null };
|
|
61
61
|
authCache = result;
|
|
62
62
|
authCacheTime = now;
|
|
@@ -86,7 +86,7 @@ export function createAuthService(config) {
|
|
|
86
86
|
return data.success;
|
|
87
87
|
}
|
|
88
88
|
catch (error) {
|
|
89
|
-
|
|
89
|
+
logger.error('Logout failed', error);
|
|
90
90
|
return false;
|
|
91
91
|
}
|
|
92
92
|
},
|
|
@@ -103,14 +103,14 @@ export function createAuthService(config) {
|
|
|
103
103
|
});
|
|
104
104
|
if (!response.ok) {
|
|
105
105
|
const errorText = await response.text();
|
|
106
|
-
|
|
106
|
+
logger.error('Profile fetch error', undefined, { status: response.status, body: errorText });
|
|
107
107
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
108
108
|
}
|
|
109
109
|
const data = await response.json();
|
|
110
110
|
return data.success ? data.user : null;
|
|
111
111
|
}
|
|
112
112
|
catch (error) {
|
|
113
|
-
|
|
113
|
+
logger.error('Get profile failed', error);
|
|
114
114
|
return null;
|
|
115
115
|
}
|
|
116
116
|
},
|
|
@@ -120,3 +120,18 @@ export function createAuthService(config) {
|
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Convenience over `createAuthService` for the frontends, which all read the
|
|
125
|
+
* same two auth URLs from their resolved config. Centralizes that key mapping
|
|
126
|
+
* so each app's `services/authService.ts` is just:
|
|
127
|
+
*
|
|
128
|
+
* export const authService = createAppAuthService(getGlobalConfig);
|
|
129
|
+
*
|
|
130
|
+
* instead of repeating the `AUTH_SERVICE_URL` / `AUTH_FRONT_URL` wiring.
|
|
131
|
+
*/
|
|
132
|
+
export function createAppAuthService(getGlobalConfig) {
|
|
133
|
+
return createAuthService({
|
|
134
|
+
getAuthServiceUrl: () => getGlobalConfig().AUTH_SERVICE_URL,
|
|
135
|
+
getAuthFrontUrl: () => getGlobalConfig().AUTH_FRONT_URL
|
|
136
|
+
});
|
|
137
|
+
}
|
package/dist/groupService.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCorrelationId, getSessionId } from './monitoring';
|
|
1
|
+
import { getCorrelationId, getSessionId, logger } from './monitoring';
|
|
2
2
|
function groupHeaders() {
|
|
3
3
|
return {
|
|
4
4
|
'Content-Type': 'application/json',
|
|
@@ -33,7 +33,7 @@ export function createGroupService(config) {
|
|
|
33
33
|
return result.data;
|
|
34
34
|
}
|
|
35
35
|
catch (error) {
|
|
36
|
-
|
|
36
|
+
logger.error('Error fetching user groups', error);
|
|
37
37
|
throw error;
|
|
38
38
|
}
|
|
39
39
|
},
|
|
@@ -53,7 +53,7 @@ export function createGroupService(config) {
|
|
|
53
53
|
return result.data;
|
|
54
54
|
}
|
|
55
55
|
catch (error) {
|
|
56
|
-
|
|
56
|
+
logger.error('Error fetching user group IDs', error);
|
|
57
57
|
throw error;
|
|
58
58
|
}
|
|
59
59
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { createApiClient, ApiError } from './apiClient';
|
|
2
2
|
export type { ApiClientOptions, ApiRequestOptions } from './apiClient';
|
|
3
|
-
export { createAuthService } from './authService';
|
|
4
|
-
export type { AuthServiceConfig, AuthService } from './authService';
|
|
3
|
+
export { createAuthService, createAppAuthService } from './authService';
|
|
4
|
+
export type { AuthServiceConfig, AuthService, AppAuthConfig } from './authService';
|
|
5
5
|
export { createGroupService } from './groupService';
|
|
6
6
|
export type { GroupServiceConfig, GroupService } from './groupService';
|
|
7
7
|
export type { User, AuthResponse, Group, ApiResponse } from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @tumbaland/frontend-core - Shared frontend auth/group/API-client logic
|
|
2
2
|
export { createApiClient, ApiError } from './apiClient';
|
|
3
|
-
export { createAuthService } from './authService';
|
|
3
|
+
export { createAuthService, createAppAuthService } from './authService';
|
|
4
4
|
export { createGroupService } from './groupService';
|
|
5
5
|
// Monitoring: headless logging, error capture, correlation IDs, and web-vitals
|
|
6
6
|
export { initMonitoring, captureException, captureMessage, setUser, setTag, startTransaction, recordMetric, initWebVitals, flushLogs, initConsoleInterception, generateCorrelationId, getCorrelationId, getSessionId, logger } from './monitoring';
|
|
@@ -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;
|
|
@@ -25,8 +25,10 @@ export const initMonitoring = (environment = 'development', options = {}) => {
|
|
|
25
25
|
component,
|
|
26
26
|
elkUrl
|
|
27
27
|
});
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if (environment === 'development') {
|
|
29
|
+
console.log(`📊 Local monitoring initialized (${environment} mode) for ${service}/${component}`);
|
|
30
|
+
console.log(`📝 Console interception enabled for levels: ${captureConsoleLevels.join(', ')}`);
|
|
31
|
+
}
|
|
30
32
|
// Initialize console interception and error handlers after modules are loaded
|
|
31
33
|
Promise.all([
|
|
32
34
|
import('./console'),
|
|
@@ -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.5.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
|
},
|