Skip to content

Support multiple templates and log sent emails - #7

Merged
vadim9999 merged 4 commits into
mainfrom
feat/multiple-templates
Dec 1, 2026
Merged

vadim9999 merged 4 commits into
mainfrom
feat/multiple-templates

Conversation

@vadim9999

@vadim9999 vadim9999 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What

  • Several templates. db.json now holds { templates, sentEmails }. Each template has its own tree and its own elements ({ id, name, tree, elements, createdAt, updatedAt }).

  • Automatic migration. An old file with recipeTemplate: { tree, options } is converted on first start into one template named "Default template". The sample db.json is migrated too.

  • Template CRUD. GET /templates, POST /templates, GET|PATCH|DELETE /templates/:templateId. Deleting a template also removes its generated file.

  • Tree, elements and generate move under the template:

    • /templates/:templateId/tree
    • /tree/nodes[/:key]
    • /elements[/:key]
    • /generate

    /generate writes generated/<templateId>.html, so templates no longer overwrite each other's output.

  • Sent emails log (no delivery yet).

    • POST /templates/:templateId/send { to, subject } renders the template and records it with status: "logged".
    • GET /sent-emails lists entries without the HTML.
    • GET /sent-emails/:id returns one entry with the HTML snapshot.
    • Log entries stay after their template is deleted.
  • Validation and errors.

    • templateId must match ^[\w-]{1,128}$, because it becomes a file name.
    • An unknown template returns 404 NOT_FOUND.
  • Docs and version. OpenAPI, README (endpoints, errors, a v2 → v3 migration section) and AGENTS.md are updated. The version is now 3.0.0.

Breaking: /tree, /elements and /generate are removed.

Why

The editor supported only one template. This adds several templates, a list of them, and a log of sent emails. There is no SMTP yet: "send" records the email and does not deliver it.

How to verify

  • npm run lint && npm run format:check && npm run typecheck && npm test all pass (103 tests). npm run openapi leaves no diff.
  • I ran the server against the old v2 db.json. GET /templates returned "Default template" with the original tree and 3 elements. Generate and send worked, and GET /tree returned 404.

Checklist

db.json now holds { templates, sentEmails }. Each template has its own
tree and its own library of elements; node and element keys are unique
within a template. The old single recipeTemplate is migrated on load
into one template named "Default template" (options become elements).

New: GET/POST /templates, GET/PATCH/DELETE /templates/:templateId.
Tree, elements and generate move under /templates/:templateId; the old
/tree, /elements and /generate routes are removed. Unknown templates
return 404 NOT_FOUND, every change bumps the template's updatedAt, and
generate writes public/generated/<templateId>.html (removed together
with the template).

Breaking change: version 3.0.0.
Sending renders the template and records it in db.json (recipients,
subject, template name, HTML snapshot, status "logged"). No email is
delivered yet: there is no transport. An empty tree returns 422
TREE_EMPTY; recipients must be 1-50 valid addresses and the subject
1-300 characters.

GET /sent-emails lists entries newest first without the HTML;
GET /sent-emails/:id returns one entry with it. Entries are kept when
their template is deleted.
Ran the store's own migration once: the No More To-Go weekly menu
becomes the "Default template" with the same tree and elements.
README: endpoint table under /templates/:templateId, error codes and a
v2 to v3 route migration section. AGENTS.md and the add-endpoint skill
describe the db.json shape and how template-scoped routes are built.
@vadim9999

Copy link
Copy Markdown
Contributor Author

Matching frontend PR: LLazyEmail/email-template-editor-reactjs#63

@vadim9999
vadim9999 merged commit c89d7fb into main Dec 1, 2026
2 checks passed
@vadim9999
vadim9999 deleted the feat/multiple-templates branch December 1, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant