@databrainhq/mcp-server 0.3.0-rc.8 → 0.3.0-rc.9
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/README.md +76 -9
- package/dist/apps/server.js +3 -3
- package/dist/apps/stdio.js +4 -4
- package/dist/{chunk-XFT7JMYY.js → chunk-6O25PXL4.js} +3 -3
- package/dist/{chunk-RDMVO56D.js → chunk-H3SI2MAU.js} +13 -2
- package/dist/chunk-H3SI2MAU.js.map +1 -0
- package/dist/{chunk-3APZIQME.js → chunk-N6SJY5JO.js} +2 -2
- package/dist/{chunk-B7HJRMR2.js → chunk-VK6XPPBT.js} +333 -215
- package/dist/chunk-VK6XPPBT.js.map +1 -0
- package/dist/{chunk-3GF7WSKK.js → chunk-Z3ZHN4UW.js} +31 -5
- package/dist/chunk-Z3ZHN4UW.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/main-SM27XA4U.js +842 -0
- package/dist/main-SM27XA4U.js.map +1 -0
- package/dist/{test-only-TJ3DQUYW.js → test-only-K7QTSVO4.js} +7 -6
- package/dist/test-only-K7QTSVO4.js.map +1 -0
- package/package.json +2 -1
- package/dist/chunk-3GF7WSKK.js.map +0 -1
- package/dist/chunk-B7HJRMR2.js.map +0 -1
- package/dist/chunk-RDMVO56D.js.map +0 -1
- package/dist/main-WLOXOKFS.js +0 -477
- package/dist/main-WLOXOKFS.js.map +0 -1
- package/dist/test-only-TJ3DQUYW.js.map +0 -1
- /package/dist/{chunk-XFT7JMYY.js.map → chunk-6O25PXL4.js.map} +0 -0
- /package/dist/{chunk-3APZIQME.js.map → chunk-N6SJY5JO.js.map} +0 -0
package/README.md
CHANGED
|
@@ -13,13 +13,79 @@ Works with Codex, Claude, Cursor, Windsurf, and any MCP-compatible client.
|
|
|
13
13
|
|
|
14
14
|
## Setup (2 minutes)
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
There are two ways in. Pick one.
|
|
17
|
+
|
|
18
|
+
| | Best for | You need |
|
|
19
|
+
|---|---|---|
|
|
20
|
+
| **A. Hosted connector** | Claude, ChatGPT, Cursor, VS Code, Claude Code | Your Databrain sign-in. Nothing to install. |
|
|
21
|
+
| **B. Local server + service token** | Codex, Windsurf, any stdio client, self-hosted Databrain, CI | A service token in the MCP config |
|
|
22
|
+
|
|
23
|
+
With A you act as yourself: calls run in the workspaces you approve, with your role in each, and the audit log shows your name. With B calls run as the organization (`actor=system`).
|
|
24
|
+
|
|
25
|
+
### A. Hosted connector
|
|
26
|
+
|
|
27
|
+
Server URL: **`https://mcp.usedatabrain.com/mcp`** (beta: `https://mcp.beta.usedatabrain.com/mcp`).
|
|
28
|
+
Your AI app opens a Databrain sign-in page, you pick one or more workspaces (or "All workspaces I can access") and click Allow. No token to copy.
|
|
29
|
+
|
|
30
|
+
When you approve more than one workspace, the AI names the workspace on each call (`workspace` or `workspaceName`); `whoami` lists the ones you approved. With "All workspaces I can access", workspaces you get later are included, and `create_workspace` can make a new one if your role allows it.
|
|
31
|
+
|
|
32
|
+
<details>
|
|
33
|
+
<summary><b>Claude (claude.ai and Claude Desktop)</b></summary>
|
|
34
|
+
|
|
35
|
+
Settings > Connectors > **Add custom connector**. Name `Databrain`, URL `https://mcp.usedatabrain.com/mcp`. Click **Connect** and sign in. Custom connectors need a paid Claude plan.
|
|
36
|
+
</details>
|
|
37
|
+
|
|
38
|
+
<details>
|
|
39
|
+
<summary><b>Claude Code</b></summary>
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
claude mcp add --transport http databrain https://mcp.usedatabrain.com/mcp
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Then run `/mcp` in Claude Code, pick `databrain` and sign in.
|
|
46
|
+
</details>
|
|
47
|
+
|
|
48
|
+
<details>
|
|
49
|
+
<summary><b>Cursor</b></summary>
|
|
50
|
+
|
|
51
|
+
[](https://cursor.com/install-mcp?name=databrain&config=eyJ1cmwiOiJodHRwczovL21jcC51c2VkYXRhYnJhaW4uY29tL21jcCJ9)
|
|
52
|
+
|
|
53
|
+
Or add to `~/.cursor/mcp.json`:
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{ "mcpServers": { "databrain": { "url": "https://mcp.usedatabrain.com/mcp" } } }
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Cursor signs you in with OAuth the first time a tool runs.
|
|
60
|
+
</details>
|
|
61
|
+
|
|
62
|
+
<details>
|
|
63
|
+
<summary><b>VS Code (GitHub Copilot agent mode)</b></summary>
|
|
64
|
+
|
|
65
|
+
[Install in VS Code](https://insiders.vscode.dev/redirect/mcp/install?name=databrain&config=%7B%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fmcp.usedatabrain.com%2Fmcp%22%7D), or:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
code --add-mcp '{"name":"databrain","type":"http","url":"https://mcp.usedatabrain.com/mcp"}'
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
VS Code asks you to sign in to Databrain when the server starts.
|
|
72
|
+
</details>
|
|
73
|
+
|
|
74
|
+
<details>
|
|
75
|
+
<summary><b>ChatGPT</b></summary>
|
|
76
|
+
|
|
77
|
+
Once Databrain is in the ChatGPT directory, search for **Databrain** and connect. Until then, a workspace admin can add it as a custom MCP connection with the URL `https://mcp.usedatabrain.com/mcp` and OAuth ([OpenAI guide](https://developers.openai.com/api/docs/guides/custom-mcp-server)).
|
|
78
|
+
</details>
|
|
79
|
+
|
|
80
|
+
### B. Local server with a service token
|
|
81
|
+
|
|
82
|
+
#### 1. Get your Service Token
|
|
17
83
|
|
|
18
84
|
1. Log in to your Databrain instance (cloud or self-hosted)
|
|
19
85
|
2. Go to **Settings → Service Tokens**
|
|
20
86
|
3. Create a new token and copy it
|
|
21
87
|
|
|
22
|
-
|
|
88
|
+
#### 2. Add to your AI client
|
|
23
89
|
|
|
24
90
|
> **Self-hosted?** Also set `DATABRAIN_API_URL` in the `env` block — see [Self-hosted Databrain](#self-hosted-databrain) below.
|
|
25
91
|
|
|
@@ -319,9 +385,9 @@ Prompts are guided workflows your AI assistant can follow. Ask for them by name
|
|
|
319
385
|
|
|
320
386
|
## Tools Reference
|
|
321
387
|
|
|
322
|
-
50 tools organized by category (plus 6 chart App tools on the opt-in `databrain-mcp-chart-apps` entry). Your AI assistant picks the right tools automatically. You do not need to call them directly.
|
|
388
|
+
50 tools organized by category (plus 6 chart App tools on the opt-in `databrain-mcp-chart-apps` entry, and `create_workspace` on the hosted connector). Your AI assistant picks the right tools automatically. You do not need to call them directly.
|
|
323
389
|
|
|
324
|
-
> **Note:** Datasource
|
|
390
|
+
> **Note:** Datasource creation happens outside MCP. Workspace creation does too, except on the hosted connector: `create_workspace` works there when you granted "All workspaces I can access" and your role may create workspaces. Datamarts can be planned with `create_datamart` in `dry_run` mode and created only with `confirm: "APPLY_TO_PRODUCTION"`. The semantic layer is managed via MCP tools (`get_semantic_layer`, `update_semantic_layer`, `start_semantic_layer_generation`, `get_semantic_layer_generation_status`).
|
|
325
391
|
|
|
326
392
|
<details>
|
|
327
393
|
<summary><b>Infrastructure — Exploration and setup</b> (6)</summary>
|
|
@@ -331,7 +397,8 @@ Prompts are guided workflows your AI assistant can follow. Ask for them by name
|
|
|
331
397
|
| `list_datasources` | List connected datasources |
|
|
332
398
|
| `discover_datasource_schema` | Inspect a datasource to see available tables and columns |
|
|
333
399
|
| `list_datamarts` | List datamarts |
|
|
334
|
-
| `list_workspaces` | List all workspaces (shows datamart/datasource connections) |
|
|
400
|
+
| `list_workspaces` | List all workspaces (shows datamart/datasource connections). Hosted: only the workspaces you granted |
|
|
401
|
+
| `create_workspace` | Hosted connector only: create a workspace (needs an "All workspaces" grant and a role that may create one) |
|
|
335
402
|
| `sync_datasource` | Trigger datasource schema sync |
|
|
336
403
|
| `create_datamart` | Dry-run or create a datamart from selected tables and relationships |
|
|
337
404
|
</details>
|
|
@@ -386,16 +453,15 @@ Prompts are guided workflows your AI assistant can follow. Ask for them by name
|
|
|
386
453
|
| `propose_semantic_change` | Validate candidate YAML or a patch and return its plan without writing |
|
|
387
454
|
| `apply_semantic_change` | Preview by default, or apply live with a reviewed hash and production confirmation |
|
|
388
455
|
| `eval_semantic_model` | Run saved queries and optional questions and return pass rate and verdicts |
|
|
389
|
-
| `semantic_readiness` | Read the server readiness number, verdict and open checks |
|
|
390
456
|
|
|
391
457
|
Semantic-layer generation uses the datamart ID returned by `list_datamarts` and calls the service-token API. Pass `datamartId` directly when the ID is already known.
|
|
392
458
|
|
|
393
|
-
For a v2 model, the
|
|
459
|
+
For a v2 model, the five model tools use `datamartId` and the configured service credential. They never request a token from the user or mint a guest token. Hosted eval also requires `mcp:query`; hosted apply requires `mcp:datamarts:write` even for its dry run.
|
|
394
460
|
|
|
395
461
|
1. Use `search_semantic_model` with `question` and optional `k` (default 10, maximum 100). If the server has no retrieval route, the tool pulls the model and ranks name, alias, synonyms and description, then includes adjacent entities. Hidden tables and columns are excluded from local search.
|
|
396
462
|
2. Use `get_semantic_entity` with `kind` and an exact `name`. Column names use `table.column`. Kinds are `table`, `column`, `measure`, `metric`, `join`, `entity`, `glossary`, `saved_query`, `instruction` and `access_rule`.
|
|
397
463
|
3. Use `propose_semantic_change` with exactly one of `source` (complete YAML), `yaml_patch`, or `change`. It returns the candidate source, validation errors, the server plan and `expected_content_hash`. Invalid source returns errors and no plan.
|
|
398
|
-
4. Use `eval_semantic_model` with the proposed `source` and optional `questions`. Omitting source evaluates the stored model. The server returns pass rate and individual verdicts.
|
|
464
|
+
4. Use `eval_semantic_model` with the proposed `source` and optional `questions`. Omitting source evaluates the stored model. The server returns pass rate and individual verdicts.
|
|
399
465
|
5. Review the plan. Call `apply_semantic_change` with the exact returned `source` and `expected_content_hash`. Its `dry_run` defaults to true. A live apply requires `dry_run: false` and user supplied `confirm: "APPLY_TO_PRODUCTION"`. The assistant must never supply confirmation on its own. Explicit `expected_content_hash: null` selects the first apply only when no layer is stored. Apply changes the live model for all consumers.
|
|
400
466
|
|
|
401
467
|
A YAML patch merges mappings and named lists by name, including tables and columns. Other lists replace the original list. An empty list clears a list. Null removes a field. For example, `yaml_patch: "tables:\n - name: orders\n description: Customer purchases\n"` changes that description and preserves other tables and fields. Patch output normalizes YAML formatting and does not preserve comments. Review the returned source.
|
|
@@ -407,11 +473,12 @@ HTTP 409 conflicts and 422 validation or projection refusals return tool errors
|
|
|
407
473
|
</details>
|
|
408
474
|
|
|
409
475
|
<details>
|
|
410
|
-
<summary><b>Dashboards & Widgets</b> (
|
|
476
|
+
<summary><b>Dashboards & Widgets</b> (9) — Discover dashboards, picture them, and CRUD widgets on customer embeds</summary>
|
|
411
477
|
|
|
412
478
|
| Tool | Description |
|
|
413
479
|
|------|-------------|
|
|
414
480
|
| `list_dashboards` | List dashboards (by data app, workspace, or globally) |
|
|
481
|
+
| `dashboard_snapshot` | A PNG of a dashboard or one chart, light or dark, as the signed-in user sees it. Needs a Databrain sign-in (OAuth), not a service token |
|
|
415
482
|
| `list_widgets` | List widgets on an embed for a specific client |
|
|
416
483
|
| `validate_metric_spec` | Validate a SQL-backed metric target without saving |
|
|
417
484
|
| `create_or_update_metric_from_query` | Dry-run or apply a SQL-backed metric create/update |
|
package/dist/apps/server.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
createChartAppServer
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-6O25PXL4.js";
|
|
5
|
+
import "../chunk-VK6XPPBT.js";
|
|
6
|
+
import "../chunk-H3SI2MAU.js";
|
|
7
7
|
export {
|
|
8
8
|
createChartAppServer
|
|
9
9
|
};
|
package/dist/apps/stdio.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
loadConfig
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-N6SJY5JO.js";
|
|
5
5
|
import {
|
|
6
6
|
createChartAppServer
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
7
|
+
} from "../chunk-6O25PXL4.js";
|
|
8
|
+
import "../chunk-VK6XPPBT.js";
|
|
9
|
+
import "../chunk-H3SI2MAU.js";
|
|
10
10
|
|
|
11
11
|
// src/apps/stdio.ts
|
|
12
12
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
@@ -22,13 +22,13 @@ import {
|
|
|
22
22
|
saveDraftAsDashboard,
|
|
23
23
|
viewSchema,
|
|
24
24
|
workspacesForDatamart
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-VK6XPPBT.js";
|
|
26
26
|
import {
|
|
27
27
|
DatabrainApiError,
|
|
28
28
|
DatabrainClient,
|
|
29
29
|
MCP_SERVER_VERSION,
|
|
30
30
|
toolContext
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-H3SI2MAU.js";
|
|
32
32
|
|
|
33
33
|
// src/apps/server.ts
|
|
34
34
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
@@ -513,4 +513,4 @@ function createChartAppServer(config, backend) {
|
|
|
513
513
|
export {
|
|
514
514
|
createChartAppServer
|
|
515
515
|
};
|
|
516
|
-
//# sourceMappingURL=chunk-
|
|
516
|
+
//# sourceMappingURL=chunk-6O25PXL4.js.map
|
|
@@ -46,6 +46,15 @@ var DatabrainApiError = class extends Error {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
hint() {
|
|
49
|
+
if (this.code === "OAUTH_SIGN_IN_REQUIRED") {
|
|
50
|
+
return "Hint: Snapshots draw as a signed-in Databrain user. Connect this AI app with a Databrain sign-in (the hosted connector, or /mcp in Claude Code); a service token cannot take them.";
|
|
51
|
+
}
|
|
52
|
+
if (this.code === "RENDER_IN_PROGRESS") {
|
|
53
|
+
return "Hint: Your other snapshot is still rendering. Wait a few seconds, then call the tool again.";
|
|
54
|
+
}
|
|
55
|
+
if (this.code === "SNAPSHOT_TIMEOUT" || this.code === "SNAPSHOT_TOO_LARGE") {
|
|
56
|
+
return "Hint: Ask for one chart with metricId, or a smaller width.";
|
|
57
|
+
}
|
|
49
58
|
if (this.code === "UNAUTHORIZED_ORIGIN") {
|
|
50
59
|
return "Hint: The embed origin is not on the allowed domains list. Add the domain to the allowed domains in the Databrain settings; the token itself is fine.";
|
|
51
60
|
}
|
|
@@ -128,7 +137,8 @@ var logger = {
|
|
|
128
137
|
// package.json
|
|
129
138
|
var package_default = {
|
|
130
139
|
name: "@databrainhq/mcp-server",
|
|
131
|
-
|
|
140
|
+
mcpName: "com.usedatabrain/mcp-server",
|
|
141
|
+
version: "0.3.0-rc.9",
|
|
132
142
|
description: "MCP server for Databrain embedded analytics - connect databases, create datamarts, configure embeds, and generate frontend code",
|
|
133
143
|
type: "module",
|
|
134
144
|
bin: {
|
|
@@ -1914,6 +1924,7 @@ export {
|
|
|
1914
1924
|
registerSecret,
|
|
1915
1925
|
redactSecrets,
|
|
1916
1926
|
logger,
|
|
1927
|
+
parseErrorBody,
|
|
1917
1928
|
MCP_SERVER_VERSION,
|
|
1918
1929
|
toolContext,
|
|
1919
1930
|
DatabrainClient,
|
|
@@ -1932,4 +1943,4 @@ export {
|
|
|
1932
1943
|
apiProblems,
|
|
1933
1944
|
planUpload
|
|
1934
1945
|
};
|
|
1935
|
-
//# sourceMappingURL=chunk-
|
|
1946
|
+
//# sourceMappingURL=chunk-H3SI2MAU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/errors.ts","../src/utils/logger.ts","../package.json","../src/version.ts","../src/utils/cache.ts","../src/client/error-body.ts","../src/utils/tool-context.ts","../src/client/oauth-client-credentials.ts","../src/client/databrain-client.ts","../src/custom-chart/assets.ts","../src/custom-chart/manifest.ts","../src/custom-chart/types.ts","../src/custom-chart/scaffold.ts","../src/custom-chart/bundle.ts","../src/custom-chart/sanitize-svg.ts","../src/custom-chart/icon.ts","../src/custom-chart/zip.ts","../src/api/custom-charts-api.ts","../src/custom-chart/api.ts"],"sourcesContent":["export class DatabrainApiError extends Error {\n constructor(\n public readonly status: number,\n public readonly code: string,\n message: string,\n public readonly details?: unknown,\n /** The server's own next step for this error class, when it sent one. */\n public readonly serverHint?: string,\n public readonly retryable?: boolean,\n ) {\n super(message);\n this.name = 'DatabrainApiError';\n }\n\n toToolResponse(): { content: Array<{ type: 'text'; text: string }>; isError: true } {\n const parts = [`Error: ${this.message}`];\n const detailDump = this.formatDetails();\n if (detailDump) parts.push(detailDump);\n const hint = this.serverHint ? `Hint: ${this.serverHint}` : this.hint();\n if (hint) parts.push(hint);\n return {\n content: [{ type: 'text', text: parts.join('\\n\\n') }],\n isError: true,\n };\n }\n\n /**\n * Surface API-returned details for 4xx errors so the LLM can recover or\n * report the real reason (validation messages, field names, etc.). Skips\n * fields already collapsed into `message`/`code`, and skips 5xx where the\n * payload usually isn't actionable.\n */\n private formatDetails(): string {\n if (this.status < 400 || this.status >= 500) return '';\n if (!this.details || typeof this.details !== 'object') return '';\n\n const skipKeys = new Set(['message', 'detail', 'error', 'code', 'data', 'hint', 'retryable']);\n const extra: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(this.details as Record<string, unknown>)) {\n if (skipKeys.has(k)) continue;\n if (v === null || v === undefined) continue;\n extra[k] = v;\n }\n if (Object.keys(extra).length === 0) return '';\n try {\n return `API details: ${JSON.stringify(extra)}`;\n } catch {\n return '';\n }\n }\n\n private hint(): string {\n // dashboard_snapshot: the API's own reasons, so the generic status hints below do not mislead.\n if (this.code === 'OAUTH_SIGN_IN_REQUIRED') {\n return 'Hint: Snapshots draw as a signed-in Databrain user. Connect this AI app with a Databrain sign-in (the hosted connector, or /mcp in Claude Code); a service token cannot take them.';\n }\n if (this.code === 'RENDER_IN_PROGRESS') {\n return 'Hint: Your other snapshot is still rendering. Wait a few seconds, then call the tool again.';\n }\n if (this.code === 'SNAPSHOT_TIMEOUT' || this.code === 'SNAPSHOT_TOO_LARGE') {\n return 'Hint: Ask for one chart with metricId, or a smaller width.';\n }\n if (this.code === 'UNAUTHORIZED_ORIGIN') {\n return 'Hint: The embed origin is not on the allowed domains list. Add the domain to the allowed domains in the Databrain settings; the token itself is fine.';\n }\n if (this.status === 401 || this.status === 403) {\n if (this.code === 'OAUTH_API_ERROR') {\n return 'Hint: Check that the backend accepts the configured OAuth issuer and resource, and that the service principal has permission for this operation. Static fallback applies only to token acquisition failures.';\n }\n if (\n this.code === 'INVALID_SERVICE_TOKEN' ||\n this.code === 'MISSING_SERVICE_TOKEN' ||\n this.message.toLowerCase().includes('service token')\n ) {\n return 'Hint: The service token (DATABRAIN_SERVICE_TOKEN) is invalid, expired, or missing. It must be set in the MCP server config (not at runtime). Check Settings > Service Tokens in the Databrain UI.';\n }\n return 'Hint: The per-data-app API token is invalid or expired. Use `create_api_token` to generate a new one. Do not ask the user — manage tokens via MCP tools.';\n }\n if (this.status === 400) {\n return 'Hint: The request was invalid. Check parameter values match expected types and formats. Use the corresponding list tool to verify IDs and names.';\n }\n if (this.status === 404) {\n return 'Hint: The requested resource was not found. Verify the ID or name is correct using the corresponding list tool.';\n }\n if (this.status === 409) {\n return 'Hint: A resource with this name already exists. Use a different name or list existing resources first.';\n }\n if (this.status === 422) {\n return 'Hint: The request parameters are invalid. Check the required fields and their formats.';\n }\n if (this.status === 429) {\n return 'Hint: API rate limit reached. Wait a moment and try again.';\n }\n if (this.status >= 500) {\n return 'Hint: The Databrain API is experiencing issues. Try again in a few moments.';\n }\n return '';\n }\n}\n\nexport function toolError(message: string): { content: Array<{ type: 'text'; text: string }>; isError: true } {\n return {\n content: [{ type: 'text', text: message }],\n isError: true,\n };\n}\n\nexport function stringify(value: unknown): string {\n if (typeof value === 'string') return value;\n try {\n return JSON.stringify(value, null, 2);\n } catch {\n return String(value);\n }\n}\n\nexport function toolSuccess(text: string): { content: Array<{ type: 'text'; text: string }> } {\n return {\n content: [{ type: 'text', text }],\n };\n}\n","const LOG_LEVELS = { debug: 0, info: 1, warn: 2, error: 3 } as const;\ntype LogLevel = keyof typeof LOG_LEVELS;\n\nconst currentLevel: LogLevel =\n (process.env.DATABRAIN_LOG_LEVEL as LogLevel) || 'warn';\n\n/**\n * Credentials the process holds. Every log line is scrubbed of them before it\n * reaches stderr, because an API error body can quote the Authorization\n * header back and stderr is a terminal, a CI log or the MCP host's log.\n */\nconst secrets = new Set<string>();\n\nexport function registerSecret(value: string | undefined | null): void {\n if (typeof value === 'string' && value.length >= 8) secrets.add(value);\n}\n\nexport function redactSecrets(text: string): string {\n let out = text;\n for (const secret of secrets) out = out.split(secret).join('[redacted]');\n return out;\n}\n\nfunction log(level: LogLevel, message: string, data?: unknown): void {\n if (LOG_LEVELS[level] < LOG_LEVELS[currentLevel]) return;\n const line = `[databrain-mcp] [${level.toUpperCase()}] ${message}`;\n const text = data !== undefined ? `${line} ${JSON.stringify(data)}` : line;\n process.stderr.write(`${redactSecrets(text)}\\n`);\n}\n\nexport const logger = {\n debug: (msg: string, data?: unknown) => log('debug', msg, data),\n info: (msg: string, data?: unknown) => log('info', msg, data),\n warn: (msg: string, data?: unknown) => log('warn', msg, data),\n error: (msg: string, data?: unknown) => log('error', msg, data),\n};\n","{\n \"name\": \"@databrainhq/mcp-server\",\n \"mcpName\": \"com.usedatabrain/mcp-server\",\n \"version\": \"0.3.0-rc.9\",\n \"description\": \"MCP server for Databrain embedded analytics - connect databases, create datamarts, configure embeds, and generate frontend code\",\n \"type\": \"module\",\n \"bin\": {\n \"mcp-server\": \"dist/index.js\",\n \"databrain-mcp-server\": \"dist/index.js\",\n \"databrain-mcp-chart-apps\": \"dist/apps/stdio.js\",\n \"databrain\": \"dist/cli.js\"\n },\n \"main\": \"dist/index.js\",\n \"types\": \"dist/index.d.ts\",\n \"files\": [\n \"dist\",\n \"skills\",\n \".claude-plugin\",\n \".mcp.json\"\n ],\n \"scripts\": {\n \"build\": \"tsup && node scripts/copy-custom-chart-assets.mjs\",\n \"dev\": \"tsx src/index.ts\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"test:live\": \"vitest run tests/integration/prompt-flows.test.ts\",\n \"lint\": \"tsc --noEmit\",\n \"prepublishOnly\": \"npm run build\"\n },\n \"keywords\": [\n \"mcp\",\n \"databrain\",\n \"embedded-analytics\",\n \"ai\",\n \"model-context-protocol\"\n ],\n \"license\": \"MIT\",\n \"dependencies\": {\n \"@modelcontextprotocol/sdk\": \"^1.32.1\",\n \"@posthog/mcp\": \"^0.10.7\",\n \"esbuild\": \"0.27.3\",\n \"fflate\": \"0.8.3\",\n \"posthog-node\": \"^5.21.2\",\n \"yaml\": \"^2.9.1\",\n \"zod\": \"^3.24.0\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^25.3.5\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.0\",\n \"typescript\": \"^5.7.0\",\n \"vitest\": \"^3.0.0\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/databrainhq/mcp-server.git\"\n },\n \"engines\": {\n \"node\": \">=18.0.0\"\n }\n}\n","import packageJson from '../package.json';\n\n// tsup embeds this package.json value in dist while tsx resolves the same file\n// during development. The handshake and request headers therefore share the\n// package version without maintaining a second release string.\nexport const MCP_SERVER_VERSION = packageJson.version;\n","interface CacheEntry<T> {\n value: T;\n expiresAt: number;\n}\n\nexport class TtlCache {\n private store = new Map<string, CacheEntry<unknown>>();\n\n get<T>(key: string): T | undefined {\n const entry = this.store.get(key);\n if (!entry) return undefined;\n if (Date.now() > entry.expiresAt) {\n this.store.delete(key);\n return undefined;\n }\n return entry.value as T;\n }\n\n set<T>(key: string, value: T, ttlMs: number): void {\n this.store.set(key, { value, expiresAt: Date.now() + ttlMs });\n }\n\n invalidateByPrefix(prefix: string): void {\n for (const key of this.store.keys()) {\n if (key.startsWith(prefix)) {\n this.store.delete(key);\n }\n }\n }\n\n clear(): void {\n this.store.clear();\n }\n}\n","/**\n * Reads a Databrain error body into one shape. The backend sends the same\n * envelope `{ code, message, hint, retryable, details }` in three places:\n * flat (`{ code, message }`), under `error` (public REST, datasource API) and\n * under `data.error` (the externalApis routes, which also send `error` as a\n * plain string). Reading only the flat form dropped the code and hint.\n */\nexport interface ParsedErrorBody {\n code?: string;\n message?: string;\n hint?: string;\n retryable?: boolean;\n details?: unknown;\n}\n\nconst isRecord = (v: unknown): v is Record<string, unknown> =>\n typeof v === 'object' && v !== null && !Array.isArray(v);\n\nconst str = (v: unknown): string | undefined =>\n typeof v === 'string' && v.trim() ? v : undefined;\n\nconst fromEnvelope = (v: unknown): ParsedErrorBody | undefined => {\n if (!isRecord(v)) return undefined;\n const out: ParsedErrorBody = {\n code: str(v.code),\n message: str(v.message) ?? str(v.detail),\n hint: str(v.hint),\n retryable: typeof v.retryable === 'boolean' ? v.retryable : undefined,\n details: v.details,\n };\n return out.code || out.message || out.hint ? out : undefined;\n};\n\nexport function parseErrorBody(body: unknown): ParsedErrorBody {\n if (!isRecord(body)) return {};\n const nested =\n fromEnvelope(isRecord(body.data) ? body.data.error : undefined) ??\n fromEnvelope(body.error) ??\n fromEnvelope(body);\n if (nested) {\n return { ...nested, message: nested.message ?? str(body.error) };\n }\n return { message: str(body.error) };\n}\n","import { AsyncLocalStorage } from 'node:async_hooks';\n\n/**\n * Per-tool-call intent metadata. Set when an MCP tool handler runs (see\n * registerAllTools, which wraps every handler), and read by DatabrainClient to\n * tag outbound API requests with X-Databrain-MCP-* headers. The backend\n * (mcpTracking) records these so usage can be attributed to a specific tool and\n * workflow intent — letting us see, e.g., embedding vs internal-analytics flows.\n */\nexport interface ToolCallContext {\n /** The MCP tool name being executed, e.g. 'create_workspace_metric'. */\n tool: string;\n /** Coarse domain bucket, e.g. 'embedding' | 'internal_analytics'. */\n category: string;\n /** Use-case bucket, e.g. 'sql_to_workspace_metric'. */\n workflowIntent: string;\n /** How the request was initiated; 'tool_call' for MCP tool invocations. */\n inputMode: string;\n}\n\nexport const toolContext = new AsyncLocalStorage<ToolCallContext>();\n","import { z } from 'zod';\n\n// Validate without transforming: issuer identity uses exact string comparison.\nexport const oauthHttpsUrl = z.string().refine(value => {\n try {\n const url = new URL(value);\n return url.protocol === 'https:' && !url.username && !url.password && !url.hash;\n } catch { return false; }\n}, 'OAuth URLs must use HTTPS without userinfo or fragments');\n\nexport const oauthConfigSchema = z.object({\n issuer: oauthHttpsUrl.refine(value => {\n try { return !new URL(value).search; } catch { return false; }\n }, 'OAuth issuer must not contain a query'),\n clientId: z.string().min(1),\n clientSecret: z.string().min(1),\n resource: oauthHttpsUrl,\n scope: z.string().min(1).optional(),\n authMethod: z.enum(['client_secret_basic', 'client_secret_post']).default('client_secret_basic'),\n});\n\nexport type OAuthConfig = z.infer<typeof oauthConfigSchema>;\n\nconst metadataSchema = z.object({\n issuer: z.string(),\n token_endpoint: oauthHttpsUrl,\n token_endpoint_auth_methods_supported: z.array(z.string()).optional(),\n grant_types_supported: z.array(z.string()).optional(),\n});\nconst tokenSchema = z.object({\n access_token: z.string().regex(/^[A-Za-z0-9\\-._~+/]+=*$/),\n token_type: z.string().refine(value => value.toLowerCase() === 'bearer'),\n expires_in: z.number().finite().positive().optional(),\n});\n\nconst TOKEN_TIMEOUT_MS = 10_000;\nconst FAILURE_COOLDOWN_MS = 30_000;\nconst MAX_REFRESH_SKEW_MS = 60_000;\n\nfunction authError(): Error {\n // Never retain an IdP body, a fetch error, or a schema error as a cause:\n // those can contain credentials and are serialized by callers/telemetry.\n return new Error('OAuth token acquisition failed. Check the configured issuer, client credentials, resource and scopes.');\n}\n\n/** One immutable credential/issuer/resource binding per MCP process client. */\nexport class OAuthClientCredentials {\n private readonly config: OAuthConfig;\n private tokenEndpoint?: string;\n private cached?: { value: string; renewAt: number };\n private pending?: Promise<string>;\n private retryAt = 0;\n\n constructor(config: OAuthConfig) {\n // Also validate programmatic callers; do not expose invalid values in errors.\n const parsed = oauthConfigSchema.safeParse(config);\n if (!parsed.success) throw authError();\n this.config = Object.freeze(parsed.data);\n }\n\n getStatus(): 'configured' | 'ready' | 'unavailable' {\n if (this.cached && Date.now() < this.cached.renewAt) return 'ready';\n if (this.retryAt > 0) return 'unavailable';\n return 'configured';\n }\n\n async getToken(): Promise<string> {\n if (this.cached && Date.now() < this.cached.renewAt) return this.cached.value;\n if (this.pending) return this.pending;\n if (Date.now() < this.retryAt) throw authError();\n\n this.cached = undefined;\n this.pending = this.acquire().catch(() => {\n this.retryAt = Date.now() + FAILURE_COOLDOWN_MS;\n throw authError();\n }).finally(() => { this.pending = undefined; });\n return this.pending;\n }\n\n private async discoverTokenEndpoint(signal: AbortSignal): Promise<string> {\n if (this.tokenEndpoint) return this.tokenEndpoint;\n const issuer = new URL(this.config.issuer);\n const path = issuer.pathname.replace(/\\/$/, '');\n const candidates = [...new Set([\n `${issuer.origin}/.well-known/oauth-authorization-server${path}`,\n `${issuer.origin}/.well-known/openid-configuration${path}`,\n `${issuer.origin}${path}/.well-known/openid-configuration`,\n ])];\n\n for (const url of candidates) {\n // No credentials, cookies, API headers, or redirects during discovery.\n const response = await fetch(url, {\n headers: { Accept: 'application/json' }, redirect: 'error', signal,\n });\n if (response.status === 404 || response.status === 405) continue;\n if (!response.ok) throw authError();\n const metadata = metadataSchema.parse(await response.json());\n if (metadata.issuer !== this.config.issuer) throw authError();\n const methods = metadata.token_endpoint_auth_methods_supported ?? ['client_secret_basic'];\n if (!methods.includes(this.config.authMethod)) throw authError();\n if (metadata.grant_types_supported && !metadata.grant_types_supported.includes('client_credentials')) {\n throw authError();\n }\n this.tokenEndpoint = metadata.token_endpoint;\n return this.tokenEndpoint;\n }\n throw authError();\n }\n\n private async acquire(): Promise<string> {\n // One time budget covers all discovery attempts and token acquisition.\n const signal = AbortSignal.timeout(TOKEN_TIMEOUT_MS);\n const endpoint = await this.discoverTokenEndpoint(signal);\n const body = new URLSearchParams({\n grant_type: 'client_credentials', resource: this.config.resource,\n });\n if (this.config.scope) body.set('scope', this.config.scope);\n const headers: Record<string, string> = {\n Accept: 'application/json', 'Content-Type': 'application/x-www-form-urlencoded',\n };\n if (this.config.authMethod === 'client_secret_post') {\n body.set('client_id', this.config.clientId);\n body.set('client_secret', this.config.clientSecret);\n } else {\n // RFC 6749 2.3.1: form-encode EACH value before constructing Basic auth.\n const encode = (value: string) => new URLSearchParams({ value }).toString().slice(6);\n headers.Authorization = `Basic ${Buffer.from(`${encode(this.config.clientId)}:${encode(this.config.clientSecret)}`).toString('base64')}`;\n }\n\n const startedAt = Date.now();\n const response = await fetch(endpoint, {\n method: 'POST', headers, body: body.toString(), redirect: 'error', signal,\n });\n if (!response.ok) throw authError();\n const token = tokenSchema.parse(await response.json());\n if (token.expires_in !== undefined) {\n const lifetimeMs = token.expires_in * 1000;\n const expiresAt = startedAt + lifetimeMs;\n if (!Number.isFinite(expiresAt) || Date.now() >= expiresAt) throw authError();\n this.cached = {\n value: token.access_token,\n renewAt: expiresAt - Math.min(MAX_REFRESH_SKEW_MS, lifetimeMs * 0.1),\n };\n }\n // With no expires_in, use the token for this call only. No JWT decoding,\n // assumed lifetime, refresh_token grant, disk storage, or background timer.\n this.retryAt = 0;\n return token.access_token;\n }\n}\n","import { TtlCache } from '../utils/cache.js';\nimport type { Config } from '../utils/config.js';\nimport { DatabrainApiError } from '../utils/errors.js';\nimport { logger, registerSecret } from '../utils/logger.js';\nimport type { RequestOptions } from './types.js';\nimport { parseErrorBody } from './error-body.js';\nimport { MCP_SERVER_VERSION } from '../version.js';\nimport { toolContext } from '../utils/tool-context.js';\nimport { OAuthClientCredentials, oauthHttpsUrl } from './oauth-client-credentials.js';\n\nconst MCP_USER_AGENT = `databrain-mcp-server/${MCP_SERVER_VERSION}`;\n\nconst MAX_RETRIES = 3;\nconst REQUEST_TIMEOUT_MS = 30_000;\n\nconst NON_TRANSIENT_PATTERNS = [\n 'out of context',\n 'Definition not found',\n 'not a data question',\n 'Query generation failed',\n 'not found',\n 'not authenticated',\n 'Invalid Service Token',\n 'service token',\n];\n\nexport class DatabrainClient {\n private cache = new TtlCache();\n private runtimeApiToken: string | undefined;\n private readonly oauth?: OAuthClientCredentials;\n private oauthFallback = false;\n\n constructor(private config: Config) {\n registerSecret(config.serviceToken);\n registerSecret(config.apiToken);\n if (config.oauth) {\n if (!oauthHttpsUrl.safeParse(config.apiUrl).success) {\n throw new Error('OAuth requires an HTTPS Databrain API URL without userinfo or fragments.');\n }\n this.oauth = new OAuthClientCredentials(config.oauth);\n // Prevent later mutation of a caller-owned config from moving credentials\n // or the resource bearer to another API/issuer within this client session.\n this.config = Object.freeze({ ...config });\n }\n }\n\n hasApiToken(): boolean {\n return !!(this.runtimeApiToken || this.config.apiToken);\n }\n\n setRuntimeApiToken(token: string): void {\n registerSecret(token);\n this.runtimeApiToken = token;\n logger.info('Runtime API token set for this session');\n }\n\n getServiceToken(): string | undefined {\n return this.config.serviceToken;\n }\n\n getApiUrl(): string {\n return this.config.apiUrl;\n }\n\n getDemoDomain(): string {\n return this.config.demoDomain;\n }\n\n /**\n * Describes which credential is currently used as the bearer for outgoing\n * API calls. Used by `whoami` so the LLM can give the user a truthful answer.\n */\n getActiveAuth():\n | { source: 'service-token'; oauthFallback?: boolean }\n | { source: 'oauth-client-credentials'; status: 'configured' | 'ready' | 'unavailable' }\n | { source: 'api-token' }\n | { source: 'none' } {\n if (this.oauth) {\n if (this.oauthFallback) return { source: 'service-token', oauthFallback: true };\n return { source: 'oauth-client-credentials', status: this.oauth.getStatus() };\n }\n if (this.config.serviceToken) return { source: 'service-token' };\n if (this.runtimeApiToken || this.config.apiToken) return { source: 'api-token' };\n return { source: 'none' };\n }\n\n private async getToken(auth: 'service' | 'api' | 'none'): Promise<string | undefined> {\n if (auth === 'none') return undefined;\n if (auth === 'service') {\n if (this.oauth) {\n try {\n const token = await this.oauth.getToken();\n this.oauthFallback = false;\n return token;\n } catch {\n if (!this.config.serviceToken) {\n throw new DatabrainApiError(0, 'OAUTH_TOKEN_ERROR',\n 'OAuth token acquisition failed. Check the configured issuer, client credentials, resource and scopes.');\n }\n if (!this.oauthFallback) logger.warn('OAuth unavailable; using the configured static service token.');\n this.oauthFallback = true;\n }\n }\n return this.config.serviceToken;\n }\n return this.runtimeApiToken || this.config.apiToken;\n }\n\n async request<T>(options: RequestOptions): Promise<T> {\n return this.requestInternal<T>(options);\n }\n\n private async requestInternal<T>(options: RequestOptions): Promise<T> {\n const usesOAuth = !!this.oauth && options.auth === 'service' && !options.token;\n // An OAuth renewal can switch to a differently scoped static principal.\n // Do not serve/store service response caches across that auth boundary.\n const cacheAllowed = !usesOAuth;\n // Invalidate caches first\n if (options.invalidateCache) {\n for (const prefix of options.invalidateCache) {\n this.cache.invalidateByPrefix(prefix);\n }\n }\n\n // Check cache\n if (cacheAllowed && options.cacheKey && options.cacheTtlMs) {\n const cached = this.cache.get<T>(options.cacheKey);\n if (cached !== undefined) {\n logger.debug(`Cache hit: ${options.cacheKey}`);\n return cached;\n }\n }\n\n let token = options.token ?? await this.getToken(options.auth);\n if (options.auth !== 'none' && !options.token && !token) {\n if (options.auth === 'service') {\n throw new DatabrainApiError(\n 401,\n 'MISSING_SERVICE_TOKEN',\n 'DATABRAIN_SERVICE_TOKEN is required for this operation (org-level token for discovery and data app management). It must be set in the MCP server configuration — do not ask the user for it at runtime.',\n );\n }\n throw new DatabrainApiError(\n 401,\n 'MISSING_API_TOKEN',\n 'A per-data-app API token is required for this embedding operation but none is configured. ' +\n 'Call `create_api_token` to generate one, or `set_api_token` if you already have the value. Do not ask the user for this token — create it via the MCP tools.',\n );\n }\n\n // Build URL\n let url = `${this.config.apiUrl}${options.path}`;\n if (options.query) {\n const params = new URLSearchParams(options.query);\n url += `?${params.toString()}`;\n }\n\n let lastError: Error | undefined;\n\n for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {\n try {\n if (usesOAuth && attempt > 1) token = await this.getToken(options.auth);\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n 'User-Agent': MCP_USER_AGENT,\n 'X-Databrain-Client': MCP_USER_AGENT,\n ...options.headers,\n };\n // Tag the call with the active tool's intent so backend telemetry can\n // attribute usage (embedding vs internal analytics, per-tool). Present\n // only when invoked from within a tool handler (see registry wrapper).\n const ctx = toolContext.getStore();\n if (ctx) {\n headers['X-Databrain-MCP-Tool'] = ctx.tool;\n headers['X-Databrain-MCP-Tool-Category'] = ctx.category;\n headers['X-Databrain-MCP-Workflow-Intent'] = ctx.workflowIntent;\n headers['X-Databrain-MCP-Input-Mode'] = ctx.inputMode;\n }\n if (token) {\n // Guest-token endpoints (auth: 'none' with a minted token) read the\n // token from `x-plugin-token` and require a whitelisted Origin.\n // DATABRAIN_DOMAINS includes `usedatabrain.com`, so `mcp.usedatabrain.com`\n // passes the whitelist without needing a per-company config.\n if (options.auth === 'none') {\n headers['x-plugin-token'] = token;\n headers['Origin'] = 'https://mcp.usedatabrain.com';\n } else {\n headers['Authorization'] = `Bearer ${token}`;\n }\n }\n\n const response = await fetch(url, {\n method: options.method,\n headers,\n body: options.body ? JSON.stringify(options.body) : undefined,\n signal: AbortSignal.timeout(options.timeoutMs || REQUEST_TIMEOUT_MS),\n ...(usesOAuth ? { redirect: 'error' as const } : {}),\n });\n\n if (!response.ok) {\n // An untrusted API can echo credentials in its error body. Keep\n // OAuth errors body-free in both tool output and telemetry. Never\n // retry/downgrade a backend denial with the static service token.\n if (usesOAuth) {\n throw new DatabrainApiError(response.status, 'OAUTH_API_ERROR',\n `Databrain API request failed with status ${response.status} using configured service credentials.`);\n }\n const errorBody = await response.text();\n logger.warn(`[API Error] ${options.method} ${options.path} status=${response.status} body=${errorBody.slice(0, 500)}`);\n let parsed: unknown = {};\n try {\n parsed = JSON.parse(errorBody);\n } catch {\n // not JSON\n }\n\n const envelope = parseErrorBody(parsed);\n const errorMsg = envelope.message || `API request failed with status ${response.status}`;\n const error = new DatabrainApiError(\n response.status,\n envelope.code || `HTTP_${response.status}`,\n errorMsg,\n parsed,\n envelope.hint,\n envelope.retryable,\n );\n\n // Retry on 429 or 5xx (but not when the error is clearly non-transient)\n // The server's own retryable flag wins over the status heuristic.\n const isTransient =\n envelope.retryable !== undefined\n ? envelope.retryable && (response.status === 429 || response.status >= 500)\n : response.status === 429 ||\n (response.status >= 500 &&\n !NON_TRANSIENT_PATTERNS.some((p) => errorMsg.includes(p)));\n if (isTransient && attempt < MAX_RETRIES) {\n const delay = Math.min(1000 * Math.pow(2, attempt - 1), 8000);\n logger.warn(`Retrying in ${delay}ms (attempt ${attempt}/${MAX_RETRIES})`, {\n status: response.status,\n path: options.path,\n });\n await new Promise((r) => setTimeout(r, delay));\n lastError = error;\n continue;\n }\n\n throw error;\n }\n\n const text = await response.text();\n let data = text ? (JSON.parse(text) as T) : ({} as T);\n\n // Databrain API wraps most responses in { data: ... } — unwrap automatically\n if (\n !options.skipDataUnwrap &&\n data &&\n typeof data === 'object' &&\n !Array.isArray(data) &&\n 'data' in data\n ) {\n const inner = (data as Record<string, unknown>).data;\n if (inner !== null && inner !== undefined) {\n data = inner as unknown as T;\n }\n }\n\n // Store in cache\n if (cacheAllowed && options.cacheKey && options.cacheTtlMs) {\n this.cache.set(options.cacheKey, data, options.cacheTtlMs);\n }\n\n return data;\n } catch (err) {\n if (err instanceof DatabrainApiError) throw err;\n\n if (attempt < MAX_RETRIES && (err as Error)?.name === 'TimeoutError' && !options.noRetryOnTimeout) {\n const delay = Math.min(1000 * Math.pow(2, attempt - 1), 8000);\n logger.warn(`Request timed out, retrying in ${delay}ms`, { path: options.path });\n await new Promise((r) => setTimeout(r, delay));\n lastError = err as Error;\n continue;\n }\n\n throw new DatabrainApiError(\n 0,\n 'NETWORK_ERROR',\n usesOAuth ? 'Failed to connect to Databrain API using configured service credentials.'\n : `Failed to connect to Databrain API: ${(err as Error).message}`,\n );\n }\n }\n\n throw lastError || new DatabrainApiError(0, 'UNKNOWN', 'Request failed after retries');\n }\n}\n","import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\n/**\n * The template project and the runtime shim are shipped as plain files, not\n * as strings baked into the bundle, so that they stay byte identical to the\n * copies other repos test against. In source they live in\n * src/custom-chart/; tsup copies them to dist/custom-chart/ after a build\n * (see tsup.config.ts onSuccess). This finds them from either place.\n */\nlet cachedDir: string | undefined;\n\nexport function customChartAssetDir(): string {\n if (cachedDir) return cachedDir;\n const here = dirname(fileURLToPath(import.meta.url));\n const candidates = [\n here,\n join(here, 'custom-chart'),\n join(here, '..', 'custom-chart'),\n join(here, '..', '..', 'custom-chart'),\n join(here, '..', 'src', 'custom-chart'),\n ];\n for (const candidate of candidates) {\n if (existsSync(join(candidate, 'runtime-shim.js')) && existsSync(join(candidate, 'template', 'manifest.json'))) {\n cachedDir = resolve(candidate);\n return cachedDir;\n }\n }\n throw new Error(\n `Custom chart assets not found near ${here}. Expected runtime-shim.js and template/ (run npm run build).`,\n );\n}\n\nexport function readRuntimeShim(): string {\n return readFileSync(join(customChartAssetDir(), 'runtime-shim.js'), 'utf8');\n}\n\nexport function templateDir(): string {\n return join(customChartAssetDir(), 'template');\n}\n\n/** Every file in the template folder, keyed by its file name. */\nexport function readTemplateFiles(): Record<string, string> {\n const dir = templateDir();\n const files: Record<string, string> = {};\n for (const name of readdirSync(dir).sort()) {\n const path = join(dir, name);\n if (statSync(path).isFile()) files[name] = readFileSync(path, 'utf8');\n }\n return files;\n}\n","import { z } from 'zod';\nimport {\n MAX_MANIFEST_BYTES,\n MAX_OPTIONS,\n MAX_SLOTS,\n type CustomChartManifest,\n type Problem,\n} from './types.js';\n\n/**\n * Manifest v2 validator (brief section 3). It is a strict superset of the\n * plugin's sandbox manifest v1: every v1 manifest validates with\n * schemaVersion 1, and schemaVersion 2 unlocks version, description, the\n * color option type, the number step, the option group, slot descriptions and\n * translations. Unknown keys are refused at every level.\n *\n * The checks run in the plugin parser's order, step for step, and the backend\n * (`serverless/express/src/lib/customCharts/manifest.ts`) runs the same steps,\n * so the three validators produce the same problem list for the same\n * manifest. The cross-repo fixtures in tests/fixtures/custom-chart-manifests\n * pin the first code for every invalid case.\n *\n * 1. object, schemaVersion (stop on failure)\n * 2. top-level unknown and missing keys (stop on failure)\n * 3. id, name, version, description\n * 4. slots: shape and count, then each slot (unknown and missing keys\n * first, then the fields), then duplicate ids\n * 5. options: shape and count, then each option (reserved id, type,\n * unknown and missing keys, then the fields), then duplicate ids\n * 6. translations, only when everything above is clean\n * 7. size, only when everything above is clean\n */\n\nconst ID_PATTERN = /^[a-z][a-z0-9_-]{0,63}$/;\nconst FORBIDDEN_IDS = ['constructor', 'prototype', '__proto__'];\nconst LANGUAGE_PATTERN = /^[a-z]{2}(-[A-Z]{2})?$/;\nconst SEMVER_PATTERN =\n /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(-[0-9A-Za-z.-]+)?(\\+[0-9A-Za-z.-]+)?$/;\nconst COLOR_PATTERN = /^#[0-9a-fA-F]{6}$/;\nconst FIELD_TYPES = ['string', 'number', 'boolean'];\nconst MAX_TEXT = 256;\nconst MAX_DESCRIPTION = 500;\nconst MAX_GROUP = 64;\nconst MAX_CHOICES = 32;\nconst MAX_STRING_OPTION_LENGTH = 1024;\n\nconst V1_TOP_KEYS = ['schemaVersion', 'id', 'name', 'slots', 'options'];\nconst V2_TOP_EXTRA_KEYS = ['version', 'description', 'translations'];\nconst V1_SLOT_KEYS = ['id', 'label', 'role', 'types', 'required'];\nconst V2_SLOT_EXTRA_KEYS = ['description'];\nconst OPTION_BASE_KEYS = ['id', 'label', 'type', 'default'];\nconst OPTION_TYPE_KEYS: Record<string, string[]> = {\n boolean: [],\n number: ['min', 'max'],\n string: ['maxLength'],\n select: ['choices'],\n color: [],\n};\nconst V2_OPTION_EXTRA_KEYS: Record<string, string[]> = {\n boolean: ['group'],\n number: ['group', 'step'],\n string: ['group'],\n select: ['group'],\n color: ['group'],\n};\nconst TRANSLATION_KEYS = ['name', 'description', 'slots', 'options'];\nconst SLOT_TRANSLATION_KEYS = ['label', 'description'];\nconst OPTION_TRANSLATION_KEYS = ['label', 'group', 'choices'];\n\nexport const isRecord = (value: unknown): value is Record<string, unknown> =>\n value !== null &&\n typeof value === 'object' &&\n !Array.isArray(value) &&\n Object.getPrototypeOf(value) === Object.prototype;\n\nexport const isId = (value: unknown): value is string =>\n typeof value === 'string' && ID_PATTERN.test(value) && !FORBIDDEN_IDS.includes(value);\n\nconst isText = (value: unknown, max = MAX_TEXT): value is string =>\n typeof value === 'string' && value.length > 0 && value.length <= max;\n\n/** A translated string may be empty: the plugin renders it as given. */\nconst isTranslationText = (value: unknown): value is string =>\n typeof value === 'string' && value.length <= MAX_TEXT;\n\nconst isFiniteNumber = (value: unknown): value is number =>\n typeof value === 'number' && Number.isFinite(value);\n\nexport const jsonBytes = (value: unknown): number =>\n Buffer.byteLength(JSON.stringify(value), 'utf8');\n\nclass Collector {\n readonly problems: Problem[] = [];\n\n add(code: string, path: string, message: string): void {\n this.problems.push({ code, path, message });\n }\n\n /**\n * Unknown keys report `<scope>.unknownKey`, one per key; a missing required\n * key reports `missingCode(key)`. Returns false when anything was reported,\n * so the caller can stop looking at a shape it cannot trust.\n */\n checkKeys(\n value: Record<string, unknown>,\n path: string,\n scope: string,\n required: readonly string[],\n optional: readonly string[],\n missingCode: (key: string) => string = (key) => `${scope}.${key}`,\n ): boolean {\n const allowed = new Set([...required, ...optional]);\n let ok = true;\n for (const key of Object.keys(value)) {\n if (!allowed.has(key)) {\n this.add(`${scope}.unknownKey`, `${path}/${key}`, `Remove \"${key}\". It is not a known key here.`);\n ok = false;\n }\n }\n for (const key of required) {\n if (!Object.hasOwn(value, key)) {\n this.add(missingCode(key), `${path}/${key}`, `Add the required key \"${key}\".`);\n ok = false;\n }\n }\n return ok;\n }\n}\n\nfunction validateSlot(c: Collector, value: unknown, path: string, v2: boolean): void {\n if (!isRecord(value)) {\n c.add('manifest.slot.invalid', path, 'A slot must be an object.');\n return;\n }\n if (!c.checkKeys(value, path, 'manifest.slot', V1_SLOT_KEYS, v2 ? V2_SLOT_EXTRA_KEYS : [])) return;\n if (!isId(value.id)) {\n c.add('manifest.slot.id', `${path}/id`, 'A slot id is lowercase, starts with a letter, and uses only a-z, 0-9, _ and -, up to 64 characters.');\n }\n if (!isText(value.label)) {\n c.add('manifest.slot.label', `${path}/label`, `A slot label is 1 to ${MAX_TEXT} characters.`);\n }\n const role = value.role;\n if (role !== 'dimension' && role !== 'measure') {\n c.add('manifest.slot.role', `${path}/role`, 'A slot role is \"dimension\" or \"measure\".');\n }\n if (typeof value.required !== 'boolean') {\n c.add('manifest.slot.required', `${path}/required`, 'required is true or false.');\n }\n const types = value.types;\n const typesOk =\n Array.isArray(types) &&\n types.length > 0 &&\n types.length <= 3 &&\n new Set(types).size === types.length &&\n types.every((type) => FIELD_TYPES.includes(type as string));\n if (!typesOk) {\n c.add('manifest.slot.types', `${path}/types`, 'types is a list of 1 to 3 distinct values from \"string\", \"number\" and \"boolean\".');\n } else if (role === 'measure' && (types.length !== 1 || (types as string[])[0] !== 'number')) {\n c.add('manifest.slot.types', `${path}/types`, 'A measure slot accepts only [\"number\"].');\n }\n if (Object.hasOwn(value, 'description') && !isText(value.description)) {\n c.add('manifest.slot.description', `${path}/description`, `A slot description is 1 to ${MAX_TEXT} characters.`);\n }\n}\n\nfunction validateOption(c: Collector, value: unknown, path: string, v2: boolean): void {\n if (!isRecord(value)) {\n c.add('manifest.option.invalid', path, 'An option must be an object.');\n return;\n }\n // Reserved before anything else: the author needs to hear \"reserved\" first.\n const id = value.id;\n if (typeof id === 'string' && (id === 'theme' || id.startsWith('theme.'))) {\n c.add('manifest.option.reserved', `${path}/id`, 'The option id \"theme\" (and any id starting with \"theme.\") is reserved for the host theme.');\n return;\n }\n const type = typeof value.type === 'string' ? value.type : '';\n const typeKeys = Object.hasOwn(OPTION_TYPE_KEYS, type) ? OPTION_TYPE_KEYS[type] : undefined;\n if (!typeKeys || (type === 'color' && !v2)) {\n c.add(\n 'manifest.option.type',\n `${path}/type`,\n v2\n ? 'An option type is one of \"boolean\", \"number\", \"string\", \"select\", \"color\".'\n : 'An option type is one of \"boolean\", \"number\", \"string\", \"select\" (color needs schemaVersion 2).',\n );\n return;\n }\n if (!c.checkKeys(value, path, 'manifest.option', [...OPTION_BASE_KEYS, ...typeKeys], v2 ? V2_OPTION_EXTRA_KEYS[type] : [])) return;\n if (!isId(id)) {\n c.add('manifest.option.id', `${path}/id`, 'An option id is lowercase, starts with a letter, and uses only a-z, 0-9, _ and -, up to 64 characters.');\n }\n if (!isText(value.label)) {\n c.add('manifest.option.label', `${path}/label`, `An option label is 1 to ${MAX_TEXT} characters.`);\n }\n if (Object.hasOwn(value, 'group') && !isText(value.group, MAX_GROUP)) {\n c.add('manifest.option.group', `${path}/group`, `An option group is 1 to ${MAX_GROUP} characters.`);\n }\n switch (type) {\n case 'boolean':\n if (typeof value.default !== 'boolean') {\n c.add('manifest.option.default', `${path}/default`, 'A boolean default is true or false.');\n }\n break;\n case 'number': {\n const rangeOk = isFiniteNumber(value.min) && isFiniteNumber(value.max) && value.min <= value.max;\n if (!rangeOk) {\n c.add('manifest.option.range', `${path}/min`, 'Set finite min and max with min <= max.');\n break;\n }\n const min = value.min as number;\n const max = value.max as number;\n if (!isFiniteNumber(value.default) || value.default < min || value.default > max) {\n c.add('manifest.option.default', `${path}/default`, 'A number default is a finite number between min and max.');\n }\n if (Object.hasOwn(value, 'step') && (!isFiniteNumber(value.step) || value.step <= 0 || value.step > max - min)) {\n c.add('manifest.option.step', `${path}/step`, 'step is a positive number no larger than max - min.');\n }\n break;\n }\n case 'string': {\n const maxLength = value.maxLength;\n if (!isFiniteNumber(maxLength) || !Number.isInteger(maxLength) || maxLength < 1 || maxLength > MAX_STRING_OPTION_LENGTH) {\n c.add('manifest.option.maxLength', `${path}/maxLength`, `A string option needs an integer \"maxLength\" from 1 to ${MAX_STRING_OPTION_LENGTH}.`);\n break;\n }\n if (typeof value.default !== 'string' || value.default.length > maxLength) {\n c.add('manifest.option.default', `${path}/default`, 'A string default is a string no longer than maxLength.');\n }\n break;\n }\n case 'select': {\n const choices = value.choices;\n const choicesOk =\n Array.isArray(choices) &&\n choices.length > 0 &&\n choices.length <= MAX_CHOICES &&\n choices.every(\n (choice) => isRecord(choice) && Object.keys(choice).length === 2 && isId(choice.value) && isText(choice.label),\n ) &&\n new Set(choices.map((choice) => choice.value)).size === choices.length;\n if (!choicesOk) {\n c.add('manifest.option.choices', `${path}/choices`, `choices is a list of 1 to ${MAX_CHOICES} distinct { value, label } pairs; a value follows the id rule.`);\n break;\n }\n if (!choices.some((choice) => choice.value === value.default)) {\n c.add('manifest.option.default', `${path}/default`, 'A select default is the value of one of its choices.');\n }\n break;\n }\n case 'color':\n if (typeof value.default !== 'string' || !COLOR_PATTERN.test(value.default)) {\n c.add('manifest.option.color', `${path}/default`, 'A color default is a 6 digit hex colour like \"#3366cc\".');\n }\n break;\n default:\n break;\n }\n}\n\n/** Runs only on a manifest whose slots and options are already valid. */\nfunction validateTranslations(\n c: Collector,\n value: unknown,\n slots: { id: string }[],\n options: { id: string; type: string; choices?: { value: string }[] }[],\n): void {\n const path = '/translations';\n if (!isRecord(value)) {\n c.add('manifest.translations.invalid', path, 'translations is an object keyed by language code.');\n return;\n }\n for (const [language, entry] of Object.entries(value)) {\n const langPath = `${path}/${language}`;\n if (!LANGUAGE_PATTERN.test(language)) {\n c.add('manifest.translations.language', langPath, `\"${language}\" is not a language code like \"fr\" or \"pt-BR\".`);\n continue;\n }\n if (!isRecord(entry)) {\n c.add('manifest.translations.invalid', langPath, 'A translation is an object with optional name, description, slots and options.');\n continue;\n }\n if (!c.checkKeys(entry, langPath, 'manifest.translations', [], TRANSLATION_KEYS)) continue;\n for (const key of ['name', 'description'] as const) {\n if (Object.hasOwn(entry, key) && !isTranslationText(entry[key])) {\n c.add('manifest.translations.text', `${langPath}/${key}`, `A translated string is at most ${MAX_TEXT} characters.`);\n }\n }\n if (Object.hasOwn(entry, 'slots')) {\n const entrySlots = entry.slots;\n if (!isRecord(entrySlots)) {\n c.add('manifest.translations.invalid', `${langPath}/slots`, 'slots is an object keyed by slot id.');\n } else {\n for (const [slotId, slotEntry] of Object.entries(entrySlots)) {\n const slotPath = `${langPath}/slots/${slotId}`;\n if (!slots.some((slot) => slot.id === slotId)) {\n c.add('manifest.translations.slot', slotPath, `\"${slotId}\" is not a slot id in this manifest.`);\n continue;\n }\n if (!isRecord(slotEntry)) {\n c.add('manifest.translations.invalid', slotPath, 'A slot translation is an object with optional label and description.');\n continue;\n }\n if (!c.checkKeys(slotEntry, slotPath, 'manifest.translations', [], SLOT_TRANSLATION_KEYS)) continue;\n for (const key of ['label', 'description'] as const) {\n if (Object.hasOwn(slotEntry, key) && !isTranslationText(slotEntry[key])) {\n c.add('manifest.translations.text', `${slotPath}/${key}`, `A translated string is at most ${MAX_TEXT} characters.`);\n }\n }\n }\n }\n }\n if (Object.hasOwn(entry, 'options')) {\n const entryOptions = entry.options;\n if (!isRecord(entryOptions)) {\n c.add('manifest.translations.invalid', `${langPath}/options`, 'options is an object keyed by option id.');\n } else {\n for (const [optionId, optionEntry] of Object.entries(entryOptions)) {\n const optionPath = `${langPath}/options/${optionId}`;\n const option = options.find((item) => item.id === optionId);\n if (!option) {\n c.add('manifest.translations.option', optionPath, `\"${optionId}\" is not an option id in this manifest.`);\n continue;\n }\n if (!isRecord(optionEntry)) {\n c.add('manifest.translations.invalid', optionPath, 'An option translation is an object with optional label, group and choices.');\n continue;\n }\n if (!c.checkKeys(optionEntry, optionPath, 'manifest.translations', [], OPTION_TRANSLATION_KEYS)) continue;\n for (const key of ['label', 'group'] as const) {\n if (Object.hasOwn(optionEntry, key) && !isTranslationText(optionEntry[key])) {\n c.add('manifest.translations.text', `${optionPath}/${key}`, `A translated string is at most ${MAX_TEXT} characters.`);\n }\n }\n if (!Object.hasOwn(optionEntry, 'choices')) continue;\n const choices = optionEntry.choices;\n if (!isRecord(choices)) {\n c.add('manifest.translations.invalid', `${optionPath}/choices`, 'choices is an object keyed by choice value.');\n continue;\n }\n for (const [choiceValue, label] of Object.entries(choices)) {\n const choicePath = `${optionPath}/choices/${choiceValue}`;\n if (option.type !== 'select' || !(option.choices ?? []).some((choice) => choice.value === choiceValue)) {\n c.add('manifest.translations.choice', choicePath, `\"${choiceValue}\" is not a choice of option \"${optionId}\".`);\n } else if (!isTranslationText(label)) {\n c.add('manifest.translations.text', choicePath, `A translated string is at most ${MAX_TEXT} characters.`);\n }\n }\n }\n }\n }\n }\n}\n\n/**\n * Validate a manifest value. Returns every problem found, first problem first.\n * An empty array means the manifest is valid.\n */\nexport function validateManifest(value: unknown): Problem[] {\n const c = new Collector();\n if (!isRecord(value)) {\n c.add('manifest.invalid', '', 'manifest.json must be a JSON object.');\n return c.problems;\n }\n\n // 1. schemaVersion\n const schemaVersion = value.schemaVersion;\n if (schemaVersion !== 1 && schemaVersion !== 2) {\n c.add('manifest.schemaVersion.unsupported', '/schemaVersion', 'schemaVersion must be 1 or 2.');\n return c.problems;\n }\n const v2 = schemaVersion === 2;\n\n // 2. unknown and missing top-level keys\n if (!c.checkKeys(value, '', 'manifest', V1_TOP_KEYS, v2 ? V2_TOP_EXTRA_KEYS : [], (key) => `manifest.${key}.required`)) {\n return c.problems;\n }\n\n // 3. id, name and the v2 labels (on v1 the keys were already refused above)\n if (!isId(value.id)) {\n c.add('manifest.id.invalid', '/id', 'id is lowercase, starts with a letter, and uses only a-z, 0-9, _ and -, up to 64 characters. It becomes the chart type \"custom:<id>\".');\n }\n if (!isText(value.name)) {\n c.add('manifest.name.invalid', '/name', `name is 1 to ${MAX_TEXT} characters.`);\n }\n if (Object.hasOwn(value, 'version') && (typeof value.version !== 'string' || !SEMVER_PATTERN.test(value.version))) {\n c.add('manifest.version.invalid', '/version', 'version is a semver string like \"1.2.0\".');\n }\n if (Object.hasOwn(value, 'description') && !isText(value.description, MAX_DESCRIPTION)) {\n c.add('manifest.description.invalid', '/description', `description is 1 to ${MAX_DESCRIPTION} characters.`);\n }\n\n // 4. slots\n const slots = value.slots;\n if (!Array.isArray(slots)) {\n c.add('manifest.slots.invalid', '/slots', 'slots must be an array.');\n } else if (slots.length === 0) {\n c.add('manifest.slots.empty', '/slots', 'Declare at least one slot.');\n } else if (slots.length > MAX_SLOTS) {\n c.add('manifest.slots.tooMany', '/slots', `Declare at most ${MAX_SLOTS} slots.`);\n } else {\n slots.forEach((slot, index) => validateSlot(c, slot, `/slots/${index}`, v2));\n const seen = new Set<string>();\n slots.forEach((slot, index) => {\n if (!isRecord(slot) || typeof slot.id !== 'string') return;\n if (seen.has(slot.id)) {\n c.add('manifest.slot.duplicate', `/slots/${index}/id`, `Slot id \"${slot.id}\" is used more than once.`);\n }\n seen.add(slot.id);\n });\n }\n\n // 5. options\n const options = value.options;\n if (!Array.isArray(options)) {\n c.add('manifest.options.invalid', '/options', 'options must be an array (it may be empty).');\n } else if (options.length > MAX_OPTIONS) {\n c.add('manifest.options.tooMany', '/options', `Declare at most ${MAX_OPTIONS} options.`);\n } else {\n options.forEach((option, index) => validateOption(c, option, `/options/${index}`, v2));\n const seen = new Set<string>();\n options.forEach((option, index) => {\n if (!isRecord(option) || typeof option.id !== 'string') return;\n if (seen.has(option.id)) {\n c.add('manifest.option.duplicate', `/options/${index}/id`, `Option id \"${option.id}\" is used more than once.`);\n }\n seen.add(option.id);\n });\n }\n\n // 6. translations, only on an otherwise clean manifest (v2 only; on v1 the key is unknown)\n if (c.problems.length === 0 && Object.hasOwn(value, 'translations')) {\n validateTranslations(\n c,\n value.translations,\n slots as { id: string }[],\n options as { id: string; type: string; choices?: { value: string }[] }[],\n );\n }\n\n // 7. size, only on an otherwise clean manifest\n if (c.problems.length === 0 && jsonBytes(value) > MAX_MANIFEST_BYTES) {\n c.add('manifest.size', '', `manifest.json must be at most ${MAX_MANIFEST_BYTES} bytes as JSON.`);\n }\n\n return c.problems;\n}\n\n/** Parse a manifest; returns null when validateManifest reports anything. */\nexport function parseManifest(value: unknown): CustomChartManifest | null {\n return validateManifest(value).length === 0 ? (value as CustomChartManifest) : null;\n}\n\n/** Zod view of manifest v2 for tool input schemas. Shape only: validateManifest owns the rules. */\nconst slotSchema = z.object({\n id: z.string(),\n label: z.string(),\n role: z.enum(['dimension', 'measure']),\n types: z.array(z.enum(['string', 'number', 'boolean'])),\n required: z.boolean(),\n description: z.string().optional(),\n});\n\nconst optionSchema = z.object({\n id: z.string(),\n label: z.string(),\n type: z.enum(['boolean', 'number', 'string', 'select', 'color']),\n default: z.union([z.string(), z.number(), z.boolean()]),\n min: z.number().optional(),\n max: z.number().optional(),\n step: z.number().optional(),\n maxLength: z.number().optional(),\n choices: z.array(z.object({ value: z.string(), label: z.string() })).optional(),\n group: z.string().optional(),\n});\n\nexport const manifestSchema = z.object({\n schemaVersion: z.union([z.literal(1), z.literal(2)]),\n id: z.string(),\n name: z.string(),\n version: z.string().optional(),\n description: z.string().optional(),\n slots: z.array(slotSchema),\n options: z.array(optionSchema),\n translations: z.record(z.unknown()).optional(),\n});\n\nexport type ManifestSlotInput = z.infer<typeof slotSchema>;\nexport type ManifestOptionInput = z.infer<typeof optionSchema>;\nexport { slotSchema as manifestSlotSchema, optionSchema as manifestOptionSchema };\n\n/** Deep key sort used by the content hash (brief section 5). Arrays keep their order. */\nexport function sortKeys<T>(value: T): T {\n if (Array.isArray(value)) return value.map((item) => sortKeys(item)) as T;\n if (isRecord(value)) {\n const out: Record<string, unknown> = {};\n for (const key of Object.keys(value).sort()) out[key] = sortKeys(value[key]);\n return out as T;\n }\n return value;\n}\n","/**\n * Shared shapes for the custom chart package pipeline (DAT-925).\n * Problem is the one error shape used by the manifest validator, the bundle\n * builder, the icon check and the backend API (section 5 of the brief).\n */\nexport interface Problem {\n code: string;\n path: string;\n message: string;\n}\n\nexport type CustomChartFieldType = 'string' | 'number' | 'boolean';\n\nexport interface CustomChartSlot {\n id: string;\n label: string;\n role: 'dimension' | 'measure';\n types: CustomChartFieldType[];\n required: boolean;\n description?: string;\n}\n\nexport type CustomChartOption = { id: string; label: string; group?: string } & (\n | { type: 'boolean'; default: boolean }\n | { type: 'number'; default: number; min: number; max: number; step?: number }\n | { type: 'string'; default: string; maxLength: number }\n | { type: 'select'; default: string; choices: { value: string; label: string }[] }\n | { type: 'color'; default: string }\n);\n\nexport interface CustomChartTranslation {\n name?: string;\n description?: string;\n slots?: Record<string, { label?: string; description?: string }>;\n options?: Record<string, { label?: string; group?: string; choices?: Record<string, string> }>;\n}\n\nexport interface CustomChartManifest {\n schemaVersion: 1 | 2;\n id: string;\n name: string;\n version?: string;\n description?: string;\n slots: CustomChartSlot[];\n options: CustomChartOption[];\n translations?: Record<string, CustomChartTranslation>;\n}\n\n/** The four artifacts a build produces and an upload sends. */\nexport interface CustomChartBundle {\n manifest: CustomChartManifest;\n bundleJs: string;\n bundleCss?: string;\n iconSvg: string;\n}\n\nexport const MAX_MANIFEST_BYTES = 32 * 1024;\nexport const MAX_BUNDLE_JS_BYTES = 2 * 1024 * 1024;\nexport const MAX_BUNDLE_CSS_BYTES = 256 * 1024;\nexport const MAX_ICON_BYTES = 16 * 1024;\nexport const MAX_SLOTS = 16;\nexport const MAX_OPTIONS = 32;\n","import { readTemplateFiles } from './assets.js';\nimport { isId, validateManifest } from './manifest.js';\nimport type { CustomChartOption, CustomChartSlot, Problem } from './types.js';\n\n/**\n * A chart project is the template folder with manifest.json and package.json\n * rewritten for the requested key, name, slots and options. Every other file\n * is copied verbatim so that the guide, the types and the sample chart stay\n * byte identical to what the tests exercise.\n */\nexport interface ScaffoldInput {\n key: string;\n name: string;\n description?: string;\n slots?: CustomChartSlot[];\n options?: CustomChartOption[];\n}\n\nexport interface ScaffoldResult {\n ok: boolean;\n problems: Problem[];\n files: Record<string, string>;\n nextStep: string;\n}\n\nconst DEFAULT_SLOTS: CustomChartSlot[] = [\n { id: 'category', label: 'Category', role: 'dimension', types: ['string'], required: true, description: 'One bar per value.' },\n { id: 'value', label: 'Value', role: 'measure', types: ['number'], required: true },\n { id: 'target', label: 'Target', role: 'measure', types: ['number'], required: false },\n];\n\nexport function scaffoldProject(input: ScaffoldInput): ScaffoldResult {\n const template = readTemplateFiles();\n const templateManifest = JSON.parse(template['manifest.json']) as {\n slots: CustomChartSlot[];\n options: CustomChartOption[];\n };\n const problems: Problem[] = [];\n if (!isId(input.key)) {\n problems.push({\n code: 'manifest.id.invalid',\n path: '/id',\n message: 'key must match ^[a-z][a-z0-9_-]{0,63}$ (lowercase letters, digits, _ and -).',\n });\n }\n const name = typeof input.name === 'string' ? input.name.trim() : '';\n if (name.length === 0 || name.length > 256) {\n problems.push({ code: 'manifest.name.invalid', path: '/name', message: 'name must be 1 to 256 characters.' });\n }\n\n const manifest: Record<string, unknown> = {\n schemaVersion: 2,\n id: input.key,\n name,\n version: '1.0.0',\n ...(input.description ? { description: input.description } : {}),\n slots: input.slots && input.slots.length > 0 ? input.slots : templateManifest.slots ?? DEFAULT_SLOTS,\n options: input.options ?? templateManifest.options,\n };\n problems.push(...validateManifest(manifest));\n\n const packageJson = JSON.parse(template['package.json']) as Record<string, unknown>;\n packageJson.name = input.key;\n\n const files: Record<string, string> = {};\n for (const [file, content] of Object.entries(template)) {\n if (file === 'manifest.json') files[file] = JSON.stringify(manifest, null, 2) + '\\n';\n else if (file === 'package.json') files[file] = JSON.stringify(packageJson, null, 2) + '\\n';\n else files[file] = content;\n }\n\n return {\n ok: problems.length === 0,\n problems,\n files,\n nextStep:\n 'Write these files into a folder, edit chart.ts, then run `databrain custom-chart validate` and ' +\n '`databrain custom-chart build`. Upload with `databrain custom-chart upload` or the custom_chart_upload tool.',\n };\n}\n","import { createHash } from 'node:crypto';\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { join, resolve, sep } from 'node:path';\nimport { build as esbuild, type Plugin } from 'esbuild';\nimport { readRuntimeShim } from './assets.js';\nimport { sanitizeIcon, validateIcon } from './icon.js';\nimport { sortKeys, validateManifest } from './manifest.js';\nimport {\n MAX_BUNDLE_CSS_BYTES,\n MAX_BUNDLE_JS_BYTES,\n type CustomChartBundle,\n type CustomChartManifest,\n type Problem,\n} from './types.js';\nimport { writeBundleZip } from './zip.js';\n\nconst utf8Bytes = (text: string): number => Buffer.byteLength(text, 'utf8');\n\n/**\n * Content hash exactly as the backend computes it (brief section 5 and\n * FINDINGS be-core 2): sha256 hex over\n * JSON.stringify({ manifest, bundleJs, bundleCss, iconSvg }) in that key\n * order, the manifest keys sorted recursively (arrays keep their order) and\n * bundleCss always present, as \"\" when there is none.\n */\nexport function contentHash(bundle: CustomChartBundle): string {\n const payload = JSON.stringify({\n manifest: sortKeys(bundle.manifest),\n bundleJs: bundle.bundleJs,\n bundleCss: bundle.bundleCss ?? '',\n iconSvg: bundle.iconSvg,\n });\n return createHash('sha256').update(payload, 'utf8').digest('hex');\n}\n\n/** Bytes the upload carries: the four artifacts as UTF-8. */\nexport function bundleSizeBytes(bundle: CustomChartBundle): number {\n return (\n utf8Bytes(JSON.stringify(bundle.manifest)) +\n utf8Bytes(bundle.bundleJs) +\n (bundle.bundleCss ? utf8Bytes(bundle.bundleCss) : 0) +\n utf8Bytes(bundle.iconSvg)\n );\n}\n\nexport interface ValidateBundleInput {\n manifest: unknown;\n bundleJs?: string;\n bundleCss?: string;\n iconSvg?: string;\n}\n\n/**\n * The client side of the upload validation (the server repeats it). Manifest\n * rules first, then the bundle sizes, then the icon.\n */\nexport function validateBundle(input: ValidateBundleInput): Problem[] {\n const problems = validateManifest(input.manifest);\n if (input.bundleJs !== undefined) {\n if (typeof input.bundleJs !== 'string') {\n problems.push({ code: 'bundle.js.type', path: '/bundleJs', message: 'bundleJs must be a string.' });\n } else if (input.bundleJs.trim().length === 0) {\n problems.push({ code: 'bundle.js.empty', path: '/bundleJs', message: 'bundleJs must contain JavaScript.' });\n } else if (utf8Bytes(input.bundleJs) > MAX_BUNDLE_JS_BYTES) {\n problems.push({\n code: 'bundle.js.size',\n path: '/bundleJs',\n message: `bundleJs must be at most ${MAX_BUNDLE_JS_BYTES} bytes (2 MiB) as UTF-8. Drop or shrink a dependency.`,\n });\n }\n }\n if (input.bundleCss !== undefined) {\n if (typeof input.bundleCss !== 'string') {\n problems.push({ code: 'bundle.css.type', path: '/bundleCss', message: 'bundleCss must be a string when present.' });\n } else if (utf8Bytes(input.bundleCss) > MAX_BUNDLE_CSS_BYTES) {\n problems.push({\n code: 'bundle.css.size',\n path: '/bundleCss',\n message: `bundleCss must be at most ${MAX_BUNDLE_CSS_BYTES} bytes (256 KiB).`,\n });\n }\n }\n if (input.iconSvg !== undefined) problems.push(...validateIcon(input.iconSvg, '/iconSvg'));\n return problems;\n}\n\nexport interface ChartProject {\n dir: string;\n manifest: unknown;\n manifestText?: string;\n chartEntry?: string;\n css?: string;\n icon?: string;\n sampleData?: unknown;\n problems: Problem[];\n}\n\n/** Read a chart project folder. Missing or unparsable files become problems. */\nexport function readProject(dirInput: string): ChartProject {\n const dir = resolve(dirInput);\n const problems: Problem[] = [];\n const project: ChartProject = { dir, manifest: undefined, problems };\n\n const manifestPath = join(dir, 'manifest.json');\n if (!existsSync(manifestPath)) {\n problems.push({ code: 'project.manifest.missing', path: '/manifest.json', message: `No manifest.json in ${dir}.` });\n } else {\n project.manifestText = readFileSync(manifestPath, 'utf8');\n try {\n project.manifest = JSON.parse(project.manifestText);\n } catch (err) {\n problems.push({\n code: 'project.manifest.parse',\n path: '/manifest.json',\n message: `manifest.json is not valid JSON: ${(err as Error).message}`,\n });\n }\n }\n\n const entry = ['chart.ts', 'chart.js'].map((name) => join(dir, name)).find((path) => existsSync(path));\n if (!entry) {\n problems.push({ code: 'project.chart.missing', path: '/chart.ts', message: `No chart.ts in ${dir}. It must export render(ctx).` });\n } else {\n project.chartEntry = entry;\n }\n\n const cssPath = join(dir, 'chart.css');\n if (existsSync(cssPath)) project.css = readFileSync(cssPath, 'utf8');\n\n const iconPath = join(dir, 'icon.svg');\n if (!existsSync(iconPath)) {\n problems.push({ code: 'bundle.icon.required', path: '/icon.svg', message: `No icon.svg in ${dir}.` });\n } else {\n project.icon = readFileSync(iconPath, 'utf8');\n }\n\n const samplePath = join(dir, 'sample-data.json');\n if (existsSync(samplePath)) {\n try {\n project.sampleData = JSON.parse(readFileSync(samplePath, 'utf8'));\n } catch (err) {\n problems.push({\n code: 'project.sampleData.parse',\n path: '/sample-data.json',\n message: `sample-data.json is not valid JSON: ${(err as Error).message}`,\n });\n }\n }\n return project;\n}\n\n/** validate = read the folder, check the manifest and the icon. No esbuild. */\nexport function validateProject(dir: string): { ok: boolean; problems: Problem[]; project: ChartProject } {\n const project = readProject(dir);\n const problems = [...project.problems];\n if (project.manifest !== undefined) problems.push(...validateManifest(project.manifest));\n // The build strips the XML declaration and comments before upload, so check that form.\n if (project.icon !== undefined) problems.push(...validateIcon(sanitizeIcon(project.icon)));\n if (project.css !== undefined && utf8Bytes(project.css) > MAX_BUNDLE_CSS_BYTES) {\n problems.push({ code: 'bundle.css.size', path: '/chart.css', message: `chart.css must be at most ${MAX_BUNDLE_CSS_BYTES} bytes.` });\n }\n return { ok: problems.length === 0, problems, project };\n}\n\nexport interface BuildOutputs extends CustomChartBundle {\n manifest: CustomChartManifest;\n contentHash: string;\n sizeBytes: number;\n}\n\nexport interface BuildResult {\n ok: boolean;\n problems: Problem[];\n outputs?: BuildOutputs;\n /** Absolute paths written under dist/, in write order. Empty when write is false. */\n written: string[];\n}\n\nexport const DIST_FILES = ['index.js', 'manifest.json', 'icon.svg', 'index.css', 'bundle.zip'] as const;\n\n/**\n * Every import must resolve to a file inside the chart project. A relative\n * path that climbs out (`../../.config/x.json`) would be inlined into the\n * bundle and uploaded with it; the build refuses it with a problem instead.\n */\nfunction insideProjectOnly(dir: string): Plugin {\n const root = dir.endsWith(sep) ? dir : `${dir}${sep}`;\n return {\n name: 'databrain-inside-project-only',\n setup(build) {\n build.onResolve({ filter: /.*/ }, async (args) => {\n if (args.kind === 'entry-point' || args.pluginData?.databrainChecked) return undefined;\n const resolved = await build.resolve(args.path, {\n kind: args.kind,\n resolveDir: args.resolveDir,\n importer: args.importer,\n pluginData: { databrainChecked: true },\n });\n if (resolved.errors.length > 0) return { errors: resolved.errors };\n if (resolved.external || resolved.path.startsWith(root)) return resolved;\n return {\n errors: [\n {\n text: `\"${args.path}\" is outside the chart project. Only files inside ${dir} can be imported.`,\n },\n ],\n };\n });\n },\n };\n}\n\n/**\n * Compile chart.ts with esbuild to one IIFE, prepend the runtime shim and\n * the slot id list the shim reads, enforce the 2 MiB gate and write dist/.\n * See brief section 4 and contract/runtime-shim.js.\n */\nexport async function buildProject(dir: string, options: { write?: boolean } = {}): Promise<BuildResult> {\n const validated = validateProject(dir);\n const { project } = validated;\n const problems = [...validated.problems];\n if (!project.chartEntry || project.manifest === undefined || problems.length > 0) {\n return { ok: false, problems, written: [] };\n }\n const manifest = project.manifest as CustomChartManifest;\n\n // Bundled for the browser with no externals: every import is resolved\n // inside the project or it is a build error (a node builtin like \"fs\" does\n // not resolve on the browser platform), so dist/index.js never carries a\n // dangling require. The entry must be an ES module that exports render():\n // the shim reads globalThis.__dbnCustomChart.render, and a CommonJS\n // module.exports or a missing export would only fail later, as a blank tile.\n const common = {\n plugins: [insideProjectOnly(project.dir)],\n entryPoints: [project.chartEntry],\n absWorkingDir: project.dir,\n bundle: true as const,\n target: 'es2020',\n platform: 'browser' as const,\n write: false as const,\n legalComments: 'none' as const,\n logLevel: 'silent' as const,\n charset: 'utf8' as const,\n };\n let moduleJs: string;\n try {\n const shape = await esbuild({ ...common, format: 'esm', metafile: true });\n const exported = Object.values(shape.metafile.outputs)[0]?.exports ?? [];\n if (!exported.includes('render')) {\n problems.push({\n code: 'bundle.build.noRender',\n path: '/chart.ts',\n message:\n 'chart.ts must be an ES module that exports a function named render: `export function render(ctx) { ... }`. module.exports and default exports are not read.',\n });\n return { ok: false, problems, written: [] };\n }\n const result = await esbuild({\n ...common,\n format: 'iife',\n globalName: '__dbnCustomChart',\n minify: true,\n });\n moduleJs = result.outputFiles.map((file) => file.text).join('\\n');\n } catch (err) {\n const errors = (err as { errors?: { text: string; location?: { file?: string; line?: number } | null }[] }).errors;\n if (Array.isArray(errors) && errors.length > 0) {\n for (const error of errors) {\n const where = error.location ? `${error.location.file ?? 'chart.ts'}:${error.location.line ?? 0}` : 'chart.ts';\n problems.push({ code: 'bundle.build.failed', path: `/${where}`, message: error.text });\n }\n } else {\n problems.push({ code: 'bundle.build.failed', path: '/chart.ts', message: (err as Error).message });\n }\n return { ok: false, problems, written: [] };\n }\n\n // Shim first (byte identical to contract/runtime-shim.js), then the slot ids\n // so every manifest slot is present on ctx.slots, then the chart module.\n // chart.css is NOT inlined: the host injects bundleCss into the frame\n // (brief section 6.5); dist/index.css carries it for provenance and upload.\n const shim = readRuntimeShim();\n const slotIds = manifest.slots.map((slot) => slot.id);\n const globals = `globalThis.__dbnCustomChartSlots=${JSON.stringify(slotIds)};\\n`;\n const bundleJs = `${shim.trimEnd()}\\n${globals}${moduleJs.trimEnd()}\\nglobalThis.__dbnCustomChart=__dbnCustomChart;\\n`;\n const iconSvg = sanitizeIcon(project.icon as string);\n const bundleCss = project.css;\n\n problems.push(...validateBundle({ manifest, bundleJs, bundleCss, iconSvg }));\n if (problems.length > 0) return { ok: false, problems, written: [] };\n\n const bundle: CustomChartBundle = { manifest, bundleJs, bundleCss, iconSvg };\n const outputs: BuildOutputs = {\n ...bundle,\n contentHash: contentHash(bundle),\n sizeBytes: bundleSizeBytes(bundle),\n };\n\n const written: string[] = [];\n if (options.write !== false) {\n const dist = join(project.dir, 'dist');\n mkdirSync(dist, { recursive: true });\n const manifestJson = JSON.stringify(manifest, null, 2) + '\\n';\n const write = (name: string, content: string | Uint8Array) => {\n const path = join(dist, name);\n writeFileSync(path, content);\n written.push(path);\n };\n write('index.js', bundleJs);\n write('manifest.json', manifestJson);\n write('icon.svg', iconSvg);\n if (bundleCss !== undefined) write('index.css', bundleCss);\n write(\n 'bundle.zip',\n writeBundleZip({\n 'index.js': bundleJs,\n 'manifest.json': manifestJson,\n 'icon.svg': iconSvg,\n ...(bundleCss !== undefined ? { 'index.css': bundleCss } : {}),\n }),\n );\n }\n\n return { ok: true, problems: [], outputs, written };\n}\n\n/** Read a previous build from dist/ (for upload without rebuilding). */\nexport function readDist(dir: string): { bundle?: CustomChartBundle; problems: Problem[] } {\n const dist = join(resolve(dir), 'dist');\n const problems: Problem[] = [];\n const need = ['index.js', 'manifest.json', 'icon.svg'];\n for (const name of need) {\n if (!existsSync(join(dist, name))) {\n problems.push({ code: 'project.dist.missing', path: `/dist/${name}`, message: `dist/${name} is missing. Run databrain custom-chart build first.` });\n }\n }\n if (problems.length > 0) return { problems };\n let manifest: unknown;\n try {\n manifest = JSON.parse(readFileSync(join(dist, 'manifest.json'), 'utf8'));\n } catch (err) {\n return { problems: [{ code: 'project.dist.parse', path: '/dist/manifest.json', message: (err as Error).message }] };\n }\n const manifestProblems = validateManifest(manifest);\n if (manifestProblems.length > 0) return { problems: manifestProblems };\n const cssPath = join(dist, 'index.css');\n return {\n problems,\n bundle: {\n manifest: manifest as CustomChartManifest,\n bundleJs: readFileSync(join(dist, 'index.js'), 'utf8'),\n bundleCss: existsSync(cssPath) ? readFileSync(cssPath, 'utf8') : undefined,\n iconSvg: readFileSync(join(dist, 'icon.svg'), 'utf8'),\n },\n };\n}\n","/**\n * Allow-list SVG sanitiser for icon.svg. A verbatim copy of the backend's\n * `serverless/express/src/utils/helpers/sanitizeSvg.ts` (the one that gates\n * the upload), so the CLI and the validate tool refuse exactly what the\n * server refuses instead of guessing with regexes. Keep the two files in\n * step: a rule added on one side and not the other means \"validate says ok,\n * upload says no\".\n *\n * WHAT IT DOES\n * ------------\n * - Drops the DOCTYPE (entity expansion) and every processing instruction\n * except the XML declaration; drops CDATA and comments.\n * - Keeps only elements on ALLOWED_ELEMENTS. A disallowed element and\n * everything inside it is removed (`<script>`, `<foreignObject>`,\n * `<iframe>`, `<animate>` ... ).\n * - Keeps only attributes on ALLOWED_ATTRIBUTES (plus `data-*` and the\n * `xmlns*` declarations). Every `on*` attribute goes. Any attribute whose\n * value carries `javascript:`, `data:text/html`, or `vbscript:` after\n * entity decoding goes.\n * - `href` / `xlink:href` survive only as a same-document `#id` reference,\n * or, on `<image>` alone, as a `data:image/(png|jpeg|gif|webp);base64`\n * URI. An external `<image href>` is removed with the element.\n * - `<style>` and `style=\"\"` survive only when they contain no `url(`,\n * `@import`, `expression(` or `-moz-binding`. A style that reaches out\n * of the file is dropped entirely rather than partially rewritten.\n *\n * Returns the cleaned markup and a count of what was removed, so the caller\n * can refuse the icon rather than silently rewriting it.\n */\nconst ALLOWED_ELEMENTS: ReadonlySet<string> = new Set([\n 'svg',\n 'g',\n 'defs',\n 'symbol',\n 'use',\n 'title',\n 'desc',\n 'metadata',\n 'path',\n 'rect',\n 'circle',\n 'ellipse',\n 'line',\n 'polyline',\n 'polygon',\n 'text',\n 'tspan',\n 'textpath',\n 'image',\n 'lineargradient',\n 'radialgradient',\n 'stop',\n 'clippath',\n 'mask',\n 'pattern',\n 'marker',\n 'filter',\n 'fegaussianblur',\n 'feoffset',\n 'feblend',\n 'fecolormatrix',\n 'fecomposite',\n 'feflood',\n 'femerge',\n 'femergenode',\n 'fedropshadow',\n 'style',\n 'switch',\n]);\n\nconst ALLOWED_ATTRIBUTES: ReadonlySet<string> = new Set([\n 'id',\n 'class',\n 'style',\n 'href',\n 'xlink:href',\n 'xml:space',\n 'lang',\n 'xml:lang',\n 'version',\n 'baseprofile',\n 'viewbox',\n 'preserveaspectratio',\n 'width',\n 'height',\n 'x',\n 'y',\n 'x1',\n 'y1',\n 'x2',\n 'y2',\n 'cx',\n 'cy',\n 'r',\n 'rx',\n 'ry',\n 'fx',\n 'fy',\n 'fr',\n 'd',\n 'points',\n 'transform',\n 'transform-origin',\n 'fill',\n 'fill-opacity',\n 'fill-rule',\n 'stroke',\n 'stroke-width',\n 'stroke-linecap',\n 'stroke-linejoin',\n 'stroke-miterlimit',\n 'stroke-dasharray',\n 'stroke-dashoffset',\n 'stroke-opacity',\n 'opacity',\n 'color',\n 'display',\n 'visibility',\n 'overflow',\n 'clip-path',\n 'clip-rule',\n 'clippathunits',\n 'mask',\n 'maskunits',\n 'maskcontentunits',\n 'filter',\n 'filterunits',\n 'primitiveunits',\n 'in',\n 'in2',\n 'result',\n 'mode',\n 'operator',\n 'values',\n 'type',\n 'stddeviation',\n 'dx',\n 'dy',\n 'flood-color',\n 'flood-opacity',\n 'offset',\n 'stop-color',\n 'stop-opacity',\n 'gradientunits',\n 'gradienttransform',\n 'spreadmethod',\n 'patternunits',\n 'patterncontentunits',\n 'patterntransform',\n 'markerunits',\n 'markerwidth',\n 'markerheight',\n 'refx',\n 'refy',\n 'orient',\n 'font-family',\n 'font-size',\n 'font-weight',\n 'font-style',\n 'letter-spacing',\n 'text-anchor',\n 'dominant-baseline',\n 'alignment-baseline',\n 'text-decoration',\n 'word-spacing',\n 'paint-order',\n 'vector-effect',\n 'shape-rendering',\n 'text-rendering',\n 'image-rendering',\n 'color-interpolation',\n 'color-interpolation-filters',\n 'enable-background',\n 'startoffset',\n 'method',\n 'spacing',\n 'requiredfeatures',\n 'systemlanguage',\n 'role',\n 'aria-label',\n 'aria-labelledby',\n 'aria-hidden',\n 'focusable',\n 'tabindex',\n]);\n\n/** Pattern over a tag's raw text: name, then attributes, then optional `/`. */\nconst TAG_RE = /^<\\s*(\\/?)\\s*([A-Za-z_][\\w:.-]*)([\\s\\S]*?)(\\/?)\\s*>$/;\n\nconst ATTRIBUTE_RE =\n /([^\\s=/\"']+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'>]+)))?/g;\n\nconst decodeEntities = (value: string): string =>\n value\n .replace(/&#x([0-9a-fA-F]+);?/g, (_m, hex: string) =>\n String.fromCodePoint(parseInt(hex, 16)),\n )\n .replace(/&#(\\d+);?/g, (_m, dec: string) =>\n String.fromCodePoint(parseInt(dec, 10)),\n )\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/"/g, '\"')\n .replace(/'/g, \"'\")\n .replace(/&/g, '&');\n\n/** Entity-decode, drop control and whitespace characters, lower-case. Then a scheme cannot hide as `java\\tscript:`. */\nconst normaliseForSchemeCheck = (value: string): string =>\n decodeEntities(value)\n .replace(/[\\u0000-\\u0020\\u007f-\\u00a0\\u200b-\\u200f\\u2028\\u2029\\ufeff]/g, '')\n .toLowerCase();\n\nconst DANGEROUS_SCHEME_RE =\n /^(javascript|vbscript|livescript|mocha|data:text\\/html|data:application)/;\n\nconst isDangerousValue = (value: string): boolean => {\n const normalised = normaliseForSchemeCheck(value);\n return (\n DANGEROUS_SCHEME_RE.test(normalised) ||\n normalised.includes('javascript:') ||\n normalised.includes('vbscript:')\n );\n};\n\nconst SAFE_DATA_IMAGE_RE =\n /^data:image\\/(png|jpeg|jpg|gif|webp);base64,[a-z0-9+/=]+$/;\n\nconst isAcceptableHref = (value: string, element: string): boolean => {\n const normalised = normaliseForSchemeCheck(value);\n if (normalised.startsWith('#')) return true;\n return element === 'image' && SAFE_DATA_IMAGE_RE.test(normalised);\n};\n\n/**\n * A style that leaves the document is dropped whole. `url(#id)` is a same\n * document paint server reference (`fill: url(#gradient)`) and is the one\n * `url(` a logo legitimately uses, so it is blanked before the test.\n */\nconst LOCAL_URL_RE = /url\\s*\\(\\s*(['\"]?)#[^)'\"]*\\1\\s*\\)/gi;\nconst STYLE_ESCAPE_RE =\n /url\\s*\\(|@import|expression\\s*\\(|-moz-binding|behavior\\s*:/i;\n\nconst isSafeStyle = (value: string): boolean =>\n !STYLE_ESCAPE_RE.test(decodeEntities(value).replace(LOCAL_URL_RE, ''));\n\nexport type SanitizeSvgResult = {\n svg: string;\n /** Elements, attributes and declarations that were taken out. */\n removed: number;\n /** True when the input did not even look like an SVG document. */\n isSvg: boolean;\n};\n\ntype Token =\n | { kind: 'text'; raw: string }\n | { kind: 'tag'; raw: string }\n | { kind: 'special'; raw: string };\n\n/**\n * Split markup into text, tags, and the specials (comments, CDATA, DOCTYPE,\n * processing instructions) that need their own terminators.\n */\nconst tokenize = (input: string): Token[] => {\n const tokens: Token[] = [];\n let index = 0;\n const length = input.length;\n\n const pushSpecial = (end: number, terminator: string): void => {\n const close = input.indexOf(terminator, end);\n const stop = close === -1 ? length : close + terminator.length;\n tokens.push({ kind: 'special', raw: input.slice(index, stop) });\n index = stop;\n };\n\n while (index < length) {\n const open = input.indexOf('<', index);\n if (open === -1) {\n tokens.push({ kind: 'text', raw: input.slice(index) });\n break;\n }\n if (open > index) {\n tokens.push({ kind: 'text', raw: input.slice(index, open) });\n index = open;\n }\n if (input.startsWith('<!--', index)) {\n pushSpecial(index + 4, '-->');\n continue;\n }\n if (input.startsWith('<![CDATA[', index)) {\n pushSpecial(index + 9, ']]>');\n continue;\n }\n if (input.startsWith('<?', index)) {\n pushSpecial(index + 2, '?>');\n continue;\n }\n if (input.startsWith('<!', index)) {\n // DOCTYPE may carry an internal subset in [ ... ]; find the real end.\n const bracket = input.indexOf('[', index);\n const plainEnd = input.indexOf('>', index);\n if (bracket !== -1 && (plainEnd === -1 || bracket < plainEnd)) {\n const subsetEnd = input.indexOf(']', bracket);\n pushSpecial(subsetEnd === -1 ? index + 2 : subsetEnd, '>');\n } else {\n pushSpecial(index + 2, '>');\n }\n continue;\n }\n // Ordinary tag: ends at the first `>` outside a quoted attribute value.\n let cursor = index + 1;\n let quote: string | null = null;\n while (cursor < length) {\n const ch = input[cursor];\n if (quote) {\n if (ch === quote) quote = null;\n } else if (ch === '\"' || ch === \"'\") {\n quote = ch;\n } else if (ch === '>') {\n break;\n }\n cursor += 1;\n }\n const stop = cursor >= length ? length : cursor + 1;\n tokens.push({ kind: 'tag', raw: input.slice(index, stop) });\n index = stop;\n }\n return tokens;\n};\n\nconst isXmlDeclaration = (raw: string): boolean => /^<\\?xml\\b/i.test(raw);\n\n/**\n * Filter a tag's attributes. Returns the rebuilt attribute string (or `null`\n * when the element itself must go because its only href was hostile) and the\n * number of attributes dropped.\n */\nconst cleanAttributes = (\n element: string,\n rawAttributes: string,\n): { attributes: string; removed: number; dropElement: boolean } => {\n let removed = 0;\n let dropElement = false;\n const kept: string[] = [];\n ATTRIBUTE_RE.lastIndex = 0;\n let match: RegExpExecArray | null;\n while ((match = ATTRIBUTE_RE.exec(rawAttributes)) !== null) {\n const [whole, name, dq, sq, bare] = match;\n if (!name || name === '/') continue;\n const lower = name.toLowerCase();\n const value = dq ?? sq ?? bare ?? '';\n\n if (lower.startsWith('on')) {\n removed += 1;\n continue;\n }\n const isNamespaceDeclaration =\n lower === 'xmlns' || lower.startsWith('xmlns:');\n const isData = lower.startsWith('data-');\n if (!isNamespaceDeclaration && !isData && !ALLOWED_ATTRIBUTES.has(lower)) {\n removed += 1;\n continue;\n }\n if (isDangerousValue(value)) {\n removed += 1;\n continue;\n }\n if (lower === 'href' || lower === 'xlink:href') {\n if (!isAcceptableHref(value, element)) {\n removed += 1;\n // An <image> or <use> whose only reason to exist is an external\n // reference is not a logo any more once that reference is gone.\n if (element === 'image' || element === 'use') dropElement = true;\n continue;\n }\n }\n if (lower === 'style' && !isSafeStyle(value)) {\n removed += 1;\n continue;\n }\n kept.push(whole.trim());\n }\n return {\n attributes: kept.length ? ` ${kept.join(' ')}` : '',\n removed,\n dropElement,\n };\n};\n\n/**\n * Sentinel pushed before a `<style>` open tag so the whole element can be\n * unwound if its content turns out to reach outside the file. NUL bytes cannot\n * occur in well formed XML text, so no real chunk can collide with it, and it\n * is filtered out before the chunks are joined.\n */\nconst STYLE_OPEN_MARKER = '\\u0000style-open\\u0000';\n\nexport const sanitizeSvg = (input: string): SanitizeSvgResult => {\n const tokens = tokenize(input);\n const out: string[] = [];\n let removed = 0;\n let isSvg = false;\n\n // Depth inside a dropped element: while > 0 every token is discarded. The\n // stack tracks which open tags were dropped so the matching close is too.\n let dropDepth = 0;\n const dropStack: string[] = [];\n // Inside <style>: content must be checked as CSS, not copied blind.\n let styleBuffer: string[] | null = null;\n\n for (const token of tokens) {\n if (token.kind === 'special') {\n if (isXmlDeclaration(token.raw) && dropDepth === 0) {\n out.push(token.raw);\n } else {\n removed += 1;\n }\n continue;\n }\n\n if (token.kind === 'text') {\n if (dropDepth > 0) continue;\n if (styleBuffer) {\n styleBuffer.push(token.raw);\n } else {\n out.push(token.raw);\n }\n continue;\n }\n\n const parsed = TAG_RE.exec(token.raw);\n if (!parsed) {\n // Unparseable tag text. Inside a drop it goes anyway; outside, it is\n // not markup we can vouch for, so it goes too.\n removed += 1;\n continue;\n }\n const [, closing, rawName, rawAttributes, selfClosingSlash] = parsed;\n const name = rawName.toLowerCase();\n const isClosing = closing === '/';\n const isSelfClosing = selfClosingSlash === '/';\n\n if (name === 'svg') isSvg = true;\n\n if (dropDepth > 0) {\n if (isClosing) {\n if (dropStack[dropStack.length - 1] === name) {\n dropStack.pop();\n dropDepth -= 1;\n }\n } else if (!isSelfClosing) {\n dropStack.push(name);\n dropDepth += 1;\n }\n continue;\n }\n\n if (isClosing) {\n if (name === 'style' && styleBuffer) {\n const css = styleBuffer.join('');\n styleBuffer = null;\n if (isSafeStyle(css)) {\n out.push(css, token.raw);\n } else {\n // Drop the <style> we already emitted the open tag for.\n const openIndex = out.lastIndexOf(STYLE_OPEN_MARKER);\n if (openIndex !== -1) out.splice(openIndex);\n removed += 1;\n }\n continue;\n }\n if (ALLOWED_ELEMENTS.has(name)) out.push(token.raw);\n continue;\n }\n\n if (!ALLOWED_ELEMENTS.has(name)) {\n removed += 1;\n if (!isSelfClosing) {\n dropStack.push(name);\n dropDepth += 1;\n }\n continue;\n }\n\n const cleaned = cleanAttributes(name, rawAttributes);\n removed += cleaned.removed;\n if (cleaned.dropElement) {\n removed += 1;\n if (!isSelfClosing) {\n dropStack.push(name);\n dropDepth += 1;\n }\n continue;\n }\n\n const rebuilt = `<${rawName}${cleaned.attributes}${\n isSelfClosing ? '/' : ''\n }>`;\n if (name === 'style' && !isSelfClosing) {\n out.push(STYLE_OPEN_MARKER, rebuilt);\n styleBuffer = [];\n continue;\n }\n out.push(rebuilt);\n }\n\n // An unterminated <style> at EOF: keep nothing of it.\n if (styleBuffer) {\n const openIndex = out.lastIndexOf(STYLE_OPEN_MARKER);\n if (openIndex !== -1) out.splice(openIndex);\n removed += 1;\n }\n\n return {\n svg: out.filter((chunk) => chunk !== STYLE_OPEN_MARKER).join(''),\n removed,\n isSvg,\n };\n};\n","import { sanitizeSvg } from './sanitize-svg.js';\nimport { MAX_ICON_BYTES, type Problem } from './types.js';\n\n/**\n * Strict SVG check for icon.svg (brief sections 4 and 5). Nothing is rewritten:\n * an icon either passes every rule or is refused with a problem that says what\n * to remove. The check is the backend's own allow-list sanitiser\n * (`sanitize-svg.ts`, a copy of the server file): the icon is refused when the\n * sanitiser would remove anything, when it carries an `<image>` element, or\n * when it is not one `<svg>` element. The backend runs the same sanitiser on\n * upload and refuses with the same codes: bundle.icon.required,\n * bundle.icon.size, bundle.icon.notSvg, bundle.icon.unsafe. The message names\n * the rule that tripped when one of the common ones did.\n */\nconst UNSAFE = 'bundle.icon.unsafe';\nconst RULES: { pattern: RegExp; message: string }[] = [\n { pattern: /<\\s*script\\b/i, message: 'Remove every <script> element from icon.svg.' },\n { pattern: /<\\s*foreignObject\\b/i, message: 'Remove every <foreignObject> element from icon.svg.' },\n { pattern: /<\\s*image\\b/i, message: 'Remove every <image> element from icon.svg. Draw with paths and shapes.' },\n { pattern: /[\\s/]on[a-z]+\\s*=/i, message: 'Remove every on*= event attribute from icon.svg.' },\n { pattern: /<!--/, message: 'Remove every <!-- comment --> from icon.svg.' },\n { pattern: /<!(?:ENTITY|DOCTYPE)\\b/i, message: 'Remove the DOCTYPE and entity declarations from icon.svg.' },\n { pattern: /<!\\[CDATA\\[/, message: 'Remove every CDATA section from icon.svg.' },\n { pattern: /(?:xlink:)?href\\s*=\\s*[\"']\\s*(?!#)/i, message: 'Every href in icon.svg must start with # (no external or data references).' },\n { pattern: /javascript\\s*:/i, message: 'Remove every javascript: reference from icon.svg.' },\n { pattern: /@import|expression\\s*\\(|-moz-binding/i, message: 'Remove @import, expression() and -moz-binding from icon.svg styles.' },\n { pattern: /url\\s*\\(\\s*['\"]?\\s*(?!#)/i, message: 'Every url() in icon.svg must point at a same-document #id.' },\n];\nconst GENERIC_UNSAFE =\n 'icon.svg must use only plain SVG drawing elements and attributes: no script, event handlers, foreignObject, image, animation, external hrefs, url() styles, comments, DOCTYPE or unknown attributes.';\n\nconst XML_DECLARATION = /^\\s*<\\?xml[^>]*\\?>\\s*/i;\n\n/** One `<svg ...>...</svg>` (or `<svg .../>`) and nothing else, after the XML declaration. */\nexport function isSingleSvgRoot(svg: string): boolean {\n const body = svg.replace(/^/, '').replace(XML_DECLARATION, '').trim();\n return /^<svg[\\s>][\\s\\S]*<\\/svg>$/i.test(body) || /^<svg\\b[^>]*\\/>$/i.test(body);\n}\n\nexport function validateIcon(svg: unknown, path = '/icon.svg'): Problem[] {\n if (typeof svg !== 'string' || svg.trim().length === 0) {\n return [{ code: 'bundle.icon.required', path, message: 'icon.svg is required and must not be empty.' }];\n }\n if (Buffer.byteLength(svg, 'utf8') > MAX_ICON_BYTES) {\n return [{ code: 'bundle.icon.size', path, message: `icon.svg must be at most ${MAX_ICON_BYTES} bytes.` }];\n }\n const cleaned = sanitizeSvg(svg);\n if (!cleaned.isSvg || !isSingleSvgRoot(cleaned.svg)) {\n return [{ code: 'bundle.icon.notSvg', path, message: 'icon.svg must be one <svg> element with nothing after it.' }];\n }\n if (cleaned.removed > 0 || /<\\s*image\\b/i.test(svg)) {\n const rule = RULES.find((candidate) => candidate.pattern.test(svg));\n return [{ code: UNSAFE, path, message: rule ? rule.message : GENERIC_UNSAFE }];\n }\n return [];\n}\n\n/**\n * The form the CLI writes to dist/icon.svg and uploads: BOM, XML declaration\n * and comments removed, trimmed. The server refuses a comment rather than\n * stripping it, so the build strips them here; everything else is left as the\n * author wrote it and must already pass validateIcon.\n */\nexport function sanitizeIcon(svg: string): string {\n return svg\n .replace(/^/, '')\n .replace(XML_DECLARATION, '')\n .replace(/<!--[\\s\\S]*?-->/g, '')\n .trim();\n}\n","import { strFromU8, strToU8, unzipSync, zipSync } from 'fflate';\n\n/**\n * dist/bundle.zip is for humans (drag and drop upload in the app). The API\n * takes JSON. The zip holds exactly the four build outputs at its root.\n */\nexport const BUNDLE_ZIP_FILES = ['index.js', 'manifest.json', 'icon.svg', 'index.css'] as const;\nexport type BundleZipFile = (typeof BUNDLE_ZIP_FILES)[number];\n\nexport type BundleZipInput = Partial<Record<BundleZipFile, string>> &\n Pick<Record<BundleZipFile, string>, 'index.js' | 'manifest.json' | 'icon.svg'>;\n\nexport function writeBundleZip(files: BundleZipInput): Uint8Array {\n const entries: Record<string, Uint8Array> = {};\n for (const name of BUNDLE_ZIP_FILES) {\n const content = files[name];\n if (typeof content === 'string') entries[name] = strToU8(content);\n }\n // Fixed mtime keeps the zip bytes stable for the same inputs.\n return zipSync(entries, { level: 6, mtime: new Date('2000-01-01T00:00:00Z') });\n}\n\nexport function readBundleZip(bytes: Uint8Array): Partial<Record<BundleZipFile, string>> {\n const unzipped = unzipSync(bytes, {\n filter: (file) => (BUNDLE_ZIP_FILES as readonly string[]).includes(file.name),\n });\n const files: Partial<Record<BundleZipFile, string>> = {};\n for (const name of BUNDLE_ZIP_FILES) {\n if (unzipped[name]) files[name] = strFromU8(unzipped[name]);\n }\n return files;\n}\n","import type { DatabrainClient } from '../client/databrain-client.js';\nimport type { CustomChartBundle, Problem } from '../custom-chart/types.js';\n\n/**\n * Service-token custom chart API (brief section 5), mounted by the backend\n * under /api/mcp/custom-charts. Company scope comes from the token; nothing\n * here sends a company or tenant selector.\n */\nexport const CUSTOM_CHARTS_PATH = '/api/mcp/custom-charts';\nconst LIST_CACHE_KEY = 'list_custom_charts';\n\nexport interface CustomChartVersionSummary {\n id: string;\n versionNumber: number;\n contentHash: string;\n sizeBytes?: number;\n createdAt?: string;\n createdBy?: string | null;\n [key: string]: unknown;\n}\n\nexport interface CustomChartSummary {\n id: string;\n key: string;\n name: string;\n description?: string | null;\n status: 'private' | 'published' | string;\n chartType?: string;\n publishedVersionId?: string | null;\n previewVersionId?: string | null;\n publishedVersionNumber?: number | null;\n previewVersionNumber?: number | null;\n versionsCount?: number;\n iconSvg?: string;\n createdBy?: string | null;\n createdAt?: string;\n updatedAt?: string;\n [key: string]: unknown;\n}\n\nexport interface CustomChartDetail extends CustomChartSummary {\n versions?: CustomChartVersionSummary[];\n}\n\nexport interface ValidateResponse {\n ok: boolean;\n problems: Problem[];\n contentHash?: string;\n sizeBytes?: number;\n}\n\nexport interface UploadResponse {\n chart: CustomChartSummary;\n version: CustomChartVersionSummary;\n created: 'chart' | 'version' | 'none';\n}\n\nexport interface UploadBody extends CustomChartBundle {\n name?: string;\n description?: string;\n}\n\nconst encodeKey = (key: string): string => encodeURIComponent(key);\n\nexport class CustomChartsApi {\n constructor(private readonly client: DatabrainClient) {}\n\n async list(): Promise<CustomChartSummary[]> {\n const response = await this.client.request<{ charts?: CustomChartSummary[] } | CustomChartSummary[]>({\n method: 'GET',\n path: CUSTOM_CHARTS_PATH,\n auth: 'service',\n cacheKey: LIST_CACHE_KEY,\n cacheTtlMs: 30_000,\n });\n if (Array.isArray(response)) return response;\n return Array.isArray(response?.charts) ? response.charts : [];\n }\n\n async get(key: string): Promise<CustomChartDetail> {\n const response = await this.client.request<{ chart?: CustomChartDetail } | CustomChartDetail>({\n method: 'GET',\n path: `${CUSTOM_CHARTS_PATH}/${encodeKey(key)}`,\n auth: 'service',\n });\n const wrapped = response as { chart?: CustomChartDetail };\n return wrapped.chart ? wrapped.chart : (response as CustomChartDetail);\n }\n\n /** Never persists. The server repeats every client side check. */\n async validate(body: UploadBody): Promise<ValidateResponse> {\n const response = await this.client.request<ValidateResponse>({\n method: 'POST',\n path: `${CUSTOM_CHARTS_PATH}/validate`,\n auth: 'service',\n body,\n timeoutMs: 60_000,\n });\n return {\n ok: response.ok === true,\n problems: Array.isArray(response.problems) ? response.problems : [],\n contentHash: response.contentHash,\n sizeBytes: response.sizeBytes,\n };\n }\n\n /** Creates the chart (first upload) or a preview version; idempotent on contentHash. */\n async upload(body: UploadBody): Promise<UploadResponse> {\n return this.client.request<UploadResponse>({\n method: 'POST',\n path: CUSTOM_CHARTS_PATH,\n auth: 'service',\n body,\n timeoutMs: 60_000,\n invalidateCache: [LIST_CACHE_KEY],\n });\n }\n\n async publish(key: string, versionId?: string): Promise<{ chart: CustomChartSummary }> {\n return this.client.request<{ chart: CustomChartSummary }>({\n method: 'POST',\n path: `${CUSTOM_CHARTS_PATH}/${encodeKey(key)}/publish`,\n auth: 'service',\n body: versionId ? { versionId } : {},\n invalidateCache: [LIST_CACHE_KEY],\n });\n }\n\n async discardPreview(key: string): Promise<{ chart: CustomChartSummary }> {\n return this.client.request<{ chart: CustomChartSummary }>({\n method: 'POST',\n path: `${CUSTOM_CHARTS_PATH}/${encodeKey(key)}/discard-preview`,\n auth: 'service',\n body: {},\n invalidateCache: [LIST_CACHE_KEY],\n });\n }\n}\n","import type { DatabrainClient } from '../client/databrain-client.js';\nimport { CustomChartsApi } from '../api/custom-charts-api.js';\nimport type { CustomChartSummary } from '../api/custom-charts-api.js';\nimport { DatabrainApiError } from '../utils/errors.js';\nimport type { Problem } from './types.js';\n\nexport {\n CustomChartsApi,\n CUSTOM_CHARTS_PATH,\n type CustomChartDetail,\n type CustomChartSummary,\n type CustomChartVersionSummary,\n type UploadBody,\n type UploadResponse,\n type ValidateResponse,\n} from '../api/custom-charts-api.js';\n\nexport function createCustomChartsApi(client: DatabrainClient): CustomChartsApi {\n return new CustomChartsApi(client);\n}\n\n/** The backend error body is { error: { code, message, problems? } }. Pull the problems out. */\nexport function apiProblems(err: unknown): Problem[] {\n if (!(err instanceof DatabrainApiError)) return [];\n const details = err.details as { error?: { problems?: unknown }; problems?: unknown } | undefined;\n const list = details?.error?.problems ?? details?.problems;\n if (!Array.isArray(list)) return [];\n return list.filter(\n (item): item is Problem =>\n !!item && typeof item === 'object' && typeof (item as Problem).code === 'string' && typeof (item as Problem).message === 'string',\n );\n}\n\nexport interface UploadPlan {\n action: 'create chart' | 'create version' | 'no change';\n key: string;\n existing?: CustomChartSummary;\n nextVersionNumber: number;\n summary: string;\n}\n\n/**\n * What an apply will do, computed from the chart list (brief section 8):\n * \"will create chart\" when the key is new, \"will create version n\" when the\n * chart exists. The content-hash replay (\"none\") is only known to the server.\n */\nexport function planUpload(key: string, existing: CustomChartSummary | undefined, versionsKnown?: number): UploadPlan {\n if (!existing) {\n return { action: 'create chart', key, nextVersionNumber: 1, summary: `will create chart custom:${key} (version 1, status private)` };\n }\n const count = typeof versionsKnown === 'number' ? versionsKnown : typeof existing.versionsCount === 'number' ? existing.versionsCount : undefined;\n const next = count !== undefined ? count + 1 : NaN;\n const label = Number.isFinite(next) ? `version ${next}` : 'the next version';\n return {\n action: 'create version',\n key,\n existing,\n nextVersionNumber: Number.isFinite(next) ? next : 0,\n summary: `will create ${label} of custom:${key} in preview (status stays ${existing.status}; the published version keeps serving until you publish)`,\n };\n}\n"],"mappings":";;;AAAO,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC3C,YACkB,QACA,MAChB,SACgB,SAEA,YACA,WAChB;AACA,UAAM,OAAO;AARG;AACA;AAEA;AAEA;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,iBAAoF;AAClF,UAAM,QAAQ,CAAC,UAAU,KAAK,OAAO,EAAE;AACvC,UAAM,aAAa,KAAK,cAAc;AACtC,QAAI,WAAY,OAAM,KAAK,UAAU;AACrC,UAAM,OAAO,KAAK,aAAa,SAAS,KAAK,UAAU,KAAK,KAAK,KAAK;AACtE,QAAI,KAAM,OAAM,KAAK,IAAI;AACzB,WAAO;AAAA,MACL,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,MAAM,KAAK,MAAM,EAAE,CAAC;AAAA,MACpD,SAAS;AAAA,IACX;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,gBAAwB;AAC9B,QAAI,KAAK,SAAS,OAAO,KAAK,UAAU,IAAK,QAAO;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AAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGD,IAAM,SAAS;AAEf,IAAM,eACJ;AAEF,IAAM,iBAAiB,CAAC,UACtB,MACG;AAAA,EAAQ;AAAA,EAA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ACA,QAAM,QAAQ,OAAO,kBAAkB,WAAW,gBAAgB,OAAO,SAAS,kBAAkB,WAAW,SAAS,gBAAgB;AACxI,QAAM,OAAO,UAAU,SAAY,QAAQ,IAAI;AAC/C,QAAM,QAAQ,OAAO,SAAS,IAAI,IAAI,WAAW,IAAI,KAAK;AAC1D,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,mBAAmB,OAAO,SAAS,IAAI,IAAI,OAAO;AAAA,IAClD,SAAS,eAAe,KAAK,cAAc,GAAG,6BAA6B,SAAS,MAAM;AAAA,EAC5F;AACF;","names":["z","isRecord","z","isRecord","existsSync","readFileSync","join","resolve","resolve","join","existsSync","readFileSync","join","resolve","existsSync","readFileSync"]}
|