@querypanel/node-sdk 1.2.2 → 1.2.3

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.
package/README.md CHANGED
@@ -93,6 +93,31 @@ const response = await qp.ask("Revenue by product", {
93
93
  });
94
94
  ```
95
95
 
96
+ ### Restricting VizSpec chart types
97
+
98
+ If your UI only supports a subset of VizSpec chart kinds (for example no area or scatter), set **`supportedChartTypes`** on the SDK constructor or on each `ask` / `modifyChart` call. The API’s `/vizspec` step then steers generation toward allowed types only (`line`, `bar`, `column`, `area`, `scatter`, `pie`). This applies whenever you use **`chartType: "vizspec"`** (including the default v2 flow after SQL runs).
99
+
100
+ ```ts
101
+ import { QueryPanelSdkAPI, ALL_VIZ_CHART_TYPES, type ChartType } from "@querypanel/sdk";
102
+
103
+ const allowed: ChartType[] = ["line", "bar", "column", "pie"];
104
+
105
+ const qp = new QueryPanelSdkAPI(url, privateKey, workspaceId, {
106
+ supportedChartTypes: allowed,
107
+ });
108
+
109
+ // Or per request:
110
+ await qp.ask("Revenue by month", {
111
+ tenantId: "t1",
112
+ database: "analytics",
113
+ chartType: "vizspec",
114
+ pipeline: "v2",
115
+ supportedChartTypes: allowed,
116
+ });
117
+ ```
118
+
119
+ Use `ALL_VIZ_CHART_TYPES` when you need the full list (for example to derive `allowed` with `.filter(...)`).
120
+
96
121
  ## Session History & Context-Aware Queries
97
122
 
98
123
  The SDK can link related questions into a session so follow-ups like “filter that to Europe” use prior context. The backend generates a QueryPanel session ID for every query and returns it in the response so you can reuse it.
package/dist/index.cjs CHANGED
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ ALL_VIZ_CHART_TYPES: () => ALL_VIZ_CHART_TYPES,
33
34
  BigQueryAdapter: () => BigQueryAdapter,
34
35
  CallbackApiClient: () => CallbackApiClient,
35
36
  ClickHouseAdapter: () => ClickHouseAdapter,
@@ -1819,7 +1820,10 @@ async function ask(client, queryEngine, question, options, signal) {
1819
1820
  fields: execution.fields,
1820
1821
  rows: anonymizeResults(rows),
1821
1822
  max_retries: options.chartMaxRetries ?? 3,
1822
- query_id: queryResponse.data.queryId
1823
+ query_id: queryResponse.data.queryId,
1824
+ ...options.supportedChartTypes?.length ? {
1825
+ supported_chart_types: options.supportedChartTypes
1826
+ } : {}
1823
1827
  },
1824
1828
  tenantId,
1825
1829
  options.userId,
@@ -2160,7 +2164,8 @@ async function modifyChart(client, queryEngine, input, options, signal) {
2160
2164
  max_retries: options?.chartMaxRetries ?? 3,
2161
2165
  query_id: queryId,
2162
2166
  // Include viz hints for the chart generator
2163
- ...hasVizMods ? { encoding_hints: vizHintsForChart } : {}
2167
+ ...hasVizMods ? { encoding_hints: vizHintsForChart } : {},
2168
+ ...options?.supportedChartTypes?.length ? { supported_chart_types: options.supportedChartTypes } : {}
2164
2169
  },
2165
2170
  tenantId,
2166
2171
  options?.userId,
@@ -2307,7 +2312,8 @@ async function generateVizSpec(client, input, options, signal) {
2307
2312
  rows: input.rows,
2308
2313
  max_retries: options?.maxRetries ?? input.max_retries ?? 3,
2309
2314
  query_id: input.query_id,
2310
- encoding_hints: input.encoding_hints
2315
+ encoding_hints: input.encoding_hints,
2316
+ ...input.supported_chart_types?.length ? { supported_chart_types: input.supported_chart_types } : {}
2311
2317
  },
2312
2318
  tenantId,
2313
2319
  options?.userId,
@@ -2327,10 +2333,21 @@ function resolveTenantId8(client, tenantId) {
2327
2333
  return resolved;
2328
2334
  }
2329
2335
 
2336
+ // src/types/vizspec.ts
2337
+ var ALL_VIZ_CHART_TYPES = [
2338
+ "line",
2339
+ "bar",
2340
+ "column",
2341
+ "area",
2342
+ "scatter",
2343
+ "pie"
2344
+ ];
2345
+
2330
2346
  // src/index.ts
2331
2347
  var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2332
2348
  client;
2333
2349
  queryEngine;
2350
+ supportedChartTypes;
2334
2351
  /**
2335
2352
  * @param workspaceId - Workspace UUID (same value as your org in the dashboard). Passed to the API as JWT claim `organizationId`.
2336
2353
  */
@@ -2348,6 +2365,7 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2348
2365
  });
2349
2366
  }
2350
2367
  this.queryEngine = new QueryEngine();
2368
+ this.supportedChartTypes = options?.supportedChartTypes;
2351
2369
  }
2352
2370
  /**
2353
2371
  * Create an SDK instance that uses a request callback instead of HTTP.
@@ -2384,7 +2402,10 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2384
2402
  const api = new CallbackApiClient(requestHandler, {
2385
2403
  defaultTenantId: options?.defaultTenantId
2386
2404
  });
2387
- return new _QueryPanelSdkAPI("", "", workspaceId, { api });
2405
+ return new _QueryPanelSdkAPI("", "", workspaceId, {
2406
+ api,
2407
+ supportedChartTypes: options?.supportedChartTypes
2408
+ });
2388
2409
  }
2389
2410
  // Database attachment methods
2390
2411
  attachClickhouse(name, clientFn, options) {
@@ -2508,7 +2529,10 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2508
2529
  this.client,
2509
2530
  this.queryEngine,
2510
2531
  question,
2511
- options,
2532
+ {
2533
+ ...options,
2534
+ supportedChartTypes: options.supportedChartTypes ?? this.supportedChartTypes
2535
+ },
2512
2536
  signal
2513
2537
  );
2514
2538
  }
@@ -2580,7 +2604,10 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2580
2604
  async generateVizSpec(input, options, signal) {
2581
2605
  return await generateVizSpec(
2582
2606
  this.client,
2583
- input,
2607
+ {
2608
+ ...input,
2609
+ supported_chart_types: input.supported_chart_types ?? this.supportedChartTypes
2610
+ },
2584
2611
  options,
2585
2612
  signal
2586
2613
  );
@@ -2648,7 +2675,10 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2648
2675
  this.client,
2649
2676
  this.queryEngine,
2650
2677
  input,
2651
- options,
2678
+ options ? {
2679
+ ...options,
2680
+ supportedChartTypes: options.supportedChartTypes ?? this.supportedChartTypes
2681
+ } : this.supportedChartTypes ? { supportedChartTypes: this.supportedChartTypes } : void 0,
2652
2682
  signal
2653
2683
  );
2654
2684
  }
@@ -3287,6 +3317,7 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
3287
3317
  };
3288
3318
  // Annotate the CommonJS export names for ESM import in node:
3289
3319
  0 && (module.exports = {
3320
+ ALL_VIZ_CHART_TYPES,
3290
3321
  BigQueryAdapter,
3291
3322
  CallbackApiClient,
3292
3323
  ClickHouseAdapter,