import type { FilterState, FilterValue, SetFiltersOptions } from './EmbedFilters'; type DashboardColorScheme = 'light' | 'dark' | 'light dark'; /** * Controls the global filters panel in an embedded dashboard. * * - **`hiddenByDefault`:** the panel starts collapsed. Viewers can still open it. * - **`shownByDefault`:** the panel starts expanded. Viewers can still collapse it. * - **`disabled`:** the panel and its toggle button are hidden entirely. Viewers cannot open * or change the global filters. This only hides the controls. Filter values from the embed URL * or the dashboard's author-configured defaults still apply. * - **Omitted:** the dashboard's own default behavior is used. * * The `hiddenByDefault` / `shownByDefault` states set the initial visibility only. Viewers can * toggle the panel afterwards and their saved preference takes precedence on later visits. */ export type GlobalFilterVisibility = 'hiddenByDefault' | 'shownByDefault' | 'disabled'; export interface DashboardConfiguration { version: number; /** * Hides the refresh button in the dashboard. * * @deprecated This property is not currently available while we take time to conduct additional * testing and analyze additional scenarios. */ hideRefreshButton?: boolean; /** * When true, hides the "Powered by Databricks" logo in the embedded dashboard footer. */ hideDatabricksLogo?: boolean; /** * Controls the embedded dashboard's global filters panel. Omit for the dashboard's default * behavior. See {@link GlobalFilterVisibility}. */ globalFilterVisibility?: GlobalFilterVisibility; } export interface NavigateOptions { /** * The ID of the dashboard to navigate to. * * @example 'abcdedf123456' */ dashboardId: string; /** * The ID of the page to navigate to. If not provided, navigates to the first page. * * @example 'ab12cd34' */ pageId?: string; } export interface DatabricksDashboardOptions { /** * The workspace ID where the dashboard is located. * * @example 1234567890123456 */ workspaceId: string; /** * The instance URL of the Databricks workspace or the custom URL of the Databricks account. * * @example https://my-databricks-instance */ instanceUrl: string; /** * The container element to render the dashboard in. */ container: HTMLElement; /** * The ID of the dashboard to render. * * @example https://my-databricks-instance/dashboardsv3//published */ dashboardId: string; /** * The id of the page to render. Defaults to the first page. * * @example https://my-databricks-instance/dashboardsv3//published/pages/ */ pageId?: string; /** * The token generated by Databricks. * * ⚠️ CAUTION: This token is accessible by viewers of this page. Please * consider: * - **Restrict the scope of the token appropriately.** Follow Databricks documentation * to ensure the scope shared in the browser only allows access to the * current dashboard. */ token: string | undefined; /** * Utility function that sets a new token for the dashboard. * Use this to maintain access to long-running dashboards without interrupting the user experience. * * @returns A new token generated by Databricks. */ getNewToken?: () => Promise; /** * Specifies the color scheme for the embedded dashboard. * * - "light": Forces light mode * - "dark": Forces dark mode * - "light dark": Allows the dashboard to automatically match the user's system/browser preference * * This value maps to the CSS `color-scheme` property: * https://developer.mozilla.org/en-US/docs/Web/CSS/color-scheme */ colorScheme?: DashboardColorScheme; /** * Configuration properties for the dashboard instance to be embedded. */ config?: DashboardConfiguration; } /** * Payload delivered to an {@link DatabricksDashboard.onFiltersReady} subscriber * when the embed's filter controls become available. */ export interface FiltersReadyEvent { /** The dashboard's filter selections at the moment controls became ready. */ filters: FilterState[]; } /** * A Databricks dashboard that can be embedded in a web page. * @example * ```typescript * const dashboard = new DatabricksDashboard({ * workspaceId: "1234567890123456", * instanceUrl: "https://my-databricks-instance.com", * container: document.getElementById("dashboard-container"), * dashboardId: "abcdedf123456", * pageId: "ab12cd34", * token: tokenThatCanBeSeenByViewers, * getNewToken: getNewTokenFunction, // Retrieve a new token from your server. * config: { * version: 1, * hideRefreshButton: true, // Hide the refresh button in the dashboard. * hideDatabricksLogo: true, // Hide the "Powered by Databricks" logo. * globalFilterVisibility: 'shownByDefault', // Global filters panel starts expanded. * }, * }).initialize(); * ``` */ export declare class DatabricksDashboard { readonly container: HTMLElement; readonly dashboardId: string; readonly instanceUrl: string; readonly workspaceId: string; readonly pageId: string | undefined; private getNewToken; private iframe; private isDestroyed; private refreshTimeoutId; private initialToken; private config; private isIframeLoaded; private iframeLoadedPromiseResolver; private isIframeLoadedPromise; private colorScheme; private requestChannel; private filtersChangedListeners; private filtersReadyListeners; private filtersReadyState; private filtersReadySnapshot; constructor({ workspaceId, instanceUrl, container, dashboardId, pageId, token, getNewToken, colorScheme, config, }: DatabricksDashboardOptions); initialize(): void; destroy(): void; /** * Navigate to a different dashboard or page within the embedded iframe without reloading. * This provides a smooth transition between dashboards. * * @param options - Navigation options including dashboardId and optional pageId * @throws {DatabricksDashboardError} If the instance is destroyed or iframe is not loaded * * @example * ```typescript * // Navigate to a different dashboard * dashboard.navigate({ dashboardId: 'xyz789' }); * * // Navigate to a specific page in a dashboard * dashboard.navigate({ dashboardId: 'xyz789', pageId: 'page123' }); * ``` */ navigate(options: NavigateOptions): Promise; /** * Read the current state of every filter in the embedded dashboard. * * @throws {DatabricksDashboardError} `REQUEST_TIMED_OUT` if the embedded dashboard does not respond. * * @example * ```typescript * const filters = await dashboard.getFilters(); * * const filtersById = Object.fromEntries(filters.map((f) => [f.id, f])); * const regionFilter = filtersById['sales~region']; * * const filtersByPage = Object.groupBy(filters, (f) => f.id.split('~')[0]); * const salesFilters = filtersByPage['sales']; * ``` */ getFilters(): Promise; /** * Set one or more filter values in the embedded dashboard. * * @param filters - The filter values to apply, each targeting a filter by its * {@link FilterState.id ID}. * @param options - See {@link SetFiltersOptions}. * @throws {DatabricksDashboardError} `INVALID_REQUEST` if the dashboard rejects the * values (e.g. an unknown filter ID or a type mismatch), `REQUEST_TIMED_OUT` on no * response, or `REQUEST_FAILED` on an internal error. * * @example * ```typescript * await dashboard.setFilters([{ id: 'sales~region', type: 'single-select', value: 'US' }]); * ``` */ setFilters(filters: FilterValue[], options?: SetFiltersOptions): Promise; /** * Commit every staged filter value, as the dashboard's "Apply" button does. * Values are staged via {@link setFilters} with `{ apply: false }`. A no-op when * the dashboard is not in apply mode. * * @throws {DatabricksDashboardError} `REQUEST_TIMED_OUT` if the embedded dashboard does not respond. */ applyStagedFilters(): Promise; /** * Discard every staged filter value, reverting to the committed values, as the * dashboard's "Cancel" button does. A no-op when the dashboard is not in apply mode. * * @throws {DatabricksDashboardError} `REQUEST_TIMED_OUT` if the embedded dashboard does not respond. */ cancelStagedFilters(): Promise; /** * Subscribe to filter changes in embedded dashboards. The callback fires whenever a filter's * value changes (from viewer interaction, an applied {@link setFilters} call, or a URL restore) * with a snapshot of every filter's current state. It does not fire on subscribe. * Call {@link getFilters} or use {@link onFiltersReady} for the initial state. * * @param callback - Invoked with the latest {@link FilterState} snapshot on * each change. * @returns A function that removes the subscription. * * @example * ```typescript * const unsubscribe = dashboard.onFiltersChanged((filters) => { * console.log('filters changed', filters); * }); * // later: unsubscribe(); * ``` */ onFiltersChanged(callback: (filters: FilterState[]) => void): () => void; /** * Fires at most once, when the embed's filter controls become available, with the initial * {@link FilterState} snapshot. Late subscribers still fire on the next task. It never fires if * controls are unavailable or the embed never becomes ready. * * This isn't necessary to call the filter APIs (early calls are buffered by the embed), but it * allows gating the host UI on readiness. * * @param callback - Receives the {@link FiltersReadyEvent} when controls are ready. * @returns A function that removes the subscription. * * @example * ```typescript * const unsubscribe = dashboard.onFiltersReady(({ filters }) => { * renderFilterControls(filters); * }); * ``` */ onFiltersReady(callback: (event: FiltersReadyEvent) => void): () => void; /** * Fans a filters-changed snapshot out to every subscriber. Iterates a copy so a * listener that subscribes/unsubscribes during dispatch is safe, and isolates * each callback so one throwing host consumer can't starve the others. A thrown * error is re-raised on a fresh task so it reaches the host's global error * handler without aborting the remaining listeners. */ private notifyFiltersChanged; /** Snapshots the ready filter selections into a subscriber payload. */ private buildFiltersReadyEvent; /** * Fires the one-shot filters-ready listeners with the resolved status, then * clears them. Isolates each callback like {@link notifyFiltersChanged} so one * throwing consumer can't starve the others. */ private notifyFiltersReady; /** * Posts a typed message to the embedded iframe, targeting the instance origin. */ private postToEmbed; /** * Waits for the ready handshake before posting a correlated request, so it * reaches a listening embed rather than racing iframe load. Whether the embed * can service the request is answered by its own reply (`NOT_SUPPORTED` when * filter controls are disabled). The wait is bounded by {@link awaitHandshake}, * which rejects with `REQUEST_TIMED_OUT` if the handshake never arrives. */ private awaitReadyToSend; /** * Resolves once the embed's ready handshake arrives, or rejects with * `REQUEST_TIMED_OUT` if it does not within {@link HANDSHAKE_TIMEOUT_MS}. */ private awaitHandshake; private initializeIframe; private initializeRefreshTokenTimer; private initializeConfig; /** * Sends a fire-and-forget command to the embed, targeted at its exact origin * so no other frame can receive it. */ private postCommand; private displayError; private handleMessages; /** * Validates and migrates the configuration to the latest version. Provides sensible defaults where possible. * * @param config - The configuration to migrate. * @returns The migrated configuration, or throws an error if the configuration is invalid. */ private migrateConfig; } export {}; //# sourceMappingURL=DatabricksDashboard.d.ts.map