@memberjunction/ng-notifications 2.43.0 → 2.45.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 +316 -64
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -4,13 +4,15 @@ Angular service for handling user notifications in MemberJunction applications,
4
4
 
5
5
  ## Features
6
6
 
7
- - Singleton notification service for consistent application-wide notifications
8
- - Support for temporary UI notifications
9
- - Database-backed persistent user notifications
10
- - Real-time push notification updates
11
- - Notification styling options (success, error, warning, info)
12
- - Automatic notification refresh on login
13
- - Unread notification tracking
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
14
16
 
15
17
  ## Installation
16
18
 
@@ -18,86 +20,154 @@ Angular service for handling user notifications in MemberJunction applications,
18
20
  npm install @memberjunction/ng-notifications
19
21
  ```
20
22
 
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
38
+
21
39
  ## Usage
22
40
 
23
- The service is automatically provided at the root level, so you can inject it directly into your components:
41
+ ### Module Setup
42
+
43
+ Import the `MJNotificationsModule` in your Angular module:
44
+
45
+ ```typescript
46
+ import { MJNotificationsModule } from '@memberjunction/ng-notifications';
47
+
48
+ @NgModule({
49
+ imports: [
50
+ // other imports...
51
+ MJNotificationsModule
52
+ ],
53
+ })
54
+ export class YourModule { }
55
+ ```
56
+
57
+ ### Service Injection
58
+
59
+ The service is automatically provided at the root level, so you can inject it directly:
24
60
 
25
61
  ```typescript
26
62
  import { MJNotificationService } from '@memberjunction/ng-notifications';
27
63
 
28
64
  @Component({
29
- // ...
65
+ selector: 'app-example',
66
+ templateUrl: './example.component.html'
30
67
  })
31
- export class YourComponent {
32
- constructor(private notificationService: MJNotificationService) {
33
- // Use the service directly
34
- }
68
+ export class ExampleComponent {
69
+ constructor(private notificationService: MJNotificationService) {}
35
70
 
36
71
  // Or access the singleton instance
37
72
  showNotification() {
38
- MJNotificationService.Instance.CreateSimpleNotification('Operation completed', 'success', 3000);
73
+ MJNotificationService.Instance.CreateSimpleNotification(
74
+ 'Operation completed',
75
+ 'success',
76
+ 3000
77
+ );
39
78
  }
40
79
  }
41
80
  ```
42
81
 
43
- ## Features
82
+ ## API Reference
44
83
 
45
- ### Simple UI Notifications
84
+ ### MJNotificationService
46
85
 
47
- Display temporary notifications to the user:
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.
48
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:**
49
107
  ```typescript
50
108
  // Basic success notification
51
- notificationService.CreateSimpleNotification('Operation completed successfully');
109
+ notificationService.CreateSimpleNotification('Data saved successfully');
52
110
 
53
- // Error notification that disappears after 5 seconds
111
+ // Error notification that auto-hides after 5 seconds
54
112
  notificationService.CreateSimpleNotification(
55
- 'An error occurred while processing your request',
113
+ 'Failed to process request',
56
114
  'error',
57
115
  5000
58
116
  );
59
117
 
60
- // Warning notification with manual close button
118
+ // Warning with manual close
61
119
  notificationService.CreateSimpleNotification(
62
- 'Please verify your input data',
120
+ 'Please review your changes',
63
121
  'warning'
64
122
  );
65
-
66
- // Informational notification
67
- notificationService.CreateSimpleNotification(
68
- 'New updates are available',
69
- 'info',
70
- 3000
71
- );
72
123
  ```
73
124
 
74
- ### Persistent Database Notifications
125
+ ##### CreateNotification
126
+ Creates a persistent notification stored in the database.
75
127
 
76
- Create notifications that are stored in the database and can be viewed later:
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)
77
146
 
147
+ **Examples:**
78
148
  ```typescript
79
- // Create a simple notification
80
- await notificationService.CreateNotification(
81
- 'New Comment',
82
- 'User John added a comment to your post',
149
+ // Simple notification
150
+ const notification = await notificationService.CreateNotification(
151
+ 'Welcome!',
152
+ 'Thank you for joining our platform',
83
153
  null,
84
154
  null,
85
155
  null
86
156
  );
87
157
 
88
- // Create a notification linked to a resource
89
- await notificationService.CreateNotification(
90
- 'Report Ready',
91
- 'Your requested report is now available',
158
+ // Resource-linked notification
159
+ const reportNotification = await notificationService.CreateNotification(
160
+ 'Report Generated',
161
+ 'Your monthly sales report is ready',
92
162
  reportResourceTypeId,
93
163
  reportId,
94
- { reportConfig: 'some-config-data' }
164
+ { format: 'pdf', includeCharts: true }
95
165
  );
96
166
 
97
- // Create a notification but don't display it to the user immediately
167
+ // Silent notification (no immediate UI display)
98
168
  await notificationService.CreateNotification(
99
- 'Background Update',
100
- 'System updated your preferences',
169
+ 'Settings Updated',
170
+ 'Your preferences have been saved',
101
171
  null,
102
172
  null,
103
173
  null,
@@ -105,43 +175,225 @@ await notificationService.CreateNotification(
105
175
  );
106
176
  ```
107
177
 
108
- ### Accessing User Notifications
178
+ ##### PushStatusUpdates
179
+ Returns an observable for subscribing to real-time push notification updates.
109
180
 
110
- Retrieve user notifications:
181
+ ```typescript
182
+ PushStatusUpdates(): Observable<string>
183
+ ```
111
184
 
185
+ **Example:**
112
186
  ```typescript
113
- // Get all notifications for the current user
114
- const notifications = MJNotificationService.UserNotifications;
187
+ notificationService.PushStatusUpdates().subscribe(status => {
188
+ const statusObj = JSON.parse(status.message);
189
+ console.log('Push update received:', statusObj);
190
+ });
191
+ ```
115
192
 
116
- // Get only unread notifications
117
- const unreadNotifications = MJNotificationService.UnreadUserNotifications;
193
+ #### Static Methods
118
194
 
119
- // Get count of unread notifications
120
- const unreadCount = MJNotificationService.UnreadUserNotificationCount;
195
+ ##### RefreshUserNotifications
196
+ Manually refreshes the user's notifications from the database.
121
197
 
122
- // Manually refresh notifications from the database
198
+ ```typescript
199
+ static async RefreshUserNotifications(): Promise<void>
200
+ ```
201
+
202
+ **Example:**
203
+ ```typescript
123
204
  await MJNotificationService.RefreshUserNotifications();
205
+ console.log('Notifications refreshed');
124
206
  ```
125
207
 
126
- ## Push Notifications
208
+ #### Static Properties
127
209
 
128
- The service automatically subscribes to push notifications after login, handling:
210
+ ##### Instance
211
+ Access the singleton instance of the notification service.
212
+
213
+ ```typescript
214
+ static get Instance(): MJNotificationService
215
+ ```
129
216
 
130
- - User notification updates
131
- - System status messages
132
- - Custom event propagation
217
+ ##### UserNotifications
218
+ Get all notifications for the current user.
133
219
 
134
220
  ```typescript
135
- // Access push status updates directly
136
- notificationService.PushStatusUpdates().subscribe(status => {
137
- // Handle status updates
221
+ static get UserNotifications(): UserNotificationEntity[]
222
+ ```
223
+
224
+ ##### UnreadUserNotifications
225
+ Get only unread notifications.
226
+
227
+ ```typescript
228
+ static get UnreadUserNotifications(): UserNotificationEntity[]
229
+ ```
230
+
231
+ ##### UnreadUserNotificationCount
232
+ Get the count of unread notifications.
233
+
234
+ ```typescript
235
+ static get UnreadUserNotificationCount(): number
236
+ ```
237
+
238
+ **Example:**
239
+ ```typescript
240
+ // Display unread count in UI
241
+ const unreadCount = MJNotificationService.UnreadUserNotificationCount;
242
+ console.log(`You have ${unreadCount} unread notifications`);
243
+
244
+ // Process unread notifications
245
+ const unread = MJNotificationService.UnreadUserNotifications;
246
+ unread.forEach(notification => {
247
+ console.log(notification.Title, notification.Message);
138
248
  });
139
249
  ```
140
250
 
141
251
  ## Event Integration
142
252
 
143
- The service integrates with MemberJunction global events, reacting to:
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
389
+
390
+ The package exports:
391
+ - `MJNotificationsModule` - The Angular module to import
392
+ - `MJNotificationService` - The notification service
393
+
394
+ ## Support
144
395
 
145
- - `MJEventType.LoggedIn`: Refreshes notifications and sets up push updates
146
- - `MJEventType.DisplaySimpleNotificationRequest`: Displays notifications from other parts of the application
147
- - `MJEventType.ComponentEvent` with `UserNotificationsUpdated` code: Refreshes notification list
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/ng-notifications",
3
- "version": "2.43.0",
3
+ "version": "2.45.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",
@@ -24,10 +24,10 @@
24
24
  "@progress/kendo-angular-notification": "16.2.0"
25
25
  },
26
26
  "dependencies": {
27
- "@memberjunction/core": "2.43.0",
28
- "@memberjunction/core-entities": "2.43.0",
29
- "@memberjunction/global": "2.43.0",
30
- "@memberjunction/graphql-dataprovider": "2.43.0",
27
+ "@memberjunction/core": "2.45.0",
28
+ "@memberjunction/core-entities": "2.45.0",
29
+ "@memberjunction/global": "2.45.0",
30
+ "@memberjunction/graphql-dataprovider": "2.45.0",
31
31
  "tslib": "^2.3.0",
32
32
  "rxjs": "^7.8.1"
33
33
  },