UNPKG

@connectifi/sdk

Version:

Connectifi SDK

902 lines (876 loc) 63.4 kB
/** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ /** * Identifies an application, or instance of an application, and is used to target FDC3 API calls, such as `fdc3.open` or `fdc3.raiseIntent` at specific applications or application instances. * * Will always include at least an `appId` field, which uniquely identifies a specific app. * * If the `instanceId` field is set then the `AppMetadata` object represents a specific instance of the application that may be addressed using that Id. */ interface AppIdentifier { /** The unique application identifier located within a specific application directory instance. An example of an appId might be 'app@sub.root' */ readonly appId: string; /** An optional instance identifier, indicating that this object represents a specific instance of the application described.*/ readonly instanceId?: string; /** The Desktop Agent that the app is available on. Used in Desktop Agent Bridging to identify the Desktop Agent to target. * @experimental Introduced in FDC3 2.1 and may be refined by further changes outside the normal FDC3 versioning policy. **/ readonly desktopAgent?: string; } /** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ interface Icon { /** The icon url */ readonly src: string; /** The icon dimension, formatted as `<height>x<width>`. */ readonly size?: string; /** Icon media type. If not present the Desktop Agent may use the src file extension. */ readonly type?: string; } /** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ interface Image { /** The image url. */ readonly src: string; /** The image dimension, formatted as `<height>x<width>`. */ readonly size?: string; /** Image media type. If not present the Desktop Agent may use the src file extension. */ readonly type?: string; /** Caption for the image. */ readonly label?: string; } /** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ /** * Extends an `AppIdentifier`, describing an application or instance of an application, with additional descriptive metadata that is usually provided by an FDC3 App Directory that the desktop agent connects to. * * The additional information from an app directory can aid in rendering UI elements, such as a launcher menu or resolver UI. This includes a title, description, tooltip and icon and screenshot URLs. * * Note that as `AppMetadata` instances are also `AppIdentifiers` they may be passed to the `app` argument of `fdc3.open`, `fdc3.raiseIntent` etc. */ interface AppMetadata extends AppIdentifier { /** The 'friendly' app name. This field was used with the `open` and `raiseIntent` calls in FDC3 <2.0, which now require an `AppIdentifier` wth `appId` set. Note that for display purposes the `title` field should be used, if set, in preference to this field. */ readonly name?: string; /** The Version of the application. */ readonly version?: string; /** An optional set of, implementation specific, metadata fields that can be used to disambiguate instances, such as a window title or screen position. Must only be set if `instanceId` is set. */ readonly instanceMetadata?: { [key: string]: any; }; /** A more user-friendly application title that can be used to render UI elements */ readonly title?: string; /** A tooltip for the application that can be used to render UI elements */ readonly tooltip?: string; /** A longer, multi-paragraph description for the application that could include markup */ readonly description?: string; /** A list of icon URLs for the application that can be used to render UI elements */ readonly icons?: Array<Icon>; /** Images representing the app in common usage scenarios that can be used to render UI elements */ readonly screenshots?: Array<Image>; /** The type of output returned for any intent specified during resolution. May express a particular context type (e.g. "fdc3.instrument"), channel (e.g. "channel") or a channel that will receive a specified type (e.g. "channel<fdc3.instrument>"). */ readonly resultType?: string | null; } /** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ /** * @see https://fdc3.finos.org/docs/intents/spec#standard-intents */ type StandardIntent = 'CreateInteraction' | 'SendChatMessage' | 'StartCall' | 'StartChat' | 'StartEmail' | 'ViewAnalysis' | 'ViewChat' | 'ViewChart' | 'ViewContact' | 'ViewHoldings' | 'ViewInstrument' | 'ViewInteractions' | 'ViewMessages' | 'ViewNews' | 'ViewOrders' | 'ViewProfile' | 'ViewQuote' | 'ViewResearch'; /** * @see https://fdc3.finos.org/docs/intents/spec */ type Intent = StandardIntent | (string & {}); /** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ /** * Intent descriptor */ interface IntentMetadata { /** The unique name of the intent that can be invoked by the raiseIntent call */ readonly name: Intent; /** Display name for the intent. * @deprecated Use the intent name for display as display name may vary for * each application as it is defined in the app's AppD record. */ readonly displayName: string; } /** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ /** * An interface that relates an intent to apps */ interface AppIntent { /** Details of the intent whose relationship to resolving applications is being described. */ readonly intent: IntentMetadata; /** Details of applications that can resolve the intent. */ readonly apps: Array<AppMetadata>; } /** * The `fdc3.context` type defines the basic contract or "shape" for all data exchanged by * FDC3 operations. As such, it is not really meant to be used on its own, but is imported * by more specific type definitions (standardized or custom) to provide the structure and * properties shared by all FDC3 context data types. * * The key element of FDC3 context types is their mandatory `type` property, which is used * to identify what type of data the object represents, and what shape it has. * * The FDC3 context type, and all derived types, define the minimum set of fields a context * data object of a particular type can be expected to have, but this can always be extended * with custom fields as appropriate. */ interface Context { /** * Context data objects may include a set of equivalent key-value pairs that can be used to * help applications identify and look up the context type they receive in their own domain. * The idea behind this design is that applications can provide as many equivalent * identifiers to a target application as possible, e.g. an instrument may be represented by * an ISIN, CUSIP or Bloomberg identifier. * * Identifiers do not make sense for all types of data, so the `id` property is therefore * optional, but some derived types may choose to require at least one identifier. * Identifier values SHOULD always be of type string. */ id?: { [key: string]: any; }; /** * Context data objects may include a name property that can be used for more information, * or display purposes. Some derived types may require the name object as mandatory, * depending on use case. */ name?: string; /** * The type property is the only _required_ part of the FDC3 context data schema. The FDC3 * [API](https://fdc3.finos.org/docs/api/spec) relies on the `type` property being present * to route shared context data appropriately. * * FDC3 [Intents](https://fdc3.finos.org/docs/intents/spec) also register the context data * types they support in an FDC3 [App * Directory](https://fdc3.finos.org/docs/app-directory/overview), used for intent discovery * and routing. * * Standardized FDC3 context types have well-known `type` properties prefixed with the * `fdc3` namespace, e.g. `fdc3.instrument`. For non-standard types, e.g. those defined and * used by a particular organization, the convention is to prefix them with an * organization-specific namespace, e.g. `blackrock.fund`. * * See the [Context Data Specification](https://fdc3.finos.org/docs/context/spec) for more * information about context data types. */ type: string; [property: string]: any; } /** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ /** * Describes a callback that handles a context event. * Used when attaching listeners for context broadcasts. * * Optional metadata about the context message, including the app that originated * the message, SHOULD be provided by the desktop agent implementation. */ type ContextHandler = (context: Context, metadata?: ContextMetadata) => void; /** * Intents can return results that are either context data objects * or a reference to a Channel. */ type IntentResult = Context | Channel | void; /** * Describes a callback that handles a context event and may return a * promise of a Context, Channel object or void to be returned to the * application that raised the intent. * Used when attaching listeners for raised intents. * * Optional metadata about the raised intent, including the app that originated * the message, SHOULD be provided by the desktop agent implementation. */ type IntentHandler = (context: Context, metadata?: ContextMetadata) => Promise<IntentResult> | void; /** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ /** * A system channel will be global enough to have a presence across many apps. This gives us some hints * to render them in a standard way. It is assumed it may have other properties too, but if it has these, * this is their meaning. */ interface DisplayMetadata { /** * A user-readable name for this channel, e.g: `"Red"` */ readonly name?: string; /** * The color that should be associated within this channel when displaying this channel in a UI, e.g: `0xFF0000`. */ readonly color?: string; /** * A URL of an image that can be used to display this channel */ readonly glyph?: string; } /** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ interface Listener { /** * Unsubscribe the listener object. */ unsubscribe(): void; } /** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ /** * Represents a context channel that applications can use to send and receive * context data. * * Please note that There are differences in behavior when you interact with a * User channel via the `DesktopAgent` interface and the `Channel` interface. * Specifically, when 'joining' a User channel or adding a context listener * when already joined to a channel via the `DesktopAgent` interface, existing * context (matching the type of the context listener) on the channel is * received by the context listener immediately. Whereas, when a context * listener is added via the Channel interface, context is not received * automatically, but may be retrieved manually via the `getCurrentContext()` * function. */ interface Channel { /** * Constant that uniquely identifies this channel. */ readonly id: string; /** * Uniquely defines each channel type. * Can be "user", "app" or "private". */ readonly type: 'user' | 'app' | 'private'; /** * Channels may be visualized and selectable by users. DisplayMetadata may be used to provide hints on how to see them. * For App channels, displayMetadata would typically not be present. */ readonly displayMetadata?: DisplayMetadata; /** * Broadcasts a context on the channel. This function can be used without first joining the channel, allowing applications to broadcast on both App Channels and User Channels that they aren't a member of. * * If the broadcast is denied by the channel or the channel is not available, the promise will be rejected with an `Error` with a `message` string from the `ChannelError` enumeration. * * Channel implementations should ensure that context messages broadcast by an application on a channel should not be delivered back to that same application if they are joined to the channel. * * If you are working with complex context types composed of other simpler types (as recommended by the FDC3 Context Data specification) then you should broadcast each individual type (starting with the simpler types, followed by the complex type) that you want other apps to be able to respond to. Doing so allows applications to filter the context types they receive by adding listeners for specific context types. * * If an application attempts to broadcast an invalid context argument the Promise returned by this function should reject with the `ChannelError.MalformedContext` error. */ broadcast(context: Context): Promise<void>; /** * When a `contextType`_` is provided, the most recent context matching the type will be returned, or `null` if no matching context is found. * * If no `contextType` is provided, the most recent context that was broadcast on the channel - regardless of type - will be returned. If no context has been set on the channel, it will return `null`. * * It is up to the specific Desktop Agent implementation whether and how recent contexts are stored. For example, an implementation could store context history for a channel in a single array and search through the array for the last context matching a provided type, or context could be maintained as a dictionary keyed by context types. An implementation could also choose not to support context history, in which case this method will return `null` for any context type not matching the type of the most recent context. * * If getting the current context fails, the promise will be rejected with an `Error` with a `message` string from the `ChannelError` enumeration. */ getCurrentContext(contextType?: string): Promise<Context | null>; /** * Adds a listener for incoming contexts of the specified _context type_ whenever a broadcast happens on this channel. * * If, when this function is called, the channel already contains context that would be passed to the listener it is NOT called or passed this context automatically (this behavior differs from that of the [`fdc3.addContextListener`](DesktopAgent#addcontextlistener) function). Apps wishing to access to the current context of the channel should instead call the `getCurrentContext(contextType)` function. * * Optional metadata about each context message received, including the app that originated the message, SHOULD be provided by the desktop agent implementation. */ addContextListener(contextType: string | null, handler: ContextHandler): Promise<Listener>; /** * @deprecated use `addContextListener(null, handler)` instead of `addContextListener(handler)`. */ addContextListener(handler: ContextHandler): Promise<Listener>; } /** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ /** * IntentResolution provides a standard format for data returned upon resolving an intent. * * ```javascript * //resolve a "Chain" type intent * let resolution = await agent.raiseIntent("intentName", context); * * //resolve a "Client-Service" type intent with a data response or a Channel * let resolution = await agent.raiseIntent("intentName", context); * try { * const result = await resolution.getResult(); * if (result && result.broadcast) { * console.log(`${resolution.source} returned a channel with id ${result.id}`); * } else if (result){ * console.log(`${resolution.source} returned data: ${JSON.stringify(result)}`); * } else { * console.error(`${resolution.source} didn't return data` * } * } catch(error) { * console.error(`${resolution.source} returned an error: ${error}`); * } * * // Use metadata about the resolving app instance to target a further intent * await agent.raiseIntent("intentName", context, resolution.source); * ``` */ interface IntentResolution { /** * Identifier for the app instance that was selected (or started) to resolve the intent. * `source.instanceId` MUST be set, indicating the specific app instance that * received the intent. */ readonly source: AppIdentifier; /** * The intent that was raised. May be used to determine which intent the user * chose in response to `fdc3.raiseIntentForContext()`. */ readonly intent: Intent; /** * The version number of the Intents schema being used. */ readonly version?: string; /** * Retrieves a promise that will resolve to `Context` data returned * by the application that resolves the raised intent, a `Channel` * established and returned by the app resolving the intent or void. * * A `Channel` returned MAY be of the `PrivateChannel` type. The * client can then `addContextListener()` on that channel to, for example, * receive a stream of data. * * If an error occurs (i.e. an error is thrown by the handler function, * the promise it returns is rejected, or the promise resolved to an invalid * type) then the Desktop Agent MUST reject the promise returned by the * `getResult()` function of the `IntentResolution` with a string from * the `ResultError` enumeration, or (if connected to a Desktop Agent * Bridge) the `BridgingError` enumeration. */ getResult(): Promise<IntentResult>; } /** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ /** * Metadata relating to the FDC3 Desktop Agent implementation and its provider. */ interface ImplementationMetadata { /** The version number of the FDC3 specification that the implementation provides. * The string must be a numeric semver version, e.g. 1.2 or 1.2.1. */ readonly fdc3Version: string; /** The name of the provider of the Desktop Agent implementation (e.g. Finsemble, Glue42, OpenFin etc.). */ readonly provider: string; /** The version of the provider of the Desktop Agent implementation (e.g. 5.3.0). */ readonly providerVersion?: string; /** Metadata indicating whether the Desktop Agent implements optional features of * the Desktop Agent API. */ readonly optionalFeatures: { /** Used to indicate whether the exposure of 'originating app metadata' for * context and intent messages is supported by the Desktop Agent.*/ readonly OriginatingAppMetadata: boolean; /** Used to indicate whether the optional `fdc3.joinUserChannel`, * `fdc3.getCurrentChannel` and `fdc3.leaveCurrentChannel` are implemented by * the Desktop Agent.*/ readonly UserChannelMembershipAPIs: boolean; /** Used to indicate whether the experimental Desktop Agent Bridging * feature is implemented by the Desktop Agent.*/ readonly DesktopAgentBridging: boolean; }; /** The calling application instance's own metadata, according to the Desktop Agent (MUST include at least the `appId` and `instanceId`). */ readonly appMetadata: AppMetadata; } /** * SPDX-License-Identifier: Apache-2.0 * Copyright 2021 FINOS FDC3 contributors - see NOTICE file */ /** * Object representing a private context channel, which is intended to support * secure communication between applications, and extends the Channel interface * with event handlers which provide information on the connection state of both * parties, ensuring that desktop agents do not need to queue or retain messages * that are broadcast before a context listener is added and that applications * are able to stop broadcasting messages when the other party has disconnected. * * It is intended that Desktop Agent implementations: * - SHOULD restrict external apps from listening or publishing on this channel. * - MUST prevent private channels from being retrieved via fdc3.getOrCreateChannel. * - MUST provide the `id` value for the channel as required by the Channel interface. */ interface PrivateChannel extends Channel { /** * Adds a listener that will be called each time that the remote app invokes * addContextListener on this channel. * * Desktop Agents MUST call this for each invocation of addContextListener on this * channel, including those that occurred before this handler was registered * (to prevent race conditions). */ onAddContextListener(handler: (contextType?: string) => void): Listener; /** * Adds a listener that will be called whenever the remote app invokes * Listener.unsubscribe() on a context listener that it previously added. * * Desktop Agents MUST call this when disconnect() is called by the other party, for * each listener that they have added. */ onUnsubscribe(handler: (contextType?: string) => void): Listener; /** * Adds a listener that will be called when the remote app terminates, for example * when its window is closed or because disconnect was called. This is in addition * to calls that will be made to onUnsubscribe listeners. */ onDisconnect(handler: () => void): Listener; /** * May be called to indicate that a participant will no longer interact with this channel. * * After this function has been called, Desktop Agents SHOULD prevent apps from broadcasting * on this channel and MUST automatically call Listener.unsubscribe() for each listener that * they've added (causing any onUnsubscribe handler added by the other party to be called) * before triggering any onDisconnect handler added by the other party. */ disconnect(): void; } /** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ /** * @see https://fdc3.finos.org/docs/context/spec#standard-context-types */ type StandardContextType = 'fdc3.action' | 'fdc3.chart' | 'fdc3.chat.initSettings' | 'fdc3.chat.message' | 'fdc3.chat.room' | 'fdc3.chat.searchCriteria' | 'fdc3.contact' | 'fdc3.contactList' | 'fdc3.country' | 'fdc3.currency' | 'fdc3.email' | 'fdc3.instrument' | 'fdc3.instrumentList' | 'fdc3.interaction' | 'fdc3.message' | 'fdc3.organization' | 'fdc3.portfolio' | 'fdc3.position' | 'fdc3.nothing' | 'fdc3.timeRange' | 'fdc3.transactionResult' | 'fdc3.valuation'; /** * @see https://fdc3.finos.org/docs/context/spec#standard-context-types */ type ExperimentalContextType = 'fdc3.order' | 'fdc3.orderList' | 'fdc3.product' | 'fdc3.trade' | 'fdc3.tradeList'; /** * @see https://fdc3.finos.org/docs/context/spec */ type ContextType = StandardContextType | ExperimentalContextType | (string & {}); /** * SPDX-License-Identifier: Apache-2.0 * Copyright FINOS FDC3 contributors - see NOTICE file */ /** * A Desktop Agent is a desktop component (or aggregate of components) that serves as a * launcher and message router (broker) for applications in its domain. * * A Desktop Agent can be connected to one or more App Directories and will use directories for application * identity and discovery. Typically, a Desktop Agent will contain the proprietary logic of * a given platform, handling functionality like explicit application interop workflows where * security, consistency, and implementation requirements are proprietary. */ interface DesktopAgent { /** * Launches an app, specified via an `AppIdentifier` object. * * The `open` method differs in use from `raiseIntent`. Generally, it should be used when the target application is known but there is no specific intent. For example, if an application is querying the App Directory, `open` would be used to open an app returned in the search results. * * **Note**, if the intent, context and target app name are all known, it is recommended to instead use `raiseIntent` with the `target` argument. * * If a Context object is passed in, this object will be provided to the opened application via a contextListener. The Context argument is functionally equivalent to opening the target app with no context and broadcasting the context directly to it. * * Returns an `AppIdentifier` object with the `instanceId` field set identifying the instance of the application opened by this call. * * If an error occurs while opening the app, the promise MUST be rejected with an `Error` Object with a `message` chosen from the `OpenError` enumeration, or (if connected to a Desktop Agent Bridge) the `BridgingError` enumeration. * * ```javascript * //Open an app without context, using an AppIdentifier object to specify the target by `appId`. * let appIdentifier = {appId: 'myApp-v1.0.1'}; * let instanceIdentifier = await fdc3.open(appIdentifier); * * //Open an app with context * let instanceIdentifier = await fdc3.open(appIdentifier, context); * ``` */ open(app: AppIdentifier, context?: Context): Promise<AppIdentifier>; /** * Find out more information about a particular intent by passing its name, and optionally its context and/or a desired result context type. * * `findIntent` is effectively granting programmatic access to the Desktop Agent's resolver. * It returns a promise resolving to the intent, its metadata and metadata about the apps and app instances that registered that intent. * This can be used to raise the intent against a specific app or app instance. * * If the resolution fails, the promise MUST be rejected with an `Error` Object with a `message` chosen from the `ResolveError` enumeration, or (if connected to a Desktop Agent Bridge) the `BridgingError` enumeration. This includes the case where no apps are found that resolve the intent, when the `ResolveError.NoAppsFound` message should be used, and when an invalid context object is passed as an argument, when the `ResolveError.MalformedContext` message should be used. * * Result types may be a type name, the string "channel" (which indicates that the app * will return a channel) or a string indicating a channel that returns a specific type, * e.g. "channel<fdc3.instrument>". * * If intent resolution to an app returning a channel is requested, the desktop agent * MUST include both apps that are registered as returning a channel and those registered * as returning a channel with a specific type in the response. * * ```javascript * // I know 'StartChat' exists as a concept, and want to know which apps can resolve it ... * const appIntent = await fdc3.findIntent("StartChat"); * * // returns a single AppIntent: * // { * // intent: { name: "StartChat" }, * // apps: [ * // { appId: "Skype" }, * // { appId: "Symphony" }, * // { appId: "Slack" } * // ] * // } * * // raise the intent against a particular app * await fdc3.raiseIntent(appIntent.intent.name, context, appIntent.apps[0]); * * //later, we want to raise 'StartChat' intent again * const appIntent = await fdc3.findIntent("StartChat"); * // returns an AppIntent, but with multiple options for resolution, * // which includes an existing instance of an application: * // { * // intent: { name: "StartChat" }, * // apps: [ * // { appId: "Skype" }, * // { appId: "Symphony" }, * // { appId: "Symphony", instanceId: "93d2fe3e-a66c-41e1-b80b-246b87120859" }, * // { appId: "Slack" } * // ] * ``` * * An optional input context object and result type may be specified, which the resolver MUST use to filter the returned applications such that each supports the specified input and result types. * * ```javascript * const appIntent = await fdc3.findIntent("StartChat", contact); * * // returns only apps that support the type of the specified input context: * // { * // intent: { name: "StartChat" }, * // apps: [{ appId: "Symphony" }] * // } * * const appIntent = await fdc3.findIntent("ViewContact", contact, "fdc3.ContactList"); * * // returns only apps that return the specified result Context type: * // { * // intent: { name: "ViewContact" }, * // apps: { appId: "MyCRM", resultType: "fdc3.ContactList"}] * // } * * const appIntent = await fdc3.findIntent("QuoteStream", instrument, "channel<fdc3.Quote>"); * * // returns only apps that return a channel which will receive the specified input and result types: * // { * // intent: { name: "QuoteStream" }, * // apps: [{ appId: "MyOMS", resultType: "channel<fdc3.Quote>"}] * // } * ``` */ findIntent(intent: Intent, context?: Context, resultType?: string): Promise<AppIntent>; /** * Find all the available intents for a particular context, and optionally a desired result context type. * * `findIntentsByContext` is effectively granting programmatic access to the Desktop Agent's resolver. * It returns a promise resolving to an `AppIntent` which provides details of the intent, its metadata and metadata about the apps and app instances that are registered to handle it. This can be used to raise the intent against a specific app or app instance. * * If the resolution fails, the promise MUST be rejected with an `Error` Object with a `message` chosen from the `ResolveError` enumeration, or (if connected to a Desktop Agent Bridge) the `BridgingError` enumeration. This includes the case where no intents with associated apps are found, when the `ResolveError.NoAppsFound` message should be used, and when an invalid context object is passed as an argument, when the `ResolveError.MalformedContext` message should be used. * * The optional `resultType` argument may be a type name, the string "channel" (which indicates that the app * should return a channel) or a string indicating a channel that returns a specific type, * e.g. "channel<fdc3.instrument>". If intent resolution to an app returning a channel is requested without * a specified context type, the desktop agent MUST also include apps that are registered as returning a * channel with a specific type in the response. * * ```javascript * // I have a context object, and I want to know what I can do with it, hence, I look for intents and apps to resolve them... * const appIntents = await fdc3.findIntentsByContext(context); * * // returns for example: * // [ * // { * // intent: { name: "StartCall" }, * // apps: [{ name: "Skype" }] * // }, * // { * // intent: { name: "StartChat" }, * // apps: [ * // { appId: "Skype" }, * // { appId: "Symphony" }, * // { appId: "Symphony", instanceId: "93d2fe3e-a66c-41e1-b80b-246b87120859" }, * // { appId: "Slack" } * // ] * // } * // ]; * * // or I look for only intents that are resolved by apps returning a particular result type * const appIntentsForType = await fdc3.findIntentsByContext(context, "fdc3.ContactList"); * // returns for example: * // [{ * // intent: { name: "ViewContact" }, * // apps: [{ appId: "MyCRM", resultType: "fdc3.ContactList"}] * // }]; * * // select a particular intent to raise * const resolvedIntent = appIntents[1]; * * // target a particular app or instance * const selectedApp = resolvedIntent.apps[2]; * * // raise the intent, passing the given context, targeting the app or app instance * await fdc3.raiseIntent(startChat.intent.name, context, selectedApp); * ``` */ findIntentsByContext(context: Context, resultType?: string): Promise<Array<AppIntent>>; /** * Find all the available instances for a particular application. * * If there are no instances of the specified application the returned promise should resolve to an empty array. * * If the request fails for another reason, the promise MUST be rejected with an `Error` Object with a `message` chosen from the `ResolveError` enumeration, or (if connected to a Desktop Agent Bridge) the `BridgingError` enumeration. * * ```javascript * // Retrieve a list of instances of an application * let instances = await fdc3.findInstances({appId: "MyAppId"}); * * // Target a raised intent at a specific instance * let resolution = fdc3.raiseIntent("ViewInstrument", context, instances[0]); * ``` * @param app */ findInstances(app: AppIdentifier): Promise<Array<AppIdentifier>>; /** * Publishes context to other apps on the desktop. Calling `broadcast` at the `DesktopAgent` scope will push the context to whatever _User Channel_ the app is joined to. If the app is not currently joined to a channel, calling `fdc3.broadcast` will have no effect. Apps can still directly broadcast and listen to context on any channel via the methods on the `Channel` class. * * DesktopAgent implementations should ensure that context messages broadcast to a channel by an application joined to it should not be delivered back to that same application. * * If you are working with complex context types composed of other simpler types then you should broadcast * each individual type (starting with the simpler types, followed by the complex type) that you want other * apps to be able to respond to. Doing so allows applications to filter the context types they receive by * adding listeners for specific context types. * * If an application attempts to broadcast an invalid context argument the Promise returned by this function should reject with the `ChannelError.MalformedContext` error. * * ```javascript * const instrument = { * type: 'fdc3.instrument', * id: { * ticker: 'AAPL' * } * }; * fdc3.broadcast(context); * ``` */ broadcast(context: Context): Promise<void>; /** * Raises a specific intent for resolution against apps registered with the Desktop Agent. * * The desktop agent MUST resolve the correct app to target based on the provided intent name and context data. If multiple matching apps are found, the user MAY be presented with a Resolver UI allowing them to pick one, or another method of Resolution applied to select an app. * Alternatively, the specific app or app instance to target can also be provided. A list of valid target applications and instances can be retrieved via `findIntent`. * * If a target app for the intent cannot be found with the criteria provided or the user either closes the resolver UI or otherwise cancels resolution, the promise MUST be rejected with an `Error` object with a `message` chosen from the `ResolveError` enumeration, or (if connected to a Desktop Agent Bridge) the `BridgingError` enumeration. If a specific target `app` parameter was set, but either the app or app instance is not available, the promise MUST be rejected with an `Error` object with either the `ResolveError.TargetAppUnavailable` or `ResolveError.TargetInstanceUnavailable` string as its `message`. If an invalid context object is passed as an argument the promise MUST be rejected with an `Error` object with the `ResolveError.MalformedContext` string as its `message`. * * 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. * * Returns an `IntentResolution` object with details of the app instance that was selected (or started) to respond to the intent. * * 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. * * ```javascript * // raise an intent for resolution by the desktop agent * // a resolver UI may be displayed if more than one application can resolve the intent * await fdc3.raiseIntent("StartChat", context); * * // or find apps to resolve an intent to start a chat with a given contact * const appIntent = await fdc3.findIntent("StartChat", context); * // use the metadata of an app or app instance to describe the target app for the intent * await fdc3.raiseIntent("StartChat", context, appIntent.apps[0]); * * //Raise an intent without a context by using the null context type * await fdc3.raiseIntent("StartChat", {type: "fdc3.nothing"}); * * //Raise an intent and retrieve a result from the IntentResolution * let resolution = await agent.raiseIntent("intentName", context); * try { * const result = await resolution.getResult(); * if (result && result.broadcast) { //detect whether the result is Context or a Channel * console.log(`${resolution.source} returned a channel with id ${result.id}`); * } else if (result){ * console.log(`${resolution.source} returned data: ${JSON.stringify(result)}`); * } else { * console.error(`${resolution.source} didn't return anything` * } * } catch(error) { * console.error(`${resolution.source} returned an error: ${error}`); * } * ``` */ raiseIntent(intent: Intent, context: Context, app?: AppIdentifier): Promise<IntentResolution>; /** * Finds and raises an intent against apps registered with the desktop agent based on the type of the specified context data example. * * The desktop agent SHOULD first resolve to a specific intent based on the provided context if more than one intent is available for the specified context. This MAY be achieved by displaying a resolver UI. It SHOULD then resolve to a specific app to handle the selected intent and specified context. * Alternatively, the specific app or app instance to target can also be provided, in which case the resolver SHOULD only offer intents supported by the specified application. * * Using `raiseIntentForContext` is similar to calling `findIntentsByContext`, and then raising an intent against one of the returned apps, except in this case the desktop agent has the opportunity to provide the user with a richer selection interface where they can choose both the intent and target app. * * Returns an `IntentResolution` object, see `raiseIntent()` for details. * * If a target intent and app cannot be found with the criteria provided or the user either closes the resolver UI or otherwise cancels resolution, the promise MUST be rejected with an `Error` object with a `message` chosen from the `ResolveError` enumeration, or (if connected to a Desktop Agent Bridge) the `BridgingError` enumeration. If a specific target `app` parameter was set, but either the app or app instance is not available, the promise MUST be rejected with an `Error` object with either the `ResolveError.TargetAppUnavailable` or `ResolveError.TargetInstanceUnavailable` string as its `message`. If an invalid context object is passed as an argument the promise MUST be rejected with an `Error` object with the `ResolveError.MalformedContext` string as its `message`. * * ```javascript * // Resolve against all intents registered for the type of the specified context * await fdc3.raiseIntentForContext(context); * * // Resolve against all intents registered by a specific target app for the specified context * await fdc3.raiseIntentForContext(context, targetAppIdentifier); * ``` */ raiseIntentForContext(context: Context, app?: AppIdentifier): Promise<IntentResolution>; /** * Adds a listener for incoming intents raised by other applications, via calls to `fdc3.raiseIntent` or `fdc3.raiseIntentForContext. If the application is intended to be launched to resolve raised intents, it SHOULD add its intent listeners as quickly as possible after launch or an error MAY be returned to the caller and the intent and context may not be delivered. The exact timeout used is set by the Desktop Agent implementation, but MUST be at least 15 seconds. * * The handler function may return void or a promise that should resolve to an `IntentResult`, which is either a `Context` object, representing any data that should be returned to the app that raised the intent, a `Channel` Object, a `PrivateChannel` over which data responses will be sent, or `void`. The `IntentResult` will be returned to app that raised the intent via the `IntentResolution` and retrieved from it using the `getResult()` function. * * The Desktop Agent MUST reject the promise returned by the `getResult()` function of `IntentResolution` if: (1) the intent handling function's returned promise rejects, (2) the intent handling function doesn't return a promise, or (3) the returned promise resolves to an invalid type. * * The `PrivateChannel` type is provided to support synchronization of data transmitted over returned channels, by allowing both parties to listen for events denoting subscription and unsubscription from the returned channel. `PrivateChannels` are only retrievable via raising an intent. * * Optional metadata about the raised intent, including the app that originated the message, SHOULD be provided by the desktop agent implementation. * * ```javascript * //Handle a raised intent * const listener = fdc3.addIntentListener('StartChat', context => { * // start chat has been requested by another application * return; * }); * * //Handle a raised intent and log the originating app metadata * const listener = fdc3.addIntentListener('StartChat', (contact, metadata) => { * console.log(`Received intent StartChat\nContext: ${contact}\nOriginating app: ${metadata?.source}`); * return; * }); * * //Handle a raised intent and return Context data via a promise * fdc3.addIntentListener("CreateOrder", (context) => { * return new Promise<Context>((resolve) => { * // go create the order * resolve({type: "fdc3.order", id: { "orderId": 1234}}); * }); * }); * * //Handle a raised intent and return a Private Channel over which response will be sent * fdc3.addIntentListener("QuoteStream", async (context) => { * const channel: PrivateChannel = await fdc3.createPrivateChannel(); * const symbol = context.id.symbol; * * // Called when the remote side adds a context listener * const addContextListener = channel.onAddContextListener((contextType) => { * // broadcast price quotes as they come in from our quote feed * feed.onQuote(symbol, (price) => { * channel.broadcast({ type: "price", price}); * }); * }); * * // Stop the feed if the remote side closes * const disconnectListener = channel.onDisconnect(() => { * feed.stop(symbol); * }); * * return channel; * }); * ``` */ addIntentListener(intent: Intent, handler: IntentHandler): Promise<Listener>; /** * 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. * * Context broadcasts are primarily received from apps that are joined to the same User Channel as the listening application, hence, if the application is not currently joined to a User Channel no broadcasts will be received from channels. If this function is called after the app has already joined a channel and the channel already contains context that would be passed to the context listener, then it will be called immediately with that context. * * Context may also be received via this listener if the application was launched via a call to `fdc3.open`, where context was passed as an argument. In order to receive this, applications SHOULD add their context listener as quickly as possible after launch, or an error MAY be returned to the caller and the context may not be delivered. The exact timeout used is set by the Desktop Agent implementation, but MUST be at least 15 seconds. * * Optional metadata about the context message, including the app that originated the message, SHOULD be provided by the desktop agent implementation. * * ```javascript * // any context * const listener = await fdc3.addContextListener(null, context => { ... }); * * // listener for a specific type * const contactListener = await fdc3.addContextListener('fdc3.contact', contact => { ... }); * * // listener that logs metadata for the message a specific type * const contactListener = await fdc3.addContextListener('fdc3.contact', (contact, metadata) => { * console.log(`Received context message\nContext: ${contact}\nOriginating app: ${metadata?.source}`); * //do something else with the context * }); * ``` */ addContextListener(contextType: ContextType | null, handler: ContextHandler): Promise<Listener>; /** * Retrieves a list of the User channels available for the app to join. */ getUserChannels(): Promise<Array<Channel>>; /** * Optional function that joins the app to the specified User channel. In most cases, applications SHOULD be joined to channels via UX provided to the application by the desktop agent, rather than calling this function directly. * * If an app is joined to a channel, all `fdc3.broadcast` calls will go to the channel, and all listeners assigned via `fdc3.addContextListener` will listen on the channel. * * If the channel already contains context that would be passed to context listeners added via `fdc3.addContextListener` then those listeners will be called immediately with that context. * * An app can only be joined to one channel at a time. * * If an error occurs (such as the channel is unavailable or the join request is denied) the promise MUST be rejected with an `Error` Object with a `message` chosen from the `ChannelError` enumeration. * * ```javascript * // get all system channels * const channels = await fdc3.getUserChannels(); * // create UI to pick from the User channels * // join the channel on selection * fdc3.joinUserChannel(selectedChannel.id); * ``` */ joinUserChannel(channelId: string): Promise<void>; /** * Returns a `Channel` object for the specified channel, creating it (as an _App_ channel) if it does not exist. * * If the Channel cannot be created or access was denied, the returned promise MUST be rejected with an `Error` Object with a `message` chosen from the `ChannelError` enumeration. * * ```javascript * try { * const myChannel = await fdc3.getOrCreateChannel("myChannel"); * const myChannel.addContextListener(null, context => {}); * } * catch (err){ * //app could not register the channel * } * ``` */ getOrCreateChannel(channelId: string): Promise<Channel>; /** * Returns a `Channel` with an auto-generated identity that is intended for private communication between applications. Primarily used to create Channels that will be returned to other applications via an `IntentResolution` for a raised intent. * * If the `PrivateChannel` cannot be created, the returned promise MUST be rejected with an `Error` object with a `message` chosen from the `ChannelError` enumeration. * * The `PrivateChannel` type is provided to support synchronization of data transmitted over returned channels, by allowing both parties to listen for events denoting subscription and unsubscription from the returned channel. `PrivateChannels` are only retrievable via raising an intent. * * * It is intended that Desktop Agent implementations: * - SHOULD restrict external apps from listening or publishing on this channel. * - MUST prevent `PrivateChannels` from being retrieved via fdc3.getOrCreateChannel. * - MUST provide the `id` value for the channel as requir