@opensourcekd/ng-common-libs 1.2.7 → 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
@@ -365,5 +439,5 @@ declare function removeStorageItem(key: string, storageType?: 'localStorage' | '
365
439
  */
366
440
  declare function configureAuth0(config: Partial<typeof AUTH0_CONFIG>): void;
367
441
 
368
- 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 };
369
443
  export type { UserData, UserInfo };