@opensourcekd/ng-common-libs 2.0.0 → 2.0.2

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/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { EventType } from 'mitt';
4
4
  /**
5
5
  * Event payload interface
6
6
  */
7
- interface EventPayload<T = any> {
7
+ interface EventPayload<T = unknown> {
8
8
  type: string;
9
9
  data: T;
10
10
  timestamp?: number;
@@ -34,13 +34,13 @@ declare class EventBus {
34
34
  * @param eventType - The type/name of the event
35
35
  * @param data - Optional data to send with the event
36
36
  */
37
- emit<T = any>(eventType: string, data?: T): void;
37
+ emit<T = unknown>(eventType: string, data?: T): void;
38
38
  /**
39
39
  * Subscribe to a specific event type
40
40
  * @param eventType - The type/name of the event to listen for
41
41
  * @returns Observable that emits the event data
42
42
  */
43
- on<T = any>(eventType: string): Observable<T>;
43
+ on<T = unknown>(eventType: string): Observable<T>;
44
44
  /**
45
45
  * Subscribe to multiple event types
46
46
  * @param eventTypes - Array of event types to listen for
@@ -83,22 +83,12 @@ declare const APP_CONFIG: {
83
83
  * The ReplaySubject keeps last 100 events in memory for late subscribers
84
84
  *
85
85
  * **IMPORTANT for Module Federation / MicroFrontends:**
86
- * This service uses a module-level singleton to ensure ONE instance across all MFEs and shell.
87
- * Before using `inject(EventBusService)` in components, you must provide it at application level:
86
+ * This service uses Angular's dependency injection with providedIn: 'root' to ensure
87
+ * singleton behavior across all MFEs and shell when shared via Module Federation webpack config.
88
88
  *
89
- * @example
90
- * ```typescript
91
- * // In app.config.ts (standalone) or app.module.ts (NgModule)
92
- * import { EventBusService, getEventBusService } from '@opensourcekd/ng-common-libs';
93
- *
94
- * export const appConfig: ApplicationConfig = {
95
- * providers: [
96
- * { provide: EventBusService, useFactory: getEventBusService }
97
- * ]
98
- * };
99
- * ```
89
+ * Simply inject in components using Angular DI:
100
90
  *
101
- * Then use in components:
91
+ * @example
102
92
  * ```typescript
103
93
  * import { Component, inject, OnInit } from '@angular/core';
104
94
  * import { EventBusService } from '@opensourcekd/ng-common-libs';
@@ -164,25 +154,6 @@ declare class EventBusService {
164
154
  */
165
155
  sendEvent(s: string): void;
166
156
  }
167
- /**
168
- * Factory function to get the singleton EventBusService instance
169
- * Use this in your application providers to ensure singleton behavior across MFEs
170
- *
171
- * @example
172
- * ```typescript
173
- * // In app.config.ts or app.module.ts
174
- * import { EventBusService, getEventBusService } from '@opensourcekd/ng-common-libs';
175
- *
176
- * export const appConfig: ApplicationConfig = {
177
- * providers: [
178
- * { provide: EventBusService, useFactory: getEventBusService }
179
- * ]
180
- * };
181
- * ```
182
- *
183
- * @returns The singleton EventBusService instance
184
- */
185
- declare function getEventBusService(): EventBusService;
186
157
 
187
158
  /**
188
159
  * User information from ID token
@@ -205,7 +176,7 @@ interface UserInfo {
205
176
  role?: string;
206
177
  org?: string;
207
178
  organization?: string;
208
- [key: string]: any;
179
+ [key: string]: unknown;
209
180
  }
210
181
  /**
211
182
  * Simplified user data extracted from token
@@ -217,6 +188,32 @@ interface UserData {
217
188
  role: string;
218
189
  org: string;
219
190
  }
191
+ /**
192
+ * App state for preserving information through auth flow
193
+ */
194
+ interface AppState {
195
+ returnTo?: string;
196
+ [key: string]: unknown;
197
+ }
198
+ /**
199
+ * Authorization parameters for Auth0
200
+ */
201
+ interface AuthorizationParams {
202
+ redirect_uri: string;
203
+ scope: string;
204
+ audience?: string;
205
+ connection?: string;
206
+ invitation?: string;
207
+ organization?: string;
208
+ [key: string]: unknown;
209
+ }
210
+ /**
211
+ * Callback result from Auth0
212
+ */
213
+ interface CallbackResult {
214
+ success: boolean;
215
+ appState?: AppState;
216
+ }
220
217
  /**
221
218
  * Authentication service for Auth0 integration
222
219
  * Handles login, logout, token management, and user session
@@ -225,20 +222,23 @@ interface UserData {
225
222
  * Configuration is centralized in config/auth.config.ts for easy management
226
223
  *
227
224
  * **IMPORTANT for Module Federation / MicroFrontends:**
228
- * This service uses a module-level singleton to ensure ONE instance across all MFEs and shell.
229
- * Before using `inject(AuthService)` in components, you must provide it at application level:
225
+ * This service uses Angular's dependency injection with providedIn: 'root' to ensure
226
+ * singleton behavior across all MFEs and shell when shared via Module Federation webpack config.
227
+ *
228
+ * Simply inject in components using Angular DI:
230
229
  *
231
230
  * @example
232
231
  * ```typescript
233
- * // In app.config.ts (standalone) or app.module.ts (NgModule)
234
- * import { AuthService, getAuthService, EventBusService, getEventBusService } from '@opensourcekd/ng-common-libs';
232
+ * import { Component, inject } from '@angular/core';
233
+ * import { AuthService } from '@opensourcekd/ng-common-libs';
235
234
  *
236
- * export const appConfig: ApplicationConfig = {
237
- * providers: [
238
- * { provide: EventBusService, useFactory: getEventBusService },
239
- * { provide: AuthService, useFactory: getAuthService }
240
- * ]
241
- * };
235
+ * @Component({
236
+ * selector: 'app-example',
237
+ * template: '...'
238
+ * })
239
+ * export class ExampleComponent {
240
+ * private authService = inject(AuthService);
241
+ * }
242
242
  * ```
243
243
  *
244
244
  * NOTE: All navigation logic using setTimeout is commented out as per requirements.
@@ -258,6 +258,8 @@ declare class AuthService {
258
258
  private initializeAuth0;
259
259
  /**
260
260
  * Ensure Auth0 client is initialized before use
261
+ * Lazy initialization pattern - client is created on first use
262
+ * Handles concurrent calls safely by checking promise first
261
263
  */
262
264
  private ensureInitialized;
263
265
  /**
@@ -279,19 +281,9 @@ declare class AuthService {
279
281
  * NOTE: Navigation after successful/failed authentication should be handled in the calling component
280
282
  * using setTimeout. See commented examples in app.component.ts
281
283
  *
282
- * @returns Promise<{ success: boolean, appState?: any }> - Success status and preserved appState
283
- */
284
- handleCallback(): Promise<{
285
- success: boolean;
286
- appState?: any;
287
- }>;
288
- /**
289
- * Decode and log the access token to console
290
- * NOTE: This logs sensitive token information to console for debugging purposes.
291
- * In production environments, consider disabling this or filtering console logs.
292
- * @param token - The JWT access token
284
+ * @returns Promise<CallbackResult> - Success status and preserved appState
293
285
  */
294
- private decodeAndLogToken;
286
+ handleCallback(): Promise<CallbackResult>;
295
287
  /**
296
288
  * Log all user claims for debugging
297
289
  * @param user - User info from Auth0
@@ -398,28 +390,6 @@ declare class AuthService {
398
390
  */
399
391
  private emitAuthEvent;
400
392
  }
401
- /**
402
- * Factory function to get the singleton AuthService instance
403
- * Use this in your application providers to ensure singleton behavior across MFEs
404
- *
405
- * Lazy initialization ensures Auth0 can be configured before service creation
406
- *
407
- * @example
408
- * ```typescript
409
- * // In app.config.ts or app.module.ts
410
- * import { AuthService, getAuthService, EventBusService, getEventBusService } from '@opensourcekd/ng-common-libs';
411
- *
412
- * export const appConfig: ApplicationConfig = {
413
- * providers: [
414
- * { provide: EventBusService, useFactory: getEventBusService },
415
- * { provide: AuthService, useFactory: getAuthService }
416
- * ]
417
- * };
418
- * ```
419
- *
420
- * @returns The singleton AuthService instance
421
- */
422
- declare function getAuthService(): AuthService;
423
393
 
424
394
  /**
425
395
  * Auth0 Configuration
@@ -511,7 +481,23 @@ declare function removeStorageItem(key: string, storageType?: 'localStorage' | '
511
481
  * });
512
482
  * ```
513
483
  */
514
- declare function configureAuth0(config: Partial<typeof AUTH0_CONFIG>): void;
484
+ /**
485
+ * Get the API URL
486
+ * Returns the API URL that was configured during library build from GitHub repository variables.
487
+ * No configuration needed - the value is baked into the library during CI/CD build process.
488
+ *
489
+ * @returns string - The API URL from APP_CONFIG (set during build time)
490
+ *
491
+ * @example
492
+ * ```typescript
493
+ * import { getApiUrl } from '@opensourcekd/ng-common-libs';
494
+ *
495
+ * // Use in HTTP interceptor or service
496
+ * const apiUrl = getApiUrl();
497
+ * const fullUrl = `${apiUrl}/users`;
498
+ * ```
499
+ */
500
+ declare function getApiUrl(): string;
515
501
 
516
- export { APP_CONFIG, AUTH0_CONFIG, AuthService, EventBus, EventBusService, STORAGE_CONFIG, STORAGE_KEYS, configureAuth0, getAuthService, getEventBusService, getStorageItem, removeStorageItem, setStorageItem };
517
- export type { EventPayload, UserData, UserInfo };
502
+ export { APP_CONFIG, AUTH0_CONFIG, AuthService, EventBus, EventBusService, STORAGE_CONFIG, STORAGE_KEYS, getApiUrl, getStorageItem, removeStorageItem, setStorageItem };
503
+ export type { AppState, AuthorizationParams, CallbackResult, EventPayload, UserData, UserInfo };