@opensourcekd/ng-common-libs 1.2.7 → 2.0.0
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 +93 -194
- package/dist/index.cjs +97 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +75 -1
- package/dist/index.mjs +96 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -12
- package/dist/angular/index.cjs +0 -908
- package/dist/angular/index.cjs.map +0 -1
- package/dist/angular/index.d.ts +0 -369
- package/dist/angular/index.mjs +0 -900
- package/dist/angular/index.mjs.map +0 -1
- package/dist/core/index.cjs +0 -86
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.d.ts +0 -78
- package/dist/core/index.mjs +0 -83
- package/dist/core/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -2,18 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
Angular 18 library with Auth0 authentication service and MicroFrontend event bus.
|
|
4
4
|
|
|
5
|
-
## 🎯
|
|
5
|
+
## 🎯 Simple Architecture
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**One import path. Everything you need.**
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
All services, utilities, and types are exported from a single package:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import {
|
|
13
|
+
AuthService,
|
|
14
|
+
EventBusService,
|
|
15
|
+
getAuthService,
|
|
16
|
+
getEventBusService,
|
|
17
|
+
configureAuth0,
|
|
18
|
+
UserInfo,
|
|
19
|
+
EventBus
|
|
20
|
+
} from '@opensourcekd/ng-common-libs';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
> 📖 **Complete Guide**: See [CONSUMPTION_GUIDE.md](./CONSUMPTION_GUIDE.md) for detailed usage instructions.
|
|
11
24
|
|
|
12
25
|
## 🚀 Features
|
|
13
26
|
|
|
14
|
-
- **
|
|
15
|
-
- **EventBusService**: MicroFrontend-ready event bus with replay buffer
|
|
16
|
-
- **
|
|
27
|
+
- **AuthService**: Complete Auth0 authentication with token management
|
|
28
|
+
- **EventBusService**: MicroFrontend-ready event bus with replay buffer
|
|
29
|
+
- **Module Federation Support**: Singleton pattern works across shell + MFEs
|
|
30
|
+
- **AOT-Safe**: No JIT compiler required, works in production builds
|
|
31
|
+
- **Framework-Agnostic Core**: EventBus can be used in React, Vue, or vanilla JS
|
|
17
32
|
|
|
18
33
|
## 📦 Installation
|
|
19
34
|
|
|
@@ -21,225 +36,109 @@ This library features a **dual-layer architecture**:
|
|
|
21
36
|
npm install @opensourcekd/ng-common-libs
|
|
22
37
|
```
|
|
23
38
|
|
|
24
|
-
> **Note:** `mitt` and `@auth0/auth0-spa-js` are bundled
|
|
25
|
-
>
|
|
26
|
-
> **Module Federation**: Just configure `@opensourcekd/ng-common-libs` as shared in your webpack config. The bundled dependencies (`mitt`, `@auth0/auth0-spa-js`) will be included automatically, ensuring they're loaded only once across all micro-frontends.
|
|
39
|
+
> **Note:** `mitt` and `@auth0/auth0-spa-js` are bundled. No separate installation needed.
|
|
27
40
|
|
|
28
|
-
## 🔧
|
|
41
|
+
## 🔧 Quick Start
|
|
29
42
|
|
|
30
|
-
###
|
|
43
|
+
### For Module Federation (Shell + MFEs)
|
|
31
44
|
|
|
32
|
-
|
|
45
|
+
**In your shell app AND each MFE's `app.config.ts`:**
|
|
33
46
|
|
|
34
47
|
```typescript
|
|
35
|
-
|
|
36
|
-
import {
|
|
48
|
+
import { ApplicationConfig } from '@angular/core';
|
|
49
|
+
import {
|
|
50
|
+
AuthService,
|
|
51
|
+
EventBusService,
|
|
52
|
+
getAuthService,
|
|
53
|
+
getEventBusService,
|
|
54
|
+
configureAuth0
|
|
55
|
+
} from '@opensourcekd/ng-common-libs';
|
|
56
|
+
|
|
57
|
+
// Configure Auth0 once in shell (use your environment config)
|
|
58
|
+
configureAuth0({
|
|
59
|
+
domain: 'your-tenant.auth0.com',
|
|
60
|
+
clientId: 'your-client-id',
|
|
61
|
+
audience: 'https://your-api.example.com',
|
|
62
|
+
});
|
|
37
63
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
64
|
+
export const appConfig: ApplicationConfig = {
|
|
65
|
+
providers: [
|
|
66
|
+
// Factory functions ensure singleton across all MFEs
|
|
67
|
+
{ provide: EventBusService, useFactory: getEventBusService },
|
|
68
|
+
{ provide: AuthService, useFactory: getAuthService },
|
|
69
|
+
]
|
|
70
|
+
};
|
|
42
71
|
```
|
|
43
72
|
|
|
44
|
-
**
|
|
45
|
-
|
|
46
|
-
- No runtime configuration needed - values are available immediately
|
|
47
|
-
- Can be used across any framework: Angular, React, Vue, Svelte, vanilla JS
|
|
48
|
-
- Perfect for MicroFrontends (MFEs) and shell applications
|
|
73
|
+
**Why factory functions?**
|
|
74
|
+
They create a **JavaScript module-level singleton** shared across ALL applications (shell + MFEs). Module Federation ensures the module loads once, so all apps get the same instance.
|
|
49
75
|
|
|
50
|
-
###
|
|
51
|
-
|
|
52
|
-
Complete Auth0 integration with automatic token management and event emission:
|
|
76
|
+
### For Standalone Components
|
|
53
77
|
|
|
78
|
+
Then use normally with `inject()`:
|
|
54
79
|
```typescript
|
|
55
80
|
import { Component, inject } from '@angular/core';
|
|
56
|
-
import { AuthService,
|
|
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
|
-
});
|
|
81
|
+
import { AuthService, EventBusService } from '@opensourcekd/ng-common-libs';
|
|
65
82
|
|
|
66
|
-
|
|
67
|
-
selector: 'app-login',
|
|
68
|
-
template: `
|
|
69
|
-
<button (click)="login()">Login with Auth0</button>
|
|
70
|
-
<button (click)="logout()" *ngIf="user">Logout</button>
|
|
71
|
-
<div *ngIf="user">Welcome, {{ user.name }}!</div>
|
|
72
|
-
`
|
|
73
|
-
})
|
|
74
|
-
export class LoginComponent {
|
|
83
|
+
export class MyComponent {
|
|
75
84
|
private authService = inject(AuthService);
|
|
76
|
-
user = this.authService.getUser();
|
|
77
|
-
|
|
78
|
-
async login() {
|
|
79
|
-
await this.authService.login();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async logout() {
|
|
83
|
-
await this.authService.logout();
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
See the [Auth0 Service Usage Guide](./docs/AUTH_SERVICE_USAGE.md) for complete integration instructions.
|
|
89
|
-
|
|
90
|
-
### EventBusService
|
|
91
|
-
|
|
92
|
-
Cross-application event communication for MicroFrontend architectures:
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
import { Component, OnInit, inject } from '@angular/core';
|
|
96
|
-
import { EventBusService } from '@opensourcekd/ng-common-libs';
|
|
97
|
-
|
|
98
|
-
@Component({
|
|
99
|
-
selector: 'app-event-example',
|
|
100
|
-
template: `<button (click)="sendEvent()">Send Event</button>`
|
|
101
|
-
})
|
|
102
|
-
export class EventExampleComponent implements OnInit {
|
|
103
85
|
private eventBus = inject(EventBusService);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// Subscribe to all events
|
|
107
|
-
this.eventBus.onePlusNEvents.subscribe(event => {
|
|
108
|
-
console.log('Event received:', event);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
sendEvent() {
|
|
113
|
-
// Send structured event
|
|
114
|
-
this.eventBus.sendEvent(JSON.stringify({
|
|
115
|
-
type: 'user:action',
|
|
116
|
-
payload: { userId: '123' },
|
|
117
|
-
timestamp: new Date().toISOString()
|
|
118
|
-
}));
|
|
119
|
-
}
|
|
86
|
+
|
|
87
|
+
login() { this.authService.login(); }
|
|
120
88
|
}
|
|
121
89
|
```
|
|
122
90
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
### For Non-Angular Projects (React, Vue, Svelte, Vanilla JS)
|
|
91
|
+
### Configuration
|
|
126
92
|
|
|
127
|
-
Use
|
|
93
|
+
**Use your own environment configuration** (recommended):
|
|
128
94
|
|
|
129
95
|
```typescript
|
|
130
|
-
|
|
131
|
-
import {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
console.log('User logged in:', data);
|
|
96
|
+
import { configureAuth0 } from '@opensourcekd/ng-common-libs';
|
|
97
|
+
import { environment } from './environments/environment';
|
|
98
|
+
|
|
99
|
+
configureAuth0({
|
|
100
|
+
domain: environment.auth0Domain,
|
|
101
|
+
clientId: environment.auth0ClientId,
|
|
102
|
+
audience: environment.apiUrl,
|
|
138
103
|
});
|
|
139
104
|
```
|
|
140
105
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
import { useEffect } from 'react';
|
|
145
|
-
import { EventBus } from '@opensourcekd/ng-common-libs/core';
|
|
106
|
+
> ⚠️ **Important**: Do not use `APP_CONFIG` from the library. It contains placeholder values. Always use your own environment configuration.
|
|
146
107
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
function MyComponent() {
|
|
150
|
-
useEffect(() => {
|
|
151
|
-
const subscription = eventBus.on('user:login').subscribe(data => {
|
|
152
|
-
console.log('User logged in:', data);
|
|
153
|
-
});
|
|
154
|
-
return () => subscription.unsubscribe();
|
|
155
|
-
}, []);
|
|
108
|
+
## 📚 Documentation
|
|
156
109
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
110
|
+
- **[CONSUMPTION_GUIDE.md](./CONSUMPTION_GUIDE.md)** - Complete setup guide and API reference
|
|
111
|
+
- **[Auth0 Service Usage](./docs/AUTH_SERVICE_USAGE.md)** - Detailed Auth0 integration
|
|
112
|
+
- **[EventBus Service Usage](./docs/EVENT_BUS_USAGE.md)** - Cross-application event patterns
|
|
113
|
+
- **[Module Federation Guide](./docs/MODULE_FEDERATION.md)** - Runtime sharing configuration
|
|
160
114
|
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
```
|
|
115
|
+
## 📝 What's Exported
|
|
164
116
|
|
|
165
|
-
|
|
117
|
+
Everything you need from one import:
|
|
166
118
|
|
|
167
119
|
```typescript
|
|
168
|
-
import {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
eventBus.emit('user:login', { userId: '123' });
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
return { handleLogin };
|
|
192
|
-
}
|
|
193
|
-
};
|
|
120
|
+
import {
|
|
121
|
+
// Services
|
|
122
|
+
AuthService,
|
|
123
|
+
EventBusService,
|
|
124
|
+
|
|
125
|
+
// Factory Functions
|
|
126
|
+
getAuthService,
|
|
127
|
+
getEventBusService,
|
|
128
|
+
|
|
129
|
+
// Configuration
|
|
130
|
+
configureAuth0,
|
|
131
|
+
|
|
132
|
+
// Core Utilities
|
|
133
|
+
EventBus,
|
|
134
|
+
|
|
135
|
+
// Types & Interfaces
|
|
136
|
+
UserInfo,
|
|
137
|
+
UserData,
|
|
138
|
+
EventPayload,
|
|
139
|
+
} from '@opensourcekd/ng-common-libs';
|
|
194
140
|
```
|
|
195
141
|
|
|
196
|
-
## 📚 Documentation
|
|
197
|
-
|
|
198
|
-
- **[Auth0 Service Usage](./docs/AUTH_SERVICE_USAGE.md)** - Complete Auth0 authentication integration guide
|
|
199
|
-
- **[EventBus Service Usage](./docs/EVENT_BUS_USAGE.md)** - Cross-application event communication guide
|
|
200
|
-
- **[Deployment Guide](./docs/DEPLOYMENT.md)** - Publishing, versioning, and consumption
|
|
201
|
-
- **[Microapp Triggering Guide](./docs/MICROAPP_TRIGGERING.md)** - Automatic build triggering for consuming microapps
|
|
202
|
-
- **[Module Federation Guide](./docs/MODULE_FEDERATION.md)** - Runtime sharing with Module Federation
|
|
203
|
-
|
|
204
|
-
## 📝 API Documentation
|
|
205
|
-
|
|
206
|
-
### Core Configuration (Framework-Agnostic)
|
|
207
|
-
|
|
208
|
-
- `APP_CONFIG` - Read-only application configuration object with values statically configured during build time:
|
|
209
|
-
- `auth0Domain: string` - Auth0 tenant domain (from GitHub var `AUTH0_DOMAIN`)
|
|
210
|
-
- `auth0ClientId: string` - Auth0 client ID (from GitHub var `AUTH0_CLIENT_ID`)
|
|
211
|
-
- `apiUrl: string` - API base URL (from GitHub var `API_URL`)
|
|
212
|
-
|
|
213
|
-
### Angular Configuration
|
|
214
|
-
|
|
215
|
-
- `configureAuth0(config: Partial<AUTH0_CONFIG>): void` - Configure Auth0 settings (domain, clientId, etc.)
|
|
216
|
-
- `AUTH0_CONFIG` - Auth0 configuration object (domain, clientId, redirectUri, etc.)
|
|
217
|
-
|
|
218
|
-
### AuthService
|
|
219
|
-
|
|
220
|
-
- `login(user?: string, options?: { invitation?: string; organization?: string }): Promise<void>` - Initiate Auth0 login with optional user identifier and organization invitation parameters
|
|
221
|
-
- `logout(): Promise<void>` - Logout and clear session
|
|
222
|
-
- `handleCallback(): Promise<{ success: boolean, appState?: any }>` - Handle Auth0 callback and return success status with preserved appState
|
|
223
|
-
- `getToken(): Promise<string | null>` - Get access token asynchronously (checks storage first, then Auth0)
|
|
224
|
-
- `getTokenSync(): string | null` - Get cached access token synchronously (storage only)
|
|
225
|
-
- `getUser(): UserInfo | null` - Get current user information
|
|
226
|
-
- `getUserData(): UserData | null` - Get simplified user data with role and organization extraction
|
|
227
|
-
- `isAuthenticated(): Promise<boolean>` - Check authentication status asynchronously (verifies with Auth0)
|
|
228
|
-
- `isAuthenticatedSync(): boolean` - Check authentication status synchronously (storage only)
|
|
229
|
-
- `user$: Observable<UserInfo | null>` - Observable stream of user changes
|
|
230
|
-
|
|
231
|
-
### EventBusService
|
|
232
|
-
|
|
233
|
-
- `sendEvent(event: string): void` - Send event to all subscribers
|
|
234
|
-
- `onePlusNEvents: Observable<string>` - Subscribe to all events with replay buffer
|
|
235
|
-
|
|
236
|
-
### EventBus (Core)
|
|
237
|
-
|
|
238
|
-
- `emit<T>(eventType: string, data?: T): void` - Emit an event
|
|
239
|
-
- `on<T>(eventType: string): Observable<T>` - Subscribe to an event
|
|
240
|
-
- `onMultiple(eventTypes: string[]): Observable<EventPayload>` - Subscribe to multiple events
|
|
241
|
-
- `onAll(): Observable<EventPayload>` - Subscribe to all events
|
|
242
|
-
|
|
243
142
|
## 🛠️ Development
|
|
244
143
|
|
|
245
144
|
```bash
|