@openfin/node-adapter 37.80.39 → 37.81.20

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.
@@ -5,11 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var require$$0 = require('events');
6
6
  var require$$3 = require('lodash');
7
7
  var require$$0$2 = require('fs');
8
- var require$$1$1 = require('crypto');
8
+ var require$$1$3 = require('crypto');
9
9
  var require$$2$1 = require('ws');
10
- var require$$1 = require('net');
11
- var require$$0$3 = require('path');
12
- var require$$0$4 = require('os');
10
+ var require$$1$2 = require('net');
11
+ var require$$1$1 = require('os');
12
+ var require$$1 = require('path');
13
13
  var require$$4 = require('timers');
14
14
  var require$$2 = require('child_process');
15
15
  var require$$0$1 = require('node:url');
@@ -72,13 +72,13 @@ async function promiseMapSerial(arr, func) {
72
72
  }
73
73
  promises.promiseMapSerial = promiseMapSerial;
74
74
 
75
- var __classPrivateFieldSet$d = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
75
+ var __classPrivateFieldSet$c = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
76
76
  if (kind === "m") throw new TypeError("Private method is not writable");
77
77
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
78
78
  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");
79
79
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
80
80
  };
81
- var __classPrivateFieldGet$f = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
81
+ var __classPrivateFieldGet$e = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
82
82
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
83
83
  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");
84
84
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
@@ -165,8 +165,8 @@ class EmitterBase extends Base {
165
165
  this.emit = (eventType, payload, ...args) => {
166
166
  return this.hasEmitter() ? this.getOrCreateEmitter().emit(eventType, payload, ...args) : false;
167
167
  };
168
- this.hasEmitter = () => this.wire.eventAggregator.has(__classPrivateFieldGet$f(this, _EmitterBase_emitterAccessor, "f"));
169
- this.getOrCreateEmitter = () => this.wire.eventAggregator.getOrCreate(__classPrivateFieldGet$f(this, _EmitterBase_emitterAccessor, "f"));
168
+ this.hasEmitter = () => this.wire.eventAggregator.has(__classPrivateFieldGet$e(this, _EmitterBase_emitterAccessor, "f"));
169
+ this.getOrCreateEmitter = () => this.wire.eventAggregator.getOrCreate(__classPrivateFieldGet$e(this, _EmitterBase_emitterAccessor, "f"));
170
170
  this.listeners = (type) => this.hasEmitter() ? this.getOrCreateEmitter().listeners(type) : [];
171
171
  this.listenerCount = (type) => this.hasEmitter() ? this.getOrCreateEmitter().listenerCount(type) : 0;
172
172
  this.registerEventListener = async (eventType, options = {}, applySubscription, undoSubscription) => {
@@ -204,7 +204,7 @@ class EmitterBase extends Base {
204
204
  // This will only be reached if unsubscribe from event that does not exist but do not want to error here
205
205
  return Promise.resolve();
206
206
  };
207
- __classPrivateFieldSet$d(this, _EmitterBase_emitterAccessor, [topic, ...additionalAccessors], "f");
207
+ __classPrivateFieldSet$c(this, _EmitterBase_emitterAccessor, [topic, ...additionalAccessors], "f");
208
208
  this.listeners = (event) => this.hasEmitter() ? this.getOrCreateEmitter().listeners(event) : [];
209
209
  }
210
210
  /**
@@ -322,7 +322,7 @@ class EmitterBase extends Base {
322
322
  }
323
323
  deleteEmitterIfNothingRegistered(emitter) {
324
324
  if (emitter.eventNames().length === 0) {
325
- this.wire.eventAggregator.delete(__classPrivateFieldGet$f(this, _EmitterBase_emitterAccessor, "f"));
325
+ this.wire.eventAggregator.delete(__classPrivateFieldGet$e(this, _EmitterBase_emitterAccessor, "f"));
326
326
  }
327
327
  }
328
328
  }
@@ -922,13 +922,13 @@ const createRelayedDispatch = (client, target, relayId, relayErrorMsg) => async
922
922
  };
923
923
  channelApiRelay.createRelayedDispatch = createRelayedDispatch;
924
924
 
925
- var __classPrivateFieldSet$c = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
925
+ var __classPrivateFieldSet$b = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
926
926
  if (kind === "m") throw new TypeError("Private method is not writable");
927
927
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
928
928
  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");
929
929
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
930
930
  };
931
- var __classPrivateFieldGet$e = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
931
+ var __classPrivateFieldGet$d = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
932
932
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
933
933
  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");
934
934
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
@@ -982,7 +982,7 @@ class LayoutNode {
982
982
  * console.log(`The parent ColumnOrRow is root: ${parentIsRoot}`);
983
983
  * ```
984
984
  */
985
- this.isRoot = () => __classPrivateFieldGet$e(this, _LayoutNode_client, "f").isRoot(this.entityId);
985
+ this.isRoot = () => __classPrivateFieldGet$d(this, _LayoutNode_client, "f").isRoot(this.entityId);
986
986
  /**
987
987
  * Checks if the TabStack or ColumnOrRow exists
988
988
  *
@@ -1002,7 +1002,7 @@ class LayoutNode {
1002
1002
  * console.log(`The entity exists: ${exists}`);
1003
1003
  * ```
1004
1004
  */
1005
- this.exists = () => __classPrivateFieldGet$e(this, _LayoutNode_client, "f").exists(this.entityId);
1005
+ this.exists = () => __classPrivateFieldGet$d(this, _LayoutNode_client, "f").exists(this.entityId);
1006
1006
  /**
1007
1007
  * Retrieves the parent of the TabStack or ColumnOrRow
1008
1008
  *
@@ -1023,11 +1023,11 @@ class LayoutNode {
1023
1023
  * ```
1024
1024
  */
1025
1025
  this.getParent = async () => {
1026
- const parent = await __classPrivateFieldGet$e(this, _LayoutNode_client, "f").getParent(this.entityId);
1026
+ const parent = await __classPrivateFieldGet$d(this, _LayoutNode_client, "f").getParent(this.entityId);
1027
1027
  if (!parent) {
1028
1028
  return undefined;
1029
1029
  }
1030
- return LayoutNode.getEntity(parent, __classPrivateFieldGet$e(this, _LayoutNode_client, "f"));
1030
+ return LayoutNode.getEntity(parent, __classPrivateFieldGet$d(this, _LayoutNode_client, "f"));
1031
1031
  };
1032
1032
  /**
1033
1033
  * Creates a new TabStack adjacent to the given TabStack or ColumnOrRow. Inputs can be new views to create, or existing views.
@@ -1078,8 +1078,8 @@ class LayoutNode {
1078
1078
  * @experimental
1079
1079
  */
1080
1080
  this.createAdjacentStack = async (views, options) => {
1081
- const entityId = await __classPrivateFieldGet$e(this, _LayoutNode_client, "f").createAdjacentStack(this.entityId, views, options);
1082
- return LayoutNode.getEntity({ entityId, type: 'stack' }, __classPrivateFieldGet$e(this, _LayoutNode_client, "f"));
1081
+ const entityId = await __classPrivateFieldGet$d(this, _LayoutNode_client, "f").createAdjacentStack(this.entityId, views, options);
1082
+ return LayoutNode.getEntity({ entityId, type: 'stack' }, __classPrivateFieldGet$d(this, _LayoutNode_client, "f"));
1083
1083
  };
1084
1084
  /**
1085
1085
  * Retrieves the adjacent TabStacks of the given TabStack or ColumnOrRow.
@@ -1107,16 +1107,16 @@ class LayoutNode {
1107
1107
  * @experimental
1108
1108
  */
1109
1109
  this.getAdjacentStacks = async (edge) => {
1110
- const adjacentStacks = await __classPrivateFieldGet$e(this, _LayoutNode_client, "f").getAdjacentStacks({
1110
+ const adjacentStacks = await __classPrivateFieldGet$d(this, _LayoutNode_client, "f").getAdjacentStacks({
1111
1111
  targetId: this.entityId,
1112
1112
  edge
1113
1113
  });
1114
1114
  return adjacentStacks.map((stack) => LayoutNode.getEntity({
1115
1115
  type: 'stack',
1116
1116
  entityId: stack.entityId
1117
- }, __classPrivateFieldGet$e(this, _LayoutNode_client, "f")));
1117
+ }, __classPrivateFieldGet$d(this, _LayoutNode_client, "f")));
1118
1118
  };
1119
- __classPrivateFieldSet$c(this, _LayoutNode_client, client, "f");
1119
+ __classPrivateFieldSet$b(this, _LayoutNode_client, client, "f");
1120
1120
  this.entityId = entityId;
1121
1121
  }
1122
1122
  }
@@ -1189,7 +1189,7 @@ class TabStack extends LayoutNode {
1189
1189
  * ```
1190
1190
  * @experimental
1191
1191
  */
1192
- this.getViews = () => __classPrivateFieldGet$e(this, _TabStack_client, "f").getStackViews(this.entityId);
1192
+ this.getViews = () => __classPrivateFieldGet$d(this, _TabStack_client, "f").getStackViews(this.entityId);
1193
1193
  /**
1194
1194
  * Adds or creates a view in this {@link TabStack}.
1195
1195
  *
@@ -1219,7 +1219,7 @@ class TabStack extends LayoutNode {
1219
1219
  * ```
1220
1220
  * @experimental
1221
1221
  */
1222
- this.addView = async (view, options = { index: 0 }) => __classPrivateFieldGet$e(this, _TabStack_client, "f").addViewToStack(this.entityId, view, options);
1222
+ this.addView = async (view, options = { index: 0 }) => __classPrivateFieldGet$d(this, _TabStack_client, "f").addViewToStack(this.entityId, view, options);
1223
1223
  /**
1224
1224
  * Removes a view from this {@link TabStack}.
1225
1225
  *
@@ -1249,7 +1249,7 @@ class TabStack extends LayoutNode {
1249
1249
  * ```
1250
1250
  */
1251
1251
  this.removeView = async (view) => {
1252
- await __classPrivateFieldGet$e(this, _TabStack_client, "f").removeViewFromStack(this.entityId, view);
1252
+ await __classPrivateFieldGet$d(this, _TabStack_client, "f").removeViewFromStack(this.entityId, view);
1253
1253
  };
1254
1254
  /**
1255
1255
  * Sets the active view of the {@link TabStack} without focusing it.
@@ -1273,9 +1273,9 @@ class TabStack extends LayoutNode {
1273
1273
  * @experimental
1274
1274
  */
1275
1275
  this.setActiveView = async (view) => {
1276
- await __classPrivateFieldGet$e(this, _TabStack_client, "f").setStackActiveView(this.entityId, view);
1276
+ await __classPrivateFieldGet$d(this, _TabStack_client, "f").setStackActiveView(this.entityId, view);
1277
1277
  };
1278
- __classPrivateFieldSet$c(this, _TabStack_client, client, "f");
1278
+ __classPrivateFieldSet$b(this, _TabStack_client, client, "f");
1279
1279
  }
1280
1280
  }
1281
1281
  layoutEntities.TabStack = TabStack;
@@ -1314,10 +1314,10 @@ class ColumnOrRow extends LayoutNode {
1314
1314
  * ```
1315
1315
  */
1316
1316
  this.getContent = async () => {
1317
- const contentItemEntities = await __classPrivateFieldGet$e(this, _ColumnOrRow_client, "f").getContent(this.entityId);
1318
- return contentItemEntities.map((entity) => LayoutNode.getEntity(entity, __classPrivateFieldGet$e(this, _ColumnOrRow_client, "f")));
1317
+ const contentItemEntities = await __classPrivateFieldGet$d(this, _ColumnOrRow_client, "f").getContent(this.entityId);
1318
+ return contentItemEntities.map((entity) => LayoutNode.getEntity(entity, __classPrivateFieldGet$d(this, _ColumnOrRow_client, "f")));
1319
1319
  };
1320
- __classPrivateFieldSet$c(this, _ColumnOrRow_client, client, "f");
1320
+ __classPrivateFieldSet$b(this, _ColumnOrRow_client, client, "f");
1321
1321
  this.type = type;
1322
1322
  }
1323
1323
  }
@@ -1336,8 +1336,8 @@ var main = {};
1336
1336
 
1337
1337
  Object.defineProperty(main, "__esModule", { value: true });
1338
1338
  main.WebContents = void 0;
1339
- const base_1$k = base$1;
1340
- class WebContents extends base_1$k.EmitterBase {
1339
+ const base_1$j = base$1;
1340
+ class WebContents extends base_1$j.EmitterBase {
1341
1341
  /**
1342
1342
  * @param identity The identity of the {@link OpenFin.WebContentsEvents WebContents}.
1343
1343
  * @param entityType The type of the {@link OpenFin.WebContentsEvents WebContents}.
@@ -4138,6 +4138,37 @@ function requireApplication () {
4138
4138
  return application$1;
4139
4139
  }
4140
4140
 
4141
+ var promisifySubscription$1 = {};
4142
+
4143
+ Object.defineProperty(promisifySubscription$1, "__esModule", { value: true });
4144
+ promisifySubscription$1.promisifySubscription = void 0;
4145
+ const promisifySubscription = async (emitter, eventName, predicate = () => true, timeout) => {
4146
+ let resolve;
4147
+ let reject;
4148
+ let timer;
4149
+ const valuePromise = new Promise((y, n) => {
4150
+ resolve = y;
4151
+ reject = n;
4152
+ });
4153
+ const listener = (e) => {
4154
+ if (predicate(e)) {
4155
+ clearTimeout(timer);
4156
+ resolve(e);
4157
+ }
4158
+ };
4159
+ await emitter.on(eventName, listener);
4160
+ if (timeout) {
4161
+ timer = setTimeout(() => reject(new Error('event timed out')), timeout);
4162
+ }
4163
+ valuePromise.finally(() => {
4164
+ emitter.removeListener(eventName, listener).catch(() => null);
4165
+ });
4166
+ return {
4167
+ getValue: () => valuePromise
4168
+ };
4169
+ };
4170
+ promisifySubscription$1.promisifySubscription = promisifySubscription;
4171
+
4141
4172
  var hasRequiredInstance;
4142
4173
 
4143
4174
  function requireInstance () {
@@ -4153,6 +4184,7 @@ function requireInstance () {
4153
4184
  const main_1 = main;
4154
4185
  const view_1 = requireView();
4155
4186
  const warnings_1 = warnings;
4187
+ const promisifySubscription_1 = promisifySubscription$1;
4156
4188
  /**
4157
4189
  * A basic window that wraps a native HTML window. Provides more fine-grained
4158
4190
  * control over the window state such as the ability to minimize, maximize, restore, etc.
@@ -4168,79 +4200,60 @@ function requireInstance () {
4168
4200
  constructor(wire, identity) {
4169
4201
  super(wire, identity, 'window');
4170
4202
  }
4171
- /**
4172
- * create a new window
4173
- * @internal
4174
- */
4175
- createWindow(options) {
4203
+ async createWindow(options) {
4176
4204
  this.wire.sendAction('window-create-window', this.identity).catch((e) => {
4177
4205
  // we do not want to expose this error, just continue if this analytics-only call fails
4178
4206
  });
4179
- return new Promise((resolve, reject) => {
4180
- const CONSTRUCTOR_CB_TOPIC = 'fire-constructor-callback';
4181
- // need to call pageResponse, otherwise when a child window is created, page is not loaded
4182
- const pageResponse = new Promise((resolve) => {
4183
- // TODO: fix typing (internal)
4184
- // @ts-expect-error
4185
- this.on(CONSTRUCTOR_CB_TOPIC, function fireConstructor(response) {
4186
- let cbPayload;
4187
- const { success } = response;
4188
- const responseData = response.data;
4189
- const { message } = responseData;
4190
- if (success) {
4191
- cbPayload = {
4192
- httpResponseCode: responseData.httpResponseCode,
4193
- apiInjected: responseData.apiInjected
4194
- };
4195
- }
4196
- else {
4197
- cbPayload = {
4198
- message: responseData.message,
4199
- networkErrorCode: responseData.networkErrorCode,
4200
- stack: responseData.stack
4201
- };
4202
- }
4203
- this.removeListener(CONSTRUCTOR_CB_TOPIC, fireConstructor);
4204
- resolve({
4205
- message,
4206
- cbPayload,
4207
- success
4208
- });
4209
- });
4210
- });
4211
- // set defaults:
4212
- if (options.waitForPageLoad === undefined) {
4213
- options.waitForPageLoad = false;
4214
- }
4215
- if (options.autoShow === undefined) {
4216
- options.autoShow = true;
4217
- }
4218
- (0, warnings_1.handleDeprecatedWarnings)(options);
4219
- const windowCreation = this.wire.environment.createChildContent({ entityType: 'window', options });
4220
- Promise.all([pageResponse, windowCreation])
4221
- .then((resolvedArr) => {
4222
- const pageResolve = resolvedArr[0];
4223
- if (pageResolve.success) {
4224
- resolve(this);
4225
- }
4226
- else {
4227
- reject(pageResolve);
4228
- }
4229
- try {
4230
- // this is to enforce a 5.0 contract that the child's main function
4231
- // will not fire before the parent's success callback on creation.
4232
- // if the child window is not accessible (CORS) this contract does
4233
- // not hold.
4234
- const webWindow = this.getWebWindow();
4235
- webWindow.fin.__internal_.openerSuccessCBCalled();
4236
- }
4237
- catch (e) {
4238
- // common for main windows, we do not want to expose this error. here just to have a debug target.
4239
- // console.error(e);
4240
- }
4241
- })
4242
- .catch(reject);
4243
- });
4207
+ const CONSTRUCTOR_CB_TOPIC = 'fire-constructor-callback';
4208
+ const responseSubscription = await (0, promisifySubscription_1.promisifySubscription)(this, CONSTRUCTOR_CB_TOPIC);
4209
+ // set defaults:
4210
+ if (options.waitForPageLoad === undefined) {
4211
+ options.waitForPageLoad = false;
4212
+ }
4213
+ if (options.autoShow === undefined) {
4214
+ options.autoShow = true;
4215
+ }
4216
+ (0, warnings_1.handleDeprecatedWarnings)(options);
4217
+ const windowCreation = this.wire.environment.createChildContent({ entityType: 'window', options });
4218
+ const [response] = await Promise.all([responseSubscription.getValue(), windowCreation]);
4219
+ let cbPayload;
4220
+ const { success } = response;
4221
+ const responseData = response.data;
4222
+ const { message } = responseData;
4223
+ if (success) {
4224
+ cbPayload = {
4225
+ httpResponseCode: responseData.httpResponseCode,
4226
+ apiInjected: responseData.apiInjected
4227
+ };
4228
+ }
4229
+ else {
4230
+ cbPayload = {
4231
+ message: responseData.message,
4232
+ networkErrorCode: responseData.networkErrorCode,
4233
+ stack: responseData.stack
4234
+ };
4235
+ }
4236
+ const pageResolve = {
4237
+ message,
4238
+ cbPayload,
4239
+ success
4240
+ };
4241
+ try {
4242
+ // this is to enforce a 5.0 contract that the child's main function
4243
+ // will not fire before the parent's success callback on creation.
4244
+ // if the child window is not accessible (CORS) this contract does
4245
+ // not hold.
4246
+ const webWindow = this.getWebWindow();
4247
+ webWindow.fin.__internal_.openerSuccessCBCalled();
4248
+ }
4249
+ catch (e) {
4250
+ // common for main windows, we do not want to expose this error. here just to have a debug target.
4251
+ // console.error(e);
4252
+ }
4253
+ if (pageResolve.success) {
4254
+ return this;
4255
+ }
4256
+ return Promise.reject(pageResolve);
4244
4257
  }
4245
4258
  /**
4246
4259
  * Retrieves an array of frame info objects representing the main frame and any
@@ -5619,7 +5632,7 @@ function requireWindow () {
5619
5632
  */
5620
5633
  Object.defineProperty(system$1, "__esModule", { value: true });
5621
5634
  system$1.System = void 0;
5622
- const base_1$j = base$1;
5635
+ const base_1$i = base$1;
5623
5636
  const transport_errors_1$2 = transportErrors;
5624
5637
  const window_1 = requireWindow();
5625
5638
  const events_1$6 = require$$0;
@@ -5629,7 +5642,7 @@ const events_1$6 = require$$0;
5629
5642
  * clearing the cache and exiting the runtime as well as listen to {@link OpenFin.SystemEvents system events}.
5630
5643
  *
5631
5644
  */
5632
- class System extends base_1$j.EmitterBase {
5645
+ class System extends base_1$i.EmitterBase {
5633
5646
  /**
5634
5647
  * @internal
5635
5648
  */
@@ -7535,9 +7548,10 @@ class ProtectedItems {
7535
7548
  /**
7536
7549
  * @internal
7537
7550
  */
7538
- constructor(providerIdentity, wire) {
7551
+ // eslint-disable-next-line no-useless-constructor
7552
+ constructor(providerIdentity, close) {
7539
7553
  this.providerIdentity = providerIdentity;
7540
- this.wire = wire;
7554
+ this.close = close;
7541
7555
  }
7542
7556
  }
7543
7557
  channel.ProtectedItems = ProtectedItems;
@@ -7859,12 +7873,12 @@ class ChannelBase {
7859
7873
  }
7860
7874
  channel.ChannelBase = ChannelBase;
7861
7875
 
7862
- var __classPrivateFieldGet$d = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
7876
+ var __classPrivateFieldGet$c = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
7863
7877
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
7864
7878
  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");
7865
7879
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
7866
7880
  };
7867
- var __classPrivateFieldSet$b = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7881
+ var __classPrivateFieldSet$a = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7868
7882
  if (kind === "m") throw new TypeError("Private method is not writable");
7869
7883
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
7870
7884
  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");
@@ -7906,7 +7920,7 @@ class ChannelClient extends channel_1$1.ChannelBase {
7906
7920
  static closeChannelByEndpointId(id) {
7907
7921
  const channel = channelClientsByEndpointId.get(id);
7908
7922
  if (channel) {
7909
- __classPrivateFieldGet$d(channel, _ChannelClient_close, "f").call(channel);
7923
+ __classPrivateFieldGet$c(channel, _ChannelClient_close, "f").call(channel);
7910
7924
  }
7911
7925
  }
7912
7926
  /**
@@ -7917,14 +7931,14 @@ class ChannelClient extends channel_1$1.ChannelBase {
7917
7931
  for (const channelClient of channelClientsByEndpointId.values()) {
7918
7932
  if (channelClient.providerIdentity.channelId === eventPayload.channelId) {
7919
7933
  channelClient.disconnectListener(eventPayload);
7920
- __classPrivateFieldGet$d(channelClient, _ChannelClient_close, "f").call(channelClient);
7934
+ __classPrivateFieldGet$c(channelClient, _ChannelClient_close, "f").call(channelClient);
7921
7935
  }
7922
7936
  }
7923
7937
  }
7924
7938
  /**
7925
7939
  * @internal
7926
7940
  */
7927
- constructor(routingInfo, wire, strategy) {
7941
+ constructor(routingInfo, close, strategy) {
7928
7942
  super();
7929
7943
  _ChannelClient_protectedObj.set(this, void 0);
7930
7944
  _ChannelClient_strategy.set(this, void 0);
@@ -7932,12 +7946,12 @@ class ChannelClient extends channel_1$1.ChannelBase {
7932
7946
  this.processAction = (action, payload, senderIdentity) => super.processAction(action, payload, senderIdentity);
7933
7947
  _ChannelClient_close.set(this, () => {
7934
7948
  channelClientsByEndpointId.delete(this.endpointId);
7935
- __classPrivateFieldGet$d(this, _ChannelClient_strategy, "f").close();
7949
+ __classPrivateFieldGet$c(this, _ChannelClient_strategy, "f").close();
7936
7950
  });
7937
- __classPrivateFieldSet$b(this, _ChannelClient_protectedObj, new channel_1$1.ProtectedItems(routingInfo, wire), "f");
7951
+ __classPrivateFieldSet$a(this, _ChannelClient_protectedObj, new channel_1$1.ProtectedItems(routingInfo, close), "f");
7938
7952
  this.disconnectListener = () => undefined;
7939
7953
  this.endpointId = routingInfo.endpointId;
7940
- __classPrivateFieldSet$b(this, _ChannelClient_strategy, strategy, "f");
7954
+ __classPrivateFieldSet$a(this, _ChannelClient_strategy, strategy, "f");
7941
7955
  channelClientsByEndpointId.set(this.endpointId, this);
7942
7956
  strategy.receive(this.processAction);
7943
7957
  }
@@ -7945,7 +7959,7 @@ class ChannelClient extends channel_1$1.ChannelBase {
7945
7959
  * a read-only provider identity
7946
7960
  */
7947
7961
  get providerIdentity() {
7948
- const protectedObj = __classPrivateFieldGet$d(this, _ChannelClient_protectedObj, "f");
7962
+ const protectedObj = __classPrivateFieldGet$c(this, _ChannelClient_protectedObj, "f");
7949
7963
  return protectedObj.providerIdentity;
7950
7964
  }
7951
7965
  /**
@@ -7974,8 +7988,8 @@ class ChannelClient extends channel_1$1.ChannelBase {
7974
7988
  * ```
7975
7989
  */
7976
7990
  async dispatch(action, payload) {
7977
- if (__classPrivateFieldGet$d(this, _ChannelClient_strategy, "f").isEndpointConnected(this.providerIdentity.channelId)) {
7978
- return __classPrivateFieldGet$d(this, _ChannelClient_strategy, "f").send(this.providerIdentity.channelId, action, payload);
7991
+ if (__classPrivateFieldGet$c(this, _ChannelClient_strategy, "f").isEndpointConnected(this.providerIdentity.channelId)) {
7992
+ return __classPrivateFieldGet$c(this, _ChannelClient_strategy, "f").send(this.providerIdentity.channelId, action, payload);
7979
7993
  }
7980
7994
  throw new Error('The client you are trying to dispatch from is disconnected from the target provider.');
7981
7995
  }
@@ -8025,16 +8039,23 @@ class ChannelClient extends channel_1$1.ChannelBase {
8025
8039
  */
8026
8040
  async disconnect() {
8027
8041
  await this.sendDisconnectAction();
8028
- __classPrivateFieldGet$d(this, _ChannelClient_close, "f").call(this);
8042
+ __classPrivateFieldGet$c(this, _ChannelClient_close, "f").call(this);
8029
8043
  }
8030
8044
  async sendDisconnectAction() {
8031
- const protectedObj = __classPrivateFieldGet$d(this, _ChannelClient_protectedObj, "f");
8032
- const { channelName, uuid, name } = protectedObj.providerIdentity;
8033
- await protectedObj.wire.sendAction('disconnect-from-channel', {
8045
+ const protectedObj = __classPrivateFieldGet$c(this, _ChannelClient_protectedObj, "f");
8046
+ await protectedObj.close();
8047
+ }
8048
+ /**
8049
+ * @internal
8050
+ * Writing this as a static to keep code together, but in environments with a wire, this will be DI'd into the protectedObject class as close.
8051
+ */
8052
+ static async wireClose(wire, providerIdentity, endpointId) {
8053
+ const { channelName, uuid, name } = providerIdentity;
8054
+ await wire.sendAction('disconnect-from-channel', {
8034
8055
  channelName,
8035
8056
  uuid,
8036
8057
  name,
8037
- endpointId: this.endpointId
8058
+ endpointId
8038
8059
  });
8039
8060
  }
8040
8061
  }
@@ -8054,13 +8075,13 @@ exhaustive.exhaustiveCheck = exhaustiveCheck;
8054
8075
 
8055
8076
  var strategy$3 = {};
8056
8077
 
8057
- var __classPrivateFieldSet$a = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8078
+ var __classPrivateFieldSet$9 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8058
8079
  if (kind === "m") throw new TypeError("Private method is not writable");
8059
8080
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
8060
8081
  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");
8061
8082
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
8062
8083
  };
8063
- var __classPrivateFieldGet$c = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8084
+ var __classPrivateFieldGet$b = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8064
8085
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
8065
8086
  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");
8066
8087
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
@@ -8085,7 +8106,7 @@ class ClassicStrategy {
8085
8106
  // connection problems occur
8086
8107
  _ClassicStrategy_pendingMessagesByEndpointId.set(this, new Map);
8087
8108
  this.send = async (endpointId, action, payload) => {
8088
- const to = __classPrivateFieldGet$c(this, _ClassicStrategy_endpointIdentityMap, "f").get(endpointId);
8109
+ const to = __classPrivateFieldGet$b(this, _ClassicStrategy_endpointIdentityMap, "f").get(endpointId);
8089
8110
  if (!to) {
8090
8111
  throw new Error(`Could not locate routing info for endpoint ${endpointId}`);
8091
8112
  }
@@ -8097,28 +8118,28 @@ class ClassicStrategy {
8097
8118
  }
8098
8119
  delete cleanId.isLocalEndpointId;
8099
8120
  // grab the promise before awaiting it to save in our pending messages map
8100
- const p = __classPrivateFieldGet$c(this, _ClassicStrategy_wire, "f")
8121
+ const p = __classPrivateFieldGet$b(this, _ClassicStrategy_wire, "f")
8101
8122
  .sendAction('send-channel-message', {
8102
8123
  ...cleanId,
8103
8124
  providerIdentity: this.providerIdentity,
8104
8125
  action,
8105
8126
  payload
8106
8127
  });
8107
- __classPrivateFieldGet$c(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").get(endpointId)?.add(p);
8128
+ __classPrivateFieldGet$b(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").get(endpointId)?.add(p);
8108
8129
  const raw = await p.catch((error) => {
8109
8130
  throw new Error(error.message);
8110
8131
  }).finally(() => {
8111
8132
  // clean up the pending promise
8112
- __classPrivateFieldGet$c(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").get(endpointId)?.delete(p);
8133
+ __classPrivateFieldGet$b(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").get(endpointId)?.delete(p);
8113
8134
  });
8114
8135
  return raw.payload.data.result;
8115
8136
  };
8116
8137
  this.close = async () => {
8117
8138
  this.messageReceiver.removeEndpoint(this.providerIdentity.channelId, this.endpointId);
8118
- [...__classPrivateFieldGet$c(this, _ClassicStrategy_endpointIdentityMap, "f").keys()].forEach((id) => this.closeEndpoint(id));
8119
- __classPrivateFieldSet$a(this, _ClassicStrategy_endpointIdentityMap, new Map(), "f");
8139
+ [...__classPrivateFieldGet$b(this, _ClassicStrategy_endpointIdentityMap, "f").keys()].forEach((id) => this.closeEndpoint(id));
8140
+ __classPrivateFieldSet$9(this, _ClassicStrategy_endpointIdentityMap, new Map(), "f");
8120
8141
  };
8121
- __classPrivateFieldSet$a(this, _ClassicStrategy_wire, wire, "f");
8142
+ __classPrivateFieldSet$9(this, _ClassicStrategy_wire, wire, "f");
8122
8143
  }
8123
8144
  onEndpointDisconnect(endpointId, listener) {
8124
8145
  // Never fires for 'classic'.
@@ -8127,20 +8148,20 @@ class ClassicStrategy {
8127
8148
  this.messageReceiver.addEndpoint(listener, this.providerIdentity.channelId, this.endpointId);
8128
8149
  }
8129
8150
  async closeEndpoint(endpointId) {
8130
- const id = __classPrivateFieldGet$c(this, _ClassicStrategy_endpointIdentityMap, "f").get(endpointId);
8131
- __classPrivateFieldGet$c(this, _ClassicStrategy_endpointIdentityMap, "f").delete(endpointId);
8132
- const pendingSet = __classPrivateFieldGet$c(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").get(endpointId);
8151
+ const id = __classPrivateFieldGet$b(this, _ClassicStrategy_endpointIdentityMap, "f").get(endpointId);
8152
+ __classPrivateFieldGet$b(this, _ClassicStrategy_endpointIdentityMap, "f").delete(endpointId);
8153
+ const pendingSet = __classPrivateFieldGet$b(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").get(endpointId);
8133
8154
  pendingSet?.forEach((p) => {
8134
8155
  const errorMsg = `Channel connection with identity uuid: ${id?.uuid} / name: ${id?.name} / endpointId: ${endpointId} no longer connected.`;
8135
8156
  p.cancel(new Error(errorMsg));
8136
8157
  });
8137
8158
  }
8138
8159
  isEndpointConnected(endpointId) {
8139
- return __classPrivateFieldGet$c(this, _ClassicStrategy_endpointIdentityMap, "f").has(endpointId);
8160
+ return __classPrivateFieldGet$b(this, _ClassicStrategy_endpointIdentityMap, "f").has(endpointId);
8140
8161
  }
8141
8162
  addEndpoint(endpointId, payload) {
8142
- __classPrivateFieldGet$c(this, _ClassicStrategy_endpointIdentityMap, "f").set(endpointId, payload.endpointIdentity);
8143
- __classPrivateFieldGet$c(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").set(endpointId, new Set());
8163
+ __classPrivateFieldGet$b(this, _ClassicStrategy_endpointIdentityMap, "f").set(endpointId, payload.endpointIdentity);
8164
+ __classPrivateFieldGet$b(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").set(endpointId, new Set());
8144
8165
  }
8145
8166
  isValidEndpointPayload(payload) {
8146
8167
  return (typeof payload?.endpointIdentity?.endpointId === 'string' ||
@@ -8171,12 +8192,12 @@ function errorToPOJO(error) {
8171
8192
  }
8172
8193
  errors.errorToPOJO = errorToPOJO;
8173
8194
 
8174
- var __classPrivateFieldGet$b = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8195
+ var __classPrivateFieldGet$a = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8175
8196
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
8176
8197
  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");
8177
8198
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
8178
8199
  };
8179
- var __classPrivateFieldSet$9 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8200
+ var __classPrivateFieldSet$8 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8180
8201
  if (kind === "m") throw new TypeError("Private method is not writable");
8181
8202
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
8182
8203
  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");
@@ -8211,8 +8232,8 @@ class RTCEndpoint {
8211
8232
  if (this.rtc.rtcClient.connectionState !== 'connected') {
8212
8233
  this.rtc.rtcClient.removeEventListener('connectionstatechange', this.connectionStateChangeHandler);
8213
8234
  this.close();
8214
- if (__classPrivateFieldGet$b(this, _RTCEndpoint_disconnectListener, "f")) {
8215
- __classPrivateFieldGet$b(this, _RTCEndpoint_disconnectListener, "f").call(this);
8235
+ if (__classPrivateFieldGet$a(this, _RTCEndpoint_disconnectListener, "f")) {
8236
+ __classPrivateFieldGet$a(this, _RTCEndpoint_disconnectListener, "f").call(this);
8216
8237
  }
8217
8238
  }
8218
8239
  };
@@ -8260,9 +8281,9 @@ class RTCEndpoint {
8260
8281
  data = new TextDecoder().decode(e.data);
8261
8282
  }
8262
8283
  const { messageId, action, payload } = JSON.parse(data);
8263
- if (__classPrivateFieldGet$b(this, _RTCEndpoint_processAction, "f")) {
8284
+ if (__classPrivateFieldGet$a(this, _RTCEndpoint_processAction, "f")) {
8264
8285
  try {
8265
- const res = await __classPrivateFieldGet$b(this, _RTCEndpoint_processAction, "f").call(this, action, payload, endpointIdentity);
8286
+ const res = await __classPrivateFieldGet$a(this, _RTCEndpoint_processAction, "f").call(this, action, payload, endpointIdentity);
8266
8287
  this.rtc.channels.response.send(JSON.stringify({
8267
8288
  messageId,
8268
8289
  payload: res,
@@ -8296,25 +8317,25 @@ class RTCEndpoint {
8296
8317
  datachannel.onclose = (e) => {
8297
8318
  [...this.responseMap.values()].forEach((promise) => promise.reject(new Error('RTCDataChannel closed unexpectedly, this is most commonly caused by message size. Note: RTC Channels have a message size limit of ~255kB.')));
8298
8319
  this.close();
8299
- if (__classPrivateFieldGet$b(this, _RTCEndpoint_disconnectListener, "f")) {
8300
- __classPrivateFieldGet$b(this, _RTCEndpoint_disconnectListener, "f").call(this);
8320
+ if (__classPrivateFieldGet$a(this, _RTCEndpoint_disconnectListener, "f")) {
8321
+ __classPrivateFieldGet$a(this, _RTCEndpoint_disconnectListener, "f").call(this);
8301
8322
  }
8302
8323
  };
8303
8324
  });
8304
8325
  }
8305
8326
  onDisconnect(listener) {
8306
- if (!__classPrivateFieldGet$b(this, _RTCEndpoint_disconnectListener, "f")) {
8307
- __classPrivateFieldSet$9(this, _RTCEndpoint_disconnectListener, listener, "f");
8327
+ if (!__classPrivateFieldGet$a(this, _RTCEndpoint_disconnectListener, "f")) {
8328
+ __classPrivateFieldSet$8(this, _RTCEndpoint_disconnectListener, listener, "f");
8308
8329
  }
8309
8330
  else {
8310
8331
  throw new Error('RTCEndpoint disconnectListener cannot be set twice.');
8311
8332
  }
8312
8333
  }
8313
8334
  receive(listener) {
8314
- if (__classPrivateFieldGet$b(this, _RTCEndpoint_processAction, "f")) {
8335
+ if (__classPrivateFieldGet$a(this, _RTCEndpoint_processAction, "f")) {
8315
8336
  throw new Error('You have already set a listener for this RTC Endpoint.');
8316
8337
  }
8317
- __classPrivateFieldSet$9(this, _RTCEndpoint_processAction, listener, "f");
8338
+ __classPrivateFieldSet$8(this, _RTCEndpoint_processAction, listener, "f");
8318
8339
  }
8319
8340
  get connected() {
8320
8341
  return this.rtc.rtcClient.connectionState === 'connected';
@@ -8325,12 +8346,12 @@ _RTCEndpoint_processAction = new WeakMap(), _RTCEndpoint_disconnectListener = ne
8325
8346
 
8326
8347
  var strategy$1 = {};
8327
8348
 
8328
- var __classPrivateFieldGet$a = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8349
+ var __classPrivateFieldGet$9 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8329
8350
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
8330
8351
  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");
8331
8352
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
8332
8353
  };
8333
- var __classPrivateFieldSet$8 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8354
+ var __classPrivateFieldSet$7 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8334
8355
  if (kind === "m") throw new TypeError("Private method is not writable");
8335
8356
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
8336
8357
  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");
@@ -8351,11 +8372,11 @@ class EndpointStrategy {
8351
8372
  return this.getEndpointById(endpointId).send(action, payload);
8352
8373
  };
8353
8374
  this.close = async () => {
8354
- if (__classPrivateFieldGet$a(this, _EndpointStrategy_connected, "f")) {
8355
- __classPrivateFieldGet$a(this, _EndpointStrategy_endpointMap, "f").forEach((endpoint) => endpoint.close());
8356
- __classPrivateFieldSet$8(this, _EndpointStrategy_endpointMap, new Map(), "f");
8375
+ if (__classPrivateFieldGet$9(this, _EndpointStrategy_connected, "f")) {
8376
+ __classPrivateFieldGet$9(this, _EndpointStrategy_endpointMap, "f").forEach((endpoint) => endpoint.close());
8377
+ __classPrivateFieldSet$7(this, _EndpointStrategy_endpointMap, new Map(), "f");
8357
8378
  }
8358
- __classPrivateFieldSet$8(this, _EndpointStrategy_connected, false, "f");
8379
+ __classPrivateFieldSet$7(this, _EndpointStrategy_connected, false, "f");
8359
8380
  };
8360
8381
  this.isValidEndpointPayload = validateEndpoint;
8361
8382
  }
@@ -8363,39 +8384,39 @@ class EndpointStrategy {
8363
8384
  this.getEndpointById(endpointId).onDisconnect(listener);
8364
8385
  }
8365
8386
  receive(listener) {
8366
- if (__classPrivateFieldGet$a(this, _EndpointStrategy_processAction, "f")) {
8387
+ if (__classPrivateFieldGet$9(this, _EndpointStrategy_processAction, "f")) {
8367
8388
  throw new Error(`You have already set a listener for this ${this.StrategyName} Strategy`);
8368
8389
  }
8369
- __classPrivateFieldSet$8(this, _EndpointStrategy_processAction, listener, "f");
8390
+ __classPrivateFieldSet$7(this, _EndpointStrategy_processAction, listener, "f");
8370
8391
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
8371
- __classPrivateFieldGet$a(this, _EndpointStrategy_endpointMap, "f").forEach((endpoint) => endpoint.receive(__classPrivateFieldGet$a(this, _EndpointStrategy_processAction, "f")));
8392
+ __classPrivateFieldGet$9(this, _EndpointStrategy_endpointMap, "f").forEach((endpoint) => endpoint.receive(__classPrivateFieldGet$9(this, _EndpointStrategy_processAction, "f")));
8372
8393
  }
8373
8394
  getEndpointById(endpointId) {
8374
- const endpoint = __classPrivateFieldGet$a(this, _EndpointStrategy_endpointMap, "f").get(endpointId);
8395
+ const endpoint = __classPrivateFieldGet$9(this, _EndpointStrategy_endpointMap, "f").get(endpointId);
8375
8396
  if (!endpoint) {
8376
8397
  throw new Error(`Client with endpoint id ${endpointId} is not connected`);
8377
8398
  }
8378
8399
  return endpoint;
8379
8400
  }
8380
8401
  get connected() {
8381
- return __classPrivateFieldGet$a(this, _EndpointStrategy_connected, "f");
8402
+ return __classPrivateFieldGet$9(this, _EndpointStrategy_connected, "f");
8382
8403
  }
8383
8404
  isEndpointConnected(endpointId) {
8384
- return __classPrivateFieldGet$a(this, _EndpointStrategy_endpointMap, "f").has(endpointId);
8405
+ return __classPrivateFieldGet$9(this, _EndpointStrategy_endpointMap, "f").has(endpointId);
8385
8406
  }
8386
8407
  addEndpoint(endpointId, payload) {
8387
- if (!__classPrivateFieldGet$a(this, _EndpointStrategy_connected, "f")) {
8408
+ if (!__classPrivateFieldGet$9(this, _EndpointStrategy_connected, "f")) {
8388
8409
  console.warn(`Adding endpoint to disconnected ${this.StrategyName} Strategy`);
8389
8410
  return;
8390
8411
  }
8391
8412
  const clientStrat = new this.EndpointType(payload);
8392
- if (__classPrivateFieldGet$a(this, _EndpointStrategy_processAction, "f")) {
8393
- clientStrat.receive(__classPrivateFieldGet$a(this, _EndpointStrategy_processAction, "f"));
8413
+ if (__classPrivateFieldGet$9(this, _EndpointStrategy_processAction, "f")) {
8414
+ clientStrat.receive(__classPrivateFieldGet$9(this, _EndpointStrategy_processAction, "f"));
8394
8415
  }
8395
- __classPrivateFieldGet$a(this, _EndpointStrategy_endpointMap, "f").set(endpointId, clientStrat);
8416
+ __classPrivateFieldGet$9(this, _EndpointStrategy_endpointMap, "f").set(endpointId, clientStrat);
8396
8417
  }
8397
8418
  async closeEndpoint(endpointId) {
8398
- __classPrivateFieldGet$a(this, _EndpointStrategy_endpointMap, "f").delete(endpointId);
8419
+ __classPrivateFieldGet$9(this, _EndpointStrategy_endpointMap, "f").delete(endpointId);
8399
8420
  }
8400
8421
  }
8401
8422
  strategy$1.EndpointStrategy = EndpointStrategy;
@@ -8422,11 +8443,11 @@ var iceManager = {};
8422
8443
 
8423
8444
  Object.defineProperty(iceManager, "__esModule", { value: true });
8424
8445
  iceManager.RTCICEManager = void 0;
8425
- const base_1$i = base$1;
8446
+ const base_1$h = base$1;
8426
8447
  /*
8427
8448
  Singleton that facilitates Offer and Answer exchange required for establishing RTC connections.
8428
8449
  */
8429
- class RTCICEManager extends base_1$i.EmitterBase {
8450
+ class RTCICEManager extends base_1$h.EmitterBase {
8430
8451
  constructor(wire) {
8431
8452
  super(wire, 'channel');
8432
8453
  this.ensureChannelOpened = (channel) => {
@@ -8577,12 +8598,12 @@ function runtimeUuidMeetsMinimumRuntimeVersion(runtimeUuid, minVersion) {
8577
8598
  }
8578
8599
  runtimeVersioning.runtimeUuidMeetsMinimumRuntimeVersion = runtimeUuidMeetsMinimumRuntimeVersion;
8579
8600
 
8580
- var __classPrivateFieldGet$9 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8601
+ var __classPrivateFieldGet$8 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8581
8602
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
8582
8603
  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");
8583
8604
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
8584
8605
  };
8585
- var __classPrivateFieldSet$7 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8606
+ var __classPrivateFieldSet$6 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8586
8607
  if (kind === "m") throw new TypeError("Private method is not writable");
8587
8608
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
8588
8609
  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");
@@ -8624,18 +8645,18 @@ class ChannelProvider extends channel_1.ChannelBase {
8624
8645
  * a read-only array containing all the identities of connecting clients.
8625
8646
  */
8626
8647
  get connections() {
8627
- return [...__classPrivateFieldGet$9(this, _ChannelProvider_connections, "f")];
8648
+ return [...__classPrivateFieldGet$8(this, _ChannelProvider_connections, "f")];
8628
8649
  }
8629
8650
  static handleClientDisconnection(channel, payload) {
8630
8651
  const removeById = channel.connections.find((identity) => identity.endpointId === payload.endpointId);
8631
8652
  if (removeById) {
8632
- __classPrivateFieldGet$9(channel, _ChannelProvider_removeEndpoint, "f").call(channel, removeById);
8653
+ __classPrivateFieldGet$8(channel, _ChannelProvider_removeEndpoint, "f").call(channel, removeById);
8633
8654
  }
8634
8655
  else {
8635
8656
  const multipleRemoves = channel.connections.filter((identity) => {
8636
8657
  return identity.uuid === payload.uuid && identity.name === payload.name;
8637
8658
  });
8638
- multipleRemoves.forEach(__classPrivateFieldGet$9(channel, _ChannelProvider_removeEndpoint, "f"));
8659
+ multipleRemoves.forEach(__classPrivateFieldGet$8(channel, _ChannelProvider_removeEndpoint, "f"));
8639
8660
  }
8640
8661
  channel.disconnectListener(payload);
8641
8662
  }
@@ -8645,15 +8666,15 @@ class ChannelProvider extends channel_1.ChannelBase {
8645
8666
  /**
8646
8667
  * @internal
8647
8668
  */
8648
- constructor(providerIdentity, wire, strategy) {
8669
+ constructor(providerIdentity, close, strategy) {
8649
8670
  super();
8650
8671
  _ChannelProvider_connections.set(this, void 0);
8651
8672
  _ChannelProvider_protectedObj.set(this, void 0);
8652
8673
  _ChannelProvider_strategy.set(this, void 0);
8653
8674
  _ChannelProvider_removeEndpoint.set(this, (identity) => {
8654
8675
  const remainingConnections = this.connections.filter((clientIdentity) => clientIdentity.endpointId !== identity.endpointId);
8655
- __classPrivateFieldGet$9(this, _ChannelProvider_strategy, "f").closeEndpoint(identity.endpointId);
8656
- __classPrivateFieldSet$7(this, _ChannelProvider_connections, remainingConnections, "f");
8676
+ __classPrivateFieldGet$8(this, _ChannelProvider_strategy, "f").closeEndpoint(identity.endpointId);
8677
+ __classPrivateFieldSet$6(this, _ChannelProvider_connections, remainingConnections, "f");
8657
8678
  });
8658
8679
  // Must be bound.
8659
8680
  this.processAction = async (action, payload, senderIdentity) => {
@@ -8667,17 +8688,17 @@ class ChannelProvider extends channel_1.ChannelBase {
8667
8688
  return super.processAction(action, payload, senderIdentity);
8668
8689
  };
8669
8690
  _ChannelProvider_close.set(this, () => {
8670
- __classPrivateFieldGet$9(this, _ChannelProvider_strategy, "f").close();
8691
+ __classPrivateFieldGet$8(this, _ChannelProvider_strategy, "f").close();
8671
8692
  const remove = ChannelProvider.removalMap.get(this);
8672
8693
  if (remove) {
8673
8694
  remove();
8674
8695
  }
8675
8696
  });
8676
- __classPrivateFieldSet$7(this, _ChannelProvider_protectedObj, new channel_1.ProtectedItems(providerIdentity, wire), "f");
8697
+ __classPrivateFieldSet$6(this, _ChannelProvider_protectedObj, new channel_1.ProtectedItems(providerIdentity, close), "f");
8677
8698
  this.connectListener = () => undefined;
8678
8699
  this.disconnectListener = () => undefined;
8679
- __classPrivateFieldSet$7(this, _ChannelProvider_connections, [], "f");
8680
- __classPrivateFieldSet$7(this, _ChannelProvider_strategy, strategy, "f");
8700
+ __classPrivateFieldSet$6(this, _ChannelProvider_connections, [], "f");
8701
+ __classPrivateFieldSet$6(this, _ChannelProvider_strategy, strategy, "f");
8681
8702
  strategy.receive(this.processAction);
8682
8703
  }
8683
8704
  /**
@@ -8708,13 +8729,13 @@ class ChannelProvider extends channel_1.ChannelBase {
8708
8729
  */
8709
8730
  dispatch(to, action, payload) {
8710
8731
  const endpointId = to.endpointId ?? this.getEndpointIdForOpenFinId(to, action);
8711
- if (endpointId && __classPrivateFieldGet$9(this, _ChannelProvider_strategy, "f").isEndpointConnected(endpointId)) {
8712
- return __classPrivateFieldGet$9(this, _ChannelProvider_strategy, "f").send(endpointId, action, payload);
8732
+ if (endpointId && __classPrivateFieldGet$8(this, _ChannelProvider_strategy, "f").isEndpointConnected(endpointId)) {
8733
+ return __classPrivateFieldGet$8(this, _ChannelProvider_strategy, "f").send(endpointId, action, payload);
8713
8734
  }
8714
8735
  return Promise.reject(new Error(`Client connection with identity uuid: ${to.uuid} / name: ${to.name} / endpointId: ${endpointId} no longer connected.`));
8715
8736
  }
8716
8737
  async processConnection(senderId, payload) {
8717
- __classPrivateFieldGet$9(this, _ChannelProvider_connections, "f").push(senderId);
8738
+ __classPrivateFieldGet$8(this, _ChannelProvider_connections, "f").push(senderId);
8718
8739
  return this.connectListener(senderId, payload);
8719
8740
  }
8720
8741
  /**
@@ -8737,7 +8758,7 @@ class ChannelProvider extends channel_1.ChannelBase {
8737
8758
  * ```
8738
8759
  */
8739
8760
  publish(action, payload) {
8740
- return this.connections.map((to) => __classPrivateFieldGet$9(this, _ChannelProvider_strategy, "f").send(to.endpointId, action, payload));
8761
+ return this.connections.map((to) => __classPrivateFieldGet$8(this, _ChannelProvider_strategy, "f").send(to.endpointId, action, payload));
8741
8762
  }
8742
8763
  /**
8743
8764
  * Register a listener that is called on every new client connection.
@@ -8811,11 +8832,11 @@ class ChannelProvider extends channel_1.ChannelBase {
8811
8832
  * ```
8812
8833
  */
8813
8834
  async destroy() {
8814
- const protectedObj = __classPrivateFieldGet$9(this, _ChannelProvider_protectedObj, "f");
8815
- const { channelName } = protectedObj.providerIdentity;
8816
- __classPrivateFieldSet$7(this, _ChannelProvider_connections, [], "f");
8817
- await protectedObj.wire.sendAction('destroy-channel', { channelName });
8818
- __classPrivateFieldGet$9(this, _ChannelProvider_close, "f").call(this);
8835
+ const protectedObj = __classPrivateFieldGet$8(this, _ChannelProvider_protectedObj, "f");
8836
+ protectedObj.providerIdentity;
8837
+ __classPrivateFieldSet$6(this, _ChannelProvider_connections, [], "f");
8838
+ await protectedObj.close();
8839
+ __classPrivateFieldGet$8(this, _ChannelProvider_close, "f").call(this);
8819
8840
  }
8820
8841
  /**
8821
8842
  * Returns an array with info on every Client connected to the Provider
@@ -8885,7 +8906,7 @@ class ChannelProvider extends channel_1.ChannelBase {
8885
8906
  getEndpointIdForOpenFinId(clientIdentity, action) {
8886
8907
  const matchingConnections = this.connections.filter((c) => c.name === clientIdentity.name && c.uuid === clientIdentity.uuid);
8887
8908
  if (matchingConnections.length >= 2) {
8888
- const protectedObj = __classPrivateFieldGet$9(this, _ChannelProvider_protectedObj, "f");
8909
+ const protectedObj = __classPrivateFieldGet$8(this, _ChannelProvider_protectedObj, "f");
8889
8910
  const { uuid, name } = clientIdentity;
8890
8911
  const providerUuid = protectedObj?.providerIdentity.uuid;
8891
8912
  const providerName = protectedObj?.providerIdentity.name;
@@ -8906,6 +8927,9 @@ class ChannelProvider extends channel_1.ChannelBase {
8906
8927
  static clientIsMultiRuntime(subscriptionIdentity) {
8907
8928
  return subscriptionIdentity.runtimeUuid !== undefined;
8908
8929
  }
8930
+ static async wireClose(wire, channelName) {
8931
+ await wire.sendAction('destroy-channel', { channelName });
8932
+ }
8909
8933
  }
8910
8934
  provider.ChannelProvider = ChannelProvider;
8911
8935
  _ChannelProvider_connections = new WeakMap(), _ChannelProvider_protectedObj = new WeakMap(), _ChannelProvider_strategy = new WeakMap(), _ChannelProvider_removeEndpoint = new WeakMap(), _ChannelProvider_close = new WeakMap();
@@ -8918,13 +8942,13 @@ var messageReceiver$1 = {};
8918
8942
  Object.defineProperty(messageReceiver$1, "__esModule", { value: true });
8919
8943
  messageReceiver$1.MessageReceiver = void 0;
8920
8944
  const client_1$1 = client;
8921
- const base_1$h = base$1;
8945
+ const base_1$g = base$1;
8922
8946
  /*
8923
8947
  This is a singleton (per fin object) tasked with routing messages coming off the ipc to the correct endpoint.
8924
8948
  It needs to be a singleton because there can only be one per wire. It tracks both clients and providers' processAction passed in via the strategy.
8925
8949
  If functionality is not about receiving messages, it does not belong here.
8926
8950
  */
8927
- class MessageReceiver extends base_1$h.Base {
8951
+ class MessageReceiver extends base_1$g.Base {
8928
8952
  constructor(wire) {
8929
8953
  super(wire);
8930
8954
  this.onmessage = (msg) => {
@@ -9091,13 +9115,13 @@ class CombinedStrategy {
9091
9115
  }
9092
9116
  strategy.default = CombinedStrategy;
9093
9117
 
9094
- var __classPrivateFieldSet$6 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
9118
+ var __classPrivateFieldSet$5 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
9095
9119
  if (kind === "m") throw new TypeError("Private method is not writable");
9096
9120
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9097
9121
  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");
9098
9122
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
9099
9123
  };
9100
- var __classPrivateFieldGet$8 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9124
+ var __classPrivateFieldGet$7 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9101
9125
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9102
9126
  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");
9103
9127
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
@@ -9106,7 +9130,7 @@ var _ConnectionManager_messageReceiver, _ConnectionManager_rtcConnectionManager;
9106
9130
  Object.defineProperty(connectionManager, "__esModule", { value: true });
9107
9131
  connectionManager.ConnectionManager = void 0;
9108
9132
  const exhaustive_1 = exhaustive;
9109
- const base_1$g = base$1;
9133
+ const base_1$f = base$1;
9110
9134
  const strategy_1 = strategy$3;
9111
9135
  const strategy_2 = strategy$2;
9112
9136
  const ice_manager_1 = iceManager;
@@ -9114,7 +9138,7 @@ const provider_1$1 = provider;
9114
9138
  const message_receiver_1 = messageReceiver$1;
9115
9139
  const protocol_manager_1 = protocolManager;
9116
9140
  const strategy_3 = strategy;
9117
- class ConnectionManager extends base_1$g.Base {
9141
+ class ConnectionManager extends base_1$f.Base {
9118
9142
  static getProtocolOptionsFromStrings(protocols) {
9119
9143
  return protocols.map((protocol) => {
9120
9144
  switch (protocol) {
@@ -9143,8 +9167,8 @@ class ConnectionManager extends base_1$g.Base {
9143
9167
  };
9144
9168
  this.providerMap = new Map();
9145
9169
  this.protocolManager = new protocol_manager_1.ProtocolManager(this.wire.environment.type === 'node' ? ['classic'] : ['rtc', 'classic']);
9146
- __classPrivateFieldSet$6(this, _ConnectionManager_messageReceiver, new message_receiver_1.MessageReceiver(wire), "f");
9147
- __classPrivateFieldSet$6(this, _ConnectionManager_rtcConnectionManager, new ice_manager_1.RTCICEManager(wire), "f");
9170
+ __classPrivateFieldSet$5(this, _ConnectionManager_messageReceiver, new message_receiver_1.MessageReceiver(wire), "f");
9171
+ __classPrivateFieldSet$5(this, _ConnectionManager_rtcConnectionManager, new ice_manager_1.RTCICEManager(wire), "f");
9148
9172
  wire.registerMessageHandler(this.onmessage.bind(this));
9149
9173
  }
9150
9174
  createProvider(options, providerIdentity) {
@@ -9155,7 +9179,7 @@ class ConnectionManager extends base_1$g.Base {
9155
9179
  case 'rtc':
9156
9180
  return new strategy_2.RTCStrategy();
9157
9181
  case 'classic':
9158
- return new strategy_1.ClassicStrategy(this.wire, __classPrivateFieldGet$8(this, _ConnectionManager_messageReceiver, "f"),
9182
+ return new strategy_1.ClassicStrategy(this.wire, __classPrivateFieldGet$7(this, _ConnectionManager_messageReceiver, "f"),
9159
9183
  // Providers do not have an endpointId, use channelId as endpointId in the strategy.
9160
9184
  providerIdentity.channelId, providerIdentity);
9161
9185
  default:
@@ -9175,7 +9199,7 @@ class ConnectionManager extends base_1$g.Base {
9175
9199
  // Should be impossible.
9176
9200
  throw new Error('failed to combine strategies');
9177
9201
  }
9178
- const channel = new provider_1$1.ChannelProvider(providerIdentity, this.wire, strategy);
9202
+ const channel = new provider_1$1.ChannelProvider(providerIdentity, () => provider_1$1.ChannelProvider.wireClose(this.wire, providerIdentity.channelName), strategy);
9179
9203
  const key = providerIdentity.channelId;
9180
9204
  this.providerMap.set(key, {
9181
9205
  provider: channel,
@@ -9191,7 +9215,7 @@ class ConnectionManager extends base_1$g.Base {
9191
9215
  const supportedProtocols = await Promise.all(protocols.map(async (type) => {
9192
9216
  switch (type) {
9193
9217
  case 'rtc': {
9194
- const { rtcClient, channels, offer, rtcConnectionId, channelsOpened } = await __classPrivateFieldGet$8(this, _ConnectionManager_rtcConnectionManager, "f").startClientOffer();
9218
+ const { rtcClient, channels, offer, rtcConnectionId, channelsOpened } = await __classPrivateFieldGet$7(this, _ConnectionManager_rtcConnectionManager, "f").startClientOffer();
9195
9219
  rtcPacket = { rtcClient, channels, channelsOpened };
9196
9220
  return {
9197
9221
  type: 'rtc',
@@ -9218,18 +9242,18 @@ class ConnectionManager extends base_1$g.Base {
9218
9242
  routingInfo.endpointId = this.wire.environment.getNextMessageId();
9219
9243
  // For New Clients connecting to Old Providers. To prevent multi-dispatching and publishing, we delete previously-connected
9220
9244
  // clients that are in the same context as the newly-connected client.
9221
- __classPrivateFieldGet$8(this, _ConnectionManager_messageReceiver, "f").checkForPreviousClientConnection(routingInfo.channelId);
9245
+ __classPrivateFieldGet$7(this, _ConnectionManager_messageReceiver, "f").checkForPreviousClientConnection(routingInfo.channelId);
9222
9246
  }
9223
9247
  const answer = routingInfo.answer ?? {
9224
9248
  supportedProtocols: [{ type: 'classic', version: 1 }]
9225
9249
  };
9226
9250
  const createStrategyFromAnswer = async (protocol) => {
9227
9251
  if (protocol.type === 'rtc' && rtcPacket) {
9228
- await __classPrivateFieldGet$8(this, _ConnectionManager_rtcConnectionManager, "f").finishClientOffer(rtcPacket.rtcClient, protocol.payload.answer, rtcPacket.channelsOpened);
9252
+ await __classPrivateFieldGet$7(this, _ConnectionManager_rtcConnectionManager, "f").finishClientOffer(rtcPacket.rtcClient, protocol.payload.answer, rtcPacket.channelsOpened);
9229
9253
  return new strategy_2.RTCStrategy();
9230
9254
  }
9231
9255
  if (protocol.type === 'classic') {
9232
- return new strategy_1.ClassicStrategy(this.wire, __classPrivateFieldGet$8(this, _ConnectionManager_messageReceiver, "f"), routingInfo.endpointId, routingInfo);
9256
+ return new strategy_1.ClassicStrategy(this.wire, __classPrivateFieldGet$7(this, _ConnectionManager_messageReceiver, "f"), routingInfo.endpointId, routingInfo);
9233
9257
  }
9234
9258
  return null;
9235
9259
  };
@@ -9297,7 +9321,7 @@ class ConnectionManager extends base_1$g.Base {
9297
9321
  clientAnswer = await overlappingProtocols.reduce(async (accumP, protocolToUse) => {
9298
9322
  const answer = await accumP;
9299
9323
  if (protocolToUse.type === 'rtc') {
9300
- const { answer: rtcAnswer, rtcClient, channels } = await __classPrivateFieldGet$8(this, _ConnectionManager_rtcConnectionManager, "f").createProviderAnswer(protocolToUse.payload.rtcConnectionId, protocolToUse.payload.offer);
9324
+ const { answer: rtcAnswer, rtcClient, channels } = await __classPrivateFieldGet$7(this, _ConnectionManager_rtcConnectionManager, "f").createProviderAnswer(protocolToUse.payload.rtcConnectionId, protocolToUse.payload.offer);
9301
9325
  answer.supportedProtocols.push({
9302
9326
  type: 'rtc',
9303
9327
  version: strategy_2.RTCInfo.version,
@@ -9345,13 +9369,13 @@ _ConnectionManager_messageReceiver = new WeakMap(), _ConnectionManager_rtcConnec
9345
9369
  *
9346
9370
  * @packageDocumentation
9347
9371
  */
9348
- var __classPrivateFieldSet$5 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
9372
+ var __classPrivateFieldSet$4 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
9349
9373
  if (kind === "m") throw new TypeError("Private method is not writable");
9350
9374
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9351
9375
  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");
9352
9376
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
9353
9377
  };
9354
- var __classPrivateFieldGet$7 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9378
+ var __classPrivateFieldGet$6 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9355
9379
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9356
9380
  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");
9357
9381
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
@@ -9362,7 +9386,7 @@ channel$1.Channel = void 0;
9362
9386
  /* eslint-disable no-console */
9363
9387
  const events_1$5 = require$$0;
9364
9388
  const lazy_1$1 = lazy;
9365
- const base_1$f = base$1;
9389
+ const base_1$e = base$1;
9366
9390
  const client_1 = client;
9367
9391
  const connection_manager_1 = connectionManager;
9368
9392
  const provider_1 = provider;
@@ -9393,7 +9417,7 @@ function retryDelay(count) {
9393
9417
  * * {@link Channel.onChannelConnect onChannelConnect(listener)}
9394
9418
  * * {@link Channel.onChannelDisconnect onChannelDisconnect(listener)}
9395
9419
  */
9396
- class Channel extends base_1$f.EmitterBase {
9420
+ class Channel extends base_1$e.EmitterBase {
9397
9421
  /**
9398
9422
  * @internal
9399
9423
  */
@@ -9408,11 +9432,11 @@ class Channel extends base_1$f.EmitterBase {
9408
9432
  client_1.ChannelClient.handleProviderDisconnect(eventPayload);
9409
9433
  }),
9410
9434
  this.on('connected', (...args) => {
9411
- __classPrivateFieldGet$7(this, _Channel_internalEmitter, "f").emit('connected', ...args);
9435
+ __classPrivateFieldGet$6(this, _Channel_internalEmitter, "f").emit('connected', ...args);
9412
9436
  })
9413
9437
  ]).catch(() => new Error('error setting up channel connection listeners'));
9414
9438
  }));
9415
- __classPrivateFieldSet$5(this, _Channel_connectionManager, new connection_manager_1.ConnectionManager(wire), "f");
9439
+ __classPrivateFieldSet$4(this, _Channel_connectionManager, new connection_manager_1.ConnectionManager(wire), "f");
9416
9440
  }
9417
9441
  /**
9418
9442
  *
@@ -9487,7 +9511,7 @@ class Channel extends base_1$f.EmitterBase {
9487
9511
  resolve(true);
9488
9512
  }
9489
9513
  };
9490
- __classPrivateFieldGet$7(this, _Channel_internalEmitter, "f").on('connected', connectedListener);
9514
+ __classPrivateFieldGet$6(this, _Channel_internalEmitter, "f").on('connected', connectedListener);
9491
9515
  });
9492
9516
  try {
9493
9517
  if (retryInfo.count > 0) {
@@ -9519,7 +9543,7 @@ class Channel extends base_1$f.EmitterBase {
9519
9543
  finally {
9520
9544
  retryInfo.count += 1;
9521
9545
  // in case of other errors, remove our listener
9522
- __classPrivateFieldGet$7(this, _Channel_internalEmitter, "f").removeListener('connected', connectedListener);
9546
+ __classPrivateFieldGet$6(this, _Channel_internalEmitter, "f").removeListener('connected', connectedListener);
9523
9547
  }
9524
9548
  } while (shouldWait); // If we're waiting we retry the above loop
9525
9549
  // Should wait was false, no channel was found.
@@ -9578,12 +9602,12 @@ class Channel extends base_1$f.EmitterBase {
9578
9602
  async connect(channelName, options = {}) {
9579
9603
  // Make sure we don't connect before listeners are set up
9580
9604
  // This also errors if we're not in OpenFin, ensuring we don't run unnecessary code
9581
- await __classPrivateFieldGet$7(this, _Channel_readyToConnect, "f").getValue();
9605
+ await __classPrivateFieldGet$6(this, _Channel_readyToConnect, "f").getValue();
9582
9606
  if (!channelName || typeof channelName !== 'string') {
9583
9607
  throw new Error('Please provide a channelName string to connect to a channel.');
9584
9608
  }
9585
9609
  const opts = { wait: true, ...this.wire.environment.getDefaultChannelOptions().connect, ...options };
9586
- const { offer, rtc: rtcPacket } = await __classPrivateFieldGet$7(this, _Channel_connectionManager, "f").createClientOffer(opts);
9610
+ const { offer, rtc: rtcPacket } = await __classPrivateFieldGet$6(this, _Channel_connectionManager, "f").createClientOffer(opts);
9587
9611
  let connectionUrl;
9588
9612
  if (this.fin.me.isFrame || this.fin.me.isView || this.fin.me.isWindow) {
9589
9613
  connectionUrl = (await this.fin.me.getInfo()).url;
@@ -9595,8 +9619,8 @@ class Channel extends base_1$f.EmitterBase {
9595
9619
  connectionUrl
9596
9620
  };
9597
9621
  const routingInfo = await this.safeConnect(channelName, opts.wait, connectPayload);
9598
- const strategy = await __classPrivateFieldGet$7(this, _Channel_connectionManager, "f").createClientStrategy(rtcPacket, routingInfo);
9599
- const channel = new client_1.ChannelClient(routingInfo, this.wire, strategy);
9622
+ const strategy = await __classPrivateFieldGet$6(this, _Channel_connectionManager, "f").createClientStrategy(rtcPacket, routingInfo);
9623
+ const channel = new client_1.ChannelClient(routingInfo, () => client_1.ChannelClient.wireClose(this.wire, routingInfo, routingInfo.endpointId), strategy);
9600
9624
  // It is the client's responsibility to handle endpoint disconnection to the provider.
9601
9625
  // If the endpoint dies, the client will force a disconnection through the core.
9602
9626
  // The provider does not care about endpoint disconnection.
@@ -9664,7 +9688,7 @@ class Channel extends base_1$f.EmitterBase {
9664
9688
  throw new Error('Please provide a channelName to create a channel');
9665
9689
  }
9666
9690
  const { payload: { data: providerIdentity } } = await this.wire.sendAction('create-channel', { channelName });
9667
- const channel = __classPrivateFieldGet$7(this, _Channel_connectionManager, "f").createProvider(options, providerIdentity);
9691
+ const channel = __classPrivateFieldGet$6(this, _Channel_connectionManager, "f").createProvider(options, providerIdentity);
9668
9692
  // TODO: fix typing (internal)
9669
9693
  // @ts-expect-error
9670
9694
  this.on('client-disconnected', (eventPayload) => {
@@ -9688,7 +9712,7 @@ interappbus.InterAppPayload = interappbus.InterApplicationBus = void 0;
9688
9712
  * @packageDocumentation
9689
9713
  */
9690
9714
  const events_1$4 = require$$0;
9691
- const base_1$e = base$1;
9715
+ const base_1$d = base$1;
9692
9716
  const ref_counter_1 = refCounter;
9693
9717
  const index_1$2 = channel$1;
9694
9718
  const validate_1$3 = validate;
@@ -9696,7 +9720,7 @@ const validate_1$3 = validate;
9696
9720
  * A messaging bus that allows for pub/sub messaging between different applications.
9697
9721
  *
9698
9722
  */
9699
- class InterApplicationBus extends base_1$e.Base {
9723
+ class InterApplicationBus extends base_1$d.Base {
9700
9724
  /**
9701
9725
  * @internal
9702
9726
  */
@@ -9902,12 +9926,12 @@ var clipboard = {};
9902
9926
  */
9903
9927
  Object.defineProperty(clipboard, "__esModule", { value: true });
9904
9928
  clipboard.Clipboard = void 0;
9905
- const base_1$d = base$1;
9929
+ const base_1$c = base$1;
9906
9930
  /**
9907
9931
  * The Clipboard API allows reading and writing to the clipboard in multiple formats.
9908
9932
  *
9909
9933
  */
9910
- class Clipboard extends base_1$d.Base {
9934
+ class Clipboard extends base_1$c.Base {
9911
9935
  /**
9912
9936
  * Writes data into the clipboard as plain text
9913
9937
  * @param writeObj The object for writing data into the clipboard
@@ -10096,7 +10120,7 @@ var Instance$4 = {};
10096
10120
  Object.defineProperty(Instance$4, "__esModule", { value: true });
10097
10121
  Instance$4.ExternalApplication = void 0;
10098
10122
  /* eslint-disable import/prefer-default-export */
10099
- const base_1$c = base$1;
10123
+ const base_1$b = base$1;
10100
10124
  /**
10101
10125
  * An ExternalApplication object representing native language adapter connections to the runtime. Allows
10102
10126
  * the developer to listen to {@link OpenFin.ExternalApplicationEvents external application events}.
@@ -10107,7 +10131,7 @@ const base_1$c = base$1;
10107
10131
  * - Processes started via `System.launchExternalApplication`
10108
10132
  * - Processes monitored via `System.monitorExternalProcess`
10109
10133
  */
10110
- class ExternalApplication extends base_1$c.EmitterBase {
10134
+ class ExternalApplication extends base_1$b.EmitterBase {
10111
10135
  /**
10112
10136
  * @internal
10113
10137
  */
@@ -10135,12 +10159,12 @@ Instance$4.ExternalApplication = ExternalApplication;
10135
10159
 
10136
10160
  Object.defineProperty(Factory$5, "__esModule", { value: true });
10137
10161
  Factory$5.ExternalApplicationModule = void 0;
10138
- const base_1$b = base$1;
10162
+ const base_1$a = base$1;
10139
10163
  const Instance_1$4 = Instance$4;
10140
10164
  /**
10141
10165
  * Static namespace for OpenFin API methods that interact with the {@link ExternalApplication} class, available under `fin.ExternalApplication`.
10142
10166
  */
10143
- class ExternalApplicationModule extends base_1$b.Base {
10167
+ class ExternalApplicationModule extends base_1$a.Base {
10144
10168
  /**
10145
10169
  * Asynchronously returns an External Application object that represents an external application.
10146
10170
  * <br>It is possible to wrap a process that does not yet exist, (for example, to listen for startup-related events)
@@ -10222,7 +10246,7 @@ var Instance$3 = {};
10222
10246
  Object.defineProperty(Instance$3, "__esModule", { value: true });
10223
10247
  Instance$3._Frame = void 0;
10224
10248
  /* eslint-disable import/prefer-default-export */
10225
- const base_1$a = base$1;
10249
+ const base_1$9 = base$1;
10226
10250
  /**
10227
10251
  * An iframe represents an embedded HTML page within a parent HTML page. Because this embedded page
10228
10252
  * has its own DOM and global JS context (which may or may not be linked to that of the parent depending
@@ -10243,7 +10267,7 @@ const base_1$a = base$1;
10243
10267
  * The fin.Frame namespace represents a way to interact with `iframes` and facilitates the discovery of current context
10244
10268
  * (iframe or main window) as well as the ability to listen for {@link OpenFin.FrameEvents frame-specific events}.
10245
10269
  */
10246
- class _Frame extends base_1$a.EmitterBase {
10270
+ class _Frame extends base_1$9.EmitterBase {
10247
10271
  /**
10248
10272
  * @internal
10249
10273
  */
@@ -10289,13 +10313,13 @@ Instance$3._Frame = _Frame;
10289
10313
 
10290
10314
  Object.defineProperty(Factory$4, "__esModule", { value: true });
10291
10315
  Factory$4._FrameModule = void 0;
10292
- const base_1$9 = base$1;
10316
+ const base_1$8 = base$1;
10293
10317
  const validate_1$2 = validate;
10294
10318
  const Instance_1$3 = Instance$3;
10295
10319
  /**
10296
10320
  * Static namespace for OpenFin API methods that interact with the {@link _Frame} class, available under `fin.Frame`.
10297
10321
  */
10298
- class _FrameModule extends base_1$9.Base {
10322
+ class _FrameModule extends base_1$8.Base {
10299
10323
  /**
10300
10324
  * Asynchronously returns an API handle for the given Frame identity.
10301
10325
  *
@@ -10416,12 +10440,12 @@ var globalHotkey$1 = {};
10416
10440
 
10417
10441
  Object.defineProperty(globalHotkey$1, "__esModule", { value: true });
10418
10442
  globalHotkey$1.GlobalHotkey = void 0;
10419
- const base_1$8 = base$1;
10443
+ const base_1$7 = base$1;
10420
10444
  /**
10421
10445
  * The GlobalHotkey module can register/unregister a global hotkeys.
10422
10446
  *
10423
10447
  */
10424
- class GlobalHotkey extends base_1$8.EmitterBase {
10448
+ class GlobalHotkey extends base_1$7.EmitterBase {
10425
10449
  /**
10426
10450
  * @internal
10427
10451
  */
@@ -10555,7 +10579,7 @@ var Factory$3 = {};
10555
10579
 
10556
10580
  var Instance$2 = {};
10557
10581
 
10558
- var __classPrivateFieldGet$6 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
10582
+ var __classPrivateFieldGet$5 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
10559
10583
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10560
10584
  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");
10561
10585
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
@@ -10564,7 +10588,7 @@ var _Platform_connectToProvider;
10564
10588
  Object.defineProperty(Instance$2, "__esModule", { value: true });
10565
10589
  Instance$2.Platform = void 0;
10566
10590
  /* eslint-disable import/prefer-default-export, no-undef */
10567
- const base_1$7 = base$1;
10591
+ const base_1$6 = base$1;
10568
10592
  const validate_1$1 = validate;
10569
10593
  // Reuse clients to avoid overwriting already-registered client in provider
10570
10594
  const clientMap = new Map();
@@ -10573,7 +10597,7 @@ const clientMap = new Map();
10573
10597
  * Enables taking snapshots of itself and applying them to restore a previous configuration
10574
10598
  * as well as listen to {@link OpenFin.PlatformEvents platform events}.
10575
10599
  */
10576
- class Platform extends base_1$7.EmitterBase {
10600
+ class Platform extends base_1$6.EmitterBase {
10577
10601
  /**
10578
10602
  * @internal
10579
10603
  */
@@ -10588,7 +10612,7 @@ class Platform extends base_1$7.EmitterBase {
10588
10612
  const target = identity || this.identity;
10589
10613
  const { uuid } = target;
10590
10614
  if (!clientMap.has(uuid)) {
10591
- const clientPromise = __classPrivateFieldGet$6(this, _Platform_connectToProvider, "f").call(this, uuid);
10615
+ const clientPromise = __classPrivateFieldGet$5(this, _Platform_connectToProvider, "f").call(this, uuid);
10592
10616
  clientMap.set(uuid, clientPromise);
10593
10617
  }
10594
10618
  // we set it above
@@ -11413,7 +11437,7 @@ function overrideFromComposables(...overrides) {
11413
11437
  commonUtils.overrideFromComposables = overrideFromComposables;
11414
11438
  commonUtils.default = { isValidPresetType };
11415
11439
 
11416
- var __classPrivateFieldGet$5 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
11440
+ var __classPrivateFieldGet$4 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
11417
11441
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
11418
11442
  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");
11419
11443
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
@@ -11423,7 +11447,7 @@ Object.defineProperty(Instance$1, "__esModule", { value: true });
11423
11447
  Instance$1.Layout = void 0;
11424
11448
  const lazy_1 = lazy;
11425
11449
  const validate_1 = validate;
11426
- const base_1$6 = base$1;
11450
+ const base_1$5 = base$1;
11427
11451
  const common_utils_1 = commonUtils;
11428
11452
  const layout_entities_1 = layoutEntities;
11429
11453
  const layout_constants_1$1 = layout_constants;
@@ -11559,7 +11583,7 @@ const layout_constants_1$1 = layout_constants;
11559
11583
  * }
11560
11584
  * ```
11561
11585
  */
11562
- class Layout extends base_1$6.Base {
11586
+ class Layout extends base_1$5.Base {
11563
11587
  /**
11564
11588
  * @internal
11565
11589
  */
@@ -11780,7 +11804,7 @@ class Layout extends base_1$6.Base {
11780
11804
  this.wire.sendAction('layout-get-root-item').catch(() => {
11781
11805
  // don't expose
11782
11806
  });
11783
- const client = await __classPrivateFieldGet$5(this, _Layout_layoutClient, "f").getValue();
11807
+ const client = await __classPrivateFieldGet$4(this, _Layout_layoutClient, "f").getValue();
11784
11808
  const root = await client.getRoot('layoutName' in this.identity ? this.identity : undefined);
11785
11809
  return layout_entities_1.LayoutNode.getEntity(root, client);
11786
11810
  }
@@ -11788,12 +11812,12 @@ class Layout extends base_1$6.Base {
11788
11812
  Instance$1.Layout = Layout;
11789
11813
  _Layout_layoutClient = new WeakMap();
11790
11814
 
11791
- var __classPrivateFieldGet$4 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
11815
+ var __classPrivateFieldGet$3 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
11792
11816
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
11793
11817
  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");
11794
11818
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11795
11819
  };
11796
- var __classPrivateFieldSet$4 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
11820
+ var __classPrivateFieldSet$3 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
11797
11821
  if (kind === "m") throw new TypeError("Private method is not writable");
11798
11822
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
11799
11823
  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");
@@ -11802,13 +11826,13 @@ var __classPrivateFieldSet$4 = (commonjsGlobal && commonjsGlobal.__classPrivateF
11802
11826
  var _LayoutModule_instances, _LayoutModule_layoutInitializationAttempted, _LayoutModule_layoutManager, _LayoutModule_getLayoutManagerSpy, _LayoutModule_getSafeLayoutManager;
11803
11827
  Object.defineProperty(Factory$2, "__esModule", { value: true });
11804
11828
  Factory$2.LayoutModule = void 0;
11805
- const base_1$5 = base$1;
11829
+ const base_1$4 = base$1;
11806
11830
  const Instance_1$2 = Instance$1;
11807
11831
  const layout_constants_1 = layout_constants;
11808
11832
  /**
11809
11833
  * Static namespace for OpenFin API methods that interact with the {@link Layout} class, available under `fin.Platform.Layout`.
11810
11834
  */
11811
- class LayoutModule extends base_1$5.Base {
11835
+ class LayoutModule extends base_1$4.Base {
11812
11836
  constructor() {
11813
11837
  super(...arguments);
11814
11838
  _LayoutModule_instances.add(this);
@@ -11859,19 +11883,19 @@ class LayoutModule extends base_1$5.Base {
11859
11883
  if (!this.fin.me.isWindow) {
11860
11884
  throw new Error('Layout.init can only be called from a Window context.');
11861
11885
  }
11862
- else if (__classPrivateFieldGet$4(this, _LayoutModule_layoutInitializationAttempted, "f")) {
11886
+ else if (__classPrivateFieldGet$3(this, _LayoutModule_layoutInitializationAttempted, "f")) {
11863
11887
  throw new Error('Layout.init was already called, please use Layout.create to add additional layouts.');
11864
11888
  }
11865
- __classPrivateFieldSet$4(this, _LayoutModule_layoutInitializationAttempted, true, "f");
11889
+ __classPrivateFieldSet$3(this, _LayoutModule_layoutInitializationAttempted, true, "f");
11866
11890
  // preload the client
11867
11891
  await this.fin.Platform.getCurrentSync().getClient();
11868
- __classPrivateFieldSet$4(this, _LayoutModule_layoutManager, await this.wire.environment.initLayoutManager(this.fin, this.wire, options), "f");
11869
- await this.wire.environment.applyLayoutSnapshot(this.fin, __classPrivateFieldGet$4(this, _LayoutModule_layoutManager, "f"), options);
11892
+ __classPrivateFieldSet$3(this, _LayoutModule_layoutManager, await this.wire.environment.initLayoutManager(this.fin, this.wire, options), "f");
11893
+ await this.wire.environment.applyLayoutSnapshot(this.fin, __classPrivateFieldGet$3(this, _LayoutModule_layoutManager, "f"), options);
11870
11894
  if (!options.layoutManagerOverride) {
11871
11895
  // CORE-1081 to be removed when we actually delete the `layoutManager` prop
11872
11896
  // in single-layout case, we return the undocumented layoutManager type
11873
11897
  const layoutIdentity = { layoutName: layout_constants_1.DEFAULT_LAYOUT_KEY, ...this.fin.me.identity };
11874
- return __classPrivateFieldGet$4(this, _LayoutModule_getLayoutManagerSpy, "f").call(this, layoutIdentity);
11898
+ return __classPrivateFieldGet$3(this, _LayoutModule_getLayoutManagerSpy, "f").call(this, layoutIdentity);
11875
11899
  }
11876
11900
  return this.wrapSync(this.fin.me.identity);
11877
11901
  };
@@ -11900,13 +11924,13 @@ class LayoutModule extends base_1$5.Base {
11900
11924
  * @returns
11901
11925
  */
11902
11926
  this.getCurrentLayoutManagerSync = () => {
11903
- return __classPrivateFieldGet$4(this, _LayoutModule_instances, "m", _LayoutModule_getSafeLayoutManager).call(this, `fin.Platform.Layout.getCurrentLayoutManagerSync()`);
11927
+ return __classPrivateFieldGet$3(this, _LayoutModule_instances, "m", _LayoutModule_getSafeLayoutManager).call(this, `fin.Platform.Layout.getCurrentLayoutManagerSync()`);
11904
11928
  };
11905
11929
  this.create = async (options) => {
11906
- return this.wire.environment.createLayout(__classPrivateFieldGet$4(this, _LayoutModule_instances, "m", _LayoutModule_getSafeLayoutManager).call(this, `fin.Platform.Layout.create()`), options);
11930
+ return this.wire.environment.createLayout(__classPrivateFieldGet$3(this, _LayoutModule_instances, "m", _LayoutModule_getSafeLayoutManager).call(this, `fin.Platform.Layout.create()`), options);
11907
11931
  };
11908
11932
  this.destroy = async (layoutIdentity) => {
11909
- return this.wire.environment.destroyLayout(__classPrivateFieldGet$4(this, _LayoutModule_instances, "m", _LayoutModule_getSafeLayoutManager).call(this, `fin.Platform.Layout.destroy()`), layoutIdentity);
11933
+ return this.wire.environment.destroyLayout(__classPrivateFieldGet$3(this, _LayoutModule_instances, "m", _LayoutModule_getSafeLayoutManager).call(this, `fin.Platform.Layout.destroy()`), layoutIdentity);
11910
11934
  };
11911
11935
  }
11912
11936
  /**
@@ -12005,10 +12029,10 @@ class LayoutModule extends base_1$5.Base {
12005
12029
  }
12006
12030
  Factory$2.LayoutModule = LayoutModule;
12007
12031
  _LayoutModule_layoutInitializationAttempted = new WeakMap(), _LayoutModule_layoutManager = new WeakMap(), _LayoutModule_getLayoutManagerSpy = new WeakMap(), _LayoutModule_instances = new WeakSet(), _LayoutModule_getSafeLayoutManager = function _LayoutModule_getSafeLayoutManager(method) {
12008
- if (!__classPrivateFieldGet$4(this, _LayoutModule_layoutManager, "f")) {
12032
+ if (!__classPrivateFieldGet$3(this, _LayoutModule_layoutManager, "f")) {
12009
12033
  throw new Error(`You must call init before using the API ${method}`);
12010
12034
  }
12011
- return __classPrivateFieldGet$4(this, _LayoutModule_layoutManager, "f");
12035
+ return __classPrivateFieldGet$3(this, _LayoutModule_layoutManager, "f");
12012
12036
  };
12013
12037
 
12014
12038
  (function (exports) {
@@ -12045,13 +12069,13 @@ _LayoutModule_layoutInitializationAttempted = new WeakMap(), _LayoutModule_layou
12045
12069
 
12046
12070
  Object.defineProperty(Factory$3, "__esModule", { value: true });
12047
12071
  Factory$3.PlatformModule = void 0;
12048
- const base_1$4 = base$1;
12072
+ const base_1$3 = base$1;
12049
12073
  const Instance_1$1 = Instance$2;
12050
12074
  const index_1$1 = layout;
12051
12075
  /**
12052
12076
  * Static namespace for OpenFin API methods that interact with the {@link Platform} class, available under `fin.Platform`.
12053
12077
  */
12054
- class PlatformModule extends base_1$4.Base {
12078
+ class PlatformModule extends base_1$3.Base {
12055
12079
  /**
12056
12080
  * @internal
12057
12081
  */
@@ -12622,7 +12646,7 @@ function requireSessionContextGroupBroker () {
12622
12646
  return SessionContextGroupBroker;
12623
12647
  }
12624
12648
 
12625
- var utils$1 = {};
12649
+ var utils$3 = {};
12626
12650
 
12627
12651
  (function (exports) {
12628
12652
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -12685,7 +12709,7 @@ var utils$1 = {};
12685
12709
  };
12686
12710
  };
12687
12711
  exports.wrapIntentHandler = wrapIntentHandler;
12688
- } (utils$1));
12712
+ } (utils$3));
12689
12713
 
12690
12714
  var PrivateChannelProvider = {};
12691
12715
 
@@ -12988,14 +13012,15 @@ function requireInteropBroker () {
12988
13012
  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");
12989
13013
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12990
13014
  };
12991
- var _InteropBroker_fdc3Info, _InteropBroker_contextGroups;
13015
+ var _InteropBroker_fdc3Info, _InteropBroker_contextGroups, _InteropBroker_providerPromise;
12992
13016
  Object.defineProperty(InteropBroker, "__esModule", { value: true });
12993
13017
  InteropBroker.InteropBroker = void 0;
12994
13018
  const base_1 = base$1;
12995
13019
  const SessionContextGroupBroker_1 = requireSessionContextGroupBroker();
12996
- const utils_1 = utils$1;
13020
+ const utils_1 = utils$3;
12997
13021
  const lodash_1 = require$$3;
12998
13022
  const PrivateChannelProvider_1 = requirePrivateChannelProvider();
13023
+ const lazy_1 = lazy;
12999
13024
  const defaultContextGroups = [
13000
13025
  {
13001
13026
  id: 'green',
@@ -13163,12 +13188,15 @@ function requireInteropBroker () {
13163
13188
  /**
13164
13189
  * @internal
13165
13190
  */
13166
- constructor(wire, getProvider, options) {
13191
+ constructor(wire, createProvider, options) {
13167
13192
  // Tip from Pierre and Michael from the overrideCheck work: Don't use bound methods for overrideable InteropBroker functions.
13168
13193
  super(wire);
13169
- this.getProvider = getProvider;
13170
13194
  _InteropBroker_fdc3Info.set(this, void 0);
13171
13195
  _InteropBroker_contextGroups.set(this, void 0);
13196
+ _InteropBroker_providerPromise.set(this, void 0);
13197
+ this.getProvider = () => {
13198
+ return __classPrivateFieldGet(this, _InteropBroker_providerPromise, "f").getValue();
13199
+ };
13172
13200
  this.interopClients = new Map();
13173
13201
  this.contextGroupsById = new Map();
13174
13202
  __classPrivateFieldSet(this, _InteropBroker_contextGroups, options.contextGroups ?? [...defaultContextGroups], "f");
@@ -13179,6 +13207,7 @@ function requireInteropBroker () {
13179
13207
  this.intentClientMap = new Map();
13180
13208
  this.lastContextMap = new Map();
13181
13209
  this.sessionContextGroupMap = new Map();
13210
+ __classPrivateFieldSet(this, _InteropBroker_providerPromise, new lazy_1.Lazy(createProvider), "f");
13182
13211
  this.setContextGroupMap();
13183
13212
  this.setupChannelProvider();
13184
13213
  }
@@ -14262,35 +14291,35 @@ function requireInteropBroker () {
14262
14291
  }
14263
14292
  };
14264
14293
  InteropBroker.InteropBroker = InteropBroker$1;
14265
- _InteropBroker_fdc3Info = new WeakMap(), _InteropBroker_contextGroups = new WeakMap();
14294
+ _InteropBroker_fdc3Info = new WeakMap(), _InteropBroker_contextGroups = new WeakMap(), _InteropBroker_providerPromise = new WeakMap();
14266
14295
  return InteropBroker;
14267
14296
  }
14268
14297
 
14269
- var InteropClient$1 = {};
14298
+ var InteropClient = {};
14270
14299
 
14271
14300
  var SessionContextGroupClient$1 = {};
14272
14301
 
14273
- var __classPrivateFieldSet$3 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
14302
+ var __classPrivateFieldSet$2 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
14274
14303
  if (kind === "m") throw new TypeError("Private method is not writable");
14275
14304
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14276
14305
  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");
14277
14306
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
14278
14307
  };
14279
- var __classPrivateFieldGet$3 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
14308
+ var __classPrivateFieldGet$2 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
14280
14309
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
14281
14310
  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");
14282
14311
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
14283
14312
  };
14284
14313
  var _SessionContextGroupClient_clientPromise;
14285
14314
  Object.defineProperty(SessionContextGroupClient$1, "__esModule", { value: true });
14286
- const base_1$3 = base$1;
14287
- const utils_1$3 = utils$1;
14288
- class SessionContextGroupClient extends base_1$3.Base {
14315
+ const base_1$2 = base$1;
14316
+ const utils_1$2 = utils$3;
14317
+ class SessionContextGroupClient extends base_1$2.Base {
14289
14318
  constructor(wire, client, id) {
14290
14319
  super(wire);
14291
14320
  _SessionContextGroupClient_clientPromise.set(this, void 0);
14292
14321
  this.id = id;
14293
- __classPrivateFieldSet$3(this, _SessionContextGroupClient_clientPromise, client, "f");
14322
+ __classPrivateFieldSet$2(this, _SessionContextGroupClient_clientPromise, client, "f");
14294
14323
  }
14295
14324
  /**
14296
14325
  * Sets a context for the session context group.
@@ -14302,7 +14331,7 @@ class SessionContextGroupClient extends base_1$3.Base {
14302
14331
  this.wire.sendAction('interop-session-context-group-set-context').catch((e) => {
14303
14332
  // don't expose, analytics-only call
14304
14333
  });
14305
- const client = await __classPrivateFieldGet$3(this, _SessionContextGroupClient_clientPromise, "f");
14334
+ const client = await __classPrivateFieldGet$2(this, _SessionContextGroupClient_clientPromise, "f");
14306
14335
  return client.dispatch(`sessionContextGroup:setContext-${this.id}`, {
14307
14336
  sessionContextGroupId: this.id,
14308
14337
  context
@@ -14312,7 +14341,7 @@ class SessionContextGroupClient extends base_1$3.Base {
14312
14341
  this.wire.sendAction('interop-session-context-group-get-context').catch((e) => {
14313
14342
  // don't expose, analytics-only call
14314
14343
  });
14315
- const client = await __classPrivateFieldGet$3(this, _SessionContextGroupClient_clientPromise, "f");
14344
+ const client = await __classPrivateFieldGet$2(this, _SessionContextGroupClient_clientPromise, "f");
14316
14345
  return client.dispatch(`sessionContextGroup:getContext-${this.id}`, {
14317
14346
  sessionContextGroupId: this.id,
14318
14347
  type
@@ -14325,20 +14354,20 @@ class SessionContextGroupClient extends base_1$3.Base {
14325
14354
  if (typeof contextHandler !== 'function') {
14326
14355
  throw new Error("Non-function argument passed to the first parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
14327
14356
  }
14328
- const client = await __classPrivateFieldGet$3(this, _SessionContextGroupClient_clientPromise, "f");
14357
+ const client = await __classPrivateFieldGet$2(this, _SessionContextGroupClient_clientPromise, "f");
14329
14358
  let handlerId;
14330
14359
  if (contextType) {
14331
- handlerId = `sessionContextHandler:invoke-${this.id}-${contextType}-${(0, utils_1$3.generateId)()}`;
14360
+ handlerId = `sessionContextHandler:invoke-${this.id}-${contextType}-${(0, utils_1$2.generateId)()}`;
14332
14361
  }
14333
14362
  else {
14334
14363
  handlerId = `sessionContextHandler:invoke-${this.id}`;
14335
14364
  }
14336
- client.register(handlerId, (0, utils_1$3.wrapContextHandler)(contextHandler, handlerId));
14365
+ client.register(handlerId, (0, utils_1$2.wrapContextHandler)(contextHandler, handlerId));
14337
14366
  await client.dispatch(`sessionContextGroup:handlerAdded-${this.id}`, { handlerId, contextType });
14338
14367
  return { unsubscribe: await this.createUnsubscribeCb(handlerId) };
14339
14368
  }
14340
14369
  async createUnsubscribeCb(handlerId) {
14341
- const client = await __classPrivateFieldGet$3(this, _SessionContextGroupClient_clientPromise, "f");
14370
+ const client = await __classPrivateFieldGet$2(this, _SessionContextGroupClient_clientPromise, "f");
14342
14371
  return async () => {
14343
14372
  client.remove(handlerId);
14344
14373
  await client.dispatch(`sessionContextGroup:handlerRemoved-${this.id}`, { handlerId });
@@ -14347,610 +14376,1770 @@ class SessionContextGroupClient extends base_1$3.Base {
14347
14376
  getUserInstance() {
14348
14377
  return {
14349
14378
  id: this.id,
14350
- setContext: (0, utils_1$3.wrapInTryCatch)(this.setContext.bind(this), 'Failed to set context: '),
14351
- getCurrentContext: (0, utils_1$3.wrapInTryCatch)(this.getCurrentContext.bind(this), 'Failed to get context: '),
14352
- addContextHandler: (0, utils_1$3.wrapInTryCatch)(this.addContextHandler.bind(this), 'Failed to add context handler: ')
14379
+ setContext: (0, utils_1$2.wrapInTryCatch)(this.setContext.bind(this), 'Failed to set context: '),
14380
+ getCurrentContext: (0, utils_1$2.wrapInTryCatch)(this.getCurrentContext.bind(this), 'Failed to get context: '),
14381
+ addContextHandler: (0, utils_1$2.wrapInTryCatch)(this.addContextHandler.bind(this), 'Failed to add context handler: ')
14353
14382
  };
14354
14383
  }
14355
14384
  }
14356
14385
  SessionContextGroupClient$1.default = SessionContextGroupClient;
14357
14386
  _SessionContextGroupClient_clientPromise = new WeakMap();
14358
14387
 
14359
- var __classPrivateFieldSet$2 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
14360
- if (kind === "m") throw new TypeError("Private method is not writable");
14361
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14362
- 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");
14363
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
14364
- };
14365
- var __classPrivateFieldGet$2 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
14366
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
14367
- 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");
14368
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
14369
- };
14370
- var _InteropClient_clientPromise, _InteropClient_sessionContextGroups;
14371
- Object.defineProperty(InteropClient$1, "__esModule", { value: true });
14372
- InteropClient$1.InteropClient = void 0;
14373
- const base_1$2 = base$1;
14374
- const SessionContextGroupClient_1 = SessionContextGroupClient$1;
14375
- const utils_1$2 = utils$1;
14376
- /**
14377
- * The Interop Client API is broken up into two groups:
14378
- *
14379
- * **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.
14380
- *
14381
- * **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.
14382
- *
14383
- * ---
14384
- *
14385
- * All APIs are available at the `fin.me.interop` namespace.
14386
- *
14387
- * ---
14388
- *
14389
- * **You only need 2 things to participate in Interop Context Grouping:**
14390
- * * A Context Handler for incoming context: {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
14391
- * * Call setContext on your context group when you want to share context with other group members: {@link InteropClient#setContext setContext(context)}
14392
- *
14393
- * ---
14394
- *
14395
- * ##### Constructor
14396
- * Returned by {@link Interop.connectSync Interop.connectSync}.
14397
- *
14398
- * ---
14399
- *
14400
- * ##### Interop methods intended for Views
14401
- *
14402
- *
14403
- * **Context Groups API**
14404
- * * {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
14405
- * * {@link InteropClient#setContext setContext(context)}
14406
- * * {@link InteropClient#getCurrentContext getCurrentContext(contextType?)}
14407
- * * {@link InteropClient#joinSessionContextGroup joinSessionContextGroup(sessionContextGroupId)}
14408
- *
14409
- *
14410
- * **Intents API**
14411
- * * {@link InteropClient#fireIntent fireIntent(intent)}
14412
- * * {@link InteropClient#registerIntentHandler registerIntentHandler(intentHandler, intentName)}
14413
- * * {@link InteropClient#getInfoForIntent getInfoForIntent(infoForIntentOptions)}
14414
- * * {@link InteropClient#getInfoForIntentsByContext getInfoForIntentsByContext(context)}
14415
- * * {@link InteropClient#fireIntentForContext fireIntentForContext(contextForIntent)}
14416
- *
14417
- * ##### Interop methods intended for Windows
14418
- * * {@link InteropClient#getContextGroups getContextGroups()}
14419
- * * {@link InteropClient#joinContextGroup joinContextGroup(contextGroupId, target?)}
14420
- * * {@link InteropClient#removeFromContextGroup removeFromContextGroup(target?)}
14421
- * * {@link InteropClient#getInfoForContextGroup getInfoForContextGroup(contextGroupId)}
14422
- * * {@link InteropClient#getAllClientsInContextGroup getAllClientsInContextGroup(contextGroupId)}
14423
- *
14424
- */
14425
- class InteropClient extends base_1$2.Base {
14426
- /**
14427
- * @internal
14428
- */
14429
- constructor(wire, name, interopConfig = {}) {
14430
- super(wire);
14431
- _InteropClient_clientPromise.set(this, void 0);
14432
- _InteropClient_sessionContextGroups.set(this, void 0);
14433
- __classPrivateFieldSet$2(this, _InteropClient_sessionContextGroups, new Map(), "f");
14434
- __classPrivateFieldSet$2(this, _InteropClient_clientPromise, this.wire.environment.whenReady().then(() => {
14435
- return this.fin.InterApplicationBus.Channel.connect(`interop-broker-${name}`, {
14436
- payload: interopConfig
14437
- });
14438
- }), "f");
14388
+ var fdc31_2 = {};
14389
+
14390
+ var fdc3Common = {};
14391
+
14392
+ var utils$2 = {};
14393
+
14394
+ var PrivateChannelClient$1 = {};
14395
+
14396
+ Object.defineProperty(PrivateChannelClient$1, "__esModule", { value: true });
14397
+ PrivateChannelClient$1.PrivateChannelClient = void 0;
14398
+ const utils$1 = utils$3;
14399
+ class PrivateChannelClient {
14400
+ constructor(client, id) {
14401
+ this.id = id;
14402
+ this.client = client;
14403
+ this.listeners = new Map();
14439
14404
  }
14440
- /*
14441
- Client APIs
14442
- */
14443
- /**
14444
- * Sets a context for the context group of the current entity.
14445
- *
14446
- * @remarks The entity must be part of a context group in order set a context.
14447
- *
14448
- * @param context - New context to set.
14449
- *
14450
- * @example
14451
- * ```js
14452
- * setInstrumentContext = async (ticker) => {
14453
- * fin.me.interop.setContext({type: 'instrument', id: {ticker}})
14454
- * }
14455
- *
14456
- * // 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
14457
- * instrumentElement.on('click', (evt) => {
14458
- * setInstrumentContext(evt.ticker)
14459
- * })
14460
- * ```
14461
- */
14462
- async setContext(context) {
14463
- this.wire.sendAction('interop-client-set-context').catch((e) => {
14464
- // don't expose, analytics-only call
14465
- });
14466
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14467
- return client.dispatch('setContext', { context });
14405
+ async broadcast(context) {
14406
+ return this.client.dispatch('broadcast', { context });
14468
14407
  }
14469
- /**
14470
- * Add a context handler for incoming context. If an entity is part of a context group, and then sets its context handler,
14471
- * it will receive all of its declared contexts.
14472
- *
14473
- * @param handler - Handler for incoming context.
14474
- * @param contextType - The type of context you wish to handle.
14475
- *
14476
- * @example
14477
- * ```js
14478
- * function handleIncomingContext(contextInfo) {
14479
- * const { type, id } = contextInfo;
14480
- * switch (type) {
14481
- * case 'instrument':
14482
- * handleInstrumentContext(contextInfo);
14483
- * break;
14484
- * case 'country':
14485
- * handleCountryContext(contextInfo);
14486
- * break;
14487
- *
14488
- * default:
14489
- * break;
14490
- * }
14491
- * }
14492
- *
14493
- *
14494
- * function handleInstrumentContext(contextInfo) {
14495
- * const { type, id } = contextInfo;
14496
- * console.log('contextInfo for instrument', contextInfo)
14497
- * }
14498
- *
14499
- * function handleCountryContext(contextInfo) {
14500
- * const { type, id } = contextInfo;
14501
- * console.log('contextInfo for country', contextInfo)
14502
- * }
14503
- *
14504
- * fin.me.interop.addContextHandler(handleIncomingContext);
14505
- * ```
14506
- *
14507
- *
14508
- * We are also testing the ability to add a context handler for specific contexts. If you would like to use
14509
- * this, please make sure you add your context handlers at the top level of your application, on a page that
14510
- * does not navigate/reload/re-render, to avoid memory leaks. This feature is experimental:
14511
- *
14512
- * ```js
14513
- * function handleInstrumentContext(contextInfo) {
14514
- * const { type, id } = contextInfo;
14515
- * console.log('contextInfo for instrument', contextInfo)
14516
- * }
14517
- *
14518
- * function handleCountryContext(contextInfo) {
14519
- * const { type, id } = contextInfo;
14520
- * console.log('contextInfo for country', contextInfo)
14521
- * }
14522
- *
14523
- *
14524
- * fin.me.interop.addContextHandler(handleInstrumentContext, 'instrument')
14525
- * fin.me.interop.addContextHandler(handleCountryContext, 'country')
14526
- * ```
14527
- */
14528
- async addContextHandler(handler, contextType) {
14529
- this.wire.sendAction('interop-client-add-context-handler').catch((e) => {
14530
- // don't expose, analytics-only call
14531
- });
14408
+ async getCurrentContext(contextType) {
14409
+ return this.client.dispatch('getCurrentContext', { contextType });
14410
+ }
14411
+ async addContextListener(contextType, handler) {
14532
14412
  if (typeof handler !== 'function') {
14533
- throw new Error("Non-function argument passed to the first parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
14413
+ throw new Error("Non-function argument passed to the second parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
14534
14414
  }
14535
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14536
14415
  let handlerId;
14537
14416
  if (contextType) {
14538
- handlerId = `invokeContextHandler-${contextType}-${(0, utils_1$2.generateId)()}`;
14539
- 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.`);
14417
+ handlerId = `contextHandler:invoke-${this.id}-${contextType}-${utils$1.generateId()}`;
14540
14418
  }
14541
14419
  else {
14542
- handlerId = 'invokeContextHandler';
14420
+ handlerId = `contextHandler:invoke-${this.id}-${utils$1.generateId()}`;
14543
14421
  }
14544
- const wrappedHandler = (0, utils_1$2.wrapContextHandler)(handler, handlerId);
14545
- client.register(handlerId, wrappedHandler);
14546
- await client.dispatch('contextHandlerRegistered', { handlerId, contextType });
14547
- return {
14548
- unsubscribe: async () => {
14549
- client.remove(handlerId);
14550
- await client.dispatch('removeContextHandler', { handlerId });
14551
- }
14422
+ this.client.register(handlerId, utils$1.wrapContextHandler(handler, handlerId));
14423
+ const listener = { unsubscribe: await this.createContextUnsubscribeCb(handlerId) };
14424
+ this.listeners.set(handlerId, listener);
14425
+ await this.client.dispatch(`contextHandlerAdded`, { handlerId, contextType });
14426
+ return listener;
14427
+ }
14428
+ createNonStandardUnsubscribeCb(handlerId) {
14429
+ return async () => {
14430
+ this.client.remove(handlerId);
14431
+ this.listeners.delete(handlerId);
14432
+ await this.client.dispatch('nonStandardHandlerRemoved', { handlerId });
14552
14433
  };
14553
14434
  }
14554
- /*
14555
- Platform Window APIs
14556
- */
14557
- /**
14558
- * Returns the Interop-Broker-defined context groups available for an entity to join.
14559
- * Used by Platform Windows.
14560
- *
14561
- * @example
14562
- * ```js
14563
- * fin.me.interop.getContextGroups()
14564
- * .then(contextGroups => {
14565
- * contextGroups.forEach(contextGroup => {
14566
- * console.log(contextGroup.displayMetadata.name)
14567
- * console.log(contextGroup.displayMetadata.color)
14568
- * })
14569
- * })
14570
- * ```
14571
- */
14572
- async getContextGroups() {
14573
- this.wire.sendAction('interop-client-get-context-groups').catch((e) => {
14574
- // don't expose, analytics-only call
14575
- });
14576
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14577
- return client.dispatch('getContextGroups');
14435
+ createContextUnsubscribeCb(handlerId) {
14436
+ return async () => {
14437
+ this.client.remove(handlerId);
14438
+ this.listeners.delete(handlerId);
14439
+ await this.client.dispatch('contextHandlerRemoved', { handlerId });
14440
+ };
14578
14441
  }
14579
- /**
14580
- * Join all Interop Clients at the given identity to context group `contextGroupId`.
14581
- * If no target is specified, it adds the sender to the context group.
14582
- *
14583
- * @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.
14584
- * 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.
14585
- * 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.
14586
- * Used by Platform Windows.
14587
- *
14588
- * @param contextGroupId - Id of the context group.
14589
- * @param target - Identity of the entity you wish to join to a context group.
14590
- *
14591
- * @example
14592
- * ```js
14593
- * joinViewToContextGroup = async (contextGroupId, view) => {
14594
- * await fin.me.interop.joinContextGroup(contextGroupId, view);
14595
- * }
14596
- *
14597
- * getLastFocusedView()
14598
- * .then(lastFocusedViewIdentity => {
14599
- * joinViewToContextGroup('red', lastFocusedViewIdentity)
14600
- * })
14601
- * ```
14602
- */
14603
- async joinContextGroup(contextGroupId, target) {
14604
- this.wire.sendAction('interop-client-join-context-group').catch((e) => {
14605
- // don't expose, analytics-only call
14442
+ onAddContextListener(handler) {
14443
+ const handlerId = `onContextHandlerAdded:invoke-${this.id}-${utils$1.generateId()}`;
14444
+ this.client.register(handlerId, handler);
14445
+ const listener = { unsubscribe: this.createNonStandardUnsubscribeCb(handlerId) };
14446
+ this.listeners.set(handlerId, listener);
14447
+ this.client.dispatch(`onAddContextHandlerAdded`, { handlerId });
14448
+ return listener;
14449
+ }
14450
+ onDisconnect(handler) {
14451
+ const handlerId = `onDisconnect:invoke-${this.id}-${utils$1.generateId()}`;
14452
+ this.client.register(handlerId, handler);
14453
+ const listener = { unsubscribe: this.createNonStandardUnsubscribeCb(handlerId) };
14454
+ this.listeners.set(handlerId, listener);
14455
+ this.client.dispatch(`onDisconnectHandlerAdded`, { handlerId });
14456
+ return listener;
14457
+ }
14458
+ onUnsubscribe(handler) {
14459
+ const handlerId = `onUnsubscribe:invoke-${this.id}-${utils$1.generateId()}`;
14460
+ this.client.register(handlerId, handler);
14461
+ const listener = { unsubscribe: this.createNonStandardUnsubscribeCb(handlerId) };
14462
+ this.listeners.set(handlerId, listener);
14463
+ this.client.dispatch(`onUnsubscribeHandlerAdded`, { handlerId });
14464
+ return listener;
14465
+ }
14466
+ async cleanUpAllSubs() {
14467
+ const listenerUnsubscribers = Array.from(this.listeners.keys());
14468
+ listenerUnsubscribers.forEach((handlerId) => {
14469
+ this.client.remove(handlerId);
14470
+ this.listeners.delete(handlerId);
14606
14471
  });
14607
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14608
- if (!contextGroupId) {
14609
- throw new Error('No contextGroupId specified for joinContextGroup.');
14472
+ }
14473
+ async disconnect() {
14474
+ try {
14475
+ await this.client.dispatch('clientDisconnecting');
14476
+ await this.cleanUpAllSubs();
14477
+ await this.client.disconnect();
14478
+ }
14479
+ catch (error) {
14480
+ throw new Error(error.message);
14610
14481
  }
14611
- return client.dispatch('joinContextGroup', { contextGroupId, target });
14612
- }
14613
- /**
14614
- * Removes the specified target from a context group.
14615
- * If no target is specified, it removes the sender from their context group.
14616
- * Used by Platform Windows.
14617
- *
14618
- * @param target - Identity of the entity you wish to join to a context group.
14619
- *
14620
- * @example
14621
- * ```js
14622
- * removeViewFromContextGroup = async (view) => {
14623
- * await fin.me.interop.removeFromContextGroup(view);
14624
- * }
14625
- *
14626
- * getLastFocusedView()
14627
- * .then(lastFocusedViewIdentity => {
14628
- * removeViewFromContextGroup(lastFocusedViewIdentity)
14629
- * })
14630
- * ```
14631
- */
14632
- async removeFromContextGroup(target) {
14633
- this.wire.sendAction('interop-client-remove-from-context-group').catch((e) => {
14634
- // don't expose, analytics-only call
14635
- });
14636
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14637
- return client.dispatch('removeFromContextGroup', { target });
14638
- }
14639
- /**
14640
- * Gets all clients for a context group.
14641
- *
14642
- * @remarks **This is primarily used for platform windows. Views within a platform should not have to use this API.**
14643
- *
14644
- * Returns the Interop-Broker-defined context groups available for an entity to join.
14645
- * @param contextGroupId - The id of context group you wish to get clients for.
14646
- *
14647
- * @example
14648
- * ```js
14649
- * fin.me.interop.getAllClientsInContextGroup('red')
14650
- * .then(clientsInContextGroup => {
14651
- * console.log(clientsInContextGroup)
14652
- * })
14653
- * ```
14654
- */
14655
- async getAllClientsInContextGroup(contextGroupId) {
14656
- this.wire.sendAction('interop-client-get-all-clients-in-context-group').catch((e) => {
14657
- // don't expose, analytics-only call
14658
- });
14659
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14660
- if (!contextGroupId) {
14661
- throw new Error('No contextGroupId specified for getAllClientsInContextGroup.');
14662
- }
14663
- return client.dispatch('getAllClientsInContextGroup', { contextGroupId });
14664
- }
14665
- /**
14666
- * Gets display info for a context group
14667
- *
14668
- * @remarks Used by Platform Windows.
14669
- * @param contextGroupId - The id of context group you wish to get display info for.
14670
- *
14671
- * @example
14672
- * ```js
14673
- * fin.me.interop.getInfoForContextGroup('red')
14674
- * .then(contextGroupInfo => {
14675
- * console.log(contextGroupInfo.displayMetadata.name)
14676
- * console.log(contextGroupInfo.displayMetadata.color)
14677
- * })
14678
- * ```
14679
- */
14680
- async getInfoForContextGroup(contextGroupId) {
14681
- this.wire.sendAction('interop-client-get-info-for-context-group').catch((e) => {
14682
- // don't expose, analytics-only call
14683
- });
14684
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14685
- if (!contextGroupId) {
14686
- throw new Error('No contextGroupId specified for getInfoForContextGroup.');
14687
- }
14688
- return client.dispatch('getInfoForContextGroup', { contextGroupId });
14689
- }
14690
- /**
14691
- * Sends an intent to the Interop Broker to resolve.
14692
- * @param intent - The combination of an action and a context that is passed to an application for resolution.
14693
- *
14694
- * @example
14695
- * ```js
14696
- * // View wants to fire an Intent after a user clicks on a ticker
14697
- * tickerElement.on('click', (element) => {
14698
- * const ticker = element.innerText;
14699
- * const intent = {
14700
- * name: 'ViewChart',
14701
- * context: {type: 'fdc3.instrument', id: { ticker }}
14702
- * }
14703
- *
14704
- * fin.me.interop.fireIntent(intent);
14705
- * })
14706
- * ```
14707
- */
14708
- async fireIntent(intent) {
14709
- this.wire.sendAction('interop-client-fire-intent').catch((e) => {
14710
- // don't expose, this is only for api analytics purposes
14711
- });
14712
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14713
- return client.dispatch('fireIntent', intent);
14714
- }
14715
- /**
14716
- * Adds an intent handler for incoming intents. The last intent sent of the name subscribed to will be received.
14717
- * @param handler - Registered function meant to handle a specific intent type.
14718
- * @param intentName - The name of an intent.
14719
- *
14720
- * @example
14721
- * ```js
14722
- * const intentHandler = (intent) => {
14723
- * const { context } = intent;
14724
- * myViewChartHandler(context);
14725
- * };
14726
- *
14727
- * const subscription = await fin.me.interop.registerIntentHandler(intentHandler, 'ViewChart');
14728
- *
14729
- * function myAppCloseSequence() {
14730
- * // to unsubscribe the handler, simply call:
14731
- * subscription.unsubscribe();
14732
- * }
14733
- * ```
14734
- */
14735
- async registerIntentHandler(handler, intentName, options) {
14736
- this.wire.sendAction('interop-client-register-intent-handler').catch((e) => {
14737
- // don't expose, this is only for api analytics purposes
14738
- });
14739
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14740
- const handlerId = `intent-handler-${intentName}`;
14741
- const wrappedHandler = (0, utils_1$2.wrapIntentHandler)(handler, handlerId);
14742
- try {
14743
- await client.register(handlerId, wrappedHandler);
14744
- await client.dispatch('intentHandlerRegistered', { handlerId, ...options });
14745
- }
14746
- catch (error) {
14747
- throw new Error('Unable to register intent handler');
14748
- }
14749
- return {
14750
- unsubscribe: async () => {
14751
- client.remove(handlerId);
14752
- }
14753
- };
14754
- }
14755
- /**
14756
- * Gets the last context of the Context Group currently subscribed to. It takes an optional Context Type and returns the
14757
- * last context of that type.
14758
- * @param contextType
14759
- *
14760
- * @example
14761
- * ```js
14762
- * await fin.me.interop.joinContextGroup('yellow');
14763
- * await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
14764
- * const currentContext = await fin.me.interop.getCurrentContext();
14765
- *
14766
- * // with a specific context
14767
- * await fin.me.interop.joinContextGroup('yellow');
14768
- * await fin.me.interop.setContext({ type: 'country', id: { ISOALPHA3: 'US' }});
14769
- * await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
14770
- * const currentContext = await fin.me.interop.getCurrentContext('country');
14771
- * ```
14772
- */
14773
- async getCurrentContext(contextType) {
14774
- this.wire.sendAction('interop-client-get-current-context').catch((e) => {
14775
- // don't expose, analytics-only call
14776
- });
14777
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14778
- return client.dispatch('getCurrentContext', { contextType });
14779
- }
14780
- /**
14781
- * Get information for a particular Intent from the Interop Broker.
14782
- *
14783
- * @remarks To resolve this info, the function handleInfoForIntent is meant to be overridden in the Interop Broker.
14784
- * The format for the response will be determined by the App Provider overriding the function.
14785
- *
14786
- * @param options
14787
- *
14788
- * @example
14789
- * ```js
14790
- * const intentInfo = await fin.me.interop.getInfoForIntent('ViewChart');
14791
- * ```
14792
- */
14793
- async getInfoForIntent(options) {
14794
- this.wire.sendAction('interop-client-get-info-for-intent').catch((e) => {
14795
- // don't expose, analytics-only call
14796
- });
14797
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14798
- return client.dispatch('getInfoForIntent', options);
14799
- }
14800
- /**
14801
- * Get information from the Interop Broker on all Intents that are meant to handle a particular context.
14802
- *
14803
- * @remarks To resolve this info, the function handleInfoForIntentsByContext is meant to be overridden in the Interop Broker.
14804
- * The format for the response will be determined by the App Provider overriding the function.
14805
- *
14806
- * @param context
14807
- *
14808
- * @example
14809
- * ```js
14810
- * tickerElement.on('click', (element) => {
14811
- * const ticker = element.innerText;
14812
- *
14813
- * const context = {
14814
- * type: 'fdc3.instrument',
14815
- * id: {
14816
- * ticker
14817
- * }
14818
- * }
14819
- *
14820
- * const intentsInfo = await fin.me.interop.getInfoForIntentByContext(context);
14821
- * })
14822
- * ```
14823
- */
14824
- async getInfoForIntentsByContext(context) {
14825
- this.wire.sendAction('interop-client-get-info-for-intents-by-context').catch((e) => {
14826
- // don't expose, analytics-only call
14827
- });
14828
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14829
- return client.dispatch('getInfoForIntentsByContext', context);
14830
- }
14831
- /**
14832
- * Sends a Context that will be resolved to an Intent by the Interop Broker.
14833
- * This context accepts a metadata property.
14834
- *
14835
- * @remarks To resolve this info, the function handleFiredIntentByContext is meant to be overridden in the Interop Broker.
14836
- * The format for the response will be determined by the App Provider overriding the function.
14837
- *
14838
- * @param context
14839
- *
14840
- * @example
14841
- * ```js
14842
- * tickerElement.on('click', (element) => {
14843
- * const ticker = element.innerText;
14844
- *
14845
- * const context = {
14846
- * type: 'fdc3.instrument',
14847
- * id: {
14848
- * ticker
14849
- * }
14850
- * }
14851
- *
14852
- * const intentResolution = await fin.me.interop.fireIntentForContext(context);
14853
- * })
14854
- * ```
14855
- */
14856
- async fireIntentForContext(context) {
14857
- this.wire.sendAction('interop-client-fire-intent-for-context').catch((e) => {
14858
- // don't expose, analytics-only call
14859
- });
14860
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14861
- return client.dispatch('fireIntentForContext', context);
14862
- }
14863
- /**
14864
- * Join the current entity to session context group `sessionContextGroupId` and return a sessionContextGroup instance.
14865
- * If the sessionContextGroup doesn't exist, one will get created.
14866
- *
14867
- * @remarks Session Context Groups do not persist between runs and aren't present on snapshots.
14868
- * @param sessionContextGroupId - Id of the context group.
14869
- *
14870
- * @example
14871
- * Say we want to have a Session Context Group that holds UI theme information for all apps to consume:
14872
- *
14873
- * My color-picker View:
14874
- * ```js
14875
- * const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');
14876
- *
14877
- * const myColorPickerElement = document.getElementById('color-palette-picker');
14878
- * myColorPickerElement.addEventListener('change', event => {
14879
- * themeSessionContextGroup.setContext({ type: 'color-palette', selection: event.value });
14880
- * });
14881
- * ```
14882
- *
14883
- * In other views:
14884
- * ```js
14885
- * const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');
14886
- *
14887
- * const changeColorPalette = ({ selection }) => {
14888
- * // change the color palette to the selection
14889
- * };
14890
- *
14891
- * // If the context is already set by the time the handler was set, the handler will get invoked immediately with the current context.
14892
- * themeSessionContextGroup.addContextHandler(changeColorPalette, 'color-palette');
14893
- * ```
14894
- */
14895
- async joinSessionContextGroup(sessionContextGroupId) {
14896
- try {
14897
- const currentSessionContextGroup = __classPrivateFieldGet$2(this, _InteropClient_sessionContextGroups, "f").get(sessionContextGroupId);
14898
- if (currentSessionContextGroup) {
14899
- return currentSessionContextGroup.getUserInstance();
14900
- }
14901
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14902
- const { hasConflict } = await client.dispatch('sessionContextGroup:createIfNeeded', {
14903
- sessionContextGroupId
14904
- });
14905
- if (hasConflict) {
14906
- 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.`);
14907
- }
14908
- const newSessionContextGroup = new SessionContextGroupClient_1.default(this.wire, __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f"), sessionContextGroupId);
14909
- __classPrivateFieldGet$2(this, _InteropClient_sessionContextGroups, "f").set(sessionContextGroupId, newSessionContextGroup);
14910
- return newSessionContextGroup.getUserInstance();
14911
- }
14912
- catch (error) {
14913
- console.error(`Error thrown trying to create Session Context Group with id "${sessionContextGroupId}": ${error}`);
14914
- throw error;
14915
- }
14916
- }
14917
- /**
14918
- * Register a listener that is called when the Interop Client has been disconnected from the Interop Broker.
14919
- * Only one listener per Interop Client can be set.
14920
- * @param listener
14921
- *
14922
- * @example
14923
- * ```js
14924
- * const listener = (event) => {
14925
- * const { type, topic, brokerName} = event;
14926
- * console.log(`Disconnected from Interop Broker ${brokerName} `);
14927
- * }
14928
- *
14929
- * await fin.me.interop.onDisconnection(listener);
14930
- * ```
14931
- */
14932
- async onDisconnection(listener) {
14933
- this.wire.sendAction('interop-client-add-ondisconnection-listener').catch((e) => {
14934
- // don't expose, analytics-only call
14935
- });
14936
- const client = await __classPrivateFieldGet$2(this, _InteropClient_clientPromise, "f");
14937
- return client.onDisconnection((event) => {
14938
- const { uuid } = event;
14939
- listener({ type: 'interop-broker', topic: 'disconnected', brokerName: uuid });
14940
- });
14941
- }
14942
- /**
14943
- * @internal
14944
- *
14945
- * Used to ferry fdc3-only calls from the fdc3 shim to the Interop Broker
14946
- */
14947
- static async ferryFdc3Call(interopClient, action, payload) {
14948
- const client = await __classPrivateFieldGet$2(interopClient, _InteropClient_clientPromise, "f");
14949
- return client.dispatch(action, payload || null);
14950
14482
  }
14951
14483
  }
14952
- InteropClient$1.InteropClient = InteropClient;
14953
- _InteropClient_clientPromise = new WeakMap(), _InteropClient_sessionContextGroups = new WeakMap();
14484
+ PrivateChannelClient$1.PrivateChannelClient = PrivateChannelClient;
14485
+
14486
+ (function (exports) {
14487
+ Object.defineProperty(exports, "__esModule", { value: true });
14488
+ exports.getIntentResolution = exports.isChannel = exports.isContext = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ChannelError = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
14489
+ const utils_1 = utils$3;
14490
+ const PrivateChannelClient_1 = PrivateChannelClient$1;
14491
+ const lodash_1 = require$$3;
14492
+ const getUnsupportedChannelApis = (channelType) => {
14493
+ return {
14494
+ addContextListener: () => {
14495
+ throw new UnsupportedChannelApiError('Channel.addContextListener', channelType);
14496
+ },
14497
+ broadcast: () => {
14498
+ throw new UnsupportedChannelApiError('Channel.broadcast', channelType);
14499
+ },
14500
+ getCurrentContext: () => {
14501
+ throw new UnsupportedChannelApiError('Channel.getCurrentContext', channelType);
14502
+ }
14503
+ };
14504
+ };
14505
+ exports.getUnsupportedChannelApis = getUnsupportedChannelApis;
14506
+ class UnsupportedChannelApiError extends Error {
14507
+ constructor(apiName, channelType = 'System') {
14508
+ super(apiName);
14509
+ 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.`;
14510
+ }
14511
+ }
14512
+ exports.UnsupportedChannelApiError = UnsupportedChannelApiError;
14513
+ var ResultError;
14514
+ (function (ResultError) {
14515
+ /** Returned if the `IntentHandler` exited without returning a Promise or that
14516
+ * Promise was not resolved with a Context or Channel object.
14517
+ */
14518
+ ResultError["NoResultReturned"] = "NoResultReturned";
14519
+ /** Returned if the `IntentHandler` function processing the raised intent
14520
+ * throws an error or rejects the Promise it returned.
14521
+ */
14522
+ ResultError["IntentHandlerRejected"] = "IntentHandlerRejected";
14523
+ })(ResultError = exports.ResultError || (exports.ResultError = {}));
14524
+ (function (ChannelError) {
14525
+ /** Returned if the specified channel is not found when attempting to join a
14526
+ * channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).
14527
+ */
14528
+ ChannelError["NoChannelFound"] = "NoChannelFound";
14529
+ /** SHOULD be returned when a request to join a user channel or to a retrieve
14530
+ * a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods
14531
+ * of the DesktopAgent (`fdc3`) object is denied.
14532
+ */
14533
+ ChannelError["AccessDenied"] = "AccessDenied";
14534
+ /** SHOULD be returned when a channel cannot be created or retrieved via the
14535
+ * `getOrCreateChannel` method of the DesktopAgent (`fdc3`).
14536
+ */
14537
+ ChannelError["CreationFailed"] = "CreationFailed";
14538
+ })(exports.ChannelError || (exports.ChannelError = {}));
14539
+ const buildPrivateChannelObject = (privateChannelClient) => {
14540
+ let clientDisconnected = false;
14541
+ const checkIfClientDisconnected = () => {
14542
+ if (clientDisconnected) {
14543
+ throw new Error('Private Channel Client has been disconnected from the Private Channel');
14544
+ }
14545
+ };
14546
+ return {
14547
+ id: privateChannelClient.id,
14548
+ type: 'private',
14549
+ broadcast: async (context) => {
14550
+ checkIfClientDisconnected();
14551
+ return privateChannelClient.broadcast(context);
14552
+ },
14553
+ getCurrentContext: async (contextType) => {
14554
+ checkIfClientDisconnected();
14555
+ return privateChannelClient.getCurrentContext(contextType);
14556
+ },
14557
+ // @ts-expect-error TODO [CORE-1524]
14558
+ addContextListener: async (contextType, handler) => {
14559
+ checkIfClientDisconnected();
14560
+ let handlerInUse = handler;
14561
+ let contextTypeInUse = contextType;
14562
+ if (typeof contextType === 'function') {
14563
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
14564
+ handlerInUse = contextType;
14565
+ contextTypeInUse = null;
14566
+ }
14567
+ const listener = privateChannelClient.addContextListener(contextTypeInUse, handlerInUse);
14568
+ return listener;
14569
+ },
14570
+ onAddContextListener: (handler) => {
14571
+ checkIfClientDisconnected();
14572
+ return privateChannelClient.onAddContextListener(handler);
14573
+ },
14574
+ disconnect: async () => {
14575
+ checkIfClientDisconnected();
14576
+ clientDisconnected = true;
14577
+ return privateChannelClient.disconnect();
14578
+ },
14579
+ onDisconnect: (handler) => {
14580
+ checkIfClientDisconnected();
14581
+ return privateChannelClient.onDisconnect(handler);
14582
+ },
14583
+ onUnsubscribe: (handler) => {
14584
+ checkIfClientDisconnected();
14585
+ return privateChannelClient.onUnsubscribe(handler);
14586
+ }
14587
+ };
14588
+ };
14589
+ exports.buildPrivateChannelObject = buildPrivateChannelObject;
14590
+ const buildAppChannelObject = (sessionContextGroup) => {
14591
+ return {
14592
+ id: sessionContextGroup.id,
14593
+ type: 'app',
14594
+ broadcast: sessionContextGroup.setContext,
14595
+ getCurrentContext: async (contextType) => {
14596
+ const context = await sessionContextGroup.getCurrentContext(contextType);
14597
+ return context === undefined ? null : context;
14598
+ },
14599
+ // @ts-expect-error TODO [CORE-1524]
14600
+ addContextListener: (contextType, handler) => {
14601
+ let realHandler;
14602
+ let realType;
14603
+ if (typeof contextType === 'function') {
14604
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
14605
+ realHandler = contextType;
14606
+ }
14607
+ else {
14608
+ realHandler = handler;
14609
+ if (typeof contextType === 'string') {
14610
+ realType = contextType;
14611
+ }
14612
+ }
14613
+ const listener = (async () => {
14614
+ let first = true;
14615
+ const currentContext = await sessionContextGroup.getCurrentContext(realType);
14616
+ const wrappedHandler = (context, contextMetadata) => {
14617
+ if (first) {
14618
+ first = false;
14619
+ if ((0, lodash_1.isEqual)(currentContext, context)) {
14620
+ return;
14621
+ }
14622
+ }
14623
+ // eslint-disable-next-line consistent-return
14624
+ return realHandler(context, contextMetadata);
14625
+ };
14626
+ return sessionContextGroup.addContextHandler(wrappedHandler, realType);
14627
+ })();
14628
+ return {
14629
+ ...listener,
14630
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
14631
+ };
14632
+ }
14633
+ };
14634
+ };
14635
+ exports.buildAppChannelObject = buildAppChannelObject;
14636
+ const connectPrivateChannel = async (channelId) => {
14637
+ try {
14638
+ const channelClient = await fin.InterApplicationBus.Channel.connect(channelId);
14639
+ const privateChannelClient = new PrivateChannelClient_1.PrivateChannelClient(channelClient, channelId);
14640
+ return (0, exports.buildPrivateChannelObject)(privateChannelClient);
14641
+ }
14642
+ catch (error) {
14643
+ throw new Error(`Private Channel with id: ${channelId} doesn't exist`);
14644
+ }
14645
+ };
14646
+ exports.connectPrivateChannel = connectPrivateChannel;
14647
+ const isContext = (context) => {
14648
+ if (context && typeof context === 'object' && 'type' in context) {
14649
+ const { type } = context;
14650
+ return typeof type === 'string';
14651
+ }
14652
+ return false;
14653
+ };
14654
+ exports.isContext = isContext;
14655
+ const isChannel = (channel) => {
14656
+ if (channel && typeof channel === 'object' && 'type' in channel && 'id' in channel) {
14657
+ const { type, id } = channel;
14658
+ return typeof type === 'string' && typeof id === 'string' && (type === 'app' || type === 'private');
14659
+ }
14660
+ return false;
14661
+ };
14662
+ exports.isChannel = isChannel;
14663
+ const getIntentResolution = async (interopModule, context, app, intent) => {
14664
+ // Generate an ID to make a session context group with. We will pass that ID to the Broker.
14665
+ // The broker will then setContext on that session context group later with our Intent Result,
14666
+ const guid = (0, utils_1.generateId)(); // TODO make this undefined in web
14667
+ // Promise we'll use in getResult
14668
+ const getResultPromise = new Promise((resolve, reject) => {
14669
+ fin.InterApplicationBus.subscribe({ uuid: '*' }, guid, (intentResult) => {
14670
+ resolve(intentResult);
14671
+ }).catch(() => reject(new Error('getResult is not supported in this environment')));
14672
+ });
14673
+ // Adding the intentResolutionResultId to the intentObj. Because fireIntent only accepts a single arg, we have to slap it in here.
14674
+ const metadata = app ? { target: app, intentResolutionResultId: guid } : { intentResolutionResultId: guid };
14675
+ const intentObj = intent ? { name: intent, context, metadata } : { ...context, metadata };
14676
+ // Set up the getResult call.
14677
+ const getResult = async () => {
14678
+ let intentResult = await getResultPromise;
14679
+ if (!intentResult || typeof intentResult !== 'object') {
14680
+ throw new Error(ResultError.NoResultReturned);
14681
+ }
14682
+ const { error } = intentResult;
14683
+ if (error) {
14684
+ throw new Error(ResultError.IntentHandlerRejected);
14685
+ }
14686
+ if ((0, exports.isChannel)(intentResult)) {
14687
+ const { id, type } = intentResult;
14688
+ switch (type) {
14689
+ case 'private': {
14690
+ intentResult = await (0, exports.connectPrivateChannel)(id);
14691
+ break;
14692
+ }
14693
+ case 'app': {
14694
+ const sessionContextGroup = await interopModule.joinSessionContextGroup(id);
14695
+ intentResult = (0, exports.buildAppChannelObject)(sessionContextGroup);
14696
+ break;
14697
+ }
14698
+ }
14699
+ }
14700
+ else if (!(0, exports.isContext)(intentResult)) {
14701
+ throw new Error(ResultError.NoResultReturned);
14702
+ }
14703
+ return intentResult;
14704
+ };
14705
+ // Finally fire the intent.
14706
+ const intentResolutionInfoFromBroker = intent
14707
+ ? await interopModule.fireIntent(intentObj)
14708
+ : await interopModule.fireIntentForContext(intentObj);
14709
+ if (typeof intentResolutionInfoFromBroker !== 'object') {
14710
+ return {
14711
+ source: {
14712
+ appId: '',
14713
+ instanceId: ''
14714
+ },
14715
+ intent: '',
14716
+ version: '2.0',
14717
+ getResult
14718
+ };
14719
+ }
14720
+ return { ...intentResolutionInfoFromBroker, getResult };
14721
+ };
14722
+ exports.getIntentResolution = getIntentResolution;
14723
+ } (utils$2));
14724
+
14725
+ var hasRequiredFdc3Common;
14726
+
14727
+ function requireFdc3Common () {
14728
+ if (hasRequiredFdc3Common) return fdc3Common;
14729
+ hasRequiredFdc3Common = 1;
14730
+ var __classPrivateFieldGet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
14731
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
14732
+ 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");
14733
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
14734
+ };
14735
+ var __classPrivateFieldSet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
14736
+ if (kind === "m") throw new TypeError("Private method is not writable");
14737
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14738
+ 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");
14739
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
14740
+ };
14741
+ var _FDC3ModuleBase_producer;
14742
+ Object.defineProperty(fdc3Common, "__esModule", { value: true });
14743
+ fdc3Common.FDC3ModuleBase = void 0;
14744
+ const utils_1 = utils$2;
14745
+ const utils_2 = utils$3;
14746
+ const InteropClient_1 = requireInteropClient();
14747
+ const lodash_1 = require$$3;
14748
+ class FDC3ModuleBase {
14749
+ get client() {
14750
+ return __classPrivateFieldGet(this, _FDC3ModuleBase_producer, "f").call(this);
14751
+ }
14752
+ get fin() {
14753
+ return this.wire.getFin();
14754
+ }
14755
+ // eslint-disable-next-line no-useless-constructor
14756
+ constructor(producer, wire) {
14757
+ this.wire = wire;
14758
+ _FDC3ModuleBase_producer.set(this, void 0);
14759
+ __classPrivateFieldSet(this, _FDC3ModuleBase_producer, producer, "f");
14760
+ }
14761
+ /**
14762
+ * Broadcasts a context for the channel of the current entity.
14763
+ * @param context - New context to set.
14764
+ *
14765
+ * @tutorial fdc3.broadcast
14766
+ * @static
14767
+ */
14768
+ async broadcast(context) {
14769
+ this.wire.sendAction('fdc3-broadcast').catch((e) => {
14770
+ // we do not want to expose this error, just continue if this analytics-only call fails
14771
+ });
14772
+ return this.client.setContext(context);
14773
+ }
14774
+ /**
14775
+ * Launches an app with target information, which can either be a string or an AppMetadata object.
14776
+ * @param app
14777
+ * @param context
14778
+ *
14779
+ * @tutorial fdc3.open
14780
+ */
14781
+ async _open(app, context) {
14782
+ this.wire.sendAction('fdc3-open').catch((e) => {
14783
+ // we do not want to expose this error, just continue if this analytics-only call fails
14784
+ });
14785
+ try {
14786
+ return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3Open', { app, context });
14787
+ }
14788
+ catch (error) {
14789
+ const errorToThrow = error.message === utils_2.BROKER_ERRORS.fdc3Open ? 'ResolverUnavailable' : error.message;
14790
+ throw new Error(errorToThrow);
14791
+ }
14792
+ }
14793
+ /**
14794
+ * Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
14795
+ * @param channelId
14796
+ *
14797
+ * @tutorial fdc3.getOrCreateChannel
14798
+ */
14799
+ async getOrCreateChannel(channelId) {
14800
+ this.wire.sendAction('fdc3-get-or-create-channel').catch((e) => {
14801
+ // we do not want to expose this error, just continue if this analytics-only call fails
14802
+ });
14803
+ const systemChannels = await this.getSystemChannels();
14804
+ const userChannel = systemChannels.find((channel) => channel.id === channelId);
14805
+ if (userChannel) {
14806
+ return { ...userChannel, type: 'system', ...(0, utils_1.getUnsupportedChannelApis)() };
14807
+ }
14808
+ try {
14809
+ const sessionContextGroup = await this.client.joinSessionContextGroup(channelId);
14810
+ return (0, utils_1.buildAppChannelObject)(sessionContextGroup);
14811
+ }
14812
+ catch (error) {
14813
+ console.error(error.message);
14814
+ throw new Error(utils_1.ChannelError.CreationFailed);
14815
+ }
14816
+ }
14817
+ /**
14818
+ * Returns the Interop-Broker-defined context groups available for an entity to join.
14819
+ *
14820
+ * @tutorial fdc3.getSystemChannels
14821
+ * @static
14822
+ */
14823
+ async getSystemChannels() {
14824
+ this.wire.sendAction('fdc3-get-system-channels').catch((e) => {
14825
+ // we do not want to expose this error, just continue if this analytics-only call fails
14826
+ });
14827
+ const channels = await this.client.getContextGroups();
14828
+ // fdc3 implementation of getSystemChannels returns on array of channels, have to decorate over
14829
+ // this so people know that these APIs are not supported
14830
+ return channels.map((channel) => {
14831
+ return { ...channel, type: 'system', ...(0, utils_1.getUnsupportedChannelApis)() };
14832
+ });
14833
+ }
14834
+ /**
14835
+ * Join all Interop Clients at the given identity to context group `contextGroupId`.
14836
+ * If no target is specified, it adds the sender to the context group.
14837
+ * 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.
14838
+ * 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.
14839
+ * 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.
14840
+ * @param channelId - Id of the context group.
14841
+ *
14842
+ * @tutorial fdc3.joinChannel
14843
+ * @static
14844
+ */
14845
+ async joinChannel(channelId) {
14846
+ this.wire.sendAction('fdc3-join-channel').catch((e) => {
14847
+ // we do not want to expose this error, just continue if this analytics-only call fails
14848
+ });
14849
+ try {
14850
+ return await this.client.joinContextGroup(channelId);
14851
+ }
14852
+ catch (error) {
14853
+ if (error.message === utils_2.BROKER_ERRORS.joinSessionContextGroupWithJoinContextGroup) {
14854
+ 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.');
14855
+ }
14856
+ else {
14857
+ console.error(error.message);
14858
+ }
14859
+ if (error.message.startsWith('Attempting to join a context group that does not exist')) {
14860
+ throw new Error(utils_1.ChannelError.NoChannelFound);
14861
+ }
14862
+ throw new Error(utils_1.ChannelError.AccessDenied);
14863
+ }
14864
+ }
14865
+ /**
14866
+ * Returns the Channel that the entity is subscribed to. Returns null if not joined to a channel.
14867
+ *
14868
+ * @tutorial fdc3.getCurrentChannel
14869
+ */
14870
+ async getCurrentChannel() {
14871
+ this.wire.sendAction('fdc3-get-current-channel').catch((e) => {
14872
+ // we do not want to expose this error, just continue if this analytics-only call fails
14873
+ });
14874
+ const currentContextGroupInfo = await this.getCurrentContextGroupInfo();
14875
+ if (!currentContextGroupInfo) {
14876
+ return null;
14877
+ }
14878
+ return this.buildChannelObject(currentContextGroupInfo);
14879
+ }
14880
+ /**
14881
+ * Removes the specified target from a context group.
14882
+ * If no target is specified, it removes the sender from their context group.
14883
+ *
14884
+ * @tutorial fdc3.leaveCurrentChannel
14885
+ * @static
14886
+ */
14887
+ async leaveCurrentChannel() {
14888
+ this.wire.sendAction('fdc3-leave-current-channel').catch((e) => {
14889
+ // we do not want to expose this error, just continue if this analytics-only call fails
14890
+ });
14891
+ return this.client.removeFromContextGroup();
14892
+ }
14893
+ // utils
14894
+ // eslint-disable-next-line class-methods-use-this
14895
+ async getCurrentContextGroupInfo() {
14896
+ const contextGroups = await this.client.getContextGroups();
14897
+ const clientsInCtxGroupsPromise = contextGroups.map(async (ctxGroup) => {
14898
+ return this.client.getAllClientsInContextGroup(ctxGroup.id);
14899
+ });
14900
+ const clientsInCtxGroups = await Promise.all(clientsInCtxGroupsPromise);
14901
+ const clientIdx = clientsInCtxGroups.findIndex((clientIdentityArr) => {
14902
+ return clientIdentityArr.some((clientIdentity) => {
14903
+ const { uuid, name } = clientIdentity;
14904
+ return this.wire.me.uuid === uuid && this.wire.me.name === name;
14905
+ });
14906
+ });
14907
+ return contextGroups[clientIdx];
14908
+ }
14909
+ async buildChannelObject(currentContextGroupInfo) {
14910
+ // @ts-expect-error
14911
+ return {
14912
+ ...currentContextGroupInfo,
14913
+ type: 'system',
14914
+ addContextListener: (...[contextType, handler]) => {
14915
+ let realHandler;
14916
+ let realType;
14917
+ if (typeof contextType === 'function') {
14918
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
14919
+ realHandler = contextType;
14920
+ }
14921
+ else {
14922
+ realHandler = handler;
14923
+ if (typeof contextType === 'string') {
14924
+ realType = contextType;
14925
+ }
14926
+ }
14927
+ const listener = (async () => {
14928
+ let first = true;
14929
+ const currentContext = await this.client.getCurrentContext(realType);
14930
+ const wrappedHandler = (context, contextMetadata) => {
14931
+ if (first) {
14932
+ first = false;
14933
+ if ((0, lodash_1.isEqual)(currentContext, context)) {
14934
+ return;
14935
+ }
14936
+ }
14937
+ // eslint-disable-next-line consistent-return
14938
+ return realHandler(context, contextMetadata);
14939
+ };
14940
+ return this.client.addContextHandler(wrappedHandler, realType);
14941
+ })();
14942
+ // @ts-expect-error TODO [CORE-1524]
14943
+ return {
14944
+ ...listener,
14945
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
14946
+ };
14947
+ },
14948
+ broadcast: this.broadcast.bind(this),
14949
+ // @ts-expect-error Typescript fails to infer the returntype is a Promise
14950
+ getCurrentContext: async (contextType) => {
14951
+ const context = await this.client.getCurrentContext(contextType);
14952
+ // @ts-expect-error Typescript fails to infer the returntype is a Promise
14953
+ return context === undefined ? null : context;
14954
+ }
14955
+ };
14956
+ }
14957
+ }
14958
+ fdc3Common.FDC3ModuleBase = FDC3ModuleBase;
14959
+ _FDC3ModuleBase_producer = new WeakMap();
14960
+ return fdc3Common;
14961
+ }
14962
+
14963
+ var hasRequiredFdc31_2;
14964
+
14965
+ function requireFdc31_2 () {
14966
+ if (hasRequiredFdc31_2) return fdc31_2;
14967
+ hasRequiredFdc31_2 = 1;
14968
+ Object.defineProperty(fdc31_2, "__esModule", { value: true });
14969
+ fdc31_2.Fdc3Module = void 0;
14970
+ const utils_1 = utils$3;
14971
+ const fdc3_common_1 = requireFdc3Common();
14972
+ /**
14973
+ * @version 1.2
14974
+ * The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
14975
+ * while using our Interop API under the hood. In order to use this set of APIs
14976
+ * 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
14977
+ * our {@link https://developers.openfin.co/of-docs/docs/enable-color-linking Interop API}.
14978
+ *
14979
+ * To enable the FDC3 APIs in a {@link Window Window} or {@link View View}, add the fdc3InteropApi
14980
+ * property to its options:
14981
+ *
14982
+ * ```js
14983
+ * {
14984
+ * autoShow: false,
14985
+ * saveWindowState: true,
14986
+ * url: 'https://openfin.co',
14987
+ * fdc3InteropApi: '1.2'
14988
+ * }
14989
+ * ```
14990
+ *
14991
+ * If using a {@link Platform Platform } application, you can set this property in defaultWindowOptions and defaultViewOptions.
14992
+ *
14993
+ * In order to ensure that the FDC3 Api is ready before use, you can use the 'fdc3Ready' event fired on the DOM Window object:
14994
+ *
14995
+ * ```js
14996
+ * function fdc3Action() {
14997
+ * // Make some fdc3 API calls here
14998
+ * }
14999
+ *
15000
+ * if (window.fdc3) {
15001
+ * fdc3Action();
15002
+ * } else {
15003
+ * window.addEventListener('fdc3Ready', fdc3Action);
15004
+ * }
15005
+ * ```
15006
+ */
15007
+ class Fdc3Module extends fdc3_common_1.FDC3ModuleBase {
15008
+ async open(app, context) {
15009
+ // eslint-disable-next-line no-underscore-dangle
15010
+ await super._open(app, context);
15011
+ }
15012
+ /**
15013
+ * 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.
15014
+ * @param contextType - The type of context you wish to handle.
15015
+ * @param handler - Handler for incoming context.
15016
+ *
15017
+ * @tutorial fdc3.addContextListener
15018
+ * @static
15019
+ */
15020
+ // @ts-expect-error TODO [CORE-1524]
15021
+ addContextListener(contextType, handler) {
15022
+ this.wire.sendAction('fdc3-add-context-listener').catch((e) => {
15023
+ // we do not want to expose this error, just continue if this analytics-only call fails
15024
+ });
15025
+ let listener;
15026
+ if (typeof contextType === 'function') {
15027
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
15028
+ listener = this.client.addContextHandler(contextType);
15029
+ }
15030
+ else {
15031
+ listener = this.client.addContextHandler(handler, contextType === null ? undefined : contextType);
15032
+ }
15033
+ return {
15034
+ ...listener,
15035
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
15036
+ };
15037
+ }
15038
+ /**
15039
+ * Adds a listener for incoming Intents.
15040
+ * @param intent - Name of the Intent
15041
+ * @param handler - Handler for incoming Intent
15042
+ *
15043
+ * @tutorial fdc3.addIntentListener
15044
+ * @static
15045
+ */
15046
+ addIntentListener(intent, handler) {
15047
+ this.wire.sendAction('fdc3-add-intent-listener').catch((e) => {
15048
+ // we do not want to expose this error, just continue if this analytics-only call fails
15049
+ });
15050
+ const contextHandler = (raisedIntent) => {
15051
+ const { context, metadata: intentMetadata } = raisedIntent;
15052
+ const { metadata } = context;
15053
+ const intentResolutionResultId = intentMetadata?.intentResolutionResultId || metadata?.intentResolutionResultId;
15054
+ if (intentResolutionResultId) {
15055
+ this.fin.InterApplicationBus.publish(intentResolutionResultId, null).catch(() => null);
15056
+ }
15057
+ handler(raisedIntent.context);
15058
+ };
15059
+ const listener = this.client.registerIntentHandler(contextHandler, intent, {
15060
+ fdc3Version: '1.2'
15061
+ });
15062
+ return {
15063
+ ...listener,
15064
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
15065
+ };
15066
+ }
15067
+ /**
15068
+ * Raises a specific intent.
15069
+ * @param intent Name of the Intent.
15070
+ * @param context Context associated with the Intent.
15071
+ * @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}.
15072
+ *
15073
+ * @tutorial fdc3.raiseIntent
15074
+ * @static
15075
+ */
15076
+ async raiseIntent(intent, context, app) {
15077
+ this.wire.sendAction('fdc3-raise-intent').catch((e) => {
15078
+ // we do not want to expose this error, just continue if this analytics-only call fails
15079
+ });
15080
+ const intentObj = app
15081
+ ? { name: intent, context, metadata: { target: app } }
15082
+ : { name: intent, context };
15083
+ try {
15084
+ return await this.client.fireIntent(intentObj);
15085
+ }
15086
+ catch (error) {
15087
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
15088
+ throw new Error(errorToThrow);
15089
+ }
15090
+ }
15091
+ /**
15092
+ * Find out more information about a particular intent by passing its name, and optionally its context.
15093
+ * @param intent Name of the Intent
15094
+ * @param context
15095
+ *
15096
+ * @tutorial fdc3.findIntent
15097
+ */
15098
+ async findIntent(intent, context) {
15099
+ this.wire.sendAction('fdc3-find-intent').catch((e) => {
15100
+ // we do not want to expose this error, just continue if this analytics-only call fails
15101
+ });
15102
+ try {
15103
+ return await this.client.getInfoForIntent({ name: intent, context });
15104
+ }
15105
+ catch (error) {
15106
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntent ? 'ResolverUnavailable' : error.message;
15107
+ throw new Error(errorToThrow);
15108
+ }
15109
+ }
15110
+ /**
15111
+ * Find all the available intents for a particular context.
15112
+ * @param context
15113
+ *
15114
+ * @tutorial fdc3.findIntentsByContext
15115
+ */
15116
+ async findIntentsByContext(context) {
15117
+ this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
15118
+ // we do not want to expose this error, just continue if this analytics-only call fails
15119
+ });
15120
+ try {
15121
+ return await this.client.getInfoForIntentsByContext(context);
15122
+ }
15123
+ catch (error) {
15124
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error.message;
15125
+ throw new Error(errorToThrow);
15126
+ }
15127
+ }
15128
+ /**
15129
+ * Finds and raises an intent against a target app based purely on context data.
15130
+ * @param context
15131
+ * @param app
15132
+ *
15133
+ * @tutorial fdc3.raiseIntentForContext
15134
+ */
15135
+ async raiseIntentForContext(context, app) {
15136
+ this.wire.sendAction('fdc3-raise-intent-for-context').catch((e) => {
15137
+ // we do not want to expose this error, just continue if this analytics-only call fails
15138
+ });
15139
+ try {
15140
+ return await this.client.fireIntentForContext({ ...context, metadata: { target: app } });
15141
+ }
15142
+ catch (error) {
15143
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntentForContext ? 'ResolverUnavailable' : error.message;
15144
+ throw new Error(errorToThrow);
15145
+ }
15146
+ }
15147
+ /**
15148
+ * Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
15149
+ * @param channelId
15150
+ *
15151
+ * @tutorial fdc3.getOrCreateChannel
15152
+ */
15153
+ async getOrCreateChannel(channelId) {
15154
+ return super.getOrCreateChannel(channelId);
15155
+ }
15156
+ /**
15157
+ * 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.
15158
+ *
15159
+ * @tutorial fdc3.getInfo
15160
+ */
15161
+ getInfo() {
15162
+ this.wire.sendAction('fdc3-get-info').catch((e) => {
15163
+ // we do not want to expose this error, just continue if this analytics-only call fails
15164
+ });
15165
+ // @ts-expect-error
15166
+ const { uuid, fdc3InteropApi } = fin.__internal_.initialOptions;
15167
+ // @ts-expect-error
15168
+ const runtimeVersion = fin.desktop.getVersion();
15169
+ return {
15170
+ fdc3Version: fdc3InteropApi,
15171
+ provider: `openfin-${uuid}`,
15172
+ providerVersion: runtimeVersion
15173
+ };
15174
+ }
15175
+ }
15176
+ fdc31_2.Fdc3Module = Fdc3Module;
15177
+ return fdc31_2;
15178
+ }
15179
+
15180
+ var fdc32_0 = {};
15181
+
15182
+ var hasRequiredFdc32_0;
15183
+
15184
+ function requireFdc32_0 () {
15185
+ if (hasRequiredFdc32_0) return fdc32_0;
15186
+ hasRequiredFdc32_0 = 1;
15187
+ Object.defineProperty(fdc32_0, "__esModule", { value: true });
15188
+ fdc32_0.Fdc3Module2 = void 0;
15189
+ const fdc3_common_1 = requireFdc3Common();
15190
+ const utils_1 = utils$3;
15191
+ const InteropClient_1 = requireInteropClient();
15192
+ const utils_2 = utils$2;
15193
+ const PrivateChannelClient_1 = PrivateChannelClient$1;
15194
+ /**
15195
+ * @version 2.0
15196
+ * The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
15197
+ * while using our Interop API under the hood. In order to use this set of APIs
15198
+ * 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
15199
+ * our {@link https://developers.openfin.co/of-docs/docs/enable-context-sharing Interop API}.
15200
+ *
15201
+ * To enable the FDC3 APIs in a {@link Window Window} or {@link View View}, add the fdc3InteropApi
15202
+ * property to its options:
15203
+ *
15204
+ * ```js
15205
+ * {
15206
+ * autoShow: false,
15207
+ * saveWindowState: true,
15208
+ * url: 'https://openfin.co',
15209
+ * fdc3InteropApi: '2.0'
15210
+ * }
15211
+ * ```
15212
+ *
15213
+ * If using a {@link Platform Platform } application, you can set this property in defaultWindowOptions and defaultViewOptions.
15214
+ *
15215
+ * In order to ensure that the FDC3 Api is ready before use, you can use the 'fdc3Ready' event fired on the DOM Window object:
15216
+ *
15217
+ * ```js
15218
+ * function fdc3Action() {
15219
+ * // Make some fdc3 API calls here
15220
+ * }
15221
+ *
15222
+ * if (window.fdc3) {
15223
+ * fdc3Action();
15224
+ * } else {
15225
+ * window.addEventListener('fdc3Ready', fdc3Action);
15226
+ * }
15227
+ * ```
15228
+ */
15229
+ class Fdc3Module2 extends fdc3_common_1.FDC3ModuleBase {
15230
+ /**
15231
+ * Launches an app, specified via an AppIdentifier object.
15232
+ * @param app
15233
+ * @param context
15234
+ *
15235
+ * @tutorial fdc3.open
15236
+ */
15237
+ async open(app, context) {
15238
+ if (typeof app === 'string') {
15239
+ console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
15240
+ }
15241
+ // eslint-disable-next-line no-underscore-dangle
15242
+ return super._open(app, context);
15243
+ }
15244
+ /**
15245
+ * Find all the available instances for a particular application.
15246
+ * @param app
15247
+ *
15248
+ * @tutorial fdc3v2.findInstances
15249
+ */
15250
+ async findInstances(app) {
15251
+ this.wire.sendAction('fdc3-find-instances').catch((e) => {
15252
+ // we do not want to expose this error, just continue if this analytics-only call fails
15253
+ });
15254
+ try {
15255
+ return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3FindInstances', app);
15256
+ }
15257
+ catch (error) {
15258
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fdc3FindInstances ? 'ResolverUnavailable' : error.message;
15259
+ throw new Error(errorToThrow);
15260
+ }
15261
+ }
15262
+ /**
15263
+ * 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.
15264
+ * @param app
15265
+ *
15266
+ * @tutorial fdc3v2.getAppMetadata
15267
+ */
15268
+ async getAppMetadata(app) {
15269
+ this.wire.sendAction('fdc3-get-app-metadata').catch((e) => {
15270
+ // we do not want to expose this error, just continue if this analytics-only call fails
15271
+ });
15272
+ try {
15273
+ return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3GetAppMetadata', app);
15274
+ }
15275
+ catch (error) {
15276
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fdc3GetAppMetadata ? 'ResolverUnavailable' : error.message;
15277
+ throw new Error(errorToThrow);
15278
+ }
15279
+ }
15280
+ /**
15281
+ * 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.
15282
+ * @param contextType
15283
+ * @param handler
15284
+ *
15285
+ * @tutorial fdc3.addContextListener
15286
+ */
15287
+ // @ts-expect-error TODO [CORE-1524]
15288
+ async addContextListener(contextType, handler) {
15289
+ this.wire.sendAction('fdc3-add-context-listener').catch((e) => {
15290
+ // we do not want to expose this error, just continue if this analytics-only call fails
15291
+ });
15292
+ // The FDC3 ContextHandler only expects the context and optional ContextMetadata, so we wrap the handler
15293
+ // here so it only gets passed these parameters
15294
+ const getWrappedHandler = (handlerToWrap) => {
15295
+ return (context) => {
15296
+ const { contextMetadata, ...rest } = context;
15297
+ const args = contextMetadata ? [{ ...rest }, contextMetadata] : [context, null];
15298
+ handlerToWrap(...args);
15299
+ };
15300
+ };
15301
+ let actualHandler = handler;
15302
+ let wrappedHandler = getWrappedHandler(actualHandler);
15303
+ if (typeof contextType === 'function') {
15304
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
15305
+ actualHandler = contextType;
15306
+ wrappedHandler = getWrappedHandler(actualHandler);
15307
+ return this.client.addContextHandler(wrappedHandler);
15308
+ }
15309
+ return this.client.addContextHandler(wrappedHandler, contextType === null ? undefined : contextType);
15310
+ }
15311
+ /**
15312
+ * Find out more information about a particular intent by passing its name, and optionally its context and resultType.
15313
+ * @param intent Name of the Intent
15314
+ * @param context Context
15315
+ * @param resultType The type of result returned for any intent specified during resolution.
15316
+ *
15317
+ * @tutorial fdc3.findIntent
15318
+ */
15319
+ async findIntent(intent, context, resultType) {
15320
+ this.wire.sendAction('fdc3-find-intent').catch((e) => {
15321
+ // we do not want to expose this error, just continue if this analytics-only call fails
15322
+ });
15323
+ try {
15324
+ return await this.client.getInfoForIntent({ name: intent, context, metadata: { resultType } });
15325
+ }
15326
+ catch (error) {
15327
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntent ? 'ResolverUnavailable' : error.message;
15328
+ throw new Error(errorToThrow);
15329
+ }
15330
+ }
15331
+ /**
15332
+ * Find all the available intents for a particular context.
15333
+ * @param context
15334
+ * @param resultType The type of result returned for any intent specified during resolution.
15335
+ *
15336
+ * @tutorial fdc3v2.findIntentsByContext
15337
+ */
15338
+ async findIntentsByContext(context, resultType) {
15339
+ this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
15340
+ // we do not want to expose this error, just continue if this analytics-only call fails
15341
+ });
15342
+ const payload = resultType ? { context, metadata: { resultType } } : context;
15343
+ try {
15344
+ return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3v2FindIntentsByContext', payload);
15345
+ }
15346
+ catch (error) {
15347
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error.message;
15348
+ throw new Error(errorToThrow);
15349
+ }
15350
+ }
15351
+ /**
15352
+ * Raises a specific intent for resolution against apps registered with the desktop agent.
15353
+ * @param intent Name of the Intent
15354
+ * @param context Context associated with the Intent
15355
+ * @param app
15356
+ *
15357
+ * @tutorial fdc3v2.raiseIntent
15358
+ */
15359
+ async raiseIntent(intent, context, app) {
15360
+ this.wire.sendAction('fdc3-raise-intent').catch((e) => {
15361
+ // we do not want to expose this error, just continue if this analytics-only call fails
15362
+ });
15363
+ try {
15364
+ if (typeof app === 'string') {
15365
+ console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
15366
+ }
15367
+ return (0, utils_2.getIntentResolution)(this.client, context, app, intent);
15368
+ }
15369
+ catch (error) {
15370
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
15371
+ throw new Error(errorToThrow);
15372
+ }
15373
+ }
15374
+ /**
15375
+ * Finds and raises an intent against apps registered with the desktop agent based purely on the type of the context data.
15376
+ * @param context Context associated with the Intent
15377
+ * @param app
15378
+ *
15379
+ * @tutorial fdc3v2.raiseIntentForContext
15380
+ */
15381
+ async raiseIntentForContext(context, app) {
15382
+ // TODO: We have to do the same thing we do for raiseIntent here as well.
15383
+ this.wire.sendAction('fdc3-raise-intent-for-context').catch((e) => {
15384
+ // we do not want to expose this error, just continue if this analytics-only call fails
15385
+ });
15386
+ try {
15387
+ if (typeof app === 'string') {
15388
+ console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
15389
+ }
15390
+ return (0, utils_2.getIntentResolution)(this.client, context, app);
15391
+ }
15392
+ catch (error) {
15393
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
15394
+ throw new Error(errorToThrow);
15395
+ }
15396
+ }
15397
+ /**
15398
+ * Adds a listener for incoming intents.
15399
+ * @param intent Name of the Intent
15400
+ * @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.
15401
+ *
15402
+ * @tutorial fdc3.addIntentListener
15403
+ */
15404
+ async addIntentListener(intent, handler) {
15405
+ this.wire.sendAction('fdc3-add-intent-listener').catch((e) => {
15406
+ // we do not want to expose this error, just continue if this analytics-only call fails
15407
+ });
15408
+ if (typeof intent !== 'string') {
15409
+ throw new Error('First argument must be an Intent name');
15410
+ }
15411
+ // The FDC3 Intenter handler only expects the context and contextMetadata to be passed to the handler,
15412
+ // so we wrap it here and only pass those paramaters.
15413
+ const contextHandler = async (raisedIntent) => {
15414
+ let intentResult;
15415
+ let intentResultToSend;
15416
+ const { context, metadata: intentMetadata } = raisedIntent;
15417
+ const { contextMetadata, metadata, ...rest } = context;
15418
+ const intentResolutionResultId = intentMetadata?.intentResolutionResultId || metadata?.intentResolutionResultId;
15419
+ try {
15420
+ const newContext = metadata ? { metadata, ...rest } : { ...rest };
15421
+ intentResult = await handler(newContext, contextMetadata);
15422
+ intentResultToSend = intentResult;
15423
+ }
15424
+ catch (error) {
15425
+ intentResult = error;
15426
+ intentResultToSend = { error: true };
15427
+ }
15428
+ if (intentResolutionResultId) {
15429
+ this.fin.InterApplicationBus.publish(intentResolutionResultId, intentResultToSend).catch(() => null);
15430
+ }
15431
+ if (intentResult instanceof Error) {
15432
+ throw new Error(intentResult.message);
15433
+ }
15434
+ return intentResult;
15435
+ };
15436
+ return this.client.registerIntentHandler(contextHandler, intent, { fdc3Version: '2.0' });
15437
+ }
15438
+ /**
15439
+ * Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
15440
+ * @param channelId
15441
+ *
15442
+ * @tutorial fdc3.getOrCreateChannel
15443
+ */
15444
+ async getOrCreateChannel(channelId) {
15445
+ return super.getOrCreateChannel(channelId);
15446
+ }
15447
+ /**
15448
+ * 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.
15449
+ *
15450
+ * @tutorial fdc3v2.createPrivateChannel
15451
+ */
15452
+ async createPrivateChannel() {
15453
+ const channelId = (0, utils_1.generateId)();
15454
+ await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'createPrivateChannelProvider', { channelId });
15455
+ const channelClient = await this.fin.InterApplicationBus.Channel.connect(channelId);
15456
+ const newPrivateChannelClient = new PrivateChannelClient_1.PrivateChannelClient(channelClient, channelId);
15457
+ return (0, utils_2.buildPrivateChannelObject)(newPrivateChannelClient);
15458
+ }
15459
+ /**
15460
+ * Retrieves a list of the User Channels available for the app to join.
15461
+ *
15462
+ * @tutorial fdc3v2.getUserChannels
15463
+ */
15464
+ async getUserChannels() {
15465
+ const channels = await this.client.getContextGroups();
15466
+ // fdc3 implementation of getUserChannels returns on array of channels, have to decorate over
15467
+ // this so people know that these APIs are not supported
15468
+ return channels.map((channel) => {
15469
+ // @ts-expect-error TODO [CORE-1524]
15470
+ return { ...channel, type: 'user', ...(0, utils_2.getUnsupportedChannelApis)('User') };
15471
+ });
15472
+ }
15473
+ /**
15474
+ * Retrieves a list of the User Channels available for the app to join.
15475
+ *
15476
+ * @deprecated Please use {@link fdc3.getUserChannels fdc3.getUserChannels} instead
15477
+ * @tutorial fdc3.getSystemChannels
15478
+ */
15479
+ async getSystemChannels() {
15480
+ console.warn('This API has been deprecated. Please use fdc3.getUserChannels instead.');
15481
+ return super.getSystemChannels();
15482
+ }
15483
+ /**
15484
+ * Join an app to a specified User channel.
15485
+ * @param channelId Channel name
15486
+ *
15487
+ * @tutorial fdc3v2.joinUserChannel
15488
+ */
15489
+ async joinUserChannel(channelId) {
15490
+ return super.joinChannel(channelId);
15491
+ }
15492
+ /**
15493
+ * Join an app to a specified User channel.
15494
+ * @param channelId Channel name
15495
+ * @deprecated Please use {@link fdc3.joinUserChannel fdc3.joinUserChannel} instead
15496
+ *
15497
+ * @tutorial fdc3.joinChannel
15498
+ */
15499
+ async joinChannel(channelId) {
15500
+ console.warn('This API has been deprecated. Please use fdc3.joinUserChannel instead.');
15501
+ return super.joinChannel(channelId);
15502
+ }
15503
+ /**
15504
+ * Returns the Channel object for the current User channel membership
15505
+ *
15506
+ * @tutorial fdc3.getCurrentChannel
15507
+ */
15508
+ async getCurrentChannel() {
15509
+ const currentChannel = await super.getCurrentChannel();
15510
+ if (!currentChannel) {
15511
+ return null;
15512
+ }
15513
+ return {
15514
+ ...currentChannel,
15515
+ type: 'user',
15516
+ broadcast: this.broadcast.bind(this)
15517
+ };
15518
+ }
15519
+ /**
15520
+ * 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.
15521
+ * fdc3HandleGetInfo must be overridden in the InteropBroker so that the ImplementationMetadata will have the appMetadata info.
15522
+ *
15523
+ * @tutorial fdc3v2.getInfo
15524
+ */
15525
+ async getInfo() {
15526
+ return InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3v2GetInfo', { fdc3Version: '2.0' });
15527
+ }
15528
+ }
15529
+ fdc32_0.Fdc3Module2 = Fdc3Module2;
15530
+ return fdc32_0;
15531
+ }
15532
+
15533
+ var hasRequiredInteropClient;
15534
+
15535
+ function requireInteropClient () {
15536
+ if (hasRequiredInteropClient) return InteropClient;
15537
+ hasRequiredInteropClient = 1;
15538
+ var __classPrivateFieldSet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
15539
+ if (kind === "m") throw new TypeError("Private method is not writable");
15540
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
15541
+ 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");
15542
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15543
+ };
15544
+ var __classPrivateFieldGet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
15545
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
15546
+ 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");
15547
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15548
+ };
15549
+ var _InteropClient_clientPromise, _InteropClient_sessionContextGroups;
15550
+ Object.defineProperty(InteropClient, "__esModule", { value: true });
15551
+ InteropClient.InteropClient = void 0;
15552
+ const base_1 = base$1;
15553
+ const SessionContextGroupClient_1 = SessionContextGroupClient$1;
15554
+ const fdc3_1_2_1 = requireFdc31_2();
15555
+ const fdc3_2_0_1 = requireFdc32_0();
15556
+ const utils_1 = utils$3;
15557
+ /**
15558
+ * The Interop Client API is broken up into two groups:
15559
+ *
15560
+ * **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.
15561
+ *
15562
+ * **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.
15563
+ *
15564
+ * ---
15565
+ *
15566
+ * All APIs are available at the `fin.me.interop` namespace.
15567
+ *
15568
+ * ---
15569
+ *
15570
+ * **You only need 2 things to participate in Interop Context Grouping:**
15571
+ * * A Context Handler for incoming context: {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
15572
+ * * Call setContext on your context group when you want to share context with other group members: {@link InteropClient#setContext setContext(context)}
15573
+ *
15574
+ * ---
15575
+ *
15576
+ * ##### Constructor
15577
+ * Returned by {@link Interop.connectSync Interop.connectSync}.
15578
+ *
15579
+ * ---
15580
+ *
15581
+ * ##### Interop methods intended for Views
15582
+ *
15583
+ *
15584
+ * **Context Groups API**
15585
+ * * {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
15586
+ * * {@link InteropClient#setContext setContext(context)}
15587
+ * * {@link InteropClient#getCurrentContext getCurrentContext(contextType?)}
15588
+ * * {@link InteropClient#joinSessionContextGroup joinSessionContextGroup(sessionContextGroupId)}
15589
+ *
15590
+ *
15591
+ * **Intents API**
15592
+ * * {@link InteropClient#fireIntent fireIntent(intent)}
15593
+ * * {@link InteropClient#registerIntentHandler registerIntentHandler(intentHandler, intentName)}
15594
+ * * {@link InteropClient#getInfoForIntent getInfoForIntent(infoForIntentOptions)}
15595
+ * * {@link InteropClient#getInfoForIntentsByContext getInfoForIntentsByContext(context)}
15596
+ * * {@link InteropClient#fireIntentForContext fireIntentForContext(contextForIntent)}
15597
+ *
15598
+ * ##### Interop methods intended for Windows
15599
+ * * {@link InteropClient#getContextGroups getContextGroups()}
15600
+ * * {@link InteropClient#joinContextGroup joinContextGroup(contextGroupId, target?)}
15601
+ * * {@link InteropClient#removeFromContextGroup removeFromContextGroup(target?)}
15602
+ * * {@link InteropClient#getInfoForContextGroup getInfoForContextGroup(contextGroupId)}
15603
+ * * {@link InteropClient#getAllClientsInContextGroup getAllClientsInContextGroup(contextGroupId)}
15604
+ *
15605
+ */
15606
+ let InteropClient$1 = class InteropClient extends base_1.Base {
15607
+ /**
15608
+ * @internal
15609
+ */
15610
+ constructor(wire, clientPromise) {
15611
+ super(wire);
15612
+ _InteropClient_clientPromise.set(this, void 0);
15613
+ _InteropClient_sessionContextGroups.set(this, void 0);
15614
+ __classPrivateFieldSet(this, _InteropClient_sessionContextGroups, new Map(), "f");
15615
+ __classPrivateFieldSet(this, _InteropClient_clientPromise, clientPromise, "f");
15616
+ }
15617
+ /*
15618
+ Client APIs
15619
+ */
15620
+ /**
15621
+ * Sets a context for the context group of the current entity.
15622
+ *
15623
+ * @remarks The entity must be part of a context group in order set a context.
15624
+ *
15625
+ * @param context - New context to set.
15626
+ *
15627
+ * @example
15628
+ * ```js
15629
+ * setInstrumentContext = async (ticker) => {
15630
+ * fin.me.interop.setContext({type: 'instrument', id: {ticker}})
15631
+ * }
15632
+ *
15633
+ * // 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
15634
+ * instrumentElement.on('click', (evt) => {
15635
+ * setInstrumentContext(evt.ticker)
15636
+ * })
15637
+ * ```
15638
+ */
15639
+ async setContext(context) {
15640
+ this.wire.sendAction('interop-client-set-context').catch((e) => {
15641
+ // don't expose, analytics-only call
15642
+ });
15643
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
15644
+ return client.dispatch('setContext', { context });
15645
+ }
15646
+ /**
15647
+ * Add a context handler for incoming context. If an entity is part of a context group, and then sets its context handler,
15648
+ * it will receive all of its declared contexts.
15649
+ *
15650
+ * @param handler - Handler for incoming context.
15651
+ * @param contextType - The type of context you wish to handle.
15652
+ *
15653
+ * @example
15654
+ * ```js
15655
+ * function handleIncomingContext(contextInfo) {
15656
+ * const { type, id } = contextInfo;
15657
+ * switch (type) {
15658
+ * case 'instrument':
15659
+ * handleInstrumentContext(contextInfo);
15660
+ * break;
15661
+ * case 'country':
15662
+ * handleCountryContext(contextInfo);
15663
+ * break;
15664
+ *
15665
+ * default:
15666
+ * break;
15667
+ * }
15668
+ * }
15669
+ *
15670
+ *
15671
+ * function handleInstrumentContext(contextInfo) {
15672
+ * const { type, id } = contextInfo;
15673
+ * console.log('contextInfo for instrument', contextInfo)
15674
+ * }
15675
+ *
15676
+ * function handleCountryContext(contextInfo) {
15677
+ * const { type, id } = contextInfo;
15678
+ * console.log('contextInfo for country', contextInfo)
15679
+ * }
15680
+ *
15681
+ * fin.me.interop.addContextHandler(handleIncomingContext);
15682
+ * ```
15683
+ *
15684
+ *
15685
+ * Passing in a context type as the second parameter will cause the handler to only be invoked with that context type.
15686
+ *
15687
+ * ```js
15688
+ * function handleInstrumentContext(contextInfo) {
15689
+ * const { type, id } = contextInfo;
15690
+ * console.log('contextInfo for instrument', contextInfo)
15691
+ * }
15692
+ *
15693
+ * function handleCountryContext(contextInfo) {
15694
+ * const { type, id } = contextInfo;
15695
+ * console.log('contextInfo for country', contextInfo)
15696
+ * }
15697
+ *
15698
+ *
15699
+ * fin.me.interop.addContextHandler(handleInstrumentContext, 'instrument')
15700
+ * fin.me.interop.addContextHandler(handleCountryContext, 'country')
15701
+ * ```
15702
+ */
15703
+ async addContextHandler(handler, contextType) {
15704
+ this.wire.sendAction('interop-client-add-context-handler').catch((e) => {
15705
+ // don't expose, analytics-only call
15706
+ });
15707
+ if (typeof handler !== 'function') {
15708
+ throw new Error("Non-function argument passed to the first parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
15709
+ }
15710
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
15711
+ let handlerId;
15712
+ if (contextType) {
15713
+ handlerId = `invokeContextHandler-${contextType}-${(0, utils_1.generateId)()}`;
15714
+ }
15715
+ else {
15716
+ handlerId = 'invokeContextHandler';
15717
+ }
15718
+ const wrappedHandler = (0, utils_1.wrapContextHandler)(handler, handlerId);
15719
+ client.register(handlerId, wrappedHandler);
15720
+ await client.dispatch('contextHandlerRegistered', { handlerId, contextType });
15721
+ return {
15722
+ unsubscribe: async () => {
15723
+ client.remove(handlerId);
15724
+ await client.dispatch('removeContextHandler', { handlerId });
15725
+ }
15726
+ };
15727
+ }
15728
+ /*
15729
+ Platform Window APIs
15730
+ */
15731
+ /**
15732
+ * Returns the Interop-Broker-defined context groups available for an entity to join.
15733
+ * Used by Platform Windows.
15734
+ *
15735
+ * @example
15736
+ * ```js
15737
+ * fin.me.interop.getContextGroups()
15738
+ * .then(contextGroups => {
15739
+ * contextGroups.forEach(contextGroup => {
15740
+ * console.log(contextGroup.displayMetadata.name)
15741
+ * console.log(contextGroup.displayMetadata.color)
15742
+ * })
15743
+ * })
15744
+ * ```
15745
+ */
15746
+ async getContextGroups() {
15747
+ this.wire.sendAction('interop-client-get-context-groups').catch((e) => {
15748
+ // don't expose, analytics-only call
15749
+ });
15750
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
15751
+ return client.dispatch('getContextGroups');
15752
+ }
15753
+ /**
15754
+ * Join all Interop Clients at the given identity to context group `contextGroupId`.
15755
+ * If no target is specified, it adds the sender to the context group.
15756
+ *
15757
+ * @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.
15758
+ * 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.
15759
+ * 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.
15760
+ * Used by Platform Windows.
15761
+ *
15762
+ * @param contextGroupId - Id of the context group.
15763
+ * @param target - Identity of the entity you wish to join to a context group.
15764
+ *
15765
+ * @example
15766
+ * ```js
15767
+ * joinViewToContextGroup = async (contextGroupId, view) => {
15768
+ * await fin.me.interop.joinContextGroup(contextGroupId, view);
15769
+ * }
15770
+ *
15771
+ * getLastFocusedView()
15772
+ * .then(lastFocusedViewIdentity => {
15773
+ * joinViewToContextGroup('red', lastFocusedViewIdentity)
15774
+ * })
15775
+ * ```
15776
+ */
15777
+ async joinContextGroup(contextGroupId, target) {
15778
+ this.wire.sendAction('interop-client-join-context-group').catch((e) => {
15779
+ // don't expose, analytics-only call
15780
+ });
15781
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
15782
+ if (!contextGroupId) {
15783
+ throw new Error('No contextGroupId specified for joinContextGroup.');
15784
+ }
15785
+ return client.dispatch('joinContextGroup', { contextGroupId, target });
15786
+ }
15787
+ /**
15788
+ * Removes the specified target from a context group.
15789
+ * If no target is specified, it removes the sender from their context group.
15790
+ * Used by Platform Windows.
15791
+ *
15792
+ * @param target - Identity of the entity you wish to join to a context group.
15793
+ *
15794
+ * @example
15795
+ * ```js
15796
+ * removeViewFromContextGroup = async (view) => {
15797
+ * await fin.me.interop.removeFromContextGroup(view);
15798
+ * }
15799
+ *
15800
+ * getLastFocusedView()
15801
+ * .then(lastFocusedViewIdentity => {
15802
+ * removeViewFromContextGroup(lastFocusedViewIdentity)
15803
+ * })
15804
+ * ```
15805
+ */
15806
+ async removeFromContextGroup(target) {
15807
+ this.wire.sendAction('interop-client-remove-from-context-group').catch((e) => {
15808
+ // don't expose, analytics-only call
15809
+ });
15810
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
15811
+ return client.dispatch('removeFromContextGroup', { target });
15812
+ }
15813
+ /**
15814
+ * Gets all clients for a context group.
15815
+ *
15816
+ * @remarks **This is primarily used for platform windows. Views within a platform should not have to use this API.**
15817
+ *
15818
+ * Returns the Interop-Broker-defined context groups available for an entity to join.
15819
+ * @param contextGroupId - The id of context group you wish to get clients for.
15820
+ *
15821
+ * @example
15822
+ * ```js
15823
+ * fin.me.interop.getAllClientsInContextGroup('red')
15824
+ * .then(clientsInContextGroup => {
15825
+ * console.log(clientsInContextGroup)
15826
+ * })
15827
+ * ```
15828
+ */
15829
+ async getAllClientsInContextGroup(contextGroupId) {
15830
+ this.wire.sendAction('interop-client-get-all-clients-in-context-group').catch((e) => {
15831
+ // don't expose, analytics-only call
15832
+ });
15833
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
15834
+ if (!contextGroupId) {
15835
+ throw new Error('No contextGroupId specified for getAllClientsInContextGroup.');
15836
+ }
15837
+ return client.dispatch('getAllClientsInContextGroup', { contextGroupId });
15838
+ }
15839
+ /**
15840
+ * Gets display info for a context group
15841
+ *
15842
+ * @remarks Used by Platform Windows.
15843
+ * @param contextGroupId - The id of context group you wish to get display info for.
15844
+ *
15845
+ * @example
15846
+ * ```js
15847
+ * fin.me.interop.getInfoForContextGroup('red')
15848
+ * .then(contextGroupInfo => {
15849
+ * console.log(contextGroupInfo.displayMetadata.name)
15850
+ * console.log(contextGroupInfo.displayMetadata.color)
15851
+ * })
15852
+ * ```
15853
+ */
15854
+ async getInfoForContextGroup(contextGroupId) {
15855
+ this.wire.sendAction('interop-client-get-info-for-context-group').catch((e) => {
15856
+ // don't expose, analytics-only call
15857
+ });
15858
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
15859
+ if (!contextGroupId) {
15860
+ throw new Error('No contextGroupId specified for getInfoForContextGroup.');
15861
+ }
15862
+ return client.dispatch('getInfoForContextGroup', { contextGroupId });
15863
+ }
15864
+ /**
15865
+ * Sends an intent to the Interop Broker to resolve.
15866
+ * @param intent - The combination of an action and a context that is passed to an application for resolution.
15867
+ *
15868
+ * @example
15869
+ * ```js
15870
+ * // View wants to fire an Intent after a user clicks on a ticker
15871
+ * tickerElement.on('click', (element) => {
15872
+ * const ticker = element.innerText;
15873
+ * const intent = {
15874
+ * name: 'ViewChart',
15875
+ * context: {type: 'fdc3.instrument', id: { ticker }}
15876
+ * }
15877
+ *
15878
+ * fin.me.interop.fireIntent(intent);
15879
+ * })
15880
+ * ```
15881
+ */
15882
+ async fireIntent(intent) {
15883
+ this.wire.sendAction('interop-client-fire-intent').catch((e) => {
15884
+ // don't expose, this is only for api analytics purposes
15885
+ });
15886
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
15887
+ return client.dispatch('fireIntent', intent);
15888
+ }
15889
+ /**
15890
+ * Adds an intent handler for incoming intents. The last intent sent of the name subscribed to will be received.
15891
+ * @param handler - Registered function meant to handle a specific intent type.
15892
+ * @param intentName - The name of an intent.
15893
+ *
15894
+ * @example
15895
+ * ```js
15896
+ * const intentHandler = (intent) => {
15897
+ * const { context } = intent;
15898
+ * myViewChartHandler(context);
15899
+ * };
15900
+ *
15901
+ * const subscription = await fin.me.interop.registerIntentHandler(intentHandler, 'ViewChart');
15902
+ *
15903
+ * function myAppCloseSequence() {
15904
+ * // to unsubscribe the handler, simply call:
15905
+ * subscription.unsubscribe();
15906
+ * }
15907
+ * ```
15908
+ */
15909
+ async registerIntentHandler(handler, intentName, options) {
15910
+ this.wire.sendAction('interop-client-register-intent-handler').catch((e) => {
15911
+ // don't expose, this is only for api analytics purposes
15912
+ });
15913
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
15914
+ const handlerId = `intent-handler-${intentName}`;
15915
+ const wrappedHandler = (0, utils_1.wrapIntentHandler)(handler, handlerId);
15916
+ try {
15917
+ await client.register(handlerId, wrappedHandler);
15918
+ await client.dispatch('intentHandlerRegistered', { handlerId, ...options });
15919
+ }
15920
+ catch (error) {
15921
+ throw new Error('Unable to register intent handler');
15922
+ }
15923
+ return {
15924
+ unsubscribe: async () => {
15925
+ client.remove(handlerId);
15926
+ }
15927
+ };
15928
+ }
15929
+ /**
15930
+ * Gets the last context of the Context Group currently subscribed to. It takes an optional Context Type and returns the
15931
+ * last context of that type.
15932
+ * @param contextType
15933
+ *
15934
+ * @example
15935
+ * ```js
15936
+ * await fin.me.interop.joinContextGroup('yellow');
15937
+ * await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
15938
+ * const currentContext = await fin.me.interop.getCurrentContext();
15939
+ *
15940
+ * // with a specific context
15941
+ * await fin.me.interop.joinContextGroup('yellow');
15942
+ * await fin.me.interop.setContext({ type: 'country', id: { ISOALPHA3: 'US' }});
15943
+ * await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
15944
+ * const currentContext = await fin.me.interop.getCurrentContext('country');
15945
+ * ```
15946
+ */
15947
+ async getCurrentContext(contextType) {
15948
+ this.wire.sendAction('interop-client-get-current-context').catch((e) => {
15949
+ // don't expose, analytics-only call
15950
+ });
15951
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
15952
+ return client.dispatch('getCurrentContext', { contextType });
15953
+ }
15954
+ /**
15955
+ * Get information for a particular Intent from the Interop Broker.
15956
+ *
15957
+ * @remarks To resolve this info, the function handleInfoForIntent is meant to be overridden in the Interop Broker.
15958
+ * The format for the response will be determined by the App Provider overriding the function.
15959
+ *
15960
+ * @param options
15961
+ *
15962
+ * @example
15963
+ * ```js
15964
+ * const intentInfo = await fin.me.interop.getInfoForIntent('ViewChart');
15965
+ * ```
15966
+ */
15967
+ async getInfoForIntent(options) {
15968
+ this.wire.sendAction('interop-client-get-info-for-intent').catch((e) => {
15969
+ // don't expose, analytics-only call
15970
+ });
15971
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
15972
+ return client.dispatch('getInfoForIntent', options);
15973
+ }
15974
+ /**
15975
+ * Get information from the Interop Broker on all Intents that are meant to handle a particular context.
15976
+ *
15977
+ * @remarks To resolve this info, the function handleInfoForIntentsByContext is meant to be overridden in the Interop Broker.
15978
+ * The format for the response will be determined by the App Provider overriding the function.
15979
+ *
15980
+ * @param context
15981
+ *
15982
+ * @example
15983
+ * ```js
15984
+ * tickerElement.on('click', (element) => {
15985
+ * const ticker = element.innerText;
15986
+ *
15987
+ * const context = {
15988
+ * type: 'fdc3.instrument',
15989
+ * id: {
15990
+ * ticker
15991
+ * }
15992
+ * }
15993
+ *
15994
+ * const intentsInfo = await fin.me.interop.getInfoForIntentByContext(context);
15995
+ * })
15996
+ * ```
15997
+ */
15998
+ async getInfoForIntentsByContext(context) {
15999
+ this.wire.sendAction('interop-client-get-info-for-intents-by-context').catch((e) => {
16000
+ // don't expose, analytics-only call
16001
+ });
16002
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
16003
+ return client.dispatch('getInfoForIntentsByContext', context);
16004
+ }
16005
+ /**
16006
+ * Sends a Context that will be resolved to an Intent by the Interop Broker.
16007
+ * This context accepts a metadata property.
16008
+ *
16009
+ * @remarks To resolve this info, the function handleFiredIntentByContext is meant to be overridden in the Interop Broker.
16010
+ * The format for the response will be determined by the App Provider overriding the function.
16011
+ *
16012
+ * @param context
16013
+ *
16014
+ * @example
16015
+ * ```js
16016
+ * tickerElement.on('click', (element) => {
16017
+ * const ticker = element.innerText;
16018
+ *
16019
+ * const context = {
16020
+ * type: 'fdc3.instrument',
16021
+ * id: {
16022
+ * ticker
16023
+ * }
16024
+ * }
16025
+ *
16026
+ * const intentResolution = await fin.me.interop.fireIntentForContext(context);
16027
+ * })
16028
+ * ```
16029
+ */
16030
+ async fireIntentForContext(context) {
16031
+ this.wire.sendAction('interop-client-fire-intent-for-context').catch((e) => {
16032
+ // don't expose, analytics-only call
16033
+ });
16034
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
16035
+ return client.dispatch('fireIntentForContext', context);
16036
+ }
16037
+ /**
16038
+ * Join the current entity to session context group `sessionContextGroupId` and return a sessionContextGroup instance.
16039
+ * If the sessionContextGroup doesn't exist, one will get created.
16040
+ *
16041
+ * @remarks Session Context Groups do not persist between runs and aren't present on snapshots.
16042
+ * @param sessionContextGroupId - Id of the context group.
16043
+ *
16044
+ * @example
16045
+ * Say we want to have a Session Context Group that holds UI theme information for all apps to consume:
16046
+ *
16047
+ * My color-picker View:
16048
+ * ```js
16049
+ * const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');
16050
+ *
16051
+ * const myColorPickerElement = document.getElementById('color-palette-picker');
16052
+ * myColorPickerElement.addEventListener('change', event => {
16053
+ * themeSessionContextGroup.setContext({ type: 'color-palette', selection: event.value });
16054
+ * });
16055
+ * ```
16056
+ *
16057
+ * In other views:
16058
+ * ```js
16059
+ * const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');
16060
+ *
16061
+ * const changeColorPalette = ({ selection }) => {
16062
+ * // change the color palette to the selection
16063
+ * };
16064
+ *
16065
+ * // If the context is already set by the time the handler was set, the handler will get invoked immediately with the current context.
16066
+ * themeSessionContextGroup.addContextHandler(changeColorPalette, 'color-palette');
16067
+ * ```
16068
+ */
16069
+ async joinSessionContextGroup(sessionContextGroupId) {
16070
+ try {
16071
+ const currentSessionContextGroup = __classPrivateFieldGet(this, _InteropClient_sessionContextGroups, "f").get(sessionContextGroupId);
16072
+ if (currentSessionContextGroup) {
16073
+ return currentSessionContextGroup.getUserInstance();
16074
+ }
16075
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
16076
+ const { hasConflict } = await client.dispatch('sessionContextGroup:createIfNeeded', {
16077
+ sessionContextGroupId
16078
+ });
16079
+ if (hasConflict) {
16080
+ 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.`);
16081
+ }
16082
+ const newSessionContextGroup = new SessionContextGroupClient_1.default(this.wire, __classPrivateFieldGet(this, _InteropClient_clientPromise, "f"), sessionContextGroupId);
16083
+ __classPrivateFieldGet(this, _InteropClient_sessionContextGroups, "f").set(sessionContextGroupId, newSessionContextGroup);
16084
+ return newSessionContextGroup.getUserInstance();
16085
+ }
16086
+ catch (error) {
16087
+ console.error(`Error thrown trying to create Session Context Group with id "${sessionContextGroupId}": ${error}`);
16088
+ throw error;
16089
+ }
16090
+ }
16091
+ /**
16092
+ * Register a listener that is called when the Interop Client has been disconnected from the Interop Broker.
16093
+ * Only one listener per Interop Client can be set.
16094
+ * @param listener
16095
+ *
16096
+ * @example
16097
+ * ```js
16098
+ * const listener = (event) => {
16099
+ * const { type, topic, brokerName} = event;
16100
+ * console.log(`Disconnected from Interop Broker ${brokerName} `);
16101
+ * }
16102
+ *
16103
+ * await fin.me.interop.onDisconnection(listener);
16104
+ * ```
16105
+ */
16106
+ async onDisconnection(listener) {
16107
+ this.wire.sendAction('interop-client-add-ondisconnection-listener').catch((e) => {
16108
+ // don't expose, analytics-only call
16109
+ });
16110
+ const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
16111
+ return client.onDisconnection((event) => {
16112
+ const { uuid } = event;
16113
+ listener({ type: 'interop-broker', topic: 'disconnected', brokerName: uuid });
16114
+ });
16115
+ }
16116
+ getFDC3Sync(version) {
16117
+ switch (version) {
16118
+ case '1.2':
16119
+ return new fdc3_1_2_1.Fdc3Module(() => this, this.wire);
16120
+ case '2.0':
16121
+ return new fdc3_2_0_1.Fdc3Module2(() => this, this.wire);
16122
+ default:
16123
+ throw new Error(`Invalid FDC3 version provided: ${version}. Must be '1.2' or '2.0'`);
16124
+ }
16125
+ }
16126
+ async getFDC3(version) {
16127
+ return this.getFDC3Sync(version);
16128
+ }
16129
+ /**
16130
+ * @internal
16131
+ *
16132
+ * Used to ferry fdc3-only calls from the fdc3 shim to the Interop Broker
16133
+ */
16134
+ static async ferryFdc3Call(interopClient, action, payload) {
16135
+ const client = await __classPrivateFieldGet(interopClient, _InteropClient_clientPromise, "f");
16136
+ return client.dispatch(action, payload || null);
16137
+ }
16138
+ };
16139
+ InteropClient.InteropClient = InteropClient$1;
16140
+ _InteropClient_clientPromise = new WeakMap(), _InteropClient_sessionContextGroups = new WeakMap();
16141
+ return InteropClient;
16142
+ }
14954
16143
 
14955
16144
  var overrideCheck = {};
14956
16145
 
@@ -15007,7 +16196,7 @@ function requireFactory () {
15007
16196
  const inaccessibleObject_1 = inaccessibleObject;
15008
16197
  const base_1 = base$1;
15009
16198
  const InteropBroker_1 = requireInteropBroker();
15010
- const InteropClient_1 = InteropClient$1;
16199
+ const InteropClient_1 = requireInteropClient();
15011
16200
  const overrideCheck_1 = requireOverrideCheck();
15012
16201
  const common_utils_1 = commonUtils;
15013
16202
  const defaultOverride = (Class) => new Class();
@@ -15041,12 +16230,8 @@ function requireFactory () {
15041
16230
  const options = await this.wire.environment.getInteropInfo(this.wire.getFin());
15042
16231
  const objectThatThrows = (0, inaccessibleObject_1.createUnusableObject)(BrokerParamAccessError);
15043
16232
  const warningOptsClone = (0, inaccessibleObject_1.createWarningObject)(BrokerParamAccessError, (0, lodash_1.cloneDeep)(options));
15044
- let provider;
15045
16233
  const getProvider = () => {
15046
- if (!provider) {
15047
- provider = this.fin.InterApplicationBus.Channel.create(`interop-broker-${name}`);
15048
- }
15049
- return provider;
16234
+ return this.fin.InterApplicationBus.Channel.create(`interop-broker-${name}`);
15050
16235
  };
15051
16236
  const throwingGetProvider = async () => {
15052
16237
  // eslint-disable-next-line no-console
@@ -15092,7 +16277,11 @@ function requireFactory () {
15092
16277
  this.wire.sendAction('interop-connect-sync').catch(() => {
15093
16278
  // don't expose, analytics-only call
15094
16279
  });
15095
- return new InteropClient_1.InteropClient(this.wire, name, interopConfig);
16280
+ return new InteropClient_1.InteropClient(this.wire, this.wire.environment.whenReady().then(() => {
16281
+ return this.fin.InterApplicationBus.Channel.connect(`interop-broker-${name}`, {
16282
+ payload: interopConfig
16283
+ });
16284
+ }));
15096
16285
  }
15097
16286
  }
15098
16287
  Factory$1.InteropModule = InteropModule;
@@ -15129,7 +16318,7 @@ function requireInterop () {
15129
16318
  };
15130
16319
  Object.defineProperty(exports, "__esModule", { value: true });
15131
16320
  __exportStar(requireFactory(), exports);
15132
- __exportStar(InteropClient$1, exports);
16321
+ __exportStar(requireInteropClient(), exports);
15133
16322
  __exportStar(requireInteropBroker(), exports);
15134
16323
  } (interop));
15135
16324
  return interop;
@@ -15522,7 +16711,7 @@ var portDiscovery = {};
15522
16711
 
15523
16712
  var launcher = {};
15524
16713
 
15525
- var winLaunch = {};
16714
+ var nixLaunch = {};
15526
16715
 
15527
16716
  var util = {};
15528
16717
 
@@ -15635,7 +16824,7 @@ var http = {};
15635
16824
 
15636
16825
  Object.defineProperty(util, "__esModule", { value: true });
15637
16826
  util.resolveDir = util.first = util.resolveRuntimeVersion = util.rmDir = util.unzip = util.exists = void 0;
15638
- const path$1 = require$$0$3;
16827
+ const path$1 = require$$1;
15639
16828
  const fs$1 = require$$0$2;
15640
16829
  const child_process_1$1 = require$$2;
15641
16830
  const promises_1$1 = promises;
@@ -15737,54 +16926,6 @@ async function resolveDir(base, paths) {
15737
16926
  }
15738
16927
  util.resolveDir = resolveDir;
15739
16928
 
15740
- Object.defineProperty(winLaunch, "__esModule", { value: true });
15741
- const path = require$$0$3;
15742
- const child_process_1 = require$$2;
15743
- const util_1 = util;
15744
- function launchRVM(config, manifestLocation, namedPipeName, rvm) {
15745
- const runtimeArgs = `--runtime-arguments=--runtime-information-channel-v6=${namedPipeName}`;
15746
- const rvmArgs = [];
15747
- if (config.installerUI !== true) {
15748
- rvmArgs.push('--no-ui');
15749
- }
15750
- rvmArgs.push(`--config=${manifestLocation}`);
15751
- rvmArgs.push(runtimeArgs);
15752
- if (config.runtime.rvmDir) {
15753
- rvmArgs.push(`--working-dir=${config.runtime.rvmDir}`);
15754
- }
15755
- if (config.assetsUrl) {
15756
- rvmArgs.push(`--assetsUrl=${config.assetsUrl}`);
15757
- }
15758
- return (0, child_process_1.spawn)(rvm, rvmArgs, { stdio: ['pipe', 'ignore', 'pipe'], detached: true });
15759
- }
15760
- async function checkRvmPath() {
15761
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15762
- let rvmPath = path.resolve(process.env.LOCALAPPDATA, 'OpenFin', 'OpenFinRVM.exe');
15763
- if (!(await (0, util_1.exists)(rvmPath))) {
15764
- rvmPath = path.join(__dirname, '..', 'resources', 'win', 'OpenFinRVM.exe');
15765
- }
15766
- return rvmPath;
15767
- }
15768
- const checkRVM = makeQueued(checkRvmPath);
15769
- async function launch(config, manifestLocation, namedPipeName) {
15770
- const rvmPath = await checkRVM();
15771
- return launchRVM(config, manifestLocation, namedPipeName, rvmPath);
15772
- }
15773
- winLaunch.default = launch;
15774
- function makeQueued(func) {
15775
- let initial;
15776
- return async function (...args) {
15777
- const x = initial || Promise.resolve();
15778
- initial = x
15779
- .then(() => new Promise((resolve, reject) => setImmediate(() => resolve())))
15780
- .then(() => func(...args))
15781
- .catch(() => func(...args));
15782
- return initial;
15783
- };
15784
- }
15785
-
15786
- var nixLaunch = {};
15787
-
15788
16929
  var services = {};
15789
16930
 
15790
16931
  var hasRequiredServices;
@@ -15834,9 +16975,9 @@ function requireNixLaunch () {
15834
16975
  if (hasRequiredNixLaunch) return nixLaunch;
15835
16976
  hasRequiredNixLaunch = 1;
15836
16977
  Object.defineProperty(nixLaunch, "__esModule", { value: true });
15837
- nixLaunch.install = nixLaunch.getRuntimePath = nixLaunch.download = nixLaunch.getUrl = void 0;
16978
+ nixLaunch.launch = nixLaunch.install = nixLaunch.getRuntimePath = nixLaunch.download = nixLaunch.getUrl = void 0;
15838
16979
  const fs = require$$0$2;
15839
- const path = require$$0$3;
16980
+ const path = require$$1;
15840
16981
  const child_process_1 = require$$2;
15841
16982
  const promises_1 = promises;
15842
16983
  const util_1 = util;
@@ -15934,85 +17075,161 @@ function requireNixLaunch () {
15934
17075
  throw e;
15935
17076
  }
15936
17077
  }
15937
- nixLaunch.default = launch;
17078
+ nixLaunch.launch = launch;
15938
17079
  return nixLaunch;
15939
17080
  }
15940
17081
 
17082
+ var rvmLaunch = {};
17083
+
17084
+ Object.defineProperty(rvmLaunch, "__esModule", { value: true });
17085
+ rvmLaunch.launch = void 0;
17086
+ const child_process_1 = require$$2;
17087
+ const os = require$$1$1;
17088
+ const path = require$$1;
17089
+ const util_1 = util;
17090
+ const getRvmPath = () => {
17091
+ switch (process.platform) {
17092
+ case 'darwin':
17093
+ return path.resolve(os.homedir(), 'Applications', 'OpenFinRVM.app', 'Contents', 'MacOS', 'OpenFinRVM');
17094
+ case 'win32':
17095
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17096
+ return path.resolve(process.env.LOCALAPPDATA, 'OpenFin', 'OpenFinRVM.exe');
17097
+ default:
17098
+ throw new Error(`Unsupported platform: ${process.platform}`);
17099
+ }
17100
+ };
17101
+ const getRvmLocalPath = () => {
17102
+ switch (process.platform) {
17103
+ case 'darwin':
17104
+ return path.resolve(__dirname, '..', 'resources', 'darwin', 'OpenFinRVM.app', 'Contents', 'MacOS', 'OpenFinRVM');
17105
+ case 'win32':
17106
+ return path.resolve(__dirname, '..', 'resources', 'win', 'OpenFinRVM.exe');
17107
+ default:
17108
+ throw new Error(`Unsupported platform: ${process.platform}`);
17109
+ }
17110
+ };
17111
+ function launchRVM(config, manifestLocation, namedPipeName, rvm) {
17112
+ const runtimeArgs = `--runtime-arguments=--runtime-information-channel-v6=${namedPipeName}`;
17113
+ const rvmArgs = [];
17114
+ if (config.installerUI !== true) {
17115
+ rvmArgs.push('--no-ui');
17116
+ }
17117
+ rvmArgs.push(`--config=${manifestLocation}`);
17118
+ rvmArgs.push(runtimeArgs);
17119
+ if (config.runtime.rvmDir) {
17120
+ rvmArgs.push(`--working-dir=${config.runtime.rvmDir}`);
17121
+ }
17122
+ if (config.assetsUrl) {
17123
+ rvmArgs.push(`--assetsUrl=${config.assetsUrl}`);
17124
+ }
17125
+ return (0, child_process_1.spawn)(rvm, rvmArgs, { stdio: ['pipe', 'ignore', 'pipe'], detached: true });
17126
+ }
17127
+ async function checkRvmPath() {
17128
+ const rvmPath = getRvmPath();
17129
+ if (!(await (0, util_1.exists)(rvmPath))) {
17130
+ // TODO: update win RVM exe to v13
17131
+ const newRvmPath = getRvmLocalPath();
17132
+ console.log(`[OpenFin Launcher] RVM not found at ${rvmPath}, spwaning locally pacakged RVM at ${newRvmPath}`);
17133
+ return newRvmPath;
17134
+ }
17135
+ return rvmPath;
17136
+ }
17137
+ const checkRVM = makeQueued(checkRvmPath);
17138
+ async function launch(config, manifestLocation, namedPipeName) {
17139
+ const rvmPath = await checkRVM();
17140
+ return launchRVM(config, manifestLocation, namedPipeName, rvmPath);
17141
+ }
17142
+ rvmLaunch.launch = launch;
17143
+ function makeQueued(func) {
17144
+ let initial;
17145
+ return async function (...args) {
17146
+ const x = initial || Promise.resolve();
17147
+ initial = x
17148
+ .then(() => new Promise((resolve, reject) => setImmediate(() => resolve())))
17149
+ .then(() => func(...args))
17150
+ .catch(() => func(...args));
17151
+ return initial;
17152
+ };
17153
+ }
17154
+
15941
17155
  var hasRequiredLauncher;
15942
17156
 
15943
17157
  function requireLauncher () {
15944
17158
  if (hasRequiredLauncher) return launcher;
15945
17159
  hasRequiredLauncher = 1;
15946
17160
  Object.defineProperty(launcher, "__esModule", { value: true });
15947
- const os = require$$0$4;
15948
- const path = require$$0$3;
15949
- const win_launch_1 = winLaunch;
17161
+ const os = require$$1$1;
17162
+ const path = require$$1;
15950
17163
  const nix_launch_1 = requireNixLaunch();
17164
+ const rvm_launch_1 = rvmLaunch;
15951
17165
  class Launcher {
15952
17166
  constructor() {
15953
- this.OpenFin_Installer = 'OpenFinInstaller.exe';
15954
17167
  this.Installer_Work_Dir = path.join(os.tmpdir(), 'openfinnode');
15955
17168
  this.Security_Realm_Config_Key = '--security-realm=';
15956
- this.os = os.platform();
15957
- if (this.os !== 'win32') {
15958
- if (this.os === 'darwin') {
15959
- this.nixConfig = {
15960
- urlPath: 'mac/x64',
15961
- executablePath: 'OpenFin.app/Contents/MacOS/OpenFin'
15962
- };
15963
- }
15964
- else if (this.os === 'linux') {
15965
- this.nixConfig = {
15966
- urlPath: `linux/${os.arch()}`,
15967
- executablePath: 'openfin'
15968
- };
15969
- }
15970
- else {
15971
- throw new Error(`Launching not supported on ${this.os}`);
15972
- }
17169
+ if (!Launcher.IS_SUPPORTED()) {
17170
+ throw new Error(`Launching not supported on ${os.platform()}`);
15973
17171
  }
15974
17172
  }
15975
- launch(config, manifestLocation, namedPipeName) {
15976
- if (this.os === 'win32') {
15977
- return this.winLaunch(config, manifestLocation, namedPipeName);
15978
- }
15979
- if (this.os === 'darwin') {
15980
- const osConf = {
15981
- manifestLocation,
15982
- namedPipeName,
15983
- ...this.nixConfig
15984
- };
15985
- return this.macLaunch(config, osConf);
17173
+ async launch(config, manifestLocation, namedPipeName) {
17174
+ if (Launcher.RVM_SUPPORTED()) {
17175
+ return (0, rvm_launch_1.launch)(config, manifestLocation, namedPipeName);
15986
17176
  }
15987
- if (this.os === 'linux') {
15988
- const osConf = {
17177
+ if (os.platform() === 'linux') {
17178
+ const osConfig = {
15989
17179
  manifestLocation,
15990
17180
  namedPipeName,
15991
17181
  urlPath: `linux/${os.arch()}`,
15992
- executablePath: 'openfin',
15993
- ...this.nixConfig
17182
+ executablePath: 'openfin'
15994
17183
  };
15995
- return this.macLaunch(config, osConf);
17184
+ return (0, nix_launch_1.launch)(config, osConfig);
15996
17185
  }
15997
- throw new Error(`Launching not supported on ${this.os}`);
17186
+ throw new Error(`Launching not supported on ${os.platform()}`);
15998
17187
  }
15999
17188
  static IS_SUPPORTED() {
16000
17189
  const platform = os.platform();
16001
- return platform === 'win32' || platform === 'darwin' || os.platform() === 'linux';
17190
+ return ['win32', 'darwin', 'linux'].includes(platform);
16002
17191
  }
16003
- // eslint-disable-next-line class-methods-use-this
16004
- macLaunch(config, osConfig) {
16005
- return (0, nix_launch_1.default)(config, osConfig);
16006
- }
16007
- // eslint-disable-next-line class-methods-use-this
16008
- winLaunch(config, manifestLocation, namedPipeName) {
16009
- return (0, win_launch_1.default)(config, manifestLocation, namedPipeName);
17192
+ static RVM_SUPPORTED() {
17193
+ const platform = os.platform();
17194
+ return ['win32', 'darwin'].includes(platform);
16010
17195
  }
16011
17196
  }
16012
17197
  launcher.default = Launcher;
16013
17198
  return launcher;
16014
17199
  }
16015
17200
 
17201
+ var bufferReader = {};
17202
+
17203
+ Object.defineProperty(bufferReader, "__esModule", { value: true });
17204
+ bufferReader.BufferReader = void 0;
17205
+ /**
17206
+ * Really simple buffer reader that reads from a buffer and keeps track of the offset.
17207
+ * Ripped from runtime test helpers: https://gitlab.com/openfin/runtime/runtime/-/commit/d5f8e356911d70f92d78f4f62874f659f36f3667
17208
+ */
17209
+ class BufferReader {
17210
+ constructor(buf) {
17211
+ this.buf = buf;
17212
+ this.buf = buf;
17213
+ this.offset = 0;
17214
+ }
17215
+ readInt16() {
17216
+ const result = this.buf.readInt16LE(this.offset);
17217
+ this.offset += 2;
17218
+ return result;
17219
+ }
17220
+ readInt32() {
17221
+ const result = this.buf.readInt32LE(this.offset);
17222
+ this.offset += 4;
17223
+ return result;
17224
+ }
17225
+ readString(stringLength) {
17226
+ const result = this.buf.subarray(this.offset, this.offset + stringLength).toString();
17227
+ this.offset += stringLength;
17228
+ return result;
17229
+ }
17230
+ }
17231
+ bufferReader.BufferReader = BufferReader;
17232
+
16016
17233
  var hasRequiredPortDiscovery;
16017
17234
 
16018
17235
  function requirePortDiscovery () {
@@ -16021,14 +17238,14 @@ function requirePortDiscovery () {
16021
17238
  Object.defineProperty(portDiscovery, "__esModule", { value: true });
16022
17239
  /* eslint-disable @typescript-eslint/naming-convention */
16023
17240
  const fs = require$$0$2;
16024
- const net = require$$1;
16025
- const path = require$$0$3;
16026
- const os = require$$0$4;
17241
+ const net = require$$1$2;
17242
+ const os = require$$1$1;
17243
+ const path = require$$1;
16027
17244
  const timers_1 = require$$4;
16028
- const wire_1 = wire;
16029
17245
  const launcher_1 = requireLauncher();
17246
+ const buffer_reader_1 = bufferReader;
17247
+ const wire_1 = wire;
16030
17248
  const launcher = new launcher_1.default();
16031
- const MessageHeaderSize = 20; // sizeof(ChromiumMessageHeader)
16032
17249
  // value for message_type
16033
17250
  var ChromiumMessageType;
16034
17251
  (function (ChromiumMessageType) {
@@ -16083,78 +17300,59 @@ function requirePortDiscovery () {
16083
17300
  return manifest;
16084
17301
  }
16085
17302
  function onRuntimeHello(data, conn) {
16086
- const header = readHeader(data);
17303
+ const reader = new buffer_reader_1.BufferReader(data);
17304
+ const header = readHeader(reader);
16087
17305
  if (header.message_type === ChromiumMessageType.RUNTIME_HELLO_MESSAGE) {
16088
- let helloPayload = readUint32(data, MessageHeaderSize);
16089
- if (helloPayload === 0) {
16090
- // need to read again on unix
16091
- header.extraInteger = true;
16092
- helloPayload = readUint32(data, MessageHeaderSize + 4);
16093
- }
16094
- writeHelloMessage(header, conn);
17306
+ conn.write(data);
16095
17307
  }
16096
17308
  else {
16097
- console.error(`Invalid port discovery hello message type ${header.message_type}`);
17309
+ console.error(`[port-discovery] Invalid port discovery hello message type ${header.message_type}`);
16098
17310
  }
16099
17311
  }
16100
17312
  function onDiscoverMessage(data) {
16101
- const header = readHeader(data);
17313
+ const reader = new buffer_reader_1.BufferReader(data);
17314
+ const header = readHeader(reader);
16102
17315
  if (header.message_type === ChromiumMessageType.RUNTIME_STRING_MESSAGE) {
16103
- const strLength = readUint32(data, MessageHeaderSize); // length of following discovery string
16104
- // BAD CODE
16105
- let msg;
16106
- if (os.platform() !== 'win32') {
16107
- const raw = data.toString('utf8');
16108
- const firstBrace = raw.indexOf('{');
16109
- const lastBrace = raw.lastIndexOf('}');
16110
- msg = raw.slice(firstBrace, lastBrace + 1);
16111
- }
16112
- else {
16113
- // //////Bad code end
16114
- msg = data.toString('utf8', MessageHeaderSize + 4, MessageHeaderSize + 4 + strLength);
17316
+ const messageLength = reader.readInt32();
17317
+ const msg = reader.readString(messageLength);
17318
+ try {
17319
+ const env = JSON.parse(msg);
17320
+ if (env?.payload) {
17321
+ return env.payload;
17322
+ }
17323
+ console.warn(`[port-discovery] Discovery message did not have payload`, {
17324
+ header,
17325
+ msg,
17326
+ messageLength
17327
+ });
16115
17328
  }
16116
- const msg2 = msg.replace(/\\/g, '\\\\');
16117
- const env = JSON.parse(msg2);
16118
- if (env.payload) {
16119
- return env.payload;
17329
+ catch (e) {
17330
+ console.error(`[port-discovery] Error parsing discovery message: ${e.message}`, {
17331
+ header,
17332
+ msg,
17333
+ messageLength
17334
+ });
16120
17335
  }
16121
- console.warn('discovery message did not have payload');
16122
17336
  }
16123
17337
  else {
16124
- console.error(`Invalid port discovery message type ${header.message_type}`);
17338
+ console.error(`[port-discovery] Invalid port discovery message type ${header.message_type}`);
16125
17339
  }
16126
17340
  return undefined;
16127
17341
  }
16128
- function readHeader(data) {
17342
+ function readHeader(reader) {
16129
17343
  const header = {};
16130
- header.payload_size = readUint32(data, 0);
16131
- header.routing_id = readUint32(data, 4);
16132
- header.message_type = readUint32(data, 8);
16133
- header.flags = readUint32(data, 12);
16134
- header.attachment_count = readUint32(data, 16);
17344
+ header.payload_size = reader.readInt32();
17345
+ header.routing_id = reader.readInt32();
17346
+ header.message_type = reader.readInt32();
17347
+ header.flags = reader.readInt32();
17348
+ header.attachment_count = reader.readInt32();
17349
+ header.os = os.platform();
17350
+ if (header.os !== 'win32') {
17351
+ header.num_fds = reader.readInt16();
17352
+ header.pad = reader.readInt16();
17353
+ }
16135
17354
  return header;
16136
17355
  }
16137
- function writeHelloMessage(header, conn) {
16138
- const data = Buffer.alloc(MessageHeaderSize + (header.extraInteger ? 28 : 4));
16139
- writeUint32(data, header.payload_size, 0);
16140
- writeUint32(data, header.routing_id, 4);
16141
- writeUint32(data, header.message_type, 8);
16142
- writeUint32(data, header.flags, 12);
16143
- writeUint32(data, header.attachment_count, 16);
16144
- let next = 20;
16145
- if (header.extraInteger) {
16146
- writeUint32(data, 0, next);
16147
- next += 4;
16148
- }
16149
- writeUint32(data, process.pid, next);
16150
- conn.write(data);
16151
- }
16152
- function readUint32(data, offset) {
16153
- return data.readInt32LE(offset);
16154
- }
16155
- function writeUint32(data, value, offset) {
16156
- data.writeInt32LE(value, offset);
16157
- }
16158
17356
  class PortDiscovery {
16159
17357
  constructor(config, environment) {
16160
17358
  this.savedConfig = { ...config };
@@ -16319,7 +17517,7 @@ function requireNodeEnv () {
16319
17517
  Object.defineProperty(nodeEnv, "__esModule", { value: true });
16320
17518
  /* eslint-disable class-methods-use-this */
16321
17519
  const fs_1 = require$$0$2;
16322
- const crypto_1 = require$$1$1;
17520
+ const crypto_1 = require$$1$3;
16323
17521
  const _WS = require$$2$1;
16324
17522
  const environment_1 = environment;
16325
17523
  const port_discovery_1 = requirePortDiscovery();