feat(scripts): add mustache render-template via Responses pages

Add HTML template kind to Responses with a seeded system email-default
template, render-template.js using Mustache, and html body support in
send-email. Templates are editable but system pages cannot be deleted.

Co-authored-by: Nasyarobby Putra <nasyarobby@gmail.com>
This commit is contained in:
Cursor Agent
2026-08-15 01:44:51 +00:00
co-authored by nsrb
parent 23ce72fec2
commit 46e2cbb83b
12 changed files with 426 additions and 50 deletions
+13 -5
View File
@@ -2,7 +2,7 @@ import { timingSafeEqual } from "node:crypto";
import { kvGet } from "./kv-store.js";
import { getSecretPlaintext } from "./secrets-store.js";
import { getHttpAuthInternal, assertAuthType } from "./http-auths-store.js";
import { getHttpPageByName, contentTypeForMime } from "./http-pages-store.js";
import { getHttpPageByName, contentTypeForMime, assertHttpResponsePage } from "./http-pages-store.js";
import { log } from "./logger.js";
/**
@@ -246,14 +246,18 @@ export function resolveUnauthorizedSpec(trigger, mechanism) {
export async function sendHttpPageOrJson(reply, status, pageName, fallbackBody) {
if (pageName) {
const page = await getHttpPageByName(pageName);
if (page) {
if (page && page.kind !== "template") {
const code = status ?? page.status;
return reply
.code(code)
.type(contentTypeForMime(page.mime))
.send(page.content);
}
log.warn({ pageName }, "http page not found; using fallback");
if (page?.kind === "template") {
log.warn({ pageName }, "http template page cannot be used as HTTP response");
} else {
log.warn({ pageName }, "http page not found; using fallback");
}
}
return reply.code(status).send(fallbackBody ?? { error: "unauthorized" });
}
@@ -266,12 +270,16 @@ export async function sendHttpPageOrJson(reply, status, pageName, fallbackBody)
*/
export async function sendSuccessPage(reply, pageName, fallbackBody) {
const page = await getHttpPageByName(pageName);
if (page) {
if (page && page.kind !== "template") {
return reply
.code(page.status)
.type(contentTypeForMime(page.mime))
.send(page.content);
}
log.warn({ pageName }, "success page not found; using default JSON");
if (page?.kind === "template") {
log.warn({ pageName }, "html template page cannot be used as HTTP success response");
} else {
log.warn({ pageName }, "success page not found; using default JSON");
}
return reply.send(fallbackBody);
}