@opensourcekd/ng-common-libs 2.0.5 → 2.0.6

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.cjs CHANGED
@@ -12,6 +12,9 @@ var operators = require('rxjs/operators');
12
12
  * // Create an instance
13
13
  * const eventBus = new EventBus();
14
14
  *
15
+ * // Create an instance with an identifier
16
+ * const eventBus = new EventBus({ id: 'MFE' });
17
+ *
15
18
  * // Emit an event
16
19
  * eventBus.emit('user:login', { userId: '123', username: 'john' });
17
20
  *
@@ -19,10 +22,28 @@ var operators = require('rxjs/operators');
19
22
  * eventBus.on('user:login').subscribe(data => {
20
23
  * console.log('User logged in:', data);
21
24
  * });
25
+ *
26
+ * // Get the identifier
27
+ * const id = eventBus.getId(); // 'MFE' or undefined
22
28
  * ```
23
29
  */
24
30
  class EventBus {
25
31
  eventSubject = new rxjs.Subject();
32
+ id;
33
+ /**
34
+ * Create a new EventBus instance
35
+ * @param options - Optional configuration with an id to identify the instance
36
+ */
37
+ constructor(options) {
38
+ this.id = options?.id;
39
+ }
40
+ /**
41
+ * Get the identifier of this EventBus instance
42
+ * @returns The id if provided during initialization, undefined otherwise
43
+ */
44
+ getId() {
45
+ return this.id;
46
+ }
26
47
  /**
27
48
  * Emit an event with optional data
28
49
  * @param eventType - The type/name of the event
@@ -245,10 +266,16 @@ function removeStorageItem(key, storageType = 'sessionStorage') {
245
266
  * };
246
267
  * const authService = new AuthService(authConfig, eventBus);
247
268
  *
269
+ * // Or create with an identifier
270
+ * const authService = new AuthService(authConfig, eventBus, undefined, undefined, { id: 'MFE' });
271
+ *
248
272
  * // Use the service
249
273
  * await authService.login();
250
274
  * const user = authService.getUser();
251
275
  * const token = await authService.getToken();
276
+ *
277
+ * // Get the identifier
278
+ * const id = authService.getId(); // 'MFE' or undefined
252
279
  * ```
253
280
  */
254
281
  class AuthService {
@@ -267,12 +294,14 @@ class AuthService {
267
294
  storageConfig;
268
295
  storageKeys;
269
296
  eventBus;
297
+ id;
270
298
  /**
271
299
  * Create a new AuthService instance
272
300
  * @param config - Auth0 configuration
273
301
  * @param eventBus - EventBus instance for emitting auth events
274
302
  * @param storageConfig - Storage configuration (optional, defaults to sessionStorage)
275
303
  * @param storageKeys - Storage keys (optional, defaults to standard keys)
304
+ * @param options - Optional configuration with an id to identify the instance
276
305
  */
277
306
  constructor(config, eventBus, storageConfig = {
278
307
  TOKEN_STORAGE: 'sessionStorage',
@@ -280,16 +309,24 @@ class AuthService {
280
309
  }, storageKeys = {
281
310
  ACCESS_TOKEN: 'auth0_access_token',
282
311
  USER_INFO: 'auth0_user_info'
283
- }) {
312
+ }, options) {
284
313
  this.config = config;
285
314
  this.eventBus = eventBus;
286
315
  this.storageConfig = storageConfig;
287
316
  this.storageKeys = storageKeys;
317
+ this.id = options?.id;
288
318
  this.userSubject = new rxjs.BehaviorSubject(this.getUserInfoFromStorage());
289
319
  this.user$ = this.userSubject.asObservable();
290
320
  console.log("[AuthService] AuthService instance created (Auth0 client will be initialized on first use)");
291
321
  // Lazy initialization - Auth0 client will be initialized in ensureInitialized() on first use
292
322
  }
323
+ /**
324
+ * Get the identifier of this AuthService instance
325
+ * @returns The id if provided during initialization, undefined otherwise
326
+ */
327
+ getId() {
328
+ return this.id;
329
+ }
293
330
  /**
294
331
  * Initialize Auth0 client
295
332
  */