@openfin/fdc3-api 37.81.30 → 38.81.19
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/package.json +1 -1
- package/out/fdc3-api-alpha.d.ts +0 -18078
- package/out/fdc3-api-beta.d.ts +0 -18078
- package/out/fdc3-api-public.d.ts +0 -18078
- package/out/fdc3-api.d.ts +0 -18537
- package/out/fdc3-api.js +0 -2251
package/out/fdc3-api.js
DELETED
|
@@ -1,2251 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var require$$2 = require('lodash');
|
|
4
|
-
|
|
5
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
6
|
-
|
|
7
|
-
var fdc31_2 = {};
|
|
8
|
-
|
|
9
|
-
var utils$2 = {};
|
|
10
|
-
|
|
11
|
-
(function (exports) {
|
|
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;
|
|
14
|
-
const generateId = () => `${Math.random()}${Date.now()}`;
|
|
15
|
-
exports.generateId = generateId;
|
|
16
|
-
const wrapInTryCatch = (f, prefix) => (...args) => {
|
|
17
|
-
try {
|
|
18
|
-
return f(...args);
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
throw new Error((prefix || '') + e);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
exports.wrapInTryCatch = wrapInTryCatch;
|
|
25
|
-
const wrapContextHandler = (handler, handlerId) => {
|
|
26
|
-
return async (context) => {
|
|
27
|
-
try {
|
|
28
|
-
await handler(context);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
console.error(`Error thrown by handler ${handlerId} for context type ${context.type}: ${error}`);
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
exports.wrapContextHandler = wrapContextHandler;
|
|
37
|
-
const generateOverrideError = (clientApi, brokerApi) => {
|
|
38
|
-
return `You have tried to to use ${clientApi} but ${brokerApi} has not been overridden in the Interop Broker. Please override this function. Refer to our documentation for more info.`;
|
|
39
|
-
};
|
|
40
|
-
exports.generateOverrideError = generateOverrideError;
|
|
41
|
-
const generateOverrideWarning = (fdc3ClientApi, brokerApi, identity, interopClientApi) => {
|
|
42
|
-
const { uuid, name } = identity;
|
|
43
|
-
const message = interopClientApi
|
|
44
|
-
? `Entity with identity: ${uuid}/${name} has called ${interopClientApi} or ${fdc3ClientApi} but ${brokerApi} has not been overridden.`
|
|
45
|
-
: `Entity with identity: ${uuid}/${name} has called ${fdc3ClientApi} but ${brokerApi} has not been overridden.`;
|
|
46
|
-
return message;
|
|
47
|
-
};
|
|
48
|
-
exports.generateOverrideWarning = generateOverrideWarning;
|
|
49
|
-
exports.BROKER_ERRORS = {
|
|
50
|
-
fireIntent: (0, exports.generateOverrideError)('fireIntent', 'handleFiredIntent'),
|
|
51
|
-
fireIntentForContext: (0, exports.generateOverrideError)('fireIntentForContext', 'handleFiredIntentForContext'),
|
|
52
|
-
getInfoForIntent: (0, exports.generateOverrideError)('getInfoForIntent', 'handleInfoForIntent'),
|
|
53
|
-
getInfoForIntentsByContext: (0, exports.generateOverrideError)('getInfoForIntentsByContext', 'handleInfoForIntentsByContext'),
|
|
54
|
-
joinSessionContextGroupWithJoinContextGroup: 'The Context Group you have tried to join is a Session Context Group. Custom Context Groups can only be defined by the Interop Broker through code or manifest configuration. Please use joinSessionContextGroup.',
|
|
55
|
-
fdc3Open: (0, exports.generateOverrideError)('fdc3.open', 'fdc3HandleOpen'),
|
|
56
|
-
fdc3FindInstances: (0, exports.generateOverrideError)('fdc3.findInstances', 'fdc3HandleFindInstances'),
|
|
57
|
-
fdc3GetAppMetadata: (0, exports.generateOverrideError)('fdc3.getAppMetadata', 'fdc3HandleGetAppMetadata'),
|
|
58
|
-
fdc3GetInfo: (0, exports.generateOverrideError)('fdc3.getInfo', 'fdc3HandleGetInfo')
|
|
59
|
-
};
|
|
60
|
-
const wrapIntentHandler = (handler, handlerId) => {
|
|
61
|
-
return async (intent) => {
|
|
62
|
-
try {
|
|
63
|
-
return handler(intent);
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
console.error(`Error thrown by handler ${handlerId}: ${error}`);
|
|
67
|
-
throw error;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
exports.wrapIntentHandler = wrapIntentHandler;
|
|
72
|
-
} (utils$2));
|
|
73
|
-
|
|
74
|
-
var fdc3Common = {};
|
|
75
|
-
|
|
76
|
-
var utils$1 = {};
|
|
77
|
-
|
|
78
|
-
var PrivateChannelClient$1 = {};
|
|
79
|
-
|
|
80
|
-
Object.defineProperty(PrivateChannelClient$1, "__esModule", { value: true });
|
|
81
|
-
PrivateChannelClient$1.PrivateChannelClient = void 0;
|
|
82
|
-
const utils = utils$2;
|
|
83
|
-
class PrivateChannelClient {
|
|
84
|
-
constructor(client, id) {
|
|
85
|
-
this.id = id;
|
|
86
|
-
this.client = client;
|
|
87
|
-
this.listeners = new Map();
|
|
88
|
-
}
|
|
89
|
-
async broadcast(context) {
|
|
90
|
-
return this.client.dispatch('broadcast', { context });
|
|
91
|
-
}
|
|
92
|
-
async getCurrentContext(contextType) {
|
|
93
|
-
return this.client.dispatch('getCurrentContext', { contextType });
|
|
94
|
-
}
|
|
95
|
-
async addContextListener(contextType, handler) {
|
|
96
|
-
if (typeof handler !== 'function') {
|
|
97
|
-
throw new Error("Non-function argument passed to the second parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
|
|
98
|
-
}
|
|
99
|
-
let handlerId;
|
|
100
|
-
if (contextType) {
|
|
101
|
-
handlerId = `contextHandler:invoke-${this.id}-${contextType}-${utils.generateId()}`;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
handlerId = `contextHandler:invoke-${this.id}-${utils.generateId()}`;
|
|
105
|
-
}
|
|
106
|
-
this.client.register(handlerId, utils.wrapContextHandler(handler, handlerId));
|
|
107
|
-
const listener = { unsubscribe: await this.createContextUnsubscribeCb(handlerId) };
|
|
108
|
-
this.listeners.set(handlerId, listener);
|
|
109
|
-
await this.client.dispatch(`contextHandlerAdded`, { handlerId, contextType });
|
|
110
|
-
return listener;
|
|
111
|
-
}
|
|
112
|
-
createNonStandardUnsubscribeCb(handlerId) {
|
|
113
|
-
return async () => {
|
|
114
|
-
this.client.remove(handlerId);
|
|
115
|
-
this.listeners.delete(handlerId);
|
|
116
|
-
await this.client.dispatch('nonStandardHandlerRemoved', { handlerId });
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
createContextUnsubscribeCb(handlerId) {
|
|
120
|
-
return async () => {
|
|
121
|
-
this.client.remove(handlerId);
|
|
122
|
-
this.listeners.delete(handlerId);
|
|
123
|
-
await this.client.dispatch('contextHandlerRemoved', { handlerId });
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
onAddContextListener(handler) {
|
|
127
|
-
const handlerId = `onContextHandlerAdded:invoke-${this.id}-${utils.generateId()}`;
|
|
128
|
-
this.client.register(handlerId, handler);
|
|
129
|
-
const listener = { unsubscribe: this.createNonStandardUnsubscribeCb(handlerId) };
|
|
130
|
-
this.listeners.set(handlerId, listener);
|
|
131
|
-
this.client.dispatch(`onAddContextHandlerAdded`, { handlerId });
|
|
132
|
-
return listener;
|
|
133
|
-
}
|
|
134
|
-
onDisconnect(handler) {
|
|
135
|
-
const handlerId = `onDisconnect:invoke-${this.id}-${utils.generateId()}`;
|
|
136
|
-
this.client.register(handlerId, handler);
|
|
137
|
-
const listener = { unsubscribe: this.createNonStandardUnsubscribeCb(handlerId) };
|
|
138
|
-
this.listeners.set(handlerId, listener);
|
|
139
|
-
this.client.dispatch(`onDisconnectHandlerAdded`, { handlerId });
|
|
140
|
-
return listener;
|
|
141
|
-
}
|
|
142
|
-
onUnsubscribe(handler) {
|
|
143
|
-
const handlerId = `onUnsubscribe:invoke-${this.id}-${utils.generateId()}`;
|
|
144
|
-
this.client.register(handlerId, handler);
|
|
145
|
-
const listener = { unsubscribe: this.createNonStandardUnsubscribeCb(handlerId) };
|
|
146
|
-
this.listeners.set(handlerId, listener);
|
|
147
|
-
this.client.dispatch(`onUnsubscribeHandlerAdded`, { handlerId });
|
|
148
|
-
return listener;
|
|
149
|
-
}
|
|
150
|
-
async cleanUpAllSubs() {
|
|
151
|
-
const listenerUnsubscribers = Array.from(this.listeners.keys());
|
|
152
|
-
listenerUnsubscribers.forEach((handlerId) => {
|
|
153
|
-
this.client.remove(handlerId);
|
|
154
|
-
this.listeners.delete(handlerId);
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
async disconnect() {
|
|
158
|
-
try {
|
|
159
|
-
await this.client.dispatch('clientDisconnecting');
|
|
160
|
-
await this.cleanUpAllSubs();
|
|
161
|
-
await this.client.disconnect();
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
throw new Error(error.message);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
PrivateChannelClient$1.PrivateChannelClient = PrivateChannelClient;
|
|
169
|
-
|
|
170
|
-
(function (exports) {
|
|
171
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
172
|
-
exports.getIntentResolution = exports.isChannel = exports.isContext = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ChannelError = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
|
|
173
|
-
const utils_1 = utils$2;
|
|
174
|
-
const PrivateChannelClient_1 = PrivateChannelClient$1;
|
|
175
|
-
const lodash_1 = require$$2;
|
|
176
|
-
const getUnsupportedChannelApis = (channelType) => {
|
|
177
|
-
return {
|
|
178
|
-
addContextListener: () => {
|
|
179
|
-
throw new UnsupportedChannelApiError('Channel.addContextListener', channelType);
|
|
180
|
-
},
|
|
181
|
-
broadcast: () => {
|
|
182
|
-
throw new UnsupportedChannelApiError('Channel.broadcast', channelType);
|
|
183
|
-
},
|
|
184
|
-
getCurrentContext: () => {
|
|
185
|
-
throw new UnsupportedChannelApiError('Channel.getCurrentContext', channelType);
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
exports.getUnsupportedChannelApis = getUnsupportedChannelApis;
|
|
190
|
-
class UnsupportedChannelApiError extends Error {
|
|
191
|
-
constructor(apiName, channelType = 'System') {
|
|
192
|
-
super(apiName);
|
|
193
|
-
this.message = `Calling ${apiName} on an instance of a ${channelType} Channel returned by fdc3.get${channelType}Channels is not supported. If you would like to use a ${channelType} Channel, please use fdc3.joinChannel, fdc3.addContextListener, and fdc3.broadcast instead.`;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
exports.UnsupportedChannelApiError = UnsupportedChannelApiError;
|
|
197
|
-
var ResultError;
|
|
198
|
-
(function (ResultError) {
|
|
199
|
-
/** Returned if the `IntentHandler` exited without returning a Promise or that
|
|
200
|
-
* Promise was not resolved with a Context or Channel object.
|
|
201
|
-
*/
|
|
202
|
-
ResultError["NoResultReturned"] = "NoResultReturned";
|
|
203
|
-
/** Returned if the `IntentHandler` function processing the raised intent
|
|
204
|
-
* throws an error or rejects the Promise it returned.
|
|
205
|
-
*/
|
|
206
|
-
ResultError["IntentHandlerRejected"] = "IntentHandlerRejected";
|
|
207
|
-
})(ResultError = exports.ResultError || (exports.ResultError = {}));
|
|
208
|
-
(function (ChannelError) {
|
|
209
|
-
/** Returned if the specified channel is not found when attempting to join a
|
|
210
|
-
* channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).
|
|
211
|
-
*/
|
|
212
|
-
ChannelError["NoChannelFound"] = "NoChannelFound";
|
|
213
|
-
/** SHOULD be returned when a request to join a user channel or to a retrieve
|
|
214
|
-
* a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods
|
|
215
|
-
* of the DesktopAgent (`fdc3`) object is denied.
|
|
216
|
-
*/
|
|
217
|
-
ChannelError["AccessDenied"] = "AccessDenied";
|
|
218
|
-
/** SHOULD be returned when a channel cannot be created or retrieved via the
|
|
219
|
-
* `getOrCreateChannel` method of the DesktopAgent (`fdc3`).
|
|
220
|
-
*/
|
|
221
|
-
ChannelError["CreationFailed"] = "CreationFailed";
|
|
222
|
-
})(exports.ChannelError || (exports.ChannelError = {}));
|
|
223
|
-
const buildPrivateChannelObject = (privateChannelClient) => {
|
|
224
|
-
let clientDisconnected = false;
|
|
225
|
-
const checkIfClientDisconnected = () => {
|
|
226
|
-
if (clientDisconnected) {
|
|
227
|
-
throw new Error('Private Channel Client has been disconnected from the Private Channel');
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
return {
|
|
231
|
-
id: privateChannelClient.id,
|
|
232
|
-
type: 'private',
|
|
233
|
-
broadcast: async (context) => {
|
|
234
|
-
checkIfClientDisconnected();
|
|
235
|
-
return privateChannelClient.broadcast(context);
|
|
236
|
-
},
|
|
237
|
-
getCurrentContext: async (contextType) => {
|
|
238
|
-
checkIfClientDisconnected();
|
|
239
|
-
return privateChannelClient.getCurrentContext(contextType);
|
|
240
|
-
},
|
|
241
|
-
// @ts-expect-error TODO [CORE-1524]
|
|
242
|
-
addContextListener: async (contextType, handler) => {
|
|
243
|
-
checkIfClientDisconnected();
|
|
244
|
-
let handlerInUse = handler;
|
|
245
|
-
let contextTypeInUse = contextType;
|
|
246
|
-
if (typeof contextType === 'function') {
|
|
247
|
-
console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
|
|
248
|
-
handlerInUse = contextType;
|
|
249
|
-
contextTypeInUse = null;
|
|
250
|
-
}
|
|
251
|
-
const listener = privateChannelClient.addContextListener(contextTypeInUse, handlerInUse);
|
|
252
|
-
return listener;
|
|
253
|
-
},
|
|
254
|
-
onAddContextListener: (handler) => {
|
|
255
|
-
checkIfClientDisconnected();
|
|
256
|
-
return privateChannelClient.onAddContextListener(handler);
|
|
257
|
-
},
|
|
258
|
-
disconnect: async () => {
|
|
259
|
-
checkIfClientDisconnected();
|
|
260
|
-
clientDisconnected = true;
|
|
261
|
-
return privateChannelClient.disconnect();
|
|
262
|
-
},
|
|
263
|
-
onDisconnect: (handler) => {
|
|
264
|
-
checkIfClientDisconnected();
|
|
265
|
-
return privateChannelClient.onDisconnect(handler);
|
|
266
|
-
},
|
|
267
|
-
onUnsubscribe: (handler) => {
|
|
268
|
-
checkIfClientDisconnected();
|
|
269
|
-
return privateChannelClient.onUnsubscribe(handler);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
};
|
|
273
|
-
exports.buildPrivateChannelObject = buildPrivateChannelObject;
|
|
274
|
-
const buildAppChannelObject = (sessionContextGroup) => {
|
|
275
|
-
return {
|
|
276
|
-
id: sessionContextGroup.id,
|
|
277
|
-
type: 'app',
|
|
278
|
-
broadcast: sessionContextGroup.setContext,
|
|
279
|
-
getCurrentContext: async (contextType) => {
|
|
280
|
-
const context = await sessionContextGroup.getCurrentContext(contextType);
|
|
281
|
-
return context === undefined ? null : context;
|
|
282
|
-
},
|
|
283
|
-
// @ts-expect-error TODO [CORE-1524]
|
|
284
|
-
addContextListener: (contextType, handler) => {
|
|
285
|
-
let realHandler;
|
|
286
|
-
let realType;
|
|
287
|
-
if (typeof contextType === 'function') {
|
|
288
|
-
console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
|
|
289
|
-
realHandler = contextType;
|
|
290
|
-
}
|
|
291
|
-
else {
|
|
292
|
-
realHandler = handler;
|
|
293
|
-
if (typeof contextType === 'string') {
|
|
294
|
-
realType = contextType;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
const listener = (async () => {
|
|
298
|
-
let first = true;
|
|
299
|
-
const currentContext = await sessionContextGroup.getCurrentContext(realType);
|
|
300
|
-
const wrappedHandler = (context, contextMetadata) => {
|
|
301
|
-
if (first) {
|
|
302
|
-
first = false;
|
|
303
|
-
if ((0, lodash_1.isEqual)(currentContext, context)) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
// eslint-disable-next-line consistent-return
|
|
308
|
-
return realHandler(context, contextMetadata);
|
|
309
|
-
};
|
|
310
|
-
return sessionContextGroup.addContextHandler(wrappedHandler, realType);
|
|
311
|
-
})();
|
|
312
|
-
return {
|
|
313
|
-
...listener,
|
|
314
|
-
unsubscribe: () => listener.then((l) => l.unsubscribe())
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
};
|
|
319
|
-
exports.buildAppChannelObject = buildAppChannelObject;
|
|
320
|
-
const connectPrivateChannel = async (channelId) => {
|
|
321
|
-
try {
|
|
322
|
-
const channelClient = await fin.InterApplicationBus.Channel.connect(channelId);
|
|
323
|
-
const privateChannelClient = new PrivateChannelClient_1.PrivateChannelClient(channelClient, channelId);
|
|
324
|
-
return (0, exports.buildPrivateChannelObject)(privateChannelClient);
|
|
325
|
-
}
|
|
326
|
-
catch (error) {
|
|
327
|
-
throw new Error(`Private Channel with id: ${channelId} doesn't exist`);
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
exports.connectPrivateChannel = connectPrivateChannel;
|
|
331
|
-
const isContext = (context) => {
|
|
332
|
-
if (context && typeof context === 'object' && 'type' in context) {
|
|
333
|
-
const { type } = context;
|
|
334
|
-
return typeof type === 'string';
|
|
335
|
-
}
|
|
336
|
-
return false;
|
|
337
|
-
};
|
|
338
|
-
exports.isContext = isContext;
|
|
339
|
-
const isChannel = (channel) => {
|
|
340
|
-
if (channel && typeof channel === 'object' && 'type' in channel && 'id' in channel) {
|
|
341
|
-
const { type, id } = channel;
|
|
342
|
-
return typeof type === 'string' && typeof id === 'string' && (type === 'app' || type === 'private');
|
|
343
|
-
}
|
|
344
|
-
return false;
|
|
345
|
-
};
|
|
346
|
-
exports.isChannel = isChannel;
|
|
347
|
-
const getIntentResolution = async (interopModule, context, app, intent) => {
|
|
348
|
-
// Generate an ID to make a session context group with. We will pass that ID to the Broker.
|
|
349
|
-
// The broker will then setContext on that session context group later with our Intent Result,
|
|
350
|
-
const guid = (0, utils_1.generateId)(); // TODO make this undefined in web
|
|
351
|
-
// Promise we'll use in getResult
|
|
352
|
-
const getResultPromise = new Promise((resolve, reject) => {
|
|
353
|
-
fin.InterApplicationBus.subscribe({ uuid: '*' }, guid, (intentResult) => {
|
|
354
|
-
resolve(intentResult);
|
|
355
|
-
}).catch(() => reject(new Error('getResult is not supported in this environment')));
|
|
356
|
-
});
|
|
357
|
-
// Adding the intentResolutionResultId to the intentObj. Because fireIntent only accepts a single arg, we have to slap it in here.
|
|
358
|
-
const metadata = app ? { target: app, intentResolutionResultId: guid } : { intentResolutionResultId: guid };
|
|
359
|
-
const intentObj = intent ? { name: intent, context, metadata } : { ...context, metadata };
|
|
360
|
-
// Set up the getResult call.
|
|
361
|
-
const getResult = async () => {
|
|
362
|
-
let intentResult = await getResultPromise;
|
|
363
|
-
if (!intentResult || typeof intentResult !== 'object') {
|
|
364
|
-
throw new Error(ResultError.NoResultReturned);
|
|
365
|
-
}
|
|
366
|
-
const { error } = intentResult;
|
|
367
|
-
if (error) {
|
|
368
|
-
throw new Error(ResultError.IntentHandlerRejected);
|
|
369
|
-
}
|
|
370
|
-
if ((0, exports.isChannel)(intentResult)) {
|
|
371
|
-
const { id, type } = intentResult;
|
|
372
|
-
switch (type) {
|
|
373
|
-
case 'private': {
|
|
374
|
-
intentResult = await (0, exports.connectPrivateChannel)(id);
|
|
375
|
-
break;
|
|
376
|
-
}
|
|
377
|
-
case 'app': {
|
|
378
|
-
const sessionContextGroup = await interopModule.joinSessionContextGroup(id);
|
|
379
|
-
intentResult = (0, exports.buildAppChannelObject)(sessionContextGroup);
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
else if (!(0, exports.isContext)(intentResult)) {
|
|
385
|
-
throw new Error(ResultError.NoResultReturned);
|
|
386
|
-
}
|
|
387
|
-
return intentResult;
|
|
388
|
-
};
|
|
389
|
-
// Finally fire the intent.
|
|
390
|
-
const intentResolutionInfoFromBroker = intent
|
|
391
|
-
? await interopModule.fireIntent(intentObj)
|
|
392
|
-
: await interopModule.fireIntentForContext(intentObj);
|
|
393
|
-
if (typeof intentResolutionInfoFromBroker !== 'object') {
|
|
394
|
-
return {
|
|
395
|
-
source: {
|
|
396
|
-
appId: '',
|
|
397
|
-
instanceId: ''
|
|
398
|
-
},
|
|
399
|
-
intent: '',
|
|
400
|
-
version: '2.0',
|
|
401
|
-
getResult
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
return { ...intentResolutionInfoFromBroker, getResult };
|
|
405
|
-
};
|
|
406
|
-
exports.getIntentResolution = getIntentResolution;
|
|
407
|
-
} (utils$1));
|
|
408
|
-
|
|
409
|
-
var InteropClient = {};
|
|
410
|
-
|
|
411
|
-
var base = {};
|
|
412
|
-
|
|
413
|
-
var promises = {};
|
|
414
|
-
|
|
415
|
-
Object.defineProperty(promises, "__esModule", { value: true });
|
|
416
|
-
promises.promiseMapSerial = promises.serial = promises.promiseMap = promises.promisify = void 0;
|
|
417
|
-
function promisify(func) {
|
|
418
|
-
return (...args) => new Promise((resolve, reject) => {
|
|
419
|
-
func(...args, (err, val) => (err ? reject(err) : resolve(val)));
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
promises.promisify = promisify;
|
|
423
|
-
async function promiseMap(arr, asyncF) {
|
|
424
|
-
return Promise.all(arr.map(asyncF));
|
|
425
|
-
}
|
|
426
|
-
promises.promiseMap = promiseMap;
|
|
427
|
-
async function serial(arr) {
|
|
428
|
-
const ret = [];
|
|
429
|
-
for (const func of arr) {
|
|
430
|
-
// eslint-disable-next-line no-await-in-loop
|
|
431
|
-
const next = await func();
|
|
432
|
-
ret.push(next);
|
|
433
|
-
}
|
|
434
|
-
return ret;
|
|
435
|
-
}
|
|
436
|
-
promises.serial = serial;
|
|
437
|
-
async function promiseMapSerial(arr, func) {
|
|
438
|
-
return serial(arr.map((value, index, array) => () => func(value, index, array)));
|
|
439
|
-
}
|
|
440
|
-
promises.promiseMapSerial = promiseMapSerial;
|
|
441
|
-
|
|
442
|
-
var __classPrivateFieldSet$1 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
443
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
444
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
445
|
-
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");
|
|
446
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
447
|
-
};
|
|
448
|
-
var __classPrivateFieldGet$1 = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
449
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
450
|
-
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");
|
|
451
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
452
|
-
};
|
|
453
|
-
var _EmitterBase_emitterAccessor;
|
|
454
|
-
Object.defineProperty(base, "__esModule", { value: true });
|
|
455
|
-
base.Reply = base.EmitterBase = base.Base = void 0;
|
|
456
|
-
const promises_1 = promises;
|
|
457
|
-
class Base {
|
|
458
|
-
/**
|
|
459
|
-
* @internal
|
|
460
|
-
*/
|
|
461
|
-
constructor(wire) {
|
|
462
|
-
/**
|
|
463
|
-
* @internal
|
|
464
|
-
* @deprecated
|
|
465
|
-
*/
|
|
466
|
-
this.isNodeEnvironment = () => {
|
|
467
|
-
return this.wire.environment.type === 'node';
|
|
468
|
-
};
|
|
469
|
-
/**
|
|
470
|
-
* @internal
|
|
471
|
-
* @deprecated
|
|
472
|
-
*/
|
|
473
|
-
this.isOpenFinEnvironment = () => {
|
|
474
|
-
return this.wire.environment.type === 'openfin';
|
|
475
|
-
};
|
|
476
|
-
/**
|
|
477
|
-
* @internal
|
|
478
|
-
* @deprecated
|
|
479
|
-
*/
|
|
480
|
-
this.isBrowserEnvironment = () => {
|
|
481
|
-
return this.wire.environment.type === 'other';
|
|
482
|
-
};
|
|
483
|
-
this.wire = wire;
|
|
484
|
-
}
|
|
485
|
-
get fin() {
|
|
486
|
-
return this.wire.getFin();
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* Provides access to the OpenFin representation of the current code context (usually a document
|
|
490
|
-
* such as a {@link OpenFin.View} or {@link OpenFin.Window}), as well as to the current `Interop` context.
|
|
491
|
-
*
|
|
492
|
-
* Useful for debugging in the devtools console, where this will intelligently type itself based
|
|
493
|
-
* on the context in which the devtools panel was opened.
|
|
494
|
-
*/
|
|
495
|
-
get me() {
|
|
496
|
-
return this.wire.me;
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
base.Base = Base;
|
|
500
|
-
/**
|
|
501
|
-
* An entity that emits OpenFin events.
|
|
502
|
-
*
|
|
503
|
-
* @remarks Event-binding methods are asynchronous as they must cross process boundaries
|
|
504
|
-
* and setup the listener in the browser process. When the `EventEmitter` receives an event from the browser process
|
|
505
|
-
* and emits on the renderer, all of the functions attached to that specific event are called synchronously. Any values
|
|
506
|
-
* returned by the called listeners are ignored and will be discarded. If the execution context of the window is destroyed
|
|
507
|
-
* by page navigation or reload, any events that have been setup in that context will be destroyed.
|
|
508
|
-
*
|
|
509
|
-
* It is important to keep in mind that when an ordinary listener function is called, the standard `this` keyword is intentionally
|
|
510
|
-
* set to reference the `EventEmitter` instance to which the listener is attached. It is possible to use ES6 Arrow Functions as
|
|
511
|
-
* listeners, however, when doing so, the `this` keyword will no longer reference the `EventEmitter` instance.
|
|
512
|
-
*
|
|
513
|
-
* Events re-propagate from smaller/more-local scopes to larger/more-global scopes. For example, an event emitted on a specific
|
|
514
|
-
* view will propagate to the window in which the view is embedded, and then to the application in which the window is running, and
|
|
515
|
-
* finally to the OpenFin runtime itself at the "system" level. Re-propagated events are prefixed with the name of the scope in which
|
|
516
|
-
* they originated - for example, a "shown" event emitted on a view will be re-propagated at the window level as "view-shown", and
|
|
517
|
-
* then to the application as "window-view-shown", and finally at the system level as "application-window-view-shown".
|
|
518
|
-
*
|
|
519
|
-
* All event propagations are visible at the System level, regardless of source, so transitive re-propagations (e.g. from view to window
|
|
520
|
-
* to application) are visible in their entirety at the system level. So, we can listen to the above event as "shown", "view-shown",
|
|
521
|
-
* "window-view-shown", or "application-window-view-shown."
|
|
522
|
-
*/
|
|
523
|
-
class EmitterBase extends Base {
|
|
524
|
-
constructor(wire, topic, ...additionalAccessors) {
|
|
525
|
-
super(wire);
|
|
526
|
-
this.topic = topic;
|
|
527
|
-
_EmitterBase_emitterAccessor.set(this, void 0);
|
|
528
|
-
this.eventNames = () => (this.hasEmitter() ? this.getOrCreateEmitter().eventNames() : []);
|
|
529
|
-
/**
|
|
530
|
-
* @internal
|
|
531
|
-
*/
|
|
532
|
-
this.emit = (eventType, payload, ...args) => {
|
|
533
|
-
return this.hasEmitter() ? this.getOrCreateEmitter().emit(eventType, payload, ...args) : false;
|
|
534
|
-
};
|
|
535
|
-
this.hasEmitter = () => this.wire.eventAggregator.has(__classPrivateFieldGet$1(this, _EmitterBase_emitterAccessor, "f"));
|
|
536
|
-
this.getOrCreateEmitter = () => this.wire.eventAggregator.getOrCreate(__classPrivateFieldGet$1(this, _EmitterBase_emitterAccessor, "f"));
|
|
537
|
-
this.listeners = (type) => this.hasEmitter() ? this.getOrCreateEmitter().listeners(type) : [];
|
|
538
|
-
this.listenerCount = (type) => this.hasEmitter() ? this.getOrCreateEmitter().listenerCount(type) : 0;
|
|
539
|
-
this.registerEventListener = async (eventType, options = {}, applySubscription, undoSubscription) => {
|
|
540
|
-
const runtimeEvent = {
|
|
541
|
-
...this.identity,
|
|
542
|
-
timestamp: options.timestamp || Date.now(),
|
|
543
|
-
topic: this.topic,
|
|
544
|
-
type: eventType
|
|
545
|
-
};
|
|
546
|
-
const emitter = this.getOrCreateEmitter();
|
|
547
|
-
// We apply the subscription and then undo if the async call fails to avoid
|
|
548
|
-
// indeterminacy in subscription application order, which can break things elsewhere
|
|
549
|
-
applySubscription(emitter);
|
|
550
|
-
try {
|
|
551
|
-
await this.wire.sendAction('subscribe-to-desktop-event', runtimeEvent);
|
|
552
|
-
}
|
|
553
|
-
catch (e) {
|
|
554
|
-
undoSubscription(emitter);
|
|
555
|
-
this.deleteEmitterIfNothingRegistered(emitter);
|
|
556
|
-
throw e;
|
|
557
|
-
}
|
|
558
|
-
};
|
|
559
|
-
this.deregisterEventListener = async (eventType, options = {}) => {
|
|
560
|
-
if (this.hasEmitter()) {
|
|
561
|
-
const runtimeEvent = {
|
|
562
|
-
...this.identity,
|
|
563
|
-
timestamp: options.timestamp || Date.now(),
|
|
564
|
-
topic: this.topic,
|
|
565
|
-
type: eventType
|
|
566
|
-
};
|
|
567
|
-
await this.wire.sendAction('unsubscribe-to-desktop-event', runtimeEvent).catch(() => null);
|
|
568
|
-
const emitter = this.getOrCreateEmitter();
|
|
569
|
-
return emitter;
|
|
570
|
-
}
|
|
571
|
-
// This will only be reached if unsubscribe from event that does not exist but do not want to error here
|
|
572
|
-
return Promise.resolve();
|
|
573
|
-
};
|
|
574
|
-
__classPrivateFieldSet$1(this, _EmitterBase_emitterAccessor, [topic, ...additionalAccessors], "f");
|
|
575
|
-
this.listeners = (event) => this.hasEmitter() ? this.getOrCreateEmitter().listeners(event) : [];
|
|
576
|
-
}
|
|
577
|
-
/**
|
|
578
|
-
* Adds a listener to the end of the listeners array for the specified event.
|
|
579
|
-
*
|
|
580
|
-
* @remarks Event payloads are documented in the {@link OpenFin.Events} namespace.
|
|
581
|
-
*/
|
|
582
|
-
async on(eventType, listener, options) {
|
|
583
|
-
await this.registerEventListener(eventType, options, (emitter) => {
|
|
584
|
-
emitter.on(eventType, listener);
|
|
585
|
-
}, (emitter) => {
|
|
586
|
-
emitter.removeListener(eventType, listener);
|
|
587
|
-
});
|
|
588
|
-
return this;
|
|
589
|
-
}
|
|
590
|
-
/**
|
|
591
|
-
* Adds a listener to the end of the listeners array for the specified event.
|
|
592
|
-
*/
|
|
593
|
-
async addListener(eventType, listener, options) {
|
|
594
|
-
return this.on(eventType, listener, options);
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* Adds a one time listener for the event. The listener is invoked only the first time the event is fired, after which it is removed.
|
|
598
|
-
*
|
|
599
|
-
* @remarks Event payloads are documented in the {@link OpenFin.Events} namespace.
|
|
600
|
-
*/
|
|
601
|
-
async once(eventType, listener, options) {
|
|
602
|
-
const deregister = () => this.deregisterEventListener(eventType);
|
|
603
|
-
await this.registerEventListener(eventType, options, (emitter) => {
|
|
604
|
-
emitter.once(eventType, deregister);
|
|
605
|
-
emitter.once(eventType, listener);
|
|
606
|
-
}, (emitter) => {
|
|
607
|
-
emitter.removeListener(eventType, deregister);
|
|
608
|
-
emitter.removeListener(eventType, listener);
|
|
609
|
-
});
|
|
610
|
-
return this;
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* Adds a listener to the beginning of the listeners array for the specified event.
|
|
614
|
-
*
|
|
615
|
-
* @remarks Event payloads are documented in the {@link OpenFin.Events} namespace.
|
|
616
|
-
*/
|
|
617
|
-
async prependListener(eventType, listener, options) {
|
|
618
|
-
await this.registerEventListener(eventType, options, (emitter) => {
|
|
619
|
-
emitter.prependListener(eventType, listener);
|
|
620
|
-
}, (emitter) => {
|
|
621
|
-
emitter.removeListener(eventType, listener);
|
|
622
|
-
});
|
|
623
|
-
return this;
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* Adds a one time listener for the event. The listener is invoked only the first time the event is fired,
|
|
627
|
-
* after which it is removed. The listener is added to the beginning of the listeners array.
|
|
628
|
-
*
|
|
629
|
-
* @remarks Event payloads are documented in the {@link OpenFin.Events} namespace.
|
|
630
|
-
*/
|
|
631
|
-
async prependOnceListener(eventType, listener, options) {
|
|
632
|
-
const deregister = () => this.deregisterEventListener(eventType);
|
|
633
|
-
await this.registerEventListener(eventType, options, (emitter) => {
|
|
634
|
-
emitter.prependOnceListener(eventType, listener);
|
|
635
|
-
emitter.once(eventType, deregister);
|
|
636
|
-
}, (emitter) => {
|
|
637
|
-
emitter.removeListener(eventType, listener);
|
|
638
|
-
emitter.removeListener(eventType, deregister);
|
|
639
|
-
});
|
|
640
|
-
return this;
|
|
641
|
-
}
|
|
642
|
-
/**
|
|
643
|
-
* Remove a listener from the listener array for the specified event.
|
|
644
|
-
*
|
|
645
|
-
* @remarks Caution: Calling this method changes the array indices in the listener array behind the listener.
|
|
646
|
-
*/
|
|
647
|
-
async removeListener(eventType, listener, options) {
|
|
648
|
-
const emitter = await this.deregisterEventListener(eventType, options);
|
|
649
|
-
if (emitter) {
|
|
650
|
-
emitter.removeListener(eventType, listener);
|
|
651
|
-
this.deleteEmitterIfNothingRegistered(emitter);
|
|
652
|
-
}
|
|
653
|
-
return this;
|
|
654
|
-
}
|
|
655
|
-
async deregisterAllListeners(eventType) {
|
|
656
|
-
const runtimeEvent = { ...this.identity, type: eventType, topic: this.topic };
|
|
657
|
-
if (this.hasEmitter()) {
|
|
658
|
-
const emitter = this.getOrCreateEmitter();
|
|
659
|
-
const refCount = emitter.listenerCount(runtimeEvent.type);
|
|
660
|
-
const unsubscribePromises = [];
|
|
661
|
-
for (let i = 0; i < refCount; i++) {
|
|
662
|
-
unsubscribePromises.push(this.wire.sendAction('unsubscribe-to-desktop-event', runtimeEvent).catch(() => null));
|
|
663
|
-
}
|
|
664
|
-
await Promise.all(unsubscribePromises);
|
|
665
|
-
return emitter;
|
|
666
|
-
}
|
|
667
|
-
return undefined;
|
|
668
|
-
}
|
|
669
|
-
/**
|
|
670
|
-
* Removes all listeners, or those of the specified event.
|
|
671
|
-
*
|
|
672
|
-
*/
|
|
673
|
-
async removeAllListeners(eventType) {
|
|
674
|
-
const removeByEvent = async (event) => {
|
|
675
|
-
const emitter = await this.deregisterAllListeners(event);
|
|
676
|
-
if (emitter) {
|
|
677
|
-
emitter.removeAllListeners(event);
|
|
678
|
-
this.deleteEmitterIfNothingRegistered(emitter);
|
|
679
|
-
}
|
|
680
|
-
};
|
|
681
|
-
if (eventType) {
|
|
682
|
-
await removeByEvent(eventType);
|
|
683
|
-
}
|
|
684
|
-
else if (this.hasEmitter()) {
|
|
685
|
-
const events = this.getOrCreateEmitter().eventNames();
|
|
686
|
-
await (0, promises_1.promiseMap)(events, removeByEvent);
|
|
687
|
-
}
|
|
688
|
-
return this;
|
|
689
|
-
}
|
|
690
|
-
deleteEmitterIfNothingRegistered(emitter) {
|
|
691
|
-
if (emitter.eventNames().length === 0) {
|
|
692
|
-
this.wire.eventAggregator.delete(__classPrivateFieldGet$1(this, _EmitterBase_emitterAccessor, "f"));
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
base.EmitterBase = EmitterBase;
|
|
697
|
-
_EmitterBase_emitterAccessor = new WeakMap();
|
|
698
|
-
class Reply {
|
|
699
|
-
}
|
|
700
|
-
base.Reply = Reply;
|
|
701
|
-
|
|
702
|
-
var SessionContextGroupClient$1 = {};
|
|
703
|
-
|
|
704
|
-
var __classPrivateFieldSet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
705
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
706
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
707
|
-
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");
|
|
708
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
709
|
-
};
|
|
710
|
-
var __classPrivateFieldGet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
711
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
712
|
-
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");
|
|
713
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
714
|
-
};
|
|
715
|
-
var _SessionContextGroupClient_clientPromise;
|
|
716
|
-
Object.defineProperty(SessionContextGroupClient$1, "__esModule", { value: true });
|
|
717
|
-
const base_1 = base;
|
|
718
|
-
const utils_1 = utils$2;
|
|
719
|
-
class SessionContextGroupClient extends base_1.Base {
|
|
720
|
-
constructor(wire, client, id) {
|
|
721
|
-
super(wire);
|
|
722
|
-
_SessionContextGroupClient_clientPromise.set(this, void 0);
|
|
723
|
-
this.id = id;
|
|
724
|
-
__classPrivateFieldSet(this, _SessionContextGroupClient_clientPromise, client, "f");
|
|
725
|
-
}
|
|
726
|
-
/**
|
|
727
|
-
* Sets a context for the session context group.
|
|
728
|
-
* @param context - New context to set.
|
|
729
|
-
*
|
|
730
|
-
* @tutorial interop.setContext
|
|
731
|
-
*/
|
|
732
|
-
async setContext(context) {
|
|
733
|
-
this.wire.sendAction('interop-session-context-group-set-context').catch((e) => {
|
|
734
|
-
// don't expose, analytics-only call
|
|
735
|
-
});
|
|
736
|
-
const client = await __classPrivateFieldGet(this, _SessionContextGroupClient_clientPromise, "f");
|
|
737
|
-
return client.dispatch(`sessionContextGroup:setContext-${this.id}`, {
|
|
738
|
-
sessionContextGroupId: this.id,
|
|
739
|
-
context
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
async getCurrentContext(type) {
|
|
743
|
-
this.wire.sendAction('interop-session-context-group-get-context').catch((e) => {
|
|
744
|
-
// don't expose, analytics-only call
|
|
745
|
-
});
|
|
746
|
-
const client = await __classPrivateFieldGet(this, _SessionContextGroupClient_clientPromise, "f");
|
|
747
|
-
return client.dispatch(`sessionContextGroup:getContext-${this.id}`, {
|
|
748
|
-
sessionContextGroupId: this.id,
|
|
749
|
-
type
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
async addContextHandler(contextHandler, contextType) {
|
|
753
|
-
this.wire.sendAction('interop-session-context-group-add-handler').catch((e) => {
|
|
754
|
-
// don't expose, analytics-only call
|
|
755
|
-
});
|
|
756
|
-
if (typeof contextHandler !== 'function') {
|
|
757
|
-
throw new Error("Non-function argument passed to the first parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
|
|
758
|
-
}
|
|
759
|
-
const client = await __classPrivateFieldGet(this, _SessionContextGroupClient_clientPromise, "f");
|
|
760
|
-
let handlerId;
|
|
761
|
-
if (contextType) {
|
|
762
|
-
handlerId = `sessionContextHandler:invoke-${this.id}-${contextType}-${(0, utils_1.generateId)()}`;
|
|
763
|
-
}
|
|
764
|
-
else {
|
|
765
|
-
handlerId = `sessionContextHandler:invoke-${this.id}`;
|
|
766
|
-
}
|
|
767
|
-
client.register(handlerId, (0, utils_1.wrapContextHandler)(contextHandler, handlerId));
|
|
768
|
-
await client.dispatch(`sessionContextGroup:handlerAdded-${this.id}`, { handlerId, contextType });
|
|
769
|
-
return { unsubscribe: await this.createUnsubscribeCb(handlerId) };
|
|
770
|
-
}
|
|
771
|
-
async createUnsubscribeCb(handlerId) {
|
|
772
|
-
const client = await __classPrivateFieldGet(this, _SessionContextGroupClient_clientPromise, "f");
|
|
773
|
-
return async () => {
|
|
774
|
-
client.remove(handlerId);
|
|
775
|
-
await client.dispatch(`sessionContextGroup:handlerRemoved-${this.id}`, { handlerId });
|
|
776
|
-
};
|
|
777
|
-
}
|
|
778
|
-
getUserInstance() {
|
|
779
|
-
return {
|
|
780
|
-
id: this.id,
|
|
781
|
-
setContext: (0, utils_1.wrapInTryCatch)(this.setContext.bind(this), 'Failed to set context: '),
|
|
782
|
-
getCurrentContext: (0, utils_1.wrapInTryCatch)(this.getCurrentContext.bind(this), 'Failed to get context: '),
|
|
783
|
-
addContextHandler: (0, utils_1.wrapInTryCatch)(this.addContextHandler.bind(this), 'Failed to add context handler: ')
|
|
784
|
-
};
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
SessionContextGroupClient$1.default = SessionContextGroupClient;
|
|
788
|
-
_SessionContextGroupClient_clientPromise = new WeakMap();
|
|
789
|
-
|
|
790
|
-
var fdc32_0 = {};
|
|
791
|
-
|
|
792
|
-
var hasRequiredFdc32_0;
|
|
793
|
-
|
|
794
|
-
function requireFdc32_0 () {
|
|
795
|
-
if (hasRequiredFdc32_0) return fdc32_0;
|
|
796
|
-
hasRequiredFdc32_0 = 1;
|
|
797
|
-
Object.defineProperty(fdc32_0, "__esModule", { value: true });
|
|
798
|
-
fdc32_0.Fdc3Module2 = void 0;
|
|
799
|
-
const fdc3_common_1 = requireFdc3Common();
|
|
800
|
-
const utils_1 = utils$2;
|
|
801
|
-
const InteropClient_1 = requireInteropClient();
|
|
802
|
-
const utils_2 = utils$1;
|
|
803
|
-
const PrivateChannelClient_1 = PrivateChannelClient$1;
|
|
804
|
-
/**
|
|
805
|
-
* @version 2.0
|
|
806
|
-
* The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
|
|
807
|
-
* while using our Interop API under the hood. In order to use this set of APIs
|
|
808
|
-
* 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
|
|
809
|
-
* our {@link https://developers.openfin.co/of-docs/docs/enable-context-sharing Interop API}.
|
|
810
|
-
*
|
|
811
|
-
* To enable the FDC3 APIs in a {@link Window Window} or {@link View View}, add the fdc3InteropApi
|
|
812
|
-
* property to its options:
|
|
813
|
-
*
|
|
814
|
-
* ```js
|
|
815
|
-
* {
|
|
816
|
-
* autoShow: false,
|
|
817
|
-
* saveWindowState: true,
|
|
818
|
-
* url: 'https://openfin.co',
|
|
819
|
-
* fdc3InteropApi: '2.0'
|
|
820
|
-
* }
|
|
821
|
-
* ```
|
|
822
|
-
*
|
|
823
|
-
* If using a {@link Platform Platform } application, you can set this property in defaultWindowOptions and defaultViewOptions.
|
|
824
|
-
*
|
|
825
|
-
* In order to ensure that the FDC3 Api is ready before use, you can use the 'fdc3Ready' event fired on the DOM Window object:
|
|
826
|
-
*
|
|
827
|
-
* ```js
|
|
828
|
-
* function fdc3Action() {
|
|
829
|
-
* // Make some fdc3 API calls here
|
|
830
|
-
* }
|
|
831
|
-
*
|
|
832
|
-
* if (window.fdc3) {
|
|
833
|
-
* fdc3Action();
|
|
834
|
-
* } else {
|
|
835
|
-
* window.addEventListener('fdc3Ready', fdc3Action);
|
|
836
|
-
* }
|
|
837
|
-
* ```
|
|
838
|
-
*/
|
|
839
|
-
class Fdc3Module2 extends fdc3_common_1.FDC3ModuleBase {
|
|
840
|
-
/**
|
|
841
|
-
* Launches an app, specified via an AppIdentifier object.
|
|
842
|
-
* @param app
|
|
843
|
-
* @param context
|
|
844
|
-
*
|
|
845
|
-
* @tutorial fdc3.open
|
|
846
|
-
*/
|
|
847
|
-
async open(app, context) {
|
|
848
|
-
if (typeof app === 'string') {
|
|
849
|
-
console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
|
|
850
|
-
}
|
|
851
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
852
|
-
return super._open(app, context);
|
|
853
|
-
}
|
|
854
|
-
/**
|
|
855
|
-
* Find all the available instances for a particular application.
|
|
856
|
-
* @param app
|
|
857
|
-
*
|
|
858
|
-
* @tutorial fdc3v2.findInstances
|
|
859
|
-
*/
|
|
860
|
-
async findInstances(app) {
|
|
861
|
-
this.wire.sendAction('fdc3-find-instances').catch((e) => {
|
|
862
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
863
|
-
});
|
|
864
|
-
try {
|
|
865
|
-
return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3FindInstances', app);
|
|
866
|
-
}
|
|
867
|
-
catch (error) {
|
|
868
|
-
const errorToThrow = error.message === utils_1.BROKER_ERRORS.fdc3FindInstances ? 'ResolverUnavailable' : error.message;
|
|
869
|
-
throw new Error(errorToThrow);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
/**
|
|
873
|
-
* 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.
|
|
874
|
-
* @param app
|
|
875
|
-
*
|
|
876
|
-
* @tutorial fdc3v2.getAppMetadata
|
|
877
|
-
*/
|
|
878
|
-
async getAppMetadata(app) {
|
|
879
|
-
this.wire.sendAction('fdc3-get-app-metadata').catch((e) => {
|
|
880
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
881
|
-
});
|
|
882
|
-
try {
|
|
883
|
-
return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3GetAppMetadata', app);
|
|
884
|
-
}
|
|
885
|
-
catch (error) {
|
|
886
|
-
const errorToThrow = error.message === utils_1.BROKER_ERRORS.fdc3GetAppMetadata ? 'ResolverUnavailable' : error.message;
|
|
887
|
-
throw new Error(errorToThrow);
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* 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.
|
|
892
|
-
* @param contextType
|
|
893
|
-
* @param handler
|
|
894
|
-
*
|
|
895
|
-
* @tutorial fdc3.addContextListener
|
|
896
|
-
*/
|
|
897
|
-
// @ts-expect-error TODO [CORE-1524]
|
|
898
|
-
async addContextListener(contextType, handler) {
|
|
899
|
-
this.wire.sendAction('fdc3-add-context-listener').catch((e) => {
|
|
900
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
901
|
-
});
|
|
902
|
-
// The FDC3 ContextHandler only expects the context and optional ContextMetadata, so we wrap the handler
|
|
903
|
-
// here so it only gets passed these parameters
|
|
904
|
-
const getWrappedHandler = (handlerToWrap) => {
|
|
905
|
-
return (context) => {
|
|
906
|
-
const { contextMetadata, ...rest } = context;
|
|
907
|
-
const args = contextMetadata ? [{ ...rest }, contextMetadata] : [context, null];
|
|
908
|
-
handlerToWrap(...args);
|
|
909
|
-
};
|
|
910
|
-
};
|
|
911
|
-
let actualHandler = handler;
|
|
912
|
-
let wrappedHandler = getWrappedHandler(actualHandler);
|
|
913
|
-
if (typeof contextType === 'function') {
|
|
914
|
-
console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
|
|
915
|
-
actualHandler = contextType;
|
|
916
|
-
wrappedHandler = getWrappedHandler(actualHandler);
|
|
917
|
-
return this.client.addContextHandler(wrappedHandler);
|
|
918
|
-
}
|
|
919
|
-
return this.client.addContextHandler(wrappedHandler, contextType === null ? undefined : contextType);
|
|
920
|
-
}
|
|
921
|
-
/**
|
|
922
|
-
* Find out more information about a particular intent by passing its name, and optionally its context and resultType.
|
|
923
|
-
* @param intent Name of the Intent
|
|
924
|
-
* @param context Context
|
|
925
|
-
* @param resultType The type of result returned for any intent specified during resolution.
|
|
926
|
-
*
|
|
927
|
-
* @tutorial fdc3.findIntent
|
|
928
|
-
*/
|
|
929
|
-
async findIntent(intent, context, resultType) {
|
|
930
|
-
this.wire.sendAction('fdc3-find-intent').catch((e) => {
|
|
931
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
932
|
-
});
|
|
933
|
-
try {
|
|
934
|
-
return await this.client.getInfoForIntent({ name: intent, context, metadata: { resultType } });
|
|
935
|
-
}
|
|
936
|
-
catch (error) {
|
|
937
|
-
const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntent ? 'ResolverUnavailable' : error.message;
|
|
938
|
-
throw new Error(errorToThrow);
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
/**
|
|
942
|
-
* Find all the available intents for a particular context.
|
|
943
|
-
* @param context
|
|
944
|
-
* @param resultType The type of result returned for any intent specified during resolution.
|
|
945
|
-
*
|
|
946
|
-
* @tutorial fdc3v2.findIntentsByContext
|
|
947
|
-
*/
|
|
948
|
-
async findIntentsByContext(context, resultType) {
|
|
949
|
-
this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
|
|
950
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
951
|
-
});
|
|
952
|
-
const payload = resultType ? { context, metadata: { resultType } } : context;
|
|
953
|
-
try {
|
|
954
|
-
return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3v2FindIntentsByContext', payload);
|
|
955
|
-
}
|
|
956
|
-
catch (error) {
|
|
957
|
-
const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error.message;
|
|
958
|
-
throw new Error(errorToThrow);
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
/**
|
|
962
|
-
* Raises a specific intent for resolution against apps registered with the desktop agent.
|
|
963
|
-
* @param intent Name of the Intent
|
|
964
|
-
* @param context Context associated with the Intent
|
|
965
|
-
* @param app
|
|
966
|
-
*
|
|
967
|
-
* @tutorial fdc3v2.raiseIntent
|
|
968
|
-
*/
|
|
969
|
-
async raiseIntent(intent, context, app) {
|
|
970
|
-
this.wire.sendAction('fdc3-raise-intent').catch((e) => {
|
|
971
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
972
|
-
});
|
|
973
|
-
try {
|
|
974
|
-
if (typeof app === 'string') {
|
|
975
|
-
console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
|
|
976
|
-
}
|
|
977
|
-
return (0, utils_2.getIntentResolution)(this.client, context, app, intent);
|
|
978
|
-
}
|
|
979
|
-
catch (error) {
|
|
980
|
-
const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
|
|
981
|
-
throw new Error(errorToThrow);
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
/**
|
|
985
|
-
* Finds and raises an intent against apps registered with the desktop agent based purely on the type of the context data.
|
|
986
|
-
* @param context Context associated with the Intent
|
|
987
|
-
* @param app
|
|
988
|
-
*
|
|
989
|
-
* @tutorial fdc3v2.raiseIntentForContext
|
|
990
|
-
*/
|
|
991
|
-
async raiseIntentForContext(context, app) {
|
|
992
|
-
// TODO: We have to do the same thing we do for raiseIntent here as well.
|
|
993
|
-
this.wire.sendAction('fdc3-raise-intent-for-context').catch((e) => {
|
|
994
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
995
|
-
});
|
|
996
|
-
try {
|
|
997
|
-
if (typeof app === 'string') {
|
|
998
|
-
console.warn('Passing a string as the app parameter is deprecated, please use an AppIdentifier ({ appId: string; instanceId?: string }).');
|
|
999
|
-
}
|
|
1000
|
-
return (0, utils_2.getIntentResolution)(this.client, context, app);
|
|
1001
|
-
}
|
|
1002
|
-
catch (error) {
|
|
1003
|
-
const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
|
|
1004
|
-
throw new Error(errorToThrow);
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
/**
|
|
1008
|
-
* Adds a listener for incoming intents.
|
|
1009
|
-
* @param intent Name of the Intent
|
|
1010
|
-
* @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.
|
|
1011
|
-
*
|
|
1012
|
-
* @tutorial fdc3.addIntentListener
|
|
1013
|
-
*/
|
|
1014
|
-
async addIntentListener(intent, handler) {
|
|
1015
|
-
this.wire.sendAction('fdc3-add-intent-listener').catch((e) => {
|
|
1016
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
1017
|
-
});
|
|
1018
|
-
if (typeof intent !== 'string') {
|
|
1019
|
-
throw new Error('First argument must be an Intent name');
|
|
1020
|
-
}
|
|
1021
|
-
// The FDC3 Intenter handler only expects the context and contextMetadata to be passed to the handler,
|
|
1022
|
-
// so we wrap it here and only pass those paramaters.
|
|
1023
|
-
const contextHandler = async (raisedIntent) => {
|
|
1024
|
-
let intentResult;
|
|
1025
|
-
let intentResultToSend;
|
|
1026
|
-
const { context, metadata: intentMetadata } = raisedIntent;
|
|
1027
|
-
const { contextMetadata, metadata, ...rest } = context;
|
|
1028
|
-
const intentResolutionResultId = intentMetadata?.intentResolutionResultId || metadata?.intentResolutionResultId;
|
|
1029
|
-
try {
|
|
1030
|
-
const newContext = metadata ? { metadata, ...rest } : { ...rest };
|
|
1031
|
-
intentResult = await handler(newContext, contextMetadata);
|
|
1032
|
-
intentResultToSend = intentResult;
|
|
1033
|
-
}
|
|
1034
|
-
catch (error) {
|
|
1035
|
-
intentResult = error;
|
|
1036
|
-
intentResultToSend = { error: true };
|
|
1037
|
-
}
|
|
1038
|
-
if (intentResolutionResultId) {
|
|
1039
|
-
this.fin.InterApplicationBus.publish(intentResolutionResultId, intentResultToSend).catch(() => null);
|
|
1040
|
-
}
|
|
1041
|
-
if (intentResult instanceof Error) {
|
|
1042
|
-
throw new Error(intentResult.message);
|
|
1043
|
-
}
|
|
1044
|
-
return intentResult;
|
|
1045
|
-
};
|
|
1046
|
-
return this.client.registerIntentHandler(contextHandler, intent, { fdc3Version: '2.0' });
|
|
1047
|
-
}
|
|
1048
|
-
/**
|
|
1049
|
-
* Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
|
|
1050
|
-
* @param channelId
|
|
1051
|
-
*
|
|
1052
|
-
* @tutorial fdc3.getOrCreateChannel
|
|
1053
|
-
*/
|
|
1054
|
-
async getOrCreateChannel(channelId) {
|
|
1055
|
-
return super.getOrCreateChannel(channelId);
|
|
1056
|
-
}
|
|
1057
|
-
/**
|
|
1058
|
-
* 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.
|
|
1059
|
-
*
|
|
1060
|
-
* @tutorial fdc3v2.createPrivateChannel
|
|
1061
|
-
*/
|
|
1062
|
-
async createPrivateChannel() {
|
|
1063
|
-
const channelId = (0, utils_1.generateId)();
|
|
1064
|
-
await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'createPrivateChannelProvider', { channelId });
|
|
1065
|
-
const channelClient = await this.fin.InterApplicationBus.Channel.connect(channelId);
|
|
1066
|
-
const newPrivateChannelClient = new PrivateChannelClient_1.PrivateChannelClient(channelClient, channelId);
|
|
1067
|
-
return (0, utils_2.buildPrivateChannelObject)(newPrivateChannelClient);
|
|
1068
|
-
}
|
|
1069
|
-
/**
|
|
1070
|
-
* Retrieves a list of the User Channels available for the app to join.
|
|
1071
|
-
*
|
|
1072
|
-
* @tutorial fdc3v2.getUserChannels
|
|
1073
|
-
*/
|
|
1074
|
-
async getUserChannels() {
|
|
1075
|
-
const channels = await this.client.getContextGroups();
|
|
1076
|
-
// fdc3 implementation of getUserChannels returns on array of channels, have to decorate over
|
|
1077
|
-
// this so people know that these APIs are not supported
|
|
1078
|
-
return channels.map((channel) => {
|
|
1079
|
-
// @ts-expect-error TODO [CORE-1524]
|
|
1080
|
-
return { ...channel, type: 'user', ...(0, utils_2.getUnsupportedChannelApis)('User') };
|
|
1081
|
-
});
|
|
1082
|
-
}
|
|
1083
|
-
/**
|
|
1084
|
-
* Retrieves a list of the User Channels available for the app to join.
|
|
1085
|
-
*
|
|
1086
|
-
* @deprecated Please use {@link fdc3.getUserChannels fdc3.getUserChannels} instead
|
|
1087
|
-
* @tutorial fdc3.getSystemChannels
|
|
1088
|
-
*/
|
|
1089
|
-
async getSystemChannels() {
|
|
1090
|
-
console.warn('This API has been deprecated. Please use fdc3.getUserChannels instead.');
|
|
1091
|
-
return super.getSystemChannels();
|
|
1092
|
-
}
|
|
1093
|
-
/**
|
|
1094
|
-
* Join an app to a specified User channel.
|
|
1095
|
-
* @param channelId Channel name
|
|
1096
|
-
*
|
|
1097
|
-
* @tutorial fdc3v2.joinUserChannel
|
|
1098
|
-
*/
|
|
1099
|
-
async joinUserChannel(channelId) {
|
|
1100
|
-
return super.joinChannel(channelId);
|
|
1101
|
-
}
|
|
1102
|
-
/**
|
|
1103
|
-
* Join an app to a specified User channel.
|
|
1104
|
-
* @param channelId Channel name
|
|
1105
|
-
* @deprecated Please use {@link fdc3.joinUserChannel fdc3.joinUserChannel} instead
|
|
1106
|
-
*
|
|
1107
|
-
* @tutorial fdc3.joinChannel
|
|
1108
|
-
*/
|
|
1109
|
-
async joinChannel(channelId) {
|
|
1110
|
-
console.warn('This API has been deprecated. Please use fdc3.joinUserChannel instead.');
|
|
1111
|
-
return super.joinChannel(channelId);
|
|
1112
|
-
}
|
|
1113
|
-
/**
|
|
1114
|
-
* Returns the Channel object for the current User channel membership
|
|
1115
|
-
*
|
|
1116
|
-
* @tutorial fdc3.getCurrentChannel
|
|
1117
|
-
*/
|
|
1118
|
-
async getCurrentChannel() {
|
|
1119
|
-
const currentChannel = await super.getCurrentChannel();
|
|
1120
|
-
if (!currentChannel) {
|
|
1121
|
-
return null;
|
|
1122
|
-
}
|
|
1123
|
-
return {
|
|
1124
|
-
...currentChannel,
|
|
1125
|
-
type: 'user',
|
|
1126
|
-
broadcast: this.broadcast.bind(this)
|
|
1127
|
-
};
|
|
1128
|
-
}
|
|
1129
|
-
/**
|
|
1130
|
-
* 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.
|
|
1131
|
-
* fdc3HandleGetInfo must be overridden in the InteropBroker so that the ImplementationMetadata will have the appMetadata info.
|
|
1132
|
-
*
|
|
1133
|
-
* @tutorial fdc3v2.getInfo
|
|
1134
|
-
*/
|
|
1135
|
-
async getInfo() {
|
|
1136
|
-
return InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3v2GetInfo', { fdc3Version: '2.0' });
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
fdc32_0.Fdc3Module2 = Fdc3Module2;
|
|
1140
|
-
return fdc32_0;
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
var hasRequiredInteropClient;
|
|
1144
|
-
|
|
1145
|
-
function requireInteropClient () {
|
|
1146
|
-
if (hasRequiredInteropClient) return InteropClient;
|
|
1147
|
-
hasRequiredInteropClient = 1;
|
|
1148
|
-
var __classPrivateFieldSet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
1149
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1150
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
1151
|
-
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");
|
|
1152
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1153
|
-
};
|
|
1154
|
-
var __classPrivateFieldGet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
1155
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1156
|
-
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");
|
|
1157
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1158
|
-
};
|
|
1159
|
-
var _InteropClient_clientPromise, _InteropClient_sessionContextGroups;
|
|
1160
|
-
Object.defineProperty(InteropClient, "__esModule", { value: true });
|
|
1161
|
-
InteropClient.InteropClient = void 0;
|
|
1162
|
-
const base_1 = base;
|
|
1163
|
-
const SessionContextGroupClient_1 = SessionContextGroupClient$1;
|
|
1164
|
-
const fdc3_1_2_1 = requireFdc31_2();
|
|
1165
|
-
const fdc3_2_0_1 = requireFdc32_0();
|
|
1166
|
-
const utils_1 = utils$2;
|
|
1167
|
-
/**
|
|
1168
|
-
* The Interop Client API is broken up into two groups:
|
|
1169
|
-
*
|
|
1170
|
-
* **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.
|
|
1171
|
-
*
|
|
1172
|
-
* **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.
|
|
1173
|
-
*
|
|
1174
|
-
* ---
|
|
1175
|
-
*
|
|
1176
|
-
* All APIs are available at the `fin.me.interop` namespace.
|
|
1177
|
-
*
|
|
1178
|
-
* ---
|
|
1179
|
-
*
|
|
1180
|
-
* **You only need 2 things to participate in Interop Context Grouping:**
|
|
1181
|
-
* * A Context Handler for incoming context: {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
|
|
1182
|
-
* * Call setContext on your context group when you want to share context with other group members: {@link InteropClient#setContext setContext(context)}
|
|
1183
|
-
*
|
|
1184
|
-
* ---
|
|
1185
|
-
*
|
|
1186
|
-
* ##### Constructor
|
|
1187
|
-
* Returned by {@link Interop.connectSync Interop.connectSync}.
|
|
1188
|
-
*
|
|
1189
|
-
* ---
|
|
1190
|
-
*
|
|
1191
|
-
* ##### Interop methods intended for Views
|
|
1192
|
-
*
|
|
1193
|
-
*
|
|
1194
|
-
* **Context Groups API**
|
|
1195
|
-
* * {@link InteropClient#addContextHandler addContextHandler(handler, contextType?)}
|
|
1196
|
-
* * {@link InteropClient#setContext setContext(context)}
|
|
1197
|
-
* * {@link InteropClient#getCurrentContext getCurrentContext(contextType?)}
|
|
1198
|
-
* * {@link InteropClient#joinSessionContextGroup joinSessionContextGroup(sessionContextGroupId)}
|
|
1199
|
-
*
|
|
1200
|
-
*
|
|
1201
|
-
* **Intents API**
|
|
1202
|
-
* * {@link InteropClient#fireIntent fireIntent(intent)}
|
|
1203
|
-
* * {@link InteropClient#registerIntentHandler registerIntentHandler(intentHandler, intentName)}
|
|
1204
|
-
* * {@link InteropClient#getInfoForIntent getInfoForIntent(infoForIntentOptions)}
|
|
1205
|
-
* * {@link InteropClient#getInfoForIntentsByContext getInfoForIntentsByContext(context)}
|
|
1206
|
-
* * {@link InteropClient#fireIntentForContext fireIntentForContext(contextForIntent)}
|
|
1207
|
-
*
|
|
1208
|
-
* ##### Interop methods intended for Windows
|
|
1209
|
-
* * {@link InteropClient#getContextGroups getContextGroups()}
|
|
1210
|
-
* * {@link InteropClient#joinContextGroup joinContextGroup(contextGroupId, target?)}
|
|
1211
|
-
* * {@link InteropClient#removeFromContextGroup removeFromContextGroup(target?)}
|
|
1212
|
-
* * {@link InteropClient#getInfoForContextGroup getInfoForContextGroup(contextGroupId)}
|
|
1213
|
-
* * {@link InteropClient#getAllClientsInContextGroup getAllClientsInContextGroup(contextGroupId)}
|
|
1214
|
-
*
|
|
1215
|
-
*/
|
|
1216
|
-
let InteropClient$1 = class InteropClient extends base_1.Base {
|
|
1217
|
-
/**
|
|
1218
|
-
* @internal
|
|
1219
|
-
*/
|
|
1220
|
-
constructor(wire, clientPromise) {
|
|
1221
|
-
super(wire);
|
|
1222
|
-
_InteropClient_clientPromise.set(this, void 0);
|
|
1223
|
-
_InteropClient_sessionContextGroups.set(this, void 0);
|
|
1224
|
-
__classPrivateFieldSet(this, _InteropClient_sessionContextGroups, new Map(), "f");
|
|
1225
|
-
__classPrivateFieldSet(this, _InteropClient_clientPromise, clientPromise, "f");
|
|
1226
|
-
}
|
|
1227
|
-
/*
|
|
1228
|
-
Client APIs
|
|
1229
|
-
*/
|
|
1230
|
-
/**
|
|
1231
|
-
* Sets a context for the context group of the current entity.
|
|
1232
|
-
*
|
|
1233
|
-
* @remarks The entity must be part of a context group in order set a context.
|
|
1234
|
-
*
|
|
1235
|
-
* @param context - New context to set.
|
|
1236
|
-
*
|
|
1237
|
-
* @example
|
|
1238
|
-
* ```js
|
|
1239
|
-
* setInstrumentContext = async (ticker) => {
|
|
1240
|
-
* fin.me.interop.setContext({type: 'instrument', id: {ticker}})
|
|
1241
|
-
* }
|
|
1242
|
-
*
|
|
1243
|
-
* // 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
|
|
1244
|
-
* instrumentElement.on('click', (evt) => {
|
|
1245
|
-
* setInstrumentContext(evt.ticker)
|
|
1246
|
-
* })
|
|
1247
|
-
* ```
|
|
1248
|
-
*/
|
|
1249
|
-
async setContext(context) {
|
|
1250
|
-
this.wire.sendAction('interop-client-set-context').catch((e) => {
|
|
1251
|
-
// don't expose, analytics-only call
|
|
1252
|
-
});
|
|
1253
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1254
|
-
return client.dispatch('setContext', { context });
|
|
1255
|
-
}
|
|
1256
|
-
/**
|
|
1257
|
-
* Add a context handler for incoming context. If an entity is part of a context group, and then sets its context handler,
|
|
1258
|
-
* it will receive all of its declared contexts.
|
|
1259
|
-
*
|
|
1260
|
-
* @param handler - Handler for incoming context.
|
|
1261
|
-
* @param contextType - The type of context you wish to handle.
|
|
1262
|
-
*
|
|
1263
|
-
* @example
|
|
1264
|
-
* ```js
|
|
1265
|
-
* function handleIncomingContext(contextInfo) {
|
|
1266
|
-
* const { type, id } = contextInfo;
|
|
1267
|
-
* switch (type) {
|
|
1268
|
-
* case 'instrument':
|
|
1269
|
-
* handleInstrumentContext(contextInfo);
|
|
1270
|
-
* break;
|
|
1271
|
-
* case 'country':
|
|
1272
|
-
* handleCountryContext(contextInfo);
|
|
1273
|
-
* break;
|
|
1274
|
-
*
|
|
1275
|
-
* default:
|
|
1276
|
-
* break;
|
|
1277
|
-
* }
|
|
1278
|
-
* }
|
|
1279
|
-
*
|
|
1280
|
-
*
|
|
1281
|
-
* function handleInstrumentContext(contextInfo) {
|
|
1282
|
-
* const { type, id } = contextInfo;
|
|
1283
|
-
* console.log('contextInfo for instrument', contextInfo)
|
|
1284
|
-
* }
|
|
1285
|
-
*
|
|
1286
|
-
* function handleCountryContext(contextInfo) {
|
|
1287
|
-
* const { type, id } = contextInfo;
|
|
1288
|
-
* console.log('contextInfo for country', contextInfo)
|
|
1289
|
-
* }
|
|
1290
|
-
*
|
|
1291
|
-
* fin.me.interop.addContextHandler(handleIncomingContext);
|
|
1292
|
-
* ```
|
|
1293
|
-
*
|
|
1294
|
-
*
|
|
1295
|
-
* Passing in a context type as the second parameter will cause the handler to only be invoked with that context type.
|
|
1296
|
-
*
|
|
1297
|
-
* ```js
|
|
1298
|
-
* function handleInstrumentContext(contextInfo) {
|
|
1299
|
-
* const { type, id } = contextInfo;
|
|
1300
|
-
* console.log('contextInfo for instrument', contextInfo)
|
|
1301
|
-
* }
|
|
1302
|
-
*
|
|
1303
|
-
* function handleCountryContext(contextInfo) {
|
|
1304
|
-
* const { type, id } = contextInfo;
|
|
1305
|
-
* console.log('contextInfo for country', contextInfo)
|
|
1306
|
-
* }
|
|
1307
|
-
*
|
|
1308
|
-
*
|
|
1309
|
-
* fin.me.interop.addContextHandler(handleInstrumentContext, 'instrument')
|
|
1310
|
-
* fin.me.interop.addContextHandler(handleCountryContext, 'country')
|
|
1311
|
-
* ```
|
|
1312
|
-
*/
|
|
1313
|
-
async addContextHandler(handler, contextType) {
|
|
1314
|
-
this.wire.sendAction('interop-client-add-context-handler').catch((e) => {
|
|
1315
|
-
// don't expose, analytics-only call
|
|
1316
|
-
});
|
|
1317
|
-
if (typeof handler !== 'function') {
|
|
1318
|
-
throw new Error("Non-function argument passed to the first parameter 'handler'. Be aware that the argument order does not match the FDC3 standard.");
|
|
1319
|
-
}
|
|
1320
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1321
|
-
let handlerId;
|
|
1322
|
-
if (contextType) {
|
|
1323
|
-
handlerId = `invokeContextHandler-${contextType}-${(0, utils_1.generateId)()}`;
|
|
1324
|
-
}
|
|
1325
|
-
else {
|
|
1326
|
-
handlerId = 'invokeContextHandler';
|
|
1327
|
-
}
|
|
1328
|
-
const wrappedHandler = (0, utils_1.wrapContextHandler)(handler, handlerId);
|
|
1329
|
-
client.register(handlerId, wrappedHandler);
|
|
1330
|
-
await client.dispatch('contextHandlerRegistered', { handlerId, contextType });
|
|
1331
|
-
return {
|
|
1332
|
-
unsubscribe: async () => {
|
|
1333
|
-
client.remove(handlerId);
|
|
1334
|
-
await client.dispatch('removeContextHandler', { handlerId });
|
|
1335
|
-
}
|
|
1336
|
-
};
|
|
1337
|
-
}
|
|
1338
|
-
/*
|
|
1339
|
-
Platform Window APIs
|
|
1340
|
-
*/
|
|
1341
|
-
/**
|
|
1342
|
-
* Returns the Interop-Broker-defined context groups available for an entity to join.
|
|
1343
|
-
* Used by Platform Windows.
|
|
1344
|
-
*
|
|
1345
|
-
* @example
|
|
1346
|
-
* ```js
|
|
1347
|
-
* fin.me.interop.getContextGroups()
|
|
1348
|
-
* .then(contextGroups => {
|
|
1349
|
-
* contextGroups.forEach(contextGroup => {
|
|
1350
|
-
* console.log(contextGroup.displayMetadata.name)
|
|
1351
|
-
* console.log(contextGroup.displayMetadata.color)
|
|
1352
|
-
* })
|
|
1353
|
-
* })
|
|
1354
|
-
* ```
|
|
1355
|
-
*/
|
|
1356
|
-
async getContextGroups() {
|
|
1357
|
-
this.wire.sendAction('interop-client-get-context-groups').catch((e) => {
|
|
1358
|
-
// don't expose, analytics-only call
|
|
1359
|
-
});
|
|
1360
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1361
|
-
return client.dispatch('getContextGroups');
|
|
1362
|
-
}
|
|
1363
|
-
/**
|
|
1364
|
-
* Join all Interop Clients at the given identity to context group `contextGroupId`.
|
|
1365
|
-
* If no target is specified, it adds the sender to the context group.
|
|
1366
|
-
*
|
|
1367
|
-
* @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.
|
|
1368
|
-
* 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.
|
|
1369
|
-
* 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.
|
|
1370
|
-
* Used by Platform Windows.
|
|
1371
|
-
*
|
|
1372
|
-
* @param contextGroupId - Id of the context group.
|
|
1373
|
-
* @param target - Identity of the entity you wish to join to a context group.
|
|
1374
|
-
*
|
|
1375
|
-
* @example
|
|
1376
|
-
* ```js
|
|
1377
|
-
* joinViewToContextGroup = async (contextGroupId, view) => {
|
|
1378
|
-
* await fin.me.interop.joinContextGroup(contextGroupId, view);
|
|
1379
|
-
* }
|
|
1380
|
-
*
|
|
1381
|
-
* getLastFocusedView()
|
|
1382
|
-
* .then(lastFocusedViewIdentity => {
|
|
1383
|
-
* joinViewToContextGroup('red', lastFocusedViewIdentity)
|
|
1384
|
-
* })
|
|
1385
|
-
* ```
|
|
1386
|
-
*/
|
|
1387
|
-
async joinContextGroup(contextGroupId, target) {
|
|
1388
|
-
this.wire.sendAction('interop-client-join-context-group').catch((e) => {
|
|
1389
|
-
// don't expose, analytics-only call
|
|
1390
|
-
});
|
|
1391
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1392
|
-
if (!contextGroupId) {
|
|
1393
|
-
throw new Error('No contextGroupId specified for joinContextGroup.');
|
|
1394
|
-
}
|
|
1395
|
-
return client.dispatch('joinContextGroup', { contextGroupId, target });
|
|
1396
|
-
}
|
|
1397
|
-
/**
|
|
1398
|
-
* Removes the specified target from a context group.
|
|
1399
|
-
* If no target is specified, it removes the sender from their context group.
|
|
1400
|
-
* Used by Platform Windows.
|
|
1401
|
-
*
|
|
1402
|
-
* @param target - Identity of the entity you wish to join to a context group.
|
|
1403
|
-
*
|
|
1404
|
-
* @example
|
|
1405
|
-
* ```js
|
|
1406
|
-
* removeViewFromContextGroup = async (view) => {
|
|
1407
|
-
* await fin.me.interop.removeFromContextGroup(view);
|
|
1408
|
-
* }
|
|
1409
|
-
*
|
|
1410
|
-
* getLastFocusedView()
|
|
1411
|
-
* .then(lastFocusedViewIdentity => {
|
|
1412
|
-
* removeViewFromContextGroup(lastFocusedViewIdentity)
|
|
1413
|
-
* })
|
|
1414
|
-
* ```
|
|
1415
|
-
*/
|
|
1416
|
-
async removeFromContextGroup(target) {
|
|
1417
|
-
this.wire.sendAction('interop-client-remove-from-context-group').catch((e) => {
|
|
1418
|
-
// don't expose, analytics-only call
|
|
1419
|
-
});
|
|
1420
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1421
|
-
return client.dispatch('removeFromContextGroup', { target });
|
|
1422
|
-
}
|
|
1423
|
-
/**
|
|
1424
|
-
* Gets all clients for a context group.
|
|
1425
|
-
*
|
|
1426
|
-
* @remarks **This is primarily used for platform windows. Views within a platform should not have to use this API.**
|
|
1427
|
-
*
|
|
1428
|
-
* Returns the Interop-Broker-defined context groups available for an entity to join.
|
|
1429
|
-
* @param contextGroupId - The id of context group you wish to get clients for.
|
|
1430
|
-
*
|
|
1431
|
-
* @example
|
|
1432
|
-
* ```js
|
|
1433
|
-
* fin.me.interop.getAllClientsInContextGroup('red')
|
|
1434
|
-
* .then(clientsInContextGroup => {
|
|
1435
|
-
* console.log(clientsInContextGroup)
|
|
1436
|
-
* })
|
|
1437
|
-
* ```
|
|
1438
|
-
*/
|
|
1439
|
-
async getAllClientsInContextGroup(contextGroupId) {
|
|
1440
|
-
this.wire.sendAction('interop-client-get-all-clients-in-context-group').catch((e) => {
|
|
1441
|
-
// don't expose, analytics-only call
|
|
1442
|
-
});
|
|
1443
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1444
|
-
if (!contextGroupId) {
|
|
1445
|
-
throw new Error('No contextGroupId specified for getAllClientsInContextGroup.');
|
|
1446
|
-
}
|
|
1447
|
-
return client.dispatch('getAllClientsInContextGroup', { contextGroupId });
|
|
1448
|
-
}
|
|
1449
|
-
/**
|
|
1450
|
-
* Gets display info for a context group
|
|
1451
|
-
*
|
|
1452
|
-
* @remarks Used by Platform Windows.
|
|
1453
|
-
* @param contextGroupId - The id of context group you wish to get display info for.
|
|
1454
|
-
*
|
|
1455
|
-
* @example
|
|
1456
|
-
* ```js
|
|
1457
|
-
* fin.me.interop.getInfoForContextGroup('red')
|
|
1458
|
-
* .then(contextGroupInfo => {
|
|
1459
|
-
* console.log(contextGroupInfo.displayMetadata.name)
|
|
1460
|
-
* console.log(contextGroupInfo.displayMetadata.color)
|
|
1461
|
-
* })
|
|
1462
|
-
* ```
|
|
1463
|
-
*/
|
|
1464
|
-
async getInfoForContextGroup(contextGroupId) {
|
|
1465
|
-
this.wire.sendAction('interop-client-get-info-for-context-group').catch((e) => {
|
|
1466
|
-
// don't expose, analytics-only call
|
|
1467
|
-
});
|
|
1468
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1469
|
-
if (!contextGroupId) {
|
|
1470
|
-
throw new Error('No contextGroupId specified for getInfoForContextGroup.');
|
|
1471
|
-
}
|
|
1472
|
-
return client.dispatch('getInfoForContextGroup', { contextGroupId });
|
|
1473
|
-
}
|
|
1474
|
-
/**
|
|
1475
|
-
* Sends an intent to the Interop Broker to resolve.
|
|
1476
|
-
* @param intent - The combination of an action and a context that is passed to an application for resolution.
|
|
1477
|
-
*
|
|
1478
|
-
* @example
|
|
1479
|
-
* ```js
|
|
1480
|
-
* // View wants to fire an Intent after a user clicks on a ticker
|
|
1481
|
-
* tickerElement.on('click', (element) => {
|
|
1482
|
-
* const ticker = element.innerText;
|
|
1483
|
-
* const intent = {
|
|
1484
|
-
* name: 'ViewChart',
|
|
1485
|
-
* context: {type: 'fdc3.instrument', id: { ticker }}
|
|
1486
|
-
* }
|
|
1487
|
-
*
|
|
1488
|
-
* fin.me.interop.fireIntent(intent);
|
|
1489
|
-
* })
|
|
1490
|
-
* ```
|
|
1491
|
-
*/
|
|
1492
|
-
async fireIntent(intent) {
|
|
1493
|
-
this.wire.sendAction('interop-client-fire-intent').catch((e) => {
|
|
1494
|
-
// don't expose, this is only for api analytics purposes
|
|
1495
|
-
});
|
|
1496
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1497
|
-
return client.dispatch('fireIntent', intent);
|
|
1498
|
-
}
|
|
1499
|
-
/**
|
|
1500
|
-
* Adds an intent handler for incoming intents. The last intent sent of the name subscribed to will be received.
|
|
1501
|
-
* @param handler - Registered function meant to handle a specific intent type.
|
|
1502
|
-
* @param intentName - The name of an intent.
|
|
1503
|
-
*
|
|
1504
|
-
* @example
|
|
1505
|
-
* ```js
|
|
1506
|
-
* const intentHandler = (intent) => {
|
|
1507
|
-
* const { context } = intent;
|
|
1508
|
-
* myViewChartHandler(context);
|
|
1509
|
-
* };
|
|
1510
|
-
*
|
|
1511
|
-
* const subscription = await fin.me.interop.registerIntentHandler(intentHandler, 'ViewChart');
|
|
1512
|
-
*
|
|
1513
|
-
* function myAppCloseSequence() {
|
|
1514
|
-
* // to unsubscribe the handler, simply call:
|
|
1515
|
-
* subscription.unsubscribe();
|
|
1516
|
-
* }
|
|
1517
|
-
* ```
|
|
1518
|
-
*/
|
|
1519
|
-
async registerIntentHandler(handler, intentName, options) {
|
|
1520
|
-
this.wire.sendAction('interop-client-register-intent-handler').catch((e) => {
|
|
1521
|
-
// don't expose, this is only for api analytics purposes
|
|
1522
|
-
});
|
|
1523
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1524
|
-
const handlerId = `intent-handler-${intentName}`;
|
|
1525
|
-
const wrappedHandler = (0, utils_1.wrapIntentHandler)(handler, handlerId);
|
|
1526
|
-
try {
|
|
1527
|
-
await client.register(handlerId, wrappedHandler);
|
|
1528
|
-
await client.dispatch('intentHandlerRegistered', { handlerId, ...options });
|
|
1529
|
-
}
|
|
1530
|
-
catch (error) {
|
|
1531
|
-
throw new Error('Unable to register intent handler');
|
|
1532
|
-
}
|
|
1533
|
-
return {
|
|
1534
|
-
unsubscribe: async () => {
|
|
1535
|
-
client.remove(handlerId);
|
|
1536
|
-
}
|
|
1537
|
-
};
|
|
1538
|
-
}
|
|
1539
|
-
/**
|
|
1540
|
-
* Gets the last context of the Context Group currently subscribed to. It takes an optional Context Type and returns the
|
|
1541
|
-
* last context of that type.
|
|
1542
|
-
* @param contextType
|
|
1543
|
-
*
|
|
1544
|
-
* @example
|
|
1545
|
-
* ```js
|
|
1546
|
-
* await fin.me.interop.joinContextGroup('yellow');
|
|
1547
|
-
* await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
|
|
1548
|
-
* const currentContext = await fin.me.interop.getCurrentContext();
|
|
1549
|
-
*
|
|
1550
|
-
* // with a specific context
|
|
1551
|
-
* await fin.me.interop.joinContextGroup('yellow');
|
|
1552
|
-
* await fin.me.interop.setContext({ type: 'country', id: { ISOALPHA3: 'US' }});
|
|
1553
|
-
* await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
|
|
1554
|
-
* const currentContext = await fin.me.interop.getCurrentContext('country');
|
|
1555
|
-
* ```
|
|
1556
|
-
*/
|
|
1557
|
-
async getCurrentContext(contextType) {
|
|
1558
|
-
this.wire.sendAction('interop-client-get-current-context').catch((e) => {
|
|
1559
|
-
// don't expose, analytics-only call
|
|
1560
|
-
});
|
|
1561
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1562
|
-
return client.dispatch('getCurrentContext', { contextType });
|
|
1563
|
-
}
|
|
1564
|
-
/**
|
|
1565
|
-
* Get information for a particular Intent from the Interop Broker.
|
|
1566
|
-
*
|
|
1567
|
-
* @remarks To resolve this info, the function handleInfoForIntent is meant to be overridden in the Interop Broker.
|
|
1568
|
-
* The format for the response will be determined by the App Provider overriding the function.
|
|
1569
|
-
*
|
|
1570
|
-
* @param options
|
|
1571
|
-
*
|
|
1572
|
-
* @example
|
|
1573
|
-
* ```js
|
|
1574
|
-
* const intentInfo = await fin.me.interop.getInfoForIntent('ViewChart');
|
|
1575
|
-
* ```
|
|
1576
|
-
*/
|
|
1577
|
-
async getInfoForIntent(options) {
|
|
1578
|
-
this.wire.sendAction('interop-client-get-info-for-intent').catch((e) => {
|
|
1579
|
-
// don't expose, analytics-only call
|
|
1580
|
-
});
|
|
1581
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1582
|
-
return client.dispatch('getInfoForIntent', options);
|
|
1583
|
-
}
|
|
1584
|
-
/**
|
|
1585
|
-
* Get information from the Interop Broker on all Intents that are meant to handle a particular context.
|
|
1586
|
-
*
|
|
1587
|
-
* @remarks To resolve this info, the function handleInfoForIntentsByContext is meant to be overridden in the Interop Broker.
|
|
1588
|
-
* The format for the response will be determined by the App Provider overriding the function.
|
|
1589
|
-
*
|
|
1590
|
-
* @param context
|
|
1591
|
-
*
|
|
1592
|
-
* @example
|
|
1593
|
-
* ```js
|
|
1594
|
-
* tickerElement.on('click', (element) => {
|
|
1595
|
-
* const ticker = element.innerText;
|
|
1596
|
-
*
|
|
1597
|
-
* const context = {
|
|
1598
|
-
* type: 'fdc3.instrument',
|
|
1599
|
-
* id: {
|
|
1600
|
-
* ticker
|
|
1601
|
-
* }
|
|
1602
|
-
* }
|
|
1603
|
-
*
|
|
1604
|
-
* const intentsInfo = await fin.me.interop.getInfoForIntentByContext(context);
|
|
1605
|
-
* })
|
|
1606
|
-
* ```
|
|
1607
|
-
*/
|
|
1608
|
-
async getInfoForIntentsByContext(context) {
|
|
1609
|
-
this.wire.sendAction('interop-client-get-info-for-intents-by-context').catch((e) => {
|
|
1610
|
-
// don't expose, analytics-only call
|
|
1611
|
-
});
|
|
1612
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1613
|
-
return client.dispatch('getInfoForIntentsByContext', context);
|
|
1614
|
-
}
|
|
1615
|
-
/**
|
|
1616
|
-
* Sends a Context that will be resolved to an Intent by the Interop Broker.
|
|
1617
|
-
* This context accepts a metadata property.
|
|
1618
|
-
*
|
|
1619
|
-
* @remarks To resolve this info, the function handleFiredIntentByContext is meant to be overridden in the Interop Broker.
|
|
1620
|
-
* The format for the response will be determined by the App Provider overriding the function.
|
|
1621
|
-
*
|
|
1622
|
-
* @param context
|
|
1623
|
-
*
|
|
1624
|
-
* @example
|
|
1625
|
-
* ```js
|
|
1626
|
-
* tickerElement.on('click', (element) => {
|
|
1627
|
-
* const ticker = element.innerText;
|
|
1628
|
-
*
|
|
1629
|
-
* const context = {
|
|
1630
|
-
* type: 'fdc3.instrument',
|
|
1631
|
-
* id: {
|
|
1632
|
-
* ticker
|
|
1633
|
-
* }
|
|
1634
|
-
* }
|
|
1635
|
-
*
|
|
1636
|
-
* const intentResolution = await fin.me.interop.fireIntentForContext(context);
|
|
1637
|
-
* })
|
|
1638
|
-
* ```
|
|
1639
|
-
*/
|
|
1640
|
-
async fireIntentForContext(context) {
|
|
1641
|
-
this.wire.sendAction('interop-client-fire-intent-for-context').catch((e) => {
|
|
1642
|
-
// don't expose, analytics-only call
|
|
1643
|
-
});
|
|
1644
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1645
|
-
return client.dispatch('fireIntentForContext', context);
|
|
1646
|
-
}
|
|
1647
|
-
/**
|
|
1648
|
-
* Join the current entity to session context group `sessionContextGroupId` and return a sessionContextGroup instance.
|
|
1649
|
-
* If the sessionContextGroup doesn't exist, one will get created.
|
|
1650
|
-
*
|
|
1651
|
-
* @remarks Session Context Groups do not persist between runs and aren't present on snapshots.
|
|
1652
|
-
* @param sessionContextGroupId - Id of the context group.
|
|
1653
|
-
*
|
|
1654
|
-
* @example
|
|
1655
|
-
* Say we want to have a Session Context Group that holds UI theme information for all apps to consume:
|
|
1656
|
-
*
|
|
1657
|
-
* My color-picker View:
|
|
1658
|
-
* ```js
|
|
1659
|
-
* const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');
|
|
1660
|
-
*
|
|
1661
|
-
* const myColorPickerElement = document.getElementById('color-palette-picker');
|
|
1662
|
-
* myColorPickerElement.addEventListener('change', event => {
|
|
1663
|
-
* themeSessionContextGroup.setContext({ type: 'color-palette', selection: event.value });
|
|
1664
|
-
* });
|
|
1665
|
-
* ```
|
|
1666
|
-
*
|
|
1667
|
-
* In other views:
|
|
1668
|
-
* ```js
|
|
1669
|
-
* const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');
|
|
1670
|
-
*
|
|
1671
|
-
* const changeColorPalette = ({ selection }) => {
|
|
1672
|
-
* // change the color palette to the selection
|
|
1673
|
-
* };
|
|
1674
|
-
*
|
|
1675
|
-
* // If the context is already set by the time the handler was set, the handler will get invoked immediately with the current context.
|
|
1676
|
-
* themeSessionContextGroup.addContextHandler(changeColorPalette, 'color-palette');
|
|
1677
|
-
* ```
|
|
1678
|
-
*/
|
|
1679
|
-
async joinSessionContextGroup(sessionContextGroupId) {
|
|
1680
|
-
try {
|
|
1681
|
-
const currentSessionContextGroup = __classPrivateFieldGet(this, _InteropClient_sessionContextGroups, "f").get(sessionContextGroupId);
|
|
1682
|
-
if (currentSessionContextGroup) {
|
|
1683
|
-
return currentSessionContextGroup.getUserInstance();
|
|
1684
|
-
}
|
|
1685
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1686
|
-
const { hasConflict } = await client.dispatch('sessionContextGroup:createIfNeeded', {
|
|
1687
|
-
sessionContextGroupId
|
|
1688
|
-
});
|
|
1689
|
-
if (hasConflict) {
|
|
1690
|
-
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.`);
|
|
1691
|
-
}
|
|
1692
|
-
const newSessionContextGroup = new SessionContextGroupClient_1.default(this.wire, __classPrivateFieldGet(this, _InteropClient_clientPromise, "f"), sessionContextGroupId);
|
|
1693
|
-
__classPrivateFieldGet(this, _InteropClient_sessionContextGroups, "f").set(sessionContextGroupId, newSessionContextGroup);
|
|
1694
|
-
return newSessionContextGroup.getUserInstance();
|
|
1695
|
-
}
|
|
1696
|
-
catch (error) {
|
|
1697
|
-
console.error(`Error thrown trying to create Session Context Group with id "${sessionContextGroupId}": ${error}`);
|
|
1698
|
-
throw error;
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
/**
|
|
1702
|
-
* Register a listener that is called when the Interop Client has been disconnected from the Interop Broker.
|
|
1703
|
-
* Only one listener per Interop Client can be set.
|
|
1704
|
-
* @param listener
|
|
1705
|
-
*
|
|
1706
|
-
* @example
|
|
1707
|
-
* ```js
|
|
1708
|
-
* const listener = (event) => {
|
|
1709
|
-
* const { type, topic, brokerName} = event;
|
|
1710
|
-
* console.log(`Disconnected from Interop Broker ${brokerName} `);
|
|
1711
|
-
* }
|
|
1712
|
-
*
|
|
1713
|
-
* await fin.me.interop.onDisconnection(listener);
|
|
1714
|
-
* ```
|
|
1715
|
-
*/
|
|
1716
|
-
async onDisconnection(listener) {
|
|
1717
|
-
this.wire.sendAction('interop-client-add-ondisconnection-listener').catch((e) => {
|
|
1718
|
-
// don't expose, analytics-only call
|
|
1719
|
-
});
|
|
1720
|
-
const client = await __classPrivateFieldGet(this, _InteropClient_clientPromise, "f");
|
|
1721
|
-
return client.onDisconnection((event) => {
|
|
1722
|
-
const { uuid } = event;
|
|
1723
|
-
listener({ type: 'interop-broker', topic: 'disconnected', brokerName: uuid });
|
|
1724
|
-
});
|
|
1725
|
-
}
|
|
1726
|
-
getFDC3Sync(version) {
|
|
1727
|
-
switch (version) {
|
|
1728
|
-
case '1.2':
|
|
1729
|
-
return new fdc3_1_2_1.Fdc3Module(() => this, this.wire);
|
|
1730
|
-
case '2.0':
|
|
1731
|
-
return new fdc3_2_0_1.Fdc3Module2(() => this, this.wire);
|
|
1732
|
-
default:
|
|
1733
|
-
throw new Error(`Invalid FDC3 version provided: ${version}. Must be '1.2' or '2.0'`);
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
async getFDC3(version) {
|
|
1737
|
-
return this.getFDC3Sync(version);
|
|
1738
|
-
}
|
|
1739
|
-
/**
|
|
1740
|
-
* @internal
|
|
1741
|
-
*
|
|
1742
|
-
* Used to ferry fdc3-only calls from the fdc3 shim to the Interop Broker
|
|
1743
|
-
*/
|
|
1744
|
-
static async ferryFdc3Call(interopClient, action, payload) {
|
|
1745
|
-
const client = await __classPrivateFieldGet(interopClient, _InteropClient_clientPromise, "f");
|
|
1746
|
-
return client.dispatch(action, payload || null);
|
|
1747
|
-
}
|
|
1748
|
-
};
|
|
1749
|
-
InteropClient.InteropClient = InteropClient$1;
|
|
1750
|
-
_InteropClient_clientPromise = new WeakMap(), _InteropClient_sessionContextGroups = new WeakMap();
|
|
1751
|
-
return InteropClient;
|
|
1752
|
-
}
|
|
1753
|
-
|
|
1754
|
-
var hasRequiredFdc3Common;
|
|
1755
|
-
|
|
1756
|
-
function requireFdc3Common () {
|
|
1757
|
-
if (hasRequiredFdc3Common) return fdc3Common;
|
|
1758
|
-
hasRequiredFdc3Common = 1;
|
|
1759
|
-
var __classPrivateFieldGet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
1760
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1761
|
-
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");
|
|
1762
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1763
|
-
};
|
|
1764
|
-
var __classPrivateFieldSet = (commonjsGlobal && commonjsGlobal.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
1765
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1766
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
1767
|
-
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");
|
|
1768
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1769
|
-
};
|
|
1770
|
-
var _FDC3ModuleBase_producer;
|
|
1771
|
-
Object.defineProperty(fdc3Common, "__esModule", { value: true });
|
|
1772
|
-
fdc3Common.FDC3ModuleBase = void 0;
|
|
1773
|
-
const utils_1 = utils$1;
|
|
1774
|
-
const utils_2 = utils$2;
|
|
1775
|
-
const InteropClient_1 = requireInteropClient();
|
|
1776
|
-
const lodash_1 = require$$2;
|
|
1777
|
-
class FDC3ModuleBase {
|
|
1778
|
-
get client() {
|
|
1779
|
-
return __classPrivateFieldGet(this, _FDC3ModuleBase_producer, "f").call(this);
|
|
1780
|
-
}
|
|
1781
|
-
get fin() {
|
|
1782
|
-
return this.wire.getFin();
|
|
1783
|
-
}
|
|
1784
|
-
// eslint-disable-next-line no-useless-constructor
|
|
1785
|
-
constructor(producer, wire) {
|
|
1786
|
-
this.wire = wire;
|
|
1787
|
-
_FDC3ModuleBase_producer.set(this, void 0);
|
|
1788
|
-
__classPrivateFieldSet(this, _FDC3ModuleBase_producer, producer, "f");
|
|
1789
|
-
}
|
|
1790
|
-
/**
|
|
1791
|
-
* Broadcasts a context for the channel of the current entity.
|
|
1792
|
-
* @param context - New context to set.
|
|
1793
|
-
*
|
|
1794
|
-
* @tutorial fdc3.broadcast
|
|
1795
|
-
* @static
|
|
1796
|
-
*/
|
|
1797
|
-
async broadcast(context) {
|
|
1798
|
-
this.wire.sendAction('fdc3-broadcast').catch((e) => {
|
|
1799
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
1800
|
-
});
|
|
1801
|
-
return this.client.setContext(context);
|
|
1802
|
-
}
|
|
1803
|
-
/**
|
|
1804
|
-
* Launches an app with target information, which can either be a string or an AppMetadata object.
|
|
1805
|
-
* @param app
|
|
1806
|
-
* @param context
|
|
1807
|
-
*
|
|
1808
|
-
* @tutorial fdc3.open
|
|
1809
|
-
*/
|
|
1810
|
-
async _open(app, context) {
|
|
1811
|
-
this.wire.sendAction('fdc3-open').catch((e) => {
|
|
1812
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
1813
|
-
});
|
|
1814
|
-
try {
|
|
1815
|
-
return await InteropClient_1.InteropClient.ferryFdc3Call(this.client, 'fdc3Open', { app, context });
|
|
1816
|
-
}
|
|
1817
|
-
catch (error) {
|
|
1818
|
-
const errorToThrow = error.message === utils_2.BROKER_ERRORS.fdc3Open ? 'ResolverUnavailable' : error.message;
|
|
1819
|
-
throw new Error(errorToThrow);
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
async _getChannels() {
|
|
1823
|
-
const channels = await this.client.getContextGroups();
|
|
1824
|
-
// fdc3 implementation of getSystemChannels returns an array of channels, have to decorate over
|
|
1825
|
-
// this so people know that these APIs are not supported
|
|
1826
|
-
return channels.map((channel) => {
|
|
1827
|
-
return { ...channel, type: 'system', ...(0, utils_1.getUnsupportedChannelApis)() };
|
|
1828
|
-
});
|
|
1829
|
-
}
|
|
1830
|
-
/**
|
|
1831
|
-
* Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
|
|
1832
|
-
* @param channelId
|
|
1833
|
-
*
|
|
1834
|
-
* @tutorial fdc3.getOrCreateChannel
|
|
1835
|
-
*/
|
|
1836
|
-
async getOrCreateChannel(channelId) {
|
|
1837
|
-
this.wire.sendAction('fdc3-get-or-create-channel').catch((e) => {
|
|
1838
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
1839
|
-
});
|
|
1840
|
-
const systemChannels = await this._getChannels();
|
|
1841
|
-
const userChannel = systemChannels.find((channel) => channel.id === channelId);
|
|
1842
|
-
if (userChannel) {
|
|
1843
|
-
return { ...userChannel, type: 'system', ...(0, utils_1.getUnsupportedChannelApis)() };
|
|
1844
|
-
}
|
|
1845
|
-
try {
|
|
1846
|
-
const sessionContextGroup = await this.client.joinSessionContextGroup(channelId);
|
|
1847
|
-
return (0, utils_1.buildAppChannelObject)(sessionContextGroup);
|
|
1848
|
-
}
|
|
1849
|
-
catch (error) {
|
|
1850
|
-
console.error(error.message);
|
|
1851
|
-
throw new Error(utils_1.ChannelError.CreationFailed);
|
|
1852
|
-
}
|
|
1853
|
-
}
|
|
1854
|
-
/**
|
|
1855
|
-
* Returns the Interop-Broker-defined context groups available for an entity to join.
|
|
1856
|
-
*
|
|
1857
|
-
* @tutorial fdc3.getSystemChannels
|
|
1858
|
-
* @static
|
|
1859
|
-
*/
|
|
1860
|
-
async getSystemChannels() {
|
|
1861
|
-
this.wire.sendAction('fdc3-get-system-channels').catch((e) => {
|
|
1862
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
1863
|
-
});
|
|
1864
|
-
return this._getChannels();
|
|
1865
|
-
}
|
|
1866
|
-
/**
|
|
1867
|
-
* Join all Interop Clients at the given identity to context group `contextGroupId`.
|
|
1868
|
-
* If no target is specified, it adds the sender to the context group.
|
|
1869
|
-
* 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.
|
|
1870
|
-
* 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.
|
|
1871
|
-
* 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.
|
|
1872
|
-
* @param channelId - Id of the context group.
|
|
1873
|
-
*
|
|
1874
|
-
* @tutorial fdc3.joinChannel
|
|
1875
|
-
* @static
|
|
1876
|
-
*/
|
|
1877
|
-
async joinChannel(channelId) {
|
|
1878
|
-
this.wire.sendAction('fdc3-join-channel').catch((e) => {
|
|
1879
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
1880
|
-
});
|
|
1881
|
-
try {
|
|
1882
|
-
return await this.client.joinContextGroup(channelId);
|
|
1883
|
-
}
|
|
1884
|
-
catch (error) {
|
|
1885
|
-
if (error.message === utils_2.BROKER_ERRORS.joinSessionContextGroupWithJoinContextGroup) {
|
|
1886
|
-
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.');
|
|
1887
|
-
}
|
|
1888
|
-
else {
|
|
1889
|
-
console.error(error.message);
|
|
1890
|
-
}
|
|
1891
|
-
if (error.message.startsWith('Attempting to join a context group that does not exist')) {
|
|
1892
|
-
throw new Error(utils_1.ChannelError.NoChannelFound);
|
|
1893
|
-
}
|
|
1894
|
-
throw new Error(utils_1.ChannelError.AccessDenied);
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
/**
|
|
1898
|
-
* Returns the Channel that the entity is subscribed to. Returns null if not joined to a channel.
|
|
1899
|
-
*
|
|
1900
|
-
* @tutorial fdc3.getCurrentChannel
|
|
1901
|
-
*/
|
|
1902
|
-
async getCurrentChannel() {
|
|
1903
|
-
this.wire.sendAction('fdc3-get-current-channel').catch((e) => {
|
|
1904
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
1905
|
-
});
|
|
1906
|
-
const currentContextGroupInfo = await this.getCurrentContextGroupInfo();
|
|
1907
|
-
if (!currentContextGroupInfo) {
|
|
1908
|
-
return null;
|
|
1909
|
-
}
|
|
1910
|
-
return this.buildChannelObject(currentContextGroupInfo);
|
|
1911
|
-
}
|
|
1912
|
-
/**
|
|
1913
|
-
* Removes the specified target from a context group.
|
|
1914
|
-
* If no target is specified, it removes the sender from their context group.
|
|
1915
|
-
*
|
|
1916
|
-
* @tutorial fdc3.leaveCurrentChannel
|
|
1917
|
-
* @static
|
|
1918
|
-
*/
|
|
1919
|
-
async leaveCurrentChannel() {
|
|
1920
|
-
this.wire.sendAction('fdc3-leave-current-channel').catch((e) => {
|
|
1921
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
1922
|
-
});
|
|
1923
|
-
return this.client.removeFromContextGroup();
|
|
1924
|
-
}
|
|
1925
|
-
// utils
|
|
1926
|
-
// eslint-disable-next-line class-methods-use-this
|
|
1927
|
-
async getCurrentContextGroupInfo() {
|
|
1928
|
-
const contextGroups = await this.client.getContextGroups();
|
|
1929
|
-
const clientsInCtxGroupsPromise = contextGroups.map(async (ctxGroup) => {
|
|
1930
|
-
return this.client.getAllClientsInContextGroup(ctxGroup.id);
|
|
1931
|
-
});
|
|
1932
|
-
const clientsInCtxGroups = await Promise.all(clientsInCtxGroupsPromise);
|
|
1933
|
-
const clientIdx = clientsInCtxGroups.findIndex((clientIdentityArr) => {
|
|
1934
|
-
return clientIdentityArr.some((clientIdentity) => {
|
|
1935
|
-
const { uuid, name } = clientIdentity;
|
|
1936
|
-
return this.wire.me.uuid === uuid && this.wire.me.name === name;
|
|
1937
|
-
});
|
|
1938
|
-
});
|
|
1939
|
-
return contextGroups[clientIdx];
|
|
1940
|
-
}
|
|
1941
|
-
async buildChannelObject(currentContextGroupInfo) {
|
|
1942
|
-
// @ts-expect-error
|
|
1943
|
-
return {
|
|
1944
|
-
...currentContextGroupInfo,
|
|
1945
|
-
type: 'system',
|
|
1946
|
-
addContextListener: (...[contextType, handler]) => {
|
|
1947
|
-
let realHandler;
|
|
1948
|
-
let realType;
|
|
1949
|
-
if (typeof contextType === 'function') {
|
|
1950
|
-
console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
|
|
1951
|
-
realHandler = contextType;
|
|
1952
|
-
}
|
|
1953
|
-
else {
|
|
1954
|
-
realHandler = handler;
|
|
1955
|
-
if (typeof contextType === 'string') {
|
|
1956
|
-
realType = contextType;
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
|
-
const listener = (async () => {
|
|
1960
|
-
let first = true;
|
|
1961
|
-
const currentContext = await this.client.getCurrentContext(realType);
|
|
1962
|
-
const wrappedHandler = (context, contextMetadata) => {
|
|
1963
|
-
if (first) {
|
|
1964
|
-
first = false;
|
|
1965
|
-
if ((0, lodash_1.isEqual)(currentContext, context)) {
|
|
1966
|
-
return;
|
|
1967
|
-
}
|
|
1968
|
-
}
|
|
1969
|
-
// eslint-disable-next-line consistent-return
|
|
1970
|
-
return realHandler(context, contextMetadata);
|
|
1971
|
-
};
|
|
1972
|
-
return this.client.addContextHandler(wrappedHandler, realType);
|
|
1973
|
-
})();
|
|
1974
|
-
// @ts-expect-error TODO [CORE-1524]
|
|
1975
|
-
return {
|
|
1976
|
-
...listener,
|
|
1977
|
-
unsubscribe: () => listener.then((l) => l.unsubscribe())
|
|
1978
|
-
};
|
|
1979
|
-
},
|
|
1980
|
-
broadcast: this.broadcast.bind(this),
|
|
1981
|
-
// @ts-expect-error Typescript fails to infer the returntype is a Promise
|
|
1982
|
-
getCurrentContext: async (contextType) => {
|
|
1983
|
-
const context = await this.client.getCurrentContext(contextType);
|
|
1984
|
-
// @ts-expect-error Typescript fails to infer the returntype is a Promise
|
|
1985
|
-
return context === undefined ? null : context;
|
|
1986
|
-
}
|
|
1987
|
-
};
|
|
1988
|
-
}
|
|
1989
|
-
}
|
|
1990
|
-
fdc3Common.FDC3ModuleBase = FDC3ModuleBase;
|
|
1991
|
-
_FDC3ModuleBase_producer = new WeakMap();
|
|
1992
|
-
return fdc3Common;
|
|
1993
|
-
}
|
|
1994
|
-
|
|
1995
|
-
var hasRequiredFdc31_2;
|
|
1996
|
-
|
|
1997
|
-
function requireFdc31_2 () {
|
|
1998
|
-
if (hasRequiredFdc31_2) return fdc31_2;
|
|
1999
|
-
hasRequiredFdc31_2 = 1;
|
|
2000
|
-
Object.defineProperty(fdc31_2, "__esModule", { value: true });
|
|
2001
|
-
fdc31_2.Fdc3Module = void 0;
|
|
2002
|
-
const utils_1 = utils$2;
|
|
2003
|
-
const fdc3_common_1 = requireFdc3Common();
|
|
2004
|
-
/**
|
|
2005
|
-
* @version 1.2
|
|
2006
|
-
* The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
|
|
2007
|
-
* while using our Interop API under the hood. In order to use this set of APIs
|
|
2008
|
-
* 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
|
|
2009
|
-
* our {@link https://developers.openfin.co/of-docs/docs/enable-color-linking Interop API}.
|
|
2010
|
-
*
|
|
2011
|
-
* To enable the FDC3 APIs in a {@link Window Window} or {@link View View}, add the fdc3InteropApi
|
|
2012
|
-
* property to its options:
|
|
2013
|
-
*
|
|
2014
|
-
* ```js
|
|
2015
|
-
* {
|
|
2016
|
-
* autoShow: false,
|
|
2017
|
-
* saveWindowState: true,
|
|
2018
|
-
* url: 'https://openfin.co',
|
|
2019
|
-
* fdc3InteropApi: '1.2'
|
|
2020
|
-
* }
|
|
2021
|
-
* ```
|
|
2022
|
-
*
|
|
2023
|
-
* If using a {@link Platform Platform } application, you can set this property in defaultWindowOptions and defaultViewOptions.
|
|
2024
|
-
*
|
|
2025
|
-
* In order to ensure that the FDC3 Api is ready before use, you can use the 'fdc3Ready' event fired on the DOM Window object:
|
|
2026
|
-
*
|
|
2027
|
-
* ```js
|
|
2028
|
-
* function fdc3Action() {
|
|
2029
|
-
* // Make some fdc3 API calls here
|
|
2030
|
-
* }
|
|
2031
|
-
*
|
|
2032
|
-
* if (window.fdc3) {
|
|
2033
|
-
* fdc3Action();
|
|
2034
|
-
* } else {
|
|
2035
|
-
* window.addEventListener('fdc3Ready', fdc3Action);
|
|
2036
|
-
* }
|
|
2037
|
-
* ```
|
|
2038
|
-
*/
|
|
2039
|
-
class Fdc3Module extends fdc3_common_1.FDC3ModuleBase {
|
|
2040
|
-
async open(app, context) {
|
|
2041
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
2042
|
-
await super._open(app, context);
|
|
2043
|
-
}
|
|
2044
|
-
/**
|
|
2045
|
-
* 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.
|
|
2046
|
-
* @param contextType - The type of context you wish to handle.
|
|
2047
|
-
* @param handler - Handler for incoming context.
|
|
2048
|
-
*
|
|
2049
|
-
* @tutorial fdc3.addContextListener
|
|
2050
|
-
* @static
|
|
2051
|
-
*/
|
|
2052
|
-
// @ts-expect-error TODO [CORE-1524]
|
|
2053
|
-
addContextListener(contextType, handler) {
|
|
2054
|
-
this.wire.sendAction('fdc3-add-context-listener').catch((e) => {
|
|
2055
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
2056
|
-
});
|
|
2057
|
-
let listener;
|
|
2058
|
-
if (typeof contextType === 'function') {
|
|
2059
|
-
console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
|
|
2060
|
-
listener = this.client.addContextHandler(contextType);
|
|
2061
|
-
}
|
|
2062
|
-
else {
|
|
2063
|
-
listener = this.client.addContextHandler(handler, contextType === null ? undefined : contextType);
|
|
2064
|
-
}
|
|
2065
|
-
return {
|
|
2066
|
-
...listener,
|
|
2067
|
-
unsubscribe: () => listener.then((l) => l.unsubscribe())
|
|
2068
|
-
};
|
|
2069
|
-
}
|
|
2070
|
-
/**
|
|
2071
|
-
* Adds a listener for incoming Intents.
|
|
2072
|
-
* @param intent - Name of the Intent
|
|
2073
|
-
* @param handler - Handler for incoming Intent
|
|
2074
|
-
*
|
|
2075
|
-
* @tutorial fdc3.addIntentListener
|
|
2076
|
-
* @static
|
|
2077
|
-
*/
|
|
2078
|
-
addIntentListener(intent, handler) {
|
|
2079
|
-
this.wire.sendAction('fdc3-add-intent-listener').catch((e) => {
|
|
2080
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
2081
|
-
});
|
|
2082
|
-
const contextHandler = (raisedIntent) => {
|
|
2083
|
-
const { context, metadata: intentMetadata } = raisedIntent;
|
|
2084
|
-
const { metadata } = context;
|
|
2085
|
-
const intentResolutionResultId = intentMetadata?.intentResolutionResultId || metadata?.intentResolutionResultId;
|
|
2086
|
-
if (intentResolutionResultId) {
|
|
2087
|
-
this.fin.InterApplicationBus.publish(intentResolutionResultId, null).catch(() => null);
|
|
2088
|
-
}
|
|
2089
|
-
handler(raisedIntent.context);
|
|
2090
|
-
};
|
|
2091
|
-
const listener = this.client.registerIntentHandler(contextHandler, intent, {
|
|
2092
|
-
fdc3Version: '1.2'
|
|
2093
|
-
});
|
|
2094
|
-
return {
|
|
2095
|
-
...listener,
|
|
2096
|
-
unsubscribe: () => listener.then((l) => l.unsubscribe())
|
|
2097
|
-
};
|
|
2098
|
-
}
|
|
2099
|
-
/**
|
|
2100
|
-
* Raises a specific intent.
|
|
2101
|
-
* @param intent Name of the Intent.
|
|
2102
|
-
* @param context Context associated with the Intent.
|
|
2103
|
-
* @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}.
|
|
2104
|
-
*
|
|
2105
|
-
* @tutorial fdc3.raiseIntent
|
|
2106
|
-
* @static
|
|
2107
|
-
*/
|
|
2108
|
-
async raiseIntent(intent, context, app) {
|
|
2109
|
-
this.wire.sendAction('fdc3-raise-intent').catch((e) => {
|
|
2110
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
2111
|
-
});
|
|
2112
|
-
const intentObj = app
|
|
2113
|
-
? { name: intent, context, metadata: { target: app } }
|
|
2114
|
-
: { name: intent, context };
|
|
2115
|
-
try {
|
|
2116
|
-
return await this.client.fireIntent(intentObj);
|
|
2117
|
-
}
|
|
2118
|
-
catch (error) {
|
|
2119
|
-
const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
|
|
2120
|
-
throw new Error(errorToThrow);
|
|
2121
|
-
}
|
|
2122
|
-
}
|
|
2123
|
-
/**
|
|
2124
|
-
* Find out more information about a particular intent by passing its name, and optionally its context.
|
|
2125
|
-
* @param intent Name of the Intent
|
|
2126
|
-
* @param context
|
|
2127
|
-
*
|
|
2128
|
-
* @tutorial fdc3.findIntent
|
|
2129
|
-
*/
|
|
2130
|
-
async findIntent(intent, context) {
|
|
2131
|
-
this.wire.sendAction('fdc3-find-intent').catch((e) => {
|
|
2132
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
2133
|
-
});
|
|
2134
|
-
try {
|
|
2135
|
-
return await this.client.getInfoForIntent({ name: intent, context });
|
|
2136
|
-
}
|
|
2137
|
-
catch (error) {
|
|
2138
|
-
const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntent ? 'ResolverUnavailable' : error.message;
|
|
2139
|
-
throw new Error(errorToThrow);
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
/**
|
|
2143
|
-
* Find all the available intents for a particular context.
|
|
2144
|
-
* @param context
|
|
2145
|
-
*
|
|
2146
|
-
* @tutorial fdc3.findIntentsByContext
|
|
2147
|
-
*/
|
|
2148
|
-
async findIntentsByContext(context) {
|
|
2149
|
-
this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
|
|
2150
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
2151
|
-
});
|
|
2152
|
-
try {
|
|
2153
|
-
return await this.client.getInfoForIntentsByContext(context);
|
|
2154
|
-
}
|
|
2155
|
-
catch (error) {
|
|
2156
|
-
const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error.message;
|
|
2157
|
-
throw new Error(errorToThrow);
|
|
2158
|
-
}
|
|
2159
|
-
}
|
|
2160
|
-
/**
|
|
2161
|
-
* Finds and raises an intent against a target app based purely on context data.
|
|
2162
|
-
* @param context
|
|
2163
|
-
* @param app
|
|
2164
|
-
*
|
|
2165
|
-
* @tutorial fdc3.raiseIntentForContext
|
|
2166
|
-
*/
|
|
2167
|
-
async raiseIntentForContext(context, app) {
|
|
2168
|
-
this.wire.sendAction('fdc3-raise-intent-for-context').catch((e) => {
|
|
2169
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
2170
|
-
});
|
|
2171
|
-
try {
|
|
2172
|
-
return await this.client.fireIntentForContext({ ...context, metadata: { target: app } });
|
|
2173
|
-
}
|
|
2174
|
-
catch (error) {
|
|
2175
|
-
const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntentForContext ? 'ResolverUnavailable' : error.message;
|
|
2176
|
-
throw new Error(errorToThrow);
|
|
2177
|
-
}
|
|
2178
|
-
}
|
|
2179
|
-
/**
|
|
2180
|
-
* Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
|
|
2181
|
-
* @param channelId
|
|
2182
|
-
*
|
|
2183
|
-
* @tutorial fdc3.getOrCreateChannel
|
|
2184
|
-
*/
|
|
2185
|
-
async getOrCreateChannel(channelId) {
|
|
2186
|
-
return super.getOrCreateChannel(channelId);
|
|
2187
|
-
}
|
|
2188
|
-
/**
|
|
2189
|
-
* 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.
|
|
2190
|
-
*
|
|
2191
|
-
* @tutorial fdc3.getInfo
|
|
2192
|
-
*/
|
|
2193
|
-
getInfo() {
|
|
2194
|
-
this.wire.sendAction('fdc3-get-info').catch((e) => {
|
|
2195
|
-
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
2196
|
-
});
|
|
2197
|
-
// @ts-expect-error
|
|
2198
|
-
const { uuid, fdc3InteropApi } = fin.__internal_.initialOptions;
|
|
2199
|
-
// @ts-expect-error
|
|
2200
|
-
const runtimeVersion = fin.desktop.getVersion();
|
|
2201
|
-
return {
|
|
2202
|
-
fdc3Version: fdc3InteropApi,
|
|
2203
|
-
provider: `openfin-${uuid}`,
|
|
2204
|
-
providerVersion: runtimeVersion
|
|
2205
|
-
};
|
|
2206
|
-
}
|
|
2207
|
-
}
|
|
2208
|
-
fdc31_2.Fdc3Module = Fdc3Module;
|
|
2209
|
-
return fdc31_2;
|
|
2210
|
-
}
|
|
2211
|
-
|
|
2212
|
-
var fdc31_2Exports = requireFdc31_2();
|
|
2213
|
-
|
|
2214
|
-
var fdc3 = {};
|
|
2215
|
-
|
|
2216
|
-
(function (exports) {
|
|
2217
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2218
|
-
exports.getFdc3 = exports.versionMap = void 0;
|
|
2219
|
-
/* eslint-disable no-console */
|
|
2220
|
-
/* eslint-disable no-param-reassign */
|
|
2221
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2222
|
-
const fdc3_1_2_1 = requireFdc31_2();
|
|
2223
|
-
const fdc3_2_0_1 = requireFdc32_0();
|
|
2224
|
-
exports.versionMap = {
|
|
2225
|
-
'1.2': fdc3_1_2_1.Fdc3Module,
|
|
2226
|
-
'2.0': fdc3_2_0_1.Fdc3Module2
|
|
2227
|
-
};
|
|
2228
|
-
const latestVersion = '2.0';
|
|
2229
|
-
function getFdc3(transport, version = latestVersion) {
|
|
2230
|
-
if (!(version in exports.versionMap)) {
|
|
2231
|
-
console.warn(`FDC3 API version: ${version} is not supported. Defaulting to latest version: ${latestVersion}.`);
|
|
2232
|
-
version = latestVersion;
|
|
2233
|
-
}
|
|
2234
|
-
const Fdc3Api = exports.versionMap[version];
|
|
2235
|
-
const fdc3 = new Fdc3Api(() => transport.getFin().me.interop, transport);
|
|
2236
|
-
window.dispatchEvent(new CustomEvent('fdc3Ready'));
|
|
2237
|
-
return fdc3;
|
|
2238
|
-
}
|
|
2239
|
-
exports.getFdc3 = getFdc3;
|
|
2240
|
-
} (fdc3));
|
|
2241
|
-
|
|
2242
|
-
var fdc32_0Exports = requireFdc32_0();
|
|
2243
|
-
|
|
2244
|
-
async function fdc3FromFin(fin, { fdc3Version } = { fdc3Version: '2.0' }) {
|
|
2245
|
-
// @ts-expect-error
|
|
2246
|
-
return fdc3.getFdc3(fin.wire, fdc3Version);
|
|
2247
|
-
}
|
|
2248
|
-
|
|
2249
|
-
exports.Fdc3Module = fdc31_2Exports.Fdc3Module;
|
|
2250
|
-
exports.Fdc3Module2 = fdc32_0Exports.Fdc3Module2;
|
|
2251
|
-
exports.fdc3FromFin = fdc3FromFin;
|