@openfin/core 33.76.31 → 33.76.38

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 (269) hide show
  1. package/OpenFin.d.ts +1 -1
  2. package/README.md +29 -4
  3. package/fin.d.ts +2 -2
  4. package/{src → out}/GlobalOpenFin.d.ts +1 -1
  5. package/out/mock-alpha.d.ts +16112 -0
  6. package/out/mock-beta.d.ts +16112 -0
  7. package/out/mock-public.d.ts +16112 -0
  8. package/out/mock.d.ts +16797 -0
  9. package/out/mock.js +17104 -0
  10. package/package.json +30 -23
  11. package/LICENSE +0 -13
  12. package/NOTICE +0 -16
  13. package/openfin-core-33.76.31.tgz +0 -0
  14. package/src/OpenFin.d.ts +0 -3080
  15. package/src/OpenFin.js +0 -2
  16. package/src/api/api-exposer/api-consumer.d.ts +0 -28
  17. package/src/api/api-exposer/api-consumer.js +0 -28
  18. package/src/api/api-exposer/api-exposer.d.ts +0 -35
  19. package/src/api/api-exposer/api-exposer.js +0 -38
  20. package/src/api/api-exposer/decorators.d.ts +0 -10
  21. package/src/api/api-exposer/decorators.js +0 -18
  22. package/src/api/api-exposer/index.d.ts +0 -4
  23. package/src/api/api-exposer/index.js +0 -20
  24. package/src/api/api-exposer/strategies/index.d.ts +0 -1
  25. package/src/api/api-exposer/strategies/index.js +0 -17
  26. package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.d.ts +0 -14
  27. package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.js +0 -20
  28. package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.d.ts +0 -20
  29. package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.js +0 -23
  30. package/src/api/api-exposer/strategies/openfin-channels/index.d.ts +0 -2
  31. package/src/api/api-exposer/strategies/openfin-channels/index.js +0 -18
  32. package/src/api/application/Factory.d.ts +0 -148
  33. package/src/api/application/Factory.js +0 -230
  34. package/src/api/application/Instance.d.ts +0 -321
  35. package/src/api/application/Instance.js +0 -453
  36. package/src/api/application/index.d.ts +0 -3
  37. package/src/api/application/index.js +0 -19
  38. package/src/api/base.d.ts +0 -48
  39. package/src/api/base.js +0 -177
  40. package/src/api/clipboard/index.d.ts +0 -92
  41. package/src/api/clipboard/index.js +0 -120
  42. package/src/api/events/application.d.ts +0 -146
  43. package/src/api/events/application.js +0 -2
  44. package/src/api/events/base.d.ts +0 -42
  45. package/src/api/events/base.js +0 -2
  46. package/src/api/events/channel.d.ts +0 -30
  47. package/src/api/events/channel.js +0 -2
  48. package/src/api/events/emitterMap.d.ts +0 -11
  49. package/src/api/events/emitterMap.js +0 -35
  50. package/src/api/events/eventAggregator.d.ts +0 -5
  51. package/src/api/events/eventAggregator.js +0 -35
  52. package/src/api/events/externalApplication.d.ts +0 -19
  53. package/src/api/events/externalApplication.js +0 -2
  54. package/src/api/events/frame.d.ts +0 -30
  55. package/src/api/events/frame.js +0 -2
  56. package/src/api/events/globalHotkey.d.ts +0 -20
  57. package/src/api/events/globalHotkey.js +0 -2
  58. package/src/api/events/platform.d.ts +0 -26
  59. package/src/api/events/platform.js +0 -2
  60. package/src/api/events/system.d.ts +0 -113
  61. package/src/api/events/system.js +0 -2
  62. package/src/api/events/typedEventEmitter.d.ts +0 -20
  63. package/src/api/events/typedEventEmitter.js +0 -2
  64. package/src/api/events/view.d.ts +0 -82
  65. package/src/api/events/view.js +0 -2
  66. package/src/api/events/webcontents.d.ts +0 -266
  67. package/src/api/events/webcontents.js +0 -2
  68. package/src/api/events/window.d.ts +0 -352
  69. package/src/api/events/window.js +0 -2
  70. package/src/api/external-application/Factory.d.ts +0 -27
  71. package/src/api/external-application/Factory.js +0 -40
  72. package/src/api/external-application/Instance.d.ts +0 -102
  73. package/src/api/external-application/Instance.js +0 -109
  74. package/src/api/external-application/index.d.ts +0 -3
  75. package/src/api/external-application/index.js +0 -19
  76. package/src/api/fin.d.ts +0 -51
  77. package/src/api/fin.js +0 -42
  78. package/src/api/frame/Factory.d.ts +0 -37
  79. package/src/api/frame/Factory.js +0 -69
  80. package/src/api/frame/Instance.d.ts +0 -123
  81. package/src/api/frame/Instance.js +0 -130
  82. package/src/api/frame/index.d.ts +0 -3
  83. package/src/api/frame/index.js +0 -19
  84. package/src/api/global-hotkey/index.d.ts +0 -38
  85. package/src/api/global-hotkey/index.js +0 -64
  86. package/src/api/interappbus/channel/channel.d.ts +0 -28
  87. package/src/api/interappbus/channel/channel.js +0 -77
  88. package/src/api/interappbus/channel/channels-docs.d.ts +0 -340
  89. package/src/api/interappbus/channel/channels-docs.js +0 -398
  90. package/src/api/interappbus/channel/client.d.ts +0 -24
  91. package/src/api/interappbus/channel/client.js +0 -89
  92. package/src/api/interappbus/channel/connection-manager.d.ts +0 -29
  93. package/src/api/interappbus/channel/connection-manager.js +0 -246
  94. package/src/api/interappbus/channel/index.d.ts +0 -25
  95. package/src/api/interappbus/channel/index.js +0 -169
  96. package/src/api/interappbus/channel/protocols/classic/message-receiver.d.ts +0 -13
  97. package/src/api/interappbus/channel/protocols/classic/message-receiver.js +0 -73
  98. package/src/api/interappbus/channel/protocols/classic/strategy.d.ts +0 -24
  99. package/src/api/interappbus/channel/protocols/classic/strategy.js +0 -101
  100. package/src/api/interappbus/channel/protocols/combined/strategy.d.ts +0 -20
  101. package/src/api/interappbus/channel/protocols/combined/strategy.js +0 -58
  102. package/src/api/interappbus/channel/protocols/index.d.ts +0 -47
  103. package/src/api/interappbus/channel/protocols/index.js +0 -2
  104. package/src/api/interappbus/channel/protocols/protocol-manager.d.ts +0 -10
  105. package/src/api/interappbus/channel/protocols/protocol-manager.js +0 -43
  106. package/src/api/interappbus/channel/protocols/rtc/endpoint.d.ts +0 -25
  107. package/src/api/interappbus/channel/protocols/rtc/endpoint.js +0 -141
  108. package/src/api/interappbus/channel/protocols/rtc/ice-manager.d.ts +0 -30
  109. package/src/api/interappbus/channel/protocols/rtc/ice-manager.js +0 -130
  110. package/src/api/interappbus/channel/protocols/rtc/strategy.d.ts +0 -24
  111. package/src/api/interappbus/channel/protocols/rtc/strategy.js +0 -85
  112. package/src/api/interappbus/channel/protocols/strategy-types.d.ts +0 -13
  113. package/src/api/interappbus/channel/protocols/strategy-types.js +0 -2
  114. package/src/api/interappbus/channel/protocols/strategy.d.ts +0 -17
  115. package/src/api/interappbus/channel/protocols/strategy.js +0 -2
  116. package/src/api/interappbus/channel/provider.d.ts +0 -34
  117. package/src/api/interappbus/channel/provider.js +0 -166
  118. package/src/api/interappbus/index.d.ts +0 -85
  119. package/src/api/interappbus/index.js +0 -175
  120. package/src/api/interop/Factory.d.ts +0 -37
  121. package/src/api/interop/Factory.js +0 -76
  122. package/src/api/interop/InteropBroker.d.ts +0 -437
  123. package/src/api/interop/InteropBroker.js +0 -1085
  124. package/src/api/interop/InteropClient.d.ts +0 -278
  125. package/src/api/interop/InteropClient.js +0 -459
  126. package/src/api/interop/SessionContextGroupBroker.d.ts +0 -27
  127. package/src/api/interop/SessionContextGroupBroker.js +0 -108
  128. package/src/api/interop/SessionContextGroupClient.d.ts +0 -21
  129. package/src/api/interop/SessionContextGroupClient.js +0 -86
  130. package/src/api/interop/fdc3/PrivateChannelClient.d.ts +0 -20
  131. package/src/api/interop/fdc3/PrivateChannelClient.js +0 -90
  132. package/src/api/interop/fdc3/PrivateChannelProvider.d.ts +0 -55
  133. package/src/api/interop/fdc3/PrivateChannelProvider.js +0 -276
  134. package/src/api/interop/fdc3/fdc3-1.2.d.ts +0 -208
  135. package/src/api/interop/fdc3/fdc3-1.2.js +0 -438
  136. package/src/api/interop/fdc3/fdc3-2.0.d.ts +0 -301
  137. package/src/api/interop/fdc3/fdc3-2.0.js +0 -482
  138. package/src/api/interop/fdc3/fdc3.d.ts +0 -12
  139. package/src/api/interop/fdc3/fdc3.js +0 -35
  140. package/src/api/interop/fdc3/overrideCheck.d.ts +0 -4
  141. package/src/api/interop/fdc3/overrideCheck.js +0 -32
  142. package/src/api/interop/fdc3/shapes/fdc3v1.d.ts +0 -53
  143. package/src/api/interop/fdc3/shapes/fdc3v1.js +0 -4
  144. package/src/api/interop/fdc3/shapes/fdc3v2.d.ts +0 -75
  145. package/src/api/interop/fdc3/shapes/fdc3v2.js +0 -2
  146. package/src/api/interop/fdc3/utils.d.ts +0 -45
  147. package/src/api/interop/fdc3/utils.js +0 -239
  148. package/src/api/interop/fdc3/versions.d.ts +0 -1
  149. package/src/api/interop/fdc3/versions.js +0 -2
  150. package/src/api/interop/index.d.ts +0 -4
  151. package/src/api/interop/index.js +0 -20
  152. package/src/api/interop/utils.d.ts +0 -18
  153. package/src/api/interop/utils.js +0 -61
  154. package/src/api/me.d.ts +0 -40
  155. package/src/api/me.js +0 -134
  156. package/src/api/platform/Factory.d.ts +0 -115
  157. package/src/api/platform/Factory.js +0 -184
  158. package/src/api/platform/Instance.d.ts +0 -150
  159. package/src/api/platform/Instance.js +0 -332
  160. package/src/api/platform/common-utils.d.ts +0 -7
  161. package/src/api/platform/common-utils.js +0 -16
  162. package/src/api/platform/index.d.ts +0 -3
  163. package/src/api/platform/index.js +0 -19
  164. package/src/api/platform/layout/Factory.d.ts +0 -114
  165. package/src/api/platform/layout/Factory.js +0 -174
  166. package/src/api/platform/layout/Instance.d.ts +0 -57
  167. package/src/api/platform/layout/Instance.js +0 -126
  168. package/src/api/platform/layout/controllers/layout-content-cache.d.ts +0 -9
  169. package/src/api/platform/layout/controllers/layout-content-cache.js +0 -54
  170. package/src/api/platform/layout/controllers/layout-entities-controller.d.ts +0 -119
  171. package/src/api/platform/layout/controllers/layout-entities-controller.js +0 -287
  172. package/src/api/platform/layout/entities/layout-entities.d.ts +0 -235
  173. package/src/api/platform/layout/entities/layout-entities.js +0 -312
  174. package/src/api/platform/layout/entities/shapes.d.ts +0 -6
  175. package/src/api/platform/layout/entities/shapes.js +0 -2
  176. package/src/api/platform/layout/index.d.ts +0 -2
  177. package/src/api/platform/layout/index.js +0 -18
  178. package/src/api/platform/layout/layout.constants.d.ts +0 -1
  179. package/src/api/platform/layout/layout.constants.js +0 -4
  180. package/src/api/platform/layout/shapes.d.ts +0 -16
  181. package/src/api/platform/layout/shapes.js +0 -2
  182. package/src/api/platform/layout/utils/layout-traversal.d.ts +0 -4
  183. package/src/api/platform/layout/utils/layout-traversal.js +0 -65
  184. package/src/api/platform/provider.d.ts +0 -163
  185. package/src/api/platform/provider.js +0 -2
  186. package/src/api/snapshot-source/Factory.d.ts +0 -38
  187. package/src/api/snapshot-source/Factory.js +0 -66
  188. package/src/api/snapshot-source/Instance.d.ts +0 -31
  189. package/src/api/snapshot-source/Instance.js +0 -132
  190. package/src/api/snapshot-source/index.d.ts +0 -3
  191. package/src/api/snapshot-source/index.js +0 -19
  192. package/src/api/snapshot-source/utils.d.ts +0 -2
  193. package/src/api/snapshot-source/utils.js +0 -6
  194. package/src/api/system/index.d.ts +0 -517
  195. package/src/api/system/index.js +0 -895
  196. package/src/api/view/Factory.d.ts +0 -50
  197. package/src/api/view/Factory.js +0 -103
  198. package/src/api/view/Instance.d.ts +0 -487
  199. package/src/api/view/Instance.js +0 -557
  200. package/src/api/view/index.d.ts +0 -3
  201. package/src/api/view/index.js +0 -19
  202. package/src/api/webcontents/main.d.ts +0 -32
  203. package/src/api/webcontents/main.js +0 -156
  204. package/src/api/window/Factory.d.ts +0 -45
  205. package/src/api/window/Factory.js +0 -91
  206. package/src/api/window/Instance.d.ts +0 -1090
  207. package/src/api/window/Instance.js +0 -1349
  208. package/src/api/window/index.d.ts +0 -3
  209. package/src/api/window/index.js +0 -19
  210. package/src/browser.d.ts +0 -10
  211. package/src/browser.js +0 -36
  212. package/src/environment/browser.d.ts +0 -29
  213. package/src/environment/browser.js +0 -60
  214. package/src/environment/environment.d.ts +0 -33
  215. package/src/environment/environment.js +0 -4
  216. package/src/environment/mockEnvironment.d.ts +0 -27
  217. package/src/environment/mockEnvironment.js +0 -61
  218. package/src/environment/node-env.d.ts +0 -29
  219. package/src/environment/node-env.js +0 -72
  220. package/src/fdc3.d.ts +0 -3
  221. package/src/fdc3.js +0 -9
  222. package/src/mock.d.ts +0 -3
  223. package/src/mock.js +0 -18
  224. package/src/namespaces.d.ts +0 -21
  225. package/src/namespaces.js +0 -24
  226. package/src/shapes/ERROR_BOX_TYPES.d.ts +0 -1
  227. package/src/shapes/ERROR_BOX_TYPES.js +0 -2
  228. package/src/shapes/WebOptions.d.ts +0 -13
  229. package/src/shapes/WebOptions.js +0 -2
  230. package/src/shapes/WindowOptions.d.ts +0 -43
  231. package/src/shapes/WindowOptions.js +0 -2
  232. package/src/shapes/protocol.d.ts +0 -200
  233. package/src/shapes/protocol.js +0 -2
  234. package/src/transport/mockWire.d.ts +0 -11
  235. package/src/transport/mockWire.js +0 -26
  236. package/src/transport/transport-errors.d.ts +0 -31
  237. package/src/transport/transport-errors.js +0 -79
  238. package/src/transport/transport.d.ts +0 -73
  239. package/src/transport/transport.js +0 -219
  240. package/src/transport/wire.d.ts +0 -77
  241. package/src/transport/wire.js +0 -36
  242. package/src/util/asyncFilter.d.ts +0 -1
  243. package/src/util/asyncFilter.js +0 -7
  244. package/src/util/channel-api-relay.d.ts +0 -13
  245. package/src/util/channel-api-relay.js +0 -47
  246. package/src/util/errors.d.ts +0 -10
  247. package/src/util/errors.js +0 -12
  248. package/src/util/exhaustive.d.ts +0 -1
  249. package/src/util/exhaustive.js +0 -7
  250. package/src/util/http.d.ts +0 -11
  251. package/src/util/http.js +0 -90
  252. package/src/util/inaccessibleObject.d.ts +0 -2
  253. package/src/util/inaccessibleObject.js +0 -49
  254. package/src/util/lazy.d.ts +0 -34
  255. package/src/util/lazy.js +0 -54
  256. package/src/util/normalize-config.d.ts +0 -3
  257. package/src/util/normalize-config.js +0 -52
  258. package/src/util/promises.d.ts +0 -5
  259. package/src/util/promises.js +0 -27
  260. package/src/util/ref-counter.d.ts +0 -7
  261. package/src/util/ref-counter.js +0 -52
  262. package/src/util/reversible-map.d.ts +0 -11
  263. package/src/util/reversible-map.js +0 -49
  264. package/src/util/runtimeVersioning.d.ts +0 -3
  265. package/src/util/runtimeVersioning.js +0 -25
  266. package/src/util/utilTypes.d.ts +0 -8
  267. package/src/util/utilTypes.js +0 -2
  268. package/src/util/validate.d.ts +0 -3
  269. package/src/util/validate.js +0 -11
@@ -1,1085 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InteropBroker = void 0;
4
- const base_1 = require("../base");
5
- const SessionContextGroupBroker_1 = require("./SessionContextGroupBroker");
6
- const utils_1 = require("./utils");
7
- const lodash_1 = require("lodash");
8
- const PrivateChannelProvider_1 = require("./fdc3/PrivateChannelProvider");
9
- let contextGroups = [
10
- {
11
- id: 'green',
12
- displayMetadata: {
13
- color: '#00CC88',
14
- name: 'green'
15
- }
16
- },
17
- {
18
- id: 'purple',
19
- displayMetadata: {
20
- color: '#8C61FF',
21
- name: 'purple'
22
- }
23
- },
24
- {
25
- id: 'orange',
26
- displayMetadata: {
27
- color: '#FF8C4C',
28
- name: 'orange'
29
- }
30
- },
31
- {
32
- id: 'red',
33
- displayMetadata: {
34
- color: '#FF5E60',
35
- name: 'red'
36
- }
37
- },
38
- {
39
- id: 'pink',
40
- displayMetadata: {
41
- color: '#FF8FB8',
42
- name: 'pink'
43
- }
44
- },
45
- {
46
- id: 'yellow',
47
- displayMetadata: {
48
- color: '#E9FF8F',
49
- name: 'yellow'
50
- }
51
- }
52
- ];
53
- /**
54
- * {@link https://developers.openfin.co/of-docs/docs/enable-color-linking}
55
- *
56
- * The Interop Broker is responsible for keeping track of the Interop state of the Platform, and for directing messages to the proper locations.
57
- *
58
- * ---
59
- *
60
- * There are 2 ways to inject custom functionality into the Interop Broker:
61
- *
62
- * **1. Configuration**
63
- *
64
- * At the moment, you can configure the default context groups for the Interop Broker without having to override it. To do so, include the `interopBrokerConfiguration` `contextGroups` option in your `platform` options in your manifest. This is the preferred method.
65
- * ```js
66
- * {
67
- * "runtime": {
68
- * "arguments": "--v=1 --inspect",
69
- * "version": "alpha-v19"
70
- * },
71
- * "platform": {
72
- * "uuid": "platform_customization_local",
73
- * "applicationIcon": "https://openfin.github.io/golden-prototype/favicon.ico",
74
- * "autoShow": false,
75
- * "providerUrl": "http://localhost:5555/provider.html",
76
- * "interopBrokerConfiguration": {
77
- * "contextGroups": [
78
- * {
79
- * "id": "green",
80
- * "displayMetadata": {
81
- * "color": "#00CC88",
82
- * "name": "green"
83
- * }
84
- * },
85
- * {
86
- * "id": "purple",
87
- * "displayMetadata": {
88
- * "color": "#8C61FF",
89
- * "name": "purple"
90
- * }
91
- * },
92
- * ]
93
- * }
94
- * }
95
- * }
96
- * ```
97
- *
98
- * By default the Interop Broker logs all actions to the console. You can disable this by using the logging option in `interopBrokerConfiguration`:
99
- * ```js
100
- * {
101
- * "runtime": {
102
- * "arguments": "--v=1 --inspect",
103
- * "version": "alpha-v19"
104
- * },
105
- * "platform": {
106
- * "uuid": "platform_customization_local",
107
- * "applicationIcon": "https://openfin.github.io/golden-prototype/favicon.ico",
108
- * "autoShow": false,
109
- * "providerUrl": "http://localhost:5555/provider.html",
110
- * "interopBrokerConfiguration": {
111
- * "logging": {
112
- * "beforeAction": {
113
- * "enabled": false
114
- * },
115
- * "afterAction": {
116
- * "enabled": false
117
- * }
118
- * }
119
- * }
120
- * }
121
- * }
122
- * ```
123
- *
124
- * ---
125
- * **2. Overriding**
126
- *
127
- * Similarly to how [Platform Overriding]{@link https://developers.openfin.co/docs/platform-customization#section-customizing-platform-behavior} works, you can override functions in the Interop Broker in `fin.Platform.init`. An example of that is shown below. Overriding `isConnectionAuthorized` and `isActionAuthorized` will allow you to control allowed connections and allowed actions.
128
- *
129
- * However, if there is custom functionality you wish to include in the Interop Broker, please let us know. We would like to provide better configuration options so that you don't have to continually maintain your own override code.
130
- *
131
- * ```js
132
- * fin.Platform.init({
133
- * overrideCallback: async (Provider) => {
134
- * class Override extends Provider {
135
- * async getSnapshot() {
136
- * console.log('before getSnapshot')
137
- * const snapshot = await super.getSnapshot();
138
- * console.log('after getSnapshot')
139
- * return snapshot;
140
- * }
141
- *
142
- * async applySnapshot({ snapshot, options }) {
143
- * console.log('before applySnapshot')
144
- * const originalPromise = super.applySnapshot({ snapshot, options });
145
- * console.log('after applySnapshot')
146
- *
147
- * return originalPromise;
148
- * }
149
- * };
150
- * return new Override();
151
- * },
152
- * interopOverride: async (InteropBroker) => {
153
- * class Override extends InteropBroker {
154
- * async joinContextGroup(channelName = 'default', target) {
155
- * console.log('before super joinContextGroup')
156
- * super.joinContextGroup(channelName, target);
157
- * console.log('after super joinContextGroup')
158
- * }
159
- * }
160
- *
161
- * return new Override();
162
- * }
163
- * });
164
- * ```
165
- *
166
- * ---
167
- *
168
- * @hideconstructor
169
- * @class
170
- */
171
- class InteropBroker extends base_1.Base {
172
- constructor(wire, getProvider, options) {
173
- // Tip from Pierre and Michael from the overrideCheck work: Don't use bound methods for overrideable InteropBroker functions.
174
- super(wire);
175
- this.getProvider = getProvider;
176
- this.interopClients = new Map();
177
- this.contextGroupsById = new Map();
178
- if (options === null || options === void 0 ? void 0 : options.contextGroups) {
179
- contextGroups = options.contextGroups;
180
- }
181
- if (options === null || options === void 0 ? void 0 : options.logging) {
182
- this.logging = options.logging;
183
- }
184
- this.intentClientMap = new Map();
185
- this.lastContextMap = new Map();
186
- this.sessionContextGroupMap = new Map();
187
- this.setContextGroupMap();
188
- this.setupChannelProvider();
189
- }
190
- static createClosedConstructor(...args) {
191
- return class OverrideableBroker extends InteropBroker {
192
- constructor(...unused) {
193
- if (unused.length) {
194
- const [_ignore1, ignore2, opts] = unused;
195
- if (opts && typeof opts === 'object' && !(0, lodash_1.isEqual)(opts, args[2])) {
196
- // eslint-disable-next-line no-console
197
- console.warn('You have modified the parameters of the InteropOverride constructor. This behavior is deprecated and will be removed in a future version. You can modify these options in your manifest. Please consult our Interop docs for guidance on migrating to the new override scheme.');
198
- super(args[0], args[1], opts);
199
- return;
200
- }
201
- // eslint-disable-next-line no-console
202
- console.warn('You are attempting to pass arguments to the InteropOverride constructor. This is not necessary, and these passed arguments will be ignored. You are likely using an older InteropBroker override scheme. Please consult our Interop docs for guidance on migrating to the new override scheme.');
203
- }
204
- super(...args);
205
- }
206
- };
207
- }
208
- /*
209
- Client API
210
- */
211
- /**
212
- * @REMOVED
213
- * SetContextOptions interface
214
- * @typedef { object } SetContextOptions
215
- * @property { Context } {context} - New context to set.
216
- */
217
- /**
218
- * @REMOVED
219
- * GetContextOptions interface
220
- * @typedef { object } GetContextOptions
221
- * @property { string } [contextType] - Context Type
222
- */
223
- // TODO: extract inline type and do proper comments
224
- /**
225
- * @REMOVED
226
- * JoinContextGroupOptions interface
227
- * @typedef { object } JoinContextGroupOptions
228
- * @property { string } contextGroupId - Id of the context group.
229
- * @property { Identity | ClientIdentity } [target] - Identity of the entity you wish to join to a context group.
230
- */
231
- /**
232
- * @REMOVED
233
- * AddClientToContextGroupOptions interface
234
- * @typedef { object } AddClientToContextGroupOptions
235
- * @property { string } contextGroupId - Name of the context group.
236
- */
237
- /**
238
- * @REMOVED
239
- * RemoveFromContextGroupOptions interface
240
- * @typedef { object } RemoveFromContextGroupOptions
241
- * @property { Identity | ClientIdentity } target - Identity of the entity you wish to join to a context group.
242
- */
243
- /**
244
- * @REMOVED
245
- * GetInfoForContextGroupOptions interface
246
- * @typedef { object } GetInfoForContextGroupOptions
247
- * @property { string } contextGroupId - Name of the context group to get info for.
248
- */
249
- /**
250
- * @REMOVED
251
- * GetAllClientsInContextGroupOptions interface
252
- * @typedef { object } GetAllClientsInContextGroupOptions
253
- * @property { string } contextGroupId - Name of the context group to get info for.
254
- */
255
- /**
256
- * @PORTED
257
- * InfoForIntentOptions interface
258
- * @typedef { object } InfoForIntentOptions
259
- * @property { string } name Name of the intent to get info for.
260
- * @property { Context } [context] Optional context.
261
- */
262
- /**
263
- * Sets a context for the context group of the incoming current entity.
264
- * @param { SetContextOptions } setContextOptions - New context to set.
265
- * @param { ClientIdentity } clientIdentity - Identity of the client sender.
266
- * @return { void }
267
- */
268
- setContext({ context }, clientIdentity) {
269
- this.wire.sendAction('interop-broker-set-context').catch((e) => {
270
- // don't expose, analytics-only call
271
- });
272
- const clientState = this.getClientState(clientIdentity);
273
- if (clientState && clientState.contextGroupId) {
274
- const { contextGroupId } = clientState;
275
- if (!this.contextGroupsById.has(contextGroupId)) {
276
- // Theoretically not possible.
277
- throw new Error(`Client has a context group that isn't in the context group mapping: ${contextGroupId}.`);
278
- }
279
- const contextIntegrityCheckResult = InteropBroker.checkContextIntegrity(context);
280
- if (contextIntegrityCheckResult.isValid === false) {
281
- throw new Error(`Failed to set Context - bad Context. Reason: ${contextIntegrityCheckResult.reason}. Context: ${JSON.stringify(context)}`);
282
- }
283
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
284
- const contextGroupState = this.contextGroupsById.get(contextGroupId);
285
- const broadcastedContextType = context.type;
286
- contextGroupState.set(broadcastedContextType, context);
287
- this.lastContextMap.set(contextGroupId, broadcastedContextType);
288
- const clientsInSameContextGroup = Array.from(this.interopClients.values()).filter((connectedClient) => connectedClient.contextGroupId === contextGroupId);
289
- clientsInSameContextGroup.forEach((client) => {
290
- for (const [, handlerInfo] of client.contextHandlers) {
291
- if (InteropBroker.isContextTypeCompatible(broadcastedContextType, handlerInfo.contextType)) {
292
- this.invokeContextHandler(client.clientIdentity, handlerInfo.handlerId, context);
293
- }
294
- }
295
- });
296
- }
297
- else if (clientState) {
298
- // Client has not joined any context group behavior.
299
- throw new Error('You must join a context group before you can set context.');
300
- }
301
- else {
302
- // This shouldn't get hit.
303
- throw new Error(`Client with Identity: ${clientIdentity.uuid} ${clientIdentity.name} not in Client State Map`);
304
- }
305
- }
306
- /**
307
- * Get current context for a client subscribed to a Context Group.
308
- * @param { GetContextOptions } getContextOptions - Options for getting context
309
- * @param { ClientIdentity } clientIdentity - Identity of the client sender.
310
- * @return { Context }
311
- */
312
- getCurrentContext(getCurrentContextOptions, clientIdentity) {
313
- var _a;
314
- this.wire.sendAction('interop-broker-get-current-context').catch((e) => {
315
- // don't expose, analytics-only call
316
- });
317
- const clientState = this.getClientState(clientIdentity);
318
- if (!(clientState === null || clientState === void 0 ? void 0 : clientState.contextGroupId)) {
319
- throw new Error('You must be a member of a context group to call getCurrentContext');
320
- }
321
- const { contextGroupId } = clientState;
322
- const contextGroupState = this.contextGroupsById.get(contextGroupId);
323
- const lastContextType = this.lastContextMap.get(contextGroupId);
324
- const contextType = (_a = getCurrentContextOptions === null || getCurrentContextOptions === void 0 ? void 0 : getCurrentContextOptions.contextType) !== null && _a !== void 0 ? _a : lastContextType;
325
- return contextGroupState && contextType ? contextGroupState.get(contextType) : undefined;
326
- }
327
- /*
328
- Platform Window APIs
329
- */
330
- // joinContextGroup and addClientToContextGroup are separate functions here, for easier overrides and separation of concerns.
331
- // joinContextGroup checks all connections for matching identities, in case we have multiple connection from an entity.
332
- /**
333
- * Join all connections at the given identity (or just one if endpointId provided) to context group `contextGroupId`.
334
- * If no target is specified, it adds the sender to the context group.
335
- * joinContextGroup is responsible for checking connections at the incoming identity. It calls {@link InteropBroker#addClientToContextGroup InteropBroker.addClientToContextGroup} to actually group the client.
336
- * Used by Platform Windows.
337
- * @return { Promise<void> }
338
- * @param { JoinContextGroupOptions } joinContextGroupOptions - Id of the Context Group and identity of the entity to join to the group.
339
- * @param { ClientIdentity } senderIdentity - Identity of the client sender.
340
- */
341
- async joinContextGroup({ contextGroupId, target }, senderIdentity) {
342
- this.wire.sendAction('interop-broker-join-context-group').catch((e) => {
343
- // don't expose, analytics-only call
344
- });
345
- if (this.sessionContextGroupMap.has(contextGroupId)) {
346
- throw new Error(utils_1.BROKER_ERRORS.joinSessionContextGroupWithJoinContextGroup);
347
- }
348
- if (target) {
349
- // If an endpointId is provided, use that. This will likely be used by external adapters.
350
- if (InteropBroker.hasEndpointId(target)) {
351
- await this.addClientToContextGroup({ contextGroupId }, target);
352
- }
353
- // Sanity check here in case a single app has multiple connections
354
- try {
355
- const allConnections = this.channel.connections.filter((x) => x.uuid === target.uuid && x.name === target.name);
356
- if (!allConnections.length) {
357
- throw new Error(`Given Identity ${target.uuid} ${target.name} is not connected to the Interop Broker.`);
358
- }
359
- if (allConnections.length > 1) {
360
- // Should figure out how we want to handle this situation. In the meantime, just change context group for all connections.
361
- console.warn(`More than one connection found for identity ${target.uuid} ${target.name}`);
362
- }
363
- const promises = [];
364
- for (const connection of allConnections) {
365
- promises.push(this.addClientToContextGroup({ contextGroupId }, connection));
366
- }
367
- await Promise.all(promises);
368
- }
369
- catch (error) {
370
- throw new Error(error);
371
- }
372
- }
373
- else {
374
- // No target provided, add the sender to the context group.
375
- await this.addClientToContextGroup({ contextGroupId }, senderIdentity);
376
- }
377
- }
378
- // addClientToContextGroup does the actual addition of the client to the Context Group
379
- /**
380
- * Helper function for {@link InteropBroker#joinContextGroup InteropBroker.joinContextGroup}. Does the work of actually adding the client to the Context Group.
381
- * Used by Platform Windows.
382
- * @return { Promise<void> }
383
- * @param { AddClientToContextGroupOptions } addClientToContextGroupOptions - Contains the contextGroupId
384
- * @param { ClientIdentity } clientIdentity - Identity of the client sender.
385
- */
386
- async addClientToContextGroup({ contextGroupId }, clientIdentity) {
387
- this.wire.sendAction('interop-broker-add-client-to-context-group').catch((e) => {
388
- // don't expose, analytics-only call
389
- });
390
- const clientSubscriptionState = this.getClientState(clientIdentity);
391
- if (!clientSubscriptionState) {
392
- throw new Error(`Client with Identity: ${clientIdentity.uuid} ${clientIdentity.name} not in Client State Map`);
393
- }
394
- if (!this.getContextGroups().find((contextGroupInfo) => contextGroupInfo.id === contextGroupId)) {
395
- throw new Error(`Attempting to join a context group that does not exist: ${contextGroupId}. You may only join existing context groups.`);
396
- }
397
- const oldContextGroupId = clientSubscriptionState.contextGroupId;
398
- if (oldContextGroupId !== contextGroupId) {
399
- clientSubscriptionState.contextGroupId = contextGroupId;
400
- await this.setCurrentContextGroupInClientOptions(clientIdentity, contextGroupId);
401
- const contextGroupMap = this.contextGroupsById.get(contextGroupId);
402
- for (const [, handlerInfo] of clientSubscriptionState.contextHandlers) {
403
- const { contextType, handlerId } = handlerInfo;
404
- if (contextType === undefined) {
405
- // Send this single handler all of the context, because it accepts all.
406
- contextGroupMap.forEach((context, _) => {
407
- this.invokeContextHandler(clientIdentity, handlerId, context);
408
- });
409
- }
410
- else if (contextGroupMap.has(contextType)) {
411
- const contextForType = contextGroupMap.get(contextType);
412
- if (contextForType) {
413
- this.invokeContextHandler(clientIdentity, handlerId, contextForType);
414
- }
415
- }
416
- }
417
- }
418
- }
419
- // Removes the target from its context group. Similar structure to joinContextGroup.
420
- /**
421
- * Removes the specified target from a context group.
422
- * If no target is specified, it removes the sender from their context group.
423
- * removeFromContextGroup is responsible for checking connections at the incoming identity. It calls {@link InteropBroker#removeClientFromContextGroup InteropBroker.removeClientFromContextGroup} to actually ungroup the client.
424
- * Used by Platform Windows.
425
- * @return { Promise<void> }
426
- * @param { RemoveFromContextGroupOptions } removeFromContextGroupOptions - Contains the target identity to remove.
427
- * @param { ClientIdentity } senderIdentity - Identity of the client sender.
428
- */
429
- async removeFromContextGroup({ target }, senderIdentity) {
430
- this.wire.sendAction('interop-broker-remove-from-context-group').catch((e) => {
431
- // don't expose, analytics-only call
432
- });
433
- if (target) {
434
- // If an endpointId is provided, use that. This will likely be used by external adapters.
435
- if (InteropBroker.hasEndpointId(target)) {
436
- await this.removeClientFromContextGroup(target);
437
- }
438
- try {
439
- // Sanity check here in case a single app has multiple connections
440
- const allConnections = this.channel.connections.filter((x) => x.uuid === target.uuid && x.name === target.name);
441
- if (!allConnections.length) {
442
- throw new Error(`No connection found for given Identity ${target.uuid} ${target.name}`);
443
- }
444
- if (allConnections.length > 1) {
445
- console.warn(`More than one connection found for identity ${target.uuid} ${target.name}`);
446
- }
447
- const promises = [];
448
- for (const connection of allConnections) {
449
- promises.push(this.removeClientFromContextGroup(connection));
450
- }
451
- await Promise.all(promises);
452
- }
453
- catch (error) {
454
- throw new Error(error);
455
- }
456
- }
457
- else {
458
- // No target provided, remove the sender from the context group.
459
- await this.removeClientFromContextGroup(senderIdentity);
460
- }
461
- }
462
- // removeClientFromContextGroup does the actual remove of the client from the Context Group
463
- /**
464
- * Helper function for {@link InteropBroker#removeFromContextGroup InteropBroker.removeFromContextGroup}. Does the work of actually removing the client from the Context Group.
465
- * Used by Platform Windows.
466
- * @return { Promise<void> }
467
- * @property { ClientIdentity } clientIdentity - Identity of the client sender.
468
- */
469
- async removeClientFromContextGroup(clientIdentity) {
470
- this.wire.sendAction('interop-broker-remove-client-from-context-group').catch((e) => {
471
- // don't expose, analytics-only call
472
- });
473
- const clientState = this.getClientState(clientIdentity);
474
- if (clientState) {
475
- clientState.contextGroupId = undefined;
476
- }
477
- await this.setCurrentContextGroupInClientOptions(clientIdentity, null);
478
- }
479
- // Used by platform windows to know what client groups the provider has declared. Also used internally to access context groups. Overrideable so that the platform developer can modify it.
480
- /**
481
- * Returns the Interop-Broker-defined context groups available for an entity to join. Because this function is used in the rest of the Interop Broker to fetch the Context Groups, overriding this allows you to customize the Context Groups for the Interop Broker. However, we recommend customizing the context groups through configuration instead.
482
- * Used by Platform Windows.
483
- * @return { Promise<ContextGroupInfo[]>}
484
- */
485
- // eslint-disable-next-line class-methods-use-this
486
- getContextGroups() {
487
- this.wire.sendAction('interop-broker-get-context-groups').catch((e) => {
488
- // don't expose, analytics-only call
489
- });
490
- // Create copy for immutability
491
- return contextGroups.map((contextGroup) => {
492
- return { ...contextGroup };
493
- });
494
- }
495
- // Used to by platform windows to get display metadata for a context group.
496
- /**
497
- * Gets display info for a context group
498
- * Used by Platform Windows.
499
- * @param { GetInfoForContextGroupOptions } getInfoForContextGroupOptions - Contains contextGroupId, the context group you wish to get display info for.
500
- * @return { Promise<ContextGroupInfo>}
501
- */
502
- getInfoForContextGroup({ contextGroupId }) {
503
- this.wire.sendAction('interop-broker-get-info-for-context-group').catch((e) => {
504
- // don't expose, analytics-only call
505
- });
506
- return this.getContextGroups().find((contextGroup) => contextGroup.id === contextGroupId);
507
- }
508
- // Used by platform windows to get all clients for a context group.
509
- /**
510
- * Gets all clients for a context group.
511
- * Used by Platform Windows.
512
- * @param { GetAllClientsInContextGroupOptions } getAllClientsInContextGroupOptions - Contains contextGroupId, the context group you wish to get clients for.
513
- * @return { Promise<ClientIdentity[]>}
514
- */
515
- getAllClientsInContextGroup({ contextGroupId }) {
516
- this.wire.sendAction('interop-broker-get-all-clients-in-context-group').catch((e) => {
517
- // don't expose, analytics-only call
518
- });
519
- const clientsInContextGroup = Array.from(this.interopClients.values())
520
- .filter((connectedClient) => connectedClient.contextGroupId === contextGroupId)
521
- .map((subscriptionState) => {
522
- return subscriptionState.clientIdentity;
523
- });
524
- return clientsInContextGroup;
525
- }
526
- /**
527
- * Responsible for launching of applications that can handle a given intent, and delegation of intents to those applications.
528
- * Must be overridden.
529
- * @param { Intent } intent The combination of an action and a context that is passed to an application for resolution.
530
- * @param { ClientIdentity } clientIdentity Identity of the Client making the request.
531
- * @return { Promise<unknown> }
532
- * @tutorial interop.handleFiredIntent
533
- */
534
- // eslint-disable-next-line class-methods-use-this
535
- async handleFiredIntent(intent, clientIdentity) {
536
- const warning = (0, utils_1.generateOverrideWarning)('fdc3.raiseIntent', 'InteropBroker.handleFiredIntent', clientIdentity, 'interopClient.fireIntent');
537
- console.warn(warning);
538
- throw new Error(utils_1.BROKER_ERRORS.fireIntent);
539
- }
540
- /**
541
- * Should be called in {@link InteropBroker#handleFiredIntent InteropBroker.handleFiredIntent}.
542
- * While handleFiredIntent is responsible for launching applications, setIntentTarget is used to tell the InteropBroker which application should receive the intent when it is ready.
543
- * @param { Intent } intent The combination of an action and a context that is passed to an application for resolution.
544
- * @param { Identity } target - Identity of the target that will handle the intent.
545
- * @return { Promise<void> }
546
- */
547
- async setIntentTarget(intent, target) {
548
- this.wire.sendAction('interop-broker-set-intent-target').catch((e) => {
549
- // don't expose, this is only for api analytics purposes
550
- });
551
- const targetInfo = this.intentClientMap.get(target.name);
552
- const handlerId = `intent-handler-${intent.name}`;
553
- if (!targetInfo) {
554
- this.intentClientMap.set(target.name, new Map());
555
- const newHandlerInfoMap = this.intentClientMap.get(target.name);
556
- if (newHandlerInfoMap) {
557
- newHandlerInfoMap.set(handlerId, { isReady: false, pendingIntents: [intent] });
558
- }
559
- }
560
- else {
561
- const handlerInfo = targetInfo.get(handlerId);
562
- if (!handlerInfo) {
563
- targetInfo.set(handlerId, { isReady: false, pendingIntents: [intent] });
564
- }
565
- else {
566
- handlerInfo.pendingIntents.push(intent);
567
- if (handlerInfo.clientIdentity && handlerInfo.isReady) {
568
- const { clientIdentity, pendingIntents } = handlerInfo;
569
- try {
570
- const intentToSend = pendingIntents[pendingIntents.length - 1];
571
- await this.invokeIntentHandler(clientIdentity, handlerId, intentToSend);
572
- handlerInfo.pendingIntents = [];
573
- }
574
- catch (error) {
575
- console.error(`Error invoking intent handler for client ${clientIdentity.uuid}/${clientIdentity.name}/${clientIdentity.endpointId}`);
576
- handlerInfo.isReady = false;
577
- }
578
- }
579
- }
580
- }
581
- }
582
- /**
583
- * Responsible for returning information on a particular Intent.
584
- * Must be overridden.
585
- * @param { InfoForIntentOptions } options
586
- * @param { ClientIdentity } clientIdentity Identity of the Client making the request.
587
- * @return { Promise<unknown> }
588
- * @tutorial interop.handleInfoForIntent
589
- */
590
- // eslint-disable-next-line class-methods-use-this
591
- async handleInfoForIntent(options, clientIdentity) {
592
- const warning = (0, utils_1.generateOverrideWarning)('fdc3.findIntent', 'InteropBroker.handleInfoForIntent', clientIdentity, 'interopClient.getInfoForIntent');
593
- console.warn(warning);
594
- throw new Error(utils_1.BROKER_ERRORS.getInfoForIntent);
595
- }
596
- /**
597
- * Responsible for returning information on which Intents are meant to handle a specific Context.
598
- * Must be overridden.
599
- * @param { Context } context Data passed between entities and applications.
600
- * @param { ClientIdentity } clientIdentity Identity of the Client making the request.
601
- * @return { Promise<unknown> }
602
- * @tutorial interop.handleInfoForIntentsByContext
603
- */
604
- // eslint-disable-next-line class-methods-use-this
605
- async handleInfoForIntentsByContext(context, clientIdentity) {
606
- const warning = (0, utils_1.generateOverrideWarning)('fdc3.findIntentsByContext', 'InteropBroker.handleInfoForIntentsByContext', clientIdentity, 'interopClient.getInfoForIntentsByContext');
607
- console.warn(warning);
608
- throw new Error(utils_1.BROKER_ERRORS.getInfoForIntentsByContext);
609
- }
610
- /**
611
- * Responsible for resolving an Intent based on a specific Context.
612
- * Must be overridden.
613
- * @param { ContextForIntent } contextForIntent Data passed between entities and applications.
614
- * @param { ClientIdentity } clientIdentity Identity of the Client making the request.
615
- * @return { Promise<unknown> }
616
- * @tutorial interop.handleFiredIntentForContext
617
- */
618
- // eslint-disable-next-line class-methods-use-this
619
- async handleFiredIntentForContext(contextForIntent, clientIdentity) {
620
- const warning = (0, utils_1.generateOverrideWarning)('fdc3.raiseIntentForContext', 'InteropBroker.handleFiredIntentForContext', clientIdentity, 'interopClient.fireIntentForContext');
621
- console.warn(warning);
622
- throw new Error(utils_1.BROKER_ERRORS.fireIntentForContext);
623
- }
624
- /**
625
- * Provides the identity of any Interop Client that disconnects from the Interop Broker. It is meant to be overriden.
626
- * @param clientIdentity
627
- * @return { Promise<void> }
628
- * @tutorial interop.clientDisconnected
629
- */
630
- // eslint-disable-next-line class-methods-use-this
631
- async clientDisconnected(clientIdentity) {
632
- // This function is called in channel.onDisconnection.
633
- // It is meant to be overridden to inform when an Interop Client has been disconnected.
634
- }
635
- /**
636
- * Responsible for resolving an fdc3.open call.
637
- * Must be overridden.
638
- * @param { Fdc3OpenOptions } fdc3OpenOptions fdc3.open options
639
- * @param { ClientIdentity } clientIdentity Identity of the Client making the request.
640
- */
641
- // eslint-disable-next-line class-methods-use-this
642
- async fdc3HandleOpen({ app, context }, clientIdentity) {
643
- const warning = (0, utils_1.generateOverrideWarning)('fdc3.open', 'InteropBroker.fdc3HandleOpen', clientIdentity);
644
- console.warn(warning);
645
- throw new Error(utils_1.BROKER_ERRORS.fdc3Open);
646
- }
647
- /**
648
- * Responsible for resolving the fdc3.findInstances call.
649
- * Must be overridden
650
- * @param { AppIdentifier(2) } app AppIdentifier that was passed to fdc3.findInstances
651
- * @param { ClientIdentity } clientIdentity Identity of the Client making the request.
652
- */
653
- // eslint-disable-next-line class-methods-use-this
654
- async fdc3HandleFindInstances(app, clientIdentity) {
655
- const warning = (0, utils_1.generateOverrideWarning)('fdc3.open', 'InteropBroker.fdc3HandleFindInstances', clientIdentity);
656
- console.warn(warning);
657
- throw new Error(utils_1.BROKER_ERRORS.fdc3FindInstances);
658
- }
659
- /**
660
- * Responsible for resolving the fdc3.getAppMetadata call.
661
- * Must be overridden
662
- * @param { AppIdentifier(2) } app AppIdentifier that was passed to fdc3.getAppMetadata
663
- * @param { ClientIdentity } clientIdentity Identity of the Client making the request.
664
- */
665
- // eslint-disable-next-line class-methods-use-this
666
- async fdc3HandleGetAppMetadata(app, clientIdentity) {
667
- const warning = (0, utils_1.generateOverrideWarning)('fdc3.getAppMetadata', 'InteropBroker.fdc3HandleGetAppMetadata', clientIdentity);
668
- console.warn(warning);
669
- throw new Error(utils_1.BROKER_ERRORS.fdc3GetAppMetadata);
670
- }
671
- /**
672
- * This function is called by the Interop Broker whenever a Context handler would fire.
673
- * For FDC3 2.0 you would need to override this function and add the contextMetadata as
674
- * part of the Context object. Then would you need to call
675
- * super.invokeContextHandler passing it this new Context object along with the clientIdentity and handlerId
676
- * @param { ClientIdentity } clientIdentity
677
- * @param { string } handlerId
678
- * @param { Context } context
679
- * @returns { Promise<void> }
680
- * @tutorial interopBroker.invokeContextHandler
681
- */
682
- async invokeContextHandler(clientIdentity, handlerId, context) {
683
- const provider = await this.getProvider();
684
- try {
685
- await provider.dispatch(clientIdentity, handlerId, context);
686
- }
687
- catch (error) {
688
- console.error(`Error invoking context handler ${handlerId} for context type ${context.type} in client ${clientIdentity.uuid}/${clientIdentity.name}/${clientIdentity.endpointId}`, error);
689
- }
690
- }
691
- /**
692
- * This function is called by the Interop Broker whenever an Intent handler would fire.
693
- * For FDC3 2.0 you would need to override this function and add the contextMetadata as
694
- * part of the Context object inside the Intent object. Then would you need to call
695
- * super.invokeIntentHandler passing it this new Intent object along with the clientIdentity and handlerId
696
- * @param { ClientIdentity } ClientIdentity
697
- * @param { string } handlerId
698
- * @param { Context } context
699
- * @returns { Promise<void> }
700
- * @tutorial interopBroker.invokeIntentHandler
701
- */
702
- async invokeIntentHandler(clientIdentity, handlerId, intent) {
703
- const provider = await this.getProvider();
704
- await provider.dispatch(clientIdentity, handlerId, intent);
705
- }
706
- /**
707
- * Responsible for resolving fdc3.getInfo for FDC3 2.0
708
- * Would need to return the optionalFeatures and appMetadata for the {@link ImplementationMetadata ImplementationMetadata}.
709
- * Must be overridden.
710
- * @param clientIdentity
711
- * @returns { Promise<ImplementationMetadata(2)> }
712
- */
713
- // eslint-disable-next-line class-methods-use-this
714
- async fdc3HandleGetInfo(payload, clientIdentity) {
715
- const { fdc3Version } = payload;
716
- return {
717
- fdc3Version,
718
- provider: 'OpenFin',
719
- providerVersion: await this.fin.System.getVersion(),
720
- optionalFeatures: {
721
- OriginatingAppMetadata: false,
722
- UserChannelMembershipAPIs: true
723
- },
724
- appMetadata: {
725
- appId: '',
726
- instanceId: ''
727
- }
728
- };
729
- }
730
- /**
731
- * Returns an array of info for each Interop Client connected to the Interop Broker.
732
- *
733
- * FDC3 2.0: Use the endpointId in the ClientInfo as the instanceId when generating
734
- * an AppIdentifier.
735
- * @return { Promise<Array<ClientInfo>> }
736
- * @tutorial interop.getAllClientInfo
737
- */
738
- async getAllClientInfo() {
739
- const provider = await this.getProvider();
740
- return provider.getAllClientInfo();
741
- }
742
- /*
743
- Snapshot APIs
744
- */
745
- // Used to save interop broker state in snapshots
746
- decorateSnapshot(snapshot) {
747
- return { ...snapshot, interopSnapshotDetails: { contextGroupStates: this.getContextGroupStates() } };
748
- }
749
- // Used to restore interop broker state in snapshots.
750
- applySnapshot(snapshot, options) {
751
- var _a;
752
- const contextGroupStates = (_a = snapshot === null || snapshot === void 0 ? void 0 : snapshot.interopSnapshotDetails) === null || _a === void 0 ? void 0 : _a.contextGroupStates;
753
- if (contextGroupStates) {
754
- if (!(options === null || options === void 0 ? void 0 : options.closeExistingWindows)) {
755
- this.updateExistingClients(contextGroupStates);
756
- }
757
- this.rehydrateContextGroupStates(contextGroupStates);
758
- }
759
- }
760
- updateExistingClients(contextGroupStates) {
761
- const clients = this.interopClients;
762
- clients.forEach((subState) => {
763
- const { clientIdentity, contextGroupId, contextHandlers } = subState;
764
- if (contextGroupId) {
765
- const groupContexts = contextGroupStates[contextGroupId];
766
- for (const [, context] of Object.entries(groupContexts)) {
767
- contextHandlers.forEach((contextHandler) => {
768
- const { handlerId, contextType } = contextHandler;
769
- if (InteropBroker.isContextTypeCompatible(context.type, contextType)) {
770
- this.invokeContextHandler(clientIdentity, handlerId, context);
771
- }
772
- });
773
- }
774
- }
775
- });
776
- }
777
- // Used to store context group state in snapshots
778
- getContextGroupStates() {
779
- return InteropBroker.toObject(this.contextGroupsById);
780
- }
781
- // Used to rehydrate the context state from a snapshot
782
- rehydrateContextGroupStates(incomingContextGroupStates) {
783
- const contextGroupStates = Object.entries(incomingContextGroupStates);
784
- for (const [contextGroupId, contexts] of contextGroupStates) {
785
- const contextObjects = Object.entries(contexts);
786
- for (const [contextType, context] of contextObjects) {
787
- if (this.contextGroupsById.has(contextGroupId)) {
788
- const currentContextGroupState = this.contextGroupsById.get(contextGroupId);
789
- currentContextGroupState.set(contextType, context);
790
- }
791
- else {
792
- // This logic will change when dynamic context group creation comes in.
793
- console.warn(`Attempting to set a context group that isn't in the context group mapping. Skipping context group rehydration for: ${contextGroupId}`);
794
- }
795
- }
796
- }
797
- }
798
- /*
799
- Internal Context Handler APIs
800
- */
801
- // Used to give context to a client that has registered their context handler
802
- contextHandlerRegistered({ contextType, handlerId }, clientIdentity) {
803
- const handlerInfo = { contextType, handlerId };
804
- const clientState = this.getClientState(clientIdentity);
805
- clientState === null || clientState === void 0 ? void 0 : clientState.contextHandlers.set(handlerId, handlerInfo);
806
- if (clientState && clientState.contextGroupId) {
807
- const { contextGroupId } = clientState;
808
- const contextGroupMap = this.contextGroupsById.get(contextGroupId);
809
- if (contextType === undefined) {
810
- // Send this single handler all of the context, because it accepts all.
811
- contextGroupMap.forEach((context, _) => {
812
- this.invokeContextHandler(clientIdentity, handlerId, context);
813
- });
814
- }
815
- else if (contextGroupMap.has(contextType)) {
816
- const contextForType = contextGroupMap.get(contextType);
817
- if (contextForType) {
818
- this.invokeContextHandler(clientIdentity, handlerId, contextForType);
819
- }
820
- }
821
- }
822
- }
823
- // eslint-disable-next-line class-methods-use-this
824
- async intentHandlerRegistered(payload, clientIdentity) {
825
- const { handlerId } = payload;
826
- const clientIntentInfo = this.intentClientMap.get(clientIdentity.name);
827
- const handlerInfo = clientIntentInfo === null || clientIntentInfo === void 0 ? void 0 : clientIntentInfo.get(handlerId);
828
- if (!clientIntentInfo) {
829
- this.intentClientMap.set(clientIdentity.name, new Map());
830
- const newHandlerInfoMap = this.intentClientMap.get(clientIdentity.name);
831
- if (newHandlerInfoMap) {
832
- newHandlerInfoMap.set(handlerId, { isReady: true, pendingIntents: [], clientIdentity });
833
- }
834
- }
835
- else if (!handlerInfo) {
836
- clientIntentInfo.set(handlerId, { isReady: true, pendingIntents: [], clientIdentity });
837
- }
838
- else {
839
- const { pendingIntents } = handlerInfo;
840
- handlerInfo.clientIdentity = clientIdentity;
841
- handlerInfo.isReady = true;
842
- try {
843
- if (pendingIntents.length > 0) {
844
- const intentToSend = pendingIntents[pendingIntents.length - 1];
845
- await this.invokeIntentHandler(clientIdentity, handlerId, intentToSend);
846
- handlerInfo.pendingIntents = [];
847
- }
848
- }
849
- catch (error) {
850
- console.error(`Error invoking intent handler: ${handlerId} for client ${clientIdentity.uuid}/${clientIdentity.name}/${clientIdentity.endpointId}`);
851
- }
852
- }
853
- }
854
- // Used to remove a context handler for a client
855
- removeContextHandler({ handlerId }, clientIdentity) {
856
- const clientState = this.getClientState(clientIdentity);
857
- if (clientState) {
858
- clientState.contextHandlers.delete(handlerId);
859
- }
860
- }
861
- handleJoinSessionContextGroup({ sessionContextGroupId }, clientIdentity) {
862
- try {
863
- if (!sessionContextGroupId) {
864
- throw new Error('Failed to join session context group: must specify group id.');
865
- }
866
- const sessionContextGroup = this.sessionContextGroupMap.get(sessionContextGroupId);
867
- if (sessionContextGroup) {
868
- sessionContextGroup.registerNewClient(clientIdentity);
869
- }
870
- else {
871
- const newSessionContextGroupBroker = new SessionContextGroupBroker_1.default(this.channel, sessionContextGroupId);
872
- newSessionContextGroupBroker.registerNewClient(clientIdentity);
873
- this.sessionContextGroupMap.set(sessionContextGroupId, newSessionContextGroupBroker);
874
- }
875
- return { hasConflict: this.contextGroupsById.has(sessionContextGroupId) };
876
- }
877
- catch (error) {
878
- throw new Error(error);
879
- }
880
- }
881
- /*
882
- Internal Utilties
883
- */
884
- // Getter for interop info for a client.
885
- getClientState(id) {
886
- return this.interopClients.get(id.endpointId);
887
- }
888
- // Util for getContextGroupStates. Serializes the contextGroupStates object so we can store it.
889
- static toObject(map) {
890
- const objectFromMap = Object.fromEntries(map);
891
- const newObject = {};
892
- Object.entries(objectFromMap).forEach(([contextGroupId, contextMap]) => {
893
- const newContextObject = Object.fromEntries(contextMap);
894
- newObject[contextGroupId] = newContextObject;
895
- });
896
- return newObject;
897
- }
898
- static checkContextIntegrity(context) {
899
- if (!context) {
900
- return { isValid: false, reason: 'No context supplied' };
901
- }
902
- if (typeof context !== 'object') {
903
- return { isValid: false, reason: 'Context must be an Object' };
904
- }
905
- if (!context.type) {
906
- return { isValid: false, reason: 'Context must have a type property' };
907
- }
908
- if (context.id && typeof context.id !== 'object') {
909
- return {
910
- isValid: false,
911
- reason: 'Context id must be an Object populated with key-value identifiers (if set)'
912
- };
913
- }
914
- if (context.id) {
915
- const { id } = context;
916
- const keys = Object.keys(id);
917
- let foundBadIdentifier = false;
918
- if (!keys.length) {
919
- return { isValid: false, reason: 'Context id must have at least one key-value identifier' };
920
- }
921
- keys.forEach((key) => {
922
- if (typeof key !== 'string' || typeof id[key] !== 'string') {
923
- foundBadIdentifier = true;
924
- }
925
- });
926
- if (foundBadIdentifier) {
927
- return { isValid: false, reason: 'Context id key-value identifiers must be of type string' };
928
- }
929
- }
930
- if (context.name && typeof context.name !== 'string') {
931
- return { isValid: false, reason: 'Context name must be of string type (if set)' };
932
- }
933
- return { isValid: true };
934
- }
935
- // Util to check a client identity.
936
- static hasEndpointId(target) {
937
- return target.endpointId !== undefined;
938
- }
939
- // Util to check if we should send a context to a handler.
940
- static isContextTypeCompatible(contextType, registeredContextType) {
941
- return typeof registeredContextType === 'undefined' || contextType === registeredContextType;
942
- }
943
- // Setup function for state mapping
944
- setContextGroupMap() {
945
- // This way, if a user overrides this.getContextGroups, it's reflected in the contextGroupMapping.
946
- for (const contextGroupInfo of this.getContextGroups()) {
947
- this.contextGroupsById.set(contextGroupInfo.id, new Map());
948
- }
949
- }
950
- async setCurrentContextGroupInClientOptions(clientIdentity, contextGroupId) {
951
- const entityInfo = await this.fin.System.getEntityInfo(clientIdentity.uuid, clientIdentity.name);
952
- let entity;
953
- if (entityInfo.entityType === 'view') {
954
- entity = await this.fin.View.wrap(clientIdentity);
955
- }
956
- else if (entityInfo.entityType === 'window') {
957
- entity = await this.fin.Window.wrap(clientIdentity);
958
- }
959
- if (entity) {
960
- await entity.updateOptions({
961
- interop: {
962
- currentContextGroup: contextGroupId
963
- }
964
- });
965
- }
966
- else {
967
- console.warn(`Setting Current Context Group: Entity with identity ${clientIdentity.uuid}, ${clientIdentity.name} is not a window or view. It is a ${entityInfo.entityType} instead.`);
968
- }
969
- }
970
- async setupChannelProvider() {
971
- try {
972
- const channel = await this.getProvider();
973
- this.channel = channel;
974
- this.wireChannel(channel);
975
- }
976
- catch (error) {
977
- throw new Error(`Error setting up Interop Broker Channel Provider: ${error}`);
978
- }
979
- }
980
- // Setup Channel Connection Logic
981
- wireChannel(channel) {
982
- channel.onConnection(async (clientIdentity, payload) => {
983
- if (!(await this.isConnectionAuthorized(clientIdentity, payload))) {
984
- throw new Error(`Connection not authorized for ${clientIdentity.uuid}, ${clientIdentity.name}`);
985
- }
986
- if (!clientIdentity.endpointId) {
987
- throw new Error('Version too old to be compatible with Interop. Please upgrade your runtime to a more recent version.');
988
- }
989
- const clientSubscriptionState = {
990
- contextGroupId: undefined,
991
- contextHandlers: new Map(),
992
- clientIdentity
993
- };
994
- // Only allow the client to join a contextGroup that actually exists.
995
- if ((payload === null || payload === void 0 ? void 0 : payload.currentContextGroup) && this.contextGroupsById.has(payload.currentContextGroup)) {
996
- clientSubscriptionState.contextGroupId = payload === null || payload === void 0 ? void 0 : payload.currentContextGroup;
997
- }
998
- this.interopClients.set(clientIdentity.endpointId, clientSubscriptionState);
999
- });
1000
- channel.onDisconnection((clientIdentity) => {
1001
- this.interopClients.delete(clientIdentity.endpointId);
1002
- const targetInfo = this.intentClientMap.get(clientIdentity.name);
1003
- if (targetInfo && clientIdentity.uuid === this.fin.me.uuid) {
1004
- targetInfo.forEach((handler) => {
1005
- handler.isReady = false;
1006
- });
1007
- }
1008
- this.sessionContextGroupMap.forEach((sessionContextGroup) => {
1009
- sessionContextGroup.onDisconnection(clientIdentity);
1010
- });
1011
- this.clientDisconnected(clientIdentity);
1012
- });
1013
- channel.beforeAction(async (action, payload, clientIdentity) => {
1014
- var _a, _b;
1015
- if (!(await this.isActionAuthorized(action, payload, clientIdentity))) {
1016
- throw new Error(`Action (${action}) not authorized for ${clientIdentity.uuid}, ${clientIdentity.name}`);
1017
- }
1018
- if ((_b = (_a = this.logging) === null || _a === void 0 ? void 0 : _a.beforeAction) === null || _b === void 0 ? void 0 : _b.enabled) {
1019
- console.log(action, payload, clientIdentity);
1020
- }
1021
- });
1022
- channel.afterAction((action, payload, clientIdentity) => {
1023
- var _a, _b;
1024
- if ((_b = (_a = this.logging) === null || _a === void 0 ? void 0 : _a.afterAction) === null || _b === void 0 ? void 0 : _b.enabled) {
1025
- console.log(action, payload, clientIdentity);
1026
- }
1027
- });
1028
- // Client functions
1029
- channel.register('setContext', this.setContext.bind(this));
1030
- channel.register('fireIntent', this.handleFiredIntent.bind(this));
1031
- channel.register('getCurrentContext', this.getCurrentContext.bind(this));
1032
- channel.register('getInfoForIntent', this.handleInfoForIntent.bind(this));
1033
- channel.register('getInfoForIntentsByContext', this.handleInfoForIntentsByContext.bind(this));
1034
- channel.register('fireIntentForContext', this.handleFiredIntentForContext.bind(this));
1035
- // Platform window functions
1036
- channel.register('getContextGroups', this.getContextGroups.bind(this));
1037
- channel.register('joinContextGroup', this.joinContextGroup.bind(this));
1038
- channel.register('removeFromContextGroup', this.removeFromContextGroup.bind(this));
1039
- channel.register('getAllClientsInContextGroup', this.getAllClientsInContextGroup.bind(this));
1040
- channel.register('getInfoForContextGroup', this.getInfoForContextGroup.bind(this));
1041
- // Internal methods
1042
- channel.register('contextHandlerRegistered', this.contextHandlerRegistered.bind(this));
1043
- channel.register('intentHandlerRegistered', this.intentHandlerRegistered.bind(this));
1044
- channel.register('removeContextHandler', this.removeContextHandler.bind(this));
1045
- channel.register('sessionContextGroup:createIfNeeded', this.handleJoinSessionContextGroup.bind(this));
1046
- // fdc3 only methods
1047
- channel.register('fdc3Open', this.fdc3HandleOpen.bind(this));
1048
- channel.register('fdc3v2FindIntentsByContext', this.handleInfoForIntentsByContext.bind(this));
1049
- channel.register('fdc3FindInstances', this.fdc3HandleFindInstances.bind(this));
1050
- channel.register('fdc3GetAppMetadata', this.fdc3HandleGetAppMetadata.bind(this));
1051
- channel.register('fdc3v2GetInfo', async (payload, clientIdentity) => {
1052
- return this.fdc3HandleGetInfo.bind(this)(payload, clientIdentity);
1053
- });
1054
- channel.register('createPrivateChannelProvider', async (payload) => {
1055
- const { channelId } = payload;
1056
- const channelProvider = await this.fin.InterApplicationBus.Channel.create(channelId);
1057
- PrivateChannelProvider_1.PrivateChannelProvider.init(channelProvider, channelId);
1058
- });
1059
- }
1060
- /**
1061
- * Can be used to completely prevent a connection. Return false to prevent connections. Allows all connections by default.
1062
- * @param _id the identity tryinc to connect
1063
- * @param _connectionPayload optional payload to use in custom implementations, will be undefined by default
1064
- */
1065
- isConnectionAuthorized(_id, _connectionPayload) {
1066
- this.wire.sendAction('interop-broker-is-connection-authorized').catch((e) => {
1067
- // don't expose, analytics-only call
1068
- });
1069
- return Promise.resolve(true);
1070
- }
1071
- /**
1072
- * Called before every action to check if this entity should be allowed to take the action.
1073
- * Return false to prevent the action
1074
- * @param _action the string action to authorize in camel case
1075
- * @param _payload the data being sent for this action
1076
- * @param _identity the connection attempting to dispatch this action
1077
- */
1078
- isActionAuthorized(_action, _payload, _identity) {
1079
- this.wire.sendAction('interop-broker-is-action-authorized').catch((e) => {
1080
- // don't expose, analytics-only call
1081
- });
1082
- return Promise.resolve(true);
1083
- }
1084
- }
1085
- exports.InteropBroker = InteropBroker;