Skip to content

Commit f245e93

Browse files
Julianna Langstonkriswest
authored andcommitted
Add *ProvidableContextMetadata types and prox-agent handling
1 parent 3f3b8cb commit f245e93

24 files changed

Lines changed: 258 additions & 38 deletions

packages/fdc3-agent-proxy/src/DesktopAgentProxy.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
AppIdentifier,
33
AppMetadata,
4+
AppProvidableContextMetadata,
45
ContextHandler,
56
DesktopAgent,
67
EventHandler,
@@ -82,10 +83,10 @@ export class DesktopAgentProxy implements DesktopAgent, Connectable {
8283
return this.apps.getImplementationMetadata();
8384
}
8485

85-
async broadcast(context: Context): Promise<void> {
86+
async broadcast(context: Context, metadata?: AppProvidableContextMetadata): Promise<void> {
8687
const channel = await this.channels.getUserChannel();
8788
if (channel) {
88-
return channel.broadcast(context);
89+
return channel.broadcast(context, metadata);
8990
} else {
9091
return Promise.resolve();
9192
}
@@ -169,20 +170,24 @@ export class DesktopAgentProxy implements DesktopAgent, Connectable {
169170
}
170171
}
171172

172-
raiseIntent(intent: string, context: Context, app?: string | AppIdentifier) {
173-
return this.intents.raiseIntent(intent, context, this.ensureAppId(app));
173+
raiseIntent(intent: string, context: Context, app?: string | AppIdentifier, metadata?: AppProvidableContextMetadata) {
174+
return this.intents.raiseIntent(intent, context, this.ensureAppId(app), metadata);
174175
}
175176

176177
addIntentListener(intent: string, handler: IntentHandler) {
177178
return this.intents.addIntentListener(intent, handler);
178179
}
179180

180-
raiseIntentForContext(context: Context, app?: string | AppIdentifier): Promise<IntentResolution> {
181-
return this.intents.raiseIntentForContext(context, this.ensureAppId(app));
181+
raiseIntentForContext(
182+
context: Context,
183+
app?: string | AppIdentifier,
184+
metadata?: AppProvidableContextMetadata
185+
): Promise<IntentResolution> {
186+
return this.intents.raiseIntentForContext(context, this.ensureAppId(app), metadata);
182187
}
183188

184-
open(app: string | AppIdentifier, context?: Context | undefined) {
185-
return this.apps.open(this.ensureAppId(app)!, context);
189+
open(app: string | AppIdentifier, context?: Context, metadata?: AppProvidableContextMetadata) {
190+
return this.apps.open(this.ensureAppId(app)!, context, metadata);
186191
}
187192

188193
findInstances(app: AppIdentifier) {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { AppIdentifier, AppMetadata, ImplementationMetadata } from '@finos/fdc3-standard';
1+
import { AppIdentifier, AppMetadata, AppProvidableContextMetadata, ImplementationMetadata } from '@finos/fdc3-standard';
22
import { Context } from '@finos/fdc3-context';
33

44
export interface AppSupport {
55
findInstances(app: AppIdentifier): Promise<Array<AppIdentifier>>;
66
getAppMetadata(app: AppIdentifier): Promise<AppMetadata>;
7-
open(app: AppIdentifier, context?: Context): Promise<AppIdentifier>;
7+
open(app: AppIdentifier, context?: Context, metadata?: AppProvidableContextMetadata): Promise<AppIdentifier>;
88
getImplementationMetadata(): Promise<ImplementationMetadata>;
99
}

packages/fdc3-agent-proxy/src/apps/DefaultAppSupport.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { AppIdentifier, AppMetadata, ImplementationMetadata, OpenError, ResolveError } from '@finos/fdc3-standard';
1+
import {
2+
AppIdentifier,
3+
AppMetadata,
4+
AppProvidableContextMetadata,
5+
ImplementationMetadata,
6+
OpenError,
7+
ResolveError,
8+
} from '@finos/fdc3-standard';
29
import { Context } from '@finos/fdc3-context';
310
import { AppSupport } from './AppSupport.js';
411
import { Messaging } from '../Messaging.js';
@@ -68,7 +75,11 @@ export class DefaultAppSupport implements AppSupport {
6875
return response.payload.appMetadata!;
6976
}
7077

71-
async open(app: AppIdentifier, context?: Context | undefined): Promise<AppIdentifier> {
78+
async open(
79+
app: AppIdentifier,
80+
context?: Context | undefined,
81+
metadata?: AppProvidableContextMetadata
82+
): Promise<AppIdentifier> {
7283
const request: OpenRequest = {
7384
type: 'openRequest',
7485
payload: {
@@ -78,6 +89,7 @@ export class DefaultAppSupport implements AppSupport {
7889
},
7990
context,
8091
},
92+
metadata,
8193
meta: this.messaging.createMeta(),
8294
};
8395

packages/fdc3-agent-proxy/src/intents/DefaultIntentSupport.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
IntentResult,
99
IntentResolver,
1010
IntentResolutionChoice,
11+
AppProvidableContextMetadata,
1112
} from '@finos/fdc3-standard';
1213
import { IntentSupport } from './IntentSupport.js';
1314
import { Messaging } from '../Messaging.js';
@@ -28,6 +29,7 @@ import {
2829
RaiseIntentResultResponse,
2930
} from '@finos/fdc3-schema/dist/generated/api/BrowserTypes.js';
3031
import { throwIfUndefined } from '../util/throwIfUndefined.js';
32+
import { v4 } from 'uuid';
3133

3234
const convertIntentResult = async (
3335
{ payload }: RaiseIntentResultResponse,
@@ -130,16 +132,25 @@ export class DefaultIntentSupport implements IntentSupport {
130132
return ir;
131133
}
132134

133-
async raiseIntent(intent: string, context: Context, app: AppIdentifier): Promise<IntentResolution> {
135+
async raiseIntent(
136+
intent: string,
137+
context: Context,
138+
app: AppIdentifier,
139+
metadata?: AppProvidableContextMetadata
140+
): Promise<IntentResolution> {
134141
const meta = this.messaging.createMeta();
135142
const request: RaiseIntentRequest = {
136143
type: 'raiseIntentRequest',
137144
payload: {
138145
intent,
139146
context,
140-
app: app,
147+
app,
141148
},
142-
meta: meta,
149+
metadata: {
150+
signature: metadata?.signature,
151+
traceId: metadata?.traceId ?? v4(),
152+
},
153+
meta,
143154
};
144155

145156
const resultPromise = this.createResultPromise(request);
@@ -163,7 +174,7 @@ export class DefaultIntentSupport implements IntentSupport {
163174
context
164175
);
165176
if (result) {
166-
return this.raiseIntent(intent, context, result.appId);
177+
return this.raiseIntent(intent, context, result.appId, metadata);
167178
} else {
168179
throw new Error(ResolveError.UserCancelled);
169180
}
@@ -174,14 +185,23 @@ export class DefaultIntentSupport implements IntentSupport {
174185
}
175186
}
176187

177-
async raiseIntentForContext(context: Context, app?: AppIdentifier | undefined): Promise<IntentResolution> {
188+
async raiseIntentForContext(
189+
context: Context,
190+
app?: AppIdentifier,
191+
metadata?: AppProvidableContextMetadata
192+
): Promise<IntentResolution> {
193+
const meta = this.messaging.createMeta();
178194
const request: RaiseIntentForContextRequest = {
179195
type: 'raiseIntentForContextRequest',
180196
payload: {
181197
context,
182-
app: app,
198+
app,
183199
},
184-
meta: this.messaging.createMeta(),
200+
metadata: {
201+
signature: metadata?.signature,
202+
traceId: metadata?.traceId ?? v4(),
203+
},
204+
meta,
185205
};
186206

187207
const resultPromise = this.createResultPromise(request);
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1-
import { AppIdentifier, AppIntent, IntentHandler, IntentResolution, Listener } from '@finos/fdc3-standard';
1+
import {
2+
AppIdentifier,
3+
AppIntent,
4+
AppProvidableContextMetadata,
5+
IntentHandler,
6+
IntentResolution,
7+
Listener,
8+
} from '@finos/fdc3-standard';
29
import { Context } from '@finos/fdc3-context';
310

411
export interface IntentSupport {
512
findIntent(intent: string, context: Context, resultType: string | undefined): Promise<AppIntent>;
613
findIntentsByContext(context: Context): Promise<AppIntent[]>;
7-
raiseIntent(intent: string, context: Context, app?: AppIdentifier): Promise<IntentResolution>;
8-
raiseIntentForContext(context: Context, app?: AppIdentifier): Promise<IntentResolution>;
14+
raiseIntent(
15+
intent: string,
16+
context: Context,
17+
app?: AppIdentifier,
18+
metadata?: AppProvidableContextMetadata
19+
): Promise<IntentResolution>;
20+
raiseIntentForContext(
21+
context: Context,
22+
app?: AppIdentifier,
23+
metadata?: AppProvidableContextMetadata
24+
): Promise<IntentResolution>;
925
addIntentListener(intent: string, handler: IntentHandler): Promise<Listener>;
1026
}

packages/fdc3-agent-proxy/src/listeners/DefaultContextListener.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { AppIdentifier, ContextHandler } from '@finos/fdc3-standard';
1+
import { ContextHandler, DesktopAgentProvidableContextMetadata } from '@finos/fdc3-standard';
22
import { Messaging } from '../Messaging.js';
33
import { AbstractListener } from './AbstractListener.js';
44
import { AddContextListenerRequest, BroadcastEvent } from '@finos/fdc3-schema/dist/generated/api/BrowserTypes.js';
55
import { RegisterableListener } from './RegisterableListener.js';
66

7+
78
export class DefaultContextListener
89
extends AbstractListener<ContextHandler, AddContextListenerRequest>
910
implements RegisterableListener
@@ -44,8 +45,12 @@ export class DefaultContextListener
4445
}
4546

4647
action(m: BroadcastEvent): void {
47-
this.handler(m.payload.context, {
48-
source: m.payload.originatingApp as AppIdentifier,
49-
});
48+
const metadata: DesktopAgentProvidableContextMetadata = {
49+
source: m.payload.originatingApp,
50+
timestamp: m.meta.timestamp,
51+
traceId: m.metadata?.traceId,
52+
signature: m.metadata?.signature,
53+
};
54+
this.handler(m.payload.context, metadata);
5055
}
5156
}

packages/fdc3-agent-proxy/src/listeners/DefaultIntentListener.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
IntentResultResponse,
1010
//RaiseIntentResponse,
1111
} from '@finos/fdc3-schema/dist/generated/api/BrowserTypes.js';
12+
import { v4 } from 'uuid';
1213

1314
export class DefaultIntentListener extends AbstractListener<IntentHandler, AddIntentListenerRequest> {
1415
readonly intent: string;
@@ -34,6 +35,9 @@ export class DefaultIntentListener extends AbstractListener<IntentHandler, AddIn
3435
action(m: IntentEvent): void {
3536
const done = this.handler(m.payload.context, {
3637
source: m.payload.originatingApp as AppIdentifier,
38+
timestamp: m.meta.timestamp,
39+
traceId: m.metadata?.traceId ?? v4(),
40+
signature: m.metadata?.signature,
3741
});
3842

3943
this.handleIntentResult(done, m);
@@ -51,6 +55,7 @@ export class DefaultIntentListener extends AbstractListener<IntentHandler, AddIn
5155
intentEventUuid: m.meta.eventUuid,
5256
raiseIntentRequestUuid: m.payload.raiseIntentRequestUuid,
5357
},
58+
metadata: m.metadata,
5459
};
5560

5661
return out;

packages/fdc3-schema/schemas/api/addIntentListenerResponse.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
}
2525
]
2626
},
27+
"metadata": {
28+
"$ref": "api.schema.json#/definitions/DesktopAgentProvidableContextMetadata"
29+
},
2730
"meta": true
2831
},
2932
"additionalProperties": false

packages/fdc3-schema/schemas/api/agentEvent.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"description": "The message payload contains details of the event that the app is being notified about.",
2828
"additionalProperties": true
2929
},
30+
"metadata": {
31+
"$ref": "api.schema.json#/definitions/DesktopAgentProvidableContextMetadata"
32+
},
3033
"meta": {
3134
"title": "Event Metadata",
3235
"description": "Metadata for messages sent by a Desktop Agent to an app notifying it of an event.",

packages/fdc3-schema/schemas/api/api.schema.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,45 @@
283283
"source"
284284
]
285285
},
286+
"AppProvidableContextMetadata": {
287+
"description": "Metadata that can be provided by an app.",
288+
"title": "AppProvidableContextMetadata",
289+
"type": "object",
290+
"properties": {
291+
"signature": {
292+
"type": "string"
293+
},
294+
"traceId": {
295+
"type": "string"
296+
},
297+
"hostParams": {
298+
"type": "object"
299+
}
300+
},
301+
"additionalProperties": false
302+
},
303+
"DesktopAgentProvidableContextMetadata": {
304+
"description": "Metadata that can be provided by an app.",
305+
"title": "DesktopAgentProvidableContextMetadata",
306+
"type": "object",
307+
"properties": {
308+
"signature": {
309+
"type": "string"
310+
},
311+
"traceId": {
312+
"type": "string"
313+
},
314+
"timestamp": {
315+
"type": "number"
316+
},
317+
"source": {
318+
"$ref": "#/definitions/AppIdentifier",
319+
"description": "Identifier for the source app instance",
320+
"title": "source"
321+
}
322+
},
323+
"additionalProperties": false
324+
},
286325
"DesktopAgentIdentifier": {
287326
"description": "Identifies a particular Desktop Agent in Desktop Agent Bridging scenarios\nwhere a request needs to be directed to a Desktop Agent rather than a specific app, or a\nresponse message is returned by the Desktop Agent (or more specifically its resolver)\nrather than a specific app. Used as a substitute for `AppIdentifier` in cases where no\napp details are available or are appropriate.",
288327
"title": "DesktopAgentIdentifier",

0 commit comments

Comments
 (0)