@k-msg/provider 0.1.0 → 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 +3 -1
- package/dist/abstract/provider.base.d.ts +108 -0
- package/dist/adapters/aligo.adapter.d.ts +50 -0
- package/dist/adapters/iwinv.adapter.d.ts +111 -0
- package/dist/aligo/provider.d.ts +18 -0
- package/dist/config/provider-config-v2.d.ts +122 -0
- package/dist/contracts/provider.contract.d.ts +355 -0
- package/dist/contracts/sms.contract.d.ts +135 -0
- package/dist/index.d.ts +29 -1424
- package/dist/index.js +21 -2003
- package/dist/index.js.map +98 -1
- package/dist/index.mjs +25 -0
- package/dist/index.mjs.map +98 -0
- package/dist/interfaces/index.d.ts +14 -0
- package/dist/interfaces/plugin.d.ts +122 -0
- package/dist/interfaces/services.d.ts +222 -0
- package/dist/iwinv/contracts/account.contract.d.ts +11 -0
- package/dist/iwinv/contracts/analytics.contract.d.ts +16 -0
- package/dist/iwinv/contracts/channel.contract.d.ts +15 -0
- package/dist/iwinv/contracts/messaging.contract.d.ts +14 -0
- package/dist/iwinv/contracts/sms.contract.d.ts +33 -0
- package/dist/iwinv/contracts/template.contract.d.ts +18 -0
- package/dist/iwinv/index.d.ts +5 -0
- package/dist/iwinv/provider-multi.d.ts +116 -0
- package/dist/iwinv/provider-sms.d.ts +55 -0
- package/dist/iwinv/provider.d.ts +42 -0
- package/dist/iwinv/types/iwinv.d.ts +153 -0
- package/dist/middleware/index.d.ts +27 -0
- package/dist/mock/index.d.ts +1 -0
- package/dist/providers/mock/index.d.ts +1 -0
- package/dist/providers/mock/mock.provider.d.ts +22 -0
- package/dist/registry/index.d.ts +1 -0
- package/dist/registry/plugin-registry.d.ts +15 -0
- package/dist/services/provider.manager.d.ts +24 -0
- package/dist/services/provider.service.d.ts +49 -0
- package/dist/test-helpers.d.ts +110 -0
- package/dist/types/aligo.d.ts +69 -0
- package/dist/types/base.d.ts +172 -0
- package/dist/types/typed-templates.d.ts +199 -0
- package/dist/types/unified-config.d.ts +197 -0
- package/dist/types/unified-errors.d.ts +225 -0
- package/dist/utils/base-plugin.d.ts +35 -0
- package/dist/utils/index.d.ts +12 -0
- package/package.json +25 -14
- package/dist/index.cjs +0 -2061
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1425
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed Template System
|
|
3
|
+
* 템플릿별 강타입 시스템
|
|
4
|
+
*/
|
|
5
|
+
import type { StandardRequest, StandardResult } from "@k-msg/core";
|
|
6
|
+
export type MessageChannel = "alimtalk" | "sms" | "mms";
|
|
7
|
+
export interface VariableType {
|
|
8
|
+
string: string;
|
|
9
|
+
number: number;
|
|
10
|
+
boolean: boolean;
|
|
11
|
+
date: string;
|
|
12
|
+
phoneNumber: string;
|
|
13
|
+
url: string;
|
|
14
|
+
email: string;
|
|
15
|
+
}
|
|
16
|
+
export interface VariableDefinition<T extends keyof VariableType = keyof VariableType> {
|
|
17
|
+
type: T;
|
|
18
|
+
required: boolean;
|
|
19
|
+
description?: string;
|
|
20
|
+
validation?: {
|
|
21
|
+
pattern?: RegExp;
|
|
22
|
+
minLength?: number;
|
|
23
|
+
maxLength?: number;
|
|
24
|
+
min?: number;
|
|
25
|
+
max?: number;
|
|
26
|
+
};
|
|
27
|
+
defaultValue?: VariableType[T];
|
|
28
|
+
}
|
|
29
|
+
export interface TemplateSchema<V extends Record<string, VariableDefinition> = Record<string, VariableDefinition>> {
|
|
30
|
+
templateCode: string;
|
|
31
|
+
name: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
channels: MessageChannel[];
|
|
34
|
+
variables: V;
|
|
35
|
+
metadata?: {
|
|
36
|
+
category?: string;
|
|
37
|
+
version?: string;
|
|
38
|
+
author?: string;
|
|
39
|
+
createdAt?: string;
|
|
40
|
+
updatedAt?: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface TemplateRegistry {
|
|
44
|
+
WELCOME_001: TemplateSchema<{
|
|
45
|
+
name: VariableDefinition<"string">;
|
|
46
|
+
service: VariableDefinition<"string">;
|
|
47
|
+
date: VariableDefinition<"date">;
|
|
48
|
+
}>;
|
|
49
|
+
OTP_AUTH_001: TemplateSchema<{
|
|
50
|
+
code: VariableDefinition<"string">;
|
|
51
|
+
expiry: VariableDefinition<"string">;
|
|
52
|
+
serviceName: VariableDefinition<"string">;
|
|
53
|
+
}>;
|
|
54
|
+
ORDER_CONFIRM_001: TemplateSchema<{
|
|
55
|
+
orderNumber: VariableDefinition<"string">;
|
|
56
|
+
productName: VariableDefinition<"string">;
|
|
57
|
+
amount: VariableDefinition<"string">;
|
|
58
|
+
deliveryDate: VariableDefinition<"date">;
|
|
59
|
+
customerName: VariableDefinition<"string">;
|
|
60
|
+
}>;
|
|
61
|
+
PAYMENT_COMPLETE_001: TemplateSchema<{
|
|
62
|
+
amount: VariableDefinition<"string">;
|
|
63
|
+
paymentMethod: VariableDefinition<"string">;
|
|
64
|
+
transactionId: VariableDefinition<"string">;
|
|
65
|
+
customerName: VariableDefinition<"string">;
|
|
66
|
+
}>;
|
|
67
|
+
SMS_DIRECT: TemplateSchema<{
|
|
68
|
+
message: VariableDefinition<"string">;
|
|
69
|
+
}>;
|
|
70
|
+
LMS_DIRECT: TemplateSchema<{
|
|
71
|
+
subject: VariableDefinition<"string">;
|
|
72
|
+
message: VariableDefinition<"string">;
|
|
73
|
+
}>;
|
|
74
|
+
EMERGENCY_NOTIFICATION: TemplateSchema<{
|
|
75
|
+
alertType: VariableDefinition<"string">;
|
|
76
|
+
message: VariableDefinition<"string">;
|
|
77
|
+
contactInfo: VariableDefinition<"string">;
|
|
78
|
+
urgencyLevel: VariableDefinition<"string">;
|
|
79
|
+
}>;
|
|
80
|
+
}
|
|
81
|
+
export type TemplateCode = keyof TemplateRegistry;
|
|
82
|
+
export type ExtractVariables<T extends TemplateCode> = {
|
|
83
|
+
[K in keyof TemplateRegistry[T]["variables"]]: TemplateRegistry[T]["variables"][K] extends VariableDefinition<infer VT> ? VariableType[VT] : never;
|
|
84
|
+
};
|
|
85
|
+
export type ExtractRequiredVariables<T extends TemplateCode> = {
|
|
86
|
+
[K in keyof TemplateRegistry[T]["variables"] as TemplateRegistry[T]["variables"][K] extends {
|
|
87
|
+
required: true;
|
|
88
|
+
} ? K : never]: TemplateRegistry[T]["variables"][K] extends VariableDefinition<infer VT> ? VariableType[VT] : never;
|
|
89
|
+
};
|
|
90
|
+
export type ExtractOptionalVariables<T extends TemplateCode> = {
|
|
91
|
+
[K in keyof TemplateRegistry[T]["variables"] as TemplateRegistry[T]["variables"][K] extends {
|
|
92
|
+
required: false;
|
|
93
|
+
} ? K : never]?: TemplateRegistry[T]["variables"][K] extends VariableDefinition<infer VT> ? VariableType[VT] : never;
|
|
94
|
+
};
|
|
95
|
+
export type TemplateVariables<T extends TemplateCode> = ExtractRequiredVariables<T> & ExtractOptionalVariables<T>;
|
|
96
|
+
export type ExtractChannels<T extends TemplateCode> = TemplateRegistry[T]["channels"][number];
|
|
97
|
+
export interface TypedRequest<T extends TemplateCode> {
|
|
98
|
+
templateCode: T;
|
|
99
|
+
phoneNumber: string;
|
|
100
|
+
variables: TemplateVariables<T>;
|
|
101
|
+
options?: {
|
|
102
|
+
senderNumber?: string;
|
|
103
|
+
scheduledAt?: Date;
|
|
104
|
+
priority?: "high" | "normal" | "low";
|
|
105
|
+
channel?: ExtractChannels<T>;
|
|
106
|
+
subject?: string;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export interface TypedResult<T extends TemplateCode> {
|
|
110
|
+
messageId: string;
|
|
111
|
+
templateCode: T;
|
|
112
|
+
phoneNumber: string;
|
|
113
|
+
channel: ExtractChannels<T>;
|
|
114
|
+
status: "sent" | "pending" | "failed";
|
|
115
|
+
timestamp: Date;
|
|
116
|
+
variables: TemplateVariables<T>;
|
|
117
|
+
error?: {
|
|
118
|
+
code: string;
|
|
119
|
+
message: string;
|
|
120
|
+
retryable: boolean;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* TypedRequest를 StandardRequest로 변환하는 유틸리티 타입
|
|
125
|
+
*/
|
|
126
|
+
export type ToStandardRequest<T extends TemplateCode> = StandardRequest & {
|
|
127
|
+
templateCode: T;
|
|
128
|
+
variables: Record<string, string>;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* StandardResult를 TypedResult로 변환하는 유틸리티 타입
|
|
132
|
+
*/
|
|
133
|
+
export type ToTypedResult<T extends TemplateCode> = Omit<TypedResult<T>, "templateCode" | "channel"> & {
|
|
134
|
+
templateCode: T;
|
|
135
|
+
channel: ExtractChannels<T>;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* 타입 안전한 템플릿 변환 함수들
|
|
139
|
+
*/
|
|
140
|
+
export declare class TemplateTypeConverter {
|
|
141
|
+
/**
|
|
142
|
+
* TypedRequest를 StandardRequest로 변환
|
|
143
|
+
*/
|
|
144
|
+
static toStandardRequest<T extends TemplateCode>(typedRequest: TypedRequest<T>): StandardRequest;
|
|
145
|
+
/**
|
|
146
|
+
* StandardResult를 TypedResult로 변환
|
|
147
|
+
*/
|
|
148
|
+
static toTypedResult<T extends TemplateCode>(standardResult: StandardResult, templateCode: T, originalVariables: TemplateVariables<T>): TypedResult<T>;
|
|
149
|
+
/**
|
|
150
|
+
* 템플릿 코드로부터 채널 추론
|
|
151
|
+
*/
|
|
152
|
+
private static inferChannel;
|
|
153
|
+
/**
|
|
154
|
+
* StandardStatus를 TypedResult 상태로 매핑
|
|
155
|
+
*/
|
|
156
|
+
private static mapStandardStatus;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 타입 안전한 Provider 래퍼
|
|
160
|
+
* 기존 Provider를 감싸서 타입 안전성을 제공
|
|
161
|
+
*/
|
|
162
|
+
export declare class TypedProvider {
|
|
163
|
+
private provider;
|
|
164
|
+
constructor(provider: import("@k-msg/core").BaseProvider);
|
|
165
|
+
/**
|
|
166
|
+
* 타입 안전한 메시지 전송
|
|
167
|
+
*/
|
|
168
|
+
send<T extends TemplateCode>(request: TypedRequest<T>): Promise<TypedResult<T>>;
|
|
169
|
+
/**
|
|
170
|
+
* 대량 전송 (타입 안전)
|
|
171
|
+
*/
|
|
172
|
+
sendBulk<T extends TemplateCode>(requests: TypedRequest<T>[], options?: {
|
|
173
|
+
batchSize?: number;
|
|
174
|
+
concurrency?: number;
|
|
175
|
+
failFast?: boolean;
|
|
176
|
+
}): Promise<TypedResult<T>[]>;
|
|
177
|
+
/**
|
|
178
|
+
* 상태 조회 (타입 안전하지 않은 부분 - messageId만 필요)
|
|
179
|
+
*/
|
|
180
|
+
getStatus(messageId: string): Promise<import("@k-msg/core").DeliveryStatus>;
|
|
181
|
+
/**
|
|
182
|
+
* 기본 Provider 접근 (고급 사용자용)
|
|
183
|
+
*/
|
|
184
|
+
getUnderlyingProvider(): import("@k-msg/core").BaseProvider<StandardRequest, StandardResult>;
|
|
185
|
+
}
|
|
186
|
+
export declare const TEMPLATE_REGISTRY: TemplateRegistry;
|
|
187
|
+
export declare class TemplateValidator {
|
|
188
|
+
static validateVariables<T extends TemplateCode>(templateCode: T, variables: Record<string, any>): ValidationResult<TemplateVariables<T>>;
|
|
189
|
+
static validateChannel<T extends TemplateCode>(templateCode: T, channel: string): boolean;
|
|
190
|
+
private static validateType;
|
|
191
|
+
private static validateValue;
|
|
192
|
+
private static applyDefaults;
|
|
193
|
+
}
|
|
194
|
+
export interface ValidationResult<T> {
|
|
195
|
+
isValid: boolean;
|
|
196
|
+
errors: string[];
|
|
197
|
+
warnings: string[];
|
|
198
|
+
validatedVariables: T;
|
|
199
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Configuration Types
|
|
3
|
+
* 통합된 설정 타입 시스템
|
|
4
|
+
*/
|
|
5
|
+
import type { ProviderConfig } from "@k-msg/core";
|
|
6
|
+
/**
|
|
7
|
+
* 환경별 설정
|
|
8
|
+
*/
|
|
9
|
+
export type Environment = "development" | "staging" | "production";
|
|
10
|
+
/**
|
|
11
|
+
* 로그 레벨
|
|
12
|
+
*/
|
|
13
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
14
|
+
/**
|
|
15
|
+
* 공통 설정 인터페이스
|
|
16
|
+
*/
|
|
17
|
+
export interface BaseConfig {
|
|
18
|
+
environment: Environment;
|
|
19
|
+
debug?: boolean;
|
|
20
|
+
logLevel?: LogLevel;
|
|
21
|
+
timeout?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* IWINV 기본 설정 (모든 IWINV 관련 설정의 기준)
|
|
25
|
+
*/
|
|
26
|
+
export interface IWINVBaseConfig extends ProviderConfig, BaseConfig {
|
|
27
|
+
apiKey: string;
|
|
28
|
+
baseUrl: string;
|
|
29
|
+
userId?: string;
|
|
30
|
+
senderNumber?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* AlimTalk 특화 설정
|
|
34
|
+
*/
|
|
35
|
+
export interface AlimTalkConfig extends IWINVBaseConfig {
|
|
36
|
+
type: "alimtalk";
|
|
37
|
+
senderKey?: string;
|
|
38
|
+
fallbackSettings?: {
|
|
39
|
+
enableSMSFallback: boolean;
|
|
40
|
+
fallbackSenderNumber?: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* SMS 특화 설정
|
|
45
|
+
*/
|
|
46
|
+
export interface SMSConfig extends IWINVBaseConfig {
|
|
47
|
+
type: "sms";
|
|
48
|
+
defaultMsgType?: "SMS" | "LMS" | "MMS";
|
|
49
|
+
autoDetectMessageType?: boolean;
|
|
50
|
+
maxSMSLength?: number;
|
|
51
|
+
maxLMSLength?: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* MMS 특화 설정
|
|
55
|
+
*/
|
|
56
|
+
export interface MMSConfig extends IWINVBaseConfig {
|
|
57
|
+
type: "mms";
|
|
58
|
+
maxFileSize?: number;
|
|
59
|
+
allowedMimeTypes?: string[];
|
|
60
|
+
imageOptimization?: {
|
|
61
|
+
enabled: boolean;
|
|
62
|
+
maxWidth?: number;
|
|
63
|
+
maxHeight?: number;
|
|
64
|
+
quality?: number;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 채널별 설정 유니온
|
|
69
|
+
*/
|
|
70
|
+
export type ChannelConfig = AlimTalkConfig | SMSConfig | MMSConfig;
|
|
71
|
+
/**
|
|
72
|
+
* 다중 채널 지원 설정
|
|
73
|
+
*/
|
|
74
|
+
export interface MultiChannelConfig {
|
|
75
|
+
channels: ChannelConfig[];
|
|
76
|
+
defaultChannel: "alimtalk" | "sms" | "mms";
|
|
77
|
+
fallbackChain?: ("alimtalk" | "sms" | "mms")[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 성능 및 안정성 설정
|
|
81
|
+
*/
|
|
82
|
+
export interface PerformanceConfig {
|
|
83
|
+
rateLimiting?: {
|
|
84
|
+
requestsPerSecond: number;
|
|
85
|
+
burstSize: number;
|
|
86
|
+
strategy: "token_bucket" | "sliding_window";
|
|
87
|
+
};
|
|
88
|
+
circuitBreaker?: {
|
|
89
|
+
enabled: boolean;
|
|
90
|
+
failureThreshold: number;
|
|
91
|
+
timeoutMs: number;
|
|
92
|
+
retryDelayMs: number;
|
|
93
|
+
};
|
|
94
|
+
caching?: {
|
|
95
|
+
enabled: boolean;
|
|
96
|
+
ttl: number;
|
|
97
|
+
maxSize: number;
|
|
98
|
+
};
|
|
99
|
+
connectionPool?: {
|
|
100
|
+
maxConnections: number;
|
|
101
|
+
idleTimeout: number;
|
|
102
|
+
connectionTimeout: number;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 모니터링 설정
|
|
107
|
+
*/
|
|
108
|
+
export interface MonitoringConfig {
|
|
109
|
+
enableMetrics: boolean;
|
|
110
|
+
enableTracing: boolean;
|
|
111
|
+
enableHealthChecks: boolean;
|
|
112
|
+
metricsInterval?: number;
|
|
113
|
+
healthCheckInterval?: number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 완전한 통합 설정
|
|
117
|
+
*/
|
|
118
|
+
export interface UnifiedProviderConfig extends BaseConfig {
|
|
119
|
+
provider: {
|
|
120
|
+
type: "iwinv";
|
|
121
|
+
apiKey: string;
|
|
122
|
+
baseUrl: string;
|
|
123
|
+
};
|
|
124
|
+
channels?: {
|
|
125
|
+
alimtalk?: Omit<AlimTalkConfig, "apiKey" | "baseUrl" | "type">;
|
|
126
|
+
sms?: Omit<SMSConfig, "apiKey" | "baseUrl" | "type">;
|
|
127
|
+
mms?: Omit<MMSConfig, "apiKey" | "baseUrl" | "type">;
|
|
128
|
+
};
|
|
129
|
+
performance?: PerformanceConfig;
|
|
130
|
+
monitoring?: MonitoringConfig;
|
|
131
|
+
multiChannel?: {
|
|
132
|
+
defaultChannel: "alimtalk" | "sms" | "mms";
|
|
133
|
+
fallbackChain: ("alimtalk" | "sms" | "mms")[];
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 기본 설정 검증
|
|
138
|
+
*/
|
|
139
|
+
export declare function isValidBaseConfig(config: unknown): config is BaseConfig;
|
|
140
|
+
/**
|
|
141
|
+
* IWINV 기본 설정 검증
|
|
142
|
+
*/
|
|
143
|
+
export declare function isValidIWINVBaseConfig(config: unknown): config is IWINVBaseConfig;
|
|
144
|
+
/**
|
|
145
|
+
* AlimTalk 설정 검증
|
|
146
|
+
*/
|
|
147
|
+
export declare function isValidAlimTalkConfig(config: unknown): config is AlimTalkConfig;
|
|
148
|
+
/**
|
|
149
|
+
* SMS 설정 검증
|
|
150
|
+
*/
|
|
151
|
+
export declare function isValidSMSConfig(config: unknown): config is SMSConfig;
|
|
152
|
+
/**
|
|
153
|
+
* MMS 설정 검증
|
|
154
|
+
*/
|
|
155
|
+
export declare function isValidMMSConfig(config: unknown): config is MMSConfig;
|
|
156
|
+
/**
|
|
157
|
+
* 통합 설정 검증
|
|
158
|
+
*/
|
|
159
|
+
export declare function isValidUnifiedConfig(config: unknown): config is UnifiedProviderConfig;
|
|
160
|
+
/**
|
|
161
|
+
* 타입 안전한 설정 빌더
|
|
162
|
+
*/
|
|
163
|
+
export declare class UnifiedConfigBuilder {
|
|
164
|
+
private config;
|
|
165
|
+
static create(): UnifiedConfigBuilder;
|
|
166
|
+
environment(env: Environment): this;
|
|
167
|
+
provider(apiKey: string, baseUrl: string): this;
|
|
168
|
+
alimtalk(config: Omit<AlimTalkConfig, "apiKey" | "baseUrl" | "type">): this;
|
|
169
|
+
sms(config: Omit<SMSConfig, "apiKey" | "baseUrl" | "type">): this;
|
|
170
|
+
mms(config: Omit<MMSConfig, "apiKey" | "baseUrl" | "type">): this;
|
|
171
|
+
performance(config: PerformanceConfig): this;
|
|
172
|
+
monitoring(config: MonitoringConfig): this;
|
|
173
|
+
multiChannel(defaultChannel: "alimtalk" | "sms" | "mms", fallbackChain: ("alimtalk" | "sms" | "mms")[]): this;
|
|
174
|
+
build(): UnifiedProviderConfig;
|
|
175
|
+
}
|
|
176
|
+
export declare class UnifiedConfigFactory {
|
|
177
|
+
/**
|
|
178
|
+
* 개발 환경 기본 설정
|
|
179
|
+
*/
|
|
180
|
+
static development(apiKey: string, baseUrl?: string): UnifiedProviderConfig;
|
|
181
|
+
/**
|
|
182
|
+
* 프로덕션 환경 기본 설정
|
|
183
|
+
*/
|
|
184
|
+
static production(apiKey: string, baseUrl?: string): UnifiedProviderConfig;
|
|
185
|
+
/**
|
|
186
|
+
* 환경 변수에서 설정 생성
|
|
187
|
+
*/
|
|
188
|
+
static fromEnvironment(): UnifiedProviderConfig;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 통합 설정을 레거시 IWINVConfig로 변환
|
|
192
|
+
*/
|
|
193
|
+
export declare function toLegacyIWINVConfig(config: UnifiedProviderConfig): IWINVBaseConfig;
|
|
194
|
+
/**
|
|
195
|
+
* 레거시 IWINVConfig를 통합 설정으로 변환
|
|
196
|
+
*/
|
|
197
|
+
export declare function fromLegacyIWINVConfig(legacyConfig: IWINVBaseConfig): UnifiedProviderConfig;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Error System
|
|
3
|
+
* 통합 에러 처리 시스템
|
|
4
|
+
*/
|
|
5
|
+
type StandardError = any;
|
|
6
|
+
/**
|
|
7
|
+
* 에러 카테고리
|
|
8
|
+
*/
|
|
9
|
+
export declare enum ErrorCategory {
|
|
10
|
+
SYSTEM = "SYSTEM",
|
|
11
|
+
NETWORK = "NETWORK",
|
|
12
|
+
CONFIGURATION = "CONFIGURATION",
|
|
13
|
+
AUTHENTICATION = "AUTHENTICATION",
|
|
14
|
+
AUTHORIZATION = "AUTHORIZATION",
|
|
15
|
+
VALIDATION = "VALIDATION",
|
|
16
|
+
BUSINESS_LOGIC = "BUSINESS_LOGIC",
|
|
17
|
+
PROVIDER = "PROVIDER",
|
|
18
|
+
TEMPLATE = "TEMPLATE",
|
|
19
|
+
RATE_LIMIT = "RATE_LIMIT",
|
|
20
|
+
UNKNOWN = "UNKNOWN"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 에러 심각도
|
|
24
|
+
*/
|
|
25
|
+
export declare enum ErrorSeverity {
|
|
26
|
+
LOW = "LOW",// 로깅만, 재시도 불필요
|
|
27
|
+
MEDIUM = "MEDIUM",// 경고, 재시도 가능
|
|
28
|
+
HIGH = "HIGH",// 에러, 재시도 필요
|
|
29
|
+
CRITICAL = "CRITICAL"
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 기본 에러 정보
|
|
33
|
+
*/
|
|
34
|
+
export interface BaseErrorInfo {
|
|
35
|
+
code: string;
|
|
36
|
+
message: string;
|
|
37
|
+
category: ErrorCategory;
|
|
38
|
+
severity: ErrorSeverity;
|
|
39
|
+
retryable: boolean;
|
|
40
|
+
timestamp: Date;
|
|
41
|
+
context?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Provider 특화 에러 정보
|
|
45
|
+
*/
|
|
46
|
+
export interface ProviderErrorInfo extends BaseErrorInfo {
|
|
47
|
+
provider: string;
|
|
48
|
+
originalCode?: string | number;
|
|
49
|
+
originalMessage?: string;
|
|
50
|
+
endpoint?: string;
|
|
51
|
+
requestId?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 템플릿 관련 에러 정보
|
|
55
|
+
*/
|
|
56
|
+
export interface TemplateErrorInfo extends BaseErrorInfo {
|
|
57
|
+
templateCode?: string;
|
|
58
|
+
templateName?: string;
|
|
59
|
+
validationErrors?: string[];
|
|
60
|
+
missingVariables?: string[];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 네트워크 관련 에러 정보
|
|
64
|
+
*/
|
|
65
|
+
export interface NetworkErrorInfo extends BaseErrorInfo {
|
|
66
|
+
url?: string;
|
|
67
|
+
method?: string;
|
|
68
|
+
statusCode?: number;
|
|
69
|
+
timeout?: boolean;
|
|
70
|
+
connectionRefused?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 통합 에러 타입
|
|
74
|
+
*/
|
|
75
|
+
export type UnifiedErrorInfo = ProviderErrorInfo | TemplateErrorInfo | NetworkErrorInfo | BaseErrorInfo;
|
|
76
|
+
/**
|
|
77
|
+
* 기본 통합 에러 클래스
|
|
78
|
+
*/
|
|
79
|
+
export declare class UnifiedError extends Error {
|
|
80
|
+
readonly category: ErrorCategory;
|
|
81
|
+
readonly severity: ErrorSeverity;
|
|
82
|
+
readonly retryable: boolean;
|
|
83
|
+
readonly timestamp: Date;
|
|
84
|
+
readonly context: Record<string, unknown>;
|
|
85
|
+
constructor(info: BaseErrorInfo);
|
|
86
|
+
/**
|
|
87
|
+
* StandardError 형식으로 변환
|
|
88
|
+
*/
|
|
89
|
+
toStandardError(): StandardError;
|
|
90
|
+
/**
|
|
91
|
+
* 에러 카테고리를 StandardErrorCode로 매핑
|
|
92
|
+
*/
|
|
93
|
+
private mapToStandardErrorCode;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Provider 에러 클래스
|
|
97
|
+
*/
|
|
98
|
+
export declare class ProviderError extends UnifiedError {
|
|
99
|
+
readonly provider: string;
|
|
100
|
+
readonly originalCode?: string | number;
|
|
101
|
+
readonly originalMessage?: string;
|
|
102
|
+
readonly endpoint?: string;
|
|
103
|
+
readonly requestId?: string;
|
|
104
|
+
constructor(info: ProviderErrorInfo);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 템플릿 에러 클래스
|
|
108
|
+
*/
|
|
109
|
+
export declare class TemplateError extends UnifiedError {
|
|
110
|
+
readonly templateCode?: string;
|
|
111
|
+
readonly templateName?: string;
|
|
112
|
+
readonly validationErrors?: string[];
|
|
113
|
+
readonly missingVariables?: string[];
|
|
114
|
+
constructor(info: TemplateErrorInfo);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 네트워크 에러 클래스
|
|
118
|
+
*/
|
|
119
|
+
export declare class NetworkError extends UnifiedError {
|
|
120
|
+
readonly url?: string;
|
|
121
|
+
readonly method?: string;
|
|
122
|
+
readonly statusCode?: number;
|
|
123
|
+
readonly timeout?: boolean;
|
|
124
|
+
readonly connectionRefused?: boolean;
|
|
125
|
+
constructor(info: NetworkErrorInfo);
|
|
126
|
+
}
|
|
127
|
+
export declare class ErrorFactory {
|
|
128
|
+
/**
|
|
129
|
+
* Provider 에러 생성
|
|
130
|
+
*/
|
|
131
|
+
static createProviderError(params: {
|
|
132
|
+
provider: string;
|
|
133
|
+
message: string;
|
|
134
|
+
originalCode?: string | number;
|
|
135
|
+
originalMessage?: string;
|
|
136
|
+
endpoint?: string;
|
|
137
|
+
retryable?: boolean;
|
|
138
|
+
context?: Record<string, unknown>;
|
|
139
|
+
}): ProviderError;
|
|
140
|
+
/**
|
|
141
|
+
* 템플릿 에러 생성
|
|
142
|
+
*/
|
|
143
|
+
static createTemplateError(params: {
|
|
144
|
+
templateCode?: string;
|
|
145
|
+
message: string;
|
|
146
|
+
validationErrors?: string[];
|
|
147
|
+
missingVariables?: string[];
|
|
148
|
+
retryable?: boolean;
|
|
149
|
+
}): TemplateError;
|
|
150
|
+
/**
|
|
151
|
+
* 네트워크 에러 생성
|
|
152
|
+
*/
|
|
153
|
+
static createNetworkError(params: {
|
|
154
|
+
url?: string;
|
|
155
|
+
method?: string;
|
|
156
|
+
statusCode?: number;
|
|
157
|
+
message: string;
|
|
158
|
+
timeout?: boolean;
|
|
159
|
+
connectionRefused?: boolean;
|
|
160
|
+
}): NetworkError;
|
|
161
|
+
/**
|
|
162
|
+
* 인증 에러 생성
|
|
163
|
+
*/
|
|
164
|
+
static createAuthenticationError(message?: string): UnifiedError;
|
|
165
|
+
/**
|
|
166
|
+
* 검증 에러 생성
|
|
167
|
+
*/
|
|
168
|
+
static createValidationError(message: string, context?: Record<string, unknown>): UnifiedError;
|
|
169
|
+
/**
|
|
170
|
+
* 요율 제한 에러 생성
|
|
171
|
+
*/
|
|
172
|
+
static createRateLimitError(message?: string, retryAfter?: number): UnifiedError;
|
|
173
|
+
}
|
|
174
|
+
export declare class ErrorConverter {
|
|
175
|
+
/**
|
|
176
|
+
* 임의의 에러를 UnifiedError로 변환
|
|
177
|
+
*/
|
|
178
|
+
static toUnifiedError(error: unknown, context?: Record<string, unknown>): UnifiedError;
|
|
179
|
+
/**
|
|
180
|
+
* IWINV 에러를 ProviderError로 변환
|
|
181
|
+
*/
|
|
182
|
+
static fromIWINVError(error: {
|
|
183
|
+
code: number;
|
|
184
|
+
message: string;
|
|
185
|
+
status?: number;
|
|
186
|
+
data?: unknown;
|
|
187
|
+
}): ProviderError;
|
|
188
|
+
/**
|
|
189
|
+
* HTTP 에러를 NetworkError로 변환
|
|
190
|
+
*/
|
|
191
|
+
static fromHttpError(params: {
|
|
192
|
+
url: string;
|
|
193
|
+
method: string;
|
|
194
|
+
statusCode: number;
|
|
195
|
+
statusText?: string;
|
|
196
|
+
responseBody?: unknown;
|
|
197
|
+
}): NetworkError;
|
|
198
|
+
}
|
|
199
|
+
export declare function isUnifiedError(error: unknown): error is UnifiedError;
|
|
200
|
+
export declare function isProviderError(error: unknown): error is ProviderError;
|
|
201
|
+
export declare function isTemplateError(error: unknown): error is TemplateError;
|
|
202
|
+
export declare function isNetworkError(error: unknown): error is NetworkError;
|
|
203
|
+
export declare function isRetryableError(error: unknown): boolean;
|
|
204
|
+
export interface ErrorStats {
|
|
205
|
+
total: number;
|
|
206
|
+
byCategory: Record<ErrorCategory, number>;
|
|
207
|
+
bySeverity: Record<ErrorSeverity, number>;
|
|
208
|
+
retryable: number;
|
|
209
|
+
nonRetryable: number;
|
|
210
|
+
}
|
|
211
|
+
export declare class ErrorAnalyzer {
|
|
212
|
+
/**
|
|
213
|
+
* 에러 목록 통계 분석
|
|
214
|
+
*/
|
|
215
|
+
static analyze(errors: UnifiedError[]): ErrorStats;
|
|
216
|
+
/**
|
|
217
|
+
* 중요 에러 필터링
|
|
218
|
+
*/
|
|
219
|
+
static getCriticalErrors(errors: UnifiedError[]): UnifiedError[];
|
|
220
|
+
/**
|
|
221
|
+
* 재시도 가능한 에러 필터링
|
|
222
|
+
*/
|
|
223
|
+
static getRetryableErrors(errors: UnifiedError[]): UnifiedError[];
|
|
224
|
+
}
|
|
225
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PluginContext, ProviderCapabilities, ProviderImplementation, ProviderMetadata, ProviderMiddleware, ProviderPlugin } from "../interfaces";
|
|
2
|
+
export declare abstract class BasePlugin implements ProviderPlugin {
|
|
3
|
+
abstract readonly metadata: ProviderMetadata;
|
|
4
|
+
abstract readonly capabilities: ProviderCapabilities;
|
|
5
|
+
protected context: PluginContext;
|
|
6
|
+
middleware: ProviderMiddleware[];
|
|
7
|
+
initialize(context: PluginContext): Promise<void>;
|
|
8
|
+
destroy(): Promise<void>;
|
|
9
|
+
abstract getImplementation(): ProviderImplementation;
|
|
10
|
+
protected executeMiddleware(phase: "pre" | "post" | "error", context: any, error?: Error): Promise<void>;
|
|
11
|
+
protected createMiddlewareContext(request: any, metadata?: Record<string, any>): {
|
|
12
|
+
request: any;
|
|
13
|
+
response: any;
|
|
14
|
+
metadata: {
|
|
15
|
+
pluginName: string;
|
|
16
|
+
pluginVersion: string;
|
|
17
|
+
};
|
|
18
|
+
startTime: number;
|
|
19
|
+
};
|
|
20
|
+
protected validateConfig(config: any, required: string[]): void;
|
|
21
|
+
protected makeRequest(url: string, options: RequestInit, metadata?: Record<string, any>): Promise<Response>;
|
|
22
|
+
/**
|
|
23
|
+
* Make HTTP request and parse JSON response
|
|
24
|
+
* Subclasses should use their specific response adapters to transform the result
|
|
25
|
+
*/
|
|
26
|
+
protected makeJSONRequest<T = any>(url: string, options: RequestInit, metadata?: Record<string, any>): Promise<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Helper method for logging provider-specific operations
|
|
29
|
+
*/
|
|
30
|
+
protected logOperation(operation: string, data?: any): void;
|
|
31
|
+
/**
|
|
32
|
+
* Helper method for logging provider-specific errors
|
|
33
|
+
*/
|
|
34
|
+
protected logError(operation: string, error: any, data?: any): void;
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./base-plugin";
|
|
2
|
+
export declare function normalizePhoneNumber(phone: string): string;
|
|
3
|
+
export declare function validatePhoneNumber(phone: string): boolean;
|
|
4
|
+
export declare function formatDateTime(date: Date): string;
|
|
5
|
+
export declare function parseTemplate(template: string, variables: Record<string, string>): string;
|
|
6
|
+
export declare function extractVariables(template: string): string[];
|
|
7
|
+
export declare function delay(ms: number): Promise<void>;
|
|
8
|
+
export declare function retry<T>(fn: () => Promise<T>, options: {
|
|
9
|
+
maxRetries: number;
|
|
10
|
+
delay: number;
|
|
11
|
+
backoff?: "linear" | "exponential";
|
|
12
|
+
}): Promise<T>;
|