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.

196 lines 8.41 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.NestDynamicTemplate = void 0; const typeorm_1 = require("typeorm"); const template_types_1 = require("../interfaces/template.types"); const class_validator_1 = require("class-validator"); const swagger_1 = require("@nestjs/swagger"); let NestDynamicTemplate = class NestDynamicTemplate extends typeorm_1.BaseEntity { id; name; displayName; description; type; engine; language; subject; content; templateLayoutName; scope; scopeId; locale; previewContext; isActive; createdAt; updatedAt; }; exports.NestDynamicTemplate = NestDynamicTemplate; __decorate([ (0, swagger_1.ApiProperty)({ type: String, format: 'uuid', readOnly: true, description: 'Primary key.' }), (0, typeorm_1.PrimaryGeneratedColumn)('uuid'), __metadata("design:type", String) ], NestDynamicTemplate.prototype, "id", void 0); __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' }), (0, typeorm_1.Column)(), __metadata("design:type", String) ], NestDynamicTemplate.prototype, "name", void 0); __decorate([ (0, swagger_1.ApiProperty)({ type: String, nullable: true, description: 'Human-friendly label for admin UIs, e.g. "Welcome email".' }), (0, class_validator_1.IsString)(), (0, class_validator_1.IsOptional)(), (0, typeorm_1.Column)({ nullable: true }), __metadata("design:type", String) ], NestDynamicTemplate.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)(), (0, typeorm_1.Column)({ type: 'text', nullable: true }), __metadata("design:type", String) ], NestDynamicTemplate.prototype, "description", void 0); __decorate([ (0, swagger_1.ApiProperty)({ type: String, nullable: true, example: 'email', description: 'Free category for grouping/filtering, e.g. email, sms, push, pdf.', }), (0, class_validator_1.IsString)(), (0, class_validator_1.IsOptional)(), (0, typeorm_1.Column)({ type: 'text', nullable: true }), __metadata("design:type", String) ], NestDynamicTemplate.prototype, "type", 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, typeorm_1.Column)({ type: 'text', enum: template_types_1.TemplateEngineEnum, default: template_types_1.TemplateEngineEnum.NUNJUCKS }), __metadata("design:type", String) ], NestDynamicTemplate.prototype, "engine", void 0); __decorate([ (0, swagger_1.ApiProperty)({ enum: template_types_1.TemplateLanguageEnum, type: String, nullable: true, description: 'Output processor applied after interpolation: html, mjml, md, txt. Omit to skip post-processing.', }), (0, class_validator_1.IsEnum)(template_types_1.TemplateLanguageEnum), (0, class_validator_1.IsOptional)(), (0, typeorm_1.Column)({ type: 'text' }), __metadata("design:type", String) ], NestDynamicTemplate.prototype, "language", void 0); __decorate([ (0, swagger_1.ApiProperty)({ 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)(), (0, typeorm_1.Column)({ nullable: true }), __metadata("design:type", String) ], NestDynamicTemplate.prototype, "subject", void 0); __decorate([ (0, swagger_1.ApiProperty)({ type: String, description: "The template body, written in the chosen engine's syntax." }), (0, class_validator_1.IsString)(), (0, class_validator_1.IsOptional)(), (0, typeorm_1.Column)('text'), __metadata("design:type", String) ], NestDynamicTemplate.prototype, "content", void 0); __decorate([ (0, swagger_1.ApiProperty)({ type: String, nullable: true, description: 'Name of a layout to wrap this content in.' }), (0, class_validator_1.IsString)(), (0, class_validator_1.IsOptional)(), (0, typeorm_1.Column)({ nullable: true }), __metadata("design:type", String) ], NestDynamicTemplate.prototype, "templateLayoutName", void 0); __decorate([ (0, swagger_1.ApiProperty)({ type: String, nullable: true, default: 'system', description: 'Who owns this version: "system" (shared default) or a custom owner kind like "tenant"/"user". Overrides fall back to the system template.', }), (0, class_validator_1.IsString)(), (0, typeorm_1.Column)({ nullable: true, default: 'system' }), __metadata("design:type", String) ], NestDynamicTemplate.prototype, "scope", void 0); __decorate([ (0, swagger_1.ApiProperty)({ type: String, nullable: true, description: 'Which owner inside the scope (e.g. the tenant id). Leave empty for system templates.', }), (0, class_validator_1.IsString)(), (0, typeorm_1.Column)({ nullable: true }), __metadata("design:type", String) ], NestDynamicTemplate.prototype, "scopeId", void 0); __decorate([ (0, swagger_1.ApiProperty)({ 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, typeorm_1.Column)({ nullable: true, default: 'en' }), __metadata("design:type", String) ], NestDynamicTemplate.prototype, "locale", void 0); __decorate([ (0, swagger_1.ApiProperty)({ type: Object, nullable: true, description: 'Sample data used to preview the template (not applied during render).', }), (0, class_validator_1.IsOptional)(), (0, typeorm_1.Column)('simple-json', { nullable: true }), __metadata("design:type", Object) ], NestDynamicTemplate.prototype, "previewContext", void 0); __decorate([ (0, swagger_1.ApiProperty)({ type: Boolean, description: 'Set false to disable without deleting; inactive templates are skipped during resolution.', }), (0, class_validator_1.IsBoolean)(), (0, typeorm_1.Column)({ default: true }), __metadata("design:type", Boolean) ], NestDynamicTemplate.prototype, "isActive", void 0); __decorate([ (0, swagger_1.ApiProperty)({ type: Date, readOnly: true }), (0, typeorm_1.CreateDateColumn)(), __metadata("design:type", Date) ], NestDynamicTemplate.prototype, "createdAt", void 0); __decorate([ (0, swagger_1.ApiProperty)({ type: Date, readOnly: true }), (0, typeorm_1.UpdateDateColumn)(), __metadata("design:type", Date) ], NestDynamicTemplate.prototype, "updatedAt", void 0); exports.NestDynamicTemplate = NestDynamicTemplate = __decorate([ (0, typeorm_1.Entity)('nest_dynamic_templates'), (0, typeorm_1.Index)(['name', 'scope', 'scopeId', 'locale'], { unique: true }) ], NestDynamicTemplate); //# sourceMappingURL=template.entity.js.map