@openfin/fdc3-api 43.100.91 → 43.100.93

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.
@@ -5769,7 +5769,7 @@ declare class FDC3ModuleBase<ChannelType extends v1_2.Channel | v2_0.Channel> {
5769
5769
  *
5770
5770
  * @tutorial fdc3.getOrCreateChannel
5771
5771
  */
5772
- getOrCreateChannel(channelId: string): Promise<ChannelType>;
5772
+ protected getOrCreateChannel(channelId: string, fdc3Factory: (contextGroup: OpenFin.SessionContextGroup) => ChannelType): Promise<ChannelType>;
5773
5773
  /**
5774
5774
  * Returns the Interop-Broker-defined context groups available for an entity to join.
5775
5775
  *
@@ -5769,7 +5769,7 @@ declare class FDC3ModuleBase<ChannelType extends v1_2.Channel | v2_0.Channel> {
5769
5769
  *
5770
5770
  * @tutorial fdc3.getOrCreateChannel
5771
5771
  */
5772
- getOrCreateChannel(channelId: string): Promise<ChannelType>;
5772
+ protected getOrCreateChannel(channelId: string, fdc3Factory: (contextGroup: OpenFin.SessionContextGroup) => ChannelType): Promise<ChannelType>;
5773
5773
  /**
5774
5774
  * Returns the Interop-Broker-defined context groups available for an entity to join.
5775
5775
  *
@@ -5769,7 +5769,7 @@ declare class FDC3ModuleBase<ChannelType extends v1_2.Channel | v2_0.Channel> {
5769
5769
  *
5770
5770
  * @tutorial fdc3.getOrCreateChannel
5771
5771
  */
5772
- getOrCreateChannel(channelId: string): Promise<ChannelType>;
5772
+ protected getOrCreateChannel(channelId: string, fdc3Factory: (contextGroup: OpenFin.SessionContextGroup) => ChannelType): Promise<ChannelType>;
5773
5773
  /**
5774
5774
  * Returns the Interop-Broker-defined context groups available for an entity to join.
5775
5775
  *
package/out/fdc3-api.d.ts CHANGED
@@ -5854,7 +5854,7 @@ declare class FDC3ModuleBase<ChannelType extends v1_2.Channel | v2_0.Channel> {
5854
5854
  *
5855
5855
  * @tutorial fdc3.getOrCreateChannel
5856
5856
  */
5857
- getOrCreateChannel(channelId: string): Promise<ChannelType>;
5857
+ protected getOrCreateChannel(channelId: string, fdc3Factory: (contextGroup: OpenFin.SessionContextGroup) => ChannelType): Promise<ChannelType>;
5858
5858
  /**
5859
5859
  * Returns the Interop-Broker-defined context groups available for an entity to join.
5860
5860
  *
package/out/fdc3-api.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var require$$2 = require('lodash/isEqual');
3
+ var require$$0 = 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,15 +203,86 @@ 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
+
206
276
  (function (exports) {
207
277
  var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
208
278
  return (mod && mod.__esModule) ? mod : { "default": mod };
209
279
  };
210
280
  Object.defineProperty(exports, "__esModule", { value: true });
211
- exports.getIntentResolution = exports.isChannel = exports.isContext = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ChannelError = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
281
+ exports.getIntentResolution = exports.isChannel = exports.isContext = exports.connectPrivateChannel = exports.buildPrivateChannelObject = exports.ChannelError = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
212
282
  const utils_1 = utils$2;
213
283
  const PrivateChannelClient_1 = PrivateChannelClient$1;
214
- const isEqual_1 = __importDefault(require$$2);
284
+ __importDefault(require$$0);
285
+ const fdc3_channels_2_0_1 = fdc3Channels2_0;
215
286
  const getUnsupportedChannelApis = (channelType) => {
216
287
  return {
217
288
  addContextListener: () => {
@@ -310,52 +381,6 @@ PrivateChannelClient$1.PrivateChannelClient = PrivateChannelClient;
310
381
  };
311
382
  };
312
383
  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;
359
384
  const connectPrivateChannel = async (channelId) => {
360
385
  try {
361
386
  const channelClient = await fin.InterApplicationBus.Channel.connect(channelId);
@@ -387,6 +412,10 @@ PrivateChannelClient$1.PrivateChannelClient = PrivateChannelClient;
387
412
  // Generate an ID to make a session context group with. We will pass that ID to the Broker.
388
413
  // The broker will then setContext on that session context group later with our Intent Result,
389
414
  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 };
390
419
  // Promise we'll use in getResult
391
420
  const getResultPromise = new Promise((resolve, reject) => {
392
421
  fin.InterApplicationBus.subscribe({ uuid: '*' }, guid, (intentResult) => {
@@ -399,13 +428,24 @@ PrivateChannelClient$1.PrivateChannelClient = PrivateChannelClient;
399
428
  reject(new Error('getResult is not supported in this environment'));
400
429
  });
401
430
  });
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 };
431
+ getResultPromise
432
+ .then(() => {
433
+ isPromiseSettled = true;
434
+ })
435
+ .catch(() => {
436
+ isPromiseSettled = true;
437
+ });
405
438
  // Set up the getResult call.
406
439
  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
+ }
407
444
  let intentResult = await getResultPromise;
408
- if (!intentResult || typeof intentResult !== 'object') {
445
+ if (isPromiseSettled && !intentResult) {
446
+ return undefined;
447
+ }
448
+ if (typeof intentResult !== 'object') {
409
449
  throw new Error(ResultError.NoResultReturned);
410
450
  }
411
451
  const { error } = intentResult;
@@ -421,7 +461,7 @@ PrivateChannelClient$1.PrivateChannelClient = PrivateChannelClient;
421
461
  }
422
462
  case 'app': {
423
463
  const sessionContextGroup = await interopModule.joinSessionContextGroup(id);
424
- intentResult = (0, exports.buildAppChannelObject)(sessionContextGroup);
464
+ intentResult = (0, fdc3_channels_2_0_1.createV2Channel)(sessionContextGroup);
425
465
  break;
426
466
  }
427
467
  }
@@ -1473,7 +1513,7 @@ fdc3Common.FDC3ModuleBase = void 0;
1473
1513
  const utils_1$2 = utils$1;
1474
1514
  const utils_2$1 = utils$2;
1475
1515
  const InteropClient_1$1 = InteropClient$1;
1476
- const isEqual_1 = __importDefault(require$$2);
1516
+ const isEqual_1 = __importDefault(require$$0);
1477
1517
  class FDC3ModuleBase {
1478
1518
  get client() {
1479
1519
  return __classPrivateFieldGet(this, _FDC3ModuleBase_producer, "f").call(this);
@@ -1533,7 +1573,7 @@ class FDC3ModuleBase {
1533
1573
  *
1534
1574
  * @tutorial fdc3.getOrCreateChannel
1535
1575
  */
1536
- async getOrCreateChannel(channelId) {
1576
+ async getOrCreateChannel(channelId, fdc3Factory) {
1537
1577
  this.wire.sendAction('fdc3-get-or-create-channel').catch((e) => {
1538
1578
  // we do not want to expose this error, just continue if this analytics-only call fails
1539
1579
  });
@@ -1550,7 +1590,7 @@ class FDC3ModuleBase {
1550
1590
  }
1551
1591
  try {
1552
1592
  const sessionContextGroup = await this.client.joinSessionContextGroup(channelId);
1553
- return (0, utils_1$2.buildAppChannelObject)(sessionContextGroup);
1593
+ return fdc3Factory(sessionContextGroup);
1554
1594
  }
1555
1595
  catch (error) {
1556
1596
  console.error(error.message);
@@ -1700,6 +1740,7 @@ Object.defineProperty(fdc31_2, "__esModule", { value: true });
1700
1740
  exports.Fdc3Module = fdc31_2.Fdc3Module = void 0;
1701
1741
  const utils_1$1 = utils$2;
1702
1742
  const fdc3_common_1$1 = fdc3Common;
1743
+ const fdc3_channels_1_2_1 = fdc3Channels1_2;
1703
1744
  /**
1704
1745
  * @version 1.2
1705
1746
  * The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
@@ -1882,7 +1923,7 @@ class Fdc3Module extends fdc3_common_1$1.FDC3ModuleBase {
1882
1923
  * @tutorial fdc3.getOrCreateChannel
1883
1924
  */
1884
1925
  async getOrCreateChannel(channelId) {
1885
- return super.getOrCreateChannel(channelId);
1926
+ return super.getOrCreateChannel(channelId, fdc3_channels_1_2_1.createV1Channel);
1886
1927
  }
1887
1928
  /**
1888
1929
  * 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.
@@ -1914,6 +1955,7 @@ const utils_1 = utils$2;
1914
1955
  const InteropClient_1 = InteropClient$1;
1915
1956
  const utils_2 = utils$1;
1916
1957
  const PrivateChannelClient_1 = PrivateChannelClient$1;
1958
+ const fdc3_channels_2_0_1 = fdc3Channels2_0;
1917
1959
  /**
1918
1960
  * @version 2.0
1919
1961
  * The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
@@ -2165,7 +2207,7 @@ class Fdc3Module2 extends fdc3_common_1.FDC3ModuleBase {
2165
2207
  * @tutorial fdc3.getOrCreateChannel
2166
2208
  */
2167
2209
  async getOrCreateChannel(channelId) {
2168
- return super.getOrCreateChannel(channelId);
2210
+ return super.getOrCreateChannel(channelId, fdc3_channels_2_0_1.createV2Channel);
2169
2211
  }
2170
2212
  /**
2171
2213
  * 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": "43.100.91",
3
+ "version": "43.100.93",
4
4
  "description": "OpenFin fdc3 module utilities and types.",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "private": false,