@stacksjs/buddy 0.70.182 → 0.70.183

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.
@@ -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
- `)).toString("base64") : "", script = `set -e
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}'
@@ -1023,6 +1024,12 @@ if [ "$ENV_CHANGED" = 1 ]; then systemctl restart mail 2>/dev/null || true; echo
1023
1024
  stdio: ["pipe", "pipe", "pipe"]
1024
1025
  }), 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
1026
  logger.success(`Mail routing reconciled (${line.replace("MAILTENANT:", "")})`);
1027
+ const failed = [...out.matchAll(/FAIL:([^\n]+)/g)].flatMap((m) => m[1] ? [m[1].trim()] : []);
1028
+ if (failed.length)
1029
+ logger.warn(`Mail: the server refused ${failed.length} mailbox(es): ${failed.join(", ")}`);
1030
+ 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);
1031
+ if (unaccounted.length)
1032
+ logger.warn(`Mail: ${unaccounted.length} declared mailbox(es) were not reconciled: ${unaccounted.join(", ")}`);
1026
1033
  if (created.length) {
1027
1034
  logger.info(`Mail: created ${created.length} mailbox(es) \u2014 credentials below (save them; shown once):`);
1028
1035
  for (const b of created)
@@ -1058,7 +1065,18 @@ export async function reconcileMailDns(res, ip, logger) {
1058
1065
  headers: { "Content-Type": "application/json" },
1059
1066
  body: JSON.stringify({ ...auth, ...body })
1060
1067
  })).json().catch(() => ({}));
1061
- }, upsert = async (type, name, content, extra = {}) => {
1068
+ }, ownership = await call(`dns/retrieve/${domain}`, {});
1069
+ if (ownership?.status !== "SUCCESS") {
1070
+ logger.warn(`Mail DNS skipped: ${domain} is not administered by these Porkbun credentials (${ownership?.message || "domain not in this account"}).`);
1071
+ logger.info(`Set \`domain\` in config/email.ts to a zone you own, or add these records for ${domain} by hand:`);
1072
+ logger.info(` MX @ 10 ${mailHost}`);
1073
+ logger.info(` TXT @ ${spf}`);
1074
+ if (dkim)
1075
+ logger.info(` TXT mail._domainkey ${dkim}`);
1076
+ logger.info(` TXT _dmarc ${dmarc}`);
1077
+ return;
1078
+ }
1079
+ const upsert = async (type, name, content, extra = {}) => {
1062
1080
  const sub = name === "@" ? "" : `/${name}`;
1063
1081
  await call(`dns/deleteByNameType/${domain}/${type}${sub}`, {});
1064
1082
  const created = await call(`dns/create/${domain}`, { name: name === "@" ? "" : name, type, content, ttl: "600", ...extra });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/buddy",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.70.182",
5
+ "version": "0.70.183",
6
6
  "description": "Meet Buddy. The Stacks runtime.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [