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