@opensourcekd/ng-common-libs 2.0.1 โ 2.0.3
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 +65 -58
- package/dist/index.cjs +114 -499
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +123 -280
- package/dist/index.mjs +112 -497
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -3
package/README.md
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
# ng-common-libs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Pure TypeScript library with Auth0 authentication service and framework-agnostic event bus.
|
|
4
4
|
|
|
5
5
|
## ๐ฏ Simple Architecture
|
|
6
6
|
|
|
7
|
-
**One import path. Everything you need.**
|
|
7
|
+
**One import path. Everything you need. Framework-agnostic.**
|
|
8
8
|
|
|
9
9
|
All services, utilities, and types are exported from a single package:
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
12
|
import {
|
|
13
13
|
AuthService,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
getApiUrl,
|
|
18
|
-
UserInfo,
|
|
19
|
-
EventBus
|
|
14
|
+
EventBus,
|
|
15
|
+
APP_CONFIG,
|
|
16
|
+
UserInfo
|
|
20
17
|
} from '@opensourcekd/ng-common-libs';
|
|
21
18
|
```
|
|
22
19
|
|
|
@@ -24,11 +21,11 @@ import {
|
|
|
24
21
|
|
|
25
22
|
## ๐ Features
|
|
26
23
|
|
|
27
|
-
- **AuthService**: Complete Auth0 authentication with token management
|
|
28
|
-
- **
|
|
24
|
+
- **AuthService**: Complete Auth0 authentication with token management (Pure TypeScript - no Angular dependency)
|
|
25
|
+
- **EventBus**: Framework-agnostic event bus using RxJS
|
|
26
|
+
- **Works with any framework**: Angular, React, Vue, Svelte, vanilla JS
|
|
29
27
|
- **Module Federation Support**: Singleton pattern works across shell + MFEs
|
|
30
|
-
- **
|
|
31
|
-
- **Framework-Agnostic Core**: EventBus can be used in React, Vue, or vanilla JS
|
|
28
|
+
- **Zero Framework Lock-in**: Core services are pure TypeScript classes
|
|
32
29
|
|
|
33
30
|
## ๐ฆ Installation
|
|
34
31
|
|
|
@@ -40,46 +37,31 @@ npm install @opensourcekd/ng-common-libs
|
|
|
40
37
|
|
|
41
38
|
## ๐ง Quick Start
|
|
42
39
|
|
|
43
|
-
###
|
|
44
|
-
|
|
45
|
-
**In your shell app AND each MFE's `app.config.ts`:**
|
|
40
|
+
### Pure TypeScript Usage (Framework-Agnostic)
|
|
46
41
|
|
|
47
42
|
```typescript
|
|
48
|
-
import {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export const appConfig: ApplicationConfig = {
|
|
59
|
-
providers: [
|
|
60
|
-
// Factory functions ensure singleton across all MFEs
|
|
61
|
-
{ provide: EventBusService, useFactory: getEventBusService },
|
|
62
|
-
{ provide: AuthService, useFactory: getAuthService },
|
|
63
|
-
]
|
|
43
|
+
import { AuthService, EventBus } from '@opensourcekd/ng-common-libs';
|
|
44
|
+
|
|
45
|
+
// Create instances
|
|
46
|
+
const eventBus = new EventBus();
|
|
47
|
+
const authConfig = {
|
|
48
|
+
domain: 'your-domain.auth0.com',
|
|
49
|
+
clientId: 'your-client-id',
|
|
50
|
+
redirectUri: window.location.origin,
|
|
51
|
+
logoutUri: window.location.origin,
|
|
52
|
+
scope: 'openid profile email'
|
|
64
53
|
};
|
|
65
|
-
|
|
66
|
-
|
|
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.
|
|
54
|
+
const authService = new AuthService(authConfig, eventBus);
|
|
69
55
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
import { Component, inject } from '@angular/core';
|
|
75
|
-
import { AuthService, EventBusService } from '@opensourcekd/ng-common-libs';
|
|
56
|
+
// Use the service
|
|
57
|
+
await authService.login();
|
|
58
|
+
const user = authService.getUser();
|
|
59
|
+
const token = await authService.getToken();
|
|
76
60
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
login() { this.authService.login(); }
|
|
82
|
-
}
|
|
61
|
+
// Subscribe to events
|
|
62
|
+
eventBus.on('auth:login_success').subscribe(data => {
|
|
63
|
+
console.log('User logged in:', data);
|
|
64
|
+
});
|
|
83
65
|
```
|
|
84
66
|
|
|
85
67
|
### API URL Access
|
|
@@ -87,10 +69,10 @@ export class MyComponent {
|
|
|
87
69
|
**No configuration needed** - API URL is automatically available:
|
|
88
70
|
|
|
89
71
|
```typescript
|
|
90
|
-
import {
|
|
72
|
+
import { APP_CONFIG } from '@opensourcekd/ng-common-libs';
|
|
91
73
|
|
|
92
74
|
// API URL is baked into the library during build from GitHub repository variables
|
|
93
|
-
const apiUrl =
|
|
75
|
+
const apiUrl = APP_CONFIG.apiUrl;
|
|
94
76
|
const endpoint = `${apiUrl}/users`;
|
|
95
77
|
```
|
|
96
78
|
|
|
@@ -111,22 +93,29 @@ Everything you need from one import:
|
|
|
111
93
|
import {
|
|
112
94
|
// Services
|
|
113
95
|
AuthService,
|
|
114
|
-
|
|
96
|
+
EventBus,
|
|
115
97
|
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
98
|
+
// Configuration
|
|
99
|
+
APP_CONFIG,
|
|
100
|
+
AUTH0_CONFIG,
|
|
101
|
+
STORAGE_CONFIG,
|
|
102
|
+
STORAGE_KEYS,
|
|
119
103
|
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
EventBus,
|
|
104
|
+
// Utilities
|
|
105
|
+
getStorageItem,
|
|
106
|
+
setStorageItem,
|
|
107
|
+
removeStorageItem,
|
|
125
108
|
|
|
126
109
|
// Types & Interfaces
|
|
127
110
|
UserInfo,
|
|
128
111
|
UserData,
|
|
129
112
|
EventPayload,
|
|
113
|
+
Auth0Config,
|
|
114
|
+
StorageConfig,
|
|
115
|
+
StorageKeys,
|
|
116
|
+
AppState,
|
|
117
|
+
AuthorizationParams,
|
|
118
|
+
CallbackResult,
|
|
130
119
|
} from '@opensourcekd/ng-common-libs';
|
|
131
120
|
```
|
|
132
121
|
|
|
@@ -141,8 +130,26 @@ npm run build
|
|
|
141
130
|
|
|
142
131
|
# Run linter
|
|
143
132
|
npm run lint
|
|
133
|
+
|
|
134
|
+
# Run tests
|
|
135
|
+
npm test
|
|
136
|
+
|
|
137
|
+
# Run tests with coverage
|
|
138
|
+
npm run test:coverage
|
|
139
|
+
|
|
140
|
+
# Run tests in watch mode
|
|
141
|
+
npm run test:watch
|
|
144
142
|
```
|
|
145
143
|
|
|
144
|
+
## ๐งช Testing
|
|
145
|
+
|
|
146
|
+
This library maintains high test coverage:
|
|
147
|
+
- **99.26%** statement coverage
|
|
148
|
+
- **83.45%** branch coverage
|
|
149
|
+
- **100%** function coverage
|
|
150
|
+
|
|
151
|
+
All core utilities and services are thoroughly tested using Jest and Angular testing utilities.
|
|
152
|
+
|
|
146
153
|
## ๐ License
|
|
147
154
|
|
|
148
155
|
MIT
|