TypeScript/Bun project scaffold
- Stack: Bun, Hono, Drizzle ORM, Zod, Handlebars, Pino - Models: ticket, queue, transaction, scrip, template, custom_field, user, lifecycle - Scrip engine: prepare/commit two-phase dispatch, template rendering, mock actions - Lifecycle validator: state machine transition validation with wildcard support - Routes: health, tickets (full CRUD + preview + transactions), queues, scrips, custom-fields, lifecycles - Middleware: Pino logging, error handler - Database: Drizzle ORM schema + initial migration (10 tables) - Type-check: passes (tsc --noEmit, zero errors)
This commit is contained in:
39
src/scrip/templates.ts
Normal file
39
src/scrip/templates.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import Handlebars from 'handlebars';
|
||||
|
||||
export class TemplateRenderer {
|
||||
render(
|
||||
subjectTemplate: string,
|
||||
bodyTemplate: string,
|
||||
context: TemplateContext,
|
||||
): { subject: string; body: string } {
|
||||
const subjectCompiled = Handlebars.compile(subjectTemplate);
|
||||
const bodyCompiled = Handlebars.compile(bodyTemplate);
|
||||
return {
|
||||
subject: subjectCompiled(context),
|
||||
body: bodyCompiled(context),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export interface TemplateContext {
|
||||
ticket: {
|
||||
id: string;
|
||||
subject: string;
|
||||
status: string;
|
||||
queue_id: string;
|
||||
owner_id: string | null;
|
||||
creator_id: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
};
|
||||
queue: {
|
||||
name: string;
|
||||
};
|
||||
transaction: {
|
||||
type: string;
|
||||
field: string | null;
|
||||
old_value: string | null;
|
||||
new_value: string | null;
|
||||
};
|
||||
custom_fields: Record<string, string>;
|
||||
}
|
||||
Reference in New Issue
Block a user