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