@lightdash-tools/cli 0.2.4 → 0.2.6

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/README.md CHANGED
@@ -155,9 +155,9 @@ The CLI implements a hierarchical safety model to prevent accidental destructive
155
155
 
156
156
  You can control the safety mode via the `LIGHTDASH_TOOL_SAFETY_MODE` environment variable or the global `--safety-mode` flag.
157
157
 
158
- - `read-only`: Only allows non-modifying operations (e.g., list, get).
158
+ - `read-only` (default): Only allows non-modifying operations (e.g., list, get).
159
159
  - `write-idempotent`: Allows read operations and non-destructive writes (e.g., upsert, validate run).
160
- - `write-destructive` (default): Allows all operations, including deletions.
160
+ - `write-destructive`: Allows all operations, including deletions.
161
161
 
162
162
  ### Enforcement
163
163
 
@@ -78,4 +78,95 @@ function registerGroupsCommand(program) {
78
78
  process.exit(1);
79
79
  }
80
80
  })));
81
+ groupsCmd
82
+ .command('create <name>')
83
+ .description('Create a new group')
84
+ .action((0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, (name) => __awaiter(this, void 0, void 0, function* () {
85
+ try {
86
+ const client = (0, client_1.getClient)();
87
+ const group = yield client.v1.groups.createGroup({ name });
88
+ console.log(JSON.stringify(group, null, 2));
89
+ }
90
+ catch (error) {
91
+ console.error('Error creating group:', error instanceof Error ? error.message : String(error));
92
+ process.exit(1);
93
+ }
94
+ })));
95
+ groupsCmd
96
+ .command('update <groupUuid>')
97
+ .description('Update a group')
98
+ .option('--name <name>', 'New name for the group')
99
+ .action((0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, (groupUuid, cmd) => __awaiter(this, void 0, void 0, function* () {
100
+ const options = cmd.opts();
101
+ if (!options.name) {
102
+ console.error('Error: --name is required for update');
103
+ process.exit(1);
104
+ }
105
+ try {
106
+ const client = (0, client_1.getClient)();
107
+ const group = yield client.v1.groups.updateGroup(groupUuid, { name: options.name });
108
+ console.log(JSON.stringify(group, null, 2));
109
+ }
110
+ catch (error) {
111
+ console.error('Error updating group:', error instanceof Error ? error.message : String(error));
112
+ process.exit(1);
113
+ }
114
+ })));
115
+ groupsCmd
116
+ .command('delete <groupUuid>')
117
+ .description('Delete a group')
118
+ .action((0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, (groupUuid) => __awaiter(this, void 0, void 0, function* () {
119
+ try {
120
+ const client = (0, client_1.getClient)();
121
+ yield client.v1.groups.deleteGroup(groupUuid);
122
+ console.error(`Group ${groupUuid} deleted successfully`);
123
+ }
124
+ catch (error) {
125
+ console.error('Error deleting group:', error instanceof Error ? error.message : String(error));
126
+ process.exit(1);
127
+ }
128
+ })));
129
+ const membersCmd = groupsCmd.command('members').description('Manage group members');
130
+ membersCmd
131
+ .command('list <groupUuid>')
132
+ .description('List members of a group')
133
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, (groupUuid) => __awaiter(this, void 0, void 0, function* () {
134
+ try {
135
+ const client = (0, client_1.getClient)();
136
+ const members = yield client.v1.groups.getGroupMembers(groupUuid);
137
+ console.log(JSON.stringify(members, null, 2));
138
+ }
139
+ catch (error) {
140
+ console.error('Error listing group members:', error instanceof Error ? error.message : String(error));
141
+ process.exit(1);
142
+ }
143
+ })));
144
+ membersCmd
145
+ .command('add <groupUuid> <userUuid>')
146
+ .description('Add a user to a group')
147
+ .action((0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, (groupUuid, userUuid) => __awaiter(this, void 0, void 0, function* () {
148
+ try {
149
+ const client = (0, client_1.getClient)();
150
+ yield client.v1.groups.addUserToGroup(groupUuid, userUuid);
151
+ console.error(`User ${userUuid} added to group ${groupUuid} successfully`);
152
+ }
153
+ catch (error) {
154
+ console.error('Error adding user to group:', error instanceof Error ? error.message : String(error));
155
+ process.exit(1);
156
+ }
157
+ })));
158
+ membersCmd
159
+ .command('remove <groupUuid> <userUuid>')
160
+ .description('Remove a user from a group')
161
+ .action((0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, (groupUuid, userUuid) => __awaiter(this, void 0, void 0, function* () {
162
+ try {
163
+ const client = (0, client_1.getClient)();
164
+ yield client.v1.groups.removeUserFromGroup(groupUuid, userUuid);
165
+ console.error(`User ${userUuid} removed from group ${groupUuid} successfully`);
166
+ }
167
+ catch (error) {
168
+ console.error('Error removing user from group:', error instanceof Error ? error.message : String(error));
169
+ process.exit(1);
170
+ }
171
+ })));
81
172
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Space access (v1) command implementation.
3
+ */
4
+ import type { Command } from 'commander';
5
+ /**
6
+ * Registers the space access subcommands under the existing projects command.
7
+ */
8
+ export declare function registerSpaceAccessCommand(program: Command): void;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ /**
3
+ * Space access (v1) 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.registerSpaceAccessCommand = registerSpaceAccessCommand;
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 space access subcommands under the existing projects command.
21
+ */
22
+ function registerSpaceAccessCommand(program) {
23
+ const projectsCmd = program.commands.find((c) => c.name() === 'projects');
24
+ if (!projectsCmd) {
25
+ throw new Error('projects command must be registered before space-access');
26
+ }
27
+ const spaceAccessCmd = projectsCmd
28
+ .command('space-access')
29
+ .description('Manage space access (v1)');
30
+ const userCmd = spaceAccessCmd.command('user').description('Manage user access to a space');
31
+ userCmd
32
+ .command('grant <projectUuid> <spaceUuid> <userUuid> <role>')
33
+ .description('Grant a user access to a space')
34
+ .action((0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, (projectUuid, spaceUuid, userUuid, role) => __awaiter(this, void 0, void 0, function* () {
35
+ try {
36
+ const client = (0, client_1.getClient)();
37
+ yield client.v1.spaces.grantUserAccessToSpace(projectUuid, spaceUuid, {
38
+ userUuid,
39
+ spaceRole: role,
40
+ });
41
+ console.error(`Successfully granted ${role} access to user ${userUuid} in space ${spaceUuid}`);
42
+ }
43
+ catch (error) {
44
+ console.error('Error granting user access to space:', error instanceof Error ? error.message : String(error));
45
+ process.exit(1);
46
+ }
47
+ })));
48
+ userCmd
49
+ .command('revoke <projectUuid> <spaceUuid> <userUuid>')
50
+ .description("Revoke a user's access to a space")
51
+ .action((0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, (projectUuid, spaceUuid, userUuid) => __awaiter(this, void 0, void 0, function* () {
52
+ try {
53
+ const client = (0, client_1.getClient)();
54
+ yield client.v1.spaces.revokeUserAccessToSpace(projectUuid, spaceUuid, userUuid);
55
+ console.error(`Successfully revoked access for user ${userUuid} in space ${spaceUuid}`);
56
+ }
57
+ catch (error) {
58
+ console.error('Error revoking user access from space:', error instanceof Error ? error.message : String(error));
59
+ process.exit(1);
60
+ }
61
+ })));
62
+ const groupCmd = spaceAccessCmd.command('group').description('Manage group access to a space');
63
+ groupCmd
64
+ .command('grant <projectUuid> <spaceUuid> <groupUuid> <role>')
65
+ .description('Grant a group access to a space')
66
+ .action((0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, (projectUuid, spaceUuid, groupUuid, role) => __awaiter(this, void 0, void 0, function* () {
67
+ try {
68
+ const client = (0, client_1.getClient)();
69
+ yield client.v1.spaces.grantGroupAccessToSpace(projectUuid, spaceUuid, {
70
+ groupUuid,
71
+ spaceRole: role,
72
+ });
73
+ console.error(`Successfully granted ${role} access to group ${groupUuid} in space ${spaceUuid}`);
74
+ }
75
+ catch (error) {
76
+ console.error('Error granting group access to space:', error instanceof Error ? error.message : String(error));
77
+ process.exit(1);
78
+ }
79
+ })));
80
+ groupCmd
81
+ .command('revoke <projectUuid> <spaceUuid> <groupUuid>')
82
+ .description("Revoke a group's access to a space")
83
+ .action((0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, (projectUuid, spaceUuid, groupUuid) => __awaiter(this, void 0, void 0, function* () {
84
+ try {
85
+ const client = (0, client_1.getClient)();
86
+ yield client.v1.spaces.revokeGroupAccessToSpace(projectUuid, spaceUuid, groupUuid);
87
+ console.error(`Successfully revoked access for group ${groupUuid} in space ${spaceUuid}`);
88
+ }
89
+ catch (error) {
90
+ console.error('Error revoking group access from space:', error instanceof Error ? error.message : String(error));
91
+ process.exit(1);
92
+ }
93
+ })));
94
+ }
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ const projects_1 = require("./commands/projects");
11
11
  const project_role_assignments_1 = require("./commands/project-role-assignments");
12
12
  const project_access_1 = require("./commands/project-access");
13
13
  const spaces_1 = require("./commands/spaces");
14
+ const space_access_1 = require("./commands/space-access");
14
15
  const charts_1 = require("./commands/charts");
15
16
  const dashboards_1 = require("./commands/dashboards");
16
17
  const ai_agents_1 = require("./commands/ai-agents");
@@ -26,8 +27,8 @@ const program = new commander_1.Command();
26
27
  program
27
28
  .name('lightdash-ai')
28
29
  .description('CLI for Lightdash AI')
29
- .version('1.0.0')
30
- .option('--safety-mode <mode>', 'Safety mode (read-only, write-idempotent, write-destructive)', 'write-destructive');
30
+ .version('0.2.6')
31
+ .option('--safety-mode <mode>', 'Safety mode (read-only, write-idempotent, write-destructive)', 'read-only');
31
32
  // Register all commands (organization and projects first so subcommands can attach)
32
33
  (0, organization_1.registerOrganizationCommand)(program);
33
34
  (0, organization_roles_1.registerOrganizationRolesCommand)(program);
@@ -35,6 +36,7 @@ program
35
36
  (0, project_role_assignments_1.registerProjectRoleAssignmentsCommand)(program);
36
37
  (0, project_access_1.registerProjectAccessCommand)(program);
37
38
  (0, spaces_1.registerSpacesCommand)(program);
39
+ (0, space_access_1.registerSpaceAccessCommand)(program);
38
40
  (0, charts_1.registerChartsCommand)(program);
39
41
  (0, dashboards_1.registerDashboardsCommand)(program);
40
42
  (0, ai_agents_1.registerAiAgentsCommand)(program);
@@ -8,6 +8,7 @@ const projects_1 = require("./commands/projects");
8
8
  const project_role_assignments_1 = require("./commands/project-role-assignments");
9
9
  const project_access_1 = require("./commands/project-access");
10
10
  const spaces_1 = require("./commands/spaces");
11
+ const space_access_1 = require("./commands/space-access");
11
12
  const charts_1 = require("./commands/charts");
12
13
  const dashboards_1 = require("./commands/dashboards");
13
14
  const ai_agents_1 = require("./commands/ai-agents");
@@ -33,7 +34,7 @@ const explores_1 = require("./commands/explores");
33
34
  const listCmd = projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.find((cmd) => cmd.name() === 'list');
34
35
  (0, vitest_1.expect)(listCmd).toBeDefined();
35
36
  });
36
- (0, vitest_1.it)('should register groups command with list and get subcommands', () => {
37
+ (0, vitest_1.it)('should register groups command with list, get, create, update, delete, and members subcommands', () => {
37
38
  const program = new commander_1.Command();
38
39
  (0, groups_1.registerGroupsCommand)(program);
39
40
  const groupsCmd = program.commands.find((cmd) => cmd.name() === 'groups');
@@ -42,6 +43,20 @@ const explores_1 = require("./commands/explores");
42
43
  (0, vitest_1.expect)(listCmd).toBeDefined();
43
44
  const getCmd = groupsCmd === null || groupsCmd === void 0 ? void 0 : groupsCmd.commands.find((cmd) => cmd.name() === 'get');
44
45
  (0, vitest_1.expect)(getCmd).toBeDefined();
46
+ const createCmd = groupsCmd === null || groupsCmd === void 0 ? void 0 : groupsCmd.commands.find((cmd) => cmd.name() === 'create');
47
+ (0, vitest_1.expect)(createCmd).toBeDefined();
48
+ const updateCmd = groupsCmd === null || groupsCmd === void 0 ? void 0 : groupsCmd.commands.find((cmd) => cmd.name() === 'update');
49
+ (0, vitest_1.expect)(updateCmd).toBeDefined();
50
+ const deleteCmd = groupsCmd === null || groupsCmd === void 0 ? void 0 : groupsCmd.commands.find((cmd) => cmd.name() === 'delete');
51
+ (0, vitest_1.expect)(deleteCmd).toBeDefined();
52
+ const membersCmd = groupsCmd === null || groupsCmd === void 0 ? void 0 : groupsCmd.commands.find((cmd) => cmd.name() === 'members');
53
+ (0, vitest_1.expect)(membersCmd).toBeDefined();
54
+ const membersListCmd = membersCmd === null || membersCmd === void 0 ? void 0 : membersCmd.commands.find((cmd) => cmd.name() === 'list');
55
+ (0, vitest_1.expect)(membersListCmd).toBeDefined();
56
+ const membersAddCmd = membersCmd === null || membersCmd === void 0 ? void 0 : membersCmd.commands.find((cmd) => cmd.name() === 'add');
57
+ (0, vitest_1.expect)(membersAddCmd).toBeDefined();
58
+ const membersRemoveCmd = membersCmd === null || membersCmd === void 0 ? void 0 : membersCmd.commands.find((cmd) => cmd.name() === 'remove');
59
+ (0, vitest_1.expect)(membersRemoveCmd).toBeDefined();
45
60
  });
46
61
  (0, vitest_1.it)('should register users list with --all option', () => {
47
62
  const program = new commander_1.Command();
@@ -82,16 +97,18 @@ const explores_1 = require("./commands/explores");
82
97
  (0, vitest_1.expect)(rolesCmd === null || rolesCmd === void 0 ? void 0 : rolesCmd.commands.some((c) => c.name() === 'get')).toBe(true);
83
98
  (0, vitest_1.expect)(rolesCmd === null || rolesCmd === void 0 ? void 0 : rolesCmd.commands.some((c) => c.name() === 'assign')).toBe(true);
84
99
  });
85
- (0, vitest_1.it)('should register projects roles, access, spaces subcommands', () => {
100
+ (0, vitest_1.it)('should register projects roles, access, spaces, and space-access subcommands', () => {
86
101
  const program = new commander_1.Command();
87
102
  (0, projects_1.registerProjectsCommand)(program);
88
103
  (0, project_role_assignments_1.registerProjectRoleAssignmentsCommand)(program);
89
104
  (0, project_access_1.registerProjectAccessCommand)(program);
90
105
  (0, spaces_1.registerSpacesCommand)(program);
106
+ (0, space_access_1.registerSpaceAccessCommand)(program);
91
107
  const projectsCmd = program.commands.find((cmd) => cmd.name() === 'projects');
92
108
  (0, vitest_1.expect)(projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.some((c) => c.name() === 'roles')).toBe(true);
93
109
  (0, vitest_1.expect)(projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.some((c) => c.name() === 'access')).toBe(true);
94
110
  (0, vitest_1.expect)(projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.some((c) => c.name() === 'spaces')).toBe(true);
111
+ (0, vitest_1.expect)(projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.some((c) => c.name() === 'space-access')).toBe(true);
95
112
  });
96
113
  (0, vitest_1.it)('should register projects charts and dashboards subcommands', () => {
97
114
  const program = new commander_1.Command();
@@ -141,6 +158,7 @@ const explores_1 = require("./commands/explores");
141
158
  (0, project_role_assignments_1.registerProjectRoleAssignmentsCommand)(program);
142
159
  (0, project_access_1.registerProjectAccessCommand)(program);
143
160
  (0, spaces_1.registerSpacesCommand)(program);
161
+ (0, space_access_1.registerSpaceAccessCommand)(program);
144
162
  (0, charts_1.registerChartsCommand)(program);
145
163
  (0, dashboards_1.registerDashboardsCommand)(program);
146
164
  (0, ai_agents_1.registerAiAgentsCommand)(program);
@@ -158,7 +176,7 @@ const explores_1 = require("./commands/explores");
158
176
  });
159
177
  (0, vitest_1.it)('should have --safety-mode option', () => {
160
178
  const program = new commander_1.Command();
161
- program.option('--safety-mode <mode>', 'description', 'write-destructive');
179
+ program.option('--safety-mode <mode>', 'description', 'read-only');
162
180
  const option = program.options.find((opt) => opt.long === '--safety-mode');
163
181
  (0, vitest_1.expect)(option).toBeDefined();
164
182
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash-tools/cli",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
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.2.4",
16
- "@lightdash-tools/common": "0.2.4"
15
+ "@lightdash-tools/client": "0.2.6",
16
+ "@lightdash-tools/common": "0.2.6"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/node": "^25.2.3"
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import type { Command } from 'commander';
6
- import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
6
+ import { READ_ONLY_DEFAULT, WRITE_IDEMPOTENT, WRITE_DESTRUCTIVE } from '@lightdash-tools/common';
7
7
  import { getClient } from '../utils/client';
8
8
  import { wrapAction } from '../utils/safety';
9
9
 
@@ -87,4 +87,126 @@ export function registerGroupsCommand(program: Command): void {
87
87
  }
88
88
  }),
89
89
  );
90
+
91
+ groupsCmd
92
+ .command('create <name>')
93
+ .description('Create a new group')
94
+ .action(
95
+ wrapAction(WRITE_IDEMPOTENT, async (name: string) => {
96
+ try {
97
+ const client = getClient();
98
+ const group = await client.v1.groups.createGroup({ name });
99
+ console.log(JSON.stringify(group, null, 2));
100
+ } catch (error) {
101
+ console.error(
102
+ 'Error creating group:',
103
+ error instanceof Error ? error.message : String(error),
104
+ );
105
+ process.exit(1);
106
+ }
107
+ }),
108
+ );
109
+
110
+ groupsCmd
111
+ .command('update <groupUuid>')
112
+ .description('Update a group')
113
+ .option('--name <name>', 'New name for the group')
114
+ .action(
115
+ wrapAction(WRITE_IDEMPOTENT, async (groupUuid: string, cmd: Command) => {
116
+ const options = cmd.opts() as { name?: string };
117
+ if (!options.name) {
118
+ console.error('Error: --name is required for update');
119
+ process.exit(1);
120
+ }
121
+ try {
122
+ const client = getClient();
123
+ const group = await client.v1.groups.updateGroup(groupUuid, { name: options.name });
124
+ console.log(JSON.stringify(group, null, 2));
125
+ } catch (error) {
126
+ console.error(
127
+ 'Error updating group:',
128
+ error instanceof Error ? error.message : String(error),
129
+ );
130
+ process.exit(1);
131
+ }
132
+ }),
133
+ );
134
+
135
+ groupsCmd
136
+ .command('delete <groupUuid>')
137
+ .description('Delete a group')
138
+ .action(
139
+ wrapAction(WRITE_DESTRUCTIVE, async (groupUuid: string) => {
140
+ try {
141
+ const client = getClient();
142
+ await client.v1.groups.deleteGroup(groupUuid);
143
+ console.error(`Group ${groupUuid} deleted successfully`);
144
+ } catch (error) {
145
+ console.error(
146
+ 'Error deleting group:',
147
+ error instanceof Error ? error.message : String(error),
148
+ );
149
+ process.exit(1);
150
+ }
151
+ }),
152
+ );
153
+
154
+ const membersCmd = groupsCmd.command('members').description('Manage group members');
155
+
156
+ membersCmd
157
+ .command('list <groupUuid>')
158
+ .description('List members of a group')
159
+ .action(
160
+ wrapAction(READ_ONLY_DEFAULT, async (groupUuid: string) => {
161
+ try {
162
+ const client = getClient();
163
+ const members = await client.v1.groups.getGroupMembers(groupUuid);
164
+ console.log(JSON.stringify(members, null, 2));
165
+ } catch (error) {
166
+ console.error(
167
+ 'Error listing group members:',
168
+ error instanceof Error ? error.message : String(error),
169
+ );
170
+ process.exit(1);
171
+ }
172
+ }),
173
+ );
174
+
175
+ membersCmd
176
+ .command('add <groupUuid> <userUuid>')
177
+ .description('Add a user to a group')
178
+ .action(
179
+ wrapAction(WRITE_IDEMPOTENT, async (groupUuid: string, userUuid: string) => {
180
+ try {
181
+ const client = getClient();
182
+ await client.v1.groups.addUserToGroup(groupUuid, userUuid);
183
+ console.error(`User ${userUuid} added to group ${groupUuid} successfully`);
184
+ } catch (error) {
185
+ console.error(
186
+ 'Error adding user to group:',
187
+ error instanceof Error ? error.message : String(error),
188
+ );
189
+ process.exit(1);
190
+ }
191
+ }),
192
+ );
193
+
194
+ membersCmd
195
+ .command('remove <groupUuid> <userUuid>')
196
+ .description('Remove a user from a group')
197
+ .action(
198
+ wrapAction(WRITE_DESTRUCTIVE, async (groupUuid: string, userUuid: string) => {
199
+ try {
200
+ const client = getClient();
201
+ await client.v1.groups.removeUserFromGroup(groupUuid, userUuid);
202
+ console.error(`User ${userUuid} removed from group ${groupUuid} successfully`);
203
+ } catch (error) {
204
+ console.error(
205
+ 'Error removing user from group:',
206
+ error instanceof Error ? error.message : String(error),
207
+ );
208
+ process.exit(1);
209
+ }
210
+ }),
211
+ );
90
212
  }
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Space access (v1) command implementation.
3
+ */
4
+
5
+ import type { Command } from 'commander';
6
+ import { WRITE_IDEMPOTENT, WRITE_DESTRUCTIVE, type SpaceMemberRole } from '@lightdash-tools/common';
7
+ import { getClient } from '../utils/client';
8
+ import { wrapAction } from '../utils/safety';
9
+
10
+ /**
11
+ * Registers the space access subcommands under the existing projects command.
12
+ */
13
+ export function registerSpaceAccessCommand(program: Command): void {
14
+ const projectsCmd = program.commands.find((c) => c.name() === 'projects');
15
+ if (!projectsCmd) {
16
+ throw new Error('projects command must be registered before space-access');
17
+ }
18
+
19
+ const spaceAccessCmd = projectsCmd
20
+ .command('space-access')
21
+ .description('Manage space access (v1)');
22
+
23
+ const userCmd = spaceAccessCmd.command('user').description('Manage user access to a space');
24
+
25
+ userCmd
26
+ .command('grant <projectUuid> <spaceUuid> <userUuid> <role>')
27
+ .description('Grant a user access to a space')
28
+ .action(
29
+ wrapAction(
30
+ WRITE_IDEMPOTENT,
31
+ async (projectUuid: string, spaceUuid: string, userUuid: string, role: string) => {
32
+ try {
33
+ const client = getClient();
34
+ await client.v1.spaces.grantUserAccessToSpace(projectUuid, spaceUuid, {
35
+ userUuid,
36
+ spaceRole: role as SpaceMemberRole,
37
+ });
38
+ console.error(
39
+ `Successfully granted ${role} access to user ${userUuid} in space ${spaceUuid}`,
40
+ );
41
+ } catch (error) {
42
+ console.error(
43
+ 'Error granting user access to space:',
44
+ error instanceof Error ? error.message : String(error),
45
+ );
46
+ process.exit(1);
47
+ }
48
+ },
49
+ ),
50
+ );
51
+
52
+ userCmd
53
+ .command('revoke <projectUuid> <spaceUuid> <userUuid>')
54
+ .description("Revoke a user's access to a space")
55
+ .action(
56
+ wrapAction(
57
+ WRITE_DESTRUCTIVE,
58
+ async (projectUuid: string, spaceUuid: string, userUuid: string) => {
59
+ try {
60
+ const client = getClient();
61
+ await client.v1.spaces.revokeUserAccessToSpace(projectUuid, spaceUuid, userUuid);
62
+ console.error(`Successfully revoked access for user ${userUuid} in space ${spaceUuid}`);
63
+ } catch (error) {
64
+ console.error(
65
+ 'Error revoking user access from space:',
66
+ error instanceof Error ? error.message : String(error),
67
+ );
68
+ process.exit(1);
69
+ }
70
+ },
71
+ ),
72
+ );
73
+
74
+ const groupCmd = spaceAccessCmd.command('group').description('Manage group access to a space');
75
+
76
+ groupCmd
77
+ .command('grant <projectUuid> <spaceUuid> <groupUuid> <role>')
78
+ .description('Grant a group access to a space')
79
+ .action(
80
+ wrapAction(
81
+ WRITE_IDEMPOTENT,
82
+ async (projectUuid: string, spaceUuid: string, groupUuid: string, role: string) => {
83
+ try {
84
+ const client = getClient();
85
+ await client.v1.spaces.grantGroupAccessToSpace(projectUuid, spaceUuid, {
86
+ groupUuid,
87
+ spaceRole: role as SpaceMemberRole,
88
+ });
89
+ console.error(
90
+ `Successfully granted ${role} access to group ${groupUuid} in space ${spaceUuid}`,
91
+ );
92
+ } catch (error) {
93
+ console.error(
94
+ 'Error granting group access to space:',
95
+ error instanceof Error ? error.message : String(error),
96
+ );
97
+ process.exit(1);
98
+ }
99
+ },
100
+ ),
101
+ );
102
+
103
+ groupCmd
104
+ .command('revoke <projectUuid> <spaceUuid> <groupUuid>')
105
+ .description("Revoke a group's access to a space")
106
+ .action(
107
+ wrapAction(
108
+ WRITE_DESTRUCTIVE,
109
+ async (projectUuid: string, spaceUuid: string, groupUuid: string) => {
110
+ try {
111
+ const client = getClient();
112
+ await client.v1.spaces.revokeGroupAccessToSpace(projectUuid, spaceUuid, groupUuid);
113
+ console.error(
114
+ `Successfully revoked access for group ${groupUuid} in space ${spaceUuid}`,
115
+ );
116
+ } catch (error) {
117
+ console.error(
118
+ 'Error revoking group access from space:',
119
+ error instanceof Error ? error.message : String(error),
120
+ );
121
+ process.exit(1);
122
+ }
123
+ },
124
+ ),
125
+ );
126
+ }
package/src/index.test.ts CHANGED
@@ -6,6 +6,7 @@ import { registerProjectsCommand } from './commands/projects';
6
6
  import { registerProjectRoleAssignmentsCommand } from './commands/project-role-assignments';
7
7
  import { registerProjectAccessCommand } from './commands/project-access';
8
8
  import { registerSpacesCommand } from './commands/spaces';
9
+ import { registerSpaceAccessCommand } from './commands/space-access';
9
10
  import { registerChartsCommand } from './commands/charts';
10
11
  import { registerDashboardsCommand } from './commands/dashboards';
11
12
  import { registerAiAgentsCommand } from './commands/ai-agents';
@@ -39,7 +40,7 @@ describe('CLI Command Registration', () => {
39
40
  expect(listCmd).toBeDefined();
40
41
  });
41
42
 
42
- it('should register groups command with list and get subcommands', () => {
43
+ it('should register groups command with list, get, create, update, delete, and members subcommands', () => {
43
44
  const program = new Command();
44
45
  registerGroupsCommand(program);
45
46
 
@@ -51,6 +52,27 @@ describe('CLI Command Registration', () => {
51
52
 
52
53
  const getCmd = groupsCmd?.commands.find((cmd) => cmd.name() === 'get');
53
54
  expect(getCmd).toBeDefined();
55
+
56
+ const createCmd = groupsCmd?.commands.find((cmd) => cmd.name() === 'create');
57
+ expect(createCmd).toBeDefined();
58
+
59
+ const updateCmd = groupsCmd?.commands.find((cmd) => cmd.name() === 'update');
60
+ expect(updateCmd).toBeDefined();
61
+
62
+ const deleteCmd = groupsCmd?.commands.find((cmd) => cmd.name() === 'delete');
63
+ expect(deleteCmd).toBeDefined();
64
+
65
+ const membersCmd = groupsCmd?.commands.find((cmd) => cmd.name() === 'members');
66
+ expect(membersCmd).toBeDefined();
67
+
68
+ const membersListCmd = membersCmd?.commands.find((cmd) => cmd.name() === 'list');
69
+ expect(membersListCmd).toBeDefined();
70
+
71
+ const membersAddCmd = membersCmd?.commands.find((cmd) => cmd.name() === 'add');
72
+ expect(membersAddCmd).toBeDefined();
73
+
74
+ const membersRemoveCmd = membersCmd?.commands.find((cmd) => cmd.name() === 'remove');
75
+ expect(membersRemoveCmd).toBeDefined();
54
76
  });
55
77
 
56
78
  it('should register users list with --all option', () => {
@@ -104,17 +126,19 @@ describe('CLI Command Registration', () => {
104
126
  expect(rolesCmd?.commands.some((c) => c.name() === 'assign')).toBe(true);
105
127
  });
106
128
 
107
- it('should register projects roles, access, spaces subcommands', () => {
129
+ it('should register projects roles, access, spaces, and space-access subcommands', () => {
108
130
  const program = new Command();
109
131
  registerProjectsCommand(program);
110
132
  registerProjectRoleAssignmentsCommand(program);
111
133
  registerProjectAccessCommand(program);
112
134
  registerSpacesCommand(program);
135
+ registerSpaceAccessCommand(program);
113
136
 
114
137
  const projectsCmd = program.commands.find((cmd) => cmd.name() === 'projects');
115
138
  expect(projectsCmd?.commands.some((c) => c.name() === 'roles')).toBe(true);
116
139
  expect(projectsCmd?.commands.some((c) => c.name() === 'access')).toBe(true);
117
140
  expect(projectsCmd?.commands.some((c) => c.name() === 'spaces')).toBe(true);
141
+ expect(projectsCmd?.commands.some((c) => c.name() === 'space-access')).toBe(true);
118
142
  });
119
143
 
120
144
  it('should register projects charts and dashboards subcommands', () => {
@@ -173,6 +197,7 @@ describe('CLI Command Registration', () => {
173
197
  registerProjectRoleAssignmentsCommand(program);
174
198
  registerProjectAccessCommand(program);
175
199
  registerSpacesCommand(program);
200
+ registerSpaceAccessCommand(program);
176
201
  registerChartsCommand(program);
177
202
  registerDashboardsCommand(program);
178
203
  registerAiAgentsCommand(program);
@@ -192,7 +217,7 @@ describe('CLI Command Registration', () => {
192
217
 
193
218
  it('should have --safety-mode option', () => {
194
219
  const program = new Command();
195
- program.option('--safety-mode <mode>', 'description', 'write-destructive');
220
+ program.option('--safety-mode <mode>', 'description', 'read-only');
196
221
  const option = program.options.find((opt) => opt.long === '--safety-mode');
197
222
  expect(option).toBeDefined();
198
223
  });
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ import { registerProjectsCommand } from './commands/projects';
10
10
  import { registerProjectRoleAssignmentsCommand } from './commands/project-role-assignments';
11
11
  import { registerProjectAccessCommand } from './commands/project-access';
12
12
  import { registerSpacesCommand } from './commands/spaces';
13
+ import { registerSpaceAccessCommand } from './commands/space-access';
13
14
  import { registerChartsCommand } from './commands/charts';
14
15
  import { registerDashboardsCommand } from './commands/dashboards';
15
16
  import { registerAiAgentsCommand } from './commands/ai-agents';
@@ -27,11 +28,11 @@ const program = new Command();
27
28
  program
28
29
  .name('lightdash-ai')
29
30
  .description('CLI for Lightdash AI')
30
- .version('1.0.0')
31
+ .version('0.2.6')
31
32
  .option(
32
33
  '--safety-mode <mode>',
33
34
  'Safety mode (read-only, write-idempotent, write-destructive)',
34
- 'write-destructive',
35
+ 'read-only',
35
36
  );
36
37
 
37
38
  // Register all commands (organization and projects first so subcommands can attach)
@@ -41,6 +42,7 @@ registerProjectsCommand(program);
41
42
  registerProjectRoleAssignmentsCommand(program);
42
43
  registerProjectAccessCommand(program);
43
44
  registerSpacesCommand(program);
45
+ registerSpaceAccessCommand(program);
44
46
  registerChartsCommand(program);
45
47
  registerDashboardsCommand(program);
46
48
  registerAiAgentsCommand(program);