@openfin/cloud-notification-core-api 0.0.1-alpha.2049c34

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,288 @@
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 the Cloud Notification service
19
+ *
20
+ */
21
+ export declare class CloudNotificationAPI {
22
+ #private;
23
+ constructor(cloudNotificationSettings: CloudNotificationSettings);
24
+ /**
25
+ * Connects and creates a session on the Cloud Notifications service
26
+ *
27
+ * @param {ConnectParameters} parameters - The parameters to use to connect
28
+ * @returns {*} {Promise<void>}
29
+ * @memberof CloudNotificationAPI
30
+ * @throws {CloudNotificationAPIError} - If an error occurs during connection
31
+ * @throws {AuthorizationError} - If the connection is unauthorized
32
+ */
33
+ connect(parameters: ConnectParameters): Promise<ConnectionResult>;
34
+ /**
35
+ * Disconnects from the Cloud Notification service
36
+ *
37
+ * @returns {*} {Promise<void>}
38
+ * @memberof CloudNotificationAPI
39
+ * @throws {CloudNotificationAPIError} - If an error occurs during disconnection
40
+ */
41
+ disconnect(): Promise<void>;
42
+ postNotificationEvent(notificationId: string, event: {
43
+ category: string;
44
+ type: string;
45
+ payload?: unknown;
46
+ }): Promise<void>;
47
+ /**
48
+ * Raises a notification to the Cloud Notification service
49
+ *
50
+ * @param {NotificationOptions} options - The options for the notification
51
+ * @param {unknown} payload - The payload of the notification
52
+ * @returns {*} {Promise<NotificationRaiseResult>}
53
+ * @memberof CloudNotificationAPI
54
+ * @throws {SessionNotConnectedError} - If the session is not connected
55
+ * @throws {PublishError} - If an error occurs during publishing
56
+ */
57
+ raiseNotification(options: NotificationOptions_2, payload: unknown): Promise<NotificationRaiseResult>;
58
+ updateNotification(): Promise<void>;
59
+ deleteNotification(): Promise<void>;
60
+ addEventListener<K extends keyof EventMap>(type: K, callback: EventMap[K]): void;
61
+ removeEventListener<K extends keyof EventMap>(type: K, callback: EventMap[K]): void;
62
+ once<K extends keyof EventMap>(type: K, callback: EventMap[K]): void;
63
+ }
64
+
65
+ export declare class CloudNotificationAPIError extends Error {
66
+ code: string;
67
+ constructor(message?: string, code?: string, cause?: unknown);
68
+ }
69
+
70
+ /**
71
+ * Represents a logging function to be used by the cloud notification client
72
+ */
73
+ export declare type CloudNotificationLogger = (level: LogLevel, message: string) => void;
74
+
75
+ export declare type CloudNotificationSettings = {
76
+ /**
77
+ * The URL of the notification server to connect to
78
+ */
79
+ url: string;
80
+ };
81
+
82
+ /**
83
+ * Repesents the result of a successful connection to the server
84
+ */
85
+ export declare type ConnectionResult = {
86
+ /**
87
+ * The unique identifier for the session
88
+ */
89
+ sessionId: string;
90
+ /**
91
+ * The platform identifier
92
+ */
93
+ platformId: string;
94
+ /**
95
+ * The source identifier
96
+ */
97
+ sourceId: string;
98
+ /**
99
+ * The user identifier
100
+ */
101
+ userId: string;
102
+ /**
103
+ * A collection of groups that the user is either a direct or indirect member of
104
+ */
105
+ groups: {
106
+ uuid: string;
107
+ name: string;
108
+ }[];
109
+ };
110
+
111
+ /**
112
+ * Represents the parameters to use to connect to an notification server
113
+ */
114
+ export declare type ConnectParameters = {
115
+ /**
116
+ * ID for a group of shared applications.
117
+ * This acts as a namespace for the notification messages that allows separation of messages between different groups of applications for the same user
118
+ */
119
+ platformId: string;
120
+ /**
121
+ * A value that distinguishes the host the application is running in. For example this could be the hostname of the current machine
122
+ */
123
+ sourceId: string;
124
+ /**
125
+ * The maximum number of times to retry connecting to the cloud notification service when the connection is dropped
126
+ * defaults to 30
127
+ */
128
+ reconnectRetryLimit?: number;
129
+ /**
130
+ * Specifies how often keep alive messages should be sent to the cloud notification service in seconds
131
+ * defaults to 30
132
+ */
133
+ keepAliveIntervalSeconds?: number;
134
+ /**
135
+ * Calculates the time offset between the local machine and the notification server
136
+ * defaults to true
137
+ */
138
+ syncTime?: boolean;
139
+ /**
140
+ * Optional function to call with any logging messages to allow integration with the host application's logging
141
+ *
142
+ * defaults to console.log
143
+ */
144
+ logger?: CloudNotificationLogger;
145
+ /**
146
+ * Determines the type of authentication to use with the service gateway
147
+ * defaults to 'none'
148
+ *
149
+ * 'jwt' - Use JWT authentication, in this case jwtAuthenticationParameters must also be provided
150
+ * 'basic' - Use basic authentication, in this case basicAuthenticationParameters must also be provided
151
+ * 'default' - Authentication will be inherited from the current session
152
+ */
153
+ authenticationType?: 'jwt' | 'basic' | 'default';
154
+ /**
155
+ * Optional parameters for basic authentication
156
+ */
157
+ basicAuthenticationParameters?: {
158
+ /**
159
+ * The username to use for basic authentication
160
+ */
161
+ username: string;
162
+ /**
163
+ * The password to use for basic authentication
164
+ */
165
+ password: string;
166
+ };
167
+ /**
168
+ * Optional parameters for JWT authentication
169
+ */
170
+ jwtAuthenticationParameters?: {
171
+ /**
172
+ * When JWT authentication is being used, this will be invoked just whenever a JWT token is required for a request
173
+ */
174
+ jwtRequestCallback: () => string | object;
175
+ /**
176
+ * The id of the service gateway JWT authentication definition to use
177
+ *
178
+ * Note: Contact Here support to to get your organization's authentication id
179
+ */
180
+ authenticationId: string;
181
+ };
182
+ };
183
+
184
+ export declare type EventListenersMap = Map<keyof EventMap, Array<(...args: Parameters<EventMap[keyof EventMap]>) => void>>;
185
+
186
+ export declare type EventMap = {
187
+ reconnected: () => void;
188
+ disconnected: () => void;
189
+ reconnecting: (attemptNo: number) => void;
190
+ error: (error: Error) => void;
191
+ 'session-expired': () => void;
192
+ 'session-extended': () => void;
193
+ 'new-notification': (event: NewNotificationEvent) => void;
194
+ 'update-notification': (event: UpdateNotificationEvent) => void;
195
+ 'notification-event': (event: NotificationEvent) => void;
196
+ };
197
+
198
+ export declare class EventRetrievalError extends CloudNotificationAPIError {
199
+ constructor(message?: string, code?: string, cause?: unknown);
200
+ }
201
+
202
+ export declare class InvalidMessageFormatError extends CloudNotificationAPIError {
203
+ constructor(zodParseResult: z.SafeParseReturnType<unknown, unknown>);
204
+ }
205
+
206
+ export declare type LogLevel = 'log' | 'debug' | 'info' | 'warn' | 'error';
207
+
208
+ export declare type NewNotificationEvent = BaseNotificationReceivedEvent & {
209
+ action: 'new';
210
+ };
211
+
212
+ export declare type NotificationEvent = {
213
+ notificationId: string;
214
+ correlationId?: string;
215
+ category: string;
216
+ type: string;
217
+ payload?: unknown;
218
+ };
219
+
220
+ /**
221
+ * Represents the options for a notification publish
222
+ */
223
+ declare type NotificationOptions_2 = {
224
+ /**
225
+ * A caller specified identifier for the notification
226
+ * This is used to identify the notification in the system when events and responses are received
227
+ */
228
+ correlationId?: string;
229
+ /**
230
+ * The targets to send the notification to
231
+ * This is a set of groups and users that the notification will be sent to
232
+ */
233
+ targets: NotificationTargets;
234
+ };
235
+ export { NotificationOptions_2 as NotificationOptions }
236
+
237
+ /**
238
+ * Represents the response from raising a notification
239
+ */
240
+ export declare type NotificationRaiseResult = {
241
+ /**
242
+ * The unique identifier for the notification
243
+ */
244
+ notificationId: string;
245
+ /**
246
+ * The correlation ID that was provided when raising the notification
247
+ */
248
+ correlationId?: string;
249
+ };
250
+
251
+ /**
252
+ * Represents a set of targets for a notification publish
253
+ */
254
+ export declare type NotificationTargets = {
255
+ /**
256
+ * The groups to send the notification to
257
+ */
258
+ groups: string[];
259
+ /**
260
+ * The users to send the notification to
261
+ */
262
+ users: string[];
263
+ };
264
+
265
+ export declare class PublishError extends CloudNotificationAPIError {
266
+ constructor(message?: string, code?: string, cause?: unknown);
267
+ }
268
+
269
+ export declare type PublishResult = {
270
+ notificationId: string;
271
+ correlationId: string | undefined;
272
+ };
273
+
274
+ export declare class SessionNotConnectedError extends CloudNotificationAPIError {
275
+ constructor(message?: string, code?: string);
276
+ }
277
+
278
+ export declare type UpdateNotificationEvent = BaseNotificationReceivedEvent & {
279
+ action: 'update';
280
+ };
281
+
282
+ export declare type UserGroupWithTopic = {
283
+ uuid: string;
284
+ name: string;
285
+ topic?: string;
286
+ };
287
+
288
+ export { }