@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,506 @@
1
+ import { IOConnectWorkspaces } from "@interopio/workspaces-api";
2
+ import { RawWindowsLayoutDataRequestConfig } from "../layouts/types";
3
+
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ export interface WorkspaceWindowData {
6
+ name: string;
7
+ windowId: string;
8
+ frameId: string;
9
+ workspaceId?: string;
10
+ appName?: string;
11
+ context?: any;
12
+ title?: string;
13
+ }
14
+
15
+ export type WorkspaceEventType = "frame" | "workspace" | "container" | "window";
16
+ export type WorkspaceEventScope = "global" | "frame" | "workspace" | "window";
17
+ export type WorkspaceEventAction = "opened" | "closing" | "closed" | "focus" | "added" | "loaded" | "removed" | "childrenUpdate" | "containerChange" | "maximized" | "restored" | "minimized" | "normal" | "selected" | "lock-configuration-changed" | "hibernated" | "resumed";
18
+ export interface WorkspaceEventPayload {
19
+ action: WorkspaceEventAction;
20
+ type: WorkspaceEventType;
21
+ payload: FrameStreamData | WorkspaceStreamData | ContainerStreamData | WindowStreamData;
22
+ }
23
+
24
+ export type WorkspacesOperationsTypes = "isWindowInWorkspace" |
25
+ "createWorkspace" |
26
+ "getAllFramesSummaries" |
27
+ "getFrameSummary" |
28
+ "getAllWorkspacesSummaries" |
29
+ "getWorkspaceSnapshot" |
30
+ "getAllLayoutsSummaries" |
31
+ "openWorkspace" |
32
+ "deleteLayout" |
33
+ "saveLayout" |
34
+ "importLayout" |
35
+ "exportAllLayouts" |
36
+ "restoreItem" |
37
+ "maximizeItem" |
38
+ "focusItem" |
39
+ "closeItem" |
40
+ "resizeItem" |
41
+ "moveFrame" |
42
+ "getFrameSnapshot" |
43
+ "forceLoadWindow" |
44
+ "ejectWindow" |
45
+ "setItemTitle" |
46
+ "moveWindowTo" |
47
+ "addWindow" |
48
+ "addContainer" |
49
+ "bundleWorkspace" |
50
+ "bundleItem" |
51
+ "changeFrameState" |
52
+ "getFrameState" |
53
+ "getFrameBounds" |
54
+ "frameHello" |
55
+ "hibernateWorkspace" |
56
+ "resumeWorkspace" |
57
+ "getWorkspacesConfig" |
58
+ "lockWorkspace" |
59
+ "lockContainer" |
60
+ "lockWindow" |
61
+ "pinWorkspace" |
62
+ "unpinWorkspace" |
63
+ "getWorkspaceIcon" |
64
+ "setWorkspaceIcon" |
65
+ "createFrame" |
66
+ "initFrame" |
67
+ "checkStarted" |
68
+ "getPlatformFrameId" |
69
+ "getWorkspaceWindowsOnLayoutSaveContext" |
70
+ "getWorkspacesLayouts" |
71
+ "setMaximizationBoundary" |
72
+ "operationCheck" |
73
+ "getWorkspaceWindowFrameBounds" |
74
+ "focusChange";
75
+
76
+ export interface FrameQueryConfig {
77
+ frameId?: string;
78
+ itemId?: string;
79
+ newFrame?: IOConnectWorkspaces.NewFrameConfig | boolean;
80
+ }
81
+
82
+ export interface FrameLock {
83
+ lift(value?: void | PromiseLike<void> | undefined): void;
84
+ }
85
+
86
+ export interface FrameHello {
87
+ windowId?: string;
88
+ }
89
+
90
+ export interface FrameInstance {
91
+ windowId: string;
92
+ }
93
+
94
+ export interface FrameSessionData {
95
+ windowId: string;
96
+ active: boolean;
97
+ isPlatform: boolean;
98
+ layoutComponentId?: string;
99
+ }
100
+
101
+ // #region incoming
102
+ export interface IsWindowInSwimlaneResult {
103
+ inWorkspace: boolean;
104
+ }
105
+
106
+ export interface WorkspacesLayoutImportConfig {
107
+ layout: IOConnectWorkspaces.WorkspaceLayout;
108
+ mode: "replace" | "merge";
109
+ }
110
+
111
+ export interface WorkspaceConfigResult {
112
+ frameId: string;
113
+ title: string;
114
+ name: string;
115
+ positionIndex: number;
116
+ layoutName: string | undefined;
117
+ isSelected: boolean;
118
+ isHibernated: boolean;
119
+ lastActive: number;
120
+ allowDrop?: boolean;
121
+ allowExtract?: boolean;
122
+ allowWindowReorder?: boolean;
123
+ allowSystemHibernation?: boolean;
124
+ allowSplitters?: boolean;
125
+ showCloseButton?: boolean;
126
+ showSaveButton?: boolean;
127
+ allowWorkspaceTabReorder?: boolean;
128
+ allowDropLeft?: boolean;
129
+ allowDropTop?: boolean;
130
+ allowDropRight?: boolean;
131
+ allowDropBottom?: boolean;
132
+ showAddWindowButtons?: boolean;
133
+ showEjectButtons?: boolean;
134
+ showWindowCloseButtons?: boolean;
135
+ minWidth?: number;
136
+ maxWidth?: number;
137
+ minHeight?: number;
138
+ maxHeight?: number;
139
+ widthInPx?: number;
140
+ heightInPx?: number;
141
+ }
142
+
143
+ export interface BaseChildSnapshotConfig {
144
+ frameId: string;
145
+ workspaceId: string;
146
+ positionIndex: number;
147
+ }
148
+
149
+ export interface ParentSnapshotConfig extends BaseChildSnapshotConfig {
150
+ type?: "window" | "row" | "column" | "group"; // this just a place-holder until there are real parent-specific configs
151
+ }
152
+
153
+ export interface SwimlaneWindowSnapshotConfig extends BaseChildSnapshotConfig {
154
+ windowId?: string;
155
+ isMaximized: boolean;
156
+ isFocused: boolean;
157
+ appName?: string;
158
+ title?: string;
159
+ context?: any;
160
+ }
161
+
162
+ export interface ChildSnapshotResult {
163
+ id?: string;
164
+ type: "window" | "row" | "column" | "group";
165
+ children?: ChildSnapshotResult[];
166
+ config: ParentSnapshotConfig | SwimlaneWindowSnapshotConfig;
167
+ }
168
+
169
+ export interface FrameSnapshotResult {
170
+ id: string;
171
+ config: any;
172
+ workspaces: WorkspaceSnapshotResult[];
173
+ }
174
+
175
+ export interface FrameSummaryResult {
176
+ id: string;
177
+ isFocused?: boolean;
178
+ isInitialized?: boolean;
179
+ initializationContext?: {
180
+ context?: object;
181
+ };
182
+ }
183
+
184
+ export interface FrameSummariesResult {
185
+ summaries: FrameSummaryResult[];
186
+ }
187
+
188
+ export interface WorkspaceSnapshotResult {
189
+ id: string;
190
+ config: WorkspaceConfigResult;
191
+ children: ChildSnapshotResult[];
192
+ frameSummary: FrameSummaryResult;
193
+ context?: any;
194
+ }
195
+
196
+ export interface WorkspaceSummaryResult {
197
+ id: string;
198
+ config: WorkspaceConfigResult;
199
+ }
200
+
201
+ export interface WorkspaceSummariesResult {
202
+ summaries: WorkspaceSummaryResult[];
203
+ }
204
+
205
+ export interface LayoutSummary {
206
+ name: string;
207
+ }
208
+
209
+ export interface LayoutSummariesResult {
210
+ summaries: LayoutSummary[];
211
+ }
212
+
213
+ export interface ContainerSummaryResult {
214
+ itemId: string;
215
+ config: ParentSnapshotConfig;
216
+ }
217
+
218
+ export interface ExportedLayoutsResult {
219
+ layouts: IOConnectWorkspaces.WorkspaceLayout[];
220
+ }
221
+
222
+ export interface SimpleWindowOperationSuccessResult {
223
+ windowId: string;
224
+ }
225
+
226
+ export interface AddItemResult {
227
+ itemId: string;
228
+ windowId?: string;
229
+ }
230
+
231
+ export interface PingResult {
232
+ live: boolean;
233
+ }
234
+
235
+ export interface FrameStateResult {
236
+ state: IOConnectWorkspaces.FrameState;
237
+ }
238
+
239
+ export interface FrameBounds {
240
+ top: number;
241
+ left: number;
242
+ width: number;
243
+ height: number;
244
+ }
245
+
246
+ export interface FrameBoundsResult {
247
+ bounds: FrameBounds;
248
+ }
249
+
250
+ export interface WorkspaceIconResult {
251
+ icon?: string;
252
+ }
253
+
254
+ // #endregion
255
+
256
+ // #region outgoing
257
+
258
+ export interface WorkspaceCreateConfigProtocol extends IOConnectWorkspaces.WorkspaceDefinition {
259
+ saveConfig?: IOConnectWorkspaces.WorkspaceCreateConfig;
260
+ }
261
+
262
+ export interface FrameInitializationConfigProtocol extends IOConnectWorkspaces.FrameInitializationConfig {
263
+ frameId: string;
264
+ }
265
+
266
+ export interface GetFrameSummaryConfig {
267
+ itemId: string;
268
+ }
269
+
270
+ export interface OpenWorkspaceConfig {
271
+ name: string;
272
+ restoreOptions?: IOConnectWorkspaces.RestoreWorkspaceConfig;
273
+ }
274
+
275
+ export interface DeleteLayoutConfig {
276
+ name: string;
277
+ }
278
+
279
+ export interface SimpleItemConfig {
280
+ itemId: string;
281
+ }
282
+
283
+ export interface FrameSnapshotConfig extends SimpleItemConfig {
284
+ excludeIds?: boolean;
285
+ }
286
+
287
+ export interface FrameStateConfig {
288
+ frameId: string;
289
+ requestedState?: IOConnectWorkspaces.FrameState;
290
+ }
291
+
292
+ export interface ResizeItemConfig {
293
+ itemId: string;
294
+ width?: number;
295
+ height?: number;
296
+ relative?: boolean;
297
+ }
298
+
299
+ export interface MoveFrameConfig {
300
+ itemId: string;
301
+ top?: number;
302
+ left?: number;
303
+ relative?: boolean;
304
+ }
305
+
306
+ export interface SetItemTitleConfig {
307
+ itemId: string;
308
+ title: string;
309
+ }
310
+
311
+ export interface MoveWindowConfig {
312
+ itemId: string;
313
+ containerId: string;
314
+ }
315
+
316
+ export interface AddWindowConfig {
317
+ definition: IOConnectWorkspaces.WorkspaceWindowDefinition;
318
+ parentId: string;
319
+ parentType: "row" | "column" | "group" | "workspace";
320
+ }
321
+
322
+ export interface AddContainerConfig {
323
+ definition: IOConnectWorkspaces.BoxDefinition;
324
+ parentId: string;
325
+ parentType: "row" | "column" | "group" | "workspace";
326
+ }
327
+
328
+ export interface BundleWorkspaceConfig {
329
+ type: "row" | "column";
330
+ workspaceId: string;
331
+ }
332
+
333
+ export interface BundleItemConfig {
334
+ type: "row" | "column";
335
+ itemId: string;
336
+ }
337
+
338
+ export interface WorkspaceSelector {
339
+ workspaceId: string;
340
+ }
341
+
342
+ export interface PinWorkspaceConfig extends WorkspaceSelector {
343
+ icon?: string;
344
+ }
345
+
346
+ export interface SetWorkspaceIconConfig extends WorkspaceSelector {
347
+ icon?: string;
348
+ }
349
+
350
+ // #endregion
351
+
352
+ export interface FrameStreamData {
353
+ frameSummary: FrameSummaryResult;
354
+ frameBounds?: FrameBounds;
355
+ }
356
+
357
+ export interface WorkspaceStreamData {
358
+ workspaceSummary: WorkspaceSummaryResult;
359
+ frameSummary: FrameSummaryResult;
360
+ frameBounds?: FrameBounds;
361
+ }
362
+
363
+ export interface ContainerStreamData {
364
+ containerSummary: ContainerSummaryResult;
365
+ }
366
+
367
+ export interface WindowStreamData {
368
+ windowSummary: {
369
+ itemId: string;
370
+ parentId: string;
371
+ config: SwimlaneWindowSnapshotConfig;
372
+ };
373
+ }
374
+
375
+ export type WorkspaceConfigWithReuseWorkspaceId = IOConnectWorkspaces.WorkspaceConfig & { reuseWorkspaceId: string };
376
+
377
+ export interface LockWindowConfig {
378
+ windowPlacementId: string;
379
+ config?: {
380
+ allowExtract?: boolean;
381
+ allowReorder?: boolean;
382
+ showCloseButton?: boolean;
383
+ };
384
+ }
385
+
386
+ export interface LockRowConfig {
387
+ itemId: string;
388
+ type: "row";
389
+ config?: {
390
+ allowDrop?: boolean;
391
+ allowSplitters?: boolean;
392
+ };
393
+ }
394
+
395
+ export interface LockColumnConfig {
396
+ itemId: string;
397
+ type: "column";
398
+ config?: {
399
+ allowDrop?: boolean;
400
+ allowSplitters?: boolean;
401
+ };
402
+ }
403
+
404
+ export interface LockGroupConfig {
405
+ itemId: string;
406
+ type: "group";
407
+ config?: {
408
+ allowExtract?: boolean;
409
+ allowReorder?: boolean;
410
+ allowDrop?: boolean;
411
+ allowDropHeader?: boolean;
412
+ allowDropLeft?: boolean;
413
+ allowDropTop?: boolean;
414
+ allowDropRight?: boolean;
415
+ allowDropBottom?: boolean;
416
+ showMaximizeButton?: boolean;
417
+ showEjectButton?: boolean;
418
+ showAddWindowButton?: boolean;
419
+ };
420
+ }
421
+
422
+ export type LockContainerConfig = LockColumnConfig | LockRowConfig | LockGroupConfig;
423
+
424
+ export interface LockWorkspaceConfig {
425
+ workspaceId: string;
426
+ config?: {
427
+ allowDrop?: boolean;
428
+ allowDropLeft?: boolean;
429
+ allowDropTop?: boolean;
430
+ allowDropRight?: boolean;
431
+ allowDropBottom?: boolean;
432
+ allowExtract?: boolean;
433
+ allowWindowReorder?: boolean;
434
+ allowSystemHibernation?: boolean;
435
+ allowSplitters?: boolean;
436
+ showCloseButton?: boolean;
437
+ showSaveButton?: boolean;
438
+ allowWorkspaceTabReorder?: boolean;
439
+ showAddWindowButtons?: boolean;
440
+ showWindowCloseButtons?: boolean;
441
+ showEjectButtons?: boolean;
442
+ };
443
+ }
444
+
445
+ export interface GroupDefinitionConfig {
446
+ minWidth?: number;
447
+ maxWidth?: number;
448
+ minHeight?: number;
449
+ maxHeight?: number;
450
+ allowExtract?: boolean;
451
+ allowReorder?: boolean;
452
+ showMaximizeButton?: boolean;
453
+ showEjectButton?: boolean;
454
+ allowDrop?: boolean;
455
+ allowDropHeader?: boolean;
456
+ allowDropLeft?: boolean;
457
+ allowDropTop?: boolean;
458
+ allowDropRight?: boolean;
459
+ allowDropBottom?: boolean;
460
+ showAddWindowButton?: boolean;
461
+ }
462
+
463
+ export interface RowDefinitionConfig {
464
+ minHeight?: number;
465
+ maxHeight?: number;
466
+ allowDrop?: boolean;
467
+ allowSplitters?: boolean;
468
+ isPinned?: boolean;
469
+ }
470
+
471
+ export interface ColumnDefinitionConfig {
472
+ minWidth?: number;
473
+ maxWidth?: number;
474
+ allowDrop?: boolean;
475
+ allowSplitters?: boolean;
476
+ isPinned?: boolean;
477
+ }
478
+
479
+ export interface GetWorkspaceWindowsOnLayoutSaveContextConfig extends RawWindowsLayoutDataRequestConfig {
480
+ windowIds: string[];
481
+ }
482
+
483
+ export interface SetMaximizationBoundaryConfig {
484
+ itemId: string;
485
+ enabled: boolean;
486
+ }
487
+
488
+ export interface WorkspaceWindowOnSaveData {
489
+ windowId: string;
490
+ windowContext?: any;
491
+ }
492
+
493
+ export interface GetWorkspaceWindowsOnLayoutSaveContextResult {
494
+ windowsOnSaveData: WorkspaceWindowOnSaveData[];
495
+ }
496
+
497
+ export interface GetWorkspacesLayoutsConfig {
498
+ frameId: string;
499
+ layoutName: string;
500
+ layoutType: "Global" | "Workspace";
501
+ context?: any;
502
+ }
503
+
504
+ export interface GetWorkspacesLayoutsResponse {
505
+ workspaces: WorkspaceSnapshotResult[];
506
+ }
@@ -0,0 +1,156 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { IOConnectBrowserPlatform } from "../browser.platform";
3
+ import { platformConfigDecoder } from "./shared/decoders";
4
+ import { defaultPlatformConfig } from "./common/defaultConfig";
5
+ import deepMerge from "deepmerge";
6
+ import { PlatformController } from "./controllers/main";
7
+ import { IOConnectBrowser } from "@interopio/browser";
8
+ import IOSearch from "@interopio/search-api";
9
+ import { InternalPlatformConfig } from "./common/types";
10
+ import { nanoid } from "nanoid";
11
+ import { SessionStorageController } from "./storage/session";
12
+
13
+ export class Platform {
14
+
15
+ private platformConfig!: InternalPlatformConfig;
16
+
17
+ constructor(
18
+ private readonly controller: PlatformController,
19
+ private readonly session: SessionStorageController,
20
+ private readonly config?: IOConnectBrowserPlatform.Config,
21
+ ) {}
22
+
23
+ public async ready(): Promise<void> {
24
+ this.session.start();
25
+
26
+ this.checkSingleton();
27
+ this.processConfig(this.config);
28
+
29
+ await this.controller.start(this.platformConfig);
30
+ }
31
+
32
+ public getClientGlue(): IOConnectBrowser.API {
33
+ return this.controller.getClientGlue();
34
+ }
35
+
36
+ public getPlatformApi(): IOConnectBrowserPlatform.API {
37
+ return this.controller.platformApi;
38
+ }
39
+
40
+ private checkSingleton(): void {
41
+ const globalNamespace = (window as any).glue42core || (window as any).iobrowser;
42
+
43
+ if (globalNamespace && globalNamespace.platformStarted) {
44
+ throw new Error("The Glue42 Core Platform has already been started for this application.");
45
+ }
46
+ }
47
+
48
+ private processConfig(config?: IOConnectBrowserPlatform.Config): void {
49
+ if (!config) {
50
+ throw new Error("Cannot start the IoConnect Browser Platform without a config object.");
51
+ }
52
+
53
+ const verifiedConfig = platformConfigDecoder.runWithException(config);
54
+
55
+ this.addSearch(verifiedConfig);
56
+
57
+ this.validatePlugins(verifiedConfig);
58
+
59
+ this.platformConfig = deepMerge<InternalPlatformConfig>(defaultPlatformConfig, verifiedConfig as any);
60
+
61
+ let systemSettings = this.session.getSystemSettings();
62
+
63
+ if (!systemSettings) {
64
+ systemSettings = {
65
+ systemInstanceId: nanoid(),
66
+ ctxTrackInstanceId: nanoid()
67
+ };
68
+
69
+ this.session.saveSystemSettings(systemSettings);
70
+ }
71
+
72
+ this.platformConfig.workspacesFrameCache = typeof verifiedConfig.workspaces?.frameCache === "boolean" ? verifiedConfig.workspaces?.frameCache : true;
73
+
74
+ // deep merge deletes the promise object when merging, probably due to some cyclical references
75
+ this.transferPromiseObjects(verifiedConfig);
76
+
77
+ const iobrowser = {
78
+ isPlatformFrame: !!verifiedConfig.workspaces?.isFrame,
79
+ initAsEmptyFrame: !!verifiedConfig.workspaces?.initAsEmpty,
80
+ workspacesFrameCache: this.platformConfig.workspacesFrameCache,
81
+ platformStarted: true,
82
+ environment: Object.assign({}, this.platformConfig.environment, { extension: undefined }),
83
+ communicationId: systemSettings.systemInstanceId,
84
+ workspaces: {
85
+ frameCache: this.platformConfig.workspacesFrameCache,
86
+ isPlatform: !!verifiedConfig.workspaces?.isFrame,
87
+ initAsEmpty: !!verifiedConfig.workspaces?.initAsEmpty
88
+ }
89
+ };
90
+
91
+ (window as any).iobrowser = iobrowser;
92
+ }
93
+
94
+ private transferPromiseObjects(verifiedConfig: IOConnectBrowserPlatform.Config): void {
95
+ if (verifiedConfig.serviceWorker?.registrationPromise) {
96
+ (this.platformConfig.serviceWorker as IOConnectBrowserPlatform.ServiceWorker.Config).registrationPromise = verifiedConfig.serviceWorker.registrationPromise;
97
+ }
98
+
99
+ if (verifiedConfig.plugins && verifiedConfig.plugins.definitions.length) {
100
+ const definitions = verifiedConfig.plugins.definitions;
101
+
102
+ definitions.forEach((def) => {
103
+ const found = this.platformConfig.plugins?.definitions.find((savedDef) => savedDef.name === def.name);
104
+
105
+ if (found) {
106
+ found.config = def.config;
107
+ }
108
+ });
109
+ }
110
+ }
111
+
112
+ private validatePlugins(verifiedConfig: IOConnectBrowserPlatform.Config): void {
113
+
114
+ if (!verifiedConfig.plugins?.definitions) {
115
+ return;
116
+ }
117
+
118
+ const badDefinitions = verifiedConfig.plugins.definitions.reduce<Array<{ name: string; startType: string; stopType: string }>>((soFar, definition) => {
119
+ const startType = typeof definition.start;
120
+ const stopType = typeof definition.stop;
121
+ const name = definition.name;
122
+
123
+ if (startType !== "function" || (definition.stop && stopType !== "function")) {
124
+ soFar.push({ name, startType, stopType });
125
+ }
126
+
127
+ return soFar;
128
+ }, []);
129
+
130
+ if (badDefinitions.length) {
131
+ const errorStack = badDefinitions
132
+ .map((def) => `The start and stop functions for plugin ${def.name} were expected to be of type function, but was provided start: ${def.startType} and stop: ${def.stopType}`)
133
+ .join("\n");
134
+ throw new Error(errorStack);
135
+ }
136
+ }
137
+
138
+ private addSearch(verifiedConfig: IOConnectBrowserPlatform.Config): void {
139
+ if (!verifiedConfig.browser) {
140
+ verifiedConfig.browser = {
141
+ libraries: [IOSearch]
142
+ };
143
+ return;
144
+ }
145
+
146
+ if (verifiedConfig.browser.libraries) {
147
+ verifiedConfig.browser.libraries.push(IOSearch);
148
+ return;
149
+ }
150
+
151
+ if (!verifiedConfig.browser.libraries) {
152
+ verifiedConfig.browser.libraries = [IOSearch];
153
+ return;
154
+ }
155
+ }
156
+ }