@openfin/cloud-notification-core-api 0.0.1-alpha.babe94a

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/LICENSE.md ADDED
@@ -0,0 +1,4 @@
1
+ Learn more about OpenFin licensing at the links listed below or email us at support@openfin.co with questions.
2
+
3
+ - [Developer agreement](https://openfin.co/developer-agreement)
4
+
package/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # @openfin/cloud-notification-core-api
2
+
3
+ This package contains the core notification library that handles all interactions with the Here™ Cloud Notification Service.
4
+
5
+ It is callable via browser or node applications.
6
+
7
+
8
+ ## Authentication
9
+
10
+ The library supports authentication with the Here™ Cloud Notification Service using the following methods:
11
+ - Basic Authentication
12
+ - JWT Token Authentication
13
+ - Default Authentication i.e. Interactive session based authentication using cookies
14
+
package/bundle.d.ts ADDED
@@ -0,0 +1,334 @@
1
+ import z from 'zod';
2
+
3
+ export declare class AuthorizationError extends CloudNotificationAPIError {
4
+ constructor(message?: string, code?: string);
5
+ }
6
+
7
+ export declare type BaseNotificationReceivedEvent = {
8
+ action: 'new' | 'update';
9
+ notificationId: string;
10
+ correlationId?: string;
11
+ target: string;
12
+ targetName?: string;
13
+ targetType: string;
14
+ payload: unknown;
15
+ };
16
+
17
+ /**
18
+ * Represents a single connection to a Cloud Notification service
19
+ *
20
+ * @public
21
+ * @class
22
+ */
23
+ export declare class CloudNotificationAPI {
24
+ #private;
25
+ constructor(cloudNotificationSettings: CloudNotificationSettings);
26
+ /**
27
+ * Connects and creates a session on the Cloud Notifications service
28
+ *
29
+ * @param {ConnectParameters} parameters - The parameters to use to connect
30
+ * @returns {*} {Promise<void>}
31
+ * @memberof CloudNotificationAPI
32
+ * @throws {CloudNotificationAPIError} - If an error occurs during connection
33
+ * @throws {AuthorizationError} - If the connection is unauthorized
34
+ */
35
+ connect(parameters: ConnectParameters): Promise<ConnectionResult>;
36
+ /**
37
+ * Disconnects from the Cloud Notification service
38
+ *
39
+ * @returns {*} {Promise<void>}
40
+ * @memberof CloudNotificationAPI
41
+ * @throws {CloudNotificationAPIError} - If an error occurs during disconnection
42
+ */
43
+ disconnect(): Promise<void>;
44
+ postNotificationEvent(event: {
45
+ notificationId: string;
46
+ category: string;
47
+ type: string;
48
+ payload?: unknown;
49
+ }): Promise<void>;
50
+ getNotificationEvents(notificationIds: string[]): Promise<NotificationEventDetailGroupedByUserId>;
51
+ raiseNotification(options: NotificationOptions_2, payload: unknown): Promise<NotificationRaiseResult>;
52
+ updateNotification(): Promise<void>;
53
+ deleteNotification(): Promise<void>;
54
+ addEventListener<K extends keyof EventMap>(type: K, callback: EventMap[K]): void;
55
+ removeEventListener<K extends keyof EventMap>(type: K, callback: EventMap[K]): void;
56
+ once<K extends keyof EventMap>(type: K, callback: EventMap[K]): void;
57
+ }
58
+
59
+ export declare class CloudNotificationAPIError extends Error {
60
+ code: string;
61
+ constructor(message?: string, code?: string, cause?: unknown);
62
+ }
63
+
64
+ /**
65
+ * Represents a logging function to be used by the cloud notification client
66
+ */
67
+ export declare type CloudNotificationLogger = (level: LogLevel, message: string) => void;
68
+
69
+ export declare type CloudNotificationSettings = {
70
+ /**
71
+ * The URL of the notification server to connect to
72
+ */
73
+ url: string;
74
+ /**
75
+ * The default TTL for notifications published.
76
+ * Can be overridden on each publish if required
77
+ * */
78
+ defaultTTL?: number;
79
+ };
80
+
81
+ export declare type ConnectionResult = {
82
+ sessionId: string;
83
+ platformId: string;
84
+ sourceId: string;
85
+ userId: string;
86
+ groups: {
87
+ uuid: string;
88
+ name: string;
89
+ }[];
90
+ };
91
+
92
+ /**
93
+ * Represents the parameters to use to connect to an notification server
94
+ */
95
+ export declare type ConnectParameters = {
96
+ /**
97
+ * ID for a group of shared applications.
98
+ * This acts as a namespace for the notification messages that allows separation of messages between different groups of applications for the same user
99
+ */
100
+ platformId: string;
101
+ /**
102
+ * A value that distinguishes the host the application is running in. For example this could be the hostname of the current machine
103
+ */
104
+ sourceId: string;
105
+ /**
106
+ * The maximum number of times to retry connecting to the cloud notification service when the connection is dropped
107
+ * defaults to 30
108
+ */
109
+ reconnectRetryLimit?: number;
110
+ /**
111
+ * Specifies how often keep alive messages should be sent to the cloud notification service in seconds
112
+ * defaults to 30
113
+ */
114
+ keepAliveIntervalSeconds?: number;
115
+ /**
116
+ * Calculates the time offset between the local machine and the notification server
117
+ * defaults to true
118
+ */
119
+ syncTime?: boolean;
120
+ /**
121
+ * Optional function to call with any logging messages to allow integration with the host application's logging
122
+ *
123
+ * defaults to console.log
124
+ */
125
+ logger?: CloudNotificationLogger;
126
+ /**
127
+ * Determines the type of authentication to use with the service gateway
128
+ * defaults to 'none'
129
+ *
130
+ * 'jwt' - Use JWT authentication, in this case jwtAuthenticationParameters must also be provided
131
+ * 'basic' - Use basic authentication, in this case basicAuthenticationParameters must also be provided
132
+ * 'default' - Authentication will be inherited from the current session
133
+ */
134
+ authenticationType?: 'jwt' | 'basic' | 'default';
135
+ /**
136
+ * Optional parameters for basic authentication
137
+ */
138
+ basicAuthenticationParameters?: {
139
+ /**
140
+ * The username to use for basic authentication
141
+ */
142
+ username: string;
143
+ /**
144
+ * The password to use for basic authentication
145
+ */
146
+ password: string;
147
+ };
148
+ /**
149
+ * Optional parameters for JWT authentication
150
+ */
151
+ jwtAuthenticationParameters?: {
152
+ /**
153
+ * When JWT authentication is being used, this will be invoked just whenever a JWT token is required for a request
154
+ */
155
+ jwtRequestCallback: () => string | object;
156
+ /**
157
+ * The id of the service gateway JWT authentication definition to use
158
+ *
159
+ * Note: Contact Here support to to get your organization's authentication id
160
+ */
161
+ authenticationId: string;
162
+ };
163
+ };
164
+
165
+ export declare type CreateSessionResponse = {
166
+ sessionId: string;
167
+ sessionRootTopic: string;
168
+ userNotificationEventsTopic: string;
169
+ allNotificationEventsTopic: string;
170
+ channelsRootTopic: string;
171
+ publishTopic: string;
172
+ lastWillTopic: string;
173
+ url: string;
174
+ token: string;
175
+ orgId: string;
176
+ userId: string;
177
+ platformId: string;
178
+ groups: UserGroupWithTopic[];
179
+ userNotificationTopic: string;
180
+ };
181
+
182
+ export declare type EventListenersMap = Map<keyof EventMap, Array<(...args: Parameters<EventMap[keyof EventMap]>) => void>>;
183
+
184
+ export declare type EventMap = {
185
+ reconnected: () => void;
186
+ disconnected: () => void;
187
+ reconnecting: (attemptNo: number) => void;
188
+ error: (error: Error) => void;
189
+ 'session-expired': () => void;
190
+ 'session-extended': () => void;
191
+ 'new-notification': (event: NewNotificationEvent) => void;
192
+ 'update-notification': (event: UpdateNotificationEvent) => void;
193
+ 'notification-event': (event: NotificationEvent) => void;
194
+ 'notification-event-all': (event: NotificationEvent) => void;
195
+ };
196
+
197
+ export declare class EventRetrievalError extends CloudNotificationAPIError {
198
+ constructor(message?: string, code?: string, cause?: unknown);
199
+ }
200
+
201
+ export declare class InvalidMessageFormatError extends CloudNotificationAPIError {
202
+ constructor(zodParseResult: z.SafeParseReturnType<unknown, unknown>);
203
+ }
204
+
205
+ export declare type LogLevel = 'log' | 'debug' | 'info' | 'warn' | 'error';
206
+
207
+ export declare type NewNotificationEvent = BaseNotificationReceivedEvent & {
208
+ action: 'new';
209
+ };
210
+
211
+ export declare type NotificationEvent = {
212
+ notificationId: string;
213
+ correlationId?: string;
214
+ category: string;
215
+ type: string;
216
+ payload?: unknown;
217
+ };
218
+
219
+ export declare type NotificationEventDetail = z.infer<typeof notificationEventDetailSchema>;
220
+
221
+ export declare type NotificationEventDetailGroupedByUserId = {
222
+ [userId: string]: NotificationEventDetail[];
223
+ };
224
+
225
+ export declare const notificationEventDetailSchema: z.ZodObject<{
226
+ userId: z.ZodString;
227
+ platformId: z.ZodString;
228
+ sourceId: z.ZodString;
229
+ notificationId: z.ZodString;
230
+ category: z.ZodString;
231
+ type: z.ZodString;
232
+ sessionId: z.ZodString;
233
+ payload: z.ZodOptional<z.ZodUnknown>;
234
+ correlationId: z.ZodOptional<z.ZodString>;
235
+ timestamp: z.ZodString;
236
+ }, "strip", z.ZodTypeAny, {
237
+ notificationId: string;
238
+ category: string;
239
+ type: string;
240
+ userId: string;
241
+ platformId: string;
242
+ sourceId: string;
243
+ sessionId: string;
244
+ timestamp: string;
245
+ payload?: unknown;
246
+ correlationId?: string | undefined;
247
+ }, {
248
+ notificationId: string;
249
+ category: string;
250
+ type: string;
251
+ userId: string;
252
+ platformId: string;
253
+ sourceId: string;
254
+ sessionId: string;
255
+ timestamp: string;
256
+ payload?: unknown;
257
+ correlationId?: string | undefined;
258
+ }>;
259
+
260
+ /**
261
+ * Represents the options for a notification publish
262
+ */
263
+ declare type NotificationOptions_2 = {
264
+ /**
265
+ * Time to live for the notification in seconds
266
+ * This is the time that the notification will be kept in the system before it is deleted
267
+ * If not specified, the default time to live for the notification will be used
268
+ */
269
+ ttl?: number;
270
+ /**
271
+ * A caller specified identifier for the notification
272
+ * This is used to identify the notification in the system when events and responses are received
273
+ */
274
+ correlationId?: string;
275
+ /**
276
+ * The targets to send the notification to
277
+ * This is a set of groups and users that the notification will be sent to
278
+ */
279
+ targets: NotificationTargets;
280
+ };
281
+ export { NotificationOptions_2 as NotificationOptions }
282
+
283
+ /**
284
+ * Represents the response from raising a notification
285
+ */
286
+ export declare type NotificationRaiseResult = {
287
+ /**
288
+ * The unique identifier for the notification
289
+ */
290
+ notificationId: string;
291
+ /**
292
+ * The correction ID that was provided when raising the notification
293
+ */
294
+ correlationId?: string;
295
+ };
296
+
297
+ /**
298
+ * Represents a set of targets for a notification publish
299
+ */
300
+ export declare type NotificationTargets = {
301
+ /**
302
+ * The groups to send the notification to
303
+ */
304
+ groups: string[];
305
+ /**
306
+ * The users to send the notification to
307
+ */
308
+ users: string[];
309
+ };
310
+
311
+ export declare class PublishError extends CloudNotificationAPIError {
312
+ constructor(message?: string, code?: string, cause?: unknown);
313
+ }
314
+
315
+ export declare type PublishResult = {
316
+ notificationId: string;
317
+ correlationId: string | undefined;
318
+ };
319
+
320
+ export declare class SessionNotConnectedError extends CloudNotificationAPIError {
321
+ constructor(message?: string, code?: string);
322
+ }
323
+
324
+ export declare type UpdateNotificationEvent = BaseNotificationReceivedEvent & {
325
+ action: 'update';
326
+ };
327
+
328
+ export declare type UserGroupWithTopic = {
329
+ uuid: string;
330
+ name: string;
331
+ topic?: string;
332
+ };
333
+
334
+ export { }