@openfin/core 29.72.17 → 29.72.18
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/OpenFin.d.ts
CHANGED
|
@@ -250,13 +250,13 @@ declare namespace OpenFin {
|
|
|
250
250
|
|
|
251
251
|
export type WindowOptions = MutableWindowOptions & ConstWindowOptions;
|
|
252
252
|
|
|
253
|
-
export type ViewVisibilityOption = {
|
|
253
|
+
export type ViewVisibilityOption = {
|
|
254
254
|
enabled?: boolean;
|
|
255
|
-
}
|
|
255
|
+
};
|
|
256
256
|
|
|
257
|
-
export type ShowViewOnWindowResizeOptions =
|
|
257
|
+
export type ShowViewOnWindowResizeOptions = ViewVisibilityOption & {
|
|
258
258
|
paintIntervalMs?: number;
|
|
259
|
-
}
|
|
259
|
+
};
|
|
260
260
|
|
|
261
261
|
export type ViewVisibilityOptions = {
|
|
262
262
|
showViewsOnWindowResize?: ShowViewOnWindowResizeOptions;
|
|
@@ -1427,6 +1427,7 @@ declare namespace OpenFin {
|
|
|
1427
1427
|
export type IntentMetadata<TargetType = any> = {
|
|
1428
1428
|
target?: TargetType;
|
|
1429
1429
|
resultType?: string;
|
|
1430
|
+
intentResolutionResultId?: string;
|
|
1430
1431
|
};
|
|
1431
1432
|
|
|
1432
1433
|
export type IntentHandler = (intent: OpenFin.Intent) => void;
|
package/package.json
CHANGED
|
@@ -203,7 +203,7 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
|
|
|
203
203
|
* @param { Context } context Context associated with the Intent
|
|
204
204
|
* @param { AppIdentifier | TargetApp } [app]
|
|
205
205
|
* @returns { Promise<IntentResolution(2)> }
|
|
206
|
-
* @tutorial
|
|
206
|
+
* @tutorial fdc3v2.raiseIntent
|
|
207
207
|
*/
|
|
208
208
|
raiseIntent(intent: string, context: OpenFin.Context, app?: FDC3v2.AppIdentifier | FDC3.TargetApp): Promise<FDC3v2.IntentResolution>;
|
|
209
209
|
/**
|
|
@@ -211,7 +211,7 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
|
|
|
211
211
|
* @param { Context } context Context associated with the Intent
|
|
212
212
|
* @param { AppIdentifier | TargetApp } [app]
|
|
213
213
|
* @returns { Promise<IntentResolution(2)> }
|
|
214
|
-
* @tutorial
|
|
214
|
+
* @tutorial fdc3v2.raiseIntentForContext
|
|
215
215
|
*/
|
|
216
216
|
raiseIntentForContext(context: OpenFin.Context, app?: FDC3v2.AppIdentifier | FDC3.TargetApp): Promise<FDC3v2.IntentResolution>;
|
|
217
217
|
/**
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const base_1 = require("../../base");
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const InteropClient_1 = require("../InteropClient");
|
|
6
|
+
const utils_2 = require("./utils");
|
|
6
7
|
const fdc3_1_2_1 = require("./fdc3-1.2");
|
|
7
8
|
/**
|
|
8
9
|
* @typedef { object } AppIdentifier
|
|
@@ -281,20 +282,39 @@ class Fdc3Module2 extends base_1.Base {
|
|
|
281
282
|
* @param { Context } context Context associated with the Intent
|
|
282
283
|
* @param { AppIdentifier | TargetApp } [app]
|
|
283
284
|
* @returns { Promise<IntentResolution(2)> }
|
|
284
|
-
* @tutorial
|
|
285
|
+
* @tutorial fdc3v2.raiseIntent
|
|
285
286
|
*/
|
|
286
287
|
async raiseIntent(intent, context, app) {
|
|
287
|
-
|
|
288
|
+
this.wire.sendAction('fdc3-raise-intent').catch((e) => {
|
|
289
|
+
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
290
|
+
});
|
|
291
|
+
try {
|
|
292
|
+
return utils_2.getIntentResolution(this.fin.me.interop, context, app, intent);
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error;
|
|
296
|
+
throw new Error(errorToThrow);
|
|
297
|
+
}
|
|
288
298
|
}
|
|
289
299
|
/**
|
|
290
300
|
* Finds and raises an intent against apps registered with the desktop agent based purely on the type of the context data.
|
|
291
301
|
* @param { Context } context Context associated with the Intent
|
|
292
302
|
* @param { AppIdentifier | TargetApp } [app]
|
|
293
303
|
* @returns { Promise<IntentResolution(2)> }
|
|
294
|
-
* @tutorial
|
|
304
|
+
* @tutorial fdc3v2.raiseIntentForContext
|
|
295
305
|
*/
|
|
296
306
|
async raiseIntentForContext(context, app) {
|
|
297
|
-
|
|
307
|
+
// TODO: We have to do the same thing we do for raiseIntent here as well.
|
|
308
|
+
this.wire.sendAction('fdc3-raise-intent-for-context').catch((e) => {
|
|
309
|
+
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
310
|
+
});
|
|
311
|
+
try {
|
|
312
|
+
return utils_2.getIntentResolution(this.fin.me.interop, context, app);
|
|
313
|
+
}
|
|
314
|
+
catch (error) {
|
|
315
|
+
const errorToThrow = error.message === utils_1.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error;
|
|
316
|
+
throw new Error(errorToThrow);
|
|
317
|
+
}
|
|
298
318
|
}
|
|
299
319
|
/**
|
|
300
320
|
* Adds a listener for incoming intents.
|
|
@@ -307,13 +327,33 @@ class Fdc3Module2 extends base_1.Base {
|
|
|
307
327
|
this.wire.sendAction('fdc3-add-intent-listener').catch((e) => {
|
|
308
328
|
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
309
329
|
});
|
|
330
|
+
if (typeof intent !== 'string') {
|
|
331
|
+
throw new Error('First argument must be an Intent name');
|
|
332
|
+
}
|
|
310
333
|
// The FDC3 Intenter handler only expects the context and contextMetadata to be passed to the handler,
|
|
311
334
|
// so we wrap it here and only pass those paramaters.
|
|
312
|
-
const contextHandler = (raisedIntent) => {
|
|
313
|
-
const { context } = raisedIntent;
|
|
314
|
-
const { contextMetadata, ...rest } = context;
|
|
315
|
-
|
|
316
|
-
|
|
335
|
+
const contextHandler = async (raisedIntent) => {
|
|
336
|
+
const { context, metadata: intentMetadata } = raisedIntent;
|
|
337
|
+
const { contextMetadata, metadata, ...rest } = context;
|
|
338
|
+
let intentResult;
|
|
339
|
+
try {
|
|
340
|
+
const newContext = metadata ? { metadata, ...rest } : { ...rest };
|
|
341
|
+
intentResult = await handler(newContext, contextMetadata);
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
intentResult = error;
|
|
345
|
+
}
|
|
346
|
+
const intentResolutionResultId = (intentMetadata === null || intentMetadata === void 0 ? void 0 : intentMetadata.intentResolutionResultId) || (metadata === null || metadata === void 0 ? void 0 : metadata.intentResolutionResultId);
|
|
347
|
+
if (intentResolutionResultId) {
|
|
348
|
+
// Send whatever the result is.
|
|
349
|
+
fin.InterApplicationBus.publish(intentResolutionResultId, intentResult);
|
|
350
|
+
}
|
|
351
|
+
if (intentResult instanceof Error) {
|
|
352
|
+
throw new Error(intentResult.message);
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
return intentResult;
|
|
356
|
+
}
|
|
317
357
|
};
|
|
318
358
|
return this.fin.me.interop.registerIntentHandler(contextHandler, intent, { fdc3Version: '2.0' });
|
|
319
359
|
}
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
export declare class UnsupportedChannelApiError extends Error {
|
|
2
2
|
constructor(apiName: string);
|
|
3
3
|
}
|
|
4
|
+
export declare enum ResultError {
|
|
5
|
+
/** Returned if the `IntentHandler` exited without returning a Promise or that
|
|
6
|
+
* Promise was not resolved with a Context or Channel object.
|
|
7
|
+
*/
|
|
8
|
+
NoResultReturned = "NoResultReturned",
|
|
9
|
+
/** Returned if the `IntentHandler` function processing the raised intent
|
|
10
|
+
* throws an error or rejects the Promise it returned.
|
|
11
|
+
*/
|
|
12
|
+
IntentHandlerRejected = "IntentHandlerRejected"
|
|
13
|
+
}
|
|
14
|
+
export declare const getIntentResolution: (interopModule: OpenFin.InteropClient, context: OpenFin.Context, app?: FDC3v2.AppIdentifier | FDC3.TargetApp, intent?: string) => Promise<FDC3v2.IntentResolution>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnsupportedChannelApiError = void 0;
|
|
3
|
+
exports.getIntentResolution = exports.ResultError = exports.UnsupportedChannelApiError = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
4
5
|
class UnsupportedChannelApiError extends Error {
|
|
5
6
|
constructor(apiName) {
|
|
6
7
|
super(apiName);
|
|
@@ -8,3 +9,55 @@ class UnsupportedChannelApiError extends Error {
|
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
11
|
exports.UnsupportedChannelApiError = UnsupportedChannelApiError;
|
|
12
|
+
var ResultError;
|
|
13
|
+
(function (ResultError) {
|
|
14
|
+
/** Returned if the `IntentHandler` exited without returning a Promise or that
|
|
15
|
+
* Promise was not resolved with a Context or Channel object.
|
|
16
|
+
*/
|
|
17
|
+
ResultError["NoResultReturned"] = "NoResultReturned";
|
|
18
|
+
/** Returned if the `IntentHandler` function processing the raised intent
|
|
19
|
+
* throws an error or rejects the Promise it returned.
|
|
20
|
+
*/
|
|
21
|
+
ResultError["IntentHandlerRejected"] = "IntentHandlerRejected";
|
|
22
|
+
})(ResultError = exports.ResultError || (exports.ResultError = {}));
|
|
23
|
+
exports.getIntentResolution = async (interopModule, context, app, intent) => {
|
|
24
|
+
// Generate an ID to make a session context group with. We will pass that ID to the Broker.
|
|
25
|
+
// The broker will then setContext on that session context group later with our Intent Result,
|
|
26
|
+
const guid = utils_1.generateId();
|
|
27
|
+
// Promise we'll use in getResult
|
|
28
|
+
const getResultPromise = new Promise((resolve) => {
|
|
29
|
+
fin.InterApplicationBus.subscribe({ uuid: '*' }, guid, (intentResult) => {
|
|
30
|
+
resolve(intentResult);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
// Adding the intentResolutionResultId to the intentObj. Because fireIntent only accepts a single arg, we have to slap it in here.
|
|
34
|
+
const metadata = app ? { target: app, intentResolutionResultId: guid } : { intentResolutionResultId: guid };
|
|
35
|
+
const intentObj = intent ? { name: intent, context, metadata } : { ...context, metadata };
|
|
36
|
+
// Set up the getResult call.
|
|
37
|
+
const getResult = async () => {
|
|
38
|
+
const intentResult = await getResultPromise;
|
|
39
|
+
if (!intentResult) {
|
|
40
|
+
throw new Error(ResultError.NoResultReturned);
|
|
41
|
+
}
|
|
42
|
+
if (intentResult instanceof Error) {
|
|
43
|
+
throw new Error(ResultError.IntentHandlerRejected);
|
|
44
|
+
}
|
|
45
|
+
return intentResult;
|
|
46
|
+
};
|
|
47
|
+
// Finally fire the intent.
|
|
48
|
+
const intentResolutionInfoFromBroker = intent
|
|
49
|
+
? await interopModule.fireIntent(intentObj)
|
|
50
|
+
: await interopModule.fireIntentForContext(intentObj);
|
|
51
|
+
if (typeof intentResolutionInfoFromBroker !== 'object') {
|
|
52
|
+
return {
|
|
53
|
+
source: {
|
|
54
|
+
appId: '',
|
|
55
|
+
instanceId: ''
|
|
56
|
+
},
|
|
57
|
+
intent: '',
|
|
58
|
+
version: '2.0',
|
|
59
|
+
getResult
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return { ...intentResolutionInfoFromBroker, getResult };
|
|
63
|
+
};
|
package/src/api/interop/utils.js
CHANGED
|
@@ -45,7 +45,7 @@ exports.BROKER_ERRORS = {
|
|
|
45
45
|
exports.wrapIntentHandler = (handler, handlerId) => {
|
|
46
46
|
return async (intent) => {
|
|
47
47
|
try {
|
|
48
|
-
|
|
48
|
+
return handler(intent);
|
|
49
49
|
}
|
|
50
50
|
catch (error) {
|
|
51
51
|
console.error(`Error thrown by handler ${handlerId}: ${error}`);
|