deliveryapi 1.8.0 → 1.10.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/dist/index.js CHANGED
@@ -1,11 +1,62 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // ../shared-types/dist/courier/CourierDeliveryStatus.js
28
+ var require_CourierDeliveryStatus = __commonJS({
29
+ "../shared-types/dist/courier/CourierDeliveryStatus.js"(exports) {
30
+ "use strict";
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.CourierDeliveryStatus = void 0;
33
+ var CourierDeliveryStatus2;
34
+ (function(CourierDeliveryStatus3) {
35
+ CourierDeliveryStatus3["PENDING"] = "PENDING";
36
+ CourierDeliveryStatus3["REGISTERED"] = "REGISTERED";
37
+ CourierDeliveryStatus3["PICKUP_READY"] = "PICKUP_READY";
38
+ CourierDeliveryStatus3["PICKED_UP"] = "PICKED_UP";
39
+ CourierDeliveryStatus3["IN_TRANSIT"] = "IN_TRANSIT";
40
+ CourierDeliveryStatus3["OUT_FOR_DELIVERY"] = "OUT_FOR_DELIVERY";
41
+ CourierDeliveryStatus3["DELIVERED"] = "DELIVERED";
42
+ CourierDeliveryStatus3["FAILED"] = "FAILED";
43
+ CourierDeliveryStatus3["RETURNED"] = "RETURNED";
44
+ CourierDeliveryStatus3["CANCELLED"] = "CANCELLED";
45
+ CourierDeliveryStatus3["HOLD"] = "HOLD";
46
+ CourierDeliveryStatus3["UNKNOWN"] = "UNKNOWN";
47
+ })(CourierDeliveryStatus2 || (exports.CourierDeliveryStatus = CourierDeliveryStatus2 = {}));
48
+ }
49
+ });
50
+
1
51
  // src/http.ts
2
52
  var BASE_URL = "https://api.deliveryapi.co.kr";
3
53
  var ApiError = class extends Error {
4
- constructor(code, message, status) {
54
+ constructor(code, message, status, data) {
5
55
  super(message);
6
56
  this.name = "ApiError";
7
57
  this.code = code;
8
58
  this.status = status;
59
+ this.data = data;
9
60
  }
10
61
  };
11
62
  async function request(path, options, auth) {
@@ -27,7 +78,8 @@ async function request(path, options, auth) {
27
78
  throw new ApiError(
28
79
  json.errorCode ?? "INTERNAL_ERROR",
29
80
  json.error ?? json.message ?? `HTTP ${res.status}`,
30
- json.statusCode ?? res.status
81
+ res.status,
82
+ json.data
31
83
  );
32
84
  }
33
85
  return json.data;
@@ -252,7 +304,7 @@ var SubscriptionsResource = class {
252
304
  async list(params) {
253
305
  return request(
254
306
  "/v1/webhooks/subscriptions",
255
- { params: { cursor: params?.cursor, limit: params?.limit } },
307
+ { params: { cursor: params?.cursor, limit: params?.limit, status: params?.status, from: params?.from, to: params?.to } },
256
308
  this.auth
257
309
  );
258
310
  }
@@ -322,6 +374,374 @@ var WebhooksResource = class {
322
374
  }
323
375
  };
324
376
 
377
+ // src/resources/accounts.ts
378
+ var AccountsResource = class {
379
+ constructor(auth) {
380
+ this.auth = auth;
381
+ }
382
+ /**
383
+ * 택배사 계정을 등록합니다.
384
+ *
385
+ * 롯데택배, CJ대한통운 계정을 등록할 수 있습니다.
386
+ * CJ대한통운은 2FA(OTP) 인증이 필요할 수 있으며, 이 경우 `COURIER_OTP_REQUIRED` 에러가 발생합니다.
387
+ *
388
+ * @param params - 계정 등록 파라미터
389
+ * @returns 등록된 계정 정보 (courierAccountKey 포함)
390
+ * @throws {ApiError} COURIER_OTP_REQUIRED — CJ 계정 OTP 인증 필요
391
+ * @throws {ApiError} COURIER_AUTH_FAILED — 계정 인증 실패 (아이디/비밀번호 오류)
392
+ * @throws {ApiError} FORBIDDEN — 계정 슬롯 한도 초과
393
+ *
394
+ * @example
395
+ * const account = await client.courier.accounts.register({
396
+ * providerId: 'lotte',
397
+ * accountId: 'my-lotte-id',
398
+ * accountPassword: 'my-password',
399
+ * accountName: '메인 롯데 계정',
400
+ * })
401
+ * console.log(account.courierAccountKey) // 이후 API 호출에 사용
402
+ */
403
+ async register(params) {
404
+ return request(
405
+ "/v1/courier/accounts/register",
406
+ { method: "POST", body: params },
407
+ this.auth
408
+ );
409
+ }
410
+ /**
411
+ * 등록된 택배사 계정 목록을 조회합니다.
412
+ *
413
+ * @returns 계정 목록 (courierAccountKey, providerId, isActive 등)
414
+ *
415
+ * @example
416
+ * const accounts = await client.courier.accounts.list()
417
+ * const active = accounts.filter(a => a.isActive)
418
+ * console.log(active[0].courierAccountKey)
419
+ */
420
+ async list() {
421
+ return request(
422
+ "/v1/courier/accounts",
423
+ {},
424
+ this.auth
425
+ );
426
+ }
427
+ /**
428
+ * 특정 택배사 계정의 상세 정보를 조회합니다.
429
+ *
430
+ * 목록 조회와 달리 `accountPassword` 필드가 포함됩니다 (항상 마스킹된 값).
431
+ * `expiresAt` 필드는 포함되지 않습니다.
432
+ *
433
+ * @param accountKey - 조회할 계정의 courierAccountKey
434
+ * @returns 계정 상세 정보
435
+ * @throws {ApiError} NOT_FOUND — 존재하지 않는 계정
436
+ *
437
+ * @example
438
+ * const detail = await client.courier.accounts.get('your-account-key')
439
+ * console.log(detail.accountId) // 'my-lotte-id'
440
+ * console.log(detail.accountPassword) // '(암호화하여 저장중)'
441
+ */
442
+ async get(accountKey) {
443
+ return request(
444
+ `/v1/courier/accounts/${accountKey}`,
445
+ {},
446
+ this.auth
447
+ );
448
+ }
449
+ /**
450
+ * 택배사 계정을 삭제합니다.
451
+ *
452
+ * @param accountKey - 삭제할 계정의 courierAccountKey
453
+ * @throws {ApiError} NOT_FOUND — 존재하지 않는 계정
454
+ *
455
+ * @example
456
+ * await client.courier.accounts.delete('your-account-key')
457
+ */
458
+ async delete(accountKey) {
459
+ await request(
460
+ `/v1/courier/accounts/${accountKey}`,
461
+ { method: "DELETE" },
462
+ this.auth
463
+ );
464
+ }
465
+ };
466
+
467
+ // src/resources/histories.ts
468
+ var HistoriesResource = class {
469
+ constructor(auth) {
470
+ this.auth = auth;
471
+ }
472
+ /**
473
+ * 대량 등록 이력 목록을 조회합니다.
474
+ *
475
+ * @param params - 조회 파라미터 (providerId 필수)
476
+ * @returns 이력 목록 (histories 배열)
477
+ *
478
+ * @example
479
+ * const { histories } = await client.courier.deliveries.histories.list({
480
+ * providerId: 'lotte',
481
+ * courierAccountKey: 'your-key',
482
+ * limit: 20,
483
+ * })
484
+ * const completed = histories.filter(h => h.status === 'completed')
485
+ */
486
+ async list(params) {
487
+ return request(
488
+ "/v1/courier/deliveries/bulk-upload-histories",
489
+ {
490
+ method: "GET",
491
+ params: {
492
+ providerId: params.providerId,
493
+ courierAccountKey: params.courierAccountKey,
494
+ fromDate: params.fromDate,
495
+ toDate: params.toDate,
496
+ limit: params.limit
497
+ }
498
+ },
499
+ this.auth
500
+ );
501
+ }
502
+ /**
503
+ * 대량 등록 이력의 상세 정보를 조회합니다.
504
+ *
505
+ * 택배사 API를 호출하여 실시간 배송 상태를 함께 반환합니다.
506
+ *
507
+ * @param historyId - 이력 ID
508
+ * @param params - 조회 파라미터 (courierAccountKey 필수)
509
+ * @returns 이력 정보 + 실시간 배송 상태 (detailItems)
510
+ * @throws {ApiError} NOT_FOUND — 존재하지 않는 이력 또는 계정
511
+ *
512
+ * @example
513
+ * const { history, detailItems } = await client.courier.deliveries.histories.get(
514
+ * '202603221456_a1b2c',
515
+ * { courierAccountKey: 'your-key' },
516
+ * )
517
+ * const delivered = detailItems.filter(d => d.isDelivered)
518
+ */
519
+ async get(historyId, params) {
520
+ return request(
521
+ `/v1/courier/deliveries/bulk-upload-histories/${historyId}/detail`,
522
+ {
523
+ method: "GET",
524
+ params: { courierAccountKey: params.courierAccountKey }
525
+ },
526
+ this.auth
527
+ );
528
+ }
529
+ /**
530
+ * 대량 등록 이력을 삭제(취소)합니다.
531
+ *
532
+ * `courierDeliveryIds`를 지정하면 부분 취소, 생략하면 전체 취소(soft delete)입니다.
533
+ * 택배사 API를 호출하여 실제 접수도 취소합니다.
534
+ *
535
+ * @param historyId - 이력 ID
536
+ * @param params - 삭제 파라미터 (courierAccountKey 필수)
537
+ * @throws {ApiError} NOT_FOUND — 존재하지 않는 이력 또는 계정
538
+ *
539
+ * @example
540
+ * // 전체 취소
541
+ * await client.courier.deliveries.histories.delete('202603221456_a1b2c', {
542
+ * courierAccountKey: 'your-key',
543
+ * })
544
+ *
545
+ * // 부분 취소
546
+ * await client.courier.deliveries.histories.delete('202603221456_a1b2c', {
547
+ * courierAccountKey: 'your-key',
548
+ * courierDeliveryIds: ['7705241632'],
549
+ * })
550
+ */
551
+ async delete(historyId, params) {
552
+ await request(
553
+ `/v1/courier/deliveries/bulk-upload-histories/${historyId}`,
554
+ {
555
+ method: "DELETE",
556
+ params: { courierAccountKey: params.courierAccountKey },
557
+ body: params.courierDeliveryIds ? { courierDeliveryIds: params.courierDeliveryIds } : void 0
558
+ },
559
+ this.auth
560
+ );
561
+ }
562
+ };
563
+
564
+ // src/resources/deliveries.ts
565
+ var DeliveriesResource = class {
566
+ constructor(auth) {
567
+ this.auth = auth;
568
+ this.histories = new HistoriesResource(auth);
569
+ }
570
+ /**
571
+ * 택배를 대량 등록합니다. 최대 1,000건까지 한 번에 등록 가능합니다.
572
+ *
573
+ * 등록 직후에는 관리번호(courierDeliveryId)만 발급됩니다.
574
+ * 송장번호(trackingNumber)는 **송장 출력 시점에 발급**됩니다.
575
+ *
576
+ * HTTP 200으로 응답하며, `success`는 전체 성공 여부입니다.
577
+ * 부분 실패가 가능하므로 반드시 `results[].success`로 개별 확인하세요.
578
+ *
579
+ * @param params - 대량 등록 요청 파라미터
580
+ * @returns 등록 결과 (부분 성공 포함, results[].success로 개별 확인)
581
+ * @throws {ApiError} RATE_LIMITED — 요청 한도 초과
582
+ * @throws {ApiError} FORBIDDEN — 계정 슬롯 한도 초과
583
+ *
584
+ * @example
585
+ * const result = await client.courier.deliveries.bulkUpload({
586
+ * courierAccountKey: 'your-key',
587
+ * items: [{
588
+ * clientOrderId: 'ORD-001',
589
+ * receiverName: '홍길동',
590
+ * receiverPhone1: '01012345678',
591
+ * receiverAddress: '서울특별시 중구 세종대로 110',
592
+ * productName: '테스트 상품',
593
+ * quantity: 1,
594
+ * }],
595
+ * })
596
+ * const failed = result.results.filter(r => !r.success)
597
+ * const ids = result.results.filter(r => r.success).map(r => r.courierDeliveryId)
598
+ */
599
+ async bulkUpload(params) {
600
+ return request(
601
+ "/v1/courier/deliveries/bulk-upload",
602
+ { method: "POST", body: params },
603
+ this.auth
604
+ );
605
+ }
606
+ /**
607
+ * 택배사 계정의 배송 목록을 조회합니다.
608
+ *
609
+ * 택배사 API를 실시간으로 호출하여 최신 배송 상태를 반환합니다.
610
+ *
611
+ * @param params - 조회 파라미터
612
+ * @returns 배송 목록 (items) + 요약 통계 (summary)
613
+ * @throws {ApiError} NOT_FOUND — 존재하지 않는 계정
614
+ *
615
+ * @example
616
+ * const result = await client.courier.deliveries.inquiry({
617
+ * courierAccountKey: 'your-key',
618
+ * fromDate: '2026-03-01',
619
+ * toDate: '2026-03-22',
620
+ * })
621
+ * console.log(result.summary.delivered) // 배송 완료 건수
622
+ * const pending = result.items.filter(i => i.deliveryStatus === 'PENDING')
623
+ */
624
+ async inquiry(params) {
625
+ return request(
626
+ "/v1/courier/deliveries/inquiry",
627
+ { method: "POST", body: params },
628
+ this.auth
629
+ );
630
+ }
631
+ /**
632
+ * 택배사 계정의 배송 통계(대시보드)를 조회합니다.
633
+ *
634
+ * @param params - 조회 파라미터
635
+ * @returns 배송 통계 (items: 상세 행, summary: 요약)
636
+ * @throws {ApiError} NOT_FOUND — 존재하지 않는 계정
637
+ *
638
+ * @example
639
+ * const stats = await client.courier.deliveries.dashboard({
640
+ * courierAccountKey: 'your-key',
641
+ * fromDate: '2026-03-01',
642
+ * toDate: '2026-03-22',
643
+ * })
644
+ * console.log(stats.summary.totalCount) // 전체 건수
645
+ * console.log(stats.summary.delivered) // 배송 완료 건수
646
+ */
647
+ async dashboard(params) {
648
+ return request(
649
+ "/v1/courier/deliveries/dashboard",
650
+ {
651
+ method: "GET",
652
+ params: {
653
+ courierAccountKey: params.courierAccountKey,
654
+ fromDate: params.fromDate,
655
+ toDate: params.toDate
656
+ }
657
+ },
658
+ this.auth
659
+ );
660
+ }
661
+ /**
662
+ * 등록된 배송을 취소합니다.
663
+ *
664
+ * **주의**: 등록 후 7일 이내의 배송만 취소 가능합니다.
665
+ * 7일 이상 경과한 배송은 택배사에서 조회되지 않아 취소할 수 없습니다.
666
+ * 지원하지 않는 택배사의 경우 에러가 반환됩니다.
667
+ *
668
+ * 이력 단위 취소가 필요하면 `client.courier.deliveries.histories.delete()`를 사용하세요.
669
+ *
670
+ * @param params - 취소 파라미터 (courierDeliveryId 목록)
671
+ * @throws {ApiError} NOT_FOUND — 존재하지 않는 계정
672
+ * @throws {ApiError} INVALID_PARAMS — 택배사가 배송 취소를 지원하지 않음
673
+ *
674
+ * @example
675
+ * await client.courier.deliveries.cancel({
676
+ * courierAccountKey: 'your-key',
677
+ * courierDeliveryIds: ['7705241632', '7705241633'],
678
+ * })
679
+ */
680
+ async cancel(params) {
681
+ await request(
682
+ "/v1/courier/deliveries/cancel",
683
+ { method: "POST", body: params },
684
+ this.auth
685
+ );
686
+ }
687
+ };
688
+
689
+ // src/resources/print.ts
690
+ var PrintResource = class {
691
+ constructor(auth) {
692
+ this.auth = auth;
693
+ }
694
+ /**
695
+ * 송장 출력 세션을 생성합니다.
696
+ *
697
+ * 세션 ID로 출력 페이지(`https://print.deliveryapi.co.kr?session={sessionId}`)에 접속할 수 있습니다.
698
+ * 세션은 **10분 유효, 1회용**입니다. OZ Viewer 설치가 필요합니다.
699
+ *
700
+ * `courierTrackingIds` 또는 `bulkUploadHistoryId` 중 하나를 지정하세요.
701
+ *
702
+ * **중요**: 대부분의 택배사에서 송장번호(trackingNumber)는 이 출력 시점에 발급됩니다.
703
+ * 출력 후 `client.courier.deliveries.inquiry()`로 발급된 송장번호를 확인하세요.
704
+ *
705
+ * @param params - 출력 세션 생성 파라미터
706
+ * @returns 세션 정보 (sessionId, expiresAt)
707
+ * @throws {ApiError} NOT_FOUND — 존재하지 않는 계정 또는 배송 ID
708
+ *
709
+ * @example
710
+ * // 개별 ID로 출력
711
+ * const session = await client.courier.print.createSession({
712
+ * courierAccountKey: 'your-key',
713
+ * providerId: 'lotte',
714
+ * courierTrackingIds: ['7705241632', '7705241633'],
715
+ * })
716
+ * // 브라우저에서 출력 페이지 열기
717
+ * window.open(`https://print.deliveryapi.co.kr?session=${session.sessionId}`)
718
+ *
719
+ * @example
720
+ * // 이력 전체 출력
721
+ * const session = await client.courier.print.createSession({
722
+ * courierAccountKey: 'your-key',
723
+ * providerId: 'lotte',
724
+ * bulkUploadHistoryId: '202603221456_a1b2c',
725
+ * })
726
+ */
727
+ async createSession(params) {
728
+ return request(
729
+ "/v1/courier/print/sessions",
730
+ { method: "POST", body: params },
731
+ this.auth
732
+ );
733
+ }
734
+ };
735
+
736
+ // src/resources/courier.ts
737
+ var CourierResource = class {
738
+ constructor(auth) {
739
+ this.accounts = new AccountsResource(auth);
740
+ this.deliveries = new DeliveriesResource(auth);
741
+ this.print = new PrintResource(auth);
742
+ }
743
+ };
744
+
325
745
  // src/client.ts
326
746
  var DeliveryAPIClient = class {
327
747
  constructor(options) {
@@ -330,28 +750,21 @@ var DeliveryAPIClient = class {
330
750
  const auth = { apiKey: options.apiKey, secretKey: options.secretKey };
331
751
  this.tracking = new TrackingResource(auth);
332
752
  this.webhooks = new WebhooksResource(auth);
753
+ this.courier = new CourierResource(auth);
333
754
  }
334
755
  };
335
756
 
336
757
  // src/types.ts
337
- var CourierDeliveryStatus = /* @__PURE__ */ ((CourierDeliveryStatus2) => {
338
- CourierDeliveryStatus2["PENDING"] = "PENDING";
339
- CourierDeliveryStatus2["REGISTERED"] = "REGISTERED";
340
- CourierDeliveryStatus2["PICKUP_READY"] = "PICKUP_READY";
341
- CourierDeliveryStatus2["PICKED_UP"] = "PICKED_UP";
342
- CourierDeliveryStatus2["IN_TRANSIT"] = "IN_TRANSIT";
343
- CourierDeliveryStatus2["OUT_FOR_DELIVERY"] = "OUT_FOR_DELIVERY";
344
- CourierDeliveryStatus2["DELIVERED"] = "DELIVERED";
345
- CourierDeliveryStatus2["FAILED"] = "FAILED";
346
- CourierDeliveryStatus2["RETURNED"] = "RETURNED";
347
- CourierDeliveryStatus2["CANCELLED"] = "CANCELLED";
348
- CourierDeliveryStatus2["HOLD"] = "HOLD";
349
- CourierDeliveryStatus2["UNKNOWN"] = "UNKNOWN";
350
- return CourierDeliveryStatus2;
351
- })(CourierDeliveryStatus || {});
758
+ var import_CourierDeliveryStatus = __toESM(require_CourierDeliveryStatus(), 1);
759
+ var export_CourierDeliveryStatus = import_CourierDeliveryStatus.CourierDeliveryStatus;
352
760
  export {
761
+ AccountsResource,
353
762
  ApiError,
354
- CourierDeliveryStatus,
355
- DeliveryAPIClient
763
+ export_CourierDeliveryStatus as CourierDeliveryStatus,
764
+ CourierResource,
765
+ DeliveriesResource,
766
+ DeliveryAPIClient,
767
+ HistoriesResource,
768
+ PrintResource
356
769
  };
357
770
  //# sourceMappingURL=index.js.map