import type OpenFin from '@openfin/core'; import type { Awaitable } from '../../../../../common/src/utils/types'; import type { dockOFIdentity, homeOFIdentity, storefrontOFIdentity } from '../../../../../common/src/utils/window'; import type { SearchQueryWithProviderID, SearchQueryWithProviderIdentity } from '../../../../../common/src/api/home'; import type { ProviderChannelPayload, ProviderDeregisterPayload, ProviderInfoInternal, ProviderRegisterPayload, ProviderUpdatePayload } from '../../../../../common/src/api/provider'; import type { ClientAPILaunchStorefrontProviderAppRequest, LaunchStorefrontProviderAppRequest } from '../../../../../common/src/api/storefront'; import type { WorkspaceComponentSetSelectedSchemePayload } from '../../../../../common/src/api/theming'; import type { Workspace as LegacyWorkspace } from '../../../../../common/src/api/workspaces'; import type { HomeSearchListenerRequest } from '../../../../../client-api/src/home'; import type { RegisterMetaInfoInternal } from '../../../../../client-api/src/index'; import type { StorefrontFooter, StorefrontLandingPage, StorefrontNavigationSection, UpdateButtonConfigRequest } from '../../../../../client-api/src/store'; import type { App, ColorSchemeOptionType, Page } from '../../../../../client-api-platform/src/shapes'; export type WorkspaceChannelAction = keyof WorkspaceChannelTypes; /****** API Client Channel Actions ******/ /** * Channel actions, related to store, **registered** by the Workspace Platform Provider e.g. Studio. */ type StoreAPIClientChannelActions = { 'get-storefront-provider-apps': (id: string) => Promise; 'get-storefront-provider-footer': (id: string) => Promise; 'get-storefront-provider-landing-page': (id: string) => Promise; 'get-storefront-provider-navigation': (id: string) => Promise<[StorefrontNavigationSection?, StorefrontNavigationSection?, StorefrontNavigationSection?]>; 'launch-storefront-provider-app': (payload: ClientAPILaunchStorefrontProviderAppRequest) => Promise; }; /** * Channel actions, related to dock, **registered** by the Workspace Platform Provider e.g. Studio. */ type DockAPIClientChannelActions = Record; /** * Channel actions, related to home, **registered** by the Workspace Platform Provider e.g. Studio. */ type HomeAPIClientChannelActions = Record; type WorkspaceAPIClientChannelActions = StoreAPIClientChannelActions | DockAPIClientChannelActions | HomeAPIClientChannelActions; /****** End of API Client Channel Actions ******/ /****** Workspace Component Channel Actions ******/ export type WorkspaceComponentSetSelectedLanguagePayload = { locale: string; identity: OpenFin.Identity; }; /** * Channel Actions **registered** by all workspace components. */ type SharedChannelActions = { 'set-selected-scheme': (ctx: WorkspaceComponentSetSelectedSchemePayload) => Promise; 'set-selected-language': (payload: WorkspaceComponentSetSelectedLanguagePayload) => Promise; }; /** * Channel Actions **registered** by the Home workspace component. */ type HomeChannelActions = { 'assign-home-search-context': (payload: Partial) => Promise; 'open-home-and-set-search-query': (payload: SearchQueryWithProviderIdentity) => Promise; 'temporary-is-home-ready': () => Promise; }; /** * Channel Actions **registered** by the Storefront workspace component. */ type StoreChannelActions = { 'update-app-card-button-config': (payload: UpdateButtonConfigRequest & ProviderInfoInternal<'storefront'>) => Promise; }; /** * Channel Actions **registered** by the Dock workspace component. */ interface DockChannelActions { } type WorkspaceComponentChannelActions = SharedChannelActions & HomeChannelActions & StoreChannelActions & DockChannelActions; /****** End of Workspace Component Channel Actions ******/ /****** Workspace Provider Channel Actions ******/ /** * These are channel actions that can be accessed by the client API OR the workspace component. * In other words these are channel actions that are **registered** by the workspace provider. * * The handlers for these actions are defined [here](https://github.com/openfin/workspace/blob/develop/provider/src/api/protocol.ts#L32) */ type WorkspaceChannelTypes = { 'register-provider': (payload: ProviderRegisterPayload) => RegisterMetaInfoInternal; 'deregister-provider': (payload: ProviderDeregisterPayload) => Promise; 'get-providers': (payload: ProviderChannelPayload) => Promise; 'show-provider-window': (payload: ProviderChannelPayload) => Promise; 'hide-provider-window': (payload: ProviderChannelPayload) => Promise; 'update-provider': (payload: ProviderUpdatePayload) => Promise; 'get-storefront-provider-apps': (payload: ProviderInfoInternal<'storefront'>) => Promise; 'get-storefront-provider-landing-page': (payload: ProviderInfoInternal<'storefront'>) => Promise; 'get-storefront-provider-footer': (payload: ProviderInfoInternal<'storefront'>) => Promise; 'get-storefront-provider-navigation': (payload: ProviderInfoInternal<'storefront'>) => Promise>; 'launch-storefront-provider-app': (payload: LaunchStorefrontProviderAppRequest) => Promise; 'update-app-card-button-config': (payload: UpdateButtonConfigRequest & Omit, 'uniqueId'>) => Promise; 'show-home': (payload: undefined) => Promise; 'hide-home': (payload: undefined) => Promise; 'set-search-query': (payload: SearchQueryWithProviderID) => Promise; 'assign-home-search-context': (payload: Partial) => Promise; 'set-selected-scheme': (ctx: ColorSchemeOptionType) => Promise; 'initialize-theme': (themeData: { themePaletteSheet: string; selectedScheme: ColorSchemeOptionType; themePalette: { light: string; dark: string; }; }) => Promise; 'set-selected-language': (locale: string) => Promise; 'get-legacy-pages': () => Promise; 'get-legacy-workspaces': (payload: undefined) => Promise; 'register-storefront-provider': () => Promise; 'deregister-storefront-provider': () => Promise; 'hide-storefront': () => Promise; 'show-storefront': () => Promise; }; /****** End of Workspace Provider Channel Actions ******/ /** * This is a shared interface between the client API and the workspace components. * * Since all actions are dispatched to the channel provider, the `dispatch` function is the same for both the client API and the workspace components. */ interface WorkspaceChannelClientBase extends Omit { /** * Dispatches an action to the Workspace Provider. * @param action The action to dispatch * @param payload The payload to send with the action */ dispatch: (action: T, payload: Parameters[0]) => Promise>>; } /** * This is the Workspace Component Channel Client. * This is used to communicate with the workspace provider from a workspace component (home, storefront, dock). * * This extends `WorkspaceChannelClientBase`. */ export interface WorkspaceComponentChannelClient extends WorkspaceChannelClientBase { /** * Registers a handler for a channel action. * @param action * @param handler * @returns */ register: (action: T, handler: (payload: Parameters[0], id: OpenFin.ProviderIdentity | OpenFin.ClientIdentity) => Awaitable>) => boolean; } /** * This is the Client API channel client. * This is used to communicate with the Workspace Provider from the client API. (`@openfin/workspace` / `client-api`) * * This extends `WorkspaceChannelClientBase`. */ export interface WorkspaceAPIClientChannelClient extends WorkspaceChannelClientBase { /** * Registers a handler for a channel action. * This function is ONLY used from within `client-api` and should not be used by the workspace components. * * @param action The action to register a handler for. * @param handler The handler to register. */ register: (action: T, handler: (payload: Parameters[0], id: OpenFin.ProviderIdentity | OpenFin.ClientIdentity) => Awaitable>) => boolean; } export interface WorkspaceChannelProvider extends Omit { /** * Used for dispatching a channel action to a channel client * * @param to The identity of the client to send the action to. * @param action The action to send. * @param payload The payload to send with the action. */ dispatch: (to: I, action: T, payload: T extends keyof SharedChannelActions ? Parameters[0] : I['name'] extends (typeof homeOFIdentity)['name'] ? T extends keyof HomeChannelActions ? Parameters[0] : never : I['name'] extends (typeof dockOFIdentity)['name'] ? T extends keyof DockChannelActions ? Parameters[0] : never : I['name'] extends (typeof storefrontOFIdentity)['name'] ? T extends keyof StoreChannelActions ? Parameters[0] : never : T extends keyof WorkspaceAPIClientChannelActions ? Parameters[0] : never) => Promise : never : I['name'] extends (typeof dockOFIdentity)['name'] ? T extends keyof DockChannelActions ? ReturnType : never : I['name'] extends (typeof storefrontOFIdentity)['name'] ? T extends keyof StoreChannelActions ? ReturnType : never : never>>; /** * Used for registering a channel action handler for a channel client * * @param action The action to register a handler for. * @param handler The handler to register. */ register: (action: T, handler: (payload: Parameters[0], id: OpenFin.ProviderIdentity | OpenFin.ClientIdentity) => Awaitable>) => boolean; } export {};