@k-msg/core 0.1.5 → 0.2.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/README.md +23 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +25 -25
- package/dist/index.js.map +5 -4
- package/dist/index.mjs +25 -25
- package/dist/index.mjs.map +5 -4
- package/dist/platform.d.ts +20 -10
- package/dist/router/round-robin-router-provider.d.ts +20 -0
- package/dist/types/balance.d.ts +12 -0
- package/dist/types/history.d.ts +31 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/platform.d.ts +19 -7
- package/package.json +1 -1
package/dist/platform.d.ts
CHANGED
|
@@ -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: (
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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
|
-
*
|
|
54
|
-
*
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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,20 @@
|
|
|
1
|
+
import type { BaseProvider, ProviderHealthStatus, StandardRequest, StandardResult } from "../types/index";
|
|
2
|
+
/**
|
|
3
|
+
* Round-robin router provider that forwards requests to upstream providers.
|
|
4
|
+
* Useful for simple load distribution or provider rotation strategies.
|
|
5
|
+
*/
|
|
6
|
+
export declare class RoundRobinRouterProvider implements BaseProvider<StandardRequest, StandardResult> {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly type: "messaging";
|
|
10
|
+
readonly version = "1.0.0";
|
|
11
|
+
private readonly providers;
|
|
12
|
+
private idx;
|
|
13
|
+
constructor(params: {
|
|
14
|
+
id: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
providers: BaseProvider<StandardRequest, StandardResult>[];
|
|
17
|
+
});
|
|
18
|
+
healthCheck(): Promise<ProviderHealthStatus>;
|
|
19
|
+
send<T extends StandardRequest = StandardRequest, R extends StandardResult = StandardResult>(request: T): Promise<R>;
|
|
20
|
+
}
|
|
@@ -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,31 @@
|
|
|
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
|
+
phone?: string;
|
|
10
|
+
requestNo?: string;
|
|
11
|
+
companyId?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface HistoryItem {
|
|
14
|
+
providerId: string;
|
|
15
|
+
channel: HistoryChannel;
|
|
16
|
+
messageId: string;
|
|
17
|
+
to?: string;
|
|
18
|
+
from?: string;
|
|
19
|
+
status?: string;
|
|
20
|
+
statusCode?: string;
|
|
21
|
+
statusMessage?: string;
|
|
22
|
+
sentAt?: Date;
|
|
23
|
+
raw: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface HistoryResult {
|
|
26
|
+
providerId: string;
|
|
27
|
+
channel: HistoryChannel;
|
|
28
|
+
totalCount: number;
|
|
29
|
+
items: HistoryItem[];
|
|
30
|
+
raw?: unknown;
|
|
31
|
+
}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/platform.d.ts
CHANGED
|
@@ -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,
|
|
19
|
+
variables?: Record<string, unknown>;
|
|
17
20
|
}[];
|
|
18
|
-
variables: Record<string,
|
|
21
|
+
variables: Record<string, unknown>;
|
|
19
22
|
}
|
|
20
23
|
export interface UnifiedMessageRecipient {
|
|
21
24
|
phoneNumber: string;
|
|
22
|
-
variables?: Record<string,
|
|
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,
|
|
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]:
|
|
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:
|
|
60
|
-
getProvider(providerId: string):
|
|
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>;
|