@tumbaland/frontend-core 1.4.0 → 1.6.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.
@@ -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;
@@ -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
- console.error('Auth check failed:', error);
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
- console.error('Logout failed:', error);
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
- console.error('Profile fetch error:', response.status, errorText);
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
- console.error('Get profile failed:', error);
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
+ }
@@ -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
- console.error('Error fetching user groups:', error);
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
- console.error('Error fetching user group IDs:', error);
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';
@@ -25,8 +25,10 @@ export const initMonitoring = (environment = 'development', options = {}) => {
25
25
  component,
26
26
  elkUrl
27
27
  });
28
- console.log(`📊 Local monitoring initialized (${environment} mode) for ${service}/${component}`);
29
- console.log(`📝 Console interception enabled for levels: ${captureConsoleLevels.join(', ')}`);
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'),
package/dist/types.d.ts CHANGED
@@ -7,6 +7,7 @@ export interface User {
7
7
  picture?: string;
8
8
  roles?: string[];
9
9
  isApproved?: boolean;
10
+ lastLoginAt?: string;
10
11
  }
11
12
  export interface AuthResponse {
12
13
  authenticated: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tumbaland/frontend-core",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Shared frontend auth/group/API-client logic for Tumbaland frontends",
5
5
  "author": "Tumbaland",
6
6
  "license": "MIT",