@openfin/core 31.74.19 → 31.74.22
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/src/api/api-exposer/api-consumer.d.ts +28 -0
- package/src/api/api-exposer/api-consumer.js +28 -0
- package/src/api/api-exposer/api-exposer.d.ts +35 -0
- package/src/api/api-exposer/api-exposer.js +38 -0
- package/src/api/api-exposer/decorators.d.ts +10 -0
- package/src/api/api-exposer/decorators.js +18 -0
- package/src/api/api-exposer/index.d.ts +4 -0
- package/src/api/api-exposer/index.js +20 -0
- package/src/api/api-exposer/strategies/index.d.ts +1 -0
- package/src/api/api-exposer/strategies/index.js +17 -0
- package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.d.ts +14 -0
- package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.js +20 -0
- package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.d.ts +20 -0
- package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.js +23 -0
- package/src/api/api-exposer/strategies/openfin-channels/index.d.ts +2 -0
- package/src/api/api-exposer/strategies/openfin-channels/index.js +18 -0
- package/src/api/interop/fdc3/fdc3-1.2.js +19 -4
- package/src/api/interop/fdc3/fdc3-2.0.js +7 -7
- package/src/api/interop/fdc3/utils.d.ts +17 -0
- package/src/api/interop/fdc3/utils.js +52 -18
package/package.json
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ExposedProp } from "./decorators";
|
|
2
|
+
export type ConsumeStrategy<TMetaConsumeOptions, TPropConsumeDefinition> = {
|
|
3
|
+
getExposedFunctions: (options: TMetaConsumeOptions) => Promise<ExposedProp<TPropConsumeDefinition>[]>;
|
|
4
|
+
createFunction: (options: ExposedProp<TPropConsumeDefinition>, meta: TMetaConsumeOptions) => Function;
|
|
5
|
+
};
|
|
6
|
+
type PickOfType<T extends Record<any, any>, TTarget> = {
|
|
7
|
+
[key in keyof T as T[key] extends TTarget | undefined ? key : never]: T[key];
|
|
8
|
+
};
|
|
9
|
+
export type ApiClient<T extends Record<any, any>> = {
|
|
10
|
+
[key in keyof PickOfType<T, Function>]: (...args: Parameters<T[key]>) => ReturnType<T[key]> extends Promise<any> ? ReturnType<T[key]> : Promise<ReturnType<T[key]>>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Consumer for apis exposed with {@see ApiExposer}.
|
|
14
|
+
*
|
|
15
|
+
* A strategy that matches the strategy used to expose a target API must be provided.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ApiConsumer<TMetaConsumeOptions = any, TPropConsumptionOptions = any> {
|
|
18
|
+
private strategy;
|
|
19
|
+
constructor(strategy: ConsumeStrategy<TMetaConsumeOptions, TPropConsumptionOptions>);
|
|
20
|
+
/**
|
|
21
|
+
* Consumes an api exposed using a given transport strategy, and generates a client
|
|
22
|
+
* for easy, type safe consumption of that client.
|
|
23
|
+
* @param options Strategy specific consumption options.
|
|
24
|
+
* @returns An api client matching the given type.
|
|
25
|
+
*/
|
|
26
|
+
consume: <T extends Record<any, any>>(options: TMetaConsumeOptions) => Promise<ApiClient<T>>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiConsumer = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Consumer for apis exposed with {@see ApiExposer}.
|
|
6
|
+
*
|
|
7
|
+
* A strategy that matches the strategy used to expose a target API must be provided.
|
|
8
|
+
*/
|
|
9
|
+
class ApiConsumer {
|
|
10
|
+
// eslint-disable-next-line
|
|
11
|
+
constructor(strategy) {
|
|
12
|
+
this.strategy = strategy;
|
|
13
|
+
/**
|
|
14
|
+
* Consumes an api exposed using a given transport strategy, and generates a client
|
|
15
|
+
* for easy, type safe consumption of that client.
|
|
16
|
+
* @param options Strategy specific consumption options.
|
|
17
|
+
* @returns An api client matching the given type.
|
|
18
|
+
*/
|
|
19
|
+
this.consume = async (options) => {
|
|
20
|
+
const exposedProperties = await this.strategy.getExposedFunctions(options);
|
|
21
|
+
return exposedProperties.reduce((client, prop) => ({
|
|
22
|
+
...client,
|
|
23
|
+
[prop.key]: this.strategy.createFunction(prop, options)
|
|
24
|
+
}), {});
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ApiConsumer = ApiConsumer;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ExposedProp } from './decorators';
|
|
2
|
+
export type ConsumptionConfig<T> = {
|
|
3
|
+
key: string;
|
|
4
|
+
options: T;
|
|
5
|
+
};
|
|
6
|
+
export type ExposeStrategy<TInstanceExposeOptions, TPropExposeOptions, TPropConsumeOptions> = {
|
|
7
|
+
/**
|
|
8
|
+
* Exposes the given function on the strategy.
|
|
9
|
+
*/
|
|
10
|
+
exposeFunction: (target: Function, config: {
|
|
11
|
+
key: string;
|
|
12
|
+
options: TPropExposeOptions;
|
|
13
|
+
meta: TInstanceExposeOptions;
|
|
14
|
+
}) => Promise<TPropConsumeOptions>;
|
|
15
|
+
/**
|
|
16
|
+
* Exposes metadata to enable creation of client objects.
|
|
17
|
+
*/
|
|
18
|
+
exposeMeta: (instanceOptions: TInstanceExposeOptions, props: ExposedProp<TPropConsumeOptions>[]) => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Exposes api services on the transport of choice.
|
|
22
|
+
*/
|
|
23
|
+
export declare class ApiExposer<TInstanceExposeOptions = any, TPropExposeOptions = any, TPropConsumptionOptions = any> {
|
|
24
|
+
private strategy;
|
|
25
|
+
/**
|
|
26
|
+
* @param strategy The expose strategy to use to expose instances.
|
|
27
|
+
*/
|
|
28
|
+
constructor(strategy: ExposeStrategy<TInstanceExposeOptions, TPropExposeOptions, TPropConsumptionOptions>);
|
|
29
|
+
/**
|
|
30
|
+
* Exposes an instance of a given api on
|
|
31
|
+
* @param instance Instance of a class which has been decorated to indicate which functions can be exposed.
|
|
32
|
+
* @param instanceOptions Transport strategy specific options to use when exposing.
|
|
33
|
+
*/
|
|
34
|
+
exposeInstance: (instance: Record<any, any>, instanceOptions: TInstanceExposeOptions) => Promise<void>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiExposer = void 0;
|
|
4
|
+
const decorators_1 = require("./decorators");
|
|
5
|
+
/**
|
|
6
|
+
* Exposes api services on the transport of choice.
|
|
7
|
+
*/
|
|
8
|
+
class ApiExposer {
|
|
9
|
+
/**
|
|
10
|
+
* @param strategy The expose strategy to use to expose instances.
|
|
11
|
+
*/
|
|
12
|
+
// eslint-disable-next-line
|
|
13
|
+
constructor(strategy) {
|
|
14
|
+
this.strategy = strategy;
|
|
15
|
+
/**
|
|
16
|
+
* Exposes an instance of a given api on
|
|
17
|
+
* @param instance Instance of a class which has been decorated to indicate which functions can be exposed.
|
|
18
|
+
* @param instanceOptions Transport strategy specific options to use when exposing.
|
|
19
|
+
*/
|
|
20
|
+
this.exposeInstance = async (instance, instanceOptions) => {
|
|
21
|
+
const exposableProps = (0, decorators_1.getExposedProperties)(instance);
|
|
22
|
+
const exposedProps = await Promise.all(exposableProps.map(async ({ key, options }) => {
|
|
23
|
+
const customConsumptionOptions = await this.strategy.exposeFunction(instance[key].bind(instance), {
|
|
24
|
+
key,
|
|
25
|
+
options,
|
|
26
|
+
meta: instanceOptions
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
key,
|
|
30
|
+
options: customConsumptionOptions
|
|
31
|
+
};
|
|
32
|
+
}));
|
|
33
|
+
await this.strategy.exposeMeta(instanceOptions, exposedProps);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
;
|
|
37
|
+
}
|
|
38
|
+
exports.ApiExposer = ApiExposer;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ExposedProp<T> = {
|
|
2
|
+
key: string;
|
|
3
|
+
options: T;
|
|
4
|
+
};
|
|
5
|
+
export declare const getExposedProperties: <T>(target: Record<any, any>) => ExposedProp<T>[];
|
|
6
|
+
/**
|
|
7
|
+
* Indicates that a class member function can be exposed using {@link ApiExposer}.
|
|
8
|
+
* @param options Options specific to the strategy used in {@link ApiExposer}
|
|
9
|
+
*/
|
|
10
|
+
export declare const expose: <T = undefined>(options?: T) => any;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expose = exports.getExposedProperties = void 0;
|
|
4
|
+
const exposedProperties = Symbol('exposedProperties');
|
|
5
|
+
const getExposedProperties = (target) => {
|
|
6
|
+
return target[exposedProperties] || target.prototype[exposedProperties] || [];
|
|
7
|
+
};
|
|
8
|
+
exports.getExposedProperties = getExposedProperties;
|
|
9
|
+
/**
|
|
10
|
+
* Indicates that a class member function can be exposed using {@link ApiExposer}.
|
|
11
|
+
* @param options Options specific to the strategy used in {@link ApiExposer}
|
|
12
|
+
*/
|
|
13
|
+
// Returns any as decorator typing is weird.
|
|
14
|
+
const expose = (options) => (target, key, descriptor) => {
|
|
15
|
+
target[exposedProperties] = target[exposedProperties] || [];
|
|
16
|
+
target[exposedProperties].push({ key, descriptor, options });
|
|
17
|
+
};
|
|
18
|
+
exports.expose = expose;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./api-consumer"), exports);
|
|
18
|
+
__exportStar(require("./api-exposer"), exports);
|
|
19
|
+
__exportStar(require("./strategies"), exports);
|
|
20
|
+
__exportStar(require("./decorators"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './openfin-channels';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./openfin-channels"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ConsumeStrategy } from "../../api-consumer";
|
|
2
|
+
import { ExposedProp } from "../../decorators";
|
|
3
|
+
export type ChannelConsumeOptions = {
|
|
4
|
+
id: string;
|
|
5
|
+
};
|
|
6
|
+
export type ChannelsPropConfig = {
|
|
7
|
+
action: string;
|
|
8
|
+
};
|
|
9
|
+
export declare class ChannelsConsumer implements ConsumeStrategy<ChannelConsumeOptions, ChannelsPropConfig> {
|
|
10
|
+
private channel;
|
|
11
|
+
constructor(channel: any);
|
|
12
|
+
getExposedFunctions: (options: ChannelConsumeOptions) => Promise<ExposedProp<ChannelsPropConfig>[]>;
|
|
13
|
+
createFunction: (prop: ExposedProp<ChannelsPropConfig>) => Function;
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChannelsConsumer = void 0;
|
|
4
|
+
class ChannelsConsumer {
|
|
5
|
+
// eslint-disable-next-line
|
|
6
|
+
constructor(channel) {
|
|
7
|
+
this.channel = channel;
|
|
8
|
+
this.getExposedFunctions = async (options) => {
|
|
9
|
+
const { id } = options;
|
|
10
|
+
const { props } = await this.channel.dispatch(`api-meta:${id}`);
|
|
11
|
+
return props;
|
|
12
|
+
};
|
|
13
|
+
this.createFunction = (prop) => (...args) => {
|
|
14
|
+
const { action } = prop.options;
|
|
15
|
+
return this.channel.dispatch(action, { args });
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
;
|
|
19
|
+
}
|
|
20
|
+
exports.ChannelsConsumer = ChannelsConsumer;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ExposeStrategy } from '../../api-exposer';
|
|
2
|
+
import { ExposedProp } from '../../decorators';
|
|
3
|
+
import { ChannelsPropConfig } from './channels-consumer';
|
|
4
|
+
type ChannelInstanceExposeOptions = {
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
7
|
+
export type ChannelsPropOptions = {
|
|
8
|
+
action?: string;
|
|
9
|
+
} | undefined;
|
|
10
|
+
export declare class ChannelsExposer implements ExposeStrategy<ChannelInstanceExposeOptions, ChannelsPropOptions, ChannelsPropConfig> {
|
|
11
|
+
private channelProviderOrClient;
|
|
12
|
+
constructor(channelProviderOrClient: any);
|
|
13
|
+
exposeFunction: (target: Function, config: {
|
|
14
|
+
key: string;
|
|
15
|
+
options: ChannelsPropOptions;
|
|
16
|
+
meta: ChannelInstanceExposeOptions;
|
|
17
|
+
}) => Promise<ChannelsPropConfig>;
|
|
18
|
+
exposeMeta: ({ id }: ChannelInstanceExposeOptions, props: ExposedProp<ChannelsPropOptions>[]) => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChannelsExposer = void 0;
|
|
4
|
+
class ChannelsExposer {
|
|
5
|
+
// eslint-disable-next-line
|
|
6
|
+
constructor(channelProviderOrClient) {
|
|
7
|
+
this.channelProviderOrClient = channelProviderOrClient;
|
|
8
|
+
this.exposeFunction = async (target, config) => {
|
|
9
|
+
const { key, options, meta } = config;
|
|
10
|
+
const { id } = meta;
|
|
11
|
+
const action = `${id}.${(options === null || options === void 0 ? void 0 : options.action) || key}`;
|
|
12
|
+
await this.channelProviderOrClient.register(action, async ({ args }) => {
|
|
13
|
+
return target(...args);
|
|
14
|
+
});
|
|
15
|
+
return { action };
|
|
16
|
+
};
|
|
17
|
+
this.exposeMeta = async ({ id }, props) => {
|
|
18
|
+
const action = `api-meta:${id}`;
|
|
19
|
+
await this.channelProviderOrClient.register(action, () => ({ props }));
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.ChannelsExposer = ChannelsExposer;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./channels-consumer"), exports);
|
|
18
|
+
__exportStar(require("./channels-exposer"), exports);
|
|
@@ -169,11 +169,15 @@ class Fdc3Module extends base_1.Base {
|
|
|
169
169
|
}
|
|
170
170
|
catch (error) {
|
|
171
171
|
if (error.message === utils_2.BROKER_ERRORS.joinSessionContextGroupWithJoinContextGroup) {
|
|
172
|
-
|
|
172
|
+
console.error('The Channel you have tried to join is an App Channel. Custom Channels can only be defined by the Interop Broker through code or manifest configuration. Please use getOrCreateChannel.');
|
|
173
173
|
}
|
|
174
174
|
else {
|
|
175
|
-
|
|
175
|
+
console.error(error.message);
|
|
176
176
|
}
|
|
177
|
+
if (error.message.startsWith('Attempting to join a context group that does not exist')) {
|
|
178
|
+
throw new Error(utils_1.ChannelError.NoChannelFound);
|
|
179
|
+
}
|
|
180
|
+
throw new Error(utils_1.ChannelError.AccessDenied);
|
|
177
181
|
}
|
|
178
182
|
}
|
|
179
183
|
/**
|
|
@@ -317,8 +321,19 @@ class Fdc3Module extends base_1.Base {
|
|
|
317
321
|
this.wire.sendAction('fdc3-get-or-create-channel').catch((e) => {
|
|
318
322
|
// we do not want to expose this error, just continue if this analytics-only call fails
|
|
319
323
|
});
|
|
320
|
-
const
|
|
321
|
-
|
|
324
|
+
const systemChannels = await this.getSystemChannels();
|
|
325
|
+
const userChannel = systemChannels.find((channel) => channel.id === channelId);
|
|
326
|
+
if (userChannel) {
|
|
327
|
+
return { ...userChannel, type: 'system', ...(0, utils_1.getUnsupportedChannelApis)() };
|
|
328
|
+
}
|
|
329
|
+
try {
|
|
330
|
+
const sessionContextGroup = await this.fin.me.interop.joinSessionContextGroup(channelId);
|
|
331
|
+
return (0, utils_1.buildAppChannelObject)(sessionContextGroup);
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
console.error(error.message);
|
|
335
|
+
throw new Error(utils_1.ChannelError.CreationFailed);
|
|
336
|
+
}
|
|
322
337
|
}
|
|
323
338
|
/**
|
|
324
339
|
* 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.
|
|
@@ -348,27 +348,27 @@ class Fdc3Module2 extends base_1.Base {
|
|
|
348
348
|
// The FDC3 Intenter handler only expects the context and contextMetadata to be passed to the handler,
|
|
349
349
|
// so we wrap it here and only pass those paramaters.
|
|
350
350
|
const contextHandler = async (raisedIntent) => {
|
|
351
|
+
let intentResult;
|
|
352
|
+
let intentResultToSend;
|
|
351
353
|
const { context, metadata: intentMetadata } = raisedIntent;
|
|
352
354
|
const { contextMetadata, metadata, ...rest } = context;
|
|
353
|
-
|
|
355
|
+
const intentResolutionResultId = (intentMetadata === null || intentMetadata === void 0 ? void 0 : intentMetadata.intentResolutionResultId) || (metadata === null || metadata === void 0 ? void 0 : metadata.intentResolutionResultId);
|
|
354
356
|
try {
|
|
355
357
|
const newContext = metadata ? { metadata, ...rest } : { ...rest };
|
|
356
358
|
intentResult = await handler(newContext, contextMetadata);
|
|
359
|
+
intentResultToSend = intentResult;
|
|
357
360
|
}
|
|
358
361
|
catch (error) {
|
|
359
362
|
intentResult = error;
|
|
363
|
+
intentResultToSend = { error: true };
|
|
360
364
|
}
|
|
361
|
-
const intentResolutionResultId = (intentMetadata === null || intentMetadata === void 0 ? void 0 : intentMetadata.intentResolutionResultId) || (metadata === null || metadata === void 0 ? void 0 : metadata.intentResolutionResultId);
|
|
362
365
|
if (intentResolutionResultId) {
|
|
363
|
-
|
|
364
|
-
this.fin.InterApplicationBus.publish(intentResolutionResultId, intentResult);
|
|
366
|
+
this.fin.InterApplicationBus.publish(intentResolutionResultId, intentResultToSend);
|
|
365
367
|
}
|
|
366
368
|
if (intentResult instanceof Error) {
|
|
367
369
|
throw new Error(intentResult.message);
|
|
368
370
|
}
|
|
369
|
-
|
|
370
|
-
return intentResult;
|
|
371
|
-
}
|
|
371
|
+
return intentResult;
|
|
372
372
|
};
|
|
373
373
|
return this.fin.me.interop.registerIntentHandler(contextHandler, intent, { fdc3Version: '2.0' });
|
|
374
374
|
}
|
|
@@ -21,8 +21,25 @@ export declare enum ResultError {
|
|
|
21
21
|
*/
|
|
22
22
|
IntentHandlerRejected = "IntentHandlerRejected"
|
|
23
23
|
}
|
|
24
|
+
export declare enum ChannelError {
|
|
25
|
+
/** Returned if the specified channel is not found when attempting to join a
|
|
26
|
+
* channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).
|
|
27
|
+
*/
|
|
28
|
+
NoChannelFound = "NoChannelFound",
|
|
29
|
+
/** SHOULD be returned when a request to join a user channel or to a retrieve
|
|
30
|
+
* a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods
|
|
31
|
+
* of the DesktopAgent (`fdc3`) object is denied.
|
|
32
|
+
*/
|
|
33
|
+
AccessDenied = "AccessDenied",
|
|
34
|
+
/** SHOULD be returned when a channel cannot be created or retrieved via the
|
|
35
|
+
* `getOrCreateChannel` method of the DesktopAgent (`fdc3`).
|
|
36
|
+
*/
|
|
37
|
+
CreationFailed = "CreationFailed"
|
|
38
|
+
}
|
|
24
39
|
export declare const buildPrivateChannelObject: (privateChannelClient: PrivateChannelClient) => PrivateChannel;
|
|
25
40
|
export declare const buildAppChannelObject: (sessionContextGroup: OpenFin.SessionContextGroup) => Channel;
|
|
26
41
|
export declare const connectPrivateChannel: (channelId: string) => Promise<PrivateChannel>;
|
|
42
|
+
export declare const isContext: (context: unknown) => context is Context;
|
|
43
|
+
export declare const isChannel: (channel: unknown) => channel is Channel;
|
|
27
44
|
export declare const getIntentResolution: (interopModule: OpenFin.InteropClient, context: Context, app?: AppIdentifier | TargetApp, intent?: string) => Promise<IntentResolution>;
|
|
28
45
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getIntentResolution = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
|
|
3
|
+
exports.getIntentResolution = exports.isChannel = exports.isContext = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ChannelError = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const PrivateChannelClient_1 = require("./PrivateChannelClient");
|
|
6
6
|
const getUnsupportedChannelApis = (channelType) => {
|
|
@@ -35,6 +35,22 @@ var ResultError;
|
|
|
35
35
|
*/
|
|
36
36
|
ResultError["IntentHandlerRejected"] = "IntentHandlerRejected";
|
|
37
37
|
})(ResultError = exports.ResultError || (exports.ResultError = {}));
|
|
38
|
+
var ChannelError;
|
|
39
|
+
(function (ChannelError) {
|
|
40
|
+
/** Returned if the specified channel is not found when attempting to join a
|
|
41
|
+
* channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).
|
|
42
|
+
*/
|
|
43
|
+
ChannelError["NoChannelFound"] = "NoChannelFound";
|
|
44
|
+
/** SHOULD be returned when a request to join a user channel or to a retrieve
|
|
45
|
+
* a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods
|
|
46
|
+
* of the DesktopAgent (`fdc3`) object is denied.
|
|
47
|
+
*/
|
|
48
|
+
ChannelError["AccessDenied"] = "AccessDenied";
|
|
49
|
+
/** SHOULD be returned when a channel cannot be created or retrieved via the
|
|
50
|
+
* `getOrCreateChannel` method of the DesktopAgent (`fdc3`).
|
|
51
|
+
*/
|
|
52
|
+
ChannelError["CreationFailed"] = "CreationFailed";
|
|
53
|
+
})(ChannelError = exports.ChannelError || (exports.ChannelError = {}));
|
|
38
54
|
const buildPrivateChannelObject = (privateChannelClient) => {
|
|
39
55
|
let clientDisconnected = false;
|
|
40
56
|
const checkIfClientDisconnected = () => {
|
|
@@ -122,6 +138,22 @@ const connectPrivateChannel = async (channelId) => {
|
|
|
122
138
|
}
|
|
123
139
|
};
|
|
124
140
|
exports.connectPrivateChannel = connectPrivateChannel;
|
|
141
|
+
const isContext = (context) => {
|
|
142
|
+
if (context && typeof context === 'object' && 'type' in context) {
|
|
143
|
+
const { type } = context;
|
|
144
|
+
return typeof type === 'string';
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
};
|
|
148
|
+
exports.isContext = isContext;
|
|
149
|
+
const isChannel = (channel) => {
|
|
150
|
+
if (channel && typeof channel === 'object' && 'type' in channel && 'id' in channel) {
|
|
151
|
+
const { type, id } = channel;
|
|
152
|
+
return (typeof type === 'string' && typeof id === 'string' && (type === 'app' || type === 'private'));
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
};
|
|
156
|
+
exports.isChannel = isChannel;
|
|
125
157
|
const getIntentResolution = async (interopModule, context, app, intent) => {
|
|
126
158
|
// Generate an ID to make a session context group with. We will pass that ID to the Broker.
|
|
127
159
|
// The broker will then setContext on that session context group later with our Intent Result,
|
|
@@ -138,31 +170,33 @@ const getIntentResolution = async (interopModule, context, app, intent) => {
|
|
|
138
170
|
// Set up the getResult call.
|
|
139
171
|
const getResult = async () => {
|
|
140
172
|
let intentResult = await getResultPromise;
|
|
141
|
-
if (!intentResult) {
|
|
173
|
+
if (!intentResult || typeof intentResult !== 'object') {
|
|
142
174
|
throw new Error(ResultError.NoResultReturned);
|
|
143
175
|
}
|
|
144
|
-
|
|
176
|
+
const { error } = intentResult;
|
|
177
|
+
if (error) {
|
|
145
178
|
throw new Error(ResultError.IntentHandlerRejected);
|
|
146
179
|
}
|
|
147
|
-
if (
|
|
180
|
+
if ((0, exports.isChannel)(intentResult)) {
|
|
148
181
|
const { id, type } = intentResult;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
182
|
+
switch (type) {
|
|
183
|
+
case 'private': {
|
|
184
|
+
intentResult = await (0, exports.connectPrivateChannel)(id);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
case 'app': {
|
|
188
|
+
const sessionContextGroup = await interopModule.joinSessionContextGroup(id);
|
|
189
|
+
intentResult = (0, exports.buildAppChannelObject)(sessionContextGroup);
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
default: {
|
|
193
|
+
break;
|
|
163
194
|
}
|
|
164
195
|
}
|
|
165
196
|
}
|
|
197
|
+
else if (!(0, exports.isContext)(intentResult)) {
|
|
198
|
+
throw new Error(ResultError.NoResultReturned);
|
|
199
|
+
}
|
|
166
200
|
return intentResult;
|
|
167
201
|
};
|
|
168
202
|
// Finally fire the intent.
|