@lightdash/query-sdk 0.3486.1 → 0.3487.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Static registry of SDK capabilities, reported to the Lightdash host via the
3
+ * `lightdash:sdk:manifest` message so the host can detect apps built on an
4
+ * older SDK and offer an upgrade.
5
+ *
6
+ * Adding an SDK capability requires an entry here — features.test.ts fails if
7
+ * a `lightdash:*:available` message exists without a matching key. Keys are
8
+ * stable identifiers; label/description feed the host's "What's new" UI.
9
+ */
10
+ export type SdkFeature = {
11
+ key: string;
12
+ label: string;
13
+ description: string;
14
+ /** Agent-facing note on the app-code wiring the feature needs before the
15
+ * host can use it (absent = zero wiring; it activates automatically once
16
+ * the bundle runs on a current SDK). Never rendered in user-facing UI. */
17
+ wiring?: string;
18
+ };
19
+ export declare const SDK_FEATURES: SdkFeature[];
20
+ export declare const SDK_FEATURE_KEYS: string[];
21
+ export declare const SDK_MANIFEST_MESSAGE_TYPE = "lightdash:sdk:manifest";
22
+ /**
23
+ * Sent from the app iframe to the Lightdash host: once when the postMessage
24
+ * transport is created, and again each time the host announces
25
+ * `lightdash:sdk:ready` (covers either side mounting first).
26
+ */
27
+ export type SdkManifestMessage = {
28
+ type: typeof SDK_MANIFEST_MESSAGE_TYPE;
29
+ sdkVersion: string;
30
+ features: string[];
31
+ };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Static registry of SDK capabilities, reported to the Lightdash host via the
3
+ * `lightdash:sdk:manifest` message so the host can detect apps built on an
4
+ * older SDK and offer an upgrade.
5
+ *
6
+ * Adding an SDK capability requires an entry here — features.test.ts fails if
7
+ * a `lightdash:*:available` message exists without a matching key. Keys are
8
+ * stable identifiers; label/description feed the host's "What's new" UI.
9
+ */
10
+ export const SDK_FEATURES = [
11
+ {
12
+ key: 'query',
13
+ label: 'Semantic layer queries',
14
+ description: 'Run metric and dimension queries against the Lightdash semantic layer.',
15
+ },
16
+ {
17
+ key: 'saved-chart',
18
+ label: 'Saved chart queries',
19
+ description: 'Fetch results from existing saved charts instead of ad-hoc queries.',
20
+ },
21
+ {
22
+ key: 'drill-down',
23
+ label: 'Drill-down helper',
24
+ description: 'Derive drill-down queries from a clicked result row to build explore-style interactions.',
25
+ },
26
+ {
27
+ key: 'inspect',
28
+ label: 'Element inspection',
29
+ description: 'Lets the Lightdash editor highlight and select app elements to reference them in prompts.',
30
+ },
31
+ {
32
+ key: 'lineage',
33
+ label: 'Inspect data',
34
+ description: 'Click any chart to trace it back to the query and fields behind it, from the Inspect data button in the editor.',
35
+ wiring: "Spread the `lineage` props returned by useLightdash onto each query-bound block's root element; without these stamps the host's Inspect data button stays disabled.",
36
+ },
37
+ {
38
+ key: 'screenshot',
39
+ label: 'In-app screenshots',
40
+ description: 'Lets the host rasterize the app to an image for thumbnails and scheduled deliveries.',
41
+ },
42
+ {
43
+ key: 'external-fetch',
44
+ label: 'External data fetch',
45
+ description: 'Fetch approved external HTTP data sources through the Lightdash proxy.',
46
+ },
47
+ {
48
+ key: 'gsheet-export',
49
+ label: 'Google Sheets export',
50
+ description: 'Export tabular results from the app straight to Google Sheets.',
51
+ },
52
+ {
53
+ key: 'url-state',
54
+ label: 'Shareable URL state',
55
+ description: 'Sync in-app state to the page URL so app views can be shared and restored.',
56
+ },
57
+ {
58
+ key: 'viz-context',
59
+ label: 'Dashboard visualization context',
60
+ description: 'Receive query context when app visualizations are embedded in dashboards.',
61
+ },
62
+ ];
63
+ export const SDK_FEATURE_KEYS = SDK_FEATURES.map((f) => f.key);
64
+ export const SDK_MANIFEST_MESSAGE_TYPE = 'lightdash:sdk:manifest';
@@ -0,0 +1 @@
1
+ export declare const SDK_VERSION = "0.3487.0";
@@ -0,0 +1,2 @@
1
+ // Generated by scripts/generateSdkVersion.mjs (prebuild) — do not edit.
2
+ export const SDK_VERSION = '0.3487.0';
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export { useLightdash } from './useLightdash';
6
6
  export { LightdashProvider, useLightdashClient } from './LightdashProvider';
7
7
  export { createApiTransport, type FetchAdapter } from './apiTransport';
8
8
  export { createPostMessageTransport } from './postMessageTransport';
9
+ export { SDK_FEATURES, SDK_FEATURE_KEYS, SDK_MANIFEST_MESSAGE_TYPE, type SdkFeature, type SdkManifestMessage, } from './features';
9
10
  export type { AdditionalMetric, Column, CustomDimension, DownloadResultsFileType, DownloadResultsLimit, DownloadResultsOptions, DownloadResultsResult, DownloadResultsValues, DownloadUnderlyingDataOptions, ExternalFetchMethod, ExternalFetchOptions, ExternalFetchResult, Filter, FilterOperator, FilterValue, FormatFunction, LightdashClientConfig, LightdashUser, MetricType, QueryDefinition, QueryResult, Row, Sort, TableCalculation, Transport, UnitOfTime, UnderlyingDataOptions, UnderlyingDataResult, } from './types';
10
11
  export type { SdkExternalFetchRequest, SdkExternalFetchResponse, SdkFetchRequest, SdkFetchResponse, SdkReadyMessage, SdkScreenshotAvailableMessage, SdkScreenshotRequest, SdkScreenshotResponse, SdkGsheetExportRequest, SdkGsheetExportResponse, SdkGsheetExportColumn, SdkGsheetExportColumnType, SdkGsheetExportRow, } from './postMessageTransport';
11
12
  export type { InspectAvailableMessage, InspectSelectedMessage, } from './inspector';
package/dist/index.js CHANGED
@@ -12,6 +12,8 @@ export { LightdashProvider, useLightdashClient } from './LightdashProvider';
12
12
  // Transports
13
13
  export { createApiTransport } from './apiTransport';
14
14
  export { createPostMessageTransport } from './postMessageTransport';
15
+ // Feature manifest (also exported via the "./features" subpath for hosts)
16
+ export { SDK_FEATURES, SDK_FEATURE_KEYS, SDK_MANIFEST_MESSAGE_TYPE, } from './features';
15
17
  // Google Sheets export (data apps)
16
18
  export { exportToSheets } from './exportToSheets';
17
19
  // Data app viz render context (host-pushed rows + field mapping)
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Announce this bundle's SDK capabilities to the host: immediately, and again
3
+ * whenever the host posts `lightdash:sdk:ready` — whichever side mounts first,
4
+ * the host ends up with a manifest. The host dedupes repeats.
5
+ *
6
+ * One listener per bundle: the manifest is module-constant, so re-creating the
7
+ * transport re-posts instead of stacking duplicate listeners. Returns a
8
+ * cleanup that unregisters the listener.
9
+ */
10
+ export declare function announceSdkManifest(targetWindow: Window): () => void;
@@ -0,0 +1,43 @@
1
+ import { SDK_FEATURE_KEYS, SDK_MANIFEST_MESSAGE_TYPE, } from './features';
2
+ import { SDK_VERSION } from './generated/sdkVersion';
3
+ let activeCleanup = null;
4
+ /**
5
+ * Announce this bundle's SDK capabilities to the host: immediately, and again
6
+ * whenever the host posts `lightdash:sdk:ready` — whichever side mounts first,
7
+ * the host ends up with a manifest. The host dedupes repeats.
8
+ *
9
+ * One listener per bundle: the manifest is module-constant, so re-creating the
10
+ * transport re-posts instead of stacking duplicate listeners. Returns a
11
+ * cleanup that unregisters the listener.
12
+ */
13
+ export function announceSdkManifest(targetWindow) {
14
+ if (typeof window === 'undefined')
15
+ return () => { };
16
+ const message = {
17
+ type: SDK_MANIFEST_MESSAGE_TYPE,
18
+ sdkVersion: SDK_VERSION,
19
+ features: SDK_FEATURE_KEYS,
20
+ };
21
+ // Bundles are served from the host page's own origin, and location.origin
22
+ // is URL-derived so it survives the sandboxed (opaque-origin) iframe.
23
+ const { origin } = window.location;
24
+ const targetOrigin = origin && origin !== 'null' ? origin : '*';
25
+ const post = () => targetWindow.postMessage(message, targetOrigin);
26
+ activeCleanup?.();
27
+ const handler = (event) => {
28
+ if (event.source !== targetWindow)
29
+ return;
30
+ const type = event.data?.type;
31
+ if (type === 'lightdash:sdk:ready')
32
+ post();
33
+ };
34
+ window.addEventListener('message', handler);
35
+ const cleanup = () => {
36
+ window.removeEventListener('message', handler);
37
+ if (activeCleanup === cleanup)
38
+ activeCleanup = null;
39
+ };
40
+ activeCleanup = cleanup;
41
+ post();
42
+ return cleanup;
43
+ }
@@ -9,6 +9,7 @@
9
9
  * mapping) stays in the SDK's apiTransport.
10
10
  */
11
11
  import { createApiTransport } from './apiTransport';
12
+ import { announceSdkManifest } from './manifest';
12
13
  const DEFAULT_TIMEOUT_MS = 120000;
13
14
  const READY_TIMEOUT_MS = 10000;
14
15
  /**
@@ -162,6 +163,8 @@ function createPostMessageExternalFetch(config) {
162
163
  * by the SDK's apiTransport — the postMessage layer is just the HTTP adapter.
163
164
  */
164
165
  export function createPostMessageTransport(config) {
166
+ // Report this bundle's SDK capabilities so the host can offer upgrades.
167
+ announceSdkManifest(config.targetWindow);
165
168
  const adapter = createPostMessageFetchAdapter({
166
169
  targetWindow: config.targetWindow,
167
170
  timeoutMs: config.timeoutMs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/query-sdk",
3
- "version": "0.3486.1",
3
+ "version": "0.3487.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "SDK for building custom data apps against the Lightdash semantic layer",
@@ -19,12 +19,17 @@
19
19
  ".": {
20
20
  "types": "./dist/index.d.ts",
21
21
  "import": "./dist/index.js"
22
+ },
23
+ "./features": {
24
+ "types": "./dist/features.d.ts",
25
+ "import": "./dist/features.js"
22
26
  }
23
27
  },
24
28
  "peerDependencies": {
25
29
  "react": "^18.x || ^19.x"
26
30
  },
27
31
  "devDependencies": {
32
+ "@types/node": "22.13.1",
28
33
  "@types/react": "19.2.2",
29
34
  "jsdom": "26.1.0",
30
35
  "typescript": "npm:@typescript/typescript6@6.0.1",
@@ -32,11 +37,13 @@
32
37
  "vitest": "4.1.6"
33
38
  },
34
39
  "scripts": {
40
+ "prebuild": "node ./scripts/generateSdkVersion.mjs",
35
41
  "build": "tsc6 --project tsconfig.build.json",
36
42
  "build:fast": "tsc --project tsconfig.build.fast.json",
37
43
  "typecheck": "tsc6 --noEmit",
38
44
  "typecheck:fast": "tsc --project tsconfig.fast.json --noEmit",
39
45
  "lint": "eslint src/",
46
+ "pretest": "node ./scripts/generateSdkVersion.mjs",
40
47
  "test": "vitest run",
41
48
  "format": "oxfmt ./src --check",
42
49
  "fix-format": "oxfmt ./src",