Skip to content

@k-msg/template

Template management and validation system for the K-Message platform.

Terminal window
npm install @k-msg/template @k-msg/core
# or
bun add @k-msg/template @k-msg/core
  • Template Engine: Comprehensive template management system
  • Variable Parsing: Automatic template variable extraction and validation
  • Template Validation: Built-in validation for template content and structure
  • Template Registry: Centralized template storage and retrieval
  • Template Builder: Dynamic template creation and modification
  • Works in Edge runtimes without nodejs_compat (no runtime dependency on Node built-ins).
import { interpolate } from '@k-msg/template';
const text = interpolate('[MyApp] Your verification code is #{code}.', {
code: '123456',
});
console.log(text); // "[MyApp] Your verification code is 123456."
import { TemplateRegistry } from '@k-msg/template';
const registry = new TemplateRegistry();
// Register a template
await registry.register({
id: 'otp-basic',
name: 'Basic OTP Template',
content: '[#{service}] Verification code: #{code}',
category: 'AUTHENTICATION'
});
// Search templates
const templates = await registry.search({
category: 'AUTHENTICATION',
status: 'ACTIVE'
});

Provider-backed TemplateService (Optional)

Section titled “Provider-backed TemplateService (Optional)”

TemplateService is a small helper around the TemplateProvider interface from @k-msg/core.

import { TemplateService } from '@k-msg/template';
import type { TemplateProvider } from '@k-msg/core';
const provider: TemplateProvider = /* your implementation */;
const templateService = new TemplateService(provider);
await templateService.create({
code: 'OTP_001',
name: 'OTP Verification',
content: '[MyApp] Your verification code is #{code}.',
category: 'AUTHENTICATION'
});

MIT