@lightdash-tools/common 0.11.0 → 0.13.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 (66) hide show
  1. package/dist/agent-safe.d.ts +4 -0
  2. package/dist/agent-safe.js +13 -0
  3. package/dist/audit.d.ts +1 -1
  4. package/dist/index.d.ts +2 -1
  5. package/dist/index.js +4 -2
  6. package/dist/profile-ids.d.ts +5 -0
  7. package/dist/profile-ids.js +15 -0
  8. package/package.json +1 -3
  9. package/src/agent-safe.ts +11 -0
  10. package/src/audit.ts +1 -1
  11. package/src/index.ts +5 -2
  12. package/src/profile-ids.ts +15 -0
  13. package/dist/operations/agent-safe.d.ts +0 -5
  14. package/dist/operations/agent-safe.js +0 -9
  15. package/dist/operations/ai-agents.d.ts +0 -6
  16. package/dist/operations/ai-agents.js +0 -495
  17. package/dist/operations/cli-content.d.ts +0 -5
  18. package/dist/operations/cli-content.js +0 -69
  19. package/dist/operations/client-coverage.d.ts +0 -120
  20. package/dist/operations/client-coverage.js +0 -139
  21. package/dist/operations/client-coverage.test.d.ts +0 -1
  22. package/dist/operations/client-coverage.test.js +0 -22
  23. package/dist/operations/content-developer.d.ts +0 -2
  24. package/dist/operations/content-developer.js +0 -471
  25. package/dist/operations/content-governance.d.ts +0 -7
  26. package/dist/operations/content-governance.js +0 -98
  27. package/dist/operations/content-reader.d.ts +0 -2
  28. package/dist/operations/content-reader.js +0 -198
  29. package/dist/operations/data-analyst.d.ts +0 -5
  30. package/dist/operations/data-analyst.js +0 -23
  31. package/dist/operations/index.d.ts +0 -13
  32. package/dist/operations/index.js +0 -37
  33. package/dist/operations/organization-audit.d.ts +0 -2
  34. package/dist/operations/organization-audit.js +0 -273
  35. package/dist/operations/parity.test.d.ts +0 -1
  36. package/dist/operations/parity.test.js +0 -29
  37. package/dist/operations/registry.d.ts +0 -18
  38. package/dist/operations/registry.js +0 -136
  39. package/dist/operations/registry.test.d.ts +0 -1
  40. package/dist/operations/registry.test.js +0 -201
  41. package/dist/operations/semantic-layer.d.ts +0 -6
  42. package/dist/operations/semantic-layer.js +0 -155
  43. package/dist/operations/types.d.ts +0 -90
  44. package/dist/operations/types.js +0 -113
  45. package/dist/operations/types.test.d.ts +0 -1
  46. package/dist/operations/types.test.js +0 -101
  47. package/dist/operations/users.d.ts +0 -6
  48. package/dist/operations/users.js +0 -56
  49. package/src/operations/agent-safe.ts +0 -8
  50. package/src/operations/ai-agents.ts +0 -539
  51. package/src/operations/cli-content.ts +0 -76
  52. package/src/operations/client-coverage.test.ts +0 -23
  53. package/src/operations/client-coverage.ts +0 -156
  54. package/src/operations/content-developer.ts +0 -501
  55. package/src/operations/content-governance.ts +0 -110
  56. package/src/operations/content-reader.ts +0 -213
  57. package/src/operations/data-analyst.ts +0 -27
  58. package/src/operations/index.ts +0 -44
  59. package/src/operations/organization-audit.ts +0 -293
  60. package/src/operations/parity.test.ts +0 -33
  61. package/src/operations/registry.test.ts +0 -229
  62. package/src/operations/registry.ts +0 -158
  63. package/src/operations/semantic-layer.ts +0 -167
  64. package/src/operations/types.test.ts +0 -138
  65. package/src/operations/types.ts +0 -241
  66. package/src/operations/users.ts +0 -62
@@ -1,113 +0,0 @@
1
- "use strict";
2
- /**
3
- * Shared typed operation catalog (ADR-0013 / ADR-0006).
4
- * Single source of truth for HTTP, CLI, and MCP exposure of Lightdash API operations.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.PROFILE_IDS = void 0;
8
- exports.defineOperation = defineOperation;
9
- /** Runtime list of every MCP serving profile id (ADR-0006; fixed mounts / stdio). */
10
- exports.PROFILE_IDS = [
11
- 'ai-agent-ops',
12
- 'content-developer',
13
- 'content-governance',
14
- 'content-reader',
15
- 'data-analyst',
16
- 'organization-audit',
17
- 'semantic-layer',
18
- ];
19
- const VALID_PROFILES = new Set(exports.PROFILE_IDS);
20
- const VALID_SENSITIVITY = new Set([
21
- 'none',
22
- 'pii.email',
23
- 'secret.connection',
24
- 'secret.destination',
25
- ]);
26
- function assertNonEmpty(value, field) {
27
- if (value.trim().length === 0) {
28
- throw new Error(`Operation ${field} must be a non-empty string`);
29
- }
30
- }
31
- function expectedImpactFromAnnotations(annotations) {
32
- if (annotations.readOnlyHint) {
33
- return 'read';
34
- }
35
- if (annotations.destructiveHint) {
36
- return 'write-destructive';
37
- }
38
- if (annotations.openWorldHint) {
39
- return 'external-side-effect';
40
- }
41
- return 'write-nondestructive';
42
- }
43
- function validateIdempotentHint(annotations, impact, id) {
44
- if (impact === 'write-destructive' && annotations.idempotentHint === true) {
45
- throw new Error(`Operation '${id}': destructive operations must not set mcp.annotations.idempotentHint = true`);
46
- }
47
- }
48
- function validateProfiles(input) {
49
- const { id, profiles, mcp } = input;
50
- const mcpExposed = (mcp === null || mcp === void 0 ? void 0 : mcp.taskSupport.exposed) === true;
51
- if (mcpExposed && profiles.length === 0) {
52
- throw new Error(`Operation '${id}' must declare at least one profile when mcp.taskSupport.exposed is true`);
53
- }
54
- if (new Set(profiles).size !== profiles.length) {
55
- throw new Error(`Operation '${id}' has duplicate profiles: ${profiles.join(', ')}`);
56
- }
57
- for (const profile of profiles) {
58
- if (!VALID_PROFILES.has(profile)) {
59
- throw new Error(`Operation '${id}' has unknown profile '${profile}'`);
60
- }
61
- }
62
- if (!mcpExposed && profiles.length > 0) {
63
- throw new Error(`Operation '${id}' must use empty profiles when not MCP-exposed (got ${profiles.join(', ')})`);
64
- }
65
- }
66
- function validateClientOnlyOperation(input) {
67
- var _a;
68
- if (input.mcp !== undefined || input.cli !== undefined) {
69
- throw new Error(`Operation '${input.id}': client-only operations must omit mcp and cli metadata`);
70
- }
71
- if (input.bannedMcpToolName !== undefined && input.bannedMcpToolName.trim().length === 0) {
72
- throw new Error(`Operation '${input.id}': bannedMcpToolName must be non-empty when set`);
73
- }
74
- return Object.assign(Object.assign({}, input), { agentExposure: 'client-only', sensitivity: (_a = input.sensitivity) !== null && _a !== void 0 ? _a : 'none' });
75
- }
76
- function validateAgentMcp(input) {
77
- if (input.mcp === undefined) {
78
- return;
79
- }
80
- assertNonEmpty(input.mcp.toolName, 'mcp.toolName');
81
- const expectedImpact = expectedImpactFromAnnotations(input.mcp.annotations);
82
- if (input.authorization.safetyImpact !== expectedImpact) {
83
- throw new Error(`Operation '${input.id}': authorization.safetyImpact is '${input.authorization.safetyImpact}' but MCP annotations imply '${expectedImpact}'`);
84
- }
85
- validateIdempotentHint(input.mcp.annotations, input.authorization.safetyImpact, input.id);
86
- }
87
- /**
88
- * Defines a typed operation descriptor with catalog consistency checks (ADR-0013).
89
- * Agent ops require at least one of `mcp` or `cli`. Client-only ops omit both.
90
- */
91
- function defineOperation(input) {
92
- var _a, _b;
93
- assertNonEmpty(input.id, 'id');
94
- assertNonEmpty(input.summary, 'summary');
95
- assertNonEmpty(input.http.path, 'http.path');
96
- const sensitivity = (_a = input.sensitivity) !== null && _a !== void 0 ? _a : 'none';
97
- if (!VALID_SENSITIVITY.has(sensitivity)) {
98
- throw new Error(`Operation '${input.id}' has unknown sensitivity '${String(sensitivity)}'`);
99
- }
100
- validateProfiles(input);
101
- const agentExposure = (_b = input.agentExposure) !== null && _b !== void 0 ? _b : 'agent';
102
- if (agentExposure === 'client-only') {
103
- return validateClientOnlyOperation(Object.assign(Object.assign({}, input), { sensitivity }));
104
- }
105
- if (input.mcp === undefined && input.cli === undefined) {
106
- throw new Error(`Operation '${input.id}': agent operations require mcp and/or cli metadata`);
107
- }
108
- validateAgentMcp(input);
109
- if (input.cli !== undefined) {
110
- assertNonEmpty(input.cli.commandPath, 'cli.commandPath');
111
- }
112
- return Object.assign(Object.assign({}, input), { agentExposure: 'agent', sensitivity });
113
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,101 +0,0 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- const vitest_1 = require("vitest");
15
- const types_1 = require("./types");
16
- const baseDescriptor = {
17
- id: 'test.operation',
18
- summary: 'Test operation',
19
- http: { method: 'GET', path: '/api/v1/test' },
20
- authorization: { safetyImpact: 'read' },
21
- sensitivity: 'none',
22
- mcp: {
23
- toolName: 'test_op',
24
- annotations: {
25
- readOnlyHint: true,
26
- destructiveHint: false,
27
- idempotentHint: true,
28
- openWorldHint: false,
29
- },
30
- taskSupport: { exposed: true, taskEligible: false },
31
- },
32
- cli: { commandPath: 'test op' },
33
- agentExposure: 'agent',
34
- profiles: ['semantic-layer'],
35
- };
36
- (0, vitest_1.describe)('defineOperation', () => {
37
- (0, vitest_1.it)('accepts a valid read descriptor', () => {
38
- (0, vitest_1.expect)((0, types_1.defineOperation)(baseDescriptor)).toEqual(Object.assign(Object.assign({}, baseDescriptor), { agentExposure: 'agent', sensitivity: 'none' }));
39
- });
40
- (0, vitest_1.it)('defaults agentExposure to agent and sensitivity to none', () => {
41
- const { agentExposure, sensitivity } = baseDescriptor, withoutDefaults = __rest(baseDescriptor, ["agentExposure", "sensitivity"]);
42
- void agentExposure;
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');
47
- });
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();
52
- });
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)(Object.assign(Object.assign({}, rest), { profiles: [] })).mcp).toBeUndefined();
57
- });
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)(Object.assign(Object.assign({}, rest), { profiles: [] }))).toThrow(/require mcp and\/or cli/);
63
- });
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/);
66
- });
67
- (0, vitest_1.it)('rejects unknown profile', () => {
68
- (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { profiles: ['unknown-profile'] }))).toThrow(/unknown profile/);
69
- });
70
- (0, vitest_1.it)('rejects empty profiles when MCP-exposed', () => {
71
- (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { profiles: [] }))).toThrow(/at least one profile/);
72
- });
73
- (0, vitest_1.it)('rejects duplicate profiles', () => {
74
- (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { profiles: ['semantic-layer', 'semantic-layer'] }))).toThrow(/duplicate profiles/);
75
- });
76
- (0, vitest_1.it)('rejects non-empty profiles when not MCP-exposed', () => {
77
- (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { mcp: Object.assign(Object.assign({}, baseDescriptor.mcp), { taskSupport: { exposed: false, taskEligible: false } }), profiles: ['semantic-layer'] }))).toThrow(/empty profiles/);
78
- });
79
- (0, vitest_1.it)('allows read operation with idempotentHint false (transient execution)', () => {
80
- var _a;
81
- 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 }) }) }));
82
- (0, vitest_1.expect)((_a = op.mcp) === null || _a === void 0 ? void 0 : _a.annotations.idempotentHint).toBe(false);
83
- });
84
- (0, vitest_1.it)('rejects client-only operation that still has mcp', () => {
85
- (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { agentExposure: 'client-only' }))).toThrow(/must omit mcp and cli/);
86
- });
87
- (0, vitest_1.it)('allows client-only operation with bannedMcpToolName and no mcp/cli', () => {
88
- const op = (0, types_1.defineOperation)({
89
- id: 'test.client-only',
90
- summary: 'Client only delete',
91
- http: { method: 'DELETE', path: '/api/v1/test/{id}' },
92
- authorization: { safetyImpact: 'write-destructive' },
93
- agentExposure: 'client-only',
94
- bannedMcpToolName: 'delete_test',
95
- profiles: [],
96
- });
97
- (0, vitest_1.expect)(op.agentExposure).toBe('client-only');
98
- (0, vitest_1.expect)(op.bannedMcpToolName).toBe('delete_test');
99
- (0, vitest_1.expect)(op.sensitivity).toBe('none');
100
- });
101
- });
@@ -1,6 +0,0 @@
1
- /**
2
- * Organization member operations in the shared operation catalog.
3
- */
4
- import type { OperationDescriptor } from './types';
5
- /** Organization member operations registered in the shared operation catalog. */
6
- export declare const USER_OPERATIONS: readonly OperationDescriptor[];
@@ -1,56 +0,0 @@
1
- "use strict";
2
- /**
3
- * Organization member operations in the shared operation catalog.
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.USER_OPERATIONS = void 0;
7
- const safety_1 = require("../safety");
8
- const types_1 = require("./types");
9
- const API_V1 = '/api/v1';
10
- const MEMBERS_PATH = `${API_V1}/org/users`;
11
- const MEMBER_PATH = `${MEMBERS_PATH}/{userUuid}`;
12
- const DELETE_MEMBER_PATH = `${API_V1}/org/user/{userUuid}`;
13
- const membersList = (0, types_1.defineOperation)({
14
- id: 'users.members.list',
15
- summary: 'List organization members (one page)',
16
- http: { method: 'GET', path: MEMBERS_PATH },
17
- authorization: { safetyImpact: 'read' },
18
- sensitivity: 'pii.email',
19
- mcp: {
20
- toolName: 'list_organization_members',
21
- annotations: safety_1.READ_ONLY_DEFAULT,
22
- taskSupport: { exposed: false, taskEligible: false },
23
- },
24
- cli: { commandPath: 'users list' },
25
- profiles: [],
26
- });
27
- const membersGet = (0, types_1.defineOperation)({
28
- id: 'users.members.get',
29
- summary: 'Get an organization member by UUID',
30
- http: { method: 'GET', path: MEMBER_PATH },
31
- authorization: { safetyImpact: 'read' },
32
- sensitivity: 'pii.email',
33
- mcp: {
34
- toolName: 'get_member',
35
- annotations: safety_1.READ_ONLY_DEFAULT,
36
- taskSupport: { exposed: false, taskEligible: false },
37
- },
38
- cli: { commandPath: 'users get' },
39
- profiles: [],
40
- });
41
- const membersDelete = (0, types_1.defineOperation)({
42
- id: 'users.members.delete',
43
- summary: 'Permanently remove a user from the organization (irrecoverable; client-only)',
44
- http: { method: 'DELETE', path: DELETE_MEMBER_PATH },
45
- authorization: { safetyImpact: 'write-destructive' },
46
- sensitivity: 'none',
47
- agentExposure: 'client-only',
48
- bannedMcpToolName: 'delete_member',
49
- profiles: [],
50
- });
51
- /** Organization member operations registered in the shared operation catalog. */
52
- exports.USER_OPERATIONS = [
53
- membersList,
54
- membersGet,
55
- membersDelete,
56
- ];
@@ -1,8 +0,0 @@
1
- /**
2
- * Agent-safe surface policy helpers (ADR-0004 / ADR-0013).
3
- */
4
-
5
- import { listBannedMcpToolNames } from './registry';
6
-
7
- /** Banned MCP tool names (without `lightdash_` prefix) for regression tests. */
8
- export const IRRECOVERABLE_TOOL_DENYLIST = listBannedMcpToolNames();