@stacksjs/buddy 0.70.182 → 0.70.184
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/dist/commands/deploy.js +34 -4
- package/package.json +1 -1
package/dist/commands/deploy.js
CHANGED
|
@@ -875,8 +875,9 @@ export async function provisionMailTenant(ip, logger) {
|
|
|
875
875
|
const domain = cfg.domain || (typeof cfg.from?.address === "string" && cfg.from.address.includes("@") ? cfg.from.address.split("@")[1] : void 0), forwards = cfg.forwards && typeof cfg.forwards === "object" ? cfg.forwards : {}, hasForwards = Object.keys(forwards).length > 0, boxes = domain ? resolveMailboxes(cfg.mailboxes, domain) : [];
|
|
876
876
|
if (!domain && !hasForwards)
|
|
877
877
|
return null;
|
|
878
|
-
const { execSync } = await import("node:child_process"), sshArgs = ["-o", "StrictHostKeyChecking=accept-new", "-o", "BatchMode=yes", "-o", "ConnectTimeout=20", `root@${ip}`], forwardsB64 = hasForwards ? Buffer.from(JSON.stringify(forwards)).toString("base64") : "", readme = "Auto-forwarding rules, re-read on every message (edits take effect immediately, no restart). KEY = the delivered mailbox: the FULL address for per-domain isolated mailboxes (e.g. no-reply@app.com), or a bare local-part for legacy role mailboxes. VALUE = list of destination addresses; targets on a local domain are written straight to that mailbox Maildir, external targets are relayed. Managed by buddy deploy " + "from config/email.ts (merge-based \u2014 hand edits to other keys are preserved).", readmeB64 = Buffer.from(readme).toString("base64"), boxesB64 = boxes.length ? Buffer.from(boxes.map((b) => `${b.address} ${b.password}`).join(`
|
|
879
|
-
`)
|
|
878
|
+
const { execSync } = await import("node:child_process"), sshArgs = ["-o", "StrictHostKeyChecking=accept-new", "-o", "BatchMode=yes", "-o", "ConnectTimeout=20", `root@${ip}`], forwardsB64 = hasForwards ? Buffer.from(JSON.stringify(forwards)).toString("base64") : "", readme = "Auto-forwarding rules, re-read on every message (edits take effect immediately, no restart). KEY = the delivered mailbox: the FULL address for per-domain isolated mailboxes (e.g. no-reply@app.com), or a bare local-part for legacy role mailboxes. VALUE = list of destination addresses; targets on a local domain are written straight to that mailbox Maildir, external targets are relayed. Managed by buddy deploy " + "from config/email.ts (merge-based \u2014 hand edits to other keys are preserved).", readmeB64 = Buffer.from(readme).toString("base64"), boxesB64 = boxes.length ? Buffer.from(`${boxes.map((b) => `${b.address} ${b.password}`).join(`
|
|
879
|
+
`)}
|
|
880
|
+
`).toString("base64") : "", script = `set -e
|
|
880
881
|
DOMAIN=${domain ? `'${domain}'` : "''"}
|
|
881
882
|
FWD_B64='${forwardsB64}'
|
|
882
883
|
README_B64='${readmeB64}'
|
|
@@ -944,6 +945,11 @@ fi
|
|
|
944
945
|
if [ -n "$FWD_B64" ] && [ -x /usr/local/bin/bun ]; then
|
|
945
946
|
echo "$FWD_B64" | base64 -d > /tmp/.mailtenant-fwd.json
|
|
946
947
|
echo "$README_B64" | base64 -d > /tmp/.mailtenant-readme.txt
|
|
948
|
+
# \`let\`, not \`const\`: both of these were const with an assignment inside a
|
|
949
|
+
# try, which Bun rejects at parse time ("this assignment will throw because
|
|
950
|
+
# X is a constant"). The whole snippet therefore never ran, stderr was sent
|
|
951
|
+
# to /dev/null, and every reconcile since has reported forwards=nochange
|
|
952
|
+
# while forwards.json sat untouched.
|
|
947
953
|
/usr/local/bin/bun --bun -e '
|
|
948
954
|
const fs=require("fs"); const f="/opt/mail/forwards.json";
|
|
949
955
|
const cur={}; try{cur=JSON.parse(fs.readFileSync(f,"utf8"))}catch{}
|
|
@@ -955,7 +961,11 @@ if [ -n "$FWD_B64" ] && [ -x /usr/local/bin/bun ]; then
|
|
|
955
961
|
const s=JSON.stringify(out,null,2)+"\\n";
|
|
956
962
|
const prev=""; try{prev=fs.readFileSync(f,"utf8")}catch{}
|
|
957
963
|
if(s!==prev){ fs.writeFileSync(f,s); process.stdout.write("FWDCHANGED"); }
|
|
958
|
-
' > /tmp/.mailtenant-res 2>/
|
|
964
|
+
' > /tmp/.mailtenant-res 2>/tmp/.mailtenant-err || true
|
|
965
|
+
# A merge that failed is worth one line, not silence: the rules decide where
|
|
966
|
+
# mail goes.
|
|
967
|
+
if [ -s /tmp/.mailtenant-err ]; then echo "FWDERR:$(head -c 200 /tmp/.mailtenant-err | tr '\\n' ' ')"; fi
|
|
968
|
+
rm -f /tmp/.mailtenant-err
|
|
959
969
|
chown mail-server:mail-server "$FJSON" 2>/dev/null || true
|
|
960
970
|
chmod 644 "$FJSON" 2>/dev/null || true
|
|
961
971
|
rm -f /tmp/.mailtenant-fwd.json /tmp/.mailtenant-readme.txt
|
|
@@ -1023,6 +1033,15 @@ if [ "$ENV_CHANGED" = 1 ]; then systemctl restart mail 2>/dev/null || true; echo
|
|
|
1023
1033
|
stdio: ["pipe", "pipe", "pipe"]
|
|
1024
1034
|
}), line = (out.match(/MAILTENANT:[^\n]*/) || [])[0] || "MAILTENANT:done", mailHost = (out.match(/MAILHOST:([^\n]*)/) || [])[1]?.trim() || `mail.${domain}`, dkimPubB64 = (out.match(/DKIMPUB:([^\n]*)/) || [])[1]?.trim() || void 0, madeAddrs = new Set([...out.matchAll(/MADE:([^\n]+)/g)].flatMap((m) => m[1] ? [m[1].trim()] : [])), created = boxes.filter((b) => madeAddrs.has(b.address)).map((b) => ({ address: b.address, password: b.password }));
|
|
1025
1035
|
logger.success(`Mail routing reconciled (${line.replace("MAILTENANT:", "")})`);
|
|
1036
|
+
const failed = [...out.matchAll(/FAIL:([^\n]+)/g)].flatMap((m) => m[1] ? [m[1].trim()] : []);
|
|
1037
|
+
if (failed.length)
|
|
1038
|
+
logger.warn(`Mail: the server refused ${failed.length} mailbox(es): ${failed.join(", ")}`);
|
|
1039
|
+
const forwardError = (out.match(/FWDERR:([^\n]*)/) || [])[1]?.trim();
|
|
1040
|
+
if (forwardError)
|
|
1041
|
+
logger.warn(`Mail: the forward rules were not merged: ${forwardError}`);
|
|
1042
|
+
const seen = new Set([...madeAddrs, ...[...out.matchAll(/EXISTS:([^\n]+)/g)].flatMap((m) => m[1] ? [m[1].trim()] : [])]), unaccounted = boxes.filter((b) => !seen.has(b.address)).map((b) => b.address);
|
|
1043
|
+
if (unaccounted.length)
|
|
1044
|
+
logger.warn(`Mail: ${unaccounted.length} declared mailbox(es) were not reconciled: ${unaccounted.join(", ")}`);
|
|
1026
1045
|
if (created.length) {
|
|
1027
1046
|
logger.info(`Mail: created ${created.length} mailbox(es) \u2014 credentials below (save them; shown once):`);
|
|
1028
1047
|
for (const b of created)
|
|
@@ -1058,7 +1077,18 @@ export async function reconcileMailDns(res, ip, logger) {
|
|
|
1058
1077
|
headers: { "Content-Type": "application/json" },
|
|
1059
1078
|
body: JSON.stringify({ ...auth, ...body })
|
|
1060
1079
|
})).json().catch(() => ({}));
|
|
1061
|
-
},
|
|
1080
|
+
}, ownership = await call(`dns/retrieve/${domain}`, {});
|
|
1081
|
+
if (ownership?.status !== "SUCCESS") {
|
|
1082
|
+
logger.warn(`Mail DNS skipped: ${domain} is not administered by these Porkbun credentials (${ownership?.message || "domain not in this account"}).`);
|
|
1083
|
+
logger.info(`Set \`domain\` in config/email.ts to a zone you own, or add these records for ${domain} by hand:`);
|
|
1084
|
+
logger.info(` MX @ 10 ${mailHost}`);
|
|
1085
|
+
logger.info(` TXT @ ${spf}`);
|
|
1086
|
+
if (dkim)
|
|
1087
|
+
logger.info(` TXT mail._domainkey ${dkim}`);
|
|
1088
|
+
logger.info(` TXT _dmarc ${dmarc}`);
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
const upsert = async (type, name, content, extra = {}) => {
|
|
1062
1092
|
const sub = name === "@" ? "" : `/${name}`;
|
|
1063
1093
|
await call(`dns/deleteByNameType/${domain}/${type}${sub}`, {});
|
|
1064
1094
|
const created = await call(`dns/create/${domain}`, { name: name === "@" ? "" : name, type, content, ttl: "600", ...extra });
|