@lightdash-tools/common 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agentops/extract-yaml-project.d.ts +7 -0
- package/dist/agentops/extract-yaml-project.js +42 -0
- package/dist/agentops/formatters.d.ts +5 -0
- package/dist/agentops/formatters.js +47 -0
- package/dist/agentops/snapshots.d.ts +32 -0
- package/dist/agentops/snapshots.js +34 -0
- package/dist/agentops/types.d.ts +224 -0
- package/dist/agentops/types.js +430 -0
- package/dist/argument-validation.d.ts +25 -0
- package/dist/argument-validation.js +199 -0
- package/dist/argument-validation.test.d.ts +1 -0
- package/dist/argument-validation.test.js +183 -0
- package/dist/audit.d.ts +9 -2
- package/dist/audit.js +17 -2
- package/dist/audit.test.d.ts +1 -0
- package/dist/audit.test.js +73 -0
- package/dist/env.d.ts +8 -0
- package/dist/env.js +9 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +14 -0
- package/dist/input-validation.d.ts +35 -0
- package/dist/input-validation.js +87 -0
- package/dist/input-validation.test.js +93 -0
- package/dist/operations/agent-safe.d.ts +7 -0
- package/dist/operations/agent-safe.js +16 -0
- package/dist/operations/ai-agents.d.ts +6 -0
- package/dist/operations/ai-agents.js +411 -0
- package/dist/operations/index.d.ts +5 -0
- package/dist/operations/index.js +16 -0
- package/dist/operations/parity.test.d.ts +1 -0
- package/dist/operations/parity.test.js +28 -0
- package/dist/operations/registry.d.ts +10 -0
- package/dist/operations/registry.js +35 -0
- package/dist/operations/registry.test.d.ts +1 -0
- package/dist/operations/registry.test.js +196 -0
- package/dist/operations/types.d.ts +69 -0
- package/dist/operations/types.js +70 -0
- package/dist/operations/types.test.d.ts +1 -0
- package/dist/operations/types.test.js +104 -0
- package/dist/operations/users.d.ts +6 -0
- package/dist/operations/users.js +60 -0
- package/dist/safety.d.ts +27 -2
- package/dist/safety.js +52 -5
- package/dist/safety.test.js +217 -4
- package/dist/types/generated/openapi-types.d.ts +35895 -10622
- package/dist/types/generated/openapi-types.js +0 -1
- package/dist/types/lightdash-api.d.ts +1 -1
- package/dist/types/v1/ai-agents.d.ts +112 -3
- package/dist/types/v1/charts.d.ts +5 -3
- package/dist/types/v1/dashboards.d.ts +13 -0
- package/dist/types/v1/index.d.ts +45 -8
- package/dist/types/v1/index.js +1 -1
- package/dist/types/v1/lightdash-api.d.ts +107 -16
- package/dist/types/v1/users.d.ts +4 -0
- package/dist/types/v2/content.d.ts +2 -0
- package/dist/types/v2/content.js +8 -0
- package/dist/types/v2/index.d.ts +11 -9
- package/dist/types/v2/index.js +1 -1
- package/package.json +16 -3
- package/src/agentops/extract-yaml-project.ts +42 -0
- package/src/agentops/formatters.ts +52 -0
- package/src/agentops/snapshots.ts +56 -0
- package/src/agentops/types.ts +599 -0
- package/src/argument-validation.test.ts +270 -0
- package/src/argument-validation.ts +240 -0
- package/src/audit.test.ts +87 -0
- package/src/audit.ts +21 -3
- package/src/env.ts +9 -0
- package/src/index.test.ts +1 -0
- package/src/index.ts +16 -1
- package/src/input-validation.test.ts +157 -1
- package/src/input-validation.ts +95 -0
- package/src/operations/agent-safe.ts +18 -0
- package/src/operations/ai-agents.ts +451 -0
- package/src/operations/index.ts +19 -0
- package/src/operations/parity.test.ts +35 -0
- package/src/operations/registry.test.ts +219 -0
- package/src/operations/registry.ts +44 -0
- package/src/operations/types.test.ts +148 -0
- package/src/operations/types.ts +168 -0
- package/src/operations/users.ts +67 -0
- package/src/safety.test.ts +276 -4
- package/src/safety.ts +72 -4
- package/src/types/generated/openapi-types.ts +37017 -11241
- package/src/types/lightdash-api.ts +39 -0
- package/src/types/v1/ai-agents.ts +133 -3
- package/src/types/v1/charts.ts +5 -3
- package/src/types/v1/dashboards.ts +19 -0
- package/src/types/v1/index.ts +51 -8
- package/src/types/v1/lightdash-api.ts +129 -20
- package/src/types/v1/users.ts +4 -0
- package/src/types/v2/content.ts +8 -0
- package/src/types/v2/index.ts +11 -9
- package/tsconfig.json +1 -0
|
@@ -0,0 +1,183 @@
|
|
|
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
|
+
'dashboardUuid',
|
|
14
|
+
'evalUuid',
|
|
15
|
+
'fingerprint',
|
|
16
|
+
'groupUuid',
|
|
17
|
+
'mcpServerUuid',
|
|
18
|
+
'messageUuid',
|
|
19
|
+
'organizationUuid',
|
|
20
|
+
'parentSpaceUuid',
|
|
21
|
+
'project',
|
|
22
|
+
'projectUuid',
|
|
23
|
+
'projectUuids',
|
|
24
|
+
'projects',
|
|
25
|
+
'promptUuid',
|
|
26
|
+
'roleUuid',
|
|
27
|
+
'runUuid',
|
|
28
|
+
'savedQueryUuid',
|
|
29
|
+
'schedulerUuid',
|
|
30
|
+
'slug',
|
|
31
|
+
'spaceUuid',
|
|
32
|
+
'spaceUuids',
|
|
33
|
+
'threadUuid',
|
|
34
|
+
'toolCallId',
|
|
35
|
+
'userUuid',
|
|
36
|
+
'versionUuid',
|
|
37
|
+
].sort());
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
(0, vitest_1.describe)('validateArguments', () => {
|
|
41
|
+
(0, vitest_1.it)('validates uuid arguments', () => {
|
|
42
|
+
const descriptors = [
|
|
43
|
+
{ name: 'projectUuid', source: 'option', semanticType: 'uuid', required: true },
|
|
44
|
+
];
|
|
45
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ projectUuid: VALID_UUID }, descriptors)).not.toThrow();
|
|
46
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ projectUuid: 'bad-uuid' }, descriptors)).toThrow('Invalid UUID format');
|
|
47
|
+
});
|
|
48
|
+
(0, vitest_1.it)('validates slug arguments', () => {
|
|
49
|
+
const descriptors = [
|
|
50
|
+
{ name: 'slug', source: 'option', semanticType: 'slug' },
|
|
51
|
+
];
|
|
52
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ slug: 'my-chart' }, descriptors)).not.toThrow();
|
|
53
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ slug: 'bad slug' }, descriptors)).toThrow('Slug must contain only alphanumeric characters');
|
|
54
|
+
});
|
|
55
|
+
(0, vitest_1.it)('validates fingerprint arguments', () => {
|
|
56
|
+
const descriptors = [
|
|
57
|
+
{ name: 'fingerprint', source: 'body', semanticType: 'fingerprint' },
|
|
58
|
+
];
|
|
59
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ fingerprint: 'abc123' }, descriptors)).not.toThrow();
|
|
60
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ fingerprint: '' }, descriptors)).toThrow('Fingerprint must be between 1 and 512 characters');
|
|
61
|
+
});
|
|
62
|
+
(0, vitest_1.it)('throws when required argument is missing', () => {
|
|
63
|
+
const descriptors = [
|
|
64
|
+
{ name: 'projectUuid', source: 'option', semanticType: 'uuid', required: true },
|
|
65
|
+
];
|
|
66
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({}, descriptors)).toThrow("Required argument 'projectUuid' is missing");
|
|
67
|
+
});
|
|
68
|
+
(0, vitest_1.it)('skips optional missing arguments', () => {
|
|
69
|
+
const descriptors = [
|
|
70
|
+
{ name: 'slug', source: 'option', semanticType: 'slug' },
|
|
71
|
+
];
|
|
72
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({}, descriptors)).not.toThrow();
|
|
73
|
+
});
|
|
74
|
+
(0, vitest_1.it)('validates uuid arrays', () => {
|
|
75
|
+
const descriptors = [
|
|
76
|
+
{ name: 'projectUuid', source: 'body', semanticType: 'uuid' },
|
|
77
|
+
];
|
|
78
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ projectUuid: [VALID_UUID, VALID_UUID] }, descriptors)).not.toThrow();
|
|
79
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ projectUuid: [VALID_UUID, 'not-uuid'] }, descriptors)).toThrow('Invalid UUID format');
|
|
80
|
+
});
|
|
81
|
+
(0, vitest_1.it)('validates free-text with control char rejection only', () => {
|
|
82
|
+
const descriptors = [
|
|
83
|
+
{ name: 'query', source: 'positional', semanticType: 'free-text' },
|
|
84
|
+
];
|
|
85
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ query: 'what? growth%' }, descriptors)).not.toThrow();
|
|
86
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ query: 'bad\u0000' }, descriptors)).toThrow('Input contains invalid control characters');
|
|
87
|
+
});
|
|
88
|
+
(0, vitest_1.it)('validates json string arguments', () => {
|
|
89
|
+
const descriptors = [
|
|
90
|
+
{ name: 'payload', source: 'body', semanticType: 'json' },
|
|
91
|
+
];
|
|
92
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ payload: '{"a":1}' }, descriptors)).not.toThrow();
|
|
93
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ payload: 'not-json' }, descriptors)).toThrow("Argument 'payload' must be valid JSON");
|
|
94
|
+
});
|
|
95
|
+
(0, vitest_1.it)('validates boolean arguments', () => {
|
|
96
|
+
const descriptors = [
|
|
97
|
+
{ name: 'enabled', source: 'option', semanticType: 'boolean' },
|
|
98
|
+
];
|
|
99
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ enabled: true }, descriptors)).not.toThrow();
|
|
100
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ enabled: 'true' }, descriptors)).toThrow("Argument 'enabled' must be a boolean");
|
|
101
|
+
});
|
|
102
|
+
(0, vitest_1.it)('validates number arguments', () => {
|
|
103
|
+
const descriptors = [
|
|
104
|
+
{ name: 'limit', source: 'option', semanticType: 'number' },
|
|
105
|
+
];
|
|
106
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ limit: 10 }, descriptors)).not.toThrow();
|
|
107
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateArguments)({ limit: Number.NaN }, descriptors)).toThrow("Argument 'limit' must be a number");
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
(0, vitest_1.describe)('validateResourceIdsInObject', () => {
|
|
111
|
+
(0, vitest_1.it)('validates top-level resource id keys', () => {
|
|
112
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
|
|
113
|
+
projectUuid: VALID_UUID,
|
|
114
|
+
slug: 'my-chart',
|
|
115
|
+
})).not.toThrow();
|
|
116
|
+
});
|
|
117
|
+
(0, vitest_1.it)('validates projectUuids / projects array entries as UUIDs', () => {
|
|
118
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ projectUuids: [VALID_UUID] })).not.toThrow();
|
|
119
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ projectUuids: [VALID_UUID, 'bad-uuid'] })).toThrow('Invalid UUID format');
|
|
120
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ projects: ['bad-uuid'] })).toThrow('Invalid UUID format');
|
|
121
|
+
});
|
|
122
|
+
(0, vitest_1.it)('validates nested resource id keys', () => {
|
|
123
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
|
|
124
|
+
filter: {
|
|
125
|
+
agentUuid: VALID_UUID,
|
|
126
|
+
nested: {
|
|
127
|
+
threadUuid: VALID_UUID,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
})).not.toThrow();
|
|
131
|
+
});
|
|
132
|
+
(0, vitest_1.it)('validates resource id keys inside arrays', () => {
|
|
133
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)([{ projectUuid: VALID_UUID }, { projectUuid: 'bad-uuid' }])).toThrow('Invalid UUID format');
|
|
134
|
+
});
|
|
135
|
+
(0, vitest_1.it)('validates uuid keys with uuid rules', () => {
|
|
136
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ runUuid: 'not-a-uuid' })).toThrow('Invalid UUID format');
|
|
137
|
+
});
|
|
138
|
+
(0, vitest_1.it)('validates slug key with slug rules', () => {
|
|
139
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ slug: 'bad slug' })).toThrow('Slug must contain only alphanumeric characters');
|
|
140
|
+
});
|
|
141
|
+
(0, vitest_1.it)('accepts UUID or slug for dashboardUuid and chartUuid', () => {
|
|
142
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ dashboardUuid: 'sales-overview' })).not.toThrow();
|
|
143
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ dashboardUuid: VALID_UUID })).not.toThrow();
|
|
144
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ chartUuid: 'my-chart' })).not.toThrow();
|
|
145
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ dashboardUuid: 'bad?' })).toThrow('Slug must contain only alphanumeric characters');
|
|
146
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ dashboardUuid: '..' })).toThrow('Slug must not contain path traversal segments');
|
|
147
|
+
});
|
|
148
|
+
(0, vitest_1.it)('validates spaceUuids and parentSpaceUuid as UUIDs', () => {
|
|
149
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
|
|
150
|
+
spaceUuids: [VALID_UUID],
|
|
151
|
+
parentSpaceUuid: VALID_UUID,
|
|
152
|
+
})).not.toThrow();
|
|
153
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ spaceUuids: ['bad?'] })).toThrow('Invalid UUID format');
|
|
154
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ parentSpaceUuid: '..' })).toThrow('Invalid UUID format');
|
|
155
|
+
});
|
|
156
|
+
(0, vitest_1.it)('validates fingerprint and toolCallId with fingerprint rules', () => {
|
|
157
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
|
|
158
|
+
fingerprint: 'fp-123',
|
|
159
|
+
toolCallId: 'call-abc',
|
|
160
|
+
})).not.toThrow();
|
|
161
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ fingerprint: '' })).toThrow('Fingerprint must be between 1 and 512 characters');
|
|
162
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ toolCallId: '' })).toThrow('Fingerprint must be between 1 and 512 characters');
|
|
163
|
+
});
|
|
164
|
+
(0, vitest_1.it)('validates string arrays under resource id keys', () => {
|
|
165
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
|
|
166
|
+
projectUuid: [VALID_UUID, VALID_UUID],
|
|
167
|
+
})).not.toThrow();
|
|
168
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
|
|
169
|
+
projectUuid: [VALID_UUID, 'invalid'],
|
|
170
|
+
})).toThrow('Invalid UUID format');
|
|
171
|
+
});
|
|
172
|
+
(0, vitest_1.it)('ignores non-resource keys', () => {
|
|
173
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
|
|
174
|
+
query: 'what? growth%',
|
|
175
|
+
name: '../etc/passwd',
|
|
176
|
+
})).not.toThrow();
|
|
177
|
+
});
|
|
178
|
+
(0, vitest_1.it)('handles null and undefined', () => {
|
|
179
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)(null)).not.toThrow();
|
|
180
|
+
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)(undefined)).not.toThrow();
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
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,
|
|
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 = '
|
|
12
|
+
export type AuditStatus = 'blocked' | 'error' | '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,
|
|
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
|
-
|
|
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,13 @@ 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
12
|
export * from './types/lightdash-api';
|
|
7
|
-
export
|
|
13
|
+
export { CONTENT_SORT_BY_COLUMNS } from './types/v2/content';
|
|
8
14
|
export type { paths, components, operations } from './types/generated/openapi-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.CONTENT_SORT_BY_COLUMNS = exports.hasYamlProjectDocumentArgs = exports.extractProjectUuidsFromToolArgs = void 0;
|
|
17
18
|
exports.greet = greet;
|
|
18
19
|
function greet(name) {
|
|
19
20
|
return `Hello, ${name}!`;
|
|
@@ -24,7 +25,20 @@ __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 (RFC Phase 0)
|
|
29
|
+
__exportStar(require("./argument-validation"), exports);
|
|
30
|
+
// Export shared typed operation registry (RFC Section 7)
|
|
31
|
+
__exportStar(require("./operations"), exports);
|
|
32
|
+
// Export AgentOps bundle and gate types (RFC Phase 2)
|
|
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
41
|
// Export Lightdash API models
|
|
30
42
|
__exportStar(require("./types/lightdash-api"), exports);
|
|
43
|
+
var content_1 = require("./types/v2/content");
|
|
44
|
+
Object.defineProperty(exports, "CONTENT_SORT_BY_COLUMNS", { enumerable: true, get: function () { return content_1.CONTENT_SORT_BY_COLUMNS; } });
|
|
@@ -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.
|
package/dist/input-validation.js
CHANGED
|
@@ -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.
|