@ackplus/nest-dynamic-templates 1.1.1 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/{index.ts → index.d.ts} +2 -14
- package/src/index.d.ts.map +1 -0
- package/src/index.js +25 -0
- package/src/lib/constant.d.ts +3 -0
- package/src/lib/constant.d.ts.map +1 -0
- package/src/lib/constant.js +5 -0
- package/src/lib/dto/create-template-layout.dto.d.ts +16 -0
- package/src/lib/dto/create-template-layout.dto.d.ts.map +1 -0
- package/src/lib/dto/create-template-layout.dto.js +86 -0
- package/src/lib/dto/create-template.dto.d.ts +18 -0
- package/src/lib/dto/create-template.dto.d.ts.map +1 -0
- package/src/lib/dto/create-template.dto.js +103 -0
- package/src/lib/dto/render-content-template-layout.dto.d.ts +8 -0
- package/src/lib/dto/render-content-template-layout.dto.d.ts.map +1 -0
- package/src/lib/dto/render-content-template-layout.dto.js +40 -0
- package/src/lib/dto/render-content-template.dto.d.ts +9 -0
- package/src/lib/dto/render-content-template.dto.d.ts.map +1 -0
- package/src/lib/dto/render-content-template.dto.js +46 -0
- package/src/lib/dto/render-template-layout.dto.d.ts +11 -0
- package/src/lib/dto/render-template-layout.dto.d.ts.map +1 -0
- package/src/lib/dto/render-template-layout.dto.js +66 -0
- package/src/lib/dto/render-template.dto.d.ts +15 -0
- package/src/lib/dto/render-template.dto.d.ts.map +1 -0
- package/src/lib/dto/render-template.dto.js +90 -0
- package/src/lib/dto/template-filter.dto.d.ts +9 -0
- package/src/lib/dto/template-filter.dto.d.ts.map +1 -0
- package/src/lib/dto/template-filter.dto.js +61 -0
- package/src/lib/dto/template-layout-filter.dto.d.ts +8 -0
- package/src/lib/dto/template-layout-filter.dto.d.ts.map +1 -0
- package/src/lib/dto/template-layout-filter.dto.js +60 -0
- package/src/lib/engines/language/html.engine.d.ts +10 -0
- package/src/lib/engines/language/html.engine.d.ts.map +1 -0
- package/src/lib/engines/language/html.engine.js +80 -0
- package/src/lib/engines/language/{index.ts → index.d.ts} +1 -0
- package/src/lib/engines/language/index.d.ts.map +1 -0
- package/src/lib/engines/language/index.js +11 -0
- package/src/lib/engines/language/markdown.engine.d.ts +10 -0
- package/src/lib/engines/language/markdown.engine.d.ts.map +1 -0
- package/src/lib/engines/language/markdown.engine.js +39 -0
- package/src/lib/engines/language/mjml.engine.d.ts +10 -0
- package/src/lib/engines/language/mjml.engine.d.ts.map +1 -0
- package/src/lib/engines/language/mjml.engine.js +75 -0
- package/src/lib/engines/language/text.engine.d.ts +8 -0
- package/src/lib/engines/language/text.engine.d.ts.map +1 -0
- package/src/lib/engines/language/text.engine.js +15 -0
- package/src/lib/engines/{language-engine.ts → language-engine.d.ts} +2 -7
- package/src/lib/engines/language-engine.d.ts.map +1 -0
- package/src/lib/engines/language-engine.js +6 -0
- package/src/lib/engines/template/ejs.engine.d.ts +11 -0
- package/src/lib/engines/template/ejs.engine.d.ts.map +1 -0
- package/src/lib/engines/template/ejs.engine.js +65 -0
- package/src/lib/engines/template/handlebars.engine.d.ts +11 -0
- package/src/lib/engines/template/handlebars.engine.d.ts.map +1 -0
- package/src/lib/engines/template/handlebars.engine.js +66 -0
- package/src/lib/engines/template/{index.ts → index.d.ts} +1 -0
- package/src/lib/engines/template/index.d.ts.map +1 -0
- package/src/lib/engines/template/index.js +11 -0
- package/src/lib/engines/template/nunjucks.engine.d.ts +17 -0
- package/src/lib/engines/template/nunjucks.engine.d.ts.map +1 -0
- package/src/lib/engines/template/{nunjucks.engine.ts → nunjucks.engine.js} +24 -30
- package/src/lib/engines/template/pug.engine.d.ts +13 -0
- package/src/lib/engines/template/pug.engine.d.ts.map +1 -0
- package/src/lib/engines/template/pug.engine.js +74 -0
- package/src/lib/engines/{template-engine.ts → template-engine.d.ts} +2 -6
- package/src/lib/engines/template-engine.d.ts.map +1 -0
- package/src/lib/engines/template-engine.js +6 -0
- package/src/lib/entities/template-layout.entity.d.ts +21 -0
- package/src/lib/entities/template-layout.entity.d.ts.map +1 -0
- package/src/lib/entities/template-layout.entity.js +120 -0
- package/src/lib/entities/template.entity.d.ts +22 -0
- package/src/lib/entities/template.entity.d.ts.map +1 -0
- package/src/lib/entities/template.entity.js +127 -0
- package/src/lib/errors/template.errors.d.ts +20 -0
- package/src/lib/errors/template.errors.d.ts.map +1 -0
- package/src/lib/errors/{template.errors.ts → template.errors.js} +22 -20
- package/src/lib/interfaces/{module-config.interface.ts → module-config.interface.d.ts} +2 -10
- package/src/lib/interfaces/module-config.interface.d.ts.map +1 -0
- package/src/lib/interfaces/module-config.interface.js +2 -0
- package/src/lib/interfaces/template.types.d.ts +23 -0
- package/src/lib/interfaces/template.types.d.ts.map +1 -0
- package/src/lib/interfaces/template.types.js +24 -0
- package/src/lib/nest-dynamic-templates.module.d.ts +11 -0
- package/src/lib/nest-dynamic-templates.module.d.ts.map +1 -0
- package/src/lib/nest-dynamic-templates.module.js +131 -0
- package/src/lib/services/template-config.service.d.ts +55 -0
- package/src/lib/services/template-config.service.d.ts.map +1 -0
- package/src/lib/services/{template-config.service.ts → template-config.service.js} +32 -43
- package/src/lib/services/template-engine.registry.d.ts +22 -0
- package/src/lib/services/template-engine.registry.d.ts.map +1 -0
- package/src/lib/services/template-engine.registry.js +93 -0
- package/src/lib/services/template-layout.service.d.ts +37 -0
- package/src/lib/services/template-layout.service.d.ts.map +1 -0
- package/src/lib/services/{template-layout.service.ts → template-layout.service.js} +101 -165
- package/src/lib/services/template.service.d.ts +39 -0
- package/src/lib/services/template.service.d.ts.map +1 -0
- package/src/lib/services/{template.service.ts → template.service.js} +137 -199
- package/src/test/helpers.d.ts +5 -0
- package/src/test/helpers.d.ts.map +1 -0
- package/src/test/{helpers.ts → helpers.js} +7 -5
- package/src/test/test-database.config.d.ts +5 -0
- package/src/test/test-database.config.d.ts.map +1 -0
- package/src/test/test-database.config.js +23 -0
- package/src/test/test.setup.d.ts +4 -0
- package/src/test/test.setup.d.ts.map +1 -0
- package/src/test/test.setup.js +30 -0
- package/eslint.config.mjs +0 -22
- package/jest.config.ts +0 -10
- package/project.json +0 -38
- package/src/lib/constant.ts +0 -2
- package/src/lib/dto/create-template-layout.dto.ts +0 -65
- package/src/lib/dto/create-template.dto.ts +0 -80
- package/src/lib/dto/render-content-template-layout.dto.ts +0 -32
- package/src/lib/dto/render-content-template.dto.ts +0 -37
- package/src/lib/dto/render-template-layout.dto.ts +0 -55
- package/src/lib/dto/render-template.dto.ts +0 -74
- package/src/lib/dto/template-filter.dto.ts +0 -52
- package/src/lib/dto/template-layout-filter.dto.ts +0 -51
- package/src/lib/engines/language/html.engine.ts +0 -49
- package/src/lib/engines/language/markdown.engine.ts +0 -37
- package/src/lib/engines/language/mjml.engine.ts +0 -44
- package/src/lib/engines/language/text.engine.ts +0 -15
- package/src/lib/engines/template/ejs.engine.ts +0 -33
- package/src/lib/engines/template/handlebars.engine.ts +0 -35
- package/src/lib/engines/template/pug.engine.ts +0 -43
- package/src/lib/entities/template-layout.entity.ts +0 -99
- package/src/lib/entities/template.entity.ts +0 -105
- package/src/lib/interfaces/template.types.ts +0 -25
- package/src/lib/nest-dynamic-templates.module.ts +0 -143
- package/src/lib/services/template-engine.registry.ts +0 -109
- package/src/test/nunjucks.service.spec.ts +0 -157
- package/src/test/pug.service.spec-temp +0 -254
- package/src/test/template-layout.service.spec.ts +0 -422
- package/src/test/template.service.spec.ts +0 -862
- package/src/test/test-database.config.ts +0 -24
- package/src/test/test-database.d.ts +0 -6
- package/src/test/test.setup.ts +0 -34
- package/src/types/ioredis.d.ts +0 -6
- package/src/types/mjml.d.ts +0 -5
- package/tsconfig.json +0 -17
- package/tsconfig.lib.json +0 -14
- package/tsconfig.spec.json +0 -15
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testRedisConfig = exports.testDatabaseConfig = void 0;
|
|
4
|
+
const template_entity_1 = require("../lib/entities/template.entity");
|
|
5
|
+
const template_layout_entity_1 = require("../lib/entities/template-layout.entity");
|
|
6
|
+
exports.testDatabaseConfig = {
|
|
7
|
+
type: 'sqlite',
|
|
8
|
+
database: ':memory:',
|
|
9
|
+
entities: [template_entity_1.NestDynamicTemplate, template_layout_entity_1.NestDynamicTemplateLayout],
|
|
10
|
+
logging: ['error', 'warn'],
|
|
11
|
+
synchronize: true, // Disable auto-synchronization
|
|
12
|
+
dropSchema: true, // Drop schema before tests
|
|
13
|
+
};
|
|
14
|
+
exports.testRedisConfig = {
|
|
15
|
+
type: 'single',
|
|
16
|
+
options: {
|
|
17
|
+
host: 'localhost',
|
|
18
|
+
port: 6379,
|
|
19
|
+
retryStrategy: (times) => {
|
|
20
|
+
return Math.min(times * 50, 2000);
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { NestDynamicTemplatesModuleConfig } from '../lib/interfaces/module-config.interface';
|
|
2
|
+
export declare function createTestModule(options?: Partial<NestDynamicTemplatesModuleConfig>): Promise<import("@nestjs/testing").TestingModule>;
|
|
3
|
+
export declare function createTestApp(options?: Partial<NestDynamicTemplatesModuleConfig>): Promise<import("@nestjs/common").INestApplication<any>>;
|
|
4
|
+
//# sourceMappingURL=test.setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.setup.d.ts","sourceRoot":"","sources":["../../../../../packages/nest-dynamic-templates/src/test/test.setup.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gCAAgC,EAAE,MAAM,2CAA2C,CAAC;AAG7F,wBAAsB,gBAAgB,CAAC,OAAO,GAAE,OAAO,CAAC,gCAAgC,CAAM,oDAY7F;AAED,wBAAsB,aAAa,CAAC,OAAO,GAAE,OAAO,CAAC,gCAAgC,CAAM,2DAU1F"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTestModule = createTestModule;
|
|
4
|
+
exports.createTestApp = createTestApp;
|
|
5
|
+
const testing_1 = require("@nestjs/testing");
|
|
6
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
7
|
+
const test_database_config_1 = require("./test-database.config");
|
|
8
|
+
const template_layout_entity_1 = require("../lib/entities/template-layout.entity");
|
|
9
|
+
const template_entity_1 = require("../lib/entities/template.entity");
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const nest_dynamic_templates_module_1 = require("../lib/nest-dynamic-templates.module");
|
|
12
|
+
async function createTestModule(options = {}) {
|
|
13
|
+
const moduleRef = await testing_1.Test.createTestingModule({
|
|
14
|
+
imports: [
|
|
15
|
+
typeorm_1.TypeOrmModule.forRoot(test_database_config_1.testDatabaseConfig),
|
|
16
|
+
typeorm_1.TypeOrmModule.forFeature([template_entity_1.NestDynamicTemplate, template_layout_entity_1.NestDynamicTemplateLayout]),
|
|
17
|
+
// RedisModule.forRoot(testRedisConfig),
|
|
18
|
+
nest_dynamic_templates_module_1.NestDynamicTemplatesModule.forRoot(options),
|
|
19
|
+
],
|
|
20
|
+
}).compile();
|
|
21
|
+
return moduleRef;
|
|
22
|
+
}
|
|
23
|
+
async function createTestApp(options = {}) {
|
|
24
|
+
const moduleRef = await createTestModule(options);
|
|
25
|
+
const app = moduleRef.createNestApplication();
|
|
26
|
+
// Enable validation
|
|
27
|
+
app.useGlobalPipes(new common_1.ValidationPipe());
|
|
28
|
+
await app.init();
|
|
29
|
+
return app;
|
|
30
|
+
}
|
package/eslint.config.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import baseConfig from '../../eslint.base.config';
|
|
2
|
-
|
|
3
|
-
export default [
|
|
4
|
-
...baseConfig,
|
|
5
|
-
{
|
|
6
|
-
files: ['**/*.json'],
|
|
7
|
-
rules: {
|
|
8
|
-
'@nx/dependency-checks': [
|
|
9
|
-
'error',
|
|
10
|
-
{
|
|
11
|
-
ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs,ts,cts,mts}'],
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
},
|
|
15
|
-
languageOptions: {
|
|
16
|
-
parser: await import('jsonc-eslint-parser'),
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
ignores: ['**/out-tsc'],
|
|
21
|
-
},
|
|
22
|
-
];
|
package/jest.config.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
displayName: 'nest-dynamic-templates',
|
|
3
|
-
preset: '../../jest.preset.js',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
transform: {
|
|
6
|
-
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
|
|
7
|
-
},
|
|
8
|
-
moduleFileExtensions: ['ts', 'js', 'html'],
|
|
9
|
-
coverageDirectory: '../../coverage/packages/nest-dynamic-templates',
|
|
10
|
-
};
|
package/project.json
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "nest-dynamic-templates",
|
|
3
|
-
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "packages/nest-dynamic-templates/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"release": {
|
|
7
|
-
"version": {
|
|
8
|
-
"manifestRootsToUpdate": [
|
|
9
|
-
"dist/{projectRoot}"
|
|
10
|
-
],
|
|
11
|
-
"currentVersionResolver": "git-tag",
|
|
12
|
-
"fallbackCurrentVersionResolver": "disk"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"tags": [],
|
|
16
|
-
"targets": {
|
|
17
|
-
"build": {
|
|
18
|
-
"executor": "@nx/js:tsc",
|
|
19
|
-
"outputs": [
|
|
20
|
-
"{options.outputPath}"
|
|
21
|
-
],
|
|
22
|
-
"options": {
|
|
23
|
-
"outputPath": "dist/packages/nest-dynamic-templates",
|
|
24
|
-
"tsConfig": "packages/nest-dynamic-templates/tsconfig.lib.json",
|
|
25
|
-
"packageJson": "packages/nest-dynamic-templates/package.json",
|
|
26
|
-
"main": "packages/nest-dynamic-templates/src/index.ts",
|
|
27
|
-
"assets": [
|
|
28
|
-
"packages/nest-dynamic-templates/*.md"
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"nx-release-publish": {
|
|
33
|
-
"options": {
|
|
34
|
-
"packageRoot": "dist/{projectRoot}"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
package/src/lib/constant.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { IsString, IsEnum, IsOptional, IsNotEmpty, Matches } from 'class-validator';
|
|
2
|
-
import { TemplateEngineEnum, TemplateLanguageEnum } from '../interfaces/template.types';
|
|
3
|
-
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export class CreateTemplateLayoutDto {
|
|
7
|
-
|
|
8
|
-
@ApiProperty({ type: String })
|
|
9
|
-
@IsString()
|
|
10
|
-
@IsNotEmpty()
|
|
11
|
-
@Matches(/^[a-z0-9\-_]+$/, { message: 'Invalid template name format' })
|
|
12
|
-
name: string;
|
|
13
|
-
|
|
14
|
-
@ApiProperty({ type: String })
|
|
15
|
-
@IsString()
|
|
16
|
-
@IsOptional()
|
|
17
|
-
type?: string;
|
|
18
|
-
|
|
19
|
-
@ApiPropertyOptional({ type: String })
|
|
20
|
-
@IsString()
|
|
21
|
-
@IsNotEmpty()
|
|
22
|
-
displayName: string;
|
|
23
|
-
|
|
24
|
-
@ApiProperty({ type: String, nullable: true })
|
|
25
|
-
@IsString()
|
|
26
|
-
@IsOptional()
|
|
27
|
-
description?: string;
|
|
28
|
-
|
|
29
|
-
@ApiProperty({ enum: TemplateEngineEnum, type: String })
|
|
30
|
-
@IsEnum(TemplateEngineEnum)
|
|
31
|
-
@IsOptional()
|
|
32
|
-
engine: TemplateEngineEnum = TemplateEngineEnum.NUNJUCKS;
|
|
33
|
-
|
|
34
|
-
@ApiProperty({ enum: TemplateLanguageEnum, type: String })
|
|
35
|
-
@IsEnum(TemplateLanguageEnum)
|
|
36
|
-
@IsNotEmpty()
|
|
37
|
-
language: TemplateLanguageEnum;
|
|
38
|
-
|
|
39
|
-
@ApiProperty({ type: String, nullable: true })
|
|
40
|
-
@IsString()
|
|
41
|
-
content: string;
|
|
42
|
-
|
|
43
|
-
@ApiPropertyOptional({ type: String, default: 'system' })
|
|
44
|
-
@IsString()
|
|
45
|
-
@IsOptional()
|
|
46
|
-
scope: string = 'system';
|
|
47
|
-
|
|
48
|
-
@ApiPropertyOptional({ type: String })
|
|
49
|
-
@IsString()
|
|
50
|
-
@IsOptional()
|
|
51
|
-
scopeId?: string;
|
|
52
|
-
|
|
53
|
-
@ApiPropertyOptional({ type: String, nullable: true, default: 'en' })
|
|
54
|
-
@IsString()
|
|
55
|
-
@IsOptional()
|
|
56
|
-
locale?: string = 'en';
|
|
57
|
-
|
|
58
|
-
@ApiPropertyOptional({ type: Object, nullable: true })
|
|
59
|
-
@IsOptional()
|
|
60
|
-
previewContext?: Record<string, any>;
|
|
61
|
-
|
|
62
|
-
@ApiPropertyOptional({ type: Boolean, nullable: true })
|
|
63
|
-
@IsOptional()
|
|
64
|
-
isActive?: boolean = true;
|
|
65
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { IsString, IsEnum, IsOptional, IsNotEmpty, Matches, IsBoolean } from 'class-validator';
|
|
2
|
-
import { TemplateEngineEnum, TemplateLanguageEnum, TemplateTypeEnum } from '../interfaces/template.types';
|
|
3
|
-
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
4
|
-
import { Transform } from 'class-transformer';
|
|
5
|
-
|
|
6
|
-
export class CreateTemplateDto {
|
|
7
|
-
|
|
8
|
-
@ApiProperty({ type: String })
|
|
9
|
-
@IsString()
|
|
10
|
-
@IsNotEmpty()
|
|
11
|
-
@Matches(/^[a-z0-9\-_]+$/, { message: 'Invalid template name format' })
|
|
12
|
-
name: string;
|
|
13
|
-
|
|
14
|
-
@ApiPropertyOptional({ type: String, nullable: true })
|
|
15
|
-
@IsString()
|
|
16
|
-
@IsOptional()
|
|
17
|
-
templateLayoutName?: string;
|
|
18
|
-
|
|
19
|
-
@ApiProperty({ type: String })
|
|
20
|
-
@IsString()
|
|
21
|
-
@IsOptional()
|
|
22
|
-
type?: string;
|
|
23
|
-
|
|
24
|
-
@ApiPropertyOptional({ type: String })
|
|
25
|
-
@IsString()
|
|
26
|
-
@IsNotEmpty()
|
|
27
|
-
displayName: string;
|
|
28
|
-
|
|
29
|
-
@ApiProperty({ type: String, nullable: true })
|
|
30
|
-
@IsString()
|
|
31
|
-
@IsOptional()
|
|
32
|
-
description?: string;
|
|
33
|
-
|
|
34
|
-
@ApiProperty({ enum: TemplateEngineEnum, type: String })
|
|
35
|
-
@IsEnum(TemplateEngineEnum)
|
|
36
|
-
@IsOptional()
|
|
37
|
-
engine: TemplateEngineEnum = TemplateEngineEnum.NUNJUCKS;
|
|
38
|
-
|
|
39
|
-
@ApiProperty({ enum: TemplateLanguageEnum, type: String })
|
|
40
|
-
@IsEnum(TemplateLanguageEnum)
|
|
41
|
-
language: TemplateLanguageEnum;
|
|
42
|
-
|
|
43
|
-
@ApiProperty({ type: String, nullable: true })
|
|
44
|
-
@IsString()
|
|
45
|
-
@IsOptional()
|
|
46
|
-
content: string;
|
|
47
|
-
|
|
48
|
-
@ApiPropertyOptional({ type: String, nullable: true })
|
|
49
|
-
@IsString()
|
|
50
|
-
@IsOptional()
|
|
51
|
-
subject?: string;
|
|
52
|
-
|
|
53
|
-
@ApiPropertyOptional({ type: String, default: 'system' })
|
|
54
|
-
@IsString()
|
|
55
|
-
@IsOptional()
|
|
56
|
-
@Transform(({ value }) => value || 'system')
|
|
57
|
-
scope: string = 'system';
|
|
58
|
-
|
|
59
|
-
@ApiPropertyOptional({ type: String })
|
|
60
|
-
@IsString()
|
|
61
|
-
@IsOptional()
|
|
62
|
-
scopeId?: string;
|
|
63
|
-
|
|
64
|
-
@ApiPropertyOptional({ type: String, nullable: true, default: 'en' })
|
|
65
|
-
@IsString()
|
|
66
|
-
@IsOptional()
|
|
67
|
-
@IsNotEmpty()
|
|
68
|
-
@Transform(({ value }) => value || 'en')
|
|
69
|
-
locale?: string = 'en';
|
|
70
|
-
|
|
71
|
-
@ApiPropertyOptional({ type: Object, nullable: true })
|
|
72
|
-
@IsOptional()
|
|
73
|
-
previewContext?: Record<string, any>;
|
|
74
|
-
|
|
75
|
-
@ApiPropertyOptional({ type: Boolean, nullable: true })
|
|
76
|
-
@IsBoolean()
|
|
77
|
-
@IsOptional()
|
|
78
|
-
isActive?: boolean = true;
|
|
79
|
-
|
|
80
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { IsString, IsEnum, IsObject, IsOptional, IsNotEmpty } from 'class-validator';
|
|
2
|
-
import { TemplateEngineEnum, TemplateLanguageEnum } from '../interfaces/template.types';
|
|
3
|
-
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
4
|
-
import { Transform } from 'class-transformer';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export class RenderContentTemplateLayoutDto {
|
|
8
|
-
@ApiProperty({ type: String })
|
|
9
|
-
@IsString()
|
|
10
|
-
@IsNotEmpty()
|
|
11
|
-
content?: string;
|
|
12
|
-
|
|
13
|
-
@ApiProperty({ enum: TemplateLanguageEnum, type: String })
|
|
14
|
-
@IsEnum(TemplateLanguageEnum)
|
|
15
|
-
@IsNotEmpty()
|
|
16
|
-
@Transform(({ value }) => value || TemplateLanguageEnum.HTML)
|
|
17
|
-
language?: TemplateLanguageEnum;
|
|
18
|
-
|
|
19
|
-
@ApiProperty({ enum: TemplateEngineEnum, type: String })
|
|
20
|
-
@IsEnum(TemplateEngineEnum)
|
|
21
|
-
@Transform(({ value }) => value || TemplateEngineEnum.NUNJUCKS)
|
|
22
|
-
engine?: TemplateEngineEnum;
|
|
23
|
-
|
|
24
|
-
@ApiPropertyOptional({
|
|
25
|
-
type: String,
|
|
26
|
-
nullable: true,
|
|
27
|
-
description: 'The context of the template'
|
|
28
|
-
})
|
|
29
|
-
@IsObject()
|
|
30
|
-
@IsOptional()
|
|
31
|
-
context?: Record<string, any>;
|
|
32
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { IsString, IsEnum, IsObject, IsOptional, IsNotEmpty } from 'class-validator';
|
|
2
|
-
import { TemplateEngineEnum, TemplateLanguageEnum } from '../interfaces/template.types';
|
|
3
|
-
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
4
|
-
import { Transform } from 'class-transformer';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export class RenderContentTemplateDto {
|
|
8
|
-
@ApiProperty({ type: String })
|
|
9
|
-
@IsString()
|
|
10
|
-
@IsNotEmpty()
|
|
11
|
-
content?: string;
|
|
12
|
-
|
|
13
|
-
@ApiProperty({ enum: TemplateLanguageEnum, type: String })
|
|
14
|
-
@IsEnum(TemplateLanguageEnum)
|
|
15
|
-
@IsNotEmpty()
|
|
16
|
-
@Transform(({ value }) => value || TemplateLanguageEnum.HTML)
|
|
17
|
-
language?: TemplateLanguageEnum;
|
|
18
|
-
|
|
19
|
-
@ApiProperty({ enum: TemplateEngineEnum, type: String })
|
|
20
|
-
@IsEnum(TemplateEngineEnum)
|
|
21
|
-
@Transform(({ value }) => value || TemplateEngineEnum.NUNJUCKS)
|
|
22
|
-
engine?: TemplateEngineEnum;
|
|
23
|
-
|
|
24
|
-
@ApiPropertyOptional({
|
|
25
|
-
type: String,
|
|
26
|
-
nullable: true,
|
|
27
|
-
description: 'The context of the template'
|
|
28
|
-
})
|
|
29
|
-
@IsObject()
|
|
30
|
-
@IsOptional()
|
|
31
|
-
context?: Record<string, any>;
|
|
32
|
-
|
|
33
|
-
@ApiPropertyOptional({ type: String })
|
|
34
|
-
@IsString()
|
|
35
|
-
@IsOptional()
|
|
36
|
-
templateLayoutId?: string;
|
|
37
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { IsString, IsEnum, IsObject, IsOptional, IsNotEmpty } from 'class-validator';
|
|
2
|
-
import { TemplateTypeEnum } from '../interfaces/template.types';
|
|
3
|
-
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export class RenderTemplateLayoutDto {
|
|
7
|
-
|
|
8
|
-
@ApiPropertyOptional({
|
|
9
|
-
type: String,
|
|
10
|
-
default: 'en',
|
|
11
|
-
description: 'The locale code, i.e en, fr, es, etc.'
|
|
12
|
-
})
|
|
13
|
-
@IsString()
|
|
14
|
-
@IsOptional()
|
|
15
|
-
locale?: string = 'en';
|
|
16
|
-
|
|
17
|
-
@ApiProperty({ type: String })
|
|
18
|
-
@IsString()
|
|
19
|
-
@IsNotEmpty()
|
|
20
|
-
name: string;
|
|
21
|
-
|
|
22
|
-
@ApiProperty({
|
|
23
|
-
type: String,
|
|
24
|
-
default: 'system',
|
|
25
|
-
description: 'The scope of the template, i.e user, organization, etc.'
|
|
26
|
-
})
|
|
27
|
-
@IsString()
|
|
28
|
-
scope: string;
|
|
29
|
-
|
|
30
|
-
@ApiPropertyOptional({
|
|
31
|
-
type: String,
|
|
32
|
-
default: null,
|
|
33
|
-
description: 'The scope id of the template, i.e user id, organization id, etc.'
|
|
34
|
-
})
|
|
35
|
-
@IsString()
|
|
36
|
-
@IsOptional()
|
|
37
|
-
scopeId?: string;
|
|
38
|
-
|
|
39
|
-
@ApiPropertyOptional({
|
|
40
|
-
type: String,
|
|
41
|
-
nullable: true,
|
|
42
|
-
description: 'The context of the template'
|
|
43
|
-
})
|
|
44
|
-
@IsObject()
|
|
45
|
-
@IsOptional()
|
|
46
|
-
context?: Record<string, any>;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export class RenderTemplateLayoutOutput {
|
|
51
|
-
@ApiProperty({ type: String })
|
|
52
|
-
@IsString()
|
|
53
|
-
@IsNotEmpty()
|
|
54
|
-
content: string;
|
|
55
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { IsString, IsEnum, IsObject, IsOptional, IsNotEmpty, Matches, ValidateIf } from 'class-validator';
|
|
2
|
-
import { TemplateLanguageEnum, TemplateTypeEnum } from '../interfaces/template.types';
|
|
3
|
-
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export class RenderTemplateDto {
|
|
7
|
-
|
|
8
|
-
@ApiPropertyOptional({
|
|
9
|
-
type: String,
|
|
10
|
-
default: 'en',
|
|
11
|
-
description: 'The locale code, i.e en, fr, es, etc.'
|
|
12
|
-
})
|
|
13
|
-
@IsString()
|
|
14
|
-
@IsOptional()
|
|
15
|
-
locale?: string = 'en';
|
|
16
|
-
|
|
17
|
-
@ApiProperty({ type: String })
|
|
18
|
-
@IsString()
|
|
19
|
-
@IsNotEmpty()
|
|
20
|
-
@ValidateIf((object, value) => !object?.content)
|
|
21
|
-
name?: string;
|
|
22
|
-
|
|
23
|
-
@ApiProperty({ type: String })
|
|
24
|
-
@IsString()
|
|
25
|
-
@IsNotEmpty()
|
|
26
|
-
@ValidateIf((object, value) => !object?.name)
|
|
27
|
-
content?: string;
|
|
28
|
-
|
|
29
|
-
@ApiProperty({ enum: TemplateLanguageEnum, type: String })
|
|
30
|
-
@IsEnum(TemplateLanguageEnum)
|
|
31
|
-
@IsNotEmpty()
|
|
32
|
-
@ValidateIf((object, value) => !object?.name)
|
|
33
|
-
language?: TemplateLanguageEnum;
|
|
34
|
-
|
|
35
|
-
@ApiPropertyOptional({
|
|
36
|
-
type: String,
|
|
37
|
-
default: 'system',
|
|
38
|
-
description: 'The scope of the template, i.e user, organization, etc.'
|
|
39
|
-
})
|
|
40
|
-
@IsString()
|
|
41
|
-
@IsOptional()
|
|
42
|
-
scope?: string = 'system';
|
|
43
|
-
|
|
44
|
-
@ApiPropertyOptional({
|
|
45
|
-
type: String,
|
|
46
|
-
default: null,
|
|
47
|
-
description: 'The scope id of the template, i.e user id, organization id, etc.'
|
|
48
|
-
})
|
|
49
|
-
@IsString()
|
|
50
|
-
@IsOptional()
|
|
51
|
-
scopeId?: string;
|
|
52
|
-
|
|
53
|
-
@ApiPropertyOptional({
|
|
54
|
-
type: String,
|
|
55
|
-
nullable: true,
|
|
56
|
-
description: 'The context of the template'
|
|
57
|
-
})
|
|
58
|
-
@IsObject()
|
|
59
|
-
@IsOptional()
|
|
60
|
-
context?: Record<string, any>;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
export class RenderTemplateOutputDTO {
|
|
65
|
-
@ApiProperty({ type: String })
|
|
66
|
-
@IsString()
|
|
67
|
-
@IsNotEmpty()
|
|
68
|
-
content: string;
|
|
69
|
-
|
|
70
|
-
@ApiProperty({ type: String })
|
|
71
|
-
@IsString()
|
|
72
|
-
@IsNotEmpty()
|
|
73
|
-
subject: string;
|
|
74
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { IsEnum, IsOptional, IsString, IsArray } from 'class-validator';
|
|
2
|
-
import { ApiProperty } from '@nestjs/swagger';
|
|
3
|
-
import { TemplateTypeEnum } from '../interfaces/template.types';
|
|
4
|
-
|
|
5
|
-
export class TemplateFilterDto {
|
|
6
|
-
@ApiProperty({
|
|
7
|
-
type: String,
|
|
8
|
-
required: false,
|
|
9
|
-
description: 'Filter by scope (e.g., system, tenant, organization)'
|
|
10
|
-
})
|
|
11
|
-
@IsString()
|
|
12
|
-
@IsOptional()
|
|
13
|
-
scope?: string;
|
|
14
|
-
|
|
15
|
-
@ApiProperty({
|
|
16
|
-
type: String,
|
|
17
|
-
required: false,
|
|
18
|
-
description: 'Filter by scope ID (e.g., tenant ID, organization ID)'
|
|
19
|
-
})
|
|
20
|
-
@IsString()
|
|
21
|
-
@IsOptional()
|
|
22
|
-
scopeId?: string;
|
|
23
|
-
|
|
24
|
-
@ApiProperty({
|
|
25
|
-
enum: TemplateTypeEnum,
|
|
26
|
-
required: false,
|
|
27
|
-
description: 'Filter by template type'
|
|
28
|
-
})
|
|
29
|
-
@IsEnum(TemplateTypeEnum)
|
|
30
|
-
@IsOptional()
|
|
31
|
-
type?: TemplateTypeEnum;
|
|
32
|
-
|
|
33
|
-
@ApiProperty({
|
|
34
|
-
type: String,
|
|
35
|
-
required: false,
|
|
36
|
-
description: 'Filter by locale (e.g., en, fr, es)'
|
|
37
|
-
})
|
|
38
|
-
@IsString()
|
|
39
|
-
@IsOptional()
|
|
40
|
-
locale?: string;
|
|
41
|
-
|
|
42
|
-
@ApiProperty({
|
|
43
|
-
type: [String],
|
|
44
|
-
required: false,
|
|
45
|
-
description: 'Exclude templates with these names'
|
|
46
|
-
})
|
|
47
|
-
@IsArray()
|
|
48
|
-
@IsString({ each: true })
|
|
49
|
-
@IsOptional()
|
|
50
|
-
excludeNames?: string[];
|
|
51
|
-
|
|
52
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { IsOptional, IsString, IsArray } from 'class-validator';
|
|
2
|
-
import { ApiProperty } from '@nestjs/swagger';
|
|
3
|
-
|
|
4
|
-
export class TemplateLayoutFilterDto {
|
|
5
|
-
@ApiProperty({
|
|
6
|
-
type: String,
|
|
7
|
-
required: false,
|
|
8
|
-
description: 'Filter by scope (e.g., system, tenant, organization)'
|
|
9
|
-
})
|
|
10
|
-
@IsString()
|
|
11
|
-
@IsOptional()
|
|
12
|
-
scope?: string;
|
|
13
|
-
|
|
14
|
-
@ApiProperty({
|
|
15
|
-
type: String,
|
|
16
|
-
required: false,
|
|
17
|
-
description: 'Filter by scope ID (e.g., tenant ID, organization ID)'
|
|
18
|
-
})
|
|
19
|
-
@IsString()
|
|
20
|
-
@IsOptional()
|
|
21
|
-
scopeId?: string;
|
|
22
|
-
|
|
23
|
-
@ApiProperty({
|
|
24
|
-
type: String,
|
|
25
|
-
required: false,
|
|
26
|
-
description: 'Filter by template type'
|
|
27
|
-
})
|
|
28
|
-
@IsString()
|
|
29
|
-
@IsOptional()
|
|
30
|
-
type?: string;
|
|
31
|
-
|
|
32
|
-
@ApiProperty({
|
|
33
|
-
type: String,
|
|
34
|
-
required: false,
|
|
35
|
-
description: 'Filter by locale (e.g., en, fr, es)'
|
|
36
|
-
})
|
|
37
|
-
@IsString()
|
|
38
|
-
@IsOptional()
|
|
39
|
-
locale?: string;
|
|
40
|
-
|
|
41
|
-
@ApiProperty({
|
|
42
|
-
type: [String],
|
|
43
|
-
required: false,
|
|
44
|
-
description: 'Exclude templates with these names'
|
|
45
|
-
})
|
|
46
|
-
@IsArray()
|
|
47
|
-
@IsString({ each: true })
|
|
48
|
-
@IsOptional()
|
|
49
|
-
excludeNames?: string[];
|
|
50
|
-
|
|
51
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { TemplateLanguageEnum } from '../../interfaces/template.types';
|
|
2
|
-
import { LanguageEngine } from '../language-engine';
|
|
3
|
-
|
|
4
|
-
export class HtmlEngine extends LanguageEngine {
|
|
5
|
-
static override engineName = TemplateLanguageEnum.HTML;
|
|
6
|
-
|
|
7
|
-
private options: any; // Using any for now since htmlparser2 types are causing issues
|
|
8
|
-
|
|
9
|
-
constructor(options?: any) {
|
|
10
|
-
super();
|
|
11
|
-
this.options = options;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async render(content: string): Promise<string> {
|
|
15
|
-
try {
|
|
16
|
-
// For HTML, we just return the content as is
|
|
17
|
-
// But we validate it first to ensure it's valid HTML
|
|
18
|
-
const isValid = await this.validate(content);
|
|
19
|
-
if (!isValid) {
|
|
20
|
-
throw new Error('Invalid HTML content');
|
|
21
|
-
}
|
|
22
|
-
return content;
|
|
23
|
-
} catch (error: any) {
|
|
24
|
-
throw new Error(`Failed to render HTML: ${error?.message || 'Unknown error'}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async validate(content: string): Promise<boolean> {
|
|
29
|
-
try {
|
|
30
|
-
const { Parser } = await import('htmlparser2');
|
|
31
|
-
|
|
32
|
-
return new Promise((resolve) => {
|
|
33
|
-
const parser = new Parser({
|
|
34
|
-
onerror: () => {
|
|
35
|
-
resolve(false);
|
|
36
|
-
},
|
|
37
|
-
onend: () => {
|
|
38
|
-
resolve(true);
|
|
39
|
-
}
|
|
40
|
-
}, this.options);
|
|
41
|
-
|
|
42
|
-
parser.write(content);
|
|
43
|
-
parser.end();
|
|
44
|
-
});
|
|
45
|
-
} catch (error) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { TemplateLanguageEnum } from '../../interfaces/template.types';
|
|
3
|
-
import { LanguageEngine } from '../language-engine';
|
|
4
|
-
|
|
5
|
-
@Injectable()
|
|
6
|
-
export class MarkdownEngine extends LanguageEngine {
|
|
7
|
-
static override engineName = TemplateLanguageEnum.MARKDOWN;
|
|
8
|
-
|
|
9
|
-
private options: any; // Using any for now since marked types are causing issues
|
|
10
|
-
|
|
11
|
-
constructor(options?: any) {
|
|
12
|
-
super();
|
|
13
|
-
this.options = options;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async render(content: string): Promise<string> {
|
|
17
|
-
// try {
|
|
18
|
-
// const { marked } = await import('marked');
|
|
19
|
-
// return marked(content, this.options);
|
|
20
|
-
// } catch (error: any) {
|
|
21
|
-
// throw new Error(`Failed to render Markdown: ${error?.message || 'Unknown error'}`);
|
|
22
|
-
// }
|
|
23
|
-
return content;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async validate(content: string): Promise<boolean> {
|
|
27
|
-
// try {
|
|
28
|
-
// const { marked } = await import('marked');
|
|
29
|
-
// // Basic Markdown validation - check for common syntax errors
|
|
30
|
-
// marked(content, this.options);
|
|
31
|
-
// return true;
|
|
32
|
-
// } catch (error) {
|
|
33
|
-
// return false;
|
|
34
|
-
// }
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
}
|