changemaker.lite/api/dist/modules/email-templates/email-templates.schemas.js

73 lines
3.8 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendTestEmailSchema = exports.validateTemplateSchema = exports.rollbackToVersionSchema = exports.updateEmailTemplateSchema = exports.createEmailTemplateSchema = exports.listEmailTemplatesSchema = exports.emailTemplateVariableSchema = exports.EmailTemplateVariableTypeSchema = void 0;
const zod_1 = require("zod");
const client_1 = require("@prisma/client");
// Variable type enum
exports.EmailTemplateVariableTypeSchema = zod_1.z.enum(['TEXT', 'VIDEO']);
// Variable schema
exports.emailTemplateVariableSchema = zod_1.z.object({
key: zod_1.z.string().regex(/^[A-Z_]+$/, 'Variable key must be uppercase letters and underscores'),
label: zod_1.z.string().min(1).max(100),
description: zod_1.z.string().max(500).optional(),
type: exports.EmailTemplateVariableTypeSchema.default('TEXT'),
videoId: zod_1.z.number().int().positive().optional(),
isRequired: zod_1.z.boolean().default(true),
isConditional: zod_1.z.boolean().default(false),
sampleValue: zod_1.z.string().max(1000).optional(),
sortOrder: zod_1.z.number().int().min(0).default(0),
}).refine((data) => {
// VIDEO type must have videoId
if (data.type === 'VIDEO' && !data.videoId) {
return false;
}
return true;
}, { message: 'VIDEO variables must have a videoId', path: ['videoId'] });
// List templates
exports.listEmailTemplatesSchema = zod_1.z.object({
page: zod_1.z.coerce.number().int().min(1).default(1),
limit: zod_1.z.coerce.number().int().min(1).max(100).default(20),
search: zod_1.z.string().max(200).optional(),
category: zod_1.z.nativeEnum(client_1.EmailTemplateCategory).optional(),
isActive: zod_1.z.coerce.boolean().optional(),
});
// Create template
exports.createEmailTemplateSchema = zod_1.z.object({
key: zod_1.z.string().regex(/^[a-z0-9-]+$/, 'Template key must be lowercase alphanumeric with hyphens').min(1).max(100),
name: zod_1.z.string().min(1).max(200),
description: zod_1.z.string().max(1000).optional(),
category: zod_1.z.nativeEnum(client_1.EmailTemplateCategory),
subjectLine: zod_1.z.string().min(1).max(500),
htmlContent: zod_1.z.string().min(1).max(100000, 'HTML content exceeds 100KB limit'),
textContent: zod_1.z.string().min(1).max(50000, 'Text content exceeds 50KB limit'),
isActive: zod_1.z.boolean().default(true),
variables: zod_1.z.array(exports.emailTemplateVariableSchema).optional(),
});
// Update template
exports.updateEmailTemplateSchema = zod_1.z.object({
name: zod_1.z.string().min(1).max(200).optional(),
description: zod_1.z.string().max(1000).optional().nullable(),
category: zod_1.z.nativeEnum(client_1.EmailTemplateCategory).optional(),
subjectLine: zod_1.z.string().min(1).max(500).optional(),
htmlContent: zod_1.z.string().min(1).max(100000, 'HTML content exceeds 100KB limit').optional(),
textContent: zod_1.z.string().min(1).max(50000, 'Text content exceeds 50KB limit').optional(),
isActive: zod_1.z.boolean().optional(),
variables: zod_1.z.array(exports.emailTemplateVariableSchema).optional(),
});
// Rollback to version
exports.rollbackToVersionSchema = zod_1.z.object({
versionNumber: zod_1.z.number().int().min(1),
changeNotes: zod_1.z.string().max(500).optional(),
});
// Validate template
exports.validateTemplateSchema = zod_1.z.object({
htmlContent: zod_1.z.string().min(1).max(100000),
textContent: zod_1.z.string().min(1).max(50000),
subjectLine: zod_1.z.string().min(1).max(500).optional(),
});
// Send test email
exports.sendTestEmailSchema = zod_1.z.object({
recipientEmail: zod_1.z.string().email('Invalid email address').max(255),
testData: zod_1.z.record(zod_1.z.string(), zod_1.z.string()),
});
//# sourceMappingURL=email-templates.schemas.js.map