@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 +38 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +44 -2
- package/dist/index.mjs +38 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,12 @@ interface EventPayload<T = unknown> {
|
|
|
8
8
|
data: T;
|
|
9
9
|
timestamp?: number;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* EventBus options interface
|
|
13
|
+
*/
|
|
14
|
+
interface EventBusOptions {
|
|
15
|
+
id?: string;
|
|
16
|
+
}
|
|
11
17
|
/**
|
|
12
18
|
* EventBus - A centralized event bus for application-wide communication
|
|
13
19
|
* Framework-agnostic implementation using only RxJS
|
|
@@ -17,6 +23,9 @@ interface EventPayload<T = unknown> {
|
|
|
17
23
|
* // Create an instance
|
|
18
24
|
* const eventBus = new EventBus();
|
|
19
25
|
*
|
|
26
|
+
* // Create an instance with an identifier
|
|
27
|
+
* const eventBus = new EventBus({ id: 'MFE' });
|
|
28
|
+
*
|
|
20
29
|
* // Emit an event
|
|
21
30
|
* eventBus.emit('user:login', { userId: '123', username: 'john' });
|
|
22
31
|
*
|
|
@@ -24,10 +33,24 @@ interface EventPayload<T = unknown> {
|
|
|
24
33
|
* eventBus.on('user:login').subscribe(data => {
|
|
25
34
|
* console.log('User logged in:', data);
|
|
26
35
|
* });
|
|
36
|
+
*
|
|
37
|
+
* // Get the identifier
|
|
38
|
+
* const id = eventBus.getId(); // 'MFE' or undefined
|
|
27
39
|
* ```
|
|
28
40
|
*/
|
|
29
41
|
declare class EventBus {
|
|
30
42
|
private eventSubject;
|
|
43
|
+
private id?;
|
|
44
|
+
/**
|
|
45
|
+
* Create a new EventBus instance
|
|
46
|
+
* @param options - Optional configuration with an id to identify the instance
|
|
47
|
+
*/
|
|
48
|
+
constructor(options?: EventBusOptions);
|
|
49
|
+
/**
|
|
50
|
+
* Get the identifier of this EventBus instance
|
|
51
|
+
* @returns The id if provided during initialization, undefined otherwise
|
|
52
|
+
*/
|
|
53
|
+
getId(): string | undefined;
|
|
31
54
|
/**
|
|
32
55
|
* Emit an event with optional data
|
|
33
56
|
* @param eventType - The type/name of the event
|
|
@@ -243,6 +266,12 @@ interface Auth0Config {
|
|
|
243
266
|
scope: string;
|
|
244
267
|
connection?: string;
|
|
245
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* AuthService options interface
|
|
271
|
+
*/
|
|
272
|
+
interface AuthServiceOptions {
|
|
273
|
+
id?: string;
|
|
274
|
+
}
|
|
246
275
|
/**
|
|
247
276
|
* Storage configuration
|
|
248
277
|
*/
|
|
@@ -280,10 +309,16 @@ interface StorageKeys {
|
|
|
280
309
|
* };
|
|
281
310
|
* const authService = new AuthService(authConfig, eventBus);
|
|
282
311
|
*
|
|
312
|
+
* // Or create with an identifier
|
|
313
|
+
* const authService = new AuthService(authConfig, eventBus, undefined, undefined, { id: 'MFE' });
|
|
314
|
+
*
|
|
283
315
|
* // Use the service
|
|
284
316
|
* await authService.login();
|
|
285
317
|
* const user = authService.getUser();
|
|
286
318
|
* const token = await authService.getToken();
|
|
319
|
+
*
|
|
320
|
+
* // Get the identifier
|
|
321
|
+
* const id = authService.getId(); // 'MFE' or undefined
|
|
287
322
|
* ```
|
|
288
323
|
*/
|
|
289
324
|
declare class AuthService {
|
|
@@ -296,14 +331,21 @@ declare class AuthService {
|
|
|
296
331
|
private storageConfig;
|
|
297
332
|
private storageKeys;
|
|
298
333
|
private eventBus;
|
|
334
|
+
private id?;
|
|
299
335
|
/**
|
|
300
336
|
* Create a new AuthService instance
|
|
301
337
|
* @param config - Auth0 configuration
|
|
302
338
|
* @param eventBus - EventBus instance for emitting auth events
|
|
303
339
|
* @param storageConfig - Storage configuration (optional, defaults to sessionStorage)
|
|
304
340
|
* @param storageKeys - Storage keys (optional, defaults to standard keys)
|
|
341
|
+
* @param options - Optional configuration with an id to identify the instance
|
|
342
|
+
*/
|
|
343
|
+
constructor(config: Auth0Config, eventBus: EventBus, storageConfig?: StorageConfig, storageKeys?: StorageKeys, options?: AuthServiceOptions);
|
|
344
|
+
/**
|
|
345
|
+
* Get the identifier of this AuthService instance
|
|
346
|
+
* @returns The id if provided during initialization, undefined otherwise
|
|
305
347
|
*/
|
|
306
|
-
|
|
348
|
+
getId(): string | undefined;
|
|
307
349
|
/**
|
|
308
350
|
* Initialize Auth0 client
|
|
309
351
|
*/
|
|
@@ -406,4 +448,4 @@ declare class AuthService {
|
|
|
406
448
|
declare function createAuthService(eventBus: EventBus): AuthService;
|
|
407
449
|
|
|
408
450
|
export { APP_CONFIG, AUTH0_CONFIG, AuthService, EventBus, STORAGE_CONFIG, STORAGE_KEYS, configureAuth0, createAuthService, getStorageItem, removeStorageItem, resetAuth0Config, setStorageItem };
|
|
409
|
-
export type { AppState, Auth0Config, Auth0ConfigOptions, AuthorizationParams, CallbackResult, EventPayload, StorageConfig, StorageKeys, UserData, UserInfo };
|
|
451
|
+
export type { AppState, Auth0Config, Auth0ConfigOptions, AuthServiceOptions, AuthorizationParams, CallbackResult, EventBusOptions, EventPayload, StorageConfig, StorageKeys, UserData, UserInfo };
|
package/dist/index.mjs
CHANGED
|
@@ -10,6 +10,9 @@ import { filter, map } from 'rxjs/operators';
|
|
|
10
10
|
* // Create an instance
|
|
11
11
|
* const eventBus = new EventBus();
|
|
12
12
|
*
|
|
13
|
+
* // Create an instance with an identifier
|
|
14
|
+
* const eventBus = new EventBus({ id: 'MFE' });
|
|
15
|
+
*
|
|
13
16
|
* // Emit an event
|
|
14
17
|
* eventBus.emit('user:login', { userId: '123', username: 'john' });
|
|
15
18
|
*
|
|
@@ -17,10 +20,28 @@ import { filter, map } from 'rxjs/operators';
|
|
|
17
20
|
* eventBus.on('user:login').subscribe(data => {
|
|
18
21
|
* console.log('User logged in:', data);
|
|
19
22
|
* });
|
|
23
|
+
*
|
|
24
|
+
* // Get the identifier
|
|
25
|
+
* const id = eventBus.getId(); // 'MFE' or undefined
|
|
20
26
|
* ```
|
|
21
27
|
*/
|
|
22
28
|
class EventBus {
|
|
23
29
|
eventSubject = new Subject();
|
|
30
|
+
id;
|
|
31
|
+
/**
|
|
32
|
+
* Create a new EventBus instance
|
|
33
|
+
* @param options - Optional configuration with an id to identify the instance
|
|
34
|
+
*/
|
|
35
|
+
constructor(options) {
|
|
36
|
+
this.id = options?.id;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the identifier of this EventBus instance
|
|
40
|
+
* @returns The id if provided during initialization, undefined otherwise
|
|
41
|
+
*/
|
|
42
|
+
getId() {
|
|
43
|
+
return this.id;
|
|
44
|
+
}
|
|
24
45
|
/**
|
|
25
46
|
* Emit an event with optional data
|
|
26
47
|
* @param eventType - The type/name of the event
|
|
@@ -243,10 +264,16 @@ function removeStorageItem(key, storageType = 'sessionStorage') {
|
|
|
243
264
|
* };
|
|
244
265
|
* const authService = new AuthService(authConfig, eventBus);
|
|
245
266
|
*
|
|
267
|
+
* // Or create with an identifier
|
|
268
|
+
* const authService = new AuthService(authConfig, eventBus, undefined, undefined, { id: 'MFE' });
|
|
269
|
+
*
|
|
246
270
|
* // Use the service
|
|
247
271
|
* await authService.login();
|
|
248
272
|
* const user = authService.getUser();
|
|
249
273
|
* const token = await authService.getToken();
|
|
274
|
+
*
|
|
275
|
+
* // Get the identifier
|
|
276
|
+
* const id = authService.getId(); // 'MFE' or undefined
|
|
250
277
|
* ```
|
|
251
278
|
*/
|
|
252
279
|
class AuthService {
|
|
@@ -265,12 +292,14 @@ class AuthService {
|
|
|
265
292
|
storageConfig;
|
|
266
293
|
storageKeys;
|
|
267
294
|
eventBus;
|
|
295
|
+
id;
|
|
268
296
|
/**
|
|
269
297
|
* Create a new AuthService instance
|
|
270
298
|
* @param config - Auth0 configuration
|
|
271
299
|
* @param eventBus - EventBus instance for emitting auth events
|
|
272
300
|
* @param storageConfig - Storage configuration (optional, defaults to sessionStorage)
|
|
273
301
|
* @param storageKeys - Storage keys (optional, defaults to standard keys)
|
|
302
|
+
* @param options - Optional configuration with an id to identify the instance
|
|
274
303
|
*/
|
|
275
304
|
constructor(config, eventBus, storageConfig = {
|
|
276
305
|
TOKEN_STORAGE: 'sessionStorage',
|
|
@@ -278,16 +307,24 @@ class AuthService {
|
|
|
278
307
|
}, storageKeys = {
|
|
279
308
|
ACCESS_TOKEN: 'auth0_access_token',
|
|
280
309
|
USER_INFO: 'auth0_user_info'
|
|
281
|
-
}) {
|
|
310
|
+
}, options) {
|
|
282
311
|
this.config = config;
|
|
283
312
|
this.eventBus = eventBus;
|
|
284
313
|
this.storageConfig = storageConfig;
|
|
285
314
|
this.storageKeys = storageKeys;
|
|
315
|
+
this.id = options?.id;
|
|
286
316
|
this.userSubject = new BehaviorSubject(this.getUserInfoFromStorage());
|
|
287
317
|
this.user$ = this.userSubject.asObservable();
|
|
288
318
|
console.log("[AuthService] AuthService instance created (Auth0 client will be initialized on first use)");
|
|
289
319
|
// Lazy initialization - Auth0 client will be initialized in ensureInitialized() on first use
|
|
290
320
|
}
|
|
321
|
+
/**
|
|
322
|
+
* Get the identifier of this AuthService instance
|
|
323
|
+
* @returns The id if provided during initialization, undefined otherwise
|
|
324
|
+
*/
|
|
325
|
+
getId() {
|
|
326
|
+
return this.id;
|
|
327
|
+
}
|
|
291
328
|
/**
|
|
292
329
|
* Initialize Auth0 client
|
|
293
330
|
*/
|