@lightdash-tools/cli 0.1.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.
- package/LICENSE +201 -0
- package/README.md +113 -0
- package/dist/commands/ai-agents.d.ts +8 -0
- package/dist/commands/ai-agents.js +74 -0
- package/dist/commands/charts.d.ts +8 -0
- package/dist/commands/charts.js +117 -0
- package/dist/commands/dashboards.d.ts +8 -0
- package/dist/commands/dashboards.js +42 -0
- package/dist/commands/explores.d.ts +8 -0
- package/dist/commands/explores.js +56 -0
- package/dist/commands/groups.d.ts +9 -0
- package/dist/commands/groups.js +79 -0
- package/dist/commands/organization-roles.d.ts +9 -0
- package/dist/commands/organization-roles.js +106 -0
- package/dist/commands/organization.d.ts +8 -0
- package/dist/commands/organization.js +36 -0
- package/dist/commands/project-access.d.ts +8 -0
- package/dist/commands/project-access.js +69 -0
- package/dist/commands/project-role-assignments.d.ts +8 -0
- package/dist/commands/project-role-assignments.js +102 -0
- package/dist/commands/projects.d.ts +8 -0
- package/dist/commands/projects.js +55 -0
- package/dist/commands/query.d.ts +8 -0
- package/dist/commands/query.js +86 -0
- package/dist/commands/spaces.d.ts +8 -0
- package/dist/commands/spaces.js +54 -0
- package/dist/commands/users.d.ts +9 -0
- package/dist/commands/users.js +74 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +38 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +159 -0
- package/dist/utils/client.d.ts +11 -0
- package/dist/utils/client.js +16 -0
- package/dist/utils/client.test.d.ts +1 -0
- package/dist/utils/client.test.js +30 -0
- package/package.json +24 -0
- package/src/commands/ai-agents.ts +72 -0
- package/src/commands/charts.ts +125 -0
- package/src/commands/dashboards.ts +37 -0
- package/src/commands/explores.ts +54 -0
- package/src/commands/groups.ts +84 -0
- package/src/commands/organization-roles.ts +109 -0
- package/src/commands/organization.ts +30 -0
- package/src/commands/project-access.ts +70 -0
- package/src/commands/project-role-assignments.ts +117 -0
- package/src/commands/projects.ts +52 -0
- package/src/commands/query.ts +83 -0
- package/src/commands/spaces.ts +52 -0
- package/src/commands/users.ts +73 -0
- package/src/index.test.ts +192 -0
- package/src/index.ts +41 -0
- package/src/utils/client.test.ts +37 -0
- package/src/utils/client.ts +15 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Users command implementation.
|
|
3
|
+
*/
|
|
4
|
+
import type { Command } from 'commander';
|
|
5
|
+
/**
|
|
6
|
+
* Registers the users command and its subcommands.
|
|
7
|
+
* Uses client.v1.users (typed client) per ADR-0010 and OpenSpec cli-parity-with-client.
|
|
8
|
+
*/
|
|
9
|
+
export declare function registerUsersCommand(program: Command): void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Users command implementation.
|
|
4
|
+
*/
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.registerUsersCommand = registerUsersCommand;
|
|
16
|
+
const client_1 = require("../utils/client");
|
|
17
|
+
/**
|
|
18
|
+
* Registers the users command and its subcommands.
|
|
19
|
+
* Uses client.v1.users (typed client) per ADR-0010 and OpenSpec cli-parity-with-client.
|
|
20
|
+
*/
|
|
21
|
+
function registerUsersCommand(program) {
|
|
22
|
+
const usersCmd = program.command('users').description('Manage users');
|
|
23
|
+
usersCmd
|
|
24
|
+
.command('list')
|
|
25
|
+
.description('List all users in the current organization')
|
|
26
|
+
.option('--all', 'Fetch all pages and output the full list')
|
|
27
|
+
.option('--page <number>', 'Page number (1-based)', (v) => parseInt(v, 10))
|
|
28
|
+
.option('--page-size <number>', 'Page size', (v) => parseInt(v, 10))
|
|
29
|
+
.option('--search <query>', 'Search query')
|
|
30
|
+
.action(function () {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const options = this.opts();
|
|
33
|
+
try {
|
|
34
|
+
const client = (0, client_1.getClient)();
|
|
35
|
+
if (options.all) {
|
|
36
|
+
const listParams = {};
|
|
37
|
+
if (options.search != null)
|
|
38
|
+
listParams.searchQuery = options.search;
|
|
39
|
+
const list = yield client.v1.users.listAllMembers(Object.keys(listParams).length > 0 ? listParams : undefined);
|
|
40
|
+
console.log(JSON.stringify(list, null, 2));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const params = {};
|
|
44
|
+
if (options.page != null)
|
|
45
|
+
params.page = options.page;
|
|
46
|
+
if (options.pageSize != null)
|
|
47
|
+
params.pageSize = options.pageSize;
|
|
48
|
+
if (options.search != null)
|
|
49
|
+
params.searchQuery = options.search;
|
|
50
|
+
const result = yield client.v1.users.listMembers(Object.keys(params).length > 0 ? params : undefined);
|
|
51
|
+
console.log(JSON.stringify(result, null, 2));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error('Error listing users:', error instanceof Error ? error.message : String(error));
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
usersCmd
|
|
61
|
+
.command('get <userUuid>')
|
|
62
|
+
.description('Get a user by UUID')
|
|
63
|
+
.action((userUuid) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
try {
|
|
65
|
+
const client = (0, client_1.getClient)();
|
|
66
|
+
const member = yield client.v1.users.getMemberByUuid(userUuid);
|
|
67
|
+
console.log(JSON.stringify(member, null, 2));
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error('Error fetching user:', error instanceof Error ? error.message : String(error));
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* Main entry point for Lightdash AI CLI.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const organization_1 = require("./commands/organization");
|
|
9
|
+
const organization_roles_1 = require("./commands/organization-roles");
|
|
10
|
+
const projects_1 = require("./commands/projects");
|
|
11
|
+
const project_role_assignments_1 = require("./commands/project-role-assignments");
|
|
12
|
+
const project_access_1 = require("./commands/project-access");
|
|
13
|
+
const spaces_1 = require("./commands/spaces");
|
|
14
|
+
const charts_1 = require("./commands/charts");
|
|
15
|
+
const dashboards_1 = require("./commands/dashboards");
|
|
16
|
+
const ai_agents_1 = require("./commands/ai-agents");
|
|
17
|
+
const groups_1 = require("./commands/groups");
|
|
18
|
+
const users_1 = require("./commands/users");
|
|
19
|
+
const query_1 = require("./commands/query");
|
|
20
|
+
const explores_1 = require("./commands/explores");
|
|
21
|
+
const program = new commander_1.Command();
|
|
22
|
+
program.name('lightdash-ai').description('CLI for Lightdash AI').version('1.0.0');
|
|
23
|
+
// Register all commands (organization and projects first so subcommands can attach)
|
|
24
|
+
(0, organization_1.registerOrganizationCommand)(program);
|
|
25
|
+
(0, organization_roles_1.registerOrganizationRolesCommand)(program);
|
|
26
|
+
(0, projects_1.registerProjectsCommand)(program);
|
|
27
|
+
(0, project_role_assignments_1.registerProjectRoleAssignmentsCommand)(program);
|
|
28
|
+
(0, project_access_1.registerProjectAccessCommand)(program);
|
|
29
|
+
(0, spaces_1.registerSpacesCommand)(program);
|
|
30
|
+
(0, charts_1.registerChartsCommand)(program);
|
|
31
|
+
(0, dashboards_1.registerDashboardsCommand)(program);
|
|
32
|
+
(0, ai_agents_1.registerAiAgentsCommand)(program);
|
|
33
|
+
(0, groups_1.registerGroupsCommand)(program);
|
|
34
|
+
(0, users_1.registerUsersCommand)(program);
|
|
35
|
+
(0, query_1.registerQueryCommand)(program);
|
|
36
|
+
(0, explores_1.registerExploresCommand)(program);
|
|
37
|
+
// Parse command line arguments
|
|
38
|
+
program.parse(process.argv);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const organization_1 = require("./commands/organization");
|
|
6
|
+
const organization_roles_1 = require("./commands/organization-roles");
|
|
7
|
+
const projects_1 = require("./commands/projects");
|
|
8
|
+
const project_role_assignments_1 = require("./commands/project-role-assignments");
|
|
9
|
+
const project_access_1 = require("./commands/project-access");
|
|
10
|
+
const spaces_1 = require("./commands/spaces");
|
|
11
|
+
const charts_1 = require("./commands/charts");
|
|
12
|
+
const dashboards_1 = require("./commands/dashboards");
|
|
13
|
+
const ai_agents_1 = require("./commands/ai-agents");
|
|
14
|
+
const groups_1 = require("./commands/groups");
|
|
15
|
+
const users_1 = require("./commands/users");
|
|
16
|
+
const explores_1 = require("./commands/explores");
|
|
17
|
+
(0, vitest_1.describe)('CLI Command Registration', () => {
|
|
18
|
+
(0, vitest_1.it)('should register organization command', () => {
|
|
19
|
+
const program = new commander_1.Command();
|
|
20
|
+
(0, organization_1.registerOrganizationCommand)(program);
|
|
21
|
+
const orgCmd = program.commands.find((cmd) => cmd.name() === 'organization');
|
|
22
|
+
(0, vitest_1.expect)(orgCmd).toBeDefined();
|
|
23
|
+
const getCmd = orgCmd === null || orgCmd === void 0 ? void 0 : orgCmd.commands.find((cmd) => cmd.name() === 'get');
|
|
24
|
+
(0, vitest_1.expect)(getCmd).toBeDefined();
|
|
25
|
+
});
|
|
26
|
+
(0, vitest_1.it)('should register projects command with get and list subcommands', () => {
|
|
27
|
+
const program = new commander_1.Command();
|
|
28
|
+
(0, projects_1.registerProjectsCommand)(program);
|
|
29
|
+
const projectsCmd = program.commands.find((cmd) => cmd.name() === 'projects');
|
|
30
|
+
(0, vitest_1.expect)(projectsCmd).toBeDefined();
|
|
31
|
+
const getCmd = projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.find((cmd) => cmd.name() === 'get');
|
|
32
|
+
(0, vitest_1.expect)(getCmd).toBeDefined();
|
|
33
|
+
const listCmd = projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.find((cmd) => cmd.name() === 'list');
|
|
34
|
+
(0, vitest_1.expect)(listCmd).toBeDefined();
|
|
35
|
+
});
|
|
36
|
+
(0, vitest_1.it)('should register groups command with list and get subcommands', () => {
|
|
37
|
+
const program = new commander_1.Command();
|
|
38
|
+
(0, groups_1.registerGroupsCommand)(program);
|
|
39
|
+
const groupsCmd = program.commands.find((cmd) => cmd.name() === 'groups');
|
|
40
|
+
(0, vitest_1.expect)(groupsCmd).toBeDefined();
|
|
41
|
+
const listCmd = groupsCmd === null || groupsCmd === void 0 ? void 0 : groupsCmd.commands.find((cmd) => cmd.name() === 'list');
|
|
42
|
+
(0, vitest_1.expect)(listCmd).toBeDefined();
|
|
43
|
+
const getCmd = groupsCmd === null || groupsCmd === void 0 ? void 0 : groupsCmd.commands.find((cmd) => cmd.name() === 'get');
|
|
44
|
+
(0, vitest_1.expect)(getCmd).toBeDefined();
|
|
45
|
+
});
|
|
46
|
+
(0, vitest_1.it)('should register users list with --all option', () => {
|
|
47
|
+
const program = new commander_1.Command();
|
|
48
|
+
(0, users_1.registerUsersCommand)(program);
|
|
49
|
+
const usersCmd = program.commands.find((cmd) => cmd.name() === 'users');
|
|
50
|
+
const listCmd = usersCmd === null || usersCmd === void 0 ? void 0 : usersCmd.commands.find((cmd) => cmd.name() === 'list');
|
|
51
|
+
(0, vitest_1.expect)(listCmd).toBeDefined();
|
|
52
|
+
const allOpt = listCmd === null || listCmd === void 0 ? void 0 : listCmd.options.find((opt) => opt.long === '--all');
|
|
53
|
+
(0, vitest_1.expect)(allOpt).toBeDefined();
|
|
54
|
+
});
|
|
55
|
+
(0, vitest_1.it)('should register groups list with --all option', () => {
|
|
56
|
+
const program = new commander_1.Command();
|
|
57
|
+
(0, groups_1.registerGroupsCommand)(program);
|
|
58
|
+
const groupsCmd = program.commands.find((cmd) => cmd.name() === 'groups');
|
|
59
|
+
const listCmd = groupsCmd === null || groupsCmd === void 0 ? void 0 : groupsCmd.commands.find((cmd) => cmd.name() === 'list');
|
|
60
|
+
(0, vitest_1.expect)(listCmd).toBeDefined();
|
|
61
|
+
const allOpt = listCmd === null || listCmd === void 0 ? void 0 : listCmd.options.find((opt) => opt.long === '--all');
|
|
62
|
+
(0, vitest_1.expect)(allOpt).toBeDefined();
|
|
63
|
+
});
|
|
64
|
+
(0, vitest_1.it)('should register users command with list and get subcommands', () => {
|
|
65
|
+
const program = new commander_1.Command();
|
|
66
|
+
(0, users_1.registerUsersCommand)(program);
|
|
67
|
+
const usersCmd = program.commands.find((cmd) => cmd.name() === 'users');
|
|
68
|
+
(0, vitest_1.expect)(usersCmd).toBeDefined();
|
|
69
|
+
const listCmd = usersCmd === null || usersCmd === void 0 ? void 0 : usersCmd.commands.find((cmd) => cmd.name() === 'list');
|
|
70
|
+
(0, vitest_1.expect)(listCmd).toBeDefined();
|
|
71
|
+
const getCmd = usersCmd === null || usersCmd === void 0 ? void 0 : usersCmd.commands.find((cmd) => cmd.name() === 'get');
|
|
72
|
+
(0, vitest_1.expect)(getCmd).toBeDefined();
|
|
73
|
+
});
|
|
74
|
+
(0, vitest_1.it)('should register organization roles subcommands', () => {
|
|
75
|
+
const program = new commander_1.Command();
|
|
76
|
+
(0, organization_1.registerOrganizationCommand)(program);
|
|
77
|
+
(0, organization_roles_1.registerOrganizationRolesCommand)(program);
|
|
78
|
+
const orgCmd = program.commands.find((cmd) => cmd.name() === 'organization');
|
|
79
|
+
const rolesCmd = orgCmd === null || orgCmd === void 0 ? void 0 : orgCmd.commands.find((cmd) => cmd.name() === 'roles');
|
|
80
|
+
(0, vitest_1.expect)(rolesCmd).toBeDefined();
|
|
81
|
+
(0, vitest_1.expect)(rolesCmd === null || rolesCmd === void 0 ? void 0 : rolesCmd.commands.some((c) => c.name() === 'list')).toBe(true);
|
|
82
|
+
(0, vitest_1.expect)(rolesCmd === null || rolesCmd === void 0 ? void 0 : rolesCmd.commands.some((c) => c.name() === 'get')).toBe(true);
|
|
83
|
+
(0, vitest_1.expect)(rolesCmd === null || rolesCmd === void 0 ? void 0 : rolesCmd.commands.some((c) => c.name() === 'assign')).toBe(true);
|
|
84
|
+
});
|
|
85
|
+
(0, vitest_1.it)('should register projects roles, access, spaces subcommands', () => {
|
|
86
|
+
const program = new commander_1.Command();
|
|
87
|
+
(0, projects_1.registerProjectsCommand)(program);
|
|
88
|
+
(0, project_role_assignments_1.registerProjectRoleAssignmentsCommand)(program);
|
|
89
|
+
(0, project_access_1.registerProjectAccessCommand)(program);
|
|
90
|
+
(0, spaces_1.registerSpacesCommand)(program);
|
|
91
|
+
const projectsCmd = program.commands.find((cmd) => cmd.name() === 'projects');
|
|
92
|
+
(0, vitest_1.expect)(projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.some((c) => c.name() === 'roles')).toBe(true);
|
|
93
|
+
(0, vitest_1.expect)(projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.some((c) => c.name() === 'access')).toBe(true);
|
|
94
|
+
(0, vitest_1.expect)(projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.some((c) => c.name() === 'spaces')).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
(0, vitest_1.it)('should register projects charts and dashboards subcommands', () => {
|
|
97
|
+
const program = new commander_1.Command();
|
|
98
|
+
(0, projects_1.registerProjectsCommand)(program);
|
|
99
|
+
(0, charts_1.registerChartsCommand)(program);
|
|
100
|
+
(0, dashboards_1.registerDashboardsCommand)(program);
|
|
101
|
+
const projectsCmd = program.commands.find((cmd) => cmd.name() === 'projects');
|
|
102
|
+
(0, vitest_1.expect)(projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.some((c) => c.name() === 'charts')).toBe(true);
|
|
103
|
+
(0, vitest_1.expect)(projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.some((c) => c.name() === 'dashboards')).toBe(true);
|
|
104
|
+
});
|
|
105
|
+
(0, vitest_1.it)('should register projects charts code list and upsert subcommands', () => {
|
|
106
|
+
const program = new commander_1.Command();
|
|
107
|
+
(0, projects_1.registerProjectsCommand)(program);
|
|
108
|
+
(0, charts_1.registerChartsCommand)(program);
|
|
109
|
+
const projectsCmd = program.commands.find((cmd) => cmd.name() === 'projects');
|
|
110
|
+
const chartsCmd = projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.find((cmd) => cmd.name() === 'charts');
|
|
111
|
+
(0, vitest_1.expect)(chartsCmd).toBeDefined();
|
|
112
|
+
const codeCmd = chartsCmd === null || chartsCmd === void 0 ? void 0 : chartsCmd.commands.find((cmd) => cmd.name() === 'code');
|
|
113
|
+
(0, vitest_1.expect)(codeCmd).toBeDefined();
|
|
114
|
+
(0, vitest_1.expect)(codeCmd === null || codeCmd === void 0 ? void 0 : codeCmd.commands.some((c) => c.name() === 'list')).toBe(true);
|
|
115
|
+
(0, vitest_1.expect)(codeCmd === null || codeCmd === void 0 ? void 0 : codeCmd.commands.some((c) => c.name() === 'upsert')).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
(0, vitest_1.it)('should register projects explores subcommands', () => {
|
|
118
|
+
const program = new commander_1.Command();
|
|
119
|
+
(0, projects_1.registerProjectsCommand)(program);
|
|
120
|
+
(0, explores_1.registerExploresCommand)(program);
|
|
121
|
+
const projectsCmd = program.commands.find((cmd) => cmd.name() === 'projects');
|
|
122
|
+
const exploresCmd = projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.find((cmd) => cmd.name() === 'explores');
|
|
123
|
+
(0, vitest_1.expect)(exploresCmd).toBeDefined();
|
|
124
|
+
(0, vitest_1.expect)(exploresCmd === null || exploresCmd === void 0 ? void 0 : exploresCmd.commands.some((c) => c.name() === 'list')).toBe(true);
|
|
125
|
+
(0, vitest_1.expect)(exploresCmd === null || exploresCmd === void 0 ? void 0 : exploresCmd.commands.some((c) => c.name() === 'get')).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
(0, vitest_1.it)('should register ai-agents command with list, threads, settings', () => {
|
|
128
|
+
const program = new commander_1.Command();
|
|
129
|
+
(0, ai_agents_1.registerAiAgentsCommand)(program);
|
|
130
|
+
const aiAgentsCmd = program.commands.find((cmd) => cmd.name() === 'ai-agents');
|
|
131
|
+
(0, vitest_1.expect)(aiAgentsCmd).toBeDefined();
|
|
132
|
+
(0, vitest_1.expect)(aiAgentsCmd === null || aiAgentsCmd === void 0 ? void 0 : aiAgentsCmd.commands.some((c) => c.name() === 'list')).toBe(true);
|
|
133
|
+
(0, vitest_1.expect)(aiAgentsCmd === null || aiAgentsCmd === void 0 ? void 0 : aiAgentsCmd.commands.some((c) => c.name() === 'threads')).toBe(true);
|
|
134
|
+
(0, vitest_1.expect)(aiAgentsCmd === null || aiAgentsCmd === void 0 ? void 0 : aiAgentsCmd.commands.some((c) => c.name() === 'settings')).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
(0, vitest_1.it)('should register all commands on a program', () => {
|
|
137
|
+
const program = new commander_1.Command();
|
|
138
|
+
(0, organization_1.registerOrganizationCommand)(program);
|
|
139
|
+
(0, organization_roles_1.registerOrganizationRolesCommand)(program);
|
|
140
|
+
(0, projects_1.registerProjectsCommand)(program);
|
|
141
|
+
(0, project_role_assignments_1.registerProjectRoleAssignmentsCommand)(program);
|
|
142
|
+
(0, project_access_1.registerProjectAccessCommand)(program);
|
|
143
|
+
(0, spaces_1.registerSpacesCommand)(program);
|
|
144
|
+
(0, charts_1.registerChartsCommand)(program);
|
|
145
|
+
(0, dashboards_1.registerDashboardsCommand)(program);
|
|
146
|
+
(0, ai_agents_1.registerAiAgentsCommand)(program);
|
|
147
|
+
(0, groups_1.registerGroupsCommand)(program);
|
|
148
|
+
(0, users_1.registerUsersCommand)(program);
|
|
149
|
+
(0, explores_1.registerExploresCommand)(program);
|
|
150
|
+
(0, vitest_1.expect)(program.commands).toHaveLength(5);
|
|
151
|
+
(0, vitest_1.expect)(program.commands.map((cmd) => cmd.name()).sort()).toEqual([
|
|
152
|
+
'ai-agents',
|
|
153
|
+
'groups',
|
|
154
|
+
'organization',
|
|
155
|
+
'projects',
|
|
156
|
+
'users',
|
|
157
|
+
]);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client utility for initializing LightdashClient from environment variables.
|
|
3
|
+
*/
|
|
4
|
+
import { LightdashClient } from '@lightdash-tools/client';
|
|
5
|
+
/**
|
|
6
|
+
* Gets a LightdashClient instance initialized from environment variables.
|
|
7
|
+
* Uses LIGHTDASH_URL and LIGHTDASH_API_KEY environment variables.
|
|
8
|
+
*
|
|
9
|
+
* @throws Error if required environment variables are missing
|
|
10
|
+
*/
|
|
11
|
+
export declare function getClient(): LightdashClient;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Client utility for initializing LightdashClient from environment variables.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getClient = getClient;
|
|
7
|
+
const client_1 = require("@lightdash-tools/client");
|
|
8
|
+
/**
|
|
9
|
+
* Gets a LightdashClient instance initialized from environment variables.
|
|
10
|
+
* Uses LIGHTDASH_URL and LIGHTDASH_API_KEY environment variables.
|
|
11
|
+
*
|
|
12
|
+
* @throws Error if required environment variables are missing
|
|
13
|
+
*/
|
|
14
|
+
function getClient() {
|
|
15
|
+
return new client_1.LightdashClient(); // Uses env vars automatically
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
(0, vitest_1.describe)('getClient', () => {
|
|
6
|
+
const originalEnv = process.env;
|
|
7
|
+
(0, vitest_1.beforeEach)(() => {
|
|
8
|
+
process.env = Object.assign({}, originalEnv);
|
|
9
|
+
});
|
|
10
|
+
(0, vitest_1.afterEach)(() => {
|
|
11
|
+
process.env = originalEnv;
|
|
12
|
+
});
|
|
13
|
+
(0, vitest_1.it)('should create a client instance', () => {
|
|
14
|
+
process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
|
|
15
|
+
process.env.LIGHTDASH_API_KEY = 'test-token';
|
|
16
|
+
const client = (0, client_1.getClient)();
|
|
17
|
+
(0, vitest_1.expect)(client).toBeDefined();
|
|
18
|
+
(0, vitest_1.expect)(client.v1).toBeDefined();
|
|
19
|
+
});
|
|
20
|
+
(0, vitest_1.it)('should throw error when LIGHTDASH_URL is missing', () => {
|
|
21
|
+
delete process.env.LIGHTDASH_URL;
|
|
22
|
+
process.env.LIGHTDASH_API_KEY = 'test-token';
|
|
23
|
+
(0, vitest_1.expect)(() => (0, client_1.getClient)()).toThrow();
|
|
24
|
+
});
|
|
25
|
+
(0, vitest_1.it)('should throw error when LIGHTDASH_API_KEY is missing', () => {
|
|
26
|
+
process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
|
|
27
|
+
delete process.env.LIGHTDASH_API_KEY;
|
|
28
|
+
(0, vitest_1.expect)(() => (0, client_1.getClient)()).toThrow();
|
|
29
|
+
});
|
|
30
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lightdash-tools/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI for Lightdash AI.",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"author": "",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"bin": {
|
|
11
|
+
"lightdash-tools": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"commander": "^14.0.3",
|
|
15
|
+
"@lightdash-tools/client": "0.1.0",
|
|
16
|
+
"@lightdash-tools/common": "0.1.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^25.2.3"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI agents (v1) command implementation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Command } from 'commander';
|
|
6
|
+
import { getClient } from '../utils/client';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers the top-level ai-agents command and its subcommands.
|
|
10
|
+
*/
|
|
11
|
+
export function registerAiAgentsCommand(program: Command): void {
|
|
12
|
+
const aiAgentsCmd = program.command('ai-agents').description('Manage AI agents (admin, v1)');
|
|
13
|
+
|
|
14
|
+
aiAgentsCmd
|
|
15
|
+
.command('list')
|
|
16
|
+
.description('List all AI agents (admin)')
|
|
17
|
+
.action(async () => {
|
|
18
|
+
try {
|
|
19
|
+
const client = getClient();
|
|
20
|
+
const result = await client.v1.aiAgents.listAdminAgents();
|
|
21
|
+
console.log(JSON.stringify(result, null, 2));
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error(
|
|
24
|
+
'Error listing AI agents:',
|
|
25
|
+
error instanceof Error ? error.message : String(error),
|
|
26
|
+
);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
aiAgentsCmd
|
|
32
|
+
.command('threads')
|
|
33
|
+
.description('List AI agent threads (admin)')
|
|
34
|
+
.option('--page <number>', 'Page number', (v: string) => parseInt(v, 10))
|
|
35
|
+
.option('--page-size <number>', 'Page size', (v: string) => parseInt(v, 10))
|
|
36
|
+
.action(async function (this: Command) {
|
|
37
|
+
const options = this.opts() as { page?: number; pageSize?: number };
|
|
38
|
+
try {
|
|
39
|
+
const client = getClient();
|
|
40
|
+
const params: { page?: number; pageSize?: number } = {};
|
|
41
|
+
if (options.page != null) params.page = options.page;
|
|
42
|
+
if (options.pageSize != null) params.pageSize = options.pageSize;
|
|
43
|
+
const result = await client.v1.aiAgents.getAdminThreads(
|
|
44
|
+
Object.keys(params).length > 0 ? params : undefined,
|
|
45
|
+
);
|
|
46
|
+
console.log(JSON.stringify(result, null, 2));
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error(
|
|
49
|
+
'Error listing AI agent threads:',
|
|
50
|
+
error instanceof Error ? error.message : String(error),
|
|
51
|
+
);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
aiAgentsCmd
|
|
57
|
+
.command('settings')
|
|
58
|
+
.description('Get AI organization settings')
|
|
59
|
+
.action(async () => {
|
|
60
|
+
try {
|
|
61
|
+
const client = getClient();
|
|
62
|
+
const result = await client.v1.aiAgents.getAiOrganizationSettings();
|
|
63
|
+
console.log(JSON.stringify(result, null, 2));
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error(
|
|
66
|
+
'Error fetching AI organization settings:',
|
|
67
|
+
error instanceof Error ? error.message : String(error),
|
|
68
|
+
);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Charts (v1) command implementation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Command } from 'commander';
|
|
6
|
+
import { readFileSync } from 'fs';
|
|
7
|
+
import { getClient } from '../utils/client';
|
|
8
|
+
import type { UpsertChartAsCodeBody } from '@lightdash-tools/common';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Reads JSON from stdin or a file (for chart-as-code upsert body).
|
|
12
|
+
*/
|
|
13
|
+
async function readChartJsonInput(filePath?: string): Promise<UpsertChartAsCodeBody> {
|
|
14
|
+
if (filePath) {
|
|
15
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
16
|
+
return JSON.parse(content) as UpsertChartAsCodeBody;
|
|
17
|
+
}
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
if (process.stdin.isTTY) {
|
|
20
|
+
reject(new Error('No input provided. Use --file <path> or pipe JSON to stdin.'));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const chunks: Buffer[] = [];
|
|
24
|
+
process.stdin.setEncoding('utf8');
|
|
25
|
+
process.stdin.on('data', (chunk) => {
|
|
26
|
+
chunks.push(Buffer.from(chunk));
|
|
27
|
+
});
|
|
28
|
+
process.stdin.on('end', () => {
|
|
29
|
+
try {
|
|
30
|
+
const input = Buffer.concat(chunks).toString('utf-8');
|
|
31
|
+
resolve(JSON.parse(input) as UpsertChartAsCodeBody);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
reject(
|
|
34
|
+
new Error(`Failed to parse JSON: ${err instanceof Error ? err.message : String(err)}`),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
process.stdin.on('error', (err) => {
|
|
39
|
+
reject(err);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Registers the projects charts subcommands under the existing projects command.
|
|
46
|
+
*/
|
|
47
|
+
export function registerChartsCommand(program: Command): void {
|
|
48
|
+
const projectsCmd = program.commands.find((c) => c.name() === 'projects');
|
|
49
|
+
if (!projectsCmd) {
|
|
50
|
+
throw new Error('projects command must be registered before charts');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const chartsCmd = projectsCmd
|
|
54
|
+
.command('charts')
|
|
55
|
+
.description('List project charts and charts-as-code operations (v1)');
|
|
56
|
+
|
|
57
|
+
chartsCmd
|
|
58
|
+
.command('list <projectUuid>')
|
|
59
|
+
.description('List charts in a project')
|
|
60
|
+
.action(async (projectUuid: string) => {
|
|
61
|
+
try {
|
|
62
|
+
const client = getClient();
|
|
63
|
+
const result = await client.v1.charts.listCharts(projectUuid);
|
|
64
|
+
console.log(JSON.stringify(result, null, 2));
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error(
|
|
67
|
+
'Error listing charts:',
|
|
68
|
+
error instanceof Error ? error.message : String(error),
|
|
69
|
+
);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const codeCmd = chartsCmd
|
|
75
|
+
.command('code')
|
|
76
|
+
.description('Charts as code (get list, upsert by slug)');
|
|
77
|
+
|
|
78
|
+
codeCmd
|
|
79
|
+
.command('list <projectUuid>')
|
|
80
|
+
.description('Get charts in code representation')
|
|
81
|
+
.option('--ids <ids...>', 'Filter by chart IDs (slugs)')
|
|
82
|
+
.option('--offset <number>', 'Pagination offset', (v) => parseInt(v, 10))
|
|
83
|
+
.option('--language-map', 'Include language map in response')
|
|
84
|
+
.action(
|
|
85
|
+
async (
|
|
86
|
+
projectUuid: string,
|
|
87
|
+
options: { ids?: string[]; offset?: number; languageMap?: boolean },
|
|
88
|
+
) => {
|
|
89
|
+
try {
|
|
90
|
+
const client = getClient();
|
|
91
|
+
const result = await client.v1.charts.getChartsAsCode(projectUuid, {
|
|
92
|
+
ids: options.ids,
|
|
93
|
+
offset: options.offset,
|
|
94
|
+
languageMap: options.languageMap,
|
|
95
|
+
});
|
|
96
|
+
console.log(JSON.stringify(result, null, 2));
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error(
|
|
99
|
+
'Error getting charts as code:',
|
|
100
|
+
error instanceof Error ? error.message : String(error),
|
|
101
|
+
);
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
codeCmd
|
|
108
|
+
.command('upsert <projectUuid> <slug>')
|
|
109
|
+
.description('Upsert a chart from code (body from --file or stdin)')
|
|
110
|
+
.option('--file <path>', 'Read chart JSON from file (default: stdin)')
|
|
111
|
+
.action(async (projectUuid: string, slug: string, options: { file?: string }) => {
|
|
112
|
+
try {
|
|
113
|
+
const body = await readChartJsonInput(options.file);
|
|
114
|
+
const client = getClient();
|
|
115
|
+
const result = await client.v1.charts.upsertChartAsCode(projectUuid, slug, body);
|
|
116
|
+
console.log(JSON.stringify(result, null, 2));
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error(
|
|
119
|
+
'Error upserting chart as code:',
|
|
120
|
+
error instanceof Error ? error.message : String(error),
|
|
121
|
+
);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dashboards (v1) command implementation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Command } from 'commander';
|
|
6
|
+
import { getClient } from '../utils/client';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers the projects dashboards subcommands under the existing projects command.
|
|
10
|
+
*/
|
|
11
|
+
export function registerDashboardsCommand(program: Command): void {
|
|
12
|
+
const projectsCmd = program.commands.find((c) => c.name() === 'projects');
|
|
13
|
+
if (!projectsCmd) {
|
|
14
|
+
throw new Error('projects command must be registered before dashboards');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const dashboardsCmd = projectsCmd
|
|
18
|
+
.command('dashboards')
|
|
19
|
+
.description('List project dashboards (v1)');
|
|
20
|
+
|
|
21
|
+
dashboardsCmd
|
|
22
|
+
.command('list <projectUuid>')
|
|
23
|
+
.description('List dashboards in a project')
|
|
24
|
+
.action(async (projectUuid: string) => {
|
|
25
|
+
try {
|
|
26
|
+
const client = getClient();
|
|
27
|
+
const result = await client.v1.dashboards.listDashboards(projectUuid);
|
|
28
|
+
console.log(JSON.stringify(result, null, 2));
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error(
|
|
31
|
+
'Error listing dashboards:',
|
|
32
|
+
error instanceof Error ? error.message : String(error),
|
|
33
|
+
);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|