@openfin/fdc3-api 36.78.10 → 36.78.12

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.
package/out/fdc3-api.js CHANGED
@@ -10,279 +10,279 @@ var base = {};
10
10
 
11
11
  var promises = {};
12
12
 
13
- Object.defineProperty(promises, "__esModule", { value: true });
14
- promises.promiseMapSerial = promises.serial = promises.promiseMap = promises.promisify = void 0;
15
- function promisify(func) {
16
- return (...args) => new Promise((resolve, reject) => {
17
- func(...args, (err, val) => (err ? reject(err) : resolve(val)));
18
- });
19
- }
20
- promises.promisify = promisify;
21
- async function promiseMap(arr, asyncF) {
22
- return Promise.all(arr.map(asyncF));
23
- }
24
- promises.promiseMap = promiseMap;
25
- async function serial(arr) {
26
- const ret = [];
27
- for (const func of arr) {
28
- // eslint-disable-next-line no-await-in-loop
29
- const next = await func();
30
- ret.push(next);
31
- }
32
- return ret;
33
- }
34
- promises.serial = serial;
35
- async function promiseMapSerial(arr, func) {
36
- return serial(arr.map((value, index, array) => () => func(value, index, array)));
37
- }
13
+ Object.defineProperty(promises, "__esModule", { value: true });
14
+ promises.promiseMapSerial = promises.serial = promises.promiseMap = promises.promisify = void 0;
15
+ function promisify(func) {
16
+ return (...args) => new Promise((resolve, reject) => {
17
+ func(...args, (err, val) => (err ? reject(err) : resolve(val)));
18
+ });
19
+ }
20
+ promises.promisify = promisify;
21
+ async function promiseMap(arr, asyncF) {
22
+ return Promise.all(arr.map(asyncF));
23
+ }
24
+ promises.promiseMap = promiseMap;
25
+ async function serial(arr) {
26
+ const ret = [];
27
+ for (const func of arr) {
28
+ // eslint-disable-next-line no-await-in-loop
29
+ const next = await func();
30
+ ret.push(next);
31
+ }
32
+ return ret;
33
+ }
34
+ promises.serial = serial;
35
+ async function promiseMapSerial(arr, func) {
36
+ return serial(arr.map((value, index, array) => () => func(value, index, array)));
37
+ }
38
38
  promises.promiseMapSerial = promiseMapSerial;
39
39
 
40
- var __classPrivateFieldSet$2 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
41
- if (kind === "m") throw new TypeError("Private method is not writable");
42
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
43
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
44
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
45
- };
46
- var __classPrivateFieldGet$2 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
47
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
48
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
49
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
50
- };
51
- var _EmitterBase_emitterAccessor;
52
- Object.defineProperty(base, "__esModule", { value: true });
53
- base.Reply = base.EmitterBase = base.Base = void 0;
54
- const promises_1 = promises;
55
- class Base {
56
- /**
57
- * @internal
58
- */
59
- constructor(wire) {
60
- this.isNodeEnvironment = () => {
61
- return this.wire.environment.constructor.name === 'NodeEnvironment';
62
- };
63
- this.isOpenFinEnvironment = () => {
64
- return this.wire.environment.constructor.name === 'OpenFinEnvironment';
65
- };
66
- this.isBrowserEnvironment = () => {
67
- return this.wire.environment.constructor.name === 'BrowserEnvironment';
68
- };
69
- this.wire = wire;
70
- }
71
- get fin() {
72
- return this.wire.getFin();
73
- }
74
- /**
75
- * Provides access to the OpenFin representation of the current code context (usually a document
76
- * such as a {@link OpenFin.View} or {@link OpenFin.Window}), as well as to the current `Interop` context.
77
- *
78
- * Useful for debugging in the devtools console, where this will intelligently type itself based
79
- * on the context in which the devtools panel was opened.
80
- */
81
- get me() {
82
- return this.wire.me;
83
- }
84
- }
85
- base.Base = Base;
86
- /**
87
- * An entity that emits OpenFin events.
88
- *
89
- * @remarks Event-binding methods are asynchronous as they must cross process boundaries
90
- * and setup the listener in the browser process. When the `EventEmitter` receives an event from the browser process
91
- * and emits on the renderer, all of the functions attached to that specific event are called synchronously. Any values
92
- * returned by the called listeners are ignored and will be discarded. If the execution context of the window is destroyed
93
- * by page navigation or reload, any events that have been setup in that context will be destroyed.
94
- *
95
- * It is important to keep in mind that when an ordinary listener function is called, the standard `this` keyword is intentionally
96
- * set to reference the `EventEmitter` instance to which the listener is attached. It is possible to use ES6 Arrow Functions as
97
- * listeners, however, when doing so, the `this` keyword will no longer reference the `EventEmitter` instance.
98
- *
99
- * Events re-propagate from smaller/more-local scopes to larger/more-global scopes. For example, an event emitted on a specific
100
- * view will propagate to the window in which the view is embedded, and then to the application in which the window is running, and
101
- * finally to the OpenFin runtime itself at the "system" level. Re-propagated events are prefixed with the name of the scope in which
102
- * they originated - for example, a "shown" event emitted on a view will be re-propagated at the window level as "view-shown", and
103
- * then to the application as "window-view-shown", and finally at the system level as "application-window-view-shown".
104
- *
105
- * All event propagations are visible at the System level, regardless of source, so transitive re-propagations (e.g. from view to window
106
- * to application) are visible in their entirety at the system level. So, we can listen to the above event as "shown", "view-shown",
107
- * "window-view-shown", or "application-window-view-shown."
108
- */
109
- class EmitterBase extends Base {
110
- constructor(wire, topic, ...additionalAccessors) {
111
- super(wire);
112
- this.topic = topic;
113
- _EmitterBase_emitterAccessor.set(this, void 0);
114
- this.eventNames = () => (this.hasEmitter() ? this.getOrCreateEmitter().eventNames() : []);
115
- /**
116
- * @internal
117
- */
118
- this.emit = (eventType, payload, ...args) => {
119
- return this.hasEmitter() ? this.getOrCreateEmitter().emit(eventType, payload, ...args) : false;
120
- };
121
- this.hasEmitter = () => this.wire.eventAggregator.has(__classPrivateFieldGet$2(this, _EmitterBase_emitterAccessor, "f"));
122
- this.getOrCreateEmitter = () => this.wire.eventAggregator.getOrCreate(__classPrivateFieldGet$2(this, _EmitterBase_emitterAccessor, "f"));
123
- this.listeners = (type) => this.hasEmitter() ? this.getOrCreateEmitter().listeners(type) : [];
124
- this.listenerCount = (type) => this.hasEmitter() ? this.getOrCreateEmitter().listenerCount(type) : 0;
125
- this.registerEventListener = async (eventType, options = {}, applySubscription, undoSubscription) => {
126
- const runtimeEvent = {
127
- ...this.identity,
128
- timestamp: options.timestamp || Date.now(),
129
- topic: this.topic,
130
- type: eventType
131
- };
132
- const emitter = this.getOrCreateEmitter();
133
- // We apply the subscription and then undo if the async call fails to avoid
134
- // indeterminacy in subscription application order, which can break things elsewhere
135
- applySubscription(emitter);
136
- try {
137
- await this.wire.sendAction('subscribe-to-desktop-event', runtimeEvent);
138
- }
139
- catch (e) {
140
- undoSubscription(emitter);
141
- this.deleteEmitterIfNothingRegistered(emitter);
142
- throw e;
143
- }
144
- };
145
- this.deregisterEventListener = async (eventType, options = {}) => {
146
- if (this.hasEmitter()) {
147
- const runtimeEvent = {
148
- ...this.identity,
149
- timestamp: options.timestamp || Date.now(),
150
- topic: this.topic,
151
- type: eventType
152
- };
153
- await this.wire.sendAction('unsubscribe-to-desktop-event', runtimeEvent).catch(() => null);
154
- const emitter = this.getOrCreateEmitter();
155
- return emitter;
156
- }
157
- // This will only be reached if unsubscribe from event that does not exist but do not want to error here
158
- return Promise.resolve();
159
- };
160
- __classPrivateFieldSet$2(this, _EmitterBase_emitterAccessor, [topic, ...additionalAccessors], "f");
161
- this.listeners = (event) => this.hasEmitter() ? this.getOrCreateEmitter().listeners(event) : [];
162
- }
163
- /**
164
- * Adds a listener to the end of the listeners array for the specified event.
165
- *
166
- * @remarks Event payloads are documented in the {@link OpenFin.Events} namespace.
167
- */
168
- async on(eventType, listener, options) {
169
- await this.registerEventListener(eventType, options, (emitter) => {
170
- emitter.on(eventType, listener);
171
- }, (emitter) => {
172
- emitter.removeListener(eventType, listener);
173
- });
174
- return this;
175
- }
176
- /**
177
- * Adds a listener to the end of the listeners array for the specified event.
178
- */
179
- async addListener(eventType, listener, options) {
180
- return this.on(eventType, listener, options);
181
- }
182
- /**
183
- * Adds a one time listener for the event. The listener is invoked only the first time the event is fired, after which it is removed.
184
- *
185
- * @remarks Event payloads are documented in the {@link OpenFin.Events} namespace.
186
- */
187
- async once(eventType, listener, options) {
188
- const deregister = () => this.deregisterEventListener(eventType);
189
- await this.registerEventListener(eventType, options, (emitter) => {
190
- emitter.once(eventType, deregister);
191
- emitter.once(eventType, listener);
192
- }, (emitter) => {
193
- emitter.removeListener(eventType, deregister);
194
- emitter.removeListener(eventType, listener);
195
- });
196
- return this;
197
- }
198
- /**
199
- * Adds a listener to the beginning of the listeners array for the specified event.
200
- *
201
- * @remarks Event payloads are documented in the {@link OpenFin.Events} namespace.
202
- */
203
- async prependListener(eventType, listener, options) {
204
- await this.registerEventListener(eventType, options, (emitter) => {
205
- emitter.prependListener(eventType, listener);
206
- }, (emitter) => {
207
- emitter.removeListener(eventType, listener);
208
- });
209
- return this;
210
- }
211
- /**
212
- * Adds a one time listener for the event. The listener is invoked only the first time the event is fired,
213
- * after which it is removed. The listener is added to the beginning of the listeners array.
214
- *
215
- * @remarks Event payloads are documented in the {@link OpenFin.Events} namespace.
216
- */
217
- async prependOnceListener(eventType, listener, options) {
218
- const deregister = () => this.deregisterEventListener(eventType);
219
- await this.registerEventListener(eventType, options, (emitter) => {
220
- emitter.prependOnceListener(eventType, listener);
221
- emitter.once(eventType, deregister);
222
- }, (emitter) => {
223
- emitter.removeListener(eventType, listener);
224
- emitter.removeListener(eventType, deregister);
225
- });
226
- return this;
227
- }
228
- /**
229
- * Remove a listener from the listener array for the specified event.
230
- *
231
- * @remarks Caution: Calling this method changes the array indices in the listener array behind the listener.
232
- */
233
- async removeListener(eventType, listener, options) {
234
- const emitter = await this.deregisterEventListener(eventType, options);
235
- if (emitter) {
236
- emitter.removeListener(eventType, listener);
237
- this.deleteEmitterIfNothingRegistered(emitter);
238
- }
239
- return this;
240
- }
241
- async deregisterAllListeners(eventType) {
242
- const runtimeEvent = { ...this.identity, type: eventType, topic: this.topic };
243
- if (this.hasEmitter()) {
244
- const emitter = this.getOrCreateEmitter();
245
- const refCount = emitter.listenerCount(runtimeEvent.type);
246
- const unsubscribePromises = [];
247
- for (let i = 0; i < refCount; i++) {
248
- unsubscribePromises.push(this.wire.sendAction('unsubscribe-to-desktop-event', runtimeEvent).catch(() => null));
249
- }
250
- await Promise.all(unsubscribePromises);
251
- return emitter;
252
- }
253
- return undefined;
254
- }
255
- /**
256
- * Removes all listeners, or those of the specified event.
257
- *
258
- */
259
- async removeAllListeners(eventType) {
260
- const removeByEvent = async (event) => {
261
- const emitter = await this.deregisterAllListeners(event);
262
- if (emitter) {
263
- emitter.removeAllListeners(event);
264
- this.deleteEmitterIfNothingRegistered(emitter);
265
- }
266
- };
267
- if (eventType) {
268
- await removeByEvent(eventType);
269
- }
270
- else if (this.hasEmitter()) {
271
- const events = this.getOrCreateEmitter().eventNames();
272
- await (0, promises_1.promiseMap)(events, removeByEvent);
273
- }
274
- return this;
275
- }
276
- deleteEmitterIfNothingRegistered(emitter) {
277
- if (emitter.eventNames().length === 0) {
278
- this.wire.eventAggregator.delete(__classPrivateFieldGet$2(this, _EmitterBase_emitterAccessor, "f"));
279
- }
280
- }
281
- }
282
- base.EmitterBase = EmitterBase;
283
- _EmitterBase_emitterAccessor = new WeakMap();
284
- class Reply {
285
- }
40
+ var __classPrivateFieldSet$2 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
41
+ if (kind === "m") throw new TypeError("Private method is not writable");
42
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
43
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
44
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
45
+ };
46
+ var __classPrivateFieldGet$2 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
47
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
48
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
49
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
50
+ };
51
+ var _EmitterBase_emitterAccessor;
52
+ Object.defineProperty(base, "__esModule", { value: true });
53
+ base.Reply = base.EmitterBase = base.Base = void 0;
54
+ const promises_1 = promises;
55
+ class Base {
56
+ /**
57
+ * @internal
58
+ */
59
+ constructor(wire) {
60
+ this.isNodeEnvironment = () => {
61
+ return this.wire.environment.constructor.name === 'NodeEnvironment';
62
+ };
63
+ this.isOpenFinEnvironment = () => {
64
+ return this.wire.environment.constructor.name === 'OpenFinEnvironment';
65
+ };
66
+ this.isBrowserEnvironment = () => {
67
+ return this.wire.environment.constructor.name === 'BrowserEnvironment';
68
+ };
69
+ this.wire = wire;
70
+ }
71
+ get fin() {
72
+ return this.wire.getFin();
73
+ }
74
+ /**
75
+ * Provides access to the OpenFin representation of the current code context (usually a document
76
+ * such as a {@link OpenFin.View} or {@link OpenFin.Window}), as well as to the current `Interop` context.
77
+ *
78
+ * Useful for debugging in the devtools console, where this will intelligently type itself based
79
+ * on the context in which the devtools panel was opened.
80
+ */
81
+ get me() {
82
+ return this.wire.me;
83
+ }
84
+ }
85
+ base.Base = Base;
86
+ /**
87
+ * An entity that emits OpenFin events.
88
+ *
89
+ * @remarks Event-binding methods are asynchronous as they must cross process boundaries
90
+ * and setup the listener in the browser process. When the `EventEmitter` receives an event from the browser process
91
+ * and emits on the renderer, all of the functions attached to that specific event are called synchronously. Any values
92
+ * returned by the called listeners are ignored and will be discarded. If the execution context of the window is destroyed
93
+ * by page navigation or reload, any events that have been setup in that context will be destroyed.
94
+ *
95
+ * It is important to keep in mind that when an ordinary listener function is called, the standard `this` keyword is intentionally
96
+ * set to reference the `EventEmitter` instance to which the listener is attached. It is possible to use ES6 Arrow Functions as
97
+ * listeners, however, when doing so, the `this` keyword will no longer reference the `EventEmitter` instance.
98
+ *
99
+ * Events re-propagate from smaller/more-local scopes to larger/more-global scopes. For example, an event emitted on a specific
100
+ * view will propagate to the window in which the view is embedded, and then to the application in which the window is running, and
101
+ * finally to the OpenFin runtime itself at the "system" level. Re-propagated events are prefixed with the name of the scope in which
102
+ * they originated - for example, a "shown" event emitted on a view will be re-propagated at the window level as "view-shown", and
103
+ * then to the application as "window-view-shown", and finally at the system level as "application-window-view-shown".
104
+ *
105
+ * All event propagations are visible at the System level, regardless of source, so transitive re-propagations (e.g. from view to window
106
+ * to application) are visible in their entirety at the system level. So, we can listen to the above event as "shown", "view-shown",
107
+ * "window-view-shown", or "application-window-view-shown."
108
+ */
109
+ class EmitterBase extends Base {
110
+ constructor(wire, topic, ...additionalAccessors) {
111
+ super(wire);
112
+ this.topic = topic;
113
+ _EmitterBase_emitterAccessor.set(this, void 0);
114
+ this.eventNames = () => (this.hasEmitter() ? this.getOrCreateEmitter().eventNames() : []);
115
+ /**
116
+ * @internal
117
+ */
118
+ this.emit = (eventType, payload, ...args) => {
119
+ return this.hasEmitter() ? this.getOrCreateEmitter().emit(eventType, payload, ...args) : false;
120
+ };
121
+ this.hasEmitter = () => this.wire.eventAggregator.has(__classPrivateFieldGet$2(this, _EmitterBase_emitterAccessor, "f"));
122
+ this.getOrCreateEmitter = () => this.wire.eventAggregator.getOrCreate(__classPrivateFieldGet$2(this, _EmitterBase_emitterAccessor, "f"));
123
+ this.listeners = (type) => this.hasEmitter() ? this.getOrCreateEmitter().listeners(type) : [];
124
+ this.listenerCount = (type) => this.hasEmitter() ? this.getOrCreateEmitter().listenerCount(type) : 0;
125
+ this.registerEventListener = async (eventType, options = {}, applySubscription, undoSubscription) => {
126
+ const runtimeEvent = {
127
+ ...this.identity,
128
+ timestamp: options.timestamp || Date.now(),
129
+ topic: this.topic,
130
+ type: eventType
131
+ };
132
+ const emitter = this.getOrCreateEmitter();
133
+ // We apply the subscription and then undo if the async call fails to avoid
134
+ // indeterminacy in subscription application order, which can break things elsewhere
135
+ applySubscription(emitter);
136
+ try {
137
+ await this.wire.sendAction('subscribe-to-desktop-event', runtimeEvent);
138
+ }
139
+ catch (e) {
140
+ undoSubscription(emitter);
141
+ this.deleteEmitterIfNothingRegistered(emitter);
142
+ throw e;
143
+ }
144
+ };
145
+ this.deregisterEventListener = async (eventType, options = {}) => {
146
+ if (this.hasEmitter()) {
147
+ const runtimeEvent = {
148
+ ...this.identity,
149
+ timestamp: options.timestamp || Date.now(),
150
+ topic: this.topic,
151
+ type: eventType
152
+ };
153
+ await this.wire.sendAction('unsubscribe-to-desktop-event', runtimeEvent).catch(() => null);
154
+ const emitter = this.getOrCreateEmitter();
155
+ return emitter;
156
+ }
157
+ // This will only be reached if unsubscribe from event that does not exist but do not want to error here
158
+ return Promise.resolve();
159
+ };
160
+ __classPrivateFieldSet$2(this, _EmitterBase_emitterAccessor, [topic, ...additionalAccessors], "f");
161
+ this.listeners = (event) => this.hasEmitter() ? this.getOrCreateEmitter().listeners(event) : [];
162
+ }
163
+ /**
164
+ * Adds a listener to the end of the listeners array for the specified event.
165
+ *
166
+ * @remarks Event payloads are documented in the {@link OpenFin.Events} namespace.
167
+ */
168
+ async on(eventType, listener, options) {
169
+ await this.registerEventListener(eventType, options, (emitter) => {
170
+ emitter.on(eventType, listener);
171
+ }, (emitter) => {
172
+ emitter.removeListener(eventType, listener);
173
+ });
174
+ return this;
175
+ }
176
+ /**
177
+ * Adds a listener to the end of the listeners array for the specified event.
178
+ */
179
+ async addListener(eventType, listener, options) {
180
+ return this.on(eventType, listener, options);
181
+ }
182
+ /**
183
+ * Adds a one time listener for the event. The listener is invoked only the first time the event is fired, after which it is removed.
184
+ *
185
+ * @remarks Event payloads are documented in the {@link OpenFin.Events} namespace.
186
+ */
187
+ async once(eventType, listener, options) {
188
+ const deregister = () => this.deregisterEventListener(eventType);
189
+ await this.registerEventListener(eventType, options, (emitter) => {
190
+ emitter.once(eventType, deregister);
191
+ emitter.once(eventType, listener);
192
+ }, (emitter) => {
193
+ emitter.removeListener(eventType, deregister);
194
+ emitter.removeListener(eventType, listener);
195
+ });
196
+ return this;
197
+ }
198
+ /**
199
+ * Adds a listener to the beginning of the listeners array for the specified event.
200
+ *
201
+ * @remarks Event payloads are documented in the {@link OpenFin.Events} namespace.
202
+ */
203
+ async prependListener(eventType, listener, options) {
204
+ await this.registerEventListener(eventType, options, (emitter) => {
205
+ emitter.prependListener(eventType, listener);
206
+ }, (emitter) => {
207
+ emitter.removeListener(eventType, listener);
208
+ });
209
+ return this;
210
+ }
211
+ /**
212
+ * Adds a one time listener for the event. The listener is invoked only the first time the event is fired,
213
+ * after which it is removed. The listener is added to the beginning of the listeners array.
214
+ *
215
+ * @remarks Event payloads are documented in the {@link OpenFin.Events} namespace.
216
+ */
217
+ async prependOnceListener(eventType, listener, options) {
218
+ const deregister = () => this.deregisterEventListener(eventType);
219
+ await this.registerEventListener(eventType, options, (emitter) => {
220
+ emitter.prependOnceListener(eventType, listener);
221
+ emitter.once(eventType, deregister);
222
+ }, (emitter) => {
223
+ emitter.removeListener(eventType, listener);
224
+ emitter.removeListener(eventType, deregister);
225
+ });
226
+ return this;
227
+ }
228
+ /**
229
+ * Remove a listener from the listener array for the specified event.
230
+ *
231
+ * @remarks Caution: Calling this method changes the array indices in the listener array behind the listener.
232
+ */
233
+ async removeListener(eventType, listener, options) {
234
+ const emitter = await this.deregisterEventListener(eventType, options);
235
+ if (emitter) {
236
+ emitter.removeListener(eventType, listener);
237
+ this.deleteEmitterIfNothingRegistered(emitter);
238
+ }
239
+ return this;
240
+ }
241
+ async deregisterAllListeners(eventType) {
242
+ const runtimeEvent = { ...this.identity, type: eventType, topic: this.topic };
243
+ if (this.hasEmitter()) {
244
+ const emitter = this.getOrCreateEmitter();
245
+ const refCount = emitter.listenerCount(runtimeEvent.type);
246
+ const unsubscribePromises = [];
247
+ for (let i = 0; i < refCount; i++) {
248
+ unsubscribePromises.push(this.wire.sendAction('unsubscribe-to-desktop-event', runtimeEvent).catch(() => null));
249
+ }
250
+ await Promise.all(unsubscribePromises);
251
+ return emitter;
252
+ }
253
+ return undefined;
254
+ }
255
+ /**
256
+ * Removes all listeners, or those of the specified event.
257
+ *
258
+ */
259
+ async removeAllListeners(eventType) {
260
+ const removeByEvent = async (event) => {
261
+ const emitter = await this.deregisterAllListeners(event);
262
+ if (emitter) {
263
+ emitter.removeAllListeners(event);
264
+ this.deleteEmitterIfNothingRegistered(emitter);
265
+ }
266
+ };
267
+ if (eventType) {
268
+ await removeByEvent(eventType);
269
+ }
270
+ else if (this.hasEmitter()) {
271
+ const events = this.getOrCreateEmitter().eventNames();
272
+ await (0, promises_1.promiseMap)(events, removeByEvent);
273
+ }
274
+ return this;
275
+ }
276
+ deleteEmitterIfNothingRegistered(emitter) {
277
+ if (emitter.eventNames().length === 0) {
278
+ this.wire.eventAggregator.delete(__classPrivateFieldGet$2(this, _EmitterBase_emitterAccessor, "f"));
279
+ }
280
+ }
281
+ }
282
+ base.EmitterBase = EmitterBase;
283
+ _EmitterBase_emitterAccessor = new WeakMap();
284
+ class Reply {
285
+ }
286
286
  base.Reply = Reply;
287
287
 
288
288
  var utils$2 = {};
@@ -290,394 +290,394 @@ var utils$2 = {};
290
290
  var utils$1 = {};
291
291
 
292
292
  (function (exports) {
293
- Object.defineProperty(exports, "__esModule", { value: true });
294
- exports.wrapIntentHandler = exports.BROKER_ERRORS = exports.generateOverrideWarning = exports.generateOverrideError = exports.wrapContextHandler = exports.wrapInTryCatch = exports.generateId = void 0;
295
- const generateId = () => `${Math.random()}${Date.now()}`;
296
- exports.generateId = generateId;
297
- const wrapInTryCatch = (f, prefix) => (...args) => {
298
- try {
299
- return f(...args);
300
- }
301
- catch (e) {
302
- throw new Error((prefix || '') + e);
303
- }
304
- };
305
- exports.wrapInTryCatch = wrapInTryCatch;
306
- const wrapContextHandler = (handler, handlerId) => {
307
- return async (context) => {
308
- try {
309
- await handler(context);
310
- }
311
- catch (error) {
312
- console.error(`Error thrown by handler ${handlerId} for context type ${context.type}: ${error}`);
313
- throw error;
314
- }
315
- };
316
- };
317
- exports.wrapContextHandler = wrapContextHandler;
318
- const generateOverrideError = (clientApi, brokerApi) => {
319
- return `You have tried to to use ${clientApi} but ${brokerApi} has not been overridden in the Interop Broker. Please override this function. Refer to our documentation for more info.`;
320
- };
321
- exports.generateOverrideError = generateOverrideError;
322
- const generateOverrideWarning = (fdc3ClientApi, brokerApi, identity, interopClientApi) => {
323
- const { uuid, name } = identity;
324
- const message = interopClientApi
325
- ? `Entity with identity: ${uuid}/${name} has called ${interopClientApi} or ${fdc3ClientApi} but ${brokerApi} has not been overridden.`
326
- : `Entity with identity: ${uuid}/${name} has called ${fdc3ClientApi} but ${brokerApi} has not been overridden.`;
327
- return message;
328
- };
329
- exports.generateOverrideWarning = generateOverrideWarning;
330
- exports.BROKER_ERRORS = {
331
- fireIntent: (0, exports.generateOverrideError)('fireIntent', 'handleFiredIntent'),
332
- fireIntentForContext: (0, exports.generateOverrideError)('fireIntentForContext', 'handleFiredIntentForContext'),
333
- getInfoForIntent: (0, exports.generateOverrideError)('getInfoForIntent', 'handleInfoForIntent'),
334
- getInfoForIntentsByContext: (0, exports.generateOverrideError)('getInfoForIntentsByContext', 'handleInfoForIntentsByContext'),
335
- joinSessionContextGroupWithJoinContextGroup: 'The Context Group you have tried to join is a Session Context Group. Custom Context Groups can only be defined by the Interop Broker through code or manifest configuration. Please use joinSessionContextGroup.',
336
- fdc3Open: (0, exports.generateOverrideError)('fdc3.open', 'fdc3HandleOpen'),
337
- fdc3FindInstances: (0, exports.generateOverrideError)('fdc3.findInstances', 'fdc3HandleFindInstances'),
338
- fdc3GetAppMetadata: (0, exports.generateOverrideError)('fdc3.getAppMetadata', 'fdc3HandleGetAppMetadata'),
339
- fdc3GetInfo: (0, exports.generateOverrideError)('fdc3.getInfo', 'fdc3HandleGetInfo')
340
- };
341
- const wrapIntentHandler = (handler, handlerId) => {
342
- return async (intent) => {
343
- try {
344
- return handler(intent);
345
- }
346
- catch (error) {
347
- console.error(`Error thrown by handler ${handlerId}: ${error}`);
348
- throw error;
349
- }
350
- };
351
- };
293
+ Object.defineProperty(exports, "__esModule", { value: true });
294
+ exports.wrapIntentHandler = exports.BROKER_ERRORS = exports.generateOverrideWarning = exports.generateOverrideError = exports.wrapContextHandler = exports.wrapInTryCatch = exports.generateId = void 0;
295
+ const generateId = () => `${Math.random()}${Date.now()}`;
296
+ exports.generateId = generateId;
297
+ const wrapInTryCatch = (f, prefix) => (...args) => {
298
+ try {
299
+ return f(...args);
300
+ }
301
+ catch (e) {
302
+ throw new Error((prefix || '') + e);
303
+ }
304
+ };
305
+ exports.wrapInTryCatch = wrapInTryCatch;
306
+ const wrapContextHandler = (handler, handlerId) => {
307
+ return async (context) => {
308
+ try {
309
+ await handler(context);
310
+ }
311
+ catch (error) {
312
+ console.error(`Error thrown by handler ${handlerId} for context type ${context.type}: ${error}`);
313
+ throw error;
314
+ }
315
+ };
316
+ };
317
+ exports.wrapContextHandler = wrapContextHandler;
318
+ const generateOverrideError = (clientApi, brokerApi) => {
319
+ return `You have tried to to use ${clientApi} but ${brokerApi} has not been overridden in the Interop Broker. Please override this function. Refer to our documentation for more info.`;
320
+ };
321
+ exports.generateOverrideError = generateOverrideError;
322
+ const generateOverrideWarning = (fdc3ClientApi, brokerApi, identity, interopClientApi) => {
323
+ const { uuid, name } = identity;
324
+ const message = interopClientApi
325
+ ? `Entity with identity: ${uuid}/${name} has called ${interopClientApi} or ${fdc3ClientApi} but ${brokerApi} has not been overridden.`
326
+ : `Entity with identity: ${uuid}/${name} has called ${fdc3ClientApi} but ${brokerApi} has not been overridden.`;
327
+ return message;
328
+ };
329
+ exports.generateOverrideWarning = generateOverrideWarning;
330
+ exports.BROKER_ERRORS = {
331
+ fireIntent: (0, exports.generateOverrideError)('fireIntent', 'handleFiredIntent'),
332
+ fireIntentForContext: (0, exports.generateOverrideError)('fireIntentForContext', 'handleFiredIntentForContext'),
333
+ getInfoForIntent: (0, exports.generateOverrideError)('getInfoForIntent', 'handleInfoForIntent'),
334
+ getInfoForIntentsByContext: (0, exports.generateOverrideError)('getInfoForIntentsByContext', 'handleInfoForIntentsByContext'),
335
+ joinSessionContextGroupWithJoinContextGroup: 'The Context Group you have tried to join is a Session Context Group. Custom Context Groups can only be defined by the Interop Broker through code or manifest configuration. Please use joinSessionContextGroup.',
336
+ fdc3Open: (0, exports.generateOverrideError)('fdc3.open', 'fdc3HandleOpen'),
337
+ fdc3FindInstances: (0, exports.generateOverrideError)('fdc3.findInstances', 'fdc3HandleFindInstances'),
338
+ fdc3GetAppMetadata: (0, exports.generateOverrideError)('fdc3.getAppMetadata', 'fdc3HandleGetAppMetadata'),
339
+ fdc3GetInfo: (0, exports.generateOverrideError)('fdc3.getInfo', 'fdc3HandleGetInfo')
340
+ };
341
+ const wrapIntentHandler = (handler, handlerId) => {
342
+ return async (intent) => {
343
+ try {
344
+ return handler(intent);
345
+ }
346
+ catch (error) {
347
+ console.error(`Error thrown by handler ${handlerId}: ${error}`);
348
+ throw error;
349
+ }
350
+ };
351
+ };
352
352
  exports.wrapIntentHandler = wrapIntentHandler;
353
353
  } (utils$1));
354
354
 
355
355
  var PrivateChannelClient$1 = {};
356
356
 
357
- Object.defineProperty(PrivateChannelClient$1, "__esModule", { value: true });
358
- PrivateChannelClient$1.PrivateChannelClient = void 0;
359
- const utils = utils$1;
360
- class PrivateChannelClient {
361
- constructor(client, id) {
362
- this.id = id;
363
- this.client = client;
364
- this.listeners = new Map();
365
- }
366
- async broadcast(context) {
367
- return this.client.dispatch('broadcast', { context });
368
- }
369
- async getCurrentContext(contextType) {
370
- return this.client.dispatch('getCurrentContext', { contextType });
371
- }
372
- async addContextListener(contextType, handler) {
373
- if (typeof handler !== 'function') {
374
- throw new Error("Non-function argument passed to the second parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
375
- }
376
- let handlerId;
377
- if (contextType) {
378
- handlerId = `contextHandler:invoke-${this.id}-${contextType}-${utils.generateId()}`;
379
- }
380
- else {
381
- handlerId = `contextHandler:invoke-${this.id}-${utils.generateId()}`;
382
- }
383
- this.client.register(handlerId, utils.wrapContextHandler(handler, handlerId));
384
- const listener = { unsubscribe: await this.createContextUnsubscribeCb(handlerId) };
385
- this.listeners.set(handlerId, listener);
386
- await this.client.dispatch(`contextHandlerAdded`, { handlerId, contextType });
387
- return listener;
388
- }
389
- createNonStandardUnsubscribeCb(handlerId) {
390
- return async () => {
391
- this.client.remove(handlerId);
392
- this.listeners.delete(handlerId);
393
- await this.client.dispatch('nonStandardHandlerRemoved', { handlerId });
394
- };
395
- }
396
- createContextUnsubscribeCb(handlerId) {
397
- return async () => {
398
- this.client.remove(handlerId);
399
- this.listeners.delete(handlerId);
400
- await this.client.dispatch('contextHandlerRemoved', { handlerId });
401
- };
402
- }
403
- onAddContextListener(handler) {
404
- const handlerId = `onContextHandlerAdded:invoke-${this.id}-${utils.generateId()}`;
405
- this.client.register(handlerId, handler);
406
- const listener = { unsubscribe: this.createNonStandardUnsubscribeCb(handlerId) };
407
- this.listeners.set(handlerId, listener);
408
- this.client.dispatch(`onAddContextHandlerAdded`, { handlerId });
409
- return listener;
410
- }
411
- onDisconnect(handler) {
412
- const handlerId = `onDisconnect:invoke-${this.id}-${utils.generateId()}`;
413
- this.client.register(handlerId, handler);
414
- const listener = { unsubscribe: this.createNonStandardUnsubscribeCb(handlerId) };
415
- this.listeners.set(handlerId, listener);
416
- this.client.dispatch(`onDisconnectHandlerAdded`, { handlerId });
417
- return listener;
418
- }
419
- onUnsubscribe(handler) {
420
- const handlerId = `onUnsubscribe:invoke-${this.id}-${utils.generateId()}`;
421
- this.client.register(handlerId, handler);
422
- const listener = { unsubscribe: this.createNonStandardUnsubscribeCb(handlerId) };
423
- this.listeners.set(handlerId, listener);
424
- this.client.dispatch(`onUnsubscribeHandlerAdded`, { handlerId });
425
- return listener;
426
- }
427
- async cleanUpAllSubs() {
428
- const listenerUnsubscribers = Array.from(this.listeners.keys());
429
- listenerUnsubscribers.forEach((handlerId) => {
430
- this.client.remove(handlerId);
431
- this.listeners.delete(handlerId);
432
- });
433
- }
434
- async disconnect() {
435
- try {
436
- await this.client.dispatch('clientDisconnecting');
437
- await this.cleanUpAllSubs();
438
- await this.client.disconnect();
439
- }
440
- catch (error) {
441
- throw new Error(error.message);
442
- }
443
- }
444
- }
357
+ Object.defineProperty(PrivateChannelClient$1, "__esModule", { value: true });
358
+ PrivateChannelClient$1.PrivateChannelClient = void 0;
359
+ const utils = utils$1;
360
+ class PrivateChannelClient {
361
+ constructor(client, id) {
362
+ this.id = id;
363
+ this.client = client;
364
+ this.listeners = new Map();
365
+ }
366
+ async broadcast(context) {
367
+ return this.client.dispatch('broadcast', { context });
368
+ }
369
+ async getCurrentContext(contextType) {
370
+ return this.client.dispatch('getCurrentContext', { contextType });
371
+ }
372
+ async addContextListener(contextType, handler) {
373
+ if (typeof handler !== 'function') {
374
+ throw new Error("Non-function argument passed to the second parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
375
+ }
376
+ let handlerId;
377
+ if (contextType) {
378
+ handlerId = `contextHandler:invoke-${this.id}-${contextType}-${utils.generateId()}`;
379
+ }
380
+ else {
381
+ handlerId = `contextHandler:invoke-${this.id}-${utils.generateId()}`;
382
+ }
383
+ this.client.register(handlerId, utils.wrapContextHandler(handler, handlerId));
384
+ const listener = { unsubscribe: await this.createContextUnsubscribeCb(handlerId) };
385
+ this.listeners.set(handlerId, listener);
386
+ await this.client.dispatch(`contextHandlerAdded`, { handlerId, contextType });
387
+ return listener;
388
+ }
389
+ createNonStandardUnsubscribeCb(handlerId) {
390
+ return async () => {
391
+ this.client.remove(handlerId);
392
+ this.listeners.delete(handlerId);
393
+ await this.client.dispatch('nonStandardHandlerRemoved', { handlerId });
394
+ };
395
+ }
396
+ createContextUnsubscribeCb(handlerId) {
397
+ return async () => {
398
+ this.client.remove(handlerId);
399
+ this.listeners.delete(handlerId);
400
+ await this.client.dispatch('contextHandlerRemoved', { handlerId });
401
+ };
402
+ }
403
+ onAddContextListener(handler) {
404
+ const handlerId = `onContextHandlerAdded:invoke-${this.id}-${utils.generateId()}`;
405
+ this.client.register(handlerId, handler);
406
+ const listener = { unsubscribe: this.createNonStandardUnsubscribeCb(handlerId) };
407
+ this.listeners.set(handlerId, listener);
408
+ this.client.dispatch(`onAddContextHandlerAdded`, { handlerId });
409
+ return listener;
410
+ }
411
+ onDisconnect(handler) {
412
+ const handlerId = `onDisconnect:invoke-${this.id}-${utils.generateId()}`;
413
+ this.client.register(handlerId, handler);
414
+ const listener = { unsubscribe: this.createNonStandardUnsubscribeCb(handlerId) };
415
+ this.listeners.set(handlerId, listener);
416
+ this.client.dispatch(`onDisconnectHandlerAdded`, { handlerId });
417
+ return listener;
418
+ }
419
+ onUnsubscribe(handler) {
420
+ const handlerId = `onUnsubscribe:invoke-${this.id}-${utils.generateId()}`;
421
+ this.client.register(handlerId, handler);
422
+ const listener = { unsubscribe: this.createNonStandardUnsubscribeCb(handlerId) };
423
+ this.listeners.set(handlerId, listener);
424
+ this.client.dispatch(`onUnsubscribeHandlerAdded`, { handlerId });
425
+ return listener;
426
+ }
427
+ async cleanUpAllSubs() {
428
+ const listenerUnsubscribers = Array.from(this.listeners.keys());
429
+ listenerUnsubscribers.forEach((handlerId) => {
430
+ this.client.remove(handlerId);
431
+ this.listeners.delete(handlerId);
432
+ });
433
+ }
434
+ async disconnect() {
435
+ try {
436
+ await this.client.dispatch('clientDisconnecting');
437
+ await this.cleanUpAllSubs();
438
+ await this.client.disconnect();
439
+ }
440
+ catch (error) {
441
+ throw new Error(error.message);
442
+ }
443
+ }
444
+ }
445
445
  PrivateChannelClient$1.PrivateChannelClient = PrivateChannelClient;
446
446
 
447
447
  (function (exports) {
448
- Object.defineProperty(exports, "__esModule", { value: true });
449
- exports.getIntentResolution = exports.isChannel = exports.isContext = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ChannelError = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
450
- const utils_1 = utils$1;
451
- const PrivateChannelClient_1 = PrivateChannelClient$1;
452
- const lodash_1 = require$$2;
453
- const getUnsupportedChannelApis = (channelType) => {
454
- return {
455
- addContextListener: () => {
456
- throw new UnsupportedChannelApiError('Channel.addContextListener', channelType);
457
- },
458
- broadcast: () => {
459
- throw new UnsupportedChannelApiError('Channel.broadcast', channelType);
460
- },
461
- getCurrentContext: () => {
462
- throw new UnsupportedChannelApiError('Channel.getCurrentContext', channelType);
463
- }
464
- };
465
- };
466
- exports.getUnsupportedChannelApis = getUnsupportedChannelApis;
467
- class UnsupportedChannelApiError extends Error {
468
- constructor(apiName, channelType = 'System') {
469
- super(apiName);
470
- this.message = `Calling ${apiName} on an instance of a ${channelType} Channel returned by fdc3.get${channelType}Channels is not supported. If you would like to use a ${channelType} Channel, please use fdc3.joinChannel, fdc3.addContextListener, and fdc3.broadcast instead.`;
471
- }
472
- }
473
- exports.UnsupportedChannelApiError = UnsupportedChannelApiError;
474
- var ResultError;
475
- (function (ResultError) {
476
- /** Returned if the `IntentHandler` exited without returning a Promise or that
477
- * Promise was not resolved with a Context or Channel object.
478
- */
479
- ResultError["NoResultReturned"] = "NoResultReturned";
480
- /** Returned if the `IntentHandler` function processing the raised intent
481
- * throws an error or rejects the Promise it returned.
482
- */
483
- ResultError["IntentHandlerRejected"] = "IntentHandlerRejected";
484
- })(ResultError = exports.ResultError || (exports.ResultError = {}));
485
- (function (ChannelError) {
486
- /** Returned if the specified channel is not found when attempting to join a
487
- * channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).
488
- */
489
- ChannelError["NoChannelFound"] = "NoChannelFound";
490
- /** SHOULD be returned when a request to join a user channel or to a retrieve
491
- * a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods
492
- * of the DesktopAgent (`fdc3`) object is denied.
493
- */
494
- ChannelError["AccessDenied"] = "AccessDenied";
495
- /** SHOULD be returned when a channel cannot be created or retrieved via the
496
- * `getOrCreateChannel` method of the DesktopAgent (`fdc3`).
497
- */
498
- ChannelError["CreationFailed"] = "CreationFailed";
499
- })(exports.ChannelError || (exports.ChannelError = {}));
500
- const buildPrivateChannelObject = (privateChannelClient) => {
501
- let clientDisconnected = false;
502
- const checkIfClientDisconnected = () => {
503
- if (clientDisconnected) {
504
- throw new Error('Private Channel Client has been disconnected from the Private Channel');
505
- }
506
- };
507
- return {
508
- id: privateChannelClient.id,
509
- type: 'private',
510
- broadcast: async (context) => {
511
- checkIfClientDisconnected();
512
- return privateChannelClient.broadcast(context);
513
- },
514
- getCurrentContext: async (contextType) => {
515
- checkIfClientDisconnected();
516
- return privateChannelClient.getCurrentContext(contextType);
517
- },
518
- addContextListener: async (contextType, handler) => {
519
- checkIfClientDisconnected();
520
- let handlerInUse = handler;
521
- let contextTypeInUse = contextType;
522
- if (typeof contextType === 'function') {
523
- console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
524
- handlerInUse = contextType;
525
- contextTypeInUse = null;
526
- }
527
- const listener = privateChannelClient.addContextListener(contextTypeInUse, handlerInUse);
528
- return listener;
529
- },
530
- onAddContextListener: (handler) => {
531
- checkIfClientDisconnected();
532
- return privateChannelClient.onAddContextListener(handler);
533
- },
534
- disconnect: async () => {
535
- checkIfClientDisconnected();
536
- clientDisconnected = true;
537
- return privateChannelClient.disconnect();
538
- },
539
- onDisconnect: (handler) => {
540
- checkIfClientDisconnected();
541
- return privateChannelClient.onDisconnect(handler);
542
- },
543
- onUnsubscribe: (handler) => {
544
- checkIfClientDisconnected();
545
- return privateChannelClient.onUnsubscribe(handler);
546
- }
547
- };
548
- };
549
- exports.buildPrivateChannelObject = buildPrivateChannelObject;
550
- const buildAppChannelObject = (sessionContextGroup) => {
551
- return {
552
- id: sessionContextGroup.id,
553
- type: 'app',
554
- broadcast: sessionContextGroup.setContext,
555
- getCurrentContext: async (contextType) => {
556
- const context = await sessionContextGroup.getCurrentContext(contextType);
557
- return context === undefined ? null : context;
558
- },
559
- addContextListener: (contextType, handler) => {
560
- let realHandler;
561
- let realType;
562
- if (typeof contextType === 'function') {
563
- console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
564
- realHandler = contextType;
565
- }
566
- else {
567
- realHandler = handler;
568
- if (typeof contextType === 'string') {
569
- realType = contextType;
570
- }
571
- }
572
- const listener = (async () => {
573
- let first = true;
574
- const currentContext = await sessionContextGroup.getCurrentContext(realType);
575
- const wrappedHandler = (context, contextMetadata) => {
576
- if (first) {
577
- first = false;
578
- if ((0, lodash_1.isEqual)(currentContext, context)) {
579
- return;
580
- }
581
- }
582
- // eslint-disable-next-line consistent-return
583
- return realHandler(context, contextMetadata);
584
- };
585
- return sessionContextGroup.addContextHandler(wrappedHandler, realType);
586
- })();
587
- return {
588
- ...listener,
589
- unsubscribe: () => listener.then((l) => l.unsubscribe())
590
- };
591
- }
592
- };
593
- };
594
- exports.buildAppChannelObject = buildAppChannelObject;
595
- const connectPrivateChannel = async (channelId) => {
596
- try {
597
- const channelClient = await fin.InterApplicationBus.Channel.connect(channelId);
598
- const privateChannelClient = new PrivateChannelClient_1.PrivateChannelClient(channelClient, channelId);
599
- return (0, exports.buildPrivateChannelObject)(privateChannelClient);
600
- }
601
- catch (error) {
602
- throw new Error(`Private Channel with id: ${channelId} doesn't exist`);
603
- }
604
- };
605
- exports.connectPrivateChannel = connectPrivateChannel;
606
- const isContext = (context) => {
607
- if (context && typeof context === 'object' && 'type' in context) {
608
- const { type } = context;
609
- return typeof type === 'string';
610
- }
611
- return false;
612
- };
613
- exports.isContext = isContext;
614
- const isChannel = (channel) => {
615
- if (channel && typeof channel === 'object' && 'type' in channel && 'id' in channel) {
616
- const { type, id } = channel;
617
- return typeof type === 'string' && typeof id === 'string' && (type === 'app' || type === 'private');
618
- }
619
- return false;
620
- };
621
- exports.isChannel = isChannel;
622
- const getIntentResolution = async (interopModule, context, app, intent) => {
623
- // Generate an ID to make a session context group with. We will pass that ID to the Broker.
624
- // The broker will then setContext on that session context group later with our Intent Result,
625
- const guid = (0, utils_1.generateId)();
626
- // Promise we'll use in getResult
627
- const getResultPromise = new Promise((resolve) => {
628
- fin.InterApplicationBus.subscribe({ uuid: '*' }, guid, (intentResult) => {
629
- resolve(intentResult);
630
- });
631
- });
632
- // Adding the intentResolutionResultId to the intentObj. Because fireIntent only accepts a single arg, we have to slap it in here.
633
- const metadata = app ? { target: app, intentResolutionResultId: guid } : { intentResolutionResultId: guid };
634
- const intentObj = intent ? { name: intent, context, metadata } : { ...context, metadata };
635
- // Set up the getResult call.
636
- const getResult = async () => {
637
- let intentResult = await getResultPromise;
638
- if (!intentResult || typeof intentResult !== 'object') {
639
- throw new Error(ResultError.NoResultReturned);
640
- }
641
- const { error } = intentResult;
642
- if (error) {
643
- throw new Error(ResultError.IntentHandlerRejected);
644
- }
645
- if ((0, exports.isChannel)(intentResult)) {
646
- const { id, type } = intentResult;
647
- switch (type) {
648
- case 'private': {
649
- intentResult = await (0, exports.connectPrivateChannel)(id);
650
- break;
651
- }
652
- case 'app': {
653
- const sessionContextGroup = await interopModule.joinSessionContextGroup(id);
654
- intentResult = (0, exports.buildAppChannelObject)(sessionContextGroup);
655
- break;
656
- }
657
- }
658
- }
659
- else if (!(0, exports.isContext)(intentResult)) {
660
- throw new Error(ResultError.NoResultReturned);
661
- }
662
- return intentResult;
663
- };
664
- // Finally fire the intent.
665
- const intentResolutionInfoFromBroker = intent
666
- ? await interopModule.fireIntent(intentObj)
667
- : await interopModule.fireIntentForContext(intentObj);
668
- if (typeof intentResolutionInfoFromBroker !== 'object') {
669
- return {
670
- source: {
671
- appId: '',
672
- instanceId: ''
673
- },
674
- intent: '',
675
- version: '2.0',
676
- getResult
677
- };
678
- }
679
- return { ...intentResolutionInfoFromBroker, getResult };
680
- };
448
+ Object.defineProperty(exports, "__esModule", { value: true });
449
+ exports.getIntentResolution = exports.isChannel = exports.isContext = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ChannelError = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
450
+ const utils_1 = utils$1;
451
+ const PrivateChannelClient_1 = PrivateChannelClient$1;
452
+ const lodash_1 = require$$2;
453
+ const getUnsupportedChannelApis = (channelType) => {
454
+ return {
455
+ addContextListener: () => {
456
+ throw new UnsupportedChannelApiError('Channel.addContextListener', channelType);
457
+ },
458
+ broadcast: () => {
459
+ throw new UnsupportedChannelApiError('Channel.broadcast', channelType);
460
+ },
461
+ getCurrentContext: () => {
462
+ throw new UnsupportedChannelApiError('Channel.getCurrentContext', channelType);
463
+ }
464
+ };
465
+ };
466
+ exports.getUnsupportedChannelApis = getUnsupportedChannelApis;
467
+ class UnsupportedChannelApiError extends Error {
468
+ constructor(apiName, channelType = 'System') {
469
+ super(apiName);
470
+ this.message = `Calling ${apiName} on an instance of a ${channelType} Channel returned by fdc3.get${channelType}Channels is not supported. If you would like to use a ${channelType} Channel, please use fdc3.joinChannel, fdc3.addContextListener, and fdc3.broadcast instead.`;
471
+ }
472
+ }
473
+ exports.UnsupportedChannelApiError = UnsupportedChannelApiError;
474
+ var ResultError;
475
+ (function (ResultError) {
476
+ /** Returned if the `IntentHandler` exited without returning a Promise or that
477
+ * Promise was not resolved with a Context or Channel object.
478
+ */
479
+ ResultError["NoResultReturned"] = "NoResultReturned";
480
+ /** Returned if the `IntentHandler` function processing the raised intent
481
+ * throws an error or rejects the Promise it returned.
482
+ */
483
+ ResultError["IntentHandlerRejected"] = "IntentHandlerRejected";
484
+ })(ResultError = exports.ResultError || (exports.ResultError = {}));
485
+ (function (ChannelError) {
486
+ /** Returned if the specified channel is not found when attempting to join a
487
+ * channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).
488
+ */
489
+ ChannelError["NoChannelFound"] = "NoChannelFound";
490
+ /** SHOULD be returned when a request to join a user channel or to a retrieve
491
+ * a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods
492
+ * of the DesktopAgent (`fdc3`) object is denied.
493
+ */
494
+ ChannelError["AccessDenied"] = "AccessDenied";
495
+ /** SHOULD be returned when a channel cannot be created or retrieved via the
496
+ * `getOrCreateChannel` method of the DesktopAgent (`fdc3`).
497
+ */
498
+ ChannelError["CreationFailed"] = "CreationFailed";
499
+ })(exports.ChannelError || (exports.ChannelError = {}));
500
+ const buildPrivateChannelObject = (privateChannelClient) => {
501
+ let clientDisconnected = false;
502
+ const checkIfClientDisconnected = () => {
503
+ if (clientDisconnected) {
504
+ throw new Error('Private Channel Client has been disconnected from the Private Channel');
505
+ }
506
+ };
507
+ return {
508
+ id: privateChannelClient.id,
509
+ type: 'private',
510
+ broadcast: async (context) => {
511
+ checkIfClientDisconnected();
512
+ return privateChannelClient.broadcast(context);
513
+ },
514
+ getCurrentContext: async (contextType) => {
515
+ checkIfClientDisconnected();
516
+ return privateChannelClient.getCurrentContext(contextType);
517
+ },
518
+ addContextListener: async (contextType, handler) => {
519
+ checkIfClientDisconnected();
520
+ let handlerInUse = handler;
521
+ let contextTypeInUse = contextType;
522
+ if (typeof contextType === 'function') {
523
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
524
+ handlerInUse = contextType;
525
+ contextTypeInUse = null;
526
+ }
527
+ const listener = privateChannelClient.addContextListener(contextTypeInUse, handlerInUse);
528
+ return listener;
529
+ },
530
+ onAddContextListener: (handler) => {
531
+ checkIfClientDisconnected();
532
+ return privateChannelClient.onAddContextListener(handler);
533
+ },
534
+ disconnect: async () => {
535
+ checkIfClientDisconnected();
536
+ clientDisconnected = true;
537
+ return privateChannelClient.disconnect();
538
+ },
539
+ onDisconnect: (handler) => {
540
+ checkIfClientDisconnected();
541
+ return privateChannelClient.onDisconnect(handler);
542
+ },
543
+ onUnsubscribe: (handler) => {
544
+ checkIfClientDisconnected();
545
+ return privateChannelClient.onUnsubscribe(handler);
546
+ }
547
+ };
548
+ };
549
+ exports.buildPrivateChannelObject = buildPrivateChannelObject;
550
+ const buildAppChannelObject = (sessionContextGroup) => {
551
+ return {
552
+ id: sessionContextGroup.id,
553
+ type: 'app',
554
+ broadcast: sessionContextGroup.setContext,
555
+ getCurrentContext: async (contextType) => {
556
+ const context = await sessionContextGroup.getCurrentContext(contextType);
557
+ return context === undefined ? null : context;
558
+ },
559
+ addContextListener: (contextType, handler) => {
560
+ let realHandler;
561
+ let realType;
562
+ if (typeof contextType === 'function') {
563
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
564
+ realHandler = contextType;
565
+ }
566
+ else {
567
+ realHandler = handler;
568
+ if (typeof contextType === 'string') {
569
+ realType = contextType;
570
+ }
571
+ }
572
+ const listener = (async () => {
573
+ let first = true;
574
+ const currentContext = await sessionContextGroup.getCurrentContext(realType);
575
+ const wrappedHandler = (context, contextMetadata) => {
576
+ if (first) {
577
+ first = false;
578
+ if ((0, lodash_1.isEqual)(currentContext, context)) {
579
+ return;
580
+ }
581
+ }
582
+ // eslint-disable-next-line consistent-return
583
+ return realHandler(context, contextMetadata);
584
+ };
585
+ return sessionContextGroup.addContextHandler(wrappedHandler, realType);
586
+ })();
587
+ return {
588
+ ...listener,
589
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
590
+ };
591
+ }
592
+ };
593
+ };
594
+ exports.buildAppChannelObject = buildAppChannelObject;
595
+ const connectPrivateChannel = async (channelId) => {
596
+ try {
597
+ const channelClient = await fin.InterApplicationBus.Channel.connect(channelId);
598
+ const privateChannelClient = new PrivateChannelClient_1.PrivateChannelClient(channelClient, channelId);
599
+ return (0, exports.buildPrivateChannelObject)(privateChannelClient);
600
+ }
601
+ catch (error) {
602
+ throw new Error(`Private Channel with id: ${channelId} doesn't exist`);
603
+ }
604
+ };
605
+ exports.connectPrivateChannel = connectPrivateChannel;
606
+ const isContext = (context) => {
607
+ if (context && typeof context === 'object' && 'type' in context) {
608
+ const { type } = context;
609
+ return typeof type === 'string';
610
+ }
611
+ return false;
612
+ };
613
+ exports.isContext = isContext;
614
+ const isChannel = (channel) => {
615
+ if (channel && typeof channel === 'object' && 'type' in channel && 'id' in channel) {
616
+ const { type, id } = channel;
617
+ return typeof type === 'string' && typeof id === 'string' && (type === 'app' || type === 'private');
618
+ }
619
+ return false;
620
+ };
621
+ exports.isChannel = isChannel;
622
+ const getIntentResolution = async (interopModule, context, app, intent) => {
623
+ // Generate an ID to make a session context group with. We will pass that ID to the Broker.
624
+ // The broker will then setContext on that session context group later with our Intent Result,
625
+ const guid = (0, utils_1.generateId)();
626
+ // Promise we'll use in getResult
627
+ const getResultPromise = new Promise((resolve) => {
628
+ fin.InterApplicationBus.subscribe({ uuid: '*' }, guid, (intentResult) => {
629
+ resolve(intentResult);
630
+ });
631
+ });
632
+ // Adding the intentResolutionResultId to the intentObj. Because fireIntent only accepts a single arg, we have to slap it in here.
633
+ const metadata = app ? { target: app, intentResolutionResultId: guid } : { intentResolutionResultId: guid };
634
+ const intentObj = intent ? { name: intent, context, metadata } : { ...context, metadata };
635
+ // Set up the getResult call.
636
+ const getResult = async () => {
637
+ let intentResult = await getResultPromise;
638
+ if (!intentResult || typeof intentResult !== 'object') {
639
+ throw new Error(ResultError.NoResultReturned);
640
+ }
641
+ const { error } = intentResult;
642
+ if (error) {
643
+ throw new Error(ResultError.IntentHandlerRejected);
644
+ }
645
+ if ((0, exports.isChannel)(intentResult)) {
646
+ const { id, type } = intentResult;
647
+ switch (type) {
648
+ case 'private': {
649
+ intentResult = await (0, exports.connectPrivateChannel)(id);
650
+ break;
651
+ }
652
+ case 'app': {
653
+ const sessionContextGroup = await interopModule.joinSessionContextGroup(id);
654
+ intentResult = (0, exports.buildAppChannelObject)(sessionContextGroup);
655
+ break;
656
+ }
657
+ }
658
+ }
659
+ else if (!(0, exports.isContext)(intentResult)) {
660
+ throw new Error(ResultError.NoResultReturned);
661
+ }
662
+ return intentResult;
663
+ };
664
+ // Finally fire the intent.
665
+ const intentResolutionInfoFromBroker = intent
666
+ ? await interopModule.fireIntent(intentObj)
667
+ : await interopModule.fireIntentForContext(intentObj);
668
+ if (typeof intentResolutionInfoFromBroker !== 'object') {
669
+ return {
670
+ source: {
671
+ appId: '',
672
+ instanceId: ''
673
+ },
674
+ intent: '',
675
+ version: '2.0',
676
+ getResult
677
+ };
678
+ }
679
+ return { ...intentResolutionInfoFromBroker, getResult };
680
+ };
681
681
  exports.getIntentResolution = getIntentResolution;
682
682
  } (utils$2));
683
683
 
@@ -685,1470 +685,1470 @@ var InteropClient$1 = {};
685
685
 
686
686
  var SessionContextGroupClient$1 = {};
687
687
 
688
- var __classPrivateFieldSet$1 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
689
- if (kind === "m") throw new TypeError("Private method is not writable");
690
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
691
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
692
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
693
- };
694
- var __classPrivateFieldGet$1 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
695
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
696
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
697
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
698
- };
699
- var _SessionContextGroupClient_clientPromise;
700
- Object.defineProperty(SessionContextGroupClient$1, "__esModule", { value: true });
701
- const base_1$3 = base;
702
- const utils_1$3 = utils$1;
703
- class SessionContextGroupClient extends base_1$3.Base {
704
- constructor(wire, client, id) {
705
- super(wire);
706
- _SessionContextGroupClient_clientPromise.set(this, void 0);
707
- this.id = id;
708
- __classPrivateFieldSet$1(this, _SessionContextGroupClient_clientPromise, client, "f");
709
- }
710
- /**
711
- * Sets a context for the session context group.
712
- * @param context - New context to set.
713
- *
714
- * @tutorial interop.setContext
715
- */
716
- async setContext(context) {
717
- this.wire.sendAction('interop-session-context-group-set-context').catch((e) => {
718
- // don't expose, analytics-only call
719
- });
720
- const client = await __classPrivateFieldGet$1(this, _SessionContextGroupClient_clientPromise, "f");
721
- return client.dispatch(`sessionContextGroup:setContext-${this.id}`, {
722
- sessionContextGroupId: this.id,
723
- context
724
- });
725
- }
726
- async getCurrentContext(type) {
727
- this.wire.sendAction('interop-session-context-group-get-context').catch((e) => {
728
- // don't expose, analytics-only call
729
- });
730
- const client = await __classPrivateFieldGet$1(this, _SessionContextGroupClient_clientPromise, "f");
731
- return client.dispatch(`sessionContextGroup:getContext-${this.id}`, {
732
- sessionContextGroupId: this.id,
733
- type
734
- });
735
- }
736
- async addContextHandler(contextHandler, contextType) {
737
- this.wire.sendAction('interop-session-context-group-add-handler').catch((e) => {
738
- // don't expose, analytics-only call
739
- });
740
- if (typeof contextHandler !== 'function') {
741
- throw new Error("Non-function argument passed to the first parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
742
- }
743
- const client = await __classPrivateFieldGet$1(this, _SessionContextGroupClient_clientPromise, "f");
744
- let handlerId;
745
- if (contextType) {
746
- handlerId = `sessionContextHandler:invoke-${this.id}-${contextType}-${(0, utils_1$3.generateId)()}`;
747
- }
748
- else {
749
- handlerId = `sessionContextHandler:invoke-${this.id}`;
750
- }
751
- client.register(handlerId, (0, utils_1$3.wrapContextHandler)(contextHandler, handlerId));
752
- await client.dispatch(`sessionContextGroup:handlerAdded-${this.id}`, { handlerId, contextType });
753
- return { unsubscribe: await this.createUnsubscribeCb(handlerId) };
754
- }
755
- async createUnsubscribeCb(handlerId) {
756
- const client = await __classPrivateFieldGet$1(this, _SessionContextGroupClient_clientPromise, "f");
757
- return async () => {
758
- client.remove(handlerId);
759
- await client.dispatch(`sessionContextGroup:handlerRemoved-${this.id}`, { handlerId });
760
- };
761
- }
762
- getUserInstance() {
763
- return {
764
- id: this.id,
765
- setContext: (0, utils_1$3.wrapInTryCatch)(this.setContext.bind(this), 'Failed to set context: '),
766
- getCurrentContext: (0, utils_1$3.wrapInTryCatch)(this.getCurrentContext.bind(this), 'Failed to get context: '),
767
- addContextHandler: (0, utils_1$3.wrapInTryCatch)(this.addContextHandler.bind(this), 'Failed to add context handler: ')
768
- };
769
- }
770
- }
771
- SessionContextGroupClient$1.default = SessionContextGroupClient;
688
+ var __classPrivateFieldSet$1 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
689
+ if (kind === "m") throw new TypeError("Private method is not writable");
690
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
691
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
692
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
693
+ };
694
+ var __classPrivateFieldGet$1 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
695
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
696
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
697
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
698
+ };
699
+ var _SessionContextGroupClient_clientPromise;
700
+ Object.defineProperty(SessionContextGroupClient$1, "__esModule", { value: true });
701
+ const base_1$3 = base;
702
+ const utils_1$3 = utils$1;
703
+ class SessionContextGroupClient extends base_1$3.Base {
704
+ constructor(wire, client, id) {
705
+ super(wire);
706
+ _SessionContextGroupClient_clientPromise.set(this, void 0);
707
+ this.id = id;
708
+ __classPrivateFieldSet$1(this, _SessionContextGroupClient_clientPromise, client, "f");
709
+ }
710
+ /**
711
+ * Sets a context for the session context group.
712
+ * @param context - New context to set.
713
+ *
714
+ * @tutorial interop.setContext
715
+ */
716
+ async setContext(context) {
717
+ this.wire.sendAction('interop-session-context-group-set-context').catch((e) => {
718
+ // don't expose, analytics-only call
719
+ });
720
+ const client = await __classPrivateFieldGet$1(this, _SessionContextGroupClient_clientPromise, "f");
721
+ return client.dispatch(`sessionContextGroup:setContext-${this.id}`, {
722
+ sessionContextGroupId: this.id,
723
+ context
724
+ });
725
+ }
726
+ async getCurrentContext(type) {
727
+ this.wire.sendAction('interop-session-context-group-get-context').catch((e) => {
728
+ // don't expose, analytics-only call
729
+ });
730
+ const client = await __classPrivateFieldGet$1(this, _SessionContextGroupClient_clientPromise, "f");
731
+ return client.dispatch(`sessionContextGroup:getContext-${this.id}`, {
732
+ sessionContextGroupId: this.id,
733
+ type
734
+ });
735
+ }
736
+ async addContextHandler(contextHandler, contextType) {
737
+ this.wire.sendAction('interop-session-context-group-add-handler').catch((e) => {
738
+ // don't expose, analytics-only call
739
+ });
740
+ if (typeof contextHandler !== 'function') {
741
+ throw new Error("Non-function argument passed to the first parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
742
+ }
743
+ const client = await __classPrivateFieldGet$1(this, _SessionContextGroupClient_clientPromise, "f");
744
+ let handlerId;
745
+ if (contextType) {
746
+ handlerId = `sessionContextHandler:invoke-${this.id}-${contextType}-${(0, utils_1$3.generateId)()}`;
747
+ }
748
+ else {
749
+ handlerId = `sessionContextHandler:invoke-${this.id}`;
750
+ }
751
+ client.register(handlerId, (0, utils_1$3.wrapContextHandler)(contextHandler, handlerId));
752
+ await client.dispatch(`sessionContextGroup:handlerAdded-${this.id}`, { handlerId, contextType });
753
+ return { unsubscribe: await this.createUnsubscribeCb(handlerId) };
754
+ }
755
+ async createUnsubscribeCb(handlerId) {
756
+ const client = await __classPrivateFieldGet$1(this, _SessionContextGroupClient_clientPromise, "f");
757
+ return async () => {
758
+ client.remove(handlerId);
759
+ await client.dispatch(`sessionContextGroup:handlerRemoved-${this.id}`, { handlerId });
760
+ };
761
+ }
762
+ getUserInstance() {
763
+ return {
764
+ id: this.id,
765
+ setContext: (0, utils_1$3.wrapInTryCatch)(this.setContext.bind(this), 'Failed to set context: '),
766
+ getCurrentContext: (0, utils_1$3.wrapInTryCatch)(this.getCurrentContext.bind(this), 'Failed to get context: '),
767
+ addContextHandler: (0, utils_1$3.wrapInTryCatch)(this.addContextHandler.bind(this), 'Failed to add context handler: ')
768
+ };
769
+ }
770
+ }
771
+ SessionContextGroupClient$1.default = SessionContextGroupClient;
772
772
  _SessionContextGroupClient_clientPromise = new WeakMap();
773
773
 
774
- var __classPrivateFieldSet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
775
- if (kind === "m") throw new TypeError("Private method is not writable");
776
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
777
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
778
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
779
- };
780
- var __classPrivateFieldGet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
781
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
782
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
783
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
784
- };
785
- var _InteropClient_clientPromise, _InteropClient_sessionContextGroups;
786
- Object.defineProperty(InteropClient$1, "__esModule", { value: true });
787
- InteropClient$1.InteropClient = void 0;
788
- const base_1$2 = base;
789
- const SessionContextGroupClient_1 = SessionContextGroupClient$1;
790
- const utils_1$2 = utils$1;
791
- /**
792
- * The Interop Client API is broken up into two groups:
793
- *
794
- * **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.
795
- *
796
- * **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.
797
- *
798
- * ---
799
- *
800
- * All APIs are available at the `fin.me.interop` namespace.
801
- *
802
- * ---
803
- *
804
- * **You only need 2 things to participate in Interop Context Grouping:**
805
- * * A Context Handler for incoming context: {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
806
- * * Call setContext on your context group when you want to share context with other group members: {@link InteropClient#setContext setContext(context)}
807
- *
808
- * ---
809
- *
810
- * ##### Constructor
811
- * Returned by {@link Interop.connectSync Interop.connectSync}.
812
- *
813
- * ---
814
- *
815
- * ##### Interop methods intended for Views
816
- *
817
- *
818
- * **Context Groups API**
819
- * * {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
820
- * * {@link InteropClient#setContext setContext(context)}
821
- * * {@link InteropClient#getCurrentContext getCurrentContext(contextType?)}
822
- * * {@link InteropClient#joinSessionContextGroup joinSessionContextGroup(sessionContextGroupId)}
823
- *
824
- *
825
- * **Intents API**
826
- * * {@link InteropClient#fireIntent fireIntent(intent)}
827
- * * {@link InteropClient#registerIntentHandler registerIntentHandler(intentHandler, intentName)}
828
- * * {@link InteropClient#getInfoForIntent getInfoForIntent(infoForIntentOptions)}
829
- * * {@link InteropClient#getInfoForIntentsByContext getInfoForIntentsByContext(context)}
830
- * * {@link InteropClient#fireIntentForContext fireIntentForContext(contextForIntent)}
831
- *
832
- * ##### Interop methods intended for Windows
833
- * * {@link InteropClient#getContextGroups getContextGroups()}
834
- * * {@link InteropClient#joinContextGroup joinContextGroup(contextGroupId, target?)}
835
- * * {@link InteropClient#removeFromContextGroup removeFromContextGroup(target?)}
836
- * * {@link InteropClient#getInfoForContextGroup getInfoForContextGroup(contextGroupId)}
837
- * * {@link InteropClient#getAllClientsInContextGroup getAllClientsInContextGroup(contextGroupId)}
838
- *
839
- */
840
- class InteropClient extends base_1$2.Base {
841
- /**
842
- * @internal
843
- */
844
- constructor(wire, name, interopConfig = {}) {
845
- super(wire);
846
- _InteropClient_clientPromise.set(this, void 0);
847
- _InteropClient_sessionContextGroups.set(this, void 0);
848
- __classPrivateFieldSet(this, _InteropClient_sessionContextGroups, new Map(), "f");
849
- __classPrivateFieldSet(this, _InteropClient_clientPromise, this.wire.environment.whenReady().then(() => {
850
- return this.fin.InterApplicationBus.Channel.connect(`interop-broker-${name}`, {
851
- payload: interopConfig
852
- });
853
- }), "f");
854
- }
855
- /*
856
- Client APIs
857
- */
858
- /**
859
- * Sets a context for the context group of the current entity.
860
- *
861
- * @remarks The entity must be part of a context group in order set a context.
862
- *
863
- * @param context - New context to set.
864
- *
865
- * @example
866
- * ```js
867
- * setInstrumentContext = async (ticker) => {
868
- * fin.me.interop.setContext({type: 'instrument', id: {ticker}})
869
- * }
870
- *
871
- * // The user clicks an instrument of interest. We want to set that Instrument context so that the rest of our workflow updates with information for that instrument
872
- * instrumentElement.on('click', (evt) => {
873
- * setInstrumentContext(evt.ticker)
874
- * })
875
- * ```
876
- */
877
- async setContext(context) {
878
- this.wire.sendAction('interop-client-set-context').catch((e) => {
879
- // don't expose, analytics-only call
880
- });
881
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
882
- return client.dispatch('setContext', { context });
883
- }
884
- /**
885
- * Add a context handler for incoming context. If an entity is part of a context group, and then sets its context handler,
886
- * it will receive all of its declared contexts.
887
- *
888
- * @param handler - Handler for incoming context.
889
- * @param contextType - The type of context you wish to handle.
890
- *
891
- * @example
892
- * ```js
893
- * function handleIncomingContext(contextInfo) {
894
- * const { type, id } = contextInfo;
895
- * switch (type) {
896
- * case 'instrument':
897
- * handleInstrumentContext(contextInfo);
898
- * break;
899
- * case 'country':
900
- * handleCountryContext(contextInfo);
901
- * break;
902
- *
903
- * default:
904
- * break;
905
- * }
906
- * }
907
- *
908
- *
909
- * function handleInstrumentContext(contextInfo) {
910
- * const { type, id } = contextInfo;
911
- * console.log('contextInfo for instrument', contextInfo)
912
- * }
913
- *
914
- * function handleCountryContext(contextInfo) {
915
- * const { type, id } = contextInfo;
916
- * console.log('contextInfo for country', contextInfo)
917
- * }
918
- *
919
- * fin.me.interop.addContextHandler(handleIncomingContext);
920
- * ```
921
- *
922
- *
923
- * We are also testing the ability to add a context handler for specific contexts. If you would like to use
924
- * this, please make sure you add your context handlers at the top level of your application, on a page that
925
- * does not navigate/reload/re-render, to avoid memory leaks. This feature is experimental:
926
- *
927
- * ```js
928
- * function handleInstrumentContext(contextInfo) {
929
- * const { type, id } = contextInfo;
930
- * console.log('contextInfo for instrument', contextInfo)
931
- * }
932
- *
933
- * function handleCountryContext(contextInfo) {
934
- * const { type, id } = contextInfo;
935
- * console.log('contextInfo for country', contextInfo)
936
- * }
937
- *
938
- *
939
- * fin.me.interop.addContextHandler(handleInstrumentContext, 'instrument')
940
- * fin.me.interop.addContextHandler(handleCountryContext, 'country')
941
- * ```
942
- */
943
- async addContextHandler(handler, contextType) {
944
- this.wire.sendAction('interop-client-add-context-handler').catch((e) => {
945
- // don't expose, analytics-only call
946
- });
947
- if (typeof handler !== 'function') {
948
- throw new Error("Non-function argument passed to the first parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
949
- }
950
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
951
- let handlerId;
952
- if (contextType) {
953
- handlerId = `invokeContextHandler-${contextType}-${(0, utils_1$2.generateId)()}`;
954
- 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.`);
955
- }
956
- else {
957
- handlerId = 'invokeContextHandler';
958
- }
959
- const wrappedHandler = (0, utils_1$2.wrapContextHandler)(handler, handlerId);
960
- client.register(handlerId, wrappedHandler);
961
- await client.dispatch('contextHandlerRegistered', { handlerId, contextType });
962
- return {
963
- unsubscribe: async () => {
964
- client.remove(handlerId);
965
- await client.dispatch('removeContextHandler', { handlerId });
966
- }
967
- };
968
- }
969
- /*
970
- Platform Window APIs
971
- */
972
- /**
973
- * Returns the Interop-Broker-defined context groups available for an entity to join.
974
- * Used by Platform Windows.
975
- *
976
- * @example
977
- * ```js
978
- * fin.me.interop.getContextGroups()
979
- * .then(contextGroups => {
980
- * contextGroups.forEach(contextGroup => {
981
- * console.log(contextGroup.displayMetadata.name)
982
- * console.log(contextGroup.displayMetadata.color)
983
- * })
984
- * })
985
- * ```
986
- */
987
- async getContextGroups() {
988
- this.wire.sendAction('interop-client-get-context-groups').catch((e) => {
989
- // don't expose, analytics-only call
990
- });
991
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
992
- return client.dispatch('getContextGroups');
993
- }
994
- /**
995
- * Join all Interop Clients at the given identity to context group `contextGroupId`.
996
- * If no target is specified, it adds the sender to the context group.
997
- *
998
- * @remarks 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.
999
- * 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.
1000
- * 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.
1001
- * Used by Platform Windows.
1002
- *
1003
- * @param contextGroupId - Id of the context group.
1004
- * @param target - Identity of the entity you wish to join to a context group.
1005
- *
1006
- * @example
1007
- * ```js
1008
- * joinViewToContextGroup = async (contextGroupId, view) => {
1009
- * await fin.me.interop.joinContextGroup(contextGroupId, view);
1010
- * }
1011
- *
1012
- * getLastFocusedView()
1013
- * .then(lastFocusedViewIdentity => {
1014
- * joinViewToContextGroup('red', lastFocusedViewIdentity)
1015
- * })
1016
- * ```
1017
- */
1018
- async joinContextGroup(contextGroupId, target) {
1019
- this.wire.sendAction('interop-client-join-context-group').catch((e) => {
1020
- // don't expose, analytics-only call
1021
- });
1022
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1023
- if (!contextGroupId) {
1024
- throw new Error('No contextGroupId specified for joinContextGroup.');
1025
- }
1026
- return client.dispatch('joinContextGroup', { contextGroupId, target });
1027
- }
1028
- /**
1029
- * Removes the specified target from a context group.
1030
- * If no target is specified, it removes the sender from their context group.
1031
- * Used by Platform Windows.
1032
- *
1033
- * @param target - Identity of the entity you wish to join to a context group.
1034
- *
1035
- * @example
1036
- * ```js
1037
- * removeViewFromContextGroup = async (view) => {
1038
- * await fin.me.interop.removeFromContextGroup(view);
1039
- * }
1040
- *
1041
- * getLastFocusedView()
1042
- * .then(lastFocusedViewIdentity => {
1043
- * removeViewFromContextGroup(lastFocusedViewIdentity)
1044
- * })
1045
- * ```
1046
- */
1047
- async removeFromContextGroup(target) {
1048
- this.wire.sendAction('interop-client-remove-from-context-group').catch((e) => {
1049
- // don't expose, analytics-only call
1050
- });
1051
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1052
- return client.dispatch('removeFromContextGroup', { target });
1053
- }
1054
- /**
1055
- * Gets all clients for a context group.
1056
- *
1057
- * @remarks **This is primarily used for platform windows. Views within a platform should not have to use this API.**
1058
- *
1059
- * Returns the Interop-Broker-defined context groups available for an entity to join.
1060
- * @param contextGroupId - The id of context group you wish to get clients for.
1061
- *
1062
- * @example
1063
- * ```js
1064
- * fin.me.interop.getAllClientsInContextGroup('red')
1065
- * .then(clientsInContextGroup => {
1066
- * console.log(clientsInContextGroup)
1067
- * })
1068
- * ```
1069
- */
1070
- async getAllClientsInContextGroup(contextGroupId) {
1071
- this.wire.sendAction('interop-client-get-all-clients-in-context-group').catch((e) => {
1072
- // don't expose, analytics-only call
1073
- });
1074
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1075
- if (!contextGroupId) {
1076
- throw new Error('No contextGroupId specified for getAllClientsInContextGroup.');
1077
- }
1078
- return client.dispatch('getAllClientsInContextGroup', { contextGroupId });
1079
- }
1080
- /**
1081
- * Gets display info for a context group
1082
- *
1083
- * @remarks Used by Platform Windows.
1084
- * @param contextGroupId - The id of context group you wish to get display info for.
1085
- *
1086
- * @example
1087
- * ```js
1088
- * fin.me.interop.getInfoForContextGroup('red')
1089
- * .then(contextGroupInfo => {
1090
- * console.log(contextGroupInfo.displayMetadata.name)
1091
- * console.log(contextGroupInfo.displayMetadata.color)
1092
- * })
1093
- * ```
1094
- */
1095
- async getInfoForContextGroup(contextGroupId) {
1096
- this.wire.sendAction('interop-client-get-info-for-context-group').catch((e) => {
1097
- // don't expose, analytics-only call
1098
- });
1099
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1100
- if (!contextGroupId) {
1101
- throw new Error('No contextGroupId specified for getInfoForContextGroup.');
1102
- }
1103
- return client.dispatch('getInfoForContextGroup', { contextGroupId });
1104
- }
1105
- /**
1106
- * Sends an intent to the Interop Broker to resolve.
1107
- * @param intent - The combination of an action and a context that is passed to an application for resolution.
1108
- *
1109
- * @example
1110
- * ```js
1111
- * // View wants to fire an Intent after a user clicks on a ticker
1112
- * tickerElement.on('click', (element) => {
1113
- * const ticker = element.innerText;
1114
- * const intent = {
1115
- * name: 'ViewChart',
1116
- * context: {type: 'fdc3.instrument', id: { ticker }}
1117
- * }
1118
- *
1119
- * fin.me.interop.fireIntent(intent);
1120
- * })
1121
- * ```
1122
- */
1123
- async fireIntent(intent) {
1124
- this.wire.sendAction('interop-client-fire-intent').catch((e) => {
1125
- // don't expose, this is only for api analytics purposes
1126
- });
1127
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1128
- return client.dispatch('fireIntent', intent);
1129
- }
1130
- /**
1131
- * Adds an intent handler for incoming intents. The last intent sent of the name subscribed to will be received.
1132
- * @param handler - Registered function meant to handle a specific intent type.
1133
- * @param intentName - The name of an intent.
1134
- *
1135
- * @example
1136
- * ```js
1137
- * const intentHandler = (intent) => {
1138
- * const { context } = intent;
1139
- * myViewChartHandler(context);
1140
- * };
1141
- *
1142
- * const subscription = await fin.me.interop.registerIntentHandler(intentHandler, 'ViewChart');
1143
- *
1144
- * function myAppCloseSequence() {
1145
- * // to unsubscribe the handler, simply call:
1146
- * subscription.unsubscribe();
1147
- * }
1148
- * ```
1149
- */
1150
- async registerIntentHandler(handler, intentName, options) {
1151
- this.wire.sendAction('interop-client-register-intent-handler').catch((e) => {
1152
- // don't expose, this is only for api analytics purposes
1153
- });
1154
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1155
- const handlerId = `intent-handler-${intentName}`;
1156
- const wrappedHandler = (0, utils_1$2.wrapIntentHandler)(handler, handlerId);
1157
- try {
1158
- await client.register(handlerId, wrappedHandler);
1159
- await client.dispatch('intentHandlerRegistered', { handlerId, ...options });
1160
- }
1161
- catch (error) {
1162
- throw new Error('Unable to register intent handler');
1163
- }
1164
- return {
1165
- unsubscribe: async () => {
1166
- client.remove(handlerId);
1167
- }
1168
- };
1169
- }
1170
- /**
1171
- * Gets the last context of the Context Group currently subscribed to. It takes an optional Context Type and returns the
1172
- * last context of that type.
1173
- * @param contextType
1174
- *
1175
- * @example
1176
- * ```js
1177
- * await fin.me.interop.joinContextGroup('yellow');
1178
- * await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
1179
- * const currentContext = await fin.me.interop.getCurrentContext();
1180
- *
1181
- * // with a specific context
1182
- * await fin.me.interop.joinContextGroup('yellow');
1183
- * await fin.me.interop.setContext({ type: 'country', id: { ISOALPHA3: 'US' }});
1184
- * await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
1185
- * const currentContext = await fin.me.interop.getCurrentContext('country');
1186
- * ```
1187
- */
1188
- async getCurrentContext(contextType) {
1189
- this.wire.sendAction('interop-client-get-current-context').catch((e) => {
1190
- // don't expose, analytics-only call
1191
- });
1192
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1193
- return client.dispatch('getCurrentContext', { contextType });
1194
- }
1195
- /**
1196
- * Get information for a particular Intent from the Interop Broker.
1197
- *
1198
- * @remarks To resolve this info, the function handleInfoForIntent is meant to be overridden in the Interop Broker.
1199
- * The format for the response will be determined by the App Provider overriding the function.
1200
- *
1201
- * @param options
1202
- *
1203
- * @example
1204
- * ```js
1205
- * const intentInfo = await fin.me.interop.getInfoForIntent('ViewChart');
1206
- * ```
1207
- */
1208
- async getInfoForIntent(options) {
1209
- this.wire.sendAction('interop-client-get-info-for-intent').catch((e) => {
1210
- // don't expose, analytics-only call
1211
- });
1212
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1213
- return client.dispatch('getInfoForIntent', options);
1214
- }
1215
- /**
1216
- * Get information from the Interop Broker on all Intents that are meant to handle a particular context.
1217
- *
1218
- * @remarks To resolve this info, the function handleInfoForIntentsByContext is meant to be overridden in the Interop Broker.
1219
- * The format for the response will be determined by the App Provider overriding the function.
1220
- *
1221
- * @param context
1222
- *
1223
- * @example
1224
- * ```js
1225
- * tickerElement.on('click', (element) => {
1226
- * const ticker = element.innerText;
1227
- *
1228
- * const context = {
1229
- * type: 'fdc3.instrument',
1230
- * id: {
1231
- * ticker
1232
- * }
1233
- * }
1234
- *
1235
- * const intentsInfo = await fin.me.interop.getInfoForIntentByContext(context);
1236
- * })
1237
- * ```
1238
- */
1239
- async getInfoForIntentsByContext(context) {
1240
- this.wire.sendAction('interop-client-get-info-for-intents-by-context').catch((e) => {
1241
- // don't expose, analytics-only call
1242
- });
1243
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1244
- return client.dispatch('getInfoForIntentsByContext', context);
1245
- }
1246
- /**
1247
- * Sends a Context that will be resolved to an Intent by the Interop Broker.
1248
- * This context accepts a metadata property.
1249
- *
1250
- * @remarks To resolve this info, the function handleFiredIntentByContext is meant to be overridden in the Interop Broker.
1251
- * The format for the response will be determined by the App Provider overriding the function.
1252
- *
1253
- * @param context
1254
- *
1255
- * @example
1256
- * ```js
1257
- * tickerElement.on('click', (element) => {
1258
- * const ticker = element.innerText;
1259
- *
1260
- * const context = {
1261
- * type: 'fdc3.instrument',
1262
- * id: {
1263
- * ticker
1264
- * }
1265
- * }
1266
- *
1267
- * const intentResolution = await fin.me.interop.fireIntentForContext(context);
1268
- * })
1269
- * ```
1270
- */
1271
- async fireIntentForContext(context) {
1272
- this.wire.sendAction('interop-client-fire-intent-for-context').catch((e) => {
1273
- // don't expose, analytics-only call
1274
- });
1275
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1276
- return client.dispatch('fireIntentForContext', context);
1277
- }
1278
- /**
1279
- * Join the current entity to session context group `sessionContextGroupId` and return a sessionContextGroup instance.
1280
- * If the sessionContextGroup doesn't exist, one will get created.
1281
- *
1282
- * @remarks Session Context Groups do not persist between runs and aren't present on snapshots.
1283
- * @param sessionContextGroupId - Id of the context group.
1284
- *
1285
- * @example
1286
- * Say we want to have a Session Context Group that holds UI theme information for all apps to consume:
1287
- *
1288
- * My color-picker View:
1289
- * ```js
1290
- * const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');
1291
- *
1292
- * const myColorPickerElement = document.getElementById('color-palette-picker');
1293
- * myColorPickerElement.addEventListener('change', event => {
1294
- * themeSessionContextGroup.setContext({ type: 'color-palette', selection: event.value });
1295
- * });
1296
- * ```
1297
- *
1298
- * In other views:
1299
- * ```js
1300
- * const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');
1301
- *
1302
- * const changeColorPalette = ({ selection }) => {
1303
- * // change the color palette to the selection
1304
- * };
1305
- *
1306
- * // If the context is already set by the time the handler was set, the handler will get invoked immediately with the current context.
1307
- * themeSessionContextGroup.addContextHandler(changeColorPalette, 'color-palette');
1308
- * ```
1309
- */
1310
- async joinSessionContextGroup(sessionContextGroupId) {
1311
- try {
1312
- const currentSessionContextGroup = __classPrivateFieldGet(this, _InteropClient_sessionContextGroups, "f").get(sessionContextGroupId);
1313
- if (currentSessionContextGroup) {
1314
- return currentSessionContextGroup.getUserInstance();
1315
- }
1316
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1317
- const { hasConflict } = await client.dispatch('sessionContextGroup:createIfNeeded', {
1318
- sessionContextGroupId
1319
- });
1320
- if (hasConflict) {
1321
- 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.`);
1322
- }
1323
- const newSessionContextGroup = new SessionContextGroupClient_1.default(this.wire, __classPrivateFieldGet(this, _InteropClient_clientPromise, "f"), sessionContextGroupId);
1324
- __classPrivateFieldGet(this, _InteropClient_sessionContextGroups, "f").set(sessionContextGroupId, newSessionContextGroup);
1325
- return newSessionContextGroup.getUserInstance();
1326
- }
1327
- catch (error) {
1328
- console.error(`Error thrown trying to create Session Context Group with id "${sessionContextGroupId}": ${error}`);
1329
- throw error;
1330
- }
1331
- }
1332
- /**
1333
- * Register a listener that is called when the Interop Client has been disconnected from the Interop Broker.
1334
- * Only one listener per Interop Client can be set.
1335
- * @param listener
1336
- *
1337
- * @example
1338
- * ```js
1339
- * const listener = (event) => {
1340
- * const { type, topic, brokerName} = event;
1341
- * console.log(`Disconnected from Interop Broker ${brokerName} `);
1342
- * }
1343
- *
1344
- * await fin.me.interop.onDisconnection(listener);
1345
- * ```
1346
- */
1347
- async onDisconnection(listener) {
1348
- this.wire.sendAction('interop-client-add-ondisconnection-listener').catch((e) => {
1349
- // don't expose, analytics-only call
1350
- });
1351
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1352
- return client.onDisconnection((event) => {
1353
- const { uuid } = event;
1354
- listener({ type: 'interop-broker', topic: 'disconnected', brokerName: uuid });
1355
- });
1356
- }
1357
- /**
1358
- * @internal
1359
- *
1360
- * Used to ferry fdc3-only calls from the fdc3 shim to the Interop Broker
1361
- */
1362
- static async ferryFdc3Call(interopClient, action, payload) {
1363
- const client = await __classPrivateFieldGet(interopClient, _InteropClient_clientPromise, "f");
1364
- return client.dispatch(action, payload || null);
1365
- }
1366
- }
1367
- InteropClient$1.InteropClient = InteropClient;
774
+ var __classPrivateFieldSet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
775
+ if (kind === "m") throw new TypeError("Private method is not writable");
776
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
777
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
778
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
779
+ };
780
+ var __classPrivateFieldGet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
781
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
782
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
783
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
784
+ };
785
+ var _InteropClient_clientPromise, _InteropClient_sessionContextGroups;
786
+ Object.defineProperty(InteropClient$1, "__esModule", { value: true });
787
+ InteropClient$1.InteropClient = void 0;
788
+ const base_1$2 = base;
789
+ const SessionContextGroupClient_1 = SessionContextGroupClient$1;
790
+ const utils_1$2 = utils$1;
791
+ /**
792
+ * The Interop Client API is broken up into two groups:
793
+ *
794
+ * **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.
795
+ *
796
+ * **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.
797
+ *
798
+ * ---
799
+ *
800
+ * All APIs are available at the `fin.me.interop` namespace.
801
+ *
802
+ * ---
803
+ *
804
+ * **You only need 2 things to participate in Interop Context Grouping:**
805
+ * * A Context Handler for incoming context: {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
806
+ * * Call setContext on your context group when you want to share context with other group members: {@link InteropClient#setContext setContext(context)}
807
+ *
808
+ * ---
809
+ *
810
+ * ##### Constructor
811
+ * Returned by {@link Interop.connectSync Interop.connectSync}.
812
+ *
813
+ * ---
814
+ *
815
+ * ##### Interop methods intended for Views
816
+ *
817
+ *
818
+ * **Context Groups API**
819
+ * * {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
820
+ * * {@link InteropClient#setContext setContext(context)}
821
+ * * {@link InteropClient#getCurrentContext getCurrentContext(contextType?)}
822
+ * * {@link InteropClient#joinSessionContextGroup joinSessionContextGroup(sessionContextGroupId)}
823
+ *
824
+ *
825
+ * **Intents API**
826
+ * * {@link InteropClient#fireIntent fireIntent(intent)}
827
+ * * {@link InteropClient#registerIntentHandler registerIntentHandler(intentHandler, intentName)}
828
+ * * {@link InteropClient#getInfoForIntent getInfoForIntent(infoForIntentOptions)}
829
+ * * {@link InteropClient#getInfoForIntentsByContext getInfoForIntentsByContext(context)}
830
+ * * {@link InteropClient#fireIntentForContext fireIntentForContext(contextForIntent)}
831
+ *
832
+ * ##### Interop methods intended for Windows
833
+ * * {@link InteropClient#getContextGroups getContextGroups()}
834
+ * * {@link InteropClient#joinContextGroup joinContextGroup(contextGroupId, target?)}
835
+ * * {@link InteropClient#removeFromContextGroup removeFromContextGroup(target?)}
836
+ * * {@link InteropClient#getInfoForContextGroup getInfoForContextGroup(contextGroupId)}
837
+ * * {@link InteropClient#getAllClientsInContextGroup getAllClientsInContextGroup(contextGroupId)}
838
+ *
839
+ */
840
+ class InteropClient extends base_1$2.Base {
841
+ /**
842
+ * @internal
843
+ */
844
+ constructor(wire, name, interopConfig = {}) {
845
+ super(wire);
846
+ _InteropClient_clientPromise.set(this, void 0);
847
+ _InteropClient_sessionContextGroups.set(this, void 0);
848
+ __classPrivateFieldSet(this, _InteropClient_sessionContextGroups, new Map(), "f");
849
+ __classPrivateFieldSet(this, _InteropClient_clientPromise, this.wire.environment.whenReady().then(() => {
850
+ return this.fin.InterApplicationBus.Channel.connect(`interop-broker-${name}`, {
851
+ payload: interopConfig
852
+ });
853
+ }), "f");
854
+ }
855
+ /*
856
+ Client APIs
857
+ */
858
+ /**
859
+ * Sets a context for the context group of the current entity.
860
+ *
861
+ * @remarks The entity must be part of a context group in order set a context.
862
+ *
863
+ * @param context - New context to set.
864
+ *
865
+ * @example
866
+ * ```js
867
+ * setInstrumentContext = async (ticker) => {
868
+ * fin.me.interop.setContext({type: 'instrument', id: {ticker}})
869
+ * }
870
+ *
871
+ * // The user clicks an instrument of interest. We want to set that Instrument context so that the rest of our workflow updates with information for that instrument
872
+ * instrumentElement.on('click', (evt) => {
873
+ * setInstrumentContext(evt.ticker)
874
+ * })
875
+ * ```
876
+ */
877
+ async setContext(context) {
878
+ this.wire.sendAction('interop-client-set-context').catch((e) => {
879
+ // don't expose, analytics-only call
880
+ });
881
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
882
+ return client.dispatch('setContext', { context });
883
+ }
884
+ /**
885
+ * Add a context handler for incoming context. If an entity is part of a context group, and then sets its context handler,
886
+ * it will receive all of its declared contexts.
887
+ *
888
+ * @param handler - Handler for incoming context.
889
+ * @param contextType - The type of context you wish to handle.
890
+ *
891
+ * @example
892
+ * ```js
893
+ * function handleIncomingContext(contextInfo) {
894
+ * const { type, id } = contextInfo;
895
+ * switch (type) {
896
+ * case 'instrument':
897
+ * handleInstrumentContext(contextInfo);
898
+ * break;
899
+ * case 'country':
900
+ * handleCountryContext(contextInfo);
901
+ * break;
902
+ *
903
+ * default:
904
+ * break;
905
+ * }
906
+ * }
907
+ *
908
+ *
909
+ * function handleInstrumentContext(contextInfo) {
910
+ * const { type, id } = contextInfo;
911
+ * console.log('contextInfo for instrument', contextInfo)
912
+ * }
913
+ *
914
+ * function handleCountryContext(contextInfo) {
915
+ * const { type, id } = contextInfo;
916
+ * console.log('contextInfo for country', contextInfo)
917
+ * }
918
+ *
919
+ * fin.me.interop.addContextHandler(handleIncomingContext);
920
+ * ```
921
+ *
922
+ *
923
+ * We are also testing the ability to add a context handler for specific contexts. If you would like to use
924
+ * this, please make sure you add your context handlers at the top level of your application, on a page that
925
+ * does not navigate/reload/re-render, to avoid memory leaks. This feature is experimental:
926
+ *
927
+ * ```js
928
+ * function handleInstrumentContext(contextInfo) {
929
+ * const { type, id } = contextInfo;
930
+ * console.log('contextInfo for instrument', contextInfo)
931
+ * }
932
+ *
933
+ * function handleCountryContext(contextInfo) {
934
+ * const { type, id } = contextInfo;
935
+ * console.log('contextInfo for country', contextInfo)
936
+ * }
937
+ *
938
+ *
939
+ * fin.me.interop.addContextHandler(handleInstrumentContext, 'instrument')
940
+ * fin.me.interop.addContextHandler(handleCountryContext, 'country')
941
+ * ```
942
+ */
943
+ async addContextHandler(handler, contextType) {
944
+ this.wire.sendAction('interop-client-add-context-handler').catch((e) => {
945
+ // don't expose, analytics-only call
946
+ });
947
+ if (typeof handler !== 'function') {
948
+ throw new Error("Non-function argument passed to the first parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
949
+ }
950
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
951
+ let handlerId;
952
+ if (contextType) {
953
+ handlerId = `invokeContextHandler-${contextType}-${(0, utils_1$2.generateId)()}`;
954
+ 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.`);
955
+ }
956
+ else {
957
+ handlerId = 'invokeContextHandler';
958
+ }
959
+ const wrappedHandler = (0, utils_1$2.wrapContextHandler)(handler, handlerId);
960
+ client.register(handlerId, wrappedHandler);
961
+ await client.dispatch('contextHandlerRegistered', { handlerId, contextType });
962
+ return {
963
+ unsubscribe: async () => {
964
+ client.remove(handlerId);
965
+ await client.dispatch('removeContextHandler', { handlerId });
966
+ }
967
+ };
968
+ }
969
+ /*
970
+ Platform Window APIs
971
+ */
972
+ /**
973
+ * Returns the Interop-Broker-defined context groups available for an entity to join.
974
+ * Used by Platform Windows.
975
+ *
976
+ * @example
977
+ * ```js
978
+ * fin.me.interop.getContextGroups()
979
+ * .then(contextGroups => {
980
+ * contextGroups.forEach(contextGroup => {
981
+ * console.log(contextGroup.displayMetadata.name)
982
+ * console.log(contextGroup.displayMetadata.color)
983
+ * })
984
+ * })
985
+ * ```
986
+ */
987
+ async getContextGroups() {
988
+ this.wire.sendAction('interop-client-get-context-groups').catch((e) => {
989
+ // don't expose, analytics-only call
990
+ });
991
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
992
+ return client.dispatch('getContextGroups');
993
+ }
994
+ /**
995
+ * Join all Interop Clients at the given identity to context group `contextGroupId`.
996
+ * If no target is specified, it adds the sender to the context group.
997
+ *
998
+ * @remarks 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.
999
+ * 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.
1000
+ * 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.
1001
+ * Used by Platform Windows.
1002
+ *
1003
+ * @param contextGroupId - Id of the context group.
1004
+ * @param target - Identity of the entity you wish to join to a context group.
1005
+ *
1006
+ * @example
1007
+ * ```js
1008
+ * joinViewToContextGroup = async (contextGroupId, view) => {
1009
+ * await fin.me.interop.joinContextGroup(contextGroupId, view);
1010
+ * }
1011
+ *
1012
+ * getLastFocusedView()
1013
+ * .then(lastFocusedViewIdentity => {
1014
+ * joinViewToContextGroup('red', lastFocusedViewIdentity)
1015
+ * })
1016
+ * ```
1017
+ */
1018
+ async joinContextGroup(contextGroupId, target) {
1019
+ this.wire.sendAction('interop-client-join-context-group').catch((e) => {
1020
+ // don't expose, analytics-only call
1021
+ });
1022
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1023
+ if (!contextGroupId) {
1024
+ throw new Error('No contextGroupId specified for joinContextGroup.');
1025
+ }
1026
+ return client.dispatch('joinContextGroup', { contextGroupId, target });
1027
+ }
1028
+ /**
1029
+ * Removes the specified target from a context group.
1030
+ * If no target is specified, it removes the sender from their context group.
1031
+ * Used by Platform Windows.
1032
+ *
1033
+ * @param target - Identity of the entity you wish to join to a context group.
1034
+ *
1035
+ * @example
1036
+ * ```js
1037
+ * removeViewFromContextGroup = async (view) => {
1038
+ * await fin.me.interop.removeFromContextGroup(view);
1039
+ * }
1040
+ *
1041
+ * getLastFocusedView()
1042
+ * .then(lastFocusedViewIdentity => {
1043
+ * removeViewFromContextGroup(lastFocusedViewIdentity)
1044
+ * })
1045
+ * ```
1046
+ */
1047
+ async removeFromContextGroup(target) {
1048
+ this.wire.sendAction('interop-client-remove-from-context-group').catch((e) => {
1049
+ // don't expose, analytics-only call
1050
+ });
1051
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1052
+ return client.dispatch('removeFromContextGroup', { target });
1053
+ }
1054
+ /**
1055
+ * Gets all clients for a context group.
1056
+ *
1057
+ * @remarks **This is primarily used for platform windows. Views within a platform should not have to use this API.**
1058
+ *
1059
+ * Returns the Interop-Broker-defined context groups available for an entity to join.
1060
+ * @param contextGroupId - The id of context group you wish to get clients for.
1061
+ *
1062
+ * @example
1063
+ * ```js
1064
+ * fin.me.interop.getAllClientsInContextGroup('red')
1065
+ * .then(clientsInContextGroup => {
1066
+ * console.log(clientsInContextGroup)
1067
+ * })
1068
+ * ```
1069
+ */
1070
+ async getAllClientsInContextGroup(contextGroupId) {
1071
+ this.wire.sendAction('interop-client-get-all-clients-in-context-group').catch((e) => {
1072
+ // don't expose, analytics-only call
1073
+ });
1074
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1075
+ if (!contextGroupId) {
1076
+ throw new Error('No contextGroupId specified for getAllClientsInContextGroup.');
1077
+ }
1078
+ return client.dispatch('getAllClientsInContextGroup', { contextGroupId });
1079
+ }
1080
+ /**
1081
+ * Gets display info for a context group
1082
+ *
1083
+ * @remarks Used by Platform Windows.
1084
+ * @param contextGroupId - The id of context group you wish to get display info for.
1085
+ *
1086
+ * @example
1087
+ * ```js
1088
+ * fin.me.interop.getInfoForContextGroup('red')
1089
+ * .then(contextGroupInfo => {
1090
+ * console.log(contextGroupInfo.displayMetadata.name)
1091
+ * console.log(contextGroupInfo.displayMetadata.color)
1092
+ * })
1093
+ * ```
1094
+ */
1095
+ async getInfoForContextGroup(contextGroupId) {
1096
+ this.wire.sendAction('interop-client-get-info-for-context-group').catch((e) => {
1097
+ // don't expose, analytics-only call
1098
+ });
1099
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1100
+ if (!contextGroupId) {
1101
+ throw new Error('No contextGroupId specified for getInfoForContextGroup.');
1102
+ }
1103
+ return client.dispatch('getInfoForContextGroup', { contextGroupId });
1104
+ }
1105
+ /**
1106
+ * Sends an intent to the Interop Broker to resolve.
1107
+ * @param intent - The combination of an action and a context that is passed to an application for resolution.
1108
+ *
1109
+ * @example
1110
+ * ```js
1111
+ * // View wants to fire an Intent after a user clicks on a ticker
1112
+ * tickerElement.on('click', (element) => {
1113
+ * const ticker = element.innerText;
1114
+ * const intent = {
1115
+ * name: 'ViewChart',
1116
+ * context: {type: 'fdc3.instrument', id: { ticker }}
1117
+ * }
1118
+ *
1119
+ * fin.me.interop.fireIntent(intent);
1120
+ * })
1121
+ * ```
1122
+ */
1123
+ async fireIntent(intent) {
1124
+ this.wire.sendAction('interop-client-fire-intent').catch((e) => {
1125
+ // don't expose, this is only for api analytics purposes
1126
+ });
1127
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1128
+ return client.dispatch('fireIntent', intent);
1129
+ }
1130
+ /**
1131
+ * Adds an intent handler for incoming intents. The last intent sent of the name subscribed to will be received.
1132
+ * @param handler - Registered function meant to handle a specific intent type.
1133
+ * @param intentName - The name of an intent.
1134
+ *
1135
+ * @example
1136
+ * ```js
1137
+ * const intentHandler = (intent) => {
1138
+ * const { context } = intent;
1139
+ * myViewChartHandler(context);
1140
+ * };
1141
+ *
1142
+ * const subscription = await fin.me.interop.registerIntentHandler(intentHandler, 'ViewChart');
1143
+ *
1144
+ * function myAppCloseSequence() {
1145
+ * // to unsubscribe the handler, simply call:
1146
+ * subscription.unsubscribe();
1147
+ * }
1148
+ * ```
1149
+ */
1150
+ async registerIntentHandler(handler, intentName, options) {
1151
+ this.wire.sendAction('interop-client-register-intent-handler').catch((e) => {
1152
+ // don't expose, this is only for api analytics purposes
1153
+ });
1154
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1155
+ const handlerId = `intent-handler-${intentName}`;
1156
+ const wrappedHandler = (0, utils_1$2.wrapIntentHandler)(handler, handlerId);
1157
+ try {
1158
+ await client.register(handlerId, wrappedHandler);
1159
+ await client.dispatch('intentHandlerRegistered', { handlerId, ...options });
1160
+ }
1161
+ catch (error) {
1162
+ throw new Error('Unable to register intent handler');
1163
+ }
1164
+ return {
1165
+ unsubscribe: async () => {
1166
+ client.remove(handlerId);
1167
+ }
1168
+ };
1169
+ }
1170
+ /**
1171
+ * Gets the last context of the Context Group currently subscribed to. It takes an optional Context Type and returns the
1172
+ * last context of that type.
1173
+ * @param contextType
1174
+ *
1175
+ * @example
1176
+ * ```js
1177
+ * await fin.me.interop.joinContextGroup('yellow');
1178
+ * await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
1179
+ * const currentContext = await fin.me.interop.getCurrentContext();
1180
+ *
1181
+ * // with a specific context
1182
+ * await fin.me.interop.joinContextGroup('yellow');
1183
+ * await fin.me.interop.setContext({ type: 'country', id: { ISOALPHA3: 'US' }});
1184
+ * await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
1185
+ * const currentContext = await fin.me.interop.getCurrentContext('country');
1186
+ * ```
1187
+ */
1188
+ async getCurrentContext(contextType) {
1189
+ this.wire.sendAction('interop-client-get-current-context').catch((e) => {
1190
+ // don't expose, analytics-only call
1191
+ });
1192
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1193
+ return client.dispatch('getCurrentContext', { contextType });
1194
+ }
1195
+ /**
1196
+ * Get information for a particular Intent from the Interop Broker.
1197
+ *
1198
+ * @remarks To resolve this info, the function handleInfoForIntent is meant to be overridden in the Interop Broker.
1199
+ * The format for the response will be determined by the App Provider overriding the function.
1200
+ *
1201
+ * @param options
1202
+ *
1203
+ * @example
1204
+ * ```js
1205
+ * const intentInfo = await fin.me.interop.getInfoForIntent('ViewChart');
1206
+ * ```
1207
+ */
1208
+ async getInfoForIntent(options) {
1209
+ this.wire.sendAction('interop-client-get-info-for-intent').catch((e) => {
1210
+ // don't expose, analytics-only call
1211
+ });
1212
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1213
+ return client.dispatch('getInfoForIntent', options);
1214
+ }
1215
+ /**
1216
+ * Get information from the Interop Broker on all Intents that are meant to handle a particular context.
1217
+ *
1218
+ * @remarks To resolve this info, the function handleInfoForIntentsByContext is meant to be overridden in the Interop Broker.
1219
+ * The format for the response will be determined by the App Provider overriding the function.
1220
+ *
1221
+ * @param context
1222
+ *
1223
+ * @example
1224
+ * ```js
1225
+ * tickerElement.on('click', (element) => {
1226
+ * const ticker = element.innerText;
1227
+ *
1228
+ * const context = {
1229
+ * type: 'fdc3.instrument',
1230
+ * id: {
1231
+ * ticker
1232
+ * }
1233
+ * }
1234
+ *
1235
+ * const intentsInfo = await fin.me.interop.getInfoForIntentByContext(context);
1236
+ * })
1237
+ * ```
1238
+ */
1239
+ async getInfoForIntentsByContext(context) {
1240
+ this.wire.sendAction('interop-client-get-info-for-intents-by-context').catch((e) => {
1241
+ // don't expose, analytics-only call
1242
+ });
1243
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1244
+ return client.dispatch('getInfoForIntentsByContext', context);
1245
+ }
1246
+ /**
1247
+ * Sends a Context that will be resolved to an Intent by the Interop Broker.
1248
+ * This context accepts a metadata property.
1249
+ *
1250
+ * @remarks To resolve this info, the function handleFiredIntentByContext is meant to be overridden in the Interop Broker.
1251
+ * The format for the response will be determined by the App Provider overriding the function.
1252
+ *
1253
+ * @param context
1254
+ *
1255
+ * @example
1256
+ * ```js
1257
+ * tickerElement.on('click', (element) => {
1258
+ * const ticker = element.innerText;
1259
+ *
1260
+ * const context = {
1261
+ * type: 'fdc3.instrument',
1262
+ * id: {
1263
+ * ticker
1264
+ * }
1265
+ * }
1266
+ *
1267
+ * const intentResolution = await fin.me.interop.fireIntentForContext(context);
1268
+ * })
1269
+ * ```
1270
+ */
1271
+ async fireIntentForContext(context) {
1272
+ this.wire.sendAction('interop-client-fire-intent-for-context').catch((e) => {
1273
+ // don't expose, analytics-only call
1274
+ });
1275
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1276
+ return client.dispatch('fireIntentForContext', context);
1277
+ }
1278
+ /**
1279
+ * Join the current entity to session context group `sessionContextGroupId` and return a sessionContextGroup instance.
1280
+ * If the sessionContextGroup doesn't exist, one will get created.
1281
+ *
1282
+ * @remarks Session Context Groups do not persist between runs and aren't present on snapshots.
1283
+ * @param sessionContextGroupId - Id of the context group.
1284
+ *
1285
+ * @example
1286
+ * Say we want to have a Session Context Group that holds UI theme information for all apps to consume:
1287
+ *
1288
+ * My color-picker View:
1289
+ * ```js
1290
+ * const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');
1291
+ *
1292
+ * const myColorPickerElement = document.getElementById('color-palette-picker');
1293
+ * myColorPickerElement.addEventListener('change', event => {
1294
+ * themeSessionContextGroup.setContext({ type: 'color-palette', selection: event.value });
1295
+ * });
1296
+ * ```
1297
+ *
1298
+ * In other views:
1299
+ * ```js
1300
+ * const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');
1301
+ *
1302
+ * const changeColorPalette = ({ selection }) => {
1303
+ * // change the color palette to the selection
1304
+ * };
1305
+ *
1306
+ * // If the context is already set by the time the handler was set, the handler will get invoked immediately with the current context.
1307
+ * themeSessionContextGroup.addContextHandler(changeColorPalette, 'color-palette');
1308
+ * ```
1309
+ */
1310
+ async joinSessionContextGroup(sessionContextGroupId) {
1311
+ try {
1312
+ const currentSessionContextGroup = __classPrivateFieldGet(this, _InteropClient_sessionContextGroups, "f").get(sessionContextGroupId);
1313
+ if (currentSessionContextGroup) {
1314
+ return currentSessionContextGroup.getUserInstance();
1315
+ }
1316
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1317
+ const { hasConflict } = await client.dispatch('sessionContextGroup:createIfNeeded', {
1318
+ sessionContextGroupId
1319
+ });
1320
+ if (hasConflict) {
1321
+ 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.`);
1322
+ }
1323
+ const newSessionContextGroup = new SessionContextGroupClient_1.default(this.wire, __classPrivateFieldGet(this, _InteropClient_clientPromise, "f"), sessionContextGroupId);
1324
+ __classPrivateFieldGet(this, _InteropClient_sessionContextGroups, "f").set(sessionContextGroupId, newSessionContextGroup);
1325
+ return newSessionContextGroup.getUserInstance();
1326
+ }
1327
+ catch (error) {
1328
+ console.error(`Error thrown trying to create Session Context Group with id "${sessionContextGroupId}": ${error}`);
1329
+ throw error;
1330
+ }
1331
+ }
1332
+ /**
1333
+ * Register a listener that is called when the Interop Client has been disconnected from the Interop Broker.
1334
+ * Only one listener per Interop Client can be set.
1335
+ * @param listener
1336
+ *
1337
+ * @example
1338
+ * ```js
1339
+ * const listener = (event) => {
1340
+ * const { type, topic, brokerName} = event;
1341
+ * console.log(`Disconnected from Interop Broker ${brokerName} `);
1342
+ * }
1343
+ *
1344
+ * await fin.me.interop.onDisconnection(listener);
1345
+ * ```
1346
+ */
1347
+ async onDisconnection(listener) {
1348
+ this.wire.sendAction('interop-client-add-ondisconnection-listener').catch((e) => {
1349
+ // don't expose, analytics-only call
1350
+ });
1351
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1352
+ return client.onDisconnection((event) => {
1353
+ const { uuid } = event;
1354
+ listener({ type: 'interop-broker', topic: 'disconnected', brokerName: uuid });
1355
+ });
1356
+ }
1357
+ /**
1358
+ * @internal
1359
+ *
1360
+ * Used to ferry fdc3-only calls from the fdc3 shim to the Interop Broker
1361
+ */
1362
+ static async ferryFdc3Call(interopClient, action, payload) {
1363
+ const client = await __classPrivateFieldGet(interopClient, _InteropClient_clientPromise, "f");
1364
+ return client.dispatch(action, payload || null);
1365
+ }
1366
+ }
1367
+ InteropClient$1.InteropClient = InteropClient;
1368
1368
  _InteropClient_clientPromise = new WeakMap(), _InteropClient_sessionContextGroups = new WeakMap();
1369
1369
 
1370
- Object.defineProperty(fdc31_2, "__esModule", { value: true });
1371
- exports.Fdc3Module = fdc31_2.Fdc3Module = void 0;
1372
- const base_1$1 = base;
1373
- const utils_1$1 = utils$2;
1374
- const utils_2$1 = utils$1;
1375
- const InteropClient_1$1 = InteropClient$1;
1376
- const lodash_1 = require$$2;
1377
- /**
1378
- * @version 1.2
1379
- * The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
1380
- * while using our Interop API under the hood. In order to use this set of APIs
1381
- * you will need to set up your own {@link InteropBroker InteropBroker} or use a Platform application, which does the setup for you. Refer to our documentation on
1382
- * our {@link https://developers.openfin.co/of-docs/docs/enable-color-linking Interop API}.
1383
- *
1384
- * To enable the FDC3 APIs in a {@link Window Window} or {@link View View}, add the fdc3InteropApi
1385
- * property to its options:
1386
- *
1387
- * ```js
1388
- * {
1389
- * autoShow: false,
1390
- * saveWindowState: true,
1391
- * url: 'https://openfin.co',
1392
- * fdc3InteropApi: '1.2'
1393
- * }
1394
- * ```
1395
- *
1396
- * If using a {@link Platform Platform } application, you can set this property in defaultWindowOptions and defaultViewOptions.
1397
- *
1398
- * In order to ensure that the FDC3 Api is ready before use, you can use the 'fdc3Ready' event fired on the DOM Window object:
1399
- *
1400
- * ```js
1401
- * function fdc3Action() {
1402
- * // Make some fdc3 API calls here
1403
- * }
1404
- *
1405
- * if (window.fdc3) {
1406
- * fdc3Action();
1407
- * } else {
1408
- * window.addEventListener('fdc3Ready', fdc3Action);
1409
- * }
1410
- * ```
1411
- */
1412
- class Fdc3Module extends base_1$1.Base {
1413
- /**
1414
- * 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. If you wish to listen for all incoming contexts, pass `null` for the contextType argument.
1415
- * @param contextType - The type of context you wish to handle.
1416
- * @param handler - Handler for incoming context.
1417
- *
1418
- * @tutorial fdc3.addContextListener
1419
- * @static
1420
- */
1421
- addContextListener(contextType, handler) {
1422
- this.wire.sendAction('fdc3-add-context-listener').catch((e) => {
1423
- // we do not want to expose this error, just continue if this analytics-only call fails
1424
- });
1425
- let listener;
1426
- if (typeof contextType === 'function') {
1427
- console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
1428
- listener = this.fin.me.interop.addContextHandler(contextType);
1429
- }
1430
- else {
1431
- listener = this.fin.me.interop.addContextHandler(handler, contextType === null ? undefined : contextType);
1432
- }
1433
- return {
1434
- ...listener,
1435
- unsubscribe: () => listener.then((l) => l.unsubscribe())
1436
- };
1437
- }
1438
- /**
1439
- * Broadcasts a context for the channel of the current entity.
1440
- * @param context - New context to set.
1441
- *
1442
- * @tutorial fdc3.broadcast
1443
- * @static
1444
- */
1445
- async broadcast(context) {
1446
- this.wire.sendAction('fdc3-broadcast').catch((e) => {
1447
- // we do not want to expose this error, just continue if this analytics-only call fails
1448
- });
1449
- return this.fin.me.interop.setContext(context);
1450
- }
1451
- /**
1452
- * Returns the Interop-Broker-defined context groups available for an entity to join.
1453
- *
1454
- * @tutorial fdc3.getSystemChannels
1455
- * @static
1456
- */
1457
- async getSystemChannels() {
1458
- this.wire.sendAction('fdc3-get-system-channels').catch((e) => {
1459
- // we do not want to expose this error, just continue if this analytics-only call fails
1460
- });
1461
- const channels = await this.fin.me.interop.getContextGroups();
1462
- // fdc3 implementation of getSystemChannels returns on array of channels, have to decorate over
1463
- // this so people know that these APIs are not supported
1464
- return channels.map((channel) => {
1465
- return { ...channel, type: 'system', ...(0, utils_1$1.getUnsupportedChannelApis)() };
1466
- });
1467
- }
1468
- /**
1469
- * Join all Interop Clients at the given identity to context group `contextGroupId`.
1470
- * If no target is specified, it adds the sender to the context group.
1471
- * 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.
1472
- * 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.
1473
- * For all intents and purposes, there will only be 1 connection present in Platform and Browser implementations, so this point is more-or-less moot.
1474
- * @param channelId - Id of the context group.
1475
- *
1476
- * @tutorial fdc3.joinChannel
1477
- * @static
1478
- */
1479
- async joinChannel(channelId) {
1480
- this.wire.sendAction('fdc3-join-channel').catch((e) => {
1481
- // we do not want to expose this error, just continue if this analytics-only call fails
1482
- });
1483
- try {
1484
- return await this.fin.me.interop.joinContextGroup(channelId);
1485
- }
1486
- catch (error) {
1487
- if (error.message === utils_2$1.BROKER_ERRORS.joinSessionContextGroupWithJoinContextGroup) {
1488
- console.error('The Channel you have tried to join is an App Channel. Custom Channels can only be defined by the Interop Broker through code or manifest configuration. Please use getOrCreateChannel.');
1489
- }
1490
- else {
1491
- console.error(error.message);
1492
- }
1493
- if (error.message.startsWith('Attempting to join a context group that does not exist')) {
1494
- throw new Error(utils_1$1.ChannelError.NoChannelFound);
1495
- }
1496
- throw new Error(utils_1$1.ChannelError.AccessDenied);
1497
- }
1498
- }
1499
- /**
1500
- * Removes the specified target from a context group.
1501
- * If no target is specified, it removes the sender from their context group.
1502
- *
1503
- * @tutorial fdc3.leaveCurrentChannel
1504
- * @static
1505
- */
1506
- async leaveCurrentChannel() {
1507
- this.wire.sendAction('fdc3-leave-current-channel').catch((e) => {
1508
- // we do not want to expose this error, just continue if this analytics-only call fails
1509
- });
1510
- return this.fin.me.interop.removeFromContextGroup();
1511
- }
1512
- /**
1513
- * Adds a listener for incoming Intents.
1514
- * @param intent - Name of the Intent
1515
- * @param handler - Handler for incoming Intent
1516
- *
1517
- * @tutorial fdc3.addIntentListener
1518
- * @static
1519
- */
1520
- addIntentListener(intent, handler) {
1521
- this.wire.sendAction('fdc3-add-intent-listener').catch((e) => {
1522
- // we do not want to expose this error, just continue if this analytics-only call fails
1523
- });
1524
- const contextHandler = (raisedIntent) => {
1525
- const { context, metadata: intentMetadata } = raisedIntent;
1526
- const { metadata } = context;
1527
- const intentResolutionResultId = intentMetadata?.intentResolutionResultId || metadata?.intentResolutionResultId;
1528
- if (intentResolutionResultId) {
1529
- this.fin.InterApplicationBus.publish(intentResolutionResultId, null);
1530
- }
1531
- handler(raisedIntent.context);
1532
- };
1533
- const listener = this.fin.me.interop.registerIntentHandler(contextHandler, intent, {
1534
- fdc3Version: '1.2'
1535
- });
1536
- return {
1537
- ...listener,
1538
- unsubscribe: () => listener.then((l) => l.unsubscribe())
1539
- };
1540
- }
1541
- /**
1542
- * Raises a specific intent.
1543
- * @param intent Name of the Intent.
1544
- * @param context Context associated with the Intent.
1545
- * @param app App that will resolve the Intent. This is added as metadata to the Intent. Can be accessed by the app provider in {@link InteropBroker#handleFiredIntent InteropBroker.handleFiredIntent}.
1546
- *
1547
- * @tutorial fdc3.raiseIntent
1548
- * @static
1549
- */
1550
- async raiseIntent(intent, context, app) {
1551
- this.wire.sendAction('fdc3-raise-intent').catch((e) => {
1552
- // we do not want to expose this error, just continue if this analytics-only call fails
1553
- });
1554
- const intentObj = app
1555
- ? { name: intent, context, metadata: { target: app } }
1556
- : { name: intent, context };
1557
- try {
1558
- return await this.fin.me.interop.fireIntent(intentObj);
1559
- }
1560
- catch (error) {
1561
- const errorToThrow = error.message === utils_2$1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
1562
- throw new Error(errorToThrow);
1563
- }
1564
- }
1565
- /**
1566
- * Returns the Channel that the entity is subscribed to. Returns null if not joined to a channel.
1567
- *
1568
- * @tutorial fdc3.getCurrentChannel
1569
- */
1570
- async getCurrentChannel() {
1571
- this.wire.sendAction('fdc3-get-current-channel').catch((e) => {
1572
- // we do not want to expose this error, just continue if this analytics-only call fails
1573
- });
1574
- const currentContextGroupInfo = await this.getCurrentContextGroupInfo();
1575
- if (!currentContextGroupInfo) {
1576
- return null;
1577
- }
1578
- return this.buildChannelObject(currentContextGroupInfo);
1579
- }
1580
- /**
1581
- * Find out more information about a particular intent by passing its name, and optionally its context.
1582
- * @param intent Name of the Intent
1583
- * @param context
1584
- *
1585
- * @tutorial fdc3.findIntent
1586
- */
1587
- async findIntent(intent, context) {
1588
- this.wire.sendAction('fdc3-find-intent').catch((e) => {
1589
- // we do not want to expose this error, just continue if this analytics-only call fails
1590
- });
1591
- try {
1592
- return await this.fin.me.interop.getInfoForIntent({ name: intent, context });
1593
- }
1594
- catch (error) {
1595
- const errorToThrow = error.message === utils_2$1.BROKER_ERRORS.getInfoForIntent ? 'ResolverUnavailable' : error.message;
1596
- throw new Error(errorToThrow);
1597
- }
1598
- }
1599
- /**
1600
- * Find all the available intents for a particular context.
1601
- * @param context
1602
- *
1603
- * @tutorial fdc3.findIntentsByContext
1604
- */
1605
- async findIntentsByContext(context) {
1606
- this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
1607
- // we do not want to expose this error, just continue if this analytics-only call fails
1608
- });
1609
- try {
1610
- return await this.fin.me.interop.getInfoForIntentsByContext(context);
1611
- }
1612
- catch (error) {
1613
- const errorToThrow = error.message === utils_2$1.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error.message;
1614
- throw new Error(errorToThrow);
1615
- }
1616
- }
1617
- /**
1618
- * Finds and raises an intent against a target app based purely on context data.
1619
- * @param context
1620
- * @param app
1621
- *
1622
- * @tutorial fdc3.raiseIntentForContext
1623
- */
1624
- async raiseIntentForContext(context, app) {
1625
- this.wire.sendAction('fdc3-raise-intent-for-context').catch((e) => {
1626
- // we do not want to expose this error, just continue if this analytics-only call fails
1627
- });
1628
- try {
1629
- return await this.fin.me.interop.fireIntentForContext({ ...context, metadata: { target: app } });
1630
- }
1631
- catch (error) {
1632
- const errorToThrow = error.message === utils_2$1.BROKER_ERRORS.fireIntentForContext ? 'ResolverUnavailable' : error.message;
1633
- throw new Error(errorToThrow);
1634
- }
1635
- }
1636
- /**
1637
- * Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
1638
- * @param channelId
1639
- *
1640
- * @tutorial fdc3.getOrCreateChannel
1641
- */
1642
- async getOrCreateChannel(channelId) {
1643
- this.wire.sendAction('fdc3-get-or-create-channel').catch((e) => {
1644
- // we do not want to expose this error, just continue if this analytics-only call fails
1645
- });
1646
- const systemChannels = await this.getSystemChannels();
1647
- const userChannel = systemChannels.find((channel) => channel.id === channelId);
1648
- if (userChannel) {
1649
- return { ...userChannel, type: 'system', ...(0, utils_1$1.getUnsupportedChannelApis)() };
1650
- }
1651
- try {
1652
- const sessionContextGroup = await this.fin.me.interop.joinSessionContextGroup(channelId);
1653
- return (0, utils_1$1.buildAppChannelObject)(sessionContextGroup);
1654
- }
1655
- catch (error) {
1656
- console.error(error.message);
1657
- throw new Error(utils_1$1.ChannelError.CreationFailed);
1658
- }
1659
- }
1660
- /**
1661
- * Returns metadata relating to the FDC3 object and its provider, including the supported version of the FDC3 specification and the name of the provider of the implementation.
1662
- *
1663
- * @tutorial fdc3.getInfo
1664
- */
1665
- getInfo() {
1666
- this.wire.sendAction('fdc3-get-info').catch((e) => {
1667
- // we do not want to expose this error, just continue if this analytics-only call fails
1668
- });
1669
- // @ts-expect-error
1670
- const { uuid, fdc3InteropApi } = fin.__internal_.initialOptions;
1671
- // @ts-expect-error
1672
- const runtimeVersion = fin.desktop.getVersion();
1673
- return {
1674
- fdc3Version: fdc3InteropApi,
1675
- provider: `openfin-${uuid}`,
1676
- providerVersion: runtimeVersion
1677
- };
1678
- }
1679
- /**
1680
- * Launches an app with target information, which can either be a string or an AppMetadata object.
1681
- * @param app
1682
- * @param context
1683
- *
1684
- * @tutorial fdc3.open
1685
- */
1686
- async open(app, context) {
1687
- this.wire.sendAction('fdc3-open').catch((e) => {
1688
- // we do not want to expose this error, just continue if this analytics-only call fails
1689
- });
1690
- try {
1691
- return await InteropClient_1$1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'fdc3Open', { app, context });
1692
- }
1693
- catch (error) {
1694
- const errorToThrow = error.message === utils_2$1.BROKER_ERRORS.fdc3Open ? 'ResolverUnavailable' : error.message;
1695
- throw new Error(errorToThrow);
1696
- }
1697
- }
1698
- // utils
1699
- // eslint-disable-next-line class-methods-use-this
1700
- async getCurrentContextGroupInfo() {
1701
- const contextGroups = await this.fin.me.interop.getContextGroups();
1702
- const clientsInCtxGroupsPromise = contextGroups.map(async (ctxGroup) => {
1703
- return this.fin.me.interop.getAllClientsInContextGroup(ctxGroup.id);
1704
- });
1705
- const clientsInCtxGroups = await Promise.all(clientsInCtxGroupsPromise);
1706
- const clientIdx = clientsInCtxGroups.findIndex((clientIdentityArr) => {
1707
- return clientIdentityArr.some((clientIdentity) => {
1708
- const { uuid, name } = clientIdentity;
1709
- return this.fin.me.uuid === uuid && this.fin.me.name === name;
1710
- });
1711
- });
1712
- return contextGroups[clientIdx];
1713
- }
1714
- async buildChannelObject(currentContextGroupInfo) {
1715
- return {
1716
- ...currentContextGroupInfo,
1717
- type: 'system',
1718
- addContextListener: (contextType, handler) => {
1719
- let realHandler;
1720
- let realType;
1721
- if (typeof contextType === 'function') {
1722
- console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
1723
- realHandler = contextType;
1724
- }
1725
- else {
1726
- realHandler = handler;
1727
- if (typeof contextType === 'string') {
1728
- realType = contextType;
1729
- }
1730
- }
1731
- const listener = (async () => {
1732
- let first = true;
1733
- const currentContext = await this.fin.me.interop.getCurrentContext(realType);
1734
- const wrappedHandler = (context, contextMetadata) => {
1735
- if (first) {
1736
- first = false;
1737
- if ((0, lodash_1.isEqual)(currentContext, context)) {
1738
- return;
1739
- }
1740
- }
1741
- // eslint-disable-next-line consistent-return
1742
- return realHandler(context, contextMetadata);
1743
- };
1744
- return this.fin.me.interop.addContextHandler(wrappedHandler, realType);
1745
- })();
1746
- return {
1747
- ...listener,
1748
- unsubscribe: () => listener.then((l) => l.unsubscribe())
1749
- };
1750
- },
1751
- broadcast: this.broadcast.bind(this),
1752
- getCurrentContext: async (contextType) => {
1753
- const context = await this.fin.me.interop.getCurrentContext(contextType);
1754
- return context === undefined ? null : context;
1755
- }
1756
- };
1757
- }
1758
- }
1370
+ Object.defineProperty(fdc31_2, "__esModule", { value: true });
1371
+ exports.Fdc3Module = fdc31_2.Fdc3Module = void 0;
1372
+ const base_1$1 = base;
1373
+ const utils_1$1 = utils$2;
1374
+ const utils_2$1 = utils$1;
1375
+ const InteropClient_1$1 = InteropClient$1;
1376
+ const lodash_1 = require$$2;
1377
+ /**
1378
+ * @version 1.2
1379
+ * The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
1380
+ * while using our Interop API under the hood. In order to use this set of APIs
1381
+ * you will need to set up your own {@link InteropBroker InteropBroker} or use a Platform application, which does the setup for you. Refer to our documentation on
1382
+ * our {@link https://developers.openfin.co/of-docs/docs/enable-color-linking Interop API}.
1383
+ *
1384
+ * To enable the FDC3 APIs in a {@link Window Window} or {@link View View}, add the fdc3InteropApi
1385
+ * property to its options:
1386
+ *
1387
+ * ```js
1388
+ * {
1389
+ * autoShow: false,
1390
+ * saveWindowState: true,
1391
+ * url: 'https://openfin.co',
1392
+ * fdc3InteropApi: '1.2'
1393
+ * }
1394
+ * ```
1395
+ *
1396
+ * If using a {@link Platform Platform } application, you can set this property in defaultWindowOptions and defaultViewOptions.
1397
+ *
1398
+ * In order to ensure that the FDC3 Api is ready before use, you can use the 'fdc3Ready' event fired on the DOM Window object:
1399
+ *
1400
+ * ```js
1401
+ * function fdc3Action() {
1402
+ * // Make some fdc3 API calls here
1403
+ * }
1404
+ *
1405
+ * if (window.fdc3) {
1406
+ * fdc3Action();
1407
+ * } else {
1408
+ * window.addEventListener('fdc3Ready', fdc3Action);
1409
+ * }
1410
+ * ```
1411
+ */
1412
+ class Fdc3Module extends base_1$1.Base {
1413
+ /**
1414
+ * 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. If you wish to listen for all incoming contexts, pass `null` for the contextType argument.
1415
+ * @param contextType - The type of context you wish to handle.
1416
+ * @param handler - Handler for incoming context.
1417
+ *
1418
+ * @tutorial fdc3.addContextListener
1419
+ * @static
1420
+ */
1421
+ addContextListener(contextType, handler) {
1422
+ this.wire.sendAction('fdc3-add-context-listener').catch((e) => {
1423
+ // we do not want to expose this error, just continue if this analytics-only call fails
1424
+ });
1425
+ let listener;
1426
+ if (typeof contextType === 'function') {
1427
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
1428
+ listener = this.fin.me.interop.addContextHandler(contextType);
1429
+ }
1430
+ else {
1431
+ listener = this.fin.me.interop.addContextHandler(handler, contextType === null ? undefined : contextType);
1432
+ }
1433
+ return {
1434
+ ...listener,
1435
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
1436
+ };
1437
+ }
1438
+ /**
1439
+ * Broadcasts a context for the channel of the current entity.
1440
+ * @param context - New context to set.
1441
+ *
1442
+ * @tutorial fdc3.broadcast
1443
+ * @static
1444
+ */
1445
+ async broadcast(context) {
1446
+ this.wire.sendAction('fdc3-broadcast').catch((e) => {
1447
+ // we do not want to expose this error, just continue if this analytics-only call fails
1448
+ });
1449
+ return this.fin.me.interop.setContext(context);
1450
+ }
1451
+ /**
1452
+ * Returns the Interop-Broker-defined context groups available for an entity to join.
1453
+ *
1454
+ * @tutorial fdc3.getSystemChannels
1455
+ * @static
1456
+ */
1457
+ async getSystemChannels() {
1458
+ this.wire.sendAction('fdc3-get-system-channels').catch((e) => {
1459
+ // we do not want to expose this error, just continue if this analytics-only call fails
1460
+ });
1461
+ const channels = await this.fin.me.interop.getContextGroups();
1462
+ // fdc3 implementation of getSystemChannels returns on array of channels, have to decorate over
1463
+ // this so people know that these APIs are not supported
1464
+ return channels.map((channel) => {
1465
+ return { ...channel, type: 'system', ...(0, utils_1$1.getUnsupportedChannelApis)() };
1466
+ });
1467
+ }
1468
+ /**
1469
+ * Join all Interop Clients at the given identity to context group `contextGroupId`.
1470
+ * If no target is specified, it adds the sender to the context group.
1471
+ * 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.
1472
+ * 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.
1473
+ * For all intents and purposes, there will only be 1 connection present in Platform and Browser implementations, so this point is more-or-less moot.
1474
+ * @param channelId - Id of the context group.
1475
+ *
1476
+ * @tutorial fdc3.joinChannel
1477
+ * @static
1478
+ */
1479
+ async joinChannel(channelId) {
1480
+ this.wire.sendAction('fdc3-join-channel').catch((e) => {
1481
+ // we do not want to expose this error, just continue if this analytics-only call fails
1482
+ });
1483
+ try {
1484
+ return await this.fin.me.interop.joinContextGroup(channelId);
1485
+ }
1486
+ catch (error) {
1487
+ if (error.message === utils_2$1.BROKER_ERRORS.joinSessionContextGroupWithJoinContextGroup) {
1488
+ console.error('The Channel you have tried to join is an App Channel. Custom Channels can only be defined by the Interop Broker through code or manifest configuration. Please use getOrCreateChannel.');
1489
+ }
1490
+ else {
1491
+ console.error(error.message);
1492
+ }
1493
+ if (error.message.startsWith('Attempting to join a context group that does not exist')) {
1494
+ throw new Error(utils_1$1.ChannelError.NoChannelFound);
1495
+ }
1496
+ throw new Error(utils_1$1.ChannelError.AccessDenied);
1497
+ }
1498
+ }
1499
+ /**
1500
+ * Removes the specified target from a context group.
1501
+ * If no target is specified, it removes the sender from their context group.
1502
+ *
1503
+ * @tutorial fdc3.leaveCurrentChannel
1504
+ * @static
1505
+ */
1506
+ async leaveCurrentChannel() {
1507
+ this.wire.sendAction('fdc3-leave-current-channel').catch((e) => {
1508
+ // we do not want to expose this error, just continue if this analytics-only call fails
1509
+ });
1510
+ return this.fin.me.interop.removeFromContextGroup();
1511
+ }
1512
+ /**
1513
+ * Adds a listener for incoming Intents.
1514
+ * @param intent - Name of the Intent
1515
+ * @param handler - Handler for incoming Intent
1516
+ *
1517
+ * @tutorial fdc3.addIntentListener
1518
+ * @static
1519
+ */
1520
+ addIntentListener(intent, handler) {
1521
+ this.wire.sendAction('fdc3-add-intent-listener').catch((e) => {
1522
+ // we do not want to expose this error, just continue if this analytics-only call fails
1523
+ });
1524
+ const contextHandler = (raisedIntent) => {
1525
+ const { context, metadata: intentMetadata } = raisedIntent;
1526
+ const { metadata } = context;
1527
+ const intentResolutionResultId = intentMetadata?.intentResolutionResultId || metadata?.intentResolutionResultId;
1528
+ if (intentResolutionResultId) {
1529
+ this.fin.InterApplicationBus.publish(intentResolutionResultId, null);
1530
+ }
1531
+ handler(raisedIntent.context);
1532
+ };
1533
+ const listener = this.fin.me.interop.registerIntentHandler(contextHandler, intent, {
1534
+ fdc3Version: '1.2'
1535
+ });
1536
+ return {
1537
+ ...listener,
1538
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
1539
+ };
1540
+ }
1541
+ /**
1542
+ * Raises a specific intent.
1543
+ * @param intent Name of the Intent.
1544
+ * @param context Context associated with the Intent.
1545
+ * @param app App that will resolve the Intent. This is added as metadata to the Intent. Can be accessed by the app provider in {@link InteropBroker#handleFiredIntent InteropBroker.handleFiredIntent}.
1546
+ *
1547
+ * @tutorial fdc3.raiseIntent
1548
+ * @static
1549
+ */
1550
+ async raiseIntent(intent, context, app) {
1551
+ this.wire.sendAction('fdc3-raise-intent').catch((e) => {
1552
+ // we do not want to expose this error, just continue if this analytics-only call fails
1553
+ });
1554
+ const intentObj = app
1555
+ ? { name: intent, context, metadata: { target: app } }
1556
+ : { name: intent, context };
1557
+ try {
1558
+ return await this.fin.me.interop.fireIntent(intentObj);
1559
+ }
1560
+ catch (error) {
1561
+ const errorToThrow = error.message === utils_2$1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
1562
+ throw new Error(errorToThrow);
1563
+ }
1564
+ }
1565
+ /**
1566
+ * Returns the Channel that the entity is subscribed to. Returns null if not joined to a channel.
1567
+ *
1568
+ * @tutorial fdc3.getCurrentChannel
1569
+ */
1570
+ async getCurrentChannel() {
1571
+ this.wire.sendAction('fdc3-get-current-channel').catch((e) => {
1572
+ // we do not want to expose this error, just continue if this analytics-only call fails
1573
+ });
1574
+ const currentContextGroupInfo = await this.getCurrentContextGroupInfo();
1575
+ if (!currentContextGroupInfo) {
1576
+ return null;
1577
+ }
1578
+ return this.buildChannelObject(currentContextGroupInfo);
1579
+ }
1580
+ /**
1581
+ * Find out more information about a particular intent by passing its name, and optionally its context.
1582
+ * @param intent Name of the Intent
1583
+ * @param context
1584
+ *
1585
+ * @tutorial fdc3.findIntent
1586
+ */
1587
+ async findIntent(intent, context) {
1588
+ this.wire.sendAction('fdc3-find-intent').catch((e) => {
1589
+ // we do not want to expose this error, just continue if this analytics-only call fails
1590
+ });
1591
+ try {
1592
+ return await this.fin.me.interop.getInfoForIntent({ name: intent, context });
1593
+ }
1594
+ catch (error) {
1595
+ const errorToThrow = error.message === utils_2$1.BROKER_ERRORS.getInfoForIntent ? 'ResolverUnavailable' : error.message;
1596
+ throw new Error(errorToThrow);
1597
+ }
1598
+ }
1599
+ /**
1600
+ * Find all the available intents for a particular context.
1601
+ * @param context
1602
+ *
1603
+ * @tutorial fdc3.findIntentsByContext
1604
+ */
1605
+ async findIntentsByContext(context) {
1606
+ this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
1607
+ // we do not want to expose this error, just continue if this analytics-only call fails
1608
+ });
1609
+ try {
1610
+ return await this.fin.me.interop.getInfoForIntentsByContext(context);
1611
+ }
1612
+ catch (error) {
1613
+ const errorToThrow = error.message === utils_2$1.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error.message;
1614
+ throw new Error(errorToThrow);
1615
+ }
1616
+ }
1617
+ /**
1618
+ * Finds and raises an intent against a target app based purely on context data.
1619
+ * @param context
1620
+ * @param app
1621
+ *
1622
+ * @tutorial fdc3.raiseIntentForContext
1623
+ */
1624
+ async raiseIntentForContext(context, app) {
1625
+ this.wire.sendAction('fdc3-raise-intent-for-context').catch((e) => {
1626
+ // we do not want to expose this error, just continue if this analytics-only call fails
1627
+ });
1628
+ try {
1629
+ return await this.fin.me.interop.fireIntentForContext({ ...context, metadata: { target: app } });
1630
+ }
1631
+ catch (error) {
1632
+ const errorToThrow = error.message === utils_2$1.BROKER_ERRORS.fireIntentForContext ? 'ResolverUnavailable' : error.message;
1633
+ throw new Error(errorToThrow);
1634
+ }
1635
+ }
1636
+ /**
1637
+ * Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
1638
+ * @param channelId
1639
+ *
1640
+ * @tutorial fdc3.getOrCreateChannel
1641
+ */
1642
+ async getOrCreateChannel(channelId) {
1643
+ this.wire.sendAction('fdc3-get-or-create-channel').catch((e) => {
1644
+ // we do not want to expose this error, just continue if this analytics-only call fails
1645
+ });
1646
+ const systemChannels = await this.getSystemChannels();
1647
+ const userChannel = systemChannels.find((channel) => channel.id === channelId);
1648
+ if (userChannel) {
1649
+ return { ...userChannel, type: 'system', ...(0, utils_1$1.getUnsupportedChannelApis)() };
1650
+ }
1651
+ try {
1652
+ const sessionContextGroup = await this.fin.me.interop.joinSessionContextGroup(channelId);
1653
+ return (0, utils_1$1.buildAppChannelObject)(sessionContextGroup);
1654
+ }
1655
+ catch (error) {
1656
+ console.error(error.message);
1657
+ throw new Error(utils_1$1.ChannelError.CreationFailed);
1658
+ }
1659
+ }
1660
+ /**
1661
+ * Returns metadata relating to the FDC3 object and its provider, including the supported version of the FDC3 specification and the name of the provider of the implementation.
1662
+ *
1663
+ * @tutorial fdc3.getInfo
1664
+ */
1665
+ getInfo() {
1666
+ this.wire.sendAction('fdc3-get-info').catch((e) => {
1667
+ // we do not want to expose this error, just continue if this analytics-only call fails
1668
+ });
1669
+ // @ts-expect-error
1670
+ const { uuid, fdc3InteropApi } = fin.__internal_.initialOptions;
1671
+ // @ts-expect-error
1672
+ const runtimeVersion = fin.desktop.getVersion();
1673
+ return {
1674
+ fdc3Version: fdc3InteropApi,
1675
+ provider: `openfin-${uuid}`,
1676
+ providerVersion: runtimeVersion
1677
+ };
1678
+ }
1679
+ /**
1680
+ * Launches an app with target information, which can either be a string or an AppMetadata object.
1681
+ * @param app
1682
+ * @param context
1683
+ *
1684
+ * @tutorial fdc3.open
1685
+ */
1686
+ async open(app, context) {
1687
+ this.wire.sendAction('fdc3-open').catch((e) => {
1688
+ // we do not want to expose this error, just continue if this analytics-only call fails
1689
+ });
1690
+ try {
1691
+ return await InteropClient_1$1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'fdc3Open', { app, context });
1692
+ }
1693
+ catch (error) {
1694
+ const errorToThrow = error.message === utils_2$1.BROKER_ERRORS.fdc3Open ? 'ResolverUnavailable' : error.message;
1695
+ throw new Error(errorToThrow);
1696
+ }
1697
+ }
1698
+ // utils
1699
+ // eslint-disable-next-line class-methods-use-this
1700
+ async getCurrentContextGroupInfo() {
1701
+ const contextGroups = await this.fin.me.interop.getContextGroups();
1702
+ const clientsInCtxGroupsPromise = contextGroups.map(async (ctxGroup) => {
1703
+ return this.fin.me.interop.getAllClientsInContextGroup(ctxGroup.id);
1704
+ });
1705
+ const clientsInCtxGroups = await Promise.all(clientsInCtxGroupsPromise);
1706
+ const clientIdx = clientsInCtxGroups.findIndex((clientIdentityArr) => {
1707
+ return clientIdentityArr.some((clientIdentity) => {
1708
+ const { uuid, name } = clientIdentity;
1709
+ return this.fin.me.uuid === uuid && this.fin.me.name === name;
1710
+ });
1711
+ });
1712
+ return contextGroups[clientIdx];
1713
+ }
1714
+ async buildChannelObject(currentContextGroupInfo) {
1715
+ return {
1716
+ ...currentContextGroupInfo,
1717
+ type: 'system',
1718
+ addContextListener: (contextType, handler) => {
1719
+ let realHandler;
1720
+ let realType;
1721
+ if (typeof contextType === 'function') {
1722
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
1723
+ realHandler = contextType;
1724
+ }
1725
+ else {
1726
+ realHandler = handler;
1727
+ if (typeof contextType === 'string') {
1728
+ realType = contextType;
1729
+ }
1730
+ }
1731
+ const listener = (async () => {
1732
+ let first = true;
1733
+ const currentContext = await this.fin.me.interop.getCurrentContext(realType);
1734
+ const wrappedHandler = (context, contextMetadata) => {
1735
+ if (first) {
1736
+ first = false;
1737
+ if ((0, lodash_1.isEqual)(currentContext, context)) {
1738
+ return;
1739
+ }
1740
+ }
1741
+ // eslint-disable-next-line consistent-return
1742
+ return realHandler(context, contextMetadata);
1743
+ };
1744
+ return this.fin.me.interop.addContextHandler(wrappedHandler, realType);
1745
+ })();
1746
+ return {
1747
+ ...listener,
1748
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
1749
+ };
1750
+ },
1751
+ broadcast: this.broadcast.bind(this),
1752
+ getCurrentContext: async (contextType) => {
1753
+ const context = await this.fin.me.interop.getCurrentContext(contextType);
1754
+ return context === undefined ? null : context;
1755
+ }
1756
+ };
1757
+ }
1758
+ }
1759
1759
  exports.Fdc3Module = fdc31_2.Fdc3Module = Fdc3Module;
1760
1760
 
1761
1761
  var fdc3 = {};
1762
1762
 
1763
1763
  var fdc32_0 = {};
1764
1764
 
1765
- Object.defineProperty(fdc32_0, "__esModule", { value: true });
1766
- exports.Fdc3Module2 = fdc32_0.Fdc3Module2 = void 0;
1767
- const base_1 = base;
1768
- const utils_1 = utils$1;
1769
- const InteropClient_1 = InteropClient$1;
1770
- const utils_2 = utils$2;
1771
- const fdc3_1_2_1 = fdc31_2;
1772
- const PrivateChannelClient_1 = PrivateChannelClient$1;
1773
- /**
1774
- * @version 2.0
1775
- * The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
1776
- * while using our Interop API under the hood. In order to use this set of APIs
1777
- * you will need to set up your own {@link InteropBroker InteropBroker} or use a Platform application, which does the setup for you. Refer to our documentation on
1778
- * our {@link https://developers.openfin.co/of-docs/docs/enable-context-sharing Interop API}.
1779
- *
1780
- * To enable the FDC3 APIs in a {@link Window Window} or {@link View View}, add the fdc3InteropApi
1781
- * property to its options:
1782
- *
1783
- * ```js
1784
- * {
1785
- * autoShow: false,
1786
- * saveWindowState: true,
1787
- * url: 'https://openfin.co',
1788
- * fdc3InteropApi: '2.0'
1789
- * }
1790
- * ```
1791
- *
1792
- * If using a {@link Platform Platform } application, you can set this property in defaultWindowOptions and defaultViewOptions.
1793
- *
1794
- * In order to ensure that the FDC3 Api is ready before use, you can use the 'fdc3Ready' event fired on the DOM Window object:
1795
- *
1796
- * ```js
1797
- * function fdc3Action() {
1798
- * // Make some fdc3 API calls here
1799
- * }
1800
- *
1801
- * if (window.fdc3) {
1802
- * fdc3Action();
1803
- * } else {
1804
- * window.addEventListener('fdc3Ready', fdc3Action);
1805
- * }
1806
- * ```
1807
- */
1808
- class Fdc3Module2 extends base_1.Base {
1809
- constructor(wire) {
1810
- super(wire);
1811
- // we get the module for fdc 1.2 here so we can reuse it wherever we can
1812
- this.fdc3Module = new fdc3_1_2_1.Fdc3Module(this.wire);
1813
- }
1814
- /**
1815
- * Launches an app, specified via an AppIdentifier object.
1816
- * @param app
1817
- * @param context
1818
- *
1819
- * @tutorial fdc3.open
1820
- */
1821
- async open(app, context) {
1822
- if (typeof app === 'string') {
1823
- console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
1824
- }
1825
- return this.fdc3Module.open(app, context);
1826
- }
1827
- /**
1828
- * Find all the available instances for a particular application.
1829
- * @param app
1830
- *
1831
- * @tutorial fdc3v2.findInstances
1832
- */
1833
- async findInstances(app) {
1834
- this.wire.sendAction('fdc3-find-instances').catch((e) => {
1835
- // we do not want to expose this error, just continue if this analytics-only call fails
1836
- });
1837
- try {
1838
- return await InteropClient_1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'fdc3FindInstances', app);
1839
- }
1840
- catch (error) {
1841
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.fdc3FindInstances ? 'ResolverUnavailable' : error.message;
1842
- throw new Error(errorToThrow);
1843
- }
1844
- }
1845
- /**
1846
- * Retrieves the AppMetadata for an AppIdentifier, which provides additional metadata (such as icons, a title and description) from the App Directory record for the application, that may be used for display purposes.
1847
- * @param app
1848
- *
1849
- * @tutorial fdc3v2.getAppMetadata
1850
- */
1851
- async getAppMetadata(app) {
1852
- this.wire.sendAction('fdc3-get-app-metadata').catch((e) => {
1853
- // we do not want to expose this error, just continue if this analytics-only call fails
1854
- });
1855
- try {
1856
- return await InteropClient_1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'fdc3GetAppMetadata', app);
1857
- }
1858
- catch (error) {
1859
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.fdc3GetAppMetadata ? 'ResolverUnavailable' : error.message;
1860
- throw new Error(errorToThrow);
1861
- }
1862
- }
1863
- /**
1864
- * Broadcasts a context for the channel of the current entity.
1865
- * @param context - New context to set.
1866
- *
1867
- * @tutorial fdc3.broadcast
1868
- */
1869
- async broadcast(context) {
1870
- return this.fdc3Module.broadcast(context);
1871
- }
1872
- /**
1873
- * 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. If you wish to listen for all incoming contexts, pass `null` for the contextType argument.
1874
- * @param contextType
1875
- * @param handler
1876
- *
1877
- * @tutorial fdc3.addContextListener
1878
- */
1879
- async addContextListener(contextType, handler) {
1880
- this.wire.sendAction('fdc3-add-context-listener').catch((e) => {
1881
- // we do not want to expose this error, just continue if this analytics-only call fails
1882
- });
1883
- // The FDC3 ContextHandler only expects the context and optional ContextMetadata, so we wrap the handler
1884
- // here so it only gets passed these parameters
1885
- const getWrappedHandler = (handlerToWrap) => {
1886
- return (context) => {
1887
- const { contextMetadata, ...rest } = context;
1888
- const args = contextMetadata ? [{ ...rest }, contextMetadata] : [context, null];
1889
- handlerToWrap(...args);
1890
- };
1891
- };
1892
- let actualHandler = handler;
1893
- let wrappedHandler = getWrappedHandler(actualHandler);
1894
- if (typeof contextType === 'function') {
1895
- console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
1896
- actualHandler = contextType;
1897
- wrappedHandler = getWrappedHandler(actualHandler);
1898
- return this.fin.me.interop.addContextHandler(wrappedHandler);
1899
- }
1900
- return this.fin.me.interop.addContextHandler(wrappedHandler, contextType === null ? undefined : contextType);
1901
- }
1902
- /**
1903
- * Find out more information about a particular intent by passing its name, and optionally its context and resultType.
1904
- * @param intent Name of the Intent
1905
- * @param context Context
1906
- * @param resultType The type of result returned for any intent specified during resolution.
1907
- *
1908
- * @tutorial fdc3.findIntent
1909
- */
1910
- async findIntent(intent, context, resultType) {
1911
- this.wire.sendAction('fdc3-find-intent').catch((e) => {
1912
- // we do not want to expose this error, just continue if this analytics-only call fails
1913
- });
1914
- try {
1915
- return await this.fin.me.interop.getInfoForIntent({ name: intent, context, metadata: { resultType } });
1916
- }
1917
- catch (error) {
1918
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntent ? 'ResolverUnavailable' : error.message;
1919
- throw new Error(errorToThrow);
1920
- }
1921
- }
1922
- /**
1923
- * Find all the available intents for a particular context.
1924
- * @param context
1925
- * @param resultType The type of result returned for any intent specified during resolution.
1926
- *
1927
- * @tutorial fdc3v2.findIntentsByContext
1928
- */
1929
- async findIntentsByContext(context, resultType) {
1930
- this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
1931
- // we do not want to expose this error, just continue if this analytics-only call fails
1932
- });
1933
- const payload = resultType ? { context, metadata: { resultType } } : context;
1934
- try {
1935
- return await InteropClient_1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'fdc3v2FindIntentsByContext', payload);
1936
- }
1937
- catch (error) {
1938
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error.message;
1939
- throw new Error(errorToThrow);
1940
- }
1941
- }
1942
- /**
1943
- * Raises a specific intent for resolution against apps registered with the desktop agent.
1944
- * @param intent Name of the Intent
1945
- * @param context Context associated with the Intent
1946
- * @param app
1947
- *
1948
- * @tutorial fdc3v2.raiseIntent
1949
- */
1950
- async raiseIntent(intent, context, app) {
1951
- this.wire.sendAction('fdc3-raise-intent').catch((e) => {
1952
- // we do not want to expose this error, just continue if this analytics-only call fails
1953
- });
1954
- try {
1955
- if (typeof app === 'string') {
1956
- console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
1957
- }
1958
- return (0, utils_2.getIntentResolution)(this.fin.me.interop, context, app, intent);
1959
- }
1960
- catch (error) {
1961
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
1962
- throw new Error(errorToThrow);
1963
- }
1964
- }
1965
- /**
1966
- * Finds and raises an intent against apps registered with the desktop agent based purely on the type of the context data.
1967
- * @param context Context associated with the Intent
1968
- * @param app
1969
- *
1970
- * @tutorial fdc3v2.raiseIntentForContext
1971
- */
1972
- async raiseIntentForContext(context, app) {
1973
- // TODO: We have to do the same thing we do for raiseIntent here as well.
1974
- this.wire.sendAction('fdc3-raise-intent-for-context').catch((e) => {
1975
- // we do not want to expose this error, just continue if this analytics-only call fails
1976
- });
1977
- try {
1978
- if (typeof app === 'string') {
1979
- console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
1980
- }
1981
- return (0, utils_2.getIntentResolution)(this.fin.me.interop, context, app);
1982
- }
1983
- catch (error) {
1984
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
1985
- throw new Error(errorToThrow);
1986
- }
1987
- }
1988
- /**
1989
- * Adds a listener for incoming intents.
1990
- * @param intent Name of the Intent
1991
- * @param handler A callback that handles a context event and may return a promise of a Context or Channel object to be returned to the application that raised the intent.
1992
- *
1993
- * @tutorial fdc3.addIntentListener
1994
- */
1995
- async addIntentListener(intent, handler) {
1996
- this.wire.sendAction('fdc3-add-intent-listener').catch((e) => {
1997
- // we do not want to expose this error, just continue if this analytics-only call fails
1998
- });
1999
- if (typeof intent !== 'string') {
2000
- throw new Error('First argument must be an Intent name');
2001
- }
2002
- // The FDC3 Intenter handler only expects the context and contextMetadata to be passed to the handler,
2003
- // so we wrap it here and only pass those paramaters.
2004
- const contextHandler = async (raisedIntent) => {
2005
- let intentResult;
2006
- let intentResultToSend;
2007
- const { context, metadata: intentMetadata } = raisedIntent;
2008
- const { contextMetadata, metadata, ...rest } = context;
2009
- const intentResolutionResultId = intentMetadata?.intentResolutionResultId || metadata?.intentResolutionResultId;
2010
- try {
2011
- const newContext = metadata ? { metadata, ...rest } : { ...rest };
2012
- intentResult = await handler(newContext, contextMetadata);
2013
- intentResultToSend = intentResult;
2014
- }
2015
- catch (error) {
2016
- intentResult = error;
2017
- intentResultToSend = { error: true };
2018
- }
2019
- if (intentResolutionResultId) {
2020
- this.fin.InterApplicationBus.publish(intentResolutionResultId, intentResultToSend);
2021
- }
2022
- if (intentResult instanceof Error) {
2023
- throw new Error(intentResult.message);
2024
- }
2025
- return intentResult;
2026
- };
2027
- return this.fin.me.interop.registerIntentHandler(contextHandler, intent, { fdc3Version: '2.0' });
2028
- }
2029
- /**
2030
- * Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
2031
- * @param channelId
2032
- *
2033
- * @tutorial fdc3.getOrCreateChannel
2034
- */
2035
- async getOrCreateChannel(channelId) {
2036
- return this.fdc3Module.getOrCreateChannel(channelId);
2037
- }
2038
- /**
2039
- * Returns a Channel with an auto-generated identity that is intended for private communication between applications. Primarily used to create channels that will be returned to other applications via an IntentResolution for a raised intent.
2040
- *
2041
- * @tutorial fdc3v2.createPrivateChannel
2042
- */
2043
- async createPrivateChannel() {
2044
- const channelId = (0, utils_1.generateId)();
2045
- await InteropClient_1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'createPrivateChannelProvider', { channelId });
2046
- const channelClient = await this.fin.InterApplicationBus.Channel.connect(channelId);
2047
- const newPrivateChannelClient = new PrivateChannelClient_1.PrivateChannelClient(channelClient, channelId);
2048
- return (0, utils_2.buildPrivateChannelObject)(newPrivateChannelClient);
2049
- }
2050
- /**
2051
- * Retrieves a list of the User Channels available for the app to join.
2052
- *
2053
- * @tutorial fdc3v2.getUserChannels
2054
- */
2055
- async getUserChannels() {
2056
- const channels = await this.fin.me.interop.getContextGroups();
2057
- // fdc3 implementation of getUserChannels returns on array of channels, have to decorate over
2058
- // this so people know that these APIs are not supported
2059
- return channels.map((channel) => {
2060
- return { ...channel, type: 'user', ...(0, utils_2.getUnsupportedChannelApis)('User') };
2061
- });
2062
- }
2063
- /**
2064
- * Retrieves a list of the User Channels available for the app to join.
2065
- *
2066
- * @deprecated Please use {@link fdc3.getUserChannels fdc3.getUserChannels} instead
2067
- * @tutorial fdc3.getSystemChannels
2068
- */
2069
- async getSystemChannels() {
2070
- console.warn('This API has been deprecated. Please use fdc3.getUserChannels instead.');
2071
- return this.fdc3Module.getSystemChannels();
2072
- }
2073
- /**
2074
- * Join an app to a specified User channel.
2075
- * @param channelId Channel name
2076
- *
2077
- * @tutorial fdc3v2.joinUserChannel
2078
- */
2079
- async joinUserChannel(channelId) {
2080
- return this.fdc3Module.joinChannel(channelId);
2081
- }
2082
- /**
2083
- * Join an app to a specified User channel.
2084
- * @param channelId Channel name
2085
- * @deprecated Please use {@link fdc3.joinUserChannel fdc3.joinUserChannel} instead
2086
- *
2087
- * @tutorial fdc3.joinChannel
2088
- */
2089
- async joinChannel(channelId) {
2090
- console.warn('This API has been deprecated. Please use fdc3.joinUserChannel instead.');
2091
- return this.fdc3Module.joinChannel(channelId);
2092
- }
2093
- /**
2094
- * Returns the Channel object for the current User channel membership
2095
- *
2096
- * @tutorial fdc3.getCurrentChannel
2097
- */
2098
- async getCurrentChannel() {
2099
- const currentChannel = await this.fdc3Module.getCurrentChannel();
2100
- if (!currentChannel) {
2101
- return null;
2102
- }
2103
- return {
2104
- ...currentChannel,
2105
- type: 'user',
2106
- broadcast: this.broadcast.bind(this)
2107
- };
2108
- }
2109
- /**
2110
- * Removes the app from any User channel membership.
2111
- *
2112
- * @tutorial fdc3.leaveCurrentChannel
2113
- */
2114
- async leaveCurrentChannel() {
2115
- return this.fdc3Module.leaveCurrentChannel();
2116
- }
2117
- /**
2118
- * Retrieves information about the FDC3 implementation, including the supported version of the FDC3 specification, the name of the provider of the implementation, its own version number, details of whether optional API features are implemented and the metadata of the calling application according to the desktop agent.
2119
- * fdc3HandleGetInfo must be overridden in the InteropBroker so that the ImplementationMetadata will have the appMetadata info.
2120
- *
2121
- * @tutorial fdc3v2.getInfo
2122
- */
2123
- async getInfo() {
2124
- return InteropClient_1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'fdc3v2GetInfo', { fdc3Version: '2.0' });
2125
- }
2126
- }
1765
+ Object.defineProperty(fdc32_0, "__esModule", { value: true });
1766
+ exports.Fdc3Module2 = fdc32_0.Fdc3Module2 = void 0;
1767
+ const base_1 = base;
1768
+ const utils_1 = utils$1;
1769
+ const InteropClient_1 = InteropClient$1;
1770
+ const utils_2 = utils$2;
1771
+ const fdc3_1_2_1 = fdc31_2;
1772
+ const PrivateChannelClient_1 = PrivateChannelClient$1;
1773
+ /**
1774
+ * @version 2.0
1775
+ * The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
1776
+ * while using our Interop API under the hood. In order to use this set of APIs
1777
+ * you will need to set up your own {@link InteropBroker InteropBroker} or use a Platform application, which does the setup for you. Refer to our documentation on
1778
+ * our {@link https://developers.openfin.co/of-docs/docs/enable-context-sharing Interop API}.
1779
+ *
1780
+ * To enable the FDC3 APIs in a {@link Window Window} or {@link View View}, add the fdc3InteropApi
1781
+ * property to its options:
1782
+ *
1783
+ * ```js
1784
+ * {
1785
+ * autoShow: false,
1786
+ * saveWindowState: true,
1787
+ * url: 'https://openfin.co',
1788
+ * fdc3InteropApi: '2.0'
1789
+ * }
1790
+ * ```
1791
+ *
1792
+ * If using a {@link Platform Platform } application, you can set this property in defaultWindowOptions and defaultViewOptions.
1793
+ *
1794
+ * In order to ensure that the FDC3 Api is ready before use, you can use the 'fdc3Ready' event fired on the DOM Window object:
1795
+ *
1796
+ * ```js
1797
+ * function fdc3Action() {
1798
+ * // Make some fdc3 API calls here
1799
+ * }
1800
+ *
1801
+ * if (window.fdc3) {
1802
+ * fdc3Action();
1803
+ * } else {
1804
+ * window.addEventListener('fdc3Ready', fdc3Action);
1805
+ * }
1806
+ * ```
1807
+ */
1808
+ class Fdc3Module2 extends base_1.Base {
1809
+ constructor(wire) {
1810
+ super(wire);
1811
+ // we get the module for fdc 1.2 here so we can reuse it wherever we can
1812
+ this.fdc3Module = new fdc3_1_2_1.Fdc3Module(this.wire);
1813
+ }
1814
+ /**
1815
+ * Launches an app, specified via an AppIdentifier object.
1816
+ * @param app
1817
+ * @param context
1818
+ *
1819
+ * @tutorial fdc3.open
1820
+ */
1821
+ async open(app, context) {
1822
+ if (typeof app === 'string') {
1823
+ console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
1824
+ }
1825
+ return this.fdc3Module.open(app, context);
1826
+ }
1827
+ /**
1828
+ * Find all the available instances for a particular application.
1829
+ * @param app
1830
+ *
1831
+ * @tutorial fdc3v2.findInstances
1832
+ */
1833
+ async findInstances(app) {
1834
+ this.wire.sendAction('fdc3-find-instances').catch((e) => {
1835
+ // we do not want to expose this error, just continue if this analytics-only call fails
1836
+ });
1837
+ try {
1838
+ return await InteropClient_1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'fdc3FindInstances', app);
1839
+ }
1840
+ catch (error) {
1841
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fdc3FindInstances ? 'ResolverUnavailable' : error.message;
1842
+ throw new Error(errorToThrow);
1843
+ }
1844
+ }
1845
+ /**
1846
+ * Retrieves the AppMetadata for an AppIdentifier, which provides additional metadata (such as icons, a title and description) from the App Directory record for the application, that may be used for display purposes.
1847
+ * @param app
1848
+ *
1849
+ * @tutorial fdc3v2.getAppMetadata
1850
+ */
1851
+ async getAppMetadata(app) {
1852
+ this.wire.sendAction('fdc3-get-app-metadata').catch((e) => {
1853
+ // we do not want to expose this error, just continue if this analytics-only call fails
1854
+ });
1855
+ try {
1856
+ return await InteropClient_1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'fdc3GetAppMetadata', app);
1857
+ }
1858
+ catch (error) {
1859
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fdc3GetAppMetadata ? 'ResolverUnavailable' : error.message;
1860
+ throw new Error(errorToThrow);
1861
+ }
1862
+ }
1863
+ /**
1864
+ * Broadcasts a context for the channel of the current entity.
1865
+ * @param context - New context to set.
1866
+ *
1867
+ * @tutorial fdc3.broadcast
1868
+ */
1869
+ async broadcast(context) {
1870
+ return this.fdc3Module.broadcast(context);
1871
+ }
1872
+ /**
1873
+ * 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. If you wish to listen for all incoming contexts, pass `null` for the contextType argument.
1874
+ * @param contextType
1875
+ * @param handler
1876
+ *
1877
+ * @tutorial fdc3.addContextListener
1878
+ */
1879
+ async addContextListener(contextType, handler) {
1880
+ this.wire.sendAction('fdc3-add-context-listener').catch((e) => {
1881
+ // we do not want to expose this error, just continue if this analytics-only call fails
1882
+ });
1883
+ // The FDC3 ContextHandler only expects the context and optional ContextMetadata, so we wrap the handler
1884
+ // here so it only gets passed these parameters
1885
+ const getWrappedHandler = (handlerToWrap) => {
1886
+ return (context) => {
1887
+ const { contextMetadata, ...rest } = context;
1888
+ const args = contextMetadata ? [{ ...rest }, contextMetadata] : [context, null];
1889
+ handlerToWrap(...args);
1890
+ };
1891
+ };
1892
+ let actualHandler = handler;
1893
+ let wrappedHandler = getWrappedHandler(actualHandler);
1894
+ if (typeof contextType === 'function') {
1895
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
1896
+ actualHandler = contextType;
1897
+ wrappedHandler = getWrappedHandler(actualHandler);
1898
+ return this.fin.me.interop.addContextHandler(wrappedHandler);
1899
+ }
1900
+ return this.fin.me.interop.addContextHandler(wrappedHandler, contextType === null ? undefined : contextType);
1901
+ }
1902
+ /**
1903
+ * Find out more information about a particular intent by passing its name, and optionally its context and resultType.
1904
+ * @param intent Name of the Intent
1905
+ * @param context Context
1906
+ * @param resultType The type of result returned for any intent specified during resolution.
1907
+ *
1908
+ * @tutorial fdc3.findIntent
1909
+ */
1910
+ async findIntent(intent, context, resultType) {
1911
+ this.wire.sendAction('fdc3-find-intent').catch((e) => {
1912
+ // we do not want to expose this error, just continue if this analytics-only call fails
1913
+ });
1914
+ try {
1915
+ return await this.fin.me.interop.getInfoForIntent({ name: intent, context, metadata: { resultType } });
1916
+ }
1917
+ catch (error) {
1918
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntent ? 'ResolverUnavailable' : error.message;
1919
+ throw new Error(errorToThrow);
1920
+ }
1921
+ }
1922
+ /**
1923
+ * Find all the available intents for a particular context.
1924
+ * @param context
1925
+ * @param resultType The type of result returned for any intent specified during resolution.
1926
+ *
1927
+ * @tutorial fdc3v2.findIntentsByContext
1928
+ */
1929
+ async findIntentsByContext(context, resultType) {
1930
+ this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
1931
+ // we do not want to expose this error, just continue if this analytics-only call fails
1932
+ });
1933
+ const payload = resultType ? { context, metadata: { resultType } } : context;
1934
+ try {
1935
+ return await InteropClient_1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'fdc3v2FindIntentsByContext', payload);
1936
+ }
1937
+ catch (error) {
1938
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error.message;
1939
+ throw new Error(errorToThrow);
1940
+ }
1941
+ }
1942
+ /**
1943
+ * Raises a specific intent for resolution against apps registered with the desktop agent.
1944
+ * @param intent Name of the Intent
1945
+ * @param context Context associated with the Intent
1946
+ * @param app
1947
+ *
1948
+ * @tutorial fdc3v2.raiseIntent
1949
+ */
1950
+ async raiseIntent(intent, context, app) {
1951
+ this.wire.sendAction('fdc3-raise-intent').catch((e) => {
1952
+ // we do not want to expose this error, just continue if this analytics-only call fails
1953
+ });
1954
+ try {
1955
+ if (typeof app === 'string') {
1956
+ console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
1957
+ }
1958
+ return (0, utils_2.getIntentResolution)(this.fin.me.interop, context, app, intent);
1959
+ }
1960
+ catch (error) {
1961
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
1962
+ throw new Error(errorToThrow);
1963
+ }
1964
+ }
1965
+ /**
1966
+ * Finds and raises an intent against apps registered with the desktop agent based purely on the type of the context data.
1967
+ * @param context Context associated with the Intent
1968
+ * @param app
1969
+ *
1970
+ * @tutorial fdc3v2.raiseIntentForContext
1971
+ */
1972
+ async raiseIntentForContext(context, app) {
1973
+ // TODO: We have to do the same thing we do for raiseIntent here as well.
1974
+ this.wire.sendAction('fdc3-raise-intent-for-context').catch((e) => {
1975
+ // we do not want to expose this error, just continue if this analytics-only call fails
1976
+ });
1977
+ try {
1978
+ if (typeof app === 'string') {
1979
+ console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
1980
+ }
1981
+ return (0, utils_2.getIntentResolution)(this.fin.me.interop, context, app);
1982
+ }
1983
+ catch (error) {
1984
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
1985
+ throw new Error(errorToThrow);
1986
+ }
1987
+ }
1988
+ /**
1989
+ * Adds a listener for incoming intents.
1990
+ * @param intent Name of the Intent
1991
+ * @param handler A callback that handles a context event and may return a promise of a Context or Channel object to be returned to the application that raised the intent.
1992
+ *
1993
+ * @tutorial fdc3.addIntentListener
1994
+ */
1995
+ async addIntentListener(intent, handler) {
1996
+ this.wire.sendAction('fdc3-add-intent-listener').catch((e) => {
1997
+ // we do not want to expose this error, just continue if this analytics-only call fails
1998
+ });
1999
+ if (typeof intent !== 'string') {
2000
+ throw new Error('First argument must be an Intent name');
2001
+ }
2002
+ // The FDC3 Intenter handler only expects the context and contextMetadata to be passed to the handler,
2003
+ // so we wrap it here and only pass those paramaters.
2004
+ const contextHandler = async (raisedIntent) => {
2005
+ let intentResult;
2006
+ let intentResultToSend;
2007
+ const { context, metadata: intentMetadata } = raisedIntent;
2008
+ const { contextMetadata, metadata, ...rest } = context;
2009
+ const intentResolutionResultId = intentMetadata?.intentResolutionResultId || metadata?.intentResolutionResultId;
2010
+ try {
2011
+ const newContext = metadata ? { metadata, ...rest } : { ...rest };
2012
+ intentResult = await handler(newContext, contextMetadata);
2013
+ intentResultToSend = intentResult;
2014
+ }
2015
+ catch (error) {
2016
+ intentResult = error;
2017
+ intentResultToSend = { error: true };
2018
+ }
2019
+ if (intentResolutionResultId) {
2020
+ this.fin.InterApplicationBus.publish(intentResolutionResultId, intentResultToSend);
2021
+ }
2022
+ if (intentResult instanceof Error) {
2023
+ throw new Error(intentResult.message);
2024
+ }
2025
+ return intentResult;
2026
+ };
2027
+ return this.fin.me.interop.registerIntentHandler(contextHandler, intent, { fdc3Version: '2.0' });
2028
+ }
2029
+ /**
2030
+ * Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
2031
+ * @param channelId
2032
+ *
2033
+ * @tutorial fdc3.getOrCreateChannel
2034
+ */
2035
+ async getOrCreateChannel(channelId) {
2036
+ return this.fdc3Module.getOrCreateChannel(channelId);
2037
+ }
2038
+ /**
2039
+ * Returns a Channel with an auto-generated identity that is intended for private communication between applications. Primarily used to create channels that will be returned to other applications via an IntentResolution for a raised intent.
2040
+ *
2041
+ * @tutorial fdc3v2.createPrivateChannel
2042
+ */
2043
+ async createPrivateChannel() {
2044
+ const channelId = (0, utils_1.generateId)();
2045
+ await InteropClient_1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'createPrivateChannelProvider', { channelId });
2046
+ const channelClient = await this.fin.InterApplicationBus.Channel.connect(channelId);
2047
+ const newPrivateChannelClient = new PrivateChannelClient_1.PrivateChannelClient(channelClient, channelId);
2048
+ return (0, utils_2.buildPrivateChannelObject)(newPrivateChannelClient);
2049
+ }
2050
+ /**
2051
+ * Retrieves a list of the User Channels available for the app to join.
2052
+ *
2053
+ * @tutorial fdc3v2.getUserChannels
2054
+ */
2055
+ async getUserChannels() {
2056
+ const channels = await this.fin.me.interop.getContextGroups();
2057
+ // fdc3 implementation of getUserChannels returns on array of channels, have to decorate over
2058
+ // this so people know that these APIs are not supported
2059
+ return channels.map((channel) => {
2060
+ return { ...channel, type: 'user', ...(0, utils_2.getUnsupportedChannelApis)('User') };
2061
+ });
2062
+ }
2063
+ /**
2064
+ * Retrieves a list of the User Channels available for the app to join.
2065
+ *
2066
+ * @deprecated Please use {@link fdc3.getUserChannels fdc3.getUserChannels} instead
2067
+ * @tutorial fdc3.getSystemChannels
2068
+ */
2069
+ async getSystemChannels() {
2070
+ console.warn('This API has been deprecated. Please use fdc3.getUserChannels instead.');
2071
+ return this.fdc3Module.getSystemChannels();
2072
+ }
2073
+ /**
2074
+ * Join an app to a specified User channel.
2075
+ * @param channelId Channel name
2076
+ *
2077
+ * @tutorial fdc3v2.joinUserChannel
2078
+ */
2079
+ async joinUserChannel(channelId) {
2080
+ return this.fdc3Module.joinChannel(channelId);
2081
+ }
2082
+ /**
2083
+ * Join an app to a specified User channel.
2084
+ * @param channelId Channel name
2085
+ * @deprecated Please use {@link fdc3.joinUserChannel fdc3.joinUserChannel} instead
2086
+ *
2087
+ * @tutorial fdc3.joinChannel
2088
+ */
2089
+ async joinChannel(channelId) {
2090
+ console.warn('This API has been deprecated. Please use fdc3.joinUserChannel instead.');
2091
+ return this.fdc3Module.joinChannel(channelId);
2092
+ }
2093
+ /**
2094
+ * Returns the Channel object for the current User channel membership
2095
+ *
2096
+ * @tutorial fdc3.getCurrentChannel
2097
+ */
2098
+ async getCurrentChannel() {
2099
+ const currentChannel = await this.fdc3Module.getCurrentChannel();
2100
+ if (!currentChannel) {
2101
+ return null;
2102
+ }
2103
+ return {
2104
+ ...currentChannel,
2105
+ type: 'user',
2106
+ broadcast: this.broadcast.bind(this)
2107
+ };
2108
+ }
2109
+ /**
2110
+ * Removes the app from any User channel membership.
2111
+ *
2112
+ * @tutorial fdc3.leaveCurrentChannel
2113
+ */
2114
+ async leaveCurrentChannel() {
2115
+ return this.fdc3Module.leaveCurrentChannel();
2116
+ }
2117
+ /**
2118
+ * Retrieves information about the FDC3 implementation, including the supported version of the FDC3 specification, the name of the provider of the implementation, its own version number, details of whether optional API features are implemented and the metadata of the calling application according to the desktop agent.
2119
+ * fdc3HandleGetInfo must be overridden in the InteropBroker so that the ImplementationMetadata will have the appMetadata info.
2120
+ *
2121
+ * @tutorial fdc3v2.getInfo
2122
+ */
2123
+ async getInfo() {
2124
+ return InteropClient_1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'fdc3v2GetInfo', { fdc3Version: '2.0' });
2125
+ }
2126
+ }
2127
2127
  exports.Fdc3Module2 = fdc32_0.Fdc3Module2 = Fdc3Module2;
2128
2128
 
2129
2129
  (function (exports) {
2130
- Object.defineProperty(exports, "__esModule", { value: true });
2131
- exports.getFdc3 = exports.versionMap = void 0;
2132
- /* eslint-disable no-console */
2133
- /* eslint-disable no-param-reassign */
2134
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
2135
- const fdc3_1_2_1 = fdc31_2;
2136
- const fdc3_2_0_1 = fdc32_0;
2137
- exports.versionMap = {
2138
- '1.2': fdc3_1_2_1.Fdc3Module,
2139
- '2.0': fdc3_2_0_1.Fdc3Module2
2140
- };
2141
- const latestVersion = '2.0';
2142
- function getFdc3(transport, version = latestVersion) {
2143
- if (!(version in exports.versionMap)) {
2144
- console.warn(`FDC3 API version: ${version} is not supported. Defaulting to latest version: ${latestVersion}.`);
2145
- version = latestVersion;
2146
- }
2147
- const Fdc3Api = exports.versionMap[version];
2148
- const fdc3 = new Fdc3Api(transport);
2149
- window.dispatchEvent(new CustomEvent('fdc3Ready'));
2150
- return fdc3;
2151
- }
2130
+ Object.defineProperty(exports, "__esModule", { value: true });
2131
+ exports.getFdc3 = exports.versionMap = void 0;
2132
+ /* eslint-disable no-console */
2133
+ /* eslint-disable no-param-reassign */
2134
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
2135
+ const fdc3_1_2_1 = fdc31_2;
2136
+ const fdc3_2_0_1 = fdc32_0;
2137
+ exports.versionMap = {
2138
+ '1.2': fdc3_1_2_1.Fdc3Module,
2139
+ '2.0': fdc3_2_0_1.Fdc3Module2
2140
+ };
2141
+ const latestVersion = '2.0';
2142
+ function getFdc3(transport, version = latestVersion) {
2143
+ if (!(version in exports.versionMap)) {
2144
+ console.warn(`FDC3 API version: ${version} is not supported. Defaulting to latest version: ${latestVersion}.`);
2145
+ version = latestVersion;
2146
+ }
2147
+ const Fdc3Api = exports.versionMap[version];
2148
+ const fdc3 = new Fdc3Api(transport);
2149
+ window.dispatchEvent(new CustomEvent('fdc3Ready'));
2150
+ return fdc3;
2151
+ }
2152
2152
  exports.getFdc3 = getFdc3;
2153
2153
  } (fdc3));
2154
2154
 
@@ -2156,9 +2156,9 @@ var versions = {};
2156
2156
 
2157
2157
  Object.defineProperty(versions, "__esModule", { value: true });
2158
2158
 
2159
- async function fdc3FromFin(fin, version) {
2160
- // @ts-expect-error
2161
- return fdc3.getFdc3(fin.wire, version);
2159
+ async function fdc3FromFin(fin, version) {
2160
+ // @ts-expect-error
2161
+ return fdc3.getFdc3(fin.wire, version);
2162
2162
  }
2163
2163
 
2164
2164
  exports.Fdc3Version = versions.Fdc3Version;