features
This commit is contained in:
24
apps/api/scripts/copy-mail-assets.js
Normal file
24
apps/api/scripts/copy-mail-assets.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const { copyFileSync, existsSync, mkdirSync, readdirSync, statSync } = require('node:fs');
|
||||
const { join } = require('node:path');
|
||||
|
||||
const source = join(__dirname, '..', 'src', 'mail', 'templates');
|
||||
const target = join(__dirname, '..', 'dist', 'mail', 'templates');
|
||||
|
||||
function copyDirectory(from, to) {
|
||||
if (!existsSync(from)) {
|
||||
return;
|
||||
}
|
||||
|
||||
mkdirSync(to, { recursive: true });
|
||||
for (const entry of readdirSync(from)) {
|
||||
const sourcePath = join(from, entry);
|
||||
const targetPath = join(to, entry);
|
||||
if (statSync(sourcePath).isDirectory()) {
|
||||
copyDirectory(sourcePath, targetPath);
|
||||
} else {
|
||||
copyFileSync(sourcePath, targetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
copyDirectory(source, target);
|
||||
95
apps/api/scripts/render-mail-previews.ts
Normal file
95
apps/api/scripts/render-mail-previews.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { mailBranding } from '../src/mail/mail-branding';
|
||||
import { MailTemplateName } from '../src/mail/mail-template.constants';
|
||||
import { MailTemplateRendererService } from '../src/mail/mail-template-renderer.service';
|
||||
|
||||
const outputDir = join(process.cwd(), 'tmp', 'mail-previews');
|
||||
const config = new ConfigService({
|
||||
MAIL_PRODUCT_NAME: 'LDAP Portal',
|
||||
MAIL_COMPANY_NAME: 'Example Corp',
|
||||
MAIL_PRIMARY_COLOR: '#0f6b6e',
|
||||
MAIL_SUPPORT_EMAIL: 'support@example.com',
|
||||
});
|
||||
const branding = mailBranding(config);
|
||||
const renderer = new MailTemplateRendererService();
|
||||
|
||||
async function main(): Promise<void> {
|
||||
await mkdir(outputDir, { recursive: true });
|
||||
const expiresAtText = new Intl.DateTimeFormat('de-DE', { dateStyle: 'medium', timeStyle: 'short' }).format(
|
||||
new Date(Date.now() + 30 * 60_000),
|
||||
);
|
||||
|
||||
const previews: Array<{ name: MailTemplateName; context: Record<string, unknown> }> = [
|
||||
{
|
||||
name: MailTemplateName.PASSWORD_RESET,
|
||||
context: {
|
||||
branding,
|
||||
title: 'Passwort zuruecksetzen',
|
||||
preheader: 'Fuer dein Benutzerkonto wurde das Zuruecksetzen des Passworts angefordert.',
|
||||
greeting: 'Hallo Maria,',
|
||||
intro: 'Fuer dein Benutzerkonto wurde das Zuruecksetzen des Passworts angefordert. Ueber die folgende Schaltflaeche kannst du ein neues Passwort vergeben.',
|
||||
action: { label: 'Passwort zuruecksetzen', url: 'https://portal.example.com/reset-password?token=preview' },
|
||||
resetUrl: 'https://portal.example.com/reset-password?token=preview',
|
||||
expiresAtText,
|
||||
warningBox: {
|
||||
title: 'Sicherheitshinweis',
|
||||
text: 'Falls du diese Anfrage nicht selbst gestellt hast, kannst du diese E-Mail ignorieren.',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: MailTemplateName.ACCOUNT_CREATED,
|
||||
context: {
|
||||
branding,
|
||||
title: 'Willkommen bei LDAP Portal',
|
||||
greeting: 'Hallo Maria,',
|
||||
intro: 'Dein Benutzerkonto wurde angelegt. Du kannst dich jetzt anmelden.',
|
||||
action: { label: 'Zur Anwendung', url: 'https://portal.example.com' },
|
||||
},
|
||||
},
|
||||
{
|
||||
name: MailTemplateName.INVITATION,
|
||||
context: {
|
||||
branding,
|
||||
title: 'Einladung zu LDAP Portal',
|
||||
intro: 'Du wurdest eingeladen, die Anwendung zu nutzen.',
|
||||
invitedBy: 'Max Mustermann',
|
||||
action: { label: 'Einladung annehmen', url: 'https://portal.example.com/invite/preview' },
|
||||
invitationUrl: 'https://portal.example.com/invite/preview',
|
||||
expiresAtText,
|
||||
infoBox: { text: `Diese Einladung ist gueltig bis ${expiresAtText}.` },
|
||||
},
|
||||
},
|
||||
{
|
||||
name: MailTemplateName.GENERIC_NOTIFICATION,
|
||||
context: {
|
||||
branding,
|
||||
title: 'Neue Benachrichtigung',
|
||||
intro: 'Es gibt eine neue Systembenachrichtigung.',
|
||||
paragraphs: ['Der Status deines Vorgangs wurde aktualisiert.'],
|
||||
action: { label: 'Details anzeigen', url: 'https://portal.example.com/notifications/preview' },
|
||||
},
|
||||
},
|
||||
{
|
||||
name: MailTemplateName.WARNING_NOTIFICATION,
|
||||
context: {
|
||||
branding,
|
||||
title: 'Warnmeldung',
|
||||
intro: 'Eine Aktion erfordert Aufmerksamkeit.',
|
||||
warningBox: { text: 'Bitte pruefe die betroffene Konfiguration.' },
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
for (const preview of previews) {
|
||||
const html = await renderer.renderHtml(preview.name, preview.context);
|
||||
await writeFile(join(outputDir, `${preview.name}.html`), html, 'utf8');
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in New Issue
Block a user