@lightdash-tools/cli 0.6.0 → 0.7.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.
Files changed (109) hide show
  1. package/README.md +6 -2
  2. package/dist/commands/agentops/apply.d.ts +5 -0
  3. package/dist/commands/agentops/apply.js +53 -0
  4. package/dist/commands/agentops/bundle-schema.d.ts +5 -0
  5. package/dist/commands/agentops/bundle-schema.js +16 -0
  6. package/dist/commands/agentops/drift.d.ts +5 -0
  7. package/dist/commands/agentops/drift.js +46 -0
  8. package/dist/commands/agentops/evaluate-gate.d.ts +5 -0
  9. package/dist/commands/agentops/evaluate-gate.js +89 -0
  10. package/dist/commands/agentops/gate-schema.d.ts +5 -0
  11. package/dist/commands/agentops/gate-schema.js +16 -0
  12. package/dist/commands/agentops/plan.d.ts +5 -0
  13. package/dist/commands/agentops/plan.js +42 -0
  14. package/dist/commands/agentops/state.d.ts +4 -0
  15. package/dist/commands/agentops/state.js +8 -0
  16. package/dist/commands/agentops.d.ts +8 -0
  17. package/dist/commands/agentops.js +26 -0
  18. package/dist/commands/agentops.test.d.ts +1 -0
  19. package/dist/commands/agentops.test.js +400 -0
  20. package/dist/commands/agents-crud.d.ts +8 -0
  21. package/dist/commands/agents-crud.js +144 -0
  22. package/dist/commands/agents-discovery.d.ts +8 -0
  23. package/dist/commands/agents-discovery.js +139 -0
  24. package/dist/commands/agents-discovery.test.d.ts +1 -0
  25. package/dist/commands/agents-discovery.test.js +13 -0
  26. package/dist/commands/agents-evals.d.ts +8 -0
  27. package/dist/commands/agents-evals.js +246 -0
  28. package/dist/commands/agents-threads.d.ts +8 -0
  29. package/dist/commands/agents-threads.js +83 -0
  30. package/dist/commands/agents.js +8 -360
  31. package/dist/commands/ai-agents.js +52 -70
  32. package/dist/commands/charts.js +35 -46
  33. package/dist/commands/content.js +3 -12
  34. package/dist/commands/dashboards.js +3 -12
  35. package/dist/commands/explores.js +12 -21
  36. package/dist/commands/groups.js +44 -63
  37. package/dist/commands/metrics.js +6 -15
  38. package/dist/commands/organization-roles.js +28 -39
  39. package/dist/commands/organization.js +3 -12
  40. package/dist/commands/project-access.js +9 -18
  41. package/dist/commands/project-role-assignments.js +15 -24
  42. package/dist/commands/projects.js +33 -26
  43. package/dist/commands/query.js +30 -41
  44. package/dist/commands/schedulers.js +6 -15
  45. package/dist/commands/schema.js +33 -10
  46. package/dist/commands/schema.test.js +58 -1
  47. package/dist/commands/space-access.js +12 -21
  48. package/dist/commands/spaces.js +6 -15
  49. package/dist/commands/tags.js +6 -15
  50. package/dist/commands/users.js +23 -41
  51. package/dist/index.js +18 -16
  52. package/dist/index.test.js +9 -9
  53. package/dist/utils/cli-params.d.ts +4 -0
  54. package/dist/utils/cli-params.js +15 -0
  55. package/dist/utils/cli-params.test.d.ts +1 -0
  56. package/dist/utils/cli-params.test.js +12 -0
  57. package/dist/utils/file-input.d.ts +30 -0
  58. package/dist/utils/file-input.js +77 -0
  59. package/dist/utils/file-input.test.d.ts +1 -0
  60. package/dist/utils/file-input.test.js +68 -0
  61. package/dist/utils/safety.d.ts +5 -0
  62. package/dist/utils/safety.js +97 -109
  63. package/dist/utils/safety.test.js +135 -33
  64. package/package.json +14 -5
  65. package/src/commands/agentops/apply.ts +77 -0
  66. package/src/commands/agentops/bundle-schema.ts +20 -0
  67. package/src/commands/agentops/drift.ts +63 -0
  68. package/src/commands/agentops/evaluate-gate.ts +128 -0
  69. package/src/commands/agentops/gate-schema.ts +20 -0
  70. package/src/commands/agentops/plan.ts +55 -0
  71. package/src/commands/agentops/state.ts +5 -0
  72. package/src/commands/agentops.test.ts +454 -0
  73. package/src/commands/agentops.ts +28 -0
  74. package/src/commands/agents-crud.ts +193 -0
  75. package/src/commands/agents-discovery.test.ts +16 -0
  76. package/src/commands/agents-discovery.ts +180 -0
  77. package/src/commands/agents-evals.ts +353 -0
  78. package/src/commands/agents-threads.ts +116 -0
  79. package/src/commands/agents.ts +9 -493
  80. package/src/commands/ai-agents.ts +37 -28
  81. package/src/commands/charts.ts +6 -3
  82. package/src/commands/content.ts +3 -1
  83. package/src/commands/dashboards.ts +3 -1
  84. package/src/commands/explores.ts +3 -1
  85. package/src/commands/groups.ts +33 -33
  86. package/src/commands/metrics.ts +3 -1
  87. package/src/commands/organization-roles.ts +3 -1
  88. package/src/commands/organization.ts +3 -1
  89. package/src/commands/project-access.ts +3 -1
  90. package/src/commands/project-role-assignments.ts +3 -1
  91. package/src/commands/projects.ts +44 -18
  92. package/src/commands/query.ts +4 -1
  93. package/src/commands/schedulers.ts +3 -1
  94. package/src/commands/schema.test.ts +72 -1
  95. package/src/commands/schema.ts +60 -14
  96. package/src/commands/space-access.ts +3 -1
  97. package/src/commands/spaces.ts +3 -1
  98. package/src/commands/tags.ts +3 -1
  99. package/src/commands/users.ts +29 -25
  100. package/src/index.test.ts +10 -9
  101. package/src/index.ts +19 -16
  102. package/src/utils/cli-params.test.ts +13 -0
  103. package/src/utils/cli-params.ts +12 -0
  104. package/src/utils/client.test.ts +1 -0
  105. package/src/utils/file-input.test.ts +91 -0
  106. package/src/utils/file-input.ts +83 -0
  107. package/src/utils/safety.test.ts +158 -2
  108. package/src/utils/safety.ts +27 -20
  109. package/tsconfig.json +2 -1
@@ -2,11 +2,41 @@
2
2
  * Groups command implementation.
3
3
  */
4
4
 
5
- import type { Command } from 'commander';
6
5
  import { READ_ONLY_DEFAULT, WRITE_IDEMPOTENT, WRITE_DESTRUCTIVE } from '@lightdash-tools/common';
6
+
7
+ import { pickDefined } from '../utils/cli-params';
7
8
  import { getClient } from '../utils/client';
8
9
  import { wrapAction } from '../utils/safety';
9
10
 
11
+ import type { LightdashClient } from '@lightdash-tools/client';
12
+ import type { Command } from 'commander';
13
+
14
+ type ListGroupsCliOptions = {
15
+ all?: boolean;
16
+ page?: number;
17
+ pageSize?: number;
18
+ search?: string;
19
+ includeMembers?: number;
20
+ };
21
+
22
+ async function listGroups(client: LightdashClient, options: ListGroupsCliOptions): Promise<void> {
23
+ const shared = {
24
+ searchQuery: options.search,
25
+ includeMembers: options.includeMembers,
26
+ };
27
+
28
+ if (options.all) {
29
+ const list = await client.v1.groups.listAllGroups(pickDefined(shared));
30
+ console.log(JSON.stringify(list, null, 2));
31
+ return;
32
+ }
33
+
34
+ const result = await client.v1.groups.listGroups(
35
+ pickDefined({ page: options.page, pageSize: options.pageSize, ...shared }),
36
+ );
37
+ console.log(JSON.stringify(result, null, 2));
38
+ }
39
+
10
40
  /**
11
41
  * Registers the groups command and its subcommands.
12
42
  * Uses client.v1.groups (typed client) per ADR-0010.
@@ -26,39 +56,9 @@ export function registerGroupsCommand(program: Command): void {
26
56
  )
27
57
  .action(
28
58
  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
- };
59
+ const options = this.opts() as ListGroupsCliOptions;
36
60
  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
- }
61
+ await listGroups(getClient(), options);
62
62
  } catch (error) {
63
63
  console.error(
64
64
  'Error listing groups:',
@@ -2,11 +2,13 @@
2
2
  * Metrics command implementation.
3
3
  */
4
4
 
5
- import type { Command } from 'commander';
6
5
  import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
6
+
7
7
  import { getClient } from '../utils/client';
8
8
  import { wrapAction } from '../utils/safety';
9
9
 
10
+ import type { Command } from 'commander';
11
+
10
12
  /**
11
13
  * Registers the metrics command and its subcommands.
12
14
  */
@@ -2,11 +2,13 @@
2
2
  * Organization roles (v2) command implementation.
3
3
  */
4
4
 
5
- import type { Command } from 'commander';
6
5
  import { READ_ONLY_DEFAULT, WRITE_IDEMPOTENT } from '@lightdash-tools/common';
6
+
7
7
  import { getClient } from '../utils/client';
8
8
  import { wrapAction } from '../utils/safety';
9
9
 
10
+ import type { Command } from 'commander';
11
+
10
12
  /**
11
13
  * Registers the organization roles subcommands under the existing organization command.
12
14
  * Resolves org UUID via getCurrentOrganization().organizationUuid.
@@ -2,11 +2,13 @@
2
2
  * Organization command implementation.
3
3
  */
4
4
 
5
- import type { Command } from 'commander';
6
5
  import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
6
+
7
7
  import { getClient } from '../utils/client';
8
8
  import { wrapAction } from '../utils/safety';
9
9
 
10
+ import type { Command } from 'commander';
11
+
10
12
  /**
11
13
  * Registers the organization command and its subcommands.
12
14
  */
@@ -2,11 +2,13 @@
2
2
  * Project access (v1) command implementation.
3
3
  */
4
4
 
5
- import type { Command } from 'commander';
6
5
  import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
6
+
7
7
  import { getClient } from '../utils/client';
8
8
  import { wrapAction } from '../utils/safety';
9
9
 
10
+ import type { Command } from 'commander';
11
+
10
12
  /**
11
13
  * Registers the projects access subcommands under the existing projects command.
12
14
  */
@@ -2,11 +2,13 @@
2
2
  * Project role assignments (v2) command implementation.
3
3
  */
4
4
 
5
- import type { Command } from 'commander';
6
5
  import { READ_ONLY_DEFAULT, WRITE_IDEMPOTENT, WRITE_DESTRUCTIVE } from '@lightdash-tools/common';
6
+
7
7
  import { getClient } from '../utils/client';
8
8
  import { wrapAction } from '../utils/safety';
9
9
 
10
+ import type { Command } from 'commander';
11
+
10
12
  /**
11
13
  * Registers the projects roles subcommands under the existing projects command.
12
14
  */
@@ -2,11 +2,13 @@
2
2
  * Projects command implementation.
3
3
  */
4
4
 
5
- import type { Command } from 'commander';
6
5
  import { READ_ONLY_DEFAULT, WRITE_IDEMPOTENT } from '@lightdash-tools/common';
6
+
7
7
  import { getClient } from '../utils/client';
8
8
  import { wrapAction } from '../utils/safety';
9
9
 
10
+ import type { Command } from 'commander';
11
+
10
12
  /**
11
13
  * Registers the projects command and its subcommands.
12
14
  */
@@ -79,23 +81,47 @@ export function registerProjectsCommand(program: Command): void {
79
81
 
80
82
  validateCmd
81
83
  .command('results <projectUuid>')
82
- .description('Get latest validation results for a project')
83
- .option('--job-id <id>', 'Specific validation job ID')
84
+ .description('Get validation results for a project (v2 API, paginated)')
85
+ .option('--validation-id <id>', 'Specific validation result ID (number)')
86
+ .option('--page <number>', 'Page number (1-indexed)', (v) => parseInt(v, 10))
87
+ .option('--page-size <number>', 'Results per page', (v) => parseInt(v, 10))
84
88
  .action(
85
- wrapAction(READ_ONLY_DEFAULT, async (projectUuid: string, options: { jobId?: string }) => {
86
- try {
87
- const client = getClient();
88
- const result = await client.v1.validation.getValidationResults(projectUuid, {
89
- jobId: options.jobId,
90
- });
91
- console.log(JSON.stringify(result, null, 2));
92
- } catch (error) {
93
- console.error(
94
- 'Error fetching validation results:',
95
- error instanceof Error ? error.message : String(error),
96
- );
97
- process.exit(1);
98
- }
99
- }),
89
+ wrapAction(
90
+ READ_ONLY_DEFAULT,
91
+ async (
92
+ projectUuid: string,
93
+ options: { validationId?: string; page?: number; pageSize?: number },
94
+ ) => {
95
+ try {
96
+ const client = getClient();
97
+ if (options.validationId) {
98
+ // Get specific validation result by ID
99
+ const validationId = parseInt(options.validationId, 10);
100
+ if (isNaN(validationId)) {
101
+ console.error('Error: validation-id must be a number');
102
+ process.exit(1);
103
+ }
104
+ const result = await client.v2.validation.getValidationResult(
105
+ projectUuid,
106
+ validationId,
107
+ );
108
+ console.log(JSON.stringify(result, null, 2));
109
+ } else {
110
+ // List validation results (first page by default)
111
+ const result = await client.v2.validation.listValidationResults(projectUuid, {
112
+ page: options.page,
113
+ pageSize: options.pageSize,
114
+ });
115
+ console.log(JSON.stringify(result, null, 2));
116
+ }
117
+ } catch (error) {
118
+ console.error(
119
+ 'Error fetching validation results:',
120
+ error instanceof Error ? error.message : String(error),
121
+ );
122
+ process.exit(1);
123
+ }
124
+ },
125
+ ),
100
126
  );
101
127
  }
@@ -2,12 +2,15 @@
2
2
  * Query command implementation.
3
3
  */
4
4
 
5
- import type { Command } from 'commander';
6
5
  import { readFileSync } from 'fs';
6
+
7
7
  import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
8
+
8
9
  import { getClient } from '../utils/client';
9
10
  import { wrapAction } from '../utils/safety';
11
+
10
12
  import type { CompileQueryRequest } from '@lightdash-tools/common';
13
+ import type { Command } from 'commander';
11
14
 
12
15
  /**
13
16
  * Reads JSON from stdin or a file.
@@ -2,11 +2,13 @@
2
2
  * Schedulers command implementation.
3
3
  */
4
4
 
5
- import type { Command } from 'commander';
6
5
  import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
6
+
7
7
  import { getClient } from '../utils/client';
8
8
  import { wrapAction } from '../utils/safety';
9
9
 
10
+ import type { Command } from 'commander';
11
+
10
12
  /**
11
13
  * Registers the schedulers command and its subcommands.
12
14
  */
@@ -1,4 +1,5 @@
1
1
  import { describe, it, expect } from 'vitest';
2
+
2
3
  import { getSchema, listResources } from './schema';
3
4
 
4
5
  describe('schema command', () => {
@@ -14,13 +15,76 @@ describe('schema command', () => {
14
15
  expect(schema).toHaveProperty('resource', 'charts.list');
15
16
  });
16
17
 
17
- it('returns schema for ai-agents.settings.update', () => {
18
+ it('returns schema for ai-agents.settings.update (legacy key)', () => {
18
19
  const schema = getSchema('ai-agents.settings.update');
19
20
  expect(schema).not.toBeNull();
20
21
  expect(schema).toHaveProperty('path', '/api/v1/aiAgents/admin/settings');
21
22
  expect(schema).toHaveProperty('method', 'PATCH');
22
23
  });
23
24
 
25
+ it('returns schema for ai-agents.project.agents.list from operation registry', () => {
26
+ const schema = getSchema('ai-agents.project.agents.list');
27
+ expect(schema).not.toBeNull();
28
+ expect(schema).toHaveProperty('path', '/api/v1/projects/{projectUuid}/aiAgents');
29
+ expect(schema).toHaveProperty('method', 'GET');
30
+ expect(schema).toHaveProperty('cliCommand', 'agents list');
31
+ expect(schema).toHaveProperty('profiles');
32
+ expect(schema?.profiles).toContain('core-lifecycle');
33
+ });
34
+
35
+ it('returns schema for ai-agents.project.evaluations.create from operation registry', () => {
36
+ const schema = getSchema('ai-agents.project.evaluations.create');
37
+ expect(schema).not.toBeNull();
38
+ expect(schema).toHaveProperty('method', 'POST');
39
+ expect(schema).toHaveProperty('cliCommand', 'agents evals create');
40
+ expect(schema?.params).toEqual(expect.arrayContaining(['projectUuid', 'agentUuid']));
41
+ });
42
+
43
+ it('returns schema for ai-agents.project.threads.start from operation registry', () => {
44
+ const schema = getSchema('ai-agents.project.threads.start');
45
+ expect(schema).not.toBeNull();
46
+ expect(schema).toHaveProperty('method', 'POST');
47
+ expect(schema).toHaveProperty(
48
+ 'path',
49
+ '/api/v1/projects/{projectUuid}/aiAgents/{agentUuid}/threads',
50
+ );
51
+ expect(schema).toHaveProperty('cliCommand', 'agents threads start');
52
+ expect(schema).toHaveProperty('safetyImpact', 'external-side-effect');
53
+ expect(schema?.workflow).toEqual(
54
+ expect.arrayContaining([
55
+ expect.objectContaining({
56
+ method: 'POST',
57
+ path: '/api/v1/projects/{projectUuid}/aiAgents/{agentUuid}/threads/{threadUuid}/generate',
58
+ }),
59
+ ]),
60
+ );
61
+ });
62
+
63
+ it('returns workflow for ai-agents.project.threads.continue from operation registry', () => {
64
+ const schema = getSchema('ai-agents.project.threads.continue');
65
+ expect(schema).not.toBeNull();
66
+ expect(schema?.workflow).toEqual(
67
+ expect.arrayContaining([
68
+ expect.objectContaining({
69
+ method: 'POST',
70
+ path: '/api/v1/projects/{projectUuid}/aiAgents/{agentUuid}/threads/{threadUuid}/messages',
71
+ }),
72
+ expect.objectContaining({
73
+ method: 'POST',
74
+ path: '/api/v1/projects/{projectUuid}/aiAgents/{agentUuid}/threads/{threadUuid}/generate',
75
+ }),
76
+ ]),
77
+ );
78
+ });
79
+
80
+ it('returns schema for users.members.delete with client-only exposure', () => {
81
+ const schema = getSchema('users.members.delete');
82
+ expect(schema).not.toBeNull();
83
+ expect(schema).toHaveProperty('method', 'DELETE');
84
+ expect(schema).toHaveProperty('path', '/api/v1/org/user/{userUuid}');
85
+ expect(schema).toHaveProperty('agentExposure', 'client-only');
86
+ });
87
+
24
88
  it('returns null for unknown resource', () => {
25
89
  const schema = getSchema('unknown.resource');
26
90
  expect(schema).toBeNull();
@@ -38,5 +102,12 @@ describe('schema command', () => {
38
102
  it('includes charts.list', () => {
39
103
  expect(listResources()).toContain('charts.list');
40
104
  });
105
+
106
+ it('includes project-scoped registry operation ids', () => {
107
+ const resources = listResources();
108
+ expect(resources).toContain('ai-agents.project.agents.list');
109
+ expect(resources).toContain('ai-agents.project.evaluations.run');
110
+ expect(resources).toContain('ai-agents.project.threads.continue');
111
+ });
41
112
  });
42
113
  });
@@ -3,15 +3,22 @@
3
3
  * Outputs machine-readable JSON describing API paths, methods, and parameters.
4
4
  */
5
5
 
6
- import type { Command } from 'commander';
7
- import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
6
+ import { getOperation, listOperations, READ_ONLY_DEFAULT } from '@lightdash-tools/common';
7
+
8
8
  import { wrapAction } from '../utils/safety';
9
9
 
10
- /** Maps resource identifiers to API path + method + description. */
11
- const SCHEMA_REGISTRY: Record<
12
- string,
13
- { path: string; method: string; description: string; params?: string[] }
14
- > = {
10
+ import type { OperationDescriptor } from '@lightdash-tools/common';
11
+ import type { Command } from 'commander';
12
+
13
+ type SchemaEntry = {
14
+ path: string;
15
+ method: string;
16
+ description: string;
17
+ params?: string[];
18
+ };
19
+
20
+ /** Maps legacy resource identifiers to API path + method + description. */
21
+ const LEGACY_SCHEMA_REGISTRY: Record<string, SchemaEntry> = {
15
22
  'organization.get': {
16
23
  path: '/api/v1/org',
17
24
  method: 'GET',
@@ -35,13 +42,13 @@ const SCHEMA_REGISTRY: Record<
35
42
  params: ['projectUuid'],
36
43
  },
37
44
  'charts.code.list': {
38
- path: '/api/v1/projects/{projectUuid}/charts/code',
45
+ path: '/api/v1/projects/{projectUuid}/code/charts',
39
46
  method: 'GET',
40
47
  description: 'Get charts in code representation',
41
48
  params: ['projectUuid'],
42
49
  },
43
50
  'charts.code.upsert': {
44
- path: '/api/v1/projects/{projectUuid}/charts/{slug}/code',
51
+ path: '/api/v1/projects/{projectUuid}/code/charts/{slug}',
45
52
  method: 'POST',
46
53
  description: 'Create or update chart by slug',
47
54
  params: ['projectUuid', 'slug'],
@@ -92,9 +99,30 @@ const SCHEMA_REGISTRY: Record<
92
99
  },
93
100
  };
94
101
 
95
- export function getSchema(resource: string): Record<string, unknown> | null {
96
- const entry = SCHEMA_REGISTRY[resource];
97
- if (!entry) return null;
102
+ function extractPathParams(path: string): string[] {
103
+ const params: string[] = [];
104
+ for (const match of path.matchAll(/\{([^}]+)\}/g)) {
105
+ params.push(match[1]);
106
+ }
107
+ return params;
108
+ }
109
+
110
+ function operationToSchema(operation: OperationDescriptor): Record<string, unknown> {
111
+ return {
112
+ resource: operation.id,
113
+ path: operation.http.path,
114
+ method: operation.http.method,
115
+ description: operation.summary,
116
+ params: extractPathParams(operation.http.path),
117
+ cliCommand: operation.cli.commandPath,
118
+ agentExposure: operation.agentExposure ?? 'agent',
119
+ profiles: [...operation.profiles],
120
+ safetyImpact: operation.authorization.safetyImpact,
121
+ ...(operation.workflow != null ? { workflow: [...operation.workflow] } : {}),
122
+ };
123
+ }
124
+
125
+ function legacyToSchema(resource: string, entry: SchemaEntry): Record<string, unknown> {
98
126
  return {
99
127
  resource,
100
128
  path: entry.path,
@@ -104,8 +132,26 @@ export function getSchema(resource: string): Record<string, unknown> | null {
104
132
  };
105
133
  }
106
134
 
135
+ export function getSchema(resource: string): Record<string, unknown> | null {
136
+ const legacy = LEGACY_SCHEMA_REGISTRY[resource];
137
+ if (legacy) {
138
+ return legacyToSchema(resource, legacy);
139
+ }
140
+
141
+ const operation = getOperation(resource);
142
+ if (operation) {
143
+ return operationToSchema(operation);
144
+ }
145
+
146
+ return null;
147
+ }
148
+
107
149
  export function listResources(): string[] {
108
- return Object.keys(SCHEMA_REGISTRY).sort();
150
+ const resources = new Set<string>([
151
+ ...Object.keys(LEGACY_SCHEMA_REGISTRY),
152
+ ...listOperations().map((operation) => operation.id),
153
+ ]);
154
+ return [...resources].sort();
109
155
  }
110
156
 
111
157
  /**
@@ -128,7 +174,7 @@ export function registerSchemaCommand(program: Command): void {
128
174
 
129
175
  schemaCmd
130
176
  .command('get <resource>')
131
- .description('Get schema for a resource (e.g. charts.list, ai-agents.settings.get)')
177
+ .description('Get schema for a resource (e.g. charts.list, ai-agents.project.agents.list)')
132
178
  .action(
133
179
  wrapAction(READ_ONLY_DEFAULT, (resource: string) => {
134
180
  const schema = getSchema(resource);
@@ -2,11 +2,13 @@
2
2
  * Space access (v1) command implementation.
3
3
  */
4
4
 
5
- import type { Command } from 'commander';
6
5
  import { WRITE_IDEMPOTENT, WRITE_DESTRUCTIVE, type SpaceMemberRole } from '@lightdash-tools/common';
6
+
7
7
  import { getClient } from '../utils/client';
8
8
  import { wrapAction } from '../utils/safety';
9
9
 
10
+ import type { Command } from 'commander';
11
+
10
12
  /**
11
13
  * Registers the space access subcommands under the existing projects command.
12
14
  */
@@ -2,11 +2,13 @@
2
2
  * Spaces (v1) command implementation.
3
3
  */
4
4
 
5
- import type { Command } from 'commander';
6
5
  import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
6
+
7
7
  import { getClient } from '../utils/client';
8
8
  import { wrapAction } from '../utils/safety';
9
9
 
10
+ import type { Command } from 'commander';
11
+
10
12
  /**
11
13
  * Registers the projects spaces subcommands under the existing projects command.
12
14
  */
@@ -2,11 +2,13 @@
2
2
  * Tags command implementation.
3
3
  */
4
4
 
5
- import type { Command } from 'commander';
6
5
  import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
6
+
7
7
  import { getClient } from '../utils/client';
8
8
  import { wrapAction } from '../utils/safety';
9
9
 
10
+ import type { Command } from 'commander';
11
+
10
12
  /**
11
13
  * Registers the tags command and its subcommands.
12
14
  */
@@ -2,11 +2,37 @@
2
2
  * Users command implementation.
3
3
  */
4
4
 
5
- import type { Command } from 'commander';
6
5
  import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
6
+
7
+ import { pickDefined } from '../utils/cli-params';
7
8
  import { getClient } from '../utils/client';
8
9
  import { wrapAction } from '../utils/safety';
9
10
 
11
+ import type { LightdashClient } from '@lightdash-tools/client';
12
+ import type { Command } from 'commander';
13
+
14
+ type ListUsersCliOptions = {
15
+ all?: boolean;
16
+ page?: number;
17
+ pageSize?: number;
18
+ search?: string;
19
+ };
20
+
21
+ async function listUsers(client: LightdashClient, options: ListUsersCliOptions): Promise<void> {
22
+ const searchQuery = options.search;
23
+
24
+ if (options.all) {
25
+ const list = await client.v1.users.listAllMembers(pickDefined({ searchQuery }));
26
+ console.log(JSON.stringify(list, null, 2));
27
+ return;
28
+ }
29
+
30
+ const result = await client.v1.users.listMembers(
31
+ pickDefined({ page: options.page, pageSize: options.pageSize, searchQuery }),
32
+ );
33
+ console.log(JSON.stringify(result, null, 2));
34
+ }
35
+
10
36
  /**
11
37
  * Registers the users command and its subcommands.
12
38
  * Uses client.v1.users (typed client) per ADR-0010.
@@ -23,31 +49,9 @@ export function registerUsersCommand(program: Command): void {
23
49
  .option('--search <query>', 'Search query')
24
50
  .action(
25
51
  wrapAction(READ_ONLY_DEFAULT, async function (this: Command) {
26
- const options = this.opts() as {
27
- all?: boolean;
28
- page?: number;
29
- pageSize?: number;
30
- search?: string;
31
- };
52
+ const options = this.opts() as ListUsersCliOptions;
32
53
  try {
33
- const client = getClient();
34
- if (options.all) {
35
- const listParams: { searchQuery?: string } = {};
36
- if (options.search != null) listParams.searchQuery = options.search;
37
- const list = await client.v1.users.listAllMembers(
38
- Object.keys(listParams).length > 0 ? listParams : undefined,
39
- );
40
- console.log(JSON.stringify(list, null, 2));
41
- } else {
42
- const params: { page?: number; pageSize?: number; searchQuery?: string } = {};
43
- if (options.page != null) params.page = options.page;
44
- if (options.pageSize != null) params.pageSize = options.pageSize;
45
- if (options.search != null) params.searchQuery = options.search;
46
- const result = await client.v1.users.listMembers(
47
- Object.keys(params).length > 0 ? params : undefined,
48
- );
49
- console.log(JSON.stringify(result, null, 2));
50
- }
54
+ await listUsers(getClient(), options);
51
55
  } catch (error) {
52
56
  console.error(
53
57
  'Error listing users:',
package/src/index.test.ts CHANGED
@@ -1,18 +1,19 @@
1
- import { describe, it, expect } from 'vitest';
2
1
  import { Command } from 'commander';
2
+ import { describe, it, expect } from 'vitest';
3
+
4
+ import { registerAiAgentsCommand } from './commands/ai-agents';
5
+ import { registerChartsCommand } from './commands/charts';
6
+ import { registerDashboardsCommand } from './commands/dashboards';
7
+ import { registerExploresCommand } from './commands/explores';
8
+ import { registerGroupsCommand } from './commands/groups';
3
9
  import { registerOrganizationCommand } from './commands/organization';
4
10
  import { registerOrganizationRolesCommand } from './commands/organization-roles';
5
- import { registerProjectsCommand } from './commands/projects';
6
- import { registerProjectRoleAssignmentsCommand } from './commands/project-role-assignments';
7
11
  import { registerProjectAccessCommand } from './commands/project-access';
8
- import { registerSpacesCommand } from './commands/spaces';
12
+ import { registerProjectRoleAssignmentsCommand } from './commands/project-role-assignments';
13
+ import { registerProjectsCommand } from './commands/projects';
9
14
  import { registerSpaceAccessCommand } from './commands/space-access';
10
- import { registerChartsCommand } from './commands/charts';
11
- import { registerDashboardsCommand } from './commands/dashboards';
12
- import { registerAiAgentsCommand } from './commands/ai-agents';
13
- import { registerGroupsCommand } from './commands/groups';
15
+ import { registerSpacesCommand } from './commands/spaces';
14
16
  import { registerUsersCommand } from './commands/users';
15
- import { registerExploresCommand } from './commands/explores';
16
17
 
17
18
  describe('CLI Command Registration', () => {
18
19
  it('should register organization command', () => {