@pagaqr/mcp 0.0.0-stage → 0.7.1

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +9 -0
  4. package/README.md +99 -2
  5. package/dist/capture-cli.d.ts +2 -0
  6. package/dist/capture-cli.js +34 -0
  7. package/dist/capture-local.d.ts +9 -0
  8. package/dist/capture-local.js +18 -0
  9. package/dist/capture-store.d.ts +7 -0
  10. package/dist/capture-store.js +175 -0
  11. package/dist/catalogue.d.ts +33 -0
  12. package/dist/catalogue.js +78 -0
  13. package/dist/cli.d.ts +2 -0
  14. package/dist/cli.js +27 -0
  15. package/dist/diagnose.d.ts +23 -0
  16. package/dist/diagnose.js +93 -0
  17. package/dist/index.d.ts +9 -0
  18. package/dist/index.js +134 -0
  19. package/dist/invocation-log.d.ts +9 -0
  20. package/dist/invocation-log.js +70 -0
  21. package/dist/masked-terminal.d.ts +4 -0
  22. package/dist/masked-terminal.js +71 -0
  23. package/dist/next-postgres.json +99 -0
  24. package/dist/sbom.cdx.json +523 -0
  25. package/dist/setup/database.d.ts +7 -0
  26. package/dist/setup/database.js +83 -0
  27. package/dist/setup/notice.d.ts +2 -0
  28. package/dist/setup/notice.js +2 -0
  29. package/dist/setup/run.d.ts +25 -0
  30. package/dist/setup/run.js +215 -0
  31. package/dist/setup/runtime.js +837 -0
  32. package/dist/setup/state.d.ts +7 -0
  33. package/dist/setup/state.js +81 -0
  34. package/dist/setup/step.d.ts +59 -0
  35. package/dist/setup/step.js +9 -0
  36. package/dist/setup/steps/pey.d.ts +8 -0
  37. package/dist/setup/steps/pey.js +271 -0
  38. package/dist/setup/steps/vercel.d.ts +5 -0
  39. package/dist/setup/steps/vercel.js +375 -0
  40. package/dist/setup/store-secrets.d.ts +3 -0
  41. package/dist/setup/store-secrets.js +67 -0
  42. package/dist/setup/terminal-guard.d.ts +9 -0
  43. package/dist/setup/terminal-guard.js +17 -0
  44. package/dist/setup/verify.d.ts +34 -0
  45. package/dist/setup/verify.js +144 -0
  46. package/dist/setup-cli.d.ts +2 -0
  47. package/dist/setup-cli.js +70 -0
  48. package/dist/template.d.ts +4 -0
  49. package/dist/template.js +119 -0
  50. package/dist/webhook.d.ts +1 -0
  51. package/dist/webhook.js +30 -0
  52. package/package.json +51 -3
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env node
2
+ import { argv, cwd, env, stdin, stdout } from "node:process";
3
+ import { resolveProjectDirectory } from "./diagnose.js";
4
+ import { readMasked } from "./masked-terminal.js";
5
+ import { databaseStep } from "./setup/database.js";
6
+ import { runSetup } from "./setup/run.js";
7
+ import { installationFile, installationRefusal, PRIVATE_FILE, PROGRESS_FILE } from "./setup/state.js";
8
+ import { peyStep } from "./setup/steps/pey.js";
9
+ import { vercelStep } from "./setup/steps/vercel.js";
10
+ import { storeSecretsStep } from "./setup/store-secrets.js";
11
+ import { verifyStep } from "./setup/verify.js";
12
+ async function start() {
13
+ const abort = new AbortController();
14
+ const cancel = () => abort.abort();
15
+ process.once("SIGINT", cancel);
16
+ try {
17
+ const projectDir = cwd();
18
+ return await runSetup({
19
+ stdinTTY: stdin.isTTY === true,
20
+ stdoutTTY: stdout.isTTY === true,
21
+ args: argv.slice(2),
22
+ env,
23
+ projectDir,
24
+ fetch,
25
+ signal: abort.signal,
26
+ terminal: {
27
+ write: (line) => stdout.write(line + "\n"),
28
+ async read(prompt, kind) {
29
+ const buffer = await readMasked(stdin, () => stdout.write(prompt + "\n"), kind === "text");
30
+ if (!buffer)
31
+ return undefined;
32
+ try {
33
+ return buffer.toString("utf8");
34
+ }
35
+ finally {
36
+ buffer.fill(0);
37
+ }
38
+ },
39
+ },
40
+ async open() {
41
+ const root = resolveProjectDirectory(projectDir);
42
+ if (!root)
43
+ throw new Error("Cannot resolve the storefront directory");
44
+ const refusal = installationRefusal(root);
45
+ if (refusal)
46
+ return { refusal };
47
+ const privateFile = installationFile(root, PRIVATE_FILE);
48
+ const runtime = (await import(new URL("./setup/runtime.js", import.meta.url).href));
49
+ return {
50
+ memory: installationFile(root, PROGRESS_FILE),
51
+ steps: [
52
+ peyStep,
53
+ databaseStep(runtime, privateFile),
54
+ storeSecretsStep(privateFile),
55
+ vercelStep,
56
+ verifyStep(runtime.verifyDeployment, undefined, privateFile),
57
+ ],
58
+ };
59
+ },
60
+ });
61
+ }
62
+ finally {
63
+ process.off("SIGINT", cancel);
64
+ }
65
+ }
66
+ void start().then((code) => {
67
+ process.exitCode = code;
68
+ }, () => {
69
+ process.exitCode = 2;
70
+ });
@@ -0,0 +1,4 @@
1
+ export declare const TEMPLATE_DIRECTORY = "pagaqr-installation";
2
+ type TemplateStatus = "prepared" | "conflict" | "dependency_outside_catalogue" | "unavailable";
3
+ export declare function bindTemplate(root: string | undefined): () => TemplateStatus;
4
+ export {};
@@ -0,0 +1,119 @@
1
+ import { closeSync, fstatSync, mkdirSync, openSync, lstatSync, readFileSync, realpathSync, rmdirSync, unlinkSync, writeFileSync, } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { usesCatalogue } from "./catalogue.js";
4
+ import { readProjectManifest } from "./diagnose.js";
5
+ export const TEMPLATE_DIRECTORY = "pagaqr-installation";
6
+ // The package ships a snapshot of the demo source. Applying it never executes the store.
7
+ function templateFiles() {
8
+ return JSON.parse(readFileSync(new URL("../dist/next-postgres.json", import.meta.url), "utf8"));
9
+ }
10
+ function currentDirectory(path) {
11
+ const stat = lstatSync(path);
12
+ return stat.isDirectory() && realpathSync(path) === path ? stat : undefined;
13
+ }
14
+ function sameIdentity(current, original) {
15
+ return current.dev === original.dev && current.ino === original.ino;
16
+ }
17
+ function sameDirectory(path, original) {
18
+ const current = currentDirectory(path);
19
+ return current !== undefined && sameIdentity(current, original);
20
+ }
21
+ function directoryGuard(destination, directories, relative) {
22
+ const segments = relative ? relative.split("/") : [];
23
+ for (let length = 0; length <= segments.length; length++) {
24
+ const name = segments.slice(0, length).join("/");
25
+ const identity = directories.get(name);
26
+ if (!identity || !sameDirectory(join(destination, name), identity)) {
27
+ throw new Error("Template directory changed");
28
+ }
29
+ }
30
+ }
31
+ function writeTemplate(root) {
32
+ const project = readProjectManifest(root);
33
+ if (project.status !== "found")
34
+ return "unavailable";
35
+ if (!usesCatalogue(project.manifest))
36
+ return "dependency_outside_catalogue";
37
+ const files = templateFiles();
38
+ const directory = join(root, TEMPLATE_DIRECTORY);
39
+ try {
40
+ mkdirSync(directory, { mode: 0o700 });
41
+ }
42
+ catch (error) {
43
+ return error instanceof Error && "code" in error && error.code === "EEXIST" ? "conflict" : "unavailable";
44
+ }
45
+ const original = currentDirectory(directory);
46
+ if (!original)
47
+ return "unavailable";
48
+ const owned = [];
49
+ const directories = new Map([["", original]]);
50
+ try {
51
+ for (const [name, contents] of Object.entries(files)) {
52
+ const segments = name.split("/");
53
+ if (segments.some((part) => !/^(?:[A-Za-z0-9._-]+|\[[A-Za-z0-9_-]+\])$/.test(part) || part === "." || part === "..")) {
54
+ throw new Error("Invalid packaged template path");
55
+ }
56
+ let parent = "";
57
+ for (const part of segments.slice(0, -1)) {
58
+ directoryGuard(directory, directories, parent);
59
+ const relative = parent ? parent + "/" + part : part;
60
+ if (!directories.has(relative)) {
61
+ const path = join(directory, relative);
62
+ mkdirSync(path, { mode: 0o700 });
63
+ const identity = currentDirectory(path);
64
+ if (!identity)
65
+ throw new Error("Template directory changed");
66
+ directories.set(relative, identity);
67
+ owned.push({ path, identity, parent, directory: true });
68
+ }
69
+ parent = relative;
70
+ }
71
+ directoryGuard(directory, directories, parent);
72
+ const output = join(directory, name);
73
+ const fd = openSync(output, "wx", 0o600);
74
+ try {
75
+ owned.push({ path: output, identity: fstatSync(fd), parent, directory: false });
76
+ writeFileSync(fd, contents);
77
+ }
78
+ finally {
79
+ closeSync(fd);
80
+ }
81
+ }
82
+ return "prepared";
83
+ }
84
+ catch {
85
+ for (const { path, identity, parent, directory: isDirectory } of owned.reverse()) {
86
+ directoryGuard(directory, directories, parent);
87
+ const current = lstatSync(path, { throwIfNoEntry: false });
88
+ if (!current || !sameIdentity(current, identity))
89
+ continue;
90
+ if (isDirectory)
91
+ rmdirSync(path);
92
+ else
93
+ unlinkSync(path);
94
+ }
95
+ if (sameDirectory(directory, original))
96
+ rmdirSync(directory);
97
+ return "unavailable";
98
+ }
99
+ }
100
+ export function bindTemplate(root) {
101
+ if (root === undefined)
102
+ return () => "unavailable";
103
+ try {
104
+ const identity = currentDirectory(root);
105
+ if (!identity)
106
+ return () => "unavailable";
107
+ return () => {
108
+ try {
109
+ return sameDirectory(root, identity) ? writeTemplate(root) : "unavailable";
110
+ }
111
+ catch {
112
+ return "unavailable";
113
+ }
114
+ };
115
+ }
116
+ catch {
117
+ return () => "unavailable";
118
+ }
119
+ }
@@ -0,0 +1 @@
1
+ export declare function canonicalWebhookUrl(value: string): string | undefined;
@@ -0,0 +1,30 @@
1
+ const AUTHORITY = /^[A-Za-z0-9.-]+(?::443)?$/;
2
+ const HOSTNAME = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z0-9-]{0,62}$/;
3
+ const LOCAL_SUFFIX = /(?:^|\.)(?:localhost|local|internal|home\.arpa)$/;
4
+ const ROUTE = /^\/(?:[A-Za-z0-9_~.-]+\/)*[A-Za-z0-9_~.-]+\/?$/;
5
+ export function canonicalWebhookUrl(value) {
6
+ if (value.includes("?") || value.includes("#"))
7
+ return undefined;
8
+ if (value.length > 2048 || !value.startsWith("https://") || /[\s\\]/u.test(value))
9
+ return undefined;
10
+ const separator = value.indexOf("/", "https://".length);
11
+ if (separator < 0)
12
+ return undefined;
13
+ const authority = value.slice("https://".length, separator);
14
+ // URL normalizes empty hosts, user info and ports. Check the operator's authority first.
15
+ if (!AUTHORITY.test(authority))
16
+ return undefined;
17
+ const route = value.slice(separator).split(/[?#]/, 1)[0] ?? "";
18
+ if (!ROUTE.test(route) || route.split("/").some((segment) => segment === "." || segment === "..")) {
19
+ return undefined;
20
+ }
21
+ try {
22
+ const url = new URL(value);
23
+ if (!HOSTNAME.test(url.hostname) || LOCAL_SUFFIX.test(url.hostname))
24
+ return undefined;
25
+ return url.origin + url.pathname;
26
+ }
27
+ catch {
28
+ return undefined;
29
+ }
30
+ }
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@pagaqr/mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.7.1",
4
+ "description": "Diagnóstico MCP de PagaQR y pagaqr-setup para instalación humana en terminal",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/pagaqr/pagaqr.git",
10
+ "directory": "packages/mcp"
11
+ },
12
+ "engines": {
13
+ "node": ">=24"
14
+ },
15
+ "sideEffects": false,
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "NOTICE",
20
+ "CHANGELOG.md"
21
+ ],
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ }
27
+ },
28
+ "bin": {
29
+ "pagaqr-mcp": "./dist/cli.js",
30
+ "pagaqr-capture": "./dist/capture-cli.js",
31
+ "pagaqr-setup": "./dist/setup-cli.js"
32
+ },
33
+ "dependencies": {
34
+ "@modelcontextprotocol/server": "2.4.0",
35
+ "pg": "8.23.1",
36
+ "parse5": "8.1.1"
37
+ },
38
+ "devDependencies": {
39
+ "@types/react": "19.3.3",
40
+ "@types/react-dom": "19.3.0",
41
+ "react": "19.3.1",
42
+ "react-dom": "19.3.1",
43
+ "typescript": "6.0.3",
44
+ "yaml": "2.9.1",
45
+ "@types/pg": "8.23.1"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public",
49
+ "provenance": true
50
+ },
51
+ "scripts": {
52
+ "build": "tsc -p tsconfig.build.json && node scripts/build-template.mjs && node scripts/build-setup-runtime.mjs"
53
+ }
6
54
  }