@openfin/cloud-notification-core-api 0.0.1-alpha.856abf3 → 0.0.1-alpha.85addcf
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/bundle.d.ts +203 -43
- package/index.cjs +56 -16
- package/index.mjs +56 -16
- package/package.json +1 -1
package/bundle.d.ts
CHANGED
|
@@ -4,13 +4,38 @@ export declare class AuthorizationError extends CloudNotificationAPIError {
|
|
|
4
4
|
constructor(message?: string, code?: string);
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Represents common properties for all notification events
|
|
9
|
+
*/
|
|
7
10
|
export declare type BaseNotificationReceivedEvent = {
|
|
11
|
+
/**
|
|
12
|
+
* The action that was performed on the notification
|
|
13
|
+
*/
|
|
8
14
|
action: 'new' | 'update' | 'delete';
|
|
15
|
+
/**
|
|
16
|
+
* The unique identifier for the notification
|
|
17
|
+
*/
|
|
9
18
|
notificationId: string;
|
|
19
|
+
/**
|
|
20
|
+
* The correlation identifier for the notification
|
|
21
|
+
*/
|
|
10
22
|
correlationId?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The identifier of the target of the notification
|
|
25
|
+
*/
|
|
11
26
|
target: string;
|
|
27
|
+
/**
|
|
28
|
+
* The name of the target i.e, the group or user that the notification was sent to
|
|
29
|
+
*/
|
|
12
30
|
targetName?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The type of the target i.e, 'group' or 'user'
|
|
33
|
+
*/
|
|
13
34
|
targetType: string;
|
|
35
|
+
/**
|
|
36
|
+
* The payload of the notification.
|
|
37
|
+
* See the documentation for the notification center events for more information on the payload
|
|
38
|
+
*/
|
|
14
39
|
payload: unknown;
|
|
15
40
|
};
|
|
16
41
|
|
|
@@ -20,11 +45,30 @@ export declare type BaseNotificationReceivedEvent = {
|
|
|
20
45
|
*/
|
|
21
46
|
export declare class CloudNotificationAPI {
|
|
22
47
|
#private;
|
|
23
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Constructs a new instance of the CloudNotificationAPI
|
|
50
|
+
*
|
|
51
|
+
* @param cloudNotificationSettings - The settings for the Cloud Notification API.
|
|
52
|
+
*/
|
|
24
53
|
constructor(cloudNotificationSettings: CloudNotificationSettings);
|
|
25
54
|
/**
|
|
26
55
|
* Connects and creates a session on the Cloud Notifications service.
|
|
27
56
|
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const notificationApi = new CloudNotificationAPI({
|
|
60
|
+
* url: process.env.NOTIFICATION_SERVER_HOST
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* let connectionResult: ConnectionResult;
|
|
64
|
+
* try {
|
|
65
|
+
* connectionResult = await notificationApi.connect(connectSettings);
|
|
66
|
+
* } catch (errorConnect) {
|
|
67
|
+
* terminal.write(chalk.red(`\nError connecting to notification server: ${errorConnect}\n`));
|
|
68
|
+
* process.exit(1);
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
28
72
|
* @param parameters - The parameters to use to connect.
|
|
29
73
|
* @returns A promise that resolves when the connection is established.
|
|
30
74
|
* @throws {@link CloudNotificationAPIError} If an error occurs during connection.
|
|
@@ -56,7 +100,7 @@ export declare class CloudNotificationAPI {
|
|
|
56
100
|
* Raises a notification to the Cloud Notification service.
|
|
57
101
|
*
|
|
58
102
|
* @param options - The options for the notification.
|
|
59
|
-
* @param payload - The payload of the notification
|
|
103
|
+
* @param payload - The payload of the notification which should generally conform to the notification center schema
|
|
60
104
|
* @returns A promise that resolves with the notification raise result.
|
|
61
105
|
* @throws {@link SessionNotConnectedError} If the session is not connected.
|
|
62
106
|
* @throws {@link PublishError} If an error occurs during publishing.
|
|
@@ -67,7 +111,7 @@ export declare class CloudNotificationAPI {
|
|
|
67
111
|
*
|
|
68
112
|
* @param notificationId - The ID of the notification to update.
|
|
69
113
|
* @param options - The options for the notification update.
|
|
70
|
-
* @param payload - The new payload of the notification
|
|
114
|
+
* @param payload - The new payload of the notification which should generally conform to the notification center update schema
|
|
71
115
|
* @throws {@link SessionNotConnectedError} If the session is not connected.
|
|
72
116
|
* @throws {@link PublishError} If an error occurs during publishing of the update.
|
|
73
117
|
*/
|
|
@@ -75,6 +119,8 @@ export declare class CloudNotificationAPI {
|
|
|
75
119
|
/**
|
|
76
120
|
* Marks a notification as deleted in the Cloud Notification service.
|
|
77
121
|
*
|
|
122
|
+
* This in turn causes notification events to be raised for the notification
|
|
123
|
+
*
|
|
78
124
|
* @param notificationId - The ID of the notification to delete.
|
|
79
125
|
* @returns A promise that resolves when the notification is deleted.
|
|
80
126
|
* @throws {@link SessionNotConnectedError} If the session is not connected.
|
|
@@ -83,8 +129,10 @@ export declare class CloudNotificationAPI {
|
|
|
83
129
|
/**
|
|
84
130
|
* Replays notifications from the Cloud Notification service.
|
|
85
131
|
*
|
|
132
|
+
* This is called at platform startup to populate the notification center with notifications that were missed since the last time the platform was started.
|
|
133
|
+
*
|
|
86
134
|
* @param pageItemLimit - The maximum number of items per page.
|
|
87
|
-
* @param pageStartCursor - The cursor to start the page from.
|
|
135
|
+
* @param pageStartCursor - The cursor to start the page from. This is retrieved from the pageInfo property.
|
|
88
136
|
* @returns A promise that resolves with the notifications replay details.
|
|
89
137
|
* @throws {@link SessionNotConnectedError} If the session is not connected.
|
|
90
138
|
* @throws {@link NotificationRetrievalError} If an error occurs during retrieval.
|
|
@@ -126,6 +174,8 @@ export declare class CloudNotificationAPI {
|
|
|
126
174
|
export declare type CloudNotificationSettings = {
|
|
127
175
|
/**
|
|
128
176
|
* The URL of the notification server to connect to
|
|
177
|
+
*
|
|
178
|
+
* @example 'https://the-environment.example.com/notifications'
|
|
129
179
|
*/
|
|
130
180
|
url: string;
|
|
131
181
|
/**
|
|
@@ -141,7 +191,7 @@ export declare class CloudNotificationAPI {
|
|
|
141
191
|
/**
|
|
142
192
|
* Optional function to call with any logging messages to allow integration with the host application's logging
|
|
143
193
|
*
|
|
144
|
-
*
|
|
194
|
+
* Defaults to console.log
|
|
145
195
|
*/
|
|
146
196
|
logger?: CloudNotificationLogger;
|
|
147
197
|
/**
|
|
@@ -156,7 +206,7 @@ export declare class CloudNotificationAPI {
|
|
|
156
206
|
};
|
|
157
207
|
|
|
158
208
|
/**
|
|
159
|
-
*
|
|
209
|
+
* Represents the result of a successful connection to the server
|
|
160
210
|
*/
|
|
161
211
|
export declare type ConnectionResult = {
|
|
162
212
|
/**
|
|
@@ -190,7 +240,10 @@ export declare class CloudNotificationAPI {
|
|
|
190
240
|
export declare type ConnectParameters = {
|
|
191
241
|
/**
|
|
192
242
|
* ID for a group of shared applications.
|
|
243
|
+
*
|
|
193
244
|
* This acts as a namespace for the notification messages that allows separation of messages between different groups of applications for the same user
|
|
245
|
+
*
|
|
246
|
+
* This, in general, should be the uuid of the platform that you are communicating
|
|
194
247
|
*/
|
|
195
248
|
platformId: string;
|
|
196
249
|
/**
|
|
@@ -199,11 +252,10 @@ export declare class CloudNotificationAPI {
|
|
|
199
252
|
sourceId: string;
|
|
200
253
|
/**
|
|
201
254
|
* Determines the type of authentication to use with the service gateway
|
|
202
|
-
* defaults to 'none'
|
|
203
255
|
*
|
|
204
|
-
* 'jwt' - Use JWT authentication, in this case jwtAuthenticationParameters must also be provided
|
|
205
|
-
* 'basic' - Use basic authentication, in this case basicAuthenticationParameters must also be provided
|
|
206
|
-
* 'default' - Authentication will be inherited from the current session
|
|
256
|
+
* - 'jwt' - Use JWT authentication, in this case jwtAuthenticationParameters must also be provided
|
|
257
|
+
* - 'basic' - Use basic authentication, in this case basicAuthenticationParameters must also be provided
|
|
258
|
+
* - 'default' - Authentication will be inherited from the current session
|
|
207
259
|
*/
|
|
208
260
|
authenticationType?: 'jwt' | 'basic' | 'default';
|
|
209
261
|
/**
|
|
@@ -225,6 +277,15 @@ export declare class CloudNotificationAPI {
|
|
|
225
277
|
jwtAuthenticationParameters?: {
|
|
226
278
|
/**
|
|
227
279
|
* When JWT authentication is being used, this will be invoked just whenever a JWT token is required for a request
|
|
280
|
+
*
|
|
281
|
+
* This token should be conform to the configuration set within your environment. Contact Here support for more details
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```typescript
|
|
285
|
+
* const jwtRequestCallback = () => {
|
|
286
|
+
* return 'your-jwt-token';
|
|
287
|
+
* };
|
|
288
|
+
* ```
|
|
228
289
|
*/
|
|
229
290
|
jwtRequestCallback: () => string | object;
|
|
230
291
|
/**
|
|
@@ -240,19 +301,62 @@ export declare class CloudNotificationAPI {
|
|
|
240
301
|
action: 'delete';
|
|
241
302
|
};
|
|
242
303
|
|
|
243
|
-
export declare type EventListenersMap = Map<keyof EventMap, Array<(...args: Parameters<EventMap[keyof EventMap]>) => void>>;
|
|
244
|
-
|
|
245
304
|
export declare type EventMap = {
|
|
305
|
+
/**
|
|
306
|
+
* Emitted when the connection has been re-established
|
|
307
|
+
* @returns void
|
|
308
|
+
*/
|
|
246
309
|
reconnected: () => void;
|
|
247
|
-
|
|
310
|
+
/**
|
|
311
|
+
* Emitted when the connection has been disconnected
|
|
312
|
+
* @returns void
|
|
313
|
+
*/
|
|
248
314
|
reconnecting: (attemptNo: number) => void;
|
|
315
|
+
/**
|
|
316
|
+
* Emitted when the connection has been disconnected
|
|
317
|
+
* @returns void
|
|
318
|
+
*/
|
|
319
|
+
disconnected: () => void;
|
|
320
|
+
/**
|
|
321
|
+
* Emitted when an error occurs
|
|
322
|
+
* @returns void
|
|
323
|
+
*/
|
|
249
324
|
error: (error: Error) => void;
|
|
325
|
+
/**
|
|
326
|
+
* Emitted when the session has expired
|
|
327
|
+
* @returns void
|
|
328
|
+
*/
|
|
250
329
|
'session-expired': () => void;
|
|
330
|
+
/**
|
|
331
|
+
* Emitted when the session has been extended
|
|
332
|
+
* @returns void
|
|
333
|
+
*/
|
|
251
334
|
'session-extended': () => void;
|
|
335
|
+
/**
|
|
336
|
+
* Emitted when a new notification is received
|
|
337
|
+
* @returns void
|
|
338
|
+
*/
|
|
252
339
|
'new-notification': (event: NewNotificationEvent) => void;
|
|
340
|
+
/**
|
|
341
|
+
* Emitted when an update to a notification is received
|
|
342
|
+
* @returns void
|
|
343
|
+
*/
|
|
253
344
|
'update-notification': (event: UpdateNotificationEvent) => void;
|
|
345
|
+
/**
|
|
346
|
+
* Emitted when a notification is deleted
|
|
347
|
+
* @returns void
|
|
348
|
+
*/
|
|
254
349
|
'delete-notification': (event: DeleteNotificationEvent) => void;
|
|
350
|
+
/**
|
|
351
|
+
* Emitted when a notification event is received for this specific session
|
|
352
|
+
* @returns void
|
|
353
|
+
*/
|
|
255
354
|
'notification-event': (event: NotificationEvent) => void;
|
|
355
|
+
/**
|
|
356
|
+
* Emitted when a notification event is received for all sessions
|
|
357
|
+
* @returns void
|
|
358
|
+
*/
|
|
359
|
+
'global-notification-event': (event: NotificationEvent) => void;
|
|
256
360
|
};
|
|
257
361
|
|
|
258
362
|
export declare class EventPublishError extends CloudNotificationAPIError {
|
|
@@ -273,11 +377,32 @@ export declare class CloudNotificationAPI {
|
|
|
273
377
|
action: 'new';
|
|
274
378
|
};
|
|
275
379
|
|
|
380
|
+
/**
|
|
381
|
+
* Represents a notification event
|
|
382
|
+
*/
|
|
276
383
|
export declare type NotificationEvent = {
|
|
384
|
+
/**
|
|
385
|
+
* The unique identifier for the notification
|
|
386
|
+
*/
|
|
277
387
|
notificationId: string;
|
|
388
|
+
/**
|
|
389
|
+
* The correlation identifier for the notification
|
|
390
|
+
*/
|
|
278
391
|
correlationId?: string;
|
|
392
|
+
/**
|
|
393
|
+
* The category of the notification.
|
|
394
|
+
* For notification center events this will be 'notification-center-event'
|
|
395
|
+
*/
|
|
279
396
|
category: string;
|
|
397
|
+
/**
|
|
398
|
+
* The type of the notification.
|
|
399
|
+
* For example 'notification-close' when a user closes a notification in the notification center
|
|
400
|
+
*/
|
|
280
401
|
type: string;
|
|
402
|
+
/**
|
|
403
|
+
* The payload of the notification.
|
|
404
|
+
* See the documentation for the notification center events for more information on the payload
|
|
405
|
+
*/
|
|
281
406
|
payload?: unknown;
|
|
282
407
|
};
|
|
283
408
|
|
|
@@ -287,16 +412,29 @@ export declare class CloudNotificationAPI {
|
|
|
287
412
|
declare type NotificationOptions_2 = {
|
|
288
413
|
/**
|
|
289
414
|
* A caller specified identifier for the notification
|
|
415
|
+
*
|
|
290
416
|
* This is used to identify the notification in the system when events and responses are received
|
|
291
417
|
*/
|
|
292
418
|
correlationId?: string;
|
|
293
419
|
/**
|
|
294
420
|
* The targets to send the notification to
|
|
421
|
+
*
|
|
295
422
|
* This is a set of groups and users that the notification will be sent to
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```typescript
|
|
426
|
+
* const notificationOptions: NotificationOptions = {
|
|
427
|
+
* targets: {
|
|
428
|
+
* groups: ['all-users'],
|
|
429
|
+
* users: ['someuser@company.com']
|
|
430
|
+
* }
|
|
431
|
+
* };
|
|
432
|
+
* ```
|
|
296
433
|
*/
|
|
297
434
|
targets: NotificationTargets;
|
|
298
435
|
/**
|
|
299
436
|
* Optional number of seconds to keep the notification alive
|
|
437
|
+
*
|
|
300
438
|
* After this time the notification will be expired and a delete update will be raised
|
|
301
439
|
*/
|
|
302
440
|
ttlSeconds?: number;
|
|
@@ -321,22 +459,67 @@ export declare class CloudNotificationAPI {
|
|
|
321
459
|
constructor(message?: string, code?: string, cause?: unknown);
|
|
322
460
|
}
|
|
323
461
|
|
|
462
|
+
/**
|
|
463
|
+
* Represents a single notification replay detail.
|
|
464
|
+
*/
|
|
324
465
|
export declare type NotificationsReplayDetail = {
|
|
466
|
+
/**
|
|
467
|
+
* The cursor of the notification.
|
|
468
|
+
*/
|
|
325
469
|
cursor: string;
|
|
470
|
+
/**
|
|
471
|
+
* The session ID of the notification.
|
|
472
|
+
*/
|
|
326
473
|
sessionId: string;
|
|
474
|
+
/**
|
|
475
|
+
* The notification ID.
|
|
476
|
+
*/
|
|
327
477
|
notificationId: string;
|
|
478
|
+
/**
|
|
479
|
+
* The version of the notification.
|
|
480
|
+
*/
|
|
328
481
|
version: number;
|
|
482
|
+
/**
|
|
483
|
+
* The type of notification record.
|
|
484
|
+
*/
|
|
329
485
|
action: 'new' | 'update' | 'delete';
|
|
486
|
+
/**
|
|
487
|
+
* The payload of the notification.
|
|
488
|
+
*/
|
|
330
489
|
payload?: unknown;
|
|
490
|
+
/**
|
|
491
|
+
* The original correlation ID of the notification if specified.
|
|
492
|
+
*/
|
|
331
493
|
correlationId?: string | null;
|
|
494
|
+
/**
|
|
495
|
+
* The timestamp of the notification.
|
|
496
|
+
*/
|
|
332
497
|
timestamp: Date;
|
|
333
498
|
};
|
|
334
499
|
|
|
500
|
+
/**
|
|
501
|
+
* Represents the results of a notifications replay request.
|
|
502
|
+
*/
|
|
335
503
|
export declare type NotificationsReplayDetails = {
|
|
504
|
+
/**
|
|
505
|
+
* The list of notifications replay details.
|
|
506
|
+
*/
|
|
336
507
|
data: NotificationsReplayDetail[];
|
|
508
|
+
/**
|
|
509
|
+
* The pagination information for the notifications replay request.
|
|
510
|
+
*/
|
|
337
511
|
pageInfo: {
|
|
512
|
+
/**
|
|
513
|
+
* The cursor of the first notification in the page.
|
|
514
|
+
*/
|
|
338
515
|
pageStart?: string;
|
|
516
|
+
/**
|
|
517
|
+
* The cursor of the next page.
|
|
518
|
+
*/
|
|
339
519
|
nextPage?: string;
|
|
520
|
+
/**
|
|
521
|
+
* Whether there is a next page of notifications.
|
|
522
|
+
*/
|
|
340
523
|
hasNextPage: boolean;
|
|
341
524
|
};
|
|
342
525
|
};
|
|
@@ -346,11 +529,16 @@ export declare class CloudNotificationAPI {
|
|
|
346
529
|
*/
|
|
347
530
|
export declare type NotificationTargets = {
|
|
348
531
|
/**
|
|
349
|
-
* The groups to send the notification to
|
|
532
|
+
* The optional groups to send the notification to
|
|
533
|
+
*
|
|
534
|
+
* This can be a collection of either group names e.g. all-users which can be retrieved from the admin console or the
|
|
535
|
+
* UUID of the group itself
|
|
350
536
|
*/
|
|
351
537
|
groups: string[];
|
|
352
538
|
/**
|
|
353
|
-
* The users to send the notification to
|
|
539
|
+
* The optional specific users to send the notification to
|
|
540
|
+
*
|
|
541
|
+
* This can be the username e.g. someuser\@company.com or the UUID of the user itself
|
|
354
542
|
*/
|
|
355
543
|
users: string[];
|
|
356
544
|
};
|
|
@@ -370,40 +558,12 @@ export declare class CloudNotificationAPI {
|
|
|
370
558
|
constructor(message?: string, code?: string, cause?: unknown);
|
|
371
559
|
}
|
|
372
560
|
|
|
373
|
-
export declare type PublishResult = {
|
|
374
|
-
notificationId: string;
|
|
375
|
-
correlationId: string | undefined;
|
|
376
|
-
};
|
|
377
|
-
|
|
378
561
|
export declare class SessionNotConnectedError extends CloudNotificationAPIError {
|
|
379
562
|
constructor(message?: string, code?: string);
|
|
380
563
|
}
|
|
381
564
|
|
|
382
|
-
/**
|
|
383
|
-
* Simple set-like structure that allows you to add values with a TTL (time to live).
|
|
384
|
-
* Values are automatically removed from the set after the TTL expires.
|
|
385
|
-
*/
|
|
386
|
-
declare class SetWithTTL<T> {
|
|
387
|
-
#private;
|
|
388
|
-
private ttl;
|
|
389
|
-
private store;
|
|
390
|
-
private nextCollection;
|
|
391
|
-
private collectionDelay;
|
|
392
|
-
constructor(ttl: number, collectionCheckInterval?: number);
|
|
393
|
-
get size(): number;
|
|
394
|
-
add(value: T, customTtl?: number): this;
|
|
395
|
-
has(value: T): boolean;
|
|
396
|
-
delete(value: T): this;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
565
|
export declare type UpdateNotificationEvent = BaseNotificationReceivedEvent & {
|
|
400
566
|
action: 'update';
|
|
401
567
|
};
|
|
402
568
|
|
|
403
|
-
export declare type UserGroupWithTopic = {
|
|
404
|
-
uuid: string;
|
|
405
|
-
name: string;
|
|
406
|
-
topic?: string;
|
|
407
|
-
};
|
|
408
|
-
|
|
409
569
|
export { }
|
package/index.cjs
CHANGED
|
@@ -108,13 +108,14 @@ function handleAPIException(logger, error, message, exceptionConstructor) {
|
|
|
108
108
|
}
|
|
109
109
|
throw new exceptionConstructor(undefined, undefined, error);
|
|
110
110
|
}
|
|
111
|
-
function checkResponse(logger, response, failMessage, failCode) {
|
|
111
|
+
async function checkResponse(logger, response, failMessage, failCode) {
|
|
112
112
|
if (!response.ok) {
|
|
113
113
|
if (response.status === 401 || response.status === 403) {
|
|
114
114
|
throw new AuthorizationError();
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
const responseBody = await response.text();
|
|
117
|
+
logger('error', `Response check failure ${failMessage} - ${response.status}: ${response.statusText} : ${responseBody}`);
|
|
118
|
+
throw new CloudNotificationAPIError(`${failMessage} (HTTP ${response.status}: ${response.statusText})`, failCode, responseBody);
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
function getRequestHeaders(connectionParameters) {
|
|
@@ -284,7 +285,7 @@ class CloudNotificationAPI {
|
|
|
284
285
|
#keepAliveIntervalSeconds = 30;
|
|
285
286
|
#syncTime = true;
|
|
286
287
|
#timeDifferenceTracker;
|
|
287
|
-
deDuplicator;
|
|
288
|
+
#deDuplicator;
|
|
288
289
|
#reconnectRetries = 0;
|
|
289
290
|
#connectionParams;
|
|
290
291
|
#attemptingToReconnect = false;
|
|
@@ -292,9 +293,14 @@ class CloudNotificationAPI {
|
|
|
292
293
|
#defaultSubscriptionOptions = { qos: 2, nl: true };
|
|
293
294
|
#logger = (level, message) => console[level](message);
|
|
294
295
|
#getCurrentTimeOffset = () => this.#timeDifferenceTracker?.currentOffset || 0;
|
|
296
|
+
/**
|
|
297
|
+
* Constructs a new instance of the CloudNotificationAPI
|
|
298
|
+
*
|
|
299
|
+
* @param cloudNotificationSettings - The settings for the Cloud Notification API.
|
|
300
|
+
*/
|
|
295
301
|
constructor(cloudNotificationSettings) {
|
|
296
302
|
this.#cloudNotificationSettings = cloudNotificationSettings;
|
|
297
|
-
this
|
|
303
|
+
this.#deDuplicator = new SetWithTTL(cloudNotificationSettings?.deduplicationTTLms || 10_000);
|
|
298
304
|
this.#reconnectRetryLimit = cloudNotificationSettings.reconnectRetryLimit || this.#reconnectRetryLimit;
|
|
299
305
|
this.#keepAliveIntervalSeconds = cloudNotificationSettings.keepAliveIntervalSeconds || this.#keepAliveIntervalSeconds;
|
|
300
306
|
this.#logger = cloudNotificationSettings.logger || this.#logger;
|
|
@@ -303,6 +309,21 @@ class CloudNotificationAPI {
|
|
|
303
309
|
/**
|
|
304
310
|
* Connects and creates a session on the Cloud Notifications service.
|
|
305
311
|
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```typescript
|
|
314
|
+
* const notificationApi = new CloudNotificationAPI({
|
|
315
|
+
* url: process.env.NOTIFICATION_SERVER_HOST
|
|
316
|
+
* });
|
|
317
|
+
*
|
|
318
|
+
* let connectionResult: ConnectionResult;
|
|
319
|
+
* try {
|
|
320
|
+
* connectionResult = await notificationApi.connect(connectSettings);
|
|
321
|
+
* } catch (errorConnect) {
|
|
322
|
+
* terminal.write(chalk.red(`\nError connecting to notification server: ${errorConnect}\n`));
|
|
323
|
+
* process.exit(1);
|
|
324
|
+
* }
|
|
325
|
+
* ```
|
|
326
|
+
*
|
|
306
327
|
* @param parameters - The parameters to use to connect.
|
|
307
328
|
* @returns A promise that resolves when the connection is established.
|
|
308
329
|
* @throws {@link CloudNotificationAPIError} If an error occurs during connection.
|
|
@@ -330,7 +351,7 @@ class CloudNotificationAPI {
|
|
|
330
351
|
isFullApi: true,
|
|
331
352
|
}),
|
|
332
353
|
});
|
|
333
|
-
checkResponse(this.#logger, createSessionResponse, 'Error creating session', 'ERR_CREATE_SESSION');
|
|
354
|
+
await checkResponse(this.#logger, createSessionResponse, 'Error creating session', 'ERR_CREATE_SESSION');
|
|
334
355
|
if (createSessionResponse.status !== 201) {
|
|
335
356
|
throw new CloudNotificationAPIError(`Failed to connect to the Cloud Notification service: ${this.#cloudNotificationSettings.url}`, 'ERR_CONNECT', new Error(createSessionResponse.statusText));
|
|
336
357
|
}
|
|
@@ -374,7 +395,7 @@ class CloudNotificationAPI {
|
|
|
374
395
|
headers: getRequestHeaders(this.#connectionParams),
|
|
375
396
|
body: JSON.stringify(publishPayload),
|
|
376
397
|
});
|
|
377
|
-
checkResponse(this.#logger, publishResponse, 'Error posting notification event', 'ERR_POST_NOTIFICATION_EVENT');
|
|
398
|
+
await checkResponse(this.#logger, publishResponse, 'Error posting notification event', 'ERR_POST_NOTIFICATION_EVENT');
|
|
378
399
|
}
|
|
379
400
|
catch (error) {
|
|
380
401
|
handleAPIException(this.#logger, error, 'Error posting notification event', PublishError);
|
|
@@ -384,7 +405,7 @@ class CloudNotificationAPI {
|
|
|
384
405
|
* Raises a notification to the Cloud Notification service.
|
|
385
406
|
*
|
|
386
407
|
* @param options - The options for the notification.
|
|
387
|
-
* @param payload - The payload of the notification
|
|
408
|
+
* @param payload - The payload of the notification which should generally conform to the notification center schema
|
|
388
409
|
* @returns A promise that resolves with the notification raise result.
|
|
389
410
|
* @throws {@link SessionNotConnectedError} If the session is not connected.
|
|
390
411
|
* @throws {@link PublishError} If an error occurs during publishing.
|
|
@@ -410,7 +431,7 @@ class CloudNotificationAPI {
|
|
|
410
431
|
headers: getRequestHeaders(this.#connectionParams),
|
|
411
432
|
body: JSON.stringify(publishPayload),
|
|
412
433
|
});
|
|
413
|
-
checkResponse(this.#logger, publishResponse, 'Error publishing notification', 'ERR_PUBLISH_NOTIFICATION');
|
|
434
|
+
await checkResponse(this.#logger, publishResponse, 'Error publishing notification', 'ERR_PUBLISH_NOTIFICATION');
|
|
414
435
|
const publishResponseBody = (await publishResponse.json());
|
|
415
436
|
return publishResponseBody;
|
|
416
437
|
}
|
|
@@ -423,7 +444,7 @@ class CloudNotificationAPI {
|
|
|
423
444
|
*
|
|
424
445
|
* @param notificationId - The ID of the notification to update.
|
|
425
446
|
* @param options - The options for the notification update.
|
|
426
|
-
* @param payload - The new payload of the notification
|
|
447
|
+
* @param payload - The new payload of the notification which should generally conform to the notification center update schema
|
|
427
448
|
* @throws {@link SessionNotConnectedError} If the session is not connected.
|
|
428
449
|
* @throws {@link PublishError} If an error occurs during publishing of the update.
|
|
429
450
|
*/
|
|
@@ -444,7 +465,7 @@ class CloudNotificationAPI {
|
|
|
444
465
|
headers: getRequestHeaders(this.#connectionParams),
|
|
445
466
|
body: JSON.stringify(updatePayload),
|
|
446
467
|
});
|
|
447
|
-
checkResponse(this.#logger, updateResponse, 'Error updating notification', 'ERR_UPDATING_NOTIFICATION');
|
|
468
|
+
await checkResponse(this.#logger, updateResponse, 'Error updating notification', 'ERR_UPDATING_NOTIFICATION');
|
|
448
469
|
}
|
|
449
470
|
catch (error) {
|
|
450
471
|
handleAPIException(this.#logger, error, 'Error updating notification', PublishError);
|
|
@@ -453,6 +474,8 @@ class CloudNotificationAPI {
|
|
|
453
474
|
/**
|
|
454
475
|
* Marks a notification as deleted in the Cloud Notification service.
|
|
455
476
|
*
|
|
477
|
+
* This in turn causes notification events to be raised for the notification
|
|
478
|
+
*
|
|
456
479
|
* @param notificationId - The ID of the notification to delete.
|
|
457
480
|
* @returns A promise that resolves when the notification is deleted.
|
|
458
481
|
* @throws {@link SessionNotConnectedError} If the session is not connected.
|
|
@@ -467,7 +490,7 @@ class CloudNotificationAPI {
|
|
|
467
490
|
method: 'DELETE',
|
|
468
491
|
headers: getRequestHeaders(this.#connectionParams),
|
|
469
492
|
});
|
|
470
|
-
checkResponse(this.#logger, deleteResponse, 'Error deleting notification', 'ERR_DELETE_NOTIFICATION');
|
|
493
|
+
await checkResponse(this.#logger, deleteResponse, 'Error deleting notification', 'ERR_DELETE_NOTIFICATION');
|
|
471
494
|
}
|
|
472
495
|
catch (error) {
|
|
473
496
|
handleAPIException(this.#logger, error, 'Error deleting notification', PublishError);
|
|
@@ -476,8 +499,10 @@ class CloudNotificationAPI {
|
|
|
476
499
|
/**
|
|
477
500
|
* Replays notifications from the Cloud Notification service.
|
|
478
501
|
*
|
|
502
|
+
* This is called at platform startup to populate the notification center with notifications that were missed since the last time the platform was started.
|
|
503
|
+
*
|
|
479
504
|
* @param pageItemLimit - The maximum number of items per page.
|
|
480
|
-
* @param pageStartCursor - The cursor to start the page from.
|
|
505
|
+
* @param pageStartCursor - The cursor to start the page from. This is retrieved from the pageInfo property.
|
|
481
506
|
* @returns A promise that resolves with the notifications replay details.
|
|
482
507
|
* @throws {@link SessionNotConnectedError} If the session is not connected.
|
|
483
508
|
* @throws {@link NotificationRetrievalError} If an error occurs during retrieval.
|
|
@@ -506,7 +531,7 @@ class CloudNotificationAPI {
|
|
|
506
531
|
sessionId: this.#sessionDetails.sessionId,
|
|
507
532
|
}),
|
|
508
533
|
});
|
|
509
|
-
checkResponse(this.#logger, replayResponse, 'Error replaying notifications', 'ERR_REPLAY_NOTIFICATIONS');
|
|
534
|
+
await checkResponse(this.#logger, replayResponse, 'Error replaying notifications', 'ERR_REPLAY_NOTIFICATIONS');
|
|
510
535
|
const body = (await replayResponse.json());
|
|
511
536
|
return body;
|
|
512
537
|
}
|
|
@@ -648,6 +673,10 @@ class CloudNotificationAPI {
|
|
|
648
673
|
this.#mqttClient?.subscribeAsync(this.#sessionDetails.mqtt.userNotificationTopic, this.#defaultSubscriptionOptions),
|
|
649
674
|
// The users notifications status updates
|
|
650
675
|
this.#mqttClient?.subscribeAsync(this.#sessionDetails.mqtt.userNotificationEventsTopic, this.#defaultSubscriptionOptions));
|
|
676
|
+
// Global notification events
|
|
677
|
+
if (this.#sessionDetails.mqtt.allNotificationEventsTopic) {
|
|
678
|
+
subscribePromises.push(this.#mqttClient?.subscribeAsync(this.#sessionDetails.mqtt.allNotificationEventsTopic, this.#defaultSubscriptionOptions));
|
|
679
|
+
}
|
|
651
680
|
await Promise.all(subscribePromises);
|
|
652
681
|
}
|
|
653
682
|
async #extendSession() {
|
|
@@ -731,6 +760,9 @@ class CloudNotificationAPI {
|
|
|
731
760
|
else if (topic === sessionDetails.mqtt.userNotificationEventsTopic) {
|
|
732
761
|
this.#handleUserNotificationEventMessage(messagePayload);
|
|
733
762
|
}
|
|
763
|
+
else if (topic === sessionDetails.mqtt.allNotificationEventsTopic) {
|
|
764
|
+
this.#handleAllNotificationEventMessage(messagePayload);
|
|
765
|
+
}
|
|
734
766
|
else {
|
|
735
767
|
this.#logger('warn', `Received message on unknown topic ${topic}`);
|
|
736
768
|
this.#events.emitEvent('error', new CloudNotificationAPIError(`Received message on unknown topic ${topic}`, 'ERR_UNKNOWN_TOPIC'));
|
|
@@ -753,10 +785,10 @@ class CloudNotificationAPI {
|
|
|
753
785
|
return;
|
|
754
786
|
}
|
|
755
787
|
// We might have received this update from a different group or user topic so de-dupe
|
|
756
|
-
if (this
|
|
788
|
+
if (this.#deDuplicator.has(txInstanceId)) {
|
|
757
789
|
return;
|
|
758
790
|
}
|
|
759
|
-
this
|
|
791
|
+
this.#deDuplicator.add(txInstanceId);
|
|
760
792
|
this.#sendNotificationDeliveredStatus(notificationId);
|
|
761
793
|
let targetName = target;
|
|
762
794
|
if (targetType === 'group') {
|
|
@@ -786,6 +818,14 @@ class CloudNotificationAPI {
|
|
|
786
818
|
}
|
|
787
819
|
this.#events.emitEvent('notification-event', parseResult.data);
|
|
788
820
|
}
|
|
821
|
+
#handleAllNotificationEventMessage(messagePayload) {
|
|
822
|
+
const parseResult = f.safeParse(messagePayload);
|
|
823
|
+
if (!parseResult.success) {
|
|
824
|
+
this.#logger('warn', `Received invalid notification event message payload format ${parseResult.error?.toString()}`);
|
|
825
|
+
throw new InvalidMessageFormatError(parseResult);
|
|
826
|
+
}
|
|
827
|
+
this.#events.emitEvent('global-notification-event', parseResult.data);
|
|
828
|
+
}
|
|
789
829
|
#lookupGroupNameByUuid(uuid) {
|
|
790
830
|
if (!this.#sessionDetails) {
|
|
791
831
|
return undefined;
|
package/index.mjs
CHANGED
|
@@ -106,13 +106,14 @@ function handleAPIException(logger, error, message, exceptionConstructor) {
|
|
|
106
106
|
}
|
|
107
107
|
throw new exceptionConstructor(undefined, undefined, error);
|
|
108
108
|
}
|
|
109
|
-
function checkResponse(logger, response, failMessage, failCode) {
|
|
109
|
+
async function checkResponse(logger, response, failMessage, failCode) {
|
|
110
110
|
if (!response.ok) {
|
|
111
111
|
if (response.status === 401 || response.status === 403) {
|
|
112
112
|
throw new AuthorizationError();
|
|
113
113
|
}
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
const responseBody = await response.text();
|
|
115
|
+
logger('error', `Response check failure ${failMessage} - ${response.status}: ${response.statusText} : ${responseBody}`);
|
|
116
|
+
throw new CloudNotificationAPIError(`${failMessage} (HTTP ${response.status}: ${response.statusText})`, failCode, responseBody);
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
function getRequestHeaders(connectionParameters) {
|
|
@@ -282,7 +283,7 @@ class CloudNotificationAPI {
|
|
|
282
283
|
#keepAliveIntervalSeconds = 30;
|
|
283
284
|
#syncTime = true;
|
|
284
285
|
#timeDifferenceTracker;
|
|
285
|
-
deDuplicator;
|
|
286
|
+
#deDuplicator;
|
|
286
287
|
#reconnectRetries = 0;
|
|
287
288
|
#connectionParams;
|
|
288
289
|
#attemptingToReconnect = false;
|
|
@@ -290,9 +291,14 @@ class CloudNotificationAPI {
|
|
|
290
291
|
#defaultSubscriptionOptions = { qos: 2, nl: true };
|
|
291
292
|
#logger = (level, message) => console[level](message);
|
|
292
293
|
#getCurrentTimeOffset = () => this.#timeDifferenceTracker?.currentOffset || 0;
|
|
294
|
+
/**
|
|
295
|
+
* Constructs a new instance of the CloudNotificationAPI
|
|
296
|
+
*
|
|
297
|
+
* @param cloudNotificationSettings - The settings for the Cloud Notification API.
|
|
298
|
+
*/
|
|
293
299
|
constructor(cloudNotificationSettings) {
|
|
294
300
|
this.#cloudNotificationSettings = cloudNotificationSettings;
|
|
295
|
-
this
|
|
301
|
+
this.#deDuplicator = new SetWithTTL(cloudNotificationSettings?.deduplicationTTLms || 10_000);
|
|
296
302
|
this.#reconnectRetryLimit = cloudNotificationSettings.reconnectRetryLimit || this.#reconnectRetryLimit;
|
|
297
303
|
this.#keepAliveIntervalSeconds = cloudNotificationSettings.keepAliveIntervalSeconds || this.#keepAliveIntervalSeconds;
|
|
298
304
|
this.#logger = cloudNotificationSettings.logger || this.#logger;
|
|
@@ -301,6 +307,21 @@ class CloudNotificationAPI {
|
|
|
301
307
|
/**
|
|
302
308
|
* Connects and creates a session on the Cloud Notifications service.
|
|
303
309
|
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```typescript
|
|
312
|
+
* const notificationApi = new CloudNotificationAPI({
|
|
313
|
+
* url: process.env.NOTIFICATION_SERVER_HOST
|
|
314
|
+
* });
|
|
315
|
+
*
|
|
316
|
+
* let connectionResult: ConnectionResult;
|
|
317
|
+
* try {
|
|
318
|
+
* connectionResult = await notificationApi.connect(connectSettings);
|
|
319
|
+
* } catch (errorConnect) {
|
|
320
|
+
* terminal.write(chalk.red(`\nError connecting to notification server: ${errorConnect}\n`));
|
|
321
|
+
* process.exit(1);
|
|
322
|
+
* }
|
|
323
|
+
* ```
|
|
324
|
+
*
|
|
304
325
|
* @param parameters - The parameters to use to connect.
|
|
305
326
|
* @returns A promise that resolves when the connection is established.
|
|
306
327
|
* @throws {@link CloudNotificationAPIError} If an error occurs during connection.
|
|
@@ -328,7 +349,7 @@ class CloudNotificationAPI {
|
|
|
328
349
|
isFullApi: true,
|
|
329
350
|
}),
|
|
330
351
|
});
|
|
331
|
-
checkResponse(this.#logger, createSessionResponse, 'Error creating session', 'ERR_CREATE_SESSION');
|
|
352
|
+
await checkResponse(this.#logger, createSessionResponse, 'Error creating session', 'ERR_CREATE_SESSION');
|
|
332
353
|
if (createSessionResponse.status !== 201) {
|
|
333
354
|
throw new CloudNotificationAPIError(`Failed to connect to the Cloud Notification service: ${this.#cloudNotificationSettings.url}`, 'ERR_CONNECT', new Error(createSessionResponse.statusText));
|
|
334
355
|
}
|
|
@@ -372,7 +393,7 @@ class CloudNotificationAPI {
|
|
|
372
393
|
headers: getRequestHeaders(this.#connectionParams),
|
|
373
394
|
body: JSON.stringify(publishPayload),
|
|
374
395
|
});
|
|
375
|
-
checkResponse(this.#logger, publishResponse, 'Error posting notification event', 'ERR_POST_NOTIFICATION_EVENT');
|
|
396
|
+
await checkResponse(this.#logger, publishResponse, 'Error posting notification event', 'ERR_POST_NOTIFICATION_EVENT');
|
|
376
397
|
}
|
|
377
398
|
catch (error) {
|
|
378
399
|
handleAPIException(this.#logger, error, 'Error posting notification event', PublishError);
|
|
@@ -382,7 +403,7 @@ class CloudNotificationAPI {
|
|
|
382
403
|
* Raises a notification to the Cloud Notification service.
|
|
383
404
|
*
|
|
384
405
|
* @param options - The options for the notification.
|
|
385
|
-
* @param payload - The payload of the notification
|
|
406
|
+
* @param payload - The payload of the notification which should generally conform to the notification center schema
|
|
386
407
|
* @returns A promise that resolves with the notification raise result.
|
|
387
408
|
* @throws {@link SessionNotConnectedError} If the session is not connected.
|
|
388
409
|
* @throws {@link PublishError} If an error occurs during publishing.
|
|
@@ -408,7 +429,7 @@ class CloudNotificationAPI {
|
|
|
408
429
|
headers: getRequestHeaders(this.#connectionParams),
|
|
409
430
|
body: JSON.stringify(publishPayload),
|
|
410
431
|
});
|
|
411
|
-
checkResponse(this.#logger, publishResponse, 'Error publishing notification', 'ERR_PUBLISH_NOTIFICATION');
|
|
432
|
+
await checkResponse(this.#logger, publishResponse, 'Error publishing notification', 'ERR_PUBLISH_NOTIFICATION');
|
|
412
433
|
const publishResponseBody = (await publishResponse.json());
|
|
413
434
|
return publishResponseBody;
|
|
414
435
|
}
|
|
@@ -421,7 +442,7 @@ class CloudNotificationAPI {
|
|
|
421
442
|
*
|
|
422
443
|
* @param notificationId - The ID of the notification to update.
|
|
423
444
|
* @param options - The options for the notification update.
|
|
424
|
-
* @param payload - The new payload of the notification
|
|
445
|
+
* @param payload - The new payload of the notification which should generally conform to the notification center update schema
|
|
425
446
|
* @throws {@link SessionNotConnectedError} If the session is not connected.
|
|
426
447
|
* @throws {@link PublishError} If an error occurs during publishing of the update.
|
|
427
448
|
*/
|
|
@@ -442,7 +463,7 @@ class CloudNotificationAPI {
|
|
|
442
463
|
headers: getRequestHeaders(this.#connectionParams),
|
|
443
464
|
body: JSON.stringify(updatePayload),
|
|
444
465
|
});
|
|
445
|
-
checkResponse(this.#logger, updateResponse, 'Error updating notification', 'ERR_UPDATING_NOTIFICATION');
|
|
466
|
+
await checkResponse(this.#logger, updateResponse, 'Error updating notification', 'ERR_UPDATING_NOTIFICATION');
|
|
446
467
|
}
|
|
447
468
|
catch (error) {
|
|
448
469
|
handleAPIException(this.#logger, error, 'Error updating notification', PublishError);
|
|
@@ -451,6 +472,8 @@ class CloudNotificationAPI {
|
|
|
451
472
|
/**
|
|
452
473
|
* Marks a notification as deleted in the Cloud Notification service.
|
|
453
474
|
*
|
|
475
|
+
* This in turn causes notification events to be raised for the notification
|
|
476
|
+
*
|
|
454
477
|
* @param notificationId - The ID of the notification to delete.
|
|
455
478
|
* @returns A promise that resolves when the notification is deleted.
|
|
456
479
|
* @throws {@link SessionNotConnectedError} If the session is not connected.
|
|
@@ -465,7 +488,7 @@ class CloudNotificationAPI {
|
|
|
465
488
|
method: 'DELETE',
|
|
466
489
|
headers: getRequestHeaders(this.#connectionParams),
|
|
467
490
|
});
|
|
468
|
-
checkResponse(this.#logger, deleteResponse, 'Error deleting notification', 'ERR_DELETE_NOTIFICATION');
|
|
491
|
+
await checkResponse(this.#logger, deleteResponse, 'Error deleting notification', 'ERR_DELETE_NOTIFICATION');
|
|
469
492
|
}
|
|
470
493
|
catch (error) {
|
|
471
494
|
handleAPIException(this.#logger, error, 'Error deleting notification', PublishError);
|
|
@@ -474,8 +497,10 @@ class CloudNotificationAPI {
|
|
|
474
497
|
/**
|
|
475
498
|
* Replays notifications from the Cloud Notification service.
|
|
476
499
|
*
|
|
500
|
+
* This is called at platform startup to populate the notification center with notifications that were missed since the last time the platform was started.
|
|
501
|
+
*
|
|
477
502
|
* @param pageItemLimit - The maximum number of items per page.
|
|
478
|
-
* @param pageStartCursor - The cursor to start the page from.
|
|
503
|
+
* @param pageStartCursor - The cursor to start the page from. This is retrieved from the pageInfo property.
|
|
479
504
|
* @returns A promise that resolves with the notifications replay details.
|
|
480
505
|
* @throws {@link SessionNotConnectedError} If the session is not connected.
|
|
481
506
|
* @throws {@link NotificationRetrievalError} If an error occurs during retrieval.
|
|
@@ -504,7 +529,7 @@ class CloudNotificationAPI {
|
|
|
504
529
|
sessionId: this.#sessionDetails.sessionId,
|
|
505
530
|
}),
|
|
506
531
|
});
|
|
507
|
-
checkResponse(this.#logger, replayResponse, 'Error replaying notifications', 'ERR_REPLAY_NOTIFICATIONS');
|
|
532
|
+
await checkResponse(this.#logger, replayResponse, 'Error replaying notifications', 'ERR_REPLAY_NOTIFICATIONS');
|
|
508
533
|
const body = (await replayResponse.json());
|
|
509
534
|
return body;
|
|
510
535
|
}
|
|
@@ -646,6 +671,10 @@ class CloudNotificationAPI {
|
|
|
646
671
|
this.#mqttClient?.subscribeAsync(this.#sessionDetails.mqtt.userNotificationTopic, this.#defaultSubscriptionOptions),
|
|
647
672
|
// The users notifications status updates
|
|
648
673
|
this.#mqttClient?.subscribeAsync(this.#sessionDetails.mqtt.userNotificationEventsTopic, this.#defaultSubscriptionOptions));
|
|
674
|
+
// Global notification events
|
|
675
|
+
if (this.#sessionDetails.mqtt.allNotificationEventsTopic) {
|
|
676
|
+
subscribePromises.push(this.#mqttClient?.subscribeAsync(this.#sessionDetails.mqtt.allNotificationEventsTopic, this.#defaultSubscriptionOptions));
|
|
677
|
+
}
|
|
649
678
|
await Promise.all(subscribePromises);
|
|
650
679
|
}
|
|
651
680
|
async #extendSession() {
|
|
@@ -729,6 +758,9 @@ class CloudNotificationAPI {
|
|
|
729
758
|
else if (topic === sessionDetails.mqtt.userNotificationEventsTopic) {
|
|
730
759
|
this.#handleUserNotificationEventMessage(messagePayload);
|
|
731
760
|
}
|
|
761
|
+
else if (topic === sessionDetails.mqtt.allNotificationEventsTopic) {
|
|
762
|
+
this.#handleAllNotificationEventMessage(messagePayload);
|
|
763
|
+
}
|
|
732
764
|
else {
|
|
733
765
|
this.#logger('warn', `Received message on unknown topic ${topic}`);
|
|
734
766
|
this.#events.emitEvent('error', new CloudNotificationAPIError(`Received message on unknown topic ${topic}`, 'ERR_UNKNOWN_TOPIC'));
|
|
@@ -751,10 +783,10 @@ class CloudNotificationAPI {
|
|
|
751
783
|
return;
|
|
752
784
|
}
|
|
753
785
|
// We might have received this update from a different group or user topic so de-dupe
|
|
754
|
-
if (this
|
|
786
|
+
if (this.#deDuplicator.has(txInstanceId)) {
|
|
755
787
|
return;
|
|
756
788
|
}
|
|
757
|
-
this
|
|
789
|
+
this.#deDuplicator.add(txInstanceId);
|
|
758
790
|
this.#sendNotificationDeliveredStatus(notificationId);
|
|
759
791
|
let targetName = target;
|
|
760
792
|
if (targetType === 'group') {
|
|
@@ -784,6 +816,14 @@ class CloudNotificationAPI {
|
|
|
784
816
|
}
|
|
785
817
|
this.#events.emitEvent('notification-event', parseResult.data);
|
|
786
818
|
}
|
|
819
|
+
#handleAllNotificationEventMessage(messagePayload) {
|
|
820
|
+
const parseResult = f.safeParse(messagePayload);
|
|
821
|
+
if (!parseResult.success) {
|
|
822
|
+
this.#logger('warn', `Received invalid notification event message payload format ${parseResult.error?.toString()}`);
|
|
823
|
+
throw new InvalidMessageFormatError(parseResult);
|
|
824
|
+
}
|
|
825
|
+
this.#events.emitEvent('global-notification-event', parseResult.data);
|
|
826
|
+
}
|
|
787
827
|
#lookupGroupNameByUuid(uuid) {
|
|
788
828
|
if (!this.#sessionDetails) {
|
|
789
829
|
return undefined;
|