/** * postMessage transport — routes HTTP requests through the parent window * via postMessage instead of calling the API directly. * * Used when the SDK runs inside a sandboxed iframe (sandbox="allow-scripts") * that cannot make direct API calls. The parent receives fetch requests, * executes them with its own session cookies, and sends the raw API * response back. All query logic (field qualification, polling, result * mapping) stays in the SDK's apiTransport. */ import type { ExternalFetchMethod, ExternalFetchResult, Transport } from './types'; export type SdkFetchRequest = { type: 'lightdash:sdk:fetch'; id: string; method: string; path: string; body?: unknown; /** Transport metadata for dev tools (not sent to the API) */ metadata?: Record; }; export type SdkFetchResponse = { type: 'lightdash:sdk:fetch-response'; id: string; result?: unknown; error?: string; }; export type SdkReadyMessage = { type: 'lightdash:sdk:ready'; /** True when the host is capturing this render for a scheduled delivery * or its preview. Absent (never `false`) on ordinary interactive loads — * see `deliveryRender.ts`'s `useDeliveryRender()`. */ deliveryRender?: boolean; }; export type SdkScreenshotRequest = { type: 'lightdash:sdk:screenshot-request'; id: string; }; export type SdkScreenshotResponse = { type: 'lightdash:sdk:screenshot-response'; id: string; /** PNG blob rasterized inside the iframe. Absent when `error` is set. */ blob?: Blob; error?: string; }; /** * Announced by the iframe SDK on mount so the parent can detect that * screenshot capture is wired up. Older templates running in resumed * sandboxes don't send this, so the parent leaves the Screenshot button * hidden for them — mirrors the inspector availability handshake. */ export type SdkScreenshotAvailableMessage = { type: 'lightdash:sdk:screenshot-available'; }; export type SdkGsheetExportColumnType = 'string' | 'number' | 'date' | 'timestamp' | 'boolean'; export type SdkGsheetExportColumn = { key: string; label?: string; type?: SdkGsheetExportColumnType; }; export type SdkGsheetExportRow = Record; /** * Iframe → parent. The parent host (useAppSdkBridge) runs the Google OAuth * popup if needed, POSTs to /api/v1/gdrive/upload-gsheet-from-rows, polls * the resulting job, and posts back an SdkGsheetExportResponse. * * Capability-gated on the parent side: hosts that don't opt in respond with * an error message. */ export type SdkGsheetExportRequest = { type: 'lightdash:sdk:gsheet-export-request'; id: string; title: string; columns: SdkGsheetExportColumn[]; rows: SdkGsheetExportRow[]; }; export type SdkGsheetExportResponse = { type: 'lightdash:sdk:gsheet-export-response'; id: string; fileUrl?: string; error?: string; }; export type SdkExternalFetchRequest = { type: 'lightdash:sdk:external-fetch'; id: string; alias: string; method?: ExternalFetchMethod; path: string; query?: Record; body?: unknown; }; export type SdkExternalFetchResponse = { type: 'lightdash:sdk:external-fetch-response'; id: string; result?: ExternalFetchResult; error?: string; }; /** * `crypto.randomUUID` is secure-context only, so it's missing when the app is * served over plain http. Ids only need to be unique within one page session. */ export declare const createRequestId: () => string; type PostMessageTransportConfig = { targetWindow: Window; projectUuid: string; timeoutMs?: number; }; /** * Creates a Transport that routes all API calls through the parent window * via postMessage. The parent acts as a fetch proxy using session cookies. * * All query logic (field qualification, polling, result mapping) is handled * by the SDK's apiTransport — the postMessage layer is just the HTTP adapter. */ export declare function createPostMessageTransport(config: PostMessageTransportConfig): Transport; export {};