@openfin/core 25.68.26

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 (227) hide show
  1. package/LICENSE +13 -0
  2. package/NOTICE +16 -0
  3. package/OpenFin.d.ts +1340 -0
  4. package/README.md +41 -0
  5. package/docs.README(OLD).md +82 -0
  6. package/fin.d.ts +4 -0
  7. package/package.json +33 -0
  8. package/resources/win/OpenFinRVM.exe +0 -0
  9. package/src/api/application/Factory.d.ts +145 -0
  10. package/src/api/application/Factory.js +229 -0
  11. package/src/api/application/Instance.d.ts +302 -0
  12. package/src/api/application/Instance.js +412 -0
  13. package/src/api/application/index.d.ts +3 -0
  14. package/src/api/application/index.js +15 -0
  15. package/src/api/base.d.ts +43 -0
  16. package/src/api/base.js +177 -0
  17. package/src/api/clipboard/index.d.ts +69 -0
  18. package/src/api/clipboard/index.js +88 -0
  19. package/src/api/events/application.d.ts +69 -0
  20. package/src/api/events/application.js +2 -0
  21. package/src/api/events/base.d.ts +17 -0
  22. package/src/api/events/base.js +2 -0
  23. package/src/api/events/channel.d.ts +10 -0
  24. package/src/api/events/channel.js +2 -0
  25. package/src/api/events/emitterMap.d.ts +11 -0
  26. package/src/api/events/emitterMap.js +35 -0
  27. package/src/api/events/eventAggregator.d.ts +5 -0
  28. package/src/api/events/eventAggregator.js +43 -0
  29. package/src/api/events/externalApplication.d.ts +5 -0
  30. package/src/api/events/externalApplication.js +2 -0
  31. package/src/api/events/frame.d.ts +9 -0
  32. package/src/api/events/frame.js +2 -0
  33. package/src/api/events/globalHotkey.d.ts +10 -0
  34. package/src/api/events/globalHotkey.js +2 -0
  35. package/src/api/events/platform.d.ts +18 -0
  36. package/src/api/events/platform.js +2 -0
  37. package/src/api/events/system.d.ts +22 -0
  38. package/src/api/events/system.js +2 -0
  39. package/src/api/events/view.d.ts +56 -0
  40. package/src/api/events/view.js +2 -0
  41. package/src/api/events/webcontents.d.ts +48 -0
  42. package/src/api/events/webcontents.js +2 -0
  43. package/src/api/events/window.d.ts +169 -0
  44. package/src/api/events/window.js +2 -0
  45. package/src/api/external-application/Factory.d.ts +26 -0
  46. package/src/api/external-application/Factory.js +40 -0
  47. package/src/api/external-application/Instance.d.ts +102 -0
  48. package/src/api/external-application/Instance.js +109 -0
  49. package/src/api/external-application/index.d.ts +3 -0
  50. package/src/api/external-application/index.js +15 -0
  51. package/src/api/fin.d.ts +49 -0
  52. package/src/api/fin.js +43 -0
  53. package/src/api/frame/Factory.d.ts +36 -0
  54. package/src/api/frame/Factory.js +69 -0
  55. package/src/api/frame/Instance.d.ts +121 -0
  56. package/src/api/frame/Instance.js +130 -0
  57. package/src/api/frame/index.d.ts +3 -0
  58. package/src/api/frame/index.js +15 -0
  59. package/src/api/global-hotkey/index.d.ts +38 -0
  60. package/src/api/global-hotkey/index.js +58 -0
  61. package/src/api/interappbus/channel/channel.d.ts +26 -0
  62. package/src/api/interappbus/channel/channel.js +77 -0
  63. package/src/api/interappbus/channel/channels-docs.d.ts +318 -0
  64. package/src/api/interappbus/channel/channels-docs.js +376 -0
  65. package/src/api/interappbus/channel/client.d.ts +22 -0
  66. package/src/api/interappbus/channel/client.js +84 -0
  67. package/src/api/interappbus/channel/connection-manager.d.ts +28 -0
  68. package/src/api/interappbus/channel/connection-manager.js +244 -0
  69. package/src/api/interappbus/channel/index.d.ts +22 -0
  70. package/src/api/interappbus/channel/index.js +121 -0
  71. package/src/api/interappbus/channel/protocols/classic/message-receiver.d.ts +13 -0
  72. package/src/api/interappbus/channel/protocols/classic/message-receiver.js +73 -0
  73. package/src/api/interappbus/channel/protocols/classic/strategy.d.ts +22 -0
  74. package/src/api/interappbus/channel/protocols/classic/strategy.js +84 -0
  75. package/src/api/interappbus/channel/protocols/combined/strategy.d.ts +20 -0
  76. package/src/api/interappbus/channel/protocols/combined/strategy.js +58 -0
  77. package/src/api/interappbus/channel/protocols/index.d.ts +44 -0
  78. package/src/api/interappbus/channel/protocols/index.js +2 -0
  79. package/src/api/interappbus/channel/protocols/protocol-manager.d.ts +10 -0
  80. package/src/api/interappbus/channel/protocols/protocol-manager.js +43 -0
  81. package/src/api/interappbus/channel/protocols/rtc/endpoint.d.ts +23 -0
  82. package/src/api/interappbus/channel/protocols/rtc/endpoint.js +135 -0
  83. package/src/api/interappbus/channel/protocols/rtc/ice-manager.d.ts +30 -0
  84. package/src/api/interappbus/channel/protocols/rtc/ice-manager.js +131 -0
  85. package/src/api/interappbus/channel/protocols/rtc/strategy.d.ts +22 -0
  86. package/src/api/interappbus/channel/protocols/rtc/strategy.js +87 -0
  87. package/src/api/interappbus/channel/protocols/strategy-types.d.ts +13 -0
  88. package/src/api/interappbus/channel/protocols/strategy-types.js +2 -0
  89. package/src/api/interappbus/channel/protocols/strategy.d.ts +15 -0
  90. package/src/api/interappbus/channel/protocols/strategy.js +2 -0
  91. package/src/api/interappbus/channel/provider.d.ts +31 -0
  92. package/src/api/interappbus/channel/provider.js +165 -0
  93. package/src/api/interappbus/index.d.ts +85 -0
  94. package/src/api/interappbus/index.js +175 -0
  95. package/src/api/interop/Factory.d.ts +37 -0
  96. package/src/api/interop/Factory.js +54 -0
  97. package/src/api/interop/InteropBroker.d.ts +363 -0
  98. package/src/api/interop/InteropBroker.js +914 -0
  99. package/src/api/interop/InteropClient.d.ts +268 -0
  100. package/src/api/interop/InteropClient.js +450 -0
  101. package/src/api/interop/SessionContextGroupBroker.d.ts +26 -0
  102. package/src/api/interop/SessionContextGroupBroker.js +107 -0
  103. package/src/api/interop/SessionContextGroupClient.d.ts +20 -0
  104. package/src/api/interop/SessionContextGroupClient.js +85 -0
  105. package/src/api/interop/fdc3/fdc3-1.2.d.ts +187 -0
  106. package/src/api/interop/fdc3/fdc3-1.2.js +385 -0
  107. package/src/api/interop/fdc3/fdc3.js +17 -0
  108. package/src/api/interop/fdc3/utils.d.ts +6 -0
  109. package/src/api/interop/fdc3/utils.js +17 -0
  110. package/src/api/interop/index.d.ts +4 -0
  111. package/src/api/interop/index.js +16 -0
  112. package/src/api/interop/utils.d.ts +11 -0
  113. package/src/api/interop/utils.js +36 -0
  114. package/src/api/me.d.ts +35 -0
  115. package/src/api/me.js +60 -0
  116. package/src/api/platform/Factory.d.ts +109 -0
  117. package/src/api/platform/Factory.js +188 -0
  118. package/src/api/platform/Instance.d.ts +122 -0
  119. package/src/api/platform/Instance.js +299 -0
  120. package/src/api/platform/common-utils.d.ts +6 -0
  121. package/src/api/platform/common-utils.js +16 -0
  122. package/src/api/platform/index.d.ts +3 -0
  123. package/src/api/platform/index.js +15 -0
  124. package/src/api/platform/layout/Factory.d.ts +108 -0
  125. package/src/api/platform/layout/Factory.js +189 -0
  126. package/src/api/platform/layout/Instance.d.ts +48 -0
  127. package/src/api/platform/layout/Instance.js +99 -0
  128. package/src/api/platform/layout/index.d.ts +3 -0
  129. package/src/api/platform/layout/index.js +15 -0
  130. package/src/api/platform/layout/shapes.d.ts +11 -0
  131. package/src/api/platform/layout/shapes.js +2 -0
  132. package/src/api/snapshot-source/Factory.d.ts +36 -0
  133. package/src/api/snapshot-source/Factory.js +65 -0
  134. package/src/api/snapshot-source/Instance.d.ts +30 -0
  135. package/src/api/snapshot-source/Instance.js +134 -0
  136. package/src/api/snapshot-source/index.d.ts +3 -0
  137. package/src/api/snapshot-source/index.js +15 -0
  138. package/src/api/snapshot-source/utils.d.ts +1 -0
  139. package/src/api/snapshot-source/utils.js +5 -0
  140. package/src/api/system/application.d.ts +6 -0
  141. package/src/api/system/application.js +2 -0
  142. package/src/api/system/entity.d.ts +11 -0
  143. package/src/api/system/entity.js +2 -0
  144. package/src/api/system/index.d.ts +957 -0
  145. package/src/api/system/index.js +1241 -0
  146. package/src/api/system/installedApps.d.ts +6 -0
  147. package/src/api/system/installedApps.js +2 -0
  148. package/src/api/system/log.d.ts +11 -0
  149. package/src/api/system/log.js +2 -0
  150. package/src/api/system/process.d.ts +15 -0
  151. package/src/api/system/process.js +2 -0
  152. package/src/api/system/proxy.d.ts +15 -0
  153. package/src/api/system/proxy.js +2 -0
  154. package/src/api/system/queryPermissionTypes.d.ts +1 -0
  155. package/src/api/system/queryPermissionTypes.js +2 -0
  156. package/src/api/system/registry-info.d.ts +7 -0
  157. package/src/api/system/registry-info.js +2 -0
  158. package/src/api/system/window.d.ts +16 -0
  159. package/src/api/system/window.js +2 -0
  160. package/src/api/view/Factory.d.ts +49 -0
  161. package/src/api/view/Factory.js +103 -0
  162. package/src/api/view/Instance.d.ts +379 -0
  163. package/src/api/view/Instance.js +415 -0
  164. package/src/api/view/index.d.ts +3 -0
  165. package/src/api/view/index.js +15 -0
  166. package/src/api/webcontents/main.d.ts +36 -0
  167. package/src/api/webcontents/main.js +82 -0
  168. package/src/api/window/Factory.d.ts +44 -0
  169. package/src/api/window/Factory.js +91 -0
  170. package/src/api/window/Instance.d.ts +966 -0
  171. package/src/api/window/Instance.js +1202 -0
  172. package/src/api/window/bounds-changed.d.ts +10 -0
  173. package/src/api/window/bounds-changed.js +6 -0
  174. package/src/api/window/index.d.ts +5 -0
  175. package/src/api/window/index.js +17 -0
  176. package/src/api/window/shapes.d.ts +13 -0
  177. package/src/api/window/shapes.js +2 -0
  178. package/src/environment/environment.d.ts +28 -0
  179. package/src/environment/environment.js +4 -0
  180. package/src/environment/node-env.d.ts +25 -0
  181. package/src/environment/node-env.js +64 -0
  182. package/src/environment/openfin-env.d.ts +29 -0
  183. package/src/environment/openfin-env.js +105 -0
  184. package/src/mock.d.ts +4 -0
  185. package/src/mock.js +91 -0
  186. package/src/shapes/ERROR_BOX_TYPES.d.ts +6 -0
  187. package/src/shapes/ERROR_BOX_TYPES.js +10 -0
  188. package/src/shapes/EntityType.d.ts +1 -0
  189. package/src/shapes/EntityType.js +2 -0
  190. package/src/shapes/LayoutPresetType.d.ts +1 -0
  191. package/src/shapes/LayoutPresetType.js +2 -0
  192. package/src/shapes/Platform.d.ts +112 -0
  193. package/src/shapes/Platform.js +16 -0
  194. package/src/shapes/WebOptions.d.ts +12 -0
  195. package/src/shapes/WebOptions.js +2 -0
  196. package/src/shapes/WindowOptions.d.ts +42 -0
  197. package/src/shapes/WindowOptions.js +2 -0
  198. package/src/shapes/protocol.d.ts +178 -0
  199. package/src/shapes/protocol.js +2 -0
  200. package/src/transport/fin_store.d.ts +4 -0
  201. package/src/transport/fin_store.js +16 -0
  202. package/src/transport/transport-errors.d.ts +17 -0
  203. package/src/transport/transport-errors.js +39 -0
  204. package/src/transport/transport.d.ts +57 -0
  205. package/src/transport/transport.js +195 -0
  206. package/src/transport/wire.d.ts +76 -0
  207. package/src/transport/wire.js +39 -0
  208. package/src/util/asyncFilter.d.ts +1 -0
  209. package/src/util/asyncFilter.js +7 -0
  210. package/src/util/errors.d.ts +9 -0
  211. package/src/util/errors.js +14 -0
  212. package/src/util/exhaustive.d.ts +1 -0
  213. package/src/util/exhaustive.js +7 -0
  214. package/src/util/http.d.ts +11 -0
  215. package/src/util/http.js +83 -0
  216. package/src/util/normalize-config.d.ts +3 -0
  217. package/src/util/normalize-config.js +47 -0
  218. package/src/util/promises.d.ts +5 -0
  219. package/src/util/promises.js +27 -0
  220. package/src/util/ref-counter.d.ts +7 -0
  221. package/src/util/ref-counter.js +51 -0
  222. package/src/util/runtimeVersioning.d.ts +3 -0
  223. package/src/util/runtimeVersioning.js +25 -0
  224. package/src/util/utilTypes.d.ts +8 -0
  225. package/src/util/utilTypes.js +2 -0
  226. package/src/util/validate.d.ts +3 -0
  227. package/src/util/validate.js +11 -0
@@ -0,0 +1,450 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
3
+ if (!privateMap.has(receiver)) {
4
+ throw new TypeError("attempted to set private field on non-instance");
5
+ }
6
+ privateMap.set(receiver, value);
7
+ return value;
8
+ };
9
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
10
+ if (!privateMap.has(receiver)) {
11
+ throw new TypeError("attempted to get private field on non-instance");
12
+ }
13
+ return privateMap.get(receiver);
14
+ };
15
+ var _clientPromise, _sessionContextGroups;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.InteropClient = void 0;
18
+ const base_1 = require("../base");
19
+ const SessionContextGroupClient_1 = require("./SessionContextGroupClient");
20
+ const utils_1 = require("./utils");
21
+ /**
22
+ * @typedef { object } Intent
23
+ * @summary The combination of an action and a context that is passed to an application for resolution.
24
+ * @property { string } name Name of the intent.
25
+ * @property { Context } context Data associated with the intent
26
+ */
27
+ /**
28
+ * @typedef { object } Subscription
29
+ * @summary Object returned when subscribing a handler.
30
+ * @property { function } unsubscribe Function to unsubscribe the handler.
31
+ */
32
+ /**
33
+ * @typedef { function } ContextHandler
34
+ * @summary Subscription function for addContextHandler.
35
+ */
36
+ /**
37
+ * @typedef { function } IntentHandler
38
+ * @summary Subscription function for registerIntentHandler
39
+ */
40
+ /**
41
+ * @typedef { object } ClientIdentity
42
+ * @summary The Identity for a Channel Client. Includes endpointId to differentiate between different connections for an entity.
43
+ * @property {string} uuid GUID of an application.
44
+ * @property {string} name Name of an entity in an application.
45
+ * @property {string} endpointId Unique differentiator for different Channel connections for an entity.
46
+ */
47
+ /**
48
+ * @typedef { object } ContextGroupInfo
49
+ * @summary Information for a Context Group. Contains metadata for displaying the group properly.
50
+ * @property {string} id Name of the context group
51
+ * @property {DisplayMetadata} displayMetadata Metadata for the Context Group. Contains the group's human-readable name, color, and an image, as defined by the Interop Broker.
52
+ */
53
+ /**
54
+ * @typedef { object } DisplayMetadata
55
+ * @summary The display data for a Context Group.
56
+ * @property {string} name A user-readable name for this context group, e.g: `"Red"`
57
+ * @property {string} [color] The color that should be associated within this context group when displaying this context group in a UI, e.g: `0xFF0000`.
58
+ * @property {string} [glyph] A URL of an image that can be used to display this context group
59
+ */
60
+ /**
61
+ * @typedef { object } Context
62
+ * @summary Data passed between entities and applications.
63
+ * @property {object} [id] An object containing string key-value pairs for the bulk of the data for the context. Differs between context types.
64
+ * @property {string} [name] User-readable name for the incoming context.
65
+ * @property {string} type Conserved type for the context (e.g. `instrument` or `country`)
66
+ */
67
+ /**
68
+ * @typedef { object } ContextForIntent
69
+ * @summary Data passed between entities and applications, including an optional metadata.
70
+ * @property {object} [id] An object containing string key-value pairs for the bulk of the data for the context. Differs between context types.
71
+ * @property {string} [name] User-readable name for the incoming context.
72
+ * @property {string} type Conserved type for the context (e.g. `instrument` or `country`)
73
+ * @property {any} [metadata]
74
+ */
75
+ /**
76
+ * @typedef { object } SessionContextGroup
77
+ * @summary An instance of a SessionContextGroup
78
+ * @property {string} id The SessionContextGroup's id.
79
+ * @property {setContext} setContext Sets a context of a certain type
80
+ * @property {getCurrentContext} getCurrentContext Gets the currently set context of a certain type
81
+ * @property {addContextHandler} addContextHandler Adds a handler for context change.
82
+ */
83
+ /**
84
+ * @typedef {function} setContext
85
+ * @summary A SessionContextGroup instance method for setting a context in the SessionContextGroup.
86
+ * @param {Context} context The Context to be set.
87
+ * @return {Promise<void>}
88
+ */
89
+ /**
90
+ * @typedef {function} getCurrentContext
91
+ * @summary A SessionContextGroup instance method for getting the current context of a certain type.
92
+ * @param {string} [contextType] The Context Type to get. If not specified the last contextType set would get used.
93
+ * @return {Promise<Context>}
94
+ */
95
+ /**
96
+ * @typedef {function} addContextHandler
97
+ * @summary A SessionContextGroup instance method for adding a handler for context change.
98
+ * @param {ContextHandler} contextHandler The callback to be invoked. Is invoked when (a) the context changes or (b) immediately after getting created if the context is already set.
99
+ * @param {string} [contextType] The context type this handler should listen to. If not specified, a global handler for all context types will get created. Only one global handler is allowed per SessionContextGroup.
100
+ * @return {Promise<void>}
101
+ */
102
+ /**
103
+ * {@link https://developers.openfin.co/of-docs/docs/enable-color-linking **THE INTEROP API IS EXPERIMENTAL. IF YOU WOULD LIKE TO USE IT, PLEASE USE OUR DEFAULT IMPLEMENTATION IN BROWSER**}
104
+ *
105
+ * The Interop Client API is broken up into two groups:
106
+ *
107
+ * **Content Facing APIs** - For Application Developers putting Views into a Platform Window, who care about Context. These are APIs that send out and receive the Context data that flows between applications. Think of this as the Water in the Interop Pipes.
108
+ *
109
+ * **Context Grouping APIs** - For Platform Developers, to add and remove Views to and from Context Groups. These APIs are utilized under-the-hood in Platforms, so they don't need to be used to participate in Interop. These are the APIs that decide which entities the context data flows between. Think of these as the valves or pipes that control the flow of Context Data for Interop.
110
+ *
111
+ * ---
112
+ *
113
+ * All APIs are available at the `fin.me.interop` namespace.
114
+ *
115
+ * ---
116
+ *
117
+ * **You only need 2 things to participate in Interop Context Grouping:**
118
+ * * A Context Handler for incoming context: {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
119
+ * * Call setContext on your context group when you want to share context with other group members: {@link InteropClient#setContext setContext(context)}
120
+ *
121
+ * ---
122
+ *
123
+ * ##### Constructor
124
+ * Returned by {@link Interop.connectSync Interop.connectSync}.
125
+ *
126
+ * ---
127
+ *
128
+ * ##### Interop methods intended for Views
129
+ *
130
+ *
131
+ * **Context Groups API**
132
+ * * {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
133
+ * * {@link InteropClient#setContext setContext(context)}
134
+ * * {@link InteropClient#getCurrentContext getCurrentContext(contextType?)}
135
+ * * {@link InteropClient#joinSessionContextGroup joinSessionContextGroup(sessionContextGroupId)}
136
+ *
137
+ *
138
+ * **Intents API**
139
+ * * {@link InteropClient#fireIntent fireIntent(intent)}
140
+ * * {@link InteropClient#registerIntentHandler registerIntentHandler(intentHandler, intentName)}
141
+ * * {@link InteropClient#getInfoForIntent getInfoForIntent(infoForIntentOptions)}
142
+ * * {@link InteropClient#getInfoForIntentsByContext getInfoForIntentsByContext(context)}
143
+ * * {@link InteropClient#fireIntentForContext fireIntentForContext(contextForIntent)}
144
+ *
145
+ * ##### Interop methods intended for Windows
146
+ * * {@link InteropClient#getContextGroups getContextGroups()}
147
+ * * {@link InteropClient#joinContextGroup joinContextGroup(contextGroupId, target?)}
148
+ * * {@link InteropClient#removeFromContextGroup removeFromContextGroup(target?)}
149
+ * * {@link InteropClient#getInfoForContextGroup getInfoForContextGroup(contextGroupId)}
150
+ * * {@link InteropClient#getAllClientsInContextGroup getAllClientsInContextGroup(contextGroupId)}
151
+ *
152
+
153
+ *
154
+ * @hideconstructor
155
+ * @class
156
+ */
157
+ class InteropClient extends base_1.Base {
158
+ constructor(wire, name, interopConfig) {
159
+ super(wire);
160
+ _clientPromise.set(this, void 0);
161
+ _sessionContextGroups.set(this, void 0);
162
+ __classPrivateFieldSet(this, _sessionContextGroups, new Map());
163
+ __classPrivateFieldSet(this, _clientPromise, this.wire.environment.whenReady().then(() => {
164
+ return this.fin.InterApplicationBus.Channel.connect(`interop-broker-${name}`, {
165
+ payload: interopConfig
166
+ });
167
+ }));
168
+ }
169
+ /*
170
+ Client APIs
171
+ */
172
+ /**
173
+ * Sets a context for the context group of the current entity.
174
+ * @param { Context } context - New context to set.
175
+ * @return { Promise<void> }
176
+ * @tutorial interop.setContext
177
+ */
178
+ async setContext(context) {
179
+ this.wire.sendAction('interop-client-set-context').catch((e) => {
180
+ // don't expose, analytics-only call
181
+ });
182
+ const client = await __classPrivateFieldGet(this, _clientPromise);
183
+ return client.dispatch('setContext', { context });
184
+ }
185
+ /**
186
+ * Add a context handler for incoming context. If an entity is part of a context group, and then sets its context handler, it will receive all of its declared contexts.
187
+ * @param { ContextHandler } handler - Handler for incoming context.
188
+ * @param { string } [contextType] - The type of context you wish to handle.
189
+ * @return { Promise<Subscription> }
190
+ * @tutorial interop.addContextHandler
191
+ */
192
+ async addContextHandler(handler, contextType) {
193
+ this.wire.sendAction('interop-client-add-context-handler').catch((e) => {
194
+ // don't expose, analytics-only call
195
+ });
196
+ const client = await __classPrivateFieldGet(this, _clientPromise);
197
+ let handlerId;
198
+ if (contextType) {
199
+ handlerId = `invokeContextHandler-${contextType}-${utils_1.generateId()}`;
200
+ console.warn(`Warning: By providing a contextType (${contextType}), you are using the experimental addContextHandler. To avoid issues, make sure you are adding your context handlers at the top level in your application.`);
201
+ }
202
+ else {
203
+ handlerId = 'invokeContextHandler';
204
+ }
205
+ const wrappedHandler = utils_1.wrapContextHandler(handler, handlerId);
206
+ client.register(handlerId, wrappedHandler);
207
+ await client.dispatch('contextHandlerRegistered', { handlerId, contextType });
208
+ return {
209
+ unsubscribe: async () => {
210
+ client.remove(handlerId);
211
+ await client.dispatch('removeContextHandler', { handlerId });
212
+ }
213
+ };
214
+ }
215
+ /*
216
+ Platform Window APIs
217
+ */
218
+ /**
219
+ * Returns the Interop-Broker-defined context groups available for an entity to join.
220
+ * Used by Platform Windows.
221
+ * @return { Promise<ContextGroupInfo[]>}
222
+ * @tutorial interop.getContextGroups
223
+ */
224
+ async getContextGroups() {
225
+ this.wire.sendAction('interop-client-get-context-groups').catch((e) => {
226
+ // don't expose, analytics-only call
227
+ });
228
+ const client = await __classPrivateFieldGet(this, _clientPromise);
229
+ return client.dispatch('getContextGroups');
230
+ }
231
+ /**
232
+ * Join all Interop Clients at the given identity to context group `contextGroupId`.
233
+ * If no target is specified, it adds the sender to the context group.
234
+ * Because multiple Channel connections/Interop Clients can potentially exist at a `uuid`/`name` combo, we currently join all Channel connections/Interop Clients at the given identity to the context group.
235
+ * If an `endpointId` is provided (which is unlikely, unless the call is coming from an external adapter), then we only join that single connection to the context group.
236
+ * For all intents and purposes, there will only be 1 connection present in Platform and Browser implmentations, so this point is more-or-less moot.
237
+ * Used by Platform Windows.
238
+ * @param { string } contextGroupId - Id of the context group.
239
+ * @param { Identity } [target] - Identity of the entity you wish to join to a context group.
240
+ * @return { Promise<void>}
241
+ * @tutorial interop.joinContextGroup
242
+ */
243
+ async joinContextGroup(contextGroupId, target) {
244
+ this.wire.sendAction('interop-client-join-context-group').catch((e) => {
245
+ // don't expose, analytics-only call
246
+ });
247
+ const client = await __classPrivateFieldGet(this, _clientPromise);
248
+ if (!contextGroupId) {
249
+ throw new Error('No contextGroupId specified for joinContextGroup.');
250
+ }
251
+ return client.dispatch('joinContextGroup', { contextGroupId, target });
252
+ }
253
+ /**
254
+ * Removes the specified target from a context group.
255
+ * If no target is specified, it removes the sender from their context group.
256
+ * Used by Platform Windows.
257
+ * @param { Identity } [target] - Identity of the entity you wish to join to a context group.
258
+ * @return { Promise<void>}
259
+ * @tutorial interop.removeFromContextGroup
260
+ */
261
+ async removeFromContextGroup(target) {
262
+ this.wire.sendAction('interop-client-remove-from-context-group').catch((e) => {
263
+ // don't expose, analytics-only call
264
+ });
265
+ const client = await __classPrivateFieldGet(this, _clientPromise);
266
+ return client.dispatch('removeFromContextGroup', { target });
267
+ }
268
+ /**
269
+ * Gets all clients for a context group.
270
+ * Used by Platform Windows.
271
+ * @param { string } contextGroupId - The id of context group you wish to get clients for.
272
+ * @return { Promise<ClientIdentity[]>}
273
+ * @tutorial interop.getAllClientsInContextGroup
274
+ */
275
+ async getAllClientsInContextGroup(contextGroupId) {
276
+ this.wire.sendAction('interop-client-get-all-clients-in-context-group').catch((e) => {
277
+ // don't expose, analytics-only call
278
+ });
279
+ const client = await __classPrivateFieldGet(this, _clientPromise);
280
+ if (!contextGroupId) {
281
+ throw new Error('No contextGroupId specified for getAllClientsInContextGroup.');
282
+ }
283
+ return client.dispatch('getAllClientsInContextGroup', { contextGroupId });
284
+ }
285
+ /**
286
+ * Gets display info for a context group
287
+ * Used by Platform Windows.
288
+ * @param { string } contextGroupId - The id of context group you wish to get display info for.
289
+ * @return { Promise<ContextGroupInfo>}
290
+ * @tutorial interop.getInfoForContextGroup
291
+ */
292
+ async getInfoForContextGroup(contextGroupId) {
293
+ this.wire.sendAction('interop-client-get-info-for-context-group').catch((e) => {
294
+ // don't expose, analytics-only call
295
+ });
296
+ const client = await __classPrivateFieldGet(this, _clientPromise);
297
+ if (!contextGroupId) {
298
+ throw new Error('No contextGroupId specified for getInfoForContextGroup.');
299
+ }
300
+ return client.dispatch('getInfoForContextGroup', { contextGroupId });
301
+ }
302
+ /**
303
+ * Sends an intent to the Interop Broker to resolve.
304
+ * @param { Intent } intent - The combination of an action and a context that is passed to an application for resolution.
305
+ * @return { Promise<unknown>}
306
+ * @tutorial interop.fireIntent
307
+ * @experimental
308
+ */
309
+ async fireIntent(intent) {
310
+ this.wire.sendAction('interop-client-fire-intent').catch((e) => {
311
+ // don't expose, this is only for api analytics purposes
312
+ });
313
+ const client = await __classPrivateFieldGet(this, _clientPromise);
314
+ return client.dispatch('fireIntent', intent);
315
+ }
316
+ /**
317
+ * Adds an intent handler for incoming intents. The last intent sent of the name subscribed to will be received.
318
+ * @param { IntentHandler } handler - Registered function meant to handle a specific intent type.
319
+ * @param { string } intentName - The name of an intent.
320
+ * @return { Promise<Subscription> }
321
+ * @tutorial interop.registerIntentHandler
322
+ * @experimental
323
+ */
324
+ async registerIntentHandler(handler, intentName) {
325
+ this.wire.sendAction('interop-client-register-intent-handler').catch((e) => {
326
+ // don't expose, this is only for api analytics purposes
327
+ });
328
+ const client = await __classPrivateFieldGet(this, _clientPromise);
329
+ const handlerId = `intent-handler-${intentName}`;
330
+ const wrappedHandler = this.wrapIntentHandler(handler, handlerId);
331
+ try {
332
+ await client.register(handlerId, wrappedHandler);
333
+ await client.dispatch('intentHandlerRegistered', { handlerId });
334
+ }
335
+ catch (error) {
336
+ throw new Error('Unable to register intent handler');
337
+ }
338
+ return {
339
+ unsubscribe: async () => {
340
+ client.remove(handlerId);
341
+ }
342
+ };
343
+ }
344
+ /**
345
+ * Gets the last context of the Context Group currently subscribed to. It takes an optional Context Type and returns the
346
+ * last context of that type.
347
+ * @param { string } [contextType]
348
+ * @return { Promise<Context> }
349
+ * @tutorial interop.getCurrentContext
350
+ * @experimental
351
+ */
352
+ async getCurrentContext(contextType) {
353
+ this.wire.sendAction('interop-client-get-current-context').catch((e) => {
354
+ // don't expose, analytics-only call
355
+ });
356
+ const client = await __classPrivateFieldGet(this, _clientPromise);
357
+ return client.dispatch('getCurrentContext', { contextType });
358
+ }
359
+ /**
360
+ * Get information for a particular Intent from the Interop Broker.
361
+ * @param { InfoForIntentOptions } options
362
+ * @return { Promise<unknown> }
363
+ * @tutorial interop.getInfoForIntent
364
+ * @experimental
365
+ */
366
+ async getInfoForIntent(options) {
367
+ this.wire.sendAction('interop-client-get-info-for-intent').catch((e) => {
368
+ // don't expose, analytics-only call
369
+ });
370
+ const client = await __classPrivateFieldGet(this, _clientPromise);
371
+ return client.dispatch('getInfoForIntent', options);
372
+ }
373
+ /**
374
+ * Get information from the Interop Broker on all Intents that are meant to handle a particular context.
375
+ * @param { Context } context
376
+ * @return { Promise<unknown> }
377
+ * @tutorial interop.getInfoForIntentsByContext
378
+ * @experimental
379
+ */
380
+ async getInfoForIntentsByContext(context) {
381
+ this.wire.sendAction('interop-client-get-info-for-intents-by-context').catch((e) => {
382
+ // don't expose, analytics-only call
383
+ });
384
+ const client = await __classPrivateFieldGet(this, _clientPromise);
385
+ return client.dispatch('getInfoForIntentsByContext', context);
386
+ }
387
+ /**
388
+ * Sends a Context that will be resolved to an Intent by the Interop Broker.
389
+ * This context accepts a metadata property.
390
+ * @param { ContextForIntent } context
391
+ * @return { Promise<unknown> }
392
+ * @tutorial interop.fireIntentForContext
393
+ * @experimental
394
+ */
395
+ async fireIntentForContext(context) {
396
+ this.wire.sendAction('interop-client-fire-intent-for-context').catch((e) => {
397
+ // don't expose, analytics-only call
398
+ });
399
+ const client = await __classPrivateFieldGet(this, _clientPromise);
400
+ return client.dispatch('fireIntentForContext', context);
401
+ }
402
+ /**
403
+ * Join the current entity to session context group `sessionContextGroupId` and return a sessionContextGroup instance.
404
+ * If the sessionContextGroup doesn't exist, one will get created.
405
+ * Session Context Groups do not persist between runs and aren't present on snapshots.
406
+ * @param { string } sessionContextGroupId - Id of the context group.
407
+ * @return { Promise<SessionContextGroup>}
408
+ * @tutorial interop.joinSessionContextGroup
409
+ * @experimental
410
+ */
411
+ async joinSessionContextGroup(sessionContextGroupId) {
412
+ try {
413
+ const currentSessionContextGroup = __classPrivateFieldGet(this, _sessionContextGroups).get(sessionContextGroupId);
414
+ if (currentSessionContextGroup) {
415
+ return currentSessionContextGroup.getUserInstance();
416
+ }
417
+ const client = await __classPrivateFieldGet(this, _clientPromise);
418
+ const { hasConflict } = await client.dispatch('sessionContextGroup:createIfNeeded', {
419
+ sessionContextGroupId
420
+ });
421
+ if (hasConflict) {
422
+ console.warn(`A (non-session) context group with the name "${sessionContextGroupId}" already exists. If you are trying to join a Context Group, call joinContextGroup instead.`);
423
+ }
424
+ const newSessionContextGroup = new SessionContextGroupClient_1.default(this.wire, __classPrivateFieldGet(this, _clientPromise), sessionContextGroupId);
425
+ __classPrivateFieldGet(this, _sessionContextGroups).set(sessionContextGroupId, newSessionContextGroup);
426
+ return newSessionContextGroup.getUserInstance();
427
+ }
428
+ catch (error) {
429
+ console.error(`Error thrown trying to create Session Context Group with id "${sessionContextGroupId}": ${error}`);
430
+ throw error;
431
+ }
432
+ }
433
+ /*
434
+ Internal Utilties
435
+ */
436
+ // eslint-disable-next-line class-methods-use-this
437
+ wrapIntentHandler(handler, handlerId) {
438
+ return async (intent) => {
439
+ try {
440
+ await handler(intent);
441
+ }
442
+ catch (error) {
443
+ console.error(`Error thrown by handler ${handlerId}: ${error}`);
444
+ throw error;
445
+ }
446
+ };
447
+ }
448
+ }
449
+ exports.InteropClient = InteropClient;
450
+ _clientPromise = new WeakMap(), _sessionContextGroups = new WeakMap();
@@ -0,0 +1,26 @@
1
+ import type { ChannelProvider } from '../interappbus/channel/provider';
2
+ export default class SessionContextGroupBroker {
3
+ id: string;
4
+ private contextGroupMap;
5
+ private provider;
6
+ private clients;
7
+ private lastContext;
8
+ constructor(provider: ChannelProvider, id: string);
9
+ registerListeners(): void;
10
+ getCurrentContext(payload: {
11
+ type?: string;
12
+ }): OpenFin.Context | undefined;
13
+ setContext(payload: {
14
+ context: OpenFin.Context;
15
+ }, clientIdentity: OpenFin.ClientIdentity): void;
16
+ private getClientState;
17
+ handlerAdded(payload: {
18
+ handlerId: string;
19
+ contextType?: string;
20
+ }, clientIdentity: OpenFin.ClientIdentity): void;
21
+ handlerRemoved(payload: {
22
+ handlerId: string;
23
+ }, clientIdentity: OpenFin.ClientIdentity): void;
24
+ registerNewClient(clientIdentity: OpenFin.ClientIdentity): void;
25
+ onDisconnection(clientIdentity: OpenFin.ClientIdentity): void;
26
+ }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const _1 = require(".");
4
+ class SessionContextGroupBroker {
5
+ constructor(provider, id) {
6
+ this.provider = provider;
7
+ this.id = id;
8
+ this.lastContext = undefined;
9
+ this.contextGroupMap = new Map();
10
+ this.clients = new Map();
11
+ this.registerListeners();
12
+ }
13
+ registerListeners() {
14
+ this.provider.register(`sessionContextGroup:getContext-${this.id}`, this.getCurrentContext.bind(this));
15
+ this.provider.register(`sessionContextGroup:setContext-${this.id}`, this.setContext.bind(this));
16
+ this.provider.register(`sessionContextGroup:handlerAdded-${this.id}`, this.handlerAdded.bind(this));
17
+ this.provider.register(`sessionContextGroup:handlerRemoved-${this.id}`, this.handlerRemoved.bind(this));
18
+ }
19
+ getCurrentContext(payload) {
20
+ return payload.type ? this.contextGroupMap.get(payload.type) : this.lastContext;
21
+ }
22
+ setContext(payload, clientIdentity) {
23
+ const { context } = payload;
24
+ const contextIntegrityCheckResult = _1.InteropBroker.checkContextIntegrity(context);
25
+ if (contextIntegrityCheckResult.isValid === false) {
26
+ throw new Error(`Failed to set Context - bad Context. Reason: ${contextIntegrityCheckResult.reason}. Context: ${JSON.stringify(context)}`);
27
+ }
28
+ const clientState = this.getClientState(clientIdentity);
29
+ if (!clientState) {
30
+ // This shouldn't get hit.
31
+ throw new Error(`Client with Identity: ${clientIdentity.uuid} ${clientIdentity.name} not in Session Client State Map`);
32
+ }
33
+ // set the context
34
+ this.contextGroupMap.set(context.type, context);
35
+ this.lastContext = context;
36
+ const clientSubscriptionStates = Array.from(this.clients.values());
37
+ clientSubscriptionStates.forEach((client) => {
38
+ var _a;
39
+ // eslint-disable-next-line no-unused-expressions
40
+ (_a = client.contextHandlers.get(context.type)) === null || _a === void 0 ? void 0 : _a.forEach((handlerId) => {
41
+ this.provider.dispatch(client.clientIdentity, handlerId, context);
42
+ });
43
+ if (client.globalHandler) {
44
+ this.provider.dispatch(client.clientIdentity, client.globalHandler, context);
45
+ }
46
+ });
47
+ }
48
+ getClientState(id) {
49
+ return this.clients.get(id.endpointId);
50
+ }
51
+ handlerAdded(payload, clientIdentity) {
52
+ const { handlerId, contextType } = payload;
53
+ const clientSubscriptionState = this.getClientState(clientIdentity);
54
+ if (!clientSubscriptionState) {
55
+ throw new Error(`Client with Identity: ${clientIdentity.uuid} ${clientIdentity.name} not in Client State Map`);
56
+ }
57
+ if (contextType) {
58
+ const currentHandlerList = clientSubscriptionState.contextHandlers.get(contextType) || [];
59
+ clientSubscriptionState.contextHandlers.set(contextType, [...currentHandlerList, handlerId]);
60
+ const currentContext = this.contextGroupMap.get(contextType);
61
+ if (currentContext) {
62
+ this.provider.dispatch(clientIdentity, handlerId, currentContext);
63
+ }
64
+ }
65
+ else {
66
+ clientSubscriptionState.globalHandler = handlerId;
67
+ [...this.contextGroupMap.keys()].forEach((currentContextType) => {
68
+ const currentContext = this.contextGroupMap.get(currentContextType);
69
+ if (currentContext) {
70
+ this.provider.dispatch(clientIdentity, handlerId, currentContext);
71
+ }
72
+ });
73
+ }
74
+ }
75
+ handlerRemoved(payload, clientIdentity) {
76
+ const { handlerId } = payload;
77
+ const client = this.clients.get(clientIdentity.endpointId);
78
+ if (client) {
79
+ Array.from(client.contextHandlers).forEach(([, handlers]) => {
80
+ const index = handlers.indexOf(handlerId);
81
+ if (index > -1) {
82
+ handlers.splice(index, 1);
83
+ }
84
+ });
85
+ if (client.globalHandler === handlerId) {
86
+ client.globalHandler = undefined;
87
+ }
88
+ }
89
+ else {
90
+ console.warn(`Trying to remove a handler from a client that isn't mapped. handlerId: ${handlerId}. clientIdentity: ${clientIdentity}`);
91
+ }
92
+ }
93
+ registerNewClient(clientIdentity) {
94
+ if (!this.clients.has(clientIdentity.endpointId)) {
95
+ const clientSubscriptionState = {
96
+ contextHandlers: new Map(),
97
+ clientIdentity,
98
+ globalHandler: undefined
99
+ };
100
+ this.clients.set(clientIdentity.endpointId, clientSubscriptionState);
101
+ }
102
+ }
103
+ onDisconnection(clientIdentity) {
104
+ this.clients.delete(clientIdentity.endpointId);
105
+ }
106
+ }
107
+ exports.default = SessionContextGroupBroker;
@@ -0,0 +1,20 @@
1
+ import Transport from '../../transport/transport';
2
+ import { Base } from '../base';
3
+ export default class SessionContextGroupClient extends Base {
4
+ #private;
5
+ id: string;
6
+ constructor(wire: Transport, client: Promise<OpenFin.ChannelClient>, id: string);
7
+ /**
8
+ * Sets a context for the session context group.
9
+ * @param { Context } context - New context to set.
10
+ * @return { Promise<void> }
11
+ * @tutorial interop.setContext
12
+ */
13
+ setContext(context: OpenFin.Context): Promise<void>;
14
+ getCurrentContext(type?: string): Promise<OpenFin.Context>;
15
+ addContextHandler(contextHandler: OpenFin.ContextHandler, contextType?: string): Promise<{
16
+ unsubscribe: () => void;
17
+ }>;
18
+ private createUnsubscribeCb;
19
+ getUserInstance(): OpenFin.SessionContextGroup;
20
+ }