@k-msg/template 0.19.1 → 0.21.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 +53 -43
- package/dist/index.d.ts +4 -6
- package/dist/index.js +15 -15
- package/dist/index.js.map +8 -10
- package/dist/index.mjs +15 -15
- package/dist/index.mjs.map +8 -10
- package/dist/personalization/variable.replacer.d.ts +139 -0
- package/dist/runtime/template-input.d.ts +19 -0
- package/dist/{service.d.ts → runtime/template-lifecycle.service.d.ts} +5 -3
- package/dist/{services/template.service.d.ts → toolkit/in-memory-template-store.d.ts} +2 -2
- package/dist/toolkit/index.d.ts +3 -0
- package/dist/toolkit/index.js +43 -0
- package/dist/toolkit/index.js.map +88 -0
- package/dist/toolkit/index.mjs +43 -0
- package/dist/toolkit/index.mjs.map +88 -0
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Canonical docs: [k-msg.and.guide](https://k-msg.and.guide)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Single source of truth for K-Message template runtime lifecycle, payload validation, and personalization.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -12,70 +12,80 @@ npm install @k-msg/template @k-msg/core
|
|
|
12
12
|
bun add @k-msg/template @k-msg/core
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Runtime API (`@k-msg/template`)
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
- **Variable Parsing**: Automatic template variable extraction and validation
|
|
19
|
-
- **Template Validation**: Built-in validation for template content and structure
|
|
20
|
-
- **Template Registry**: Centralized template storage and retrieval
|
|
21
|
-
- **Template Builder**: Dynamic template creation and modification
|
|
17
|
+
Main exports focus on runtime-safe template workflows:
|
|
22
18
|
|
|
23
|
-
|
|
19
|
+
- `TemplateLifecycleService`
|
|
20
|
+
- `TemplatePersonalizer`, `defaultTemplatePersonalizer`, `TemplateVariableUtils`
|
|
21
|
+
- `interpolate`
|
|
22
|
+
- `validateTemplatePayload`, `parseTemplateButtons`
|
|
23
|
+
- low-level parsers (`ButtonParser`, `VariableParser`, `TemplateValidator`)
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
## Basic Usage
|
|
25
|
+
### Lifecycle Service
|
|
28
26
|
|
|
29
27
|
```typescript
|
|
30
|
-
import {
|
|
28
|
+
import { TemplateLifecycleService } from "@k-msg/template";
|
|
29
|
+
import type { TemplateProvider } from "@k-msg/core";
|
|
31
30
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
});
|
|
31
|
+
const provider: TemplateProvider = /* your provider */;
|
|
32
|
+
const templates = new TemplateLifecycleService(provider);
|
|
35
33
|
|
|
36
|
-
|
|
34
|
+
await templates.create({
|
|
35
|
+
name: "OTP Verification",
|
|
36
|
+
content: "[MyApp] Code: #{code}",
|
|
37
|
+
});
|
|
37
38
|
```
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
### Runtime Validation
|
|
40
41
|
|
|
41
42
|
```typescript
|
|
42
|
-
import {
|
|
43
|
+
import { parseTemplateButtons, validateTemplatePayload } from "@k-msg/template";
|
|
43
44
|
|
|
44
|
-
const
|
|
45
|
+
const buttons = parseTemplateButtons('[{"type":"WL","name":"Open","url_mobile":"https://example.com"}]');
|
|
46
|
+
if (buttons.isFailure) throw buttons.error;
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
48
|
+
const payload = validateTemplatePayload(
|
|
49
|
+
{
|
|
50
|
+
name: "Notice",
|
|
51
|
+
content: "Hello #{name}",
|
|
52
|
+
buttons: buttons.value,
|
|
53
|
+
},
|
|
54
|
+
{ requireName: true, requireContent: true },
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
if (payload.isFailure) throw payload.error;
|
|
58
|
+
```
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
### Personalization
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { TemplateVariableUtils } from "@k-msg/template";
|
|
64
|
+
|
|
65
|
+
const rendered = TemplateVariableUtils.replace("Hello #{name}", {
|
|
66
|
+
name: "Jane",
|
|
58
67
|
});
|
|
68
|
+
// "Hello Jane"
|
|
59
69
|
```
|
|
60
70
|
|
|
61
|
-
##
|
|
71
|
+
## Toolkit API (`@k-msg/template/toolkit`)
|
|
62
72
|
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
Builder/registry/testing helpers are exposed separately:
|
|
74
|
+
|
|
75
|
+
- `TemplateBuilder`, `TemplateBuilders`
|
|
76
|
+
- `TemplateRegistry`
|
|
77
|
+
- `InMemoryTemplateStore`
|
|
65
78
|
|
|
66
79
|
```typescript
|
|
67
|
-
import {
|
|
68
|
-
import type { TemplateProvider } from '@k-msg/core';
|
|
80
|
+
import { TemplateRegistry, TemplateBuilders } from "@k-msg/template/toolkit";
|
|
69
81
|
|
|
70
|
-
const
|
|
71
|
-
const
|
|
82
|
+
const registry = new TemplateRegistry();
|
|
83
|
+
const template = TemplateBuilders.authentication("OTP", "mock")
|
|
84
|
+
.code("OTP_001")
|
|
85
|
+
.content("Code: #{code}")
|
|
86
|
+
.build();
|
|
72
87
|
|
|
73
|
-
await
|
|
74
|
-
code: 'OTP_001',
|
|
75
|
-
name: 'OTP Verification',
|
|
76
|
-
content: '[MyApp] Your verification code is #{code}.',
|
|
77
|
-
category: 'AUTHENTICATION'
|
|
78
|
-
});
|
|
88
|
+
await registry.register(template);
|
|
79
89
|
```
|
|
80
90
|
|
|
81
91
|
## License
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* 템플릿 파싱, 변수 치환, 검증 기능 제공
|
|
2
|
+
* Runtime template APIs
|
|
4
3
|
*/
|
|
5
|
-
export { TemplateBuilder, TemplateBuilders } from "./builder/template.builder";
|
|
6
4
|
export { interpolate } from "./interpolator";
|
|
7
5
|
export { ButtonParser } from "./parser/button.parser";
|
|
8
6
|
export { TemplateValidator, type ValidationResult } from "./parser/validator";
|
|
9
7
|
export { VariableParser } from "./parser/variable.parser";
|
|
10
|
-
export { type
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
8
|
+
export { type ConditionalBlock, defaultTemplatePersonalizer, type LoopBlock, type ReplacementError, type ReplacementResult, TemplatePersonalizer, type TemplatePersonalizerOptions, type TemplateVariableInfo, type TemplateVariableMap, TemplateVariableUtils, } from "./personalization/variable.replacer";
|
|
9
|
+
export { type NormalizedTemplatePayload, parseTemplateButtons, type ValidateTemplatePayloadOptions, validateTemplatePayload, } from "./runtime/template-input";
|
|
10
|
+
export { TemplateLifecycleService } from "./runtime/template-lifecycle.service";
|
|
13
11
|
export type { AlimTalkTemplate, TemplateButton, TemplateVariable, } from "./types/template.types";
|
|
14
12
|
export { TemplateCategory, TemplateStatus, TemplateType, } from "./types/template.types";
|