@k-msg/provider 0.3.0 → 0.5.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.
Files changed (44) hide show
  1. package/README.md +35 -124
  2. package/dist/aligo/provider.d.ts +18 -8
  3. package/dist/index.d.ts +8 -29
  4. package/dist/index.js +47 -47
  5. package/dist/index.js.map +10 -28
  6. package/dist/index.mjs +47 -47
  7. package/dist/index.mjs.map +10 -28
  8. package/dist/iwinv/provider.d.ts +21 -59
  9. package/dist/iwinv/types/iwinv.d.ts +10 -2
  10. package/dist/providers/mock/mock.provider.d.ts +6 -1
  11. package/dist/solapi/provider.d.ts +18 -6
  12. package/dist/solapi/types/solapi.d.ts +14 -2
  13. package/package.json +2 -22
  14. package/dist/abstract/provider.base.d.ts +0 -108
  15. package/dist/adapters/aligo.adapter.d.ts +0 -50
  16. package/dist/adapters/iwinv.adapter.d.ts +0 -139
  17. package/dist/adapters/solapi.adapter.d.ts +0 -48
  18. package/dist/config/provider-config-v2.d.ts +0 -122
  19. package/dist/contracts/provider.contract.d.ts +0 -355
  20. package/dist/contracts/sms.contract.d.ts +0 -135
  21. package/dist/interfaces/index.d.ts +0 -14
  22. package/dist/interfaces/plugin.d.ts +0 -122
  23. package/dist/interfaces/services.d.ts +0 -222
  24. package/dist/iwinv/contracts/account.contract.d.ts +0 -11
  25. package/dist/iwinv/contracts/analytics.contract.d.ts +0 -16
  26. package/dist/iwinv/contracts/channel.contract.d.ts +0 -15
  27. package/dist/iwinv/contracts/messaging.contract.d.ts +0 -14
  28. package/dist/iwinv/contracts/sms.contract.d.ts +0 -33
  29. package/dist/iwinv/contracts/template.contract.d.ts +0 -18
  30. package/dist/iwinv/provider-multi.d.ts +0 -116
  31. package/dist/iwinv/provider-sms.d.ts +0 -55
  32. package/dist/middleware/index.d.ts +0 -27
  33. package/dist/mock/index.d.ts +0 -1
  34. package/dist/registry/index.d.ts +0 -1
  35. package/dist/registry/plugin-registry.d.ts +0 -15
  36. package/dist/services/provider.manager.d.ts +0 -24
  37. package/dist/services/provider.service.d.ts +0 -49
  38. package/dist/test-helpers.d.ts +0 -110
  39. package/dist/types/base.d.ts +0 -172
  40. package/dist/types/typed-templates.d.ts +0 -199
  41. package/dist/types/unified-config.d.ts +0 -197
  42. package/dist/types/unified-errors.d.ts +0 -225
  43. package/dist/utils/base-plugin.d.ts +0 -35
  44. package/dist/utils/index.d.ts +0 -12
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @k-msg/provider
2
2
 
3
- Provider system and interfaces for the K-Message platform.
3
+ Provider implementations for `k-msg` (SendOptions + Result based).
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,133 +10,44 @@ npm install @k-msg/provider @k-msg/core
10
10
  bun add @k-msg/provider @k-msg/core
11
11
  ```
12
12
 
13
- ## Features
14
-
15
- - **Complete Provider System**: All-in-one package with providers, adapters, and implementations
16
- - **Built-in IWINV Provider**: Production-ready IWINV AlimTalk integration
17
- - **BaseAlimTalkProvider**: Abstract base class for creating custom providers
18
- - **Request/Response Adapters**: Standardized API communication adapters
19
- - **Provider Registry**: Centralized provider management and registration
20
- - **Contract System**: Modular contract-based architecture
21
- - **Configuration Validation**: Built-in configuration validation with schemas
22
- - **Health Monitoring**: Comprehensive health checks and diagnostics
23
-
24
13
  ## Built-in Providers
25
14
 
26
- ### IWINV Provider
27
-
28
- Production-ready AlimTalk provider with full feature support:
29
-
30
- - AlimTalk message sending with variable substitution
31
- - ✅ SMS/LMS fallback for failed AlimTalk messages
32
- - Template management (create, update, delete, list)
33
- - Account balance and profile information
34
- - ✅ Real-time delivery tracking and status updates
35
- - Channel and sender number management
36
- - ✅ Analytics and usage statistics
37
- - ✅ Configuration validation and health checks
38
-
39
- ## Basic Usage
40
-
41
- ```typescript
42
- import { IWINVProvider } from '@k-msg/provider';
43
-
44
- // Use the built-in IWINV provider
45
- const iwinvProvider = new IWINVProvider({
46
- apiKey: process.env.IWINV_API_KEY!,
47
- baseUrl: 'https://alimtalk.bizservice.iwinv.kr',
48
- debug: false
49
- });
50
-
51
- // Send a message
52
- const result = await iwinvProvider.sendMessage({
53
- templateCode: 'TPL001',
54
- phoneNumber: '01012345678',
55
- variables: { code: '123456' }
56
- });
57
-
58
- console.log('Message sent:', result.messageId);
59
- ```
60
-
61
- ### Custom Provider Registration
62
-
63
- ```typescript
64
- import { PluginRegistry } from '@k-msg/provider';
65
-
66
- const registry = new PluginRegistry();
67
-
68
- // Register a custom provider plugin
69
- await registry.registerPlugin({
70
- id: 'custom-provider',
71
- name: 'Custom Provider',
72
- version: '1.0.0',
73
- capabilities: {
74
- messaging: true,
75
- templates: true,
76
- analytics: false
15
+ - `SolapiProvider` (SOLAPI)
16
+ - `IWINVProvider` (IWINV AlimTalk + optional SMS v2)
17
+ - `AligoProvider` (Aligo)
18
+
19
+ All providers implement the `Provider` interface from `@k-msg/core`:
20
+
21
+ - `supportedTypes` declares supported message `type`s
22
+ - `send(options: SendOptions)` returns `Result<SendResult, KMsgError>` (never throws)
23
+
24
+ ## Usage (with KMsg)
25
+
26
+ ```ts
27
+ import { KMsg } from "@k-msg/messaging";
28
+ import { IWINVProvider, SolapiProvider } from "@k-msg/provider";
29
+
30
+ const kmsg = new KMsg({
31
+ providers: [
32
+ new SolapiProvider({
33
+ apiKey: process.env.SOLAPI_API_KEY!,
34
+ apiSecret: process.env.SOLAPI_API_SECRET!,
35
+ defaultFrom: "01000000000",
36
+ }),
37
+ new IWINVProvider({
38
+ apiKey: process.env.IWINV_API_KEY!,
39
+ baseUrl: "https://alimtalk.bizservice.iwinv.kr",
40
+ smsApiKey: process.env.IWINV_SMS_API_KEY,
41
+ smsAuthKey: process.env.IWINV_SMS_AUTH_KEY,
42
+ smsSenderNumber: "01000000000",
43
+ }),
44
+ ],
45
+ routing: {
46
+ defaultProviderId: "solapi",
47
+ byType: { ALIMTALK: "iwinv" },
77
48
  },
78
- factory: () => new CustomProvider()
79
49
  });
80
50
 
81
- // Get registered providers
82
- const providers = registry.getRegisteredPlugins();
83
- console.log('Available providers:', providers);
84
- ```
85
-
86
- ## Creating Custom Providers
87
-
88
- ```typescript
89
- import { BasePlugin } from '@k-msg/provider';
90
-
91
- export class CustomProvider extends BasePlugin {
92
- constructor() {
93
- super({
94
- id: 'custom-provider',
95
- name: 'Custom Provider',
96
- version: '1.0.0'
97
- });
98
- }
99
-
100
- async initialize(config: any): Promise<void> {
101
- // Initialize provider with configuration
102
- this.config = config;
103
- }
104
-
105
- async sendMessage(options: MessageSendOptions): Promise<MessageResult> {
106
- // Implement message sending logic
107
- return {
108
- messageId: 'msg-123',
109
- status: 'SENT'
110
- };
111
- }
112
-
113
- async getHealth(): Promise<HealthStatus> {
114
- // Implement health check
115
- return {
116
- healthy: true,
117
- latency: 150
118
- };
119
- }
120
- }
51
+ await kmsg.send({ to: "01012345678", text: "hello" });
121
52
  ```
122
53
 
123
- ## Service Interfaces
124
-
125
- ```typescript
126
- import { MessagingService, TemplateService } from '@k-msg/provider';
127
-
128
- // Implement messaging service
129
- class CustomMessagingService implements MessagingService {
130
- async sendMessage(request: MessageRequest): Promise<MessageResponse> {
131
- // Custom implementation
132
- }
133
-
134
- async getMessageStatus(messageId: string): Promise<MessageStatus> {
135
- // Custom implementation
136
- }
137
- }
138
- ```
139
-
140
- ## License
141
-
142
- MIT
@@ -1,18 +1,28 @@
1
- import { type SendOptions, type StandardRequest, UniversalProvider } from "@k-msg/core";
1
+ import { KMsgError, type MessageType, type Provider, type ProviderHealthStatus, type Result, type SendOptions, type SendResult } from "@k-msg/core";
2
2
  import type { AligoConfig } from "../types/aligo";
3
- export declare class AligoProvider extends UniversalProvider {
3
+ export declare class AligoProvider implements Provider {
4
+ private readonly config;
5
+ readonly id = "aligo";
6
+ readonly name = "Aligo Smart SMS";
7
+ readonly supportedTypes: readonly MessageType[];
8
+ private readonly SMS_HOST;
9
+ private readonly ALIMTALK_HOST;
4
10
  constructor(config: AligoConfig);
5
- send(params: SendOptions | StandardRequest | any): Promise<any>;
6
- getBalance(): Promise<number>;
11
+ healthCheck(): Promise<ProviderHealthStatus>;
12
+ send(options: SendOptions): Promise<Result<SendResult, KMsgError>>;
13
+ private getEndpoint;
14
+ private formatAligoDate;
15
+ private request;
16
+ private mapAligoError;
17
+ private interpolateMessage;
18
+ private sendSMS;
19
+ private sendAlimTalk;
20
+ private sendFriendTalk;
7
21
  }
8
22
  export declare const createAligoProvider: (config: AligoConfig) => AligoProvider;
9
23
  export declare const createDefaultAligoProvider: () => AligoProvider;
10
24
  export declare class AligoProviderFactory {
11
25
  static create(config: AligoConfig): AligoProvider;
12
26
  static createDefault(): AligoProvider;
13
- static getInstance(): {
14
- createProvider: (config: AligoConfig) => AligoProvider;
15
- initialize: () => void;
16
- };
17
27
  }
18
28
  export declare function initializeAligo(): void;
package/dist/index.d.ts CHANGED
@@ -1,33 +1,12 @@
1
1
  /**
2
2
  * @k-msg/provider
3
- * Complete provider system with adapters and implementations
3
+ *
4
+ * Provider implementations for the unified `SendOptions + Result` API.
4
5
  */
5
- export type { NotificationRequest, NotificationResponse, } from "./interfaces";
6
- export * from "./interfaces/plugin";
7
- export * from "./middleware";
8
- export * from "./registry";
9
- export type { BaseProvider, BaseProviderConfig, ChannelInfo, HealthCheckResult, HistoryFilters, MediaAttachment, MessageButton, MessageChannel, MessageContent, MessageType, SenderNumber, SenderVerificationResult, SendOptions, SendResult, TemplateCreateRequest, TemplateFilters, TemplateResult, TemplateUpdateRequest, } from "./types/base";
10
- export * from "./utils";
11
- export { BaseAlimTalkProvider } from "./abstract/provider.base";
12
- export { AligoAdapter } from "./adapters/aligo.adapter";
13
- export { IWINVAdapter, IWINVAdapterFactory, } from "./adapters/iwinv.adapter";
14
- export { SolapiAdapter } from "./adapters/solapi.adapter";
15
- export type { AccountContract, AnalyticsContract, ChannelContract, ConfigurationField, MessagingContract, ProviderCapabilities, ProviderConfiguration, ProviderMessageRequest, ProviderMessageResult, ScheduleResult, TemplateContract, } from "./contracts/provider.contract";
16
- export * from "./providers/mock";
17
- export * from "./services/provider.manager";
18
- export * from "./services/provider.service";
19
- export { AligoProvider, AligoProviderFactory, createAligoProvider, createDefaultAligoProvider, initializeAligo, } from "./aligo/provider";
20
- export type * from "./contracts/sms.contract";
21
- export { createDefaultIWINVProvider, createIWINVProvider, IWINVProvider, IWINVProviderFactory, initializeIWINV, } from "./iwinv/provider";
22
- export { createDefaultIWINVMultiProvider, createIWINVMultiProvider, IWINVMultiProvider, } from "./iwinv/provider-multi";
23
- export { createDefaultIWINVSMSProvider, createIWINVSMSProvider, IWINVSMSProvider, } from "./iwinv/provider-sms";
24
- export type * from "./iwinv/types/iwinv";
25
- export { createDefaultSolapiProvider, createSolapiProvider, initializeSolapi, SolapiProvider, SolapiProviderFactory, } from "./solapi/provider";
6
+ export { AligoProvider, AligoProviderFactory, createAligoProvider, createDefaultAligoProvider, initializeAligo } from "./aligo/provider";
7
+ export type { AligoConfig } from "./types/aligo";
8
+ export { IWINVProvider, IWINVProviderFactory, createIWINVProvider, createDefaultIWINVProvider, initializeIWINV } from "./iwinv/provider";
9
+ export type { IWINVConfig } from "./iwinv/types/iwinv";
10
+ export { SolapiProvider, SolapiProviderFactory, createSolapiProvider, createDefaultSolapiProvider, initializeSolapi } from "./solapi/provider";
26
11
  export type { SolapiConfig } from "./solapi/types/solapi";
27
- export type * from "./types/aligo";
28
- export type { TemplateCode, TemplateVariables, TypedRequest, TypedResult, ValidationResult, } from "./types/typed-templates";
29
- export { TEMPLATE_REGISTRY, TemplateTypeConverter, TemplateValidator, TypedProvider, } from "./types/typed-templates";
30
- export type { AlimTalkConfig, IWINVBaseConfig, MonitoringConfig, PerformanceConfig, SMSConfig, UnifiedProviderConfig, } from "./types/unified-config";
31
- export { isValidIWINVBaseConfig, isValidUnifiedConfig, toLegacyIWINVConfig, UnifiedConfigBuilder, UnifiedConfigFactory, } from "./types/unified-config";
32
- export type { BaseErrorInfo, ErrorStats, NetworkErrorInfo, ProviderErrorInfo, TemplateErrorInfo, UnifiedErrorInfo, } from "./types/unified-errors";
33
- export { ErrorAnalyzer, ErrorCategory, ErrorConverter, ErrorFactory, ErrorSeverity, isNetworkError, isProviderError, isRetryableError, isTemplateError, isUnifiedError, NetworkError, ProviderError, TemplateError, UnifiedError, } from "./types/unified-errors";
12
+ export { MockProvider } from "./providers/mock/mock.provider";