@k-msg/template 0.1.0
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/README.md +72 -0
- package/dist/index.cjs +1315 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +463 -0
- package/dist/index.d.ts +463 -0
- package/dist/index.js +1279 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @k-msg/template
|
|
2
|
+
|
|
3
|
+
Template management and validation system for the K-Message platform.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @k-msg/template @k-msg/core
|
|
9
|
+
# or
|
|
10
|
+
bun add @k-msg/template @k-msg/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Template Engine**: Comprehensive template management system
|
|
16
|
+
- **Variable Parsing**: Automatic template variable extraction and validation
|
|
17
|
+
- **Template Validation**: Built-in validation for template content and structure
|
|
18
|
+
- **Template Registry**: Centralized template storage and retrieval
|
|
19
|
+
- **Template Builder**: Dynamic template creation and modification
|
|
20
|
+
|
|
21
|
+
## Basic Usage
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { TemplateService, TemplateValidator } from '@k-msg/template';
|
|
25
|
+
|
|
26
|
+
const templateService = new TemplateService();
|
|
27
|
+
|
|
28
|
+
// Create a new template
|
|
29
|
+
const template = await templateService.create({
|
|
30
|
+
name: 'OTP Verification',
|
|
31
|
+
content: '[MyApp] Your verification code is #{code}. Valid for 10 minutes.',
|
|
32
|
+
category: 'AUTHENTICATION',
|
|
33
|
+
variables: ['code']
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Validate template
|
|
37
|
+
const validator = new TemplateValidator();
|
|
38
|
+
const validation = validator.validate(template.content);
|
|
39
|
+
|
|
40
|
+
if (validation.isValid) {
|
|
41
|
+
console.log('Template is valid');
|
|
42
|
+
console.log('Variables found:', validation.variables);
|
|
43
|
+
} else {
|
|
44
|
+
console.log('Validation errors:', validation.errors);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Template Registry
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { TemplateRegistry } from '@k-msg/template';
|
|
52
|
+
|
|
53
|
+
const registry = new TemplateRegistry();
|
|
54
|
+
|
|
55
|
+
// Register a template
|
|
56
|
+
await registry.register({
|
|
57
|
+
id: 'otp-basic',
|
|
58
|
+
name: 'Basic OTP Template',
|
|
59
|
+
content: '[#{service}] Verification code: #{code}',
|
|
60
|
+
category: 'AUTHENTICATION'
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Search templates
|
|
64
|
+
const templates = await registry.search({
|
|
65
|
+
category: 'AUTHENTICATION',
|
|
66
|
+
status: 'ACTIVE'
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
MIT
|