@memberjunction/ng-notifications 3.4.0 → 4.1.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.
Files changed (2) hide show
  1. package/README.md +100 -349
  2. package/package.json +12 -12
package/README.md CHANGED
@@ -1,18 +1,6 @@
1
1
  # @memberjunction/ng-notifications
2
2
 
3
- Angular service for handling user notifications in MemberJunction applications, providing both UI notifications and database-backed persistent notifications.
4
-
5
- ## Features
6
-
7
- - **Singleton Service Architecture**: Application-wide notification management with a single instance
8
- - **Dual Notification Types**:
9
- - Temporary UI notifications using Kendo UI
10
- - Persistent database-backed notifications via User Notifications entity
11
- - **Real-time Updates**: Push notification integration for live updates
12
- - **Flexible Styling**: Support for success, error, warning, and info styles
13
- - **Auto-refresh**: Automatic notification refresh on user login
14
- - **Event Integration**: Seamless integration with MemberJunction global events
15
- - **Resource Linking**: Connect notifications to specific resources and records
3
+ Angular singleton service for managing user notifications in MemberJunction applications. Provides both temporary UI notifications (Kendo toasts) and persistent database-backed notifications via the User Notifications entity.
16
4
 
17
5
  ## Installation
18
6
 
@@ -20,380 +8,143 @@ Angular service for handling user notifications in MemberJunction applications,
20
8
  npm install @memberjunction/ng-notifications
21
9
  ```
22
10
 
23
- ## Requirements
24
-
25
- ### Angular Version
26
- - Angular 18.0.2 or higher
27
-
28
- ### Peer Dependencies
29
- - `@angular/common`: ^18.0.2
30
- - `@angular/core`: ^18.0.2
31
- - `@progress/kendo-angular-notification`: ^16.2.0
32
-
33
- ### MemberJunction Dependencies
34
- - `@memberjunction/core`: ^2.43.0
35
- - `@memberjunction/core-entities`: ^2.43.0
36
- - `@memberjunction/global`: ^2.43.0
37
- - `@memberjunction/graphql-dataprovider`: ^2.43.0
11
+ ## Overview
12
+
13
+ The notification service acts as a centralized hub for all notifications across the application. It automatically subscribes to MemberJunction global events, manages real-time push notification updates via GraphQL WebSockets, and maintains an observable stream of unread notification counts.
14
+
15
+ ```mermaid
16
+ flowchart TD
17
+ subgraph Sources["Notification Sources"]
18
+ A["Application Code"]
19
+ B["MJGlobal Events"]
20
+ C["Push Notifications (WebSocket)"]
21
+ end
22
+ subgraph Service["MJNotificationService (Singleton)"]
23
+ D["CreateSimpleNotification()"]
24
+ E["CreateNotification()"]
25
+ F["Notification State"]
26
+ end
27
+ subgraph Outputs["Outputs"]
28
+ G["Kendo UI Toast"]
29
+ H["UserNotification Entity (DB)"]
30
+ I["Notifications$ Observable"]
31
+ J["UnreadCount$ Observable"]
32
+ end
33
+
34
+ A --> D
35
+ A --> E
36
+ B --> D
37
+ C --> F
38
+ D --> G
39
+ E --> H
40
+ F --> I
41
+ F --> J
42
+
43
+ style Sources fill:#2d6a9f,stroke:#1a4971,color:#fff
44
+ style Service fill:#7c5295,stroke:#563a6b,color:#fff
45
+ style Outputs fill:#2d8659,stroke:#1a5c3a,color:#fff
46
+ ```
38
47
 
39
48
  ## Usage
40
49
 
41
- ### Module Setup
42
-
43
- Import the `MJNotificationsModule` in your Angular module:
50
+ ### Module Import
44
51
 
45
52
  ```typescript
46
53
  import { MJNotificationsModule } from '@memberjunction/ng-notifications';
47
54
 
48
55
  @NgModule({
49
- imports: [
50
- // other imports...
51
- MJNotificationsModule
52
- ],
56
+ imports: [MJNotificationsModule]
53
57
  })
54
- export class YourModule { }
58
+ export class YourModule {}
55
59
  ```
56
60
 
57
- ### Service Injection
58
-
59
- The service is automatically provided at the root level, so you can inject it directly:
61
+ ### Simple (Transient) Notifications
60
62
 
61
63
  ```typescript
62
64
  import { MJNotificationService } from '@memberjunction/ng-notifications';
63
65
 
64
- @Component({
65
- selector: 'app-example',
66
- templateUrl: './example.component.html'
67
- })
68
- export class ExampleComponent {
69
- constructor(private notificationService: MJNotificationService) {}
70
-
71
- // Or access the singleton instance
72
- showNotification() {
73
- MJNotificationService.Instance.CreateSimpleNotification(
74
- 'Operation completed',
75
- 'success',
76
- 3000
77
- );
78
- }
79
- }
80
- ```
81
-
82
- ## API Reference
83
-
84
- ### MJNotificationService
85
-
86
- Singleton service for managing notifications across the application.
87
-
88
- #### Methods
89
-
90
- ##### CreateSimpleNotification
91
- Creates a temporary UI notification that displays to the user.
92
-
93
- ```typescript
94
- CreateSimpleNotification(
95
- message: string,
96
- style: "none" | "success" | "error" | "warning" | "info" = "success",
97
- hideAfter?: number
98
- ): void
99
- ```
100
-
101
- **Parameters:**
102
- - `message`: Text to display to the user
103
- - `style`: Visual style of the notification (default: "success")
104
- - `hideAfter`: Optional duration in milliseconds before auto-hiding. If not specified, notification shows a close button
105
-
106
- **Examples:**
107
- ```typescript
108
- // Basic success notification
109
- notificationService.CreateSimpleNotification('Data saved successfully');
110
-
111
- // Error notification that auto-hides after 5 seconds
112
- notificationService.CreateSimpleNotification(
113
- 'Failed to process request',
114
- 'error',
115
- 5000
66
+ // Via singleton instance
67
+ MJNotificationService.Instance.CreateSimpleNotification(
68
+ 'Record saved successfully',
69
+ 'success',
70
+ 3000 // auto-hide after 3 seconds
116
71
  );
117
72
 
118
- // Warning with manual close
119
- notificationService.CreateSimpleNotification(
120
- 'Please review your changes',
121
- 'warning'
73
+ // Error notification without auto-hide
74
+ MJNotificationService.Instance.CreateSimpleNotification(
75
+ 'Failed to load data',
76
+ 'error'
122
77
  );
123
78
  ```
124
79
 
125
- ##### CreateNotification
126
- Creates a persistent notification stored in the database.
127
-
128
- ```typescript
129
- async CreateNotification(
130
- title: string,
131
- message: string,
132
- resourceTypeId: string | null,
133
- resourceRecordId: string | null,
134
- resourceConfiguration: any | null,
135
- displayToUser: boolean = true
136
- ): Promise<UserNotificationEntity>
137
- ```
138
-
139
- **Parameters:**
140
- - `title`: Notification title
141
- - `message`: Notification message content
142
- - `resourceTypeId`: Optional ID of the resource type this notification relates to
143
- - `resourceRecordId`: Optional ID of the specific resource record
144
- - `resourceConfiguration`: Optional configuration object (stored as JSON)
145
- - `displayToUser`: Whether to show a UI notification immediately (default: true)
80
+ ### Persistent (Database) Notifications
146
81
 
147
- **Examples:**
148
82
  ```typescript
149
- // Simple notification
150
- const notification = await notificationService.CreateNotification(
151
- 'Welcome!',
152
- 'Thank you for joining our platform',
153
- null,
154
- null,
155
- null
156
- );
157
-
158
- // Resource-linked notification
159
- const reportNotification = await notificationService.CreateNotification(
160
- 'Report Generated',
161
- 'Your monthly sales report is ready',
162
- reportResourceTypeId,
163
- reportId,
164
- { format: 'pdf', includeCharts: true }
165
- );
166
-
167
- // Silent notification (no immediate UI display)
168
- await notificationService.CreateNotification(
169
- 'Settings Updated',
170
- 'Your preferences have been saved',
171
- null,
172
- null,
173
- null,
174
- false
83
+ const notification = await MJNotificationService.Instance.CreateNotification(
84
+ 'Report Ready',
85
+ 'Your monthly sales report has been generated',
86
+ reportResourceTypeId, // optional resource type ID
87
+ reportId, // optional resource record ID
88
+ { format: 'pdf' }, // optional configuration JSON
89
+ true // display UI notification immediately
175
90
  );
176
91
  ```
177
92
 
178
- ##### PushStatusUpdates
179
- Returns an observable for subscribing to real-time push notification updates.
93
+ ### Accessing Notification State
180
94
 
181
95
  ```typescript
182
- PushStatusUpdates(): Observable<string>
183
- ```
96
+ // All notifications
97
+ const all = MJNotificationService.UserNotifications;
184
98
 
185
- **Example:**
186
- ```typescript
187
- notificationService.PushStatusUpdates().subscribe(status => {
188
- const statusObj = JSON.parse(status.message);
189
- console.log('Push update received:', statusObj);
190
- });
191
- ```
192
-
193
- #### Static Methods
194
-
195
- ##### RefreshUserNotifications
196
- Manually refreshes the user's notifications from the database.
99
+ // Unread only
100
+ const unread = MJNotificationService.UnreadUserNotifications;
197
101
 
198
- ```typescript
199
- static async RefreshUserNotifications(): Promise<void>
200
- ```
102
+ // Unread count
103
+ const count = MJNotificationService.UnreadUserNotificationCount;
201
104
 
202
- **Example:**
203
- ```typescript
105
+ // Refresh from server
204
106
  await MJNotificationService.RefreshUserNotifications();
205
- console.log('Notifications refreshed');
206
- ```
207
-
208
- #### Static Properties
209
-
210
- ##### Instance
211
- Access the singleton instance of the notification service.
212
-
213
- ```typescript
214
- static get Instance(): MJNotificationService
215
- ```
216
-
217
- ##### UserNotifications
218
- Get all notifications for the current user.
219
-
220
- ```typescript
221
- static get UserNotifications(): UserNotificationEntity[]
222
- ```
223
-
224
- ##### UnreadUserNotifications
225
- Get only unread notifications.
226
-
227
- ```typescript
228
- static get UnreadUserNotifications(): UserNotificationEntity[]
229
107
  ```
230
108
 
231
- ##### UnreadUserNotificationCount
232
- Get the count of unread notifications.
233
-
234
- ```typescript
235
- static get UnreadUserNotificationCount(): number
236
- ```
109
+ ## API Reference
237
110
 
238
- **Example:**
239
- ```typescript
240
- // Display unread count in UI
241
- const unreadCount = MJNotificationService.UnreadUserNotificationCount;
242
- console.log(`You have ${unreadCount} unread notifications`);
111
+ ### MJNotificationService
243
112
 
244
- // Process unread notifications
245
- const unread = MJNotificationService.UnreadUserNotifications;
246
- unread.forEach(notification => {
247
- console.log(notification.Title, notification.Message);
248
- });
249
- ```
113
+ | Method | Description |
114
+ |--------|-------------|
115
+ | `CreateSimpleNotification(message, style?, hideAfter?)` | Display a temporary toast notification |
116
+ | `CreateNotification(title, message, resourceTypeId?, resourceRecordId?, config?, displayToUser?)` | Create a persistent notification in the database |
117
+ | `PushStatusUpdates()` | Returns an Observable for real-time push notifications |
118
+
119
+ | Static Property | Type | Description |
120
+ |-----------------|------|-------------|
121
+ | `Instance` | `MJNotificationService` | Singleton instance |
122
+ | `UserNotifications` | `UserNotificationEntity[]` | All user notifications |
123
+ | `UnreadUserNotifications` | `UserNotificationEntity[]` | Unread notifications only |
124
+ | `UnreadUserNotificationCount` | `number` | Count of unread notifications |
125
+
126
+ ### Notification Styles
127
+
128
+ | Style | Use Case |
129
+ |-------|----------|
130
+ | `'success'` | Completed operations, confirmations |
131
+ | `'error'` | Failed operations, validation errors |
132
+ | `'warning'` | Important notices requiring attention |
133
+ | `'info'` | General information |
134
+ | `'none'` | Unstyled notification |
250
135
 
251
136
  ## Event Integration
252
137
 
253
- The service automatically integrates with MemberJunction global events:
254
-
255
- ### Handled Events
256
-
257
- 1. **MJEventType.LoggedIn**
258
- - Refreshes user notifications from the database
259
- - Subscribes to push notification updates
260
-
261
- 2. **MJEventType.DisplaySimpleNotificationRequest**
262
- - Displays notifications triggered from other parts of the application
263
- - Allows centralized notification handling
264
-
265
- 3. **MJEventType.ComponentEvent** (code: "UserNotificationsUpdated")
266
- - Refreshes the notification list when updates occur
267
-
268
- ### Push Notification Handling
269
-
270
- The service processes push notifications for:
271
- - **User Notifications**: Automatically refreshes when new notifications are created
272
- - **Other Types**: Displays as simple notifications (except for specific system types)
273
-
274
- ## Best Practices
275
-
276
- ### 1. Use Appropriate Notification Types
277
-
278
- ```typescript
279
- // Use simple notifications for transient messages
280
- this.notificationService.CreateSimpleNotification(
281
- 'File uploaded successfully',
282
- 'success',
283
- 3000
284
- );
285
-
286
- // Use database notifications for important persistent messages
287
- await this.notificationService.CreateNotification(
288
- 'Invoice Due',
289
- 'Invoice #1234 is due in 3 days',
290
- invoiceResourceTypeId,
291
- invoiceId,
292
- { dueDate: '2024-01-15', amount: 1500 }
293
- );
294
- ```
295
-
296
- ### 2. Handle Errors Gracefully
297
-
298
- ```typescript
299
- try {
300
- await this.notificationService.CreateNotification(
301
- 'Task Complete',
302
- 'Your scheduled task has finished',
303
- null,
304
- null,
305
- null
306
- );
307
- } catch (error) {
308
- // Fall back to simple notification on error
309
- this.notificationService.CreateSimpleNotification(
310
- 'Could not save notification',
311
- 'error',
312
- 5000
313
- );
314
- }
315
- ```
316
-
317
- ### 3. Leverage Resource Linking
318
-
319
- When notifications relate to specific entities or resources, always include the resource information:
320
-
321
- ```typescript
322
- // Link to a specific record
323
- await this.notificationService.CreateNotification(
324
- 'Order Shipped',
325
- `Order ${orderNumber} has been shipped`,
326
- orderResourceTypeId,
327
- orderId,
328
- { trackingNumber: 'ABC123', carrier: 'FedEx' }
329
- );
330
- ```
331
-
332
- ### 4. Use Consistent Styling
333
-
334
- - **Success**: Completed operations, confirmations
335
- - **Error**: Failed operations, validation errors
336
- - **Warning**: Important notices, confirmations needed
337
- - **Info**: General information, tips
338
-
339
- ### 5. Consider Auto-hide Duration
340
-
341
- ```typescript
342
- // Quick confirmations: 2-3 seconds
343
- this.notificationService.CreateSimpleNotification('Saved', 'success', 2000);
344
-
345
- // Important messages: 5+ seconds or manual close
346
- this.notificationService.CreateSimpleNotification(
347
- 'Please review the validation errors below',
348
- 'warning'
349
- );
350
- ```
351
-
352
- ## Integration with MemberJunction
353
-
354
- ### User Context
355
-
356
- The service automatically uses the current user context from MemberJunction metadata:
357
-
358
- ```typescript
359
- // Notifications are automatically associated with the current user
360
- const notification = await this.notificationService.CreateNotification(
361
- 'Personal Alert',
362
- 'This is just for you',
363
- null,
364
- null,
365
- null
366
- );
367
- // notification.UserID is automatically set to the current user
368
- ```
369
-
370
- ### Entity Integration
371
-
372
- Notifications are stored as `UserNotificationEntity` objects, allowing full entity operations:
373
-
374
- ```typescript
375
- // Mark notification as read
376
- const notification = MJNotificationService.UnreadUserNotifications[0];
377
- notification.Unread = false;
378
- await notification.Save();
379
-
380
- // Delete old notifications
381
- const oldNotifications = MJNotificationService.UserNotifications
382
- .filter(n => n.CreatedAt < someDate);
383
- for (const notif of oldNotifications) {
384
- await notif.Delete();
385
- }
386
- ```
387
-
388
- ## Module Exports
138
+ The service automatically handles these MJGlobal events:
389
139
 
390
- The package exports:
391
- - `MJNotificationsModule` - The Angular module to import
392
- - `MJNotificationService` - The notification service
140
+ - **`MJEventType.LoggedIn`** -- Refreshes notifications and subscribes to push updates
141
+ - **`MJEventType.DisplaySimpleNotificationRequest`** -- Displays notifications from any part of the application
142
+ - **`MJEventType.ComponentEvent`** (`UserNotificationsUpdated`) -- Refreshes the notification list
393
143
 
394
- ## Support
144
+ ## Dependencies
395
145
 
396
- For issues or questions:
397
- - Check the [MemberJunction documentation](https://docs.memberjunction.com)
398
- - Submit issues to the [GitHub repository](https://github.com/MemberJunction/MJ)
399
- - Contact MemberJunction support
146
+ - [@memberjunction/core](../../MJCore/README.md) -- Metadata, UserInfo
147
+ - [@memberjunction/core-entities](../../MJCoreEntities/README.md) -- UserNotificationEntity
148
+ - [@memberjunction/global](../../MJGlobal/README.md) -- MJGlobal event system
149
+ - [@memberjunction/graphql-dataprovider](../../GraphQLDataProvider/README.md) -- Push notification subscriptions
150
+ - `@progress/kendo-angular-notification` -- Toast notification rendering
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/ng-notifications",
3
- "version": "3.4.0",
3
+ "version": "4.1.0",
4
4
  "description": "MemberJunction: Simple Angular library for displaying user notifications",
5
5
  "main": "./dist/public-api.js",
6
6
  "typings": "./dist/public-api.d.ts",
@@ -15,21 +15,21 @@
15
15
  "author": "",
16
16
  "license": "ISC",
17
17
  "devDependencies": {
18
- "@angular/compiler": "18.2.14",
19
- "@angular/compiler-cli": "18.2.14"
18
+ "@angular/compiler": "21.1.3",
19
+ "@angular/compiler-cli": "21.1.3"
20
20
  },
21
21
  "peerDependencies": {
22
- "@angular/common": "18.2.14",
23
- "@angular/core": "18.2.14",
24
- "@progress/kendo-angular-notification": "16.2.0"
22
+ "@angular/common": "21.1.3",
23
+ "@angular/core": "21.1.3",
24
+ "@progress/kendo-angular-notification": "22.0.1"
25
25
  },
26
26
  "dependencies": {
27
- "@memberjunction/core": "3.4.0",
28
- "@memberjunction/core-entities": "3.4.0",
29
- "@memberjunction/global": "3.4.0",
30
- "@memberjunction/graphql-dataprovider": "3.4.0",
31
- "tslib": "^2.3.0",
32
- "rxjs": "^7.8.1"
27
+ "@memberjunction/core": "4.1.0",
28
+ "@memberjunction/core-entities": "4.1.0",
29
+ "@memberjunction/global": "4.1.0",
30
+ "@memberjunction/graphql-dataprovider": "4.1.0",
31
+ "tslib": "^2.8.1",
32
+ "rxjs": "^7.8.2"
33
33
  },
34
34
  "sideEffects": false,
35
35
  "repository": {