deliveryapi 0.1.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.
@@ -0,0 +1,417 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ declare class HttpClient {
4
+ private readonly baseUrl;
5
+ private readonly authHeader;
6
+ constructor(apiKey: string, secretKey: string, baseUrl: string);
7
+ get<T>(path: string, params?: Record<string, string>): Promise<T>;
8
+ post<T>(path: string, body?: unknown): Promise<T>;
9
+ patch<T>(path: string, body?: unknown): Promise<T>;
10
+ delete<T>(path: string): Promise<T>;
11
+ private request;
12
+ }
13
+ /**
14
+ * Firebase Timestamp 호환 인터페이스
15
+ * firebase-admin/firestore 및 firebase/firestore의 Timestamp와 구조적으로 호환됨
16
+ */
17
+ export interface Timestamp {
18
+ seconds: number;
19
+ nanoseconds: number;
20
+ toDate(): Date;
21
+ toMillis(): number;
22
+ isEqual(other: Timestamp): boolean;
23
+ valueOf(): string;
24
+ }
25
+ /**
26
+ * 통일된 API 응답 형식
27
+ */
28
+ export interface ApiResponse<T = unknown> {
29
+ isSuccess: boolean;
30
+ statusCode?: number;
31
+ data?: T;
32
+ error?: string;
33
+ message?: string;
34
+ }
35
+ /**
36
+ * 택배 배송 상태 열거형
37
+ * 모든 택배사의 상태를 통합하여 정규화
38
+ *
39
+ * 📌 프로젝트별 차이점:
40
+ * - delivery-saas-api-functions (이 프로젝트): enum만 정의 (데이터 반환용)
41
+ * - farmsns-admin_new, farmsns-functions_new, farmfree-mobile:
42
+ * → CourierDeliveryStatusLabels (한글 라벨)
43
+ * → LotteStatusMapping, CJStatusMapping (택배사별 매핑)
44
+ * → Helper 함수들 (mapCourierStatus, isDeliveryInProgress 등)
45
+ *
46
+ * 이유: delivery-saas-api는 외부 API 역할로 데이터 반환만 수행하므로
47
+ * UI 표시용 라벨이나 변환 로직이 불필요
48
+ */
49
+ export declare enum CourierDeliveryStatus {
50
+ PENDING = "PENDING",// 접수 대기
51
+ REGISTERED = "REGISTERED",// 접수 완료
52
+ PICKUP_READY = "PICKUP_READY",// 집하 준비
53
+ PICKED_UP = "PICKED_UP",// 집하 완료
54
+ IN_TRANSIT = "IN_TRANSIT",// 배송 중
55
+ OUT_FOR_DELIVERY = "OUT_FOR_DELIVERY",// 배송 출발
56
+ DELIVERED = "DELIVERED",// 배송 완료
57
+ FAILED = "FAILED",// 배송 실패
58
+ RETURNED = "RETURNED",// 반송
59
+ CANCELLED = "CANCELLED",// 취소
60
+ HOLD = "HOLD",// 보류
61
+ UNKNOWN = "UNKNOWN"
62
+ }
63
+ declare const COURIER_CODES: {
64
+ readonly LOTTE: "lotte";
65
+ readonly CJ: "cj";
66
+ readonly POST: "post";
67
+ readonly HANJIN: "hanjin";
68
+ readonly LOGEN: "logen";
69
+ readonly GSPOSTBOX: "gspostbox";
70
+ readonly ILYANG: "ilyang";
71
+ readonly KYUNGDONG: "kyungdong";
72
+ readonly DAESIN: "daesin";
73
+ readonly HAPDONG: "hapdong";
74
+ readonly COUPANG: "coupang";
75
+ };
76
+ export type CourierCode = (typeof COURIER_CODES)[keyof typeof COURIER_CODES];
77
+ /**
78
+ * 인증 방식 타입
79
+ */
80
+ export type AuthMethod = "2FA_SMS" | "2FA_EMAIL" | "2FA_KAKAO" | "2FA_OTP";
81
+ /**
82
+ * 인증 코드 타입
83
+ */
84
+ export type AuthCodeType = "NUMERIC" | "ALPHANUMERIC";
85
+ /**
86
+ * 택배사 정보 인터페이스
87
+ */
88
+ export interface CourierInfo {
89
+ id: CourierCode;
90
+ trackingApiCode: CourierCode;
91
+ displayName: string;
92
+ icon: string;
93
+ supportsTracking: boolean;
94
+ supportsAccount: boolean;
95
+ adminUrl: string;
96
+ trackingUrl: string;
97
+ customerServicePhone: string;
98
+ requires2FA: boolean;
99
+ authMethod?: AuthMethod | null;
100
+ authCodeLength?: number | null;
101
+ authCodeType?: AuthCodeType | null;
102
+ supportsAutoReauth: boolean;
103
+ allowsMultipleSessions: boolean;
104
+ reauthMessage: string;
105
+ accessTokenDurationMinutes: number;
106
+ maxInquiryDays: number;
107
+ }
108
+ /**
109
+ * 개별 택배 조회 항목
110
+ */
111
+ export interface TrackingItem {
112
+ id?: string;
113
+ clientId?: string;
114
+ courierCode: string;
115
+ trackingNumber: string;
116
+ }
117
+ /**
118
+ * 택배 진행 상황
119
+ */
120
+ export interface TrackingProgress {
121
+ dateTime: string;
122
+ location: string;
123
+ status: string;
124
+ statusCode?: CourierDeliveryStatus;
125
+ description?: string;
126
+ telno?: string;
127
+ telno2?: string;
128
+ }
129
+ /**
130
+ * 통합 택배 조회 응답
131
+ */
132
+ export interface UnifiedTrackingResponse {
133
+ trackingNumber: string;
134
+ courierCode: string;
135
+ courierName: string;
136
+ deliveryStatus: CourierDeliveryStatus;
137
+ deliveryStatusText: string;
138
+ isDelivered: boolean;
139
+ senderName?: string;
140
+ receiverName?: string;
141
+ receiverAddress?: string;
142
+ productName?: string;
143
+ productQuantity?: number;
144
+ dateDelivered?: string;
145
+ dateEstimated?: string;
146
+ dateLastProgress: string;
147
+ progresses: TrackingProgress[];
148
+ queriedAt: string;
149
+ }
150
+ /**
151
+ * 택배 조회 에러 코드
152
+ *
153
+ * 과금 정책:
154
+ * - NOT_FOUND만 과금 (택배사 API를 호출했으나 데이터 없음 = 사용자 책임)
155
+ * - 나머지는 비과금 (요청 검증 실패 또는 시스템 오류)
156
+ */
157
+ export type TrackingErrorCode = "MISSING_PARAMS" | "INVALID_TRACKING_NUMBER" | "UNSUPPORTED_COURIER" | "NOT_FOUND" | "TRACKING_FAILED";
158
+ /**
159
+ * 택배 조회 오류
160
+ */
161
+ export interface TrackingError {
162
+ code: TrackingErrorCode;
163
+ message: string;
164
+ courierCode?: string;
165
+ trackingNumber?: string;
166
+ details?: unknown;
167
+ billable: boolean;
168
+ }
169
+ /**
170
+ * 캐시 메타데이터
171
+ */
172
+ export interface TrackingCacheInfo {
173
+ fromCache: boolean;
174
+ cachedAt?: string;
175
+ }
176
+ /**
177
+ * 개별 택배 조회 결과
178
+ */
179
+ export interface TrackingResult {
180
+ id?: string;
181
+ clientId?: string;
182
+ success: boolean;
183
+ data?: UnifiedTrackingResponse;
184
+ error?: TrackingError;
185
+ cache?: TrackingCacheInfo;
186
+ }
187
+ /**
188
+ * 택배 조회 응답 (배열로 다건 응답)
189
+ */
190
+ export interface TrackingResponse {
191
+ results: TrackingResult[];
192
+ summary: {
193
+ total: number;
194
+ successful: number;
195
+ failed: number;
196
+ billable: number;
197
+ };
198
+ }
199
+ /**
200
+ * 웹훅 엔드포인트 (apiKeys 문서에 저장)
201
+ * API Key당 최대 10개 등록 가능
202
+ */
203
+ export interface WebhookEndpoint {
204
+ id: string;
205
+ url: string;
206
+ name?: string;
207
+ webhookSecret: string;
208
+ webhookSecretHash: string;
209
+ status: "active" | "inactive";
210
+ dateCreated: Timestamp;
211
+ dateModified: Timestamp;
212
+ }
213
+ /**
214
+ * 구독 상태
215
+ */
216
+ export type SubscriptionStatus = "active" | "completed" | "cancelled" | "failed";
217
+ /**
218
+ * 택배 조회 구독 (trackingSubscriptions 컬렉션)
219
+ */
220
+ export interface TrackingSubscription {
221
+ id: string;
222
+ clientId?: string;
223
+ customerId: string;
224
+ apiKeyHash: string;
225
+ courierCode: string;
226
+ trackingNumber: string;
227
+ endpointId: string;
228
+ subscribedStatuses: CourierDeliveryStatus[];
229
+ currentStatus: CourierDeliveryStatus;
230
+ lastPolledAt: Timestamp;
231
+ nextPollAt: Timestamp;
232
+ status: SubscriptionStatus;
233
+ failureCount: number;
234
+ metadata?: Record<string, string>;
235
+ dateCreated: Timestamp;
236
+ dateModified: Timestamp;
237
+ }
238
+ /**
239
+ * 웹훅 페이로드
240
+ */
241
+ export interface WebhookPayload {
242
+ event: "tracking.status_changed";
243
+ subscriptionId: string;
244
+ timestamp: string;
245
+ data: {
246
+ courierCode: string;
247
+ trackingNumber: string;
248
+ previousStatus?: CourierDeliveryStatus;
249
+ currentStatus: CourierDeliveryStatus;
250
+ tracking: UnifiedTrackingResponse;
251
+ };
252
+ metadata?: Record<string, string>;
253
+ }
254
+ export interface DeliverySaasClientConfig {
255
+ /** API Key (발급받은 API Key) */
256
+ apiKey: string;
257
+ /** Secret Key (발급받은 Secret Key) */
258
+ secretKey: string;
259
+ /** API Base URL (기본값: https://api.deliveryapi.co.kr) */
260
+ baseUrl?: string;
261
+ }
262
+ export interface TrackingRequestInput {
263
+ items: TrackingItem[];
264
+ includeProgresses?: boolean;
265
+ }
266
+ export interface SubscriptionCreateInput {
267
+ courierCode: string;
268
+ trackingNumber: string;
269
+ endpointId: string;
270
+ subscribedStatuses?: CourierDeliveryStatus[];
271
+ clientId?: string;
272
+ metadata?: Record<string, string>;
273
+ }
274
+ export interface SubscriptionListResult {
275
+ subscriptions: TrackingSubscription[];
276
+ total: number;
277
+ }
278
+ export interface WebhookCreateInput {
279
+ url: string;
280
+ name?: string;
281
+ }
282
+ export interface WebhookListResult {
283
+ endpoints: WebhookEndpoint[];
284
+ total: number;
285
+ }
286
+ export interface WebhookTestResult {
287
+ success: boolean;
288
+ statusCode?: number;
289
+ message?: string;
290
+ }
291
+ export interface CourierListResult {
292
+ couriers: CourierInfo[];
293
+ }
294
+ declare class TrackingResource {
295
+ private readonly http;
296
+ constructor(http: HttpClient);
297
+ /**
298
+ * 택배 조회 (공개 API, 계정 불필요)
299
+ * @param items 조회할 택배 목록 (1건도 배열로)
300
+ * @param includeProgresses 진행 내역 포함 여부 (기본값: true)
301
+ */
302
+ get(items: TrackingRequestInput["items"], includeProgresses?: boolean): Promise<TrackingResponse>;
303
+ /**
304
+ * 단건 택배 조회 (편의 메서드)
305
+ */
306
+ getOne(courierCode: string, trackingNumber: string, options?: {
307
+ clientId?: string;
308
+ includeProgresses?: boolean;
309
+ }): Promise<TrackingResponse>;
310
+ }
311
+ declare class SubscriptionsResource {
312
+ private readonly http;
313
+ constructor(http: HttpClient);
314
+ /**
315
+ * 택배 구독 생성
316
+ * 상태 변경 시 등록된 웹훅 엔드포인트로 알림 전송
317
+ */
318
+ create(data: SubscriptionCreateInput): Promise<TrackingSubscription>;
319
+ /**
320
+ * 택배 구독 목록 조회
321
+ */
322
+ list(options?: {
323
+ status?: string;
324
+ page?: number;
325
+ pageSize?: number;
326
+ }): Promise<SubscriptionListResult>;
327
+ /**
328
+ * 택배 구독 상세 조회
329
+ */
330
+ retrieve(subscriptionId: string): Promise<TrackingSubscription>;
331
+ /**
332
+ * 택배 구독 취소
333
+ */
334
+ cancel(subscriptionId: string): Promise<void>;
335
+ }
336
+ declare class WebhooksResource {
337
+ private readonly http;
338
+ constructor(http: HttpClient);
339
+ /**
340
+ * 웹훅 엔드포인트 등록
341
+ */
342
+ create(data: WebhookCreateInput): Promise<WebhookEndpoint>;
343
+ /**
344
+ * 웹훅 엔드포인트 목록 조회
345
+ */
346
+ list(): Promise<WebhookListResult>;
347
+ /**
348
+ * 웹훅 엔드포인트 상세 조회
349
+ */
350
+ retrieve(endpointId: string): Promise<WebhookEndpoint>;
351
+ /**
352
+ * 웹훅 엔드포인트 삭제
353
+ */
354
+ delete(endpointId: string): Promise<void>;
355
+ /**
356
+ * 웹훅 엔드포인트 테스트 전송
357
+ */
358
+ test(endpointId: string): Promise<WebhookTestResult>;
359
+ }
360
+ declare class CouriersResource {
361
+ private readonly http;
362
+ constructor(http: HttpClient);
363
+ /**
364
+ * 지원 택배사 목록 조회
365
+ */
366
+ list(): Promise<CourierListResult>;
367
+ }
368
+ /**
369
+ * DeliverySaaS API Client
370
+ *
371
+ * @example
372
+ * ```typescript
373
+ * import { DeliverySaasClient } from 'deliveryapi'
374
+ *
375
+ * const client = new DeliverySaasClient({
376
+ * apiKey: 'your-api-key',
377
+ * secretKey: 'your-secret-key',
378
+ * })
379
+ *
380
+ * // 택배 조회
381
+ * const result = await client.tracking.getOne('LOTTE', '1234567890')
382
+ *
383
+ * // 구독 생성
384
+ * const subscription = await client.subscriptions.create({
385
+ * courierCode: 'LOTTE',
386
+ * trackingNumber: '1234567890',
387
+ * endpointId: 'ep_xxx',
388
+ * })
389
+ * ```
390
+ */
391
+ export declare class DeliverySaasClient {
392
+ readonly tracking: TrackingResource;
393
+ readonly subscriptions: SubscriptionsResource;
394
+ readonly webhooks: WebhooksResource;
395
+ readonly couriers: CouriersResource;
396
+ constructor(config: DeliverySaasClientConfig);
397
+ }
398
+ export declare class DeliverySaasError extends Error {
399
+ readonly statusCode: number;
400
+ readonly code?: string | undefined;
401
+ constructor(message: string, statusCode: number, code?: string | undefined);
402
+ }
403
+ export declare class AuthenticationError extends DeliverySaasError {
404
+ constructor(message?: string);
405
+ }
406
+ export declare class RateLimitError extends DeliverySaasError {
407
+ constructor(message?: string);
408
+ }
409
+ export declare class NotFoundError extends DeliverySaasError {
410
+ constructor(message?: string);
411
+ }
412
+
413
+ export {
414
+ TrackingItem as TrackingResponseItem,
415
+ };
416
+
417
+ export {};