@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.
- package/CHANGELOG.md +15 -0
- package/LICENSE +202 -0
- package/NOTICE +9 -0
- package/README.md +99 -2
- package/dist/capture-cli.d.ts +2 -0
- package/dist/capture-cli.js +34 -0
- package/dist/capture-local.d.ts +9 -0
- package/dist/capture-local.js +18 -0
- package/dist/capture-store.d.ts +7 -0
- package/dist/capture-store.js +175 -0
- package/dist/catalogue.d.ts +33 -0
- package/dist/catalogue.js +78 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +27 -0
- package/dist/diagnose.d.ts +23 -0
- package/dist/diagnose.js +93 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +134 -0
- package/dist/invocation-log.d.ts +9 -0
- package/dist/invocation-log.js +70 -0
- package/dist/masked-terminal.d.ts +4 -0
- package/dist/masked-terminal.js +71 -0
- package/dist/next-postgres.json +99 -0
- package/dist/sbom.cdx.json +523 -0
- package/dist/setup/database.d.ts +7 -0
- package/dist/setup/database.js +83 -0
- package/dist/setup/notice.d.ts +2 -0
- package/dist/setup/notice.js +2 -0
- package/dist/setup/run.d.ts +25 -0
- package/dist/setup/run.js +215 -0
- package/dist/setup/runtime.js +837 -0
- package/dist/setup/state.d.ts +7 -0
- package/dist/setup/state.js +81 -0
- package/dist/setup/step.d.ts +59 -0
- package/dist/setup/step.js +9 -0
- package/dist/setup/steps/pey.d.ts +8 -0
- package/dist/setup/steps/pey.js +271 -0
- package/dist/setup/steps/vercel.d.ts +5 -0
- package/dist/setup/steps/vercel.js +375 -0
- package/dist/setup/store-secrets.d.ts +3 -0
- package/dist/setup/store-secrets.js +67 -0
- package/dist/setup/terminal-guard.d.ts +9 -0
- package/dist/setup/terminal-guard.js +17 -0
- package/dist/setup/verify.d.ts +34 -0
- package/dist/setup/verify.js +144 -0
- package/dist/setup-cli.d.ts +2 -0
- package/dist/setup-cli.js +70 -0
- package/dist/template.d.ts +4 -0
- package/dist/template.js +119 -0
- package/dist/webhook.d.ts +1 -0
- package/dist/webhook.js +30 -0
- package/package.json +51 -3
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { canonicalWebhookUrl } from "../webhook.js";
|
|
2
|
+
import { SETUP_NOTICE } from "./notice.js";
|
|
3
|
+
import { setupRefusal } from "./terminal-guard.js";
|
|
4
|
+
const ORDER = ["pey", "database", "store-secrets", "vercel", "verificar"];
|
|
5
|
+
const FACTS = new Set([
|
|
6
|
+
"pey.bankAccountId",
|
|
7
|
+
"pey.apiKeyId",
|
|
8
|
+
"vercel.projectId",
|
|
9
|
+
"vercel.teamId",
|
|
10
|
+
"vercel.redeployId",
|
|
11
|
+
"vercel.redeployConfig",
|
|
12
|
+
"vercel.publishedId",
|
|
13
|
+
"verificar.deployment",
|
|
14
|
+
]);
|
|
15
|
+
const VALID_FACT = /^[a-zA-Z0-9_-]{1,96}$/;
|
|
16
|
+
function output(terminal) {
|
|
17
|
+
const values = new Set();
|
|
18
|
+
function hide(value) {
|
|
19
|
+
if (!value)
|
|
20
|
+
return;
|
|
21
|
+
values.add(value);
|
|
22
|
+
values.add(encodeURIComponent(value));
|
|
23
|
+
try {
|
|
24
|
+
const url = new URL(value);
|
|
25
|
+
if (url.password) {
|
|
26
|
+
values.add(url.password);
|
|
27
|
+
values.add(decodeURIComponent(url.password));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Most captured values are opaque tokens.
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function redact(line) {
|
|
35
|
+
let clean = line;
|
|
36
|
+
for (const value of [...values].sort((a, b) => b.length - a.length)) {
|
|
37
|
+
clean = clean.replaceAll(value, "[oculto]");
|
|
38
|
+
}
|
|
39
|
+
return clean.replace(/[\p{Cc}\p{Cf}]/gu, " ");
|
|
40
|
+
}
|
|
41
|
+
return { hide, redact, write: (line) => terminal.write(redact(line)) };
|
|
42
|
+
}
|
|
43
|
+
export async function runSetup(options) {
|
|
44
|
+
const out = output(options.terminal);
|
|
45
|
+
const refusal = setupRefusal(options);
|
|
46
|
+
if (refusal) {
|
|
47
|
+
out.write(refusal);
|
|
48
|
+
return 2;
|
|
49
|
+
}
|
|
50
|
+
out.write(SETUP_NOTICE);
|
|
51
|
+
const review = options.args[0] === "--revisar";
|
|
52
|
+
let save;
|
|
53
|
+
async function input(prompt, kind) {
|
|
54
|
+
options.signal.throwIfAborted();
|
|
55
|
+
const answer = await options.terminal.read(out.redact(prompt), kind);
|
|
56
|
+
if (answer === undefined)
|
|
57
|
+
throw new Error("Setup cancelled");
|
|
58
|
+
return answer.trim();
|
|
59
|
+
}
|
|
60
|
+
async function ask(question, choices) {
|
|
61
|
+
if (!choices) {
|
|
62
|
+
const answer = await input(question, "text");
|
|
63
|
+
if (out.redact(answer) !== answer) {
|
|
64
|
+
out.write("Ese dato público contiene una credencial. Vuelve a ejecutar el instalador con el dato correcto.");
|
|
65
|
+
throw new Error("A credential was entered in a public field");
|
|
66
|
+
}
|
|
67
|
+
return answer;
|
|
68
|
+
}
|
|
69
|
+
const selections = choices.map((choice, i) => String(i + 1) + ". " + choice);
|
|
70
|
+
for (const label of selections)
|
|
71
|
+
out.write(label);
|
|
72
|
+
const answer = await input(question + " Escribe el número de la opción.", "text");
|
|
73
|
+
const choice = choices[Number(answer) - 1];
|
|
74
|
+
if (!/^[1-9][0-9]*$/.test(answer) || choice === undefined)
|
|
75
|
+
throw new Error("Invalid choice");
|
|
76
|
+
return choice;
|
|
77
|
+
}
|
|
78
|
+
function show(result) {
|
|
79
|
+
switch (result.kind) {
|
|
80
|
+
case "done":
|
|
81
|
+
out.write(result.summary);
|
|
82
|
+
break;
|
|
83
|
+
case "pending":
|
|
84
|
+
for (const line of result.changes)
|
|
85
|
+
out.write(line);
|
|
86
|
+
break;
|
|
87
|
+
case "blocked":
|
|
88
|
+
out.write(result.reason);
|
|
89
|
+
out.write(result.next);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function execute() {
|
|
94
|
+
const opening = await options.open();
|
|
95
|
+
if ("refusal" in opening) {
|
|
96
|
+
out.write(opening.refusal);
|
|
97
|
+
return 1;
|
|
98
|
+
}
|
|
99
|
+
const { memory, steps } = opening;
|
|
100
|
+
if (steps.length !== ORDER.length || steps.some((step, i) => step.id !== ORDER[i]))
|
|
101
|
+
throw new Error("Invalid setup sequence");
|
|
102
|
+
const facts = new Map([...memory.read()].filter(([key, value]) => FACTS.has(key) && VALID_FACT.test(value)));
|
|
103
|
+
const secrets = new Map();
|
|
104
|
+
const values = new Map();
|
|
105
|
+
let changed = false;
|
|
106
|
+
if (!review)
|
|
107
|
+
save = () => {
|
|
108
|
+
if (changed)
|
|
109
|
+
memory.save(new Map([...facts].filter(([, value]) => out.redact(value) === value)));
|
|
110
|
+
};
|
|
111
|
+
const mode = await ask("¿Qué modo quieres configurar?", ["test", "production"]);
|
|
112
|
+
const environment = mode === "production" ? "production" : "test";
|
|
113
|
+
const entered = await ask("Escribe el origen HTTPS público de tu tienda, sin rutas.");
|
|
114
|
+
const origin = new URL(entered);
|
|
115
|
+
if ((entered !== origin.origin && entered !== origin.origin + "/") ||
|
|
116
|
+
canonicalWebhookUrl(origin.origin + "/api/pagaqr/webhooks/pey") === undefined)
|
|
117
|
+
throw new Error("Invalid store origin");
|
|
118
|
+
const context = {
|
|
119
|
+
projectDir: options.projectDir,
|
|
120
|
+
environment,
|
|
121
|
+
fetch: options.fetch,
|
|
122
|
+
signal: options.signal,
|
|
123
|
+
async secret(name) {
|
|
124
|
+
const known = secrets.get(name);
|
|
125
|
+
if (known !== undefined)
|
|
126
|
+
return known;
|
|
127
|
+
const value = await input("Escribe " + name + " con entrada oculta y pulsa Enter.", "secret");
|
|
128
|
+
if (!value)
|
|
129
|
+
throw new Error("Empty secret");
|
|
130
|
+
out.hide(value);
|
|
131
|
+
secrets.set(name, value);
|
|
132
|
+
return value;
|
|
133
|
+
},
|
|
134
|
+
provide(name, field) {
|
|
135
|
+
if (name === "VERCEL_TOKEN" || name === "DATABASE_OWNER_URL")
|
|
136
|
+
throw new Error("Installer credentials cannot be published");
|
|
137
|
+
const sensitive = field.sensitive ||
|
|
138
|
+
values.get(name)?.sensitive === true ||
|
|
139
|
+
name === "PEY_API_KEY" ||
|
|
140
|
+
name === "DATABASE_URL" ||
|
|
141
|
+
out.redact(field.value) !== field.value;
|
|
142
|
+
if (sensitive && !field.sensitive)
|
|
143
|
+
throw new Error("A credential cannot be provided as public data");
|
|
144
|
+
if (sensitive)
|
|
145
|
+
out.hide(field.value);
|
|
146
|
+
values.set(name, { value: field.value, sensitive });
|
|
147
|
+
},
|
|
148
|
+
provided: () => new Map(values),
|
|
149
|
+
remember(key, value) {
|
|
150
|
+
if (!FACTS.has(key) || !VALID_FACT.test(value) || out.redact(value) !== value)
|
|
151
|
+
return;
|
|
152
|
+
if (facts.get(key) !== value)
|
|
153
|
+
changed = true;
|
|
154
|
+
facts.set(key, value);
|
|
155
|
+
},
|
|
156
|
+
recall: (key) => facts.get(key),
|
|
157
|
+
ask,
|
|
158
|
+
};
|
|
159
|
+
context.provide("PAGAQR_STORE_ORIGIN", { value: origin.origin, sensitive: false });
|
|
160
|
+
context.provide("PAGAQR_ENVIRONMENT", { value: environment, sensitive: false });
|
|
161
|
+
out.write("Configura el aviso en el Portal de pey con esta URL: " + origin.origin + "/api/pagaqr/webhooks/pey");
|
|
162
|
+
const configured = await ask("¿Ya tienes el secreto del aviso del Portal?", ["sí", "todavía no"]);
|
|
163
|
+
if (configured === "sí") {
|
|
164
|
+
const webhook = await input("Pega el secreto del aviso de pey (whsec_) con entrada oculta y pulsa Enter.", "secret");
|
|
165
|
+
out.hide(webhook);
|
|
166
|
+
if (!/^whsec_[A-Za-z0-9+/]+={0,2}$/.test(webhook)) {
|
|
167
|
+
out.write("El secreto del aviso no tiene el formato de pey. Verifica el valor en el Portal.");
|
|
168
|
+
return 1;
|
|
169
|
+
}
|
|
170
|
+
context.provide("PEY_WEBHOOK_SECRETS", { value: webhook, sensitive: true });
|
|
171
|
+
}
|
|
172
|
+
let blocked = false;
|
|
173
|
+
for (const step of steps) {
|
|
174
|
+
options.signal.throwIfAborted();
|
|
175
|
+
out.write(step.title);
|
|
176
|
+
const status = await step.inspect(context);
|
|
177
|
+
show(status);
|
|
178
|
+
if (review) {
|
|
179
|
+
blocked ||= status.kind === "blocked";
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (status.kind === "blocked")
|
|
183
|
+
return 1;
|
|
184
|
+
if (status.kind === "done")
|
|
185
|
+
continue;
|
|
186
|
+
const answer = await input("¿Aplicar estos cambios? (s/n)", "text");
|
|
187
|
+
if (answer.toLowerCase() !== "s") {
|
|
188
|
+
out.write("Instalación detenida antes de aplicar este paso.");
|
|
189
|
+
return 1;
|
|
190
|
+
}
|
|
191
|
+
options.signal.throwIfAborted();
|
|
192
|
+
const result = await step.apply(context);
|
|
193
|
+
show(result);
|
|
194
|
+
if (result.kind !== "done")
|
|
195
|
+
return 1;
|
|
196
|
+
}
|
|
197
|
+
return blocked ? 1 : 0;
|
|
198
|
+
}
|
|
199
|
+
let code;
|
|
200
|
+
try {
|
|
201
|
+
code = await execute();
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
out.write("Instalación detenida. Verifica la carpeta, el origen público y las credenciales en tu terminal.");
|
|
205
|
+
code = 1;
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
save?.();
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
out.write("No se pudo guardar el progreso. Verifica que Git ignore el archivo de estado.");
|
|
212
|
+
return 1;
|
|
213
|
+
}
|
|
214
|
+
return code;
|
|
215
|
+
}
|