@rubytech/create-maxy-code 0.1.60 → 0.1.62
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/package.json +1 -1
- package/payload/platform/plugins/admin/PLUGIN.md +1 -1
- package/payload/platform/plugins/brochures/skills/property-brochure/SKILL.md +26 -3
- package/payload/platform/plugins/brochures/skills/property-brochure/references/registers.md +1 -1
- package/payload/platform/plugins/docs/references/admin-session.md +2 -2
- package/payload/platform/plugins/docs/references/internals.md +1 -1
- package/payload/platform/plugins/docs/references/plugins-guide.md +1 -1
- package/payload/platform/plugins/epc/.claude-plugin/plugin.json +17 -0
- package/payload/platform/plugins/epc/PLUGIN.md +85 -0
- package/payload/platform/plugins/epc/mcp/dist/index.d.ts +2 -0
- package/payload/platform/plugins/epc/mcp/dist/index.d.ts.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/index.js +117 -0
- package/payload/platform/plugins/epc/mcp/dist/index.js.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/crypto.d.ts +3 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/crypto.d.ts.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/crypto.js +72 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/crypto.js.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/epc-api.d.ts +60 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/epc-api.d.ts.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/epc-api.js +181 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/epc-api.js.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/file-crypto.d.ts +3 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/file-crypto.d.ts.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/file-crypto.js +49 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/file-crypto.js.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/key-store.d.ts +15 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/key-store.d.ts.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/key-store.js +130 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/key-store.js.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/neo4j.d.ts +5 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/neo4j.d.ts.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/neo4j.js +38 -0
- package/payload/platform/plugins/epc/mcp/dist/lib/neo4j.js.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/key-deregister.d.ts +4 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/key-deregister.d.ts.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/key-deregister.js +9 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/key-deregister.js.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/key-list.d.ts +4 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/key-list.d.ts.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/key-list.js +10 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/key-list.js.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/key-register.d.ts +5 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/key-register.d.ts.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/key-register.js +36 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/key-register.js.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/lookup.d.ts +10 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/lookup.d.ts.map +1 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/lookup.js +30 -0
- package/payload/platform/plugins/epc/mcp/dist/tools/lookup.js.map +1 -0
- package/payload/platform/plugins/epc/mcp/package-lock.json +2566 -0
- package/payload/platform/plugins/epc/mcp/package.json +21 -0
- package/payload/platform/plugins/epc/mcp/src/__tests__/epc-api.test.ts +251 -0
- package/payload/platform/plugins/epc/mcp/src/__tests__/key-roundtrip.test.ts +113 -0
- package/payload/platform/plugins/epc/mcp/src/__tests__/lookup.test.ts +181 -0
- package/payload/platform/plugins/epc/mcp/src/__tests__/schema-parity.test.ts +54 -0
- package/payload/platform/plugins/epc/mcp/src/index.ts +156 -0
- package/payload/platform/plugins/epc/mcp/src/lib/crypto.ts +79 -0
- package/payload/platform/plugins/epc/mcp/src/lib/epc-api.ts +241 -0
- package/payload/platform/plugins/epc/mcp/src/lib/file-crypto.ts +55 -0
- package/payload/platform/plugins/epc/mcp/src/lib/key-store.ts +172 -0
- package/payload/platform/plugins/epc/mcp/src/lib/neo4j.ts +47 -0
- package/payload/platform/plugins/epc/mcp/src/tools/key-deregister.ts +9 -0
- package/payload/platform/plugins/epc/mcp/src/tools/key-list.ts +10 -0
- package/payload/platform/plugins/epc/mcp/src/tools/key-register.ts +44 -0
- package/payload/platform/plugins/epc/mcp/src/tools/lookup.ts +43 -0
- package/payload/platform/plugins/epc/mcp/tsconfig.json +20 -0
- package/payload/platform/plugins/epc/mcp/vitest.config.ts +8 -0
- package/payload/platform/plugins/preval/.claude-plugin/plugin.json +1 -1
- package/payload/platform/plugins/preval/PLUGIN.md +25 -17
- package/payload/platform/plugins/preval/skills/property-preval/SKILL.md +107 -39
- package/payload/platform/plugins/preval/skills/property-preval/references/render.py +449 -84
- package/payload/platform/plugins/preval/skills/property-preval/references/template-inputs.schema.json +126 -80
- package/payload/platform/plugins/preval/skills/property-preval/references/template.html +183 -124
- package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.js +6 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.d.ts +7 -0
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.js +8 -0
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.js.map +1 -1
- package/payload/platform/templates/agents/admin/IDENTITY.md +1 -1
- package/payload/platform/templates/agents/admin/SOUL.md +1 -1
- package/payload/premium-plugins/real-agent/BUNDLE.md +4 -2
- package/payload/premium-plugins/real-agent/agents/valuer.md +1 -1
- package/payload/premium-plugins/real-agent/plugins/.claude-plugin/marketplace.json +5 -0
- package/payload/premium-plugins/real-agent/plugins/brochures/skills/property-brochure/SKILL.md +26 -3
- package/payload/premium-plugins/real-agent/plugins/brochures/skills/property-brochure/references/registers.md +1 -1
- package/payload/premium-plugins/real-agent/plugins/epc/.claude-plugin/plugin.json +17 -0
- package/payload/premium-plugins/real-agent/plugins/epc/PLUGIN.md +85 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/index.d.ts +2 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/index.d.ts.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/index.js +117 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/index.js.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/crypto.d.ts +3 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/crypto.d.ts.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/crypto.js +72 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/crypto.js.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/epc-api.d.ts +60 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/epc-api.d.ts.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/epc-api.js +181 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/epc-api.js.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/file-crypto.d.ts +3 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/file-crypto.d.ts.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/file-crypto.js +49 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/file-crypto.js.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/key-store.d.ts +15 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/key-store.d.ts.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/key-store.js +130 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/key-store.js.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/neo4j.d.ts +5 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/neo4j.d.ts.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/neo4j.js +38 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/lib/neo4j.js.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/key-deregister.d.ts +4 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/key-deregister.d.ts.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/key-deregister.js +9 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/key-deregister.js.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/key-list.d.ts +4 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/key-list.d.ts.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/key-list.js +10 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/key-list.js.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/key-register.d.ts +5 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/key-register.d.ts.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/key-register.js +36 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/key-register.js.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/lookup.d.ts +10 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/lookup.d.ts.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/lookup.js +30 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/dist/tools/lookup.js.map +1 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/package-lock.json +2566 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/package.json +21 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/src/__tests__/epc-api.test.ts +251 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/src/__tests__/key-roundtrip.test.ts +113 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/src/__tests__/lookup.test.ts +181 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/src/__tests__/schema-parity.test.ts +54 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/src/index.ts +156 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/src/lib/crypto.ts +79 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/src/lib/epc-api.ts +241 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/src/lib/file-crypto.ts +55 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/src/lib/key-store.ts +172 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/src/lib/neo4j.ts +47 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/src/tools/key-deregister.ts +9 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/src/tools/key-list.ts +10 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/src/tools/key-register.ts +44 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/src/tools/lookup.ts +43 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/tsconfig.json +20 -0
- package/payload/premium-plugins/real-agent/plugins/epc/mcp/vitest.config.ts +8 -0
- package/payload/premium-plugins/real-agent/plugins/preval/.claude-plugin/plugin.json +1 -1
- package/payload/premium-plugins/real-agent/plugins/preval/PLUGIN.md +25 -17
- package/payload/premium-plugins/real-agent/plugins/preval/skills/property-preval/SKILL.md +107 -39
- package/payload/premium-plugins/real-agent/plugins/preval/skills/property-preval/references/render.py +449 -84
- package/payload/premium-plugins/real-agent/plugins/preval/skills/property-preval/references/template-inputs.schema.json +126 -80
- package/payload/premium-plugins/real-agent/plugins/preval/skills/property-preval/references/template.html +183 -124
- package/payload/server/public/assets/{admin-Bp-BjBCX.js → admin-DhN3G8W7.js} +1 -1
- package/payload/server/public/assets/{data-BGUAGVkV.js → data-B2ZVXOcE.js} +1 -1
- package/payload/server/public/assets/{graph-MvYxZOBF.js → graph-BAMGPHrK.js} +1 -1
- package/payload/server/public/assets/{graph-labels-D865qb3K.js → graph-labels-D9eBbvxo.js} +1 -1
- package/payload/server/public/assets/{page-C2b1nlOc.js → page-CV27Al6Z.js} +1 -1
- package/payload/server/public/assets/{page--hOVRrgN.js → page-DjdVMWCz.js} +1 -1
- package/payload/server/public/data.html +3 -3
- package/payload/server/public/graph.html +3 -3
- package/payload/server/public/index.html +4 -4
- package/payload/server/server.js +3 -16
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Logging-tee was a platform-wrapper concern: the platform's mcp-spawn-tee
|
|
2
|
+
// pipes our stderr where it wants. In standalone mode (Claude Code native
|
|
3
|
+
// spawn) the host owns the stderr pipe. Either way, we just write to stderr.
|
|
4
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { keyRegister } from "./tools/key-register.js";
|
|
8
|
+
import { keyDeregister } from "./tools/key-deregister.js";
|
|
9
|
+
import { keyList } from "./tools/key-list.js";
|
|
10
|
+
import { epcLookupByAddress, epcLookupByUprn } from "./tools/lookup.js";
|
|
11
|
+
import { closeDriver } from "./lib/neo4j.js";
|
|
12
|
+
import { KeyNotRegisteredError, EpcError, BadResponseError, } from "./lib/epc-api.js";
|
|
13
|
+
import { selectKeyStore } from "./lib/key-store.js";
|
|
14
|
+
const accountId = process.env.ACCOUNT_ID ?? "local";
|
|
15
|
+
const server = new McpServer({
|
|
16
|
+
name: "maxy-epc",
|
|
17
|
+
version: "0.1.0",
|
|
18
|
+
});
|
|
19
|
+
const store = selectKeyStore();
|
|
20
|
+
console.error(`[epc] server started, account=${accountId} backend=${store.backendName} path=${store.backendPath}`);
|
|
21
|
+
function errorEnvelope(err) {
|
|
22
|
+
let text;
|
|
23
|
+
if (err instanceof KeyNotRegisteredError) {
|
|
24
|
+
text =
|
|
25
|
+
"Error: key-not-registered. Register an EPC API key with epc-key-register before calling this tool.";
|
|
26
|
+
}
|
|
27
|
+
else if (err instanceof EpcError) {
|
|
28
|
+
text = `Error: http-${err.status} from EPC register. ${err.upstreamMessage}`;
|
|
29
|
+
}
|
|
30
|
+
else if (err instanceof BadResponseError) {
|
|
31
|
+
text = `Error: bad-response from EPC register (non-JSON, length=${err.length}).`;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
text = `Error: ${err instanceof Error ? err.message : String(err)}`;
|
|
35
|
+
}
|
|
36
|
+
return { content: [{ type: "text", text }], isError: true };
|
|
37
|
+
}
|
|
38
|
+
// ─────────────────────────────────────────────────────────────────
|
|
39
|
+
// Key management
|
|
40
|
+
// ─────────────────────────────────────────────────────────────────
|
|
41
|
+
server.tool("epc-key-register", "Register the account's EPC register credential. The credential is the email that generated the API key on the EPC dashboard, a colon, then the API key (format: email:api-key). Validates against the EPC register, encrypts with AES-256-GCM, and stores in Neo4j. One credential per account; re-registering overwrites.", {
|
|
42
|
+
apiKey: z
|
|
43
|
+
.string()
|
|
44
|
+
.min(8)
|
|
45
|
+
.describe("EPC credential in the form email:api-key. The email is the account that generated the key at epc.opendatacommunities.org."),
|
|
46
|
+
}, async ({ apiKey }) => {
|
|
47
|
+
try {
|
|
48
|
+
await keyRegister({ apiKey, accountId });
|
|
49
|
+
return {
|
|
50
|
+
content: [
|
|
51
|
+
{ type: "text", text: "EPC API key registered successfully." },
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
return errorEnvelope(err);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
server.tool("epc-key-deregister", "Remove the account's EPC API credential. The encrypted credential is permanently deleted from Neo4j.", {}, async () => {
|
|
60
|
+
try {
|
|
61
|
+
await keyDeregister({ accountId });
|
|
62
|
+
return {
|
|
63
|
+
content: [{ type: "text", text: "EPC API key deregistered." }],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
return errorEnvelope(err);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
server.tool("epc-key-list", "Show whether an EPC API credential is registered for this account. Never reveals the credential value.", {}, async () => {
|
|
71
|
+
try {
|
|
72
|
+
const text = await keyList({ accountId });
|
|
73
|
+
return { content: [{ type: "text", text }] };
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
return errorEnvelope(err);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
// ─────────────────────────────────────────────────────────────────
|
|
80
|
+
// Lookup
|
|
81
|
+
// ─────────────────────────────────────────────────────────────────
|
|
82
|
+
server.tool("epc-lookup-by-address", "Look up the most recent Energy Performance Certificate per matched property for a UK address. Returns total_floor_area_m2, total_floor_area_sqft (m² × 10.7639), current and potential energy ratings, lodgement date, address, and UPRN. Multiple matches surface as an array. Zero matches return an empty array with status ok. Use to derive subject-property sqft for preval valuation.", {
|
|
83
|
+
address: z.string().min(2).describe("UK address line one (street and house number / name)"),
|
|
84
|
+
postcode: z
|
|
85
|
+
.string()
|
|
86
|
+
.optional()
|
|
87
|
+
.describe("Full UK postcode (optional but recommended to narrow matches)"),
|
|
88
|
+
}, async ({ address, postcode }) => {
|
|
89
|
+
try {
|
|
90
|
+
const text = await epcLookupByAddress({ accountId, address, postcode });
|
|
91
|
+
return { content: [{ type: "text", text }] };
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
return errorEnvelope(err);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
server.tool("epc-lookup-by-uprn", "Look up the most recent Energy Performance Certificate for a specific UPRN. Returns the same shape as epc-lookup-by-address. Use when the property's UPRN is already known from property-data-address-match-uprn or Land Registry.", {
|
|
98
|
+
uprn: z.string().min(1).describe("UK Unique Property Reference Number"),
|
|
99
|
+
}, async ({ uprn }) => {
|
|
100
|
+
try {
|
|
101
|
+
const text = await epcLookupByUprn({ accountId, uprn });
|
|
102
|
+
return { content: [{ type: "text", text }] };
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
return errorEnvelope(err);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
// ─────────────────────────────────────────────────────────────────
|
|
109
|
+
// Lifecycle
|
|
110
|
+
// ─────────────────────────────────────────────────────────────────
|
|
111
|
+
process.on("SIGINT", async () => {
|
|
112
|
+
await closeDriver();
|
|
113
|
+
process.exit(0);
|
|
114
|
+
});
|
|
115
|
+
const transport = new StdioServerTransport();
|
|
116
|
+
await server.connect(transport);
|
|
117
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,0EAA0E;AAC1E,6EAA6E;AAE7E,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,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AAG,MAAM,eAAe,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACxD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IACxD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC,CACF,CAAC;AAEF,oEAAoE;AACpE,YAAY;AACZ,oEAAoE;AAEpE,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC9B,MAAM,WAAW,EAAE,CAAC;IACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;AAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/lib/crypto.ts"],"names":[],"mappings":"AAgDA,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAQjD;AAED,wBAAgB,OAAO,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAoBtD"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { randomBytes, createCipheriv, createDecipheriv } from "node:crypto";
|
|
2
|
+
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
const ALGORITHM = "aes-256-gcm";
|
|
6
|
+
const KEY_LENGTH = 32;
|
|
7
|
+
const IV_LENGTH = 12;
|
|
8
|
+
const AUTH_TAG_LENGTH = 16;
|
|
9
|
+
const KEY_FILE_NAME = ".epc-encryption-key";
|
|
10
|
+
function resolveConfigDir() {
|
|
11
|
+
try {
|
|
12
|
+
const platformRoot = process.env.PLATFORM_ROOT;
|
|
13
|
+
if (platformRoot) {
|
|
14
|
+
const brandPath = resolve(platformRoot, "config/brand.json");
|
|
15
|
+
const brand = JSON.parse(readFileSync(brandPath, "utf-8"));
|
|
16
|
+
if (brand.configDir)
|
|
17
|
+
return brand.configDir;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Fall back to default
|
|
22
|
+
}
|
|
23
|
+
return ".maxy";
|
|
24
|
+
}
|
|
25
|
+
function keyFilePath() {
|
|
26
|
+
return resolve(homedir(), resolveConfigDir(), KEY_FILE_NAME);
|
|
27
|
+
}
|
|
28
|
+
function loadOrGenerateKey() {
|
|
29
|
+
const path = keyFilePath();
|
|
30
|
+
if (existsSync(path)) {
|
|
31
|
+
const hex = readFileSync(path, "utf-8").trim();
|
|
32
|
+
const buf = Buffer.from(hex, "hex");
|
|
33
|
+
if (buf.length !== KEY_LENGTH) {
|
|
34
|
+
throw new Error(`Encryption key at ${path} is ${buf.length} bytes, expected ${KEY_LENGTH}. ` +
|
|
35
|
+
`Delete the file and re-register the EPC API key.`);
|
|
36
|
+
}
|
|
37
|
+
return buf;
|
|
38
|
+
}
|
|
39
|
+
const key = randomBytes(KEY_LENGTH);
|
|
40
|
+
writeFileSync(path, key.toString("hex"), { mode: 0o600 });
|
|
41
|
+
console.error(`[epc] encryption key generated at ${path}`);
|
|
42
|
+
return key;
|
|
43
|
+
}
|
|
44
|
+
export function encrypt(plaintext) {
|
|
45
|
+
const key = loadOrGenerateKey();
|
|
46
|
+
const iv = randomBytes(IV_LENGTH);
|
|
47
|
+
const cipher = createCipheriv(ALGORITHM, key, iv, { authTagLength: AUTH_TAG_LENGTH });
|
|
48
|
+
let encrypted = cipher.update(plaintext, "utf-8", "hex");
|
|
49
|
+
encrypted += cipher.final("hex");
|
|
50
|
+
const authTag = cipher.getAuthTag().toString("hex");
|
|
51
|
+
return `${iv.toString("hex")}:${encrypted}:${authTag}`;
|
|
52
|
+
}
|
|
53
|
+
export function decrypt(encryptedValue) {
|
|
54
|
+
const parts = encryptedValue.split(":");
|
|
55
|
+
if (parts.length !== 3) {
|
|
56
|
+
throw new Error("Malformed encrypted value — expected iv:ciphertext:authTag");
|
|
57
|
+
}
|
|
58
|
+
const [ivHex, ciphertextHex, authTagHex] = parts;
|
|
59
|
+
const path = keyFilePath();
|
|
60
|
+
if (!existsSync(path)) {
|
|
61
|
+
throw new Error(`Encryption key not found at ${path}. The stored EPC API key is unrecoverable. Re-register.`);
|
|
62
|
+
}
|
|
63
|
+
const key = loadOrGenerateKey();
|
|
64
|
+
const iv = Buffer.from(ivHex, "hex");
|
|
65
|
+
const authTag = Buffer.from(authTagHex, "hex");
|
|
66
|
+
const decipher = createDecipheriv(ALGORITHM, key, iv, { authTagLength: AUTH_TAG_LENGTH });
|
|
67
|
+
decipher.setAuthTag(authTag);
|
|
68
|
+
let decrypted = decipher.update(ciphertextHex, "hex", "utf-8");
|
|
69
|
+
decrypted += decipher.final("utf-8");
|
|
70
|
+
return decrypted;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/lib/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,SAAS,GAAG,aAAa,CAAC;AAChC,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,aAAa,GAAG,qBAAqB,CAAC;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,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,gBAAgB,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC,CAAC;IAC1F,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC7B,IAAI,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAC/D,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export declare const BASE_URL = "https://epc.opendatacommunities.org/api/v1";
|
|
2
|
+
export declare const REQUEST_TIMEOUT_MS = 15000;
|
|
3
|
+
export declare const M2_TO_SQFT = 10.7639;
|
|
4
|
+
export declare class KeyNotRegisteredError extends Error {
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
export declare class EpcError extends Error {
|
|
8
|
+
readonly status: number;
|
|
9
|
+
readonly endpoint: string;
|
|
10
|
+
readonly upstreamMessage: string;
|
|
11
|
+
constructor(status: number, endpoint: string, upstreamMessage: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class BadResponseError extends Error {
|
|
14
|
+
readonly endpoint: string;
|
|
15
|
+
readonly length: number;
|
|
16
|
+
constructor(endpoint: string, length: number);
|
|
17
|
+
}
|
|
18
|
+
export interface EpcKeyMeta {
|
|
19
|
+
createdAt: string;
|
|
20
|
+
updatedAt: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function loadAccountKey(accountId: string): Promise<EpcKeyMeta | null>;
|
|
23
|
+
export declare function resolveAccountApiKey(accountId: string): Promise<string>;
|
|
24
|
+
export interface EpcRow {
|
|
25
|
+
"lmk-key"?: string;
|
|
26
|
+
address1?: string;
|
|
27
|
+
address2?: string;
|
|
28
|
+
address3?: string;
|
|
29
|
+
posttown?: string;
|
|
30
|
+
postcode?: string;
|
|
31
|
+
uprn?: string;
|
|
32
|
+
"current-energy-rating"?: string;
|
|
33
|
+
"potential-energy-rating"?: string;
|
|
34
|
+
"lodgement-date"?: string;
|
|
35
|
+
"total-floor-area"?: string;
|
|
36
|
+
[k: string]: unknown;
|
|
37
|
+
}
|
|
38
|
+
export interface EpcSearchOptions {
|
|
39
|
+
toolName: string;
|
|
40
|
+
accountId: string;
|
|
41
|
+
identifier: string;
|
|
42
|
+
params: Record<string, string | number | undefined>;
|
|
43
|
+
}
|
|
44
|
+
interface CallResult {
|
|
45
|
+
status: number;
|
|
46
|
+
rows: EpcRow[];
|
|
47
|
+
}
|
|
48
|
+
export declare function epcSearch(opts: EpcSearchOptions): Promise<CallResult>;
|
|
49
|
+
export interface EpcMatch {
|
|
50
|
+
total_floor_area_m2: number | null;
|
|
51
|
+
total_floor_area_sqft: number | null;
|
|
52
|
+
current_energy_rating: string | null;
|
|
53
|
+
potential_energy_rating: string | null;
|
|
54
|
+
lodgement_date: string | null;
|
|
55
|
+
address: string;
|
|
56
|
+
uprn: string | null;
|
|
57
|
+
}
|
|
58
|
+
export declare function groupAndPickMostRecent(rows: EpcRow[]): EpcMatch[];
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=epc-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"epc-api.d.ts","sourceRoot":"","sources":["../../src/lib/epc-api.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,QAAQ,+CAA+C,CAAC;AACrE,eAAO,MAAM,kBAAkB,QAAS,CAAC;AACzC,eAAO,MAAM,UAAU,UAAU,CAAC;AAElC,qBAAa,qBAAsB,SAAQ,KAAK;;CAK/C;AAED,qBAAa,QAAS,SAAQ,KAAK;aAEf,MAAM,EAAE,MAAM;aACd,QA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;AAED,UAAU,UAAU;IAGlB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,wBAAsB,SAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAiE3E;AAED,MAAM,WAAW,QAAQ;IACvB,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,uBAAuB,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAsBD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAuCjE"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { selectKeyStore } from "./key-store.js";
|
|
2
|
+
// gov.uk EPC register HTTP client. The register lives at
|
|
3
|
+
// epc.opendatacommunities.org and is reached via Basic auth where the
|
|
4
|
+
// credential is `<email>:<api-key>` (the email is the account that
|
|
5
|
+
// generated the key on the dashboard). We store the credential as a single
|
|
6
|
+
// colon-joined string so the key-management surface mirrors property-data
|
|
7
|
+
// exactly (one `apiKey` field per account).
|
|
8
|
+
//
|
|
9
|
+
// Response shape (domestic/search):
|
|
10
|
+
// { "column-names": [...], "rows": [ { "lmk-key": "...",
|
|
11
|
+
// "address1": "...", "address2": "...", "address3": "...",
|
|
12
|
+
// "posttown": "...", "postcode": "...", "uprn": "...",
|
|
13
|
+
// "current-energy-rating": "C", "potential-energy-rating": "B",
|
|
14
|
+
// "lodgement-date": "2023-05-15", "total-floor-area": "75.0", ... } ] }
|
|
15
|
+
//
|
|
16
|
+
// Multiple EPCs per property appear as separate rows (one per lodgement).
|
|
17
|
+
// Callers group by UPRN (or address fallback) and pick the most-recent
|
|
18
|
+
// row per property.
|
|
19
|
+
export const BASE_URL = "https://epc.opendatacommunities.org/api/v1";
|
|
20
|
+
export const REQUEST_TIMEOUT_MS = 15_000;
|
|
21
|
+
export const M2_TO_SQFT = 10.7639;
|
|
22
|
+
export class KeyNotRegisteredError extends Error {
|
|
23
|
+
constructor() {
|
|
24
|
+
super("key-not-registered");
|
|
25
|
+
this.name = "KeyNotRegisteredError";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class EpcError extends Error {
|
|
29
|
+
status;
|
|
30
|
+
endpoint;
|
|
31
|
+
upstreamMessage;
|
|
32
|
+
constructor(status, endpoint, upstreamMessage) {
|
|
33
|
+
super(`http-${status} from EPC endpoint=${endpoint}: ${upstreamMessage}`);
|
|
34
|
+
this.status = status;
|
|
35
|
+
this.endpoint = endpoint;
|
|
36
|
+
this.upstreamMessage = upstreamMessage;
|
|
37
|
+
this.name = "EpcError";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export class BadResponseError extends Error {
|
|
41
|
+
endpoint;
|
|
42
|
+
length;
|
|
43
|
+
constructor(endpoint, length) {
|
|
44
|
+
super(`bad-response from EPC endpoint=${endpoint} (non-JSON, length=${length})`);
|
|
45
|
+
this.endpoint = endpoint;
|
|
46
|
+
this.length = length;
|
|
47
|
+
this.name = "BadResponseError";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export async function loadAccountKey(accountId) {
|
|
51
|
+
const stored = await selectKeyStore().load(accountId);
|
|
52
|
+
if (!stored)
|
|
53
|
+
return null;
|
|
54
|
+
return { createdAt: stored.createdAt, updatedAt: stored.updatedAt };
|
|
55
|
+
}
|
|
56
|
+
export async function resolveAccountApiKey(accountId) {
|
|
57
|
+
const envKey = process.env.EPC_API_KEY;
|
|
58
|
+
if (envKey && envKey.trim())
|
|
59
|
+
return envKey.trim();
|
|
60
|
+
const stored = await selectKeyStore().load(accountId);
|
|
61
|
+
if (!stored)
|
|
62
|
+
throw new KeyNotRegisteredError();
|
|
63
|
+
return stored.apiKey;
|
|
64
|
+
}
|
|
65
|
+
function basicAuthHeader(credential) {
|
|
66
|
+
return `Basic ${Buffer.from(credential, "utf-8").toString("base64")}`;
|
|
67
|
+
}
|
|
68
|
+
export async function epcSearch(opts) {
|
|
69
|
+
const { toolName, accountId, identifier, params } = opts;
|
|
70
|
+
const credential = await resolveAccountApiKey(accountId);
|
|
71
|
+
const search = new URLSearchParams();
|
|
72
|
+
for (const [k, v] of Object.entries(params)) {
|
|
73
|
+
if (v === undefined || v === null || v === "")
|
|
74
|
+
continue;
|
|
75
|
+
search.set(k, String(v));
|
|
76
|
+
}
|
|
77
|
+
const endpoint = "domestic/search";
|
|
78
|
+
const url = `${BASE_URL}/${endpoint}?${search.toString()}`;
|
|
79
|
+
const start = Date.now();
|
|
80
|
+
const response = await fetch(url, {
|
|
81
|
+
headers: {
|
|
82
|
+
Accept: "application/json",
|
|
83
|
+
Authorization: basicAuthHeader(credential),
|
|
84
|
+
},
|
|
85
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
86
|
+
});
|
|
87
|
+
const ms = Date.now() - start;
|
|
88
|
+
const statusTag = response.ok
|
|
89
|
+
? "ok"
|
|
90
|
+
: response.status === 404
|
|
91
|
+
? "http-404"
|
|
92
|
+
: `http-${Math.floor(response.status / 100)}xx`;
|
|
93
|
+
console.error(`[epc] tool=${toolName} account=${accountId} address="${identifier}" status=${statusTag} ms=${ms}`);
|
|
94
|
+
// 404 is a valid outcome — no EPC on file for the address. Surface to the
|
|
95
|
+
// caller as an empty result set; the wrapper turns it into ok+[].
|
|
96
|
+
if (response.status === 404) {
|
|
97
|
+
return { status: 404, rows: [] };
|
|
98
|
+
}
|
|
99
|
+
if (!response.ok) {
|
|
100
|
+
const body = await response.text().catch(() => "");
|
|
101
|
+
throw new EpcError(response.status, endpoint, body.slice(0, 200));
|
|
102
|
+
}
|
|
103
|
+
const text = await response.text();
|
|
104
|
+
let parsed;
|
|
105
|
+
try {
|
|
106
|
+
parsed = JSON.parse(text);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
throw new BadResponseError(endpoint, text.length);
|
|
110
|
+
}
|
|
111
|
+
if (!parsed ||
|
|
112
|
+
typeof parsed !== "object" ||
|
|
113
|
+
Array.isArray(parsed) ||
|
|
114
|
+
!("rows" in parsed)) {
|
|
115
|
+
throw new BadResponseError(endpoint, text.length);
|
|
116
|
+
}
|
|
117
|
+
const rows = parsed.rows;
|
|
118
|
+
if (!Array.isArray(rows)) {
|
|
119
|
+
throw new BadResponseError(endpoint, text.length);
|
|
120
|
+
}
|
|
121
|
+
return { status: response.status, rows: rows };
|
|
122
|
+
}
|
|
123
|
+
// Compose the human-readable address from the upstream row's parts. Empty
|
|
124
|
+
// segments are dropped; segments are uppercase in the API and join with
|
|
125
|
+
// ", ".
|
|
126
|
+
function rowAddress(row) {
|
|
127
|
+
const parts = [row.address1, row.address2, row.address3, row.posttown, row.postcode]
|
|
128
|
+
.map((s) => (typeof s === "string" ? s.trim() : ""))
|
|
129
|
+
.filter((s) => s.length > 0);
|
|
130
|
+
return parts.join(", ");
|
|
131
|
+
}
|
|
132
|
+
function parseFloorArea(row) {
|
|
133
|
+
const raw = row["total-floor-area"];
|
|
134
|
+
if (raw == null || raw === "")
|
|
135
|
+
return null;
|
|
136
|
+
const n = Number(raw);
|
|
137
|
+
return Number.isFinite(n) ? n : null;
|
|
138
|
+
}
|
|
139
|
+
// Group rows by UPRN (or address1+postcode when UPRN is absent), then pick
|
|
140
|
+
// the most-recent EPC per group by lodgement date. Rows with no lodgement
|
|
141
|
+
// date sort last.
|
|
142
|
+
export function groupAndPickMostRecent(rows) {
|
|
143
|
+
const buckets = new Map();
|
|
144
|
+
for (const row of rows) {
|
|
145
|
+
const uprn = typeof row.uprn === "string" ? row.uprn.trim() : "";
|
|
146
|
+
const key = uprn || `${row.address1 ?? ""}|${row.postcode ?? ""}`.toLowerCase();
|
|
147
|
+
const existing = buckets.get(key);
|
|
148
|
+
if (existing)
|
|
149
|
+
existing.push(row);
|
|
150
|
+
else
|
|
151
|
+
buckets.set(key, [row]);
|
|
152
|
+
}
|
|
153
|
+
const out = [];
|
|
154
|
+
for (const bucket of buckets.values()) {
|
|
155
|
+
bucket.sort((a, b) => {
|
|
156
|
+
const da = String(a["lodgement-date"] ?? "");
|
|
157
|
+
const db = String(b["lodgement-date"] ?? "");
|
|
158
|
+
// Most-recent first: ISO dates string-sort correctly.
|
|
159
|
+
return db.localeCompare(da);
|
|
160
|
+
});
|
|
161
|
+
const winner = bucket[0];
|
|
162
|
+
const m2 = parseFloorArea(winner);
|
|
163
|
+
out.push({
|
|
164
|
+
total_floor_area_m2: m2,
|
|
165
|
+
total_floor_area_sqft: m2 == null ? null : Number((m2 * M2_TO_SQFT).toFixed(2)),
|
|
166
|
+
current_energy_rating: typeof winner["current-energy-rating"] === "string"
|
|
167
|
+
? winner["current-energy-rating"]
|
|
168
|
+
: null,
|
|
169
|
+
potential_energy_rating: typeof winner["potential-energy-rating"] === "string"
|
|
170
|
+
? winner["potential-energy-rating"]
|
|
171
|
+
: null,
|
|
172
|
+
lodgement_date: typeof winner["lodgement-date"] === "string"
|
|
173
|
+
? winner["lodgement-date"]
|
|
174
|
+
: null,
|
|
175
|
+
address: rowAddress(winner),
|
|
176
|
+
uprn: typeof winner.uprn === "string" && winner.uprn.length > 0 ? winner.uprn : null,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=epc-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"epc-api.js","sourceRoot":"","sources":["../../src/lib/epc-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,yDAAyD;AACzD,sEAAsE;AACtE,mEAAmE;AACnE,2EAA2E;AAC3E,0EAA0E;AAC1E,4CAA4C;AAC5C,EA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,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;SACrF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-crypto.d.ts","sourceRoot":"","sources":["../../src/lib/file-crypto.ts"],"names":[],"mappings":"AA8BA,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAQzF;AAED,wBAAgB,WAAW,CAAC,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAc9F"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { randomBytes, createCipheriv, createDecipheriv } from "node:crypto";
|
|
2
|
+
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
3
|
+
// Standalone-mode crypto. Same AES-256-GCM envelope as crypto.ts, but the
|
|
4
|
+
// encryption-key file path is passed in (not derived from PLATFORM_ROOT /
|
|
5
|
+
// brand.json), so it can live under ~/.claude/ when the MCP is spawned by
|
|
6
|
+
// Claude Code natively.
|
|
7
|
+
const ALGORITHM = "aes-256-gcm";
|
|
8
|
+
const KEY_LENGTH = 32;
|
|
9
|
+
const IV_LENGTH = 12;
|
|
10
|
+
const AUTH_TAG_LENGTH = 16;
|
|
11
|
+
function loadOrGenerateKey(keyFilePath, label) {
|
|
12
|
+
if (existsSync(keyFilePath)) {
|
|
13
|
+
const hex = readFileSync(keyFilePath, "utf-8").trim();
|
|
14
|
+
const buf = Buffer.from(hex, "hex");
|
|
15
|
+
if (buf.length !== KEY_LENGTH) {
|
|
16
|
+
throw new Error(`[${label}] encryption key at ${keyFilePath} is ${buf.length} bytes, expected ${KEY_LENGTH}.`);
|
|
17
|
+
}
|
|
18
|
+
return buf;
|
|
19
|
+
}
|
|
20
|
+
const key = randomBytes(KEY_LENGTH);
|
|
21
|
+
writeFileSync(keyFilePath, key.toString("hex"), { mode: 0o600 });
|
|
22
|
+
console.error(`[${label}] encryption key generated at ${keyFilePath}`);
|
|
23
|
+
return key;
|
|
24
|
+
}
|
|
25
|
+
export function encryptWith(plaintext, keyFilePath, label) {
|
|
26
|
+
const key = loadOrGenerateKey(keyFilePath, label);
|
|
27
|
+
const iv = randomBytes(IV_LENGTH);
|
|
28
|
+
const cipher = createCipheriv(ALGORITHM, key, iv, { authTagLength: AUTH_TAG_LENGTH });
|
|
29
|
+
let encrypted = cipher.update(plaintext, "utf-8", "hex");
|
|
30
|
+
encrypted += cipher.final("hex");
|
|
31
|
+
const authTag = cipher.getAuthTag().toString("hex");
|
|
32
|
+
return `${iv.toString("hex")}:${encrypted}:${authTag}`;
|
|
33
|
+
}
|
|
34
|
+
export function decryptWith(encryptedValue, keyFilePath, label) {
|
|
35
|
+
const parts = encryptedValue.split(":");
|
|
36
|
+
if (parts.length !== 3) {
|
|
37
|
+
throw new Error(`[${label}] bad encrypted envelope (expected iv:ct:tag)`);
|
|
38
|
+
}
|
|
39
|
+
const key = loadOrGenerateKey(keyFilePath, label);
|
|
40
|
+
const iv = Buffer.from(parts[0], "hex");
|
|
41
|
+
const ciphertext = parts[1];
|
|
42
|
+
const authTag = Buffer.from(parts[2], "hex");
|
|
43
|
+
const decipher = createDecipheriv(ALGORITHM, key, iv, { authTagLength: AUTH_TAG_LENGTH });
|
|
44
|
+
decipher.setAuthTag(authTag);
|
|
45
|
+
let plaintext = decipher.update(ciphertext, "hex", "utf-8");
|
|
46
|
+
plaintext += decipher.final("utf-8");
|
|
47
|
+
return plaintext;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=file-crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-crypto.js","sourceRoot":"","sources":["../../src/lib/file-crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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AAC;IAC7B,IAAI,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAC5D,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface StoredKey {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
createdAt: string;
|
|
4
|
+
updatedAt: string;
|
|
5
|
+
}
|
|
6
|
+
export interface KeyStore {
|
|
7
|
+
readonly backendName: string;
|
|
8
|
+
readonly backendPath: string;
|
|
9
|
+
load(accountId: string): Promise<StoredKey | null>;
|
|
10
|
+
save(accountId: string, apiKey: string): Promise<void>;
|
|
11
|
+
delete(accountId: string): Promise<boolean>;
|
|
12
|
+
}
|
|
13
|
+
export declare function selectKeyStore(): KeyStore;
|
|
14
|
+
export declare function _resetKeyStoreForTests(): void;
|
|
15
|
+
//# sourceMappingURL=key-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-store.d.ts","sourceRoot":"","sources":["../../src/lib/key-store.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IACnD,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7C;AA0ID,wBAAgB,cAAc,IAAI,QAAQ,CAIzC;AAED,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C"}
|