@lightdash-tools/cli 0.2.1 → 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.
- package/README.md +63 -45
- package/dist/index.js +1 -1
- package/dist/index.test.js +6 -0
- package/dist/utils/safety.js +3 -3
- package/dist/utils/safety.test.js +3 -3
- package/package.json +3 -3
- package/src/index.test.ts +7 -0
- package/src/index.ts +1 -1
- package/src/utils/safety.test.ts +3 -3
- package/src/utils/safety.ts +4 -4
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ The CLI requires the following environment variables (consistent with `@lightdas
|
|
|
25
25
|
- `LIGHTDASH_URL` - Lightdash server base URL (e.g., `https://app.lightdash.cloud`)
|
|
26
26
|
- `LIGHTDASH_API_KEY` - Personal access token (PAT)
|
|
27
27
|
- `LIGHTDASH_PROXY_AUTHORIZATION` - Optional proxy authorization header
|
|
28
|
+
- `LIGHTDASH_TOOL_SAFETY_MODE` - Optional safety mode (`read-only`, `write-idempotent`, `write-destructive`)
|
|
28
29
|
|
|
29
30
|
Example:
|
|
30
31
|
|
|
@@ -41,6 +42,7 @@ The CLI provides subcommands grouped by domain. All commands output JSON by defa
|
|
|
41
42
|
|
|
42
43
|
```bash
|
|
43
44
|
lightdash-tools organization get
|
|
45
|
+
lightdash-tools organization-roles list
|
|
44
46
|
```
|
|
45
47
|
|
|
46
48
|
#### Projects
|
|
@@ -48,64 +50,68 @@ lightdash-tools organization get
|
|
|
48
50
|
```bash
|
|
49
51
|
lightdash-tools projects list
|
|
50
52
|
lightdash-tools projects get <projectUuid>
|
|
53
|
+
lightdash-tools projects validate run <projectUuid>
|
|
54
|
+
lightdash-tools projects validate results <projectUuid>
|
|
51
55
|
```
|
|
52
56
|
|
|
53
|
-
#### Explores
|
|
54
|
-
|
|
55
|
-
```bash
|
|
56
|
-
lightdash-tools explores list <projectUuid>
|
|
57
|
-
lightdash-tools explores get <projectUuid> <exploreId>
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
#### Charts
|
|
57
|
+
#### Explores (Project-level)
|
|
61
58
|
|
|
62
59
|
```bash
|
|
63
|
-
lightdash-tools
|
|
64
|
-
lightdash-tools
|
|
65
|
-
lightdash-tools
|
|
60
|
+
lightdash-tools projects explores list <projectUuid>
|
|
61
|
+
lightdash-tools projects explores get <projectUuid> <exploreId>
|
|
62
|
+
lightdash-tools projects explores dimensions <projectUuid> <exploreId>
|
|
63
|
+
lightdash-tools projects explores lineage <projectUuid> <exploreId> <fieldId>
|
|
66
64
|
```
|
|
67
65
|
|
|
68
|
-
####
|
|
66
|
+
#### Charts (Project-level)
|
|
69
67
|
|
|
70
68
|
```bash
|
|
71
|
-
lightdash-tools
|
|
69
|
+
lightdash-tools projects charts list <projectUuid>
|
|
70
|
+
lightdash-tools projects charts code list <projectUuid> --ids <slugs...>
|
|
71
|
+
lightdash-tools projects charts code upsert <projectUuid> <slug> --file <chart.json>
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
####
|
|
74
|
+
#### Dashboards (Project-level)
|
|
75
75
|
|
|
76
76
|
```bash
|
|
77
|
-
lightdash-tools
|
|
78
|
-
lightdash-tools spaces get <projectUuid> <spaceUuid>
|
|
77
|
+
lightdash-tools projects dashboards list <projectUuid>
|
|
79
78
|
```
|
|
80
79
|
|
|
81
|
-
####
|
|
80
|
+
#### Spaces (Project-level)
|
|
82
81
|
|
|
83
82
|
```bash
|
|
84
|
-
lightdash-tools
|
|
83
|
+
lightdash-tools projects spaces list <projectUuid>
|
|
84
|
+
lightdash-tools projects spaces get <projectUuid> <spaceUuid>
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
#### Users
|
|
87
|
+
#### Users & Groups
|
|
88
88
|
|
|
89
89
|
```bash
|
|
90
90
|
lightdash-tools users list
|
|
91
|
+
lightdash-tools users get <userUuid>
|
|
92
|
+
lightdash-tools groups list
|
|
91
93
|
```
|
|
92
94
|
|
|
93
|
-
#### Metrics
|
|
95
|
+
#### Metrics & Schedulers
|
|
94
96
|
|
|
95
97
|
```bash
|
|
96
98
|
lightdash-tools metrics list <projectUuid>
|
|
99
|
+
lightdash-tools metrics get <projectUuid> <tableName> <metricName>
|
|
100
|
+
lightdash-tools schedulers list <projectUuid>
|
|
101
|
+
lightdash-tools schedulers get <schedulerUuid>
|
|
97
102
|
```
|
|
98
103
|
|
|
99
|
-
####
|
|
104
|
+
#### Tags
|
|
100
105
|
|
|
101
106
|
```bash
|
|
102
|
-
lightdash-tools
|
|
107
|
+
lightdash-tools tags list <projectUuid>
|
|
108
|
+
lightdash-tools tags get <projectUuid> <tagUuid>
|
|
103
109
|
```
|
|
104
110
|
|
|
105
|
-
####
|
|
111
|
+
#### Query
|
|
106
112
|
|
|
107
113
|
```bash
|
|
108
|
-
lightdash-tools
|
|
114
|
+
lightdash-tools query compile <projectUuid> <exploreId> --file <query.json>
|
|
109
115
|
```
|
|
110
116
|
|
|
111
117
|
#### Content (Experimental)
|
|
@@ -120,43 +126,55 @@ lightdash-tools content search "query"
|
|
|
120
126
|
lightdash-tools ai-agents list
|
|
121
127
|
```
|
|
122
128
|
|
|
123
|
-
#### Project
|
|
129
|
+
#### Access Control (Project-level)
|
|
124
130
|
|
|
125
131
|
```bash
|
|
126
|
-
lightdash-tools project-access list <projectUuid>
|
|
132
|
+
lightdash-tools projects project-access list <projectUuid>
|
|
133
|
+
lightdash-tools projects project-role-assignments list <projectUuid>
|
|
127
134
|
```
|
|
128
135
|
|
|
129
|
-
|
|
136
|
+
### Help
|
|
137
|
+
|
|
138
|
+
Get help for any command:
|
|
130
139
|
|
|
131
140
|
```bash
|
|
132
|
-
lightdash-tools
|
|
141
|
+
lightdash-tools --help
|
|
142
|
+
lightdash-tools projects --help
|
|
143
|
+
lightdash-tools projects charts --help
|
|
133
144
|
```
|
|
134
145
|
|
|
135
|
-
|
|
146
|
+
## Output Format
|
|
136
147
|
|
|
137
|
-
|
|
138
|
-
lightdash-tools project-role-assignments list <projectUuid>
|
|
139
|
-
```
|
|
148
|
+
All commands output JSON by default, formatted with 2-space indentation.
|
|
140
149
|
|
|
141
|
-
|
|
150
|
+
## Safety Modes
|
|
142
151
|
|
|
143
|
-
|
|
144
|
-
lightdash-tools query compile <projectUuid> <exploreId> --file <query.json>
|
|
145
|
-
```
|
|
152
|
+
The CLI implements a hierarchical safety model to prevent accidental destructive operations. This is the same model used by the Lightdash MCP server.
|
|
146
153
|
|
|
147
|
-
###
|
|
154
|
+
### Configuration
|
|
148
155
|
|
|
149
|
-
|
|
156
|
+
You can control the safety mode via the `LIGHTDASH_TOOL_SAFETY_MODE` environment variable or the global `--safety-mode` flag.
|
|
157
|
+
|
|
158
|
+
- `read-only`: Only allows non-modifying operations (e.g., list, get).
|
|
159
|
+
- `write-idempotent`: Allows read operations and non-destructive writes (e.g., upsert, validate run).
|
|
160
|
+
- `write-destructive` (default): Allows all operations, including deletions.
|
|
161
|
+
|
|
162
|
+
### Enforcement
|
|
163
|
+
|
|
164
|
+
The CLI uses **Dynamic Enforcement**: all commands remain visible in help, but if you attempt to execute a command that is forbidden in the current mode, the CLI will exit with an error message.
|
|
165
|
+
|
|
166
|
+
Example:
|
|
150
167
|
|
|
151
168
|
```bash
|
|
152
|
-
|
|
153
|
-
lightdash-tools
|
|
154
|
-
lightdash-tools charts --help
|
|
155
|
-
```
|
|
169
|
+
# This will work
|
|
170
|
+
lightdash-tools --safety-mode read-only users list
|
|
156
171
|
|
|
157
|
-
|
|
172
|
+
# This will fail if delete was implemented
|
|
173
|
+
lightdash-tools --safety-mode read-only users delete <uuid>
|
|
174
|
+
```
|
|
158
175
|
|
|
159
|
-
|
|
176
|
+
When a command is blocked, you will see an error like:
|
|
177
|
+
`Error: This command is disabled in read-only mode. To enable it, use --safety-mode or set LIGHTDASH_TOOL_SAFETY_MODE.`
|
|
160
178
|
|
|
161
179
|
## Error Handling
|
|
162
180
|
|
|
@@ -173,7 +191,7 @@ If you are developing the CLI itself:
|
|
|
173
191
|
1. Install dependencies: `pnpm install`
|
|
174
192
|
2. Build: `pnpm build`
|
|
175
193
|
3. Run tests: `pnpm test`
|
|
176
|
-
4. Run locally: `node dist/index.
|
|
194
|
+
4. Run locally: `node dist/index.js`
|
|
177
195
|
|
|
178
196
|
## License
|
|
179
197
|
|
package/dist/index.js
CHANGED
|
@@ -27,7 +27,7 @@ program
|
|
|
27
27
|
.name('lightdash-ai')
|
|
28
28
|
.description('CLI for Lightdash AI')
|
|
29
29
|
.version('1.0.0')
|
|
30
|
-
.option('--mode <mode>', 'Safety mode (read-only, write-idempotent, write-destructive)', 'write-destructive');
|
|
30
|
+
.option('--safety-mode <mode>', 'Safety mode (read-only, write-idempotent, write-destructive)', 'write-destructive');
|
|
31
31
|
// Register all commands (organization and projects first so subcommands can attach)
|
|
32
32
|
(0, organization_1.registerOrganizationCommand)(program);
|
|
33
33
|
(0, organization_roles_1.registerOrganizationRolesCommand)(program);
|
package/dist/index.test.js
CHANGED
|
@@ -156,4 +156,10 @@ const explores_1 = require("./commands/explores");
|
|
|
156
156
|
'users',
|
|
157
157
|
]);
|
|
158
158
|
});
|
|
159
|
+
(0, vitest_1.it)('should have --safety-mode option', () => {
|
|
160
|
+
const program = new commander_1.Command();
|
|
161
|
+
program.option('--safety-mode <mode>', 'description', 'write-destructive');
|
|
162
|
+
const option = program.options.find((opt) => opt.long === '--safety-mode');
|
|
163
|
+
(0, vitest_1.expect)(option).toBeDefined();
|
|
164
|
+
});
|
|
159
165
|
});
|
package/dist/utils/safety.js
CHANGED
|
@@ -17,8 +17,8 @@ const common_1 = require("@lightdash-tools/common");
|
|
|
17
17
|
*/
|
|
18
18
|
function getSafetyMode(cmd) {
|
|
19
19
|
const options = cmd.optsWithGlobals();
|
|
20
|
-
if (options.
|
|
21
|
-
return options.
|
|
20
|
+
if (options.safetyMode && Object.values(common_1.SafetyMode).includes(options.safetyMode)) {
|
|
21
|
+
return options.safetyMode;
|
|
22
22
|
}
|
|
23
23
|
return (0, common_1.getSafetyModeFromEnv)();
|
|
24
24
|
}
|
|
@@ -30,7 +30,7 @@ function wrapAction(annotations, action) {
|
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
31
|
const mode = getSafetyMode(this);
|
|
32
32
|
if (!(0, common_1.isAllowed)(mode, annotations)) {
|
|
33
|
-
console.error(`Error: This command is disabled in ${mode} mode. To enable it, use --mode or set
|
|
33
|
+
console.error(`Error: This command is disabled in ${mode} mode. To enable it, use --safety-mode or set LIGHTDASH_TOOL_SAFETY_MODE.`);
|
|
34
34
|
process.exit(1);
|
|
35
35
|
}
|
|
36
36
|
return action.apply(this, args);
|
|
@@ -24,7 +24,7 @@ const commander_1 = require("commander");
|
|
|
24
24
|
});
|
|
25
25
|
(0, vitest_1.it)('should allow read-only action in read-only mode', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
26
|
const cmd = new commander_1.Command();
|
|
27
|
-
cmd.setOptionValueWithSource('
|
|
27
|
+
cmd.setOptionValueWithSource('safetyMode', common_1.SafetyMode.READ_ONLY, 'cli');
|
|
28
28
|
const wrapped = (0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, mockAction);
|
|
29
29
|
yield wrapped.call(cmd, 'arg1');
|
|
30
30
|
(0, vitest_1.expect)(mockAction).toHaveBeenCalledWith('arg1');
|
|
@@ -32,7 +32,7 @@ const commander_1 = require("commander");
|
|
|
32
32
|
}));
|
|
33
33
|
(0, vitest_1.it)('should block destructive action in read-only mode', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
34
|
const cmd = new commander_1.Command();
|
|
35
|
-
cmd.setOptionValueWithSource('
|
|
35
|
+
cmd.setOptionValueWithSource('safetyMode', common_1.SafetyMode.READ_ONLY, 'cli');
|
|
36
36
|
const wrapped = (0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, mockAction);
|
|
37
37
|
yield (0, vitest_1.expect)(wrapped.call(cmd, 'arg1')).rejects.toThrow('exit');
|
|
38
38
|
(0, vitest_1.expect)(mockAction).not.toHaveBeenCalled();
|
|
@@ -41,7 +41,7 @@ const commander_1 = require("commander");
|
|
|
41
41
|
}));
|
|
42
42
|
(0, vitest_1.it)('should allow destructive action in write-destructive mode', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
43
|
const cmd = new commander_1.Command();
|
|
44
|
-
cmd.setOptionValueWithSource('
|
|
44
|
+
cmd.setOptionValueWithSource('safetyMode', common_1.SafetyMode.WRITE_DESTRUCTIVE, 'cli');
|
|
45
45
|
const wrapped = (0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, mockAction);
|
|
46
46
|
yield wrapped.call(cmd, 'arg1');
|
|
47
47
|
(0, vitest_1.expect)(mockAction).toHaveBeenCalledWith('arg1');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash-tools/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
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.
|
|
16
|
-
"@lightdash-tools/common": "0.2.
|
|
15
|
+
"@lightdash-tools/client": "0.2.4",
|
|
16
|
+
"@lightdash-tools/common": "0.2.4"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "^25.2.3"
|
package/src/index.test.ts
CHANGED
|
@@ -189,4 +189,11 @@ describe('CLI Command Registration', () => {
|
|
|
189
189
|
'users',
|
|
190
190
|
]);
|
|
191
191
|
});
|
|
192
|
+
|
|
193
|
+
it('should have --safety-mode option', () => {
|
|
194
|
+
const program = new Command();
|
|
195
|
+
program.option('--safety-mode <mode>', 'description', 'write-destructive');
|
|
196
|
+
const option = program.options.find((opt) => opt.long === '--safety-mode');
|
|
197
|
+
expect(option).toBeDefined();
|
|
198
|
+
});
|
|
192
199
|
});
|
package/src/index.ts
CHANGED
package/src/utils/safety.test.ts
CHANGED
|
@@ -16,7 +16,7 @@ describe('CLI wrapAction', () => {
|
|
|
16
16
|
|
|
17
17
|
it('should allow read-only action in read-only mode', async () => {
|
|
18
18
|
const cmd = new Command();
|
|
19
|
-
cmd.setOptionValueWithSource('
|
|
19
|
+
cmd.setOptionValueWithSource('safetyMode', SafetyMode.READ_ONLY, 'cli');
|
|
20
20
|
|
|
21
21
|
const wrapped = wrapAction(READ_ONLY_DEFAULT, mockAction);
|
|
22
22
|
await wrapped.call(cmd, 'arg1');
|
|
@@ -27,7 +27,7 @@ describe('CLI wrapAction', () => {
|
|
|
27
27
|
|
|
28
28
|
it('should block destructive action in read-only mode', async () => {
|
|
29
29
|
const cmd = new Command();
|
|
30
|
-
cmd.setOptionValueWithSource('
|
|
30
|
+
cmd.setOptionValueWithSource('safetyMode', SafetyMode.READ_ONLY, 'cli');
|
|
31
31
|
|
|
32
32
|
const wrapped = wrapAction(WRITE_DESTRUCTIVE, mockAction);
|
|
33
33
|
|
|
@@ -42,7 +42,7 @@ describe('CLI wrapAction', () => {
|
|
|
42
42
|
|
|
43
43
|
it('should allow destructive action in write-destructive mode', async () => {
|
|
44
44
|
const cmd = new Command();
|
|
45
|
-
cmd.setOptionValueWithSource('
|
|
45
|
+
cmd.setOptionValueWithSource('safetyMode', SafetyMode.WRITE_DESTRUCTIVE, 'cli');
|
|
46
46
|
|
|
47
47
|
const wrapped = wrapAction(WRITE_DESTRUCTIVE, mockAction);
|
|
48
48
|
await wrapped.call(cmd, 'arg1');
|
package/src/utils/safety.ts
CHANGED
|
@@ -6,9 +6,9 @@ import type { Command } from 'commander';
|
|
|
6
6
|
* Resolves the safety mode from the command line options or environment variables.
|
|
7
7
|
*/
|
|
8
8
|
export function getSafetyMode(cmd: Command): SafetyMode {
|
|
9
|
-
const options = cmd.optsWithGlobals() as {
|
|
10
|
-
if (options.
|
|
11
|
-
return options.
|
|
9
|
+
const options = cmd.optsWithGlobals() as { safetyMode?: string };
|
|
10
|
+
if (options.safetyMode && Object.values(SafetyMode).includes(options.safetyMode as SafetyMode)) {
|
|
11
|
+
return options.safetyMode as SafetyMode;
|
|
12
12
|
}
|
|
13
13
|
return getSafetyModeFromEnv();
|
|
14
14
|
}
|
|
@@ -24,7 +24,7 @@ export function wrapAction<T extends unknown[]>(
|
|
|
24
24
|
const mode = getSafetyMode(this);
|
|
25
25
|
if (!isAllowed(mode, annotations)) {
|
|
26
26
|
console.error(
|
|
27
|
-
`Error: This command is disabled in ${mode} mode. To enable it, use --mode or set
|
|
27
|
+
`Error: This command is disabled in ${mode} mode. To enable it, use --safety-mode or set LIGHTDASH_TOOL_SAFETY_MODE.`,
|
|
28
28
|
);
|
|
29
29
|
process.exit(1);
|
|
30
30
|
}
|