@openfin/fdc3-api 41.100.29 → 41.100.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/out/fdc3-api.js CHANGED
@@ -10,7 +10,7 @@ var utils$2 = {};
10
10
 
11
11
  (function (exports) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.wrapIntentHandler = exports.BROKER_ERRORS = exports.generateOverrideWarning = exports.generateOverrideError = exports.wrapContextHandler = exports.wrapInTryCatch = exports.generateId = void 0;
13
+ exports.checkContextIntegrity = exports.wrapIntentHandler = exports.BROKER_ERRORS = exports.generateOverrideWarning = exports.generateOverrideError = exports.wrapContextHandler = exports.wrapInTryCatch = exports.generateId = void 0;
14
14
  const generateId = () => `${Math.random()}${Date.now()}`;
15
15
  exports.generateId = generateId;
16
16
  const wrapInTryCatch = (f, prefix) => (...args) => {
@@ -68,7 +68,45 @@ var utils$2 = {};
68
68
  }
69
69
  };
70
70
  };
71
- exports.wrapIntentHandler = wrapIntentHandler;
71
+ exports.wrapIntentHandler = wrapIntentHandler;
72
+ const checkContextIntegrity = (context) => {
73
+ if (!context) {
74
+ return { isValid: false, reason: 'No context supplied' };
75
+ }
76
+ if (typeof context !== 'object') {
77
+ return { isValid: false, reason: 'Context must be an Object' };
78
+ }
79
+ if (!context.type) {
80
+ return { isValid: false, reason: 'Context must have a type property' };
81
+ }
82
+ if (context.id && typeof context.id !== 'object') {
83
+ return {
84
+ isValid: false,
85
+ reason: 'Context id must be an Object populated with key-value identifiers (if set)'
86
+ };
87
+ }
88
+ if (context.id) {
89
+ const { id } = context;
90
+ const keys = Object.keys(id);
91
+ let foundBadIdentifier = false;
92
+ if (!keys.length) {
93
+ return { isValid: false, reason: 'Context id must have at least one key-value identifier' };
94
+ }
95
+ keys.forEach((key) => {
96
+ if (typeof key !== 'string' || typeof id[key] !== 'string') {
97
+ foundBadIdentifier = true;
98
+ }
99
+ });
100
+ if (foundBadIdentifier) {
101
+ return { isValid: false, reason: 'Context id key-value identifiers must be of type string' };
102
+ }
103
+ }
104
+ if (context.name && typeof context.name !== 'string') {
105
+ return { isValid: false, reason: 'Context name must be of string type (if set)' };
106
+ }
107
+ return { isValid: true };
108
+ };
109
+ exports.checkContextIntegrity = checkContextIntegrity;
72
110
  } (utils$2));
73
111
 
74
112
  var fdc3Common = {};
@@ -432,7 +470,7 @@ PrivateChannelClient$1.PrivateChannelClient = PrivateChannelClient;
432
470
  exports.getIntentResolution = getIntentResolution;
433
471
  } (utils$1));
434
472
 
435
- var InteropClient = {};
473
+ var InteropClient$1 = {};
436
474
 
437
475
  var base = {};
438
476
 
@@ -465,13 +503,13 @@ async function promiseMapSerial(arr, func) {
465
503
  }
466
504
  promises.promiseMapSerial = promiseMapSerial;
467
505
 
468
- var __classPrivateFieldSet$1 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
506
+ var __classPrivateFieldSet$3 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
469
507
  if (kind === "m") throw new TypeError("Private method is not writable");
470
508
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
471
509
  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");
472
510
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
473
511
  };
474
- var __classPrivateFieldGet$1 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
512
+ var __classPrivateFieldGet$3 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
475
513
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
476
514
  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");
477
515
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
@@ -555,8 +593,8 @@ class EmitterBase extends Base {
555
593
  this.emit = (eventType, payload, ...args) => {
556
594
  return this.hasEmitter() ? this.getOrCreateEmitter().emit(eventType, payload, ...args) : false;
557
595
  };
558
- this.hasEmitter = () => this.wire.eventAggregator.has(__classPrivateFieldGet$1(this, _EmitterBase_emitterAccessor, "f"));
559
- this.getOrCreateEmitter = () => this.wire.eventAggregator.getOrCreate(__classPrivateFieldGet$1(this, _EmitterBase_emitterAccessor, "f"));
596
+ this.hasEmitter = () => this.wire.eventAggregator.has(__classPrivateFieldGet$3(this, _EmitterBase_emitterAccessor, "f"));
597
+ this.getOrCreateEmitter = () => this.wire.eventAggregator.getOrCreate(__classPrivateFieldGet$3(this, _EmitterBase_emitterAccessor, "f"));
560
598
  this.listeners = (type) => this.hasEmitter() ? this.getOrCreateEmitter().listeners(type) : [];
561
599
  this.listenerCount = (type) => this.hasEmitter() ? this.getOrCreateEmitter().listenerCount(type) : 0;
562
600
  this.registerEventListener = async (eventType, options = {}, applySubscription, undoSubscription) => {
@@ -594,7 +632,7 @@ class EmitterBase extends Base {
594
632
  // This will only be reached if unsubscribe from event that does not exist but do not want to error here
595
633
  return Promise.resolve();
596
634
  };
597
- __classPrivateFieldSet$1(this, _EmitterBase_emitterAccessor, [topic, ...additionalAccessors], "f");
635
+ __classPrivateFieldSet$3(this, _EmitterBase_emitterAccessor, [topic, ...additionalAccessors], "f");
598
636
  this.listeners = (event) => this.hasEmitter() ? this.getOrCreateEmitter().listeners(event) : [];
599
637
  }
600
638
  /**
@@ -712,7 +750,7 @@ class EmitterBase extends Base {
712
750
  }
713
751
  deleteEmitterIfNothingRegistered(emitter) {
714
752
  if (emitter.eventNames().length === 0) {
715
- this.wire.eventAggregator.delete(__classPrivateFieldGet$1(this, _EmitterBase_emitterAccessor, "f"));
753
+ this.wire.eventAggregator.delete(__classPrivateFieldGet$3(this, _EmitterBase_emitterAccessor, "f"));
716
754
  }
717
755
  }
718
756
  }
@@ -724,27 +762,27 @@ base.Reply = Reply;
724
762
 
725
763
  var SessionContextGroupClient$1 = {};
726
764
 
727
- var __classPrivateFieldSet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
765
+ var __classPrivateFieldSet$2 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
728
766
  if (kind === "m") throw new TypeError("Private method is not writable");
729
767
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
730
768
  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");
731
769
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
732
770
  };
733
- var __classPrivateFieldGet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
771
+ var __classPrivateFieldGet$2 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
734
772
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
735
773
  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");
736
774
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
737
775
  };
738
776
  var _SessionContextGroupClient_clientPromise;
739
777
  Object.defineProperty(SessionContextGroupClient$1, "__esModule", { value: true });
740
- const base_1 = base;
741
- const utils_1 = utils$2;
742
- class SessionContextGroupClient extends base_1.Base {
778
+ const base_1$1 = base;
779
+ const utils_1$4 = utils$2;
780
+ class SessionContextGroupClient extends base_1$1.Base {
743
781
  constructor(wire, client, id) {
744
782
  super(wire);
745
783
  _SessionContextGroupClient_clientPromise.set(this, void 0);
746
784
  this.id = id;
747
- __classPrivateFieldSet(this, _SessionContextGroupClient_clientPromise, client, "f");
785
+ __classPrivateFieldSet$2(this, _SessionContextGroupClient_clientPromise, client, "f");
748
786
  }
749
787
  /**
750
788
  * Sets a context for the session context group.
@@ -756,7 +794,7 @@ class SessionContextGroupClient extends base_1.Base {
756
794
  this.wire.sendAction('interop-session-context-group-set-context').catch((e) => {
757
795
  // don't expose, analytics-only call
758
796
  });
759
- const client = await __classPrivateFieldGet(this, _SessionContextGroupClient_clientPromise, "f");
797
+ const client = await __classPrivateFieldGet$2(this, _SessionContextGroupClient_clientPromise, "f");
760
798
  return client.dispatch(`sessionContextGroup:setContext-${this.id}`, {
761
799
  sessionContextGroupId: this.id,
762
800
  context
@@ -766,7 +804,7 @@ class SessionContextGroupClient extends base_1.Base {
766
804
  this.wire.sendAction('interop-session-context-group-get-context').catch((e) => {
767
805
  // don't expose, analytics-only call
768
806
  });
769
- const client = await __classPrivateFieldGet(this, _SessionContextGroupClient_clientPromise, "f");
807
+ const client = await __classPrivateFieldGet$2(this, _SessionContextGroupClient_clientPromise, "f");
770
808
  return client.dispatch(`sessionContextGroup:getContext-${this.id}`, {
771
809
  sessionContextGroupId: this.id,
772
810
  type
@@ -779,20 +817,20 @@ class SessionContextGroupClient extends base_1.Base {
779
817
  if (typeof contextHandler !== 'function') {
780
818
  throw new Error("Non-function argument passed to the first parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
781
819
  }
782
- const client = await __classPrivateFieldGet(this, _SessionContextGroupClient_clientPromise, "f");
820
+ const client = await __classPrivateFieldGet$2(this, _SessionContextGroupClient_clientPromise, "f");
783
821
  let handlerId;
784
822
  if (contextType) {
785
- handlerId = `sessionContextHandler:invoke-${this.id}-${contextType}-${(0, utils_1.generateId)()}`;
823
+ handlerId = `sessionContextHandler:invoke-${this.id}-${contextType}-${(0, utils_1$4.generateId)()}`;
786
824
  }
787
825
  else {
788
826
  handlerId = `sessionContextHandler:invoke-${this.id}`;
789
827
  }
790
- client.register(handlerId, (0, utils_1.wrapContextHandler)(contextHandler, handlerId));
828
+ client.register(handlerId, (0, utils_1$4.wrapContextHandler)(contextHandler, handlerId));
791
829
  await client.dispatch(`sessionContextGroup:handlerAdded-${this.id}`, { handlerId, contextType });
792
830
  return { unsubscribe: await this.createUnsubscribeCb(handlerId) };
793
831
  }
794
832
  async createUnsubscribeCb(handlerId) {
795
- const client = await __classPrivateFieldGet(this, _SessionContextGroupClient_clientPromise, "f");
833
+ const client = await __classPrivateFieldGet$2(this, _SessionContextGroupClient_clientPromise, "f");
796
834
  return async () => {
797
835
  client.remove(handlerId);
798
836
  await client.dispatch(`sessionContextGroup:handlerRemoved-${this.id}`, { handlerId });
@@ -801,1443 +839,1406 @@ class SessionContextGroupClient extends base_1.Base {
801
839
  getUserInstance() {
802
840
  return {
803
841
  id: this.id,
804
- setContext: (0, utils_1.wrapInTryCatch)(this.setContext.bind(this), 'Failed to set context: '),
805
- getCurrentContext: (0, utils_1.wrapInTryCatch)(this.getCurrentContext.bind(this), 'Failed to get context: '),
806
- addContextHandler: (0, utils_1.wrapInTryCatch)(this.addContextHandler.bind(this), 'Failed to add context handler: ')
842
+ setContext: (0, utils_1$4.wrapInTryCatch)(this.setContext.bind(this), 'Failed to set context: '),
843
+ getCurrentContext: (0, utils_1$4.wrapInTryCatch)(this.getCurrentContext.bind(this), 'Failed to get context: '),
844
+ addContextHandler: (0, utils_1$4.wrapInTryCatch)(this.addContextHandler.bind(this), 'Failed to add context handler: ')
807
845
  };
808
846
  }
809
847
  }
810
848
  SessionContextGroupClient$1.default = SessionContextGroupClient;
811
849
  _SessionContextGroupClient_clientPromise = new WeakMap();
812
850
 
813
- var fdc32_0 = {};
814
-
815
- var hasRequiredFdc32_0;
851
+ var __classPrivateFieldSet$1 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
852
+ if (kind === "m") throw new TypeError("Private method is not writable");
853
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
854
+ 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");
855
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
856
+ };
857
+ var __classPrivateFieldGet$1 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
858
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
859
+ 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");
860
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
861
+ };
862
+ var __importDefault$1 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
863
+ return (mod && mod.__esModule) ? mod : { "default": mod };
864
+ };
865
+ var _InteropClient_clientPromise, _InteropClient_sessionContextGroups, _InteropClient_fdc3Factory;
866
+ Object.defineProperty(InteropClient$1, "__esModule", { value: true });
867
+ InteropClient$1.InteropClient = void 0;
868
+ const base_1 = base;
869
+ const SessionContextGroupClient_1 = __importDefault$1(SessionContextGroupClient$1);
870
+ const utils_1$3 = utils$2;
871
+ /**
872
+ * The Interop Client API is broken up into two groups:
873
+ *
874
+ * **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.
875
+ *
876
+ * **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.
877
+ *
878
+ * ---
879
+ *
880
+ * All APIs are available at the `fin.me.interop` namespace.
881
+ *
882
+ * ---
883
+ *
884
+ * **You only need 2 things to participate in Interop Context Grouping:**
885
+ * * A Context Handler for incoming context: {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
886
+ * * Call setContext on your context group when you want to share context with other group members: {@link InteropClient#setContext setContext(context)}
887
+ *
888
+ * ---
889
+ *
890
+ * ##### Constructor
891
+ * Returned by {@link Interop.connectSync Interop.connectSync}.
892
+ *
893
+ * ---
894
+ *
895
+ * ##### Interop methods intended for Views
896
+ *
897
+ *
898
+ * **Context Groups API**
899
+ * * {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
900
+ * * {@link InteropClient#setContext setContext(context)}
901
+ * * {@link InteropClient#getCurrentContext getCurrentContext(contextType?)}
902
+ * * {@link InteropClient#joinSessionContextGroup joinSessionContextGroup(sessionContextGroupId)}
903
+ *
904
+ *
905
+ * **Intents API**
906
+ * * {@link InteropClient#fireIntent fireIntent(intent)}
907
+ * * {@link InteropClient#registerIntentHandler registerIntentHandler(intentHandler, intentName)}
908
+ * * {@link InteropClient#getInfoForIntent getInfoForIntent(infoForIntentOptions)}
909
+ * * {@link InteropClient#getInfoForIntentsByContext getInfoForIntentsByContext(context)}
910
+ * * {@link InteropClient#fireIntentForContext fireIntentForContext(contextForIntent)}
911
+ *
912
+ * ##### Interop methods intended for Windows
913
+ * * {@link InteropClient#getContextGroups getContextGroups()}
914
+ * * {@link InteropClient#joinContextGroup joinContextGroup(contextGroupId, target?)}
915
+ * * {@link InteropClient#removeFromContextGroup removeFromContextGroup(target?)}
916
+ * * {@link InteropClient#getInfoForContextGroup getInfoForContextGroup(contextGroupId)}
917
+ * * {@link InteropClient#getAllClientsInContextGroup getAllClientsInContextGroup(contextGroupId)}
918
+ *
919
+ */
920
+ class InteropClient extends base_1.Base {
921
+ /**
922
+ * @internal
923
+ */
924
+ constructor(wire, clientPromise, fdc3Factory) {
925
+ super(wire);
926
+ _InteropClient_clientPromise.set(this, void 0);
927
+ _InteropClient_sessionContextGroups.set(this, void 0);
928
+ _InteropClient_fdc3Factory.set(this, void 0);
929
+ __classPrivateFieldSet$1(this, _InteropClient_sessionContextGroups, new Map(), "f");
930
+ __classPrivateFieldSet$1(this, _InteropClient_clientPromise, clientPromise, "f");
931
+ __classPrivateFieldSet$1(this, _InteropClient_fdc3Factory, fdc3Factory, "f");
932
+ }
933
+ /*
934
+ Client APIs
935
+ */
936
+ /**
937
+ * Sets a context for the context group of the current entity.
938
+ *
939
+ * @remarks The entity must be part of a context group in order set a context.
940
+ *
941
+ * @param context - New context to set.
942
+ *
943
+ * @example
944
+ * ```js
945
+ * setInstrumentContext = async (ticker) => {
946
+ * fin.me.interop.setContext({type: 'instrument', id: {ticker}})
947
+ * }
948
+ *
949
+ * // 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
950
+ * instrumentElement.on('click', (evt) => {
951
+ * setInstrumentContext(evt.ticker)
952
+ * })
953
+ * ```
954
+ */
955
+ async setContext(context) {
956
+ this.wire.sendAction('interop-client-set-context').catch((e) => {
957
+ // don't expose, analytics-only call
958
+ });
959
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
960
+ return client.dispatch('setContext', { context });
961
+ }
962
+ /**
963
+ * Add a context handler for incoming context. If an entity is part of a context group, and then sets its context handler,
964
+ * it will receive all of its declared contexts.
965
+ *
966
+ * @param handler - Handler for incoming context.
967
+ * @param contextType - The type of context you wish to handle.
968
+ *
969
+ * @example
970
+ * ```js
971
+ * function handleIncomingContext(contextInfo) {
972
+ * const { type, id } = contextInfo;
973
+ * switch (type) {
974
+ * case 'instrument':
975
+ * handleInstrumentContext(contextInfo);
976
+ * break;
977
+ * case 'country':
978
+ * handleCountryContext(contextInfo);
979
+ * break;
980
+ *
981
+ * default:
982
+ * break;
983
+ * }
984
+ * }
985
+ *
986
+ *
987
+ * function handleInstrumentContext(contextInfo) {
988
+ * const { type, id } = contextInfo;
989
+ * console.log('contextInfo for instrument', contextInfo)
990
+ * }
991
+ *
992
+ * function handleCountryContext(contextInfo) {
993
+ * const { type, id } = contextInfo;
994
+ * console.log('contextInfo for country', contextInfo)
995
+ * }
996
+ *
997
+ * fin.me.interop.addContextHandler(handleIncomingContext);
998
+ * ```
999
+ *
1000
+ *
1001
+ * Passing in a context type as the second parameter will cause the handler to only be invoked with that context type.
1002
+ *
1003
+ * ```js
1004
+ * function handleInstrumentContext(contextInfo) {
1005
+ * const { type, id } = contextInfo;
1006
+ * console.log('contextInfo for instrument', contextInfo)
1007
+ * }
1008
+ *
1009
+ * function handleCountryContext(contextInfo) {
1010
+ * const { type, id } = contextInfo;
1011
+ * console.log('contextInfo for country', contextInfo)
1012
+ * }
1013
+ *
1014
+ *
1015
+ * fin.me.interop.addContextHandler(handleInstrumentContext, 'instrument')
1016
+ * fin.me.interop.addContextHandler(handleCountryContext, 'country')
1017
+ * ```
1018
+ */
1019
+ async addContextHandler(handler, contextType) {
1020
+ this.wire.sendAction('interop-client-add-context-handler').catch((e) => {
1021
+ // don't expose, analytics-only call
1022
+ });
1023
+ if (typeof handler !== 'function') {
1024
+ throw new Error("Non-function argument passed to the first parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
1025
+ }
1026
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
1027
+ let handlerId;
1028
+ if (contextType) {
1029
+ handlerId = `invokeContextHandler-${contextType}-${(0, utils_1$3.generateId)()}`;
1030
+ }
1031
+ else {
1032
+ handlerId = 'invokeContextHandler';
1033
+ }
1034
+ const wrappedHandler = (0, utils_1$3.wrapContextHandler)(handler, handlerId);
1035
+ client.register(handlerId, wrappedHandler);
1036
+ await client.dispatch('contextHandlerRegistered', { handlerId, contextType });
1037
+ return {
1038
+ unsubscribe: async () => {
1039
+ client.remove(handlerId);
1040
+ await client.dispatch('removeContextHandler', { handlerId });
1041
+ }
1042
+ };
1043
+ }
1044
+ /*
1045
+ Platform Window APIs
1046
+ */
1047
+ /**
1048
+ * Returns the Interop-Broker-defined context groups available for an entity to join.
1049
+ * Used by Platform Windows.
1050
+ *
1051
+ * @example
1052
+ * ```js
1053
+ * fin.me.interop.getContextGroups()
1054
+ * .then(contextGroups => {
1055
+ * contextGroups.forEach(contextGroup => {
1056
+ * console.log(contextGroup.displayMetadata.name)
1057
+ * console.log(contextGroup.displayMetadata.color)
1058
+ * })
1059
+ * })
1060
+ * ```
1061
+ */
1062
+ async getContextGroups() {
1063
+ this.wire.sendAction('interop-client-get-context-groups').catch((e) => {
1064
+ // don't expose, analytics-only call
1065
+ });
1066
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
1067
+ return client.dispatch('getContextGroups');
1068
+ }
1069
+ /**
1070
+ * Join all Interop Clients at the given identity to context group `contextGroupId`.
1071
+ * If no target is specified, it adds the sender to the context group.
1072
+ *
1073
+ * @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.
1074
+ * 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.
1075
+ * 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.
1076
+ * Used by Platform Windows.
1077
+ *
1078
+ * @param contextGroupId - Id of the context group.
1079
+ * @param target - Identity of the entity you wish to join to a context group.
1080
+ *
1081
+ * @example
1082
+ * ```js
1083
+ * joinViewToContextGroup = async (contextGroupId, view) => {
1084
+ * await fin.me.interop.joinContextGroup(contextGroupId, view);
1085
+ * }
1086
+ *
1087
+ * getLastFocusedView()
1088
+ * .then(lastFocusedViewIdentity => {
1089
+ * joinViewToContextGroup('red', lastFocusedViewIdentity)
1090
+ * })
1091
+ * ```
1092
+ */
1093
+ async joinContextGroup(contextGroupId, target) {
1094
+ this.wire.sendAction('interop-client-join-context-group').catch((e) => {
1095
+ // don't expose, analytics-only call
1096
+ });
1097
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
1098
+ if (!contextGroupId) {
1099
+ throw new Error('No contextGroupId specified for joinContextGroup.');
1100
+ }
1101
+ return client.dispatch('joinContextGroup', { contextGroupId, target });
1102
+ }
1103
+ /**
1104
+ * Removes the specified target from a context group.
1105
+ * If no target is specified, it removes the sender from their context group.
1106
+ * Used by Platform Windows.
1107
+ *
1108
+ * @param target - Identity of the entity you wish to join to a context group.
1109
+ *
1110
+ * @example
1111
+ * ```js
1112
+ * removeViewFromContextGroup = async (view) => {
1113
+ * await fin.me.interop.removeFromContextGroup(view);
1114
+ * }
1115
+ *
1116
+ * getLastFocusedView()
1117
+ * .then(lastFocusedViewIdentity => {
1118
+ * removeViewFromContextGroup(lastFocusedViewIdentity)
1119
+ * })
1120
+ * ```
1121
+ */
1122
+ async removeFromContextGroup(target) {
1123
+ this.wire.sendAction('interop-client-remove-from-context-group').catch((e) => {
1124
+ // don't expose, analytics-only call
1125
+ });
1126
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
1127
+ return client.dispatch('removeFromContextGroup', { target });
1128
+ }
1129
+ /**
1130
+ * Gets all clients for a context group.
1131
+ *
1132
+ * @remarks **This is primarily used for platform windows. Views within a platform should not have to use this API.**
1133
+ *
1134
+ * Returns the Interop-Broker-defined context groups available for an entity to join.
1135
+ * @param contextGroupId - The id of context group you wish to get clients for.
1136
+ *
1137
+ * @example
1138
+ * ```js
1139
+ * fin.me.interop.getAllClientsInContextGroup('red')
1140
+ * .then(clientsInContextGroup => {
1141
+ * console.log(clientsInContextGroup)
1142
+ * })
1143
+ * ```
1144
+ */
1145
+ async getAllClientsInContextGroup(contextGroupId) {
1146
+ this.wire.sendAction('interop-client-get-all-clients-in-context-group').catch((e) => {
1147
+ // don't expose, analytics-only call
1148
+ });
1149
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
1150
+ if (!contextGroupId) {
1151
+ throw new Error('No contextGroupId specified for getAllClientsInContextGroup.');
1152
+ }
1153
+ return client.dispatch('getAllClientsInContextGroup', { contextGroupId });
1154
+ }
1155
+ /**
1156
+ * Gets display info for a context group
1157
+ *
1158
+ * @remarks Used by Platform Windows.
1159
+ * @param contextGroupId - The id of context group you wish to get display info for.
1160
+ *
1161
+ * @example
1162
+ * ```js
1163
+ * fin.me.interop.getInfoForContextGroup('red')
1164
+ * .then(contextGroupInfo => {
1165
+ * console.log(contextGroupInfo.displayMetadata.name)
1166
+ * console.log(contextGroupInfo.displayMetadata.color)
1167
+ * })
1168
+ * ```
1169
+ */
1170
+ async getInfoForContextGroup(contextGroupId) {
1171
+ this.wire.sendAction('interop-client-get-info-for-context-group').catch((e) => {
1172
+ // don't expose, analytics-only call
1173
+ });
1174
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
1175
+ if (!contextGroupId) {
1176
+ throw new Error('No contextGroupId specified for getInfoForContextGroup.');
1177
+ }
1178
+ return client.dispatch('getInfoForContextGroup', { contextGroupId });
1179
+ }
1180
+ /**
1181
+ * Sends an intent to the Interop Broker to resolve.
1182
+ * @param intent - The combination of an action and a context that is passed to an application for resolution.
1183
+ *
1184
+ * @example
1185
+ * ```js
1186
+ * // View wants to fire an Intent after a user clicks on a ticker
1187
+ * tickerElement.on('click', (element) => {
1188
+ * const ticker = element.innerText;
1189
+ * const intent = {
1190
+ * name: 'ViewChart',
1191
+ * context: {type: 'fdc3.instrument', id: { ticker }}
1192
+ * }
1193
+ *
1194
+ * fin.me.interop.fireIntent(intent);
1195
+ * })
1196
+ * ```
1197
+ */
1198
+ async fireIntent(intent) {
1199
+ this.wire.sendAction('interop-client-fire-intent').catch((e) => {
1200
+ // don't expose, this is only for api analytics purposes
1201
+ });
1202
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
1203
+ return client.dispatch('fireIntent', intent);
1204
+ }
1205
+ /**
1206
+ * Adds an intent handler for incoming intents. The last intent sent of the name subscribed to will be received.
1207
+ * @param handler - Registered function meant to handle a specific intent type.
1208
+ * @param intentName - The name of an intent.
1209
+ *
1210
+ * @example
1211
+ * ```js
1212
+ * const intentHandler = (intent) => {
1213
+ * const { context } = intent;
1214
+ * myViewChartHandler(context);
1215
+ * };
1216
+ *
1217
+ * const subscription = await fin.me.interop.registerIntentHandler(intentHandler, 'ViewChart');
1218
+ *
1219
+ * function myAppCloseSequence() {
1220
+ * // to unsubscribe the handler, simply call:
1221
+ * subscription.unsubscribe();
1222
+ * }
1223
+ * ```
1224
+ */
1225
+ async registerIntentHandler(handler, intentName, options) {
1226
+ this.wire.sendAction('interop-client-register-intent-handler').catch((e) => {
1227
+ // don't expose, this is only for api analytics purposes
1228
+ });
1229
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
1230
+ const handlerId = `intent-handler-${intentName}`;
1231
+ const wrappedHandler = (0, utils_1$3.wrapIntentHandler)(handler, handlerId);
1232
+ try {
1233
+ await client.register(handlerId, wrappedHandler);
1234
+ await client.dispatch('intentHandlerRegistered', { handlerId, ...options });
1235
+ }
1236
+ catch (error) {
1237
+ throw new Error('Unable to register intent handler');
1238
+ }
1239
+ return {
1240
+ unsubscribe: async () => {
1241
+ client.remove(handlerId);
1242
+ }
1243
+ };
1244
+ }
1245
+ /**
1246
+ * Gets the last context of the Context Group currently subscribed to. It takes an optional Context Type and returns the
1247
+ * last context of that type.
1248
+ * @param contextType
1249
+ *
1250
+ * @example
1251
+ * ```js
1252
+ * await fin.me.interop.joinContextGroup('yellow');
1253
+ * await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
1254
+ * const currentContext = await fin.me.interop.getCurrentContext();
1255
+ *
1256
+ * // with a specific context
1257
+ * await fin.me.interop.joinContextGroup('yellow');
1258
+ * await fin.me.interop.setContext({ type: 'country', id: { ISOALPHA3: 'US' }});
1259
+ * await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
1260
+ * const currentContext = await fin.me.interop.getCurrentContext('country');
1261
+ * ```
1262
+ */
1263
+ async getCurrentContext(contextType) {
1264
+ this.wire.sendAction('interop-client-get-current-context').catch((e) => {
1265
+ // don't expose, analytics-only call
1266
+ });
1267
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
1268
+ return client.dispatch('getCurrentContext', { contextType });
1269
+ }
1270
+ /**
1271
+ * Get information for a particular Intent from the Interop Broker.
1272
+ *
1273
+ * @remarks To resolve this info, the function handleInfoForIntent is meant to be overridden in the Interop Broker.
1274
+ * The format for the response will be determined by the App Provider overriding the function.
1275
+ *
1276
+ * @param options
1277
+ *
1278
+ * @example
1279
+ * ```js
1280
+ * const intentInfo = await fin.me.interop.getInfoForIntent('ViewChart');
1281
+ * ```
1282
+ */
1283
+ async getInfoForIntent(options) {
1284
+ this.wire.sendAction('interop-client-get-info-for-intent').catch((e) => {
1285
+ // don't expose, analytics-only call
1286
+ });
1287
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
1288
+ return client.dispatch('getInfoForIntent', options);
1289
+ }
1290
+ /**
1291
+ * Get information from the Interop Broker on all Intents that are meant to handle a particular context.
1292
+ *
1293
+ * @remarks To resolve this info, the function handleInfoForIntentsByContext is meant to be overridden in the Interop Broker.
1294
+ * The format for the response will be determined by the App Provider overriding the function.
1295
+ *
1296
+ * @param context
1297
+ *
1298
+ * @example
1299
+ * ```js
1300
+ * tickerElement.on('click', (element) => {
1301
+ * const ticker = element.innerText;
1302
+ *
1303
+ * const context = {
1304
+ * type: 'fdc3.instrument',
1305
+ * id: {
1306
+ * ticker
1307
+ * }
1308
+ * }
1309
+ *
1310
+ * const intentsInfo = await fin.me.interop.getInfoForIntentByContext(context);
1311
+ * })
1312
+ * ```
1313
+ */
1314
+ async getInfoForIntentsByContext(context) {
1315
+ this.wire.sendAction('interop-client-get-info-for-intents-by-context').catch((e) => {
1316
+ // don't expose, analytics-only call
1317
+ });
1318
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
1319
+ return client.dispatch('getInfoForIntentsByContext', context);
1320
+ }
1321
+ /**
1322
+ * Sends a Context that will be resolved to an Intent by the Interop Broker.
1323
+ * This context accepts a metadata property.
1324
+ *
1325
+ * @remarks To resolve this info, the function handleFiredIntentByContext is meant to be overridden in the Interop Broker.
1326
+ * The format for the response will be determined by the App Provider overriding the function.
1327
+ *
1328
+ * @param context
1329
+ *
1330
+ * @example
1331
+ * ```js
1332
+ * tickerElement.on('click', (element) => {
1333
+ * const ticker = element.innerText;
1334
+ *
1335
+ * const context = {
1336
+ * type: 'fdc3.instrument',
1337
+ * id: {
1338
+ * ticker
1339
+ * }
1340
+ * }
1341
+ *
1342
+ * const intentResolution = await fin.me.interop.fireIntentForContext(context);
1343
+ * })
1344
+ * ```
1345
+ */
1346
+ async fireIntentForContext(context) {
1347
+ this.wire.sendAction('interop-client-fire-intent-for-context').catch((e) => {
1348
+ // don't expose, analytics-only call
1349
+ });
1350
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
1351
+ return client.dispatch('fireIntentForContext', context);
1352
+ }
1353
+ /**
1354
+ * Join the current entity to session context group `sessionContextGroupId` and return a sessionContextGroup instance.
1355
+ * If the sessionContextGroup doesn't exist, one will get created.
1356
+ *
1357
+ * @remarks Session Context Groups do not persist between runs and aren't present on snapshots.
1358
+ * @param sessionContextGroupId - Id of the context group.
1359
+ *
1360
+ * @example
1361
+ * Say we want to have a Session Context Group that holds UI theme information for all apps to consume:
1362
+ *
1363
+ * My color-picker View:
1364
+ * ```js
1365
+ * const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');
1366
+ *
1367
+ * const myColorPickerElement = document.getElementById('color-palette-picker');
1368
+ * myColorPickerElement.addEventListener('change', event => {
1369
+ * themeSessionContextGroup.setContext({ type: 'color-palette', selection: event.value });
1370
+ * });
1371
+ * ```
1372
+ *
1373
+ * In other views:
1374
+ * ```js
1375
+ * const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');
1376
+ *
1377
+ * const changeColorPalette = ({ selection }) => {
1378
+ * // change the color palette to the selection
1379
+ * };
1380
+ *
1381
+ * // If the context is already set by the time the handler was set, the handler will get invoked immediately with the current context.
1382
+ * themeSessionContextGroup.addContextHandler(changeColorPalette, 'color-palette');
1383
+ * ```
1384
+ */
1385
+ async joinSessionContextGroup(sessionContextGroupId) {
1386
+ try {
1387
+ const currentSessionContextGroup = __classPrivateFieldGet$1(this, _InteropClient_sessionContextGroups, "f").get(sessionContextGroupId);
1388
+ if (currentSessionContextGroup) {
1389
+ return currentSessionContextGroup.getUserInstance();
1390
+ }
1391
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
1392
+ const { hasConflict } = await client.dispatch('sessionContextGroup:createIfNeeded', {
1393
+ sessionContextGroupId
1394
+ });
1395
+ if (hasConflict) {
1396
+ 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.`);
1397
+ }
1398
+ const newSessionContextGroup = new SessionContextGroupClient_1.default(this.wire, __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f"), sessionContextGroupId);
1399
+ __classPrivateFieldGet$1(this, _InteropClient_sessionContextGroups, "f").set(sessionContextGroupId, newSessionContextGroup);
1400
+ return newSessionContextGroup.getUserInstance();
1401
+ }
1402
+ catch (error) {
1403
+ console.error(`Error thrown trying to create Session Context Group with id "${sessionContextGroupId}": ${error}`);
1404
+ throw error;
1405
+ }
1406
+ }
1407
+ /**
1408
+ * Register a listener that is called when the Interop Client has been disconnected from the Interop Broker.
1409
+ * Only one listener per Interop Client can be set.
1410
+ * @param listener
1411
+ *
1412
+ * @example
1413
+ * ```js
1414
+ * const listener = (event) => {
1415
+ * const { type, topic, brokerName} = event;
1416
+ * console.log(`Disconnected from Interop Broker ${brokerName} `);
1417
+ * }
1418
+ *
1419
+ * await fin.me.interop.onDisconnection(listener);
1420
+ * ```
1421
+ */
1422
+ async onDisconnection(listener) {
1423
+ this.wire.sendAction('interop-client-add-ondisconnection-listener').catch((e) => {
1424
+ // don't expose, analytics-only call
1425
+ });
1426
+ const client = await __classPrivateFieldGet$1(this, _InteropClient_clientPromise, "f");
1427
+ return client.onDisconnection((event) => {
1428
+ const { uuid } = event;
1429
+ listener({ type: 'interop-broker', topic: 'disconnected', brokerName: uuid });
1430
+ });
1431
+ }
1432
+ getFDC3Sync(version) {
1433
+ return __classPrivateFieldGet$1(this, _InteropClient_fdc3Factory, "f").call(this, version, this, this.wire);
1434
+ }
1435
+ async getFDC3(version) {
1436
+ return this.getFDC3Sync(version);
1437
+ }
1438
+ /**
1439
+ * @internal
1440
+ *
1441
+ * Used to ferry fdc3-only calls from the fdc3 shim to the Interop Broker
1442
+ */
1443
+ static async ferryFdc3Call(interopClient, action, payload) {
1444
+ const client = await __classPrivateFieldGet$1(interopClient, _InteropClient_clientPromise, "f");
1445
+ return client.dispatch(action, payload || null);
1446
+ }
1447
+ }
1448
+ InteropClient$1.InteropClient = InteropClient;
1449
+ _InteropClient_clientPromise = new WeakMap(), _InteropClient_sessionContextGroups = new WeakMap(), _InteropClient_fdc3Factory = new WeakMap();
816
1450
 
817
- function requireFdc32_0 () {
818
- if (hasRequiredFdc32_0) return fdc32_0;
819
- hasRequiredFdc32_0 = 1;
820
- Object.defineProperty(fdc32_0, "__esModule", { value: true });
821
- fdc32_0.Fdc3Module2 = void 0;
822
- const fdc3_common_1 = requireFdc3Common();
823
- const utils_1 = utils$2;
824
- const InteropClient_1 = requireInteropClient();
825
- const utils_2 = utils$1;
826
- const PrivateChannelClient_1 = PrivateChannelClient$1;
827
- /**
828
- * @version 2.0
829
- * The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
830
- * while using our Interop API under the hood. In order to use this set of APIs
831
- * 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
832
- * our {@link https://developers.openfin.co/of-docs/docs/enable-context-sharing Interop API}.
833
- *
834
- * To enable the FDC3 APIs in a {@link Window Window} or {@link View View}, add the fdc3InteropApi
835
- * property to its options:
836
- *
837
- * ```js
838
- * {
839
- * autoShow: false,
840
- * saveWindowState: true,
841
- * url: 'https://openfin.co',
842
- * fdc3InteropApi: '2.0'
843
- * }
844
- * ```
845
- *
846
- * If using a {@link Platform Platform } application, you can set this property in defaultWindowOptions and defaultViewOptions.
847
- *
848
- * In order to ensure that the FDC3 Api is ready before use, you can use the 'fdc3Ready' event fired on the DOM Window object:
849
- *
850
- * ```js
851
- * function fdc3Action() {
852
- * // Make some fdc3 API calls here
853
- * }
854
- *
855
- * if (window.fdc3) {
856
- * fdc3Action();
857
- * } else {
858
- * window.addEventListener('fdc3Ready', fdc3Action);
859
- * }
860
- * ```
861
- */
862
- class Fdc3Module2 extends fdc3_common_1.FDC3ModuleBase {
863
- /**
864
- * Launches an app, specified via an AppIdentifier object.
865
- * @param app
866
- * @param context
867
- *
868
- * @tutorial fdc3.open
869
- */
870
- async open(app, context) {
871
- if (typeof app === 'string') {
872
- console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
873
- }
874
- // eslint-disable-next-line no-underscore-dangle
875
- return super._open(app, context);
876
- }
877
- /**
878
- * Find all the available instances for a particular application.
879
- * @param app
880
- *
881
- * @tutorial fdc3v2.findInstances
882
- */
883
- async findInstances(app) {
884
- this.wire.sendAction('fdc3-find-instances').catch((e) => {
885
- // we do not want to expose this error, just continue if this analytics-only call fails
886
- });
887
- try {
888
- return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3FindInstances', app);
889
- }
890
- catch (error) {
891
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.fdc3FindInstances ? 'ResolverUnavailable' : error.message;
892
- throw new Error(errorToThrow);
893
- }
894
- }
895
- /**
896
- * 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.
897
- * @param app
898
- *
899
- * @tutorial fdc3v2.getAppMetadata
900
- */
901
- async getAppMetadata(app) {
902
- this.wire.sendAction('fdc3-get-app-metadata').catch((e) => {
903
- // we do not want to expose this error, just continue if this analytics-only call fails
904
- });
905
- try {
906
- return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3GetAppMetadata', app);
907
- }
908
- catch (error) {
909
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.fdc3GetAppMetadata ? 'ResolverUnavailable' : error.message;
910
- throw new Error(errorToThrow);
911
- }
912
- }
913
- /**
914
- * 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.
915
- * @param contextType
916
- * @param handler
917
- *
918
- * @tutorial fdc3.addContextListener
919
- */
920
- // @ts-expect-error TODO [CORE-1524]
921
- async addContextListener(contextType, handler) {
922
- this.wire.sendAction('fdc3-add-context-listener').catch((e) => {
923
- // we do not want to expose this error, just continue if this analytics-only call fails
924
- });
925
- // The FDC3 ContextHandler only expects the context and optional ContextMetadata, so we wrap the handler
926
- // here so it only gets passed these parameters
927
- const getWrappedHandler = (handlerToWrap) => {
928
- return (context) => {
929
- const { contextMetadata, ...rest } = context;
930
- const args = contextMetadata ? [{ ...rest }, contextMetadata] : [context, null];
931
- handlerToWrap(...args);
932
- };
933
- };
934
- let actualHandler = handler;
935
- let wrappedHandler = getWrappedHandler(actualHandler);
936
- if (typeof contextType === 'function') {
937
- console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
938
- actualHandler = contextType;
939
- wrappedHandler = getWrappedHandler(actualHandler);
940
- return this.client.addContextHandler(wrappedHandler);
941
- }
942
- return this.client.addContextHandler(wrappedHandler, contextType === null ? undefined : contextType);
943
- }
944
- /**
945
- * Find out more information about a particular intent by passing its name, and optionally its context and resultType.
946
- * @param intent Name of the Intent
947
- * @param context Context
948
- * @param resultType The type of result returned for any intent specified during resolution.
949
- *
950
- * @tutorial fdc3.findIntent
951
- */
952
- async findIntent(intent, context, resultType) {
953
- this.wire.sendAction('fdc3-find-intent').catch((e) => {
954
- // we do not want to expose this error, just continue if this analytics-only call fails
955
- });
956
- try {
957
- return await this.client.getInfoForIntent({ name: intent, context, metadata: { resultType } });
958
- }
959
- catch (error) {
960
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntent ? 'ResolverUnavailable' : error.message;
961
- throw new Error(errorToThrow);
962
- }
963
- }
964
- /**
965
- * Find all the available intents for a particular context.
966
- * @param context
967
- * @param resultType The type of result returned for any intent specified during resolution.
968
- *
969
- * @tutorial fdc3v2.findIntentsByContext
970
- */
971
- async findIntentsByContext(context, resultType) {
972
- this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
973
- // we do not want to expose this error, just continue if this analytics-only call fails
974
- });
975
- const payload = resultType ? { context, metadata: { resultType } } : context;
976
- try {
977
- return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3v2FindIntentsByContext', payload);
978
- }
979
- catch (error) {
980
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error.message;
981
- throw new Error(errorToThrow);
982
- }
983
- }
984
- /**
985
- * Raises a specific intent for resolution against apps registered with the desktop agent.
986
- * @param intent Name of the Intent
987
- * @param context Context associated with the Intent
988
- * @param app
989
- *
990
- * @tutorial fdc3v2.raiseIntent
991
- */
992
- async raiseIntent(intent, context, app) {
993
- this.wire.sendAction('fdc3-raise-intent').catch((e) => {
994
- // we do not want to expose this error, just continue if this analytics-only call fails
995
- });
996
- try {
997
- if (typeof app === 'string') {
998
- console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
999
- }
1000
- return (0, utils_2.getIntentResolution)(this.client, context, app, intent);
1001
- }
1002
- catch (error) {
1003
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
1004
- throw new Error(errorToThrow);
1005
- }
1006
- }
1007
- /**
1008
- * Finds and raises an intent against apps registered with the desktop agent based purely on the type of the context data.
1009
- * @param context Context associated with the Intent
1010
- * @param app
1011
- *
1012
- * @tutorial fdc3v2.raiseIntentForContext
1013
- */
1014
- async raiseIntentForContext(context, app) {
1015
- // TODO: We have to do the same thing we do for raiseIntent here as well.
1016
- this.wire.sendAction('fdc3-raise-intent-for-context').catch((e) => {
1017
- // we do not want to expose this error, just continue if this analytics-only call fails
1018
- });
1019
- try {
1020
- if (typeof app === 'string') {
1021
- console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
1022
- }
1023
- return (0, utils_2.getIntentResolution)(this.client, context, app);
1024
- }
1025
- catch (error) {
1026
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
1027
- throw new Error(errorToThrow);
1028
- }
1029
- }
1030
- /**
1031
- * Adds a listener for incoming intents.
1032
- * @param intent Name of the Intent
1033
- * @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.
1034
- *
1035
- * @tutorial fdc3.addIntentListener
1036
- */
1037
- async addIntentListener(intent, handler) {
1038
- this.wire.sendAction('fdc3-add-intent-listener').catch((e) => {
1039
- // we do not want to expose this error, just continue if this analytics-only call fails
1040
- });
1041
- if (typeof intent !== 'string') {
1042
- throw new Error('First argument must be an Intent name');
1043
- }
1044
- // The FDC3 Intenter handler only expects the context and contextMetadata to be passed to the handler,
1045
- // so we wrap it here and only pass those paramaters.
1046
- const contextHandler = async (raisedIntent) => {
1047
- let intentResult;
1048
- let intentResultToSend;
1049
- const { context, metadata: intentMetadata } = raisedIntent;
1050
- const { contextMetadata, metadata, ...rest } = context;
1051
- const intentResolutionResultId = intentMetadata?.intentResolutionResultId || metadata?.intentResolutionResultId;
1052
- try {
1053
- const newContext = metadata ? { metadata, ...rest } : { ...rest };
1054
- intentResult = await handler(newContext, contextMetadata);
1055
- intentResultToSend = intentResult;
1056
- }
1057
- catch (error) {
1058
- intentResult = error;
1059
- intentResultToSend = { error: true };
1060
- }
1061
- if (intentResolutionResultId) {
1062
- this.fin.InterApplicationBus.publish(intentResolutionResultId, intentResultToSend).catch(() => null);
1063
- }
1064
- if (intentResult instanceof Error) {
1065
- throw new Error(intentResult.message);
1066
- }
1067
- return intentResult;
1068
- };
1069
- return this.client.registerIntentHandler(contextHandler, intent, { fdc3Version: '2.0' });
1070
- }
1071
- /**
1072
- * Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
1073
- * @param channelId
1074
- *
1075
- * @tutorial fdc3.getOrCreateChannel
1076
- */
1077
- async getOrCreateChannel(channelId) {
1078
- return super.getOrCreateChannel(channelId);
1079
- }
1080
- /**
1081
- * 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.
1082
- *
1083
- * @tutorial fdc3v2.createPrivateChannel
1084
- */
1085
- async createPrivateChannel() {
1086
- const channelId = (0, utils_1.generateId)();
1087
- await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'createPrivateChannelProvider', { channelId });
1088
- const channelClient = await this.fin.InterApplicationBus.Channel.connect(channelId);
1089
- const newPrivateChannelClient = new PrivateChannelClient_1.PrivateChannelClient(channelClient, channelId);
1090
- return (0, utils_2.buildPrivateChannelObject)(newPrivateChannelClient);
1091
- }
1092
- /**
1093
- * Retrieves a list of the User Channels available for the app to join.
1094
- *
1095
- * @tutorial fdc3v2.getUserChannels
1096
- */
1097
- async getUserChannels() {
1098
- const channels = await this.client.getContextGroups();
1099
- // fdc3 implementation of getUserChannels returns on array of channels, have to decorate over
1100
- // this so people know that these APIs are not supported
1101
- return channels.map((channel) => {
1102
- // @ts-expect-error TODO [CORE-1524]
1103
- return { ...channel, type: 'user', ...(0, utils_2.getUnsupportedChannelApis)('User') };
1104
- });
1105
- }
1106
- /**
1107
- * Retrieves a list of the User Channels available for the app to join.
1108
- *
1109
- * @deprecated Please use {@link fdc3.getUserChannels fdc3.getUserChannels} instead
1110
- * @tutorial fdc3.getSystemChannels
1111
- */
1112
- async getSystemChannels() {
1113
- console.warn('This API has been deprecated. Please use fdc3.getUserChannels instead.');
1114
- return super.getSystemChannels();
1115
- }
1116
- /**
1117
- * Join an app to a specified User channel.
1118
- * @param channelId Channel name
1119
- *
1120
- * @tutorial fdc3v2.joinUserChannel
1121
- */
1122
- async joinUserChannel(channelId) {
1123
- return super.joinChannel(channelId);
1124
- }
1125
- /**
1126
- * Join an app to a specified User channel.
1127
- * @param channelId Channel name
1128
- * @deprecated Please use {@link fdc3.joinUserChannel fdc3.joinUserChannel} instead
1129
- *
1130
- * @tutorial fdc3.joinChannel
1131
- */
1132
- async joinChannel(channelId) {
1133
- console.warn('This API has been deprecated. Please use fdc3.joinUserChannel instead.');
1134
- return super.joinChannel(channelId);
1135
- }
1136
- /**
1137
- * Returns the Channel object for the current User channel membership
1138
- *
1139
- * @tutorial fdc3.getCurrentChannel
1140
- */
1141
- async getCurrentChannel() {
1142
- const currentChannel = await super.getCurrentChannel();
1143
- if (!currentChannel) {
1144
- return null;
1145
- }
1146
- return {
1147
- ...currentChannel,
1148
- type: 'user',
1149
- broadcast: this.broadcast.bind(this)
1150
- };
1151
- }
1152
- /**
1153
- * 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.
1154
- * fdc3HandleGetInfo must be overridden in the InteropBroker so that the ImplementationMetadata will have the appMetadata info.
1155
- *
1156
- * @tutorial fdc3v2.getInfo
1157
- */
1158
- async getInfo() {
1159
- return InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3v2GetInfo', { fdc3Version: '2.0' });
1160
- }
1161
- }
1162
- fdc32_0.Fdc3Module2 = Fdc3Module2;
1163
- return fdc32_0;
1451
+ var __classPrivateFieldGet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1452
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1453
+ 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");
1454
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1455
+ };
1456
+ var __classPrivateFieldSet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
1457
+ if (kind === "m") throw new TypeError("Private method is not writable");
1458
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1459
+ 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");
1460
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1461
+ };
1462
+ var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1463
+ return (mod && mod.__esModule) ? mod : { "default": mod };
1464
+ };
1465
+ var _FDC3ModuleBase_producer;
1466
+ Object.defineProperty(fdc3Common, "__esModule", { value: true });
1467
+ fdc3Common.FDC3ModuleBase = void 0;
1468
+ const utils_1$2 = utils$1;
1469
+ const utils_2$1 = utils$2;
1470
+ const InteropClient_1$1 = InteropClient$1;
1471
+ const isEqual_1 = __importDefault(require$$2);
1472
+ class FDC3ModuleBase {
1473
+ get client() {
1474
+ return __classPrivateFieldGet(this, _FDC3ModuleBase_producer, "f").call(this);
1475
+ }
1476
+ get fin() {
1477
+ return this.wire.getFin();
1478
+ }
1479
+ // eslint-disable-next-line no-useless-constructor
1480
+ constructor(producer, wire) {
1481
+ this.wire = wire;
1482
+ _FDC3ModuleBase_producer.set(this, void 0);
1483
+ __classPrivateFieldSet(this, _FDC3ModuleBase_producer, producer, "f");
1484
+ }
1485
+ /**
1486
+ * Broadcasts a context for the channel of the current entity.
1487
+ * @param context - New context to set.
1488
+ *
1489
+ * @tutorial fdc3.broadcast
1490
+ * @static
1491
+ */
1492
+ async broadcast(context) {
1493
+ this.wire.sendAction('fdc3-broadcast').catch((e) => {
1494
+ // we do not want to expose this error, just continue if this analytics-only call fails
1495
+ });
1496
+ return this.client.setContext(context);
1497
+ }
1498
+ /**
1499
+ * Launches an app with target information, which can either be a string or an AppMetadata object.
1500
+ * @param app
1501
+ * @param context
1502
+ *
1503
+ * @tutorial fdc3.open
1504
+ */
1505
+ async _open(app, context) {
1506
+ this.wire.sendAction('fdc3-open').catch((e) => {
1507
+ // we do not want to expose this error, just continue if this analytics-only call fails
1508
+ });
1509
+ try {
1510
+ return await InteropClient_1$1.InteropClient.ferryFdc3Call(this.client, 'fdc3Open', { app, context });
1511
+ }
1512
+ catch (error) {
1513
+ const errorToThrow = error.message === utils_2$1.BROKER_ERRORS.fdc3Open ? 'ResolverUnavailable' : error.message;
1514
+ throw new Error(errorToThrow);
1515
+ }
1516
+ }
1517
+ async _getChannels() {
1518
+ const channels = await this.client.getContextGroups();
1519
+ // fdc3 implementation of getSystemChannels returns an array of channels, have to decorate over
1520
+ // this so people know that these APIs are not supported
1521
+ return channels.map((channel) => {
1522
+ return { ...channel, type: 'system', ...(0, utils_1$2.getUnsupportedChannelApis)() };
1523
+ });
1524
+ }
1525
+ /**
1526
+ * Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
1527
+ * @param channelId
1528
+ *
1529
+ * @tutorial fdc3.getOrCreateChannel
1530
+ */
1531
+ async getOrCreateChannel(channelId) {
1532
+ this.wire.sendAction('fdc3-get-or-create-channel').catch((e) => {
1533
+ // we do not want to expose this error, just continue if this analytics-only call fails
1534
+ });
1535
+ const systemChannels = await this._getChannels();
1536
+ const userChannel = systemChannels.find((channel) => channel.id === channelId);
1537
+ if (userChannel) {
1538
+ return { ...userChannel, type: 'system', ...(0, utils_1$2.getUnsupportedChannelApis)() };
1539
+ }
1540
+ try {
1541
+ const sessionContextGroup = await this.client.joinSessionContextGroup(channelId);
1542
+ return (0, utils_1$2.buildAppChannelObject)(sessionContextGroup);
1543
+ }
1544
+ catch (error) {
1545
+ console.error(error.message);
1546
+ throw new Error(utils_1$2.ChannelError.CreationFailed);
1547
+ }
1548
+ }
1549
+ /**
1550
+ * Returns the Interop-Broker-defined context groups available for an entity to join.
1551
+ *
1552
+ * @tutorial fdc3.getSystemChannels
1553
+ * @static
1554
+ */
1555
+ async getSystemChannels() {
1556
+ this.wire.sendAction('fdc3-get-system-channels').catch((e) => {
1557
+ // we do not want to expose this error, just continue if this analytics-only call fails
1558
+ });
1559
+ return this._getChannels();
1560
+ }
1561
+ /**
1562
+ * Join all Interop Clients at the given identity to context group `contextGroupId`.
1563
+ * If no target is specified, it adds the sender to the context group.
1564
+ * 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.
1565
+ * 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.
1566
+ * 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.
1567
+ * @param channelId - Id of the context group.
1568
+ *
1569
+ * @tutorial fdc3.joinChannel
1570
+ * @static
1571
+ */
1572
+ async joinChannel(channelId) {
1573
+ this.wire.sendAction('fdc3-join-channel').catch((e) => {
1574
+ // we do not want to expose this error, just continue if this analytics-only call fails
1575
+ });
1576
+ try {
1577
+ return await this.client.joinContextGroup(channelId);
1578
+ }
1579
+ catch (error) {
1580
+ if (error.message === utils_2$1.BROKER_ERRORS.joinSessionContextGroupWithJoinContextGroup) {
1581
+ 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.');
1582
+ }
1583
+ else {
1584
+ console.error(error.message);
1585
+ }
1586
+ if (error.message.startsWith('Attempting to join a context group that does not exist')) {
1587
+ throw new Error(utils_1$2.ChannelError.NoChannelFound);
1588
+ }
1589
+ throw new Error(utils_1$2.ChannelError.AccessDenied);
1590
+ }
1591
+ }
1592
+ /**
1593
+ * Returns the Channel that the entity is subscribed to. Returns null if not joined to a channel.
1594
+ *
1595
+ * @tutorial fdc3.getCurrentChannel
1596
+ */
1597
+ async getCurrentChannel() {
1598
+ this.wire.sendAction('fdc3-get-current-channel').catch((e) => {
1599
+ // we do not want to expose this error, just continue if this analytics-only call fails
1600
+ });
1601
+ const currentContextGroupInfo = await this.getCurrentContextGroupInfo();
1602
+ if (!currentContextGroupInfo) {
1603
+ return null;
1604
+ }
1605
+ return this.buildChannelObject(currentContextGroupInfo);
1606
+ }
1607
+ /**
1608
+ * Removes the specified target from a context group.
1609
+ * If no target is specified, it removes the sender from their context group.
1610
+ *
1611
+ * @tutorial fdc3.leaveCurrentChannel
1612
+ * @static
1613
+ */
1614
+ async leaveCurrentChannel() {
1615
+ this.wire.sendAction('fdc3-leave-current-channel').catch((e) => {
1616
+ // we do not want to expose this error, just continue if this analytics-only call fails
1617
+ });
1618
+ return this.client.removeFromContextGroup();
1619
+ }
1620
+ // utils
1621
+ // eslint-disable-next-line class-methods-use-this
1622
+ async getCurrentContextGroupInfo() {
1623
+ const contextGroups = await this.client.getContextGroups();
1624
+ const clientsInCtxGroupsPromise = contextGroups.map(async (ctxGroup) => {
1625
+ return this.client.getAllClientsInContextGroup(ctxGroup.id);
1626
+ });
1627
+ const clientsInCtxGroups = await Promise.all(clientsInCtxGroupsPromise);
1628
+ const clientIdx = clientsInCtxGroups.findIndex((clientIdentityArr) => {
1629
+ return clientIdentityArr.some((clientIdentity) => {
1630
+ const { uuid, name } = clientIdentity;
1631
+ return this.wire.me.uuid === uuid && this.wire.me.name === name;
1632
+ });
1633
+ });
1634
+ return contextGroups[clientIdx];
1635
+ }
1636
+ async buildChannelObject(currentContextGroupInfo) {
1637
+ // @ts-expect-error
1638
+ return {
1639
+ ...currentContextGroupInfo,
1640
+ type: 'system',
1641
+ addContextListener: (...[contextType, handler]) => {
1642
+ let realHandler;
1643
+ let realType;
1644
+ if (typeof contextType === 'function') {
1645
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
1646
+ realHandler = contextType;
1647
+ }
1648
+ else {
1649
+ realHandler = handler;
1650
+ if (typeof contextType === 'string') {
1651
+ realType = contextType;
1652
+ }
1653
+ }
1654
+ const listener = (async () => {
1655
+ let first = true;
1656
+ const currentContext = await this.client.getCurrentContext(realType);
1657
+ const wrappedHandler = (context, contextMetadata) => {
1658
+ if (first) {
1659
+ first = false;
1660
+ if ((0, isEqual_1.default)(currentContext, context)) {
1661
+ return;
1662
+ }
1663
+ }
1664
+ // eslint-disable-next-line consistent-return
1665
+ return realHandler(context, contextMetadata);
1666
+ };
1667
+ return this.client.addContextHandler(wrappedHandler, realType);
1668
+ })();
1669
+ // @ts-expect-error TODO [CORE-1524]
1670
+ return {
1671
+ ...listener,
1672
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
1673
+ };
1674
+ },
1675
+ broadcast: this.broadcast.bind(this),
1676
+ // @ts-expect-error Typescript fails to infer the returntype is a Promise
1677
+ getCurrentContext: async (contextType) => {
1678
+ const context = await this.client.getCurrentContext(contextType);
1679
+ // @ts-expect-error Typescript fails to infer the returntype is a Promise
1680
+ return context === undefined ? null : context;
1681
+ }
1682
+ };
1683
+ }
1164
1684
  }
1685
+ fdc3Common.FDC3ModuleBase = FDC3ModuleBase;
1686
+ _FDC3ModuleBase_producer = new WeakMap();
1165
1687
 
1166
- var hasRequiredInteropClient;
1167
-
1168
- function requireInteropClient () {
1169
- if (hasRequiredInteropClient) return InteropClient;
1170
- hasRequiredInteropClient = 1;
1171
- var __classPrivateFieldSet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
1172
- if (kind === "m") throw new TypeError("Private method is not writable");
1173
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1174
- 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");
1175
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1176
- };
1177
- var __classPrivateFieldGet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1178
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1179
- 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");
1180
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1181
- };
1182
- var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1183
- return (mod && mod.__esModule) ? mod : { "default": mod };
1184
- };
1185
- var _InteropClient_clientPromise, _InteropClient_sessionContextGroups;
1186
- Object.defineProperty(InteropClient, "__esModule", { value: true });
1187
- InteropClient.InteropClient = void 0;
1188
- const base_1 = base;
1189
- const SessionContextGroupClient_1 = __importDefault(SessionContextGroupClient$1);
1190
- const fdc3_1_2_1 = requireFdc31_2();
1191
- const fdc3_2_0_1 = requireFdc32_0();
1192
- const utils_1 = utils$2;
1193
- /**
1194
- * The Interop Client API is broken up into two groups:
1195
- *
1196
- * **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.
1197
- *
1198
- * **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.
1199
- *
1200
- * ---
1201
- *
1202
- * All APIs are available at the `fin.me.interop` namespace.
1203
- *
1204
- * ---
1205
- *
1206
- * **You only need 2 things to participate in Interop Context Grouping:**
1207
- * * A Context Handler for incoming context: {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
1208
- * * Call setContext on your context group when you want to share context with other group members: {@link InteropClient#setContext setContext(context)}
1209
- *
1210
- * ---
1211
- *
1212
- * ##### Constructor
1213
- * Returned by {@link Interop.connectSync Interop.connectSync}.
1214
- *
1215
- * ---
1216
- *
1217
- * ##### Interop methods intended for Views
1218
- *
1219
- *
1220
- * **Context Groups API**
1221
- * * {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
1222
- * * {@link InteropClient#setContext setContext(context)}
1223
- * * {@link InteropClient#getCurrentContext getCurrentContext(contextType?)}
1224
- * * {@link InteropClient#joinSessionContextGroup joinSessionContextGroup(sessionContextGroupId)}
1225
- *
1226
- *
1227
- * **Intents API**
1228
- * * {@link InteropClient#fireIntent fireIntent(intent)}
1229
- * * {@link InteropClient#registerIntentHandler registerIntentHandler(intentHandler, intentName)}
1230
- * * {@link InteropClient#getInfoForIntent getInfoForIntent(infoForIntentOptions)}
1231
- * * {@link InteropClient#getInfoForIntentsByContext getInfoForIntentsByContext(context)}
1232
- * * {@link InteropClient#fireIntentForContext fireIntentForContext(contextForIntent)}
1233
- *
1234
- * ##### Interop methods intended for Windows
1235
- * * {@link InteropClient#getContextGroups getContextGroups()}
1236
- * * {@link InteropClient#joinContextGroup joinContextGroup(contextGroupId, target?)}
1237
- * * {@link InteropClient#removeFromContextGroup removeFromContextGroup(target?)}
1238
- * * {@link InteropClient#getInfoForContextGroup getInfoForContextGroup(contextGroupId)}
1239
- * * {@link InteropClient#getAllClientsInContextGroup getAllClientsInContextGroup(contextGroupId)}
1240
- *
1241
- */
1242
- let InteropClient$1 = class InteropClient extends base_1.Base {
1243
- /**
1244
- * @internal
1245
- */
1246
- constructor(wire, clientPromise) {
1247
- super(wire);
1248
- _InteropClient_clientPromise.set(this, void 0);
1249
- _InteropClient_sessionContextGroups.set(this, void 0);
1250
- __classPrivateFieldSet(this, _InteropClient_sessionContextGroups, new Map(), "f");
1251
- __classPrivateFieldSet(this, _InteropClient_clientPromise, clientPromise, "f");
1252
- }
1253
- /*
1254
- Client APIs
1255
- */
1256
- /**
1257
- * Sets a context for the context group of the current entity.
1258
- *
1259
- * @remarks The entity must be part of a context group in order set a context.
1260
- *
1261
- * @param context - New context to set.
1262
- *
1263
- * @example
1264
- * ```js
1265
- * setInstrumentContext = async (ticker) => {
1266
- * fin.me.interop.setContext({type: 'instrument', id: {ticker}})
1267
- * }
1268
- *
1269
- * // 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
1270
- * instrumentElement.on('click', (evt) => {
1271
- * setInstrumentContext(evt.ticker)
1272
- * })
1273
- * ```
1274
- */
1275
- async setContext(context) {
1276
- this.wire.sendAction('interop-client-set-context').catch((e) => {
1277
- // don't expose, analytics-only call
1278
- });
1279
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1280
- return client.dispatch('setContext', { context });
1281
- }
1282
- /**
1283
- * Add a context handler for incoming context. If an entity is part of a context group, and then sets its context handler,
1284
- * it will receive all of its declared contexts.
1285
- *
1286
- * @param handler - Handler for incoming context.
1287
- * @param contextType - The type of context you wish to handle.
1288
- *
1289
- * @example
1290
- * ```js
1291
- * function handleIncomingContext(contextInfo) {
1292
- * const { type, id } = contextInfo;
1293
- * switch (type) {
1294
- * case 'instrument':
1295
- * handleInstrumentContext(contextInfo);
1296
- * break;
1297
- * case 'country':
1298
- * handleCountryContext(contextInfo);
1299
- * break;
1300
- *
1301
- * default:
1302
- * break;
1303
- * }
1304
- * }
1305
- *
1306
- *
1307
- * function handleInstrumentContext(contextInfo) {
1308
- * const { type, id } = contextInfo;
1309
- * console.log('contextInfo for instrument', contextInfo)
1310
- * }
1311
- *
1312
- * function handleCountryContext(contextInfo) {
1313
- * const { type, id } = contextInfo;
1314
- * console.log('contextInfo for country', contextInfo)
1315
- * }
1316
- *
1317
- * fin.me.interop.addContextHandler(handleIncomingContext);
1318
- * ```
1319
- *
1320
- *
1321
- * Passing in a context type as the second parameter will cause the handler to only be invoked with that context type.
1322
- *
1323
- * ```js
1324
- * function handleInstrumentContext(contextInfo) {
1325
- * const { type, id } = contextInfo;
1326
- * console.log('contextInfo for instrument', contextInfo)
1327
- * }
1328
- *
1329
- * function handleCountryContext(contextInfo) {
1330
- * const { type, id } = contextInfo;
1331
- * console.log('contextInfo for country', contextInfo)
1332
- * }
1333
- *
1334
- *
1335
- * fin.me.interop.addContextHandler(handleInstrumentContext, 'instrument')
1336
- * fin.me.interop.addContextHandler(handleCountryContext, 'country')
1337
- * ```
1338
- */
1339
- async addContextHandler(handler, contextType) {
1340
- this.wire.sendAction('interop-client-add-context-handler').catch((e) => {
1341
- // don't expose, analytics-only call
1342
- });
1343
- if (typeof handler !== 'function') {
1344
- throw new Error("Non-function argument passed to the first parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
1345
- }
1346
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1347
- let handlerId;
1348
- if (contextType) {
1349
- handlerId = `invokeContextHandler-${contextType}-${(0, utils_1.generateId)()}`;
1350
- }
1351
- else {
1352
- handlerId = 'invokeContextHandler';
1353
- }
1354
- const wrappedHandler = (0, utils_1.wrapContextHandler)(handler, handlerId);
1355
- client.register(handlerId, wrappedHandler);
1356
- await client.dispatch('contextHandlerRegistered', { handlerId, contextType });
1357
- return {
1358
- unsubscribe: async () => {
1359
- client.remove(handlerId);
1360
- await client.dispatch('removeContextHandler', { handlerId });
1361
- }
1362
- };
1363
- }
1364
- /*
1365
- Platform Window APIs
1366
- */
1367
- /**
1368
- * Returns the Interop-Broker-defined context groups available for an entity to join.
1369
- * Used by Platform Windows.
1370
- *
1371
- * @example
1372
- * ```js
1373
- * fin.me.interop.getContextGroups()
1374
- * .then(contextGroups => {
1375
- * contextGroups.forEach(contextGroup => {
1376
- * console.log(contextGroup.displayMetadata.name)
1377
- * console.log(contextGroup.displayMetadata.color)
1378
- * })
1379
- * })
1380
- * ```
1381
- */
1382
- async getContextGroups() {
1383
- this.wire.sendAction('interop-client-get-context-groups').catch((e) => {
1384
- // don't expose, analytics-only call
1385
- });
1386
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1387
- return client.dispatch('getContextGroups');
1388
- }
1389
- /**
1390
- * Join all Interop Clients at the given identity to context group `contextGroupId`.
1391
- * If no target is specified, it adds the sender to the context group.
1392
- *
1393
- * @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.
1394
- * 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.
1395
- * 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.
1396
- * Used by Platform Windows.
1397
- *
1398
- * @param contextGroupId - Id of the context group.
1399
- * @param target - Identity of the entity you wish to join to a context group.
1400
- *
1401
- * @example
1402
- * ```js
1403
- * joinViewToContextGroup = async (contextGroupId, view) => {
1404
- * await fin.me.interop.joinContextGroup(contextGroupId, view);
1405
- * }
1406
- *
1407
- * getLastFocusedView()
1408
- * .then(lastFocusedViewIdentity => {
1409
- * joinViewToContextGroup('red', lastFocusedViewIdentity)
1410
- * })
1411
- * ```
1412
- */
1413
- async joinContextGroup(contextGroupId, target) {
1414
- this.wire.sendAction('interop-client-join-context-group').catch((e) => {
1415
- // don't expose, analytics-only call
1416
- });
1417
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1418
- if (!contextGroupId) {
1419
- throw new Error('No contextGroupId specified for joinContextGroup.');
1420
- }
1421
- return client.dispatch('joinContextGroup', { contextGroupId, target });
1422
- }
1423
- /**
1424
- * Removes the specified target from a context group.
1425
- * If no target is specified, it removes the sender from their context group.
1426
- * Used by Platform Windows.
1427
- *
1428
- * @param target - Identity of the entity you wish to join to a context group.
1429
- *
1430
- * @example
1431
- * ```js
1432
- * removeViewFromContextGroup = async (view) => {
1433
- * await fin.me.interop.removeFromContextGroup(view);
1434
- * }
1435
- *
1436
- * getLastFocusedView()
1437
- * .then(lastFocusedViewIdentity => {
1438
- * removeViewFromContextGroup(lastFocusedViewIdentity)
1439
- * })
1440
- * ```
1441
- */
1442
- async removeFromContextGroup(target) {
1443
- this.wire.sendAction('interop-client-remove-from-context-group').catch((e) => {
1444
- // don't expose, analytics-only call
1445
- });
1446
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1447
- return client.dispatch('removeFromContextGroup', { target });
1448
- }
1449
- /**
1450
- * Gets all clients for a context group.
1451
- *
1452
- * @remarks **This is primarily used for platform windows. Views within a platform should not have to use this API.**
1453
- *
1454
- * Returns the Interop-Broker-defined context groups available for an entity to join.
1455
- * @param contextGroupId - The id of context group you wish to get clients for.
1456
- *
1457
- * @example
1458
- * ```js
1459
- * fin.me.interop.getAllClientsInContextGroup('red')
1460
- * .then(clientsInContextGroup => {
1461
- * console.log(clientsInContextGroup)
1462
- * })
1463
- * ```
1464
- */
1465
- async getAllClientsInContextGroup(contextGroupId) {
1466
- this.wire.sendAction('interop-client-get-all-clients-in-context-group').catch((e) => {
1467
- // don't expose, analytics-only call
1468
- });
1469
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1470
- if (!contextGroupId) {
1471
- throw new Error('No contextGroupId specified for getAllClientsInContextGroup.');
1472
- }
1473
- return client.dispatch('getAllClientsInContextGroup', { contextGroupId });
1474
- }
1475
- /**
1476
- * Gets display info for a context group
1477
- *
1478
- * @remarks Used by Platform Windows.
1479
- * @param contextGroupId - The id of context group you wish to get display info for.
1480
- *
1481
- * @example
1482
- * ```js
1483
- * fin.me.interop.getInfoForContextGroup('red')
1484
- * .then(contextGroupInfo => {
1485
- * console.log(contextGroupInfo.displayMetadata.name)
1486
- * console.log(contextGroupInfo.displayMetadata.color)
1487
- * })
1488
- * ```
1489
- */
1490
- async getInfoForContextGroup(contextGroupId) {
1491
- this.wire.sendAction('interop-client-get-info-for-context-group').catch((e) => {
1492
- // don't expose, analytics-only call
1493
- });
1494
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1495
- if (!contextGroupId) {
1496
- throw new Error('No contextGroupId specified for getInfoForContextGroup.');
1497
- }
1498
- return client.dispatch('getInfoForContextGroup', { contextGroupId });
1499
- }
1500
- /**
1501
- * Sends an intent to the Interop Broker to resolve.
1502
- * @param intent - The combination of an action and a context that is passed to an application for resolution.
1503
- *
1504
- * @example
1505
- * ```js
1506
- * // View wants to fire an Intent after a user clicks on a ticker
1507
- * tickerElement.on('click', (element) => {
1508
- * const ticker = element.innerText;
1509
- * const intent = {
1510
- * name: 'ViewChart',
1511
- * context: {type: 'fdc3.instrument', id: { ticker }}
1512
- * }
1513
- *
1514
- * fin.me.interop.fireIntent(intent);
1515
- * })
1516
- * ```
1517
- */
1518
- async fireIntent(intent) {
1519
- this.wire.sendAction('interop-client-fire-intent').catch((e) => {
1520
- // don't expose, this is only for api analytics purposes
1521
- });
1522
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1523
- return client.dispatch('fireIntent', intent);
1524
- }
1525
- /**
1526
- * Adds an intent handler for incoming intents. The last intent sent of the name subscribed to will be received.
1527
- * @param handler - Registered function meant to handle a specific intent type.
1528
- * @param intentName - The name of an intent.
1529
- *
1530
- * @example
1531
- * ```js
1532
- * const intentHandler = (intent) => {
1533
- * const { context } = intent;
1534
- * myViewChartHandler(context);
1535
- * };
1536
- *
1537
- * const subscription = await fin.me.interop.registerIntentHandler(intentHandler, 'ViewChart');
1538
- *
1539
- * function myAppCloseSequence() {
1540
- * // to unsubscribe the handler, simply call:
1541
- * subscription.unsubscribe();
1542
- * }
1543
- * ```
1544
- */
1545
- async registerIntentHandler(handler, intentName, options) {
1546
- this.wire.sendAction('interop-client-register-intent-handler').catch((e) => {
1547
- // don't expose, this is only for api analytics purposes
1548
- });
1549
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1550
- const handlerId = `intent-handler-${intentName}`;
1551
- const wrappedHandler = (0, utils_1.wrapIntentHandler)(handler, handlerId);
1552
- try {
1553
- await client.register(handlerId, wrappedHandler);
1554
- await client.dispatch('intentHandlerRegistered', { handlerId, ...options });
1555
- }
1556
- catch (error) {
1557
- throw new Error('Unable to register intent handler');
1558
- }
1559
- return {
1560
- unsubscribe: async () => {
1561
- client.remove(handlerId);
1562
- }
1563
- };
1564
- }
1565
- /**
1566
- * Gets the last context of the Context Group currently subscribed to. It takes an optional Context Type and returns the
1567
- * last context of that type.
1568
- * @param contextType
1569
- *
1570
- * @example
1571
- * ```js
1572
- * await fin.me.interop.joinContextGroup('yellow');
1573
- * await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
1574
- * const currentContext = await fin.me.interop.getCurrentContext();
1575
- *
1576
- * // with a specific context
1577
- * await fin.me.interop.joinContextGroup('yellow');
1578
- * await fin.me.interop.setContext({ type: 'country', id: { ISOALPHA3: 'US' }});
1579
- * await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
1580
- * const currentContext = await fin.me.interop.getCurrentContext('country');
1581
- * ```
1582
- */
1583
- async getCurrentContext(contextType) {
1584
- this.wire.sendAction('interop-client-get-current-context').catch((e) => {
1585
- // don't expose, analytics-only call
1586
- });
1587
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1588
- return client.dispatch('getCurrentContext', { contextType });
1589
- }
1590
- /**
1591
- * Get information for a particular Intent from the Interop Broker.
1592
- *
1593
- * @remarks To resolve this info, the function handleInfoForIntent is meant to be overridden in the Interop Broker.
1594
- * The format for the response will be determined by the App Provider overriding the function.
1595
- *
1596
- * @param options
1597
- *
1598
- * @example
1599
- * ```js
1600
- * const intentInfo = await fin.me.interop.getInfoForIntent('ViewChart');
1601
- * ```
1602
- */
1603
- async getInfoForIntent(options) {
1604
- this.wire.sendAction('interop-client-get-info-for-intent').catch((e) => {
1605
- // don't expose, analytics-only call
1606
- });
1607
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1608
- return client.dispatch('getInfoForIntent', options);
1609
- }
1610
- /**
1611
- * Get information from the Interop Broker on all Intents that are meant to handle a particular context.
1612
- *
1613
- * @remarks To resolve this info, the function handleInfoForIntentsByContext is meant to be overridden in the Interop Broker.
1614
- * The format for the response will be determined by the App Provider overriding the function.
1615
- *
1616
- * @param context
1617
- *
1618
- * @example
1619
- * ```js
1620
- * tickerElement.on('click', (element) => {
1621
- * const ticker = element.innerText;
1622
- *
1623
- * const context = {
1624
- * type: 'fdc3.instrument',
1625
- * id: {
1626
- * ticker
1627
- * }
1628
- * }
1629
- *
1630
- * const intentsInfo = await fin.me.interop.getInfoForIntentByContext(context);
1631
- * })
1632
- * ```
1633
- */
1634
- async getInfoForIntentsByContext(context) {
1635
- this.wire.sendAction('interop-client-get-info-for-intents-by-context').catch((e) => {
1636
- // don't expose, analytics-only call
1637
- });
1638
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1639
- return client.dispatch('getInfoForIntentsByContext', context);
1640
- }
1641
- /**
1642
- * Sends a Context that will be resolved to an Intent by the Interop Broker.
1643
- * This context accepts a metadata property.
1644
- *
1645
- * @remarks To resolve this info, the function handleFiredIntentByContext is meant to be overridden in the Interop Broker.
1646
- * The format for the response will be determined by the App Provider overriding the function.
1647
- *
1648
- * @param context
1649
- *
1650
- * @example
1651
- * ```js
1652
- * tickerElement.on('click', (element) => {
1653
- * const ticker = element.innerText;
1654
- *
1655
- * const context = {
1656
- * type: 'fdc3.instrument',
1657
- * id: {
1658
- * ticker
1659
- * }
1660
- * }
1661
- *
1662
- * const intentResolution = await fin.me.interop.fireIntentForContext(context);
1663
- * })
1664
- * ```
1665
- */
1666
- async fireIntentForContext(context) {
1667
- this.wire.sendAction('interop-client-fire-intent-for-context').catch((e) => {
1668
- // don't expose, analytics-only call
1669
- });
1670
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1671
- return client.dispatch('fireIntentForContext', context);
1672
- }
1673
- /**
1674
- * Join the current entity to session context group `sessionContextGroupId` and return a sessionContextGroup instance.
1675
- * If the sessionContextGroup doesn't exist, one will get created.
1676
- *
1677
- * @remarks Session Context Groups do not persist between runs and aren't present on snapshots.
1678
- * @param sessionContextGroupId - Id of the context group.
1679
- *
1680
- * @example
1681
- * Say we want to have a Session Context Group that holds UI theme information for all apps to consume:
1682
- *
1683
- * My color-picker View:
1684
- * ```js
1685
- * const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');
1686
- *
1687
- * const myColorPickerElement = document.getElementById('color-palette-picker');
1688
- * myColorPickerElement.addEventListener('change', event => {
1689
- * themeSessionContextGroup.setContext({ type: 'color-palette', selection: event.value });
1690
- * });
1691
- * ```
1692
- *
1693
- * In other views:
1694
- * ```js
1695
- * const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');
1696
- *
1697
- * const changeColorPalette = ({ selection }) => {
1698
- * // change the color palette to the selection
1699
- * };
1700
- *
1701
- * // If the context is already set by the time the handler was set, the handler will get invoked immediately with the current context.
1702
- * themeSessionContextGroup.addContextHandler(changeColorPalette, 'color-palette');
1703
- * ```
1704
- */
1705
- async joinSessionContextGroup(sessionContextGroupId) {
1706
- try {
1707
- const currentSessionContextGroup = __classPrivateFieldGet(this, _InteropClient_sessionContextGroups, "f").get(sessionContextGroupId);
1708
- if (currentSessionContextGroup) {
1709
- return currentSessionContextGroup.getUserInstance();
1710
- }
1711
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1712
- const { hasConflict } = await client.dispatch('sessionContextGroup:createIfNeeded', {
1713
- sessionContextGroupId
1714
- });
1715
- if (hasConflict) {
1716
- 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.`);
1717
- }
1718
- const newSessionContextGroup = new SessionContextGroupClient_1.default(this.wire, __classPrivateFieldGet(this, _InteropClient_clientPromise, "f"), sessionContextGroupId);
1719
- __classPrivateFieldGet(this, _InteropClient_sessionContextGroups, "f").set(sessionContextGroupId, newSessionContextGroup);
1720
- return newSessionContextGroup.getUserInstance();
1721
- }
1722
- catch (error) {
1723
- console.error(`Error thrown trying to create Session Context Group with id "${sessionContextGroupId}": ${error}`);
1724
- throw error;
1725
- }
1726
- }
1727
- /**
1728
- * Register a listener that is called when the Interop Client has been disconnected from the Interop Broker.
1729
- * Only one listener per Interop Client can be set.
1730
- * @param listener
1731
- *
1732
- * @example
1733
- * ```js
1734
- * const listener = (event) => {
1735
- * const { type, topic, brokerName} = event;
1736
- * console.log(`Disconnected from Interop Broker ${brokerName} `);
1737
- * }
1738
- *
1739
- * await fin.me.interop.onDisconnection(listener);
1740
- * ```
1741
- */
1742
- async onDisconnection(listener) {
1743
- this.wire.sendAction('interop-client-add-ondisconnection-listener').catch((e) => {
1744
- // don't expose, analytics-only call
1745
- });
1746
- const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
1747
- return client.onDisconnection((event) => {
1748
- const { uuid } = event;
1749
- listener({ type: 'interop-broker', topic: 'disconnected', brokerName: uuid });
1750
- });
1751
- }
1752
- getFDC3Sync(version) {
1753
- switch (version) {
1754
- case '1.2':
1755
- return new fdc3_1_2_1.Fdc3Module(() => this, this.wire);
1756
- case '2.0':
1757
- return new fdc3_2_0_1.Fdc3Module2(() => this, this.wire);
1758
- default:
1759
- throw new Error(`Invalid FDC3 version provided: ${version}. Must be '1.2' or '2.0'`);
1760
- }
1761
- }
1762
- async getFDC3(version) {
1763
- return this.getFDC3Sync(version);
1764
- }
1765
- /**
1766
- * @internal
1767
- *
1768
- * Used to ferry fdc3-only calls from the fdc3 shim to the Interop Broker
1769
- */
1770
- static async ferryFdc3Call(interopClient, action, payload) {
1771
- const client = await __classPrivateFieldGet(interopClient, _InteropClient_clientPromise, "f");
1772
- return client.dispatch(action, payload || null);
1773
- }
1774
- };
1775
- InteropClient.InteropClient = InteropClient$1;
1776
- _InteropClient_clientPromise = new WeakMap(), _InteropClient_sessionContextGroups = new WeakMap();
1777
- return InteropClient;
1688
+ Object.defineProperty(fdc31_2, "__esModule", { value: true });
1689
+ exports.Fdc3Module = fdc31_2.Fdc3Module = void 0;
1690
+ const utils_1$1 = utils$2;
1691
+ const fdc3_common_1$1 = fdc3Common;
1692
+ /**
1693
+ * @version 1.2
1694
+ * The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
1695
+ * while using our Interop API under the hood. In order to use this set of APIs
1696
+ * 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
1697
+ * our {@link https://developers.openfin.co/of-docs/docs/enable-color-linking Interop API}.
1698
+ *
1699
+ * To enable the FDC3 APIs in a {@link Window Window} or {@link View View}, add the fdc3InteropApi
1700
+ * property to its options:
1701
+ *
1702
+ * ```js
1703
+ * {
1704
+ * autoShow: false,
1705
+ * saveWindowState: true,
1706
+ * url: 'https://openfin.co',
1707
+ * fdc3InteropApi: '1.2'
1708
+ * }
1709
+ * ```
1710
+ *
1711
+ * If using a {@link Platform Platform } application, you can set this property in defaultWindowOptions and defaultViewOptions.
1712
+ *
1713
+ * In order to ensure that the FDC3 Api is ready before use, you can use the 'fdc3Ready' event fired on the DOM Window object:
1714
+ *
1715
+ * ```js
1716
+ * function fdc3Action() {
1717
+ * // Make some fdc3 API calls here
1718
+ * }
1719
+ *
1720
+ * if (window.fdc3) {
1721
+ * fdc3Action();
1722
+ * } else {
1723
+ * window.addEventListener('fdc3Ready', fdc3Action);
1724
+ * }
1725
+ * ```
1726
+ */
1727
+ class Fdc3Module extends fdc3_common_1$1.FDC3ModuleBase {
1728
+ async open(app, context) {
1729
+ // eslint-disable-next-line no-underscore-dangle
1730
+ await super._open(app, context);
1731
+ }
1732
+ /**
1733
+ * 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.
1734
+ * @param contextType - The type of context you wish to handle.
1735
+ * @param handler - Handler for incoming context.
1736
+ *
1737
+ * @tutorial fdc3.addContextListener
1738
+ * @static
1739
+ */
1740
+ // @ts-expect-error TODO [CORE-1524]
1741
+ addContextListener(contextType, handler) {
1742
+ this.wire.sendAction('fdc3-add-context-listener').catch((e) => {
1743
+ // we do not want to expose this error, just continue if this analytics-only call fails
1744
+ });
1745
+ let listener;
1746
+ if (typeof contextType === 'function') {
1747
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
1748
+ listener = this.client.addContextHandler(contextType);
1749
+ }
1750
+ else {
1751
+ listener = this.client.addContextHandler(handler, contextType === null ? undefined : contextType);
1752
+ }
1753
+ return {
1754
+ ...listener,
1755
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
1756
+ };
1757
+ }
1758
+ /**
1759
+ * Adds a listener for incoming Intents.
1760
+ * @param intent - Name of the Intent
1761
+ * @param handler - Handler for incoming Intent
1762
+ *
1763
+ * @tutorial fdc3.addIntentListener
1764
+ * @static
1765
+ */
1766
+ addIntentListener(intent, handler) {
1767
+ this.wire.sendAction('fdc3-add-intent-listener').catch((e) => {
1768
+ // we do not want to expose this error, just continue if this analytics-only call fails
1769
+ });
1770
+ const contextHandler = (raisedIntent) => {
1771
+ const { context, metadata: intentMetadata } = raisedIntent;
1772
+ const { metadata } = context;
1773
+ const intentResolutionResultId = intentMetadata?.intentResolutionResultId || metadata?.intentResolutionResultId;
1774
+ if (intentResolutionResultId) {
1775
+ this.fin.InterApplicationBus.publish(intentResolutionResultId, null).catch(() => null);
1776
+ }
1777
+ handler(raisedIntent.context);
1778
+ };
1779
+ const listener = this.client.registerIntentHandler(contextHandler, intent, {
1780
+ fdc3Version: '1.2'
1781
+ });
1782
+ return {
1783
+ ...listener,
1784
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
1785
+ };
1786
+ }
1787
+ /**
1788
+ * Raises a specific intent.
1789
+ * @param intent Name of the Intent.
1790
+ * @param context Context associated with the Intent.
1791
+ * @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}.
1792
+ *
1793
+ * @tutorial fdc3.raiseIntent
1794
+ * @static
1795
+ */
1796
+ async raiseIntent(intent, context, app) {
1797
+ this.wire.sendAction('fdc3-raise-intent').catch((e) => {
1798
+ // we do not want to expose this error, just continue if this analytics-only call fails
1799
+ });
1800
+ const intentObj = app
1801
+ ? { name: intent, context, metadata: { target: app } }
1802
+ : { name: intent, context };
1803
+ try {
1804
+ return await this.client.fireIntent(intentObj);
1805
+ }
1806
+ catch (error) {
1807
+ const errorToThrow = error.message === utils_1$1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
1808
+ throw new Error(errorToThrow);
1809
+ }
1810
+ }
1811
+ /**
1812
+ * Find out more information about a particular intent by passing its name, and optionally its context.
1813
+ * @param intent Name of the Intent
1814
+ * @param context
1815
+ *
1816
+ * @tutorial fdc3.findIntent
1817
+ */
1818
+ async findIntent(intent, context) {
1819
+ this.wire.sendAction('fdc3-find-intent').catch((e) => {
1820
+ // we do not want to expose this error, just continue if this analytics-only call fails
1821
+ });
1822
+ try {
1823
+ return await this.client.getInfoForIntent({ name: intent, context });
1824
+ }
1825
+ catch (error) {
1826
+ const errorToThrow = error.message === utils_1$1.BROKER_ERRORS.getInfoForIntent ? 'ResolverUnavailable' : error.message;
1827
+ throw new Error(errorToThrow);
1828
+ }
1829
+ }
1830
+ /**
1831
+ * Find all the available intents for a particular context.
1832
+ * @param context
1833
+ *
1834
+ * @tutorial fdc3.findIntentsByContext
1835
+ */
1836
+ async findIntentsByContext(context) {
1837
+ this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
1838
+ // we do not want to expose this error, just continue if this analytics-only call fails
1839
+ });
1840
+ try {
1841
+ return await this.client.getInfoForIntentsByContext(context);
1842
+ }
1843
+ catch (error) {
1844
+ const errorToThrow = error.message === utils_1$1.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error.message;
1845
+ throw new Error(errorToThrow);
1846
+ }
1847
+ }
1848
+ /**
1849
+ * Finds and raises an intent against a target app based purely on context data.
1850
+ * @param context
1851
+ * @param app
1852
+ *
1853
+ * @tutorial fdc3.raiseIntentForContext
1854
+ */
1855
+ async raiseIntentForContext(context, app) {
1856
+ this.wire.sendAction('fdc3-raise-intent-for-context').catch((e) => {
1857
+ // we do not want to expose this error, just continue if this analytics-only call fails
1858
+ });
1859
+ try {
1860
+ return await this.client.fireIntentForContext({ ...context, metadata: { target: app } });
1861
+ }
1862
+ catch (error) {
1863
+ const errorToThrow = error.message === utils_1$1.BROKER_ERRORS.fireIntentForContext ? 'ResolverUnavailable' : error.message;
1864
+ throw new Error(errorToThrow);
1865
+ }
1866
+ }
1867
+ /**
1868
+ * Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
1869
+ * @param channelId
1870
+ *
1871
+ * @tutorial fdc3.getOrCreateChannel
1872
+ */
1873
+ async getOrCreateChannel(channelId) {
1874
+ return super.getOrCreateChannel(channelId);
1875
+ }
1876
+ /**
1877
+ * 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.
1878
+ *
1879
+ * @tutorial fdc3.getInfo
1880
+ */
1881
+ getInfo() {
1882
+ this.wire.sendAction('fdc3-get-info').catch((e) => {
1883
+ // we do not want to expose this error, just continue if this analytics-only call fails
1884
+ });
1885
+ const version = this.wire.environment.getAdapterVersionSync();
1886
+ return {
1887
+ providerVersion: version,
1888
+ provider: `openfin-${this.wire.me.uuid}`,
1889
+ fdc3Version: '1.2'
1890
+ };
1891
+ }
1778
1892
  }
1893
+ exports.Fdc3Module = fdc31_2.Fdc3Module = Fdc3Module;
1779
1894
 
1780
- var hasRequiredFdc3Common;
1781
-
1782
- function requireFdc3Common () {
1783
- if (hasRequiredFdc3Common) return fdc3Common;
1784
- hasRequiredFdc3Common = 1;
1785
- var __classPrivateFieldGet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1786
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1787
- 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");
1788
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1789
- };
1790
- var __classPrivateFieldSet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
1791
- if (kind === "m") throw new TypeError("Private method is not writable");
1792
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1793
- 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");
1794
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1795
- };
1796
- var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1797
- return (mod && mod.__esModule) ? mod : { "default": mod };
1798
- };
1799
- var _FDC3ModuleBase_producer;
1800
- Object.defineProperty(fdc3Common, "__esModule", { value: true });
1801
- fdc3Common.FDC3ModuleBase = void 0;
1802
- const utils_1 = utils$1;
1803
- const utils_2 = utils$2;
1804
- const InteropClient_1 = requireInteropClient();
1805
- const isEqual_1 = __importDefault(require$$2);
1806
- class FDC3ModuleBase {
1807
- get client() {
1808
- return __classPrivateFieldGet(this, _FDC3ModuleBase_producer, "f").call(this);
1809
- }
1810
- get fin() {
1811
- return this.wire.getFin();
1812
- }
1813
- // eslint-disable-next-line no-useless-constructor
1814
- constructor(producer, wire) {
1815
- this.wire = wire;
1816
- _FDC3ModuleBase_producer.set(this, void 0);
1817
- __classPrivateFieldSet(this, _FDC3ModuleBase_producer, producer, "f");
1818
- }
1819
- /**
1820
- * Broadcasts a context for the channel of the current entity.
1821
- * @param context - New context to set.
1822
- *
1823
- * @tutorial fdc3.broadcast
1824
- * @static
1825
- */
1826
- async broadcast(context) {
1827
- this.wire.sendAction('fdc3-broadcast').catch((e) => {
1828
- // we do not want to expose this error, just continue if this analytics-only call fails
1829
- });
1830
- return this.client.setContext(context);
1831
- }
1832
- /**
1833
- * Launches an app with target information, which can either be a string or an AppMetadata object.
1834
- * @param app
1835
- * @param context
1836
- *
1837
- * @tutorial fdc3.open
1838
- */
1839
- async _open(app, context) {
1840
- this.wire.sendAction('fdc3-open').catch((e) => {
1841
- // we do not want to expose this error, just continue if this analytics-only call fails
1842
- });
1843
- try {
1844
- return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3Open', { app, context });
1845
- }
1846
- catch (error) {
1847
- const errorToThrow = error.message === utils_2.BROKER_ERRORS.fdc3Open ? 'ResolverUnavailable' : error.message;
1848
- throw new Error(errorToThrow);
1849
- }
1850
- }
1851
- async _getChannels() {
1852
- const channels = await this.client.getContextGroups();
1853
- // fdc3 implementation of getSystemChannels returns an array of channels, have to decorate over
1854
- // this so people know that these APIs are not supported
1855
- return channels.map((channel) => {
1856
- return { ...channel, type: 'system', ...(0, utils_1.getUnsupportedChannelApis)() };
1857
- });
1858
- }
1859
- /**
1860
- * Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
1861
- * @param channelId
1862
- *
1863
- * @tutorial fdc3.getOrCreateChannel
1864
- */
1865
- async getOrCreateChannel(channelId) {
1866
- this.wire.sendAction('fdc3-get-or-create-channel').catch((e) => {
1867
- // we do not want to expose this error, just continue if this analytics-only call fails
1868
- });
1869
- const systemChannels = await this._getChannels();
1870
- const userChannel = systemChannels.find((channel) => channel.id === channelId);
1871
- if (userChannel) {
1872
- return { ...userChannel, type: 'system', ...(0, utils_1.getUnsupportedChannelApis)() };
1873
- }
1874
- try {
1875
- const sessionContextGroup = await this.client.joinSessionContextGroup(channelId);
1876
- return (0, utils_1.buildAppChannelObject)(sessionContextGroup);
1877
- }
1878
- catch (error) {
1879
- console.error(error.message);
1880
- throw new Error(utils_1.ChannelError.CreationFailed);
1881
- }
1882
- }
1883
- /**
1884
- * Returns the Interop-Broker-defined context groups available for an entity to join.
1885
- *
1886
- * @tutorial fdc3.getSystemChannels
1887
- * @static
1888
- */
1889
- async getSystemChannels() {
1890
- this.wire.sendAction('fdc3-get-system-channels').catch((e) => {
1891
- // we do not want to expose this error, just continue if this analytics-only call fails
1892
- });
1893
- return this._getChannels();
1894
- }
1895
- /**
1896
- * Join all Interop Clients at the given identity to context group `contextGroupId`.
1897
- * If no target is specified, it adds the sender to the context group.
1898
- * 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.
1899
- * 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.
1900
- * 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.
1901
- * @param channelId - Id of the context group.
1902
- *
1903
- * @tutorial fdc3.joinChannel
1904
- * @static
1905
- */
1906
- async joinChannel(channelId) {
1907
- this.wire.sendAction('fdc3-join-channel').catch((e) => {
1908
- // we do not want to expose this error, just continue if this analytics-only call fails
1909
- });
1910
- try {
1911
- return await this.client.joinContextGroup(channelId);
1912
- }
1913
- catch (error) {
1914
- if (error.message === utils_2.BROKER_ERRORS.joinSessionContextGroupWithJoinContextGroup) {
1915
- 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.');
1916
- }
1917
- else {
1918
- console.error(error.message);
1919
- }
1920
- if (error.message.startsWith('Attempting to join a context group that does not exist')) {
1921
- throw new Error(utils_1.ChannelError.NoChannelFound);
1922
- }
1923
- throw new Error(utils_1.ChannelError.AccessDenied);
1924
- }
1925
- }
1926
- /**
1927
- * Returns the Channel that the entity is subscribed to. Returns null if not joined to a channel.
1928
- *
1929
- * @tutorial fdc3.getCurrentChannel
1930
- */
1931
- async getCurrentChannel() {
1932
- this.wire.sendAction('fdc3-get-current-channel').catch((e) => {
1933
- // we do not want to expose this error, just continue if this analytics-only call fails
1934
- });
1935
- const currentContextGroupInfo = await this.getCurrentContextGroupInfo();
1936
- if (!currentContextGroupInfo) {
1937
- return null;
1938
- }
1939
- return this.buildChannelObject(currentContextGroupInfo);
1940
- }
1941
- /**
1942
- * Removes the specified target from a context group.
1943
- * If no target is specified, it removes the sender from their context group.
1944
- *
1945
- * @tutorial fdc3.leaveCurrentChannel
1946
- * @static
1947
- */
1948
- async leaveCurrentChannel() {
1949
- this.wire.sendAction('fdc3-leave-current-channel').catch((e) => {
1950
- // we do not want to expose this error, just continue if this analytics-only call fails
1951
- });
1952
- return this.client.removeFromContextGroup();
1953
- }
1954
- // utils
1955
- // eslint-disable-next-line class-methods-use-this
1956
- async getCurrentContextGroupInfo() {
1957
- const contextGroups = await this.client.getContextGroups();
1958
- const clientsInCtxGroupsPromise = contextGroups.map(async (ctxGroup) => {
1959
- return this.client.getAllClientsInContextGroup(ctxGroup.id);
1960
- });
1961
- const clientsInCtxGroups = await Promise.all(clientsInCtxGroupsPromise);
1962
- const clientIdx = clientsInCtxGroups.findIndex((clientIdentityArr) => {
1963
- return clientIdentityArr.some((clientIdentity) => {
1964
- const { uuid, name } = clientIdentity;
1965
- return this.wire.me.uuid === uuid && this.wire.me.name === name;
1966
- });
1967
- });
1968
- return contextGroups[clientIdx];
1969
- }
1970
- async buildChannelObject(currentContextGroupInfo) {
1971
- // @ts-expect-error
1972
- return {
1973
- ...currentContextGroupInfo,
1974
- type: 'system',
1975
- addContextListener: (...[contextType, handler]) => {
1976
- let realHandler;
1977
- let realType;
1978
- if (typeof contextType === 'function') {
1979
- console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
1980
- realHandler = contextType;
1981
- }
1982
- else {
1983
- realHandler = handler;
1984
- if (typeof contextType === 'string') {
1985
- realType = contextType;
1986
- }
1987
- }
1988
- const listener = (async () => {
1989
- let first = true;
1990
- const currentContext = await this.client.getCurrentContext(realType);
1991
- const wrappedHandler = (context, contextMetadata) => {
1992
- if (first) {
1993
- first = false;
1994
- if ((0, isEqual_1.default)(currentContext, context)) {
1995
- return;
1996
- }
1997
- }
1998
- // eslint-disable-next-line consistent-return
1999
- return realHandler(context, contextMetadata);
2000
- };
2001
- return this.client.addContextHandler(wrappedHandler, realType);
2002
- })();
2003
- // @ts-expect-error TODO [CORE-1524]
2004
- return {
2005
- ...listener,
2006
- unsubscribe: () => listener.then((l) => l.unsubscribe())
2007
- };
2008
- },
2009
- broadcast: this.broadcast.bind(this),
2010
- // @ts-expect-error Typescript fails to infer the returntype is a Promise
2011
- getCurrentContext: async (contextType) => {
2012
- const context = await this.client.getCurrentContext(contextType);
2013
- // @ts-expect-error Typescript fails to infer the returntype is a Promise
2014
- return context === undefined ? null : context;
2015
- }
2016
- };
2017
- }
2018
- }
2019
- fdc3Common.FDC3ModuleBase = FDC3ModuleBase;
2020
- _FDC3ModuleBase_producer = new WeakMap();
2021
- return fdc3Common;
2022
- }
1895
+ var fdc3 = {};
2023
1896
 
2024
- var hasRequiredFdc31_2;
1897
+ var fdc32_0 = {};
2025
1898
 
2026
- function requireFdc31_2 () {
2027
- if (hasRequiredFdc31_2) return fdc31_2;
2028
- hasRequiredFdc31_2 = 1;
2029
- Object.defineProperty(fdc31_2, "__esModule", { value: true });
2030
- fdc31_2.Fdc3Module = void 0;
2031
- const utils_1 = utils$2;
2032
- const fdc3_common_1 = requireFdc3Common();
2033
- /**
2034
- * @version 1.2
2035
- * The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
2036
- * while using our Interop API under the hood. In order to use this set of APIs
2037
- * 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
2038
- * our {@link https://developers.openfin.co/of-docs/docs/enable-color-linking Interop API}.
2039
- *
2040
- * To enable the FDC3 APIs in a {@link Window Window} or {@link View View}, add the fdc3InteropApi
2041
- * property to its options:
2042
- *
2043
- * ```js
2044
- * {
2045
- * autoShow: false,
2046
- * saveWindowState: true,
2047
- * url: 'https://openfin.co',
2048
- * fdc3InteropApi: '1.2'
2049
- * }
2050
- * ```
2051
- *
2052
- * If using a {@link Platform Platform } application, you can set this property in defaultWindowOptions and defaultViewOptions.
2053
- *
2054
- * In order to ensure that the FDC3 Api is ready before use, you can use the 'fdc3Ready' event fired on the DOM Window object:
2055
- *
2056
- * ```js
2057
- * function fdc3Action() {
2058
- * // Make some fdc3 API calls here
2059
- * }
2060
- *
2061
- * if (window.fdc3) {
2062
- * fdc3Action();
2063
- * } else {
2064
- * window.addEventListener('fdc3Ready', fdc3Action);
2065
- * }
2066
- * ```
2067
- */
2068
- class Fdc3Module extends fdc3_common_1.FDC3ModuleBase {
2069
- async open(app, context) {
2070
- // eslint-disable-next-line no-underscore-dangle
2071
- await super._open(app, context);
2072
- }
2073
- /**
2074
- * 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.
2075
- * @param contextType - The type of context you wish to handle.
2076
- * @param handler - Handler for incoming context.
2077
- *
2078
- * @tutorial fdc3.addContextListener
2079
- * @static
2080
- */
2081
- // @ts-expect-error TODO [CORE-1524]
2082
- addContextListener(contextType, handler) {
2083
- this.wire.sendAction('fdc3-add-context-listener').catch((e) => {
2084
- // we do not want to expose this error, just continue if this analytics-only call fails
2085
- });
2086
- let listener;
2087
- if (typeof contextType === 'function') {
2088
- console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
2089
- listener = this.client.addContextHandler(contextType);
2090
- }
2091
- else {
2092
- listener = this.client.addContextHandler(handler, contextType === null ? undefined : contextType);
2093
- }
2094
- return {
2095
- ...listener,
2096
- unsubscribe: () => listener.then((l) => l.unsubscribe())
2097
- };
2098
- }
2099
- /**
2100
- * Adds a listener for incoming Intents.
2101
- * @param intent - Name of the Intent
2102
- * @param handler - Handler for incoming Intent
2103
- *
2104
- * @tutorial fdc3.addIntentListener
2105
- * @static
2106
- */
2107
- addIntentListener(intent, handler) {
2108
- this.wire.sendAction('fdc3-add-intent-listener').catch((e) => {
2109
- // we do not want to expose this error, just continue if this analytics-only call fails
2110
- });
2111
- const contextHandler = (raisedIntent) => {
2112
- const { context, metadata: intentMetadata } = raisedIntent;
2113
- const { metadata } = context;
2114
- const intentResolutionResultId = intentMetadata?.intentResolutionResultId || metadata?.intentResolutionResultId;
2115
- if (intentResolutionResultId) {
2116
- this.fin.InterApplicationBus.publish(intentResolutionResultId, null).catch(() => null);
2117
- }
2118
- handler(raisedIntent.context);
2119
- };
2120
- const listener = this.client.registerIntentHandler(contextHandler, intent, {
2121
- fdc3Version: '1.2'
2122
- });
2123
- return {
2124
- ...listener,
2125
- unsubscribe: () => listener.then((l) => l.unsubscribe())
2126
- };
2127
- }
2128
- /**
2129
- * Raises a specific intent.
2130
- * @param intent Name of the Intent.
2131
- * @param context Context associated with the Intent.
2132
- * @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}.
2133
- *
2134
- * @tutorial fdc3.raiseIntent
2135
- * @static
2136
- */
2137
- async raiseIntent(intent, context, app) {
2138
- this.wire.sendAction('fdc3-raise-intent').catch((e) => {
2139
- // we do not want to expose this error, just continue if this analytics-only call fails
2140
- });
2141
- const intentObj = app
2142
- ? { name: intent, context, metadata: { target: app } }
2143
- : { name: intent, context };
2144
- try {
2145
- return await this.client.fireIntent(intentObj);
2146
- }
2147
- catch (error) {
2148
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
2149
- throw new Error(errorToThrow);
2150
- }
2151
- }
2152
- /**
2153
- * Find out more information about a particular intent by passing its name, and optionally its context.
2154
- * @param intent Name of the Intent
2155
- * @param context
2156
- *
2157
- * @tutorial fdc3.findIntent
2158
- */
2159
- async findIntent(intent, context) {
2160
- this.wire.sendAction('fdc3-find-intent').catch((e) => {
2161
- // we do not want to expose this error, just continue if this analytics-only call fails
2162
- });
2163
- try {
2164
- return await this.client.getInfoForIntent({ name: intent, context });
2165
- }
2166
- catch (error) {
2167
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntent ? 'ResolverUnavailable' : error.message;
2168
- throw new Error(errorToThrow);
2169
- }
2170
- }
2171
- /**
2172
- * Find all the available intents for a particular context.
2173
- * @param context
2174
- *
2175
- * @tutorial fdc3.findIntentsByContext
2176
- */
2177
- async findIntentsByContext(context) {
2178
- this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
2179
- // we do not want to expose this error, just continue if this analytics-only call fails
2180
- });
2181
- try {
2182
- return await this.client.getInfoForIntentsByContext(context);
2183
- }
2184
- catch (error) {
2185
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error.message;
2186
- throw new Error(errorToThrow);
2187
- }
2188
- }
2189
- /**
2190
- * Finds and raises an intent against a target app based purely on context data.
2191
- * @param context
2192
- * @param app
2193
- *
2194
- * @tutorial fdc3.raiseIntentForContext
2195
- */
2196
- async raiseIntentForContext(context, app) {
2197
- this.wire.sendAction('fdc3-raise-intent-for-context').catch((e) => {
2198
- // we do not want to expose this error, just continue if this analytics-only call fails
2199
- });
2200
- try {
2201
- return await this.client.fireIntentForContext({ ...context, metadata: { target: app } });
2202
- }
2203
- catch (error) {
2204
- const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntentForContext ? 'ResolverUnavailable' : error.message;
2205
- throw new Error(errorToThrow);
2206
- }
2207
- }
2208
- /**
2209
- * Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
2210
- * @param channelId
2211
- *
2212
- * @tutorial fdc3.getOrCreateChannel
2213
- */
2214
- async getOrCreateChannel(channelId) {
2215
- return super.getOrCreateChannel(channelId);
2216
- }
2217
- /**
2218
- * 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.
2219
- *
2220
- * @tutorial fdc3.getInfo
2221
- */
2222
- getInfo() {
2223
- this.wire.sendAction('fdc3-get-info').catch((e) => {
2224
- // we do not want to expose this error, just continue if this analytics-only call fails
2225
- });
2226
- const version = this.wire.environment.getAdapterVersionSync();
2227
- return {
2228
- providerVersion: version,
2229
- provider: `openfin-${this.wire.me.uuid}`,
2230
- fdc3Version: '1.2'
2231
- };
2232
- }
2233
- }
2234
- fdc31_2.Fdc3Module = Fdc3Module;
2235
- return fdc31_2;
1899
+ Object.defineProperty(fdc32_0, "__esModule", { value: true });
1900
+ exports.Fdc3Module2 = fdc32_0.Fdc3Module2 = void 0;
1901
+ const fdc3_common_1 = fdc3Common;
1902
+ const utils_1 = utils$2;
1903
+ const InteropClient_1 = InteropClient$1;
1904
+ const utils_2 = utils$1;
1905
+ const PrivateChannelClient_1 = PrivateChannelClient$1;
1906
+ /**
1907
+ * @version 2.0
1908
+ * The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
1909
+ * while using our Interop API under the hood. In order to use this set of APIs
1910
+ * 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
1911
+ * our {@link https://developers.openfin.co/of-docs/docs/enable-context-sharing Interop API}.
1912
+ *
1913
+ * To enable the FDC3 APIs in a {@link Window Window} or {@link View View}, add the fdc3InteropApi
1914
+ * property to its options:
1915
+ *
1916
+ * ```js
1917
+ * {
1918
+ * autoShow: false,
1919
+ * saveWindowState: true,
1920
+ * url: 'https://openfin.co',
1921
+ * fdc3InteropApi: '2.0'
1922
+ * }
1923
+ * ```
1924
+ *
1925
+ * If using a {@link Platform Platform } application, you can set this property in defaultWindowOptions and defaultViewOptions.
1926
+ *
1927
+ * In order to ensure that the FDC3 Api is ready before use, you can use the 'fdc3Ready' event fired on the DOM Window object:
1928
+ *
1929
+ * ```js
1930
+ * function fdc3Action() {
1931
+ * // Make some fdc3 API calls here
1932
+ * }
1933
+ *
1934
+ * if (window.fdc3) {
1935
+ * fdc3Action();
1936
+ * } else {
1937
+ * window.addEventListener('fdc3Ready', fdc3Action);
1938
+ * }
1939
+ * ```
1940
+ */
1941
+ class Fdc3Module2 extends fdc3_common_1.FDC3ModuleBase {
1942
+ /**
1943
+ * Launches an app, specified via an AppIdentifier object.
1944
+ * @param app
1945
+ * @param context
1946
+ *
1947
+ * @tutorial fdc3.open
1948
+ */
1949
+ async open(app, context) {
1950
+ if (typeof app === 'string') {
1951
+ console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
1952
+ }
1953
+ // eslint-disable-next-line no-underscore-dangle
1954
+ return super._open(app, context);
1955
+ }
1956
+ /**
1957
+ * Find all the available instances for a particular application.
1958
+ * @param app
1959
+ *
1960
+ * @tutorial fdc3v2.findInstances
1961
+ */
1962
+ async findInstances(app) {
1963
+ this.wire.sendAction('fdc3-find-instances').catch((e) => {
1964
+ // we do not want to expose this error, just continue if this analytics-only call fails
1965
+ });
1966
+ try {
1967
+ return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3FindInstances', app);
1968
+ }
1969
+ catch (error) {
1970
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fdc3FindInstances ? 'ResolverUnavailable' : error.message;
1971
+ throw new Error(errorToThrow);
1972
+ }
1973
+ }
1974
+ /**
1975
+ * 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.
1976
+ * @param app
1977
+ *
1978
+ * @tutorial fdc3v2.getAppMetadata
1979
+ */
1980
+ async getAppMetadata(app) {
1981
+ this.wire.sendAction('fdc3-get-app-metadata').catch((e) => {
1982
+ // we do not want to expose this error, just continue if this analytics-only call fails
1983
+ });
1984
+ try {
1985
+ return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3GetAppMetadata', app);
1986
+ }
1987
+ catch (error) {
1988
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fdc3GetAppMetadata ? 'ResolverUnavailable' : error.message;
1989
+ throw new Error(errorToThrow);
1990
+ }
1991
+ }
1992
+ /**
1993
+ * 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.
1994
+ * @param contextType
1995
+ * @param handler
1996
+ *
1997
+ * @tutorial fdc3.addContextListener
1998
+ */
1999
+ // @ts-expect-error TODO [CORE-1524]
2000
+ async addContextListener(contextType, handler) {
2001
+ this.wire.sendAction('fdc3-add-context-listener').catch((e) => {
2002
+ // we do not want to expose this error, just continue if this analytics-only call fails
2003
+ });
2004
+ // The FDC3 ContextHandler only expects the context and optional ContextMetadata, so we wrap the handler
2005
+ // here so it only gets passed these parameters
2006
+ const getWrappedHandler = (handlerToWrap) => {
2007
+ return (context) => {
2008
+ const { contextMetadata, ...rest } = context;
2009
+ const args = contextMetadata ? [{ ...rest }, contextMetadata] : [context, null];
2010
+ handlerToWrap(...args);
2011
+ };
2012
+ };
2013
+ let actualHandler = handler;
2014
+ let wrappedHandler = getWrappedHandler(actualHandler);
2015
+ if (typeof contextType === 'function') {
2016
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
2017
+ actualHandler = contextType;
2018
+ wrappedHandler = getWrappedHandler(actualHandler);
2019
+ return this.client.addContextHandler(wrappedHandler);
2020
+ }
2021
+ return this.client.addContextHandler(wrappedHandler, contextType === null ? undefined : contextType);
2022
+ }
2023
+ /**
2024
+ * Find out more information about a particular intent by passing its name, and optionally its context and resultType.
2025
+ * @param intent Name of the Intent
2026
+ * @param context Context
2027
+ * @param resultType The type of result returned for any intent specified during resolution.
2028
+ *
2029
+ * @tutorial fdc3.findIntent
2030
+ */
2031
+ async findIntent(intent, context, resultType) {
2032
+ this.wire.sendAction('fdc3-find-intent').catch((e) => {
2033
+ // we do not want to expose this error, just continue if this analytics-only call fails
2034
+ });
2035
+ try {
2036
+ return await this.client.getInfoForIntent({ name: intent, context, metadata: { resultType } });
2037
+ }
2038
+ catch (error) {
2039
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntent ? 'ResolverUnavailable' : error.message;
2040
+ throw new Error(errorToThrow);
2041
+ }
2042
+ }
2043
+ /**
2044
+ * Find all the available intents for a particular context.
2045
+ * @param context
2046
+ * @param resultType The type of result returned for any intent specified during resolution.
2047
+ *
2048
+ * @tutorial fdc3v2.findIntentsByContext
2049
+ */
2050
+ async findIntentsByContext(context, resultType) {
2051
+ this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
2052
+ // we do not want to expose this error, just continue if this analytics-only call fails
2053
+ });
2054
+ const payload = resultType ? { context, metadata: { resultType } } : context;
2055
+ try {
2056
+ return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3v2FindIntentsByContext', payload);
2057
+ }
2058
+ catch (error) {
2059
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error.message;
2060
+ throw new Error(errorToThrow);
2061
+ }
2062
+ }
2063
+ /**
2064
+ * Raises a specific intent for resolution against apps registered with the desktop agent.
2065
+ * @param intent Name of the Intent
2066
+ * @param context Context associated with the Intent
2067
+ * @param app
2068
+ *
2069
+ * @tutorial fdc3v2.raiseIntent
2070
+ */
2071
+ async raiseIntent(intent, context, app) {
2072
+ this.wire.sendAction('fdc3-raise-intent').catch((e) => {
2073
+ // we do not want to expose this error, just continue if this analytics-only call fails
2074
+ });
2075
+ try {
2076
+ if (typeof app === 'string') {
2077
+ console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
2078
+ }
2079
+ return (0, utils_2.getIntentResolution)(this.client, context, app, intent);
2080
+ }
2081
+ catch (error) {
2082
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
2083
+ throw new Error(errorToThrow);
2084
+ }
2085
+ }
2086
+ /**
2087
+ * Finds and raises an intent against apps registered with the desktop agent based purely on the type of the context data.
2088
+ * @param context Context associated with the Intent
2089
+ * @param app
2090
+ *
2091
+ * @tutorial fdc3v2.raiseIntentForContext
2092
+ */
2093
+ async raiseIntentForContext(context, app) {
2094
+ // TODO: We have to do the same thing we do for raiseIntent here as well.
2095
+ this.wire.sendAction('fdc3-raise-intent-for-context').catch((e) => {
2096
+ // we do not want to expose this error, just continue if this analytics-only call fails
2097
+ });
2098
+ try {
2099
+ if (typeof app === 'string') {
2100
+ console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
2101
+ }
2102
+ return (0, utils_2.getIntentResolution)(this.client, context, app);
2103
+ }
2104
+ catch (error) {
2105
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
2106
+ throw new Error(errorToThrow);
2107
+ }
2108
+ }
2109
+ /**
2110
+ * Adds a listener for incoming intents.
2111
+ * @param intent Name of the Intent
2112
+ * @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.
2113
+ *
2114
+ * @tutorial fdc3.addIntentListener
2115
+ */
2116
+ async addIntentListener(intent, handler) {
2117
+ this.wire.sendAction('fdc3-add-intent-listener').catch((e) => {
2118
+ // we do not want to expose this error, just continue if this analytics-only call fails
2119
+ });
2120
+ if (typeof intent !== 'string') {
2121
+ throw new Error('First argument must be an Intent name');
2122
+ }
2123
+ // The FDC3 Intenter handler only expects the context and contextMetadata to be passed to the handler,
2124
+ // so we wrap it here and only pass those paramaters.
2125
+ const contextHandler = async (raisedIntent) => {
2126
+ let intentResult;
2127
+ let intentResultToSend;
2128
+ const { context, metadata: intentMetadata } = raisedIntent;
2129
+ const { contextMetadata, metadata, ...rest } = context;
2130
+ const intentResolutionResultId = intentMetadata?.intentResolutionResultId || metadata?.intentResolutionResultId;
2131
+ try {
2132
+ const newContext = metadata ? { metadata, ...rest } : { ...rest };
2133
+ intentResult = await handler(newContext, contextMetadata);
2134
+ intentResultToSend = intentResult;
2135
+ }
2136
+ catch (error) {
2137
+ intentResult = error;
2138
+ intentResultToSend = { error: true };
2139
+ }
2140
+ if (intentResolutionResultId) {
2141
+ this.fin.InterApplicationBus.publish(intentResolutionResultId, intentResultToSend).catch(() => null);
2142
+ }
2143
+ if (intentResult instanceof Error) {
2144
+ throw new Error(intentResult.message);
2145
+ }
2146
+ return intentResult;
2147
+ };
2148
+ return this.client.registerIntentHandler(contextHandler, intent, { fdc3Version: '2.0' });
2149
+ }
2150
+ /**
2151
+ * Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
2152
+ * @param channelId
2153
+ *
2154
+ * @tutorial fdc3.getOrCreateChannel
2155
+ */
2156
+ async getOrCreateChannel(channelId) {
2157
+ return super.getOrCreateChannel(channelId);
2158
+ }
2159
+ /**
2160
+ * 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.
2161
+ *
2162
+ * @tutorial fdc3v2.createPrivateChannel
2163
+ */
2164
+ async createPrivateChannel() {
2165
+ const channelId = (0, utils_1.generateId)();
2166
+ await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'createPrivateChannelProvider', { channelId });
2167
+ const channelClient = await this.fin.InterApplicationBus.Channel.connect(channelId);
2168
+ const newPrivateChannelClient = new PrivateChannelClient_1.PrivateChannelClient(channelClient, channelId);
2169
+ return (0, utils_2.buildPrivateChannelObject)(newPrivateChannelClient);
2170
+ }
2171
+ /**
2172
+ * Retrieves a list of the User Channels available for the app to join.
2173
+ *
2174
+ * @tutorial fdc3v2.getUserChannels
2175
+ */
2176
+ async getUserChannels() {
2177
+ const channels = await this.client.getContextGroups();
2178
+ // fdc3 implementation of getUserChannels returns on array of channels, have to decorate over
2179
+ // this so people know that these APIs are not supported
2180
+ return channels.map((channel) => {
2181
+ // @ts-expect-error TODO [CORE-1524]
2182
+ return { ...channel, type: 'user', ...(0, utils_2.getUnsupportedChannelApis)('User') };
2183
+ });
2184
+ }
2185
+ /**
2186
+ * Retrieves a list of the User Channels available for the app to join.
2187
+ *
2188
+ * @deprecated Please use {@link fdc3.getUserChannels fdc3.getUserChannels} instead
2189
+ * @tutorial fdc3.getSystemChannels
2190
+ */
2191
+ async getSystemChannels() {
2192
+ console.warn('This API has been deprecated. Please use fdc3.getUserChannels instead.');
2193
+ return super.getSystemChannels();
2194
+ }
2195
+ /**
2196
+ * Join an app to a specified User channel.
2197
+ * @param channelId Channel name
2198
+ *
2199
+ * @tutorial fdc3v2.joinUserChannel
2200
+ */
2201
+ async joinUserChannel(channelId) {
2202
+ return super.joinChannel(channelId);
2203
+ }
2204
+ /**
2205
+ * Join an app to a specified User channel.
2206
+ * @param channelId Channel name
2207
+ * @deprecated Please use {@link fdc3.joinUserChannel fdc3.joinUserChannel} instead
2208
+ *
2209
+ * @tutorial fdc3.joinChannel
2210
+ */
2211
+ async joinChannel(channelId) {
2212
+ console.warn('This API has been deprecated. Please use fdc3.joinUserChannel instead.');
2213
+ return super.joinChannel(channelId);
2214
+ }
2215
+ /**
2216
+ * Returns the Channel object for the current User channel membership
2217
+ *
2218
+ * @tutorial fdc3.getCurrentChannel
2219
+ */
2220
+ async getCurrentChannel() {
2221
+ const currentChannel = await super.getCurrentChannel();
2222
+ if (!currentChannel) {
2223
+ return null;
2224
+ }
2225
+ return {
2226
+ ...currentChannel,
2227
+ type: 'user',
2228
+ broadcast: this.broadcast.bind(this)
2229
+ };
2230
+ }
2231
+ /**
2232
+ * 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.
2233
+ * fdc3HandleGetInfo must be overridden in the InteropBroker so that the ImplementationMetadata will have the appMetadata info.
2234
+ *
2235
+ * @tutorial fdc3v2.getInfo
2236
+ */
2237
+ async getInfo() {
2238
+ return InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3v2GetInfo', { fdc3Version: '2.0' });
2239
+ }
2236
2240
  }
2237
-
2238
- var fdc31_2Exports = requireFdc31_2();
2239
-
2240
- var fdc3 = {};
2241
+ exports.Fdc3Module2 = fdc32_0.Fdc3Module2 = Fdc3Module2;
2241
2242
 
2242
2243
  (function (exports) {
2243
2244
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -2245,8 +2246,8 @@ var fdc3 = {};
2245
2246
  /* eslint-disable no-console */
2246
2247
  /* eslint-disable no-param-reassign */
2247
2248
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2248
- const fdc3_1_2_1 = requireFdc31_2();
2249
- const fdc3_2_0_1 = requireFdc32_0();
2249
+ const fdc3_1_2_1 = fdc31_2;
2250
+ const fdc3_2_0_1 = fdc32_0;
2250
2251
  exports.versionMap = {
2251
2252
  '1.2': fdc3_1_2_1.Fdc3Module,
2252
2253
  '2.0': fdc3_2_0_1.Fdc3Module2
@@ -2265,13 +2266,9 @@ var fdc3 = {};
2265
2266
  exports.getFdc3 = getFdc3;
2266
2267
  } (fdc3));
2267
2268
 
2268
- var fdc32_0Exports = requireFdc32_0();
2269
-
2270
2269
  async function fdc3FromFin(fin, { fdc3Version } = { fdc3Version: '2.0' }) {
2271
2270
  // @ts-expect-error
2272
2271
  return fdc3.getFdc3(fin.wire, fdc3Version);
2273
2272
  }
2274
2273
 
2275
- exports.Fdc3Module = fdc31_2Exports.Fdc3Module;
2276
- exports.Fdc3Module2 = fdc32_0Exports.Fdc3Module2;
2277
2274
  exports.fdc3FromFin = fdc3FromFin;