@k-msg/messaging 0.4.0 → 0.6.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.
package/dist/k-msg.d.ts CHANGED
@@ -1,8 +1,63 @@
1
- import { KMsgError, type Provider, type Result, type SendOptions, type SendResult } from "@k-msg/core";
1
+ import { KMsgError, type MessageType, type Provider, type ProviderHealthStatus, type Result, type SendInput, type SendResult } from "@k-msg/core";
2
2
  import type { KMsgHooks } from "./hooks";
3
+ export type RoutingStrategy = "first" | "round_robin";
4
+ export interface KMsgRoutingConfig {
5
+ byType?: Partial<Record<MessageType, string | string[]>>;
6
+ defaultProviderId?: string;
7
+ strategy?: RoutingStrategy;
8
+ }
9
+ export interface KMsgDefaultsConfig {
10
+ from?: string;
11
+ sms?: {
12
+ /**
13
+ * If type is omitted (SMS default input), upgrade to LMS when estimated bytes exceed this value.
14
+ * Default: 90
15
+ */
16
+ autoLmsBytes?: number;
17
+ };
18
+ kakao?: {
19
+ profileId?: string;
20
+ };
21
+ naver?: {
22
+ talkId?: string;
23
+ };
24
+ rcs?: {
25
+ brandId?: string;
26
+ };
27
+ }
28
+ export interface KMsgConfig {
29
+ providers: Provider[];
30
+ routing?: KMsgRoutingConfig;
31
+ defaults?: KMsgDefaultsConfig;
32
+ hooks?: KMsgHooks;
33
+ }
3
34
  export declare class KMsg {
4
- private readonly provider;
35
+ private readonly providers;
36
+ private readonly providersById;
5
37
  private readonly hooks;
6
- constructor(provider: Provider, hooks?: KMsgHooks);
7
- send(options: SendOptions): Promise<Result<SendResult, KMsgError>>;
38
+ private readonly routing;
39
+ private readonly defaults;
40
+ private readonly rrIndexByKey;
41
+ constructor(config: KMsgConfig);
42
+ healthCheck(): Promise<{
43
+ healthy: boolean;
44
+ providers: Record<string, ProviderHealthStatus>;
45
+ issues: string[];
46
+ }>;
47
+ send(input: SendInput): Promise<Result<SendResult, KMsgError>>;
48
+ sendOrThrow(input: SendInput): Promise<SendResult>;
49
+ sendMany(inputs: SendInput[], options?: {
50
+ concurrency?: number;
51
+ stopOnFailure?: boolean;
52
+ }): Promise<Array<Result<SendResult, KMsgError>>>;
53
+ private toKMsgError;
54
+ private selectProvider;
55
+ private pickRoundRobin;
56
+ private normalizeInput;
57
+ private applyDefaults;
58
+ private coerceVariables;
59
+ private interpolateText;
60
+ private interpolateTextOptions;
61
+ private stringifyVariables;
62
+ private estimateBytes;
8
63
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Retry handler for failed message deliveries
3
3
  */
4
- import { EventEmitter } from "events";
4
+ import { EventEmitter } from "node:events";
5
5
  import { type DeliveryReport, MessageStatus } from "../types/message.types";
6
6
  export interface RetryPolicy {
7
7
  maxAttempts: number;
@@ -18,9 +18,9 @@ export interface RetryAttempt {
18
18
  attemptNumber: number;
19
19
  scheduledAt: Date;
20
20
  provider: string;
21
- templateId: string;
22
- variables: Record<string, any>;
23
- metadata: Record<string, any>;
21
+ templateCode: string;
22
+ variables: Record<string, unknown>;
23
+ metadata: Record<string, unknown>;
24
24
  }
25
25
  export interface RetryQueueItem {
26
26
  id: string;
@@ -39,7 +39,7 @@ export interface RetryHandlerOptions {
39
39
  maxQueueSize: number;
40
40
  enablePersistence: boolean;
41
41
  onRetryExhausted?: (item: RetryQueueItem) => Promise<void>;
42
- onRetrySuccess?: (item: RetryQueueItem, result: any) => Promise<void>;
42
+ onRetrySuccess?: (item: RetryQueueItem, result: unknown) => Promise<void>;
43
43
  onRetryFailed?: (item: RetryQueueItem, error: Error) => Promise<void>;
44
44
  }
45
45
  export interface RetryHandlerMetrics {
@@ -7,7 +7,8 @@ export declare class BulkMessageSender {
7
7
  sendBulk(request: BulkMessageRequest): Promise<BulkMessageResult>;
8
8
  private processBatchesAsync;
9
9
  private processBatch;
10
- private processRecipient;
10
+ private sendManyWithRetry;
11
+ private toRecipientResult;
11
12
  private createBatches;
12
13
  private delay;
13
14
  private generateRequestId;
@@ -1,7 +1,7 @@
1
1
  import type { RetryOptions } from "@k-msg/core";
2
2
  import { z } from "zod";
3
3
  export interface MessageRequest {
4
- templateId: string;
4
+ templateCode: string;
5
5
  recipients: Recipient[];
6
6
  variables: VariableMap;
7
7
  scheduling?: SchedulingOptions;
@@ -10,7 +10,7 @@ export interface MessageRequest {
10
10
  export interface Recipient {
11
11
  phoneNumber: string;
12
12
  variables?: VariableMap;
13
- metadata?: Record<string, any>;
13
+ metadata?: Record<string, unknown>;
14
14
  }
15
15
  export interface VariableMap {
16
16
  [key: string]: string | number | Date;
@@ -49,7 +49,7 @@ export interface MessageResult {
49
49
  metadata: {
50
50
  createdAt: Date;
51
51
  provider: string;
52
- templateId: string;
52
+ templateCode: string;
53
53
  };
54
54
  }
55
55
  export interface RecipientResult {
@@ -57,7 +57,7 @@ export interface RecipientResult {
57
57
  messageId?: string;
58
58
  status: MessageStatus;
59
59
  error?: MessageError;
60
- metadata?: Record<string, any>;
60
+ metadata?: Record<string, unknown>;
61
61
  }
62
62
  export declare enum MessageStatus {
63
63
  QUEUED = "QUEUED",// 큐에 대기 중
@@ -71,7 +71,7 @@ export declare enum MessageStatus {
71
71
  export interface MessageError {
72
72
  code: string;
73
73
  message: string;
74
- details?: Record<string, any>;
74
+ details?: Record<string, unknown>;
75
75
  }
76
76
  export interface DeliveryReport {
77
77
  messageId: string;
@@ -83,7 +83,7 @@ export interface DeliveryReport {
83
83
  failedAt?: Date;
84
84
  error?: MessageError;
85
85
  attempts: DeliveryAttempt[];
86
- metadata: Record<string, any>;
86
+ metadata: Record<string, unknown>;
87
87
  }
88
88
  export interface DeliveryAttempt {
89
89
  attemptNumber: number;
@@ -92,8 +92,14 @@ export interface DeliveryAttempt {
92
92
  error?: MessageError;
93
93
  provider: string;
94
94
  }
95
+ export type BulkMessageType = "ALIMTALK" | "NSA" | "RCS_TPL" | "RCS_ITPL" | "RCS_LTPL";
95
96
  export interface BulkMessageRequest {
96
- templateId: string;
97
+ /**
98
+ * BulkMessageSender currently targets template-based channels.
99
+ * Default: "ALIMTALK"
100
+ */
101
+ type?: BulkMessageType;
102
+ templateCode: string;
97
103
  recipients: BulkRecipient[];
98
104
  commonVariables?: VariableMap;
99
105
  options?: BulkSendingOptions;
@@ -101,9 +107,17 @@ export interface BulkMessageRequest {
101
107
  export interface BulkRecipient {
102
108
  phoneNumber: string;
103
109
  variables: VariableMap;
104
- metadata?: Record<string, any>;
110
+ metadata?: Record<string, unknown>;
105
111
  }
106
112
  export interface BulkSendingOptions extends SendingOptions {
113
+ /**
114
+ * Sender number / id for bulk sends (optional if KMsg defaults cover it).
115
+ */
116
+ from?: string;
117
+ /**
118
+ * Back-compat alias for legacy callers.
119
+ */
120
+ senderNumber?: string;
107
121
  batchSize?: number;
108
122
  batchDelay?: number;
109
123
  maxConcurrency?: number;
@@ -149,7 +163,7 @@ export declare enum MessageEventType {
149
163
  QUOTA_EXCEEDED = "system.quota_exceeded",
150
164
  PROVIDER_ERROR = "system.provider_error"
151
165
  }
152
- export interface MessageEvent<T = any> {
166
+ export interface MessageEvent<T = unknown> {
153
167
  id: string;
154
168
  type: MessageEventType;
155
169
  timestamp: Date;
@@ -197,7 +211,7 @@ export declare const SendingOptionsSchema: z.ZodObject<{
197
211
  }, z.core.$strip>>;
198
212
  }, z.core.$strip>;
199
213
  export declare const MessageRequestSchema: z.ZodObject<{
200
- templateId: z.ZodString;
214
+ templateCode: z.ZodString;
201
215
  recipients: z.ZodArray<z.ZodObject<{
202
216
  phoneNumber: z.ZodString;
203
217
  variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>>>;
@@ -272,7 +286,7 @@ export declare const MessageResultSchema: z.ZodObject<{
272
286
  metadata: z.ZodObject<{
273
287
  createdAt: z.ZodDate;
274
288
  provider: z.ZodString;
275
- templateId: z.ZodString;
289
+ templateCode: z.ZodString;
276
290
  }, z.core.$strip>;
277
291
  }, z.core.$strip>;
278
292
  export type MessageRequestType = z.infer<typeof MessageRequestSchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k-msg/messaging",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "packageManager": "bun@1.3.8",
5
5
  "description": "AlimTalk messaging core for sending, queuing, and tracking messages",
6
6
  "type": "module",
@@ -30,9 +30,9 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "zod": "^4.0.14",
33
- "@k-msg/core": "0.4.0",
34
- "@k-msg/provider": "0.4.0",
35
- "@k-msg/template": "0.4.0"
33
+ "@k-msg/core": "0.6.0",
34
+ "@k-msg/provider": "0.6.0",
35
+ "@k-msg/template": "0.6.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "typescript": "^5.7.2",