@k-msg/core 0.1.1 → 0.1.3

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,76 @@
1
+ import type { DeliveryStatus, StandardRequest, StandardResult } from "./standard";
2
+ export type ProviderType = "messaging" | "sms" | "email" | "push" | "voice";
3
+ export interface ProviderConfig {
4
+ apiKey: string;
5
+ baseUrl: string;
6
+ timeout?: number;
7
+ retries?: number;
8
+ debug?: boolean;
9
+ [key: string]: any;
10
+ }
11
+ export interface ConfigurationSchema {
12
+ required: ConfigField[];
13
+ optional: ConfigField[];
14
+ }
15
+ export interface ConfigField {
16
+ key: string;
17
+ type: "string" | "number" | "boolean" | "url" | "secret";
18
+ description: string;
19
+ validation?: {
20
+ pattern?: string;
21
+ min?: number;
22
+ max?: number;
23
+ enum?: string[];
24
+ };
25
+ }
26
+ export interface ProviderHealthStatus {
27
+ healthy: boolean;
28
+ issues: string[];
29
+ latency?: number;
30
+ data?: Record<string, unknown>;
31
+ }
32
+ export interface ProviderMetadata {
33
+ id: string;
34
+ name: string;
35
+ version: string;
36
+ description?: string;
37
+ supportedFeatures: string[];
38
+ capabilities: Record<string, any>;
39
+ endpoints: Record<string, string>;
40
+ authType?: string;
41
+ responseFormat?: string;
42
+ }
43
+ export interface ProviderFactoryConfig {
44
+ providers: Record<string, ProviderConfig>;
45
+ }
46
+ export declare abstract class BaseProviderAdapter {
47
+ protected config: ProviderConfig;
48
+ constructor(config: ProviderConfig);
49
+ abstract adaptRequest(request: StandardRequest): any;
50
+ abstract adaptResponse(response: any): StandardResult;
51
+ abstract mapError(error: any): import("./standard").StandardError;
52
+ abstract getAuthHeaders(): Record<string, string>;
53
+ abstract getBaseUrl(): string;
54
+ abstract getEndpoint(operation: string): string;
55
+ getRequestConfig(): RequestInit;
56
+ validateResponse(response: Response): boolean;
57
+ protected generateMessageId(): string;
58
+ protected log(message: string, data?: any): void;
59
+ isRetryableError(error: any): boolean;
60
+ }
61
+ export interface BaseProvider<TRequest = StandardRequest, TResult = StandardResult> {
62
+ readonly id: string;
63
+ readonly name: string;
64
+ readonly type: string;
65
+ readonly version: string;
66
+ healthCheck(): Promise<ProviderHealthStatus>;
67
+ send<T extends TRequest = TRequest, R extends TResult = TResult>(request: T): Promise<R>;
68
+ getStatus?(requestId: string): Promise<DeliveryStatus>;
69
+ cancel?(requestId: string): Promise<boolean>;
70
+ destroy?(): void;
71
+ }
72
+ export interface AdapterFactory {
73
+ create(config: ProviderConfig): any;
74
+ supports(providerId: string): boolean;
75
+ getMetadata(): ProviderMetadata;
76
+ }
@@ -0,0 +1,62 @@
1
+ import type { Button, MessageType } from "./message";
2
+ export interface DeliveryStatus {
3
+ status: "pending" | "sent" | "delivered" | "failed" | "cancelled";
4
+ timestamp: Date;
5
+ details?: Record<string, unknown>;
6
+ }
7
+ export declare enum StandardStatus {
8
+ PENDING = "PENDING",
9
+ SENT = "SENT",
10
+ DELIVERED = "DELIVERED",
11
+ FAILED = "FAILED",
12
+ CANCELLED = "CANCELLED"
13
+ }
14
+ export declare enum StandardErrorCode {
15
+ UNKNOWN_ERROR = "UNKNOWN_ERROR",
16
+ INVALID_REQUEST = "INVALID_REQUEST",
17
+ AUTHENTICATION_FAILED = "AUTHENTICATION_FAILED",
18
+ INSUFFICIENT_BALANCE = "INSUFFICIENT_BALANCE",
19
+ TEMPLATE_NOT_FOUND = "TEMPLATE_NOT_FOUND",
20
+ RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED",
21
+ PROVIDER_ERROR = "PROVIDER_ERROR",
22
+ NETWORK_ERROR = "NETWORK_ERROR"
23
+ }
24
+ export interface StandardError {
25
+ code: StandardErrorCode;
26
+ message: string;
27
+ retryable: boolean;
28
+ details?: Record<string, any>;
29
+ }
30
+ export interface StandardRequest {
31
+ channel?: MessageType;
32
+ templateCode: string;
33
+ phoneNumber: string;
34
+ variables: Record<string, any>;
35
+ text?: string;
36
+ imageUrl?: string;
37
+ buttons?: Button[];
38
+ options?: {
39
+ scheduledAt?: Date;
40
+ senderNumber?: string;
41
+ subject?: string;
42
+ [key: string]: any;
43
+ };
44
+ }
45
+ export interface StandardResult {
46
+ messageId: string;
47
+ status: StandardStatus;
48
+ provider: string;
49
+ timestamp: Date;
50
+ phoneNumber: string;
51
+ error?: StandardError;
52
+ metadata?: Record<string, any>;
53
+ }
54
+ export declare enum TemplateCategory {
55
+ AUTHENTICATION = "AUTHENTICATION",
56
+ NOTIFICATION = "NOTIFICATION",
57
+ PROMOTION = "PROMOTION",
58
+ INFORMATION = "INFORMATION",
59
+ RESERVATION = "RESERVATION",
60
+ SHIPPING = "SHIPPING",
61
+ PAYMENT = "PAYMENT"
62
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Universal Provider Implementation
3
+ * 어댑터 패턴을 사용한 범용 프로바이더
4
+ */
5
+ import { type BaseProvider, type BaseProviderAdapter, type ConfigurationSchema, type DeliveryStatus, type ProviderHealthStatus, type StandardRequest, type StandardResult } from "./types/index";
6
+ /**
7
+ * 어댑터 기반 범용 프로바이더
8
+ * 모든 프로바이더가 이 클래스를 사용하여 표준 인터페이스 구현
9
+ */
10
+ export declare class UniversalProvider implements BaseProvider<StandardRequest, StandardResult> {
11
+ readonly id: string;
12
+ readonly name: string;
13
+ readonly type: "messaging";
14
+ readonly version: string;
15
+ private adapter;
16
+ private config;
17
+ private isConfigured;
18
+ constructor(adapter: BaseProviderAdapter, metadata: {
19
+ id: string;
20
+ name: string;
21
+ version: string;
22
+ });
23
+ configure(config: Record<string, unknown>): void;
24
+ isReady(): boolean;
25
+ healthCheck(): Promise<ProviderHealthStatus>;
26
+ destroy(): void;
27
+ send<T extends StandardRequest = StandardRequest, R extends StandardResult = StandardResult>(request: T): Promise<R>;
28
+ getStatus(requestId: string): Promise<DeliveryStatus>;
29
+ cancel(requestId: string): Promise<boolean>;
30
+ getCapabilities(): any;
31
+ getSupportedFeatures(): string[];
32
+ getConfigurationSchema(): ConfigurationSchema;
33
+ /**
34
+ * HTTP 요청 실행
35
+ */
36
+ private makeHttpRequest;
37
+ /**
38
+ * 표준 상태를 DeliveryStatus로 변환
39
+ */
40
+ private mapStandardStatusToDeliveryStatus;
41
+ /**
42
+ * 어댑터 인스턴스 반환 (고급 사용자용)
43
+ */
44
+ getAdapter(): BaseProviderAdapter;
45
+ /**
46
+ * 프로바이더 메타데이터 반환
47
+ */
48
+ getMetadata(): {
49
+ id: string;
50
+ name: string;
51
+ version: string;
52
+ type: "messaging";
53
+ adapter: string;
54
+ };
55
+ }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@k-msg/core",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
+ "packageManager": "bun@1.3.8",
4
5
  "description": "Core types and interfaces for K-Message platform",
5
6
  "type": "module",
6
7
  "main": "./dist/index.js",
@@ -17,15 +18,27 @@
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'",
23
+ "build:cjs": "bun build ./src/index.ts --outdir ./dist --format cjs --minify --sourcemap --entry-naming '[name].js' --external 'bun:test'",
24
+ "build:types": "tsc",
21
25
  "dev": "tsc --watch",
22
- "test": "bun test",
23
- "clean": "rm -rf dist"
26
+ "test": "bun run test:unit",
27
+ "test:unit": "bun test --testPathPattern='.*\\.test\\.(ts|js)$' --testTimeout=5000",
28
+ "test:integration": "bun test --testPathPattern='.*\\.integration\\.(ts|js)$' --testTimeout=10000",
29
+ "test:e2e": "bun test --testPathPattern='.*\\.e2e\\.(ts|js)$' --testTimeout=30000",
30
+ "test:coverage": "bun test --coverage",
31
+ "test:watch": "bun test --watch",
32
+ "typecheck": "tsc --noEmit",
33
+ "clean": "rm -rf dist",
34
+ "pack": "bun pm pack",
35
+ "publish": "bun publish --access public"
36
+ },
37
+ "dependencies": {
38
+ "zod": "^4.0.14"
24
39
  },
25
- "dependencies": {},
26
40
  "devDependencies": {
27
41
  "@types/bun": "latest",
28
- "tsup": "^8.5.0",
29
42
  "typescript": "^5.0.0"
30
43
  },
31
44
  "peerDependencies": {},
@@ -42,12 +55,12 @@
42
55
  ],
43
56
  "repository": {
44
57
  "type": "git",
45
- "url": "git+https://github.com/k-otp/k-message.git"
58
+ "url": "git+https://github.com/k-otp/k-msg.git"
46
59
  },
47
- "homepage": "https://github.com/k-otp/k-message",
60
+ "homepage": "https://github.com/k-otp/k-msg",
48
61
  "bugs": {
49
- "url": "https://github.com/k-otp/k-message/issues"
62
+ "url": "https://github.com/k-otp/k-msg/issues"
50
63
  },
51
64
  "author": "imjlk",
52
65
  "license": "MIT"
53
- }
66
+ }