@lightdash-tools/cli 0.1.2 → 0.2.1

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.
Files changed (48) hide show
  1. package/README.md +49 -1
  2. package/dist/commands/ai-agents.js +8 -6
  3. package/dist/commands/charts.js +8 -6
  4. package/dist/commands/content.d.ts +8 -0
  5. package/dist/commands/content.js +48 -0
  6. package/dist/commands/dashboards.js +4 -2
  7. package/dist/commands/explores.js +34 -4
  8. package/dist/commands/groups.js +6 -4
  9. package/dist/commands/metrics.d.ts +8 -0
  10. package/dist/commands/metrics.js +59 -0
  11. package/dist/commands/organization-roles.js +10 -8
  12. package/dist/commands/organization.js +4 -2
  13. package/dist/commands/project-access.js +8 -6
  14. package/dist/commands/project-role-assignments.js +12 -10
  15. package/dist/commands/projects.js +38 -4
  16. package/dist/commands/query.js +4 -2
  17. package/dist/commands/schedulers.d.ts +8 -0
  18. package/dist/commands/schedulers.js +59 -0
  19. package/dist/commands/spaces.js +6 -4
  20. package/dist/commands/tags.d.ts +8 -0
  21. package/dist/commands/tags.js +52 -0
  22. package/dist/commands/users.js +6 -4
  23. package/dist/index.js +13 -1
  24. package/dist/utils/safety.d.ts +11 -0
  25. package/dist/utils/safety.js +39 -0
  26. package/dist/utils/safety.test.d.ts +1 -0
  27. package/dist/utils/safety.test.js +50 -0
  28. package/package.json +3 -3
  29. package/src/commands/ai-agents.ts +53 -45
  30. package/src/commands/charts.ts +59 -47
  31. package/src/commands/content.ts +55 -0
  32. package/src/commands/dashboards.ts +17 -13
  33. package/src/commands/explores.ts +77 -26
  34. package/src/commands/groups.ts +59 -53
  35. package/src/commands/metrics.ts +69 -0
  36. package/src/commands/organization-roles.ts +78 -68
  37. package/src/commands/organization.ts +17 -13
  38. package/src/commands/project-access.ts +50 -39
  39. package/src/commands/project-role-assignments.ts +87 -75
  40. package/src/commands/projects.ts +77 -28
  41. package/src/commands/query.ts +30 -23
  42. package/src/commands/schedulers.ts +66 -0
  43. package/src/commands/spaces.ts +32 -26
  44. package/src/commands/tags.ts +53 -0
  45. package/src/commands/users.ts +51 -45
  46. package/src/index.ts +17 -1
  47. package/src/utils/safety.test.ts +53 -0
  48. package/src/utils/safety.ts +33 -0
@@ -13,7 +13,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.registerProjectRoleAssignmentsCommand = registerProjectRoleAssignmentsCommand;
16
+ const common_1 = require("@lightdash-tools/common");
16
17
  const client_1 = require("../utils/client");
18
+ const safety_1 = require("../utils/safety");
17
19
  /**
18
20
  * Registers the projects roles subcommands under the existing projects command.
19
21
  */
@@ -26,7 +28,7 @@ function registerProjectRoleAssignmentsCommand(program) {
26
28
  rolesCmd
27
29
  .command('list <projectUuid>')
28
30
  .description('List project role assignments')
29
- .action((projectUuid) => __awaiter(this, void 0, void 0, function* () {
31
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, (projectUuid) => __awaiter(this, void 0, void 0, function* () {
30
32
  try {
31
33
  const client = (0, client_1.getClient)();
32
34
  const result = yield client.v2.projectRoleAssignments.listAssignments(projectUuid);
@@ -36,13 +38,13 @@ function registerProjectRoleAssignmentsCommand(program) {
36
38
  console.error('Error listing project role assignments:', error instanceof Error ? error.message : String(error));
37
39
  process.exit(1);
38
40
  }
39
- }));
41
+ })));
40
42
  const assignCmd = rolesCmd.command('assign').description('Assign role to user or group');
41
43
  assignCmd
42
44
  .command('user <projectUuid> <userUuid>')
43
45
  .description('Assign a role to a user in a project')
44
46
  .requiredOption('--role-id <roleId>', 'Role ID to assign')
45
- .action((projectUuid, userUuid, cmd) => __awaiter(this, void 0, void 0, function* () {
47
+ .action((0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, (projectUuid, userUuid, cmd) => __awaiter(this, void 0, void 0, function* () {
46
48
  const opts = cmd.opts();
47
49
  try {
48
50
  const client = (0, client_1.getClient)();
@@ -53,12 +55,12 @@ function registerProjectRoleAssignmentsCommand(program) {
53
55
  console.error('Error assigning role to user:', error instanceof Error ? error.message : String(error));
54
56
  process.exit(1);
55
57
  }
56
- }));
58
+ })));
57
59
  assignCmd
58
60
  .command('group <projectUuid> <groupId>')
59
61
  .description('Assign a role to a group in a project')
60
62
  .requiredOption('--role-id <roleId>', 'Role ID to assign')
61
- .action((projectUuid, groupId, cmd) => __awaiter(this, void 0, void 0, function* () {
63
+ .action((0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, (projectUuid, groupId, cmd) => __awaiter(this, void 0, void 0, function* () {
62
64
  const opts = cmd.opts();
63
65
  try {
64
66
  const client = (0, client_1.getClient)();
@@ -69,12 +71,12 @@ function registerProjectRoleAssignmentsCommand(program) {
69
71
  console.error('Error assigning role to group:', error instanceof Error ? error.message : String(error));
70
72
  process.exit(1);
71
73
  }
72
- }));
74
+ })));
73
75
  const unassignCmd = rolesCmd.command('unassign').description('Remove role assignment');
74
76
  unassignCmd
75
77
  .command('user <projectUuid> <userUuid>')
76
78
  .description('Remove role assignment from a user')
77
- .action((projectUuid, userUuid) => __awaiter(this, void 0, void 0, function* () {
79
+ .action((0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, (projectUuid, userUuid) => __awaiter(this, void 0, void 0, function* () {
78
80
  try {
79
81
  const client = (0, client_1.getClient)();
80
82
  yield client.v2.projectRoleAssignments.deleteUserAssignment(projectUuid, userUuid);
@@ -84,11 +86,11 @@ function registerProjectRoleAssignmentsCommand(program) {
84
86
  console.error('Error removing user role assignment:', error instanceof Error ? error.message : String(error));
85
87
  process.exit(1);
86
88
  }
87
- }));
89
+ })));
88
90
  unassignCmd
89
91
  .command('group <projectUuid> <groupId>')
90
92
  .description('Remove role assignment from a group')
91
- .action((projectUuid, groupId) => __awaiter(this, void 0, void 0, function* () {
93
+ .action((0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, (projectUuid, groupId) => __awaiter(this, void 0, void 0, function* () {
92
94
  try {
93
95
  const client = (0, client_1.getClient)();
94
96
  yield client.v2.projectRoleAssignments.deleteGroupAssignment(projectUuid, groupId);
@@ -98,5 +100,5 @@ function registerProjectRoleAssignmentsCommand(program) {
98
100
  console.error('Error removing group role assignment:', error instanceof Error ? error.message : String(error));
99
101
  process.exit(1);
100
102
  }
101
- }));
103
+ })));
102
104
  }
@@ -13,7 +13,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.registerProjectsCommand = registerProjectsCommand;
16
+ const common_1 = require("@lightdash-tools/common");
16
17
  const client_1 = require("../utils/client");
18
+ const safety_1 = require("../utils/safety");
17
19
  /**
18
20
  * Registers the projects command and its subcommands.
19
21
  */
@@ -23,7 +25,7 @@ function registerProjectsCommand(program) {
23
25
  .command('get')
24
26
  .description('Get a project by UUID')
25
27
  .argument('<projectUuid>', 'Project UUID')
26
- .action((projectUuid) => __awaiter(this, void 0, void 0, function* () {
28
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, (projectUuid) => __awaiter(this, void 0, void 0, function* () {
27
29
  try {
28
30
  if (!projectUuid) {
29
31
  console.error('Error: projectUuid is required');
@@ -37,11 +39,11 @@ function registerProjectsCommand(program) {
37
39
  console.error('Error fetching project:', error instanceof Error ? error.message : String(error));
38
40
  process.exit(1);
39
41
  }
40
- }));
42
+ })));
41
43
  projectsCmd
42
44
  .command('list')
43
45
  .description('List all projects in the current organization')
44
- .action(() => __awaiter(this, void 0, void 0, function* () {
46
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, () => __awaiter(this, void 0, void 0, function* () {
45
47
  try {
46
48
  const client = (0, client_1.getClient)();
47
49
  const projects = yield client.v1.projects.listProjects();
@@ -51,5 +53,37 @@ function registerProjectsCommand(program) {
51
53
  console.error('Error listing projects:', error instanceof Error ? error.message : String(error));
52
54
  process.exit(1);
53
55
  }
54
- }));
56
+ })));
57
+ const validateCmd = projectsCmd.command('validate').description('Project validation');
58
+ validateCmd
59
+ .command('run <projectUuid>')
60
+ .description('Trigger project validation and get job ID')
61
+ .action((0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, (projectUuid) => __awaiter(this, void 0, void 0, function* () {
62
+ try {
63
+ const client = (0, client_1.getClient)();
64
+ const result = yield client.v1.validation.validateProject(projectUuid);
65
+ console.log(JSON.stringify(result, null, 2));
66
+ }
67
+ catch (error) {
68
+ console.error('Error triggering validation:', error instanceof Error ? error.message : String(error));
69
+ process.exit(1);
70
+ }
71
+ })));
72
+ validateCmd
73
+ .command('results <projectUuid>')
74
+ .description('Get latest validation results for a project')
75
+ .option('--job-id <id>', 'Specific validation job ID')
76
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, (projectUuid, options) => __awaiter(this, void 0, void 0, function* () {
77
+ try {
78
+ const client = (0, client_1.getClient)();
79
+ const result = yield client.v1.validation.getValidationResults(projectUuid, {
80
+ jobId: options.jobId,
81
+ });
82
+ console.log(JSON.stringify(result, null, 2));
83
+ }
84
+ catch (error) {
85
+ console.error('Error fetching validation results:', error instanceof Error ? error.message : String(error));
86
+ process.exit(1);
87
+ }
88
+ })));
55
89
  }
@@ -14,7 +14,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.registerQueryCommand = registerQueryCommand;
16
16
  const fs_1 = require("fs");
17
+ const common_1 = require("@lightdash-tools/common");
17
18
  const client_1 = require("../utils/client");
19
+ const safety_1 = require("../utils/safety");
18
20
  /**
19
21
  * Reads JSON from stdin or a file.
20
22
  */
@@ -62,7 +64,7 @@ function registerQueryCommand(program) {
62
64
  .argument('<projectUuid>', 'Project UUID')
63
65
  .argument('<exploreId>', 'Explore ID')
64
66
  .option('--file <path>', 'Read metric query JSON from file (default: read from stdin)')
65
- .action((projectUuid, exploreId, options) => __awaiter(this, void 0, void 0, function* () {
67
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, (projectUuid, exploreId, options) => __awaiter(this, void 0, void 0, function* () {
66
68
  try {
67
69
  if (!projectUuid) {
68
70
  console.error('Error: projectUuid is required');
@@ -82,5 +84,5 @@ function registerQueryCommand(program) {
82
84
  console.error('Error compiling query:', error instanceof Error ? error.message : String(error));
83
85
  process.exit(1);
84
86
  }
85
- }));
87
+ })));
86
88
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Schedulers command implementation.
3
+ */
4
+ import type { Command } from 'commander';
5
+ /**
6
+ * Registers the schedulers command and its subcommands.
7
+ */
8
+ export declare function registerSchedulersCommand(program: Command): void;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /**
3
+ * Schedulers 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.registerSchedulersCommand = registerSchedulersCommand;
16
+ const common_1 = require("@lightdash-tools/common");
17
+ const client_1 = require("../utils/client");
18
+ const safety_1 = require("../utils/safety");
19
+ /**
20
+ * Registers the schedulers command and its subcommands.
21
+ */
22
+ function registerSchedulersCommand(program) {
23
+ const schedulersCmd = program.command('schedulers').description('Manage scheduled deliveries');
24
+ schedulersCmd
25
+ .command('list <projectUuid>')
26
+ .description('List schedulers in a project')
27
+ .option('--search <query>', 'Search query')
28
+ .option('--page <number>', 'Page number', (v) => parseInt(v, 10))
29
+ .option('--page-size <number>', 'Page size', (v) => parseInt(v, 10))
30
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, (projectUuid, options) => __awaiter(this, void 0, void 0, function* () {
31
+ try {
32
+ const client = (0, client_1.getClient)();
33
+ const result = yield client.v1.schedulers.listSchedulers(projectUuid, {
34
+ searchQuery: options.search,
35
+ page: options.page,
36
+ pageSize: options.pageSize,
37
+ });
38
+ console.log(JSON.stringify(result, null, 2));
39
+ }
40
+ catch (error) {
41
+ console.error('Error listing schedulers:', error instanceof Error ? error.message : String(error));
42
+ process.exit(1);
43
+ }
44
+ })));
45
+ schedulersCmd
46
+ .command('get <schedulerUuid>')
47
+ .description('Get a scheduler by UUID')
48
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, (schedulerUuid) => __awaiter(this, void 0, void 0, function* () {
49
+ try {
50
+ const client = (0, client_1.getClient)();
51
+ const result = yield client.v1.schedulers.getScheduler(schedulerUuid);
52
+ console.log(JSON.stringify(result, null, 2));
53
+ }
54
+ catch (error) {
55
+ console.error('Error fetching scheduler:', error instanceof Error ? error.message : String(error));
56
+ process.exit(1);
57
+ }
58
+ })));
59
+ }
@@ -13,7 +13,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.registerSpacesCommand = registerSpacesCommand;
16
+ const common_1 = require("@lightdash-tools/common");
16
17
  const client_1 = require("../utils/client");
18
+ const safety_1 = require("../utils/safety");
17
19
  /**
18
20
  * Registers the projects spaces subcommands under the existing projects command.
19
21
  */
@@ -26,7 +28,7 @@ function registerSpacesCommand(program) {
26
28
  spacesCmd
27
29
  .command('list <projectUuid>')
28
30
  .description('List spaces in a project')
29
- .action((projectUuid) => __awaiter(this, void 0, void 0, function* () {
31
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, (projectUuid) => __awaiter(this, void 0, void 0, function* () {
30
32
  try {
31
33
  const client = (0, client_1.getClient)();
32
34
  const result = yield client.v1.spaces.listSpacesInProject(projectUuid);
@@ -36,11 +38,11 @@ function registerSpacesCommand(program) {
36
38
  console.error('Error listing spaces:', error instanceof Error ? error.message : String(error));
37
39
  process.exit(1);
38
40
  }
39
- }));
41
+ })));
40
42
  spacesCmd
41
43
  .command('get <projectUuid> <spaceUuid>')
42
44
  .description('Get a space by UUID')
43
- .action((projectUuid, spaceUuid) => __awaiter(this, void 0, void 0, function* () {
45
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, (projectUuid, spaceUuid) => __awaiter(this, void 0, void 0, function* () {
44
46
  try {
45
47
  const client = (0, client_1.getClient)();
46
48
  const result = yield client.v1.spaces.getSpace(projectUuid, spaceUuid);
@@ -50,5 +52,5 @@ function registerSpacesCommand(program) {
50
52
  console.error('Error fetching space:', error instanceof Error ? error.message : String(error));
51
53
  process.exit(1);
52
54
  }
53
- }));
55
+ })));
54
56
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Tags command implementation.
3
+ */
4
+ import type { Command } from 'commander';
5
+ /**
6
+ * Registers the tags command and its subcommands.
7
+ */
8
+ export declare function registerTagsCommand(program: Command): void;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ /**
3
+ * Tags 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.registerTagsCommand = registerTagsCommand;
16
+ const common_1 = require("@lightdash-tools/common");
17
+ const client_1 = require("../utils/client");
18
+ const safety_1 = require("../utils/safety");
19
+ /**
20
+ * Registers the tags command and its subcommands.
21
+ */
22
+ function registerTagsCommand(program) {
23
+ const tagsCmd = program.command('tags').description('Manage tags');
24
+ tagsCmd
25
+ .command('list <projectUuid>')
26
+ .description('List tags in a project')
27
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, (projectUuid) => __awaiter(this, void 0, void 0, function* () {
28
+ try {
29
+ const client = (0, client_1.getClient)();
30
+ const result = yield client.v1.tags.listTags(projectUuid);
31
+ console.log(JSON.stringify(result, null, 2));
32
+ }
33
+ catch (error) {
34
+ console.error('Error listing tags:', error instanceof Error ? error.message : String(error));
35
+ process.exit(1);
36
+ }
37
+ })));
38
+ tagsCmd
39
+ .command('get <projectUuid> <tagUuid>')
40
+ .description('Get a tag by UUID')
41
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, (projectUuid, tagUuid) => __awaiter(this, void 0, void 0, function* () {
42
+ try {
43
+ const client = (0, client_1.getClient)();
44
+ const result = yield client.v1.tags.getTag(projectUuid, tagUuid);
45
+ console.log(JSON.stringify(result, null, 2));
46
+ }
47
+ catch (error) {
48
+ console.error('Error fetching tag:', error instanceof Error ? error.message : String(error));
49
+ process.exit(1);
50
+ }
51
+ })));
52
+ }
@@ -13,7 +13,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.registerUsersCommand = registerUsersCommand;
16
+ const common_1 = require("@lightdash-tools/common");
16
17
  const client_1 = require("../utils/client");
18
+ const safety_1 = require("../utils/safety");
17
19
  /**
18
20
  * Registers the users command and its subcommands.
19
21
  * Uses client.v1.users (typed client) per ADR-0010 and OpenSpec cli-parity-with-client.
@@ -27,7 +29,7 @@ function registerUsersCommand(program) {
27
29
  .option('--page <number>', 'Page number (1-based)', (v) => parseInt(v, 10))
28
30
  .option('--page-size <number>', 'Page size', (v) => parseInt(v, 10))
29
31
  .option('--search <query>', 'Search query')
30
- .action(function () {
32
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, function () {
31
33
  return __awaiter(this, void 0, void 0, function* () {
32
34
  const options = this.opts();
33
35
  try {
@@ -56,11 +58,11 @@ function registerUsersCommand(program) {
56
58
  process.exit(1);
57
59
  }
58
60
  });
59
- });
61
+ }));
60
62
  usersCmd
61
63
  .command('get <userUuid>')
62
64
  .description('Get a user by UUID')
63
- .action((userUuid) => __awaiter(this, void 0, void 0, function* () {
65
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, (userUuid) => __awaiter(this, void 0, void 0, function* () {
64
66
  try {
65
67
  const client = (0, client_1.getClient)();
66
68
  const member = yield client.v1.users.getMemberByUuid(userUuid);
@@ -70,5 +72,5 @@ function registerUsersCommand(program) {
70
72
  console.error('Error fetching user:', error instanceof Error ? error.message : String(error));
71
73
  process.exit(1);
72
74
  }
73
- }));
75
+ })));
74
76
  }
package/dist/index.js CHANGED
@@ -18,8 +18,16 @@ const groups_1 = require("./commands/groups");
18
18
  const users_1 = require("./commands/users");
19
19
  const query_1 = require("./commands/query");
20
20
  const explores_1 = require("./commands/explores");
21
+ const metrics_1 = require("./commands/metrics");
22
+ const schedulers_1 = require("./commands/schedulers");
23
+ const tags_1 = require("./commands/tags");
24
+ const content_1 = require("./commands/content");
21
25
  const program = new commander_1.Command();
22
- program.name('lightdash-ai').description('CLI for Lightdash AI').version('1.0.0');
26
+ program
27
+ .name('lightdash-ai')
28
+ .description('CLI for Lightdash AI')
29
+ .version('1.0.0')
30
+ .option('--mode <mode>', 'Safety mode (read-only, write-idempotent, write-destructive)', 'write-destructive');
23
31
  // Register all commands (organization and projects first so subcommands can attach)
24
32
  (0, organization_1.registerOrganizationCommand)(program);
25
33
  (0, organization_roles_1.registerOrganizationRolesCommand)(program);
@@ -34,5 +42,9 @@ program.name('lightdash-ai').description('CLI for Lightdash AI').version('1.0.0'
34
42
  (0, users_1.registerUsersCommand)(program);
35
43
  (0, query_1.registerQueryCommand)(program);
36
44
  (0, explores_1.registerExploresCommand)(program);
45
+ (0, metrics_1.registerMetricsCommand)(program);
46
+ (0, schedulers_1.registerSchedulersCommand)(program);
47
+ (0, tags_1.registerTagsCommand)(program);
48
+ (0, content_1.registerContentCommand)(program);
37
49
  // Parse command line arguments
38
50
  program.parse(process.argv);
@@ -0,0 +1,11 @@
1
+ import { SafetyMode } from '@lightdash-tools/common';
2
+ import type { ToolAnnotations } from '@lightdash-tools/common';
3
+ import type { Command } from 'commander';
4
+ /**
5
+ * Resolves the safety mode from the command line options or environment variables.
6
+ */
7
+ export declare function getSafetyMode(cmd: Command): SafetyMode;
8
+ /**
9
+ * Wraps a CLI action with a safety check.
10
+ */
11
+ export declare function wrapAction<T extends unknown[]>(annotations: ToolAnnotations, action: (...args: T) => Promise<void> | void): (this: Command, ...args: T) => Promise<void>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getSafetyMode = getSafetyMode;
13
+ exports.wrapAction = wrapAction;
14
+ const common_1 = require("@lightdash-tools/common");
15
+ /**
16
+ * Resolves the safety mode from the command line options or environment variables.
17
+ */
18
+ function getSafetyMode(cmd) {
19
+ const options = cmd.optsWithGlobals();
20
+ if (options.mode && Object.values(common_1.SafetyMode).includes(options.mode)) {
21
+ return options.mode;
22
+ }
23
+ return (0, common_1.getSafetyModeFromEnv)();
24
+ }
25
+ /**
26
+ * Wraps a CLI action with a safety check.
27
+ */
28
+ function wrapAction(annotations, action) {
29
+ return function (...args) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const mode = getSafetyMode(this);
32
+ if (!(0, common_1.isAllowed)(mode, annotations)) {
33
+ console.error(`Error: This command is disabled in ${mode} mode. To enable it, use --mode or set LIGHTDASH_AI_MODE.`);
34
+ process.exit(1);
35
+ }
36
+ return action.apply(this, args);
37
+ });
38
+ };
39
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const vitest_1 = require("vitest");
13
+ const safety_1 = require("./safety");
14
+ const common_1 = require("@lightdash-tools/common");
15
+ const commander_1 = require("commander");
16
+ (0, vitest_1.describe)('CLI wrapAction', () => {
17
+ const mockAction = vitest_1.vi.fn().mockResolvedValue(undefined);
18
+ const consoleErrorSpy = vitest_1.vi.spyOn(console, 'error').mockImplementation(() => { });
19
+ const processExitSpy = vitest_1.vi.spyOn(process, 'exit').mockImplementation(() => {
20
+ throw new Error('exit');
21
+ });
22
+ (0, vitest_1.beforeEach)(() => {
23
+ vitest_1.vi.clearAllMocks();
24
+ });
25
+ (0, vitest_1.it)('should allow read-only action in read-only mode', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const cmd = new commander_1.Command();
27
+ cmd.setOptionValueWithSource('mode', common_1.SafetyMode.READ_ONLY, 'cli');
28
+ const wrapped = (0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, mockAction);
29
+ yield wrapped.call(cmd, 'arg1');
30
+ (0, vitest_1.expect)(mockAction).toHaveBeenCalledWith('arg1');
31
+ (0, vitest_1.expect)(processExitSpy).not.toHaveBeenCalled();
32
+ }));
33
+ (0, vitest_1.it)('should block destructive action in read-only mode', () => __awaiter(void 0, void 0, void 0, function* () {
34
+ const cmd = new commander_1.Command();
35
+ cmd.setOptionValueWithSource('mode', common_1.SafetyMode.READ_ONLY, 'cli');
36
+ const wrapped = (0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, mockAction);
37
+ yield (0, vitest_1.expect)(wrapped.call(cmd, 'arg1')).rejects.toThrow('exit');
38
+ (0, vitest_1.expect)(mockAction).not.toHaveBeenCalled();
39
+ (0, vitest_1.expect)(consoleErrorSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining('disabled in read-only mode'));
40
+ (0, vitest_1.expect)(processExitSpy).toHaveBeenCalledWith(1);
41
+ }));
42
+ (0, vitest_1.it)('should allow destructive action in write-destructive mode', () => __awaiter(void 0, void 0, void 0, function* () {
43
+ const cmd = new commander_1.Command();
44
+ cmd.setOptionValueWithSource('mode', common_1.SafetyMode.WRITE_DESTRUCTIVE, 'cli');
45
+ const wrapped = (0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, mockAction);
46
+ yield wrapped.call(cmd, 'arg1');
47
+ (0, vitest_1.expect)(mockAction).toHaveBeenCalledWith('arg1');
48
+ (0, vitest_1.expect)(processExitSpy).not.toHaveBeenCalled();
49
+ }));
50
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash-tools/cli",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "description": "CLI for Lightdash AI.",
5
5
  "keywords": [],
6
6
  "license": "Apache-2.0",
@@ -12,8 +12,8 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "commander": "^14.0.3",
15
- "@lightdash-tools/client": "0.1.2",
16
- "@lightdash-tools/common": "0.1.2"
15
+ "@lightdash-tools/client": "0.2.1",
16
+ "@lightdash-tools/common": "0.2.1"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/node": "^25.2.3"