import { Liquid } from "liquidjs"; import type { ParsedLure, LureRequest } from "./types.js"; const engine = new Liquid({ strictVariables: false, strictFilters: false }); export async function renderTemplate(lure: ParsedLure, req: LureRequest): Promise { let payload: unknown = null; if (lure.frontmatter.payload?.contentType === "json") { const text = new TextDecoder().decode(req.rawBody); payload = JSON.parse(text) as unknown; } const scope: Record = { payload, headers: Object.fromEntries(req.headers), query: Object.fromEntries(req.query), }; return engine.parseAndRender(lure.template, scope); }