@interopio/browser-platform 3.0.1

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 (97) hide show
  1. package/browser.platform.d.ts +455 -0
  2. package/changelog.md +69 -0
  3. package/dist/browser.platform.es.js +46074 -0
  4. package/dist/browser.platform.es.js.map +1 -0
  5. package/dist/browser.platform.umd.js +46082 -0
  6. package/dist/browser.platform.umd.js.map +1 -0
  7. package/license.md +21 -0
  8. package/package.json +78 -0
  9. package/readme.md +9 -0
  10. package/rollup.config.js +45 -0
  11. package/src/common/constants.ts +46 -0
  12. package/src/common/defaultConfig.ts +56 -0
  13. package/src/common/gateway.d.ts +32 -0
  14. package/src/common/types.ts +222 -0
  15. package/src/connection/gateway.ts +132 -0
  16. package/src/connection/no-gateway.ts +1 -0
  17. package/src/connection/portsBridge.ts +441 -0
  18. package/src/connection/preferred.ts +247 -0
  19. package/src/controllers/domains.ts +156 -0
  20. package/src/controllers/glue.ts +604 -0
  21. package/src/controllers/interception.ts +53 -0
  22. package/src/controllers/license.ts +50 -0
  23. package/src/controllers/main.ts +256 -0
  24. package/src/controllers/plugins.ts +121 -0
  25. package/src/controllers/serviceWorker.ts +193 -0
  26. package/src/controllers/state.ts +84 -0
  27. package/src/controllers/system.ts +99 -0
  28. package/src/controllers/transactions.ts +80 -0
  29. package/src/factory.ts +40 -0
  30. package/src/fallbacks/browser.ts +47 -0
  31. package/src/fallbacks/dekstop.ts +21 -0
  32. package/src/index.ts +18 -0
  33. package/src/libs/applications/appStore/directory.ts +235 -0
  34. package/src/libs/applications/appStore/remoteWatcher.ts +112 -0
  35. package/src/libs/applications/controller.ts +469 -0
  36. package/src/libs/applications/decoders.ts +98 -0
  37. package/src/libs/applications/defaults.ts +6 -0
  38. package/src/libs/applications/types.ts +98 -0
  39. package/src/libs/channels/controller.ts +109 -0
  40. package/src/libs/channels/decoders.ts +19 -0
  41. package/src/libs/extension/controller.ts +120 -0
  42. package/src/libs/extension/decoders.ts +18 -0
  43. package/src/libs/extension/types.ts +11 -0
  44. package/src/libs/intents/constants.ts +9 -0
  45. package/src/libs/intents/controller.ts +500 -0
  46. package/src/libs/intents/decoders.ts +96 -0
  47. package/src/libs/intents/resolverHelper.ts +264 -0
  48. package/src/libs/intents/types.ts +119 -0
  49. package/src/libs/layouts/constants.ts +3 -0
  50. package/src/libs/layouts/controller.ts +476 -0
  51. package/src/libs/layouts/decoders.ts +132 -0
  52. package/src/libs/layouts/global/builder.ts +400 -0
  53. package/src/libs/layouts/global/resetter.ts +116 -0
  54. package/src/libs/layouts/global/restorer.ts +217 -0
  55. package/src/libs/layouts/global/validator.ts +169 -0
  56. package/src/libs/layouts/idbStore.ts +63 -0
  57. package/src/libs/layouts/types.ts +133 -0
  58. package/src/libs/manager/controller.ts +175 -0
  59. package/src/libs/manager/decoders.ts +6 -0
  60. package/src/libs/manager/defaults.ts +5 -0
  61. package/src/libs/manager/identity.ts +92 -0
  62. package/src/libs/manager/session.ts +195 -0
  63. package/src/libs/manager/types.ts +51 -0
  64. package/src/libs/notifications/controller.ts +447 -0
  65. package/src/libs/notifications/decoders.ts +166 -0
  66. package/src/libs/notifications/types.ts +49 -0
  67. package/src/libs/notifications/utils.ts +7 -0
  68. package/src/libs/search/controller.ts +232 -0
  69. package/src/libs/search/decoders.ts +6 -0
  70. package/src/libs/search/repositories/applications.ts +62 -0
  71. package/src/libs/search/repositories/layouts.ts +48 -0
  72. package/src/libs/search/repositories/workspaces.ts +47 -0
  73. package/src/libs/search/types.ts +9 -0
  74. package/src/libs/themes/constants.ts +9 -0
  75. package/src/libs/themes/controller.ts +153 -0
  76. package/src/libs/themes/decoders.ts +28 -0
  77. package/src/libs/themes/types.ts +28 -0
  78. package/src/libs/windows/controller.ts +498 -0
  79. package/src/libs/windows/decoders.ts +64 -0
  80. package/src/libs/windows/types.ts +59 -0
  81. package/src/libs/workspaces/controller.ts +922 -0
  82. package/src/libs/workspaces/decoders.ts +868 -0
  83. package/src/libs/workspaces/defaultConfig.ts +11 -0
  84. package/src/libs/workspaces/frames.ts +239 -0
  85. package/src/libs/workspaces/hibernationWatcher.ts +231 -0
  86. package/src/libs/workspaces/types.ts +506 -0
  87. package/src/platform.ts +156 -0
  88. package/src/shared/decoders.ts +479 -0
  89. package/src/shared/fetchTimeout.ts +25 -0
  90. package/src/shared/ioc.ts +580 -0
  91. package/src/shared/logger.ts +19 -0
  92. package/src/shared/promisePlus.ts +62 -0
  93. package/src/shared/sequelizer.ts +48 -0
  94. package/src/shared/utils.ts +86 -0
  95. package/src/storage/local.ts +111 -0
  96. package/src/storage/session.ts +436 -0
  97. package/tsconfig.json +16 -0
@@ -0,0 +1,447 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { IOConnectBrowser } from "@interopio/browser";
3
+ import { UnsubscribeFunction } from "callback-registry";
4
+ import { BridgeOperation, InternalPlatformConfig, LibController, OperationCheckConfig, OperationCheckResult } from "../../common/types";
5
+ import { GlueController } from "../../controllers/glue";
6
+ import { ServiceWorkerController } from "../../controllers/serviceWorker";
7
+ import { SessionStorageController } from "../../storage/session";
8
+ import { operationCheckConfigDecoder, operationCheckResultDecoder } from "../../shared/decoders";
9
+ import { setNotificationDefaults } from "./utils";
10
+ import logger from "../../shared/logger";
11
+ import { allNotificationsDataDecoder, notificationClickConfigDecoder, notificationsOperationDecoder, permissionQueryResultDecoder, permissionRequestResultDecoder, raiseNotificationDecoder, raiseNotificationResultDecoder, simpleNotificationSelectDecoder } from "./decoders";
12
+ import { AllNotificationsData, NotificationClickConfig, NotificationEventPayload, NotificationsOperationsTypes, PermissionQueryResult, PermissionRequestResult, RaiseNotificationConfig, RaiseNotificationResult, SimpleNotificationSelect } from "./types";
13
+
14
+ export class NotificationsController implements LibController {
15
+
16
+ private started = false;
17
+ private isInExtension = false;
18
+ private enableToasts!: boolean;
19
+ private clearNotificationOnClick!: boolean;
20
+ private extNotificationConfig: { defaultIcon: string; defaultMessage: string } | undefined;
21
+ private systemUnsubFuncs: UnsubscribeFunction[] = [];
22
+ private _chromeClickedHandler!: (notificationId: string) => void;
23
+ private _chromeButtonClickedHandler!: (notificationId: string, buttonIndex: number) => void;
24
+ private _chromeClosedHandler!: (notificationId: string) => void;
25
+
26
+ private operations: { [key in NotificationsOperationsTypes]: BridgeOperation } = {
27
+ raiseNotification: { name: "raiseNotification", execute: this.handleRaiseNotification.bind(this), dataDecoder: raiseNotificationDecoder, resultDecoder: raiseNotificationResultDecoder },
28
+ requestPermission: { name: "requestPermission", resultDecoder: permissionRequestResultDecoder, execute: this.handleRequestPermission.bind(this) },
29
+ getPermission: { name: "getPermission", resultDecoder: permissionQueryResultDecoder, execute: this.handleGetPermission.bind(this) },
30
+ operationCheck: { name: "operationCheck", dataDecoder: operationCheckConfigDecoder, resultDecoder: operationCheckResultDecoder, execute: this.handleOperationCheck.bind(this) },
31
+ list: { name: "list", resultDecoder: allNotificationsDataDecoder, execute: this.handleList.bind(this) },
32
+ click: { name: "click", dataDecoder: notificationClickConfigDecoder, execute: this.handleClick.bind(this) },
33
+ clear: { name: "clear", dataDecoder: simpleNotificationSelectDecoder, execute: this.handleClear.bind(this) },
34
+ clearAll: { name: "clearAll", execute: this.handleClearAll.bind(this) }
35
+ };
36
+
37
+ constructor(
38
+ private readonly glueController: GlueController,
39
+ private readonly serviceWorkerController: ServiceWorkerController,
40
+ private readonly session: SessionStorageController
41
+ ) {}
42
+
43
+ private get logger(): IOConnectBrowser.Logger.API | undefined {
44
+ return logger.get("notifications.controller");
45
+ }
46
+
47
+ public handlePlatformShutdown(): void {
48
+ this.started = false;
49
+
50
+ const currentProtocol = (new URL(window.location.href)).protocol;
51
+
52
+ if (currentProtocol.includes("extension")) {
53
+ this.removeExtensionNotificationsListeners();
54
+ }
55
+
56
+ this.systemUnsubFuncs.forEach((unsub) => unsub());
57
+ this.systemUnsubFuncs = [];
58
+ }
59
+
60
+ public async start(config: InternalPlatformConfig): Promise<void> {
61
+
62
+ if (!config.notifications.enable) {
63
+ this.logger?.log("Skipping the notifications controller initialization, because it was disabled upon platform initialization");
64
+ return;
65
+ }
66
+
67
+ this.enableToasts = config.notifications.enableToasts;
68
+ this.clearNotificationOnClick = config.notifications.clearNotificationOnClick;
69
+
70
+ this.started = true;
71
+
72
+ const currentProtocol = (new URL(window.location.href)).protocol;
73
+
74
+ if (currentProtocol.includes("extension")) {
75
+ await this.setupExtensionNotifications();
76
+ }
77
+
78
+ this.listenForServiceWorkerNotificationEvents();
79
+ }
80
+
81
+ private async handleOperationCheck(config: OperationCheckConfig): Promise<OperationCheckResult> {
82
+ const operations = Object.keys(this.operations);
83
+
84
+ const isSupported = operations.some((operation) => operation.toLowerCase() === config.operation.toLowerCase());
85
+
86
+ return { isSupported };
87
+ }
88
+
89
+ public async handleControl(args: any): Promise<any> {
90
+ if (!this.started) {
91
+ new Error("Cannot handle this notifications control message, because the controller has not been started");
92
+ }
93
+
94
+ const notificationsData = args.data;
95
+
96
+ const commandId = args.commandId;
97
+
98
+ const operationValidation = notificationsOperationDecoder.run(args.operation);
99
+
100
+ if (!operationValidation.ok) {
101
+ throw new Error(`This notifications request cannot be completed, because the operation name did not pass validation: ${JSON.stringify(operationValidation.error)}`);
102
+ }
103
+
104
+ const operationName: NotificationsOperationsTypes = operationValidation.result;
105
+
106
+ const incomingValidation = this.operations[operationName].dataDecoder?.run(notificationsData);
107
+
108
+ if (incomingValidation && !incomingValidation.ok) {
109
+ throw new Error(`Notifications request for ${operationName} rejected, because the provided arguments did not pass the validation: ${JSON.stringify(incomingValidation.error)}`);
110
+ }
111
+
112
+ this.logger?.debug(`[${commandId}] ${operationName} command is valid with data: ${JSON.stringify(notificationsData)}`);
113
+
114
+ const result = await this.operations[operationName].execute(notificationsData, commandId);
115
+
116
+ const resultValidation = this.operations[operationName].resultDecoder?.run(result);
117
+
118
+ if (resultValidation && !resultValidation.ok) {
119
+ throw new Error(`Notifications request for ${operationName} could not be completed, because the operation result did not pass the validation: ${JSON.stringify(resultValidation.error)}`);
120
+ }
121
+
122
+ this.logger?.trace(`[${commandId}] ${operationName} command was executed successfully`);
123
+
124
+ return result;
125
+ }
126
+
127
+ private async handleList(_: unknown, commandId: string): Promise<AllNotificationsData> {
128
+ this.logger?.trace(`[${commandId}] handling a list notification message`);
129
+
130
+ const allNotifications = this.session.getAllNotifications();
131
+
132
+ this.logger?.trace(`[${commandId}] list notification message completed`);
133
+
134
+ return { notifications: allNotifications };
135
+ }
136
+
137
+ private async handleClick(config: NotificationClickConfig, commandId: string): Promise<void> {
138
+ this.logger?.trace(`[${commandId}] handling a click notification message with data: ${JSON.stringify(config)}`);
139
+
140
+ const notification = this.session.getNotification(config.id);
141
+
142
+ if (!notification) {
143
+ throw new Error(`Cannot click a notification: ${config.id}, because it doesn't exist`);
144
+ }
145
+
146
+ if (config.action && notification.actions?.every((action) => action.action !== config.action)) {
147
+ throw new Error(`Cannot click action ${config.action} of ${config.id}, because that notification does not have that action`);
148
+ }
149
+
150
+ this.handleNotificationClick({ notification, action: config.action });
151
+
152
+ this.logger?.trace(`[${commandId}] handling a click notification message completed`);
153
+ }
154
+
155
+ private async handleClear(config: SimpleNotificationSelect, commandId: string): Promise<void> {
156
+ this.logger?.trace(`[${commandId}] handling a clear notification message with data: ${JSON.stringify(config)}`);
157
+
158
+ this.removeNotification(config.id);
159
+
160
+ this.logger?.trace(`[${commandId}] handling a clear notification message completed`);
161
+ }
162
+
163
+ private async handleClearAll(_: unknown, commandId: string): Promise<void> {
164
+ this.logger?.trace(`[${commandId}] handling a clearAll notifications message`);
165
+
166
+ const allNotifications = this.session.getAllNotifications();
167
+
168
+ allNotifications.forEach((notification) => this.removeNotification(notification.id));
169
+
170
+ this.logger?.trace(`[${commandId}] handling a clearAll notification message completed`);
171
+ }
172
+
173
+ private async handleRaiseNotification({ settings, id }: RaiseNotificationConfig, commandId: string): Promise<RaiseNotificationResult> {
174
+ this.logger?.trace(`[${commandId}] handling a raise notification message with a title: ${settings.title}`);
175
+
176
+ setNotificationDefaults(settings);
177
+
178
+ this.processNewNotification(settings, id);
179
+
180
+ // system-level enable/disable always takes precedence
181
+ const showToast = this.enableToasts ? !!settings.showToast : this.enableToasts;
182
+
183
+ await this.showToast({ settings, id }, showToast, commandId);
184
+
185
+ const definition = Object.assign({}, settings, { title: undefined, clickInterop: undefined, actions: undefined });
186
+
187
+ const notificationEventPayload: NotificationEventPayload = { definition, id };
188
+
189
+ // setImmediate allows the client which raises the event, to resolve the raise promise before receiving the show event
190
+ // which in turn allows the user to not miss the event
191
+ setTimeout(() => this.glueController.pushSystemMessage("notifications", "notificationShow", notificationEventPayload), 0);
192
+
193
+ this.logger?.trace(`[${commandId}] notification with a title: ${settings.title} was successfully raised`);
194
+
195
+ return { settings };
196
+ }
197
+
198
+ private async showToast({ settings, id }: RaiseNotificationConfig, showToast: boolean, commandId: string): Promise<void> {
199
+ if (!showToast) {
200
+ return;
201
+ }
202
+
203
+ if (this.isInExtension) {
204
+ await this.raiseExtensionToast(settings, id, commandId);
205
+
206
+ return;
207
+ }
208
+
209
+ const hasDefinedActions = settings.actions && settings.actions.length;
210
+
211
+ if (hasDefinedActions) {
212
+ await this.raiseActionsToast(settings, id, commandId);
213
+
214
+ return;
215
+ }
216
+
217
+ this.raiseSimpleToast(settings, id, commandId);
218
+ }
219
+
220
+ private async handleGetPermission(_: unknown, commandId: string): Promise<PermissionQueryResult> {
221
+ this.logger?.trace(`[${commandId}] handling a get permission message`);
222
+
223
+ const permissionValue = Notification.permission;
224
+
225
+ this.logger?.trace(`[${commandId}] permission for raising notifications is: ${permissionValue}`);
226
+
227
+ return { permission: permissionValue };
228
+ }
229
+
230
+ private async handleRequestPermission(_: unknown, commandId: string): Promise<PermissionRequestResult> {
231
+ this.logger?.trace(`[${commandId}] handling a request permission message`);
232
+
233
+ let permissionValue = Notification.permission;
234
+
235
+ if (permissionValue !== "granted") {
236
+ permissionValue = await Notification.requestPermission();
237
+ }
238
+
239
+ const permissionGranted = permissionValue === "granted";
240
+
241
+ this.logger?.trace(`[${commandId}] permission for raising notifications is: ${permissionValue}`);
242
+
243
+ return { permissionGranted };
244
+ }
245
+
246
+ private async raiseSimpleToast(settings: IOConnectBrowser.Notifications.RaiseOptions, id: string, commandId: string): Promise<void> {
247
+ this.logger?.trace(`[${commandId}] notification with a title: ${settings.title} was found to be non-persistent and therefore will be raised with the native notifications API`);
248
+
249
+ const options: NotificationOptions = Object.assign({}, settings, { title: undefined, clickInterop: undefined });
250
+
251
+ const notification = new Notification(settings.title, options);
252
+
253
+ notification.onclick = (): void => {
254
+
255
+ // do not refactor to a separate function
256
+ // will break the focus due to browser limitations
257
+ if (settings.focusPlatformOnDefaultClick) {
258
+ window.focus();
259
+ }
260
+
261
+ const notificationData = this.session.getNotification(id);
262
+
263
+ if (!notificationData) {
264
+ return;
265
+ }
266
+
267
+ this.handleNotificationClick({ action: "", notification: notificationData });
268
+ };
269
+
270
+ notification.onclose = (): void => this.removeNotification(id);
271
+ }
272
+
273
+ private async raiseActionsToast(settings: IOConnectBrowser.Notifications.RaiseOptions, id: string, commandId: string): Promise<void> {
274
+ this.logger?.trace(`[${commandId}] notification with a title: ${settings.title} was found to be persistent and therefore the service worker will be instructed to raise it.`);
275
+
276
+ await this.serviceWorkerController.showNotification(settings, id);
277
+ }
278
+
279
+ private raiseExtensionToast(settings: IOConnectBrowser.Notifications.RaiseOptions, id: string, commandId: string): Promise<void> {
280
+ return new Promise<void>((resolve, reject) => {
281
+
282
+ this.logger?.trace(`[${commandId}] notification with a title: ${settings.title} will be raised with the native extension notifications API, because the platform is running in extension mode`);
283
+
284
+ // need to get the notifications config from chrome
285
+ if (!this.extNotificationConfig) {
286
+ return reject("Cannot raise a notification, because the environment settings for the extension mode are missing.");
287
+ }
288
+
289
+ const buttons = settings.actions ?
290
+ settings.actions.map((action) => ({ title: action.title, iconUrl: action.icon })) :
291
+ undefined;
292
+
293
+ const chromeOptions: any = {
294
+ type: "basic",
295
+ iconUrl: settings.icon || this.extNotificationConfig.defaultIcon,
296
+ title: settings.title,
297
+ message: settings.body || this.extNotificationConfig.defaultMessage,
298
+ silent: settings.silent,
299
+ requireInteraction: settings.requireInteraction,
300
+ imageUrl: settings.image,
301
+ buttons
302
+ };
303
+
304
+ chrome.notifications.create(id, chromeOptions, () => resolve());
305
+ });
306
+ }
307
+
308
+ private async setupExtensionNotifications(): Promise<void> {
309
+ this.isInExtension = true;
310
+ this.extNotificationConfig = (await this.getExtNotificationsConfig()).notifications;
311
+ this.listenForExtensionNotificationsEvents();
312
+ }
313
+
314
+ private listenForExtensionNotificationsEvents(): void {
315
+
316
+ this._chromeClickedHandler = this.chromeClickedHandler.bind(this);
317
+
318
+ chrome.notifications.onClicked.addListener(this._chromeClickedHandler);
319
+
320
+ this._chromeButtonClickedHandler = this.chromeButtonClickedHandler.bind(this);
321
+
322
+ chrome.notifications.onButtonClicked.addListener(this._chromeButtonClickedHandler);
323
+
324
+ this._chromeClosedHandler = this.chromeClosedHandler.bind(this);
325
+
326
+ chrome.notifications.onClosed.addListener(this._chromeClosedHandler);
327
+ }
328
+
329
+ private removeExtensionNotificationsListeners(): void {
330
+ chrome.notifications.onClicked.removeListener(this._chromeClickedHandler);
331
+
332
+ chrome.notifications.onButtonClicked.removeListener(this._chromeButtonClickedHandler);
333
+
334
+ chrome.notifications.onClosed.removeListener(this._chromeClosedHandler);
335
+ }
336
+
337
+ private chromeClickedHandler(notificationId: string) : void {
338
+ const notificationData = this.session.getNotification(notificationId);
339
+
340
+ if (!notificationData) {
341
+ return;
342
+ }
343
+
344
+ this.handleNotificationClick({ notification: notificationData });
345
+ }
346
+
347
+ private chromeButtonClickedHandler(notificationId: string, buttonIndex: number): void {
348
+ const notificationData = this.session.getNotification(notificationId);
349
+
350
+ if (!notificationData) {
351
+ return;
352
+ }
353
+
354
+ if (!notificationData.actions) {
355
+ return;
356
+ }
357
+
358
+ const action = notificationData.actions[buttonIndex].action;
359
+
360
+ this.handleNotificationClick({ action, notification: notificationData });
361
+ }
362
+
363
+ private chromeClosedHandler(notificationId: string): void {
364
+ this.removeNotification(notificationId);
365
+ }
366
+
367
+ private listenForServiceWorkerNotificationEvents(): void {
368
+ const unsubNotificationClick = this.serviceWorkerController.onNotificationClick((clickData) => {
369
+ const notificationData = this.session.getNotification(clickData.glueData.id);
370
+
371
+ if (!notificationData) {
372
+ return;
373
+ }
374
+
375
+ this.handleNotificationClick({ action: clickData.action, notification: notificationData });
376
+ });
377
+
378
+ const unsubNotificationClose = this.serviceWorkerController.onNotificationClose((notification) => this.removeNotification(notification.glueData.id));
379
+
380
+ this.systemUnsubFuncs.push(unsubNotificationClick);
381
+ this.systemUnsubFuncs.push(unsubNotificationClose);
382
+ }
383
+
384
+ private getExtNotificationsConfig(): Promise<{ notifications: { defaultIcon: string; defaultMessage: string } }> {
385
+ return new Promise((resolve) => {
386
+ chrome.storage.local.get("notifications", (entry: any) => {
387
+ resolve(entry);
388
+ });
389
+ });
390
+ }
391
+
392
+ private handleNotificationClick(clickData: { notification: IOConnectBrowser.Notifications.NotificationData; action?: string }): void {
393
+ if (!clickData.action && clickData.notification.clickInterop) {
394
+ this.callDefinedInterop(clickData.notification.clickInterop);
395
+ }
396
+
397
+ const foundNotificationInteropAction = clickData.action ?
398
+ clickData.notification.actions?.find((actionDef) => actionDef.action === clickData.action) :
399
+ null;
400
+
401
+ if (foundNotificationInteropAction && foundNotificationInteropAction.interop) {
402
+ this.callDefinedInterop(foundNotificationInteropAction.interop);
403
+ }
404
+
405
+ if (clickData.notification.data?.glueData) {
406
+ delete clickData.notification.data.glueData;
407
+ }
408
+
409
+ const notificationEventPayload: NotificationEventPayload = {
410
+ definition: clickData.notification,
411
+ action: clickData.action,
412
+ id: clickData.notification.id
413
+ };
414
+
415
+ if (this.clearNotificationOnClick) {
416
+ this.removeNotification(clickData.notification.id);
417
+ }
418
+
419
+ this.glueController.pushSystemMessage("notifications", "notificationClick", notificationEventPayload);
420
+ }
421
+
422
+ private callDefinedInterop(interopConfig: IOConnectBrowser.Notifications.InteropActionSettings): void {
423
+ const method = interopConfig.method;
424
+ const args = interopConfig.arguments;
425
+ const target = interopConfig.target;
426
+
427
+ this.glueController.invokeMethod(method, args, target)
428
+ .catch((err) => {
429
+ const stringError = typeof err === "string" ? err : JSON.stringify(err.message);
430
+ this.logger?.warn(`The interop invocation defined in the clickInterop was rejected, reason: ${stringError}`);
431
+ });
432
+ }
433
+
434
+ private processNewNotification(settings: IOConnectBrowser.Notifications.RaiseOptions, id: string): void {
435
+ const notificationData: IOConnectBrowser.Notifications.NotificationData = { id, ...settings };
436
+
437
+ this.session.saveNotification(notificationData);
438
+
439
+ this.glueController.pushSystemMessage("notifications", "notificationRaised", { notification: notificationData });
440
+ }
441
+
442
+ private removeNotification(id: string): void {
443
+ this.session.removeNotification(id);
444
+
445
+ this.glueController.pushSystemMessage("notifications", "notificationClosed", { id });
446
+ }
447
+ }
@@ -0,0 +1,166 @@
1
+ import { IOConnectBrowser } from "@interopio/browser";
2
+ import { anyJson, array, boolean, constant, Decoder, number, object, oneOf, optional, string } from "decoder-validate";
3
+ import { nonEmptyStringDecoder, nonNegativeNumberDecoder } from "../../shared/decoders";
4
+ import { AllNotificationsData, NotificationClickConfig, NotificationsOperationsTypes, PermissionQueryResult, PermissionRequestResult, RaiseNotificationConfig, RaiseNotificationResult, SimpleNotificationSelect } from "./types";
5
+
6
+ export const notificationsOperationDecoder: Decoder<NotificationsOperationsTypes> = oneOf<"raiseNotification" | "requestPermission" | "getPermission" | "operationCheck" | "list" | "click" | "clear" | "clearAll">(
7
+ constant("raiseNotification"),
8
+ constant("requestPermission"),
9
+ constant("getPermission"),
10
+ constant("operationCheck"),
11
+ constant("list"),
12
+ constant("clear"),
13
+ constant("click"),
14
+ constant("clearAll")
15
+ );
16
+
17
+
18
+ const interopActionSettingsDecoder: Decoder<IOConnectBrowser.Notifications.InteropActionSettings> = object({
19
+ method: nonEmptyStringDecoder,
20
+ arguments: optional(anyJson()),
21
+ target: optional(oneOf<"all" | "best">(
22
+ constant("all"),
23
+ constant("best")
24
+ ))
25
+ });
26
+
27
+ const glue42NotificationActionDecoder: Decoder<IOConnectBrowser.Notifications.NotificationAction> = object({
28
+ action: string(),
29
+ title: nonEmptyStringDecoder,
30
+ icon: optional(string()),
31
+ interop: optional(interopActionSettingsDecoder)
32
+ });
33
+
34
+ const glue42NotificationOptionsDecoder: Decoder<IOConnectBrowser.Notifications.RaiseOptions> = object({
35
+ title: nonEmptyStringDecoder,
36
+ clickInterop: optional(interopActionSettingsDecoder),
37
+ actions: optional(array(glue42NotificationActionDecoder)),
38
+ focusPlatformOnDefaultClick: optional(boolean()),
39
+ badge: optional(string()),
40
+ body: optional(string()),
41
+ data: optional(anyJson()),
42
+ dir: optional(oneOf<"auto" | "ltr" | "rtl">(
43
+ constant("auto"),
44
+ constant("ltr"),
45
+ constant("rtl")
46
+ )),
47
+ icon: optional(string()),
48
+ image: optional(string()),
49
+ lang: optional(string()),
50
+ renotify: optional(boolean()),
51
+ requireInteraction: optional(boolean()),
52
+ silent: optional(boolean()),
53
+ tag: optional(string()),
54
+ timestamp: optional(nonNegativeNumberDecoder),
55
+ vibrate: optional(array(number())),
56
+ severity: optional(oneOf<"Low" | "Medium" | "High" | "Critical" | "None">(
57
+ constant("Low"),
58
+ constant("None"),
59
+ constant("Medium"),
60
+ constant("High"),
61
+ constant("Critical")
62
+ )),
63
+ showToast: optional(boolean()),
64
+ showInPanel: optional(boolean())
65
+ });
66
+
67
+ const glue42NotificationOptionsWithDefaultsDecoder: Decoder<IOConnectBrowser.Notifications.RaiseOptions> = object({
68
+ title: nonEmptyStringDecoder,
69
+ clickInterop: optional(interopActionSettingsDecoder),
70
+ actions: optional(array(glue42NotificationActionDecoder)),
71
+ focusPlatformOnDefaultClick: optional(boolean()),
72
+ badge: optional(string()),
73
+ body: optional(string()),
74
+ data: optional(anyJson()),
75
+ dir: optional(oneOf<"auto" | "ltr" | "rtl">(
76
+ constant("auto"),
77
+ constant("ltr"),
78
+ constant("rtl")
79
+ )),
80
+ icon: optional(string()),
81
+ image: optional(string()),
82
+ lang: optional(string()),
83
+ renotify: optional(boolean()),
84
+ requireInteraction: optional(boolean()),
85
+ silent: optional(boolean()),
86
+ tag: optional(string()),
87
+ timestamp: nonNegativeNumberDecoder,
88
+ vibrate: optional(array(number())),
89
+ severity: optional(oneOf<"Low" | "Medium" | "High" | "Critical" | "None">(
90
+ constant("Low"),
91
+ constant("None"),
92
+ constant("Medium"),
93
+ constant("High"),
94
+ constant("Critical")
95
+ )),
96
+ showToast: boolean(),
97
+ showInPanel: boolean()
98
+ });
99
+
100
+ export const raiseNotificationDecoder: Decoder<RaiseNotificationConfig> = object({
101
+ settings: glue42NotificationOptionsDecoder,
102
+ id: nonEmptyStringDecoder
103
+ });
104
+
105
+ export const raiseNotificationResultDecoder: Decoder<RaiseNotificationResult> = object({
106
+ settings: glue42NotificationOptionsWithDefaultsDecoder
107
+ });
108
+
109
+ export const permissionRequestResultDecoder: Decoder<PermissionRequestResult> = object({
110
+ permissionGranted: boolean()
111
+ });
112
+
113
+ export const permissionQueryResultDecoder: Decoder<PermissionQueryResult> = object({
114
+ permission: oneOf<"default" | "granted" | "denied">(
115
+ constant("default"),
116
+ constant("granted"),
117
+ constant("denied")
118
+ )
119
+ });
120
+
121
+ export const simpleNotificationSelectDecoder: Decoder<SimpleNotificationSelect> = object({
122
+ id: nonEmptyStringDecoder
123
+ });
124
+
125
+ export const notificationClickConfigDecoder: Decoder<NotificationClickConfig> = object({
126
+ id: nonEmptyStringDecoder,
127
+ action: optional(nonEmptyStringDecoder)
128
+ });
129
+
130
+ export const notificationsDataDecoder: Decoder<IOConnectBrowser.Notifications.NotificationData> = object({
131
+ id: nonEmptyStringDecoder,
132
+ title: nonEmptyStringDecoder,
133
+ clickInterop: optional(interopActionSettingsDecoder),
134
+ actions: optional(array(glue42NotificationActionDecoder)),
135
+ focusPlatformOnDefaultClick: optional(boolean()),
136
+ badge: optional(string()),
137
+ body: optional(string()),
138
+ data: optional(anyJson()),
139
+ dir: optional(oneOf<"auto" | "ltr" | "rtl">(
140
+ constant("auto"),
141
+ constant("ltr"),
142
+ constant("rtl")
143
+ )),
144
+ icon: optional(string()),
145
+ image: optional(string()),
146
+ lang: optional(string()),
147
+ renotify: optional(boolean()),
148
+ requireInteraction: optional(boolean()),
149
+ silent: optional(boolean()),
150
+ tag: optional(string()),
151
+ timestamp: optional(nonNegativeNumberDecoder),
152
+ vibrate: optional(array(number())),
153
+ severity: optional(oneOf<"Low" | "Medium" | "High" | "Critical" | "None">(
154
+ constant("Low"),
155
+ constant("None"),
156
+ constant("Medium"),
157
+ constant("High"),
158
+ constant("Critical")
159
+ )),
160
+ showToast: optional(boolean()),
161
+ showInPanel: optional(boolean())
162
+ });
163
+
164
+ export const allNotificationsDataDecoder: Decoder<AllNotificationsData> = object({
165
+ notifications: array(notificationsDataDecoder)
166
+ });
@@ -0,0 +1,49 @@
1
+ import { IOConnectBrowser } from "@interopio/browser";
2
+
3
+ export type NotificationsOperationsTypes = "raiseNotification" | "requestPermission" | "getPermission" | "operationCheck" |
4
+ "list" | "click" | "clear" | "clearAll";
5
+
6
+ export type NotificationPermissionTypes = "default" | "granted" | "denied";
7
+
8
+ export interface RaiseNotificationConfig {
9
+ settings: IOConnectBrowser.Notifications.RaiseOptions;
10
+ id: string;
11
+ }
12
+
13
+ export interface RaiseNotificationResult {
14
+ settings: IOConnectBrowser.Notifications.RaiseOptions;
15
+ }
16
+
17
+ export interface GlueNotificationData {
18
+ clickInterop?: IOConnectBrowser.Notifications.InteropActionSettings;
19
+ actions?: IOConnectBrowser.Notifications.NotificationAction[];
20
+ focusPlatformOnDefaultClick?: boolean;
21
+ id: string;
22
+ }
23
+
24
+ export interface PermissionRequestResult {
25
+ permissionGranted: boolean;
26
+ }
27
+
28
+ export interface PermissionQueryResult {
29
+ permission: NotificationPermissionTypes;
30
+ }
31
+
32
+ export interface NotificationEventPayload {
33
+ definition: IOConnectBrowser.Notifications.NotificationDefinition;
34
+ action?: string;
35
+ id?: string;
36
+ }
37
+
38
+ export interface NotificationClickConfig {
39
+ id: string;
40
+ action?: string;
41
+ }
42
+
43
+ export interface SimpleNotificationSelect {
44
+ id: string;
45
+ }
46
+
47
+ export interface AllNotificationsData {
48
+ notifications: IOConnectBrowser.Notifications.NotificationData[];
49
+ }
@@ -0,0 +1,7 @@
1
+ import { IOConnectBrowser } from "@interopio/browser";
2
+
3
+ export const setNotificationDefaults = (settings: IOConnectBrowser.Notifications.RaiseOptions): void => {
4
+ settings.showToast = typeof settings.showToast === "boolean" ? settings.showToast : true;
5
+ settings.showInPanel = typeof settings.showInPanel === "boolean" ? settings.showInPanel : true;
6
+ settings.timestamp = typeof settings.timestamp === "undefined" ? Date.now() : settings.timestamp;
7
+ };