@k-msg/template 0.1.1 → 0.1.2
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 +11 -15
- package/dist/builder/template.builder.d.ts +139 -0
- package/dist/index.d.ts +12 -461
- package/dist/index.js +21 -1276
- package/dist/index.js.map +89 -1
- package/dist/index.mjs +24 -0
- package/dist/index.mjs.map +89 -0
- package/dist/interpolator.d.ts +8 -0
- package/dist/parser/button.parser.d.ts +25 -0
- package/dist/parser/validator.d.ts +24 -0
- package/dist/parser/variable.parser.d.ts +27 -0
- package/dist/registry/template.registry.d.ts +168 -0
- package/dist/service.d.ts +14 -0
- package/dist/services/template.service.d.ts +10 -0
- package/dist/types/template.types.d.ts +150 -0
- package/package.json +18 -12
- package/dist/index.cjs +0 -1315
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -463
package/README.md
CHANGED
|
@@ -21,27 +21,23 @@ bun add @k-msg/template @k-msg/core
|
|
|
21
21
|
## Basic Usage
|
|
22
22
|
|
|
23
23
|
```typescript
|
|
24
|
-
import { TemplateService
|
|
24
|
+
import { TemplateService } from '@k-msg/template';
|
|
25
|
+
import { IWINVAdapter } from '@k-msg/provider';
|
|
25
26
|
|
|
26
|
-
const
|
|
27
|
+
const adapter = new IWINVAdapter(config);
|
|
28
|
+
const templateService = new TemplateService(adapter);
|
|
27
29
|
|
|
28
30
|
// Create a new template
|
|
29
|
-
const
|
|
31
|
+
const result = await templateService.create({
|
|
32
|
+
code: 'OTP_001',
|
|
30
33
|
name: 'OTP Verification',
|
|
31
|
-
content: '[MyApp] Your verification code is #{code}.
|
|
32
|
-
category: 'AUTHENTICATION'
|
|
33
|
-
variables: ['code']
|
|
34
|
+
content: '[MyApp] Your verification code is #{code}.',
|
|
35
|
+
category: 'AUTHENTICATION'
|
|
34
36
|
});
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
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);
|
|
38
|
+
if (result.isSuccess) {
|
|
39
|
+
const template = result.value;
|
|
40
|
+
console.log('Template created:', template.id);
|
|
45
41
|
}
|
|
46
42
|
```
|
|
47
43
|
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template Builder - Fluent API for creating AlimTalk templates
|
|
3
|
+
*/
|
|
4
|
+
import { type AlimTalkTemplate, type TemplateButton, TemplateCategory, TemplateStatus } from "../types/template.types";
|
|
5
|
+
export declare class TemplateBuilder {
|
|
6
|
+
private template;
|
|
7
|
+
/**
|
|
8
|
+
* Set template name
|
|
9
|
+
*/
|
|
10
|
+
name(name: string): TemplateBuilder;
|
|
11
|
+
/**
|
|
12
|
+
* Set template code (provider specific)
|
|
13
|
+
*/
|
|
14
|
+
code(code: string): TemplateBuilder;
|
|
15
|
+
/**
|
|
16
|
+
* Set template content with variables
|
|
17
|
+
*/
|
|
18
|
+
content(content: string): TemplateBuilder;
|
|
19
|
+
/**
|
|
20
|
+
* Set template category
|
|
21
|
+
*/
|
|
22
|
+
category(category: TemplateCategory): TemplateBuilder;
|
|
23
|
+
/**
|
|
24
|
+
* Set template provider
|
|
25
|
+
*/
|
|
26
|
+
provider(provider: string): TemplateBuilder;
|
|
27
|
+
/**
|
|
28
|
+
* Set template status
|
|
29
|
+
*/
|
|
30
|
+
status(status: TemplateStatus): TemplateBuilder;
|
|
31
|
+
/**
|
|
32
|
+
* Add a variable definition
|
|
33
|
+
*/
|
|
34
|
+
variable(name: string, type?: "string" | "number" | "date" | "custom", required?: boolean, options?: {
|
|
35
|
+
maxLength?: number;
|
|
36
|
+
format?: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
example?: string;
|
|
39
|
+
}): TemplateBuilder;
|
|
40
|
+
/**
|
|
41
|
+
* Add multiple variables at once
|
|
42
|
+
*/
|
|
43
|
+
variables(variables: Array<{
|
|
44
|
+
name: string;
|
|
45
|
+
type?: "string" | "number" | "date" | "custom";
|
|
46
|
+
required?: boolean;
|
|
47
|
+
maxLength?: number;
|
|
48
|
+
format?: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
example?: string;
|
|
51
|
+
}>): TemplateBuilder;
|
|
52
|
+
/**
|
|
53
|
+
* Add a web link button
|
|
54
|
+
*/
|
|
55
|
+
webLinkButton(name: string, mobileUrl?: string, pcUrl?: string): TemplateBuilder;
|
|
56
|
+
/**
|
|
57
|
+
* Add an app link button
|
|
58
|
+
*/
|
|
59
|
+
appLinkButton(name: string, options: {
|
|
60
|
+
iosUrl?: string;
|
|
61
|
+
androidUrl?: string;
|
|
62
|
+
iosScheme?: string;
|
|
63
|
+
androidScheme?: string;
|
|
64
|
+
}): TemplateBuilder;
|
|
65
|
+
/**
|
|
66
|
+
* Add a delivery tracking button
|
|
67
|
+
*/
|
|
68
|
+
deliveryButton(name: string): TemplateBuilder;
|
|
69
|
+
/**
|
|
70
|
+
* Add a bot keyword button
|
|
71
|
+
*/
|
|
72
|
+
botKeywordButton(name: string): TemplateBuilder;
|
|
73
|
+
/**
|
|
74
|
+
* Add a message delivery button
|
|
75
|
+
*/
|
|
76
|
+
messageDeliveryButton(name: string): TemplateBuilder;
|
|
77
|
+
/**
|
|
78
|
+
* Add a custom button
|
|
79
|
+
*/
|
|
80
|
+
button(button: TemplateButton): TemplateBuilder;
|
|
81
|
+
/**
|
|
82
|
+
* Clear all buttons
|
|
83
|
+
*/
|
|
84
|
+
clearButtons(): TemplateBuilder;
|
|
85
|
+
/**
|
|
86
|
+
* Set template metadata
|
|
87
|
+
*/
|
|
88
|
+
metadata(metadata: Partial<AlimTalkTemplate["metadata"]>): TemplateBuilder;
|
|
89
|
+
/**
|
|
90
|
+
* Validate the current template
|
|
91
|
+
*/
|
|
92
|
+
validate(): {
|
|
93
|
+
isValid: boolean;
|
|
94
|
+
errors: string[];
|
|
95
|
+
warnings: string[];
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Preview the template with sample variables
|
|
99
|
+
*/
|
|
100
|
+
preview(sampleVariables?: Record<string, any>): string;
|
|
101
|
+
/**
|
|
102
|
+
* Generate sample variables based on variable definitions
|
|
103
|
+
*/
|
|
104
|
+
private generateSampleVariables;
|
|
105
|
+
/**
|
|
106
|
+
* Clone the current builder
|
|
107
|
+
*/
|
|
108
|
+
clone(): TemplateBuilder;
|
|
109
|
+
/**
|
|
110
|
+
* Reset the builder to start fresh
|
|
111
|
+
*/
|
|
112
|
+
reset(): TemplateBuilder;
|
|
113
|
+
/**
|
|
114
|
+
* Build the final template
|
|
115
|
+
*/
|
|
116
|
+
build(): AlimTalkTemplate;
|
|
117
|
+
private generateTemplateId;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Static factory methods for common template types
|
|
121
|
+
*/
|
|
122
|
+
export declare const TemplateBuilders: {
|
|
123
|
+
/**
|
|
124
|
+
* Create an authentication template builder
|
|
125
|
+
*/
|
|
126
|
+
authentication(name: string, provider: string): TemplateBuilder;
|
|
127
|
+
/**
|
|
128
|
+
* Create a notification template builder
|
|
129
|
+
*/
|
|
130
|
+
notification(name: string, provider: string): TemplateBuilder;
|
|
131
|
+
/**
|
|
132
|
+
* Create a promotion template builder
|
|
133
|
+
*/
|
|
134
|
+
promotion(name: string, provider: string): TemplateBuilder;
|
|
135
|
+
/**
|
|
136
|
+
* Create a payment template builder
|
|
137
|
+
*/
|
|
138
|
+
payment(name: string, provider: string): TemplateBuilder;
|
|
139
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,463 +1,14 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
|
|
3
|
-
declare enum TemplateType {
|
|
4
|
-
ALIMTALK = "ALIMTALK",
|
|
5
|
-
SMS = "SMS",
|
|
6
|
-
LMS = "LMS",
|
|
7
|
-
MMS = "MMS",
|
|
8
|
-
RCS = "RCS"
|
|
9
|
-
}
|
|
10
|
-
declare enum TemplateCategory {
|
|
11
|
-
AUTHENTICATION = "AUTHENTICATION",// 인증
|
|
12
|
-
NOTIFICATION = "NOTIFICATION",// 알림
|
|
13
|
-
PROMOTION = "PROMOTION",// 프로모션
|
|
14
|
-
INFORMATION = "INFORMATION",// 정보성
|
|
15
|
-
RESERVATION = "RESERVATION",// 예약
|
|
16
|
-
SHIPPING = "SHIPPING",// 배송
|
|
17
|
-
PAYMENT = "PAYMENT"
|
|
18
|
-
}
|
|
19
|
-
declare enum TemplateStatus {
|
|
20
|
-
DRAFT = "DRAFT",// 초안
|
|
21
|
-
PENDING = "PENDING",// 검수 중
|
|
22
|
-
APPROVED = "APPROVED",// 승인됨
|
|
23
|
-
REJECTED = "REJECTED",// 반려됨
|
|
24
|
-
DISABLED = "DISABLED"
|
|
25
|
-
}
|
|
26
|
-
interface TemplateVariable {
|
|
27
|
-
name: string;
|
|
28
|
-
type: 'string' | 'number' | 'date' | 'custom';
|
|
29
|
-
required: boolean;
|
|
30
|
-
maxLength?: number;
|
|
31
|
-
format?: string;
|
|
32
|
-
description?: string;
|
|
33
|
-
example?: string;
|
|
34
|
-
}
|
|
35
|
-
interface TemplateButton {
|
|
36
|
-
type: 'WL' | 'AL' | 'DS' | 'BK' | 'MD';
|
|
37
|
-
name: string;
|
|
38
|
-
linkMobile?: string;
|
|
39
|
-
linkPc?: string;
|
|
40
|
-
linkIos?: string;
|
|
41
|
-
linkAndroid?: string;
|
|
42
|
-
schemeIos?: string;
|
|
43
|
-
schemeAndroid?: string;
|
|
44
|
-
}
|
|
45
|
-
interface AlimTalkTemplate {
|
|
46
|
-
id: string;
|
|
47
|
-
code: string;
|
|
48
|
-
name: string;
|
|
49
|
-
content: string;
|
|
50
|
-
variables: TemplateVariable[];
|
|
51
|
-
buttons?: TemplateButton[];
|
|
52
|
-
category: TemplateCategory;
|
|
53
|
-
status: TemplateStatus;
|
|
54
|
-
provider: string;
|
|
55
|
-
metadata: {
|
|
56
|
-
createdAt: Date;
|
|
57
|
-
updatedAt: Date;
|
|
58
|
-
approvedAt?: Date;
|
|
59
|
-
rejectedAt?: Date;
|
|
60
|
-
rejectionReason?: string;
|
|
61
|
-
usage: {
|
|
62
|
-
sent: number;
|
|
63
|
-
delivered: number;
|
|
64
|
-
failed: number;
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
declare class TemplateService {
|
|
70
|
-
private templates;
|
|
71
|
-
createTemplate(template: Omit<AlimTalkTemplate, 'id' | 'metadata'>): Promise<AlimTalkTemplate>;
|
|
72
|
-
getTemplate(templateId: string): Promise<AlimTalkTemplate | null>;
|
|
73
|
-
updateTemplate(templateId: string, updates: Partial<AlimTalkTemplate>): Promise<AlimTalkTemplate>;
|
|
74
|
-
deleteTemplate(templateId: string): Promise<void>;
|
|
75
|
-
renderTemplate(templateId: string, variables: Record<string, any>): Promise<string>;
|
|
76
|
-
private generateTemplateId;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
declare class VariableParser {
|
|
80
|
-
private static readonly VARIABLE_PATTERN;
|
|
81
|
-
/**
|
|
82
|
-
* 템플릿 내용에서 변수를 추출합니다
|
|
83
|
-
*/
|
|
84
|
-
static extractVariables(content: string): string[];
|
|
85
|
-
/**
|
|
86
|
-
* 템플릿 내용의 변수를 실제 값으로 치환합니다
|
|
87
|
-
*/
|
|
88
|
-
static replaceVariables(content: string, variables: Record<string, string | number | Date>): string;
|
|
89
|
-
/**
|
|
90
|
-
* 변수 정의와 실제 제공된 값을 검증합니다
|
|
91
|
-
*/
|
|
92
|
-
static validateVariables(variableDefinitions: TemplateVariable[], providedVariables: Record<string, any>): {
|
|
93
|
-
isValid: boolean;
|
|
94
|
-
errors: string[];
|
|
95
|
-
};
|
|
96
|
-
private static validateVariableType;
|
|
97
|
-
/**
|
|
98
|
-
* 템플릿에서 사용된 변수와 정의된 변수의 일치성을 검사합니다
|
|
99
|
-
*/
|
|
100
|
-
static validateTemplateVariables(content: string, variableDefinitions: TemplateVariable[]): {
|
|
101
|
-
isValid: boolean;
|
|
102
|
-
errors: string[];
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
declare class ButtonParser {
|
|
107
|
-
/**
|
|
108
|
-
* 버튼 설정의 유효성을 검증합니다
|
|
109
|
-
*/
|
|
110
|
-
static validateButtons(buttons: TemplateButton[]): {
|
|
111
|
-
isValid: boolean;
|
|
112
|
-
errors: string[];
|
|
113
|
-
};
|
|
114
|
-
private static validateButtonByType;
|
|
115
|
-
private static validateWebLinkButton;
|
|
116
|
-
private static validateAppLinkButton;
|
|
117
|
-
private static validateDeliveryButton;
|
|
118
|
-
private static validateBotKeywordButton;
|
|
119
|
-
private static validateMessageDeliveryButton;
|
|
120
|
-
private static isValidUrl;
|
|
121
|
-
/**
|
|
122
|
-
* 버튼을 JSON 문자열로 직렬화합니다 (카카오 API 형식)
|
|
123
|
-
*/
|
|
124
|
-
static serializeButtons(buttons: TemplateButton[]): string;
|
|
125
|
-
/**
|
|
126
|
-
* JSON 문자열에서 버튼 배열로 역직렬화합니다
|
|
127
|
-
*/
|
|
128
|
-
static deserializeButtons(buttonsJson: string): TemplateButton[];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
interface ValidationResult {
|
|
132
|
-
isValid: boolean;
|
|
133
|
-
errors: string[];
|
|
134
|
-
warnings: string[];
|
|
135
|
-
}
|
|
136
|
-
declare class TemplateValidator {
|
|
137
|
-
/**
|
|
138
|
-
* 알림톡 템플릿의 전체적인 유효성을 검증합니다
|
|
139
|
-
*/
|
|
140
|
-
static validate(template: AlimTalkTemplate): ValidationResult;
|
|
141
|
-
private static validateBasicFields;
|
|
142
|
-
private static validateContent;
|
|
143
|
-
private static containsProhibitedCharacters;
|
|
144
|
-
private static validateUrlsInContent;
|
|
145
|
-
private static validateByCategory;
|
|
146
|
-
private static validateAuthenticationTemplate;
|
|
147
|
-
private static validatePromotionTemplate;
|
|
148
|
-
private static validatePaymentTemplate;
|
|
149
|
-
/**
|
|
150
|
-
* 빠른 검증 - 기본적인 필수 필드만 검사
|
|
151
|
-
*/
|
|
152
|
-
static quickValidate(template: Partial<AlimTalkTemplate>): ValidationResult;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
1
|
/**
|
|
156
|
-
* Template
|
|
2
|
+
* Template Engine
|
|
3
|
+
* 템플릿 파싱, 변수 치환, 검증 기능 제공
|
|
157
4
|
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
code(code: string): TemplateBuilder;
|
|
169
|
-
/**
|
|
170
|
-
* Set template content with variables
|
|
171
|
-
*/
|
|
172
|
-
content(content: string): TemplateBuilder;
|
|
173
|
-
/**
|
|
174
|
-
* Set template category
|
|
175
|
-
*/
|
|
176
|
-
category(category: TemplateCategory): TemplateBuilder;
|
|
177
|
-
/**
|
|
178
|
-
* Set template provider
|
|
179
|
-
*/
|
|
180
|
-
provider(provider: string): TemplateBuilder;
|
|
181
|
-
/**
|
|
182
|
-
* Set template status
|
|
183
|
-
*/
|
|
184
|
-
status(status: TemplateStatus): TemplateBuilder;
|
|
185
|
-
/**
|
|
186
|
-
* Add a variable definition
|
|
187
|
-
*/
|
|
188
|
-
variable(name: string, type?: 'string' | 'number' | 'date' | 'custom', required?: boolean, options?: {
|
|
189
|
-
maxLength?: number;
|
|
190
|
-
format?: string;
|
|
191
|
-
description?: string;
|
|
192
|
-
example?: string;
|
|
193
|
-
}): TemplateBuilder;
|
|
194
|
-
/**
|
|
195
|
-
* Add multiple variables at once
|
|
196
|
-
*/
|
|
197
|
-
variables(variables: Array<{
|
|
198
|
-
name: string;
|
|
199
|
-
type?: 'string' | 'number' | 'date' | 'custom';
|
|
200
|
-
required?: boolean;
|
|
201
|
-
maxLength?: number;
|
|
202
|
-
format?: string;
|
|
203
|
-
description?: string;
|
|
204
|
-
example?: string;
|
|
205
|
-
}>): TemplateBuilder;
|
|
206
|
-
/**
|
|
207
|
-
* Add a web link button
|
|
208
|
-
*/
|
|
209
|
-
webLinkButton(name: string, mobileUrl?: string, pcUrl?: string): TemplateBuilder;
|
|
210
|
-
/**
|
|
211
|
-
* Add an app link button
|
|
212
|
-
*/
|
|
213
|
-
appLinkButton(name: string, options: {
|
|
214
|
-
iosUrl?: string;
|
|
215
|
-
androidUrl?: string;
|
|
216
|
-
iosScheme?: string;
|
|
217
|
-
androidScheme?: string;
|
|
218
|
-
}): TemplateBuilder;
|
|
219
|
-
/**
|
|
220
|
-
* Add a delivery tracking button
|
|
221
|
-
*/
|
|
222
|
-
deliveryButton(name: string): TemplateBuilder;
|
|
223
|
-
/**
|
|
224
|
-
* Add a bot keyword button
|
|
225
|
-
*/
|
|
226
|
-
botKeywordButton(name: string): TemplateBuilder;
|
|
227
|
-
/**
|
|
228
|
-
* Add a message delivery button
|
|
229
|
-
*/
|
|
230
|
-
messageDeliveryButton(name: string): TemplateBuilder;
|
|
231
|
-
/**
|
|
232
|
-
* Add a custom button
|
|
233
|
-
*/
|
|
234
|
-
button(button: TemplateButton): TemplateBuilder;
|
|
235
|
-
/**
|
|
236
|
-
* Clear all buttons
|
|
237
|
-
*/
|
|
238
|
-
clearButtons(): TemplateBuilder;
|
|
239
|
-
/**
|
|
240
|
-
* Set template metadata
|
|
241
|
-
*/
|
|
242
|
-
metadata(metadata: Partial<AlimTalkTemplate['metadata']>): TemplateBuilder;
|
|
243
|
-
/**
|
|
244
|
-
* Validate the current template
|
|
245
|
-
*/
|
|
246
|
-
validate(): {
|
|
247
|
-
isValid: boolean;
|
|
248
|
-
errors: string[];
|
|
249
|
-
warnings: string[];
|
|
250
|
-
};
|
|
251
|
-
/**
|
|
252
|
-
* Preview the template with sample variables
|
|
253
|
-
*/
|
|
254
|
-
preview(sampleVariables?: Record<string, any>): string;
|
|
255
|
-
/**
|
|
256
|
-
* Generate sample variables based on variable definitions
|
|
257
|
-
*/
|
|
258
|
-
private generateSampleVariables;
|
|
259
|
-
/**
|
|
260
|
-
* Clone the current builder
|
|
261
|
-
*/
|
|
262
|
-
clone(): TemplateBuilder;
|
|
263
|
-
/**
|
|
264
|
-
* Reset the builder to start fresh
|
|
265
|
-
*/
|
|
266
|
-
reset(): TemplateBuilder;
|
|
267
|
-
/**
|
|
268
|
-
* Build the final template
|
|
269
|
-
*/
|
|
270
|
-
build(): AlimTalkTemplate;
|
|
271
|
-
private generateTemplateId;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Static factory methods for common template types
|
|
275
|
-
*/
|
|
276
|
-
declare const TemplateBuilders: {
|
|
277
|
-
/**
|
|
278
|
-
* Create an authentication template builder
|
|
279
|
-
*/
|
|
280
|
-
authentication(name: string, provider: string): TemplateBuilder;
|
|
281
|
-
/**
|
|
282
|
-
* Create a notification template builder
|
|
283
|
-
*/
|
|
284
|
-
notification(name: string, provider: string): TemplateBuilder;
|
|
285
|
-
/**
|
|
286
|
-
* Create a promotion template builder
|
|
287
|
-
*/
|
|
288
|
-
promotion(name: string, provider: string): TemplateBuilder;
|
|
289
|
-
/**
|
|
290
|
-
* Create a payment template builder
|
|
291
|
-
*/
|
|
292
|
-
payment(name: string, provider: string): TemplateBuilder;
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Template Registry - Manages templates across providers and categories
|
|
297
|
-
*/
|
|
298
|
-
|
|
299
|
-
interface TemplateSearchFilters {
|
|
300
|
-
provider?: string;
|
|
301
|
-
category?: TemplateCategory;
|
|
302
|
-
status?: TemplateStatus;
|
|
303
|
-
nameContains?: string;
|
|
304
|
-
codeContains?: string;
|
|
305
|
-
createdAfter?: Date;
|
|
306
|
-
createdBefore?: Date;
|
|
307
|
-
usageMin?: number;
|
|
308
|
-
usageMax?: number;
|
|
309
|
-
}
|
|
310
|
-
interface TemplateSearchOptions {
|
|
311
|
-
page?: number;
|
|
312
|
-
limit?: number;
|
|
313
|
-
sortBy?: 'name' | 'code' | 'createdAt' | 'updatedAt' | 'usage';
|
|
314
|
-
sortOrder?: 'asc' | 'desc';
|
|
315
|
-
}
|
|
316
|
-
interface TemplateSearchResult {
|
|
317
|
-
templates: AlimTalkTemplate[];
|
|
318
|
-
total: number;
|
|
319
|
-
page: number;
|
|
320
|
-
limit: number;
|
|
321
|
-
hasMore: boolean;
|
|
322
|
-
}
|
|
323
|
-
interface TemplateVersion {
|
|
324
|
-
version: number;
|
|
325
|
-
template: AlimTalkTemplate;
|
|
326
|
-
changes: string[];
|
|
327
|
-
createdAt: Date;
|
|
328
|
-
createdBy?: string;
|
|
329
|
-
}
|
|
330
|
-
interface TemplateHistory {
|
|
331
|
-
templateId: string;
|
|
332
|
-
versions: TemplateVersion[];
|
|
333
|
-
currentVersion: number;
|
|
334
|
-
}
|
|
335
|
-
interface TemplateUsageStats {
|
|
336
|
-
templateId: string;
|
|
337
|
-
totalSent: number;
|
|
338
|
-
totalDelivered: number;
|
|
339
|
-
totalFailed: number;
|
|
340
|
-
deliveryRate: number;
|
|
341
|
-
failureRate: number;
|
|
342
|
-
lastUsed?: Date;
|
|
343
|
-
usageByDay: Array<{
|
|
344
|
-
date: string;
|
|
345
|
-
sent: number;
|
|
346
|
-
delivered: number;
|
|
347
|
-
failed: number;
|
|
348
|
-
}>;
|
|
349
|
-
}
|
|
350
|
-
interface TemplateRegistryOptions {
|
|
351
|
-
enableVersioning: boolean;
|
|
352
|
-
maxVersionsPerTemplate: number;
|
|
353
|
-
enableUsageTracking: boolean;
|
|
354
|
-
enableAutoBackup: boolean;
|
|
355
|
-
backupInterval: number;
|
|
356
|
-
enableValidationOnRegister: boolean;
|
|
357
|
-
}
|
|
358
|
-
declare class TemplateRegistry extends EventEmitter {
|
|
359
|
-
private options;
|
|
360
|
-
private templates;
|
|
361
|
-
private templatesByCode;
|
|
362
|
-
private templatesByProvider;
|
|
363
|
-
private templatesByCategory;
|
|
364
|
-
private templateHistories;
|
|
365
|
-
private usageStats;
|
|
366
|
-
private backupTimer?;
|
|
367
|
-
private defaultOptions;
|
|
368
|
-
constructor(options?: Partial<TemplateRegistryOptions>);
|
|
369
|
-
/**
|
|
370
|
-
* Register a new template
|
|
371
|
-
*/
|
|
372
|
-
register(template: AlimTalkTemplate): Promise<void>;
|
|
373
|
-
/**
|
|
374
|
-
* Update an existing template
|
|
375
|
-
*/
|
|
376
|
-
update(templateId: string, updates: Partial<AlimTalkTemplate>): Promise<AlimTalkTemplate>;
|
|
377
|
-
/**
|
|
378
|
-
* Get template by ID
|
|
379
|
-
*/
|
|
380
|
-
get(templateId: string): AlimTalkTemplate | null;
|
|
381
|
-
/**
|
|
382
|
-
* Get template by code and provider
|
|
383
|
-
*/
|
|
384
|
-
getByCode(code: string, provider: string): AlimTalkTemplate | null;
|
|
385
|
-
/**
|
|
386
|
-
* Search templates with filters and pagination
|
|
387
|
-
*/
|
|
388
|
-
search(filters?: TemplateSearchFilters, options?: TemplateSearchOptions): TemplateSearchResult;
|
|
389
|
-
/**
|
|
390
|
-
* Get templates by provider
|
|
391
|
-
*/
|
|
392
|
-
getByProvider(provider: string): AlimTalkTemplate[];
|
|
393
|
-
/**
|
|
394
|
-
* Get templates by category
|
|
395
|
-
*/
|
|
396
|
-
getByCategory(category: TemplateCategory): AlimTalkTemplate[];
|
|
397
|
-
/**
|
|
398
|
-
* Delete template
|
|
399
|
-
*/
|
|
400
|
-
delete(templateId: string): Promise<boolean>;
|
|
401
|
-
/**
|
|
402
|
-
* Get template version history
|
|
403
|
-
*/
|
|
404
|
-
getHistory(templateId: string): TemplateHistory | null;
|
|
405
|
-
/**
|
|
406
|
-
* Get specific template version
|
|
407
|
-
*/
|
|
408
|
-
getVersion(templateId: string, version: number): AlimTalkTemplate | null;
|
|
409
|
-
/**
|
|
410
|
-
* Restore template to a specific version
|
|
411
|
-
*/
|
|
412
|
-
restoreVersion(templateId: string, version: number): Promise<AlimTalkTemplate>;
|
|
413
|
-
/**
|
|
414
|
-
* Get template usage statistics
|
|
415
|
-
*/
|
|
416
|
-
getUsageStats(templateId: string): TemplateUsageStats | null;
|
|
417
|
-
/**
|
|
418
|
-
* Update template usage statistics
|
|
419
|
-
*/
|
|
420
|
-
updateUsageStats(templateId: string, stats: {
|
|
421
|
-
sent?: number;
|
|
422
|
-
delivered?: number;
|
|
423
|
-
failed?: number;
|
|
424
|
-
}): void;
|
|
425
|
-
/**
|
|
426
|
-
* Get registry statistics
|
|
427
|
-
*/
|
|
428
|
-
getStats(): {
|
|
429
|
-
totalTemplates: number;
|
|
430
|
-
byProvider: Record<string, number>;
|
|
431
|
-
byCategory: Record<string, number>;
|
|
432
|
-
byStatus: Record<string, number>;
|
|
433
|
-
};
|
|
434
|
-
/**
|
|
435
|
-
* Export templates to JSON
|
|
436
|
-
*/
|
|
437
|
-
export(filters?: TemplateSearchFilters): string;
|
|
438
|
-
/**
|
|
439
|
-
* Import templates from JSON
|
|
440
|
-
*/
|
|
441
|
-
import(jsonData: string, options?: {
|
|
442
|
-
overwrite?: boolean;
|
|
443
|
-
}): Promise<{
|
|
444
|
-
imported: number;
|
|
445
|
-
skipped: number;
|
|
446
|
-
errors: string[];
|
|
447
|
-
}>;
|
|
448
|
-
/**
|
|
449
|
-
* Clear all templates (use with caution!)
|
|
450
|
-
*/
|
|
451
|
-
clear(): void;
|
|
452
|
-
/**
|
|
453
|
-
* Stop the registry and cleanup
|
|
454
|
-
*/
|
|
455
|
-
destroy(): void;
|
|
456
|
-
private updateIndexes;
|
|
457
|
-
private initializeVersionHistory;
|
|
458
|
-
private addVersionToHistory;
|
|
459
|
-
private initializeUsageStats;
|
|
460
|
-
private startAutoBackup;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
export { type AlimTalkTemplate, ButtonParser, TemplateBuilder, TemplateBuilders, type TemplateButton, TemplateCategory, type TemplateHistory, TemplateRegistry, type TemplateRegistryOptions, type TemplateSearchFilters, type TemplateSearchOptions, type TemplateSearchResult, TemplateService, TemplateStatus, TemplateType, type TemplateUsageStats, TemplateValidator, type TemplateVariable, type TemplateVersion, type ValidationResult, VariableParser };
|
|
5
|
+
export { TemplateBuilder, TemplateBuilders } from "./builder/template.builder";
|
|
6
|
+
export { interpolate } from "./interpolator";
|
|
7
|
+
export { ButtonParser } from "./parser/button.parser";
|
|
8
|
+
export { TemplateValidator, type ValidationResult } from "./parser/validator";
|
|
9
|
+
export { VariableParser } from "./parser/variable.parser";
|
|
10
|
+
export { type TemplateHistory, TemplateRegistry, type TemplateRegistryOptions, type TemplateSearchFilters, type TemplateSearchOptions, type TemplateSearchResult, type TemplateUsageStats, type TemplateVersion, } from "./registry/template.registry";
|
|
11
|
+
export { TemplateService } from "./service";
|
|
12
|
+
export { TemplateService as MockTemplateService } from "./services/template.service";
|
|
13
|
+
export type { AlimTalkTemplate, TemplateButton, TemplateVariable, } from "./types/template.types";
|
|
14
|
+
export { TemplateCategory, TemplateStatus, TemplateType, } from "./types/template.types";
|