@querypanel/node-sdk 1.0.39 → 1.0.41
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/dist/index.cjs +112 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -2
- package/dist/index.d.ts +117 -2
- package/dist/index.js +100 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -554,6 +564,7 @@ function sanitize2(value) {
|
|
|
554
564
|
}
|
|
555
565
|
|
|
556
566
|
// src/core/client.ts
|
|
567
|
+
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
557
568
|
var ApiClient = class {
|
|
558
569
|
baseUrl;
|
|
559
570
|
privateKey;
|
|
@@ -711,7 +722,7 @@ var ApiClient = class {
|
|
|
711
722
|
if (this.cryptoKey) {
|
|
712
723
|
return this.cryptoKey;
|
|
713
724
|
}
|
|
714
|
-
this.cryptoKey = await
|
|
725
|
+
this.cryptoKey = await import_node_crypto.default.subtle.importKey(
|
|
715
726
|
"pkcs8",
|
|
716
727
|
this.privateKeyToArrayBuffer(this.privateKey),
|
|
717
728
|
{
|
|
@@ -753,7 +764,7 @@ var ApiClient = class {
|
|
|
753
764
|
const data = `${encodedHeader}.${encodedPayload}`;
|
|
754
765
|
const key = await this.getCryptoKey();
|
|
755
766
|
const dataBytes = new TextEncoder().encode(data);
|
|
756
|
-
const signature = await
|
|
767
|
+
const signature = await import_node_crypto.default.subtle.sign(
|
|
757
768
|
{
|
|
758
769
|
name: "RSASSA-PKCS1-v1_5"
|
|
759
770
|
},
|
|
@@ -1092,6 +1103,7 @@ function resolveTenantId2(client, tenantId) {
|
|
|
1092
1103
|
}
|
|
1093
1104
|
|
|
1094
1105
|
// src/routes/ingest.ts
|
|
1106
|
+
var import_node_crypto2 = __toESM(require("crypto"), 1);
|
|
1095
1107
|
async function syncSchema(client, queryEngine, databaseName, options, signal) {
|
|
1096
1108
|
const tenantId = resolveTenantId3(client, options.tenantId);
|
|
1097
1109
|
const adapter = queryEngine.getDatabase(databaseName);
|
|
@@ -1103,7 +1115,7 @@ async function syncSchema(client, queryEngine, databaseName, options, signal) {
|
|
|
1103
1115
|
if (options.forceReindex) {
|
|
1104
1116
|
payload.force_reindex = true;
|
|
1105
1117
|
}
|
|
1106
|
-
const sessionId =
|
|
1118
|
+
const sessionId = import_node_crypto2.default.randomUUID();
|
|
1107
1119
|
const response = await client.post(
|
|
1108
1120
|
"/ingest",
|
|
1109
1121
|
payload,
|
|
@@ -1152,9 +1164,10 @@ function buildSchemaRequest(databaseName, adapter, introspection, metadata) {
|
|
|
1152
1164
|
}
|
|
1153
1165
|
|
|
1154
1166
|
// src/routes/query.ts
|
|
1167
|
+
var import_node_crypto3 = __toESM(require("crypto"), 1);
|
|
1155
1168
|
async function ask(client, queryEngine, question, options, signal) {
|
|
1156
1169
|
const tenantId = resolveTenantId4(client, options.tenantId);
|
|
1157
|
-
const sessionId =
|
|
1170
|
+
const sessionId = import_node_crypto3.default.randomUUID();
|
|
1158
1171
|
const maxRetry = options.maxRetry ?? 0;
|
|
1159
1172
|
let attempt = 0;
|
|
1160
1173
|
let lastError = options.lastError;
|
|
@@ -1191,35 +1204,62 @@ async function ask(client, queryEngine, question, options, signal) {
|
|
|
1191
1204
|
tenantId
|
|
1192
1205
|
);
|
|
1193
1206
|
const rows = execution.rows ?? [];
|
|
1207
|
+
const chartType = options.chartType ?? "vega-lite";
|
|
1194
1208
|
let chart = {
|
|
1195
|
-
|
|
1209
|
+
specType: chartType,
|
|
1196
1210
|
notes: rows.length === 0 ? "Query returned no rows." : null
|
|
1197
1211
|
};
|
|
1198
1212
|
if (rows.length > 0) {
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
}
|
|
1213
|
+
if (chartType === "vizspec") {
|
|
1214
|
+
const vizspecResponse = await client.post(
|
|
1215
|
+
"/vizspec",
|
|
1216
|
+
{
|
|
1217
|
+
question,
|
|
1218
|
+
sql: queryResponse.sql,
|
|
1219
|
+
rationale: queryResponse.rationale,
|
|
1220
|
+
fields: execution.fields,
|
|
1221
|
+
rows: anonymizeResults(rows),
|
|
1222
|
+
max_retries: options.chartMaxRetries ?? 3,
|
|
1223
|
+
query_id: queryResponse.queryId
|
|
1224
|
+
},
|
|
1225
|
+
tenantId,
|
|
1226
|
+
options.userId,
|
|
1227
|
+
options.scopes,
|
|
1228
|
+
signal,
|
|
1229
|
+
sessionId
|
|
1230
|
+
);
|
|
1231
|
+
chart = {
|
|
1232
|
+
vizSpec: vizspecResponse.spec,
|
|
1233
|
+
specType: "vizspec",
|
|
1234
|
+
notes: vizspecResponse.notes
|
|
1235
|
+
};
|
|
1236
|
+
} else {
|
|
1237
|
+
const chartResponse = await client.post(
|
|
1238
|
+
"/chart",
|
|
1239
|
+
{
|
|
1240
|
+
question,
|
|
1241
|
+
sql: queryResponse.sql,
|
|
1242
|
+
rationale: queryResponse.rationale,
|
|
1243
|
+
fields: execution.fields,
|
|
1244
|
+
rows: anonymizeResults(rows),
|
|
1245
|
+
max_retries: options.chartMaxRetries ?? 3,
|
|
1246
|
+
query_id: queryResponse.queryId
|
|
1247
|
+
},
|
|
1248
|
+
tenantId,
|
|
1249
|
+
options.userId,
|
|
1250
|
+
options.scopes,
|
|
1251
|
+
signal,
|
|
1252
|
+
sessionId
|
|
1253
|
+
);
|
|
1254
|
+
chart = {
|
|
1255
|
+
vegaLiteSpec: chartResponse.chart ? {
|
|
1256
|
+
...chartResponse.chart,
|
|
1257
|
+
data: { values: rows }
|
|
1258
|
+
} : null,
|
|
1259
|
+
specType: "vega-lite",
|
|
1260
|
+
notes: chartResponse.notes
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1223
1263
|
}
|
|
1224
1264
|
return {
|
|
1225
1265
|
sql: queryResponse.sql,
|
|
@@ -1271,6 +1311,40 @@ function anonymizeResults(rows) {
|
|
|
1271
1311
|
});
|
|
1272
1312
|
}
|
|
1273
1313
|
|
|
1314
|
+
// src/routes/vizspec.ts
|
|
1315
|
+
var import_node_crypto4 = __toESM(require("crypto"), 1);
|
|
1316
|
+
async function generateVizSpec(client, input, options, signal) {
|
|
1317
|
+
const tenantId = resolveTenantId5(client, options?.tenantId);
|
|
1318
|
+
const sessionId = import_node_crypto4.default.randomUUID();
|
|
1319
|
+
const response = await client.post(
|
|
1320
|
+
"/vizspec",
|
|
1321
|
+
{
|
|
1322
|
+
question: input.question,
|
|
1323
|
+
sql: input.sql,
|
|
1324
|
+
rationale: input.rationale,
|
|
1325
|
+
fields: input.fields,
|
|
1326
|
+
rows: input.rows,
|
|
1327
|
+
max_retries: options?.maxRetries ?? input.max_retries ?? 3,
|
|
1328
|
+
query_id: input.query_id
|
|
1329
|
+
},
|
|
1330
|
+
tenantId,
|
|
1331
|
+
options?.userId,
|
|
1332
|
+
options?.scopes,
|
|
1333
|
+
signal,
|
|
1334
|
+
sessionId
|
|
1335
|
+
);
|
|
1336
|
+
return response;
|
|
1337
|
+
}
|
|
1338
|
+
function resolveTenantId5(client, tenantId) {
|
|
1339
|
+
const resolved = tenantId ?? client.getDefaultTenantId();
|
|
1340
|
+
if (!resolved) {
|
|
1341
|
+
throw new Error(
|
|
1342
|
+
"tenantId is required. Provide it per request or via defaultTenantId option."
|
|
1343
|
+
);
|
|
1344
|
+
}
|
|
1345
|
+
return resolved;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1274
1348
|
// src/index.ts
|
|
1275
1349
|
var QueryPanelSdkAPI = class {
|
|
1276
1350
|
client;
|
|
@@ -1336,6 +1410,15 @@ var QueryPanelSdkAPI = class {
|
|
|
1336
1410
|
signal
|
|
1337
1411
|
);
|
|
1338
1412
|
}
|
|
1413
|
+
// VizSpec generation
|
|
1414
|
+
async generateVizSpec(input, options, signal) {
|
|
1415
|
+
return await generateVizSpec(
|
|
1416
|
+
this.client,
|
|
1417
|
+
input,
|
|
1418
|
+
options,
|
|
1419
|
+
signal
|
|
1420
|
+
);
|
|
1421
|
+
}
|
|
1339
1422
|
// Chart CRUD operations
|
|
1340
1423
|
async createChart(body, options, signal) {
|
|
1341
1424
|
return await createChart(this.client, body, options, signal);
|