@k-msg/core 0.1.6 → 0.3.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.
@@ -1,4 +1,4 @@
1
- import type { BaseProvider, Config, KMsg, MessageSendOptions, MessageSendResult, PlatformHealthStatus, PlatformInfo } from "./types/index";
1
+ import type { BalanceQuery, BalanceResult, BaseProvider, Config, HistoryQuery, HistoryResult, KMsg, MessageSendOptions, MessageSendResult, PlatformHealthStatus, PlatformInfo } from "./types/index";
2
2
  /**
3
3
  * Core AlimTalk Platform implementation
4
4
  */
@@ -33,31 +33,41 @@ export declare class AlimTalkPlatform implements KMsg {
33
33
  healthCheck(): Promise<PlatformHealthStatus>;
34
34
  get messages(): {
35
35
  send: (options: MessageSendOptions) => Promise<MessageSendResult>;
36
- getStatus: (messageId: string) => Promise<string>;
36
+ getStatus: (_messageId: string) => Promise<string>;
37
37
  };
38
+ balance(providerId?: string): Promise<{
39
+ get: (query?: BalanceQuery) => Promise<BalanceResult>;
40
+ }>;
38
41
  /**
39
42
  * @deprecated Template operations are not yet migrated to the new provider interface.
40
43
  * Use the provider's adapter directly for template management.
41
44
  */
42
45
  templates(providerId?: string): Promise<{
43
46
  /** @deprecated Not yet implemented */
44
- list: (_page?: number, _size?: number, _filters?: any) => Promise<never>;
47
+ list: (_page?: number, _size?: number, _filters?: Record<string, unknown>) => Promise<never>;
45
48
  /** @deprecated Not yet implemented */
46
- create: (_name: string, _content: string, _category?: string, _variables?: any[], _buttons?: any[]) => Promise<never>;
49
+ create: (_name: string, _content: string, _category?: string, _variables?: unknown[], _buttons?: unknown[]) => Promise<never>;
47
50
  /** @deprecated Not yet implemented */
48
- modify: (_templateCode: string, _name: string, _content: string, _buttons?: any[]) => Promise<never>;
51
+ modify: (_templateCode: string, _name: string, _content: string, _buttons?: unknown[]) => Promise<never>;
49
52
  /** @deprecated Not yet implemented */
50
53
  delete: (_templateCode: string) => Promise<never>;
51
54
  }>;
52
55
  /**
53
- * @deprecated History operations are not yet migrated to the new provider interface.
54
- * Use the provider's adapter directly for history queries.
56
+ * History operations (common API surface).
57
+ *
58
+ * Notes:
59
+ * - Not all providers implement history. This method will throw when unsupported.
60
+ * - For provider-specific, advanced fields, use provider adapter directly.
55
61
  */
56
62
  history(providerId?: string): Promise<{
57
- /** @deprecated Not yet implemented */
58
- list: (_page?: number, _size?: number, _filters?: any) => Promise<never>;
59
- /** @deprecated Not yet implemented */
63
+ list: (queryOrPage?: HistoryQuery | number, pageSize?: number, filters?: Partial<Omit<HistoryQuery, "page" | "pageSize">> & {
64
+ channel?: HistoryQuery["channel"];
65
+ }) => Promise<HistoryResult>;
60
66
  cancelReservation: (_messageId: string) => Promise<never>;
61
67
  }>;
62
68
  providerHealth(providerId: string): Promise<import(".").ProviderHealthStatus>;
69
+ private getProviderAdapter;
70
+ private isSmsChannel;
71
+ private normalizeHistoryQuery;
72
+ private getFunction;
63
73
  }
@@ -0,0 +1,12 @@
1
+ import type { MessageType } from "./message";
2
+ export type BalanceChannel = MessageType;
3
+ export interface BalanceQuery {
4
+ channel?: BalanceChannel;
5
+ }
6
+ export interface BalanceResult {
7
+ providerId: string;
8
+ channel?: BalanceChannel;
9
+ amount: number;
10
+ currency?: string;
11
+ raw?: unknown;
12
+ }
@@ -0,0 +1,40 @@
1
+ import type { MessageType } from "./message";
2
+ export type HistoryChannel = MessageType;
3
+ export interface HistoryQuery {
4
+ channel: HistoryChannel;
5
+ startDate: string | Date;
6
+ endDate: string | Date;
7
+ page?: number;
8
+ pageSize?: number;
9
+ /**
10
+ * Cursor key for providers that use cursor-based pagination (e.g. SOLAPI).
11
+ * When provided, it takes precedence over `page`.
12
+ */
13
+ startKey?: string;
14
+ phone?: string;
15
+ requestNo?: string;
16
+ companyId?: string;
17
+ }
18
+ export interface HistoryItem {
19
+ providerId: string;
20
+ channel: HistoryChannel;
21
+ messageId: string;
22
+ to?: string;
23
+ from?: string;
24
+ status?: string;
25
+ statusCode?: string;
26
+ statusMessage?: string;
27
+ sentAt?: Date;
28
+ raw: unknown;
29
+ }
30
+ export interface HistoryResult {
31
+ providerId: string;
32
+ channel: HistoryChannel;
33
+ totalCount: number;
34
+ /**
35
+ * Cursor key for fetching the next page when provider supports cursor pagination.
36
+ */
37
+ nextKey?: string | null;
38
+ items: HistoryItem[];
39
+ raw?: unknown;
40
+ }
@@ -1,3 +1,5 @@
1
+ export * from "./balance";
2
+ export * from "./history";
1
3
  export * from "./message";
2
4
  export * from "./platform";
3
5
  export * from "./provider";
@@ -1,4 +1,4 @@
1
- export type MessageType = "ALIMTALK" | "FRIENDTALK" | "SMS" | "LMS" | "MMS";
1
+ export type MessageType = "ALIMTALK" | "FRIENDTALK" | "SMS" | "LMS" | "MMS" | "RCS_SMS" | "RCS_LMS" | "RCS_MMS" | "RCS_TPL" | "RCS_ITPL" | "RCS_LTPL";
2
2
  export interface BaseOptions {
3
3
  to: string;
4
4
  from: string;
@@ -1,4 +1,7 @@
1
+ import type { BalanceQuery, BalanceResult } from "./balance";
2
+ import type { HistoryQuery, HistoryResult } from "./history";
1
3
  import type { Button, MessageType } from "./message";
4
+ import type { BaseProvider } from "./provider";
2
5
  export interface PlatformHealthStatus {
3
6
  healthy: boolean;
4
7
  providers: Record<string, boolean>;
@@ -13,20 +16,20 @@ export interface LegacyMessageSendOptions {
13
16
  templateId: string;
14
17
  recipients: {
15
18
  phoneNumber: string;
16
- variables?: Record<string, any>;
19
+ variables?: Record<string, unknown>;
17
20
  }[];
18
- variables: Record<string, any>;
21
+ variables: Record<string, unknown>;
19
22
  }
20
23
  export interface UnifiedMessageRecipient {
21
24
  phoneNumber: string;
22
- variables?: Record<string, any>;
25
+ variables?: Record<string, unknown>;
23
26
  }
24
27
  export interface UnifiedMessageSendOptions {
25
28
  channel: MessageType;
26
29
  recipients: Array<string | UnifiedMessageRecipient>;
27
30
  providerId?: string;
28
31
  templateCode?: string;
29
- variables?: Record<string, any>;
32
+ variables?: Record<string, unknown>;
30
33
  text?: string;
31
34
  subject?: string;
32
35
  imageUrl?: string;
@@ -35,7 +38,7 @@ export interface UnifiedMessageSendOptions {
35
38
  scheduledAt?: Date;
36
39
  senderNumber?: string;
37
40
  subject?: string;
38
- [key: string]: any;
41
+ [key: string]: unknown;
39
42
  };
40
43
  }
41
44
  export type MessageSendOptions = LegacyMessageSendOptions | UnifiedMessageSendOptions;
@@ -56,10 +59,19 @@ export interface MessageSendResult {
56
59
  }
57
60
  export interface KMsg {
58
61
  getInfo(): PlatformInfo;
59
- registerProvider(provider: any): void;
60
- getProvider(providerId: string): any | null;
62
+ registerProvider(provider: BaseProvider): void;
63
+ getProvider(providerId: string): BaseProvider | null;
61
64
  listProviders(): string[];
62
65
  healthCheck(): Promise<PlatformHealthStatus>;
66
+ balance(providerId?: string): Promise<{
67
+ get(query?: BalanceQuery): Promise<BalanceResult>;
68
+ }>;
69
+ history(providerId?: string): Promise<{
70
+ list(query: HistoryQuery): Promise<HistoryResult>;
71
+ list(page?: number, pageSize?: number, filters?: Partial<Omit<HistoryQuery, "page" | "pageSize">> & {
72
+ channel?: HistoryQuery["channel"];
73
+ }): Promise<HistoryResult>;
74
+ }>;
63
75
  messages: {
64
76
  send(options: MessageSendOptions): Promise<MessageSendResult>;
65
77
  getStatus(messageId: string): Promise<string>;
@@ -25,13 +25,13 @@ export interface StandardError {
25
25
  code: StandardErrorCode;
26
26
  message: string;
27
27
  retryable: boolean;
28
- details?: Record<string, any>;
28
+ details?: Record<string, unknown>;
29
29
  }
30
30
  export interface StandardRequest {
31
31
  channel?: MessageType;
32
32
  templateCode: string;
33
33
  phoneNumber: string;
34
- variables: Record<string, any>;
34
+ variables: Record<string, unknown>;
35
35
  text?: string;
36
36
  imageUrl?: string;
37
37
  buttons?: Button[];
@@ -39,6 +39,31 @@ export interface StandardRequest {
39
39
  scheduledAt?: Date;
40
40
  senderNumber?: string;
41
41
  subject?: string;
42
+ /**
43
+ * Provider-specific KakaoTalk options (e.g. SOLAPI kakaoOptions).
44
+ */
45
+ kakaoOptions?: {
46
+ pfId?: string;
47
+ templateId?: string;
48
+ variables?: Record<string, string>;
49
+ disableSms?: boolean;
50
+ adFlag?: boolean;
51
+ buttons?: unknown[];
52
+ imageId?: string;
53
+ [key: string]: unknown;
54
+ };
55
+ /**
56
+ * Provider-specific RCS options (e.g. SOLAPI rcsOptions).
57
+ */
58
+ rcsOptions?: {
59
+ brandId?: string;
60
+ templateId?: string;
61
+ variables?: Record<string, string>;
62
+ disableSms?: boolean;
63
+ buttons?: unknown[];
64
+ additionalBody?: unknown;
65
+ [key: string]: unknown;
66
+ };
42
67
  [key: string]: any;
43
68
  };
44
69
  }
@@ -49,7 +74,7 @@ export interface StandardResult {
49
74
  timestamp: Date;
50
75
  phoneNumber: string;
51
76
  error?: StandardError;
52
- metadata?: Record<string, any>;
77
+ metadata?: Record<string, unknown>;
53
78
  }
54
79
  export declare enum TemplateCategory {
55
80
  AUTHENTICATION = "AUTHENTICATION",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k-msg/core",
3
- "version": "0.1.6",
3
+ "version": "0.3.0",
4
4
  "packageManager": "bun@1.3.8",
5
5
  "description": "Core types and interfaces for K-Message platform",
6
6
  "type": "module",