Skip to content

Commit a718c75

Browse files
authored
Merge branch 'main' into fix/bind-this-in-api-objects-and-docs-update
2 parents 9ef42a5 + 72c8e53 commit a718c75

22 files changed

Lines changed: 753 additions & 56 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1515
* Added clarification regarding expected behavior upon repeated calls to `addContextListener` on same or overlapping types (allowed) and `addIntentListener` on same intent (rejected; new error type added). ([#1394](https://github.com/finos/FDC3/pull/1394))
1616
* Ported FDC3 Conformance Project as-is into the FDC3 Monorepo, just including minimal fixes for typescript compilation. ([#1576](https://github.com/finos/FDC3/pull/1576))
1717

18+
* Added `clearContext` function and associated `contextClearedEvent` to the `Channel` API, to be able to clear specific or all context types from the channel. ([#1379](https://github.com/finos/FDC3/pull/1379))
19+
1820
### Changed
1921

2022
### Deprecated

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/fdc3-agent-proxy/src/channels/DefaultChannel.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import { ContextHandler, DisplayMetadata, Listener, Channel } from '@finos/fdc3-standard';
1+
import { ContextHandler, DisplayMetadata, Listener, Channel, EventHandler } from '@finos/fdc3-standard';
22
import { Context } from '@finos/fdc3-context';
33
import { Messaging } from '../Messaging';
44
import { DefaultContextListener } from '../listeners/DefaultContextListener';
55
import {
66
BroadcastRequest,
77
BroadcastResponse,
8+
ClearContextRequest,
9+
ClearContextResponse,
810
GetCurrentContextRequest,
911
GetCurrentContextResponse,
1012
} from '@finos/fdc3-schema/generated/api/BrowserTypes';
13+
import { RegisterableListener } from '../listeners/RegisterableListener';
14+
import { EventListener } from '../listeners/EventListener';
1115

1216
export class DefaultChannel implements Channel {
1317
protected readonly messaging: Messaging;
@@ -103,4 +107,30 @@ export class DefaultChannel implements Channel {
103107
await listener.register();
104108
return listener;
105109
}
110+
111+
async clearContext(contextType?: string): Promise<void> {
112+
// first, ensure channel state is up-to-date
113+
const request: ClearContextRequest = {
114+
meta: this.messaging.createMeta(),
115+
payload: {
116+
channelId: this.id,
117+
contextType: contextType ?? null,
118+
},
119+
type: 'clearContextRequest',
120+
};
121+
await this.messaging.exchange<ClearContextResponse>(request, 'clearContextResponse', this.messageExchangeTimeout);
122+
}
123+
124+
async addEventListener(type: string | null, handler: EventHandler): Promise<Listener> {
125+
let listener: RegisterableListener;
126+
switch (type) {
127+
case 'contextCleared':
128+
listener = new EventListener(this.messaging, 'contextCleared', handler);
129+
break;
130+
default:
131+
throw new Error('Unsupported event type: ' + type);
132+
}
133+
await listener.register();
134+
return listener;
135+
}
106136
}

packages/fdc3-schema/generated/api/BrowserTypes.ts

Lines changed: 277 additions & 20 deletions
Large diffs are not rendered by default.

packages/fdc3-schema/generated/bridging/BridgingTypes.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ export interface ErrorResponseMessagePayload {
114114
* Constants representing the errors that can be encountered when calling the `open` method
115115
* on the DesktopAgent object (`fdc3`).
116116
*
117-
* Constants representing the errors that can be encountered when calling the `findIntent`,
118-
* `findIntentsByContext`, `raiseIntent` or `raiseIntentForContext` methods on the
119-
* DesktopAgent (`fdc3`).
117+
* Constants representing the errors that can be encountered when calling the
118+
* `addIntentListener`, `findIntent`, `findIntentsByContext`, `raiseIntent` or
119+
* `raiseIntentForContext` methods on the DesktopAgent (`fdc3`).
120120
*/
121121
export type ResponseErrorDetail =
122122
| 'AccessDenied'
@@ -136,6 +136,7 @@ export type ResponseErrorDetail =
136136
| 'TargetAppUnavailable'
137137
| 'TargetInstanceUnavailable'
138138
| 'UserCancelledResolution'
139+
| 'IntentListenerConflict'
139140
| 'IntentHandlerRejected'
140141
| 'NoResultReturned'
141142
| 'AgentDisconnected'
@@ -1134,9 +1135,9 @@ export interface PayloadClass {
11341135
*
11351136
* Should be set if the raiseIntent request returned an error.
11361137
*
1137-
* Constants representing the errors that can be encountered when calling the `findIntent`,
1138-
* `findIntentsByContext`, `raiseIntent` or `raiseIntentForContext` methods on the
1139-
* DesktopAgent (`fdc3`).
1138+
* Constants representing the errors that can be encountered when calling the
1139+
* `addIntentListener`, `findIntent`, `findIntentsByContext`, `raiseIntent` or
1140+
* `raiseIntentForContext` methods on the DesktopAgent (`fdc3`).
11401141
*
11411142
* Array of error message strings for responses that were not returned to the bridge before
11421143
* the timeout or because an error occurred. Should be the same length as the `errorSources`
@@ -1157,6 +1158,7 @@ export type FindInstancesErrors =
11571158
| 'UserCancelledResolution'
11581159
| 'ApiTimeout'
11591160
| 'InvalidArguments'
1161+
| 'IntentListenerConflict'
11601162
| 'AgentDisconnected'
11611163
| 'NotConnectedToBridge'
11621164
| 'ResponseToBridgeTimedOut'
@@ -2572,9 +2574,9 @@ export interface OpenAgentErrorResponsePayload {
25722574
* the timeout or because an error occurred. Should be the same length as the `errorSources`
25732575
* array and ordered the same. May be omitted if all sources responded without errors.
25742576
*
2575-
* Constants representing the errors that can be encountered when calling the `findIntent`,
2576-
* `findIntentsByContext`, `raiseIntent` or `raiseIntentForContext` methods on the
2577-
* DesktopAgent (`fdc3`).
2577+
* Constants representing the errors that can be encountered when calling the
2578+
* `addIntentListener`, `findIntent`, `findIntentsByContext`, `raiseIntent` or
2579+
* `raiseIntentForContext` methods on the DesktopAgent (`fdc3`).
25782580
*/
25792581
export type OpenErrorResponsePayload =
25802582
| 'AppNotFound'
@@ -4031,9 +4033,9 @@ export interface RaiseIntentResultAgentErrorResponsePayload {
40314033
* Constants representing the errors that can be encountered when calling the `open` method
40324034
* on the DesktopAgent object (`fdc3`).
40334035
*
4034-
* Constants representing the errors that can be encountered when calling the `findIntent`,
4035-
* `findIntentsByContext`, `raiseIntent` or `raiseIntentForContext` methods on the
4036-
* DesktopAgent (`fdc3`).
4036+
* Constants representing the errors that can be encountered when calling the
4037+
* `addIntentListener`, `findIntent`, `findIntentsByContext`, `raiseIntent` or
4038+
* `raiseIntentForContext` methods on the DesktopAgent (`fdc3`).
40374039
*/
40384040
export type RaiseIntentResultErrorMessage =
40394041
| 'IntentHandlerRejected'
@@ -6489,6 +6491,7 @@ const typeMap: any = {
64896491
'ErrorOnLaunch',
64906492
'IntentDeliveryFailed',
64916493
'IntentHandlerRejected',
6494+
'IntentListenerConflict',
64926495
'InvalidArguments',
64936496
'MalformedContext',
64946497
'MalformedMessage',
@@ -6538,6 +6541,7 @@ const typeMap: any = {
65386541
'AgentDisconnected',
65396542
'DesktopAgentNotFound',
65406543
'IntentDeliveryFailed',
6544+
'IntentListenerConflict',
65416545
'InvalidArguments',
65426546
'MalformedContext',
65436547
'MalformedMessage',

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"intentEvent",
1717
"privateChannelOnAddContextListenerEvent",
1818
"privateChannelOnDisconnectEvent",
19-
"privateChannelOnUnsubscribeEvent"
19+
"privateChannelOnUnsubscribeEvent",
20+
"contextClearedEvent"
2021
],
2122
"description": "Identifies the type of the message and it is typically set to the FDC3 function name that the message relates to, e.g. 'findIntent', with 'Response' appended."
2223
},

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"privateChannelUnsubscribeEventListenerResponse",
3636
"raiseIntentForContextResponse",
3737
"raiseIntentResponse",
38-
"raiseIntentResultResponse"
38+
"raiseIntentResultResponse",
39+
"clearContextResponse"
3940
],
4041
"description": "Identifies the type of the message and it is typically set to the FDC3 function name that the message relates to, e.g. 'findIntent', with 'Response' appended."
4142
},

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"privateChannelDisconnectRequest",
3636
"privateChannelUnsubscribeEventListenerRequest",
3737
"raiseIntentForContextRequest",
38-
"raiseIntentRequest"
38+
"raiseIntentRequest",
39+
"clearContextRequest"
3940
],
4041
"description": "Identifies the type of the message and it is typically set to the FDC3 function name that the message relates to, e.g. 'findIntent', with 'Request' appended."
4142
},
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://fdc3.finos.org/schemas/next/api/clearContextRequest.schema.json",
4+
"type": "object",
5+
"title": "Clear Context Request",
6+
"description": "A request to clear context on a channel.",
7+
"allOf": [
8+
{
9+
"$ref": "appRequest.schema.json"
10+
},
11+
{
12+
"type": "object",
13+
"properties": {
14+
"type": {
15+
"$ref": "#/$defs/ClearContextRequestType"
16+
},
17+
"payload": {
18+
"$ref": "#/$defs/ClearContextRequestPayload"
19+
},
20+
"meta": true
21+
},
22+
"additionalProperties": false
23+
}
24+
],
25+
"$defs": {
26+
"ClearContextRequestType": {
27+
"title": "Clear Context Request Message Type",
28+
"const": "clearContextRequest"
29+
},
30+
"ClearContextRequestPayload": {
31+
"title": "Clear Context Request Payload",
32+
"type": "object",
33+
"properties": {
34+
"channelId": {
35+
"title": "Channel Id",
36+
"description": "The id of the channel to clear the context on.",
37+
"type": "string"
38+
},
39+
"contextType": {
40+
"title": "Context type",
41+
"description": "The type of context to clear for OR `null` indicating that all context types on the channel should be cleared.",
42+
"oneOf": [
43+
{
44+
"type": "string"
45+
},
46+
{
47+
"type": "null"
48+
}
49+
]
50+
}
51+
},
52+
"required": ["channelId", "contextType"],
53+
"additionalProperties": false
54+
}
55+
}
56+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://fdc3.finos.org/schemas/next/api/clearContextResponse.schema.json",
4+
"type": "object",
5+
"title": "Clear Context Response",
6+
"description": "A response to a request to clear context on a channel.",
7+
"allOf": [
8+
{
9+
"$ref": "agentResponse.schema.json"
10+
},
11+
{
12+
"type": "object",
13+
"properties": {
14+
"type": {
15+
"$ref": "#/$defs/ClearContextResponseType"
16+
},
17+
"payload": true,
18+
"meta": true
19+
},
20+
"additionalProperties": false
21+
}
22+
],
23+
"$defs": {
24+
"ClearContextResponseType": {
25+
"title": "Clear Context Response Message Type",
26+
"const": "clearContextResponse"
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)