import type { DashboardConfiguration } from './DatabricksDashboard'; import type { ErrorCode } from './DatabricksDashboardError'; import type { FilterState, FilterValue } from './EmbedFilters'; /** * The postMessage protocol between the host SDK and the embedded dashboard. * * Messages fall into three groups: * - Fire-and-forget commands (config/token/navigate), which predate correlation * and expect no reply. * - Correlated request/response: a host request carries a `messageId` and the * embed echoes it on the matching response, so the SDK can resolve the right * promise. * - The ready handshake, which signals the embed has attached its listeners. * * This module is the source of truth for the protocol. The embedded app * (webapp) mirrors these shapes; keep the two in sync. */ /** * Carried by every request/response pair so the SDK can match a reply to the * promise that is waiting for it. Ids are minted and consumed entirely inside * {@link EmbedRequestChannel}. */ export interface CorrelatedMessage { messageId: string; } export interface NavigateMessage { type: 'DATABRICKS_NAVIGATE'; dashboardId: string; pageId?: string; } export interface SetTokenMessage { type: 'DATABRICKS_SET_TOKEN'; token: string; } export interface SetConfigMessage { type: 'DATABRICKS_SET_CONFIG'; config: DashboardConfiguration; } /** Discriminated union of every command the host sends without awaiting a reply. */ export type HostCommandMessage = NavigateMessage | SetTokenMessage | SetConfigMessage; export interface GetFiltersMessage extends CorrelatedMessage { type: 'DATABRICKS_GET_FILTERS'; } export interface SetFiltersMessage extends CorrelatedMessage { type: 'DATABRICKS_SET_FILTERS'; filters: FilterValue[]; apply: boolean; } export interface ApplyStagedFiltersMessage extends CorrelatedMessage { type: 'DATABRICKS_APPLY_STAGED_FILTERS'; } export interface CancelStagedFiltersMessage extends CorrelatedMessage { type: 'DATABRICKS_CANCEL_STAGED_FILTERS'; } /** Discriminated union of every correlated request the host sends to the embed. */ export type HostToEmbedMessage = GetFiltersMessage | SetFiltersMessage | ApplyStagedFiltersMessage | CancelStagedFiltersMessage; /** * A correlated request as callers express it — the `messageId` is added by * {@link EmbedRequestChannel}, so callers never mint or track one. * * Distributes over the union so each member keeps its own required fields; * a plain `Omit` would collapse them to their shared keys. */ export type HostRequestPayload = T extends CorrelatedMessage ? Omit : never; /** * Sent once the embed has attached its listeners, so the host may post correlated * requests. Filter availability is reported separately by {@link FilterControlsStatusMessage}. */ export interface EmbedReadyMessage { type: 'DATABRICKS_EMBED_READY'; } /** Successful reply to a correlated filters request. */ export interface FiltersResponseMessage extends CorrelatedMessage { type: 'DATABRICKS_FILTERS_RESPONSE'; filters: FilterState[]; } /** Generic acknowledgement for a correlated request with no payload. */ export interface AckResponseMessage extends CorrelatedMessage { type: 'DATABRICKS_ACK'; } /** * Unsolicited event pushed by the embed whenever the dashboard's filter state * changes (viewer interaction, an applied {@link SetFiltersMessage}, or a URL * restore). Not correlated — it carries no `messageId`. */ export interface FiltersChangedMessage { type: 'DATABRICKS_FILTERS_CHANGED'; filters: FilterState[]; } /** * Reports whether filter controls are usable for this dashboard through * `onFiltersReady`. * * - `available: true` once the controller mounts and can service * {@link GetFiltersMessage}/{@link SetFiltersMessage}. * - `available: false` when the feature is disabled here. */ export interface FilterControlsStatusMessage { type: 'DATABRICKS_FILTER_CONTROLS_STATUS'; available: boolean; /** Initial filter selections, captured when controls became ready. Present only when `available`. */ filters?: FilterState[]; } /** * The failure identifier on an error reply. * * Every {@link ErrorCode} the SDK models is a valid value and editors suggest * them, but any string is accepted: the embed deploys independently of this SDK * and may send a code from a newer build. Unrecognized codes degrade to * {@link ErrorCode.REQUEST_FAILED} on the host. * * The `string & {}` intersection keeps TypeScript from collapsing the union to * plain `string`, which is what preserves the suggestions. */ export type ErrorResponseCode = ErrorCode | (string & {}); /** Error reply to a correlated request. */ export interface ErrorResponseMessage extends CorrelatedMessage { type: 'DATABRICKS_ERROR'; /** Identifies the failure so the host can branch on it. */ code: ErrorResponseCode; /** * Host-safe error text. Crosses into the (third-party) embedding page, so the * embed must send a stable message keyed off {@link code}, never a raw * backend error, which could leak SQL, hostnames, or stack traces. Keep * internal detail in server-side/telemetry logs. */ message: string; } /** Discriminated union of every message the embed sends to the host. */ export type EmbedToHostMessage = EmbedReadyMessage | FiltersResponseMessage | AckResponseMessage | ErrorResponseMessage | FiltersChangedMessage | FilterControlsStatusMessage; //# sourceMappingURL=messages.d.ts.map