@opensourcekd/ng-common-libs 1.2.8 â 2.0.1
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 +72 -242
- package/dist/index.cjs +105 -201
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +70 -84
- package/dist/index.mjs +105 -199
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -11
- package/dist/angular/index.cjs +0 -1001
- package/dist/angular/index.cjs.map +0 -1
- package/dist/angular/index.d.ts +0 -443
- package/dist/angular/index.mjs +0 -991
- 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
|
+
getApiUrl,
|
|
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,17 +36,13 @@ 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
|
-
|
|
33
|
-
|
|
34
|
-
**In your shell app AND each MFE's `app.config.ts` (standalone) or `app.module.ts` (NgModule):**
|
|
45
|
+
**In your shell app AND each MFE's `app.config.ts`:**
|
|
35
46
|
|
|
36
47
|
```typescript
|
|
37
48
|
import { ApplicationConfig } from '@angular/core';
|
|
@@ -39,267 +50,86 @@ import {
|
|
|
39
50
|
AuthService,
|
|
40
51
|
EventBusService,
|
|
41
52
|
getAuthService,
|
|
42
|
-
getEventBusService
|
|
43
|
-
configureAuth0
|
|
53
|
+
getEventBusService
|
|
44
54
|
} from '@opensourcekd/ng-common-libs';
|
|
45
|
-
import { APP_CONFIG } from '@opensourcekd/ng-common-libs/core';
|
|
46
55
|
|
|
47
|
-
//
|
|
48
|
-
configureAuth0({
|
|
49
|
-
domain: APP_CONFIG.auth0Domain,
|
|
50
|
-
clientId: APP_CONFIG.auth0ClientId,
|
|
51
|
-
audience: APP_CONFIG.apiUrl,
|
|
52
|
-
});
|
|
56
|
+
// No configuration needed - API URL is baked into the library during build
|
|
53
57
|
|
|
54
58
|
export const appConfig: ApplicationConfig = {
|
|
55
59
|
providers: [
|
|
56
|
-
//
|
|
60
|
+
// Factory functions ensure singleton across all MFEs
|
|
57
61
|
{ provide: EventBusService, useFactory: getEventBusService },
|
|
58
62
|
{ provide: AuthService, useFactory: getAuthService },
|
|
59
|
-
// ... your other providers
|
|
60
63
|
]
|
|
61
64
|
};
|
|
62
65
|
```
|
|
63
66
|
|
|
64
|
-
**Why
|
|
65
|
-
|
|
67
|
+
**Why factory functions?**
|
|
68
|
+
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.
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
import { NgModule } from '@angular/core';
|
|
70
|
-
import {
|
|
71
|
-
AuthService,
|
|
72
|
-
EventBusService,
|
|
73
|
-
getAuthService,
|
|
74
|
-
getEventBusService
|
|
75
|
-
} from '@opensourcekd/ng-common-libs';
|
|
70
|
+
### For Standalone Components
|
|
76
71
|
|
|
77
|
-
|
|
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()`:
|
|
72
|
+
Then use normally with `inject()`:
|
|
87
73
|
```typescript
|
|
74
|
+
import { Component, inject } from '@angular/core';
|
|
75
|
+
import { AuthService, EventBusService } from '@opensourcekd/ng-common-libs';
|
|
76
|
+
|
|
88
77
|
export class MyComponent {
|
|
89
78
|
private authService = inject(AuthService);
|
|
90
79
|
private eventBus = inject(EventBusService);
|
|
80
|
+
|
|
81
|
+
login() { this.authService.login(); }
|
|
91
82
|
}
|
|
92
83
|
```
|
|
93
84
|
|
|
94
|
-
###
|
|
95
|
-
|
|
96
|
-
The library provides a framework-agnostic configuration utility with **statically configured values** from GitHub repository variables:
|
|
97
|
-
|
|
98
|
-
```typescript
|
|
99
|
-
// Import from /core for framework-agnostic usage
|
|
100
|
-
import { APP_CONFIG } from '@opensourcekd/ng-common-libs/core';
|
|
101
|
-
|
|
102
|
-
// Access pre-configured values anywhere in your app
|
|
103
|
-
console.log(APP_CONFIG.apiUrl); // Configured during build from GitHub vars
|
|
104
|
-
console.log(APP_CONFIG.auth0Domain); // Configured during build from GitHub vars
|
|
105
|
-
console.log(APP_CONFIG.auth0ClientId); // Configured during build from GitHub vars
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
**Key Features:**
|
|
109
|
-
- Values are **statically baked** into the library during build time from GitHub repository variables
|
|
110
|
-
- No runtime configuration needed - values are available immediately
|
|
111
|
-
- Can be used across any framework: Angular, React, Vue, Svelte, vanilla JS
|
|
112
|
-
- Perfect for MicroFrontends (MFEs) and shell applications
|
|
113
|
-
|
|
114
|
-
### Auth0 Authentication
|
|
115
|
-
|
|
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!
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
import { Component, inject } from '@angular/core';
|
|
122
|
-
import { AuthService } from '@opensourcekd/ng-common-libs';
|
|
123
|
-
|
|
124
|
-
@Component({
|
|
125
|
-
selector: 'app-login',
|
|
126
|
-
template: `
|
|
127
|
-
<button (click)="login()">Login with Auth0</button>
|
|
128
|
-
<button (click)="logout()" *ngIf="user">Logout</button>
|
|
129
|
-
<div *ngIf="user">Welcome, {{ user.name }}!</div>
|
|
130
|
-
`
|
|
131
|
-
})
|
|
132
|
-
export class LoginComponent {
|
|
133
|
-
private authService = inject(AuthService);
|
|
134
|
-
user = this.authService.getUser();
|
|
135
|
-
|
|
136
|
-
async login() {
|
|
137
|
-
await this.authService.login();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
async logout() {
|
|
141
|
-
await this.authService.logout();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
See the [Auth0 Service Usage Guide](./docs/AUTH_SERVICE_USAGE.md) for complete integration instructions.
|
|
147
|
-
|
|
148
|
-
### EventBusService
|
|
149
|
-
|
|
150
|
-
Cross-application event communication for MicroFrontend architectures.
|
|
85
|
+
### API URL Access
|
|
151
86
|
|
|
152
|
-
**
|
|
87
|
+
**No configuration needed** - API URL is automatically available:
|
|
153
88
|
|
|
154
89
|
```typescript
|
|
155
|
-
import {
|
|
156
|
-
import { EventBusService } from '@opensourcekd/ng-common-libs';
|
|
157
|
-
|
|
158
|
-
@Component({
|
|
159
|
-
selector: 'app-event-example',
|
|
160
|
-
template: `<button (click)="sendEvent()">Send Event</button>`
|
|
161
|
-
})
|
|
162
|
-
export class EventExampleComponent implements OnInit {
|
|
163
|
-
private eventBus = inject(EventBusService);
|
|
90
|
+
import { getApiUrl } from '@opensourcekd/ng-common-libs';
|
|
164
91
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
console.log('Event received:', event);
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
sendEvent() {
|
|
173
|
-
// Send structured event
|
|
174
|
-
this.eventBus.sendEvent(JSON.stringify({
|
|
175
|
-
type: 'user:action',
|
|
176
|
-
payload: { userId: '123' },
|
|
177
|
-
timestamp: new Date().toISOString()
|
|
178
|
-
}));
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
See the [EventBus Service Usage Guide](./docs/EVENT_BUS_USAGE.md) for advanced patterns and MicroFrontend examples.
|
|
184
|
-
|
|
185
|
-
### For Non-Angular Projects (React, Vue, Svelte, Vanilla JS)
|
|
186
|
-
|
|
187
|
-
Use the framework-agnostic core event bus:
|
|
188
|
-
|
|
189
|
-
```typescript
|
|
190
|
-
// Import from /core
|
|
191
|
-
import { EventBus } from '@opensourcekd/ng-common-libs/core';
|
|
192
|
-
|
|
193
|
-
// Event Bus
|
|
194
|
-
const eventBus = new EventBus();
|
|
195
|
-
eventBus.emit('user:login', { userId: '123' });
|
|
196
|
-
eventBus.on('user:login').subscribe(data => {
|
|
197
|
-
console.log('User logged in:', data);
|
|
198
|
-
});
|
|
92
|
+
// API URL is baked into the library during build from GitHub repository variables
|
|
93
|
+
const apiUrl = getApiUrl();
|
|
94
|
+
const endpoint = `${apiUrl}/users`;
|
|
199
95
|
```
|
|
200
96
|
|
|
201
|
-
|
|
97
|
+
> âšī¸ **Note**: The API URL is configured in GitHub repository variables (API_URL) and baked into the library during the CI/CD build process. No runtime configuration is needed in consuming applications.
|
|
202
98
|
|
|
203
|
-
|
|
204
|
-
import { useEffect } from 'react';
|
|
205
|
-
import { EventBus } from '@opensourcekd/ng-common-libs/core';
|
|
206
|
-
|
|
207
|
-
const eventBus = new EventBus();
|
|
208
|
-
|
|
209
|
-
function MyComponent() {
|
|
210
|
-
useEffect(() => {
|
|
211
|
-
const subscription = eventBus.on('user:login').subscribe(data => {
|
|
212
|
-
console.log('User logged in:', data);
|
|
213
|
-
});
|
|
214
|
-
return () => subscription.unsubscribe();
|
|
215
|
-
}, []);
|
|
99
|
+
## đ Documentation
|
|
216
100
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
101
|
+
- **[CONSUMPTION_GUIDE.md](./CONSUMPTION_GUIDE.md)** - Complete setup guide and API reference
|
|
102
|
+
- **[Auth0 Service Usage](./docs/AUTH_SERVICE_USAGE.md)** - Detailed Auth0 integration
|
|
103
|
+
- **[EventBus Service Usage](./docs/EVENT_BUS_USAGE.md)** - Cross-application event patterns
|
|
104
|
+
- **[Module Federation Guide](./docs/MODULE_FEDERATION.md)** - Runtime sharing configuration
|
|
220
105
|
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
```
|
|
106
|
+
## đ What's Exported
|
|
224
107
|
|
|
225
|
-
|
|
108
|
+
Everything you need from one import:
|
|
226
109
|
|
|
227
110
|
```typescript
|
|
228
|
-
import {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
eventBus.emit('user:login', { userId: '123' });
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
return { handleLogin };
|
|
252
|
-
}
|
|
253
|
-
};
|
|
111
|
+
import {
|
|
112
|
+
// Services
|
|
113
|
+
AuthService,
|
|
114
|
+
EventBusService,
|
|
115
|
+
|
|
116
|
+
// Factory Functions
|
|
117
|
+
getAuthService,
|
|
118
|
+
getEventBusService,
|
|
119
|
+
|
|
120
|
+
// API Access
|
|
121
|
+
getApiUrl,
|
|
122
|
+
|
|
123
|
+
// Core Utilities
|
|
124
|
+
EventBus,
|
|
125
|
+
|
|
126
|
+
// Types & Interfaces
|
|
127
|
+
UserInfo,
|
|
128
|
+
UserData,
|
|
129
|
+
EventPayload,
|
|
130
|
+
} from '@opensourcekd/ng-common-libs';
|
|
254
131
|
```
|
|
255
132
|
|
|
256
|
-
## đ Documentation
|
|
257
|
-
|
|
258
|
-
- **[Auth0 Service Usage](./docs/AUTH_SERVICE_USAGE.md)** - Complete Auth0 authentication integration guide
|
|
259
|
-
- **[EventBus Service Usage](./docs/EVENT_BUS_USAGE.md)** - Cross-application event communication guide
|
|
260
|
-
- **[Deployment Guide](./docs/DEPLOYMENT.md)** - Publishing, versioning, and consumption
|
|
261
|
-
- **[Microapp Triggering Guide](./docs/MICROAPP_TRIGGERING.md)** - Automatic build triggering for consuming microapps
|
|
262
|
-
- **[Module Federation Guide](./docs/MODULE_FEDERATION.md)** - Runtime sharing with Module Federation
|
|
263
|
-
|
|
264
|
-
## đ API Documentation
|
|
265
|
-
|
|
266
|
-
### Core Configuration (Framework-Agnostic)
|
|
267
|
-
|
|
268
|
-
- `APP_CONFIG` - Read-only application configuration object with values statically configured during build time:
|
|
269
|
-
- `auth0Domain: string` - Auth0 tenant domain (from GitHub var `AUTH0_DOMAIN`)
|
|
270
|
-
- `auth0ClientId: string` - Auth0 client ID (from GitHub var `AUTH0_CLIENT_ID`)
|
|
271
|
-
- `apiUrl: string` - API base URL (from GitHub var `API_URL`)
|
|
272
|
-
|
|
273
|
-
### Angular Configuration
|
|
274
|
-
|
|
275
|
-
- `configureAuth0(config: Partial<AUTH0_CONFIG>): void` - Configure Auth0 settings (domain, clientId, etc.)
|
|
276
|
-
- `AUTH0_CONFIG` - Auth0 configuration object (domain, clientId, redirectUri, etc.)
|
|
277
|
-
|
|
278
|
-
### AuthService
|
|
279
|
-
|
|
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
|
|
290
|
-
|
|
291
|
-
### EventBusService
|
|
292
|
-
|
|
293
|
-
- `sendEvent(event: string): void` - Send event to all subscribers
|
|
294
|
-
- `onePlusNEvents: Observable<string>` - Subscribe to all events with replay buffer
|
|
295
|
-
|
|
296
|
-
### EventBus (Core)
|
|
297
|
-
|
|
298
|
-
- `emit<T>(eventType: string, data?: T): void` - Emit an event
|
|
299
|
-
- `on<T>(eventType: string): Observable<T>` - Subscribe to an event
|
|
300
|
-
- `onMultiple(eventTypes: string[]): Observable<EventPayload>` - Subscribe to multiple events
|
|
301
|
-
- `onAll(): Observable<EventPayload>` - Subscribe to all events
|
|
302
|
-
|
|
303
133
|
## đ ī¸ Development
|
|
304
134
|
|
|
305
135
|
```bash
|