@lightdash-tools/common 0.8.0 → 0.11.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/dist/audit.d.ts +29 -8
- package/dist/audit.js +53 -9
- package/dist/audit.test.js +51 -24
- package/dist/env.d.ts +1 -1
- package/dist/env.js +2 -2
- package/dist/operations/ai-agents.js +108 -40
- package/dist/operations/cli-content.js +6 -8
- package/dist/operations/client-coverage.d.ts +7 -0
- package/dist/operations/client-coverage.js +13 -4
- package/dist/operations/content-developer.js +19 -5
- package/dist/operations/content-governance.js +1 -1
- package/dist/operations/content-reader.js +19 -4
- package/dist/operations/data-analyst.d.ts +5 -0
- package/dist/operations/data-analyst.js +23 -0
- package/dist/operations/index.d.ts +2 -1
- package/dist/operations/index.js +4 -1
- package/dist/operations/organization-audit.js +1 -1
- package/dist/operations/registry.d.ts +5 -5
- package/dist/operations/registry.js +35 -9
- package/dist/operations/registry.test.js +23 -45
- package/dist/operations/semantic-layer.js +8 -7
- package/dist/operations/types.d.ts +10 -6
- package/dist/operations/types.js +23 -14
- package/dist/operations/types.test.js +14 -5
- package/dist/operations/users.js +3 -5
- package/dist/safety.d.ts +3 -2
- package/dist/safety.js +11 -3
- package/dist/safety.test.js +29 -6
- package/package.json +1 -1
- package/src/audit.test.ts +70 -30
- package/src/audit.ts +78 -11
- package/src/env.ts +1 -1
- package/src/operations/ai-agents.ts +113 -41
- package/src/operations/cli-content.ts +7 -10
- package/src/operations/client-coverage.ts +14 -5
- package/src/operations/content-developer.ts +23 -7
- package/src/operations/content-governance.ts +3 -3
- package/src/operations/content-reader.ts +23 -7
- package/src/operations/data-analyst.ts +27 -0
- package/src/operations/index.ts +3 -1
- package/src/operations/organization-audit.ts +2 -2
- package/src/operations/registry.test.ts +31 -52
- package/src/operations/registry.ts +42 -12
- package/src/operations/semantic-layer.ts +9 -8
- package/src/operations/types.test.ts +34 -6
- package/src/operations/types.ts +41 -31
- package/src/operations/users.ts +4 -7
- package/src/safety.test.ts +32 -6
- package/src/safety.ts +15 -4
package/src/operations/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared typed operation catalog (ADR-0013).
|
|
2
|
+
* Shared typed operation catalog (ADR-0013 / ADR-0006).
|
|
3
3
|
* Single source of truth for HTTP, CLI, and MCP exposure of Lightdash API operations.
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -13,19 +13,19 @@ export type AgentExposure = 'agent' | 'client-only';
|
|
|
13
13
|
/** HTTP verbs supported by registered operations. */
|
|
14
14
|
export type HttpMethod = 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT';
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
/** Runtime list of every MCP serving profile id (ADR-0006; fixed mounts / stdio). */
|
|
17
|
+
export const PROFILE_IDS = [
|
|
18
|
+
'ai-agent-ops',
|
|
19
|
+
'content-developer',
|
|
20
|
+
'content-governance',
|
|
21
|
+
'content-reader',
|
|
22
|
+
'data-analyst',
|
|
23
|
+
'organization-audit',
|
|
24
|
+
'semantic-layer',
|
|
25
|
+
] as const;
|
|
26
|
+
|
|
27
|
+
/** MCP serving profile ids aligned to fixed HTTP mounts / stdio subcommands (ADR-0006). */
|
|
28
|
+
export type ProfileId = (typeof PROFILE_IDS)[number];
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* MCP response sensitivity class (ADR-0011).
|
|
@@ -84,7 +84,11 @@ export type OperationDescriptor = {
|
|
|
84
84
|
* Defaults to `none` when omitted from `defineOperation` input.
|
|
85
85
|
*/
|
|
86
86
|
sensitivity: SensitivityClass;
|
|
87
|
-
|
|
87
|
+
/**
|
|
88
|
+
* MCP mounts that expose this op when `mcp.taskSupport.exposed` is true (ADR-0006).
|
|
89
|
+
* Empty when the op is not MCP-exposed (CLI-only / reserved / client-only).
|
|
90
|
+
*/
|
|
91
|
+
profiles: readonly ProfileId[];
|
|
88
92
|
/** `agent` (default) = may appear on MCP and/or CLI; `client-only` = typed client only. */
|
|
89
93
|
agentExposure: AgentExposure;
|
|
90
94
|
/** Present when the operation is registered (or reserved) as an MCP tool. */
|
|
@@ -106,17 +110,7 @@ export type OperationDefinitionInput = Omit<
|
|
|
106
110
|
sensitivity?: SensitivityClass;
|
|
107
111
|
};
|
|
108
112
|
|
|
109
|
-
const VALID_PROFILES = new Set<
|
|
110
|
-
'content-developer',
|
|
111
|
-
'content-governance',
|
|
112
|
-
'content-reader',
|
|
113
|
-
'conversations',
|
|
114
|
-
'core-lifecycle',
|
|
115
|
-
'discovery-readonly',
|
|
116
|
-
'evaluations',
|
|
117
|
-
'org-audit-readonly',
|
|
118
|
-
'semantic-discovery',
|
|
119
|
-
]);
|
|
113
|
+
const VALID_PROFILES = new Set<ProfileId>(PROFILE_IDS);
|
|
120
114
|
|
|
121
115
|
const VALID_SENSITIVITY = new Set<SensitivityClass>([
|
|
122
116
|
'none',
|
|
@@ -156,15 +150,31 @@ function validateIdempotentHint(
|
|
|
156
150
|
}
|
|
157
151
|
}
|
|
158
152
|
|
|
159
|
-
function validateProfiles(
|
|
160
|
-
|
|
161
|
-
|
|
153
|
+
function validateProfiles(input: OperationDefinitionInput): void {
|
|
154
|
+
const { id, profiles, mcp } = input;
|
|
155
|
+
const mcpExposed = mcp?.taskSupport.exposed === true;
|
|
156
|
+
|
|
157
|
+
if (mcpExposed && profiles.length === 0) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
`Operation '${id}' must declare at least one profile when mcp.taskSupport.exposed is true`,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (new Set(profiles).size !== profiles.length) {
|
|
164
|
+
throw new Error(`Operation '${id}' has duplicate profiles: ${profiles.join(', ')}`);
|
|
162
165
|
}
|
|
166
|
+
|
|
163
167
|
for (const profile of profiles) {
|
|
164
168
|
if (!VALID_PROFILES.has(profile)) {
|
|
165
|
-
throw new Error(`Operation '${id}' has unknown
|
|
169
|
+
throw new Error(`Operation '${id}' has unknown profile '${profile}'`);
|
|
166
170
|
}
|
|
167
171
|
}
|
|
172
|
+
|
|
173
|
+
if (!mcpExposed && profiles.length > 0) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
`Operation '${id}' must use empty profiles when not MCP-exposed (got ${profiles.join(', ')})`,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
168
178
|
}
|
|
169
179
|
|
|
170
180
|
function validateClientOnlyOperation(input: OperationDefinitionInput): OperationDescriptor {
|
|
@@ -211,7 +221,7 @@ export function defineOperation(input: OperationDefinitionInput): OperationDescr
|
|
|
211
221
|
throw new Error(`Operation '${input.id}' has unknown sensitivity '${String(sensitivity)}'`);
|
|
212
222
|
}
|
|
213
223
|
|
|
214
|
-
validateProfiles(input
|
|
224
|
+
validateProfiles(input);
|
|
215
225
|
|
|
216
226
|
const agentExposure = input.agentExposure ?? 'agent';
|
|
217
227
|
if (agentExposure === 'client-only') {
|
package/src/operations/users.ts
CHANGED
|
@@ -6,10 +6,7 @@ import { READ_ONLY_DEFAULT } from '../safety';
|
|
|
6
6
|
|
|
7
7
|
import { defineOperation } from './types';
|
|
8
8
|
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
const PROFILE_DISCOVERY: CapabilityProfile = 'discovery-readonly';
|
|
12
|
-
const PROFILE_CORE_LIFECYCLE: CapabilityProfile = 'core-lifecycle';
|
|
9
|
+
import type { OperationDescriptor } from './types';
|
|
13
10
|
|
|
14
11
|
const API_V1 = '/api/v1';
|
|
15
12
|
const MEMBERS_PATH = `${API_V1}/org/users`;
|
|
@@ -28,7 +25,7 @@ const membersList = defineOperation({
|
|
|
28
25
|
taskSupport: { exposed: false, taskEligible: false },
|
|
29
26
|
},
|
|
30
27
|
cli: { commandPath: 'users list' },
|
|
31
|
-
profiles: [
|
|
28
|
+
profiles: [],
|
|
32
29
|
});
|
|
33
30
|
|
|
34
31
|
const membersGet = defineOperation({
|
|
@@ -43,7 +40,7 @@ const membersGet = defineOperation({
|
|
|
43
40
|
taskSupport: { exposed: false, taskEligible: false },
|
|
44
41
|
},
|
|
45
42
|
cli: { commandPath: 'users get' },
|
|
46
|
-
profiles: [
|
|
43
|
+
profiles: [],
|
|
47
44
|
});
|
|
48
45
|
|
|
49
46
|
const membersDelete = defineOperation({
|
|
@@ -54,7 +51,7 @@ const membersDelete = defineOperation({
|
|
|
54
51
|
sensitivity: 'none',
|
|
55
52
|
agentExposure: 'client-only',
|
|
56
53
|
bannedMcpToolName: 'delete_member',
|
|
57
|
-
profiles: [
|
|
54
|
+
profiles: [],
|
|
58
55
|
});
|
|
59
56
|
|
|
60
57
|
/** Organization member operations registered in the shared operation catalog. */
|
package/src/safety.test.ts
CHANGED
|
@@ -213,36 +213,62 @@ describe('Safety Logic', () => {
|
|
|
213
213
|
});
|
|
214
214
|
|
|
215
215
|
describe('getAllowedProjectUuidsFromEnv', () => {
|
|
216
|
-
const originalEnv = process.env.
|
|
216
|
+
const originalEnv = process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS;
|
|
217
|
+
const originalLegacy = process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
|
|
217
218
|
|
|
218
219
|
afterEach(() => {
|
|
219
|
-
|
|
220
|
+
if (originalEnv === undefined) {
|
|
221
|
+
delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS;
|
|
222
|
+
} else {
|
|
223
|
+
process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS = originalEnv;
|
|
224
|
+
}
|
|
225
|
+
if (originalLegacy === undefined) {
|
|
226
|
+
delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
|
|
227
|
+
} else {
|
|
228
|
+
process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS = originalLegacy;
|
|
229
|
+
}
|
|
220
230
|
});
|
|
221
231
|
|
|
222
232
|
it('should return empty array when env is not set', () => {
|
|
233
|
+
delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS;
|
|
223
234
|
delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
|
|
224
235
|
expect(getAllowedProjectUuidsFromEnv()).toEqual([]);
|
|
225
236
|
});
|
|
226
237
|
|
|
227
238
|
it('should parse a single UUID', () => {
|
|
228
|
-
process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS
|
|
239
|
+
delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
|
|
240
|
+
process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS = 'uuid-a';
|
|
229
241
|
expect(getAllowedProjectUuidsFromEnv()).toEqual(['uuid-a']);
|
|
230
242
|
});
|
|
231
243
|
|
|
232
244
|
it('should parse comma-separated UUIDs', () => {
|
|
233
|
-
process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS
|
|
245
|
+
delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
|
|
246
|
+
process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS = 'uuid-a,uuid-b,uuid-c';
|
|
234
247
|
expect(getAllowedProjectUuidsFromEnv()).toEqual(['uuid-a', 'uuid-b', 'uuid-c']);
|
|
235
248
|
});
|
|
236
249
|
|
|
237
250
|
it('should trim whitespace around UUIDs', () => {
|
|
238
|
-
process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS
|
|
251
|
+
delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
|
|
252
|
+
process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS = ' uuid-a , uuid-b ';
|
|
239
253
|
expect(getAllowedProjectUuidsFromEnv()).toEqual(['uuid-a', 'uuid-b']);
|
|
240
254
|
});
|
|
241
255
|
|
|
242
256
|
it('should filter out empty entries', () => {
|
|
243
|
-
process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS
|
|
257
|
+
delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
|
|
258
|
+
process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS = 'uuid-a,,uuid-b';
|
|
244
259
|
expect(getAllowedProjectUuidsFromEnv()).toEqual(['uuid-a', 'uuid-b']);
|
|
245
260
|
});
|
|
261
|
+
|
|
262
|
+
it('should reject removed LIGHTDASH_TOOLS_ALLOWED_PROJECTS', () => {
|
|
263
|
+
delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS;
|
|
264
|
+
process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS = 'uuid-a';
|
|
265
|
+
expect(() => getAllowedProjectUuidsFromEnv()).toThrow(
|
|
266
|
+
/LIGHTDASH_TOOLS_ALLOWED_PROJECTS is no longer supported/,
|
|
267
|
+
);
|
|
268
|
+
expect(() => getAllowedProjectUuidsFromEnv()).toThrow(
|
|
269
|
+
/LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS/,
|
|
270
|
+
);
|
|
271
|
+
});
|
|
246
272
|
});
|
|
247
273
|
|
|
248
274
|
describe('isProjectAllowed', () => {
|
package/src/safety.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { extractProjectUuidsFromToolArgs } from './agentops/extract-yaml-project';
|
|
2
|
-
import {
|
|
2
|
+
import { ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS, ENV_LIGHTDASH_TOOLS_SAFETY_MODE } from './env';
|
|
3
|
+
|
|
4
|
+
/** Removed allowlist env — fail closed if still set. */
|
|
5
|
+
const ENV_ALLOWED_PROJECTS_REMOVED = 'LIGHTDASH_TOOLS_ALLOWED_PROJECTS';
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Semantic impact classification for operations (RFC Phase 0).
|
|
@@ -150,14 +153,22 @@ export function getSafetyModeFromEnv(): SafetyMode {
|
|
|
150
153
|
}
|
|
151
154
|
|
|
152
155
|
/**
|
|
153
|
-
* Parses allowed project UUIDs from the
|
|
156
|
+
* Parses allowed project UUIDs from the LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS environment
|
|
154
157
|
* variable (comma-separated). Returns an empty array when the variable is unset, meaning
|
|
155
158
|
* all projects are allowed.
|
|
156
159
|
*
|
|
157
|
-
*
|
|
160
|
+
* Throws if the removed name LIGHTDASH_TOOLS_ALLOWED_PROJECTS is still set.
|
|
161
|
+
* Note: CLI `--projects` takes priority over this env var.
|
|
158
162
|
*/
|
|
159
163
|
export function getAllowedProjectUuidsFromEnv(): string[] {
|
|
160
|
-
const
|
|
164
|
+
const legacy = process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
|
|
165
|
+
if (legacy !== undefined && legacy.trim() !== '') {
|
|
166
|
+
throw new Error(
|
|
167
|
+
`${ENV_ALLOWED_PROJECTS_REMOVED} is no longer supported. ` +
|
|
168
|
+
`Use ${ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS} instead.`,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
const raw = process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS ?? '';
|
|
161
172
|
return raw
|
|
162
173
|
.split(',')
|
|
163
174
|
.map((s) => s.trim())
|