@lightdash-tools/common 0.7.0 → 0.9.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 (71) hide show
  1. package/dist/argument-validation.js +20 -2
  2. package/dist/argument-validation.test.js +22 -0
  3. package/dist/audit.d.ts +29 -9
  4. package/dist/audit.js +53 -9
  5. package/dist/audit.test.js +51 -24
  6. package/dist/env.d.ts +1 -1
  7. package/dist/env.js +2 -2
  8. package/dist/index.d.ts +1 -3
  9. package/dist/index.js +6 -8
  10. package/dist/operations/agent-safe.d.ts +1 -3
  11. package/dist/operations/agent-safe.js +2 -9
  12. package/dist/operations/ai-agents.js +118 -30
  13. package/dist/operations/cli-content.d.ts +5 -0
  14. package/dist/operations/cli-content.js +71 -0
  15. package/dist/operations/client-coverage.d.ts +119 -0
  16. package/dist/operations/client-coverage.js +137 -0
  17. package/dist/operations/client-coverage.test.d.ts +1 -0
  18. package/dist/operations/client-coverage.test.js +22 -0
  19. package/dist/operations/content-developer.d.ts +2 -0
  20. package/dist/operations/content-developer.js +471 -0
  21. package/dist/operations/content-governance.d.ts +7 -0
  22. package/dist/operations/content-governance.js +98 -0
  23. package/dist/operations/content-reader.d.ts +2 -0
  24. package/dist/operations/content-reader.js +197 -0
  25. package/dist/operations/index.d.ts +10 -3
  26. package/dist/operations/index.js +20 -2
  27. package/dist/operations/organization-audit.d.ts +2 -0
  28. package/dist/operations/organization-audit.js +273 -0
  29. package/dist/operations/parity.test.js +12 -11
  30. package/dist/operations/registry.d.ts +9 -1
  31. package/dist/operations/registry.js +77 -2
  32. package/dist/operations/registry.test.js +39 -11
  33. package/dist/operations/semantic-layer.d.ts +6 -0
  34. package/dist/operations/semantic-layer.js +154 -0
  35. package/dist/operations/types.d.ts +29 -12
  36. package/dist/operations/types.js +64 -29
  37. package/dist/operations/types.test.js +33 -45
  38. package/dist/operations/users.d.ts +2 -2
  39. package/dist/operations/users.js +8 -10
  40. package/dist/safety.d.ts +8 -2
  41. package/dist/safety.js +22 -4
  42. package/dist/safety.test.js +29 -6
  43. package/dist/types/index.d.ts +12 -0
  44. package/dist/types/index.js +29 -0
  45. package/package.json +2 -1
  46. package/src/argument-validation.test.ts +31 -0
  47. package/src/argument-validation.ts +20 -2
  48. package/src/audit.test.ts +70 -30
  49. package/src/audit.ts +88 -12
  50. package/src/env.ts +1 -1
  51. package/src/index.ts +5 -9
  52. package/src/operations/agent-safe.ts +2 -12
  53. package/src/operations/ai-agents.ts +123 -31
  54. package/src/operations/cli-content.ts +79 -0
  55. package/src/operations/client-coverage.test.ts +23 -0
  56. package/src/operations/client-coverage.ts +153 -0
  57. package/src/operations/content-developer.ts +501 -0
  58. package/src/operations/content-governance.ts +110 -0
  59. package/src/operations/content-reader.ts +212 -0
  60. package/src/operations/index.ts +25 -2
  61. package/src/operations/organization-audit.ts +293 -0
  62. package/src/operations/parity.test.ts +12 -14
  63. package/src/operations/registry.test.ts +41 -9
  64. package/src/operations/registry.ts +86 -2
  65. package/src/operations/semantic-layer.ts +166 -0
  66. package/src/operations/types.test.ts +38 -76
  67. package/src/operations/types.ts +112 -47
  68. package/src/operations/users.ts +9 -11
  69. package/src/safety.test.ts +32 -6
  70. package/src/safety.ts +26 -4
  71. package/src/types/index.ts +13 -0
@@ -18,6 +18,7 @@ const baseDescriptor = {
18
18
  summary: 'Test operation',
19
19
  http: { method: 'GET', path: '/api/v1/test' },
20
20
  authorization: { safetyImpact: 'read' },
21
+ sensitivity: 'none',
21
22
  mcp: {
22
23
  toolName: 'test_op',
23
24
  annotations: {
@@ -34,71 +35,58 @@ const baseDescriptor = {
34
35
  };
35
36
  (0, vitest_1.describe)('defineOperation', () => {
36
37
  (0, vitest_1.it)('accepts a valid read descriptor', () => {
37
- (0, vitest_1.expect)((0, types_1.defineOperation)(baseDescriptor)).toEqual(Object.assign(Object.assign({}, baseDescriptor), { agentExposure: 'agent' }));
38
+ (0, vitest_1.expect)((0, types_1.defineOperation)(baseDescriptor)).toEqual(Object.assign(Object.assign({}, baseDescriptor), { agentExposure: 'agent', sensitivity: 'none' }));
38
39
  });
39
- (0, vitest_1.it)('defaults agentExposure to agent', () => {
40
- const { agentExposure } = baseDescriptor, withoutExposure = __rest(baseDescriptor, ["agentExposure"]);
40
+ (0, vitest_1.it)('defaults agentExposure to agent and sensitivity to none', () => {
41
+ const { agentExposure, sensitivity } = baseDescriptor, withoutDefaults = __rest(baseDescriptor, ["agentExposure", "sensitivity"]);
41
42
  void agentExposure;
42
- (0, vitest_1.expect)((0, types_1.defineOperation)(withoutExposure).agentExposure).toBe('agent');
43
+ void sensitivity;
44
+ const op = (0, types_1.defineOperation)(withoutDefaults);
45
+ (0, vitest_1.expect)(op.agentExposure).toBe('agent');
46
+ (0, vitest_1.expect)(op.sensitivity).toBe('none');
43
47
  });
44
- (0, vitest_1.it)('rejects empty id', () => {
45
- (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { id: ' ' }))).toThrow(/id/);
48
+ (0, vitest_1.it)('allows agent ops with mcp only', () => {
49
+ const { cli: _cli } = baseDescriptor, rest = __rest(baseDescriptor, ["cli"]);
50
+ void _cli;
51
+ (0, vitest_1.expect)((0, types_1.defineOperation)(rest).cli).toBeUndefined();
46
52
  });
47
- (0, vitest_1.it)('rejects empty summary', () => {
48
- (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { summary: '' }))).toThrow(/summary/);
53
+ (0, vitest_1.it)('allows agent ops with cli only', () => {
54
+ const { mcp: _mcp } = baseDescriptor, rest = __rest(baseDescriptor, ["mcp"]);
55
+ void _mcp;
56
+ (0, vitest_1.expect)((0, types_1.defineOperation)(rest).mcp).toBeUndefined();
49
57
  });
50
- (0, vitest_1.it)('rejects empty http path', () => {
51
- (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { http: { method: 'GET', path: '' } }))).toThrow(/http.path/);
58
+ (0, vitest_1.it)('rejects agent ops with neither mcp nor cli', () => {
59
+ const { mcp: _mcp, cli: _cli } = baseDescriptor, rest = __rest(baseDescriptor, ["mcp", "cli"]);
60
+ void _mcp;
61
+ void _cli;
62
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)(rest)).toThrow(/require mcp and\/or cli/);
52
63
  });
53
- (0, vitest_1.it)('rejects empty profiles', () => {
54
- (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { profiles: [] }))).toThrow(/profile/);
64
+ (0, vitest_1.it)('rejects empty id', () => {
65
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { id: ' ' }))).toThrow(/id/);
55
66
  });
56
67
  (0, vitest_1.it)('rejects unknown profile', () => {
57
68
  (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { profiles: ['unknown-profile'] }))).toThrow(/unknown capability profile/);
58
69
  });
59
- (0, vitest_1.it)('rejects read operation without idempotentHint', () => {
60
- (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { mcp: Object.assign(Object.assign({}, baseDescriptor.mcp), { annotations: Object.assign(Object.assign({}, baseDescriptor.mcp.annotations), { idempotentHint: false }) }) }))).toThrow(/idempotentHint/);
61
- });
62
- (0, vitest_1.it)('rejects destructive operation with idempotentHint true', () => {
63
- (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { authorization: { safetyImpact: 'write-destructive' }, mcp: Object.assign(Object.assign({}, baseDescriptor.mcp), { annotations: {
64
- readOnlyHint: false,
65
- destructiveHint: true,
66
- idempotentHint: true,
67
- openWorldHint: false,
68
- } }) }))).toThrow(/destructive operations/);
70
+ (0, vitest_1.it)('allows read operation with idempotentHint false (transient execution)', () => {
71
+ var _a;
72
+ const op = (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { mcp: Object.assign(Object.assign({}, baseDescriptor.mcp), { annotations: Object.assign(Object.assign({}, baseDescriptor.mcp.annotations), { idempotentHint: false }) }) }));
73
+ (0, vitest_1.expect)((_a = op.mcp) === null || _a === void 0 ? void 0 : _a.annotations.idempotentHint).toBe(false);
69
74
  });
70
- (0, vitest_1.it)('rejects client-only operation with mcp exposed', () => {
71
- (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { agentExposure: 'client-only', mcp: Object.assign(Object.assign({}, baseDescriptor.mcp), { taskSupport: { exposed: true, taskEligible: false } }) }))).toThrow(/client-only operations must set mcp.taskSupport.exposed to false/);
75
+ (0, vitest_1.it)('rejects client-only operation that still has mcp', () => {
76
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { agentExposure: 'client-only' }))).toThrow(/must omit mcp and cli/);
72
77
  });
73
- (0, vitest_1.it)('allows client-only operation without mcp tool name or cli path', () => {
78
+ (0, vitest_1.it)('allows client-only operation with bannedMcpToolName and no mcp/cli', () => {
74
79
  const op = (0, types_1.defineOperation)({
75
80
  id: 'test.client-only',
76
81
  summary: 'Client only delete',
77
82
  http: { method: 'DELETE', path: '/api/v1/test/{id}' },
78
83
  authorization: { safetyImpact: 'write-destructive' },
79
- mcp: {
80
- toolName: '',
81
- annotations: {
82
- readOnlyHint: false,
83
- destructiveHint: true,
84
- idempotentHint: false,
85
- openWorldHint: false,
86
- },
87
- taskSupport: { exposed: false, taskEligible: false },
88
- },
89
- cli: { commandPath: '' },
90
84
  agentExposure: 'client-only',
85
+ bannedMcpToolName: 'delete_test',
91
86
  profiles: ['discovery-readonly'],
92
87
  });
93
88
  (0, vitest_1.expect)(op.agentExposure).toBe('client-only');
94
- });
95
- (0, vitest_1.it)('maps openWorldHint to external-side-effect impact', () => {
96
- const op = (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { authorization: { safetyImpact: 'external-side-effect' }, mcp: Object.assign(Object.assign({}, baseDescriptor.mcp), { annotations: {
97
- readOnlyHint: false,
98
- destructiveHint: false,
99
- idempotentHint: false,
100
- openWorldHint: true,
101
- } }) }));
102
- (0, vitest_1.expect)(op.authorization.safetyImpact).toBe('external-side-effect');
89
+ (0, vitest_1.expect)(op.bannedMcpToolName).toBe('delete_test');
90
+ (0, vitest_1.expect)(op.sensitivity).toBe('none');
103
91
  });
104
92
  });
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Organization member operations in the shared operation registry.
2
+ * Organization member operations in the shared operation catalog.
3
3
  */
4
4
  import type { OperationDescriptor } from './types';
5
- /** Organization member operations registered in the shared operation registry. */
5
+ /** Organization member operations registered in the shared operation catalog. */
6
6
  export declare const USER_OPERATIONS: readonly OperationDescriptor[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * Organization member operations in the shared operation registry.
3
+ * Organization member operations in the shared operation catalog.
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.USER_OPERATIONS = void 0;
@@ -17,10 +17,11 @@ const membersList = (0, types_1.defineOperation)({
17
17
  summary: 'List organization members (one page)',
18
18
  http: { method: 'GET', path: MEMBERS_PATH },
19
19
  authorization: { safetyImpact: 'read' },
20
+ sensitivity: 'pii.email',
20
21
  mcp: {
21
22
  toolName: 'list_organization_members',
22
23
  annotations: safety_1.READ_ONLY_DEFAULT,
23
- taskSupport: { exposed: true, taskEligible: false },
24
+ taskSupport: { exposed: false, taskEligible: false },
24
25
  },
25
26
  cli: { commandPath: 'users list' },
26
27
  profiles: [PROFILE_DISCOVERY],
@@ -30,10 +31,11 @@ const membersGet = (0, types_1.defineOperation)({
30
31
  summary: 'Get an organization member by UUID',
31
32
  http: { method: 'GET', path: MEMBER_PATH },
32
33
  authorization: { safetyImpact: 'read' },
34
+ sensitivity: 'pii.email',
33
35
  mcp: {
34
36
  toolName: 'get_member',
35
37
  annotations: safety_1.READ_ONLY_DEFAULT,
36
- taskSupport: { exposed: true, taskEligible: false },
38
+ taskSupport: { exposed: false, taskEligible: false },
37
39
  },
38
40
  cli: { commandPath: 'users get' },
39
41
  profiles: [PROFILE_DISCOVERY],
@@ -43,16 +45,12 @@ const membersDelete = (0, types_1.defineOperation)({
43
45
  summary: 'Permanently remove a user from the organization (irrecoverable; client-only)',
44
46
  http: { method: 'DELETE', path: DELETE_MEMBER_PATH },
45
47
  authorization: { safetyImpact: 'write-destructive' },
46
- mcp: {
47
- toolName: 'delete_member',
48
- annotations: safety_1.WRITE_DESTRUCTIVE,
49
- taskSupport: { exposed: false, taskEligible: false },
50
- },
51
- cli: { commandPath: '' },
48
+ sensitivity: 'none',
52
49
  agentExposure: 'client-only',
50
+ bannedMcpToolName: 'delete_member',
53
51
  profiles: [PROFILE_CORE_LIFECYCLE],
54
52
  });
55
- /** Organization member operations registered in the shared operation registry. */
53
+ /** Organization member operations registered in the shared operation catalog. */
56
54
  exports.USER_OPERATIONS = [
57
55
  membersList,
58
56
  membersGet,
package/dist/safety.d.ts CHANGED
@@ -30,6 +30,11 @@ export type OperationPolicy = {
30
30
  };
31
31
  /** Preset: read-only, non-destructive, idempotent, closed-world. Use for list/get/compile tools. */
32
32
  export declare const READ_ONLY_DEFAULT: ToolAnnotations;
33
+ /**
34
+ * Preset: read-only but non-idempotent (transient warehouse execution).
35
+ * Used by content-reader saved-chart/tile runs (ADR-0012).
36
+ */
37
+ export declare const READ_ONLY_TRANSIENT: ToolAnnotations;
33
38
  /**
34
39
  * Legacy preset: write, non-destructive, idempotent (e.g. upsert by slug).
35
40
  * Prefer {@link WRITE_NONDESTRUCTIVE} for new tools; idempotent behavior is not implied by safety mode.
@@ -57,11 +62,12 @@ export declare function isOperationAllowed(mode: SafetyMode | string, policy: Op
57
62
  */
58
63
  export declare function getSafetyModeFromEnv(): SafetyMode;
59
64
  /**
60
- * Parses allowed project UUIDs from the LIGHTDASH_TOOLS_ALLOWED_PROJECTS environment
65
+ * Parses allowed project UUIDs from the LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS environment
61
66
  * variable (comma-separated). Returns an empty array when the variable is unset, meaning
62
67
  * all projects are allowed.
63
68
  *
64
- * Note: CLI/MCP flags (--allowed-projects) always take priority over this env var.
69
+ * Throws if the removed name LIGHTDASH_TOOLS_ALLOWED_PROJECTS is still set.
70
+ * Note: CLI `--projects` takes priority over this env var.
65
71
  */
66
72
  export declare function getAllowedProjectUuidsFromEnv(): string[];
67
73
  /**
package/dist/safety.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WRITE_DESTRUCTIVE = exports.WRITE_OPEN_WORLD = exports.WRITE_NONDESTRUCTIVE = exports.WRITE_IDEMPOTENT = exports.READ_ONLY_DEFAULT = exports.SafetyMode = void 0;
3
+ exports.WRITE_DESTRUCTIVE = exports.WRITE_OPEN_WORLD = exports.WRITE_NONDESTRUCTIVE = exports.WRITE_IDEMPOTENT = exports.READ_ONLY_TRANSIENT = exports.READ_ONLY_DEFAULT = exports.SafetyMode = void 0;
4
4
  exports.isAllowed = isAllowed;
5
5
  exports.isOperationAllowed = isOperationAllowed;
6
6
  exports.getSafetyModeFromEnv = getSafetyModeFromEnv;
@@ -10,6 +10,8 @@ exports.areAllProjectsAllowed = areAllProjectsAllowed;
10
10
  exports.extractProjectUuids = extractProjectUuids;
11
11
  const extract_yaml_project_1 = require("./agentops/extract-yaml-project");
12
12
  const env_1 = require("./env");
13
+ /** Removed allowlist env — fail closed if still set. */
14
+ const ENV_ALLOWED_PROJECTS_REMOVED = 'LIGHTDASH_TOOLS_ALLOWED_PROJECTS';
13
15
  /**
14
16
  * Hierarchical safety modes for Lightdash AI tools and CLI.
15
17
  */
@@ -28,6 +30,16 @@ exports.READ_ONLY_DEFAULT = {
28
30
  destructiveHint: false,
29
31
  idempotentHint: true,
30
32
  };
33
+ /**
34
+ * Preset: read-only but non-idempotent (transient warehouse execution).
35
+ * Used by content-reader saved-chart/tile runs (ADR-0012).
36
+ */
37
+ exports.READ_ONLY_TRANSIENT = {
38
+ readOnlyHint: true,
39
+ openWorldHint: false,
40
+ destructiveHint: false,
41
+ idempotentHint: false,
42
+ };
31
43
  /**
32
44
  * Legacy preset: write, non-destructive, idempotent (e.g. upsert by slug).
33
45
  * Prefer {@link WRITE_NONDESTRUCTIVE} for new tools; idempotent behavior is not implied by safety mode.
@@ -110,15 +122,21 @@ function getSafetyModeFromEnv() {
110
122
  return SafetyMode.READ_ONLY;
111
123
  }
112
124
  /**
113
- * Parses allowed project UUIDs from the LIGHTDASH_TOOLS_ALLOWED_PROJECTS environment
125
+ * Parses allowed project UUIDs from the LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS environment
114
126
  * variable (comma-separated). Returns an empty array when the variable is unset, meaning
115
127
  * all projects are allowed.
116
128
  *
117
- * Note: CLI/MCP flags (--allowed-projects) always take priority over this env var.
129
+ * Throws if the removed name LIGHTDASH_TOOLS_ALLOWED_PROJECTS is still set.
130
+ * Note: CLI `--projects` takes priority over this env var.
118
131
  */
119
132
  function getAllowedProjectUuidsFromEnv() {
120
133
  var _a;
121
- const raw = (_a = process.env[env_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECTS]) !== null && _a !== void 0 ? _a : '';
134
+ const legacy = process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
135
+ if (legacy !== undefined && legacy.trim() !== '') {
136
+ throw new Error(`${ENV_ALLOWED_PROJECTS_REMOVED} is no longer supported. ` +
137
+ `Use ${env_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS} instead.`);
138
+ }
139
+ const raw = (_a = process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS) !== null && _a !== void 0 ? _a : '';
122
140
  return raw
123
141
  .split(',')
124
142
  .map((s) => s.trim())
@@ -159,30 +159,53 @@ function policy(impact) {
159
159
  });
160
160
  });
161
161
  (0, vitest_1.describe)('getAllowedProjectUuidsFromEnv', () => {
162
- const originalEnv = process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
162
+ const originalEnv = process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS;
163
+ const originalLegacy = process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
163
164
  (0, vitest_1.afterEach)(() => {
164
- process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS = originalEnv;
165
+ if (originalEnv === undefined) {
166
+ delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS;
167
+ }
168
+ else {
169
+ process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS = originalEnv;
170
+ }
171
+ if (originalLegacy === undefined) {
172
+ delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
173
+ }
174
+ else {
175
+ process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS = originalLegacy;
176
+ }
165
177
  });
166
178
  (0, vitest_1.it)('should return empty array when env is not set', () => {
179
+ delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS;
167
180
  delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
168
181
  (0, vitest_1.expect)((0, safety_1.getAllowedProjectUuidsFromEnv)()).toEqual([]);
169
182
  });
170
183
  (0, vitest_1.it)('should parse a single UUID', () => {
171
- process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS = 'uuid-a';
184
+ delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
185
+ process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS = 'uuid-a';
172
186
  (0, vitest_1.expect)((0, safety_1.getAllowedProjectUuidsFromEnv)()).toEqual(['uuid-a']);
173
187
  });
174
188
  (0, vitest_1.it)('should parse comma-separated UUIDs', () => {
175
- process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS = 'uuid-a,uuid-b,uuid-c';
189
+ delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
190
+ process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS = 'uuid-a,uuid-b,uuid-c';
176
191
  (0, vitest_1.expect)((0, safety_1.getAllowedProjectUuidsFromEnv)()).toEqual(['uuid-a', 'uuid-b', 'uuid-c']);
177
192
  });
178
193
  (0, vitest_1.it)('should trim whitespace around UUIDs', () => {
179
- process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS = ' uuid-a , uuid-b ';
194
+ delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
195
+ process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS = ' uuid-a , uuid-b ';
180
196
  (0, vitest_1.expect)((0, safety_1.getAllowedProjectUuidsFromEnv)()).toEqual(['uuid-a', 'uuid-b']);
181
197
  });
182
198
  (0, vitest_1.it)('should filter out empty entries', () => {
183
- process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS = 'uuid-a,,uuid-b';
199
+ delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
200
+ process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS = 'uuid-a,,uuid-b';
184
201
  (0, vitest_1.expect)((0, safety_1.getAllowedProjectUuidsFromEnv)()).toEqual(['uuid-a', 'uuid-b']);
185
202
  });
203
+ (0, vitest_1.it)('should reject removed LIGHTDASH_TOOLS_ALLOWED_PROJECTS', () => {
204
+ delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS;
205
+ process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS = 'uuid-a';
206
+ (0, vitest_1.expect)(() => (0, safety_1.getAllowedProjectUuidsFromEnv)()).toThrow(/LIGHTDASH_TOOLS_ALLOWED_PROJECTS is no longer supported/);
207
+ (0, vitest_1.expect)(() => (0, safety_1.getAllowedProjectUuidsFromEnv)()).toThrow(/LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS/);
208
+ });
186
209
  });
187
210
  (0, vitest_1.describe)('isProjectAllowed', () => {
188
211
  (0, vitest_1.it)('should allow all projects when allowlist is empty', () => {
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Curated public type surface for `@lightdash-tools/common` (ADR-0013).
3
+ *
4
+ * Adding a consumer type:
5
+ * 1. Alias from `generated/openapi-types` in `types/v1/` or `types/v2/` domain modules.
6
+ * 2. Export it from this barrel (via `lightdash-api.ts` or a direct re-export).
7
+ *
8
+ * Outside this package, import types only from `@lightdash-tools/common` — not from nested paths.
9
+ */
10
+ export * from './lightdash-api';
11
+ export { CONTENT_SORT_BY_COLUMNS } from './v2/content';
12
+ export type { components, operations, paths } from './generated/openapi-types';
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ /**
3
+ * Curated public type surface for `@lightdash-tools/common` (ADR-0013).
4
+ *
5
+ * Adding a consumer type:
6
+ * 1. Alias from `generated/openapi-types` in `types/v1/` or `types/v2/` domain modules.
7
+ * 2. Export it from this barrel (via `lightdash-api.ts` or a direct re-export).
8
+ *
9
+ * Outside this package, import types only from `@lightdash-tools/common` — not from nested paths.
10
+ */
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
23
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.CONTENT_SORT_BY_COLUMNS = void 0;
27
+ __exportStar(require("./lightdash-api"), exports);
28
+ var content_1 = require("./v2/content");
29
+ Object.defineProperty(exports, "CONTENT_SORT_BY_COLUMNS", { enumerable: true, get: function () { return content_1.CONTENT_SORT_BY_COLUMNS; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash-tools/common",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Shared utilities and types for Lightdash AI.",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -25,6 +25,7 @@
25
25
  },
26
26
  "scripts": {
27
27
  "build": "tsc",
28
+ "check:client-coverage": "node ../../scripts/check-client-operation-coverage.mjs",
28
29
  "generate:operation-registry": "node ../../scripts/generate-operation-registry.mjs",
29
30
  "generate:types": "node ../../scripts/openapi-types-url.mjs | xargs -I{} openapi-typescript {} -o src/types/generated/openapi-types.ts && node ../../scripts/fix-openapi-duplicate-operations.mjs && prettier --write src/types/generated/openapi-types.ts"
30
31
  }
@@ -18,12 +18,17 @@ describe('argument-validation', () => {
18
18
  'agentUuid',
19
19
  'artifactUuid',
20
20
  'chartUuid',
21
+ 'chartUuidOrSlug',
22
+ 'contentUuidOrSlug',
21
23
  'dashboardUuid',
24
+ 'dashboardUuidOrSlug',
22
25
  'evalUuid',
23
26
  'fingerprint',
24
27
  'groupUuid',
28
+ 'itemUuids',
25
29
  'mcpServerUuid',
26
30
  'messageUuid',
31
+ 'newSlug',
27
32
  'organizationUuid',
28
33
  'parentSpaceUuid',
29
34
  'project',
@@ -36,12 +41,18 @@ describe('argument-validation', () => {
36
41
  'savedQueryUuid',
37
42
  'schedulerUuid',
38
43
  'slug',
44
+ 'sourceChartUuidOrSlug',
45
+ 'sourceDashboardUuid',
39
46
  'spaceUuid',
40
47
  'spaceUuids',
48
+ 'targetSpaceUuid',
41
49
  'threadUuid',
50
+ 'tileUuid',
42
51
  'toolCallId',
43
52
  'userUuid',
44
53
  'versionUuid',
54
+ 'versionUuidA',
55
+ 'versionUuidB',
45
56
  ].sort(),
46
57
  );
47
58
  });
@@ -210,6 +221,26 @@ describe('argument-validation', () => {
210
221
  );
211
222
  });
212
223
 
224
+ it('validates chartUuidOrSlug/dashboardUuidOrSlug and itemUuids/targetSpaceUuid', () => {
225
+ expect(() =>
226
+ validateResourceIdsInObject({
227
+ chartUuidOrSlug: 'my-chart',
228
+ dashboardUuidOrSlug: VALID_UUID,
229
+ itemUuids: [VALID_UUID],
230
+ targetSpaceUuid: VALID_UUID,
231
+ }),
232
+ ).not.toThrow();
233
+ expect(() => validateResourceIdsInObject({ itemUuids: [VALID_UUID, 'bad-uuid'] })).toThrow(
234
+ 'Invalid UUID format',
235
+ );
236
+ expect(() => validateResourceIdsInObject({ targetSpaceUuid: 'bad?' })).toThrow(
237
+ 'Invalid UUID format',
238
+ );
239
+ expect(() => validateResourceIdsInObject({ chartUuidOrSlug: 'bad?' })).toThrow(
240
+ 'Slug must contain only alphanumeric characters',
241
+ );
242
+ });
243
+
213
244
  it('validates spaceUuids and parentSpaceUuid as UUIDs', () => {
214
245
  expect(() =>
215
246
  validateResourceIdsInObject({
@@ -25,6 +25,8 @@ export const RESOURCE_ID_KEYS = new Set([
25
25
  'runUuid',
26
26
  'artifactUuid',
27
27
  'versionUuid',
28
+ 'versionUuidA',
29
+ 'versionUuidB',
28
30
  'mcpServerUuid',
29
31
  'toolCallId',
30
32
  'fingerprint',
@@ -35,15 +37,31 @@ export const RESOURCE_ID_KEYS = new Set([
35
37
  'spaceUuid',
36
38
  'spaceUuids',
37
39
  'parentSpaceUuid',
40
+ 'targetSpaceUuid',
41
+ 'itemUuids',
38
42
  'roleUuid',
39
43
  'dashboardUuid',
44
+ 'dashboardUuidOrSlug',
45
+ 'sourceDashboardUuid',
40
46
  'schedulerUuid',
41
47
  'organizationUuid',
42
48
  'chartUuid',
49
+ 'chartUuidOrSlug',
50
+ 'sourceChartUuidOrSlug',
51
+ 'contentUuidOrSlug',
52
+ 'tileUuid',
53
+ 'newSlug',
43
54
  ]);
44
55
 
45
56
  /** Keys that accept OpenAPI UuidOrSlug (UUID or slug), not UUID-only. */
46
- const UUID_OR_SLUG_KEYS = new Set(['dashboardUuid', 'chartUuid']);
57
+ const UUID_OR_SLUG_KEYS = new Set([
58
+ 'dashboardUuid',
59
+ 'dashboardUuidOrSlug',
60
+ 'chartUuid',
61
+ 'chartUuidOrSlug',
62
+ 'sourceChartUuidOrSlug',
63
+ 'contentUuidOrSlug',
64
+ ]);
47
65
 
48
66
  export type ArgumentSource = 'body' | 'option' | 'positional';
49
67
 
@@ -153,7 +171,7 @@ function validateBySemanticType(
153
171
  }
154
172
 
155
173
  function validateResourceIdValue(key: string, value: string): void {
156
- if (key === 'slug') {
174
+ if (key === 'slug' || key === 'newSlug') {
157
175
  validateSlug(value);
158
176
  return;
159
177
  }
package/src/audit.test.ts CHANGED
@@ -4,7 +4,14 @@ import { join } from 'node:path';
4
4
 
5
5
  import { afterEach, describe, expect, it, vi } from 'vitest';
6
6
 
7
- import { closeAuditLog, getSessionId, initAuditLog, logAuditEntry } from './audit';
7
+ import {
8
+ auditSeverityForStatus,
9
+ buildAuditLogEntry,
10
+ closeAuditLog,
11
+ getSessionId,
12
+ initAuditLog,
13
+ logAuditEntry,
14
+ } from './audit';
8
15
 
9
16
  describe('audit', () => {
10
17
  const stderrSpy = vi.spyOn(process.stderr, 'write').mockImplementation(() => true);
@@ -20,39 +27,70 @@ describe('audit', () => {
20
27
  expect(getSessionId()).toBe(getSessionId());
21
28
  });
22
29
 
23
- it('initAuditLog announces stderr destination when no file path is given', () => {
24
- const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
30
+ it('auditSeverityForStatus maps statuses for Cloud Logging', () => {
31
+ expect(auditSeverityForStatus('success')).toBe('INFO');
32
+ expect(auditSeverityForStatus('deletion_succeeded')).toBe('NOTICE');
33
+ expect(auditSeverityForStatus('blocked')).toBe('WARNING');
34
+ expect(auditSeverityForStatus('error')).toBe('ERROR');
35
+ });
36
+
37
+ it('buildAuditLogEntry derives channel, severity, and message', () => {
38
+ const entry = buildAuditLogEntry({
39
+ tool: 'demo_tool',
40
+ status: 'blocked',
41
+ startMs: Date.now() - 5,
42
+ projectUuids: [],
43
+ personaId: 'semantic-layer',
44
+ });
45
+ expect(entry.channel).toBe('audit');
46
+ expect(entry.severity).toBe('WARNING');
47
+ expect(entry.message).toBe('demo_tool blocked');
48
+ expect(entry.projectUuids).toBeUndefined();
49
+ expect(entry.personaId).toBe('semantic-layer');
50
+ expect(entry.sessionId).toBe(getSessionId());
51
+ });
52
+
53
+ it('initAuditLog announces stderr destination on stdout when no file path is given', () => {
54
+ const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
25
55
  try {
26
56
  initAuditLog();
27
- expect(consoleErrorSpy).toHaveBeenCalledWith(
57
+ expect(consoleLogSpy).toHaveBeenCalledWith(
28
58
  expect.stringContaining('[audit] Writing to stderr'),
29
59
  );
30
60
  } finally {
31
- consoleErrorSpy.mockRestore();
61
+ consoleLogSpy.mockRestore();
32
62
  }
33
63
  });
34
64
 
35
- it('logAuditEntry writes NDJSON to stderr by default', () => {
65
+ it('logAuditEntry writes pure JSON NDJSON to stderr (Cloud Logging–parseable)', () => {
36
66
  initAuditLog();
37
67
 
38
- logAuditEntry({
39
- timestamp: '2026-01-01T00:00:00.000Z',
40
- sessionId: getSessionId(),
41
- tool: 'test_tool',
42
- tokenHash: 'abc123',
43
- subject: 'user-uuid',
44
- status: 'success',
45
- durationMs: 12,
46
- });
68
+ logAuditEntry(
69
+ buildAuditLogEntry({
70
+ tool: 'test_tool',
71
+ status: 'success',
72
+ startMs: Date.now() - 12,
73
+ tokenHash: 'abc123',
74
+ subject: 'user-uuid',
75
+ clientSessionId: 'mcp-session-1',
76
+ personaId: 'semantic-layer',
77
+ }),
78
+ );
47
79
 
48
80
  const auditLine = stderrSpy.mock.calls
49
81
  .map(([chunk]) => String(chunk))
50
82
  .find((line) => line.includes('"tool":"test_tool"'));
51
83
  expect(auditLine).toBeDefined();
52
- expect(auditLine).toContain('[audit]');
53
- expect(auditLine).toContain('"status":"success"');
54
- expect(auditLine).toContain('"tokenHash":"abc123"');
55
- expect(auditLine).toContain('"subject":"user-uuid"');
84
+ expect(auditLine).not.toContain('[audit]');
85
+ const parsed = JSON.parse(auditLine!.trim()) as Record<string, unknown>;
86
+ expect(parsed.channel).toBe('audit');
87
+ expect(parsed.severity).toBe('INFO');
88
+ expect(parsed.message).toBe('test_tool success');
89
+ expect(parsed.status).toBe('success');
90
+ expect(parsed.tokenHash).toBe('abc123');
91
+ expect(parsed.subject).toBe('user-uuid');
92
+ expect(parsed.clientSessionId).toBe('mcp-session-1');
93
+ expect(parsed.personaId).toBe('semantic-layer');
56
94
  });
57
95
 
58
96
  it('logAuditEntry appends to a file when initAuditLog receives a path', async () => {
@@ -62,23 +100,25 @@ describe('audit', () => {
62
100
  try {
63
101
  initAuditLog(filePath);
64
102
 
65
- logAuditEntry({
66
- timestamp: '2026-01-01T00:00:00.000Z',
67
- sessionId: getSessionId(),
68
- tool: 'file_tool',
69
- projectUuids: ['uuid-a'],
70
- status: 'blocked',
71
- durationMs: 3,
72
- });
103
+ logAuditEntry(
104
+ buildAuditLogEntry({
105
+ tool: 'file_tool',
106
+ status: 'blocked',
107
+ startMs: Date.now() - 3,
108
+ projectUuids: ['uuid-a'],
109
+ }),
110
+ );
73
111
 
74
112
  await closeAuditLog();
75
113
 
76
114
  // filePath is a temp path from mkdtempSync in this test only
77
115
  // eslint-disable-next-line security/detect-non-literal-fs-filename
78
116
  const contents = readFileSync(filePath, 'utf8');
79
- expect(contents).toContain('"tool":"file_tool"');
80
- expect(contents).toContain('"projectUuids":["uuid-a"]');
81
- expect(contents).toContain('"status":"blocked"');
117
+ const parsed = JSON.parse(contents.trim()) as Record<string, unknown>;
118
+ expect(parsed.channel).toBe('audit');
119
+ expect(parsed.tool).toBe('file_tool');
120
+ expect(parsed.projectUuids).toEqual(['uuid-a']);
121
+ expect(parsed.status).toBe('blocked');
82
122
  } finally {
83
123
  await closeAuditLog();
84
124
  rmSync(dir, { recursive: true, force: true });