mesauth-angular 1.1.3 β†’ 1.1.5

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/package.json CHANGED
@@ -1,37 +1,44 @@
1
- {
2
- "name": "mesauth-angular",
3
- "version": "1.1.3",
4
- "description": "Angular helper library to connect to a backend API and SignalR hub to surface the current logged-in user and incoming notifications with dark/light theme support",
5
- "main": "dist/fesm2022/mesauth-angular.mjs",
6
- "types": "dist/index.d.ts",
7
- "files": ["dist"],
8
- "scripts": {
9
- "build": "ng-packagr -p ng-package.json",
10
- "prepare": "npm run build"
11
- },
12
- "keywords": ["angular","signalr","notifications","auth","mes"],
13
- "license": "MIT",
14
- "peerDependencies": {
15
- "@angular/core": "^20.0.0",
16
- "@angular/common": "^20.0.0",
17
- "@angular/router": "^20.0.0",
18
- "rxjs": "^7"
19
- },
20
- "dependencies": {
21
- "@microsoft/signalr": "^7.0.0",
22
- "rxjs": "^7.5.0"
23
- },
24
- "devDependencies": {
25
- "@angular/compiler-cli": "^20.0.0",
26
- "@angular/compiler": "^20.0.0",
27
- "@angular/core": "^20.0.0",
28
- "@angular/common": "^20.0.0",
29
- "@angular/router": "^20.0.0",
30
- "typescript": "~5.8.0",
31
- "tslib": "^2.0.0",
32
- "ng-packagr": "^20.0.0"
33
- },
34
- "angularCompilerOptions": {
35
- "enableIvy": true
36
- }
37
- }
1
+ {
2
+ "name": "mesauth-angular",
3
+ "version": "1.1.5",
4
+ "description": "Angular helper library to connect to a backend API and SignalR hub to surface the current logged-in user and incoming notifications with dark/light theme support",
5
+ "main": "dist/fesm2022/mesauth-angular.mjs",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "keywords": [
11
+ "angular",
12
+ "signalr",
13
+ "notifications",
14
+ "auth",
15
+ "mes"
16
+ ],
17
+ "license": "MIT",
18
+ "peerDependencies": {
19
+ "@angular/core": "^20.0.0",
20
+ "@angular/common": "^20.0.0",
21
+ "@angular/router": "^20.0.0",
22
+ "rxjs": "^7"
23
+ },
24
+ "dependencies": {
25
+ "@microsoft/signalr": "^7.0.0",
26
+ "rxjs": "^7.5.0",
27
+ "tslib": "^2.3.0"
28
+ },
29
+ "angularCompilerOptions": {
30
+ "enableIvy": true
31
+ },
32
+ "module": "fesm2022/mesauth-angular.mjs",
33
+ "typings": "index.d.ts",
34
+ "exports": {
35
+ "./package.json": {
36
+ "default": "./package.json"
37
+ },
38
+ ".": {
39
+ "types": "./index.d.ts",
40
+ "default": "./fesm2022/mesauth-angular.mjs"
41
+ }
42
+ },
43
+ "sideEffects": false
44
+ }
package/dist/README.md DELETED
@@ -1,291 +0,0 @@
1
- # mesauth-angular
2
-
3
- Angular helper library to connect to a backend API and SignalR hub to surface the current logged-in user and incoming notifications with dark/light theme support.
4
-
5
- ## Changelog
6
-
7
- ### v1.1.0 (2026-01-21) - **Major Update**
8
- - πŸš€ **New `provideMesAuth()` Function**: Simplified setup with a single function call
9
- - ✨ **Functional Interceptor**: New `mesAuthInterceptor` for better compatibility with standalone apps
10
- - πŸ“¦ **Automatic Initialization**: `provideMesAuth()` handles service initialization via `APP_INITIALIZER`
11
- - πŸ”§ **Simplified API**: Just pass `apiBaseUrl` and `userBaseUrl` - no manual DI required
12
-
13
- ### v1.0.1 (2026-01-21)
14
- - πŸ”§ Internal refactoring for better module compatibility
15
-
16
- ### v0.2.28 (2026-01-19)
17
- - ✨ **Enhanced Avatar Support**: Direct `avatarPath` usage from user data for instant display without backend calls
18
- - πŸ”„ **Improved Avatar Refresh**: Timestamp-based cache busting prevents request cancellation issues
19
- - 🎯 **Better Change Detection**: Signal-based user updates with `ChangeDetectorRef` for reliable UI updates
20
-
21
- ### v0.2.27 (2026-01-19)
22
- - πŸ› Fixed avatar refresh issues in header components
23
- - πŸ“¦ Improved build process and dependencies
24
-
25
- ## Features
26
-
27
- - πŸ” **Authentication**: User login/logout with API integration
28
- - πŸ”” **Real-time Notifications**: SignalR integration for live notifications
29
- - 🎨 **Dark/Light Theme**: Automatic theme detection and support
30
- - πŸ–ΌοΈ **Avatar Support**: Direct API-based avatar loading
31
- - 🍞 **Toast Notifications**: In-app notification toasts
32
- - πŸ›‘οΈ **HTTP Interceptor**: Automatic 401/403 error handling with redirects
33
-
34
- ## Quick Start (v1.1.0+)
35
-
36
- ### 1. Install
37
-
38
- ```bash
39
- npm install mesauth-angular
40
- ```
41
-
42
- ### 2. Configure in app.config.ts (Recommended for Angular 14+)
43
-
44
- ```ts
45
- import { ApplicationConfig } from '@angular/core';
46
- import { provideHttpClient, withInterceptors } from '@angular/common/http';
47
- import { provideMesAuth, mesAuthInterceptor } from 'mesauth-angular';
48
-
49
- export const appConfig: ApplicationConfig = {
50
- providers: [
51
- provideHttpClient(
52
- withInterceptors([mesAuthInterceptor]) // Handles 401/403 redirects
53
- ),
54
- provideMesAuth({
55
- apiBaseUrl: 'https://mes.kefico.vn/auth',
56
- userBaseUrl: 'https://mes.kefico.vn/x' // For login/403 redirects
57
- })
58
- ]
59
- };
60
- ```
61
-
62
- That's it! The library handles:
63
- - Service initialization via `APP_INITIALIZER`
64
- - `HttpClient` and `Router` injection automatically
65
- - 401 β†’ redirects to `{userBaseUrl}/login?returnUrl=...`
66
- - 403 β†’ redirects to `{userBaseUrl}/403?returnUrl=...`
67
-
68
- ### 3. Use in Components
69
-
70
- ```ts
71
- import { MesAuthService } from 'mesauth-angular';
72
-
73
- @Component({...})
74
- export class MyComponent {
75
- private auth = inject(MesAuthService);
76
-
77
- // Observable streams
78
- currentUser$ = this.auth.currentUser$;
79
- notifications$ = this.auth.notifications$;
80
-
81
- logout() {
82
- this.auth.logout().subscribe();
83
- }
84
- }
85
- ```
86
-
87
- ## Configuration Options
88
-
89
- ```ts
90
- interface MesAuthConfig {
91
- apiBaseUrl: string; // Required: MesAuth API base URL
92
- userBaseUrl?: string; // Optional: Base URL for login/403 redirects
93
- withCredentials?: boolean; // Optional: Send cookies (default: true)
94
- }
95
- ```
96
-
97
- ## Theme Support
98
-
99
- The library automatically detects and adapts to your application's theme:
100
-
101
- ### Automatic Theme Detection
102
- The library checks for theme indicators on the `<html>` element:
103
- - `class="dark"`
104
- - `data-theme="dark"`
105
- - `theme="dark"`
106
- - `data-coreui-theme="dark"`
107
-
108
- ### Dynamic Theme Changes
109
- Theme changes are detected in real-time using `MutationObserver`, so components automatically update when your app switches themes.
110
-
111
- ### Manual Theme Control
112
- ```ts
113
- import { ThemeService } from 'mesauth-angular';
114
-
115
- // Check current theme
116
- const currentTheme = themeService.currentTheme; // 'light' | 'dark'
117
-
118
- // Manually set theme
119
- themeService.setTheme('dark');
120
-
121
- // Listen for theme changes
122
- themeService.currentTheme$.subscribe(theme => {
123
- console.log('Theme changed to:', theme);
124
- });
125
- ```
126
-
127
- ## Avatar Loading
128
-
129
- Avatars are loaded efficiently using multiple strategies:
130
-
131
- ### Primary Method: Direct Path Usage
132
- If the user object contains an `avatarPath`, it's used directly:
133
- - **Full URLs**: Used as-is (e.g., `https://example.com/avatar.jpg`)
134
- - **Relative Paths**: Combined with API base URL (e.g., `/uploads/avatar.jpg` β†’ `{apiBaseUrl}/uploads/avatar.jpg`)
135
-
136
- ### Fallback Method: API Endpoint
137
- If no `avatarPath` is available, avatars are loaded via API:
138
- - **API Endpoint**: `GET {apiBaseUrl}/auth/{userId}/avatar`
139
- - **Authentication**: Uses the same credentials as other API calls
140
-
141
- ### Cache Busting
142
- Avatar URLs include timestamps to prevent browser caching issues during updates:
143
- - Automatic refresh when user data changes
144
- - Manual refresh triggers for upload/delete operations
145
-
146
- ### Fallback Service
147
- - **UI Avatars**: Generates initials-based avatars if no user data available
148
- - **Authentication**: Not required for fallback avatars
149
-
150
- ## Components
151
-
152
- **Note:** All components are standalone and can be imported directly.
153
-
154
- ### ma-user-profile
155
-
156
- A reusable Angular component for displaying the current user's profile information, with options for navigation and logout.
157
-
158
- - **Description**: Renders user details (e.g., name, avatar) fetched via the MesAuthService. Supports custom event handlers for navigation and logout actions.
159
- - **Inputs**: None (data is sourced from the MesAuthService).
160
- - **Outputs**:
161
- - `onNavigate`: Emits an event when the user triggers navigation (e.g., to a profile page). Pass a handler to define behavior.
162
- - `onLogout`: Emits an event when the user logs out. Pass a handler to perform logout logic (e.g., clear tokens, redirect).
163
- - **Usage Example**:
164
-
165
- ```html
166
- <ma-user-profile
167
- (onNavigate)="handleNavigation($event)"
168
- (onLogout)="handleLogout()">
169
- </ma-user-profile>
170
- ```
171
-
172
- In your component's TypeScript file:
173
-
174
- ```ts
175
- handleNavigation(event: any) {
176
- // Navigate to user profile page
177
- this.router.navigate(['/profile']);
178
- }
179
-
180
- handleLogout() {
181
- // Perform logout, e.g., clear session and redirect
182
- this.mesAuth.logout(); // Assuming a logout method exists
183
- this.router.navigate(['/login']);
184
- }
185
- ```
186
-
187
- ### ma-notification-panel
188
-
189
- A standalone component for displaying a slide-out notification panel with real-time updates.
190
-
191
- - **Description**: Shows a list of notifications, allows marking as read/delete, and integrates with toast notifications for new alerts.
192
- - **Inputs**: None.
193
- - **Outputs**: None (uses internal methods for actions).
194
- - **Usage Example**:
195
-
196
- ```html
197
- <ma-notification-panel #notificationPanel></ma-notification-panel>
198
- ```
199
-
200
- In your component:
201
-
202
- ```ts
203
- // To open the panel
204
- notificationPanel.open();
205
- ```
206
-
207
- ## Migration Guide
208
-
209
- ### Upgrading from v0.x to v1.1.0+
210
-
211
- The setup has been greatly simplified. Here's how to migrate:
212
-
213
- **Before (v0.x):**
214
- ```ts
215
- // app.config.ts - OLD WAY
216
- import { MesAuthModule, MesAuthService } from 'mesauth-angular';
217
- import { HTTP_INTERCEPTORS } from '@angular/common/http';
218
-
219
- export const appConfig: ApplicationConfig = {
220
- providers: [
221
- importProvidersFrom(MesAuthModule),
222
- { provide: HTTP_INTERCEPTORS, useClass: MesAuthInterceptor, multi: true }
223
- ]
224
- };
225
-
226
- // app.component.ts - OLD WAY
227
- export class AppComponent {
228
- constructor() {
229
- this.mesAuthService.init({
230
- apiBaseUrl: '...',
231
- userBaseUrl: '...'
232
- }, inject(HttpClient), inject(Router));
233
- }
234
- }
235
- ```
236
-
237
- **After (v1.1.0+):**
238
- ```ts
239
- // app.config.ts - NEW WAY (everything in one place!)
240
- import { provideMesAuth, mesAuthInterceptor } from 'mesauth-angular';
241
-
242
- export const appConfig: ApplicationConfig = {
243
- providers: [
244
- provideHttpClient(withInterceptors([mesAuthInterceptor])),
245
- provideMesAuth({
246
- apiBaseUrl: 'https://mes.kefico.vn/auth',
247
- userBaseUrl: 'https://mes.kefico.vn/x'
248
- })
249
- ]
250
- };
251
-
252
- // app.component.ts - No init() needed!
253
- export class AppComponent {
254
- // Just inject and use - no manual initialization required
255
- }
256
- ```
257
-
258
- **Key Changes:**
259
- - `provideMesAuth()` replaces `MesAuthModule` + manual `init()` call
260
- - `mesAuthInterceptor` (functional) replaces `MesAuthInterceptor` (class-based)
261
- - No need to inject `HttpClient` or `Router` manually
262
- - Configuration moved from `AppComponent` to `app.config.ts`
263
-
264
- ## Troubleshooting
265
-
266
- ### JIT Compiler Error in Production or AOT Mode
267
- If you encounter an error like "The injectable 'MesAuthService' needs to be compiled using the JIT compiler, but '@angular/compiler' is not available," this typically occurs because:
268
- - The package is being imported directly from source code (e.g., during development) without building it first.
269
- - The client app is running in AOT (Ahead-of-Time) compilation mode, which requires pre-compiled libraries.
270
-
271
- **Solutions:**
272
- 1. **Build the package for production/AOT compatibility:**
273
- - Ensure you have built the package using `npm run build` (which uses ng-packagr or similar to generate AOT-ready code).
274
- - Install the built package via npm (e.g., from a local tarball or registry) instead of linking to the source folder.
275
-
276
- 2. **For development (if you must link to source):**
277
- - Switch your Angular app to JIT mode by bootstrapping with `@angular/platform-browser-dynamic` instead of `@angular/platform-browser`.
278
-
279
- 3. **Verify imports:**
280
- - Ensure you're importing from the built package (e.g., `import { MesAuthService } from 'mesauth-angular';`) and not from the `src` folder.
281
-
282
- ### Components Appear Empty
283
- If components like `ma-user` or `ma-user-profile` render as empty:
284
- - Ensure `provideMesAuth()` is called in your `app.config.ts`.
285
- - Check browser console for logs from components.
286
- - If `currentUser` is null, the component shows a login buttonβ€”verify the API returns user data.
287
-
288
- ## Notes
289
- - The service expects an endpoint `GET {apiBaseUrl}/auth/me` that returns the current user.
290
- - Avatar endpoint: `GET {apiBaseUrl}/auth/{userId}/avatar`
291
- - SignalR events used: `ReceiveNotification` (adjust to your backend).