@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,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Explores (v1) command implementation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Command } from 'commander';
|
|
6
|
+
import { getClient } from '../utils/client';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers the projects explores subcommands under the existing projects command.
|
|
10
|
+
*/
|
|
11
|
+
export function registerExploresCommand(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 explores');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const exploresCmd = projectsCmd
|
|
18
|
+
.command('explores')
|
|
19
|
+
.description('List and get project explores (v1)');
|
|
20
|
+
|
|
21
|
+
exploresCmd
|
|
22
|
+
.command('list <projectUuid>')
|
|
23
|
+
.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
|
+
});
|
|
37
|
+
|
|
38
|
+
exploresCmd
|
|
39
|
+
.command('get <projectUuid> <exploreId>')
|
|
40
|
+
.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
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Groups command implementation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Command } from 'commander';
|
|
6
|
+
import { getClient } from '../utils/client';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers the groups command and its subcommands.
|
|
10
|
+
* Uses client.v1.groups (typed client) per ADR-0010 and OpenSpec cli-parity-with-client.
|
|
11
|
+
*/
|
|
12
|
+
export function registerGroupsCommand(program: Command): void {
|
|
13
|
+
const groupsCmd = program.command('groups').description('Manage groups');
|
|
14
|
+
|
|
15
|
+
groupsCmd
|
|
16
|
+
.command('list')
|
|
17
|
+
.description('List all groups in the current organization')
|
|
18
|
+
.option('--all', 'Fetch all pages and output the full list')
|
|
19
|
+
.option('--page <number>', 'Page number (1-based)', (v: string) => parseInt(v, 10))
|
|
20
|
+
.option('--page-size <number>', 'Page size', (v: string) => parseInt(v, 10))
|
|
21
|
+
.option('--search <query>', 'Search query')
|
|
22
|
+
.option('--include-members <number>', 'Include members (0 or 1)', (v: string) =>
|
|
23
|
+
parseInt(v, 10),
|
|
24
|
+
)
|
|
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,
|
|
41
|
+
);
|
|
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));
|
|
58
|
+
}
|
|
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
|
+
});
|
|
67
|
+
|
|
68
|
+
groupsCmd
|
|
69
|
+
.command('get <groupUuid>')
|
|
70
|
+
.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
|
+
});
|
|
84
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Organization roles (v2) command implementation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Command } from 'commander';
|
|
6
|
+
import { getClient } from '../utils/client';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers the organization roles subcommands under the existing organization command.
|
|
10
|
+
* Resolves org UUID via getCurrentOrganization().organizationUuid.
|
|
11
|
+
*/
|
|
12
|
+
export function registerOrganizationRolesCommand(program: Command): void {
|
|
13
|
+
const orgCmd = program.commands.find((c) => c.name() === 'organization');
|
|
14
|
+
if (!orgCmd) {
|
|
15
|
+
throw new Error('organization command must be registered before organization-roles');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const rolesCmd = orgCmd.command('roles').description('Manage organization roles (v2)');
|
|
19
|
+
|
|
20
|
+
rolesCmd
|
|
21
|
+
.command('list')
|
|
22
|
+
.description('List organization roles')
|
|
23
|
+
.option('--load <value>', 'Load query param')
|
|
24
|
+
.option('--role-type-filter <value>', 'Filter by role type')
|
|
25
|
+
.action(async function (this: Command) {
|
|
26
|
+
const options = this.opts() as { load?: string; roleTypeFilter?: string };
|
|
27
|
+
try {
|
|
28
|
+
const client = getClient();
|
|
29
|
+
const org = await client.v1.organizations.getCurrentOrganization();
|
|
30
|
+
const orgUuid = (org as { organizationUuid: string }).organizationUuid;
|
|
31
|
+
const params =
|
|
32
|
+
options.load != null || options.roleTypeFilter != null
|
|
33
|
+
? { load: options.load, roleTypeFilter: options.roleTypeFilter }
|
|
34
|
+
: undefined;
|
|
35
|
+
const result = await client.v2.organizationRoles.getRoles(orgUuid, params);
|
|
36
|
+
console.log(JSON.stringify(result, null, 2));
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error(
|
|
39
|
+
'Error listing organization roles:',
|
|
40
|
+
error instanceof Error ? error.message : String(error),
|
|
41
|
+
);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
rolesCmd
|
|
47
|
+
.command('get <roleUuid>')
|
|
48
|
+
.description('Get an organization role by UUID')
|
|
49
|
+
.action(async (roleUuid: string) => {
|
|
50
|
+
try {
|
|
51
|
+
const client = getClient();
|
|
52
|
+
const org = await client.v1.organizations.getCurrentOrganization();
|
|
53
|
+
const orgUuid = (org as { organizationUuid: string }).organizationUuid;
|
|
54
|
+
const role = await client.v2.organizationRoles.getRole(orgUuid, roleUuid);
|
|
55
|
+
console.log(JSON.stringify(role, null, 2));
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error(
|
|
58
|
+
'Error fetching organization role:',
|
|
59
|
+
error instanceof Error ? error.message : String(error),
|
|
60
|
+
);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const assignmentsCmd = rolesCmd
|
|
66
|
+
.command('assignments')
|
|
67
|
+
.description('Organization role assignments');
|
|
68
|
+
assignmentsCmd
|
|
69
|
+
.command('list')
|
|
70
|
+
.description('List organization role assignments')
|
|
71
|
+
.action(async () => {
|
|
72
|
+
try {
|
|
73
|
+
const client = getClient();
|
|
74
|
+
const org = await client.v1.organizations.getCurrentOrganization();
|
|
75
|
+
const orgUuid = (org as { organizationUuid: string }).organizationUuid;
|
|
76
|
+
const result = await client.v2.organizationRoles.listRoleAssignments(orgUuid);
|
|
77
|
+
console.log(JSON.stringify(result, null, 2));
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error(
|
|
80
|
+
'Error listing role assignments:',
|
|
81
|
+
error instanceof Error ? error.message : String(error),
|
|
82
|
+
);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
rolesCmd
|
|
88
|
+
.command('assign <userUuid>')
|
|
89
|
+
.description('Assign an organization role to a user')
|
|
90
|
+
.requiredOption('--role-id <roleId>', 'Role ID to assign')
|
|
91
|
+
.action(async (userUuid: string, cmd: Command) => {
|
|
92
|
+
const options = cmd.opts() as { roleId: string };
|
|
93
|
+
try {
|
|
94
|
+
const client = getClient();
|
|
95
|
+
const org = await client.v1.organizations.getCurrentOrganization();
|
|
96
|
+
const orgUuid = (org as { organizationUuid: string }).organizationUuid;
|
|
97
|
+
const result = await client.v2.organizationRoles.assignRoleToUser(orgUuid, userUuid, {
|
|
98
|
+
roleId: options.roleId,
|
|
99
|
+
});
|
|
100
|
+
console.log(JSON.stringify(result, null, 2));
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error(
|
|
103
|
+
'Error assigning role to user:',
|
|
104
|
+
error instanceof Error ? error.message : String(error),
|
|
105
|
+
);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Organization command implementation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Command } from 'commander';
|
|
6
|
+
import { getClient } from '../utils/client';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers the organization command and its subcommands.
|
|
10
|
+
*/
|
|
11
|
+
export function registerOrganizationCommand(program: Command): void {
|
|
12
|
+
const orgCmd = program.command('organization').description('Manage organization');
|
|
13
|
+
|
|
14
|
+
orgCmd
|
|
15
|
+
.command('get')
|
|
16
|
+
.description('Get current organization')
|
|
17
|
+
.action(async () => {
|
|
18
|
+
try {
|
|
19
|
+
const client = getClient();
|
|
20
|
+
const org = await client.v1.organizations.getCurrentOrganization();
|
|
21
|
+
console.log(JSON.stringify(org, null, 2));
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error(
|
|
24
|
+
'Error fetching organization:',
|
|
25
|
+
error instanceof Error ? error.message : String(error),
|
|
26
|
+
);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project access (v1) command implementation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Command } from 'commander';
|
|
6
|
+
import { getClient } from '../utils/client';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers the projects access subcommands under the existing projects command.
|
|
10
|
+
*/
|
|
11
|
+
export function registerProjectAccessCommand(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 project-access');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const accessCmd = projectsCmd.command('access').description('Manage project access (v1)');
|
|
18
|
+
|
|
19
|
+
accessCmd
|
|
20
|
+
.command('list <projectUuid>')
|
|
21
|
+
.description('List users with project access')
|
|
22
|
+
.action(async (projectUuid: string) => {
|
|
23
|
+
try {
|
|
24
|
+
const client = getClient();
|
|
25
|
+
const result = await client.v1.projectAccess.listProjectAccess(projectUuid);
|
|
26
|
+
console.log(JSON.stringify(result, null, 2));
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error(
|
|
29
|
+
'Error listing project access:',
|
|
30
|
+
error instanceof Error ? error.message : String(error),
|
|
31
|
+
);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const groupsCmd = accessCmd.command('groups').description('Project group access');
|
|
37
|
+
groupsCmd
|
|
38
|
+
.command('list <projectUuid>')
|
|
39
|
+
.description('List group access for a project')
|
|
40
|
+
.action(async (projectUuid: string) => {
|
|
41
|
+
try {
|
|
42
|
+
const client = getClient();
|
|
43
|
+
const result = await client.v1.projectAccess.listProjectGroupAccesses(projectUuid);
|
|
44
|
+
console.log(JSON.stringify(result, null, 2));
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error(
|
|
47
|
+
'Error listing project group access:',
|
|
48
|
+
error instanceof Error ? error.message : String(error),
|
|
49
|
+
);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
accessCmd
|
|
55
|
+
.command('get <projectUuid> <userUuid>')
|
|
56
|
+
.description('Get a project member access')
|
|
57
|
+
.action(async (projectUuid: string, userUuid: string) => {
|
|
58
|
+
try {
|
|
59
|
+
const client = getClient();
|
|
60
|
+
const result = await client.v1.projectAccess.getProjectMemberAccess(projectUuid, userUuid);
|
|
61
|
+
console.log(JSON.stringify(result, null, 2));
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error(
|
|
64
|
+
'Error fetching project member access:',
|
|
65
|
+
error instanceof Error ? error.message : String(error),
|
|
66
|
+
);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project role assignments (v2) command implementation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Command } from 'commander';
|
|
6
|
+
import { getClient } from '../utils/client';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers the projects roles subcommands under the existing projects command.
|
|
10
|
+
*/
|
|
11
|
+
export function registerProjectRoleAssignmentsCommand(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 project-role-assignments');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const rolesCmd = projectsCmd.command('roles').description('Manage project role assignments (v2)');
|
|
18
|
+
|
|
19
|
+
rolesCmd
|
|
20
|
+
.command('list <projectUuid>')
|
|
21
|
+
.description('List project role assignments')
|
|
22
|
+
.action(async (projectUuid: string) => {
|
|
23
|
+
try {
|
|
24
|
+
const client = getClient();
|
|
25
|
+
const result = await client.v2.projectRoleAssignments.listAssignments(projectUuid);
|
|
26
|
+
console.log(JSON.stringify(result, null, 2));
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error(
|
|
29
|
+
'Error listing project role assignments:',
|
|
30
|
+
error instanceof Error ? error.message : String(error),
|
|
31
|
+
);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const assignCmd = rolesCmd.command('assign').description('Assign role to user or group');
|
|
37
|
+
assignCmd
|
|
38
|
+
.command('user <projectUuid> <userUuid>')
|
|
39
|
+
.description('Assign a role to a user in a project')
|
|
40
|
+
.requiredOption('--role-id <roleId>', 'Role ID to assign')
|
|
41
|
+
.action(async (projectUuid: string, userUuid: string, cmd: Command) => {
|
|
42
|
+
const opts = cmd.opts() as { roleId: string };
|
|
43
|
+
try {
|
|
44
|
+
const client = getClient();
|
|
45
|
+
const result = await client.v2.projectRoleAssignments.upsertUserAssignment(
|
|
46
|
+
projectUuid,
|
|
47
|
+
userUuid,
|
|
48
|
+
{ roleId: opts.roleId },
|
|
49
|
+
);
|
|
50
|
+
console.log(JSON.stringify(result, null, 2));
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(
|
|
53
|
+
'Error assigning role to user:',
|
|
54
|
+
error instanceof Error ? error.message : String(error),
|
|
55
|
+
);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
assignCmd
|
|
61
|
+
.command('group <projectUuid> <groupId>')
|
|
62
|
+
.description('Assign a role to a group in a project')
|
|
63
|
+
.requiredOption('--role-id <roleId>', 'Role ID to assign')
|
|
64
|
+
.action(async (projectUuid: string, groupId: string, cmd: Command) => {
|
|
65
|
+
const opts = cmd.opts() as { roleId: string };
|
|
66
|
+
try {
|
|
67
|
+
const client = getClient();
|
|
68
|
+
const result = await client.v2.projectRoleAssignments.upsertGroupAssignment(
|
|
69
|
+
projectUuid,
|
|
70
|
+
groupId,
|
|
71
|
+
{ roleId: opts.roleId },
|
|
72
|
+
);
|
|
73
|
+
console.log(JSON.stringify(result, null, 2));
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error(
|
|
76
|
+
'Error assigning role to group:',
|
|
77
|
+
error instanceof Error ? error.message : String(error),
|
|
78
|
+
);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const unassignCmd = rolesCmd.command('unassign').description('Remove role assignment');
|
|
84
|
+
unassignCmd
|
|
85
|
+
.command('user <projectUuid> <userUuid>')
|
|
86
|
+
.description('Remove role assignment from a user')
|
|
87
|
+
.action(async (projectUuid: string, userUuid: string) => {
|
|
88
|
+
try {
|
|
89
|
+
const client = getClient();
|
|
90
|
+
await client.v2.projectRoleAssignments.deleteUserAssignment(projectUuid, userUuid);
|
|
91
|
+
console.log(JSON.stringify({ ok: true }, null, 2));
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error(
|
|
94
|
+
'Error removing user role assignment:',
|
|
95
|
+
error instanceof Error ? error.message : String(error),
|
|
96
|
+
);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
unassignCmd
|
|
102
|
+
.command('group <projectUuid> <groupId>')
|
|
103
|
+
.description('Remove role assignment from a group')
|
|
104
|
+
.action(async (projectUuid: string, groupId: string) => {
|
|
105
|
+
try {
|
|
106
|
+
const client = getClient();
|
|
107
|
+
await client.v2.projectRoleAssignments.deleteGroupAssignment(projectUuid, groupId);
|
|
108
|
+
console.log(JSON.stringify({ ok: true }, null, 2));
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error(
|
|
111
|
+
'Error removing group role assignment:',
|
|
112
|
+
error instanceof Error ? error.message : String(error),
|
|
113
|
+
);
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Projects command implementation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Command } from 'commander';
|
|
6
|
+
import { getClient } from '../utils/client';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers the projects command and its subcommands.
|
|
10
|
+
*/
|
|
11
|
+
export function registerProjectsCommand(program: Command): void {
|
|
12
|
+
const projectsCmd = program.command('projects').description('Manage projects');
|
|
13
|
+
|
|
14
|
+
projectsCmd
|
|
15
|
+
.command('get')
|
|
16
|
+
.description('Get a project by UUID')
|
|
17
|
+
.argument('<projectUuid>', 'Project UUID')
|
|
18
|
+
.action(async (projectUuid: string) => {
|
|
19
|
+
try {
|
|
20
|
+
if (!projectUuid) {
|
|
21
|
+
console.error('Error: projectUuid is required');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
const client = getClient();
|
|
25
|
+
const project = await client.v1.projects.getProject(projectUuid);
|
|
26
|
+
console.log(JSON.stringify(project, null, 2));
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error(
|
|
29
|
+
'Error fetching project:',
|
|
30
|
+
error instanceof Error ? error.message : String(error),
|
|
31
|
+
);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
projectsCmd
|
|
37
|
+
.command('list')
|
|
38
|
+
.description('List all projects in the current organization')
|
|
39
|
+
.action(async () => {
|
|
40
|
+
try {
|
|
41
|
+
const client = getClient();
|
|
42
|
+
const projects = await client.v1.projects.listProjects();
|
|
43
|
+
console.log(JSON.stringify(projects, null, 2));
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error(
|
|
46
|
+
'Error listing projects:',
|
|
47
|
+
error instanceof Error ? error.message : String(error),
|
|
48
|
+
);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query command implementation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Command } from 'commander';
|
|
6
|
+
import { readFileSync } from 'fs';
|
|
7
|
+
import { getClient } from '../utils/client';
|
|
8
|
+
import type { CompileQueryRequest } from '@lightdash-tools/common';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Reads JSON from stdin or a file.
|
|
12
|
+
*/
|
|
13
|
+
async function readJsonInput(filePath?: string): Promise<unknown> {
|
|
14
|
+
if (filePath) {
|
|
15
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
16
|
+
return JSON.parse(content);
|
|
17
|
+
}
|
|
18
|
+
// Read from stdin
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
// Check if stdin is a TTY (interactive terminal)
|
|
21
|
+
if (process.stdin.isTTY) {
|
|
22
|
+
reject(new Error('No input provided. Use --file <path> or pipe JSON to stdin.'));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const chunks: Buffer[] = [];
|
|
26
|
+
process.stdin.setEncoding('utf8');
|
|
27
|
+
process.stdin.on('data', (chunk) => {
|
|
28
|
+
chunks.push(Buffer.from(chunk));
|
|
29
|
+
});
|
|
30
|
+
process.stdin.on('end', () => {
|
|
31
|
+
try {
|
|
32
|
+
const input = Buffer.concat(chunks).toString('utf-8');
|
|
33
|
+
resolve(JSON.parse(input));
|
|
34
|
+
} catch (err) {
|
|
35
|
+
reject(
|
|
36
|
+
new Error(`Failed to parse JSON: ${err instanceof Error ? err.message : String(err)}`),
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
process.stdin.on('error', (err) => {
|
|
41
|
+
reject(err);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Registers the query command and its subcommands.
|
|
48
|
+
*/
|
|
49
|
+
export function registerQueryCommand(program: Command): void {
|
|
50
|
+
const queryCmd = program.command('query').description('Query operations');
|
|
51
|
+
|
|
52
|
+
queryCmd
|
|
53
|
+
.command('compile')
|
|
54
|
+
.description('Compile a metric query for an explore')
|
|
55
|
+
.argument('<projectUuid>', 'Project UUID')
|
|
56
|
+
.argument('<exploreId>', 'Explore ID')
|
|
57
|
+
.option('--file <path>', 'Read metric query JSON from file (default: read from stdin)')
|
|
58
|
+
.action(async (projectUuid: string, exploreId: string, options: { file?: string }) => {
|
|
59
|
+
try {
|
|
60
|
+
if (!projectUuid) {
|
|
61
|
+
console.error('Error: projectUuid is required');
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
if (!exploreId) {
|
|
65
|
+
console.error('Error: exploreId is required');
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Read JSON input
|
|
70
|
+
const body = (await readJsonInput(options.file)) as CompileQueryRequest;
|
|
71
|
+
|
|
72
|
+
const client = getClient();
|
|
73
|
+
const result = await client.v1.query.compileQuery(projectUuid, exploreId, body);
|
|
74
|
+
console.log(JSON.stringify(result, null, 2));
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error(
|
|
77
|
+
'Error compiling query:',
|
|
78
|
+
error instanceof Error ? error.message : String(error),
|
|
79
|
+
);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spaces (v1) command implementation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Command } from 'commander';
|
|
6
|
+
import { getClient } from '../utils/client';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers the projects spaces subcommands under the existing projects command.
|
|
10
|
+
*/
|
|
11
|
+
export function registerSpacesCommand(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 spaces');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const spacesCmd = projectsCmd.command('spaces').description('Manage project spaces (v1)');
|
|
18
|
+
|
|
19
|
+
spacesCmd
|
|
20
|
+
.command('list <projectUuid>')
|
|
21
|
+
.description('List spaces in a project')
|
|
22
|
+
.action(async (projectUuid: string) => {
|
|
23
|
+
try {
|
|
24
|
+
const client = getClient();
|
|
25
|
+
const result = await client.v1.spaces.listSpacesInProject(projectUuid);
|
|
26
|
+
console.log(JSON.stringify(result, null, 2));
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error(
|
|
29
|
+
'Error listing spaces:',
|
|
30
|
+
error instanceof Error ? error.message : String(error),
|
|
31
|
+
);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
spacesCmd
|
|
37
|
+
.command('get <projectUuid> <spaceUuid>')
|
|
38
|
+
.description('Get a space by UUID')
|
|
39
|
+
.action(async (projectUuid: string, spaceUuid: string) => {
|
|
40
|
+
try {
|
|
41
|
+
const client = getClient();
|
|
42
|
+
const result = await client.v1.spaces.getSpace(projectUuid, spaceUuid);
|
|
43
|
+
console.log(JSON.stringify(result, null, 2));
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error(
|
|
46
|
+
'Error fetching space:',
|
|
47
|
+
error instanceof Error ? error.message : String(error),
|
|
48
|
+
);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|