UNPKG

@ackplus/nest-dynamic-templates

Version:

A powerful and flexible dynamic template rendering library for NestJS applications with support for Nunjucks, Handlebars, EJS, Pug, MJML, Markdown, and more.

165 lines 7.05 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CreateTemplateDto = void 0; const class_validator_1 = require("class-validator"); const template_types_1 = require("../interfaces/template.types"); const swagger_1 = require("@nestjs/swagger"); const class_transformer_1 = require("class-transformer"); class CreateTemplateDto { name; templateLayoutName; type; displayName; description; engine = template_types_1.TemplateEngineEnum.NUNJUCKS; language; content; subject; scope = 'system'; scopeId; locale = 'en'; previewContext; isActive = true; } exports.CreateTemplateDto = CreateTemplateDto; __decorate([ (0, swagger_1.ApiProperty)({ type: String, example: 'welcome-email', description: 'Stable identifier you render by (lowercase letters, numbers, "-" and "_"). Stays the same across scopes and locales.', }), (0, class_validator_1.IsString)(), (0, class_validator_1.IsNotEmpty)(), (0, class_validator_1.Matches)(/^[a-z0-9\-_]+$/, { message: 'Invalid template name format' }), __metadata("design:type", String) ], CreateTemplateDto.prototype, "name", void 0); __decorate([ (0, swagger_1.ApiPropertyOptional)({ type: String, nullable: true, description: 'Name of a layout to wrap this content in.' }), (0, class_validator_1.IsString)(), (0, class_validator_1.IsOptional)(), __metadata("design:type", String) ], CreateTemplateDto.prototype, "templateLayoutName", void 0); __decorate([ (0, swagger_1.ApiProperty)({ type: String, example: 'email', description: 'Free category for grouping/filtering, e.g. email, sms, push, pdf.', }), (0, class_validator_1.IsString)(), (0, class_validator_1.IsOptional)(), __metadata("design:type", String) ], CreateTemplateDto.prototype, "type", void 0); __decorate([ (0, swagger_1.ApiPropertyOptional)({ type: String, description: 'Human-friendly label for admin UIs, e.g. "Welcome email".' }), (0, class_validator_1.IsString)(), (0, class_validator_1.IsNotEmpty)(), __metadata("design:type", String) ], CreateTemplateDto.prototype, "displayName", void 0); __decorate([ (0, swagger_1.ApiProperty)({ type: String, nullable: true, description: 'Free-text notes about what this template is for.' }), (0, class_validator_1.IsString)(), (0, class_validator_1.IsOptional)(), __metadata("design:type", String) ], CreateTemplateDto.prototype, "description", void 0); __decorate([ (0, swagger_1.ApiProperty)({ enum: template_types_1.TemplateEngineEnum, type: String, description: 'Template engine that interpolates variables: njk (Nunjucks), hbs, ejs, pug.', }), (0, class_validator_1.IsEnum)(template_types_1.TemplateEngineEnum), (0, class_validator_1.IsOptional)(), __metadata("design:type", String) ], CreateTemplateDto.prototype, "engine", void 0); __decorate([ (0, swagger_1.ApiProperty)({ enum: template_types_1.TemplateLanguageEnum, type: String, description: 'Output processor applied after interpolation: html, mjml, md, txt.', }), (0, class_validator_1.IsEnum)(template_types_1.TemplateLanguageEnum), __metadata("design:type", String) ], CreateTemplateDto.prototype, "language", void 0); __decorate([ (0, swagger_1.ApiProperty)({ type: String, nullable: true, example: '<h1>Hello {{ firstName }}</h1>', description: "The template body, written in the chosen engine's syntax.", }), (0, class_validator_1.IsString)(), (0, class_validator_1.IsOptional)(), __metadata("design:type", String) ], CreateTemplateDto.prototype, "content", void 0); __decorate([ (0, swagger_1.ApiPropertyOptional)({ type: String, nullable: true, description: 'Optional subject line (emails). Rendered with the engine, so it can use variables.', }), (0, class_validator_1.IsString)(), (0, class_validator_1.IsOptional)(), __metadata("design:type", String) ], CreateTemplateDto.prototype, "subject", void 0); __decorate([ (0, swagger_1.ApiPropertyOptional)({ type: String, default: 'system', description: 'Who owns this version: "system" (shared default) or a custom owner kind like "tenant"/"user". Note: createTemplate only creates system templates.', }), (0, class_validator_1.IsString)(), (0, class_validator_1.IsOptional)(), (0, class_transformer_1.Transform)(({ value }) => value || 'system'), __metadata("design:type", String) ], CreateTemplateDto.prototype, "scope", void 0); __decorate([ (0, swagger_1.ApiPropertyOptional)({ type: String, description: 'Which owner inside the scope (e.g. the tenant id). Leave empty for system templates.', }), (0, class_validator_1.IsString)(), (0, class_validator_1.IsOptional)(), __metadata("design:type", String) ], CreateTemplateDto.prototype, "scopeId", void 0); __decorate([ (0, swagger_1.ApiPropertyOptional)({ type: String, nullable: true, default: 'en', description: 'Language variant, e.g. en, fr, es. Missing locales fall back to "en".', }), (0, class_validator_1.IsString)(), (0, class_validator_1.IsOptional)(), (0, class_validator_1.IsNotEmpty)(), (0, class_transformer_1.Transform)(({ value }) => value || 'en'), __metadata("design:type", String) ], CreateTemplateDto.prototype, "locale", void 0); __decorate([ (0, swagger_1.ApiPropertyOptional)({ type: Object, nullable: true, description: 'Sample data used to preview the template (not applied during render).', }), (0, class_validator_1.IsOptional)(), __metadata("design:type", Object) ], CreateTemplateDto.prototype, "previewContext", void 0); __decorate([ (0, swagger_1.ApiPropertyOptional)({ type: Boolean, nullable: true, description: 'Set false to disable without deleting; inactive templates are skipped during resolution.', }), (0, class_validator_1.IsBoolean)(), (0, class_validator_1.IsOptional)(), __metadata("design:type", Boolean) ], CreateTemplateDto.prototype, "isActive", void 0); //# sourceMappingURL=create-template.dto.js.map