@k-msg/messaging 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.
@@ -0,0 +1,280 @@
1
+ import type { RetryOptions } from "@k-msg/core";
2
+ import { z } from "zod";
3
+ export interface MessageRequest {
4
+ templateId: string;
5
+ recipients: Recipient[];
6
+ variables: VariableMap;
7
+ scheduling?: SchedulingOptions;
8
+ options?: SendingOptions;
9
+ }
10
+ export interface Recipient {
11
+ phoneNumber: string;
12
+ variables?: VariableMap;
13
+ metadata?: Record<string, any>;
14
+ }
15
+ export interface VariableMap {
16
+ [key: string]: string | number | Date;
17
+ }
18
+ export interface SchedulingOptions {
19
+ scheduledAt: Date;
20
+ timezone?: string;
21
+ retryCount?: number;
22
+ }
23
+ export interface SendingOptions {
24
+ priority?: "high" | "normal" | "low";
25
+ ttl?: number;
26
+ failover?: {
27
+ enabled: boolean;
28
+ fallbackChannel?: "sms" | "lms";
29
+ fallbackContent?: string;
30
+ };
31
+ deduplication?: {
32
+ enabled: boolean;
33
+ window: number;
34
+ };
35
+ tracking?: {
36
+ enabled: boolean;
37
+ webhookUrl?: string;
38
+ };
39
+ }
40
+ export interface MessageResult {
41
+ requestId: string;
42
+ results: RecipientResult[];
43
+ summary: {
44
+ total: number;
45
+ queued: number;
46
+ sent: number;
47
+ failed: number;
48
+ };
49
+ metadata: {
50
+ createdAt: Date;
51
+ provider: string;
52
+ templateId: string;
53
+ };
54
+ }
55
+ export interface RecipientResult {
56
+ phoneNumber: string;
57
+ messageId?: string;
58
+ status: MessageStatus;
59
+ error?: MessageError;
60
+ metadata?: Record<string, any>;
61
+ }
62
+ export declare enum MessageStatus {
63
+ QUEUED = "QUEUED",// 큐에 대기 중
64
+ SENDING = "SENDING",// 발송 중
65
+ SENT = "SENT",// 발송 완료
66
+ DELIVERED = "DELIVERED",// 전달 완료
67
+ FAILED = "FAILED",// 발송 실패
68
+ CLICKED = "CLICKED",// 버튼 클릭됨
69
+ CANCELLED = "CANCELLED"
70
+ }
71
+ export interface MessageError {
72
+ code: string;
73
+ message: string;
74
+ details?: Record<string, any>;
75
+ }
76
+ export interface DeliveryReport {
77
+ messageId: string;
78
+ phoneNumber: string;
79
+ status: MessageStatus;
80
+ sentAt?: Date;
81
+ deliveredAt?: Date;
82
+ clickedAt?: Date;
83
+ failedAt?: Date;
84
+ error?: MessageError;
85
+ attempts: DeliveryAttempt[];
86
+ metadata: Record<string, any>;
87
+ }
88
+ export interface DeliveryAttempt {
89
+ attemptNumber: number;
90
+ attemptedAt: Date;
91
+ status: MessageStatus;
92
+ error?: MessageError;
93
+ provider: string;
94
+ }
95
+ export interface BulkMessageRequest {
96
+ templateId: string;
97
+ recipients: BulkRecipient[];
98
+ commonVariables?: VariableMap;
99
+ options?: BulkSendingOptions;
100
+ }
101
+ export interface BulkRecipient {
102
+ phoneNumber: string;
103
+ variables: VariableMap;
104
+ metadata?: Record<string, any>;
105
+ }
106
+ export interface BulkSendingOptions extends SendingOptions {
107
+ batchSize?: number;
108
+ batchDelay?: number;
109
+ maxConcurrency?: number;
110
+ retryOptions?: Partial<RetryOptions>;
111
+ }
112
+ export interface BulkMessageResult {
113
+ requestId: string;
114
+ totalRecipients: number;
115
+ batches: BulkBatchResult[];
116
+ summary: {
117
+ queued: number;
118
+ sent: number;
119
+ failed: number;
120
+ processing: number;
121
+ };
122
+ createdAt: Date;
123
+ completedAt?: Date;
124
+ }
125
+ export interface BulkBatchResult {
126
+ batchId: string;
127
+ batchNumber: number;
128
+ recipients: RecipientResult[];
129
+ status: "pending" | "processing" | "completed" | "failed";
130
+ createdAt: Date;
131
+ completedAt?: Date;
132
+ }
133
+ export declare enum MessageEventType {
134
+ TEMPLATE_CREATED = "template.created",
135
+ TEMPLATE_APPROVED = "template.approved",
136
+ TEMPLATE_REJECTED = "template.rejected",
137
+ TEMPLATE_UPDATED = "template.updated",
138
+ TEMPLATE_DELETED = "template.deleted",
139
+ MESSAGE_QUEUED = "message.queued",
140
+ MESSAGE_SENT = "message.sent",
141
+ MESSAGE_DELIVERED = "message.delivered",
142
+ MESSAGE_FAILED = "message.failed",
143
+ MESSAGE_CLICKED = "message.clicked",
144
+ MESSAGE_CANCELLED = "message.cancelled",
145
+ CHANNEL_CREATED = "channel.created",
146
+ CHANNEL_VERIFIED = "channel.verified",
147
+ SENDER_NUMBER_ADDED = "sender_number.added",
148
+ QUOTA_WARNING = "system.quota_warning",
149
+ QUOTA_EXCEEDED = "system.quota_exceeded",
150
+ PROVIDER_ERROR = "system.provider_error"
151
+ }
152
+ export interface MessageEvent<T = any> {
153
+ id: string;
154
+ type: MessageEventType;
155
+ timestamp: Date;
156
+ data: T;
157
+ metadata: {
158
+ providerId?: string;
159
+ userId?: string;
160
+ organizationId?: string;
161
+ correlationId?: string;
162
+ };
163
+ }
164
+ export declare const VariableMapSchema: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>>;
165
+ export declare const RecipientSchema: z.ZodObject<{
166
+ phoneNumber: z.ZodString;
167
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>>>;
168
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
169
+ }, z.core.$strip>;
170
+ export declare const SchedulingOptionsSchema: z.ZodObject<{
171
+ scheduledAt: z.ZodDate;
172
+ timezone: z.ZodOptional<z.ZodString>;
173
+ retryCount: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
174
+ }, z.core.$strip>;
175
+ export declare const SendingOptionsSchema: z.ZodObject<{
176
+ priority: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
177
+ high: "high";
178
+ normal: "normal";
179
+ low: "low";
180
+ }>>>;
181
+ ttl: z.ZodOptional<z.ZodNumber>;
182
+ failover: z.ZodOptional<z.ZodObject<{
183
+ enabled: z.ZodBoolean;
184
+ fallbackChannel: z.ZodOptional<z.ZodEnum<{
185
+ sms: "sms";
186
+ lms: "lms";
187
+ }>>;
188
+ fallbackContent: z.ZodOptional<z.ZodString>;
189
+ }, z.core.$strip>>;
190
+ deduplication: z.ZodOptional<z.ZodObject<{
191
+ enabled: z.ZodBoolean;
192
+ window: z.ZodNumber;
193
+ }, z.core.$strip>>;
194
+ tracking: z.ZodOptional<z.ZodObject<{
195
+ enabled: z.ZodBoolean;
196
+ webhookUrl: z.ZodOptional<z.ZodString>;
197
+ }, z.core.$strip>>;
198
+ }, z.core.$strip>;
199
+ export declare const MessageRequestSchema: z.ZodObject<{
200
+ templateId: z.ZodString;
201
+ recipients: z.ZodArray<z.ZodObject<{
202
+ phoneNumber: z.ZodString;
203
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>>>;
204
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
205
+ }, z.core.$strip>>;
206
+ variables: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>>;
207
+ scheduling: z.ZodOptional<z.ZodObject<{
208
+ scheduledAt: z.ZodDate;
209
+ timezone: z.ZodOptional<z.ZodString>;
210
+ retryCount: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
211
+ }, z.core.$strip>>;
212
+ options: z.ZodOptional<z.ZodObject<{
213
+ priority: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
214
+ high: "high";
215
+ normal: "normal";
216
+ low: "low";
217
+ }>>>;
218
+ ttl: z.ZodOptional<z.ZodNumber>;
219
+ failover: z.ZodOptional<z.ZodObject<{
220
+ enabled: z.ZodBoolean;
221
+ fallbackChannel: z.ZodOptional<z.ZodEnum<{
222
+ sms: "sms";
223
+ lms: "lms";
224
+ }>>;
225
+ fallbackContent: z.ZodOptional<z.ZodString>;
226
+ }, z.core.$strip>>;
227
+ deduplication: z.ZodOptional<z.ZodObject<{
228
+ enabled: z.ZodBoolean;
229
+ window: z.ZodNumber;
230
+ }, z.core.$strip>>;
231
+ tracking: z.ZodOptional<z.ZodObject<{
232
+ enabled: z.ZodBoolean;
233
+ webhookUrl: z.ZodOptional<z.ZodString>;
234
+ }, z.core.$strip>>;
235
+ }, z.core.$strip>>;
236
+ }, z.core.$strip>;
237
+ export declare const MessageErrorSchema: z.ZodObject<{
238
+ code: z.ZodString;
239
+ message: z.ZodString;
240
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
241
+ }, z.core.$strip>;
242
+ export declare const RecipientResultSchema: z.ZodObject<{
243
+ phoneNumber: z.ZodString;
244
+ messageId: z.ZodOptional<z.ZodString>;
245
+ status: z.ZodEnum<typeof MessageStatus>;
246
+ error: z.ZodOptional<z.ZodObject<{
247
+ code: z.ZodString;
248
+ message: z.ZodString;
249
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
250
+ }, z.core.$strip>>;
251
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
252
+ }, z.core.$strip>;
253
+ export declare const MessageResultSchema: z.ZodObject<{
254
+ requestId: z.ZodString;
255
+ results: z.ZodArray<z.ZodObject<{
256
+ phoneNumber: z.ZodString;
257
+ messageId: z.ZodOptional<z.ZodString>;
258
+ status: z.ZodEnum<typeof MessageStatus>;
259
+ error: z.ZodOptional<z.ZodObject<{
260
+ code: z.ZodString;
261
+ message: z.ZodString;
262
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
263
+ }, z.core.$strip>>;
264
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
265
+ }, z.core.$strip>>;
266
+ summary: z.ZodObject<{
267
+ total: z.ZodNumber;
268
+ queued: z.ZodNumber;
269
+ sent: z.ZodNumber;
270
+ failed: z.ZodNumber;
271
+ }, z.core.$strip>;
272
+ metadata: z.ZodObject<{
273
+ createdAt: z.ZodDate;
274
+ provider: z.ZodString;
275
+ templateId: z.ZodString;
276
+ }, z.core.$strip>;
277
+ }, z.core.$strip>;
278
+ export type MessageRequestType = z.infer<typeof MessageRequestSchema>;
279
+ export type RecipientType = z.infer<typeof RecipientSchema>;
280
+ export type MessageResultType = z.infer<typeof MessageResultSchema>;
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@k-msg/messaging",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
+ "packageManager": "bun@1.3.8",
4
5
  "description": "AlimTalk messaging core for sending, queuing, and tracking messages",
5
6
  "type": "module",
6
7
  "main": "dist/index.js",
@@ -17,20 +18,26 @@
17
18
  "access": "public"
18
19
  },
19
20
  "scripts": {
20
- "build": "tsup",
21
+ "build": "bun run build:esm && bun run build:cjs && bun run build:types",
22
+ "build:esm": "bun build ./src/index.ts --outdir ./dist --format esm --minify --sourcemap --entry-naming '[name].mjs' --external 'bun:test' --external 'bun:sqlite'",
23
+ "build:cjs": "bun build ./src/index.ts --outdir ./dist --format cjs --minify --sourcemap --entry-naming '[name].js' --external 'bun:test' --external 'bun:sqlite'",
24
+ "build:types": "tsc",
21
25
  "dev": "tsc --watch",
22
26
  "test": "bun test",
23
- "clean": "rm -rf dist"
27
+ "clean": "rm -rf dist",
28
+ "pack": "bun pm pack",
29
+ "publish": "bun publish --access public"
24
30
  },
25
31
  "dependencies": {
26
- "zod": "catalog:",
27
- "@k-msg/core": "workspace:*"
32
+ "zod": "^4.0.14",
33
+ "@k-msg/core": "0.1.1",
34
+ "@k-msg/provider": "0.1.1",
35
+ "@k-msg/template": "0.1.1"
28
36
  },
29
37
  "devDependencies": {
30
- "typescript": "catalog:",
31
- "@types/bun": "catalog:",
32
- "@types/node": "catalog:",
33
- "tsup": "^8.5.0"
38
+ "typescript": "^5.7.2",
39
+ "@types/bun": "latest",
40
+ "@types/node": "^22.0.0"
34
41
  },
35
42
  "files": [
36
43
  "dist",
@@ -45,12 +52,12 @@
45
52
  ],
46
53
  "repository": {
47
54
  "type": "git",
48
- "url": "git+https://github.com/k-otp/k-message.git"
55
+ "url": "git+https://github.com/k-otp/k-msg.git"
49
56
  },
50
- "homepage": "https://github.com/k-otp/k-message",
57
+ "homepage": "https://github.com/k-otp/k-msg",
51
58
  "bugs": {
52
- "url": "https://github.com/k-otp/k-message/issues"
59
+ "url": "https://github.com/k-otp/k-msg/issues"
53
60
  },
54
61
  "author": "imjlk",
55
62
  "license": "MIT"
56
- }
63
+ }