@opensourcekd/ng-common-libs 1.2.6 → 1.2.8

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.
@@ -8,8 +8,24 @@ import { EventType } from 'mitt';
8
8
  * This service is designed for MicroFrontend architectures where different apps need to communicate
9
9
  * The ReplaySubject keeps last 100 events in memory for late subscribers
10
10
  *
11
+ * **IMPORTANT for Module Federation / MicroFrontends:**
12
+ * This service uses a module-level singleton to ensure ONE instance across all MFEs and shell.
13
+ * Before using `inject(EventBusService)` in components, you must provide it at application level:
14
+ *
11
15
  * @example
12
16
  * ```typescript
17
+ * // In app.config.ts (standalone) or app.module.ts (NgModule)
18
+ * import { EventBusService, getEventBusService } from '@opensourcekd/ng-common-libs';
19
+ *
20
+ * export const appConfig: ApplicationConfig = {
21
+ * providers: [
22
+ * { provide: EventBusService, useFactory: getEventBusService }
23
+ * ]
24
+ * };
25
+ * ```
26
+ *
27
+ * Then use in components:
28
+ * ```typescript
13
29
  * import { Component, inject, OnInit } from '@angular/core';
14
30
  * import { EventBusService } from '@opensourcekd/ng-common-libs';
15
31
  *
@@ -74,6 +90,25 @@ declare class EventBusService {
74
90
  */
75
91
  sendEvent(s: string): void;
76
92
  }
93
+ /**
94
+ * Factory function to get the singleton EventBusService instance
95
+ * Use this in your application providers to ensure singleton behavior across MFEs
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * // In app.config.ts or app.module.ts
100
+ * import { EventBusService, getEventBusService } from '@opensourcekd/ng-common-libs';
101
+ *
102
+ * export const appConfig: ApplicationConfig = {
103
+ * providers: [
104
+ * { provide: EventBusService, useFactory: getEventBusService }
105
+ * ]
106
+ * };
107
+ * ```
108
+ *
109
+ * @returns The singleton EventBusService instance
110
+ */
111
+ declare function getEventBusService(): EventBusService;
77
112
 
78
113
  /**
79
114
  * User information from ID token
@@ -115,6 +150,23 @@ interface UserData {
115
150
  *
116
151
  * Configuration is centralized in config/auth.config.ts for easy management
117
152
  *
153
+ * **IMPORTANT for Module Federation / MicroFrontends:**
154
+ * This service uses a module-level singleton to ensure ONE instance across all MFEs and shell.
155
+ * Before using `inject(AuthService)` in components, you must provide it at application level:
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * // In app.config.ts (standalone) or app.module.ts (NgModule)
160
+ * import { AuthService, getAuthService, EventBusService, getEventBusService } from '@opensourcekd/ng-common-libs';
161
+ *
162
+ * export const appConfig: ApplicationConfig = {
163
+ * providers: [
164
+ * { provide: EventBusService, useFactory: getEventBusService },
165
+ * { provide: AuthService, useFactory: getAuthService }
166
+ * ]
167
+ * };
168
+ * ```
169
+ *
118
170
  * NOTE: All navigation logic using setTimeout is commented out as per requirements.
119
171
  * To enable navigation after auth operations, uncomment the marked sections in consuming components.
120
172
  */
@@ -272,6 +324,28 @@ declare class AuthService {
272
324
  */
273
325
  private emitAuthEvent;
274
326
  }
327
+ /**
328
+ * Factory function to get the singleton AuthService instance
329
+ * Use this in your application providers to ensure singleton behavior across MFEs
330
+ *
331
+ * Lazy initialization ensures Auth0 can be configured before service creation
332
+ *
333
+ * @example
334
+ * ```typescript
335
+ * // In app.config.ts or app.module.ts
336
+ * import { AuthService, getAuthService, EventBusService, getEventBusService } from '@opensourcekd/ng-common-libs';
337
+ *
338
+ * export const appConfig: ApplicationConfig = {
339
+ * providers: [
340
+ * { provide: EventBusService, useFactory: getEventBusService },
341
+ * { provide: AuthService, useFactory: getAuthService }
342
+ * ]
343
+ * };
344
+ * ```
345
+ *
346
+ * @returns The singleton AuthService instance
347
+ */
348
+ declare function getAuthService(): AuthService;
275
349
 
276
350
  /**
277
351
  * Auth0 Configuration
@@ -283,6 +357,10 @@ declare class AuthService {
283
357
  /**
284
358
  * Auth0 client configuration
285
359
  * Override these values in your consuming application by setting them before importing AuthService
360
+ *
361
+ * Note: redirectUri defaults to window.location.origin (base URL without path).
362
+ * Auth0 will redirect back to this URL after authentication.
363
+ * You can override this to a specific callback URL (e.g., '/auth-callback') using configureAuth0().
286
364
  */
287
365
  declare const AUTH0_CONFIG: {
288
366
  domain: string;
@@ -333,21 +411,33 @@ declare function setStorageItem(key: string, value: string, storageType?: 'local
333
411
  */
334
412
  declare function removeStorageItem(key: string, storageType?: 'localStorage' | 'sessionStorage'): void;
335
413
  /**
336
- * Configure Auth0 settings
337
- * Call this function in your consuming application before using AuthService
414
+ * Configure Auth0 settings (OPTIONAL)
415
+ * Call this function in your consuming application to override default Auth0 configuration.
416
+ * Only the values you provide will be overridden; all other defaults remain unchanged.
417
+ *
418
+ * Note: This function is optional. If not called, default values will be used.
419
+ *
420
+ * @param config - Partial Auth0 configuration object with values to override
338
421
  *
339
422
  * @example
340
423
  * ```typescript
341
424
  * import { configureAuth0 } from '@opensourcekd/ng-common-libs';
342
425
  *
426
+ * // Only override specific values - others keep their defaults
343
427
  * configureAuth0({
344
428
  * domain: 'your-domain.auth0.com',
345
429
  * clientId: 'your-client-id',
346
430
  * audience: 'https://your-api.com'
431
+ * // redirectUri, logoutUri, scope, etc. will use defaults
432
+ * });
433
+ *
434
+ * // Or override just redirectUri to use a specific callback page
435
+ * configureAuth0({
436
+ * redirectUri: window.location.origin + '/auth-callback'
347
437
  * });
348
438
  * ```
349
439
  */
350
440
  declare function configureAuth0(config: Partial<typeof AUTH0_CONFIG>): void;
351
441
 
352
- export { AUTH0_CONFIG, AuthService, EventBusService, STORAGE_CONFIG, STORAGE_KEYS, configureAuth0, getStorageItem, removeStorageItem, setStorageItem };
442
+ export { AUTH0_CONFIG, AuthService, EventBusService, STORAGE_CONFIG, STORAGE_KEYS, configureAuth0, getAuthService, getEventBusService, getStorageItem, removeStorageItem, setStorageItem };
353
443
  export type { UserData, UserInfo };