chore: server-and-serverless template

This commit is contained in:
e2e
2026-06-28 17:35:09 +02:00
commit 73f8ded296
202 changed files with 9063 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
import { LocalEmailService, type EmailService, type SendEmailInput, type SendEmailResult } from '@pikku/core/services'
import { renderEmailTemplate, type EmailTemplateName } from '../../.pikku/email/pikku-emails.gen.js'
type GeneratedTemplateEmailServiceOptions = {
delegate?: EmailService
defaultLocale?: string
}
export class GeneratedTemplateEmailService implements EmailService {
private readonly delegate: EmailService
private readonly defaultLocale: string
constructor(options: GeneratedTemplateEmailServiceOptions = {}) {
this.delegate = options.delegate ?? new LocalEmailService()
this.defaultLocale = options.defaultLocale ?? 'en'
}
async send(input: SendEmailInput): Promise<SendEmailResult> {
if (!('template' in input) || !input.template) {
return this.delegate.send(input)
}
const rendered = renderEmailTemplate({
name: input.template.name as EmailTemplateName,
locale: (input.template.locale ?? this.defaultLocale) as Parameters<typeof renderEmailTemplate>[0]['locale'],
data: input.template.data ?? {},
})
return this.delegate.send({
to: input.to,
from: input.from,
cc: input.cc,
bcc: input.bcc,
replyTo: input.replyTo,
headers: {
...(input.headers ?? {}),
'x-pikku-email-template': String(input.template.name),
'x-pikku-email-hash': rendered.hash,
},
subject: rendered.subject,
html: rendered.html,
...(rendered.text ? { text: rendered.text } : {}),
})
}
}