Skip to content

Commit a19a633

Browse files
Refactor standard intents declaration to use union types instead of enums
Signed-off-by: Andrei Floricel <andrei.floricel@gmail.com>
1 parent f3e8d08 commit a19a633

6 files changed

Lines changed: 51 additions & 36 deletions

File tree

src/api/DesktopAgent.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ImplementationMetadata } from './ImplementationMetadata';
1313
import { PrivateChannel } from './PrivateChannel';
1414
import { AppIdentifier } from './AppIdentifier';
1515
import { AppMetadata } from './AppMetadata';
16+
import { Intent } from '../intents/Intents';
1617

1718
/**
1819
* A Desktop Agent is a desktop component (or aggregate of components) that serves as a
@@ -125,7 +126,7 @@ export interface DesktopAgent {
125126
* // }
126127
* ```
127128
*/
128-
findIntent(intent: string, context?: Context, resultType?: string): Promise<AppIntent>;
129+
findIntent(intent: Intent, context?: Context, resultType?: string): Promise<AppIntent>;
129130

130131
/**
131132
* Find all the available intents for a particular context, and optionally a desired result context type.
@@ -234,7 +235,7 @@ export interface DesktopAgent {
234235
*
235236
* If you wish to raise an Intent without a context, use the `fdc3.nothing` context type. This type exists so that apps can explicitly declare support for raising an intent without context.
236237
*
237-
* Returns an `IntentResolution` object with details of the app instance that was selected (or started) to respond to the intent.
238+
* Returns an `IntentResolution` object with details of the app instance that was selected (or started) to respond to the intent.
238239
*
239240
* Issuing apps may optionally wait on the promise that is returned by the `getResult()` member of the `IntentResolution`. This promise will resolve when the _receiving app's_ intent handler function returns and resolves a promise. The Desktop Agent resolves the issuing app's promise with the Context object, Channel object or void that is provided as resolution within the receiving app. The Desktop Agent MUST reject the issuing app's promise, with a string from the `ResultError` enumeration, if: (1) the intent handling function's returned promise rejects, (2) the intent handling function doesn't return a valid response (a promise or void), or (3) the returned promise resolves to an invalid type.
240241
*
@@ -268,7 +269,7 @@ export interface DesktopAgent {
268269
* }
269270
* ```
270271
*/
271-
raiseIntent(intent: string, context: Context, app?: AppIdentifier): Promise<IntentResolution>;
272+
raiseIntent(intent: Intent, context: Context, app?: AppIdentifier): Promise<IntentResolution>;
272273

273274
/**
274275
* Finds and raises an intent against apps registered with the desktop agent based on the type of the specified context data example.
@@ -346,7 +347,7 @@ export interface DesktopAgent {
346347
* });
347348
* ```
348349
*/
349-
addIntentListener(intent: string, handler: IntentHandler): Promise<Listener>;
350+
addIntentListener(intent: Intent, handler: IntentHandler): Promise<Listener>;
350351

351352
/**
352353
* Adds a listener for incoming context broadcasts from the Desktop Agent (via a User channel or `fdc3.open`API call. If the consumer is only interested in a context of a particular type, they can they can specify that type. If the consumer is able to receive context of any type or will inspect types received, then they can pass `null` as the `contextType` parameter to receive all context types.
@@ -561,7 +562,7 @@ export interface DesktopAgent {
561562
* await fdc3.raiseIntent("StartChat", context, appIntent.apps[0].name);
562563
* ```
563564
*/
564-
raiseIntent(intent: string, context: Context, name: string): Promise<IntentResolution>;
565+
raiseIntent(intent: Intent, context: Context, name: string): Promise<IntentResolution>;
565566

566567
/**
567568
* @deprecated version of `raiseIntentForContext` that targets an app by by name rather than `AppIdentifier`. Provided for backwards compatibility with versions FDC3 standard <2.0.

src/api/IntentMetadata.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
* Copyright FINOS FDC3 contributors - see NOTICE file
44
*/
55

6+
import { Intent } from '../intents/Intents';
7+
68
/**
79
* Intent descriptor
810
*/
911
export interface IntentMetadata {
1012
/** The unique name of the intent that can be invoked by the raiseIntent call */
11-
readonly name: string;
13+
readonly name: Intent;
1214

1315
/** Display name for the intent.
1416
* @deprecated Use the intent name for display as display name may vary for

src/api/IntentResolution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { IntentResult } from './Types';
77
import { AppIdentifier } from './AppIdentifier';
8+
import { Intent } from '../intents/Intents';
89

910
/**
1011
* IntentResolution provides a standard format for data returned upon resolving an intent.
@@ -43,7 +44,7 @@ export interface IntentResolution {
4344
* The intent that was raised. May be used to determine which intent the user
4445
* chose in response to `fdc3.raiseIntentForContext()`.
4546
*/
46-
readonly intent: string;
47+
readonly intent: Intent;
4748
/**
4849
* The version number of the Intents schema being used.
4950
*/

src/api/Methods.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
ImplementationMetadata,
1515
AppMetadata,
1616
PrivateChannel,
17+
Intent,
1718
} from '..';
1819

1920
const DEFAULT_TIMEOUT = 5000;
@@ -74,7 +75,7 @@ export function open(app: AppIdentifier | string, context?: Context): Promise<Ap
7475
}
7576
}
7677

77-
export function findIntent(intent: string, context?: Context, resultType?: string): Promise<AppIntent> {
78+
export function findIntent(intent: Intent, context?: Context, resultType?: string): Promise<AppIntent> {
7879
return rejectIfNoGlobal(() => window.fdc3.findIntent(intent, context, resultType));
7980
}
8081

@@ -86,7 +87,7 @@ export function broadcast(context: Context): Promise<void> {
8687
return rejectIfNoGlobal(() => window.fdc3.broadcast(context));
8788
}
8889

89-
export function raiseIntent(intent: string, context: Context, app?: AppIdentifier | string): Promise<IntentResolution> {
90+
export function raiseIntent(intent: Intent, context: Context, app?: AppIdentifier | string): Promise<IntentResolution> {
9091
if (isString(app)) {
9192
return rejectIfNoGlobal(() => window.fdc3.raiseIntent(intent, context, app));
9293
} else {
@@ -102,7 +103,7 @@ export function raiseIntentForContext(context: Context, app?: AppIdentifier | st
102103
}
103104
}
104105

105-
export function addIntentListener(intent: string, handler: IntentHandler): Promise<Listener> {
106+
export function addIntentListener(intent: Intent, handler: IntentHandler): Promise<Listener> {
106107
return rejectIfNoGlobal(() => window.fdc3.addIntentListener(intent, handler));
107108
}
108109

src/bridging/BridgingTypes.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
// These functions will throw an error if the JSON doesn't
7676
// match the expected interface, even if the JSON is valid.
7777

78+
import { Intent } from '../intents/Intents';
79+
7880
/**
7981
* Metadata relating to the FDC3 Desktop Agent implementation and its provider.
8082
*/
@@ -1770,7 +1772,7 @@ export interface FindIntentAgentRequestMeta {
17701772
*/
17711773
export interface FindIntentAgentRequestPayload {
17721774
context?: ContextElement;
1773-
intent: string;
1775+
intent: Intent;
17741776
resultType?: string;
17751777
}
17761778

@@ -1844,7 +1846,7 @@ export interface IntentMetadata {
18441846
/**
18451847
* The unique name of the intent that can be invoked by the raiseIntent call
18461848
*/
1847-
name: string;
1849+
name: Intent;
18481850
}
18491851

18501852
/**
@@ -1929,7 +1931,7 @@ export interface FindIntentBridgeRequestMeta {
19291931
*/
19301932
export interface FindIntentBridgeRequestPayload {
19311933
context?: ContextElement;
1932-
intent: string;
1934+
intent: Intent;
19331935
resultType?: string;
19341936
}
19351937

@@ -3697,7 +3699,7 @@ export interface RaiseIntentAgentRequestMeta {
36973699
export interface RaiseIntentAgentRequestPayload {
36983700
app: AppDestinationIdentifier;
36993701
context: ContextElement;
3700-
intent: string;
3702+
intent: Intent;
37013703
}
37023704

37033705
/**
@@ -3774,7 +3776,7 @@ export interface IntentResolution {
37743776
* The intent that was raised. May be used to determine which intent the user
37753777
* chose in response to `fdc3.raiseIntentForContext()`.
37763778
*/
3777-
intent: string;
3779+
intent: Intent;
37783780
/**
37793781
* Identifier for the app instance that was selected (or started) to resolve the intent.
37803782
* `source.instanceId` MUST be set, indicating the specific app instance that
@@ -3870,7 +3872,7 @@ export interface RaiseIntentBridgeRequestMeta {
38703872
export interface RaiseIntentBridgeRequestPayload {
38713873
app: AppDestinationIdentifier;
38723874
context: ContextElement;
3873-
intent: string;
3875+
intent: Intent;
38743876
}
38753877

38763878
/**

src/intents/Intents.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,31 @@
22
* SPDX-License-Identifier: Apache-2.0
33
* Copyright FINOS FDC3 contributors - see NOTICE file
44
*/
5-
export enum Intents {
6-
CreateInteraction = 'CreateInteraction',
7-
SendChatMessage = 'SendChatMessage',
8-
StartCall = 'StartCall',
9-
StartChat = 'StartChat',
10-
StartEmail = 'StartEmail',
11-
ViewAnalysis = 'ViewAnalysis',
12-
ViewChat = 'ViewChat',
13-
ViewChart = 'ViewChart',
14-
ViewContact = 'ViewContact',
15-
ViewHoldings = 'ViewHoldings',
16-
ViewInstrument = 'ViewInstrument',
17-
ViewInteractions = 'ViewInteractions',
18-
ViewMessages = 'ViewMessages',
19-
ViewNews = 'ViewNews',
20-
ViewOrders = 'ViewOrders',
21-
ViewProfile = 'ViewProfile',
22-
ViewQuote = 'ViewQuote',
23-
ViewResearch = 'ViewResearch',
24-
}
5+
6+
/**
7+
* @see https://fdc3.finos.org/docs/intents/spec#standard-intents
8+
*/
9+
export type StandardIntent =
10+
| 'CreateInteraction'
11+
| 'SendChatMessage'
12+
| 'StartCall'
13+
| 'StartChat'
14+
| 'StartEmail'
15+
| 'ViewAnalysis'
16+
| 'ViewChat'
17+
| 'ViewChart'
18+
| 'ViewContact'
19+
| 'ViewHoldings'
20+
| 'ViewInstrument'
21+
| 'ViewInteractions'
22+
| 'ViewMessages'
23+
| 'ViewNews'
24+
| 'ViewOrders'
25+
| 'ViewProfile'
26+
| 'ViewQuote'
27+
| 'ViewResearch';
28+
29+
/**
30+
* @see https://fdc3.finos.org/docs/intents/spec
31+
*/
32+
export type Intent = StandardIntent | (string & {});

0 commit comments

Comments
 (0)