118 lines
4.5 KiB
TypeScript
118 lines
4.5 KiB
TypeScript
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { tmpdir } from 'node:os';
|
|
import { mailBrandingFromConfig } from '../src/mail/mail-branding';
|
|
import { MailTemplateName } from '../src/mail/mail-template.constants';
|
|
import { MailTemplateRendererService } from '../src/mail/mail-template-renderer.service';
|
|
|
|
const outputDir = process.env.MAIL_PREVIEW_DIR ?? join(tmpdir(), 'ldap-portal-mail-previews');
|
|
const renderer = new MailTemplateRendererService();
|
|
const branding = mailBrandingFromConfig({
|
|
get: (key: string) =>
|
|
({
|
|
PUBLIC_WEB_URL: 'https://portal.example.com',
|
|
MAIL_PRODUCT_NAME: 'LDAP Portal',
|
|
MAIL_COMPANY_NAME: 'Example AG',
|
|
MAIL_PRIMARY_COLOR: '#2563eb',
|
|
MAIL_SUPPORT_EMAIL: 'support@example.com',
|
|
MAIL_IMPRINT_URL: 'https://example.com/impressum',
|
|
MAIL_PRIVACY_URL: 'https://example.com/datenschutz',
|
|
})[key],
|
|
} as never);
|
|
|
|
const common = {
|
|
branding,
|
|
locale: 'de-DE',
|
|
};
|
|
|
|
const previews: Array<{ fileName: string; templateName: MailTemplateName; context: Record<string, unknown> }> = [
|
|
{
|
|
fileName: 'password-reset.html',
|
|
templateName: MailTemplateName.PASSWORD_RESET,
|
|
context: {
|
|
...common,
|
|
preheader: 'Passwort zuruecksetzen.',
|
|
title: 'Passwort zuruecksetzen',
|
|
subtitle: 'Fuer Ihr Benutzerkonto wurde das Zuruecksetzen des Passworts angefordert.',
|
|
greeting: 'Guten Tag Max Mustermann,',
|
|
action: {
|
|
label: 'Passwort zuruecksetzen',
|
|
url: 'https://portal.example.com/reset-password?token=preview-token',
|
|
},
|
|
alternateUrlLabel: 'Falls die Schaltflaeche nicht funktioniert, kopieren Sie diese URL:',
|
|
expiresAtLabel: '17.07.2026, 15:30',
|
|
warningBox: {
|
|
title: 'Sicherheitshinweis',
|
|
text: 'Falls Sie diese Anfrage nicht selbst gestellt haben, koennen Sie diese E-Mail ignorieren.',
|
|
},
|
|
},
|
|
},
|
|
{
|
|
fileName: 'account-created.html',
|
|
templateName: MailTemplateName.ACCOUNT_CREATED,
|
|
context: {
|
|
...common,
|
|
preheader: 'Ihr Benutzerkonto wurde angelegt.',
|
|
title: 'Benutzerkonto erstellt',
|
|
subtitle: 'Ihr Benutzerkonto fuer LDAP Portal ist einsatzbereit.',
|
|
greeting: 'Guten Tag Max Mustermann,',
|
|
username: 'max.mustermann@example.com',
|
|
keyValues: [{ key: 'Benutzername', value: 'max.mustermann@example.com' }],
|
|
action: { label: 'Zur Anwendung', url: 'https://portal.example.com' },
|
|
alternateUrlLabel: 'Direkter Link zur Anwendung:',
|
|
},
|
|
},
|
|
{
|
|
fileName: 'invitation.html',
|
|
templateName: MailTemplateName.INVITATION,
|
|
context: {
|
|
...common,
|
|
preheader: 'Einladung zu LDAP Portal.',
|
|
title: 'Einladung annehmen',
|
|
subtitle: 'Example AG hat Sie zu LDAP Portal eingeladen.',
|
|
greeting: 'Guten Tag,',
|
|
inviter: 'Example AG',
|
|
expiresAtLabel: '24.07.2026, 12:00',
|
|
action: { label: 'Einladung annehmen', url: 'https://portal.example.com/invitation/preview' },
|
|
alternateUrlLabel: 'Falls die Schaltflaeche nicht funktioniert, kopieren Sie diese URL:',
|
|
warningBox: {
|
|
title: 'Sicherheitshinweis',
|
|
text: 'Leiten Sie diese Einladung nicht weiter. Der Link ist nur fuer die vorgesehene Person bestimmt.',
|
|
},
|
|
},
|
|
},
|
|
{
|
|
fileName: 'generic-notification.html',
|
|
templateName: MailTemplateName.GENERIC_NOTIFICATION,
|
|
context: {
|
|
...common,
|
|
preheader: 'Neue Benachrichtigung in LDAP Portal.',
|
|
title: 'Neue Benachrichtigung',
|
|
paragraphs: ['Eine fachliche Aktion wurde erfolgreich abgeschlossen.', 'Weitere Details finden Sie in der Anwendung.'],
|
|
infoBox: { title: 'Hinweis', text: 'Diese Nachricht dient nur Ihrer Information.' },
|
|
action: { label: 'Details ansehen', url: 'https://portal.example.com/notifications/preview' },
|
|
},
|
|
},
|
|
{
|
|
fileName: 'warning-notification.html',
|
|
templateName: MailTemplateName.WARNING_NOTIFICATION,
|
|
context: {
|
|
...common,
|
|
preheader: 'Warnmeldung in LDAP Portal.',
|
|
title: 'Warnmeldung',
|
|
paragraphs: ['Eine geplante Verarbeitung konnte nicht vollstaendig abgeschlossen werden.'],
|
|
warningBox: { title: 'Pruefung erforderlich', text: 'Bitte pruefen Sie die Details in der Anwendung.' },
|
|
action: { label: 'Warnung pruefen', url: 'https://portal.example.com/admin/audit' },
|
|
},
|
|
},
|
|
];
|
|
|
|
mkdirSync(outputDir, { recursive: true });
|
|
|
|
for (const preview of previews) {
|
|
const html = renderer.renderHtml(preview.templateName, preview.context);
|
|
writeFileSync(join(outputDir, preview.fileName), html, 'utf8');
|
|
}
|
|
|
|
console.log(`Mail previews written to ${outputDir}`);
|