Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d9541d1
Context Clearing
kemerava Sep 27, 2024
77e2b61
Apply suggestions from code review
kemerava Oct 4, 2024
a2c348e
Changelog and fixing the name of the field
kemerava Oct 4, 2024
60456c3
Merge remote-tracking branch 'origin/main' into feature/context-clearing
kemerava Dec 11, 2024
768f50d
Adding conformance tests
kemerava Dec 11, 2024
acac1a0
Apply suggestions from code review
kemerava Jan 31, 2025
a4106fe
Merge remote-tracking branch 'origin/main' into feature/context-clearing
kemerava Mar 21, 2025
4e2bc61
Merge branch 'main' into feature/context-clearing
kriswest Apr 17, 2025
c66f420
Merge remote-tracking branch 'origin/main' into feature/context-clearing
kemerava May 8, 2025
cdeea6a
Adding addEventListener for listening on clearing context
kemerava May 8, 2025
1ad0c4a
Clearing context tests
kemerava May 8, 2025
a732bcc
Fixing package-lock.json
kemerava May 14, 2025
9c79048
Making build pass
kemerava Jun 20, 2025
04507e0
Merge remote-tracking branch 'origin/main' into feature/context-clearing
kemerava Jul 9, 2025
e21ec30
Adding the event for the contextCleared
kemerava Jul 9, 2025
90c8fab
npm
kemerava Jul 9, 2025
c63e1d4
PR review changes
kemerava Jul 9, 2025
b953954
Merge remote-tracking branch 'origin/main' into feature/context-clearing
kemerava Jul 25, 2025
bc5c98c
Update CHANGELOG.md
kemerava Jul 25, 2025
c572444
Merge branch 'feature/context-clearing' of https://github.com/kemerav…
kemerava Jul 25, 2025
90a06e3
Update website/docs/api/ref/Channel.md
kemerava Jul 25, 2025
ac73c5c
Updating based on reviews
kemerava Jul 25, 2025
6d22fb3
Typo
kemerava Jul 25, 2025
a7e5c4b
Update lang
kemerava Jul 25, 2025
660182d
Merge pull request #1379 from kemerava/feature/context-clearing
kemerava Jul 29, 2025
dcc18b4
Merge branch 'main' into 1197-context-clearing
kriswest Aug 13, 2025
5e6fad3
fixing lock file issues with @cucumber/messages and generally updatin…
kriswest Aug 13, 2025
ff38287
Regenerate Browser and Bridging types after addition of a new error
kriswest Aug 13, 2025
8db9281
Merge branch 'fdc3-conformance-typo' into 1197-context-clearing
kriswest Aug 13, 2025
9ed5cc0
Update website/docs/api/conformance/App-Channel-Tests.md
kriswest Aug 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* 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))
* 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))

* 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))

### Changed

### Deprecated
Expand Down
32 changes: 31 additions & 1 deletion packages/fdc3-agent-proxy/src/channels/DefaultChannel.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { ContextHandler, DisplayMetadata, Listener, Channel } from '@finos/fdc3-standard';
import { ContextHandler, DisplayMetadata, Listener, Channel, EventHandler } from '@finos/fdc3-standard';
import { Context } from '@finos/fdc3-context';
import { Messaging } from '../Messaging';
import { DefaultContextListener } from '../listeners/DefaultContextListener';
import {
BroadcastRequest,
BroadcastResponse,
ClearContextRequest,
ClearContextResponse,
GetCurrentContextRequest,
GetCurrentContextResponse,
} from '@finos/fdc3-schema/generated/api/BrowserTypes';
import { RegisterableListener } from '../listeners/RegisterableListener';
import { EventListener } from '../listeners/EventListener';

export class DefaultChannel implements Channel {
protected readonly messaging: Messaging;
Expand Down Expand Up @@ -98,4 +102,30 @@ export class DefaultChannel implements Channel {
await listener.register();
return listener;
}

async clearContext(contextType?: string): Promise<void> {
// first, ensure channel state is up-to-date
const request: ClearContextRequest = {
meta: this.messaging.createMeta(),
payload: {
channelId: this.id,
contextType: contextType ?? null,
},
type: 'clearContextRequest',
};
await this.messaging.exchange<ClearContextResponse>(request, 'clearContextResponse', this.messageExchangeTimeout);
}

async addEventListener(type: string | null, handler: EventHandler): Promise<Listener> {
let listener: RegisterableListener;
switch (type) {
case 'contextCleared':
listener = new EventListener(this.messaging, 'contextCleared', handler);
break;
default:
throw new Error('Unsupported event type: ' + type);
}
await listener.register();
return listener;
}
}
297 changes: 277 additions & 20 deletions packages/fdc3-schema/generated/api/BrowserTypes.ts

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions packages/fdc3-schema/generated/bridging/BridgingTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ export interface ErrorResponseMessagePayload {
* Constants representing the errors that can be encountered when calling the `open` method
* on the DesktopAgent object (`fdc3`).
*
* Constants representing the errors that can be encountered when calling the `findIntent`,
* `findIntentsByContext`, `raiseIntent` or `raiseIntentForContext` methods on the
* DesktopAgent (`fdc3`).
* Constants representing the errors that can be encountered when calling the
* `addIntentListener`, `findIntent`, `findIntentsByContext`, `raiseIntent` or
* `raiseIntentForContext` methods on the DesktopAgent (`fdc3`).
*/
export type ResponseErrorDetail =
| 'AccessDenied'
Expand All @@ -136,6 +136,7 @@ export type ResponseErrorDetail =
| 'TargetAppUnavailable'
| 'TargetInstanceUnavailable'
| 'UserCancelledResolution'
| 'IntentListenerConflict'
| 'IntentHandlerRejected'
| 'NoResultReturned'
| 'AgentDisconnected'
Expand Down Expand Up @@ -1134,9 +1135,9 @@ export interface PayloadClass {
*
* Should be set if the raiseIntent request returned an error.
*
* Constants representing the errors that can be encountered when calling the `findIntent`,
* `findIntentsByContext`, `raiseIntent` or `raiseIntentForContext` methods on the
* DesktopAgent (`fdc3`).
* Constants representing the errors that can be encountered when calling the
* `addIntentListener`, `findIntent`, `findIntentsByContext`, `raiseIntent` or
* `raiseIntentForContext` methods on the DesktopAgent (`fdc3`).
*
* Array of error message strings for responses that were not returned to the bridge before
* the timeout or because an error occurred. Should be the same length as the `errorSources`
Expand All @@ -1157,6 +1158,7 @@ export type FindInstancesErrors =
| 'UserCancelledResolution'
| 'ApiTimeout'
| 'InvalidArguments'
| 'IntentListenerConflict'
| 'AgentDisconnected'
| 'NotConnectedToBridge'
| 'ResponseToBridgeTimedOut'
Expand Down Expand Up @@ -2572,9 +2574,9 @@ export interface OpenAgentErrorResponsePayload {
* the timeout or because an error occurred. Should be the same length as the `errorSources`
* array and ordered the same. May be omitted if all sources responded without errors.
*
* Constants representing the errors that can be encountered when calling the `findIntent`,
* `findIntentsByContext`, `raiseIntent` or `raiseIntentForContext` methods on the
* DesktopAgent (`fdc3`).
* Constants representing the errors that can be encountered when calling the
* `addIntentListener`, `findIntent`, `findIntentsByContext`, `raiseIntent` or
* `raiseIntentForContext` methods on the DesktopAgent (`fdc3`).
*/
export type OpenErrorResponsePayload =
| 'AppNotFound'
Expand Down Expand Up @@ -4031,9 +4033,9 @@ export interface RaiseIntentResultAgentErrorResponsePayload {
* Constants representing the errors that can be encountered when calling the `open` method
* on the DesktopAgent object (`fdc3`).
*
* Constants representing the errors that can be encountered when calling the `findIntent`,
* `findIntentsByContext`, `raiseIntent` or `raiseIntentForContext` methods on the
* DesktopAgent (`fdc3`).
* Constants representing the errors that can be encountered when calling the
* `addIntentListener`, `findIntent`, `findIntentsByContext`, `raiseIntent` or
* `raiseIntentForContext` methods on the DesktopAgent (`fdc3`).
*/
export type RaiseIntentResultErrorMessage =
| 'IntentHandlerRejected'
Expand Down Expand Up @@ -6489,6 +6491,7 @@ const typeMap: any = {
'ErrorOnLaunch',
'IntentDeliveryFailed',
'IntentHandlerRejected',
'IntentListenerConflict',
'InvalidArguments',
'MalformedContext',
'MalformedMessage',
Expand Down Expand Up @@ -6538,6 +6541,7 @@ const typeMap: any = {
'AgentDisconnected',
'DesktopAgentNotFound',
'IntentDeliveryFailed',
'IntentListenerConflict',
'InvalidArguments',
'MalformedContext',
'MalformedMessage',
Expand Down
3 changes: 2 additions & 1 deletion packages/fdc3-schema/schemas/api/agentEvent.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"intentEvent",
"privateChannelOnAddContextListenerEvent",
"privateChannelOnDisconnectEvent",
"privateChannelOnUnsubscribeEvent"
"privateChannelOnUnsubscribeEvent",
"contextClearedEvent"
],
"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."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"privateChannelUnsubscribeEventListenerResponse",
"raiseIntentForContextResponse",
"raiseIntentResponse",
"raiseIntentResultResponse"
"raiseIntentResultResponse",
"clearContextResponse"
],
"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."
},
Expand Down
3 changes: 2 additions & 1 deletion packages/fdc3-schema/schemas/api/appRequest.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"privateChannelDisconnectRequest",
"privateChannelUnsubscribeEventListenerRequest",
"raiseIntentForContextRequest",
"raiseIntentRequest"
"raiseIntentRequest",
"clearContextRequest"
],
"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."
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/api/clearContextRequest.schema.json",
"type": "object",
"title": "Clear Context Request",
"description": "A request to clear context on a channel.",
"allOf": [
{
"$ref": "appRequest.schema.json"
},
{
"type": "object",
"properties": {
"type": {
"$ref": "#/$defs/ClearContextRequestType"
},
"payload": {
"$ref": "#/$defs/ClearContextRequestPayload"
},
"meta": true
},
"additionalProperties": false
}
],
"$defs": {
"ClearContextRequestType": {
"title": "Clear Context Request Message Type",
"const": "clearContextRequest"
},
"ClearContextRequestPayload": {
"title": "Clear Context Request Payload",
"type": "object",
"properties": {
"channelId": {
"title": "Channel Id",
"description": "The id of the channel to clear the context on.",
"type": "string"
},
"contextType": {
"title": "Context type",
"description": "The type of context to clear for OR `null` indicating that all context types on the channel should be cleared.",
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
},
"required": ["channelId", "contextType"],
"additionalProperties": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/api/clearContextResponse.schema.json",
"type": "object",
"title": "Clear Context Response",
"description": "A response to a request to clear context on a channel.",
"allOf": [
{
"$ref": "agentResponse.schema.json"
},
{
"type": "object",
"properties": {
"type": {
"$ref": "#/$defs/ClearContextResponseType"
},
"payload": true,
"meta": true
},
"additionalProperties": false
}
],
"$defs": {
"ClearContextResponseType": {
"title": "Clear Context Response Message Type",
"const": "clearContextResponse"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/api/contextClearedEvent.schema.json",
"type": "object",
"title": "contextCleared Event",
"description": "An event message from the Desktop Agent to an app indicating that context has been cleared on a channel.",
"allOf": [
{
"$ref": "agentEvent.schema.json"
},
{
"type": "object",
"properties": {
"type": {
"$ref": "#/$defs/ContextClearedEventType"
},
"payload": {
"$ref": "#/$defs/ContextClearedEventPayload"
},
"meta": true
},
"additionalProperties": false
}
],
"$defs": {
"ContextClearedEventType": {
"title": "ContextCleared Event Message Type",
"const": "contextClearedEvent"
},
"ContextClearedEventPayload": {
"title": "contextCleared Event Payload",
"type": "object",
"properties": {
"channelId": {
"title": "Channel Id",
"description": "The Id of the channel that was cleared.",
"type": ["string", "null"]
},
"contextType": {
"title": "Context Type",
"description": "The type of context that was cleared, or null if all types were cleared.",
"type": ["string", "null"]
}
},
"required": ["channelId", "contextType"],
"additionalProperties": false
}
}
}
33 changes: 33 additions & 0 deletions packages/fdc3-standard/src/api/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { ContextHandler } from './Types';
import { DisplayMetadata } from './DisplayMetadata';
import { Listener } from './Listener';
import { EventHandler } from './Events';

/**
* Represents a context channel that applications can use to send and receive
Expand Down Expand Up @@ -76,8 +77,40 @@
*/
addContextListener(contextType: string | null, handler: ContextHandler): Promise<Listener>;

/**
* Clears context from the channel, and triggers the event listener on the `contextCleared` event to notify existing listeners that the context was cleared. Listeners added to the channel and calls to [`getCurrentContext`](#getcurrentcontext) will not receive any existing context until new context is broadcast to the channel.
*
* If a `contextType` is provided, only contexts of that type will be cleared.
*
* If no `contextType` is provided, all contexts will be cleared.
*/
clearContext(contextType?: string): Promise<void>;

/**
* Register a handler for events from the Channel. Whenever the handler function
* is called it will be passed an event object with details related to the event.
*
* ```js
* // any event type
* const listener = await myChannel.addEventListener(null, event => {
* console.log(`Received event ${event.type}\n\tDetails: ${event.details}`);
* });
*
* // listener for a specific event type
* const contextClearedListener = await myChannel.addEventListener(
* "contextCleared",
* event => { ... }
* );
* ```
*
* @param {string | null} type If non-null, only events of the specified type will be received by the handler.
* @param {EventHandler} handler A function that events received will be passed to.
*
*/
addEventListener(type: string | null, handler: EventHandler): Promise<Listener>;

/**
* @deprecated use `addContextListener(null, handler)` instead of `addContextListener(handler)`.
*/
addContextListener(handler: ContextHandler): Promise<Listener>;

Check warning on line 115 in packages/fdc3-standard/src/api/Channel.ts

View workflow job for this annotation

GitHub Actions / test

All addContextListener signatures should be adjacent

Check warning on line 115 in packages/fdc3-standard/src/api/Channel.ts

View workflow job for this annotation

GitHub Actions / test

All addContextListener signatures should be adjacent

Check warning on line 115 in packages/fdc3-standard/src/api/Channel.ts

View workflow job for this annotation

GitHub Actions / Build on Node 20 and ubuntu-latest

All addContextListener signatures should be adjacent

Check warning on line 115 in packages/fdc3-standard/src/api/Channel.ts

View workflow job for this annotation

GitHub Actions / Build on Node 20 and windows-latest

All addContextListener signatures should be adjacent
}
10 changes: 10 additions & 0 deletions packages/fdc3-standard/src/api/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ export interface FDC3ChannelChangedEvent extends FDC3Event {
};
}

/**
* Type defining the format of event `contextCleared` objects
*/
export interface FDC3ContextClearedEvent extends FDC3Event {
readonly type: 'contextCleared';
readonly details: {
contextType: string | null;
};
}

/**
* Type defining valid type strings for Private Channel events.
*/
Expand Down
Loading
Loading