@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.
Files changed (49) hide show
  1. package/dist/audit.d.ts +29 -8
  2. package/dist/audit.js +53 -9
  3. package/dist/audit.test.js +51 -24
  4. package/dist/env.d.ts +1 -1
  5. package/dist/env.js +2 -2
  6. package/dist/operations/ai-agents.js +108 -40
  7. package/dist/operations/cli-content.js +6 -8
  8. package/dist/operations/client-coverage.d.ts +7 -0
  9. package/dist/operations/client-coverage.js +13 -4
  10. package/dist/operations/content-developer.js +19 -5
  11. package/dist/operations/content-governance.js +1 -1
  12. package/dist/operations/content-reader.js +19 -4
  13. package/dist/operations/data-analyst.d.ts +5 -0
  14. package/dist/operations/data-analyst.js +23 -0
  15. package/dist/operations/index.d.ts +2 -1
  16. package/dist/operations/index.js +4 -1
  17. package/dist/operations/organization-audit.js +1 -1
  18. package/dist/operations/registry.d.ts +5 -5
  19. package/dist/operations/registry.js +35 -9
  20. package/dist/operations/registry.test.js +23 -45
  21. package/dist/operations/semantic-layer.js +8 -7
  22. package/dist/operations/types.d.ts +10 -6
  23. package/dist/operations/types.js +23 -14
  24. package/dist/operations/types.test.js +14 -5
  25. package/dist/operations/users.js +3 -5
  26. package/dist/safety.d.ts +3 -2
  27. package/dist/safety.js +11 -3
  28. package/dist/safety.test.js +29 -6
  29. package/package.json +1 -1
  30. package/src/audit.test.ts +70 -30
  31. package/src/audit.ts +78 -11
  32. package/src/env.ts +1 -1
  33. package/src/operations/ai-agents.ts +113 -41
  34. package/src/operations/cli-content.ts +7 -10
  35. package/src/operations/client-coverage.ts +14 -5
  36. package/src/operations/content-developer.ts +23 -7
  37. package/src/operations/content-governance.ts +3 -3
  38. package/src/operations/content-reader.ts +23 -7
  39. package/src/operations/data-analyst.ts +27 -0
  40. package/src/operations/index.ts +3 -1
  41. package/src/operations/organization-audit.ts +2 -2
  42. package/src/operations/registry.test.ts +31 -52
  43. package/src/operations/registry.ts +42 -12
  44. package/src/operations/semantic-layer.ts +9 -8
  45. package/src/operations/types.test.ts +34 -6
  46. package/src/operations/types.ts +41 -31
  47. package/src/operations/users.ts +4 -7
  48. package/src/safety.test.ts +32 -6
  49. package/src/safety.ts +15 -4
@@ -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
- * Capability profiles group operations for selective exposure (CLI profiles, MCP subsets).
18
- */
19
- export type CapabilityProfile =
20
- | 'content-developer'
21
- | 'content-governance'
22
- | 'content-reader'
23
- | 'conversations'
24
- | 'core-lifecycle'
25
- | 'discovery-readonly'
26
- | 'evaluations'
27
- | 'org-audit-readonly'
28
- | 'semantic-discovery';
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
- profiles: readonly CapabilityProfile[];
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<CapabilityProfile>([
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(id: string, profiles: readonly CapabilityProfile[]): void {
160
- if (profiles.length === 0) {
161
- throw new Error(`Operation '${id}' must declare at least one capability profile`);
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 capability profile '${profile}'`);
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.id, input.profiles);
224
+ validateProfiles(input);
215
225
 
216
226
  const agentExposure = input.agentExposure ?? 'agent';
217
227
  if (agentExposure === 'client-only') {
@@ -6,10 +6,7 @@ import { READ_ONLY_DEFAULT } from '../safety';
6
6
 
7
7
  import { defineOperation } from './types';
8
8
 
9
- import type { CapabilityProfile, OperationDescriptor } from './types';
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: [PROFILE_DISCOVERY],
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: [PROFILE_DISCOVERY],
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: [PROFILE_CORE_LIFECYCLE],
54
+ profiles: [],
58
55
  });
59
56
 
60
57
  /** Organization member operations registered in the shared operation catalog. */
@@ -213,36 +213,62 @@ describe('Safety Logic', () => {
213
213
  });
214
214
 
215
215
  describe('getAllowedProjectUuidsFromEnv', () => {
216
- const originalEnv = process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
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
- process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS = originalEnv;
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 = 'uuid-a';
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 = 'uuid-a,uuid-b,uuid-c';
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 = ' uuid-a , uuid-b ';
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 = 'uuid-a,,uuid-b';
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 { ENV_LIGHTDASH_TOOLS_SAFETY_MODE, ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECTS } from './env';
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 LIGHTDASH_TOOLS_ALLOWED_PROJECTS environment
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
- * Note: CLI/MCP flags (--allowed-projects) always take priority over this env var.
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 raw = process.env[ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECTS] ?? '';
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())