@k-msg/provider 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.
Files changed (47) hide show
  1. package/README.md +3 -1
  2. package/dist/abstract/provider.base.d.ts +108 -0
  3. package/dist/adapters/aligo.adapter.d.ts +50 -0
  4. package/dist/adapters/iwinv.adapter.d.ts +111 -0
  5. package/dist/aligo/provider.d.ts +18 -0
  6. package/dist/config/provider-config-v2.d.ts +122 -0
  7. package/dist/contracts/provider.contract.d.ts +355 -0
  8. package/dist/contracts/sms.contract.d.ts +135 -0
  9. package/dist/index.d.ts +29 -1424
  10. package/dist/index.js +21 -2003
  11. package/dist/index.js.map +98 -1
  12. package/dist/index.mjs +25 -0
  13. package/dist/index.mjs.map +98 -0
  14. package/dist/interfaces/index.d.ts +14 -0
  15. package/dist/interfaces/plugin.d.ts +122 -0
  16. package/dist/interfaces/services.d.ts +222 -0
  17. package/dist/iwinv/contracts/account.contract.d.ts +11 -0
  18. package/dist/iwinv/contracts/analytics.contract.d.ts +16 -0
  19. package/dist/iwinv/contracts/channel.contract.d.ts +15 -0
  20. package/dist/iwinv/contracts/messaging.contract.d.ts +14 -0
  21. package/dist/iwinv/contracts/sms.contract.d.ts +33 -0
  22. package/dist/iwinv/contracts/template.contract.d.ts +18 -0
  23. package/dist/iwinv/index.d.ts +5 -0
  24. package/dist/iwinv/provider-multi.d.ts +116 -0
  25. package/dist/iwinv/provider-sms.d.ts +55 -0
  26. package/dist/iwinv/provider.d.ts +42 -0
  27. package/dist/iwinv/types/iwinv.d.ts +153 -0
  28. package/dist/middleware/index.d.ts +27 -0
  29. package/dist/mock/index.d.ts +1 -0
  30. package/dist/providers/mock/index.d.ts +1 -0
  31. package/dist/providers/mock/mock.provider.d.ts +22 -0
  32. package/dist/registry/index.d.ts +1 -0
  33. package/dist/registry/plugin-registry.d.ts +15 -0
  34. package/dist/services/provider.manager.d.ts +24 -0
  35. package/dist/services/provider.service.d.ts +49 -0
  36. package/dist/test-helpers.d.ts +110 -0
  37. package/dist/types/aligo.d.ts +69 -0
  38. package/dist/types/base.d.ts +172 -0
  39. package/dist/types/typed-templates.d.ts +199 -0
  40. package/dist/types/unified-config.d.ts +197 -0
  41. package/dist/types/unified-errors.d.ts +225 -0
  42. package/dist/utils/base-plugin.d.ts +35 -0
  43. package/dist/utils/index.d.ts +12 -0
  44. package/package.json +25 -14
  45. package/dist/index.cjs +0 -2061
  46. package/dist/index.cjs.map +0 -1
  47. package/dist/index.d.cts +0 -1425
package/README.md CHANGED
@@ -24,7 +24,9 @@ bun add @k-msg/provider @k-msg/core
24
24
  ## Built-in Providers
25
25
 
26
26
  ### IWINV Provider
27
+
27
28
  Production-ready AlimTalk provider with full feature support:
29
+
28
30
  - ✅ AlimTalk message sending with variable substitution
29
31
  - ✅ SMS/LMS fallback for failed AlimTalk messages
30
32
  - ✅ Template management (create, update, delete, list)
@@ -137,4 +139,4 @@ class CustomMessagingService implements MessagingService {
137
139
 
138
140
  ## License
139
141
 
140
- MIT
142
+ MIT
@@ -0,0 +1,108 @@
1
+ import type { ConfigurationSchema, DeliveryStatus } from "@k-msg/core";
2
+ import type { AccountContract, AlimTalkProvider, AlimTalkRequest, AlimTalkResult, AnalyticsContract, ChannelContract, MessagingContract, ProviderCapabilities, ProviderConfiguration, TemplateContract } from "../contracts/provider.contract";
3
+ export declare abstract class BaseAlimTalkProvider implements AlimTalkProvider {
4
+ abstract readonly id: string;
5
+ abstract readonly name: string;
6
+ readonly type: "messaging";
7
+ abstract readonly version: string;
8
+ abstract readonly capabilities: ProviderCapabilities;
9
+ protected config: Record<string, unknown>;
10
+ protected isConfigured: boolean;
11
+ abstract templates: TemplateContract;
12
+ abstract channels: ChannelContract;
13
+ abstract messaging: MessagingContract;
14
+ abstract analytics: AnalyticsContract;
15
+ abstract account: AccountContract;
16
+ constructor(config?: Record<string, unknown>);
17
+ /**
18
+ * Configure the provider with necessary credentials and settings
19
+ */
20
+ configure(config: Record<string, unknown>): void;
21
+ abstract send<T extends AlimTalkRequest = AlimTalkRequest, R extends AlimTalkResult = AlimTalkResult>(request: T): Promise<R>;
22
+ abstract getStatus(requestId: string): Promise<DeliveryStatus>;
23
+ abstract cancel?(requestId: string): Promise<boolean>;
24
+ abstract getSupportedFeatures(): string[];
25
+ abstract getConfigurationSchema(): ConfigurationSchema;
26
+ abstract getProviderConfiguration(): ProviderConfiguration;
27
+ /**
28
+ * Validate the provided configuration
29
+ */
30
+ protected validateConfiguration(config: Record<string, unknown>): void;
31
+ private validateFieldValue;
32
+ /**
33
+ * Called after configuration is set
34
+ */
35
+ protected onConfigured(): void;
36
+ /**
37
+ * Check if the provider is properly configured
38
+ */
39
+ isReady(): boolean;
40
+ /**
41
+ * Get configuration value
42
+ */
43
+ protected getConfig<T = unknown>(key: string): T;
44
+ /**
45
+ * Check if a configuration key exists
46
+ */
47
+ protected hasConfig(key: string): boolean;
48
+ getCapabilities(): ProviderCapabilities;
49
+ /**
50
+ * Perform health check on the provider
51
+ */
52
+ healthCheck(): Promise<{
53
+ healthy: boolean;
54
+ issues: string[];
55
+ latency?: number;
56
+ }>;
57
+ /**
58
+ * Test basic connectivity to the provider
59
+ */
60
+ protected abstract testConnectivity(): Promise<void>;
61
+ /**
62
+ * Test authentication with the provider
63
+ */
64
+ protected abstract testAuthentication(): Promise<void>;
65
+ /**
66
+ * Get provider information
67
+ */
68
+ getInfo(): {
69
+ id: string;
70
+ name: string;
71
+ version: string;
72
+ capabilities: ProviderCapabilities;
73
+ configured: boolean;
74
+ };
75
+ /**
76
+ * Get provider version
77
+ */
78
+ protected abstract getVersion(): string;
79
+ /**
80
+ * Cleanup resources when provider is destroyed
81
+ */
82
+ destroy(): void;
83
+ /**
84
+ * Called when provider is being destroyed
85
+ */
86
+ protected onDestroy(): void;
87
+ /**
88
+ * Create standardized error
89
+ */
90
+ protected createError(code: string, message: string, details?: Record<string, unknown>): Error;
91
+ /**
92
+ * Log provider activity
93
+ */
94
+ protected log(level: "info" | "warn" | "error", message: string, data?: unknown): void;
95
+ /**
96
+ * Handle rate limiting
97
+ */
98
+ protected handleRateLimit(operation: string): Promise<void>;
99
+ /**
100
+ * Retry mechanism for failed operations
101
+ */
102
+ protected withRetry<T>(operation: () => Promise<T>, options?: {
103
+ maxRetries?: number;
104
+ initialDelay?: number;
105
+ maxDelay?: number;
106
+ backoffFactor?: number;
107
+ }): Promise<T>;
108
+ }
@@ -0,0 +1,50 @@
1
+ import { BaseProviderAdapter, KMsgError, type Provider, type Result, type SendOptions, type SendResult, type StandardError, type StandardRequest, type StandardResult, type Template, type TemplateProvider } from "@k-msg/core";
2
+ import type { AligoConfig, AligoResponse } from "../types/aligo";
3
+ export declare class AligoAdapter extends BaseProviderAdapter implements Provider, TemplateProvider {
4
+ protected readonly aligoConfig: AligoConfig;
5
+ private static readonly directTemplates;
6
+ readonly id = "aligo";
7
+ readonly name = "Aligo Smart SMS";
8
+ private readonly SMS_HOST;
9
+ private readonly ALIMTALK_HOST;
10
+ constructor(aligoConfig: AligoConfig);
11
+ send(params: SendOptions): Promise<Result<SendResult, KMsgError>>;
12
+ sendStandard(request: StandardRequest): Promise<StandardResult>;
13
+ adaptRequest(request: StandardRequest): any;
14
+ adaptResponse(response: AligoResponse): StandardResult;
15
+ mapError(error: any): StandardError;
16
+ private mapAligoError;
17
+ getAuthHeaders(): Record<string, string>;
18
+ getBaseUrl(): string;
19
+ getEndpoint(operation: string): string;
20
+ /**
21
+ * Aligo 특화 기능: 잔액 조회
22
+ */
23
+ getBalance(): Promise<number>;
24
+ createTemplate(template: Omit<Template, "id" | "status" | "createdAt" | "updatedAt">): Promise<Result<Template, KMsgError>>;
25
+ updateTemplate(_code: string, _template: Partial<Omit<Template, "id" | "code" | "status" | "createdAt" | "updatedAt">>): Promise<Result<Template, KMsgError>>;
26
+ deleteTemplate(code: string): Promise<Result<void, KMsgError>>;
27
+ getTemplate(code: string): Promise<Result<Template, KMsgError>>;
28
+ listTemplates(_params?: {
29
+ status?: string;
30
+ page?: number;
31
+ limit?: number;
32
+ }): Promise<Result<Template[], KMsgError>>;
33
+ private sendSMS;
34
+ private sendAlimTalk;
35
+ private sendFriendTalk;
36
+ private formatAligoDate;
37
+ private request;
38
+ private handleError;
39
+ private toProviderChannel;
40
+ private normalizeChannelLike;
41
+ private resolveStandardChannel;
42
+ private extractStandardMessage;
43
+ private buildSmsBodyFromStandard;
44
+ private isKakaoChannel;
45
+ private buildFriendTalkBody;
46
+ private buildAlimTalkBodyFromStandard;
47
+ private buildFriendTalkBodyFromStandard;
48
+ private interpolateMessage;
49
+ private mapTemplateStatus;
50
+ }
@@ -0,0 +1,111 @@
1
+ /**
2
+ * IWINV Provider Adapter
3
+ * IWINV API를 표준 인터페이스로 변환하는 어댑터
4
+ */
5
+ import { type AdapterFactory, BaseProviderAdapter, KMsgError, type ProviderConfig, type ProviderMetadata, type Result, type StandardError, type StandardRequest, type StandardResult, type Template, type TemplateProvider } from "@k-msg/core";
6
+ export interface IWINVError {
7
+ code: number;
8
+ message: string;
9
+ status?: number;
10
+ data?: unknown;
11
+ }
12
+ export interface IWINVRequest {
13
+ templateCode: string;
14
+ reserve?: "Y" | "N";
15
+ sendDate?: string;
16
+ reSend?: "Y" | "N";
17
+ resendCallback?: string;
18
+ resendType?: "Y" | "N";
19
+ resendTitle?: string;
20
+ resendContent?: string;
21
+ list: IWINVRecipient[];
22
+ }
23
+ export interface IWINVRecipient {
24
+ phone: string;
25
+ templateParam?: string[];
26
+ }
27
+ export interface IWINVResponse {
28
+ code: number;
29
+ message: string;
30
+ success?: number;
31
+ fail?: number;
32
+ seqNo?: number;
33
+ }
34
+ export interface IWINVBalanceResponse {
35
+ code: number;
36
+ charge: number;
37
+ }
38
+ export interface IWINVTemplate {
39
+ templateCode: string;
40
+ templateName: string;
41
+ templateContent: string;
42
+ status: "Y" | "I" | "R";
43
+ templateStatusMsg?: string;
44
+ templateStatusComments?: string;
45
+ createDate: string;
46
+ buttons: any[];
47
+ }
48
+ export interface IWINVTemplateListResponse extends IWINVResponse {
49
+ totalCount: number;
50
+ list: IWINVTemplate[];
51
+ }
52
+ export declare function isIWINVError(error: unknown): error is IWINVError;
53
+ export declare function isIWINVResponse(response: unknown): response is IWINVResponse;
54
+ export declare function isIWINVBalanceResponse(response: unknown): response is IWINVBalanceResponse;
55
+ export interface IWINVConfig extends ProviderConfig {
56
+ userId?: string;
57
+ senderNumber?: string;
58
+ sendEndpoint?: string;
59
+ }
60
+ /**
61
+ * IWINV API 어댑터 구현
62
+ */
63
+ export declare class IWINVAdapter extends BaseProviderAdapter implements TemplateProvider {
64
+ private static readonly directTemplates;
65
+ private readonly endpoints;
66
+ constructor(config: IWINVConfig);
67
+ adaptRequest(request: StandardRequest): IWINVRequest;
68
+ adaptResponse(response: IWINVResponse): StandardResult;
69
+ mapError(error: IWINVError | Error | unknown): StandardError;
70
+ getAuthHeaders(): Record<string, string>;
71
+ getBaseUrl(): string;
72
+ getEndpoint(operation: string): string;
73
+ getRequestConfig(): RequestInit;
74
+ createTemplate(template: Omit<Template, "id" | "status" | "createdAt" | "updatedAt">): Promise<Result<Template, KMsgError>>;
75
+ updateTemplate(code: string, template: Partial<Omit<Template, "id" | "code" | "status" | "createdAt" | "updatedAt">>): Promise<Result<Template, KMsgError>>;
76
+ deleteTemplate(code: string): Promise<Result<void, KMsgError>>;
77
+ getTemplate(code: string): Promise<Result<Template, KMsgError>>;
78
+ listTemplates(params?: {
79
+ status?: string;
80
+ page?: number;
81
+ limit?: number;
82
+ }): Promise<Result<Template[], KMsgError>>;
83
+ private mapIWINVTemplate;
84
+ private mapIWINVTemplateStatus;
85
+ isRetryableError(error: IWINVError | Error | unknown): boolean;
86
+ /**
87
+ * IWINV 날짜 형식으로 변환 (yyyy-MM-dd HH:mm:ss)
88
+ */
89
+ private formatIWINVDate;
90
+ /**
91
+ * IWINV 상태 코드를 표준 상태로 매핑
92
+ */
93
+ private mapIWINVStatus;
94
+ /**
95
+ * IWINV 특화 기능: 예약 발송 취소
96
+ */
97
+ cancelScheduledMessage(messageId: string): Promise<boolean>;
98
+ /**
99
+ * IWINV 특화 기능: 잔액 조회
100
+ */
101
+ getBalance(): Promise<number>;
102
+ }
103
+ /**
104
+ * IWINV 어댑터 팩토리
105
+ */
106
+ export declare class IWINVAdapterFactory implements AdapterFactory {
107
+ create(config: ProviderConfig): BaseProviderAdapter;
108
+ private isValidIWINVConfig;
109
+ supports(providerId: string): boolean;
110
+ getMetadata(): ProviderMetadata;
111
+ }
@@ -0,0 +1,18 @@
1
+ import { type SendOptions, type StandardRequest, UniversalProvider } from "@k-msg/core";
2
+ import type { AligoConfig } from "../types/aligo";
3
+ export declare class AligoProvider extends UniversalProvider {
4
+ constructor(config: AligoConfig);
5
+ send(params: SendOptions | StandardRequest | any): Promise<any>;
6
+ getBalance(): Promise<number>;
7
+ }
8
+ export declare const createAligoProvider: (config: AligoConfig) => AligoProvider;
9
+ export declare const createDefaultAligoProvider: () => AligoProvider;
10
+ export declare class AligoProviderFactory {
11
+ static create(config: AligoConfig): AligoProvider;
12
+ static createDefault(): AligoProvider;
13
+ static getInstance(): {
14
+ createProvider: (config: AligoConfig) => AligoProvider;
15
+ initialize: () => void;
16
+ };
17
+ }
18
+ export declare function initializeAligo(): void;
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Enhanced Provider Configuration System
3
+ * 개선된 프로바이더 설정 시스템
4
+ */
5
+ export interface ProviderConfigBase {
6
+ apiKey: string;
7
+ baseUrl: string;
8
+ timeout?: number;
9
+ retries?: number;
10
+ debug?: boolean;
11
+ }
12
+ export interface AlimTalkConfig extends ProviderConfigBase {
13
+ type: "alimtalk";
14
+ senderKey?: string;
15
+ fallbackSettings?: {
16
+ enableSMSFallback: boolean;
17
+ smsConfig?: SMSConfig;
18
+ };
19
+ templateValidation?: {
20
+ enableStrictMode: boolean;
21
+ allowDynamicTemplates: boolean;
22
+ };
23
+ }
24
+ export interface SMSConfig extends ProviderConfigBase {
25
+ type: "sms";
26
+ senderNumber: string;
27
+ defaultMsgType: "SMS" | "LMS" | "MMS";
28
+ autoDetectMessageType?: boolean;
29
+ lengthLimits?: {
30
+ sms: number;
31
+ lms: number;
32
+ };
33
+ }
34
+ export interface MMSConfig extends ProviderConfigBase {
35
+ type: "mms";
36
+ senderNumber: string;
37
+ mediaSettings?: {
38
+ maxFileSize: number;
39
+ allowedTypes: string[];
40
+ compressionQuality: number;
41
+ };
42
+ }
43
+ export interface ConnectionPoolConfig {
44
+ maxConnections: number;
45
+ idleTimeout: number;
46
+ connectionTimeout: number;
47
+ keepAlive: boolean;
48
+ }
49
+ export interface CacheConfig {
50
+ enabled: boolean;
51
+ ttl: number;
52
+ maxSize: number;
53
+ strategy: "LRU" | "FIFO" | "TTL";
54
+ }
55
+ export interface CircuitBreakerConfig {
56
+ enabled: boolean;
57
+ failureThreshold: number;
58
+ timeoutMs: number;
59
+ retryDelayMs: number;
60
+ maxRetries: number;
61
+ }
62
+ export interface RateLimitConfig {
63
+ requestsPerSecond: number;
64
+ burstSize: number;
65
+ strategy: "token_bucket" | "sliding_window";
66
+ }
67
+ export interface EnvironmentConfig {
68
+ environment: "development" | "staging" | "production";
69
+ rateLimits: RateLimitConfig;
70
+ monitoring: {
71
+ enableMetrics: boolean;
72
+ enableTracing: boolean;
73
+ enableHealthChecks: boolean;
74
+ metricsInterval: number;
75
+ };
76
+ logging: {
77
+ level: "debug" | "info" | "warn" | "error";
78
+ structured: boolean;
79
+ sensitiveDataMasking: boolean;
80
+ };
81
+ }
82
+ export interface IWINVConfigV2 {
83
+ environment: EnvironmentConfig;
84
+ alimtalk?: AlimTalkConfig;
85
+ sms?: SMSConfig;
86
+ mms?: MMSConfig;
87
+ shared: {
88
+ connectionPool: ConnectionPoolConfig;
89
+ cache: CacheConfig;
90
+ circuitBreaker: CircuitBreakerConfig;
91
+ };
92
+ security?: {
93
+ enableApiKeyValidation: boolean;
94
+ enableRequestSigning: boolean;
95
+ allowedDomains?: string[];
96
+ };
97
+ }
98
+ export declare class IWINVConfigBuilder {
99
+ private config;
100
+ static create(): IWINVConfigBuilder;
101
+ environment(env: EnvironmentConfig): this;
102
+ alimtalk(config: AlimTalkConfig): this;
103
+ sms(config: SMSConfig): this;
104
+ mms(config: MMSConfig): this;
105
+ shared(config: IWINVConfigV2["shared"]): this;
106
+ security(config: IWINVConfigV2["security"]): this;
107
+ build(): IWINVConfigV2;
108
+ }
109
+ export declare class ConfigFactory {
110
+ static development(): IWINVConfigV2;
111
+ static production(): IWINVConfigV2;
112
+ static fromEnvironment(): IWINVConfigV2;
113
+ }
114
+ export declare class ConfigValidator {
115
+ static validate(config: IWINVConfigV2): ConfigValidationResult;
116
+ private static isValidUrl;
117
+ }
118
+ export interface ConfigValidationResult {
119
+ isValid: boolean;
120
+ errors: string[];
121
+ warnings: string[];
122
+ }