Skip to content

Commit bab450a

Browse files
authored
Merge pull request #1442 from finos/fdc3-for-web-update-session-storage
Updating SessionStorage data format to additionally scope data
2 parents cbf3aeb + e5a0a49 commit bab450a

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
3232
* The supported platforms page in the FDC3 documentation was moved into the API section as the information it provides all relates to FDC3 Desktop Agent API implementations. ([#1108](https://github.com/finos/FDC3/pull/1108))
3333
* FDC3 apps are now encouraged to instantiate their FDC3 interface (DesktopAgent) using the `getAgent()` function provided by the `@finos/fdc3` module. This will allow apps to interoperate in either traditional Preload DAs (i.e. Electron) as well as the new Browser-Resident DAs. ([#1191](https://github.com/finos/FDC3/pull/1191))
3434
* `ContextType` and `Intent` (`string`) types were created for use in DesktopAgent API signatures - they are unions of standardized values and `string`, enabling autocomplete/IntelliSense in IDEs when working with the FDC3 API. ([#1139](https://github.com/finos/FDC3/pull/1139))
35+
* SessionStorage use by `getAgent` was updated to scope the stored data by `window.name` and the app's `identityUrl`. ([#1442](https://github.com/finos/FDC3/pull/1442))
3536

3637
### Deprecated
3738

docs/api/ref/GetAgent.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ A small number of arguments are accepted that can affect the behavior of `getAge
6161
*
6262
* @property {number} timeoutMs Number of milliseconds to allow for an FDC3
6363
* implementation to be found before calling the failover function or
64-
* rejecting (default 750). Note that the timeout is cancelled as soon as a
64+
* rejecting (default 1000). Note that the timeout is cancelled as soon as a
6565
* Desktop Agent is detected. There may be additional set-up steps to perform
6666
* which will happen outside the timeout.
6767
*
@@ -159,11 +159,34 @@ Failover functions MUST be asynchronous and MUST resolve to one of the following
159159

160160
## Persisted Connection Data
161161

162-
The `getAgent()` function uses [`SessionStorage`](https://html.spec.whatwg.org/multipage/webstorage.html) ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage)) to persist information on an instance of an app under the key `"FDC3-Desktop-Agent-Details"` and how it connected to a Desktop Agent in order to ensure a consistent connection type and `instanceId` when reconnecting after navigation or refresh events. Applications are not expected to interact with this information directly, rather it is set and used by the `getAgent()` implementation.
162+
The `getAgent()` function uses [`SessionStorage`](https://html.spec.whatwg.org/multipage/webstorage.html) ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage)) to persist information on an instance of an app and how it connected to a Desktop Agent in order to ensure a consistent connection type and `instanceId` when reconnecting after navigation or refresh events.
163163

164-
The details persisted conform to the following type:
164+
:::warning
165+
Apps do not need to and SHOULD NOT interact with data persisted in SessionStorage by `getAgent` directly, rather it is set and used by the `getAgent()` implementation.
166+
:::
167+
168+
SessionStorage is used as for persistence as it is scoped to a single browser window and the current origin, ensuring apps in different windows or on different origins access different storage. However, as multiple iframes from the same-domain embedded within a window can share a SessionStorage instance, and multiple applications can be hosted on the same origin and be navigated to and from within a window, additional scoping is applied.
169+
170+
To differentiate storage for multiple iframes the name of the browsing context (`window.name`) is used to generate the key used in SessionStorage by concatenating the string `"FDC3-Desktop-Agent-Details-"` with `window.name`. The `window.name` remains stable during same-origin navigation and is persisted by the browser in its [session history](https://html.spec.whatwg.org/multipage/nav-history-apis.html#nav-traversal-apis) and is appropriate for scoping to a particular browsing context (window or iframe). Desktop Agents should assign a unique name to each window and iframe when they are created to facilitate such scoping. If no name is assigned, then the `getAgent` will assign a UUID as a unique name for that browsing context.
171+
172+
The data persisted is structured as an object conforming to the `SessionStorageFormat` type below, with the `identityUrl` of the app used as the key (if no `identityUrl` is provided the `actualUrl` is used instead), with the value conforming to the `DesktopAgentDetails` type. Hence, the data might be retrieved as follows:
165173

166174
```ts
175+
const sessionData: SessionStorageFormat = sessionStorage.get("FDC3-Desktop-Agent-Details-myWindowName");
176+
const agentDetails: DesktopAgentDetails = sessionData["myApIdentityUrl"];
177+
```
178+
179+
### Type Definitions
180+
181+
```ts
182+
/** Type representing the format of data stored by `getAgent`
183+
* in Session Storage. The `identityUrl` of each app is used
184+
* as the key. */
185+
type SessionStorageFormat = {
186+
/** */
187+
[key: string]: DesktopAgentDetails
188+
}
189+
167190
/** Type representing data on the Desktop Agent that an app
168191
* connected to that is persisted by the getAgent function
169192
* to be used when re-connecting (after a navigation or
@@ -232,4 +255,8 @@ enum WebDesktopAgentType {
232255
* function that was passed by the application. */
233256
Failover = "FAILOVER"
234257
}
258+
259+
const DESKTOP_AGENT_SESSION_STORAGE_KEY_PREFIX = 'fdc3-desktop-agent-details';
260+
261+
const DEFAULT_TIMEOUT_MS = 1000;
235262
```

src/api/GetAgent.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type GetAgentType = (params?: GetAgentParams) => Promise<DesktopAgent>;
4444
*
4545
* @property {number} timeoutMs Number of milliseconds to allow for an FDC3
4646
* implementation to be found before calling the failover function or
47-
* rejecting (default 750). Note that the timeout is cancelled as soon as a
47+
* rejecting (default 1000). Note that the timeout is cancelled as soon as a
4848
* Desktop Agent is detected. There may be additional set-up steps to perform
4949
* which will happen outside the timeout.
5050
*
@@ -91,6 +91,14 @@ type GetAgentParams = {
9191
failover?: (args: GetAgentParams) => Promise<WindowProxy | DesktopAgent>;
9292
};
9393

94+
/** Type representing the format of data stored by `getAgent`
95+
* in Session Storage. The `identityUrl` of each app is used
96+
* as the key. */
97+
export type SessionStorageFormat = {
98+
/** */
99+
[key: string]: DesktopAgentDetails
100+
}
101+
94102
/** Type representing data on the Desktop Agent that an app
95103
* connected to that is persisted by the getAgent function
96104
* to be used when re-connecting (after a navigation or
@@ -159,3 +167,7 @@ export enum WebDesktopAgentType {
159167
* function that was passed by the application. */
160168
Failover = 'FAILOVER',
161169
}
170+
171+
export const DESKTOP_AGENT_SESSION_STORAGE_KEY_PREFIX = 'fdc3-desktop-agent-details';
172+
173+
export const DEFAULT_TIMEOUT_MS = 1000;

0 commit comments

Comments
 (0)