@lightdash-tools/common 0.6.0 → 0.8.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 (120) hide show
  1. package/dist/agentops/extract-yaml-project.d.ts +7 -0
  2. package/dist/agentops/extract-yaml-project.js +42 -0
  3. package/dist/agentops/formatters.d.ts +5 -0
  4. package/dist/agentops/formatters.js +47 -0
  5. package/dist/agentops/snapshots.d.ts +32 -0
  6. package/dist/agentops/snapshots.js +34 -0
  7. package/dist/agentops/types.d.ts +224 -0
  8. package/dist/agentops/types.js +430 -0
  9. package/dist/argument-validation.d.ts +25 -0
  10. package/dist/argument-validation.js +217 -0
  11. package/dist/argument-validation.test.d.ts +1 -0
  12. package/dist/argument-validation.test.js +205 -0
  13. package/dist/audit.d.ts +9 -2
  14. package/dist/audit.js +17 -2
  15. package/dist/audit.test.d.ts +1 -0
  16. package/dist/audit.test.js +73 -0
  17. package/dist/env.d.ts +8 -0
  18. package/dist/env.js +9 -1
  19. package/dist/index.d.ts +7 -3
  20. package/dist/index.js +14 -2
  21. package/dist/input-validation.d.ts +35 -0
  22. package/dist/input-validation.js +87 -0
  23. package/dist/input-validation.test.js +93 -0
  24. package/dist/operations/agent-safe.d.ts +5 -0
  25. package/dist/operations/agent-safe.js +9 -0
  26. package/dist/operations/ai-agents.d.ts +6 -0
  27. package/dist/operations/ai-agents.js +427 -0
  28. package/dist/operations/cli-content.d.ts +5 -0
  29. package/dist/operations/cli-content.js +71 -0
  30. package/dist/operations/client-coverage.d.ts +113 -0
  31. package/dist/operations/client-coverage.js +130 -0
  32. package/dist/operations/client-coverage.test.d.ts +1 -0
  33. package/dist/operations/client-coverage.test.js +22 -0
  34. package/dist/operations/content-developer.d.ts +2 -0
  35. package/dist/operations/content-developer.js +457 -0
  36. package/dist/operations/content-governance.d.ts +7 -0
  37. package/dist/operations/content-governance.js +98 -0
  38. package/dist/operations/content-reader.d.ts +2 -0
  39. package/dist/operations/content-reader.js +183 -0
  40. package/dist/operations/index.d.ts +12 -0
  41. package/dist/operations/index.js +34 -0
  42. package/dist/operations/organization-audit.d.ts +2 -0
  43. package/dist/operations/organization-audit.js +273 -0
  44. package/dist/operations/parity.test.d.ts +1 -0
  45. package/dist/operations/parity.test.js +29 -0
  46. package/dist/operations/registry.d.ts +18 -0
  47. package/dist/operations/registry.js +110 -0
  48. package/dist/operations/registry.test.d.ts +1 -0
  49. package/dist/operations/registry.test.js +223 -0
  50. package/dist/operations/semantic-layer.d.ts +6 -0
  51. package/dist/operations/semantic-layer.js +154 -0
  52. package/dist/operations/types.d.ts +86 -0
  53. package/dist/operations/types.js +104 -0
  54. package/dist/operations/types.test.d.ts +1 -0
  55. package/dist/operations/types.test.js +92 -0
  56. package/dist/operations/users.d.ts +6 -0
  57. package/dist/operations/users.js +58 -0
  58. package/dist/safety.d.ts +32 -2
  59. package/dist/safety.js +62 -5
  60. package/dist/safety.test.js +217 -4
  61. package/dist/types/generated/openapi-types.d.ts +32623 -11194
  62. package/dist/types/index.d.ts +12 -0
  63. package/dist/types/index.js +29 -0
  64. package/dist/types/lightdash-api.d.ts +1 -1
  65. package/dist/types/v1/ai-agents.d.ts +112 -3
  66. package/dist/types/v1/charts.d.ts +5 -3
  67. package/dist/types/v1/dashboards.d.ts +13 -0
  68. package/dist/types/v1/index.d.ts +45 -8
  69. package/dist/types/v1/index.js +1 -1
  70. package/dist/types/v1/lightdash-api.d.ts +107 -16
  71. package/dist/types/v1/users.d.ts +4 -0
  72. package/dist/types/v2/content.d.ts +2 -0
  73. package/dist/types/v2/content.js +8 -0
  74. package/dist/types/v2/index.d.ts +11 -9
  75. package/dist/types/v2/index.js +1 -1
  76. package/package.json +17 -3
  77. package/src/agentops/extract-yaml-project.ts +42 -0
  78. package/src/agentops/formatters.ts +52 -0
  79. package/src/agentops/snapshots.ts +56 -0
  80. package/src/agentops/types.ts +599 -0
  81. package/src/argument-validation.test.ts +301 -0
  82. package/src/argument-validation.ts +258 -0
  83. package/src/audit.test.ts +87 -0
  84. package/src/audit.ts +32 -3
  85. package/src/env.ts +9 -0
  86. package/src/index.test.ts +1 -0
  87. package/src/index.ts +17 -6
  88. package/src/input-validation.test.ts +157 -1
  89. package/src/input-validation.ts +95 -0
  90. package/src/operations/agent-safe.ts +8 -0
  91. package/src/operations/ai-agents.ts +467 -0
  92. package/src/operations/cli-content.ts +79 -0
  93. package/src/operations/client-coverage.test.ts +23 -0
  94. package/src/operations/client-coverage.ts +147 -0
  95. package/src/operations/content-developer.ts +485 -0
  96. package/src/operations/content-governance.ts +110 -0
  97. package/src/operations/content-reader.ts +197 -0
  98. package/src/operations/index.ts +42 -0
  99. package/src/operations/organization-audit.ts +293 -0
  100. package/src/operations/parity.test.ts +33 -0
  101. package/src/operations/registry.test.ts +250 -0
  102. package/src/operations/registry.ts +128 -0
  103. package/src/operations/semantic-layer.ts +166 -0
  104. package/src/operations/types.test.ts +110 -0
  105. package/src/operations/types.ts +231 -0
  106. package/src/operations/users.ts +65 -0
  107. package/src/safety.test.ts +276 -4
  108. package/src/safety.ts +83 -4
  109. package/src/types/generated/openapi-types.ts +33701 -11813
  110. package/src/types/index.ts +13 -0
  111. package/src/types/lightdash-api.ts +39 -0
  112. package/src/types/v1/ai-agents.ts +133 -3
  113. package/src/types/v1/charts.ts +5 -3
  114. package/src/types/v1/dashboards.ts +19 -0
  115. package/src/types/v1/index.ts +51 -8
  116. package/src/types/v1/lightdash-api.ts +129 -20
  117. package/src/types/v1/users.ts +4 -0
  118. package/src/types/v2/content.ts +8 -0
  119. package/src/types/v2/index.ts +11 -9
  120. package/tsconfig.json +1 -0
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const argument_validation_1 = require("./argument-validation");
5
+ const VALID_UUID = '550e8400-e29b-41d4-a716-446655440000';
6
+ (0, vitest_1.describe)('argument-validation', () => {
7
+ (0, vitest_1.describe)('RESOURCE_ID_KEYS', () => {
8
+ (0, vitest_1.it)('contains all RFC Phase 0 identifier keys', () => {
9
+ (0, vitest_1.expect)([...argument_validation_1.RESOURCE_ID_KEYS].sort()).toEqual([
10
+ 'agentUuid',
11
+ 'artifactUuid',
12
+ 'chartUuid',
13
+ 'chartUuidOrSlug',
14
+ 'contentUuidOrSlug',
15
+ 'dashboardUuid',
16
+ 'dashboardUuidOrSlug',
17
+ 'evalUuid',
18
+ 'fingerprint',
19
+ 'groupUuid',
20
+ 'itemUuids',
21
+ 'mcpServerUuid',
22
+ 'messageUuid',
23
+ 'newSlug',
24
+ 'organizationUuid',
25
+ 'parentSpaceUuid',
26
+ 'project',
27
+ 'projectUuid',
28
+ 'projectUuids',
29
+ 'projects',
30
+ 'promptUuid',
31
+ 'roleUuid',
32
+ 'runUuid',
33
+ 'savedQueryUuid',
34
+ 'schedulerUuid',
35
+ 'slug',
36
+ 'sourceChartUuidOrSlug',
37
+ 'sourceDashboardUuid',
38
+ 'spaceUuid',
39
+ 'spaceUuids',
40
+ 'targetSpaceUuid',
41
+ 'threadUuid',
42
+ 'tileUuid',
43
+ 'toolCallId',
44
+ 'userUuid',
45
+ 'versionUuid',
46
+ 'versionUuidA',
47
+ 'versionUuidB',
48
+ ].sort());
49
+ });
50
+ });
51
+ (0, vitest_1.describe)('validateArguments', () => {
52
+ (0, vitest_1.it)('validates uuid arguments', () => {
53
+ const descriptors = [
54
+ { name: 'projectUuid', source: 'option', semanticType: 'uuid', required: true },
55
+ ];
56
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ projectUuid: VALID_UUID }, descriptors)).not.toThrow();
57
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ projectUuid: 'bad-uuid' }, descriptors)).toThrow('Invalid UUID format');
58
+ });
59
+ (0, vitest_1.it)('validates slug arguments', () => {
60
+ const descriptors = [
61
+ { name: 'slug', source: 'option', semanticType: 'slug' },
62
+ ];
63
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ slug: 'my-chart' }, descriptors)).not.toThrow();
64
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ slug: 'bad slug' }, descriptors)).toThrow('Slug must contain only alphanumeric characters');
65
+ });
66
+ (0, vitest_1.it)('validates fingerprint arguments', () => {
67
+ const descriptors = [
68
+ { name: 'fingerprint', source: 'body', semanticType: 'fingerprint' },
69
+ ];
70
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ fingerprint: 'abc123' }, descriptors)).not.toThrow();
71
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ fingerprint: '' }, descriptors)).toThrow('Fingerprint must be between 1 and 512 characters');
72
+ });
73
+ (0, vitest_1.it)('throws when required argument is missing', () => {
74
+ const descriptors = [
75
+ { name: 'projectUuid', source: 'option', semanticType: 'uuid', required: true },
76
+ ];
77
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({}, descriptors)).toThrow("Required argument 'projectUuid' is missing");
78
+ });
79
+ (0, vitest_1.it)('skips optional missing arguments', () => {
80
+ const descriptors = [
81
+ { name: 'slug', source: 'option', semanticType: 'slug' },
82
+ ];
83
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({}, descriptors)).not.toThrow();
84
+ });
85
+ (0, vitest_1.it)('validates uuid arrays', () => {
86
+ const descriptors = [
87
+ { name: 'projectUuid', source: 'body', semanticType: 'uuid' },
88
+ ];
89
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ projectUuid: [VALID_UUID, VALID_UUID] }, descriptors)).not.toThrow();
90
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ projectUuid: [VALID_UUID, 'not-uuid'] }, descriptors)).toThrow('Invalid UUID format');
91
+ });
92
+ (0, vitest_1.it)('validates free-text with control char rejection only', () => {
93
+ const descriptors = [
94
+ { name: 'query', source: 'positional', semanticType: 'free-text' },
95
+ ];
96
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ query: 'what? growth%' }, descriptors)).not.toThrow();
97
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ query: 'bad\u0000' }, descriptors)).toThrow('Input contains invalid control characters');
98
+ });
99
+ (0, vitest_1.it)('validates json string arguments', () => {
100
+ const descriptors = [
101
+ { name: 'payload', source: 'body', semanticType: 'json' },
102
+ ];
103
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ payload: '{"a":1}' }, descriptors)).not.toThrow();
104
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ payload: 'not-json' }, descriptors)).toThrow("Argument 'payload' must be valid JSON");
105
+ });
106
+ (0, vitest_1.it)('validates boolean arguments', () => {
107
+ const descriptors = [
108
+ { name: 'enabled', source: 'option', semanticType: 'boolean' },
109
+ ];
110
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ enabled: true }, descriptors)).not.toThrow();
111
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ enabled: 'true' }, descriptors)).toThrow("Argument 'enabled' must be a boolean");
112
+ });
113
+ (0, vitest_1.it)('validates number arguments', () => {
114
+ const descriptors = [
115
+ { name: 'limit', source: 'option', semanticType: 'number' },
116
+ ];
117
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ limit: 10 }, descriptors)).not.toThrow();
118
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ limit: Number.NaN }, descriptors)).toThrow("Argument 'limit' must be a number");
119
+ });
120
+ });
121
+ (0, vitest_1.describe)('validateResourceIdsInObject', () => {
122
+ (0, vitest_1.it)('validates top-level resource id keys', () => {
123
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
124
+ projectUuid: VALID_UUID,
125
+ slug: 'my-chart',
126
+ })).not.toThrow();
127
+ });
128
+ (0, vitest_1.it)('validates projectUuids / projects array entries as UUIDs', () => {
129
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ projectUuids: [VALID_UUID] })).not.toThrow();
130
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ projectUuids: [VALID_UUID, 'bad-uuid'] })).toThrow('Invalid UUID format');
131
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ projects: ['bad-uuid'] })).toThrow('Invalid UUID format');
132
+ });
133
+ (0, vitest_1.it)('validates nested resource id keys', () => {
134
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
135
+ filter: {
136
+ agentUuid: VALID_UUID,
137
+ nested: {
138
+ threadUuid: VALID_UUID,
139
+ },
140
+ },
141
+ })).not.toThrow();
142
+ });
143
+ (0, vitest_1.it)('validates resource id keys inside arrays', () => {
144
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)([{ projectUuid: VALID_UUID }, { projectUuid: 'bad-uuid' }])).toThrow('Invalid UUID format');
145
+ });
146
+ (0, vitest_1.it)('validates uuid keys with uuid rules', () => {
147
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ runUuid: 'not-a-uuid' })).toThrow('Invalid UUID format');
148
+ });
149
+ (0, vitest_1.it)('validates slug key with slug rules', () => {
150
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ slug: 'bad slug' })).toThrow('Slug must contain only alphanumeric characters');
151
+ });
152
+ (0, vitest_1.it)('accepts UUID or slug for dashboardUuid and chartUuid', () => {
153
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ dashboardUuid: 'sales-overview' })).not.toThrow();
154
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ dashboardUuid: VALID_UUID })).not.toThrow();
155
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ chartUuid: 'my-chart' })).not.toThrow();
156
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ dashboardUuid: 'bad?' })).toThrow('Slug must contain only alphanumeric characters');
157
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ dashboardUuid: '..' })).toThrow('Slug must not contain path traversal segments');
158
+ });
159
+ (0, vitest_1.it)('validates chartUuidOrSlug/dashboardUuidOrSlug and itemUuids/targetSpaceUuid', () => {
160
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
161
+ chartUuidOrSlug: 'my-chart',
162
+ dashboardUuidOrSlug: VALID_UUID,
163
+ itemUuids: [VALID_UUID],
164
+ targetSpaceUuid: VALID_UUID,
165
+ })).not.toThrow();
166
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ itemUuids: [VALID_UUID, 'bad-uuid'] })).toThrow('Invalid UUID format');
167
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ targetSpaceUuid: 'bad?' })).toThrow('Invalid UUID format');
168
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ chartUuidOrSlug: 'bad?' })).toThrow('Slug must contain only alphanumeric characters');
169
+ });
170
+ (0, vitest_1.it)('validates spaceUuids and parentSpaceUuid as UUIDs', () => {
171
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
172
+ spaceUuids: [VALID_UUID],
173
+ parentSpaceUuid: VALID_UUID,
174
+ })).not.toThrow();
175
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ spaceUuids: ['bad?'] })).toThrow('Invalid UUID format');
176
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ parentSpaceUuid: '..' })).toThrow('Invalid UUID format');
177
+ });
178
+ (0, vitest_1.it)('validates fingerprint and toolCallId with fingerprint rules', () => {
179
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
180
+ fingerprint: 'fp-123',
181
+ toolCallId: 'call-abc',
182
+ })).not.toThrow();
183
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ fingerprint: '' })).toThrow('Fingerprint must be between 1 and 512 characters');
184
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ toolCallId: '' })).toThrow('Fingerprint must be between 1 and 512 characters');
185
+ });
186
+ (0, vitest_1.it)('validates string arrays under resource id keys', () => {
187
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
188
+ projectUuid: [VALID_UUID, VALID_UUID],
189
+ })).not.toThrow();
190
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
191
+ projectUuid: [VALID_UUID, 'invalid'],
192
+ })).toThrow('Invalid UUID format');
193
+ });
194
+ (0, vitest_1.it)('ignores non-resource keys', () => {
195
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
196
+ query: 'what? growth%',
197
+ name: '../etc/passwd',
198
+ })).not.toThrow();
199
+ });
200
+ (0, vitest_1.it)('handles null and undefined', () => {
201
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)(null)).not.toThrow();
202
+ (0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)(undefined)).not.toThrow();
203
+ });
204
+ });
205
+ });
package/dist/audit.d.ts CHANGED
@@ -2,13 +2,14 @@
2
2
  * Structured audit logger for Lightdash tool invocations (MCP and CLI).
3
3
  *
4
4
  * Each operation is recorded as a single NDJSON line containing:
5
- * timestamp, sessionId, tool/command name, projectUuids (if present), status, and durationMs.
5
+ * timestamp, sessionId, tool/command name, projectUuids (if present), status, durationMs,
6
+ * and optional OAuth attribution fields (tokenHash, subject) when available.
6
7
  *
7
8
  * Output destination:
8
9
  * - If LIGHTDASH_TOOLS_AUDIT_LOG is set to a file path, entries are appended to that file.
9
10
  * - Otherwise entries are written to stderr with an "[audit]" prefix.
10
11
  */
11
- export type AuditStatus = 'success' | 'error' | 'blocked';
12
+ export type AuditStatus = 'blocked' | 'confirmation_cancelled' | 'confirmation_declined' | 'confirmation_requested' | 'deletion_failed' | 'deletion_succeeded' | 'error' | 'promotion_failed' | 'promotion_succeeded' | 'resource_changed' | 'success';
12
13
  export type AuditLogEntry = {
13
14
  timestamp: string;
14
15
  sessionId: string;
@@ -16,6 +17,10 @@ export type AuditLogEntry = {
16
17
  tool: string;
17
18
  /** Project UUIDs involved in the call, if any (covers both projectUuid and projectUuids[]). */
18
19
  projectUuids?: string[];
20
+ /** SHA-256 hash of the OAuth bearer token (never the raw token). */
21
+ tokenHash?: string;
22
+ /** Lightdash user UUID when the call runs under OAuth bearer auth. */
23
+ subject?: string;
19
24
  status: AuditStatus;
20
25
  durationMs: number;
21
26
  };
@@ -27,3 +32,5 @@ export declare function getSessionId(): string;
27
32
  export declare function initAuditLog(filePath?: string): void;
28
33
  /** Append one NDJSON entry to the configured output. */
29
34
  export declare function logAuditEntry(entry: AuditLogEntry): void;
35
+ /** Closes the file stream, if any. Awaits pending writes before resolving. */
36
+ export declare function closeAuditLog(): Promise<void>;
package/dist/audit.js CHANGED
@@ -3,7 +3,8 @@
3
3
  * Structured audit logger for Lightdash tool invocations (MCP and CLI).
4
4
  *
5
5
  * Each operation is recorded as a single NDJSON line containing:
6
- * timestamp, sessionId, tool/command name, projectUuids (if present), status, and durationMs.
6
+ * timestamp, sessionId, tool/command name, projectUuids (if present), status, durationMs,
7
+ * and optional OAuth attribution fields (tokenHash, subject) when available.
7
8
  *
8
9
  * Output destination:
9
10
  * - If LIGHTDASH_TOOLS_AUDIT_LOG is set to a file path, entries are appended to that file.
@@ -13,8 +14,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
14
  exports.getSessionId = getSessionId;
14
15
  exports.initAuditLog = initAuditLog;
15
16
  exports.logAuditEntry = logAuditEntry;
16
- const node_fs_1 = require("node:fs");
17
+ exports.closeAuditLog = closeAuditLog;
17
18
  const node_crypto_1 = require("node:crypto");
19
+ const node_fs_1 = require("node:fs");
18
20
  /** Unique ID for the current process lifetime. Generated once at module load. */
19
21
  const SESSION_ID = (0, node_crypto_1.randomUUID)();
20
22
  let _writeStream;
@@ -47,3 +49,16 @@ function logAuditEntry(entry) {
47
49
  process.stderr.write(`[audit] ${line}`);
48
50
  }
49
51
  }
52
+ /** Closes the file stream, if any. Awaits pending writes before resolving. */
53
+ function closeAuditLog() {
54
+ const stream = _writeStream;
55
+ if (!stream)
56
+ return Promise.resolve();
57
+ return new Promise((resolve, reject) => {
58
+ stream.end(() => {
59
+ _writeStream = undefined;
60
+ resolve();
61
+ });
62
+ stream.on('error', reject);
63
+ });
64
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_fs_1 = require("node:fs");
4
+ const node_os_1 = require("node:os");
5
+ const node_path_1 = require("node:path");
6
+ const vitest_1 = require("vitest");
7
+ const audit_1 = require("./audit");
8
+ (0, vitest_1.describe)('audit', () => {
9
+ const stderrSpy = vitest_1.vi.spyOn(process.stderr, 'write').mockImplementation(() => true);
10
+ (0, vitest_1.afterEach)(() => {
11
+ stderrSpy.mockClear();
12
+ });
13
+ (0, vitest_1.it)('getSessionId returns a stable UUID for the process', () => {
14
+ (0, vitest_1.expect)((0, audit_1.getSessionId)()).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
15
+ (0, vitest_1.expect)((0, audit_1.getSessionId)()).toBe((0, audit_1.getSessionId)());
16
+ });
17
+ (0, vitest_1.it)('initAuditLog announces stderr destination when no file path is given', () => {
18
+ const consoleErrorSpy = vitest_1.vi.spyOn(console, 'error').mockImplementation(() => { });
19
+ try {
20
+ (0, audit_1.initAuditLog)();
21
+ (0, vitest_1.expect)(consoleErrorSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining('[audit] Writing to stderr'));
22
+ }
23
+ finally {
24
+ consoleErrorSpy.mockRestore();
25
+ }
26
+ });
27
+ (0, vitest_1.it)('logAuditEntry writes NDJSON to stderr by default', () => {
28
+ (0, audit_1.initAuditLog)();
29
+ (0, audit_1.logAuditEntry)({
30
+ timestamp: '2026-01-01T00:00:00.000Z',
31
+ sessionId: (0, audit_1.getSessionId)(),
32
+ tool: 'test_tool',
33
+ tokenHash: 'abc123',
34
+ subject: 'user-uuid',
35
+ status: 'success',
36
+ durationMs: 12,
37
+ });
38
+ const auditLine = stderrSpy.mock.calls
39
+ .map(([chunk]) => String(chunk))
40
+ .find((line) => line.includes('"tool":"test_tool"'));
41
+ (0, vitest_1.expect)(auditLine).toBeDefined();
42
+ (0, vitest_1.expect)(auditLine).toContain('[audit]');
43
+ (0, vitest_1.expect)(auditLine).toContain('"status":"success"');
44
+ (0, vitest_1.expect)(auditLine).toContain('"tokenHash":"abc123"');
45
+ (0, vitest_1.expect)(auditLine).toContain('"subject":"user-uuid"');
46
+ });
47
+ (0, vitest_1.it)('logAuditEntry appends to a file when initAuditLog receives a path', async () => {
48
+ const dir = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'audit-test-'));
49
+ const filePath = (0, node_path_1.join)(dir, 'audit.ndjson');
50
+ try {
51
+ (0, audit_1.initAuditLog)(filePath);
52
+ (0, audit_1.logAuditEntry)({
53
+ timestamp: '2026-01-01T00:00:00.000Z',
54
+ sessionId: (0, audit_1.getSessionId)(),
55
+ tool: 'file_tool',
56
+ projectUuids: ['uuid-a'],
57
+ status: 'blocked',
58
+ durationMs: 3,
59
+ });
60
+ await (0, audit_1.closeAuditLog)();
61
+ // filePath is a temp path from mkdtempSync in this test only
62
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
63
+ const contents = (0, node_fs_1.readFileSync)(filePath, 'utf8');
64
+ (0, vitest_1.expect)(contents).toContain('"tool":"file_tool"');
65
+ (0, vitest_1.expect)(contents).toContain('"projectUuids":["uuid-a"]');
66
+ (0, vitest_1.expect)(contents).toContain('"status":"blocked"');
67
+ }
68
+ finally {
69
+ await (0, audit_1.closeAuditLog)();
70
+ (0, node_fs_1.rmSync)(dir, { recursive: true, force: true });
71
+ }
72
+ });
73
+ });
package/dist/env.d.ts CHANGED
@@ -7,3 +7,11 @@ export declare const ENV_LIGHTDASH_TOOLS_DRY_RUN = "LIGHTDASH_TOOLS_DRY_RUN";
7
7
  export declare const ENV_LIGHTDASH_TOOLS_AUDIT_LOG = "LIGHTDASH_TOOLS_AUDIT_LOG";
8
8
  export declare const ENV_LIGHTDASH_TOOLS_SAFETY_MODE = "LIGHTDASH_TOOLS_SAFETY_MODE";
9
9
  export declare const ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECTS = "LIGHTDASH_TOOLS_ALLOWED_PROJECTS";
10
+ /** MCP HTTP server env vars (`LIGHTDASH_TOOLS_MCP_*` / `LIGHTDASH_TOOLS_OAUTH_*` per ADR-0009). */
11
+ /** @deprecated Removed — auth is credential-inferred (ADR-0007). Kept for migration error messages. */
12
+ export declare const ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = "LIGHTDASH_TOOLS_MCP_AUTH_MODE";
13
+ export declare const ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT = "LIGHTDASH_TOOLS_MCP_HTTP_PORT";
14
+ export declare const ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = "LIGHTDASH_TOOLS_MCP_PUBLIC_URL";
15
+ export declare const ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY = "LIGHTDASH_TOOLS_MCP_SHARED_KEY";
16
+ export declare const ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID = "LIGHTDASH_TOOLS_OAUTH_CLIENT_ID";
17
+ export declare const ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET = "LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET";
package/dist/env.js CHANGED
@@ -5,8 +5,16 @@
5
5
  * from official Lightdash vars (LIGHTDASH_URL, LIGHTDASH_API_KEY).
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECTS = exports.ENV_LIGHTDASH_TOOLS_SAFETY_MODE = exports.ENV_LIGHTDASH_TOOLS_AUDIT_LOG = exports.ENV_LIGHTDASH_TOOLS_DRY_RUN = void 0;
8
+ exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET = exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID = exports.ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY = exports.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = exports.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECTS = exports.ENV_LIGHTDASH_TOOLS_SAFETY_MODE = exports.ENV_LIGHTDASH_TOOLS_AUDIT_LOG = exports.ENV_LIGHTDASH_TOOLS_DRY_RUN = void 0;
9
9
  exports.ENV_LIGHTDASH_TOOLS_DRY_RUN = 'LIGHTDASH_TOOLS_DRY_RUN';
10
10
  exports.ENV_LIGHTDASH_TOOLS_AUDIT_LOG = 'LIGHTDASH_TOOLS_AUDIT_LOG';
11
11
  exports.ENV_LIGHTDASH_TOOLS_SAFETY_MODE = 'LIGHTDASH_TOOLS_SAFETY_MODE';
12
12
  exports.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECTS = 'LIGHTDASH_TOOLS_ALLOWED_PROJECTS';
13
+ /** MCP HTTP server env vars (`LIGHTDASH_TOOLS_MCP_*` / `LIGHTDASH_TOOLS_OAUTH_*` per ADR-0009). */
14
+ /** @deprecated Removed — auth is credential-inferred (ADR-0007). Kept for migration error messages. */
15
+ exports.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = 'LIGHTDASH_TOOLS_MCP_AUTH_MODE';
16
+ exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT = 'LIGHTDASH_TOOLS_MCP_HTTP_PORT';
17
+ exports.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = 'LIGHTDASH_TOOLS_MCP_PUBLIC_URL';
18
+ exports.ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY = 'LIGHTDASH_TOOLS_MCP_SHARED_KEY';
19
+ exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID = 'LIGHTDASH_TOOLS_OAUTH_CLIENT_ID';
20
+ exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET = 'LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET';
package/dist/index.d.ts CHANGED
@@ -2,7 +2,11 @@ export declare function greet(name: string): string;
2
2
  export * from './env';
3
3
  export * from './safety';
4
4
  export * from './input-validation';
5
+ export * from './argument-validation';
6
+ export * from './operations';
7
+ export * from './agentops/types';
8
+ export * from './agentops/snapshots';
9
+ export * from './agentops/formatters';
10
+ export { extractProjectUuidsFromToolArgs, hasYamlProjectDocumentArgs, } from './agentops/extract-yaml-project';
5
11
  export * from './audit';
6
- export * from './types/lightdash-api';
7
- export type { LightdashApi } from './types/lightdash-api';
8
- export type { paths, components, operations } from './types/generated/openapi-types';
12
+ export * from './types';
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.hasYamlProjectDocumentArgs = exports.extractProjectUuidsFromToolArgs = void 0;
17
18
  exports.greet = greet;
18
19
  function greet(name) {
19
20
  return `Hello, ${name}!`;
@@ -24,7 +25,18 @@ __exportStar(require("./env"), exports);
24
25
  __exportStar(require("./safety"), exports);
25
26
  // Export input validation
26
27
  __exportStar(require("./input-validation"), exports);
28
+ // Export argument / descriptor validation
29
+ __exportStar(require("./argument-validation"), exports);
30
+ // Export shared typed operation catalog (ADR-0013)
31
+ __exportStar(require("./operations"), exports);
32
+ // Export AgentOps bundle and gate types
33
+ __exportStar(require("./agentops/types"), exports);
34
+ __exportStar(require("./agentops/snapshots"), exports);
35
+ __exportStar(require("./agentops/formatters"), exports);
36
+ var extract_yaml_project_1 = require("./agentops/extract-yaml-project");
37
+ Object.defineProperty(exports, "extractProjectUuidsFromToolArgs", { enumerable: true, get: function () { return extract_yaml_project_1.extractProjectUuidsFromToolArgs; } });
38
+ Object.defineProperty(exports, "hasYamlProjectDocumentArgs", { enumerable: true, get: function () { return extract_yaml_project_1.hasYamlProjectDocumentArgs; } });
27
39
  // Export audit logger (shared by MCP and CLI)
28
40
  __exportStar(require("./audit"), exports);
29
- // Export Lightdash API models
30
- __exportStar(require("./types/lightdash-api"), exports);
41
+ // Curated Lightdash API types + generated OpenAPI shapes (single public path)
42
+ __exportStar(require("./types"), exports);
@@ -23,6 +23,41 @@ export declare function rejectControlChars(str: string): string;
23
23
  * @throws Error if forbidden characters are present
24
24
  */
25
25
  export declare function validateResourceId(id: string): string;
26
+ /**
27
+ * Validates a UUID string (RFC 4122 format).
28
+ *
29
+ * @param id - UUID to validate
30
+ * @returns The input if valid
31
+ * @throws Error if format is invalid or control characters are present
32
+ */
33
+ export declare function validateUuid(id: string): string;
34
+ /**
35
+ * Validates a slug: 1–256 chars, alphanumeric plus `.`, `_`, `-`.
36
+ * Rejects `.` / `..` (and embedded `..`) so path clients cannot normalize
37
+ * the identifier into a parent URL segment.
38
+ *
39
+ * @param id - Slug to validate
40
+ * @returns The input if valid
41
+ * @throws Error if length or character set is invalid
42
+ */
43
+ export declare function validateSlug(id: string): string;
44
+ /**
45
+ * Validates an OpenAPI UuidOrSlug identifier: UUID when the string matches UUID form,
46
+ * otherwise a safe slug.
47
+ *
48
+ * @param id - UUID or slug to validate
49
+ * @returns The input if valid
50
+ * @throws Error if neither UUID nor slug rules pass
51
+ */
52
+ export declare function validateUuidOrSlug(id: string): string;
53
+ /**
54
+ * Validates a fingerprint identifier: 1–512 chars, no control characters.
55
+ *
56
+ * @param id - Fingerprint to validate
57
+ * @returns The input if valid
58
+ * @throws Error if length is invalid or control characters are present
59
+ */
60
+ export declare function validateFingerprint(id: string): string;
26
61
  /**
27
62
  * Validates that a file path is safe for output within the current working directory.
28
63
  * Rejects: .. traversal, absolute paths outside CWD.
@@ -41,9 +41,20 @@ var __importStar = (this && this.__importStar) || (function () {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.rejectControlChars = rejectControlChars;
43
43
  exports.validateResourceId = validateResourceId;
44
+ exports.validateUuid = validateUuid;
45
+ exports.validateSlug = validateSlug;
46
+ exports.validateUuidOrSlug = validateUuidOrSlug;
47
+ exports.validateFingerprint = validateFingerprint;
44
48
  exports.validateSafeOutputDir = validateSafeOutputDir;
45
49
  const path = __importStar(require("node:path"));
46
50
  const FORBIDDEN_IN_RESOURCE_ID = /[?#%]|\.\./;
51
+ /** RFC 4122 UUID (any version), case-insensitive hex. */
52
+ const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
53
+ const SLUG_REGEX = /^[A-Za-z0-9._-]+$/;
54
+ const SLUG_MIN_LENGTH = 1;
55
+ const SLUG_MAX_LENGTH = 256;
56
+ const FINGERPRINT_MIN_LENGTH = 1;
57
+ const FINGERPRINT_MAX_LENGTH = 512;
47
58
  function hasControlChars(str) {
48
59
  for (let i = 0; i < str.length; i++) {
49
60
  if (str.charCodeAt(i) < 0x20)
@@ -86,6 +97,82 @@ function validateResourceId(id) {
86
97
  }
87
98
  return id;
88
99
  }
100
+ /**
101
+ * Validates a UUID string (RFC 4122 format).
102
+ *
103
+ * @param id - UUID to validate
104
+ * @returns The input if valid
105
+ * @throws Error if format is invalid or control characters are present
106
+ */
107
+ function validateUuid(id) {
108
+ if (typeof id !== 'string') {
109
+ throw new Error('UUID must be a string');
110
+ }
111
+ rejectControlChars(id);
112
+ if (!UUID_REGEX.test(id)) {
113
+ throw new Error('Invalid UUID format');
114
+ }
115
+ return id;
116
+ }
117
+ /**
118
+ * Validates a slug: 1–256 chars, alphanumeric plus `.`, `_`, `-`.
119
+ * Rejects `.` / `..` (and embedded `..`) so path clients cannot normalize
120
+ * the identifier into a parent URL segment.
121
+ *
122
+ * @param id - Slug to validate
123
+ * @returns The input if valid
124
+ * @throws Error if length or character set is invalid
125
+ */
126
+ function validateSlug(id) {
127
+ if (typeof id !== 'string') {
128
+ throw new Error('Slug must be a string');
129
+ }
130
+ rejectControlChars(id);
131
+ if (id.length < SLUG_MIN_LENGTH || id.length > SLUG_MAX_LENGTH) {
132
+ throw new Error(`Slug must be between ${SLUG_MIN_LENGTH} and ${SLUG_MAX_LENGTH} characters`);
133
+ }
134
+ if (id === '.' || id === '..' || id.includes('..')) {
135
+ throw new Error('Slug must not contain path traversal segments (. or ..)');
136
+ }
137
+ if (!SLUG_REGEX.test(id)) {
138
+ throw new Error('Slug must contain only alphanumeric characters, dots, underscores, and hyphens');
139
+ }
140
+ return id;
141
+ }
142
+ /**
143
+ * Validates an OpenAPI UuidOrSlug identifier: UUID when the string matches UUID form,
144
+ * otherwise a safe slug.
145
+ *
146
+ * @param id - UUID or slug to validate
147
+ * @returns The input if valid
148
+ * @throws Error if neither UUID nor slug rules pass
149
+ */
150
+ function validateUuidOrSlug(id) {
151
+ if (typeof id !== 'string') {
152
+ throw new Error('Resource ID must be a string');
153
+ }
154
+ if (UUID_REGEX.test(id)) {
155
+ return validateUuid(id);
156
+ }
157
+ return validateSlug(id);
158
+ }
159
+ /**
160
+ * Validates a fingerprint identifier: 1–512 chars, no control characters.
161
+ *
162
+ * @param id - Fingerprint to validate
163
+ * @returns The input if valid
164
+ * @throws Error if length is invalid or control characters are present
165
+ */
166
+ function validateFingerprint(id) {
167
+ if (typeof id !== 'string') {
168
+ throw new Error('Fingerprint must be a string');
169
+ }
170
+ rejectControlChars(id);
171
+ if (id.length < FINGERPRINT_MIN_LENGTH || id.length > FINGERPRINT_MAX_LENGTH) {
172
+ throw new Error(`Fingerprint must be between ${FINGERPRINT_MIN_LENGTH} and ${FINGERPRINT_MAX_LENGTH} characters`);
173
+ }
174
+ return id;
175
+ }
89
176
  /**
90
177
  * Validates that a file path is safe for output within the current working directory.
91
178
  * Rejects: .. traversal, absolute paths outside CWD.