@duckcodeailabs/dql-cli 1.4.1 → 1.4.4
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/apps-api.d.ts +77 -0
- package/apps-api.d.ts.map +1 -0
- package/apps-api.js +612 -0
- package/apps-api.js.map +1 -0
- package/apps-api.test.d.ts +2 -0
- package/apps-api.test.d.ts.map +1 -0
- package/apps-api.test.js +111 -0
- package/apps-api.test.js.map +1 -0
- package/{dist/assets/dql-notebook/assets/index-BJ7MV8Gv.js → assets/dql-notebook/assets/index-DUTeFz5j.js} +145 -134
- package/{dist/assets → assets}/dql-notebook/index.html +1 -1
- package/{dist/commands → commands}/agent.d.ts.map +1 -1
- package/{dist/commands → commands}/agent.js +50 -2
- package/commands/agent.js.map +1 -0
- package/governance-runtime.d.ts +15 -0
- package/governance-runtime.d.ts.map +1 -0
- package/governance-runtime.js +50 -0
- package/governance-runtime.js.map +1 -0
- package/{dist/llm → llm}/index.d.ts.map +1 -1
- package/llm/index.js +19 -0
- package/llm/index.js.map +1 -0
- package/llm/providers/dql-agent-provider.d.ts +5 -0
- package/llm/providers/dql-agent-provider.d.ts.map +1 -0
- package/llm/providers/dql-agent-provider.js +99 -0
- package/llm/providers/dql-agent-provider.js.map +1 -0
- package/{dist/llm → llm}/types.d.ts +1 -1
- package/llm/types.d.ts.map +1 -0
- package/local-runtime.d.ts.map +1 -0
- package/{dist/local-runtime.js → local-runtime.js} +557 -36
- package/local-runtime.js.map +1 -0
- package/metricflow.d.ts +35 -0
- package/metricflow.d.ts.map +1 -0
- package/metricflow.js +122 -0
- package/metricflow.js.map +1 -0
- package/metricflow.test.d.ts +2 -0
- package/metricflow.test.d.ts.map +1 -0
- package/metricflow.test.js +54 -0
- package/metricflow.test.js.map +1 -0
- package/package.json +20 -30
- package/{dist/schedule → schedule}/runner.d.ts +3 -0
- package/schedule/runner.d.ts.map +1 -0
- package/schedule/runner.js +221 -0
- package/schedule/runner.js.map +1 -0
- package/{dist/schedule → schedule}/service.d.ts +2 -1
- package/schedule/service.d.ts.map +1 -0
- package/{dist/schedule → schedule}/service.js +39 -1
- package/schedule/service.js.map +1 -0
- package/{dist/schedule → schedule}/types.d.ts +6 -0
- package/schedule/types.d.ts.map +1 -0
- package/{dist/semantic-import.d.ts → semantic-import.d.ts} +9 -1
- package/semantic-import.d.ts.map +1 -0
- package/{dist/semantic-import.js → semantic-import.js} +269 -3
- package/semantic-import.js.map +1 -0
- package/LICENSE +0 -123
- package/README.md +0 -71
- package/dist/apps-api.d.ts +0 -16
- package/dist/apps-api.d.ts.map +0 -1
- package/dist/apps-api.js +0 -249
- package/dist/apps-api.js.map +0 -1
- package/dist/commands/agent.js.map +0 -1
- package/dist/llm/index.js +0 -16
- package/dist/llm/index.js.map +0 -1
- package/dist/llm/types.d.ts.map +0 -1
- package/dist/local-runtime.d.ts.map +0 -1
- package/dist/local-runtime.js.map +0 -1
- package/dist/schedule/runner.d.ts.map +0 -1
- package/dist/schedule/runner.js +0 -109
- package/dist/schedule/runner.js.map +0 -1
- package/dist/schedule/service.d.ts.map +0 -1
- package/dist/schedule/service.js.map +0 -1
- package/dist/schedule/types.d.ts.map +0 -1
- package/dist/semantic-import.d.ts.map +0 -1
- package/dist/semantic-import.js.map +0 -1
- /package/{dist/args.d.ts → args.d.ts} +0 -0
- /package/{dist/args.d.ts.map → args.d.ts.map} +0 -0
- /package/{dist/args.js → args.js} +0 -0
- /package/{dist/args.js.map → args.js.map} +0 -0
- /package/{dist/args.test.d.ts → args.test.d.ts} +0 -0
- /package/{dist/args.test.d.ts.map → args.test.d.ts.map} +0 -0
- /package/{dist/args.test.js → args.test.js} +0 -0
- /package/{dist/args.test.js.map → args.test.js.map} +0 -0
- /package/{dist/assets → assets}/dql-notebook/assets/codemirror-DJYUkPr1.js +0 -0
- /package/{dist/assets → assets}/dql-notebook/assets/index-DrhoZmtv.css +0 -0
- /package/{dist/assets → assets}/dql-notebook/assets/react-CRB3T2We.js +0 -0
- /package/{dist/assets → assets}/notebook-browser/app.js +0 -0
- /package/{dist/assets → assets}/notebook-browser/index.html +0 -0
- /package/{dist/assets → assets}/notebook-browser/styles.css +0 -0
- /package/{dist/block-templates.d.ts → block-templates.d.ts} +0 -0
- /package/{dist/block-templates.d.ts.map → block-templates.d.ts.map} +0 -0
- /package/{dist/block-templates.js → block-templates.js} +0 -0
- /package/{dist/block-templates.js.map → block-templates.js.map} +0 -0
- /package/{dist/commands → commands}/agent.d.ts +0 -0
- /package/{dist/commands → commands}/app.d.ts +0 -0
- /package/{dist/commands → commands}/app.d.ts.map +0 -0
- /package/{dist/commands → commands}/app.js +0 -0
- /package/{dist/commands → commands}/app.js.map +0 -0
- /package/{dist/commands → commands}/build.d.ts +0 -0
- /package/{dist/commands → commands}/build.d.ts.map +0 -0
- /package/{dist/commands → commands}/build.js +0 -0
- /package/{dist/commands → commands}/build.js.map +0 -0
- /package/{dist/commands → commands}/build.test.d.ts +0 -0
- /package/{dist/commands → commands}/build.test.d.ts.map +0 -0
- /package/{dist/commands → commands}/build.test.js +0 -0
- /package/{dist/commands → commands}/build.test.js.map +0 -0
- /package/{dist/commands → commands}/certify.d.ts +0 -0
- /package/{dist/commands → commands}/certify.d.ts.map +0 -0
- /package/{dist/commands → commands}/certify.js +0 -0
- /package/{dist/commands → commands}/certify.js.map +0 -0
- /package/{dist/commands → commands}/compile.d.ts +0 -0
- /package/{dist/commands → commands}/compile.d.ts.map +0 -0
- /package/{dist/commands → commands}/compile.js +0 -0
- /package/{dist/commands → commands}/compile.js.map +0 -0
- /package/{dist/commands → commands}/compile.test.d.ts +0 -0
- /package/{dist/commands → commands}/compile.test.d.ts.map +0 -0
- /package/{dist/commands → commands}/compile.test.js +0 -0
- /package/{dist/commands → commands}/compile.test.js.map +0 -0
- /package/{dist/commands → commands}/diff.d.ts +0 -0
- /package/{dist/commands → commands}/diff.d.ts.map +0 -0
- /package/{dist/commands → commands}/diff.js +0 -0
- /package/{dist/commands → commands}/diff.js.map +0 -0
- /package/{dist/commands → commands}/doctor.d.ts +0 -0
- /package/{dist/commands → commands}/doctor.d.ts.map +0 -0
- /package/{dist/commands → commands}/doctor.js +0 -0
- /package/{dist/commands → commands}/doctor.js.map +0 -0
- /package/{dist/commands → commands}/doctor.test.d.ts +0 -0
- /package/{dist/commands → commands}/doctor.test.d.ts.map +0 -0
- /package/{dist/commands → commands}/doctor.test.js +0 -0
- /package/{dist/commands → commands}/doctor.test.js.map +0 -0
- /package/{dist/commands → commands}/fmt.d.ts +0 -0
- /package/{dist/commands → commands}/fmt.d.ts.map +0 -0
- /package/{dist/commands → commands}/fmt.js +0 -0
- /package/{dist/commands → commands}/fmt.js.map +0 -0
- /package/{dist/commands → commands}/info.d.ts +0 -0
- /package/{dist/commands → commands}/info.d.ts.map +0 -0
- /package/{dist/commands → commands}/info.js +0 -0
- /package/{dist/commands → commands}/info.js.map +0 -0
- /package/{dist/commands → commands}/init.d.ts +0 -0
- /package/{dist/commands → commands}/init.d.ts.map +0 -0
- /package/{dist/commands → commands}/init.js +0 -0
- /package/{dist/commands → commands}/init.js.map +0 -0
- /package/{dist/commands → commands}/init.test.d.ts +0 -0
- /package/{dist/commands → commands}/init.test.d.ts.map +0 -0
- /package/{dist/commands → commands}/init.test.js +0 -0
- /package/{dist/commands → commands}/init.test.js.map +0 -0
- /package/{dist/commands → commands}/lineage.d.ts +0 -0
- /package/{dist/commands → commands}/lineage.d.ts.map +0 -0
- /package/{dist/commands → commands}/lineage.js +0 -0
- /package/{dist/commands → commands}/lineage.js.map +0 -0
- /package/{dist/commands → commands}/mcp.d.ts +0 -0
- /package/{dist/commands → commands}/mcp.d.ts.map +0 -0
- /package/{dist/commands → commands}/mcp.js +0 -0
- /package/{dist/commands → commands}/mcp.js.map +0 -0
- /package/{dist/commands → commands}/migrate.d.ts +0 -0
- /package/{dist/commands → commands}/migrate.d.ts.map +0 -0
- /package/{dist/commands → commands}/migrate.js +0 -0
- /package/{dist/commands → commands}/migrate.js.map +0 -0
- /package/{dist/commands → commands}/new.d.ts +0 -0
- /package/{dist/commands → commands}/new.d.ts.map +0 -0
- /package/{dist/commands → commands}/new.js +0 -0
- /package/{dist/commands → commands}/new.js.map +0 -0
- /package/{dist/commands → commands}/new.test.d.ts +0 -0
- /package/{dist/commands → commands}/new.test.d.ts.map +0 -0
- /package/{dist/commands → commands}/new.test.js +0 -0
- /package/{dist/commands → commands}/new.test.js.map +0 -0
- /package/{dist/commands → commands}/notebook.d.ts +0 -0
- /package/{dist/commands → commands}/notebook.d.ts.map +0 -0
- /package/{dist/commands → commands}/notebook.js +0 -0
- /package/{dist/commands → commands}/notebook.js.map +0 -0
- /package/{dist/commands → commands}/parse.d.ts +0 -0
- /package/{dist/commands → commands}/parse.d.ts.map +0 -0
- /package/{dist/commands → commands}/parse.js +0 -0
- /package/{dist/commands → commands}/parse.js.map +0 -0
- /package/{dist/commands → commands}/preview.d.ts +0 -0
- /package/{dist/commands → commands}/preview.d.ts.map +0 -0
- /package/{dist/commands → commands}/preview.js +0 -0
- /package/{dist/commands → commands}/preview.js.map +0 -0
- /package/{dist/commands → commands}/schedule.d.ts +0 -0
- /package/{dist/commands → commands}/schedule.d.ts.map +0 -0
- /package/{dist/commands → commands}/schedule.js +0 -0
- /package/{dist/commands → commands}/schedule.js.map +0 -0
- /package/{dist/commands → commands}/semantic.d.ts +0 -0
- /package/{dist/commands → commands}/semantic.d.ts.map +0 -0
- /package/{dist/commands → commands}/semantic.js +0 -0
- /package/{dist/commands → commands}/semantic.js.map +0 -0
- /package/{dist/commands → commands}/serve.d.ts +0 -0
- /package/{dist/commands → commands}/serve.d.ts.map +0 -0
- /package/{dist/commands → commands}/serve.js +0 -0
- /package/{dist/commands → commands}/serve.js.map +0 -0
- /package/{dist/commands → commands}/slack.d.ts +0 -0
- /package/{dist/commands → commands}/slack.d.ts.map +0 -0
- /package/{dist/commands → commands}/slack.js +0 -0
- /package/{dist/commands → commands}/slack.js.map +0 -0
- /package/{dist/commands → commands}/sync.d.ts +0 -0
- /package/{dist/commands → commands}/sync.d.ts.map +0 -0
- /package/{dist/commands → commands}/sync.js +0 -0
- /package/{dist/commands → commands}/sync.js.map +0 -0
- /package/{dist/commands → commands}/sync.test.d.ts +0 -0
- /package/{dist/commands → commands}/sync.test.d.ts.map +0 -0
- /package/{dist/commands → commands}/sync.test.js +0 -0
- /package/{dist/commands → commands}/sync.test.js.map +0 -0
- /package/{dist/commands → commands}/test.d.ts +0 -0
- /package/{dist/commands → commands}/test.d.ts.map +0 -0
- /package/{dist/commands → commands}/test.js +0 -0
- /package/{dist/commands → commands}/test.js.map +0 -0
- /package/{dist/commands → commands}/validate.d.ts +0 -0
- /package/{dist/commands → commands}/validate.d.ts.map +0 -0
- /package/{dist/commands → commands}/validate.js +0 -0
- /package/{dist/commands → commands}/validate.js.map +0 -0
- /package/{dist/commands → commands}/verify.d.ts +0 -0
- /package/{dist/commands → commands}/verify.d.ts.map +0 -0
- /package/{dist/commands → commands}/verify.js +0 -0
- /package/{dist/commands → commands}/verify.js.map +0 -0
- /package/{dist/digest.d.ts → digest.d.ts} +0 -0
- /package/{dist/digest.d.ts.map → digest.d.ts.map} +0 -0
- /package/{dist/digest.js → digest.js} +0 -0
- /package/{dist/digest.js.map → digest.js.map} +0 -0
- /package/{dist/git-service.d.ts → git-service.d.ts} +0 -0
- /package/{dist/git-service.d.ts.map → git-service.d.ts.map} +0 -0
- /package/{dist/git-service.js → git-service.js} +0 -0
- /package/{dist/git-service.js.map → git-service.js.map} +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.d.ts.map → index.d.ts.map} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/index.js.map → index.js.map} +0 -0
- /package/{dist/llm → llm}/index.d.ts +0 -0
- /package/{dist/llm → llm}/providers/claude-agent-sdk.d.ts +0 -0
- /package/{dist/llm → llm}/providers/claude-agent-sdk.d.ts.map +0 -0
- /package/{dist/llm → llm}/providers/claude-agent-sdk.js +0 -0
- /package/{dist/llm → llm}/providers/claude-agent-sdk.js.map +0 -0
- /package/{dist/llm → llm}/providers/claude-code.d.ts +0 -0
- /package/{dist/llm → llm}/providers/claude-code.d.ts.map +0 -0
- /package/{dist/llm → llm}/providers/claude-code.js +0 -0
- /package/{dist/llm → llm}/providers/claude-code.js.map +0 -0
- /package/{dist/llm → llm}/tools.d.ts +0 -0
- /package/{dist/llm → llm}/tools.d.ts.map +0 -0
- /package/{dist/llm → llm}/tools.js +0 -0
- /package/{dist/llm → llm}/tools.js.map +0 -0
- /package/{dist/llm → llm}/types.js +0 -0
- /package/{dist/llm → llm}/types.js.map +0 -0
- /package/{dist/local-runtime.d.ts → local-runtime.d.ts} +0 -0
- /package/{dist/local-runtime.test.d.ts → local-runtime.test.d.ts} +0 -0
- /package/{dist/local-runtime.test.d.ts.map → local-runtime.test.d.ts.map} +0 -0
- /package/{dist/local-runtime.test.js → local-runtime.test.js} +0 -0
- /package/{dist/local-runtime.test.js.map → local-runtime.test.js.map} +0 -0
- /package/{dist/open-browser.d.ts → open-browser.d.ts} +0 -0
- /package/{dist/open-browser.d.ts.map → open-browser.d.ts.map} +0 -0
- /package/{dist/open-browser.js → open-browser.js} +0 -0
- /package/{dist/open-browser.js.map → open-browser.js.map} +0 -0
- /package/{dist/schedule → schedule}/alerts.d.ts +0 -0
- /package/{dist/schedule → schedule}/alerts.d.ts.map +0 -0
- /package/{dist/schedule → schedule}/alerts.js +0 -0
- /package/{dist/schedule → schedule}/alerts.js.map +0 -0
- /package/{dist/schedule → schedule}/discovery.d.ts +0 -0
- /package/{dist/schedule → schedule}/discovery.d.ts.map +0 -0
- /package/{dist/schedule → schedule}/discovery.js +0 -0
- /package/{dist/schedule → schedule}/discovery.js.map +0 -0
- /package/{dist/schedule → schedule}/notifiers/email.d.ts +0 -0
- /package/{dist/schedule → schedule}/notifiers/email.d.ts.map +0 -0
- /package/{dist/schedule → schedule}/notifiers/email.js +0 -0
- /package/{dist/schedule → schedule}/notifiers/email.js.map +0 -0
- /package/{dist/schedule → schedule}/notifiers/file.d.ts +0 -0
- /package/{dist/schedule → schedule}/notifiers/file.d.ts.map +0 -0
- /package/{dist/schedule → schedule}/notifiers/file.js +0 -0
- /package/{dist/schedule → schedule}/notifiers/file.js.map +0 -0
- /package/{dist/schedule → schedule}/notifiers/index.d.ts +0 -0
- /package/{dist/schedule → schedule}/notifiers/index.d.ts.map +0 -0
- /package/{dist/schedule → schedule}/notifiers/index.js +0 -0
- /package/{dist/schedule → schedule}/notifiers/index.js.map +0 -0
- /package/{dist/schedule → schedule}/notifiers/slack.d.ts +0 -0
- /package/{dist/schedule → schedule}/notifiers/slack.d.ts.map +0 -0
- /package/{dist/schedule → schedule}/notifiers/slack.js +0 -0
- /package/{dist/schedule → schedule}/notifiers/slack.js.map +0 -0
- /package/{dist/schedule → schedule}/runs.d.ts +0 -0
- /package/{dist/schedule → schedule}/runs.d.ts.map +0 -0
- /package/{dist/schedule → schedule}/runs.js +0 -0
- /package/{dist/schedule → schedule}/runs.js.map +0 -0
- /package/{dist/schedule → schedule}/types.js +0 -0
- /package/{dist/schedule → schedule}/types.js.map +0 -0
- /package/{dist/semantic-import.test.d.ts → semantic-import.test.d.ts} +0 -0
- /package/{dist/semantic-import.test.d.ts.map → semantic-import.test.d.ts.map} +0 -0
- /package/{dist/semantic-import.test.js → semantic-import.test.js} +0 -0
- /package/{dist/semantic-import.test.js.map → semantic-import.test.js.map} +0 -0
package/apps-api.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP handlers for `/api/apps`, `/api/apps/:id`, `/api/apps/:id/dashboards/:did`,
|
|
3
|
+
* `/api/persona`. Designed to be invoked from `local-runtime.ts`'s request
|
|
4
|
+
* dispatcher — returns `true` if the request was handled, `false` otherwise.
|
|
5
|
+
*/
|
|
6
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
7
|
+
import { type AppDocument } from '@duckcodeailabs/dql-core';
|
|
8
|
+
interface Ctx {
|
|
9
|
+
req: IncomingMessage;
|
|
10
|
+
res: ServerResponse;
|
|
11
|
+
url: URL;
|
|
12
|
+
path: string;
|
|
13
|
+
projectRoot: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function handleAppsApi(ctx: Ctx): Promise<boolean>;
|
|
16
|
+
declare function collectAppsList(projectRoot: string): Array<{
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
domain: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
audience?: string;
|
|
22
|
+
status?: 'ready' | 'empty';
|
|
23
|
+
owners: string[];
|
|
24
|
+
tags: string[];
|
|
25
|
+
members: number;
|
|
26
|
+
roles: number;
|
|
27
|
+
policies: number;
|
|
28
|
+
schedules: number;
|
|
29
|
+
dashboards: Array<{
|
|
30
|
+
id: string;
|
|
31
|
+
title: string;
|
|
32
|
+
}>;
|
|
33
|
+
homepage?: AppDocument['homepage'];
|
|
34
|
+
}>;
|
|
35
|
+
interface AppRecommendationRequest {
|
|
36
|
+
domain?: string;
|
|
37
|
+
tags?: string[];
|
|
38
|
+
purpose?: string;
|
|
39
|
+
audience?: string;
|
|
40
|
+
certifiedOnly?: boolean;
|
|
41
|
+
}
|
|
42
|
+
interface AppCreateRequest {
|
|
43
|
+
name?: string;
|
|
44
|
+
domain?: string;
|
|
45
|
+
purpose?: string;
|
|
46
|
+
audience?: string;
|
|
47
|
+
tags?: string[];
|
|
48
|
+
owners?: string[];
|
|
49
|
+
selectedBlockIds?: string[];
|
|
50
|
+
}
|
|
51
|
+
interface BlockCandidate {
|
|
52
|
+
id: string;
|
|
53
|
+
name: string;
|
|
54
|
+
domain: string;
|
|
55
|
+
status: string;
|
|
56
|
+
owner: string | null;
|
|
57
|
+
tags: string[];
|
|
58
|
+
path: string;
|
|
59
|
+
lastModified: string;
|
|
60
|
+
description: string;
|
|
61
|
+
llmContext: string | null;
|
|
62
|
+
chartType?: string;
|
|
63
|
+
score: number;
|
|
64
|
+
reasons: string[];
|
|
65
|
+
}
|
|
66
|
+
export declare function recommendBlocks(projectRoot: string, input: AppRecommendationRequest): BlockCandidate[];
|
|
67
|
+
export declare function createAppPackage(projectRoot: string, input: AppCreateRequest): {
|
|
68
|
+
ok: true;
|
|
69
|
+
app: ReturnType<typeof collectAppsList>[number];
|
|
70
|
+
paths: string[];
|
|
71
|
+
dashboardId: string;
|
|
72
|
+
} | {
|
|
73
|
+
ok: false;
|
|
74
|
+
error: string;
|
|
75
|
+
};
|
|
76
|
+
export {};
|
|
77
|
+
//# sourceMappingURL=apps-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps-api.d.ts","sourceRoot":"","sources":["../src/apps-api.ts"],"names":[],"mappings":"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"}
|
package/apps-api.js
ADDED
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP handlers for `/api/apps`, `/api/apps/:id`, `/api/apps/:id/dashboards/:did`,
|
|
3
|
+
* `/api/persona`. Designed to be invoked from `local-runtime.ts`'s request
|
|
4
|
+
* dispatcher — returns `true` if the request was handled, `false` otherwise.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs';
|
|
7
|
+
import { join, dirname } from 'node:path';
|
|
8
|
+
import { loadAppDocument, findAppDocuments, loadDashboardDocument, findDashboardsForApp, parseAppDocument, parseDashboardDocument, suggestAppId, } from '@duckcodeailabs/dql-core';
|
|
9
|
+
import { defaultPersonaRegistry, personaFromMember, } from '@duckcodeailabs/dql-project';
|
|
10
|
+
export async function handleAppsApi(ctx) {
|
|
11
|
+
const { req, res, path, projectRoot } = ctx;
|
|
12
|
+
// ── Apps ────────────────────────────────────────────────────────────────
|
|
13
|
+
if (req.method === 'GET' && path === '/api/apps') {
|
|
14
|
+
const apps = collectAppsList(projectRoot);
|
|
15
|
+
sendJson(res, 200, { apps });
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
if (req.method === 'POST' && path === '/api/apps/recommend-blocks') {
|
|
19
|
+
try {
|
|
20
|
+
const body = await readJson(req);
|
|
21
|
+
sendJson(res, 200, { blocks: recommendBlocks(projectRoot, body) });
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
sendJson(res, 500, { error: err.message });
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (req.method === 'POST' && path === '/api/apps') {
|
|
29
|
+
try {
|
|
30
|
+
const body = await readJson(req);
|
|
31
|
+
const result = createAppPackage(projectRoot, body);
|
|
32
|
+
if (!result.ok) {
|
|
33
|
+
sendJson(res, 400, { error: result.error });
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
sendJson(res, 201, result);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
sendJson(res, 500, { error: err.message });
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
// /api/apps/:id — single App with dashboards summary
|
|
44
|
+
let m = path.match(/^\/api\/apps\/([^/]+)$/);
|
|
45
|
+
if (m && req.method === 'GET') {
|
|
46
|
+
const id = m[1];
|
|
47
|
+
const result = loadAppById(projectRoot, id);
|
|
48
|
+
if (!result) {
|
|
49
|
+
sendJson(res, 404, { error: `App "${id}" not found` });
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
sendJson(res, 200, result);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
// /api/apps/:id/dashboards
|
|
56
|
+
m = path.match(/^\/api\/apps\/([^/]+)\/dashboards$/);
|
|
57
|
+
if (m && req.method === 'GET') {
|
|
58
|
+
const id = m[1];
|
|
59
|
+
const dashboards = listDashboardsFor(projectRoot, id);
|
|
60
|
+
if (dashboards === null) {
|
|
61
|
+
sendJson(res, 404, { error: `App "${id}" not found` });
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
sendJson(res, 200, { dashboards });
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
// /api/apps/:id/dashboards/:did
|
|
68
|
+
m = path.match(/^\/api\/apps\/([^/]+)\/dashboards\/([^/]+)$/);
|
|
69
|
+
if (m) {
|
|
70
|
+
const id = m[1];
|
|
71
|
+
const did = m[2];
|
|
72
|
+
if (req.method === 'GET') {
|
|
73
|
+
const result = loadDashboardForApp(projectRoot, id, did);
|
|
74
|
+
if (!result) {
|
|
75
|
+
sendJson(res, 404, { error: `Dashboard "${did}" not found in app "${id}"` });
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
sendJson(res, 200, result);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (req.method === 'PUT' || req.method === 'POST') {
|
|
82
|
+
try {
|
|
83
|
+
const body = await readJson(req);
|
|
84
|
+
const written = await writeDashboard(projectRoot, id, did, body);
|
|
85
|
+
if (!written.ok) {
|
|
86
|
+
sendJson(res, 400, { error: written.error });
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
sendJson(res, 200, { ok: true, path: written.path });
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
sendJson(res, 500, { error: err.message });
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// ── Persona ────────────────────────────────────────────────────────────
|
|
98
|
+
if (path === '/api/persona') {
|
|
99
|
+
if (req.method === 'GET') {
|
|
100
|
+
sendJson(res, 200, { persona: defaultPersonaRegistry.active });
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
if (req.method === 'DELETE') {
|
|
104
|
+
defaultPersonaRegistry.clear();
|
|
105
|
+
sendJson(res, 200, { persona: null });
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
if (req.method === 'POST') {
|
|
109
|
+
try {
|
|
110
|
+
const body = await readJson(req);
|
|
111
|
+
const userId = typeof body.userId === 'string' ? body.userId : null;
|
|
112
|
+
const appId = typeof body.appId === 'string' ? body.appId : null;
|
|
113
|
+
if (!userId) {
|
|
114
|
+
sendJson(res, 400, { error: 'userId is required' });
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
const persona = activatePersona(projectRoot, userId, appId);
|
|
118
|
+
if (!persona) {
|
|
119
|
+
sendJson(res, 404, { error: 'No App member matches this userId' });
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
sendJson(res, 200, { persona });
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
sendJson(res, 500, { error: err.message });
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
// ---- Helpers ----
|
|
133
|
+
function collectAppsList(projectRoot) {
|
|
134
|
+
const out = [];
|
|
135
|
+
for (const p of findAppDocuments(projectRoot)) {
|
|
136
|
+
const { document } = loadAppDocument(p);
|
|
137
|
+
if (!document)
|
|
138
|
+
continue;
|
|
139
|
+
const appDir = p.slice(0, -'/dql.app.json'.length);
|
|
140
|
+
const dashboards = [];
|
|
141
|
+
for (const d of findDashboardsForApp(appDir)) {
|
|
142
|
+
const { document: dd } = loadDashboardDocument(d);
|
|
143
|
+
if (dd)
|
|
144
|
+
dashboards.push({ id: dd.id, title: dd.metadata.title });
|
|
145
|
+
}
|
|
146
|
+
out.push({
|
|
147
|
+
id: document.id,
|
|
148
|
+
name: document.name,
|
|
149
|
+
domain: document.domain,
|
|
150
|
+
description: document.description,
|
|
151
|
+
audience: audienceFromTags(document.tags ?? []),
|
|
152
|
+
status: dashboards.length > 0 ? 'ready' : 'empty',
|
|
153
|
+
owners: document.owners,
|
|
154
|
+
tags: document.tags ?? [],
|
|
155
|
+
members: document.members.length,
|
|
156
|
+
roles: document.roles.length,
|
|
157
|
+
policies: document.policies.length,
|
|
158
|
+
schedules: (document.schedules ?? []).length,
|
|
159
|
+
dashboards,
|
|
160
|
+
homepage: document.homepage,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return out.sort((a, b) => a.name.localeCompare(b.name));
|
|
164
|
+
}
|
|
165
|
+
export function recommendBlocks(projectRoot, input) {
|
|
166
|
+
const domain = cleanString(input.domain).toLowerCase();
|
|
167
|
+
const tags = normalizeTags(input.tags ?? []);
|
|
168
|
+
const text = [input.purpose, input.audience, ...(input.tags ?? [])].map((v) => cleanString(v).toLowerCase()).filter(Boolean);
|
|
169
|
+
const certifiedOnly = input.certifiedOnly !== false;
|
|
170
|
+
const hasCriteria = Boolean(domain || tags.length > 0 || text.length > 0);
|
|
171
|
+
return collectBlockCandidates(projectRoot)
|
|
172
|
+
.map((block) => {
|
|
173
|
+
let score = 0;
|
|
174
|
+
let criteriaScore = 0;
|
|
175
|
+
const reasons = [];
|
|
176
|
+
if (domain && block.domain.toLowerCase() === domain) {
|
|
177
|
+
score += 100;
|
|
178
|
+
criteriaScore += 100;
|
|
179
|
+
reasons.push('domain match');
|
|
180
|
+
}
|
|
181
|
+
if (certifiedOnly && block.status !== 'certified')
|
|
182
|
+
return null;
|
|
183
|
+
if (block.status === 'certified') {
|
|
184
|
+
score += 30;
|
|
185
|
+
reasons.push('certified');
|
|
186
|
+
}
|
|
187
|
+
const overlap = block.tags.filter((tag) => tags.includes(tag.toLowerCase()));
|
|
188
|
+
if (overlap.length > 0) {
|
|
189
|
+
score += overlap.length * 12;
|
|
190
|
+
criteriaScore += overlap.length * 12;
|
|
191
|
+
reasons.push(`tag match: ${overlap.join(', ')}`);
|
|
192
|
+
}
|
|
193
|
+
const haystack = [block.name, block.description, block.owner ?? '', block.llmContext ?? '', ...block.tags]
|
|
194
|
+
.join(' ')
|
|
195
|
+
.toLowerCase();
|
|
196
|
+
const textHits = text.filter((term) => term && haystack.includes(term));
|
|
197
|
+
if (textHits.length > 0) {
|
|
198
|
+
score += textHits.length * 6;
|
|
199
|
+
criteriaScore += textHits.length * 6;
|
|
200
|
+
reasons.push('context match');
|
|
201
|
+
}
|
|
202
|
+
if (score === 0 && !domain && tags.length === 0 && !certifiedOnly)
|
|
203
|
+
score = 1;
|
|
204
|
+
if (hasCriteria && criteriaScore === 0)
|
|
205
|
+
return null;
|
|
206
|
+
if (score === 0)
|
|
207
|
+
return null;
|
|
208
|
+
return { ...block, score, reasons };
|
|
209
|
+
})
|
|
210
|
+
.filter((block) => Boolean(block))
|
|
211
|
+
.sort((a, b) => b.score - a.score || new Date(b.lastModified).getTime() - new Date(a.lastModified).getTime())
|
|
212
|
+
.slice(0, 50);
|
|
213
|
+
}
|
|
214
|
+
export function createAppPackage(projectRoot, input) {
|
|
215
|
+
const name = cleanString(input.name);
|
|
216
|
+
const domain = cleanString(input.domain);
|
|
217
|
+
if (!name)
|
|
218
|
+
return { ok: false, error: 'name is required' };
|
|
219
|
+
if (!domain)
|
|
220
|
+
return { ok: false, error: 'domain is required' };
|
|
221
|
+
const id = suggestAppId(name);
|
|
222
|
+
const appDir = join(projectRoot, 'apps', id);
|
|
223
|
+
if (existsSync(appDir))
|
|
224
|
+
return { ok: false, error: `App already exists: ${id}` };
|
|
225
|
+
const owner = cleanString(input.owners?.[0]) || `${process.env.USER ?? 'owner'}@local`;
|
|
226
|
+
const audience = cleanString(input.audience);
|
|
227
|
+
const tags = normalizeTags([...(input.tags ?? []), audience ? `audience:${slugify(audience)}` : '']);
|
|
228
|
+
const selectedIds = Array.from(new Set((input.selectedBlockIds ?? []).map(cleanString).filter(Boolean)));
|
|
229
|
+
const blocks = collectBlockCandidates(projectRoot);
|
|
230
|
+
const selectedBlocks = selectedIds
|
|
231
|
+
.map((blockId) => blocks.find((block) => block.id === blockId || block.name === blockId))
|
|
232
|
+
.filter((block) => Boolean(block));
|
|
233
|
+
const app = {
|
|
234
|
+
version: 1,
|
|
235
|
+
id,
|
|
236
|
+
name,
|
|
237
|
+
description: cleanString(input.purpose) || `${name} consumption surface for ${domain}`,
|
|
238
|
+
domain,
|
|
239
|
+
owners: [owner],
|
|
240
|
+
tags,
|
|
241
|
+
members: [
|
|
242
|
+
{ userId: owner, displayName: owner, roles: ['owner', 'analyst'] },
|
|
243
|
+
],
|
|
244
|
+
roles: [
|
|
245
|
+
{ id: 'owner', displayName: 'Owner', description: 'Full access to dashboards and App configuration.' },
|
|
246
|
+
{ id: 'analyst', displayName: 'Analyst', description: 'Can execute dashboards and review generated drafts.' },
|
|
247
|
+
{ id: 'viewer', displayName: 'Viewer', description: 'Read-only access to certified dashboard consumption.' },
|
|
248
|
+
],
|
|
249
|
+
policies: [
|
|
250
|
+
{
|
|
251
|
+
id: 'viewers-read',
|
|
252
|
+
domain,
|
|
253
|
+
minClassification: 'internal',
|
|
254
|
+
allowedRoles: ['viewer', 'analyst', 'owner'],
|
|
255
|
+
accessLevel: 'read',
|
|
256
|
+
enabled: true,
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
id: 'analyst-execute',
|
|
260
|
+
domain,
|
|
261
|
+
minClassification: 'internal',
|
|
262
|
+
allowedRoles: ['analyst', 'owner'],
|
|
263
|
+
accessLevel: 'execute',
|
|
264
|
+
enabled: true,
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
id: 'owner-admin',
|
|
268
|
+
domain,
|
|
269
|
+
minClassification: 'restricted',
|
|
270
|
+
allowedRoles: ['owner'],
|
|
271
|
+
accessLevel: 'admin',
|
|
272
|
+
enabled: true,
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
rlsBindings: [],
|
|
276
|
+
schedules: [],
|
|
277
|
+
homepage: { type: 'dashboard', id: 'overview' },
|
|
278
|
+
};
|
|
279
|
+
const dashboard = {
|
|
280
|
+
version: 1,
|
|
281
|
+
id: 'overview',
|
|
282
|
+
metadata: {
|
|
283
|
+
title: `${name} Overview`,
|
|
284
|
+
description: cleanString(input.purpose) || `Starter dashboard for ${name}`,
|
|
285
|
+
domain,
|
|
286
|
+
tags,
|
|
287
|
+
},
|
|
288
|
+
layout: {
|
|
289
|
+
kind: 'grid',
|
|
290
|
+
cols: 12,
|
|
291
|
+
rowHeight: 80,
|
|
292
|
+
items: buildDashboardItems(selectedBlocks),
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
const paths = [
|
|
296
|
+
join(appDir, 'dql.app.json'),
|
|
297
|
+
join(appDir, 'README.md'),
|
|
298
|
+
join(appDir, 'dashboards', 'overview.dqld'),
|
|
299
|
+
join(appDir, 'notebooks'),
|
|
300
|
+
join(appDir, 'drafts'),
|
|
301
|
+
];
|
|
302
|
+
mkdirSync(join(appDir, 'dashboards'), { recursive: true });
|
|
303
|
+
mkdirSync(join(appDir, 'notebooks'), { recursive: true });
|
|
304
|
+
mkdirSync(join(appDir, 'drafts'), { recursive: true });
|
|
305
|
+
writeFileSync(join(appDir, 'dql.app.json'), JSON.stringify(app, null, 2) + '\n', 'utf-8');
|
|
306
|
+
writeFileSync(join(appDir, 'dashboards', 'overview.dqld'), JSON.stringify(dashboard, null, 2) + '\n', 'utf-8');
|
|
307
|
+
writeFileSync(join(appDir, 'README.md'), appReadme(app, audience, selectedBlocks), 'utf-8');
|
|
308
|
+
const created = collectAppsList(projectRoot).find((entry) => entry.id === id);
|
|
309
|
+
if (!created)
|
|
310
|
+
return { ok: false, error: `App was written but could not be reloaded: ${id}` };
|
|
311
|
+
return {
|
|
312
|
+
ok: true,
|
|
313
|
+
app: created,
|
|
314
|
+
paths: paths.map((path) => path.startsWith(projectRoot) ? path.slice(projectRoot.length + 1) : path),
|
|
315
|
+
dashboardId: 'overview',
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function buildDashboardItems(blocks) {
|
|
319
|
+
let x = 0;
|
|
320
|
+
let y = 0;
|
|
321
|
+
let rowH = 0;
|
|
322
|
+
return [...blocks]
|
|
323
|
+
.sort((a, b) => vizRank(a.chartType) - vizRank(b.chartType))
|
|
324
|
+
.map((block, index) => {
|
|
325
|
+
const chartType = normalizeVizType(block.chartType);
|
|
326
|
+
const size = tileSize(chartType);
|
|
327
|
+
if (x + size.w > 12) {
|
|
328
|
+
x = 0;
|
|
329
|
+
y += rowH || size.h;
|
|
330
|
+
rowH = 0;
|
|
331
|
+
}
|
|
332
|
+
const item = dashboardItemForBlock(block, chartType, x, y, size, index);
|
|
333
|
+
x += size.w;
|
|
334
|
+
rowH = Math.max(rowH, size.h);
|
|
335
|
+
return item;
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
function dashboardItemForBlock(block, chartType, x, y, size, index) {
|
|
339
|
+
return {
|
|
340
|
+
i: slugify(block.name) || `tile-${index + 1}`,
|
|
341
|
+
x,
|
|
342
|
+
y,
|
|
343
|
+
w: size.w,
|
|
344
|
+
h: size.h,
|
|
345
|
+
block: { blockId: block.name },
|
|
346
|
+
viz: { type: chartType },
|
|
347
|
+
title: block.name,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function vizRank(chartType) {
|
|
351
|
+
const normalized = normalizeVizType(chartType);
|
|
352
|
+
if (normalized === 'single_value' || normalized === 'kpi')
|
|
353
|
+
return 0;
|
|
354
|
+
if (normalized === 'line' || normalized === 'area')
|
|
355
|
+
return 1;
|
|
356
|
+
if (normalized === 'bar' || normalized === 'pie' || normalized === 'funnel' || normalized === 'map')
|
|
357
|
+
return 2;
|
|
358
|
+
return 3;
|
|
359
|
+
}
|
|
360
|
+
function tileSize(chartType) {
|
|
361
|
+
if (chartType === 'single_value' || chartType === 'kpi')
|
|
362
|
+
return { w: 3, h: 2 };
|
|
363
|
+
if (chartType === 'table' || chartType === 'pivot')
|
|
364
|
+
return { w: 6, h: 4 };
|
|
365
|
+
return { w: 6, h: 3 };
|
|
366
|
+
}
|
|
367
|
+
function normalizeVizType(chartType) {
|
|
368
|
+
const normalized = (chartType ?? 'table').toLowerCase().replace(/-/g, '_');
|
|
369
|
+
if (normalized === 'single' || normalized === 'single_value')
|
|
370
|
+
return 'single_value';
|
|
371
|
+
if (normalized === 'kpi')
|
|
372
|
+
return 'kpi';
|
|
373
|
+
if (normalized === 'line')
|
|
374
|
+
return 'line';
|
|
375
|
+
if (normalized === 'bar')
|
|
376
|
+
return 'bar';
|
|
377
|
+
if (normalized === 'area')
|
|
378
|
+
return 'area';
|
|
379
|
+
if (normalized === 'pie')
|
|
380
|
+
return 'pie';
|
|
381
|
+
if (normalized === 'pivot')
|
|
382
|
+
return 'pivot';
|
|
383
|
+
if (normalized === 'map')
|
|
384
|
+
return 'map';
|
|
385
|
+
if (normalized === 'funnel')
|
|
386
|
+
return 'funnel';
|
|
387
|
+
return 'table';
|
|
388
|
+
}
|
|
389
|
+
function appReadme(app, audience, blocks) {
|
|
390
|
+
return [
|
|
391
|
+
`# ${app.name}`,
|
|
392
|
+
'',
|
|
393
|
+
app.description ?? '',
|
|
394
|
+
'',
|
|
395
|
+
`- Domain: ${app.domain}`,
|
|
396
|
+
`- Audience: ${audience || 'not specified'}`,
|
|
397
|
+
`- Owners: ${app.owners.join(', ')}`,
|
|
398
|
+
`- Starter dashboard: dashboards/overview.dqld`,
|
|
399
|
+
'',
|
|
400
|
+
'## Selected Certified Blocks',
|
|
401
|
+
'',
|
|
402
|
+
...(blocks.length > 0
|
|
403
|
+
? blocks.map((block) => `- ${block.name} (${block.domain}, ${block.status}) - ${block.path}`)
|
|
404
|
+
: ['No blocks selected yet. Add certified blocks from the Apps Command Center.']),
|
|
405
|
+
'',
|
|
406
|
+
'## Governance',
|
|
407
|
+
'',
|
|
408
|
+
'This OSS App uses local persona switching with owner, analyst, and viewer roles. Real authentication and SSO are intentionally outside OSS scope.',
|
|
409
|
+
'',
|
|
410
|
+
].join('\n');
|
|
411
|
+
}
|
|
412
|
+
function collectBlockCandidates(projectRoot) {
|
|
413
|
+
const blocksDir = join(projectRoot, 'blocks');
|
|
414
|
+
const blocks = [];
|
|
415
|
+
if (!existsSync(blocksDir))
|
|
416
|
+
return blocks;
|
|
417
|
+
const scanDir = (dir) => {
|
|
418
|
+
for (const entry of readdirSyncSafe(dir)) {
|
|
419
|
+
const filePath = join(dir, entry.name);
|
|
420
|
+
if (entry.isDirectory()) {
|
|
421
|
+
scanDir(filePath);
|
|
422
|
+
}
|
|
423
|
+
else if (entry.isFile() && entry.name.endsWith('.dql')) {
|
|
424
|
+
try {
|
|
425
|
+
const source = readFileSync(filePath, 'utf-8');
|
|
426
|
+
const stat = statSyncSafe(filePath);
|
|
427
|
+
const name = matchString(source, /block\s+"([^"]+)"/) ?? entry.name.replace(/\.dql$/, '');
|
|
428
|
+
const tags = matchArray(source, /tags\s*=\s*\[([^\]]*)\]/);
|
|
429
|
+
blocks.push({
|
|
430
|
+
id: name,
|
|
431
|
+
name,
|
|
432
|
+
domain: matchString(source, /domain\s*=\s*"([^"]+)"/) ?? 'uncategorized',
|
|
433
|
+
status: matchString(source, /status\s*=\s*"([^"]+)"/) ?? 'draft',
|
|
434
|
+
owner: matchString(source, /owner\s*=\s*"([^"]+)"/),
|
|
435
|
+
tags,
|
|
436
|
+
path: filePath.slice(projectRoot.length + 1),
|
|
437
|
+
lastModified: stat?.mtime.toISOString() ?? new Date(0).toISOString(),
|
|
438
|
+
description: matchString(source, /description\s*=\s*"((?:[^"\\]|\\.)*)"/) ?? '',
|
|
439
|
+
llmContext: matchString(source, /llmContext\s*=\s*"((?:[^"\\]|\\.)*)"/),
|
|
440
|
+
chartType: matchString(source, /chart\s*=\s*"([^"]+)"/) ?? matchString(source, /chart\.(\w+)\s*\(/) ?? undefined,
|
|
441
|
+
score: 0,
|
|
442
|
+
reasons: [],
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
catch {
|
|
446
|
+
// skip unreadable block
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
scanDir(blocksDir);
|
|
452
|
+
return blocks;
|
|
453
|
+
}
|
|
454
|
+
function readdirSyncSafe(dir) {
|
|
455
|
+
try {
|
|
456
|
+
return readdirSync(dir, { withFileTypes: true });
|
|
457
|
+
}
|
|
458
|
+
catch {
|
|
459
|
+
return [];
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
function statSyncSafe(path) {
|
|
463
|
+
try {
|
|
464
|
+
return statSync(path);
|
|
465
|
+
}
|
|
466
|
+
catch {
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function matchString(source, regex) {
|
|
471
|
+
const match = regex.exec(source);
|
|
472
|
+
return match?.[1]?.replace(/\\"/g, '"').trim() || null;
|
|
473
|
+
}
|
|
474
|
+
function matchArray(source, regex) {
|
|
475
|
+
const match = regex.exec(source);
|
|
476
|
+
if (!match)
|
|
477
|
+
return [];
|
|
478
|
+
return match[1]
|
|
479
|
+
.split(',')
|
|
480
|
+
.map((item) => item.trim().replace(/^"|"$/g, ''))
|
|
481
|
+
.filter(Boolean);
|
|
482
|
+
}
|
|
483
|
+
function cleanString(value) {
|
|
484
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
485
|
+
}
|
|
486
|
+
function normalizeTags(values) {
|
|
487
|
+
return Array.from(new Set(values.map((value) => cleanString(value)).filter(Boolean)));
|
|
488
|
+
}
|
|
489
|
+
function slugify(value) {
|
|
490
|
+
return value
|
|
491
|
+
.toLowerCase()
|
|
492
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
493
|
+
.replace(/^-+|-+$/g, '');
|
|
494
|
+
}
|
|
495
|
+
function audienceFromTags(tags) {
|
|
496
|
+
const tag = tags.find((value) => value.startsWith('audience:'));
|
|
497
|
+
if (!tag)
|
|
498
|
+
return undefined;
|
|
499
|
+
return tag.slice('audience:'.length).replace(/-/g, ' ');
|
|
500
|
+
}
|
|
501
|
+
function loadAppById(projectRoot, id) {
|
|
502
|
+
for (const p of findAppDocuments(projectRoot)) {
|
|
503
|
+
const { document } = loadAppDocument(p);
|
|
504
|
+
if (!document || document.id !== id)
|
|
505
|
+
continue;
|
|
506
|
+
const appDir = p.slice(0, -'/dql.app.json'.length);
|
|
507
|
+
const dashboards = [];
|
|
508
|
+
for (const d of findDashboardsForApp(appDir)) {
|
|
509
|
+
const { document: dd } = loadDashboardDocument(d);
|
|
510
|
+
if (dd) {
|
|
511
|
+
dashboards.push({
|
|
512
|
+
id: dd.id,
|
|
513
|
+
title: dd.metadata.title,
|
|
514
|
+
description: dd.metadata.description,
|
|
515
|
+
itemCount: dd.layout.items.length,
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return { app: document, dashboards };
|
|
520
|
+
}
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
523
|
+
function listDashboardsFor(projectRoot, id) {
|
|
524
|
+
const result = loadAppById(projectRoot, id);
|
|
525
|
+
return result?.dashboards ?? null;
|
|
526
|
+
}
|
|
527
|
+
function loadDashboardForApp(projectRoot, appId, dashboardId) {
|
|
528
|
+
for (const p of findAppDocuments(projectRoot)) {
|
|
529
|
+
const { document } = loadAppDocument(p);
|
|
530
|
+
if (!document || document.id !== appId)
|
|
531
|
+
continue;
|
|
532
|
+
const appDir = p.slice(0, -'/dql.app.json'.length);
|
|
533
|
+
for (const d of findDashboardsForApp(appDir)) {
|
|
534
|
+
const { document: dd } = loadDashboardDocument(d);
|
|
535
|
+
if (dd && dd.id === dashboardId) {
|
|
536
|
+
return { app: document, dashboard: dd };
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
async function writeDashboard(projectRoot, appId, dashboardId, payload) {
|
|
543
|
+
// Validate against the dashboard schema before touching disk.
|
|
544
|
+
const { document, errors } = parseDashboardDocument(JSON.stringify(payload), '<incoming>');
|
|
545
|
+
if (!document) {
|
|
546
|
+
return { ok: false, error: errors.map((e) => e.message).join('; ') };
|
|
547
|
+
}
|
|
548
|
+
if (document.id !== dashboardId) {
|
|
549
|
+
return { ok: false, error: `dashboard.id (${document.id}) does not match URL :did (${dashboardId})` };
|
|
550
|
+
}
|
|
551
|
+
// Confirm the App exists.
|
|
552
|
+
const appDir = join(projectRoot, 'apps', appId);
|
|
553
|
+
if (!existsSync(join(appDir, 'dql.app.json'))) {
|
|
554
|
+
return { ok: false, error: `App "${appId}" not found at ${appDir}` };
|
|
555
|
+
}
|
|
556
|
+
const dashboardPath = join(appDir, 'dashboards', `${dashboardId}.dqld`);
|
|
557
|
+
mkdirSync(dirname(dashboardPath), { recursive: true });
|
|
558
|
+
writeFileSync(dashboardPath, JSON.stringify(document, null, 2) + '\n', 'utf-8');
|
|
559
|
+
return { ok: true, path: dashboardPath };
|
|
560
|
+
}
|
|
561
|
+
function activatePersona(projectRoot, userId, appId) {
|
|
562
|
+
// If an App id is provided, scope the persona to it.
|
|
563
|
+
if (appId) {
|
|
564
|
+
for (const p of findAppDocuments(projectRoot)) {
|
|
565
|
+
const { document } = loadAppDocument(p);
|
|
566
|
+
if (!document || document.id !== appId)
|
|
567
|
+
continue;
|
|
568
|
+
return defaultPersonaRegistry.setFromApp(document, userId);
|
|
569
|
+
}
|
|
570
|
+
return null;
|
|
571
|
+
}
|
|
572
|
+
// Otherwise pick the first App that contains the user.
|
|
573
|
+
for (const p of findAppDocuments(projectRoot)) {
|
|
574
|
+
const { document } = loadAppDocument(p);
|
|
575
|
+
if (!document)
|
|
576
|
+
continue;
|
|
577
|
+
const member = document.members.find((m) => m.userId === userId);
|
|
578
|
+
if (member) {
|
|
579
|
+
const persona = personaFromMember(document, member);
|
|
580
|
+
defaultPersonaRegistry.set(persona);
|
|
581
|
+
return persona;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return null;
|
|
585
|
+
}
|
|
586
|
+
// ---- IO utilities ----
|
|
587
|
+
function sendJson(res, status, body) {
|
|
588
|
+
res.writeHead(status, { 'Content-Type': 'application/json; charset=utf-8' });
|
|
589
|
+
res.end(JSON.stringify(body));
|
|
590
|
+
}
|
|
591
|
+
async function readJson(req) {
|
|
592
|
+
return new Promise((resolve, reject) => {
|
|
593
|
+
const chunks = [];
|
|
594
|
+
req.on('data', (c) => chunks.push(c));
|
|
595
|
+
req.on('end', () => {
|
|
596
|
+
const raw = Buffer.concat(chunks).toString('utf-8');
|
|
597
|
+
if (!raw)
|
|
598
|
+
return resolve({});
|
|
599
|
+
try {
|
|
600
|
+
resolve(JSON.parse(raw));
|
|
601
|
+
}
|
|
602
|
+
catch (err) {
|
|
603
|
+
reject(err);
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
req.on('error', reject);
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
// reference unused parseAppDocument/readFileSync to keep import stable for forward use
|
|
610
|
+
void parseAppDocument;
|
|
611
|
+
void readFileSync;
|
|
612
|
+
//# sourceMappingURL=apps-api.js.map
|