265 lines
10 KiB
JavaScript
265 lines
10 KiB
JavaScript
const { readFileSync, writeFileSync } = require('fs');
|
||
const { join } = require('path');
|
||
const Handlebars = require('handlebars');
|
||
|
||
// Les couleurs standardisées, comme dans le service
|
||
const STANDARD_COLORS = {
|
||
HEADER: '#171424',
|
||
BUTTON: '#efc543',
|
||
BUTTON_HOVER: '#d4a834',
|
||
BUTTON_TEXT: '#000000',
|
||
ALERT_RED: '#EF4444',
|
||
};
|
||
|
||
// On récupère le type d'email depuis les arguments de la ligne de commande
|
||
const sampleType = process.argv[2] || 'account-activation'; // e.g. 'account-activation', 'access-updated', 'access-revoked'
|
||
|
||
// Définition des templates (une version JS simplifiée de EMAIL_TEMPLATES_V2)
|
||
const EMAIL_TEMPLATES = {
|
||
'account-activation': {
|
||
subject: 'Activez votre espace Odentas Paie – {{organizationName}}',
|
||
title: 'Activez votre espace',
|
||
greeting: '{{#if firstName}}Bonjour {{firstName}},{{/if}}',
|
||
mainMessage: 'Bienvenue ! Vous avez été invité à rejoindre {{organizationName}} sur Odentas Paie.',
|
||
ctaText: 'Activer mon compte',
|
||
footerText: 'Vous recevez cet e-mail car un accès vous a été créé sur Odentas Paie.',
|
||
preheaderText: 'Activation de votre espace · {{organizationName}} · Activez maintenant',
|
||
colors: {
|
||
headerColor: STANDARD_COLORS.HEADER,
|
||
titleColor: '#0F172A',
|
||
buttonColor: STANDARD_COLORS.BUTTON,
|
||
buttonTextColor: STANDARD_COLORS.BUTTON_TEXT,
|
||
cardBackgroundColor: '#FFFFFF',
|
||
cardBorder: '#E5E7EB',
|
||
cardTitleColor: '#0F172A',
|
||
alertIndicatorColor: '#22C55E',
|
||
},
|
||
infoCard: [
|
||
{ label: 'Organisation', key: 'organizationName' },
|
||
{ label: 'Votre email', key: 'userEmail' },
|
||
{ label: 'Statut', key: 'status' },
|
||
],
|
||
detailsCard: {
|
||
title: 'Informations',
|
||
rows: [
|
||
{ label: 'Plateforme', key: 'platform' },
|
||
{ label: 'Action requise', key: 'actionRequired' },
|
||
]
|
||
}
|
||
},
|
||
'access-updated': {
|
||
subject: 'Vos habilitations ont été modifiées – {{organizationName}}',
|
||
title: 'Habilitation mise à jour',
|
||
greeting: '{{#if firstName}}Bonjour {{firstName}},{{/if}}',
|
||
mainMessage: 'Votre rôle au sein de {{organizationName}} a été modifié.',
|
||
ctaText: 'Voir vos accès',
|
||
footerText: 'Vous recevez cet e-mail suite à une modification de vos droits d’accès.',
|
||
preheaderText: 'Habilitation mise à jour · Nouveau rôle: {{newRole}}',
|
||
colors: {
|
||
headerColor: STANDARD_COLORS.HEADER,
|
||
titleColor: '#0F172A',
|
||
buttonColor: STANDARD_COLORS.BUTTON,
|
||
buttonTextColor: STANDARD_COLORS.BUTTON_TEXT,
|
||
cardBackgroundColor: '#FFFFFF',
|
||
cardBorder: '#E5E7EB',
|
||
cardTitleColor: '#0F172A',
|
||
alertIndicatorColor: '#F59E0B',
|
||
},
|
||
infoCard: [
|
||
{ label: 'Organisation', key: 'organizationName' },
|
||
{ label: 'Utilisateur', key: 'userEmail' },
|
||
],
|
||
detailsCard: {
|
||
title: 'Détails de la modification',
|
||
rows: [
|
||
{ label: 'Ancien rôle', key: 'oldRole' },
|
||
{ label: 'Nouveau rôle', key: 'newRole' },
|
||
{ label: 'Modifié par', key: 'updatedBy' },
|
||
{ label: 'Date', key: 'updateDate' },
|
||
]
|
||
}
|
||
},
|
||
'access-revoked': {
|
||
subject: 'Votre accès a été révoqué – {{organizationName}}',
|
||
title: 'Accès révoqué',
|
||
greeting: '{{#if firstName}}Bonjour {{firstName}},{{/if}}',
|
||
mainMessage: 'Votre accès à {{organizationName}} a été révoqué.',
|
||
ctaText: 'Contacter le support',
|
||
footerText: 'Vous recevez cet e-mail pour vous informer de la révocation de votre accès.',
|
||
preheaderText: 'Accès révoqué · Contactez le support en cas d’erreur',
|
||
colors: {
|
||
headerColor: STANDARD_COLORS.HEADER,
|
||
titleColor: '#0F172A',
|
||
buttonColor: STANDARD_COLORS.BUTTON,
|
||
buttonTextColor: STANDARD_COLORS.BUTTON_TEXT,
|
||
cardBackgroundColor: '#FFFFFF',
|
||
cardBorder: '#E5E7EB',
|
||
cardTitleColor: '#0F172A',
|
||
alertIndicatorColor: STANDARD_COLORS.ALERT_RED,
|
||
},
|
||
infoCard: [
|
||
{ label: 'Organisation', key: 'organizationName' },
|
||
{ label: 'Utilisateur', key: 'userEmail' },
|
||
{ label: 'Statut', key: 'status' },
|
||
],
|
||
detailsCard: {
|
||
title: 'Détails de la révocation',
|
||
rows: [
|
||
{ label: 'Date de révocation', key: 'revocationDate' },
|
||
{ label: 'Révoqué par', key: 'revokedBy' },
|
||
{ label: 'Raison', key: 'reason' },
|
||
]
|
||
}
|
||
},
|
||
'contract-cancelled': {
|
||
subject: 'CDDU annulé - {{employeeName}}',
|
||
title: 'CDDU annulé',
|
||
greeting: 'Bonjour {{userName}},',
|
||
mainMessage: 'Votre contrat CDDU a été annulé.',
|
||
closingMessage: 'Pour votre sécurité, ne partagez jamais ce message. <br>Si vous n\'êtes pas à l\'origine de cette annulation, <a href="{{supportUrl}}" style="color:#0B5FFF; text-decoration:none;">contactez le support</a>.<br><br>L\'équipe Odentas vous remercie pour votre confiance.',
|
||
ctaText: 'Accès à l\'Espace Paie',
|
||
footerText: 'Vous recevez cet e-mail car vous êtes client de Odentas, <br>pour vous notifier d\'une action sur votre compte.',
|
||
preheaderText: 'CDDU annulé pour {{employeeName}} · Réf {{contractReference}}',
|
||
colors: {
|
||
headerColor: STANDARD_COLORS.HEADER,
|
||
titleColor: '#0F172A',
|
||
buttonColor: STANDARD_COLORS.BUTTON,
|
||
buttonTextColor: STANDARD_COLORS.BUTTON_TEXT,
|
||
cardBackgroundColor: '#FFFFFF',
|
||
cardBorder: '#E5E7EB',
|
||
cardTitleColor: '#0F172A',
|
||
alertIndicatorColor: STANDARD_COLORS.ALERT_RED,
|
||
},
|
||
infoCard: [
|
||
{ label: 'Votre structure', key: 'companyName' },
|
||
{ label: 'Votre code employeur', key: 'employerCode' },
|
||
{ label: 'Votre gestionnaire', key: 'handlerName' },
|
||
],
|
||
detailsCard: {
|
||
title: 'Détails du contrat',
|
||
rows: [
|
||
{ label: 'Référence', key: 'contractReference' },
|
||
{ label: 'Salarié', key: 'employeeName' },
|
||
{ label: 'Poste', key: 'profession' },
|
||
]
|
||
}
|
||
},
|
||
'employee-created': {
|
||
subject: 'Nouveau salarié créé - {{employeeName}}',
|
||
title: 'Nouveau salarié créé',
|
||
greeting: 'Bonjour {{userName}},',
|
||
mainMessage: 'Un nouveau salarié a été créé avec succès dans votre Espace Paie Odentas.',
|
||
ctaText: 'Voir la fiche du salarié',
|
||
footerText: 'Vous recevez cet e-mail car vous êtes client de Odentas, pour vous notifier d\'une action sur votre compte.',
|
||
preheaderText: 'Nouveau salarié créé · Consultez la fiche du salarié',
|
||
colors: {
|
||
headerColor: STANDARD_COLORS.HEADER,
|
||
titleColor: '#0F172A',
|
||
buttonColor: STANDARD_COLORS.BUTTON,
|
||
buttonTextColor: STANDARD_COLORS.BUTTON_TEXT,
|
||
cardBackgroundColor: '#FFFFFF',
|
||
cardBorder: '#E5E7EB',
|
||
cardTitleColor: '#0F172A',
|
||
alertIndicatorColor: '#10B981',
|
||
},
|
||
infoCard: [
|
||
{ label: 'Votre structure', key: 'companyName' },
|
||
{ label: 'Votre code employeur', key: 'employerCode' },
|
||
{ label: 'Votre gestionnaire', key: 'handlerName' },
|
||
],
|
||
detailsCard: {
|
||
title: 'Détails du salarié',
|
||
rows: [
|
||
{ label: 'Salarié', key: 'employeeName' },
|
||
{ label: 'Email', key: 'email' },
|
||
{ label: 'Matricule', key: 'matricule' },
|
||
]
|
||
}
|
||
},
|
||
};
|
||
|
||
// Données de test
|
||
const sampleData = {
|
||
firstName: 'Marie',
|
||
userName: 'Gérant de Test',
|
||
companyName: 'Ma Super Production',
|
||
employerCode: 'PROD-123',
|
||
handlerName: 'Renaud BREVIERE-ABRAHAM',
|
||
organizationName: 'Compagnie Théâtrale',
|
||
userEmail: 'marie@example.com',
|
||
status: 'En attente d\'activation',
|
||
platform: 'Odentas Paie',
|
||
actionRequired: 'Activation du compte',
|
||
oldRole: 'AGENT',
|
||
newRole: 'ADMIN',
|
||
updatedBy: 'admin@odentas.fr',
|
||
updateDate: new Date().toLocaleString('fr-FR'),
|
||
revocationDate: new Date().toLocaleString('fr-FR'),
|
||
revokedBy: 'admin@odentas.fr',
|
||
reason: 'Accès obsolète',
|
||
employeeName: 'John Doe',
|
||
email: 'john.doe@example.com',
|
||
matricule: 'SAL-007',
|
||
contractReference: 'CDDU-XYZ-001',
|
||
profession: 'Acteur',
|
||
ctaUrl: 'https://example.com',
|
||
supportUrl: 'mailto:paie@odentas.fr',
|
||
};
|
||
|
||
// Logique de rendu
|
||
function renderEmail(type) {
|
||
const templateConfig = EMAIL_TEMPLATES[type];
|
||
if (!templateConfig) {
|
||
console.error(`Type de template inconnu: ${type}`);
|
||
process.exit(1);
|
||
}
|
||
|
||
// Compilation des variables Handlebars
|
||
const compiledTemplate = (templateString) => Handlebars.compile(templateString)(sampleData);
|
||
|
||
const templateData = {
|
||
// Textes
|
||
subject: compiledTemplate(templateConfig.subject),
|
||
title: compiledTemplate(templateConfig.title),
|
||
greeting: templateConfig.greeting ? compiledTemplate(templateConfig.greeting) : undefined,
|
||
mainMessage: compiledTemplate(templateConfig.mainMessage),
|
||
closingMessage: templateConfig.closingMessage ? compiledTemplate(templateConfig.closingMessage) : undefined,
|
||
ctaText: templateConfig.ctaText ? compiledTemplate(templateConfig.ctaText) : undefined,
|
||
footerText: compiledTemplate(templateConfig.footerText),
|
||
preheaderText: compiledTemplate(templateConfig.preheaderText),
|
||
textFallback: `${compiledTemplate(templateConfig.title)} - ${compiledTemplate(templateConfig.mainMessage)}`,
|
||
|
||
// URLs
|
||
ctaUrl: sampleData.ctaUrl,
|
||
logoUrl: 'https://newstaging.odentas.fr/wp-content/uploads/2025/08/Odentas-Logo-Bleu-Fond-Transparent-4-1.png',
|
||
|
||
// Cartes
|
||
showInfoCard: !!templateConfig.infoCard,
|
||
infoCardRows: templateConfig.infoCard?.map(field => ({
|
||
label: field.label,
|
||
value: sampleData[field.key] ?? '—'
|
||
})),
|
||
|
||
showDetailsCard: !!templateConfig.detailsCard,
|
||
detailsCardTitle: templateConfig.detailsCard?.title,
|
||
detailsCardRows: templateConfig.detailsCard?.rows.map(field => ({
|
||
label: field.label,
|
||
value: sampleData[field.key] ?? '—'
|
||
})),
|
||
|
||
// Couleurs
|
||
...templateConfig.colors,
|
||
};
|
||
|
||
// Charger et compiler le template HTML principal
|
||
const templatePath = join(process.cwd(), 'templates-mails', 'universal-template.html');
|
||
const htmlTemplateSource = readFileSync(templatePath, 'utf-8');
|
||
const handlebarsTemplate = Handlebars.compile(htmlTemplateSource);
|
||
const renderedHtml = handlebarsTemplate(templateData);
|
||
|
||
const outputPath = join(process.cwd(), 'tmp', `rendered-${type}.html`);
|
||
writeFileSync(outputPath, renderedHtml, 'utf-8');
|
||
console.log(`Email de test généré: ${outputPath}`);
|
||
}
|
||
|
||
renderEmail(sampleType);
|