@openfin/core 31.74.1 → 31.74.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/package.json +1 -1
  2. package/src/OpenFin.d.ts +284 -253
  3. package/src/OpenFin.js +0 -2
  4. package/src/api/api-exposer/api-consumer.d.ts +28 -0
  5. package/src/api/api-exposer/api-consumer.js +28 -0
  6. package/src/api/api-exposer/api-exposer.d.ts +35 -0
  7. package/src/api/api-exposer/api-exposer.js +38 -0
  8. package/src/api/api-exposer/decorators.d.ts +10 -0
  9. package/src/api/api-exposer/decorators.js +18 -0
  10. package/src/api/api-exposer/index.d.ts +4 -0
  11. package/src/api/api-exposer/index.js +20 -0
  12. package/src/api/api-exposer/strategies/index.d.ts +1 -0
  13. package/src/api/api-exposer/strategies/index.js +17 -0
  14. package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.d.ts +14 -0
  15. package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.js +20 -0
  16. package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.d.ts +20 -0
  17. package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.js +23 -0
  18. package/src/api/api-exposer/strategies/openfin-channels/index.d.ts +2 -0
  19. package/src/api/api-exposer/strategies/openfin-channels/index.js +18 -0
  20. package/src/api/application/Factory.js +1 -2
  21. package/src/api/application/Instance.js +23 -5
  22. package/src/api/base.d.ts +5 -2
  23. package/src/api/base.js +7 -0
  24. package/src/api/events/application.d.ts +22 -22
  25. package/src/api/events/base.d.ts +6 -9
  26. package/src/api/events/channel.d.ts +5 -5
  27. package/src/api/events/emitterMap.d.ts +1 -1
  28. package/src/api/events/externalApplication.d.ts +3 -3
  29. package/src/api/events/frame.d.ts +5 -5
  30. package/src/api/events/globalHotkey.d.ts +3 -3
  31. package/src/api/events/platform.d.ts +3 -3
  32. package/src/api/events/system.d.ts +18 -18
  33. package/src/api/events/typedEventEmitter.d.ts +1 -1
  34. package/src/api/events/view.d.ts +17 -14
  35. package/src/api/events/webcontents.d.ts +24 -22
  36. package/src/api/events/window.d.ts +65 -57
  37. package/src/api/fin.d.ts +1 -1
  38. package/src/api/frame/Instance.d.ts +1 -1
  39. package/src/api/interappbus/channel/channel.d.ts +4 -4
  40. package/src/api/interappbus/channel/channel.js +3 -3
  41. package/src/api/interappbus/channel/client.d.ts +2 -2
  42. package/src/api/interappbus/channel/client.js +20 -20
  43. package/src/api/interappbus/channel/connection-manager.d.ts +1 -1
  44. package/src/api/interappbus/channel/connection-manager.js +12 -12
  45. package/src/api/interappbus/channel/index.d.ts +2 -2
  46. package/src/api/interappbus/channel/index.js +1 -1
  47. package/src/api/interappbus/channel/protocols/classic/strategy.d.ts +1 -1
  48. package/src/api/interappbus/channel/protocols/combined/strategy.d.ts +2 -2
  49. package/src/api/interappbus/channel/protocols/combined/strategy.js +5 -5
  50. package/src/api/interappbus/channel/protocols/index.d.ts +4 -4
  51. package/src/api/interappbus/channel/protocols/rtc/endpoint.d.ts +1 -1
  52. package/src/api/interappbus/channel/protocols/rtc/strategy.d.ts +1 -1
  53. package/src/api/interappbus/channel/protocols/strategy-types.d.ts +4 -4
  54. package/src/api/interappbus/channel/protocols/strategy.d.ts +3 -3
  55. package/src/api/interappbus/channel/provider.d.ts +5 -5
  56. package/src/api/interappbus/channel/provider.js +24 -24
  57. package/src/api/interop/InteropBroker.d.ts +1 -1
  58. package/src/api/interop/InteropBroker.js +6 -2
  59. package/src/api/interop/fdc3/PrivateChannelClient.d.ts +2 -1
  60. package/src/api/interop/fdc3/PrivateChannelClient.js +15 -7
  61. package/src/api/interop/fdc3/PrivateChannelProvider.d.ts +16 -2
  62. package/src/api/interop/fdc3/PrivateChannelProvider.js +80 -28
  63. package/src/api/interop/fdc3/fdc3-1.2.js +53 -5
  64. package/src/api/interop/fdc3/fdc3-2.0.d.ts +11 -10
  65. package/src/api/interop/fdc3/fdc3-2.0.js +18 -19
  66. package/src/api/interop/fdc3/shapes/fdc3v1.d.ts +3 -3
  67. package/src/api/interop/fdc3/shapes/fdc3v2.d.ts +5 -5
  68. package/src/api/interop/fdc3/utils.d.ts +17 -0
  69. package/src/api/interop/fdc3/utils.js +75 -21
  70. package/src/api/interop/fdc3/versions.d.ts +1 -1
  71. package/src/api/interop/utils.d.ts +0 -1
  72. package/src/api/interop/utils.js +1 -9
  73. package/src/api/me.d.ts +3 -3
  74. package/src/api/platform/Factory.js +5 -9
  75. package/src/api/platform/Instance.d.ts +1 -1
  76. package/src/api/platform/Instance.js +1 -1
  77. package/src/api/platform/common-utils.d.ts +1 -1
  78. package/src/api/platform/layout/Factory.d.ts +1 -1
  79. package/src/api/platform/layout/Factory.js +11 -3
  80. package/src/api/platform/layout/Instance.d.ts +9 -3
  81. package/src/api/platform/layout/Instance.js +26 -1
  82. package/src/api/platform/layout/controllers/layout-content-cache.d.ts +9 -0
  83. package/src/api/platform/layout/controllers/layout-content-cache.js +54 -0
  84. package/src/api/platform/layout/controllers/layout-entities-controller.d.ts +117 -0
  85. package/src/api/platform/layout/controllers/layout-entities-controller.js +270 -0
  86. package/src/api/platform/layout/controllers/splitter-controller.d.ts +1 -1
  87. package/src/api/platform/layout/entities/layout-entities.d.ts +144 -0
  88. package/src/api/platform/layout/entities/layout-entities.js +216 -0
  89. package/src/api/platform/layout/entities/shapes.d.ts +6 -0
  90. package/src/api/platform/layout/entities/shapes.js +2 -0
  91. package/src/api/platform/layout/layout.constants.d.ts +1 -0
  92. package/src/api/platform/layout/layout.constants.js +4 -0
  93. package/src/api/platform/layout/shapes.d.ts +4 -1
  94. package/src/api/platform/layout/utils/layout-traversal.d.ts +4 -0
  95. package/src/api/platform/layout/utils/layout-traversal.js +65 -0
  96. package/src/api/system/index.d.ts +13 -13
  97. package/src/api/view/Instance.d.ts +13 -3
  98. package/src/api/view/Instance.js +41 -4
  99. package/src/environment/browser.d.ts +1 -1
  100. package/src/environment/environment.d.ts +1 -1
  101. package/src/environment/node-env.d.ts +1 -1
  102. package/src/environment/openfin-env.d.ts +1 -1
  103. package/src/mock.d.ts +1 -1
  104. package/src/mock.js +5 -2
  105. package/src/shapes/ERROR_BOX_TYPES.d.ts +1 -1
  106. package/src/shapes/protocol.d.ts +3 -3
  107. package/src/transport/transport-errors.d.ts +2 -2
  108. package/src/transport/transport.d.ts +3 -3
  109. package/src/transport/transport.js +1 -4
  110. package/src/transport/wire.d.ts +14 -13
  111. package/src/util/channel-api-relay.d.ts +13 -0
  112. package/src/util/channel-api-relay.js +37 -0
  113. package/src/util/errors.d.ts +2 -2
  114. package/src/util/http.js +4 -2
  115. package/src/util/lazy.d.ts +16 -0
  116. package/src/util/lazy.js +26 -0
  117. package/src/util/promises.d.ts +1 -1
  118. package/src/util/reversible-map.d.ts +11 -0
  119. package/src/util/reversible-map.js +49 -0
  120. package/src/util/utilTypes.d.ts +1 -1
@@ -4,6 +4,7 @@ const base_1 = require("../../base");
4
4
  const utils_1 = require("./utils");
5
5
  const utils_2 = require("../utils");
6
6
  const InteropClient_1 = require("../InteropClient");
7
+ const lodash_1 = require("lodash");
7
8
  /**
8
9
  * @typedef { object } Listener
9
10
  * @summary Listener object returned by addContextListener and addIntentListener
@@ -169,11 +170,15 @@ class Fdc3Module extends base_1.Base {
169
170
  }
170
171
  catch (error) {
171
172
  if (error.message === utils_2.BROKER_ERRORS.joinSessionContextGroupWithJoinContextGroup) {
172
- throw new 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.');
173
+ 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.');
173
174
  }
174
175
  else {
175
- throw new Error(error.message);
176
+ console.error(error.message);
176
177
  }
178
+ if (error.message.startsWith('Attempting to join a context group that does not exist')) {
179
+ throw new Error(utils_1.ChannelError.NoChannelFound);
180
+ }
181
+ throw new Error(utils_1.ChannelError.AccessDenied);
177
182
  }
178
183
  }
179
184
  /**
@@ -317,8 +322,19 @@ class Fdc3Module extends base_1.Base {
317
322
  this.wire.sendAction('fdc3-get-or-create-channel').catch((e) => {
318
323
  // we do not want to expose this error, just continue if this analytics-only call fails
319
324
  });
320
- const sessionContextGroup = await this.fin.me.interop.joinSessionContextGroup(channelId);
321
- return (0, utils_1.buildAppChannelObject)(sessionContextGroup);
325
+ const systemChannels = await this.getSystemChannels();
326
+ const userChannel = systemChannels.find((channel) => channel.id === channelId);
327
+ if (userChannel) {
328
+ return { ...userChannel, type: 'system', ...(0, utils_1.getUnsupportedChannelApis)() };
329
+ }
330
+ try {
331
+ const sessionContextGroup = await this.fin.me.interop.joinSessionContextGroup(channelId);
332
+ return (0, utils_1.buildAppChannelObject)(sessionContextGroup);
333
+ }
334
+ catch (error) {
335
+ console.error(error.message);
336
+ throw new Error(utils_1.ChannelError.CreationFailed);
337
+ }
322
338
  }
323
339
  /**
324
340
  * 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.
@@ -378,7 +394,39 @@ class Fdc3Module extends base_1.Base {
378
394
  return {
379
395
  ...currentContextGroupInfo,
380
396
  type: 'system',
381
- addContextListener: this.addContextListener.bind(this),
397
+ addContextListener: (contextType, handler) => {
398
+ let realHandler;
399
+ let realType;
400
+ if (typeof contextType === 'function') {
401
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
402
+ realHandler = contextType;
403
+ }
404
+ else {
405
+ realHandler = handler;
406
+ if (typeof contextType === 'string') {
407
+ realType = contextType;
408
+ }
409
+ }
410
+ const listener = (async () => {
411
+ let first = true;
412
+ const currentContext = await this.fin.me.interop.getCurrentContext(realType);
413
+ const wrappedHandler = (context, contextMetadata) => {
414
+ if (first) {
415
+ first = false;
416
+ if ((0, lodash_1.isEqual)(currentContext, context)) {
417
+ return;
418
+ }
419
+ }
420
+ // eslint-disable-next-line consistent-return
421
+ return realHandler(context, contextMetadata);
422
+ };
423
+ return this.fin.me.interop.addContextHandler(wrappedHandler, realType);
424
+ })();
425
+ return {
426
+ ...listener,
427
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
428
+ };
429
+ },
382
430
  broadcast: this.broadcast.bind(this),
383
431
  getCurrentContext: async (contextType) => {
384
432
  const context = await this.fin.me.interop.getCurrentContext(contextType);
@@ -171,14 +171,14 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
171
171
  * Find all the available instances for a particular application.
172
172
  * @param { AppIdentifier } app
173
173
  * @returns { Promise<Array<AppIdentifier>> }
174
- * @tutorial findInstances
174
+ * @tutorial fdc3v2.findInstances
175
175
  */
176
176
  findInstances(app: FDC3v2.AppIdentifier): Promise<Array<FDC3v2.AppIdentifier>>;
177
177
  /**
178
178
  * 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.
179
179
  * @param { AppIdentifier } app
180
180
  * @returns { Promise<AppMetadata(2)> }
181
- * @tutorial getAppMetadata
181
+ * @tutorial fdc3v2.getAppMetadata
182
182
  */
183
183
  getAppMetadata(app: FDC3v2.AppIdentifier): Promise<FDC3v2.AppMetadata>;
184
184
  /**
@@ -210,7 +210,7 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
210
210
  * @param { Context } context
211
211
  * @param { string } [resultType] The type of result returned for any intent specified during resolution.
212
212
  * @returns { Promise<Array<AppIntent(2)>> }
213
- * @tutorial findIntentsByContext
213
+ * @tutorial fdc3v2.findIntentsByContext
214
214
  */
215
215
  findIntentsByContext(context: FDC3v2.Context, resultType?: string): Promise<Array<FDC3v2.AppIntent>>;
216
216
  /**
@@ -219,7 +219,7 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
219
219
  * @param { Context } context Context associated with the Intent
220
220
  * @param { AppIdentifier | TargetApp } [app]
221
221
  * @returns { Promise<IntentResolution(2)> }
222
- * @tutorial raiseIntent
222
+ * @tutorial fdc3v2.raiseIntent
223
223
  */
224
224
  raiseIntent(intent: string, context: FDC3v2.Context, app?: FDC3v2.AppIdentifier | FDC3v1.TargetApp): Promise<FDC3v2.IntentResolution>;
225
225
  /**
@@ -227,7 +227,7 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
227
227
  * @param { Context } context Context associated with the Intent
228
228
  * @param { AppIdentifier | TargetApp } [app]
229
229
  * @returns { Promise<IntentResolution(2)> }
230
- * @tutorial raiseIntentForContext
230
+ * @tutorial fdc3v2.raiseIntentForContext
231
231
  */
232
232
  raiseIntentForContext(context: FDC3v2.Context, app?: FDC3v2.AppIdentifier | FDC3v1.TargetApp): Promise<FDC3v2.IntentResolution>;
233
233
  /**
@@ -244,17 +244,17 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
244
244
  * @returns { Promise<Channel> }
245
245
  * @tutorial fdc3.getOrCreateChannel
246
246
  */
247
- getOrCreateChannel(channelId: string): Promise<FDC3v1.Channel>;
247
+ getOrCreateChannel(channelId: string): Promise<FDC3v2.Channel>;
248
248
  /**
249
249
  * 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.
250
250
  * @returns { Promise<PrivateChannel> }
251
- * @tutorial createPrivateChannel
251
+ * @tutorial fdc3v2.createPrivateChannel
252
252
  */
253
253
  createPrivateChannel(): Promise<FDC3v2.PrivateChannel>;
254
254
  /**
255
255
  * Retrieves a list of the User Channels available for the app to join.
256
256
  * @returns { Promise<Channel[]>}
257
- * @tutorial getUserChannels
257
+ * @tutorial fdc3v2.getUserChannels
258
258
  */
259
259
  getUserChannels(): Promise<Array<FDC3v1.SystemChannel>>;
260
260
  /**
@@ -268,7 +268,7 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
268
268
  * Join an app to a specified User channel.
269
269
  * @param { string } channelId Channel name
270
270
  * @returns { Promise<void> }
271
- * @tutorial joinUserChannel
271
+ * @tutorial fdc3v2.joinUserChannel
272
272
  */
273
273
  joinUserChannel(channelId: string): Promise<void>;
274
274
  /**
@@ -282,6 +282,7 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
282
282
  /**
283
283
  * Returns the Channel object for the current User channel membership
284
284
  * @returns { Promise<FDC3.Channel | null> }
285
+ * @tutorial fdc3.getCurrentChannel
285
286
  */
286
287
  getCurrentChannel(): Promise<FDC3v2.Channel | null>;
287
288
  /**
@@ -294,7 +295,7 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
294
295
  * 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.
295
296
  * fdc3HandleGetInfo must be overridden in the InteropBroker so that the ImplementationMetadata will have the appMetadata info.
296
297
  * @returns { Promise<ImplementationMetadata(2)> }
297
- * @tutorial getInfo
298
+ * @tutorial fdc3v2.getInfo
298
299
  */
299
300
  getInfo(): Promise<FDC3v2.ImplementationMetadata>;
300
301
  }
@@ -6,7 +6,6 @@ const InteropClient_1 = require("../InteropClient");
6
6
  const utils_2 = require("./utils");
7
7
  const fdc3_1_2_1 = require("./fdc3-1.2");
8
8
  const PrivateChannelClient_1 = require("./PrivateChannelClient");
9
- const PrivateChannelProvider_1 = require("./PrivateChannelProvider");
10
9
  /**
11
10
  * @typedef { object } AppIdentifier
12
11
  * @summary Identifies an application, or instance of an application, and is used to target FDC3 API calls at specific applications.
@@ -181,7 +180,7 @@ class Fdc3Module2 extends base_1.Base {
181
180
  * Find all the available instances for a particular application.
182
181
  * @param { AppIdentifier } app
183
182
  * @returns { Promise<Array<AppIdentifier>> }
184
- * @tutorial findInstances
183
+ * @tutorial fdc3v2.findInstances
185
184
  */
186
185
  async findInstances(app) {
187
186
  this.wire.sendAction('fdc3-find-instances').catch((e) => {
@@ -199,7 +198,7 @@ class Fdc3Module2 extends base_1.Base {
199
198
  * 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.
200
199
  * @param { AppIdentifier } app
201
200
  * @returns { Promise<AppMetadata(2)> }
202
- * @tutorial getAppMetadata
201
+ * @tutorial fdc3v2.getAppMetadata
203
202
  */
204
203
  async getAppMetadata(app) {
205
204
  this.wire.sendAction('fdc3-get-app-metadata').catch((e) => {
@@ -277,7 +276,7 @@ class Fdc3Module2 extends base_1.Base {
277
276
  * @param { Context } context
278
277
  * @param { string } [resultType] The type of result returned for any intent specified during resolution.
279
278
  * @returns { Promise<Array<AppIntent(2)>> }
280
- * @tutorial findIntentsByContext
279
+ * @tutorial fdc3v2.findIntentsByContext
281
280
  */
282
281
  async findIntentsByContext(context, resultType) {
283
282
  this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
@@ -298,7 +297,7 @@ class Fdc3Module2 extends base_1.Base {
298
297
  * @param { Context } context Context associated with the Intent
299
298
  * @param { AppIdentifier | TargetApp } [app]
300
299
  * @returns { Promise<IntentResolution(2)> }
301
- * @tutorial raiseIntent
300
+ * @tutorial fdc3v2.raiseIntent
302
301
  */
303
302
  async raiseIntent(intent, context, app) {
304
303
  this.wire.sendAction('fdc3-raise-intent').catch((e) => {
@@ -317,7 +316,7 @@ class Fdc3Module2 extends base_1.Base {
317
316
  * @param { Context } context Context associated with the Intent
318
317
  * @param { AppIdentifier | TargetApp } [app]
319
318
  * @returns { Promise<IntentResolution(2)> }
320
- * @tutorial raiseIntentForContext
319
+ * @tutorial fdc3v2.raiseIntentForContext
321
320
  */
322
321
  async raiseIntentForContext(context, app) {
323
322
  // TODO: We have to do the same thing we do for raiseIntent here as well.
@@ -349,27 +348,27 @@ class Fdc3Module2 extends base_1.Base {
349
348
  // The FDC3 Intenter handler only expects the context and contextMetadata to be passed to the handler,
350
349
  // so we wrap it here and only pass those paramaters.
351
350
  const contextHandler = async (raisedIntent) => {
351
+ let intentResult;
352
+ let intentResultToSend;
352
353
  const { context, metadata: intentMetadata } = raisedIntent;
353
354
  const { contextMetadata, metadata, ...rest } = context;
354
- let intentResult;
355
+ const intentResolutionResultId = (intentMetadata === null || intentMetadata === void 0 ? void 0 : intentMetadata.intentResolutionResultId) || (metadata === null || metadata === void 0 ? void 0 : metadata.intentResolutionResultId);
355
356
  try {
356
357
  const newContext = metadata ? { metadata, ...rest } : { ...rest };
357
358
  intentResult = await handler(newContext, contextMetadata);
359
+ intentResultToSend = intentResult;
358
360
  }
359
361
  catch (error) {
360
362
  intentResult = error;
363
+ intentResultToSend = { error: true };
361
364
  }
362
- const intentResolutionResultId = (intentMetadata === null || intentMetadata === void 0 ? void 0 : intentMetadata.intentResolutionResultId) || (metadata === null || metadata === void 0 ? void 0 : metadata.intentResolutionResultId);
363
365
  if (intentResolutionResultId) {
364
- // Send whatever the result is.
365
- this.fin.InterApplicationBus.publish(intentResolutionResultId, intentResult);
366
+ this.fin.InterApplicationBus.publish(intentResolutionResultId, intentResultToSend);
366
367
  }
367
368
  if (intentResult instanceof Error) {
368
369
  throw new Error(intentResult.message);
369
370
  }
370
- else {
371
- return intentResult;
372
- }
371
+ return intentResult;
373
372
  };
374
373
  return this.fin.me.interop.registerIntentHandler(contextHandler, intent, { fdc3Version: '2.0' });
375
374
  }
@@ -385,12 +384,11 @@ class Fdc3Module2 extends base_1.Base {
385
384
  /**
386
385
  * 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.
387
386
  * @returns { Promise<PrivateChannel> }
388
- * @tutorial createPrivateChannel
387
+ * @tutorial fdc3v2.createPrivateChannel
389
388
  */
390
389
  async createPrivateChannel() {
391
390
  const channelId = (0, utils_1.generateId)();
392
- const channelProvider = await this.fin.InterApplicationBus.Channel.create(channelId);
393
- const newPrivateChannelProvider = new PrivateChannelProvider_1.PrivateChannelProvider(channelProvider, channelId);
391
+ await InteropClient_1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'createPrivateChannelProvider', { channelId });
394
392
  const channelClient = await this.fin.InterApplicationBus.Channel.connect(channelId);
395
393
  const newPrivateChannelClient = new PrivateChannelClient_1.PrivateChannelClient(channelClient, channelId);
396
394
  return (0, utils_2.buildPrivateChannelObject)(newPrivateChannelClient);
@@ -398,7 +396,7 @@ class Fdc3Module2 extends base_1.Base {
398
396
  /**
399
397
  * Retrieves a list of the User Channels available for the app to join.
400
398
  * @returns { Promise<Channel[]>}
401
- * @tutorial getUserChannels
399
+ * @tutorial fdc3v2.getUserChannels
402
400
  */
403
401
  async getUserChannels() {
404
402
  const channels = await this.fin.me.interop.getContextGroups();
@@ -422,7 +420,7 @@ class Fdc3Module2 extends base_1.Base {
422
420
  * Join an app to a specified User channel.
423
421
  * @param { string } channelId Channel name
424
422
  * @returns { Promise<void> }
425
- * @tutorial joinUserChannel
423
+ * @tutorial fdc3v2.joinUserChannel
426
424
  */
427
425
  async joinUserChannel(channelId) {
428
426
  return this.fdc3Module.joinChannel(channelId);
@@ -441,6 +439,7 @@ class Fdc3Module2 extends base_1.Base {
441
439
  /**
442
440
  * Returns the Channel object for the current User channel membership
443
441
  * @returns { Promise<FDC3.Channel | null> }
442
+ * @tutorial fdc3.getCurrentChannel
444
443
  */
445
444
  async getCurrentChannel() {
446
445
  const currentChannel = await this.fdc3Module.getCurrentChannel();
@@ -465,7 +464,7 @@ class Fdc3Module2 extends base_1.Base {
465
464
  * 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.
466
465
  * fdc3HandleGetInfo must be overridden in the InteropBroker so that the ImplementationMetadata will have the appMetadata info.
467
466
  * @returns { Promise<ImplementationMetadata(2)> }
468
- * @tutorial getInfo
467
+ * @tutorial fdc3v2.getInfo
469
468
  */
470
469
  async getInfo() {
471
470
  return InteropClient_1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'fdc3v2GetInfo', { fdc3Version: '2.0' });
@@ -8,8 +8,8 @@ export type { Listener } from 'fdc3v1/src/api/Listener';
8
8
  export type { AppMetadata } from 'fdc3v1/src/api/AppMetadata';
9
9
  export type { AppIntent } from 'fdc3v1/src/api/AppIntent';
10
10
  export type { ImplementationMetadata } from 'fdc3v1/src/api/ImplementationMetadata';
11
- export declare type ContextHandler = (context: Context) => void;
12
- export declare type TargetApp = string | AppMetadata;
11
+ export type ContextHandler = (context: Context) => void;
12
+ export type TargetApp = string | AppMetadata;
13
13
  export interface Context {
14
14
  id?: {
15
15
  [key: string]: string;
@@ -30,7 +30,7 @@ export interface Channel {
30
30
  getCurrentContext(contextType?: string): Promise<Context | null>;
31
31
  addContextListener(contextType: string | null, handler: ContextHandler): Listener & Promise<Listener>;
32
32
  }
33
- export declare type SystemChannel = Omit<Channel, 'addContextListener' | 'broadcast' | 'getCurrentContext'> & {
33
+ export type SystemChannel = Omit<Channel, 'addContextListener' | 'broadcast' | 'getCurrentContext'> & {
34
34
  addContextListener(): Error;
35
35
  broadcast(): Error;
36
36
  getCurrentContext(): Error;
@@ -14,9 +14,9 @@ export type { ContextMetadata } from 'fdc3v2/src/api/ContextMetadata';
14
14
  export type { AppIdentifier } from 'fdc3v2/src/api/AppIdentifier';
15
15
  export type { AppMetadata } from 'fdc3v2/src/api/AppMetadata';
16
16
  export type { DisplayMetadata } from 'fdc3v2/src/api/DisplayMetadata';
17
- export declare type ContextHandler = (context: Context, metadata?: ContextMetadata) => void;
18
- export declare type IntentHandler = (context: Context, metadata?: ContextMetadata) => Promise<IntentResult> | void;
19
- export declare type IntentResult = Context | Channel | PrivateChannel;
17
+ export type ContextHandler = (context: Context, metadata?: ContextMetadata) => void;
18
+ export type IntentHandler = (context: Context, metadata?: ContextMetadata) => Promise<IntentResult> | void;
19
+ export type IntentResult = Context | Channel | PrivateChannel;
20
20
  export interface Context {
21
21
  id?: {
22
22
  [key: string]: string;
@@ -45,7 +45,7 @@ export interface Channel {
45
45
  getCurrentContext(contextType?: string): Promise<Context | null>;
46
46
  addContextListener(contextType: string | null, handler: ContextHandler): Listener & Promise<Listener>;
47
47
  }
48
- export declare type PrivateChannel = Omit<Channel, 'addContextListener'> & {
48
+ export type PrivateChannel = Omit<Channel, 'addContextListener'> & {
49
49
  addContextListener(contextType: string | null, handler: ContextHandler): Promise<Listener>;
50
50
  onAddContextListener(handler: (contextType?: string) => void): Listener;
51
51
  onUnsubscribe(handler: (contextType?: string) => void): Listener;
@@ -64,7 +64,7 @@ export interface DesktopAgent {
64
64
  addContextListener(contextType: string | null, handler: ContextHandler): Promise<Listener>;
65
65
  getUserChannels(): Promise<Array<SystemChannel>>;
66
66
  joinUserChannel(channelId: string): Promise<void>;
67
- getOrCreateChannel(channelId: string): Promise<ChannelV1>;
67
+ getOrCreateChannel(channelId: string): Promise<Channel>;
68
68
  createPrivateChannel(): Promise<PrivateChannel>;
69
69
  getCurrentChannel(): Promise<ChannelV1 | null>;
70
70
  leaveCurrentChannel(): Promise<void>;
@@ -21,8 +21,25 @@ export declare enum ResultError {
21
21
  */
22
22
  IntentHandlerRejected = "IntentHandlerRejected"
23
23
  }
24
+ export declare enum ChannelError {
25
+ /** Returned if the specified channel is not found when attempting to join a
26
+ * channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).
27
+ */
28
+ NoChannelFound = "NoChannelFound",
29
+ /** SHOULD be returned when a request to join a user channel or to a retrieve
30
+ * a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods
31
+ * of the DesktopAgent (`fdc3`) object is denied.
32
+ */
33
+ AccessDenied = "AccessDenied",
34
+ /** SHOULD be returned when a channel cannot be created or retrieved via the
35
+ * `getOrCreateChannel` method of the DesktopAgent (`fdc3`).
36
+ */
37
+ CreationFailed = "CreationFailed"
38
+ }
24
39
  export declare const buildPrivateChannelObject: (privateChannelClient: PrivateChannelClient) => PrivateChannel;
25
40
  export declare const buildAppChannelObject: (sessionContextGroup: OpenFin.SessionContextGroup) => Channel;
26
41
  export declare const connectPrivateChannel: (channelId: string) => Promise<PrivateChannel>;
42
+ export declare const isContext: (context: unknown) => context is Context;
43
+ export declare const isChannel: (channel: unknown) => channel is Channel;
27
44
  export declare const getIntentResolution: (interopModule: OpenFin.InteropClient, context: Context, app?: AppIdentifier | TargetApp, intent?: string) => Promise<IntentResolution>;
28
45
  export {};
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIntentResolution = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
3
+ exports.getIntentResolution = exports.isChannel = exports.isContext = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ChannelError = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  const PrivateChannelClient_1 = require("./PrivateChannelClient");
6
+ const lodash_1 = require("lodash");
6
7
  const getUnsupportedChannelApis = (channelType) => {
7
8
  return {
8
9
  addContextListener: () => {
@@ -35,6 +36,22 @@ var ResultError;
35
36
  */
36
37
  ResultError["IntentHandlerRejected"] = "IntentHandlerRejected";
37
38
  })(ResultError = exports.ResultError || (exports.ResultError = {}));
39
+ var ChannelError;
40
+ (function (ChannelError) {
41
+ /** Returned if the specified channel is not found when attempting to join a
42
+ * channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).
43
+ */
44
+ ChannelError["NoChannelFound"] = "NoChannelFound";
45
+ /** SHOULD be returned when a request to join a user channel or to a retrieve
46
+ * a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods
47
+ * of the DesktopAgent (`fdc3`) object is denied.
48
+ */
49
+ ChannelError["AccessDenied"] = "AccessDenied";
50
+ /** SHOULD be returned when a channel cannot be created or retrieved via the
51
+ * `getOrCreateChannel` method of the DesktopAgent (`fdc3`).
52
+ */
53
+ ChannelError["CreationFailed"] = "CreationFailed";
54
+ })(ChannelError = exports.ChannelError || (exports.ChannelError = {}));
38
55
  const buildPrivateChannelObject = (privateChannelClient) => {
39
56
  let clientDisconnected = false;
40
57
  const checkIfClientDisconnected = () => {
@@ -95,14 +112,33 @@ const buildAppChannelObject = (sessionContextGroup) => {
95
112
  return context === undefined ? null : context;
96
113
  },
97
114
  addContextListener: (contextType, handler) => {
98
- let listener;
115
+ let realHandler;
116
+ let realType;
99
117
  if (typeof contextType === 'function') {
100
118
  console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
101
- listener = sessionContextGroup.addContextHandler(contextType);
119
+ realHandler = contextType;
102
120
  }
103
121
  else {
104
- listener = sessionContextGroup.addContextHandler(handler, contextType === null ? undefined : contextType);
122
+ realHandler = handler;
123
+ if (typeof contextType === 'string') {
124
+ realType = contextType;
125
+ }
105
126
  }
127
+ const listener = (async () => {
128
+ let first = true;
129
+ const currentContext = await sessionContextGroup.getCurrentContext(realType);
130
+ const wrappedHandler = (context, contextMetadata) => {
131
+ if (first) {
132
+ first = false;
133
+ if ((0, lodash_1.isEqual)(currentContext, context)) {
134
+ return;
135
+ }
136
+ }
137
+ // eslint-disable-next-line consistent-return
138
+ return realHandler(context, contextMetadata);
139
+ };
140
+ return sessionContextGroup.addContextHandler(wrappedHandler, realType);
141
+ })();
106
142
  return {
107
143
  ...listener,
108
144
  unsubscribe: () => listener.then((l) => l.unsubscribe())
@@ -122,6 +158,22 @@ const connectPrivateChannel = async (channelId) => {
122
158
  }
123
159
  };
124
160
  exports.connectPrivateChannel = connectPrivateChannel;
161
+ const isContext = (context) => {
162
+ if (context && typeof context === 'object' && 'type' in context) {
163
+ const { type } = context;
164
+ return typeof type === 'string';
165
+ }
166
+ return false;
167
+ };
168
+ exports.isContext = isContext;
169
+ const isChannel = (channel) => {
170
+ if (channel && typeof channel === 'object' && 'type' in channel && 'id' in channel) {
171
+ const { type, id } = channel;
172
+ return typeof type === 'string' && typeof id === 'string' && (type === 'app' || type === 'private');
173
+ }
174
+ return false;
175
+ };
176
+ exports.isChannel = isChannel;
125
177
  const getIntentResolution = async (interopModule, context, app, intent) => {
126
178
  // Generate an ID to make a session context group with. We will pass that ID to the Broker.
127
179
  // The broker will then setContext on that session context group later with our Intent Result,
@@ -138,31 +190,33 @@ const getIntentResolution = async (interopModule, context, app, intent) => {
138
190
  // Set up the getResult call.
139
191
  const getResult = async () => {
140
192
  let intentResult = await getResultPromise;
141
- if (!intentResult) {
193
+ if (!intentResult || typeof intentResult !== 'object') {
142
194
  throw new Error(ResultError.NoResultReturned);
143
195
  }
144
- if (intentResult instanceof Error) {
196
+ const { error } = intentResult;
197
+ if (error) {
145
198
  throw new Error(ResultError.IntentHandlerRejected);
146
199
  }
147
- if (typeof intentResult === 'object') {
200
+ if ((0, exports.isChannel)(intentResult)) {
148
201
  const { id, type } = intentResult;
149
- if (type && id && typeof id === 'string') {
150
- switch (type) {
151
- case 'private': {
152
- intentResult = await (0, exports.connectPrivateChannel)(id);
153
- break;
154
- }
155
- case 'app': {
156
- const sessionContextGroup = await interopModule.joinSessionContextGroup(id);
157
- intentResult = (0, exports.buildAppChannelObject)(sessionContextGroup);
158
- break;
159
- }
160
- default: {
161
- break;
162
- }
202
+ switch (type) {
203
+ case 'private': {
204
+ intentResult = await (0, exports.connectPrivateChannel)(id);
205
+ break;
206
+ }
207
+ case 'app': {
208
+ const sessionContextGroup = await interopModule.joinSessionContextGroup(id);
209
+ intentResult = (0, exports.buildAppChannelObject)(sessionContextGroup);
210
+ break;
211
+ }
212
+ default: {
213
+ break;
163
214
  }
164
215
  }
165
216
  }
217
+ else if (!(0, exports.isContext)(intentResult)) {
218
+ throw new Error(ResultError.NoResultReturned);
219
+ }
166
220
  return intentResult;
167
221
  };
168
222
  // Finally fire the intent.
@@ -1 +1 @@
1
- export declare type Fdc3Version = '1.2' | '2.0';
1
+ export type Fdc3Version = '1.2' | '2.0';
@@ -16,4 +16,3 @@ export declare const BROKER_ERRORS: {
16
16
  fdc3GetInfo: string;
17
17
  };
18
18
  export declare const wrapIntentHandler: (handler: OpenFin.IntentHandler, handlerId: string) => (intent: OpenFin.Intent) => Promise<void>;
19
- export declare const generateDefaultLoggingOptions: () => OpenFin.InteropLoggingOptions;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateDefaultLoggingOptions = exports.wrapIntentHandler = exports.BROKER_ERRORS = exports.generateOverrideWarning = exports.generateOverrideError = exports.wrapContextHandler = exports.wrapInTryCatch = exports.generateId = void 0;
3
+ exports.wrapIntentHandler = exports.BROKER_ERRORS = exports.generateOverrideWarning = exports.generateOverrideError = exports.wrapContextHandler = exports.wrapInTryCatch = exports.generateId = void 0;
4
4
  const generateId = () => `${Math.random()}${Date.now()}`;
5
5
  exports.generateId = generateId;
6
6
  const wrapInTryCatch = (f, prefix) => (...args) => {
@@ -59,11 +59,3 @@ const wrapIntentHandler = (handler, handlerId) => {
59
59
  };
60
60
  };
61
61
  exports.wrapIntentHandler = wrapIntentHandler;
62
- const generateDefaultLoggingOptions = () => {
63
- const loggingActions = ['beforeAction', 'afterAction'];
64
- const options = loggingActions.reduce((accumulator, loggingOption) => {
65
- return { ...accumulator, [loggingOption]: { enabled: true } };
66
- }, {});
67
- return options;
68
- };
69
- exports.generateDefaultLoggingOptions = generateDefaultLoggingOptions;
package/src/api/me.d.ts CHANGED
@@ -2,8 +2,8 @@ import type * as OpenFin from '../OpenFin';
2
2
  import type { Transport } from '../transport/transport';
3
3
  import type { InteropClient } from './interop';
4
4
  export declare const environmentUnsupportedMessage = "You are not running in OpenFin.";
5
- declare type EntityType = OpenFin.EntityType;
6
- export declare type EntityTypeHelpers<T extends EntityType> = T extends 'view' ? {
5
+ type EntityType = OpenFin.EntityType;
6
+ export type EntityTypeHelpers<T extends EntityType> = T extends 'view' ? {
7
7
  isView: true;
8
8
  isWindow: false;
9
9
  isExternal: false;
@@ -33,7 +33,7 @@ export declare function getBaseMe<T extends EntityType = EntityType>(entityType:
33
33
  export interface WithInterop {
34
34
  interop: InteropClient;
35
35
  }
36
- export declare type Me<MeType extends EntityType> = OpenFin.EntityInfo & (MeType extends 'view' ? EntityTypeHelpers<'view'> & OpenFin.View & WithInterop : MeType extends 'window' ? EntityTypeHelpers<'window'> & OpenFin.Window & WithInterop : MeType extends 'iframe' ? EntityTypeHelpers<'iframe'> & OpenFin.Frame & WithInterop : EntityTypeHelpers<MeType> & WithInterop) & {
36
+ export type Me<MeType extends EntityType> = OpenFin.EntityInfo & (MeType extends 'view' ? EntityTypeHelpers<'view'> & OpenFin.View & WithInterop : MeType extends 'window' ? EntityTypeHelpers<'window'> & OpenFin.Window & WithInterop : MeType extends 'iframe' ? EntityTypeHelpers<'iframe'> & OpenFin.Frame & WithInterop : EntityTypeHelpers<MeType> & WithInterop) & {
37
37
  isOpenFin: boolean;
38
38
  };
39
39
  export declare function getMe<MeType extends EntityType>(wire: Transport<MeType>): Me<MeType>;
@@ -77,7 +77,7 @@ class PlatformModule extends base_1.Base {
77
77
  const overrideCallback = options === null || options === void 0 ? void 0 : options.overrideCallback;
78
78
  const interopBroker = await this.fin.Interop.init(this.fin.me.uuid, options === null || options === void 0 ? void 0 : options.interopOverride);
79
79
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
80
- // @ts-ignore debugging purposes
80
+ // @ts-expect-error debugging purposes
81
81
  window.interopBroker = interopBroker;
82
82
  return this._initializer(overrideCallback, interopBroker);
83
83
  }
@@ -147,14 +147,12 @@ class PlatformModule extends base_1.Base {
147
147
  return new Promise(async (resolve, reject) => {
148
148
  try {
149
149
  const { uuid } = platformOptions;
150
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
151
- // @ts-ignore using private variable.
150
+ // @ts-expect-error using private variable.
152
151
  const app = await this.fin.Application._create({ ...platformOptions, isPlatformController: true });
153
152
  // TODO: fix typing (internal)
154
153
  // @ts-expect-error
155
154
  app.once('platform-api-ready', () => resolve(this.wrapSync({ uuid })));
156
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
157
- // @ts-ignore using private variable.
155
+ // @ts-expect-error using private variable.
158
156
  app._run({ uuid });
159
157
  }
160
158
  catch (e) {
@@ -178,14 +176,12 @@ class PlatformModule extends base_1.Base {
178
176
  // eslint-disable-next-line no-async-promise-executor
179
177
  return new Promise(async (resolve, reject) => {
180
178
  try {
181
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
182
- // @ts-ignore using private variable.
179
+ // @ts-expect-error using private variable.
183
180
  const app = await this.fin.Application._createFromManifest(manifestUrl);
184
181
  // TODO: fix typing (internal)
185
182
  // @ts-expect-error
186
183
  app.once('platform-api-ready', () => resolve(this.wrapSync({ uuid: app.identity.uuid })));
187
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
188
- // @ts-ignore using private method without warning.
184
+ // @ts-expect-error using private method without warning.
189
185
  app._run(opts);
190
186
  }
191
187
  catch (e) {
@@ -27,7 +27,7 @@ export declare class Platform extends EmitterBase<OpenFin.PlatformEvent> {
27
27
  * @return { Promise<View> }
28
28
  * @tutorial Platform.createView
29
29
  */
30
- createView(viewOptions: OpenFin.PlatformViewCreationOptions, target?: OpenFin.Identity, targetView?: OpenFin.Identity): Promise<View>;
30
+ createView(viewOptions: OpenFin.PlatformViewCreationOptions, target?: OpenFin.CreateViewTarget, targetView?: OpenFin.Identity): Promise<View>;
31
31
  /**
32
32
  * Creates a new Window.
33
33
  * @param { Window~options } options Window creation options