@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.
package/README.md CHANGED
@@ -27,6 +27,70 @@ npm install @opensourcekd/ng-common-libs
27
27
 
28
28
  ## 🔧 Usage
29
29
 
30
+ ### ⚠️ IMPORTANT: Setup for Module Federation / MicroFrontends
31
+
32
+ If you're using **Module Federation** with multiple Angular applications (shell + MFEs), you **MUST** configure the services as singletons using factory functions. This ensures ONE instance is shared across all applications.
33
+
34
+ **In your shell app AND each MFE's `app.config.ts` (standalone) or `app.module.ts` (NgModule):**
35
+
36
+ ```typescript
37
+ import { ApplicationConfig } from '@angular/core';
38
+ import {
39
+ AuthService,
40
+ EventBusService,
41
+ getAuthService,
42
+ getEventBusService,
43
+ configureAuth0
44
+ } from '@opensourcekd/ng-common-libs';
45
+ import { APP_CONFIG } from '@opensourcekd/ng-common-libs/core';
46
+
47
+ // Configure Auth0 (do this once in shell or each MFE)
48
+ configureAuth0({
49
+ domain: APP_CONFIG.auth0Domain,
50
+ clientId: APP_CONFIG.auth0ClientId,
51
+ audience: APP_CONFIG.apiUrl,
52
+ });
53
+
54
+ export const appConfig: ApplicationConfig = {
55
+ providers: [
56
+ // REQUIRED: Use factory functions for singleton behavior across MFEs
57
+ { provide: EventBusService, useFactory: getEventBusService },
58
+ { provide: AuthService, useFactory: getAuthService },
59
+ // ... your other providers
60
+ ]
61
+ };
62
+ ```
63
+
64
+ **Why is this needed?**
65
+ Angular's `providedIn: 'root'` creates one instance per Angular application. In Module Federation, each MFE is a separate Angular app, so you'd get multiple instances. Factory functions create a **JavaScript module-level singleton** that's shared across ALL applications.
66
+
67
+ **For NgModule-based apps:**
68
+ ```typescript
69
+ import { NgModule } from '@angular/core';
70
+ import {
71
+ AuthService,
72
+ EventBusService,
73
+ getAuthService,
74
+ getEventBusService
75
+ } from '@opensourcekd/ng-common-libs';
76
+
77
+ @NgModule({
78
+ providers: [
79
+ { provide: EventBusService, useFactory: getEventBusService },
80
+ { provide: AuthService, useFactory: getAuthService }
81
+ ]
82
+ })
83
+ export class AppModule { }
84
+ ```
85
+
86
+ Then use normally in components with `inject()`:
87
+ ```typescript
88
+ export class MyComponent {
89
+ private authService = inject(AuthService);
90
+ private eventBus = inject(EventBusService);
91
+ }
92
+ ```
93
+
30
94
  ### Configuration (Framework-Agnostic)
31
95
 
32
96
  The library provides a framework-agnostic configuration utility with **statically configured values** from GitHub repository variables:
@@ -49,19 +113,13 @@ console.log(APP_CONFIG.auth0ClientId); // Configured during build from GitHub v
49
113
 
50
114
  ### Auth0 Authentication
51
115
 
52
- Complete Auth0 integration with automatic token management and event emission:
116
+ Complete Auth0 integration with automatic token management and event emission.
117
+
118
+ **Note:** Make sure you've configured the providers as shown in the [Module Federation setup](#️-important-setup-for-module-federation--microfrontends) above first!
53
119
 
54
120
  ```typescript
55
121
  import { Component, inject } from '@angular/core';
56
- import { AuthService, configureAuth0 } from '@opensourcekd/ng-common-libs';
57
- import { APP_CONFIG } from '@opensourcekd/ng-common-libs/core';
58
-
59
- // Use pre-configured values from APP_CONFIG
60
- configureAuth0({
61
- domain: APP_CONFIG.auth0Domain,
62
- clientId: APP_CONFIG.auth0ClientId,
63
- audience: APP_CONFIG.apiUrl,
64
- });
122
+ import { AuthService } from '@opensourcekd/ng-common-libs';
65
123
 
66
124
  @Component({
67
125
  selector: 'app-login',
@@ -89,7 +147,9 @@ See the [Auth0 Service Usage Guide](./docs/AUTH_SERVICE_USAGE.md) for complete i
89
147
 
90
148
  ### EventBusService
91
149
 
92
- Cross-application event communication for MicroFrontend architectures:
150
+ Cross-application event communication for MicroFrontend architectures.
151
+
152
+ **Note:** Make sure you've configured the providers as shown in the [Module Federation setup](#️-important-setup-for-module-federation--microfrontends) above first!
93
153
 
94
154
  ```typescript
95
155
  import { Component, OnInit, inject } from '@angular/core';
@@ -217,14 +277,16 @@ export default {
217
277
 
218
278
  ### AuthService
219
279
 
220
- - `login(options?: RedirectLoginOptions): Promise<void>` - Initiate Auth0 login
221
- - `logout(options?: LogoutOptions): Promise<void>` - Logout and clear session
222
- - `handleCallback(): Promise<{ success: boolean, appState?: any }>` - Handle Auth0 callback
223
- - `getToken(): Promise<string | null>` - Get access token asynchronously
224
- - `getTokenSync(): string | null` - Get cached access token synchronously
225
- - `getUser(): Signal<UserInfo | null>` - Get user information as signal
226
- - `isAuthenticated(): Signal<boolean>` - Check authentication status
227
- - `isLoading(): Signal<boolean>` - Check if authentication is loading
280
+ - `login(user?: string, options?: { invitation?: string; organization?: string }): Promise<void>` - Initiate Auth0 login with optional user identifier and organization invitation parameters
281
+ - `logout(): Promise<void>` - Logout and clear session
282
+ - `handleCallback(): Promise<{ success: boolean, appState?: any }>` - Handle Auth0 callback and return success status with preserved appState
283
+ - `getToken(): Promise<string | null>` - Get access token asynchronously (checks storage first, then Auth0)
284
+ - `getTokenSync(): string | null` - Get cached access token synchronously (storage only)
285
+ - `getUser(): UserInfo | null` - Get current user information
286
+ - `getUserData(): UserData | null` - Get simplified user data with role and organization extraction
287
+ - `isAuthenticated(): Promise<boolean>` - Check authentication status asynchronously (verifies with Auth0)
288
+ - `isAuthenticatedSync(): boolean` - Check authentication status synchronously (storage only)
289
+ - `user$: Observable<UserInfo | null>` - Observable stream of user changes
228
290
 
229
291
  ### EventBusService
230
292