@zero2webmaster/starter-kit 0.2.1 → 0.3.0
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/README.md +12 -14
- package/dist/airtable.d.ts +119 -0
- package/dist/airtable.js +273 -0
- package/dist/cli.js +116 -18
- package/dist/confirm.d.ts +5 -4
- package/dist/confirm.js +41 -29
- package/dist/index.d.ts +179 -6
- package/dist/index.js +155 -6
- package/dist/inventory.d.ts +137 -0
- package/dist/inventory.js +258 -0
- package/dist/license.js +8 -6
- package/dist/parse-brief.d.ts +28 -2
- package/dist/parse-brief.js +151 -16
- package/dist/scaffolders/common.d.ts +30 -1
- package/dist/scaffolders/common.js +538 -21
- package/dist/scaffolders/index.d.ts +1 -0
- package/dist/scaffolders/index.js +3 -0
- package/dist/scaffolders/library.js +26 -2
- package/dist/scaffolders/nextjs.d.ts +1 -1
- package/dist/scaffolders/nextjs.js +250 -24
- package/dist/scaffolders/node-service.d.ts +3 -0
- package/dist/scaffolders/node-service.js +320 -0
- package/dist/scaffolders/pro-seo-extension.js +1 -1
- package/dist/scaffolders/python-service.js +5 -2
- package/dist/standards.d.ts +1 -1
- package/dist/standards.js +123 -3
- package/dist/substitute.d.ts +14 -3
- package/dist/substitute.js +8 -5
- package/dist/summary.d.ts +9 -0
- package/dist/summary.js +27 -10
- package/dist/templates.d.ts +43 -57
- package/dist/templates.js +108 -175
- package/dist/with-init.d.ts +18 -2
- package/dist/with-init.js +105 -16
- package/dist/wizard.js +21 -0
- package/dist/writer.d.ts +3 -5
- package/dist/writer.js +88 -15
- package/package.json +2 -1
|
@@ -99,6 +99,17 @@ function quickStartFor(inputs) {
|
|
|
99
99
|
`uvicorn ${slugUnder}.main:app --reload`,
|
|
100
100
|
"```",
|
|
101
101
|
].join("\n");
|
|
102
|
+
case "node-service":
|
|
103
|
+
return [
|
|
104
|
+
"```bash",
|
|
105
|
+
"npm install",
|
|
106
|
+
"# .env was scaffolded for you — fill in the values it lists",
|
|
107
|
+
"npm run dev # local server (tsx watch) on http://localhost:8080",
|
|
108
|
+
"npm test # vitest",
|
|
109
|
+
"npm run build # compile to dist/",
|
|
110
|
+
"npm start # node dist/index.js (what the container runs)",
|
|
111
|
+
"```",
|
|
112
|
+
].join("\n");
|
|
102
113
|
case "library":
|
|
103
114
|
return [
|
|
104
115
|
"```bash",
|
|
@@ -156,6 +167,110 @@ Format: [Semantic Versioning](https://semver.org/).
|
|
|
156
167
|
- Initial scaffold via \`@zero2webmaster/starter-kit\` (mirrors [[instantiate-z2w-project]]).
|
|
157
168
|
- Brand: {{brand_name}}.
|
|
158
169
|
`;
|
|
170
|
+
// Emitted by default for every project type (always-on standard, like the
|
|
171
|
+
// Skill Vault / text-size standards). Per Kerry's 2026-06-18 directive: every
|
|
172
|
+
// coding project with any likelihood of being sold or licensed should carry a
|
|
173
|
+
// marketing plan, kept up to date and tracked as a first-class artifact. The
|
|
174
|
+
// stub has an explicit N/A path for internal-only projects so it never becomes
|
|
175
|
+
// dead boilerplate. The high-level state mirrors to the project inventory's
|
|
176
|
+
// `marketing_plan` field (the at-a-glance status the command center reads).
|
|
177
|
+
const MARKETING_TEMPLATE = `# Marketing Plan — {{slug}}
|
|
178
|
+
|
|
179
|
+
> A first-class, tracked artifact for every Z2W project. Per the standing
|
|
180
|
+
> Zero2Webmaster rule (2026-06-18): every coding project with any likelihood of
|
|
181
|
+
> being sold or licensed should carry a marketing plan, kept up to date here.
|
|
182
|
+
|
|
183
|
+
**Project:** {{slug}}
|
|
184
|
+
**Status:** Stub — fill this in, or mark **N/A (internal-only, not sold/licensed)** and say why.
|
|
185
|
+
**Last Updated:** {{date}}
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Is this project sold or licensed?
|
|
190
|
+
|
|
191
|
+
- [ ] **Yes** — complete the sections below.
|
|
192
|
+
- [ ] **No / internal-only** — mark N/A here and you can delete the rest: ______________
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Positioning
|
|
197
|
+
|
|
198
|
+
- **What it is (one sentence):** {{description}}
|
|
199
|
+
- **Ideal end user:**
|
|
200
|
+
- **Where it fits among competitors:**
|
|
201
|
+
- **Primary value proposition:**
|
|
202
|
+
|
|
203
|
+
## Pricing & packaging
|
|
204
|
+
|
|
205
|
+
- **Model:** (one-time / subscription / freemium / …)
|
|
206
|
+
- **Price points:**
|
|
207
|
+
|
|
208
|
+
## Distribution & discovery
|
|
209
|
+
|
|
210
|
+
- **Where buyers find it:**
|
|
211
|
+
- **Launch channels:**
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Status tracking
|
|
216
|
+
|
|
217
|
+
Mirror the high-level state to the project inventory's \`marketing_plan\` field
|
|
218
|
+
(\`None\` / \`Stub\` / \`Drafted\` / \`Active\`). This file is the detail; the
|
|
219
|
+
inventory is the at-a-glance status the command center reads.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
*Scaffolded {{date}} via [[instantiate-z2w-project]] — mirrored by \`@zero2webmaster/starter-kit\`.*
|
|
224
|
+
`;
|
|
225
|
+
// Emitted by default for every project type (always-on standard). Per Kerry's
|
|
226
|
+
// 2026-06-18 directive: each project should keep a living document stating what
|
|
227
|
+
// parts need backups, which are actually backed up, how, and when each was last
|
|
228
|
+
// verified (code → GitHub, Neon → nightly dumps to R2, Backblaze B2 → R2, …).
|
|
229
|
+
// The high-level state mirrors to the project inventory's `backup_plan` field so
|
|
230
|
+
// the command center can surface each project's backup status / last-completed.
|
|
231
|
+
const BACKUPS_TEMPLATE = `# Backup Plan — {{slug}}
|
|
232
|
+
|
|
233
|
+
> A first-class, tracked artifact for every Z2W project. State here what parts
|
|
234
|
+
> of this project need backups, which are actually backed up, how, and when each
|
|
235
|
+
> was last verified. Keep it up to date.
|
|
236
|
+
|
|
237
|
+
**Project:** {{slug}}
|
|
238
|
+
**Status:** Stub — fill in each surface below (or mark N/A).
|
|
239
|
+
**Last Updated:** {{date}}
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Backup surfaces
|
|
244
|
+
|
|
245
|
+
For each surface: whether it needs a backup, whether one exists, the
|
|
246
|
+
method/destination, the cadence, and when it was last verified.
|
|
247
|
+
|
|
248
|
+
| Surface | Needs backup? | Backed up? | Method / destination | Cadence | Last verified |
|
|
249
|
+
|---|---|---|---|---|---|
|
|
250
|
+
| Source code | Yes | | GitHub (\`{{github_org}}/{{slug}}\`) | on push | |
|
|
251
|
+
| Database (e.g. Neon Postgres) | | | nightly \`pg_dump\` → R2 / Backblaze | | |
|
|
252
|
+
| Object storage (e.g. Backblaze B2) | | | mirror → Cloudflare R2 | | |
|
|
253
|
+
| Secrets / env vars | | | (where are they recoverable from?) | | |
|
|
254
|
+
| Other (config, DNS, …) | | | | | |
|
|
255
|
+
|
|
256
|
+
## Restore test
|
|
257
|
+
|
|
258
|
+
A backup you have never restored from is a hope, not a backup. Note the last
|
|
259
|
+
time a restore was actually exercised:
|
|
260
|
+
|
|
261
|
+
- **Last restore drill:** ______________
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Status tracking
|
|
266
|
+
|
|
267
|
+
Mirror the high-level state to the project inventory's \`backup_plan\` field. The
|
|
268
|
+
command center can then surface each project's backup status / last-completed.
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
*Scaffolded {{date}} via [[instantiate-z2w-project]] — mirrored by \`@zero2webmaster/starter-kit\`.*
|
|
273
|
+
`;
|
|
159
274
|
const ROADMAP_TEMPLATE = `# Project Roadmap
|
|
160
275
|
|
|
161
276
|
**Project:** {{slug}}
|
|
@@ -245,7 +360,7 @@ const STATUS_TEMPLATE = `# Project Status
|
|
|
245
360
|
|
|
246
361
|
*This status file provides quick context for resuming work after breaks. Keep it concise and action-oriented.*
|
|
247
362
|
`;
|
|
248
|
-
const
|
|
363
|
+
const HANDOFF_HEAD = `# Session Handoff Document
|
|
249
364
|
|
|
250
365
|
**Project:** {{slug}}
|
|
251
366
|
**Session Date:** {{date}}
|
|
@@ -262,25 +377,12 @@ Initial scaffold complete. No application code yet.
|
|
|
262
377
|
|
|
263
378
|
## 📚 Reading Order for Next Agent
|
|
264
379
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
3. **[ROADMAP.md](ROADMAP.md)** — atomic steps to v{{version}}
|
|
268
|
-
4. **[CLAUDE.md](CLAUDE.md)** — operating rules
|
|
269
|
-
|
|
270
|
-
---
|
|
271
|
-
|
|
272
|
-
## 🚀 Starting Prompt for Next Session
|
|
273
|
-
|
|
274
|
-
\`\`\`
|
|
275
|
-
I'm picking up {{slug}}. Read HANDOFF.md, STATUS.md, ROADMAP.md, then begin
|
|
276
|
-
ROADMAP Step 1.
|
|
277
|
-
\`\`\`
|
|
278
|
-
|
|
380
|
+
`;
|
|
381
|
+
const HANDOFF_TAIL = `
|
|
279
382
|
---
|
|
280
383
|
|
|
281
384
|
**Handoff Status:** ✅ CLEAN
|
|
282
|
-
**Ready for Next Session:** ✅ YES
|
|
283
|
-
`;
|
|
385
|
+
**Ready for Next Session:** ✅ YES`;
|
|
284
386
|
const CURSORIGNORE_TEMPLATE = `# Files Cursor should ignore (per project type).
|
|
285
387
|
.DS_Store
|
|
286
388
|
.tmp/
|
|
@@ -478,9 +580,81 @@ export function commonStatus(inputs, opts, spec) {
|
|
|
478
580
|
};
|
|
479
581
|
}
|
|
480
582
|
export function commonHandoff(inputs, opts, spec) {
|
|
583
|
+
// Did we capture (and persist) a brief? If so it is written verbatim to
|
|
584
|
+
// directives/PROJECT_BRIEF.md and belongs in the reading order. Is the
|
|
585
|
+
// roadmap concrete, or just placeholder prose? Both drive the starting
|
|
586
|
+
// prompt so the next agent is NEVER pointed at a "begin ROADMAP Step 1"
|
|
587
|
+
// that doesn't exist yet (the second half of the 2026-06-28 silent-miss).
|
|
588
|
+
const hasBrief = (inputs.instantiationPrompt ?? "").trim().length > 0;
|
|
589
|
+
const roadmapConcrete = (inputs.briefSections?.roadmap ?? "").trim().length > 0;
|
|
590
|
+
const readingOrder = [
|
|
591
|
+
"1. **This file (HANDOFF.md)** — current state",
|
|
592
|
+
"2. **[STATUS.md](STATUS.md)** — decisions, next actions, recent updates",
|
|
593
|
+
"3. **[ROADMAP.md](ROADMAP.md)** — atomic steps to v{{version}}",
|
|
594
|
+
];
|
|
595
|
+
if (hasBrief) {
|
|
596
|
+
readingOrder.push("4. **[directives/PROJECT_BRIEF.md](directives/PROJECT_BRIEF.md)** — the full instantiation brief (frozen charter)", "5. **[CLAUDE.md](CLAUDE.md)** — operating rules");
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
readingOrder.push("4. **[CLAUDE.md](CLAUDE.md)** — operating rules");
|
|
600
|
+
}
|
|
601
|
+
let startingPrompt;
|
|
602
|
+
if (hasBrief && roadmapConcrete) {
|
|
603
|
+
startingPrompt =
|
|
604
|
+
"I'm picking up {{slug}}. Read HANDOFF.md, STATUS.md, ROADMAP.md, and\n" +
|
|
605
|
+
"directives/PROJECT_BRIEF.md (the full brief). ROADMAP.md was seeded from the\n" +
|
|
606
|
+
"brief's plan — turn it into concrete, verifiable steps, then begin Step 1.";
|
|
607
|
+
}
|
|
608
|
+
else if (hasBrief) {
|
|
609
|
+
startingPrompt =
|
|
610
|
+
"I'm picking up {{slug}}. Read HANDOFF.md, STATUS.md, ROADMAP.md, and\n" +
|
|
611
|
+
"directives/PROJECT_BRIEF.md (the full brief). ROADMAP.md has no concrete steps\n" +
|
|
612
|
+
"yet — derive the first milestone from the brief, then begin Step 1.";
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
startingPrompt =
|
|
616
|
+
"I'm picking up {{slug}}. Read HANDOFF.md, STATUS.md, ROADMAP.md. ROADMAP.md is\n" +
|
|
617
|
+
"a placeholder — define the first concrete milestone, then begin Step 1.";
|
|
618
|
+
}
|
|
619
|
+
const body = HANDOFF_HEAD +
|
|
620
|
+
readingOrder.join("\n") +
|
|
621
|
+
"\n\n---\n\n## 🚀 Starting Prompt for Next Session\n\n```\n" +
|
|
622
|
+
startingPrompt +
|
|
623
|
+
"\n```\n" +
|
|
624
|
+
HANDOFF_TAIL +
|
|
625
|
+
"\n";
|
|
481
626
|
return {
|
|
482
627
|
path: "HANDOFF.md",
|
|
483
|
-
content: sub(
|
|
628
|
+
content: sub(body, inputs, opts, spec),
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
const PROJECT_BRIEF_HEADER = `# Project Brief — {{slug}} (frozen instantiation charter)
|
|
632
|
+
|
|
633
|
+
> This is the verbatim brief {{slug}} was scaffolded from on {{date}}, captured here
|
|
634
|
+
> so the repo is self-contained — the next agent can read the full spec without
|
|
635
|
+
> leaving the repository. It is a **frozen historical charter**: do NOT edit it to
|
|
636
|
+
> track ongoing work. The living plan is [ROADMAP.md](../ROADMAP.md); current state
|
|
637
|
+
> is [STATUS.md](../STATUS.md).
|
|
638
|
+
|
|
639
|
+
---
|
|
640
|
+
|
|
641
|
+
`;
|
|
642
|
+
/**
|
|
643
|
+
* Persist the verbatim instantiation brief into the repo at
|
|
644
|
+
* directives/PROJECT_BRIEF.md. Returns null for the wizard / `--input` paths
|
|
645
|
+
* that carry no brief text (nothing to persist). The body is the raw brief and
|
|
646
|
+
* is intentionally NOT run through the placeholder substituter, so a brief that
|
|
647
|
+
* happens to contain `{{token}}`-looking text is preserved exactly (only
|
|
648
|
+
* CLAUDE.md is validated for leftover markers — see writer.ts).
|
|
649
|
+
*/
|
|
650
|
+
export function commonProjectBrief(inputs, opts, spec) {
|
|
651
|
+
const brief = (inputs.instantiationPrompt ?? "").trim();
|
|
652
|
+
if (brief.length === 0)
|
|
653
|
+
return null;
|
|
654
|
+
const header = sub(PROJECT_BRIEF_HEADER, inputs, opts, spec);
|
|
655
|
+
return {
|
|
656
|
+
path: "directives/PROJECT_BRIEF.md",
|
|
657
|
+
content: `${header}${brief}\n`,
|
|
484
658
|
};
|
|
485
659
|
}
|
|
486
660
|
export function commonTroubleshooting(inputs, opts, spec) {
|
|
@@ -495,6 +669,18 @@ export function commonChangelog(inputs, opts, spec) {
|
|
|
495
669
|
content: sub(CHANGELOG_TEMPLATE, inputs, opts, spec),
|
|
496
670
|
};
|
|
497
671
|
}
|
|
672
|
+
export function commonMarketing(inputs, opts, spec) {
|
|
673
|
+
return {
|
|
674
|
+
path: "marketing.md",
|
|
675
|
+
content: sub(MARKETING_TEMPLATE, inputs, opts, spec),
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
export function commonBackups(inputs, opts, spec) {
|
|
679
|
+
return {
|
|
680
|
+
path: "BACKUPS.md",
|
|
681
|
+
content: sub(BACKUPS_TEMPLATE, inputs, opts, spec),
|
|
682
|
+
};
|
|
683
|
+
}
|
|
498
684
|
export function commonVersion() {
|
|
499
685
|
return { path: "VERSION", content: "0.1.0\n" };
|
|
500
686
|
}
|
|
@@ -517,6 +703,13 @@ export function commonDirective(inputs, opts, spec) {
|
|
|
517
703
|
* from past sessions; in the field they have contained live
|
|
518
704
|
* DATABASE_URLs (with password) and API keys. A fresh repo's
|
|
519
705
|
* first `git add -A` silently stages them otherwise.
|
|
706
|
+
* - `.cursorindexingignore` — Cursor auto-creates this to manage its own
|
|
707
|
+
* index. Without ignoring it, a freshly-scaffolded repo opens
|
|
708
|
+
* to a dirty tree with one mystery untracked file, and the
|
|
709
|
+
* first-session agent has to stop and ask what to do with it
|
|
710
|
+
* (contact-registry, 2026-07-12). Ignoring it gives every
|
|
711
|
+
* generated tree a clean `git status` — every file either
|
|
712
|
+
* tracked or ignored, nothing present-but-untracked.
|
|
520
713
|
*
|
|
521
714
|
* Per the 2026-06-11 z2w-member-match near-miss (live DATABASE_URL +
|
|
522
715
|
* RESEND_API_KEY staged on a fresh repo) and matching asks from
|
|
@@ -528,6 +721,8 @@ const GITIGNORE_SECRET_SCRATCH_BLOCK = `
|
|
|
528
721
|
.tmp/
|
|
529
722
|
# SpecStory chat transcripts — local only; can contain pasted secrets
|
|
530
723
|
.specstory/
|
|
724
|
+
# Cursor's own index-management file — local, auto-created; keeps git status clean
|
|
725
|
+
.cursorindexingignore
|
|
531
726
|
`;
|
|
532
727
|
/**
|
|
533
728
|
* Per-type `.gitignore` body. Sources: skill's "Inline mini-templates"
|
|
@@ -577,6 +772,13 @@ venv/
|
|
|
577
772
|
dist/
|
|
578
773
|
build/
|
|
579
774
|
*.egg-info/
|
|
775
|
+
`,
|
|
776
|
+
"node-service": `.DS_Store
|
|
777
|
+
node_modules/
|
|
778
|
+
dist/
|
|
779
|
+
.env
|
|
780
|
+
.env.local
|
|
781
|
+
*.log
|
|
580
782
|
`,
|
|
581
783
|
library: `.DS_Store
|
|
582
784
|
node_modules/
|
|
@@ -599,7 +801,7 @@ node_modules/
|
|
|
599
801
|
* rather than requiring a manual `cp .env.example .env.local` — closes the
|
|
600
802
|
* z2w-agent-command-center 2026-06-01 Open question.
|
|
601
803
|
*/
|
|
602
|
-
export function localEnvFrom(exampleContent, filename) {
|
|
804
|
+
export function localEnvFrom(exampleContent, filename, slug) {
|
|
603
805
|
const lines = exampleContent.split("\n");
|
|
604
806
|
// Drop the leading banner block (consecutive comment lines + blank lines at
|
|
605
807
|
// the top) — the per-key doc comments further down are kept verbatim.
|
|
@@ -615,7 +817,10 @@ export function localEnvFrom(exampleContent, filename) {
|
|
|
615
817
|
return m ? `${m[1]}${m[2]}=` : line;
|
|
616
818
|
})
|
|
617
819
|
.join("\n");
|
|
618
|
-
|
|
820
|
+
// Project name FIRST on line 1 (Kerry's standing rule 2026-07-01): two env
|
|
821
|
+
// files open side-by-side are easy to confuse, so the slug must lead — the
|
|
822
|
+
// filename alone ("# .env — …") doesn't say WHICH project's .env it is.
|
|
823
|
+
const banner = `# ${slug} — ${filename} (local environment values; gitignored, never committed).\n` +
|
|
619
824
|
`# Generated from .env.example at scaffold time; fill in real values below.\n\n`;
|
|
620
825
|
return banner + body;
|
|
621
826
|
}
|
|
@@ -630,7 +835,7 @@ export function localEnvFrom(exampleContent, filename) {
|
|
|
630
835
|
*/
|
|
631
836
|
export function commonBaseFiles(inputs, opts, perTypeNarrative) {
|
|
632
837
|
const spec = resolveBrandSpec(inputs);
|
|
633
|
-
|
|
838
|
+
const files = [
|
|
634
839
|
buildClaudeMd(inputs, opts, spec, perTypeNarrative),
|
|
635
840
|
commonReadme(inputs, opts, spec),
|
|
636
841
|
commonRoadmap(inputs, opts, spec),
|
|
@@ -638,9 +843,321 @@ export function commonBaseFiles(inputs, opts, perTypeNarrative) {
|
|
|
638
843
|
commonHandoff(inputs, opts, spec),
|
|
639
844
|
commonTroubleshooting(inputs, opts, spec),
|
|
640
845
|
commonChangelog(inputs, opts, spec),
|
|
846
|
+
commonMarketing(inputs, opts, spec),
|
|
847
|
+
commonBackups(inputs, opts, spec),
|
|
641
848
|
commonVersion(),
|
|
642
849
|
commonCursorignore(),
|
|
643
850
|
gitignoreFor(inputs.projectType),
|
|
644
851
|
commonDirective(inputs, opts, spec),
|
|
645
852
|
];
|
|
853
|
+
// Persist the verbatim brief into the repo (when one was captured) so the
|
|
854
|
+
// project is self-contained — see commonProjectBrief.
|
|
855
|
+
const briefFile = commonProjectBrief(inputs, opts, spec);
|
|
856
|
+
if (briefFile)
|
|
857
|
+
files.push(briefFile);
|
|
858
|
+
return files;
|
|
859
|
+
}
|
|
860
|
+
/* ─────────────────────────── Email wiring (opt-in) ─────────────────────────
|
|
861
|
+
*
|
|
862
|
+
* Emitted by the `nextjs` and `node-service` scaffolders when
|
|
863
|
+
* `inputs.sendsEmail === true` (per the 2026-06-28 email-default decision —
|
|
864
|
+
* event-engine, on Kerry's steer). A provider-router mailer with a stable
|
|
865
|
+
* `sendEmail()` signature: default provider Amazon SES, Resend as a one-env-var
|
|
866
|
+
* swappable alternative (`EMAIL_PROVIDER=resend`). SES is the default because
|
|
867
|
+
* the Z2W stacks already run authenticated SES in production (zero new vendor).
|
|
868
|
+
* See [[email-service-router]].
|
|
869
|
+
*
|
|
870
|
+
* The mailer body has NO {{tokens}} and NO relative imports, so it is
|
|
871
|
+
* byte-identical across the two types — only the file PATH differs (nextjs uses
|
|
872
|
+
* `lib/…` under the `@/*` alias; node-service uses `src/lib/…`). */
|
|
873
|
+
/** npm deps the mailer requires; merged into the scaffolded package.json. */
|
|
874
|
+
export const EMAIL_DEPS = {
|
|
875
|
+
"@aws-sdk/client-ses": "^3.1075.0",
|
|
876
|
+
resend: "^6.16.0",
|
|
877
|
+
};
|
|
878
|
+
const EMAIL_MAILER_BODY = `// Transactional / auth email — provider router. Default provider: Amazon SES;
|
|
879
|
+
// Resend is a swappable alternative selected with EMAIL_PROVIDER=resend.
|
|
880
|
+
//
|
|
881
|
+
// SERVER-SIDE ONLY. Never import this from client/browser code — it reads secret
|
|
882
|
+
// credentials from process.env and pulls in the AWS/Resend SDKs.
|
|
883
|
+
//
|
|
884
|
+
// Why SES is the default ([[email-service-router]], 2026-06-28): when a stack
|
|
885
|
+
// already runs authenticated SES in production (SAVE THE FROGS! / Bansuri Bliss /
|
|
886
|
+
// Zero2Webmaster all do), SES is zero new vendor, no domain warmup, and cheap at
|
|
887
|
+
// burst volume — past Resend Free's 100/day · 3k/mo cap, which is shared across
|
|
888
|
+
// the whole Z2W portfolio. Resend stays wired for a non-developer tenant who
|
|
889
|
+
// wants the easier DX: set EMAIL_PROVIDER=resend + RESEND_API_KEY + RESEND_FROM,
|
|
890
|
+
// no code change. Do NOT add a fifth mail vendor (SendGrid/Mailgun/Postmark/…) —
|
|
891
|
+
// [[email-service-router]] sanctions exactly these.
|
|
892
|
+
//
|
|
893
|
+
// The sendEmail() signature is provider-agnostic, so call sites (magic links,
|
|
894
|
+
// confirmations, notifications) never change when a deployment flips providers.
|
|
895
|
+
//
|
|
896
|
+
// Hard rules from the skills, enforced for BOTH providers:
|
|
897
|
+
// 1. Construct the client LAZILY — never validate creds at module import, or a
|
|
898
|
+
// build that collects env at build time (e.g. \`next build\`) dies with creds
|
|
899
|
+
// absent. (per [[portable-stack]] §15)
|
|
900
|
+
// 2. On Vercel/Lambda, SES creds use a custom SES_ prefix and are passed
|
|
901
|
+
// EXPLICITLY — Vercel injects its own AWS_* that would shadow the default
|
|
902
|
+
// credential chain. (skill caveat — see directives/email-setup.md)
|
|
903
|
+
// 3. Neither SDK is trusted to throw on a rejected send — we surface failures.
|
|
904
|
+
// 4. Unconfigured (no creds) -> logged NO-OP { sent:false }, never throws, so a
|
|
905
|
+
// sign-in / registration can't fail just because mail isn't wired yet.
|
|
906
|
+
|
|
907
|
+
import { SESClient, SendEmailCommand } from "@aws-sdk/client-ses";
|
|
908
|
+
import { Resend } from "resend";
|
|
909
|
+
|
|
910
|
+
export interface SendEmailParams {
|
|
911
|
+
to: string;
|
|
912
|
+
subject: string;
|
|
913
|
+
text: string;
|
|
914
|
+
html?: string;
|
|
915
|
+
/** Per-deployment override; defaults to the provider's configured FROM. Never noreply@. */
|
|
916
|
+
from?: string;
|
|
917
|
+
replyTo?: string;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
export interface SendEmailResult {
|
|
921
|
+
sent: boolean;
|
|
922
|
+
/** Why a send was skipped (no creds / no from) — for logs, not user display. */
|
|
923
|
+
skippedReason?: string;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
export type EmailProvider = "ses" | "resend";
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* Resolve the active provider from env. Pure + exported for testing. Defaults to
|
|
930
|
+
* SES; any value other than "resend" (including unset) -> SES.
|
|
931
|
+
*/
|
|
932
|
+
export function selectProvider(
|
|
933
|
+
value: string | undefined = process.env.EMAIL_PROVIDER,
|
|
934
|
+
): EmailProvider {
|
|
935
|
+
return value?.trim().toLowerCase() === "resend" ? "resend" : "ses";
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/* ───────────────────────────── SES ───────────────────────────── */
|
|
939
|
+
|
|
940
|
+
let _ses: SESClient | undefined;
|
|
941
|
+
|
|
942
|
+
function sesClient(): SESClient | null {
|
|
943
|
+
const region = process.env.SES_REGION;
|
|
944
|
+
const accessKeyId = process.env.SES_ACCESS_KEY_ID;
|
|
945
|
+
const secretAccessKey = process.env.SES_SECRET_ACCESS_KEY;
|
|
946
|
+
if (!region || !accessKeyId || !secretAccessKey) return null;
|
|
947
|
+
if (!_ses) {
|
|
948
|
+
// Pass creds EXPLICITLY — do NOT rely on the default chain. Vercel functions
|
|
949
|
+
// run on Lambda, which injects its own AWS_* env that would shadow ours.
|
|
950
|
+
_ses = new SESClient({
|
|
951
|
+
region,
|
|
952
|
+
credentials: { accessKeyId, secretAccessKey },
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
return _ses;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
async function sendViaSes(params: SendEmailParams): Promise<SendEmailResult> {
|
|
959
|
+
const ses = sesClient();
|
|
960
|
+
if (!ses) {
|
|
961
|
+
return {
|
|
962
|
+
sent: false,
|
|
963
|
+
skippedReason:
|
|
964
|
+
"SES creds not set (SES_REGION/SES_ACCESS_KEY_ID/SES_SECRET_ACCESS_KEY)",
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
const from = params.from ?? process.env.AWS_SES_FROM;
|
|
968
|
+
if (!from) {
|
|
969
|
+
return { sent: false, skippedReason: "no from address (AWS_SES_FROM unset)" };
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
await ses.send(
|
|
973
|
+
new SendEmailCommand({
|
|
974
|
+
Source: from,
|
|
975
|
+
Destination: { ToAddresses: [params.to] },
|
|
976
|
+
ReplyToAddresses: params.replyTo ? [params.replyTo] : undefined,
|
|
977
|
+
Message: {
|
|
978
|
+
Subject: { Data: params.subject, Charset: "UTF-8" },
|
|
979
|
+
Body: {
|
|
980
|
+
// Always send a text part — HTML-only is penalized by spam filters.
|
|
981
|
+
Text: { Data: params.text, Charset: "UTF-8" },
|
|
982
|
+
...(params.html
|
|
983
|
+
? { Html: { Data: params.html, Charset: "UTF-8" } }
|
|
984
|
+
: {}),
|
|
985
|
+
},
|
|
986
|
+
},
|
|
987
|
+
}),
|
|
988
|
+
);
|
|
989
|
+
// SendEmailCommand rejects (throws) on a hard failure; a resolved promise means
|
|
990
|
+
// SES accepted the message for delivery.
|
|
991
|
+
return { sent: true };
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
/* ───────────────────────────── Resend ───────────────────────────── */
|
|
995
|
+
|
|
996
|
+
let _resend: Resend | undefined;
|
|
997
|
+
|
|
998
|
+
function resendClient(): Resend | null {
|
|
999
|
+
const key = process.env.RESEND_API_KEY;
|
|
1000
|
+
if (!key) return null;
|
|
1001
|
+
if (!_resend) _resend = new Resend(key);
|
|
1002
|
+
return _resend;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
async function sendViaResend(params: SendEmailParams): Promise<SendEmailResult> {
|
|
1006
|
+
const resend = resendClient();
|
|
1007
|
+
if (!resend) {
|
|
1008
|
+
return { sent: false, skippedReason: "RESEND_API_KEY not set" };
|
|
1009
|
+
}
|
|
1010
|
+
const from = params.from ?? process.env.RESEND_FROM;
|
|
1011
|
+
if (!from) {
|
|
1012
|
+
return { sent: false, skippedReason: "no from address (RESEND_FROM unset)" };
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
const { error } = await resend.emails.send({
|
|
1016
|
+
from,
|
|
1017
|
+
to: params.to,
|
|
1018
|
+
subject: params.subject,
|
|
1019
|
+
text: params.text, // always send a text part — HTML-only is penalized
|
|
1020
|
+
html: params.html,
|
|
1021
|
+
replyTo: params.replyTo,
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
// The Resend SDK resolves successfully even on a rejected send — the reason is
|
|
1025
|
+
// in \`error\`. Surfacing it is our responsibility.
|
|
1026
|
+
if (error) {
|
|
1027
|
+
throw new Error(\`Resend rejected the send: \${error.name}: \${error.message}\`);
|
|
1028
|
+
}
|
|
1029
|
+
return { sent: true };
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
/* ───────────────────────────── public API ───────────────────────────── */
|
|
1033
|
+
|
|
1034
|
+
/**
|
|
1035
|
+
* Send one transactional email via the active provider. Returns
|
|
1036
|
+
* { sent: false, skippedReason } instead of throwing when mail is unconfigured,
|
|
1037
|
+
* so callers can proceed; throws only when a configured send is actually rejected.
|
|
1038
|
+
*/
|
|
1039
|
+
export async function sendEmail(
|
|
1040
|
+
params: SendEmailParams,
|
|
1041
|
+
): Promise<SendEmailResult> {
|
|
1042
|
+
return selectProvider() === "resend"
|
|
1043
|
+
? sendViaResend(params)
|
|
1044
|
+
: sendViaSes(params);
|
|
1045
|
+
}
|
|
1046
|
+
`;
|
|
1047
|
+
// Unit test for the mailer — only emitted for node-service (which scaffolds a
|
|
1048
|
+
// vitest runner). The relative import carries a .js extension for NodeNext.
|
|
1049
|
+
const EMAIL_MAILER_TEST_BODY = `import { describe, expect, it } from "vitest";
|
|
1050
|
+
|
|
1051
|
+
import { selectProvider } from "./mailer.js";
|
|
1052
|
+
|
|
1053
|
+
describe("selectProvider", () => {
|
|
1054
|
+
it("defaults to SES when unset", () => {
|
|
1055
|
+
expect(selectProvider(undefined)).toBe("ses");
|
|
1056
|
+
expect(selectProvider("")).toBe("ses");
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
it("selects resend only on an explicit 'resend' (case-insensitive)", () => {
|
|
1060
|
+
expect(selectProvider("resend")).toBe("resend");
|
|
1061
|
+
expect(selectProvider("Resend")).toBe("resend");
|
|
1062
|
+
expect(selectProvider(" RESEND ")).toBe("resend");
|
|
1063
|
+
});
|
|
1064
|
+
|
|
1065
|
+
it("any other value (including unsanctioned vendors) falls back to SES", () => {
|
|
1066
|
+
expect(selectProvider("ses")).toBe("ses");
|
|
1067
|
+
expect(selectProvider("sendgrid")).toBe("ses");
|
|
1068
|
+
expect(selectProvider("mailgun")).toBe("ses");
|
|
1069
|
+
});
|
|
1070
|
+
});
|
|
1071
|
+
`;
|
|
1072
|
+
/**
|
|
1073
|
+
* The env-var block appended to a scaffolded `.env.example` when the project
|
|
1074
|
+
* sends email. Both providers' vars are stubbed so switching is a one-line env
|
|
1075
|
+
* change with no code edit.
|
|
1076
|
+
*/
|
|
1077
|
+
export const EMAIL_ENV_BLOCK = `
|
|
1078
|
+
# ── Transactional / auth email (lib/email/mailer.ts) ────────────────────────
|
|
1079
|
+
# Provider router. Default: Amazon SES. Set to "resend" to use Resend instead —
|
|
1080
|
+
# no code change. See directives/email-setup.md + [[email-service-router]].
|
|
1081
|
+
EMAIL_PROVIDER=ses
|
|
1082
|
+
|
|
1083
|
+
# Amazon SES (default). Custom SES_ prefix + explicit creds is deliberate: on
|
|
1084
|
+
# Vercel/Lambda the platform injects its own AWS_* that would shadow the default
|
|
1085
|
+
# credential chain. SES_REGION MUST equal the region the sender domain is
|
|
1086
|
+
# verified in, or sends fail with "Email address is not verified".
|
|
1087
|
+
SES_REGION=
|
|
1088
|
+
SES_ACCESS_KEY_ID=
|
|
1089
|
+
SES_SECRET_ACCESS_KEY=
|
|
1090
|
+
# From address. A domain-verified identity can send from any local-part.
|
|
1091
|
+
# Format: "Brand Name <sender@yourdomain.com>". Never noreply@.
|
|
1092
|
+
AWS_SES_FROM=
|
|
1093
|
+
|
|
1094
|
+
# Resend (swappable alternative — only read when EMAIL_PROVIDER=resend).
|
|
1095
|
+
# RESEND_FROM must be on a Resend-verified domain.
|
|
1096
|
+
RESEND_API_KEY=
|
|
1097
|
+
RESEND_FROM=
|
|
1098
|
+
`;
|
|
1099
|
+
const EMAIL_SETUP_DIRECTIVE = `# Directive — Wire transactional / auth email for {{slug}}
|
|
1100
|
+
|
|
1101
|
+
**Decision (2026-06-28):** {{slug}} sends via **Amazon SES by default**, with
|
|
1102
|
+
Resend as a swappable alternative (\`EMAIL_PROVIDER=resend\`). SES is the default
|
|
1103
|
+
because the Z2W stacks already run authenticated SES in production — zero new
|
|
1104
|
+
vendor, no domain warmup, cheap at burst volume (past Resend Free's shared
|
|
1105
|
+
100/day · 3k/mo cap). Resend stays wired for a non-developer client who prefers
|
|
1106
|
+
the easier DX. See [[email-service-router]]; DO NOT add a fifth mail vendor.
|
|
1107
|
+
|
|
1108
|
+
Until the four \`SES_*\` vars are set, all sends are a **logged no-op**
|
|
1109
|
+
(\`{ sent: false }\`) — the app, dashboards, and login flow all work; only actual
|
|
1110
|
+
email delivery is deferred. This directive is the one-time setup to turn live
|
|
1111
|
+
email on. The \`sendEmail()\` call sites never change when you flip providers.
|
|
1112
|
+
|
|
1113
|
+
## What the operator does (AWS console + host env), one stage at a time
|
|
1114
|
+
|
|
1115
|
+
> Secrets go in the operator's OWN terminal / the AWS + host consoles — never
|
|
1116
|
+
> pasted into a chat/agent transcript ([[terminal-secret-hygiene]]).
|
|
1117
|
+
|
|
1118
|
+
1. **Verify the sender domain in the right region.** SES → *Verified identities*
|
|
1119
|
+
→ confirm your domain shows **Verified** with DKIM enabled. The identity is
|
|
1120
|
+
**region-scoped** — \`SES_REGION\` MUST equal that region.
|
|
1121
|
+
2. **Confirm production access (not sandbox).** SES → *Account dashboard*. In
|
|
1122
|
+
sandbox you can only send to verified recipients; request production access
|
|
1123
|
+
once if needed.
|
|
1124
|
+
3. **Create a send-only IAM key** allowing \`ses:SendEmail\` + \`ses:SendRawEmail\`
|
|
1125
|
+
only. These are IAM access keys (\`AKIA…\` + secret) for the SDK — NOT SMTP
|
|
1126
|
+
credentials.
|
|
1127
|
+
4. **Set the env vars** (see \`.env.example\`): \`EMAIL_PROVIDER=ses\`,
|
|
1128
|
+
\`SES_REGION\`, \`SES_ACCESS_KEY_ID\`, \`SES_SECRET_ACCESS_KEY\`, \`AWS_SES_FROM\`.
|
|
1129
|
+
On Vercel set them for Production + Preview.
|
|
1130
|
+
5. **Deploy, then smoke-test** with a real send to an allowlisted address; watch
|
|
1131
|
+
the logs for a \`skippedReason\` (creds still missing) vs. a clean send.
|
|
1132
|
+
|
|
1133
|
+
## To use Resend instead (a non-dev client)
|
|
1134
|
+
Set \`EMAIL_PROVIDER=resend\`, \`RESEND_API_KEY\`, and \`RESEND_FROM\` (from a
|
|
1135
|
+
Resend-verified domain). No code change.
|
|
1136
|
+
|
|
1137
|
+
## Uptime
|
|
1138
|
+
Point any uptime monitor at \`/health\` (DB-free), never a login or DB-touching
|
|
1139
|
+
URL ([[uptime-kuma-monitor]] / [[neon-postgres]]).
|
|
1140
|
+
`;
|
|
1141
|
+
/**
|
|
1142
|
+
* Build the email-wiring files for a scaffold that sends email. \`layout\`
|
|
1143
|
+
* selects the file paths + whether a vitest test is emitted:
|
|
1144
|
+
* - "nextjs" → \`lib/email/mailer.ts\` (imported via the \`@/*\` alias); no
|
|
1145
|
+
* test file (the nextjs scaffold ships no test runner).
|
|
1146
|
+
* - "node-service" → \`src/lib/email/mailer.ts\` + \`src/lib/email/mailer.test.ts\`
|
|
1147
|
+
* (vitest picks up \`src/**\/*.test.ts\`).
|
|
1148
|
+
* The directive is emitted for both.
|
|
1149
|
+
*/
|
|
1150
|
+
export function emailFiles(inputs, opts, spec, layout) {
|
|
1151
|
+
const dir = layout === "nextjs" ? "lib/email" : "src/lib/email";
|
|
1152
|
+
const files = [
|
|
1153
|
+
{ path: `${dir}/mailer.ts`, content: EMAIL_MAILER_BODY },
|
|
1154
|
+
{
|
|
1155
|
+
path: "directives/email-setup.md",
|
|
1156
|
+
content: sub(EMAIL_SETUP_DIRECTIVE, inputs, opts, spec),
|
|
1157
|
+
},
|
|
1158
|
+
];
|
|
1159
|
+
if (layout === "node-service") {
|
|
1160
|
+
files.push({ path: `${dir}/mailer.test.ts`, content: EMAIL_MAILER_TEST_BODY });
|
|
1161
|
+
}
|
|
1162
|
+
return files;
|
|
646
1163
|
}
|
|
@@ -4,6 +4,7 @@ export { scaffoldCfPages } from "./cf-pages.js";
|
|
|
4
4
|
export { scaffoldCfWorker } from "./cf-worker.js";
|
|
5
5
|
export { scaffoldLibrary } from "./library.js";
|
|
6
6
|
export { scaffoldNextjs, NEXTJS_SEO_BASELINE_PATHS } from "./nextjs.js";
|
|
7
|
+
export { scaffoldNodeService } from "./node-service.js";
|
|
7
8
|
export { scaffoldProtocolRepo } from "./protocol-repo.js";
|
|
8
9
|
export { scaffoldPythonService } from "./python-service.js";
|
|
9
10
|
export { scaffoldWpPlugin } from "./wp-plugin.js";
|
|
@@ -9,6 +9,7 @@ import { scaffoldCfPages } from "./cf-pages.js";
|
|
|
9
9
|
import { scaffoldCfWorker } from "./cf-worker.js";
|
|
10
10
|
import { scaffoldLibrary } from "./library.js";
|
|
11
11
|
import { scaffoldNextjs } from "./nextjs.js";
|
|
12
|
+
import { scaffoldNodeService } from "./node-service.js";
|
|
12
13
|
import { scaffoldProtocolRepo } from "./protocol-repo.js";
|
|
13
14
|
import { scaffoldPythonService } from "./python-service.js";
|
|
14
15
|
import { scaffoldWpPlugin } from "./wp-plugin.js";
|
|
@@ -16,6 +17,7 @@ export { scaffoldCfPages } from "./cf-pages.js";
|
|
|
16
17
|
export { scaffoldCfWorker } from "./cf-worker.js";
|
|
17
18
|
export { scaffoldLibrary } from "./library.js";
|
|
18
19
|
export { scaffoldNextjs, NEXTJS_SEO_BASELINE_PATHS } from "./nextjs.js";
|
|
20
|
+
export { scaffoldNodeService } from "./node-service.js";
|
|
19
21
|
export { scaffoldProtocolRepo } from "./protocol-repo.js";
|
|
20
22
|
export { scaffoldPythonService } from "./python-service.js";
|
|
21
23
|
export { scaffoldWpPlugin } from "./wp-plugin.js";
|
|
@@ -32,6 +34,7 @@ export function scaffoldByType(inputs, opts) {
|
|
|
32
34
|
nextjs: scaffoldNextjs,
|
|
33
35
|
"cf-pages": scaffoldCfPages,
|
|
34
36
|
"python-service": scaffoldPythonService,
|
|
37
|
+
"node-service": scaffoldNodeService,
|
|
35
38
|
"wp-plugin": scaffoldWpPlugin,
|
|
36
39
|
"protocol-repo": scaffoldProtocolRepo,
|
|
37
40
|
};
|