@openfin/fdc3-api 42.103.4 → 43.100.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/out/fdc3-api.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var require$$0 = require('lodash/isEqual');
3
+ var require$$2 = require('lodash/isEqual');
4
4
 
5
5
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6
6
 
@@ -203,86 +203,15 @@ class PrivateChannelClient {
203
203
  }
204
204
  PrivateChannelClient$1.PrivateChannelClient = PrivateChannelClient;
205
205
 
206
- var fdc3Channels2_0 = {};
207
-
208
- var fdc3Channels1_2 = {};
209
-
210
- var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
211
- return (mod && mod.__esModule) ? mod : { "default": mod };
212
- };
213
- Object.defineProperty(fdc3Channels1_2, "__esModule", { value: true });
214
- fdc3Channels1_2.createV1Channel = void 0;
215
- const isEqual_1$1 = __importDefault$2(require$$0);
216
- const createV1Channel = (sessionContextGroup) => {
217
- return {
218
- id: sessionContextGroup.id,
219
- type: 'app',
220
- broadcast: sessionContextGroup.setContext,
221
- getCurrentContext: async (contextType) => {
222
- const context = await sessionContextGroup.getCurrentContext(contextType);
223
- return context === undefined ? null : context;
224
- },
225
- // @ts-expect-error TODO [CORE-1524]
226
- addContextListener: (contextType, handler) => {
227
- let realHandler;
228
- let realType;
229
- if (typeof contextType === 'function') {
230
- console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
231
- realHandler = contextType;
232
- }
233
- else {
234
- realHandler = handler;
235
- if (typeof contextType === 'string') {
236
- realType = contextType;
237
- }
238
- }
239
- const listener = (async () => {
240
- let first = true;
241
- const currentContext = await sessionContextGroup.getCurrentContext(realType);
242
- const wrappedHandler = (context, contextMetadata) => {
243
- if (first) {
244
- first = false;
245
- if ((0, isEqual_1$1.default)(currentContext, context)) {
246
- return;
247
- }
248
- }
249
- // eslint-disable-next-line consistent-return
250
- return realHandler(context, contextMetadata);
251
- };
252
- return sessionContextGroup.addContextHandler(wrappedHandler, realType);
253
- })();
254
- return {
255
- ...listener,
256
- unsubscribe: () => listener.then((l) => l.unsubscribe())
257
- };
258
- }
259
- };
260
- };
261
- fdc3Channels1_2.createV1Channel = createV1Channel;
262
-
263
- Object.defineProperty(fdc3Channels2_0, "__esModule", { value: true });
264
- fdc3Channels2_0.createV2Channel = void 0;
265
- const fdc3_channels_1_2_1$1 = fdc3Channels1_2;
266
- const createV2Channel = (sessionContextGroup) => {
267
- const channel = (0, fdc3_channels_1_2_1$1.createV1Channel)(sessionContextGroup);
268
- return {
269
- ...channel,
270
- // @ts-expect-error Type incompatibility on signature.
271
- addContextListener: async (...args) => channel.addContextListener(...args)
272
- };
273
- };
274
- fdc3Channels2_0.createV2Channel = createV2Channel;
275
-
276
206
  (function (exports) {
277
207
  var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
278
208
  return (mod && mod.__esModule) ? mod : { "default": mod };
279
209
  };
280
210
  Object.defineProperty(exports, "__esModule", { value: true });
281
- exports.getIntentResolution = exports.isChannel = exports.isContext = exports.connectPrivateChannel = exports.buildPrivateChannelObject = exports.ChannelError = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
211
+ exports.getIntentResolution = exports.isChannel = exports.isContext = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ChannelError = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
282
212
  const utils_1 = utils$2;
283
213
  const PrivateChannelClient_1 = PrivateChannelClient$1;
284
- __importDefault(require$$0);
285
- const fdc3_channels_2_0_1 = fdc3Channels2_0;
214
+ const isEqual_1 = __importDefault(require$$2);
286
215
  const getUnsupportedChannelApis = (channelType) => {
287
216
  return {
288
217
  addContextListener: () => {
@@ -381,6 +310,52 @@ fdc3Channels2_0.createV2Channel = createV2Channel;
381
310
  };
382
311
  };
383
312
  exports.buildPrivateChannelObject = buildPrivateChannelObject;
313
+ const buildAppChannelObject = (sessionContextGroup) => {
314
+ return {
315
+ id: sessionContextGroup.id,
316
+ type: 'app',
317
+ broadcast: sessionContextGroup.setContext,
318
+ getCurrentContext: async (contextType) => {
319
+ const context = await sessionContextGroup.getCurrentContext(contextType);
320
+ return context === undefined ? null : context;
321
+ },
322
+ // @ts-expect-error TODO [CORE-1524]
323
+ addContextListener: (contextType, handler) => {
324
+ let realHandler;
325
+ let realType;
326
+ if (typeof contextType === 'function') {
327
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
328
+ realHandler = contextType;
329
+ }
330
+ else {
331
+ realHandler = handler;
332
+ if (typeof contextType === 'string') {
333
+ realType = contextType;
334
+ }
335
+ }
336
+ const listener = (async () => {
337
+ let first = true;
338
+ const currentContext = await sessionContextGroup.getCurrentContext(realType);
339
+ const wrappedHandler = (context, contextMetadata) => {
340
+ if (first) {
341
+ first = false;
342
+ if ((0, isEqual_1.default)(currentContext, context)) {
343
+ return;
344
+ }
345
+ }
346
+ // eslint-disable-next-line consistent-return
347
+ return realHandler(context, contextMetadata);
348
+ };
349
+ return sessionContextGroup.addContextHandler(wrappedHandler, realType);
350
+ })();
351
+ return {
352
+ ...listener,
353
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
354
+ };
355
+ }
356
+ };
357
+ };
358
+ exports.buildAppChannelObject = buildAppChannelObject;
384
359
  const connectPrivateChannel = async (channelId) => {
385
360
  try {
386
361
  const channelClient = await fin.InterApplicationBus.Channel.connect(channelId);
@@ -412,10 +387,6 @@ fdc3Channels2_0.createV2Channel = createV2Channel;
412
387
  // Generate an ID to make a session context group with. We will pass that ID to the Broker.
413
388
  // The broker will then setContext on that session context group later with our Intent Result,
414
389
  const guid = (0, utils_1.generateId)(); // TODO make this undefined in web
415
- let isPromiseSettled = false;
416
- // Adding the intentResolutionResultId to the intentObj. Because fireIntent only accepts a single arg, we have to slap it in here.
417
- const metadata = app ? { target: app, intentResolutionResultId: guid } : { intentResolutionResultId: guid };
418
- const intentObj = intent ? { name: intent, context, metadata } : { ...context, metadata };
419
390
  // Promise we'll use in getResult
420
391
  const getResultPromise = new Promise((resolve, reject) => {
421
392
  fin.InterApplicationBus.subscribe({ uuid: '*' }, guid, (intentResult) => {
@@ -428,24 +399,13 @@ fdc3Channels2_0.createV2Channel = createV2Channel;
428
399
  reject(new Error('getResult is not supported in this environment'));
429
400
  });
430
401
  });
431
- getResultPromise
432
- .then(() => {
433
- isPromiseSettled = true;
434
- })
435
- .catch(() => {
436
- isPromiseSettled = true;
437
- });
402
+ // Adding the intentResolutionResultId to the intentObj. Because fireIntent only accepts a single arg, we have to slap it in here.
403
+ const metadata = app ? { target: app, intentResolutionResultId: guid } : { intentResolutionResultId: guid };
404
+ const intentObj = intent ? { name: intent, context, metadata } : { ...context, metadata };
438
405
  // Set up the getResult call.
439
406
  const getResult = async () => {
440
- // All this mumbo jumbo is needed to make sure that getResult resolves correctly and conforms to the FDC3 spec.
441
- if (!isPromiseSettled) {
442
- return undefined;
443
- }
444
407
  let intentResult = await getResultPromise;
445
- if (isPromiseSettled && !intentResult) {
446
- return undefined;
447
- }
448
- if (typeof intentResult !== 'object') {
408
+ if (!intentResult || typeof intentResult !== 'object') {
449
409
  throw new Error(ResultError.NoResultReturned);
450
410
  }
451
411
  const { error } = intentResult;
@@ -461,7 +421,7 @@ fdc3Channels2_0.createV2Channel = createV2Channel;
461
421
  }
462
422
  case 'app': {
463
423
  const sessionContextGroup = await interopModule.joinSessionContextGroup(id);
464
- intentResult = (0, fdc3_channels_2_0_1.createV2Channel)(sessionContextGroup);
424
+ intentResult = (0, exports.buildAppChannelObject)(sessionContextGroup);
465
425
  break;
466
426
  }
467
427
  }
@@ -495,6 +455,35 @@ var InteropClient$1 = {};
495
455
 
496
456
  var base = {};
497
457
 
458
+ var promises = {};
459
+
460
+ Object.defineProperty(promises, "__esModule", { value: true });
461
+ promises.promiseMapSerial = promises.serial = promises.promiseMap = promises.promisify = void 0;
462
+ function promisify(func) {
463
+ return (...args) => new Promise((resolve, reject) => {
464
+ func(...args, (err, val) => (err ? reject(err) : resolve(val)));
465
+ });
466
+ }
467
+ promises.promisify = promisify;
468
+ async function promiseMap(arr, asyncF) {
469
+ return Promise.all(arr.map(asyncF));
470
+ }
471
+ promises.promiseMap = promiseMap;
472
+ async function serial(arr) {
473
+ const ret = [];
474
+ for (const func of arr) {
475
+ // eslint-disable-next-line no-await-in-loop
476
+ const next = await func();
477
+ ret.push(next);
478
+ }
479
+ return ret;
480
+ }
481
+ promises.serial = serial;
482
+ async function promiseMapSerial(arr, func) {
483
+ return serial(arr.map((value, index, array) => () => func(value, index, array)));
484
+ }
485
+ promises.promiseMapSerial = promiseMapSerial;
486
+
498
487
  var __classPrivateFieldSet$3 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
499
488
  if (kind === "m") throw new TypeError("Private method is not writable");
500
489
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -509,6 +498,7 @@ var __classPrivateFieldGet$3 = (commonjsGlobal && commonjsGlobal.__classPrivateF
509
498
  var _EmitterBase_emitterAccessor, _EmitterBase_deregisterOnceListeners;
510
499
  Object.defineProperty(base, "__esModule", { value: true });
511
500
  base.Reply = base.EmitterBase = base.Base = void 0;
501
+ const promises_1 = promises;
512
502
  class Base {
513
503
  /**
514
504
  * @internal
@@ -586,8 +576,27 @@ class EmitterBase extends Base {
586
576
  return this.hasEmitter() ? this.getOrCreateEmitter().emit(eventType, payload, ...args) : false;
587
577
  };
588
578
  this.hasEmitter = () => this.wire.eventAggregator.has(__classPrivateFieldGet$3(this, _EmitterBase_emitterAccessor, "f"));
579
+ /**
580
+ * Cleans up after removal of a listener, e.g. deleting any lingering deregistration handlers for a
581
+ * `once` subscription.
582
+ *
583
+ * @remarks Implementing this as a `removeListener` handler ensures that direct removal of a listener
584
+ * on the base emitter will not leak additional core handlers. We could do this in the forwarding method,
585
+ * which would involve less "magic," but would be more-vulnerable to accidental re-introduction of a leak.
586
+ */
587
+ this.cleanUpRemovedListener = (eventType, listener) => {
588
+ const deregister = __classPrivateFieldGet$3(this, _EmitterBase_deregisterOnceListeners, "f").get(listener);
589
+ if (deregister) {
590
+ const emitter = this.wire.eventAggregator.getOrCreate(__classPrivateFieldGet$3(this, _EmitterBase_emitterAccessor, "f"));
591
+ emitter.removeListener(eventType, deregister);
592
+ }
593
+ };
589
594
  this.getOrCreateEmitter = () => {
590
- return this.wire.eventAggregator.getOrCreate(__classPrivateFieldGet$3(this, _EmitterBase_emitterAccessor, "f"));
595
+ const emitter = this.wire.eventAggregator.getOrCreate(__classPrivateFieldGet$3(this, _EmitterBase_emitterAccessor, "f"));
596
+ if (!emitter.listeners('removeListener').includes(this.cleanUpRemovedListener)) {
597
+ emitter.on('removeListener', this.cleanUpRemovedListener);
598
+ }
599
+ return emitter;
591
600
  };
592
601
  this.listeners = (type) => this.hasEmitter() ? this.getOrCreateEmitter().listeners(type) : [];
593
602
  this.listenerCount = (type) => this.hasEmitter() ? this.getOrCreateEmitter().listenerCount(type) : 0;
@@ -627,6 +636,7 @@ class EmitterBase extends Base {
627
636
  };
628
637
  __classPrivateFieldSet$3(this, _EmitterBase_emitterAccessor, [topic, ...additionalAccessors], "f");
629
638
  __classPrivateFieldSet$3(this, _EmitterBase_deregisterOnceListeners, new WeakMap(), "f");
639
+ this.listeners = (event) => this.hasEmitter() ? this.getOrCreateEmitter().listeners(event) : [];
630
640
  }
631
641
  /**
632
642
  * Adds a listener to the end of the listeners array for the specified event.
@@ -704,10 +714,6 @@ class EmitterBase extends Base {
704
714
  const emitter = await this.deregisterEventListener(eventType, options);
705
715
  if (emitter) {
706
716
  emitter.removeListener(eventType, listener);
707
- const deregister = __classPrivateFieldGet$3(this, _EmitterBase_deregisterOnceListeners, "f").get(listener);
708
- if (deregister) {
709
- emitter.removeListener(eventType, deregister);
710
- }
711
717
  this.deleteEmitterIfNothingRegistered(emitter);
712
718
  }
713
719
  return this;
@@ -743,13 +749,12 @@ class EmitterBase extends Base {
743
749
  }
744
750
  else if (this.hasEmitter()) {
745
751
  const events = this.getOrCreateEmitter().eventNames();
746
- await Promise.all(events.map(removeByEvent));
752
+ await (0, promises_1.promiseMap)(events, removeByEvent);
747
753
  }
748
754
  return this;
749
755
  }
750
756
  deleteEmitterIfNothingRegistered(emitter) {
751
- // TODO: maybe emitterMap should clean up itself..
752
- if (emitter.eventNames().length === 0) {
757
+ if (emitter.eventNames().every((type) => type === 'removeListener')) {
753
758
  this.wire.eventAggregator.delete(__classPrivateFieldGet$3(this, _EmitterBase_emitterAccessor, "f"));
754
759
  }
755
760
  }
@@ -1468,7 +1473,7 @@ fdc3Common.FDC3ModuleBase = void 0;
1468
1473
  const utils_1$2 = utils$1;
1469
1474
  const utils_2$1 = utils$2;
1470
1475
  const InteropClient_1$1 = InteropClient$1;
1471
- const isEqual_1 = __importDefault(require$$0);
1476
+ const isEqual_1 = __importDefault(require$$2);
1472
1477
  class FDC3ModuleBase {
1473
1478
  get client() {
1474
1479
  return __classPrivateFieldGet(this, _FDC3ModuleBase_producer, "f").call(this);
@@ -1528,16 +1533,10 @@ class FDC3ModuleBase {
1528
1533
  *
1529
1534
  * @tutorial fdc3.getOrCreateChannel
1530
1535
  */
1531
- async getOrCreateChannel(channelId, fdc3Factory) {
1536
+ async getOrCreateChannel(channelId) {
1532
1537
  this.wire.sendAction('fdc3-get-or-create-channel').catch((e) => {
1533
1538
  // we do not want to expose this error, just continue if this analytics-only call fails
1534
1539
  });
1535
- const hasChannelIdBeenUsed = await InteropClient_1$1.InteropClient.ferryFdc3Call(this.client, 'isIdUsedByPrivateChannel', {
1536
- channelId
1537
- });
1538
- if (hasChannelIdBeenUsed) {
1539
- throw new Error(utils_1$2.ChannelError.AccessDenied);
1540
- }
1541
1540
  const systemChannels = await this._getChannels();
1542
1541
  const userChannel = systemChannels.find((channel) => channel.id === channelId);
1543
1542
  if (userChannel) {
@@ -1545,7 +1544,7 @@ class FDC3ModuleBase {
1545
1544
  }
1546
1545
  try {
1547
1546
  const sessionContextGroup = await this.client.joinSessionContextGroup(channelId);
1548
- return fdc3Factory(sessionContextGroup);
1547
+ return (0, utils_1$2.buildAppChannelObject)(sessionContextGroup);
1549
1548
  }
1550
1549
  catch (error) {
1551
1550
  console.error(error.message);
@@ -1695,7 +1694,6 @@ Object.defineProperty(fdc31_2, "__esModule", { value: true });
1695
1694
  exports.Fdc3Module = fdc31_2.Fdc3Module = void 0;
1696
1695
  const utils_1$1 = utils$2;
1697
1696
  const fdc3_common_1$1 = fdc3Common;
1698
- const fdc3_channels_1_2_1 = fdc3Channels1_2;
1699
1697
  /**
1700
1698
  * @version 1.2
1701
1699
  * The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
@@ -1878,7 +1876,7 @@ class Fdc3Module extends fdc3_common_1$1.FDC3ModuleBase {
1878
1876
  * @tutorial fdc3.getOrCreateChannel
1879
1877
  */
1880
1878
  async getOrCreateChannel(channelId) {
1881
- return super.getOrCreateChannel(channelId, fdc3_channels_1_2_1.createV1Channel);
1879
+ return super.getOrCreateChannel(channelId);
1882
1880
  }
1883
1881
  /**
1884
1882
  * 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.
@@ -1910,7 +1908,6 @@ const utils_1 = utils$2;
1910
1908
  const InteropClient_1 = InteropClient$1;
1911
1909
  const utils_2 = utils$1;
1912
1910
  const PrivateChannelClient_1 = PrivateChannelClient$1;
1913
- const fdc3_channels_2_0_1 = fdc3Channels2_0;
1914
1911
  /**
1915
1912
  * @version 2.0
1916
1913
  * The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
@@ -2162,7 +2159,7 @@ class Fdc3Module2 extends fdc3_common_1.FDC3ModuleBase {
2162
2159
  * @tutorial fdc3.getOrCreateChannel
2163
2160
  */
2164
2161
  async getOrCreateChannel(channelId) {
2165
- return super.getOrCreateChannel(channelId, fdc3_channels_2_0_1.createV2Channel);
2162
+ return super.getOrCreateChannel(channelId);
2166
2163
  }
2167
2164
  /**
2168
2165
  * 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfin/fdc3-api",
3
- "version": "42.103.4",
3
+ "version": "43.100.5",
4
4
  "description": "OpenFin fdc3 module utilities and types.",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "private": false,