@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
package/license.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Tick42
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@interopio/browser-platform",
3
+ "version": "3.0.1",
4
+ "description": "IoConnect Browser main application package",
5
+ "main": "dist/browser.platform.umd.js",
6
+ "module": "dist/browser.platform.es.js",
7
+ "types": "./browser.platform.d.ts",
8
+ "keywords": [
9
+ "glue",
10
+ "glue42",
11
+ "desktop",
12
+ "interop",
13
+ "context",
14
+ "server",
15
+ "layouts",
16
+ "metrics",
17
+ "io.connect",
18
+ "interop.io",
19
+ "io.connect browser",
20
+ "io.connect desktop",
21
+ "io.connect browser platform"
22
+ ],
23
+ "homepage": "https://interop.io/",
24
+ "author": {
25
+ "name": "Interop.IO",
26
+ "url": "https://interop.io/"
27
+ },
28
+ "license": "Commercial",
29
+ "publishConfig": {
30
+ "registry": "https://registry.npmjs.org",
31
+ "access": "public"
32
+ },
33
+ "scripts": {
34
+ "test": "echo no tests found",
35
+ "build": "rollup -c",
36
+ "audit": "echo no audit found",
37
+ "audit:V1": "node ../../scripts/audit/index.js",
38
+ "preversion": "npm run build && npm run test && npm run audit",
39
+ "version": "npm run build"
40
+ },
41
+ "dependencies": {
42
+ "@glue42/desktop": "^5.23.0",
43
+ "@glue42/gateway-web": "^3.0.17",
44
+ "@glue42/server-api": "^1.5.0",
45
+ "@interopio/browser": "^3.0.1",
46
+ "@interopio/core": "^6.0.1",
47
+ "@interopio/search-api": "^2.0.1",
48
+ "@interopio/workspaces-api": "^3.0.1",
49
+ "callback-registry": "^2.7.1",
50
+ "decoder-validate": "0.0.2",
51
+ "deep-equal": "^2.1.0",
52
+ "deepmerge": "^4.2.2",
53
+ "fast-deep-equal": "^3.1.3",
54
+ "idb": "^7.1.1",
55
+ "jsrsasign": "^10.8.6",
56
+ "nanoid": "^4.0.0",
57
+ "shortid": "^2.2.16",
58
+ "ua-parser-js": "^1.0.35"
59
+ },
60
+ "devDependencies": {
61
+ "@rollup/plugin-commonjs": "^25.0.3",
62
+ "@rollup/plugin-json": "^6.0.0",
63
+ "@rollup/plugin-node-resolve": "^15.1.0",
64
+ "@rollup/plugin-terser": "^0.4.3",
65
+ "@rollup/plugin-typescript": "^11.1.2",
66
+ "@types/chrome": "^0.0.204",
67
+ "@types/deep-equal": "^1.0.1",
68
+ "@types/jsrsasign": "^10.5.8",
69
+ "@types/node": "^18.11.15",
70
+ "@types/shortid": "^0.0.29",
71
+ "@types/ua-parser-js": "^0.7.36",
72
+ "rollup": "^3.28.0",
73
+ "rollup-plugin-delete": "^2.0.0",
74
+ "rollup-plugin-node-builtins": "^2.1.2",
75
+ "typescript": "^4.9.4"
76
+ },
77
+ "gitHead": "e611bbfef816b6ba3722ab8f0ac21d420af8ec9d"
78
+ }
package/readme.md ADDED
@@ -0,0 +1,9 @@
1
+ ## IO Connect Browser Platform
2
+
3
+ A IO Connect Browser Platform application (or "Main application") in the context of [**IO Connect Browser**](https://core-docs.glue42.com/reference/core/latest/glue42%20web/index.html) is a web application that uses the [`@interopio/browser-platform`](https://www.npmjs.com/package/@glue42/core-plus) package. This app is responsible for configuring the entire IO Connect Browser environment and acts as a central hub for all [IO Connect Browser Client](https://core-docs.glue42.com/core-concept/web-client/overview/index.html) apps in your **IO Connect Browser** project. All IO Connect operations are routed through this Main application, meaning that this is the place where you can get centralized logging, information about all operations and details about the general state of your project. The configuration for all IO Connect Browser libraries (e.g., Application Management, Layouts, Workspaces, Plugins, Notifications) is handled here.
4
+
5
+ The Main application also provides tracking and control over non-IOConnect applications opened through it. The level of control is limited, but all basic operations are available - open, close, receiving events, listing, adding and manipulating via [Workspaces](https://core-docs.glue42.com/capabilities/windows/workspaces/overview/index.html).
6
+
7
+ If the Main application is closed, all [IO Connect Browser Client](https://core-docs.glue42.com/core-concept/web-client/overview/index.html) applications will lose their connection to IO Connect Browser and therefore - all IO Connect capabilities. Opening the Main app again *won't reestablish the connection*, because this will effectively be an entirely new window with a new session and new context. However, if the Main application is *refreshed*, the existing [IO Connect Browser Client](https://core-docs.glue42.com/core-concept/web-client/overview/index.html) apps will detect that and *will reconnect* as soon as the Main app is back online.
8
+
9
+ IO Connect Browser Platform requires a license token to initialize. Please contact Interop.IO Sales team at sales@interop.io to obtain a license token.
@@ -0,0 +1,45 @@
1
+ const typescript = require('@rollup/plugin-typescript');
2
+ const commonjs = require('@rollup/plugin-commonjs');
3
+ const resolve = require('@rollup/plugin-node-resolve');
4
+ const json = require('@rollup/plugin-json');
5
+ const terser = require('@rollup/plugin-terser');
6
+ const builtins = require('rollup-plugin-node-builtins');
7
+ const pkg = require('./package.json');
8
+ const del = require('rollup-plugin-delete');
9
+
10
+ module.exports = {
11
+ input: 'src/index.ts',
12
+ output: [
13
+ {
14
+ file: pkg.main,
15
+ format: 'umd',
16
+ name: 'IoConnectBrowserPlatform',
17
+ sourcemap: true,
18
+ intro: 'const global = window;',
19
+ },
20
+ {
21
+ file: pkg.module,
22
+ format: 'es',
23
+ sourcemap: true,
24
+ intro: 'const global = window;'
25
+ },
26
+ ],
27
+ external: [
28
+ ...Object.keys(pkg.peerDependencies || {}),
29
+ ],
30
+
31
+ plugins: [
32
+ del({ targets: 'dist/*' }),
33
+ typescript({
34
+ typescript: require('typescript'),
35
+ noEmitOnError: true
36
+ }),
37
+ resolve({
38
+ browser: true
39
+ }),
40
+ commonjs(),
41
+ json(),
42
+ builtins(),
43
+ // terser()
44
+ ],
45
+ };
@@ -0,0 +1,46 @@
1
+ export const Glue42CoreMessageTypes = {
2
+ connectionRequest: { name: "connectionRequest" },
3
+ connectionAccepted: { name: "connectionAccepted" },
4
+ platformPing: { name: "platformPing" },
5
+ platformReady: { name: "platformReady" },
6
+ platformUnload: { name: "platformUnload" },
7
+ clientUnload: { name: "clientUnload" },
8
+ parentPing: { name: "parentPing" },
9
+ parentReady: { name: "parentReady" },
10
+ gatewayDisconnect: { name: "gatewayDisconnect" },
11
+ gatewayInternalConnect: { name: "gatewayInternalConnect" },
12
+ transportSwitchRequest: { name: "transportSwitchRequest" },
13
+ transportSwitchResponse: { name: "transportSwitchResponse" },
14
+ getCurrentTransport: { name: "getCurrentTransport" },
15
+ getCurrentTransportResponse: { name: "getCurrentTransportResponse" },
16
+ checkPreferredLogic: { name: "checkPreferredLogic" },
17
+ checkPreferredConnection: { name: "checkPreferredConnection" },
18
+ checkPreferredLogicResponse: { name: "checkPreferredLogicResponse" },
19
+ checkPreferredConnectionResponse: { name: "checkPreferredConnectionResponse" }
20
+ };
21
+
22
+ export const GlueWebPlatformControlName = "T42.Web.Platform.Control";
23
+
24
+ export const GlueWebPlatformStreamName = "T42.Web.Platform.Stream";
25
+
26
+ export const GlueClientControlName = "T42.Web.Client.Control";
27
+
28
+ export const GlueWebPlatformWorkspacesStreamName = "T42.Web.Platform.WSP.Stream";
29
+
30
+ export const GlueWorkspaceFrameClientControlName = "T42.Workspaces.Control";
31
+
32
+ export const GlueWorkspacesEventsReceiverName = "T42.Workspaces.Events";
33
+
34
+ export const GlueWebIntentsPrefix = "Tick42.FDC3.Intents.";
35
+
36
+ export const ChannelContextPrefix = "___channel___";
37
+
38
+ export const dbName = "glue42core";
39
+
40
+ export const serviceWorkerBroadcastChannelName = "glue42-core-worker";
41
+
42
+ export const dbVersion = 2;
43
+
44
+ export const webPlatformTransportName = "web-platform";
45
+
46
+ export const defaultNoAppWindowComponentAppName = "no-app-window";
@@ -0,0 +1,56 @@
1
+ import { InternalPlatformConfig } from "./types";
2
+
3
+ export const defaultPlatformConfig: InternalPlatformConfig = {
4
+ windows: {
5
+ windowResponseTimeoutMs: 10000,
6
+ defaultWindowOpenBounds: {
7
+ top: 0,
8
+ left: 0,
9
+ width: 800,
10
+ height: 600
11
+ }
12
+ },
13
+ notifications: {
14
+ enable: true,
15
+ enableToasts: true,
16
+ clearNotificationOnClick: true
17
+ },
18
+ applications: {
19
+ local: []
20
+ },
21
+ layouts: {
22
+ mode: "idb",
23
+ local: []
24
+ },
25
+ channels: {
26
+ definitions: []
27
+ },
28
+ plugins: {
29
+ definitions: []
30
+ },
31
+ licenseKey: "",
32
+ gateway: {
33
+ logging: {
34
+ level: "info"
35
+ }
36
+ },
37
+ themes: {
38
+ defaultTheme: "dark"
39
+ },
40
+ connection: {},
41
+ browser: {},
42
+ environment: {},
43
+ workspacesFrameCache: true
44
+ };
45
+
46
+ export const defaultTargetString = "*";
47
+
48
+ export const defaultFetchTimeoutMs = 3000;
49
+
50
+ export const defaultOpenerTimeoutMs = 1000;
51
+
52
+ export const defaultPreferredDiscoveryIntervalMS = 15000;
53
+
54
+ export const defaultClientPortRequestTimeoutMS = 15000;
55
+
56
+ export const defaultClientPreferredLogicTestTimeoutMS = 5000;
@@ -0,0 +1,32 @@
1
+ /* eslint-disable @typescript-eslint/camelcase */
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+
4
+ declare module "@glue42/gateway-web/web/gateway-web.js" {
5
+ interface LogInfo {
6
+ time: Date;
7
+ output: string;
8
+ level: string;
9
+ line: number;
10
+ message: string;
11
+ namespace: string;
12
+ stacktrace: string;
13
+ }
14
+
15
+ export interface GatewayWebAPI {
16
+ start: () => Promise<void>;
17
+ connect: (connectCb: any) => Promise<GwClient>;
18
+ }
19
+
20
+ export type GwLoggingConfig = {
21
+ level?: string;
22
+ appender?: (logInfo: LogInfo) => void;
23
+ };
24
+
25
+ export interface GwClient {
26
+ send: (data: unknown) => void;
27
+ disconnect: () => unknown;
28
+ }
29
+
30
+ export type configure_logging = (config: GwLoggingConfig) => void;
31
+ export type create = (config: any) => GatewayWebAPI;
32
+ }
@@ -0,0 +1,222 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { Glue42 } from "@glue42/desktop";
3
+ import { IOConnectBrowser } from "@interopio/browser";
4
+ import { Decoder } from "decoder-validate";
5
+ import { IOConnectBrowserPlatform } from "../../browser.platform";
6
+ import { DBSchema } from "idb";
7
+ import { IOConnectCore } from "@interopio/core";
8
+
9
+ export type Glue42API = Glue42.Glue;
10
+ export type Glue42Config = Glue42.Config;
11
+ export type LibDomains = IOConnectBrowserPlatform.LibDomains;
12
+
13
+ export type LicenseTypes = "trial" | "paid";
14
+
15
+ export interface PlatformDomain {
16
+ libController: LibController;
17
+ name: string;
18
+ domainNameDecoder?: Decoder<string>;
19
+ }
20
+
21
+ export interface OperationCheckConfig {
22
+ operation: string;
23
+ }
24
+
25
+ export interface OperationCheckResult {
26
+ isSupported: boolean;
27
+ }
28
+
29
+ export interface InternalWindowsConfig {
30
+ windowResponseTimeoutMs: number;
31
+ defaultWindowOpenBounds: IOConnectBrowser.Windows.Bounds;
32
+ }
33
+
34
+ export interface InternalNotificationsConfig {
35
+ enable: boolean;
36
+ enableToasts: boolean;
37
+ clearNotificationOnClick: boolean;
38
+ }
39
+
40
+ export interface InternalApplicationsConfig {
41
+ local: Array<IOConnectBrowser.AppManager.Definition | IOConnectBrowserPlatform.Applications.FDC3Definition>;
42
+ remote?: IOConnectBrowserPlatform.RemoteStore;
43
+ }
44
+
45
+ export interface InternalLayoutsConfig {
46
+ mode: "idb" | "session";
47
+ local: Array<IOConnectBrowser.Layouts.Layout>;
48
+ }
49
+
50
+ export interface Glue42CoreDB extends DBSchema {
51
+ workspaceLayouts: {
52
+ key: string;
53
+ value: IOConnectBrowser.Layouts.Layout;
54
+ };
55
+ autoLayouts: {
56
+ key: string;
57
+ value: IOConnectBrowser.Layouts.Layout;
58
+ };
59
+ globalLayouts: {
60
+ key: string;
61
+ value: IOConnectBrowser.Layouts.Layout;
62
+ };
63
+ serviceWorker: {
64
+ key: "workerData";
65
+ value: ServiceWorkerDbData;
66
+ };
67
+ }
68
+
69
+ export interface ServiceWorkerDbData {
70
+ platformUrl: string;
71
+ }
72
+
73
+ export interface InternalPlatformConfig {
74
+ browserFactory?: (config?: IOConnectBrowser.Config) => Promise<IOConnectBrowser.API>;
75
+ browser?: IOConnectBrowser.Config;
76
+ gateway?: IOConnectBrowserPlatform.Gateway.Config;
77
+ licenseKey: string;
78
+ windows: InternalWindowsConfig;
79
+ notifications: InternalNotificationsConfig;
80
+ applications: InternalApplicationsConfig;
81
+ layouts: InternalLayoutsConfig;
82
+ channels: {
83
+ definitions: IOConnectBrowserPlatform.Channels.ChannelDefinition[];
84
+ };
85
+ themes: IOConnectBrowserPlatform.Themes.Config;
86
+ plugins?: {
87
+ definitions: IOConnectBrowserPlatform.Plugins.PluginDefinition[];
88
+ };
89
+ manager?: IOConnectBrowserPlatform.Manager.Config;
90
+ serviceWorker?: IOConnectBrowserPlatform.ServiceWorker.Config;
91
+ workspaces?: IOConnectBrowserPlatform.Workspaces.Config;
92
+ user?: IOConnectBrowserPlatform.User.Config;
93
+ connection: IOConnectBrowserPlatform.Connection.Config;
94
+ environment: any;
95
+ workspacesFrameCache: boolean;
96
+ }
97
+
98
+ export interface CoreClientData {
99
+ windowId: string;
100
+ win: Window;
101
+ }
102
+
103
+ export interface LibController {
104
+ start(config: InternalPlatformConfig): Promise<void>;
105
+ handleControl(args: IOConnectBrowserPlatform.ControlMessage): Promise<any>;
106
+ handleClientUnloaded?(windowId: string, win: Window): void;
107
+ handlePlatformShutdown?(): void;
108
+ configurePostStart?(): Promise<void>;
109
+ }
110
+
111
+ export interface SessionNonGlueData {
112
+ windowId: string;
113
+ }
114
+
115
+ export interface SessionWindowData {
116
+ windowId: string;
117
+ name: string;
118
+ initialBounds?: IOConnectBrowser.Windows.Bounds;
119
+ initialUrl?: string;
120
+ initialContext?: any;
121
+ layoutComponentId?: string;
122
+ selfAssigned?: boolean;
123
+ }
124
+
125
+ export interface WorkspaceWindowSession {
126
+ windowId: string;
127
+ frameId: string;
128
+ workspaceId?: string;
129
+ initialTitle?: string;
130
+ }
131
+
132
+ export interface BridgeOperation {
133
+ name: string;
134
+ execute: (args: any, commandId: string, callerId?: string, callerType?: "plugin" | "client") => Promise<any>;
135
+ dataDecoder?: Decoder<any>;
136
+ resultDecoder?: Decoder<any>;
137
+ }
138
+
139
+ export interface ModeExecutor {
140
+ setup(): Promise<void>;
141
+ }
142
+
143
+ export interface ApplicationStartConfig {
144
+ name: string;
145
+ id?: string;
146
+ context?: any;
147
+ top?: number;
148
+ left?: number;
149
+ width?: number;
150
+ height?: number;
151
+ relativeTo?: string;
152
+ relativeDirection?: "top" | "left" | "right" | "bottom";
153
+ waitForAGMReady?: boolean;
154
+ forceChromeTab?: boolean;
155
+ layoutComponentId?: string;
156
+ }
157
+
158
+ export type SystemOperationTypes = "getEnvironment" | "getBase" | "operationCheck";
159
+
160
+ export interface ClientTransportSwitchLock {
161
+ promise: Promise<void>;
162
+ lift: (value: void | PromiseLike<void>) => void;
163
+ fail: (reason?: any) => void;
164
+ }
165
+
166
+ export interface Transaction<T> {
167
+ id: string;
168
+ lock: Promise<T>;
169
+ lift: (value: T) => void;
170
+ fail: (reason?: any) => void;
171
+ }
172
+
173
+ export interface TransportState extends IOConnectCore.Connection.TransportSwitchSettings {
174
+ transportName: string;
175
+ }
176
+
177
+ export interface ClientPortRequest {
178
+ type: string;
179
+ clientId: string;
180
+ timeout?: number;
181
+ args?: any;
182
+ }
183
+
184
+ export interface SessionSystemSettings {
185
+ systemInstanceId: string;
186
+ ctxTrackInstanceId: string;
187
+ }
188
+
189
+ export interface InterceptorInquiry {
190
+ domain: LibDomains;
191
+ operation: string;
192
+ }
193
+
194
+ export interface InterceptorInquiryResult {
195
+ name: string;
196
+ intercept: (config: IOConnectBrowserPlatform.ControlMessage) => Promise<any>;
197
+ }
198
+
199
+ export interface InterceptorEntry {
200
+ registrantName: string;
201
+ domain: LibDomains;
202
+ operation: string;
203
+ callInterceptor: (config: IOConnectBrowserPlatform.ControlMessage) => Promise<any>;
204
+ }
205
+
206
+ export interface PluginsConfig {
207
+ platformConfig: InternalPlatformConfig;
208
+ plugins?: IOConnectBrowserPlatform.Plugins.PluginDefinition[];
209
+ api: IOConnectBrowserPlatform.API;
210
+ handlePluginMessage: (args: IOConnectBrowserPlatform.Plugins.BaseControlMessage, pluginName: string) => Promise<any>;
211
+ }
212
+
213
+ export interface FocusEventData {
214
+ windowId: string;
215
+ hasFocus: boolean;
216
+ }
217
+
218
+ export interface GetOrCreateFrameConfig {
219
+ bounds?: IOConnectBrowser.Windows.Bounds;
220
+ layoutComponentId?: string;
221
+ frameId?: string
222
+ }
@@ -0,0 +1,132 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable @typescript-eslint/no-unused-vars */
3
+ /* eslint-disable @typescript-eslint/triple-slash-reference */
4
+ /* eslint-disable @typescript-eslint/camelcase */
5
+ /// <reference path="../common/gateway.d.ts"/>
6
+
7
+ import { IOConnectBrowserPlatform } from "../../browser.platform";
8
+ import "@glue42/gateway-web/web/gateway-web.js";
9
+ import { GatewayWebAPI, configure_logging, create, GwClient } from "@glue42/gateway-web/web/gateway-web.js";
10
+ import { Glue42CoreMessageTypes } from "../common/constants";
11
+
12
+ export class Gateway {
13
+ private _gatewayWebInstance!: GatewayWebAPI;
14
+ private readonly configureLogging: configure_logging;
15
+ private readonly create: create;
16
+
17
+ constructor() {
18
+ this.configureLogging = (window as any).gateway_web.core.configure_logging;
19
+ this.create = (window as any).gateway_web.core.create;
20
+ }
21
+
22
+ // TODO: implement GW stop when the stop is not logging errors
23
+
24
+ public async start(config?: IOConnectBrowserPlatform.Gateway.Config): Promise<void> {
25
+ if (config?.logging) {
26
+ this.configureLogging({
27
+ level: config.logging.level,
28
+ appender: config.logging.appender
29
+ });
30
+ }
31
+
32
+ const buffer_size = typeof config?.clients?.buffer_size === "number" ? config.clients.buffer_size : 1000;
33
+
34
+ this._gatewayWebInstance = this.create({ clients: { inactive_seconds: 0, buffer_size } });
35
+
36
+ await this._gatewayWebInstance.start();
37
+ }
38
+
39
+ public async connectClient(clientPort: MessagePort): Promise<GwClient> {
40
+
41
+ const client = await this._gatewayWebInstance.connect((_: object, message: string) => clientPort.postMessage(message));
42
+
43
+ return client;
44
+ }
45
+
46
+ public async connectExtClient(port: chrome.runtime.Port, removeFromPlatform?: (clientId: string, announce?: boolean) => void): Promise<void> {
47
+
48
+ const client = await this._gatewayWebInstance.connect((_: object, message: string) => port.postMessage({ glue42ExtInc: message }));
49
+
50
+ port.onMessage.addListener((message) => {
51
+
52
+ const coreData = message?.glue42ExtOut?.glue42core;
53
+
54
+ if (coreData && coreData.type === Glue42CoreMessageTypes.clientUnload.name) {
55
+
56
+ client.disconnect();
57
+
58
+ port.disconnect();
59
+
60
+ if (removeFromPlatform) {
61
+ removeFromPlatform(coreData.data.clientId, true);
62
+ }
63
+
64
+ return;
65
+ }
66
+
67
+ if (message.glue42ExtOut && !coreData) {
68
+ const msg = message.glue42ExtOut;
69
+
70
+ client.send(msg);
71
+
72
+ return;
73
+ }
74
+
75
+ });
76
+ }
77
+
78
+ public async setupInternalClient(clientPort: MessagePort): Promise<void> {
79
+
80
+ let client: GwClient | undefined;
81
+
82
+ clientPort.onmessage = async (event): Promise<void> => {
83
+ const data = event.data?.glue42core;
84
+
85
+ if (data && data.type === Glue42CoreMessageTypes.gatewayInternalConnect.name) {
86
+ client = await this.handleInternalGatewayConnectionRequest(clientPort);
87
+ return;
88
+ }
89
+
90
+ if (!client || (clientPort as any).closed) {
91
+ return;
92
+ }
93
+
94
+ if (data && data.type === Glue42CoreMessageTypes.gatewayDisconnect.name) {
95
+
96
+ (clientPort as any).closed = true;
97
+
98
+ client?.disconnect();
99
+ return;
100
+ }
101
+
102
+ client?.send(event.data);
103
+ };
104
+ }
105
+
106
+ private async handleInternalGatewayConnectionRequest(clientPort: MessagePort): Promise<GwClient | undefined> {
107
+ (clientPort as any).closed = false;
108
+
109
+ try {
110
+ const client = await this._gatewayWebInstance.connect((_: object, message: string) => clientPort.postMessage(message));
111
+
112
+ clientPort.postMessage({
113
+ glue42core: {
114
+ type: Glue42CoreMessageTypes.gatewayInternalConnect.name,
115
+ success: true
116
+ }
117
+ });
118
+
119
+ return client;
120
+ } catch (err: any) {
121
+ const stringError = typeof err === "string" ? err : JSON.stringify(err.message);
122
+
123
+ clientPort.postMessage({
124
+ glue42core: {
125
+ type: Glue42CoreMessageTypes.gatewayInternalConnect.name,
126
+ error: stringError
127
+ }
128
+ });
129
+ return;
130
+ }
131
+ }
132
+ }
@@ -0,0 +1 @@
1
+ // no gateway placeholder