@lightdash-tools/cli 0.1.2 → 0.2.4

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 (50) hide show
  1. package/README.md +84 -18
  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/index.test.js +6 -0
  25. package/dist/utils/safety.d.ts +11 -0
  26. package/dist/utils/safety.js +39 -0
  27. package/dist/utils/safety.test.d.ts +1 -0
  28. package/dist/utils/safety.test.js +50 -0
  29. package/package.json +3 -3
  30. package/src/commands/ai-agents.ts +53 -45
  31. package/src/commands/charts.ts +59 -47
  32. package/src/commands/content.ts +55 -0
  33. package/src/commands/dashboards.ts +17 -13
  34. package/src/commands/explores.ts +77 -26
  35. package/src/commands/groups.ts +59 -53
  36. package/src/commands/metrics.ts +69 -0
  37. package/src/commands/organization-roles.ts +78 -68
  38. package/src/commands/organization.ts +17 -13
  39. package/src/commands/project-access.ts +50 -39
  40. package/src/commands/project-role-assignments.ts +87 -75
  41. package/src/commands/projects.ts +77 -28
  42. package/src/commands/query.ts +30 -23
  43. package/src/commands/schedulers.ts +66 -0
  44. package/src/commands/spaces.ts +32 -26
  45. package/src/commands/tags.ts +53 -0
  46. package/src/commands/users.ts +51 -45
  47. package/src/index.test.ts +7 -0
  48. package/src/index.ts +17 -1
  49. package/src/utils/safety.test.ts +53 -0
  50. package/src/utils/safety.ts +33 -0
@@ -3,7 +3,9 @@
3
3
  */
4
4
 
5
5
  import type { Command } from 'commander';
6
+ import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
6
7
  import { getClient } from '../utils/client';
8
+ import { wrapAction } from '../utils/safety';
7
9
 
8
10
  /**
9
11
  * Registers the top-level ai-agents command and its subcommands.
@@ -14,59 +16,65 @@ export function registerAiAgentsCommand(program: Command): void {
14
16
  aiAgentsCmd
15
17
  .command('list')
16
18
  .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
- });
19
+ .action(
20
+ wrapAction(READ_ONLY_DEFAULT, async () => {
21
+ try {
22
+ const client = getClient();
23
+ const result = await client.v1.aiAgents.listAdminAgents();
24
+ console.log(JSON.stringify(result, null, 2));
25
+ } catch (error) {
26
+ console.error(
27
+ 'Error listing AI agents:',
28
+ error instanceof Error ? error.message : String(error),
29
+ );
30
+ process.exit(1);
31
+ }
32
+ }),
33
+ );
30
34
 
31
35
  aiAgentsCmd
32
36
  .command('threads')
33
37
  .description('List AI agent threads (admin)')
34
38
  .option('--page <number>', 'Page number', (v: string) => parseInt(v, 10))
35
39
  .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
- });
40
+ .action(
41
+ wrapAction(READ_ONLY_DEFAULT, async function (this: Command) {
42
+ const options = this.opts() as { page?: number; pageSize?: number };
43
+ try {
44
+ const client = getClient();
45
+ const params: { page?: number; pageSize?: number } = {};
46
+ if (options.page != null) params.page = options.page;
47
+ if (options.pageSize != null) params.pageSize = options.pageSize;
48
+ const result = await client.v1.aiAgents.getAdminThreads(
49
+ Object.keys(params).length > 0 ? params : undefined,
50
+ );
51
+ console.log(JSON.stringify(result, null, 2));
52
+ } catch (error) {
53
+ console.error(
54
+ 'Error listing AI agent threads:',
55
+ error instanceof Error ? error.message : String(error),
56
+ );
57
+ process.exit(1);
58
+ }
59
+ }),
60
+ );
55
61
 
56
62
  aiAgentsCmd
57
63
  .command('settings')
58
64
  .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
- });
65
+ .action(
66
+ wrapAction(READ_ONLY_DEFAULT, async () => {
67
+ try {
68
+ const client = getClient();
69
+ const result = await client.v1.aiAgents.getAiOrganizationSettings();
70
+ console.log(JSON.stringify(result, null, 2));
71
+ } catch (error) {
72
+ console.error(
73
+ 'Error fetching AI organization settings:',
74
+ error instanceof Error ? error.message : String(error),
75
+ );
76
+ process.exit(1);
77
+ }
78
+ }),
79
+ );
72
80
  }
@@ -4,7 +4,9 @@
4
4
 
5
5
  import type { Command } from 'commander';
6
6
  import { readFileSync } from 'fs';
7
+ import { READ_ONLY_DEFAULT, WRITE_IDEMPOTENT } from '@lightdash-tools/common';
7
8
  import { getClient } from '../utils/client';
9
+ import { wrapAction } from '../utils/safety';
8
10
  import type { UpsertChartAsCodeBody } from '@lightdash-tools/common';
9
11
 
10
12
  /**
@@ -57,19 +59,21 @@ export function registerChartsCommand(program: Command): void {
57
59
  chartsCmd
58
60
  .command('list <projectUuid>')
59
61
  .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
- });
62
+ .action(
63
+ wrapAction(READ_ONLY_DEFAULT, async (projectUuid: string) => {
64
+ try {
65
+ const client = getClient();
66
+ const result = await client.v1.charts.listCharts(projectUuid);
67
+ console.log(JSON.stringify(result, null, 2));
68
+ } catch (error) {
69
+ console.error(
70
+ 'Error listing charts:',
71
+ error instanceof Error ? error.message : String(error),
72
+ );
73
+ process.exit(1);
74
+ }
75
+ }),
76
+ );
73
77
 
74
78
  const codeCmd = chartsCmd
75
79
  .command('code')
@@ -82,44 +86,52 @@ export function registerChartsCommand(program: Command): void {
82
86
  .option('--offset <number>', 'Pagination offset', (v) => parseInt(v, 10))
83
87
  .option('--language-map', 'Include language map in response')
84
88
  .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
- },
89
+ wrapAction(
90
+ READ_ONLY_DEFAULT,
91
+ async (
92
+ projectUuid: string,
93
+ options: { ids?: string[]; offset?: number; languageMap?: boolean },
94
+ ) => {
95
+ try {
96
+ const client = getClient();
97
+ const result = await client.v1.charts.getChartsAsCode(projectUuid, {
98
+ ids: options.ids,
99
+ offset: options.offset,
100
+ languageMap: options.languageMap,
101
+ });
102
+ console.log(JSON.stringify(result, null, 2));
103
+ } catch (error) {
104
+ console.error(
105
+ 'Error getting charts as code:',
106
+ error instanceof Error ? error.message : String(error),
107
+ );
108
+ process.exit(1);
109
+ }
110
+ },
111
+ ),
105
112
  );
106
113
 
107
114
  codeCmd
108
115
  .command('upsert <projectUuid> <slug>')
109
116
  .description('Upsert a chart from code (body from --file or stdin)')
110
117
  .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
- });
118
+ .action(
119
+ wrapAction(
120
+ WRITE_IDEMPOTENT,
121
+ async (projectUuid: string, slug: string, options: { file?: string }) => {
122
+ try {
123
+ const body = await readChartJsonInput(options.file);
124
+ const client = getClient();
125
+ const result = await client.v1.charts.upsertChartAsCode(projectUuid, slug, body);
126
+ console.log(JSON.stringify(result, null, 2));
127
+ } catch (error) {
128
+ console.error(
129
+ 'Error upserting chart as code:',
130
+ error instanceof Error ? error.message : String(error),
131
+ );
132
+ process.exit(1);
133
+ }
134
+ },
135
+ ),
136
+ );
125
137
  }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Content command implementation.
3
+ */
4
+
5
+ import type { Command } from 'commander';
6
+ import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
7
+ import { getClient } from '../utils/client';
8
+ import { wrapAction } from '../utils/safety';
9
+
10
+ /**
11
+ * Registers the content command and its subcommands.
12
+ */
13
+ export function registerContentCommand(program: Command): void {
14
+ const contentCmd = program.command('content').description('Manage project content');
15
+
16
+ contentCmd
17
+ .command('search <query>')
18
+ .description('Search project content (charts, dashboards, spaces)')
19
+ .option('--project <uuids...>', 'Filter by project UUIDs')
20
+ .option('--type <types...>', 'Filter by content types (chart, dashboard, space)')
21
+ .option('--page <number>', 'Page number', (v) => parseInt(v, 10))
22
+ .option('--page-size <number>', 'Page size', (v) => parseInt(v, 10))
23
+ .action(
24
+ wrapAction(
25
+ READ_ONLY_DEFAULT,
26
+ async (
27
+ query: string,
28
+ options: {
29
+ project?: string[];
30
+ type?: ('chart' | 'dashboard' | 'space')[];
31
+ page?: number;
32
+ pageSize?: number;
33
+ },
34
+ ) => {
35
+ try {
36
+ const client = getClient();
37
+ const result = await client.v2.content.searchContent({
38
+ search: query,
39
+ projectUuids: options.project,
40
+ contentTypes: options.type,
41
+ page: options.page,
42
+ pageSize: options.pageSize,
43
+ });
44
+ console.log(JSON.stringify(result, null, 2));
45
+ } catch (error) {
46
+ console.error(
47
+ 'Error searching content:',
48
+ error instanceof Error ? error.message : String(error),
49
+ );
50
+ process.exit(1);
51
+ }
52
+ },
53
+ ),
54
+ );
55
+ }
@@ -3,7 +3,9 @@
3
3
  */
4
4
 
5
5
  import type { Command } from 'commander';
6
+ import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
6
7
  import { getClient } from '../utils/client';
8
+ import { wrapAction } from '../utils/safety';
7
9
 
8
10
  /**
9
11
  * Registers the projects dashboards subcommands under the existing projects command.
@@ -21,17 +23,19 @@ export function registerDashboardsCommand(program: Command): void {
21
23
  dashboardsCmd
22
24
  .command('list <projectUuid>')
23
25
  .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
- });
26
+ .action(
27
+ wrapAction(READ_ONLY_DEFAULT, async (projectUuid: string) => {
28
+ try {
29
+ const client = getClient();
30
+ const result = await client.v1.dashboards.listDashboards(projectUuid);
31
+ console.log(JSON.stringify(result, null, 2));
32
+ } catch (error) {
33
+ console.error(
34
+ 'Error listing dashboards:',
35
+ error instanceof Error ? error.message : String(error),
36
+ );
37
+ process.exit(1);
38
+ }
39
+ }),
40
+ );
37
41
  }
@@ -3,7 +3,9 @@
3
3
  */
4
4
 
5
5
  import type { Command } from 'commander';
6
+ import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
6
7
  import { getClient } from '../utils/client';
8
+ import { wrapAction } from '../utils/safety';
7
9
 
8
10
  /**
9
11
  * Registers the projects explores subcommands under the existing projects command.
@@ -21,34 +23,83 @@ export function registerExploresCommand(program: Command): void {
21
23
  exploresCmd
22
24
  .command('list <projectUuid>')
23
25
  .description('List explores in a project')
24
- .action(async (projectUuid: string) => {
25
- try {
26
- const client = getClient();
27
- const result = await client.v1.explores.listExplores(projectUuid);
28
- console.log(JSON.stringify(result, null, 2));
29
- } catch (error) {
30
- console.error(
31
- 'Error listing explores:',
32
- error instanceof Error ? error.message : String(error),
33
- );
34
- process.exit(1);
35
- }
36
- });
26
+ .action(
27
+ wrapAction(READ_ONLY_DEFAULT, async (projectUuid: string) => {
28
+ try {
29
+ const client = getClient();
30
+ const result = await client.v1.explores.listExplores(projectUuid);
31
+ console.log(JSON.stringify(result, null, 2));
32
+ } catch (error) {
33
+ console.error(
34
+ 'Error listing explores:',
35
+ error instanceof Error ? error.message : String(error),
36
+ );
37
+ process.exit(1);
38
+ }
39
+ }),
40
+ );
37
41
 
38
42
  exploresCmd
39
43
  .command('get <projectUuid> <exploreId>')
40
44
  .description('Get an explore by ID')
41
- .action(async (projectUuid: string, exploreId: string) => {
42
- try {
43
- const client = getClient();
44
- const result = await client.v1.explores.getExplore(projectUuid, exploreId);
45
- console.log(JSON.stringify(result, null, 2));
46
- } catch (error) {
47
- console.error(
48
- 'Error fetching explore:',
49
- error instanceof Error ? error.message : String(error),
50
- );
51
- process.exit(1);
52
- }
53
- });
45
+ .action(
46
+ wrapAction(READ_ONLY_DEFAULT, async (projectUuid: string, exploreId: string) => {
47
+ try {
48
+ const client = getClient();
49
+ const result = await client.v1.explores.getExplore(projectUuid, exploreId);
50
+ console.log(JSON.stringify(result, null, 2));
51
+ } catch (error) {
52
+ console.error(
53
+ 'Error fetching explore:',
54
+ error instanceof Error ? error.message : String(error),
55
+ );
56
+ process.exit(1);
57
+ }
58
+ }),
59
+ );
60
+
61
+ exploresCmd
62
+ .command('dimensions <projectUuid> <exploreId>')
63
+ .description('List dimensions for an explore')
64
+ .action(
65
+ wrapAction(READ_ONLY_DEFAULT, async (projectUuid: string, exploreId: string) => {
66
+ try {
67
+ const client = getClient();
68
+ const result = await client.v1.explores.listDimensions(projectUuid, exploreId);
69
+ console.log(JSON.stringify(result, null, 2));
70
+ } catch (error) {
71
+ console.error(
72
+ 'Error listing dimensions:',
73
+ error instanceof Error ? error.message : String(error),
74
+ );
75
+ process.exit(1);
76
+ }
77
+ }),
78
+ );
79
+
80
+ exploresCmd
81
+ .command('lineage <projectUuid> <exploreId> <fieldId>')
82
+ .description('Get lineage for a field in an explore')
83
+ .action(
84
+ wrapAction(
85
+ READ_ONLY_DEFAULT,
86
+ async (projectUuid: string, exploreId: string, fieldId: string) => {
87
+ try {
88
+ const client = getClient();
89
+ const result = await client.v1.explores.getFieldLineage(
90
+ projectUuid,
91
+ exploreId,
92
+ fieldId,
93
+ );
94
+ console.log(JSON.stringify(result, null, 2));
95
+ } catch (error) {
96
+ console.error(
97
+ 'Error fetching lineage:',
98
+ error instanceof Error ? error.message : String(error),
99
+ );
100
+ process.exit(1);
101
+ }
102
+ },
103
+ ),
104
+ );
54
105
  }
@@ -3,7 +3,9 @@
3
3
  */
4
4
 
5
5
  import type { Command } from 'commander';
6
+ import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
6
7
  import { getClient } from '../utils/client';
8
+ import { wrapAction } from '../utils/safety';
7
9
 
8
10
  /**
9
11
  * Registers the groups command and its subcommands.
@@ -22,63 +24,67 @@ export function registerGroupsCommand(program: Command): void {
22
24
  .option('--include-members <number>', 'Include members (0 or 1)', (v: string) =>
23
25
  parseInt(v, 10),
24
26
  )
25
- .action(async function (this: Command) {
26
- const options = this.opts() as {
27
- all?: boolean;
28
- page?: number;
29
- pageSize?: number;
30
- search?: string;
31
- includeMembers?: number;
32
- };
33
- try {
34
- const client = getClient();
35
- if (options.all) {
36
- const listParams: { searchQuery?: string; includeMembers?: number } = {};
37
- if (options.search != null) listParams.searchQuery = options.search;
38
- if (options.includeMembers != null) listParams.includeMembers = options.includeMembers;
39
- const list = await client.v1.groups.listAllGroups(
40
- Object.keys(listParams).length > 0 ? listParams : undefined,
27
+ .action(
28
+ wrapAction(READ_ONLY_DEFAULT, async function (this: Command) {
29
+ const options = this.opts() as {
30
+ all?: boolean;
31
+ page?: number;
32
+ pageSize?: number;
33
+ search?: string;
34
+ includeMembers?: number;
35
+ };
36
+ try {
37
+ const client = getClient();
38
+ if (options.all) {
39
+ const listParams: { searchQuery?: string; includeMembers?: number } = {};
40
+ if (options.search != null) listParams.searchQuery = options.search;
41
+ if (options.includeMembers != null) listParams.includeMembers = options.includeMembers;
42
+ const list = await client.v1.groups.listAllGroups(
43
+ Object.keys(listParams).length > 0 ? listParams : undefined,
44
+ );
45
+ console.log(JSON.stringify(list, null, 2));
46
+ } else {
47
+ const params: {
48
+ page?: number;
49
+ pageSize?: number;
50
+ searchQuery?: string;
51
+ includeMembers?: number;
52
+ } = {};
53
+ if (options.page != null) params.page = options.page;
54
+ if (options.pageSize != null) params.pageSize = options.pageSize;
55
+ if (options.search != null) params.searchQuery = options.search;
56
+ if (options.includeMembers != null) params.includeMembers = options.includeMembers;
57
+ const result = await client.v1.groups.listGroups(
58
+ Object.keys(params).length > 0 ? params : undefined,
59
+ );
60
+ console.log(JSON.stringify(result, null, 2));
61
+ }
62
+ } catch (error) {
63
+ console.error(
64
+ 'Error listing groups:',
65
+ error instanceof Error ? error.message : String(error),
41
66
  );
42
- console.log(JSON.stringify(list, null, 2));
43
- } else {
44
- const params: {
45
- page?: number;
46
- pageSize?: number;
47
- searchQuery?: string;
48
- includeMembers?: number;
49
- } = {};
50
- if (options.page != null) params.page = options.page;
51
- if (options.pageSize != null) params.pageSize = options.pageSize;
52
- if (options.search != null) params.searchQuery = options.search;
53
- if (options.includeMembers != null) params.includeMembers = options.includeMembers;
54
- const result = await client.v1.groups.listGroups(
55
- Object.keys(params).length > 0 ? params : undefined,
56
- );
57
- console.log(JSON.stringify(result, null, 2));
67
+ process.exit(1);
58
68
  }
59
- } catch (error) {
60
- console.error(
61
- 'Error listing groups:',
62
- error instanceof Error ? error.message : String(error),
63
- );
64
- process.exit(1);
65
- }
66
- });
69
+ }),
70
+ );
67
71
 
68
72
  groupsCmd
69
73
  .command('get <groupUuid>')
70
74
  .description('Get a group by UUID')
71
- .action(async (groupUuid: string) => {
72
- try {
73
- const client = getClient();
74
- const group = await client.v1.groups.getGroup(groupUuid);
75
- console.log(JSON.stringify(group, null, 2));
76
- } catch (error) {
77
- console.error(
78
- 'Error fetching group:',
79
- error instanceof Error ? error.message : String(error),
80
- );
81
- process.exit(1);
82
- }
83
- });
75
+ .action(
76
+ wrapAction(READ_ONLY_DEFAULT, async (groupUuid: string) => {
77
+ try {
78
+ const client = getClient();
79
+ const group = await client.v1.groups.getGroup(groupUuid);
80
+ console.log(JSON.stringify(group, null, 2));
81
+ } catch (error) {
82
+ console.error(
83
+ 'Error fetching group:',
84
+ error instanceof Error ? error.message : String(error),
85
+ );
86
+ process.exit(1);
87
+ }
88
+ }),
89
+ );
84
90
  }