@kweaver-ai/kweaver-sdk 0.4.13 → 0.4.15
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 +13 -1
- package/README.zh.md +13 -0
- package/dist/api/business-domains.d.ts +20 -0
- package/dist/api/business-domains.js +54 -0
- package/dist/api/conversations.d.ts +6 -0
- package/dist/api/conversations.js +21 -0
- package/dist/api/vega.d.ts +76 -3
- package/dist/api/vega.js +145 -10
- package/dist/auth/oauth.d.ts +9 -0
- package/dist/auth/oauth.js +9 -0
- package/dist/cli.js +2 -1
- package/dist/commands/agent.d.ts +5 -0
- package/dist/commands/agent.js +74 -2
- package/dist/commands/auth.js +5 -1
- package/dist/commands/config.js +34 -1
- package/dist/commands/vega.js +640 -21
- package/dist/config/store.d.ts +8 -0
- package/dist/config/store.js +39 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/resources/vega.d.ts +17 -3
- package/dist/resources/vega.js +44 -4
- package/package.json +1 -1
package/dist/commands/vega.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
1
2
|
import { ensureValidToken, formatHttpError, with401RefreshRetry } from "../auth/oauth.js";
|
|
2
|
-
import { vegaHealth, listVegaCatalogs, getVegaCatalog, vegaCatalogHealthStatus, testVegaCatalogConnection, discoverVegaCatalog, listVegaCatalogResources, listVegaResources, getVegaResource, queryVegaResourceData,
|
|
3
|
+
import { vegaHealth, listVegaCatalogs, getVegaCatalog, createVegaCatalog, updateVegaCatalog, deleteVegaCatalogs, vegaCatalogHealthStatus, testVegaCatalogConnection, discoverVegaCatalog, listVegaCatalogResources, listVegaResources, getVegaResource, queryVegaResourceData, createVegaResource, updateVegaResource, deleteVegaResources, listVegaConnectorTypes, getVegaConnectorType, registerVegaConnectorType, updateVegaConnectorType, deleteVegaConnectorType, setVegaConnectorTypeEnabled, listVegaDiscoverTasks, getVegaDiscoverTask, } from "../api/vega.js";
|
|
3
4
|
import { formatCallOutput } from "./call.js";
|
|
4
5
|
import { resolveBusinessDomain } from "../config/store.js";
|
|
5
6
|
// ---------------------------------------------------------------------------
|
|
@@ -18,12 +19,23 @@ Subcommands:
|
|
|
18
19
|
catalog test-connection <id> Test catalog connectivity
|
|
19
20
|
catalog discover <id> [--wait] Trigger discovery
|
|
20
21
|
catalog resources <id> [--category X] [--limit N]
|
|
22
|
+
catalog create --name <n> --connector-type <t> --connector-config <json>
|
|
23
|
+
catalog update <id> [--name X] [--connector-type X] [--tags X] [--description X]
|
|
24
|
+
catalog delete <ids...> [-y]
|
|
21
25
|
resource list [--catalog-id X] [--category X] [--status X] [--limit N] [--offset N]
|
|
22
26
|
resource get <id>
|
|
23
27
|
resource query <id> -d <json-body> Query resource data
|
|
24
|
-
resource
|
|
28
|
+
resource create --catalog-id <cid> --name <n> --category <cat>
|
|
29
|
+
resource update <id> [--name X] [--status X] [--tags X] [-d json]
|
|
30
|
+
resource delete <ids...> [-y]
|
|
25
31
|
connector-type list List connector types
|
|
26
32
|
connector-type get <type> Get connector type details
|
|
33
|
+
connector-type register -d <json> Register a new connector type
|
|
34
|
+
connector-type update <type> -d <json> Update connector type
|
|
35
|
+
connector-type delete <type> [-y] Delete connector type
|
|
36
|
+
connector-type enable <type> --enabled <bool> Enable/disable connector type
|
|
37
|
+
discovery-task list [--status X] [--limit N]
|
|
38
|
+
discovery-task get <id>
|
|
27
39
|
|
|
28
40
|
Common flags:
|
|
29
41
|
-bd, --biz-domain <s> Business domain (default: bd_public)
|
|
@@ -52,6 +64,16 @@ function parseCommonFlags(args) {
|
|
|
52
64
|
businessDomain = resolveBusinessDomain();
|
|
53
65
|
return { remaining, businessDomain, pretty };
|
|
54
66
|
}
|
|
67
|
+
function confirmYes(prompt) {
|
|
68
|
+
return new Promise((resolve) => {
|
|
69
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
70
|
+
rl.question(`${prompt} [y/N] `, (answer) => {
|
|
71
|
+
rl.close();
|
|
72
|
+
const trimmed = answer.trim().toLowerCase();
|
|
73
|
+
resolve(trimmed === "y" || trimmed === "yes");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
55
77
|
// ---------------------------------------------------------------------------
|
|
56
78
|
// Main router
|
|
57
79
|
// ---------------------------------------------------------------------------
|
|
@@ -74,6 +96,8 @@ export async function runVegaCommand(args) {
|
|
|
74
96
|
return runVegaResourceCommand(rest);
|
|
75
97
|
if (subcommand === "connector-type")
|
|
76
98
|
return runVegaConnectorTypeCommand(rest);
|
|
99
|
+
if (subcommand === "discovery-task")
|
|
100
|
+
return runVegaDiscoveryTaskCommand(rest);
|
|
77
101
|
return Promise.resolve(-1);
|
|
78
102
|
};
|
|
79
103
|
try {
|
|
@@ -192,7 +216,10 @@ Subcommands:
|
|
|
192
216
|
health <ids...> | --all
|
|
193
217
|
test-connection <id>
|
|
194
218
|
discover <id> [--wait]
|
|
195
|
-
resources <id> [--category X] [--limit N]
|
|
219
|
+
resources <id> [--category X] [--limit N]
|
|
220
|
+
create --name <name> --connector-type <type> --connector-config <json> [--tags t1,t2] [--description X]
|
|
221
|
+
update <id> [--name X] [--connector-type X] [--tags X] [--description X] [--connector-config X]
|
|
222
|
+
delete <ids...> [-y]`);
|
|
196
223
|
return 0;
|
|
197
224
|
}
|
|
198
225
|
if (sub === "list")
|
|
@@ -207,6 +234,12 @@ Subcommands:
|
|
|
207
234
|
return await runCatalogDiscover(rest);
|
|
208
235
|
if (sub === "resources")
|
|
209
236
|
return await runCatalogResources(rest);
|
|
237
|
+
if (sub === "create")
|
|
238
|
+
return await runCatalogCreate(rest);
|
|
239
|
+
if (sub === "update")
|
|
240
|
+
return await runCatalogUpdate(rest);
|
|
241
|
+
if (sub === "delete")
|
|
242
|
+
return await runCatalogDelete(rest);
|
|
210
243
|
console.error(`Unknown catalog subcommand: ${sub}`);
|
|
211
244
|
return 1;
|
|
212
245
|
}
|
|
@@ -422,6 +455,194 @@ Options:
|
|
|
422
455
|
return 0;
|
|
423
456
|
}
|
|
424
457
|
// ---------------------------------------------------------------------------
|
|
458
|
+
// catalog create
|
|
459
|
+
// ---------------------------------------------------------------------------
|
|
460
|
+
async function runCatalogCreate(args) {
|
|
461
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
462
|
+
console.log(`kweaver vega catalog create [options]
|
|
463
|
+
|
|
464
|
+
Options:
|
|
465
|
+
--name <s> Catalog name (required)
|
|
466
|
+
--connector-type <s> Connector type (required)
|
|
467
|
+
--connector-config <j> Connector config JSON (required)
|
|
468
|
+
--tags <t1,t2> Comma-separated tags
|
|
469
|
+
--description <s> Description`);
|
|
470
|
+
return 0;
|
|
471
|
+
}
|
|
472
|
+
let name;
|
|
473
|
+
let connectorType;
|
|
474
|
+
let connectorConfig;
|
|
475
|
+
let tags;
|
|
476
|
+
let description;
|
|
477
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
478
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
479
|
+
const arg = remaining[i];
|
|
480
|
+
if (arg === "--name" && remaining[i + 1]) {
|
|
481
|
+
name = remaining[++i];
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
if (arg === "--connector-type" && remaining[i + 1]) {
|
|
485
|
+
connectorType = remaining[++i];
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
if (arg === "--connector-config" && remaining[i + 1]) {
|
|
489
|
+
connectorConfig = remaining[++i];
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
if (arg === "--tags" && remaining[i + 1]) {
|
|
493
|
+
tags = remaining[++i];
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
if (arg === "--description" && remaining[i + 1]) {
|
|
497
|
+
description = remaining[++i];
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
if (!name || !connectorType || !connectorConfig) {
|
|
502
|
+
console.error("Usage: kweaver vega catalog create --name <name> --connector-type <type> --connector-config <json>");
|
|
503
|
+
return 1;
|
|
504
|
+
}
|
|
505
|
+
const payload = {
|
|
506
|
+
name,
|
|
507
|
+
connector_type: connectorType,
|
|
508
|
+
connector_config: JSON.parse(connectorConfig),
|
|
509
|
+
};
|
|
510
|
+
if (tags)
|
|
511
|
+
payload.tags = tags.split(",");
|
|
512
|
+
if (description)
|
|
513
|
+
payload.description = description;
|
|
514
|
+
const token = await ensureValidToken();
|
|
515
|
+
const body = await createVegaCatalog({
|
|
516
|
+
baseUrl: token.baseUrl,
|
|
517
|
+
accessToken: token.accessToken,
|
|
518
|
+
body: JSON.stringify(payload),
|
|
519
|
+
businessDomain,
|
|
520
|
+
});
|
|
521
|
+
console.log(formatCallOutput(body, pretty));
|
|
522
|
+
return 0;
|
|
523
|
+
}
|
|
524
|
+
// ---------------------------------------------------------------------------
|
|
525
|
+
// catalog update
|
|
526
|
+
// ---------------------------------------------------------------------------
|
|
527
|
+
async function runCatalogUpdate(args) {
|
|
528
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
529
|
+
console.log(`kweaver vega catalog update <id> [options]
|
|
530
|
+
|
|
531
|
+
Options:
|
|
532
|
+
--name <s> New name
|
|
533
|
+
--connector-type <t> Connector type (e.g. mysql, opensearch)
|
|
534
|
+
--tags <t1,t2> Comma-separated tags
|
|
535
|
+
--description <s> Description
|
|
536
|
+
--connector-config <j> Connector config JSON`);
|
|
537
|
+
return 0;
|
|
538
|
+
}
|
|
539
|
+
let name;
|
|
540
|
+
let connectorType;
|
|
541
|
+
let tags;
|
|
542
|
+
let description;
|
|
543
|
+
let connectorConfig;
|
|
544
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
545
|
+
const positionals = [];
|
|
546
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
547
|
+
const arg = remaining[i];
|
|
548
|
+
if (arg === "--name" && remaining[i + 1]) {
|
|
549
|
+
name = remaining[++i];
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
if (arg === "--connector-type" && remaining[i + 1]) {
|
|
553
|
+
connectorType = remaining[++i];
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
if (arg === "--tags" && remaining[i + 1]) {
|
|
557
|
+
tags = remaining[++i];
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
if (arg === "--description" && remaining[i + 1]) {
|
|
561
|
+
description = remaining[++i];
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
if (arg === "--connector-config" && remaining[i + 1]) {
|
|
565
|
+
connectorConfig = remaining[++i];
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
if (!arg.startsWith("-")) {
|
|
569
|
+
positionals.push(arg);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
const id = positionals[0];
|
|
573
|
+
if (!id) {
|
|
574
|
+
console.error("Usage: kweaver vega catalog update <id> [--name X] [--connector-type X] [--tags X] [--description X] [--connector-config X]");
|
|
575
|
+
return 1;
|
|
576
|
+
}
|
|
577
|
+
const payload = {};
|
|
578
|
+
if (name)
|
|
579
|
+
payload.name = name;
|
|
580
|
+
if (connectorType)
|
|
581
|
+
payload.connector_type = connectorType;
|
|
582
|
+
if (tags)
|
|
583
|
+
payload.tags = tags.split(",");
|
|
584
|
+
if (description)
|
|
585
|
+
payload.description = description;
|
|
586
|
+
if (connectorConfig)
|
|
587
|
+
payload.connector_config = JSON.parse(connectorConfig);
|
|
588
|
+
const token = await ensureValidToken();
|
|
589
|
+
const body = await updateVegaCatalog({
|
|
590
|
+
baseUrl: token.baseUrl,
|
|
591
|
+
accessToken: token.accessToken,
|
|
592
|
+
id,
|
|
593
|
+
body: JSON.stringify(payload),
|
|
594
|
+
businessDomain,
|
|
595
|
+
});
|
|
596
|
+
console.log(formatCallOutput(body || "{}", pretty));
|
|
597
|
+
return 0;
|
|
598
|
+
}
|
|
599
|
+
// ---------------------------------------------------------------------------
|
|
600
|
+
// catalog delete
|
|
601
|
+
// ---------------------------------------------------------------------------
|
|
602
|
+
async function runCatalogDelete(args) {
|
|
603
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
604
|
+
console.log(`kweaver vega catalog delete <ids...> [-y]
|
|
605
|
+
|
|
606
|
+
Options:
|
|
607
|
+
-y, --yes Skip confirmation`);
|
|
608
|
+
return 0;
|
|
609
|
+
}
|
|
610
|
+
let skipConfirm = false;
|
|
611
|
+
const { remaining, businessDomain } = parseCommonFlags(args);
|
|
612
|
+
const positionals = [];
|
|
613
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
614
|
+
const arg = remaining[i];
|
|
615
|
+
if (arg === "-y" || arg === "--yes") {
|
|
616
|
+
skipConfirm = true;
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
if (!arg.startsWith("-")) {
|
|
620
|
+
positionals.push(arg);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
if (positionals.length === 0) {
|
|
624
|
+
console.error("Usage: kweaver vega catalog delete <ids...> [-y]");
|
|
625
|
+
return 1;
|
|
626
|
+
}
|
|
627
|
+
const ids = positionals.join(",");
|
|
628
|
+
if (!skipConfirm) {
|
|
629
|
+
const ok = await confirmYes(`Delete catalog(s) ${ids}?`);
|
|
630
|
+
if (!ok) {
|
|
631
|
+
console.error("Aborted.");
|
|
632
|
+
return 1;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
const token = await ensureValidToken();
|
|
636
|
+
await deleteVegaCatalogs({
|
|
637
|
+
baseUrl: token.baseUrl,
|
|
638
|
+
accessToken: token.accessToken,
|
|
639
|
+
ids,
|
|
640
|
+
businessDomain,
|
|
641
|
+
});
|
|
642
|
+
console.error(`Deleted ${ids}`);
|
|
643
|
+
return 0;
|
|
644
|
+
}
|
|
645
|
+
// ---------------------------------------------------------------------------
|
|
425
646
|
// Resource router
|
|
426
647
|
// ---------------------------------------------------------------------------
|
|
427
648
|
async function runVegaResourceCommand(args) {
|
|
@@ -433,7 +654,9 @@ Subcommands:
|
|
|
433
654
|
list [--catalog-id X] [--category X] [--status X] [--limit N] [--offset N]
|
|
434
655
|
get <id>
|
|
435
656
|
query <id> -d <json-body>
|
|
436
|
-
|
|
657
|
+
create --catalog-id <cid> --name <name> --category <cat>
|
|
658
|
+
update <id> [--name X] [--status X] [--tags X] [-d json]
|
|
659
|
+
delete <ids...> [-y]`);
|
|
437
660
|
return 0;
|
|
438
661
|
}
|
|
439
662
|
if (sub === "list")
|
|
@@ -442,8 +665,12 @@ Subcommands:
|
|
|
442
665
|
return await runResourceGet(rest);
|
|
443
666
|
if (sub === "query")
|
|
444
667
|
return await runResourceQuery(rest);
|
|
445
|
-
if (sub === "
|
|
446
|
-
return await
|
|
668
|
+
if (sub === "create")
|
|
669
|
+
return await runResourceCreate(rest);
|
|
670
|
+
if (sub === "update")
|
|
671
|
+
return await runResourceUpdate(rest);
|
|
672
|
+
if (sub === "delete")
|
|
673
|
+
return await runResourceDelete(rest);
|
|
447
674
|
console.error(`Unknown resource subcommand: ${sub}`);
|
|
448
675
|
return 1;
|
|
449
676
|
}
|
|
@@ -572,43 +799,184 @@ Options:
|
|
|
572
799
|
return 0;
|
|
573
800
|
}
|
|
574
801
|
// ---------------------------------------------------------------------------
|
|
575
|
-
// resource
|
|
802
|
+
// resource create
|
|
576
803
|
// ---------------------------------------------------------------------------
|
|
577
|
-
async function
|
|
804
|
+
async function runResourceCreate(args) {
|
|
578
805
|
if (args.includes("--help") || args.includes("-h")) {
|
|
579
|
-
console.log(`kweaver vega resource
|
|
806
|
+
console.log(`kweaver vega resource create [options]
|
|
580
807
|
|
|
581
808
|
Options:
|
|
582
|
-
--
|
|
809
|
+
--catalog-id <cid> Catalog ID (required)
|
|
810
|
+
--name <name> Resource name (required)
|
|
811
|
+
--category <cat> Category (required)
|
|
812
|
+
--source-identifier <si> Source identifier
|
|
813
|
+
--database <db> Database name
|
|
814
|
+
-d, --data <json> Additional fields as JSON`);
|
|
583
815
|
return 0;
|
|
584
816
|
}
|
|
585
|
-
let
|
|
817
|
+
let catalogId;
|
|
818
|
+
let name;
|
|
819
|
+
let category;
|
|
820
|
+
let sourceIdentifier;
|
|
821
|
+
let database;
|
|
822
|
+
let data;
|
|
823
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
824
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
825
|
+
const arg = remaining[i];
|
|
826
|
+
if (arg === "--catalog-id" && remaining[i + 1]) {
|
|
827
|
+
catalogId = remaining[++i];
|
|
828
|
+
continue;
|
|
829
|
+
}
|
|
830
|
+
if (arg === "--name" && remaining[i + 1]) {
|
|
831
|
+
name = remaining[++i];
|
|
832
|
+
continue;
|
|
833
|
+
}
|
|
834
|
+
if (arg === "--category" && remaining[i + 1]) {
|
|
835
|
+
category = remaining[++i];
|
|
836
|
+
continue;
|
|
837
|
+
}
|
|
838
|
+
if (arg === "--source-identifier" && remaining[i + 1]) {
|
|
839
|
+
sourceIdentifier = remaining[++i];
|
|
840
|
+
continue;
|
|
841
|
+
}
|
|
842
|
+
if (arg === "--database" && remaining[i + 1]) {
|
|
843
|
+
database = remaining[++i];
|
|
844
|
+
continue;
|
|
845
|
+
}
|
|
846
|
+
if ((arg === "-d" || arg === "--data") && remaining[i + 1]) {
|
|
847
|
+
data = remaining[++i];
|
|
848
|
+
continue;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
if (!catalogId || !name || !category) {
|
|
852
|
+
console.error("Usage: kweaver vega resource create --catalog-id <cid> --name <name> --category <cat>");
|
|
853
|
+
return 1;
|
|
854
|
+
}
|
|
855
|
+
const payload = { catalog_id: catalogId, name, category };
|
|
856
|
+
if (sourceIdentifier)
|
|
857
|
+
payload.source_identifier = sourceIdentifier;
|
|
858
|
+
if (database)
|
|
859
|
+
payload.database = database;
|
|
860
|
+
if (data)
|
|
861
|
+
Object.assign(payload, JSON.parse(data));
|
|
862
|
+
const token = await ensureValidToken();
|
|
863
|
+
const body = await createVegaResource({
|
|
864
|
+
baseUrl: token.baseUrl,
|
|
865
|
+
accessToken: token.accessToken,
|
|
866
|
+
body: JSON.stringify(payload),
|
|
867
|
+
businessDomain,
|
|
868
|
+
});
|
|
869
|
+
console.log(formatCallOutput(body, pretty));
|
|
870
|
+
return 0;
|
|
871
|
+
}
|
|
872
|
+
// ---------------------------------------------------------------------------
|
|
873
|
+
// resource update
|
|
874
|
+
// ---------------------------------------------------------------------------
|
|
875
|
+
async function runResourceUpdate(args) {
|
|
876
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
877
|
+
console.log(`kweaver vega resource update <id> [options]
|
|
878
|
+
|
|
879
|
+
Options:
|
|
880
|
+
--name <name> Resource name
|
|
881
|
+
--status <s> Status
|
|
882
|
+
--tags <t1,t2> Comma-separated tags
|
|
883
|
+
-d, --data <json> Additional fields as JSON`);
|
|
884
|
+
return 0;
|
|
885
|
+
}
|
|
886
|
+
let name;
|
|
887
|
+
let status;
|
|
888
|
+
let tags;
|
|
889
|
+
let data;
|
|
586
890
|
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
587
891
|
const positionals = [];
|
|
588
892
|
for (let i = 0; i < remaining.length; i += 1) {
|
|
589
893
|
const arg = remaining[i];
|
|
590
|
-
if (arg === "--
|
|
591
|
-
|
|
894
|
+
if (arg === "--name" && remaining[i + 1]) {
|
|
895
|
+
name = remaining[++i];
|
|
592
896
|
continue;
|
|
593
897
|
}
|
|
594
|
-
if (
|
|
595
|
-
|
|
898
|
+
if (arg === "--status" && remaining[i + 1]) {
|
|
899
|
+
status = remaining[++i];
|
|
900
|
+
continue;
|
|
901
|
+
}
|
|
902
|
+
if (arg === "--tags" && remaining[i + 1]) {
|
|
903
|
+
tags = remaining[++i];
|
|
904
|
+
continue;
|
|
905
|
+
}
|
|
906
|
+
if ((arg === "-d" || arg === "--data") && remaining[i + 1]) {
|
|
907
|
+
data = remaining[++i];
|
|
908
|
+
continue;
|
|
596
909
|
}
|
|
910
|
+
if (!arg.startsWith("-"))
|
|
911
|
+
positionals.push(arg);
|
|
597
912
|
}
|
|
598
913
|
const id = positionals[0];
|
|
599
914
|
if (!id) {
|
|
600
|
-
console.error("Usage: kweaver vega resource
|
|
915
|
+
console.error("Usage: kweaver vega resource update <id> [--name X] [--status X] [--tags X] [-d json]");
|
|
601
916
|
return 1;
|
|
602
917
|
}
|
|
918
|
+
const payload = {};
|
|
919
|
+
if (name)
|
|
920
|
+
payload.name = name;
|
|
921
|
+
if (status)
|
|
922
|
+
payload.status = status;
|
|
923
|
+
if (tags)
|
|
924
|
+
payload.tags = tags.split(",");
|
|
925
|
+
if (data)
|
|
926
|
+
Object.assign(payload, JSON.parse(data));
|
|
603
927
|
const token = await ensureValidToken();
|
|
604
|
-
const body = await
|
|
928
|
+
const body = await updateVegaResource({
|
|
605
929
|
baseUrl: token.baseUrl,
|
|
606
930
|
accessToken: token.accessToken,
|
|
607
931
|
id,
|
|
608
|
-
|
|
932
|
+
body: JSON.stringify(payload),
|
|
609
933
|
businessDomain,
|
|
610
934
|
});
|
|
611
|
-
console.log(formatCallOutput(body, pretty));
|
|
935
|
+
console.log(formatCallOutput(body || "{}", pretty));
|
|
936
|
+
return 0;
|
|
937
|
+
}
|
|
938
|
+
// ---------------------------------------------------------------------------
|
|
939
|
+
// resource delete
|
|
940
|
+
// ---------------------------------------------------------------------------
|
|
941
|
+
async function runResourceDelete(args) {
|
|
942
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
943
|
+
console.log(`kweaver vega resource delete <ids...> [-y]
|
|
944
|
+
|
|
945
|
+
Options:
|
|
946
|
+
-y, --yes Skip confirmation prompt`);
|
|
947
|
+
return 0;
|
|
948
|
+
}
|
|
949
|
+
let yes = false;
|
|
950
|
+
const { remaining, businessDomain } = parseCommonFlags(args);
|
|
951
|
+
const positionals = [];
|
|
952
|
+
for (const arg of remaining) {
|
|
953
|
+
if (arg === "-y" || arg === "--yes") {
|
|
954
|
+
yes = true;
|
|
955
|
+
continue;
|
|
956
|
+
}
|
|
957
|
+
if (!arg.startsWith("-"))
|
|
958
|
+
positionals.push(arg);
|
|
959
|
+
}
|
|
960
|
+
if (positionals.length === 0) {
|
|
961
|
+
console.error("Usage: kweaver vega resource delete <ids...> [-y]");
|
|
962
|
+
return 1;
|
|
963
|
+
}
|
|
964
|
+
const ids = positionals.join(",");
|
|
965
|
+
if (!yes) {
|
|
966
|
+
const confirmed = await confirmYes(`Delete resource(s) ${ids}?`);
|
|
967
|
+
if (!confirmed) {
|
|
968
|
+
console.error("Aborted.");
|
|
969
|
+
return 1;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
const token = await ensureValidToken();
|
|
973
|
+
await deleteVegaResources({
|
|
974
|
+
baseUrl: token.baseUrl,
|
|
975
|
+
accessToken: token.accessToken,
|
|
976
|
+
ids,
|
|
977
|
+
businessDomain,
|
|
978
|
+
});
|
|
979
|
+
console.error(`Deleted ${ids}`);
|
|
612
980
|
return 0;
|
|
613
981
|
}
|
|
614
982
|
// ---------------------------------------------------------------------------
|
|
@@ -620,14 +988,26 @@ async function runVegaConnectorTypeCommand(args) {
|
|
|
620
988
|
console.log(`kweaver vega connector-type
|
|
621
989
|
|
|
622
990
|
Subcommands:
|
|
623
|
-
list
|
|
624
|
-
get <type>
|
|
991
|
+
list List connector types
|
|
992
|
+
get <type> Get connector type details
|
|
993
|
+
register -d <json> Register a new connector type
|
|
994
|
+
update <type> -d <json> Update connector type
|
|
995
|
+
delete <type> [-y] Delete connector type
|
|
996
|
+
enable <type> --enabled <bool> Enable/disable connector type`);
|
|
625
997
|
return 0;
|
|
626
998
|
}
|
|
627
999
|
if (sub === "list")
|
|
628
1000
|
return await runConnectorTypeList(rest);
|
|
629
1001
|
if (sub === "get")
|
|
630
1002
|
return await runConnectorTypeGet(rest);
|
|
1003
|
+
if (sub === "register")
|
|
1004
|
+
return await runConnectorTypeRegister(rest);
|
|
1005
|
+
if (sub === "update")
|
|
1006
|
+
return await runConnectorTypeUpdate(rest);
|
|
1007
|
+
if (sub === "delete")
|
|
1008
|
+
return await runConnectorTypeDelete(rest);
|
|
1009
|
+
if (sub === "enable")
|
|
1010
|
+
return await runConnectorTypeEnable(rest);
|
|
631
1011
|
console.error(`Unknown connector-type subcommand: ${sub}`);
|
|
632
1012
|
return 1;
|
|
633
1013
|
}
|
|
@@ -673,3 +1053,242 @@ async function runConnectorTypeGet(args) {
|
|
|
673
1053
|
console.log(formatCallOutput(body, pretty));
|
|
674
1054
|
return 0;
|
|
675
1055
|
}
|
|
1056
|
+
// ---------------------------------------------------------------------------
|
|
1057
|
+
// connector-type register
|
|
1058
|
+
// ---------------------------------------------------------------------------
|
|
1059
|
+
async function runConnectorTypeRegister(args) {
|
|
1060
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1061
|
+
console.log(`kweaver vega connector-type register -d <json>
|
|
1062
|
+
|
|
1063
|
+
Options:
|
|
1064
|
+
-d, --data <json> Connector type definition (JSON string)`);
|
|
1065
|
+
return 0;
|
|
1066
|
+
}
|
|
1067
|
+
let data;
|
|
1068
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1069
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
1070
|
+
const arg = remaining[i];
|
|
1071
|
+
if ((arg === "-d" || arg === "--data") && remaining[i + 1]) {
|
|
1072
|
+
data = remaining[++i];
|
|
1073
|
+
continue;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
if (!data) {
|
|
1077
|
+
console.error("Usage: kweaver vega connector-type register -d <json>");
|
|
1078
|
+
return 1;
|
|
1079
|
+
}
|
|
1080
|
+
const token = await ensureValidToken();
|
|
1081
|
+
const body = await registerVegaConnectorType({
|
|
1082
|
+
baseUrl: token.baseUrl,
|
|
1083
|
+
accessToken: token.accessToken,
|
|
1084
|
+
body: data,
|
|
1085
|
+
businessDomain,
|
|
1086
|
+
});
|
|
1087
|
+
console.log(formatCallOutput(body, pretty));
|
|
1088
|
+
return 0;
|
|
1089
|
+
}
|
|
1090
|
+
// ---------------------------------------------------------------------------
|
|
1091
|
+
// connector-type update
|
|
1092
|
+
// ---------------------------------------------------------------------------
|
|
1093
|
+
async function runConnectorTypeUpdate(args) {
|
|
1094
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1095
|
+
console.log(`kweaver vega connector-type update <type> -d <json>
|
|
1096
|
+
|
|
1097
|
+
Options:
|
|
1098
|
+
-d, --data <json> Updated fields (JSON string)`);
|
|
1099
|
+
return 0;
|
|
1100
|
+
}
|
|
1101
|
+
let data;
|
|
1102
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1103
|
+
const positionals = [];
|
|
1104
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
1105
|
+
const arg = remaining[i];
|
|
1106
|
+
if ((arg === "-d" || arg === "--data") && remaining[i + 1]) {
|
|
1107
|
+
data = remaining[++i];
|
|
1108
|
+
continue;
|
|
1109
|
+
}
|
|
1110
|
+
if (!arg.startsWith("-"))
|
|
1111
|
+
positionals.push(arg);
|
|
1112
|
+
}
|
|
1113
|
+
const type = positionals[0];
|
|
1114
|
+
if (!type || !data) {
|
|
1115
|
+
console.error("Usage: kweaver vega connector-type update <type> -d <json>");
|
|
1116
|
+
return 1;
|
|
1117
|
+
}
|
|
1118
|
+
const token = await ensureValidToken();
|
|
1119
|
+
const body = await updateVegaConnectorType({
|
|
1120
|
+
baseUrl: token.baseUrl,
|
|
1121
|
+
accessToken: token.accessToken,
|
|
1122
|
+
type,
|
|
1123
|
+
body: data,
|
|
1124
|
+
businessDomain,
|
|
1125
|
+
});
|
|
1126
|
+
console.log(formatCallOutput(body || "{}", pretty));
|
|
1127
|
+
return 0;
|
|
1128
|
+
}
|
|
1129
|
+
// ---------------------------------------------------------------------------
|
|
1130
|
+
// connector-type delete
|
|
1131
|
+
// ---------------------------------------------------------------------------
|
|
1132
|
+
async function runConnectorTypeDelete(args) {
|
|
1133
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1134
|
+
console.log(`kweaver vega connector-type delete <type> [-y]
|
|
1135
|
+
|
|
1136
|
+
Options:
|
|
1137
|
+
-y, --yes Skip confirmation prompt`);
|
|
1138
|
+
return 0;
|
|
1139
|
+
}
|
|
1140
|
+
let yes = false;
|
|
1141
|
+
const { remaining, businessDomain } = parseCommonFlags(args);
|
|
1142
|
+
const positionals = [];
|
|
1143
|
+
for (const arg of remaining) {
|
|
1144
|
+
if (arg === "-y" || arg === "--yes") {
|
|
1145
|
+
yes = true;
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
1148
|
+
if (!arg.startsWith("-"))
|
|
1149
|
+
positionals.push(arg);
|
|
1150
|
+
}
|
|
1151
|
+
const type = positionals[0];
|
|
1152
|
+
if (!type) {
|
|
1153
|
+
console.error("Usage: kweaver vega connector-type delete <type> [-y]");
|
|
1154
|
+
return 1;
|
|
1155
|
+
}
|
|
1156
|
+
if (!yes) {
|
|
1157
|
+
const confirmed = await confirmYes(`Delete connector type "${type}"?`);
|
|
1158
|
+
if (!confirmed) {
|
|
1159
|
+
console.error("Aborted.");
|
|
1160
|
+
return 1;
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
const token = await ensureValidToken();
|
|
1164
|
+
await deleteVegaConnectorType({
|
|
1165
|
+
baseUrl: token.baseUrl,
|
|
1166
|
+
accessToken: token.accessToken,
|
|
1167
|
+
type,
|
|
1168
|
+
businessDomain,
|
|
1169
|
+
});
|
|
1170
|
+
console.error(`Deleted ${type}`);
|
|
1171
|
+
return 0;
|
|
1172
|
+
}
|
|
1173
|
+
// ---------------------------------------------------------------------------
|
|
1174
|
+
// connector-type enable
|
|
1175
|
+
// ---------------------------------------------------------------------------
|
|
1176
|
+
async function runConnectorTypeEnable(args) {
|
|
1177
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1178
|
+
console.log(`kweaver vega connector-type enable <type> --enabled <true|false>`);
|
|
1179
|
+
return 0;
|
|
1180
|
+
}
|
|
1181
|
+
let enabled;
|
|
1182
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1183
|
+
const positionals = [];
|
|
1184
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
1185
|
+
const arg = remaining[i];
|
|
1186
|
+
if (arg === "--enabled" && remaining[i + 1]) {
|
|
1187
|
+
enabled = remaining[++i] === "true";
|
|
1188
|
+
continue;
|
|
1189
|
+
}
|
|
1190
|
+
if (!arg.startsWith("-"))
|
|
1191
|
+
positionals.push(arg);
|
|
1192
|
+
}
|
|
1193
|
+
const type = positionals[0];
|
|
1194
|
+
if (!type || enabled === undefined) {
|
|
1195
|
+
console.error("Usage: kweaver vega connector-type enable <type> --enabled <true|false>");
|
|
1196
|
+
return 1;
|
|
1197
|
+
}
|
|
1198
|
+
const token = await ensureValidToken();
|
|
1199
|
+
const body = await setVegaConnectorTypeEnabled({
|
|
1200
|
+
baseUrl: token.baseUrl,
|
|
1201
|
+
accessToken: token.accessToken,
|
|
1202
|
+
type,
|
|
1203
|
+
enabled,
|
|
1204
|
+
businessDomain,
|
|
1205
|
+
});
|
|
1206
|
+
console.log(formatCallOutput(body || "{}", pretty));
|
|
1207
|
+
return 0;
|
|
1208
|
+
}
|
|
1209
|
+
// ---------------------------------------------------------------------------
|
|
1210
|
+
// Discovery-task router
|
|
1211
|
+
// ---------------------------------------------------------------------------
|
|
1212
|
+
async function runVegaDiscoveryTaskCommand(args) {
|
|
1213
|
+
const [sub, ...rest] = args;
|
|
1214
|
+
if (!sub || sub === "--help" || sub === "-h") {
|
|
1215
|
+
console.log(`kweaver vega discovery-task
|
|
1216
|
+
|
|
1217
|
+
Subcommands:
|
|
1218
|
+
list [--status X] [--limit N]
|
|
1219
|
+
get <id>`);
|
|
1220
|
+
return 0;
|
|
1221
|
+
}
|
|
1222
|
+
if (sub === "list")
|
|
1223
|
+
return await runDiscoveryTaskList(rest);
|
|
1224
|
+
if (sub === "get")
|
|
1225
|
+
return await runDiscoveryTaskGet(rest);
|
|
1226
|
+
console.error(`Unknown discovery-task subcommand: ${sub}`);
|
|
1227
|
+
return 1;
|
|
1228
|
+
}
|
|
1229
|
+
// ---------------------------------------------------------------------------
|
|
1230
|
+
// discovery-task list
|
|
1231
|
+
// ---------------------------------------------------------------------------
|
|
1232
|
+
async function runDiscoveryTaskList(args) {
|
|
1233
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1234
|
+
console.log(`kweaver vega discovery-task list [options]
|
|
1235
|
+
|
|
1236
|
+
Options:
|
|
1237
|
+
--catalog-id <cid> Filter by catalog (reserved)
|
|
1238
|
+
--status <s> Filter by status
|
|
1239
|
+
--limit <n> Max results`);
|
|
1240
|
+
return 0;
|
|
1241
|
+
}
|
|
1242
|
+
let status;
|
|
1243
|
+
let limit;
|
|
1244
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1245
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
1246
|
+
const arg = remaining[i];
|
|
1247
|
+
if (arg === "--status" && remaining[i + 1]) {
|
|
1248
|
+
status = remaining[++i];
|
|
1249
|
+
continue;
|
|
1250
|
+
}
|
|
1251
|
+
if (arg === "--limit" && remaining[i + 1]) {
|
|
1252
|
+
limit = parseInt(remaining[++i], 10);
|
|
1253
|
+
continue;
|
|
1254
|
+
}
|
|
1255
|
+
if (arg === "--catalog-id" && remaining[i + 1]) {
|
|
1256
|
+
remaining[++i];
|
|
1257
|
+
continue;
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
const token = await ensureValidToken();
|
|
1261
|
+
const body = await listVegaDiscoverTasks({
|
|
1262
|
+
baseUrl: token.baseUrl,
|
|
1263
|
+
accessToken: token.accessToken,
|
|
1264
|
+
status,
|
|
1265
|
+
limit,
|
|
1266
|
+
businessDomain,
|
|
1267
|
+
});
|
|
1268
|
+
console.log(formatCallOutput(body, pretty));
|
|
1269
|
+
return 0;
|
|
1270
|
+
}
|
|
1271
|
+
// ---------------------------------------------------------------------------
|
|
1272
|
+
// discovery-task get
|
|
1273
|
+
// ---------------------------------------------------------------------------
|
|
1274
|
+
async function runDiscoveryTaskGet(args) {
|
|
1275
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1276
|
+
console.log("kweaver vega discovery-task get <id>");
|
|
1277
|
+
return 0;
|
|
1278
|
+
}
|
|
1279
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1280
|
+
const id = remaining.find((a) => !a.startsWith("-"));
|
|
1281
|
+
if (!id) {
|
|
1282
|
+
console.error("Usage: kweaver vega discovery-task get <id>");
|
|
1283
|
+
return 1;
|
|
1284
|
+
}
|
|
1285
|
+
const token = await ensureValidToken();
|
|
1286
|
+
const body = await getVegaDiscoverTask({
|
|
1287
|
+
baseUrl: token.baseUrl,
|
|
1288
|
+
accessToken: token.accessToken,
|
|
1289
|
+
id,
|
|
1290
|
+
businessDomain,
|
|
1291
|
+
});
|
|
1292
|
+
console.log(formatCallOutput(body, pretty));
|
|
1293
|
+
return 0;
|
|
1294
|
+
}
|