@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.
- package/dist/argument-validation.js +20 -2
- package/dist/argument-validation.test.js +22 -0
- package/dist/audit.d.ts +29 -9
- package/dist/audit.js +53 -9
- package/dist/audit.test.js +51 -24
- package/dist/env.d.ts +1 -1
- package/dist/env.js +2 -2
- package/dist/index.d.ts +1 -3
- package/dist/index.js +6 -8
- package/dist/operations/agent-safe.d.ts +1 -3
- package/dist/operations/agent-safe.js +2 -9
- package/dist/operations/ai-agents.js +118 -30
- package/dist/operations/cli-content.d.ts +5 -0
- package/dist/operations/cli-content.js +71 -0
- package/dist/operations/client-coverage.d.ts +119 -0
- package/dist/operations/client-coverage.js +137 -0
- package/dist/operations/client-coverage.test.d.ts +1 -0
- package/dist/operations/client-coverage.test.js +22 -0
- package/dist/operations/content-developer.d.ts +2 -0
- package/dist/operations/content-developer.js +471 -0
- package/dist/operations/content-governance.d.ts +7 -0
- package/dist/operations/content-governance.js +98 -0
- package/dist/operations/content-reader.d.ts +2 -0
- package/dist/operations/content-reader.js +197 -0
- package/dist/operations/index.d.ts +10 -3
- package/dist/operations/index.js +20 -2
- package/dist/operations/organization-audit.d.ts +2 -0
- package/dist/operations/organization-audit.js +273 -0
- package/dist/operations/parity.test.js +12 -11
- package/dist/operations/registry.d.ts +9 -1
- package/dist/operations/registry.js +77 -2
- package/dist/operations/registry.test.js +39 -11
- package/dist/operations/semantic-layer.d.ts +6 -0
- package/dist/operations/semantic-layer.js +154 -0
- package/dist/operations/types.d.ts +29 -12
- package/dist/operations/types.js +64 -29
- package/dist/operations/types.test.js +33 -45
- package/dist/operations/users.d.ts +2 -2
- package/dist/operations/users.js +8 -10
- package/dist/safety.d.ts +8 -2
- package/dist/safety.js +22 -4
- package/dist/safety.test.js +29 -6
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.js +29 -0
- package/package.json +2 -1
- package/src/argument-validation.test.ts +31 -0
- package/src/argument-validation.ts +20 -2
- package/src/audit.test.ts +70 -30
- package/src/audit.ts +88 -12
- package/src/env.ts +1 -1
- package/src/index.ts +5 -9
- package/src/operations/agent-safe.ts +2 -12
- package/src/operations/ai-agents.ts +123 -31
- package/src/operations/cli-content.ts +79 -0
- package/src/operations/client-coverage.test.ts +23 -0
- package/src/operations/client-coverage.ts +153 -0
- package/src/operations/content-developer.ts +501 -0
- package/src/operations/content-governance.ts +110 -0
- package/src/operations/content-reader.ts +212 -0
- package/src/operations/index.ts +25 -2
- package/src/operations/organization-audit.ts +293 -0
- package/src/operations/parity.test.ts +12 -14
- package/src/operations/registry.test.ts +41 -9
- package/src/operations/registry.ts +86 -2
- package/src/operations/semantic-layer.ts +166 -0
- package/src/operations/types.test.ts +38 -76
- package/src/operations/types.ts +112 -47
- package/src/operations/users.ts +9 -11
- package/src/safety.test.ts +32 -6
- package/src/safety.ts +26 -4
- package/src/types/index.ts +13 -0
|
@@ -22,6 +22,8 @@ exports.RESOURCE_ID_KEYS = new Set([
|
|
|
22
22
|
'runUuid',
|
|
23
23
|
'artifactUuid',
|
|
24
24
|
'versionUuid',
|
|
25
|
+
'versionUuidA',
|
|
26
|
+
'versionUuidB',
|
|
25
27
|
'mcpServerUuid',
|
|
26
28
|
'toolCallId',
|
|
27
29
|
'fingerprint',
|
|
@@ -32,14 +34,30 @@ exports.RESOURCE_ID_KEYS = new Set([
|
|
|
32
34
|
'spaceUuid',
|
|
33
35
|
'spaceUuids',
|
|
34
36
|
'parentSpaceUuid',
|
|
37
|
+
'targetSpaceUuid',
|
|
38
|
+
'itemUuids',
|
|
35
39
|
'roleUuid',
|
|
36
40
|
'dashboardUuid',
|
|
41
|
+
'dashboardUuidOrSlug',
|
|
42
|
+
'sourceDashboardUuid',
|
|
37
43
|
'schedulerUuid',
|
|
38
44
|
'organizationUuid',
|
|
39
45
|
'chartUuid',
|
|
46
|
+
'chartUuidOrSlug',
|
|
47
|
+
'sourceChartUuidOrSlug',
|
|
48
|
+
'contentUuidOrSlug',
|
|
49
|
+
'tileUuid',
|
|
50
|
+
'newSlug',
|
|
40
51
|
]);
|
|
41
52
|
/** Keys that accept OpenAPI UuidOrSlug (UUID or slug), not UUID-only. */
|
|
42
|
-
const UUID_OR_SLUG_KEYS = new Set([
|
|
53
|
+
const UUID_OR_SLUG_KEYS = new Set([
|
|
54
|
+
'dashboardUuid',
|
|
55
|
+
'dashboardUuidOrSlug',
|
|
56
|
+
'chartUuid',
|
|
57
|
+
'chartUuidOrSlug',
|
|
58
|
+
'sourceChartUuidOrSlug',
|
|
59
|
+
'contentUuidOrSlug',
|
|
60
|
+
]);
|
|
43
61
|
function isMissing(value) {
|
|
44
62
|
return value === undefined || value === null;
|
|
45
63
|
}
|
|
@@ -121,7 +139,7 @@ function validateBySemanticType(value, semanticType, name) {
|
|
|
121
139
|
}
|
|
122
140
|
}
|
|
123
141
|
function validateResourceIdValue(key, value) {
|
|
124
|
-
if (key === 'slug') {
|
|
142
|
+
if (key === 'slug' || key === 'newSlug') {
|
|
125
143
|
(0, input_validation_1.validateSlug)(value);
|
|
126
144
|
return;
|
|
127
145
|
}
|
|
@@ -10,12 +10,17 @@ const VALID_UUID = '550e8400-e29b-41d4-a716-446655440000';
|
|
|
10
10
|
'agentUuid',
|
|
11
11
|
'artifactUuid',
|
|
12
12
|
'chartUuid',
|
|
13
|
+
'chartUuidOrSlug',
|
|
14
|
+
'contentUuidOrSlug',
|
|
13
15
|
'dashboardUuid',
|
|
16
|
+
'dashboardUuidOrSlug',
|
|
14
17
|
'evalUuid',
|
|
15
18
|
'fingerprint',
|
|
16
19
|
'groupUuid',
|
|
20
|
+
'itemUuids',
|
|
17
21
|
'mcpServerUuid',
|
|
18
22
|
'messageUuid',
|
|
23
|
+
'newSlug',
|
|
19
24
|
'organizationUuid',
|
|
20
25
|
'parentSpaceUuid',
|
|
21
26
|
'project',
|
|
@@ -28,12 +33,18 @@ const VALID_UUID = '550e8400-e29b-41d4-a716-446655440000';
|
|
|
28
33
|
'savedQueryUuid',
|
|
29
34
|
'schedulerUuid',
|
|
30
35
|
'slug',
|
|
36
|
+
'sourceChartUuidOrSlug',
|
|
37
|
+
'sourceDashboardUuid',
|
|
31
38
|
'spaceUuid',
|
|
32
39
|
'spaceUuids',
|
|
40
|
+
'targetSpaceUuid',
|
|
33
41
|
'threadUuid',
|
|
42
|
+
'tileUuid',
|
|
34
43
|
'toolCallId',
|
|
35
44
|
'userUuid',
|
|
36
45
|
'versionUuid',
|
|
46
|
+
'versionUuidA',
|
|
47
|
+
'versionUuidB',
|
|
37
48
|
].sort());
|
|
38
49
|
});
|
|
39
50
|
});
|
|
@@ -145,6 +156,17 @@ const VALID_UUID = '550e8400-e29b-41d4-a716-446655440000';
|
|
|
145
156
|
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ dashboardUuid: 'bad?' })).toThrow('Slug must contain only alphanumeric characters');
|
|
146
157
|
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({ dashboardUuid: '..' })).toThrow('Slug must not contain path traversal segments');
|
|
147
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
|
+
});
|
|
148
170
|
(0, vitest_1.it)('validates spaceUuids and parentSpaceUuid as UUIDs', () => {
|
|
149
171
|
(0, vitest_1.expect)(() => (0, argument_validation_1.validateResourceIdsInObject)({
|
|
150
172
|
spaceUuids: [VALID_UUID],
|
package/dist/audit.d.ts
CHANGED
|
@@ -1,33 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Structured audit logger for Lightdash tool invocations (MCP and CLI).
|
|
3
3
|
*
|
|
4
|
-
* Each operation is recorded as a single NDJSON line
|
|
5
|
-
*
|
|
6
|
-
* and optional OAuth attribution fields (tokenHash, subject) when available.
|
|
4
|
+
* Each operation is recorded as a single NDJSON line. On stderr the line is pure JSON
|
|
5
|
+
* (Cloud Logging–parseable); text prefixes prevent jsonPayload parsing on Cloud Run.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
* - If LIGHTDASH_TOOLS_AUDIT_LOG is set to a file path, entries are appended to that file.
|
|
10
|
-
* - Otherwise entries are written to stderr with an "[audit]" prefix.
|
|
7
|
+
* If LIGHTDASH_TOOLS_AUDIT_LOG is a file path, entries are appended there; otherwise stderr.
|
|
11
8
|
*/
|
|
12
|
-
export type AuditStatus = 'blocked' | 'error' | 'success';
|
|
9
|
+
export type AuditStatus = 'blocked' | 'confirmation_cancelled' | 'confirmation_declined' | 'confirmation_requested' | 'deletion_failed' | 'deletion_succeeded' | 'error' | 'promotion_failed' | 'promotion_succeeded' | 'resource_changed' | 'success';
|
|
10
|
+
/** Cloud Logging LogSeverity-compatible strings for structured stderr JSON. */
|
|
11
|
+
export type AuditSeverity = 'ERROR' | 'INFO' | 'NOTICE' | 'WARNING';
|
|
13
12
|
export type AuditLogEntry = {
|
|
13
|
+
/** Stable filter key for Cloud Logging (`jsonPayload.channel="audit"`). */
|
|
14
|
+
channel: 'audit';
|
|
15
|
+
severity: AuditSeverity;
|
|
16
|
+
message: string;
|
|
14
17
|
timestamp: string;
|
|
18
|
+
/** Process-lifetime instance id (not the MCP client session). */
|
|
15
19
|
sessionId: string;
|
|
16
|
-
/** MCP tool name or CLI command name. */
|
|
17
20
|
tool: string;
|
|
18
|
-
/** Project UUIDs involved in the call, if any (covers both projectUuid and projectUuids[]). */
|
|
19
21
|
projectUuids?: string[];
|
|
20
22
|
/** SHA-256 hash of the OAuth bearer token (never the raw token). */
|
|
21
23
|
tokenHash?: string;
|
|
22
24
|
/** Lightdash user UUID when the call runs under OAuth bearer auth. */
|
|
23
25
|
subject?: string;
|
|
26
|
+
clientSessionId?: string;
|
|
27
|
+
personaId?: string;
|
|
24
28
|
status: AuditStatus;
|
|
25
29
|
durationMs: number;
|
|
26
30
|
};
|
|
31
|
+
export type BuildAuditLogEntryInput = {
|
|
32
|
+
tool: string;
|
|
33
|
+
status: AuditStatus;
|
|
34
|
+
/** Epoch ms when the operation started (`durationMs = now - startMs`). */
|
|
35
|
+
startMs: number;
|
|
36
|
+
projectUuids?: string[];
|
|
37
|
+
tokenHash?: string;
|
|
38
|
+
subject?: string;
|
|
39
|
+
clientSessionId?: string;
|
|
40
|
+
personaId?: string;
|
|
41
|
+
};
|
|
27
42
|
export declare function getSessionId(): string;
|
|
43
|
+
/** Map audit status to Cloud Logging severity. */
|
|
44
|
+
export declare function auditSeverityForStatus(status: AuditStatus): AuditSeverity;
|
|
45
|
+
/** Assemble a full audit entry (shared by CLI and MCP). */
|
|
46
|
+
export declare function buildAuditLogEntry(input: BuildAuditLogEntryInput): AuditLogEntry;
|
|
28
47
|
/**
|
|
29
48
|
* Initialise the audit log. Call once at process startup.
|
|
30
49
|
* If filePath is provided, entries are appended to that file; otherwise stderr is used.
|
|
50
|
+
* Startup banners go to stdout so they do not mix with structured audit JSON on stderr.
|
|
31
51
|
*/
|
|
32
52
|
export declare function initAuditLog(filePath?: string): void;
|
|
33
53
|
/** Append one NDJSON entry to the configured output. */
|
package/dist/audit.js
CHANGED
|
@@ -2,16 +2,15 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Structured audit logger for Lightdash tool invocations (MCP and CLI).
|
|
4
4
|
*
|
|
5
|
-
* Each operation is recorded as a single NDJSON line
|
|
6
|
-
*
|
|
7
|
-
* and optional OAuth attribution fields (tokenHash, subject) when available.
|
|
5
|
+
* Each operation is recorded as a single NDJSON line. On stderr the line is pure JSON
|
|
6
|
+
* (Cloud Logging–parseable); text prefixes prevent jsonPayload parsing on Cloud Run.
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
* - If LIGHTDASH_TOOLS_AUDIT_LOG is set to a file path, entries are appended to that file.
|
|
11
|
-
* - Otherwise entries are written to stderr with an "[audit]" prefix.
|
|
8
|
+
* If LIGHTDASH_TOOLS_AUDIT_LOG is a file path, entries are appended there; otherwise stderr.
|
|
12
9
|
*/
|
|
13
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
11
|
exports.getSessionId = getSessionId;
|
|
12
|
+
exports.auditSeverityForStatus = auditSeverityForStatus;
|
|
13
|
+
exports.buildAuditLogEntry = buildAuditLogEntry;
|
|
15
14
|
exports.initAuditLog = initAuditLog;
|
|
16
15
|
exports.logAuditEntry = logAuditEntry;
|
|
17
16
|
exports.closeAuditLog = closeAuditLog;
|
|
@@ -23,20 +22,65 @@ let _writeStream;
|
|
|
23
22
|
function getSessionId() {
|
|
24
23
|
return SESSION_ID;
|
|
25
24
|
}
|
|
25
|
+
/** Map audit status to Cloud Logging severity. */
|
|
26
|
+
function auditSeverityForStatus(status) {
|
|
27
|
+
switch (status) {
|
|
28
|
+
case 'success':
|
|
29
|
+
return 'INFO';
|
|
30
|
+
case 'deletion_succeeded':
|
|
31
|
+
case 'promotion_succeeded':
|
|
32
|
+
return 'NOTICE';
|
|
33
|
+
case 'blocked':
|
|
34
|
+
case 'confirmation_cancelled':
|
|
35
|
+
case 'confirmation_declined':
|
|
36
|
+
case 'confirmation_requested':
|
|
37
|
+
case 'resource_changed':
|
|
38
|
+
return 'WARNING';
|
|
39
|
+
case 'deletion_failed':
|
|
40
|
+
case 'error':
|
|
41
|
+
case 'promotion_failed':
|
|
42
|
+
return 'ERROR';
|
|
43
|
+
default: {
|
|
44
|
+
const _exhaustive = status;
|
|
45
|
+
return _exhaustive;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Assemble a full audit entry (shared by CLI and MCP). */
|
|
50
|
+
function buildAuditLogEntry(input) {
|
|
51
|
+
const projectUuids = input.projectUuids && input.projectUuids.length > 0 ? input.projectUuids : undefined;
|
|
52
|
+
return {
|
|
53
|
+
channel: 'audit',
|
|
54
|
+
severity: auditSeverityForStatus(input.status),
|
|
55
|
+
message: `${input.tool} ${input.status}`,
|
|
56
|
+
timestamp: new Date().toISOString(),
|
|
57
|
+
sessionId: SESSION_ID,
|
|
58
|
+
tool: input.tool,
|
|
59
|
+
projectUuids,
|
|
60
|
+
tokenHash: input.tokenHash,
|
|
61
|
+
subject: input.subject,
|
|
62
|
+
clientSessionId: input.clientSessionId,
|
|
63
|
+
personaId: input.personaId,
|
|
64
|
+
status: input.status,
|
|
65
|
+
durationMs: Date.now() - input.startMs,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
26
68
|
/**
|
|
27
69
|
* Initialise the audit log. Call once at process startup.
|
|
28
70
|
* If filePath is provided, entries are appended to that file; otherwise stderr is used.
|
|
71
|
+
* Startup banners go to stdout so they do not mix with structured audit JSON on stderr.
|
|
29
72
|
*/
|
|
30
73
|
function initAuditLog(filePath) {
|
|
31
74
|
if (filePath) {
|
|
32
75
|
_writeStream = (0, node_fs_1.createWriteStream)(filePath, { flags: 'a' });
|
|
33
76
|
_writeStream.on('error', (err) => {
|
|
77
|
+
// Diagnostic only — not an audit row.
|
|
34
78
|
console.error('[audit] Failed to write to audit log file:', err);
|
|
35
79
|
});
|
|
36
|
-
console.
|
|
80
|
+
console.log(`[audit] Writing to file: ${filePath} (session: ${SESSION_ID})`);
|
|
37
81
|
}
|
|
38
82
|
else {
|
|
39
|
-
console.
|
|
83
|
+
console.log(`[audit] Writing to stderr (session: ${SESSION_ID})`);
|
|
40
84
|
}
|
|
41
85
|
}
|
|
42
86
|
/** Append one NDJSON entry to the configured output. */
|
|
@@ -46,7 +90,7 @@ function logAuditEntry(entry) {
|
|
|
46
90
|
_writeStream.write(line);
|
|
47
91
|
}
|
|
48
92
|
else {
|
|
49
|
-
process.stderr.write(
|
|
93
|
+
process.stderr.write(line);
|
|
50
94
|
}
|
|
51
95
|
}
|
|
52
96
|
/** Closes the file stream, if any. Awaits pending writes before resolving. */
|
package/dist/audit.test.js
CHANGED
|
@@ -14,56 +14,83 @@ const audit_1 = require("./audit");
|
|
|
14
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
15
|
(0, vitest_1.expect)((0, audit_1.getSessionId)()).toBe((0, audit_1.getSessionId)());
|
|
16
16
|
});
|
|
17
|
-
(0, vitest_1.it)('
|
|
18
|
-
|
|
17
|
+
(0, vitest_1.it)('auditSeverityForStatus maps statuses for Cloud Logging', () => {
|
|
18
|
+
(0, vitest_1.expect)((0, audit_1.auditSeverityForStatus)('success')).toBe('INFO');
|
|
19
|
+
(0, vitest_1.expect)((0, audit_1.auditSeverityForStatus)('deletion_succeeded')).toBe('NOTICE');
|
|
20
|
+
(0, vitest_1.expect)((0, audit_1.auditSeverityForStatus)('blocked')).toBe('WARNING');
|
|
21
|
+
(0, vitest_1.expect)((0, audit_1.auditSeverityForStatus)('error')).toBe('ERROR');
|
|
22
|
+
});
|
|
23
|
+
(0, vitest_1.it)('buildAuditLogEntry derives channel, severity, and message', () => {
|
|
24
|
+
const entry = (0, audit_1.buildAuditLogEntry)({
|
|
25
|
+
tool: 'demo_tool',
|
|
26
|
+
status: 'blocked',
|
|
27
|
+
startMs: Date.now() - 5,
|
|
28
|
+
projectUuids: [],
|
|
29
|
+
personaId: 'semantic-layer',
|
|
30
|
+
});
|
|
31
|
+
(0, vitest_1.expect)(entry.channel).toBe('audit');
|
|
32
|
+
(0, vitest_1.expect)(entry.severity).toBe('WARNING');
|
|
33
|
+
(0, vitest_1.expect)(entry.message).toBe('demo_tool blocked');
|
|
34
|
+
(0, vitest_1.expect)(entry.projectUuids).toBeUndefined();
|
|
35
|
+
(0, vitest_1.expect)(entry.personaId).toBe('semantic-layer');
|
|
36
|
+
(0, vitest_1.expect)(entry.sessionId).toBe((0, audit_1.getSessionId)());
|
|
37
|
+
});
|
|
38
|
+
(0, vitest_1.it)('initAuditLog announces stderr destination on stdout when no file path is given', () => {
|
|
39
|
+
const consoleLogSpy = vitest_1.vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
19
40
|
try {
|
|
20
41
|
(0, audit_1.initAuditLog)();
|
|
21
|
-
(0, vitest_1.expect)(
|
|
42
|
+
(0, vitest_1.expect)(consoleLogSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining('[audit] Writing to stderr'));
|
|
22
43
|
}
|
|
23
44
|
finally {
|
|
24
|
-
|
|
45
|
+
consoleLogSpy.mockRestore();
|
|
25
46
|
}
|
|
26
47
|
});
|
|
27
|
-
(0, vitest_1.it)('logAuditEntry writes NDJSON to stderr
|
|
48
|
+
(0, vitest_1.it)('logAuditEntry writes pure JSON NDJSON to stderr (Cloud Logging–parseable)', () => {
|
|
28
49
|
(0, audit_1.initAuditLog)();
|
|
29
|
-
(0, audit_1.logAuditEntry)({
|
|
30
|
-
timestamp: '2026-01-01T00:00:00.000Z',
|
|
31
|
-
sessionId: (0, audit_1.getSessionId)(),
|
|
50
|
+
(0, audit_1.logAuditEntry)((0, audit_1.buildAuditLogEntry)({
|
|
32
51
|
tool: 'test_tool',
|
|
52
|
+
status: 'success',
|
|
53
|
+
startMs: Date.now() - 12,
|
|
33
54
|
tokenHash: 'abc123',
|
|
34
55
|
subject: 'user-uuid',
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
56
|
+
clientSessionId: 'mcp-session-1',
|
|
57
|
+
personaId: 'semantic-layer',
|
|
58
|
+
}));
|
|
38
59
|
const auditLine = stderrSpy.mock.calls
|
|
39
60
|
.map(([chunk]) => String(chunk))
|
|
40
61
|
.find((line) => line.includes('"tool":"test_tool"'));
|
|
41
62
|
(0, vitest_1.expect)(auditLine).toBeDefined();
|
|
42
|
-
(0, vitest_1.expect)(auditLine).toContain('[audit]');
|
|
43
|
-
|
|
44
|
-
(0, vitest_1.expect)(
|
|
45
|
-
(0, vitest_1.expect)(
|
|
63
|
+
(0, vitest_1.expect)(auditLine).not.toContain('[audit]');
|
|
64
|
+
const parsed = JSON.parse(auditLine.trim());
|
|
65
|
+
(0, vitest_1.expect)(parsed.channel).toBe('audit');
|
|
66
|
+
(0, vitest_1.expect)(parsed.severity).toBe('INFO');
|
|
67
|
+
(0, vitest_1.expect)(parsed.message).toBe('test_tool success');
|
|
68
|
+
(0, vitest_1.expect)(parsed.status).toBe('success');
|
|
69
|
+
(0, vitest_1.expect)(parsed.tokenHash).toBe('abc123');
|
|
70
|
+
(0, vitest_1.expect)(parsed.subject).toBe('user-uuid');
|
|
71
|
+
(0, vitest_1.expect)(parsed.clientSessionId).toBe('mcp-session-1');
|
|
72
|
+
(0, vitest_1.expect)(parsed.personaId).toBe('semantic-layer');
|
|
46
73
|
});
|
|
47
74
|
(0, vitest_1.it)('logAuditEntry appends to a file when initAuditLog receives a path', async () => {
|
|
48
75
|
const dir = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'audit-test-'));
|
|
49
76
|
const filePath = (0, node_path_1.join)(dir, 'audit.ndjson');
|
|
50
77
|
try {
|
|
51
78
|
(0, audit_1.initAuditLog)(filePath);
|
|
52
|
-
(0, audit_1.logAuditEntry)({
|
|
53
|
-
timestamp: '2026-01-01T00:00:00.000Z',
|
|
54
|
-
sessionId: (0, audit_1.getSessionId)(),
|
|
79
|
+
(0, audit_1.logAuditEntry)((0, audit_1.buildAuditLogEntry)({
|
|
55
80
|
tool: 'file_tool',
|
|
56
|
-
projectUuids: ['uuid-a'],
|
|
57
81
|
status: 'blocked',
|
|
58
|
-
|
|
59
|
-
|
|
82
|
+
startMs: Date.now() - 3,
|
|
83
|
+
projectUuids: ['uuid-a'],
|
|
84
|
+
}));
|
|
60
85
|
await (0, audit_1.closeAuditLog)();
|
|
61
86
|
// filePath is a temp path from mkdtempSync in this test only
|
|
62
87
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
63
88
|
const contents = (0, node_fs_1.readFileSync)(filePath, 'utf8');
|
|
64
|
-
|
|
65
|
-
(0, vitest_1.expect)(
|
|
66
|
-
(0, vitest_1.expect)(
|
|
89
|
+
const parsed = JSON.parse(contents.trim());
|
|
90
|
+
(0, vitest_1.expect)(parsed.channel).toBe('audit');
|
|
91
|
+
(0, vitest_1.expect)(parsed.tool).toBe('file_tool');
|
|
92
|
+
(0, vitest_1.expect)(parsed.projectUuids).toEqual(['uuid-a']);
|
|
93
|
+
(0, vitest_1.expect)(parsed.status).toBe('blocked');
|
|
67
94
|
}
|
|
68
95
|
finally {
|
|
69
96
|
await (0, audit_1.closeAuditLog)();
|
package/dist/env.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
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
|
-
export declare const
|
|
9
|
+
export declare const ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS = "LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS";
|
|
10
10
|
/** MCP HTTP server env vars (`LIGHTDASH_TOOLS_MCP_*` / `LIGHTDASH_TOOLS_OAUTH_*` per ADR-0009). */
|
|
11
11
|
/** @deprecated Removed — auth is credential-inferred (ADR-0007). Kept for migration error messages. */
|
|
12
12
|
export declare const ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = "LIGHTDASH_TOOLS_MCP_AUTH_MODE";
|
package/dist/env.js
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
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_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.
|
|
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_PROJECT_UUIDS = 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
|
-
exports.
|
|
12
|
+
exports.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS = 'LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS';
|
|
13
13
|
/** MCP HTTP server env vars (`LIGHTDASH_TOOLS_MCP_*` / `LIGHTDASH_TOOLS_OAUTH_*` per ADR-0009). */
|
|
14
14
|
/** @deprecated Removed — auth is credential-inferred (ADR-0007). Kept for migration error messages. */
|
|
15
15
|
exports.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = 'LIGHTDASH_TOOLS_MCP_AUTH_MODE';
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,4 @@ export * from './agentops/snapshots';
|
|
|
9
9
|
export * from './agentops/formatters';
|
|
10
10
|
export { extractProjectUuidsFromToolArgs, hasYamlProjectDocumentArgs, } from './agentops/extract-yaml-project';
|
|
11
11
|
export * from './audit';
|
|
12
|
-
export * from './types
|
|
13
|
-
export { CONTENT_SORT_BY_COLUMNS } from './types/v2/content';
|
|
14
|
-
export type { paths, components, operations } from './types/generated/openapi-types';
|
|
12
|
+
export * from './types';
|
package/dist/index.js
CHANGED
|
@@ -14,7 +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.
|
|
17
|
+
exports.hasYamlProjectDocumentArgs = exports.extractProjectUuidsFromToolArgs = void 0;
|
|
18
18
|
exports.greet = greet;
|
|
19
19
|
function greet(name) {
|
|
20
20
|
return `Hello, ${name}!`;
|
|
@@ -25,11 +25,11 @@ __exportStar(require("./env"), exports);
|
|
|
25
25
|
__exportStar(require("./safety"), exports);
|
|
26
26
|
// Export input validation
|
|
27
27
|
__exportStar(require("./input-validation"), exports);
|
|
28
|
-
// Export argument / descriptor validation
|
|
28
|
+
// Export argument / descriptor validation
|
|
29
29
|
__exportStar(require("./argument-validation"), exports);
|
|
30
|
-
// Export shared typed operation
|
|
30
|
+
// Export shared typed operation catalog (ADR-0013)
|
|
31
31
|
__exportStar(require("./operations"), exports);
|
|
32
|
-
// Export AgentOps bundle and gate types
|
|
32
|
+
// Export AgentOps bundle and gate types
|
|
33
33
|
__exportStar(require("./agentops/types"), exports);
|
|
34
34
|
__exportStar(require("./agentops/snapshots"), exports);
|
|
35
35
|
__exportStar(require("./agentops/formatters"), exports);
|
|
@@ -38,7 +38,5 @@ Object.defineProperty(exports, "extractProjectUuidsFromToolArgs", { enumerable:
|
|
|
38
38
|
Object.defineProperty(exports, "hasYamlProjectDocumentArgs", { enumerable: true, get: function () { return extract_yaml_project_1.hasYamlProjectDocumentArgs; } });
|
|
39
39
|
// Export audit logger (shared by MCP and CLI)
|
|
40
40
|
__exportStar(require("./audit"), exports);
|
|
41
|
-
//
|
|
42
|
-
__exportStar(require("./types
|
|
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; } });
|
|
41
|
+
// Curated Lightdash API types + generated OpenAPI shapes (single public path)
|
|
42
|
+
__exportStar(require("./types"), exports);
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Agent-safe surface policy helpers (ADR-0004).
|
|
2
|
+
* Agent-safe surface policy helpers (ADR-0004 / ADR-0013).
|
|
3
3
|
*/
|
|
4
|
-
/** MCP tool names that must never be registered, derived from client-only registry entries. */
|
|
5
|
-
export declare function listBannedMcpToolNames(): readonly string[];
|
|
6
4
|
/** Banned MCP tool names (without `lightdash_` prefix) for regression tests. */
|
|
7
5
|
export declare const IRRECOVERABLE_TOOL_DENYLIST: readonly string[];
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Agent-safe surface policy helpers (ADR-0004).
|
|
3
|
+
* Agent-safe surface policy helpers (ADR-0004 / ADR-0013).
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.IRRECOVERABLE_TOOL_DENYLIST = void 0;
|
|
7
|
-
exports.listBannedMcpToolNames = listBannedMcpToolNames;
|
|
8
7
|
const registry_1 = require("./registry");
|
|
9
|
-
/** MCP tool names that must never be registered, derived from client-only registry entries. */
|
|
10
|
-
function listBannedMcpToolNames() {
|
|
11
|
-
return (0, registry_1.listOperations)()
|
|
12
|
-
.filter((operation) => operation.agentExposure === 'client-only' && operation.mcp.toolName.trim().length > 0)
|
|
13
|
-
.map((operation) => operation.mcp.toolName);
|
|
14
|
-
}
|
|
15
8
|
/** Banned MCP tool names (without `lightdash_` prefix) for regression tests. */
|
|
16
|
-
exports.IRRECOVERABLE_TOOL_DENYLIST = listBannedMcpToolNames();
|
|
9
|
+
exports.IRRECOVERABLE_TOOL_DENYLIST = (0, registry_1.listBannedMcpToolNames)();
|