deliveryapi 1.8.1 → 1.11.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,3 +1,53 @@
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 {
@@ -28,7 +78,7 @@ async function request(path, options, auth) {
28
78
  throw new ApiError(
29
79
  json.errorCode ?? "INTERNAL_ERROR",
30
80
  json.error ?? json.message ?? `HTTP ${res.status}`,
31
- json.statusCode ?? res.status,
81
+ res.status,
32
82
  json.data
33
83
  );
34
84
  }
@@ -254,7 +304,7 @@ var SubscriptionsResource = class {
254
304
  async list(params) {
255
305
  return request(
256
306
  "/v1/webhooks/subscriptions",
257
- { params: { cursor: params?.cursor, limit: params?.limit } },
307
+ { params: { cursor: params?.cursor, limit: params?.limit, status: params?.status, from: params?.from, to: params?.to } },
258
308
  this.auth
259
309
  );
260
310
  }
@@ -324,6 +374,355 @@ var WebhooksResource = class {
324
374
  }
325
375
  };
326
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
+ // src/resources/deliveries.ts
532
+ var DeliveriesResource = class {
533
+ constructor(auth) {
534
+ this.auth = auth;
535
+ this.histories = new HistoriesResource(auth);
536
+ }
537
+ /**
538
+ * 택배를 대량 등록합니다. 최대 1,000건까지 한 번에 등록 가능합니다.
539
+ *
540
+ * 등록 직후에는 관리번호(courierDeliveryId)만 발급됩니다.
541
+ * 송장번호(trackingNumber)는 **송장 출력 시점에 발급**됩니다.
542
+ *
543
+ * HTTP 200으로 응답하며, `success`는 전체 성공 여부입니다.
544
+ * 부분 실패가 가능하므로 반드시 `results[].success`로 개별 확인하세요.
545
+ *
546
+ * @param params - 대량 등록 요청 파라미터
547
+ * @returns 등록 결과 (부분 성공 포함, results[].success로 개별 확인)
548
+ * @throws {ApiError} RATE_LIMITED — 요청 한도 초과
549
+ * @throws {ApiError} FORBIDDEN — 계정 슬롯 한도 초과
550
+ *
551
+ * @example
552
+ * const result = await client.courier.deliveries.bulkUpload({
553
+ * courierAccountKey: 'your-key',
554
+ * items: [{
555
+ * clientOrderId: 'ORD-001',
556
+ * receiverName: '홍길동',
557
+ * receiverPhone1: '01012345678',
558
+ * receiverAddress: '서울특별시 중구 세종대로 110',
559
+ * productName: '테스트 상품',
560
+ * quantity: 1,
561
+ * }],
562
+ * })
563
+ * const failed = result.results.filter(r => !r.success)
564
+ * const ids = result.results.filter(r => r.success).map(r => r.courierDeliveryId)
565
+ */
566
+ async bulkUpload(params) {
567
+ return request(
568
+ "/v1/courier/deliveries/bulk-upload",
569
+ { method: "POST", body: params },
570
+ this.auth
571
+ );
572
+ }
573
+ /**
574
+ * 택배사 계정의 배송 목록을 조회합니다.
575
+ *
576
+ * 택배사 API를 실시간으로 호출하여 최신 배송 상태를 반환합니다.
577
+ *
578
+ * @param params - 조회 파라미터
579
+ * @returns 배송 목록 (items) + 요약 통계 (summary)
580
+ * @throws {ApiError} NOT_FOUND — 존재하지 않는 계정
581
+ *
582
+ * @example
583
+ * const result = await client.courier.deliveries.inquiry({
584
+ * courierAccountKey: 'your-key',
585
+ * fromDate: '2026-03-01',
586
+ * toDate: '2026-03-22',
587
+ * })
588
+ * console.log(result.summary.delivered) // 배송 완료 건수
589
+ * const pending = result.items.filter(i => i.deliveryStatus === 'PENDING')
590
+ */
591
+ async inquiry(params) {
592
+ return request(
593
+ "/v1/courier/deliveries/inquiry",
594
+ { method: "POST", body: params },
595
+ this.auth
596
+ );
597
+ }
598
+ /**
599
+ * 택배사 계정의 배송 통계(대시보드)를 조회합니다.
600
+ *
601
+ * @param params - 조회 파라미터
602
+ * @returns 배송 통계 (items: 상세 행, summary: 요약)
603
+ * @throws {ApiError} NOT_FOUND — 존재하지 않는 계정
604
+ *
605
+ * @example
606
+ * const stats = await client.courier.deliveries.dashboard({
607
+ * courierAccountKey: 'your-key',
608
+ * fromDate: '2026-03-01',
609
+ * toDate: '2026-03-22',
610
+ * })
611
+ * console.log(stats.summary.totalCount) // 전체 건수
612
+ * console.log(stats.summary.delivered) // 배송 완료 건수
613
+ */
614
+ async dashboard(params) {
615
+ return request(
616
+ "/v1/courier/deliveries/dashboard",
617
+ {
618
+ method: "GET",
619
+ params: {
620
+ courierAccountKey: params.courierAccountKey,
621
+ fromDate: params.fromDate,
622
+ toDate: params.toDate
623
+ }
624
+ },
625
+ this.auth
626
+ );
627
+ }
628
+ /**
629
+ * 배송을 취소합니다. 3가지 사용 방식을 지원합니다.
630
+ *
631
+ * 1. **historyId만**: 해당 이력의 전체 배송 취소 + 이력 soft delete
632
+ * 2. **historyId + courierDeliveryIds**: 이력 내 부분 취소
633
+ * 3. **courierDeliveryIds만**: 택배사 직접 취소 (이력 무관, 최근 7일 이내)
634
+ *
635
+ * `historyId`와 `courierDeliveryIds` 중 하나는 반드시 필요합니다.
636
+ *
637
+ * @param params - 취소 파라미터
638
+ * @throws {ApiError} NOT_FOUND — 존재하지 않는 계정 또는 이력
639
+ * @throws {ApiError} INVALID_PARAMS — 택배사가 배송 취소를 지원하지 않음
640
+ *
641
+ * @example
642
+ * // 이력 전체 취소
643
+ * await client.courier.deliveries.cancel({
644
+ * courierAccountKey: 'your-key',
645
+ * historyId: '202603221456_a1b2c',
646
+ * })
647
+ *
648
+ * // 이력 내 부분 취소
649
+ * await client.courier.deliveries.cancel({
650
+ * courierAccountKey: 'your-key',
651
+ * historyId: '202603221456_a1b2c',
652
+ * courierDeliveryIds: ['7705241632'],
653
+ * })
654
+ *
655
+ * // 직접 취소 (이력 없이)
656
+ * await client.courier.deliveries.cancel({
657
+ * courierAccountKey: 'your-key',
658
+ * courierDeliveryIds: ['7705241632', '7705241633'],
659
+ * })
660
+ */
661
+ async cancel(params) {
662
+ await request(
663
+ "/v1/courier/deliveries/cancel",
664
+ { method: "POST", body: params },
665
+ this.auth
666
+ );
667
+ }
668
+ };
669
+
670
+ // src/resources/print.ts
671
+ var PrintResource = class {
672
+ constructor(auth) {
673
+ this.auth = auth;
674
+ }
675
+ /**
676
+ * 송장 출력 세션을 생성합니다.
677
+ *
678
+ * 세션 ID로 출력 페이지(`https://print.deliveryapi.co.kr?session={sessionId}`)에 접속할 수 있습니다.
679
+ * 세션은 **10분 유효, 1회용**입니다. OZ Viewer 설치가 필요합니다.
680
+ *
681
+ * `courierTrackingIds` 또는 `bulkUploadHistoryId` 중 하나를 지정하세요.
682
+ *
683
+ * **중요**: 대부분의 택배사에서 송장번호(trackingNumber)는 이 출력 시점에 발급됩니다.
684
+ * 출력 후 `client.courier.deliveries.inquiry()`로 발급된 송장번호를 확인하세요.
685
+ *
686
+ * @param params - 출력 세션 생성 파라미터
687
+ * @returns 세션 정보 (sessionId, expiresAt)
688
+ * @throws {ApiError} NOT_FOUND — 존재하지 않는 계정 또는 배송 ID
689
+ *
690
+ * @example
691
+ * // 개별 ID로 출력
692
+ * const session = await client.courier.print.createSession({
693
+ * courierAccountKey: 'your-key',
694
+ * providerId: 'lotte',
695
+ * courierTrackingIds: ['7705241632', '7705241633'],
696
+ * })
697
+ * // 브라우저에서 출력 페이지 열기
698
+ * window.open(`https://print.deliveryapi.co.kr?session=${session.sessionId}`)
699
+ *
700
+ * @example
701
+ * // 이력 전체 출력
702
+ * const session = await client.courier.print.createSession({
703
+ * courierAccountKey: 'your-key',
704
+ * providerId: 'lotte',
705
+ * bulkUploadHistoryId: '202603221456_a1b2c',
706
+ * })
707
+ */
708
+ async createSession(params) {
709
+ return request(
710
+ "/v1/courier/print/sessions",
711
+ { method: "POST", body: params },
712
+ this.auth
713
+ );
714
+ }
715
+ };
716
+
717
+ // src/resources/courier.ts
718
+ var CourierResource = class {
719
+ constructor(auth) {
720
+ this.accounts = new AccountsResource(auth);
721
+ this.deliveries = new DeliveriesResource(auth);
722
+ this.print = new PrintResource(auth);
723
+ }
724
+ };
725
+
327
726
  // src/client.ts
328
727
  var DeliveryAPIClient = class {
329
728
  constructor(options) {
@@ -332,28 +731,21 @@ var DeliveryAPIClient = class {
332
731
  const auth = { apiKey: options.apiKey, secretKey: options.secretKey };
333
732
  this.tracking = new TrackingResource(auth);
334
733
  this.webhooks = new WebhooksResource(auth);
734
+ this.courier = new CourierResource(auth);
335
735
  }
336
736
  };
337
737
 
338
738
  // src/types.ts
339
- var CourierDeliveryStatus = /* @__PURE__ */ ((CourierDeliveryStatus2) => {
340
- CourierDeliveryStatus2["PENDING"] = "PENDING";
341
- CourierDeliveryStatus2["REGISTERED"] = "REGISTERED";
342
- CourierDeliveryStatus2["PICKUP_READY"] = "PICKUP_READY";
343
- CourierDeliveryStatus2["PICKED_UP"] = "PICKED_UP";
344
- CourierDeliveryStatus2["IN_TRANSIT"] = "IN_TRANSIT";
345
- CourierDeliveryStatus2["OUT_FOR_DELIVERY"] = "OUT_FOR_DELIVERY";
346
- CourierDeliveryStatus2["DELIVERED"] = "DELIVERED";
347
- CourierDeliveryStatus2["FAILED"] = "FAILED";
348
- CourierDeliveryStatus2["RETURNED"] = "RETURNED";
349
- CourierDeliveryStatus2["CANCELLED"] = "CANCELLED";
350
- CourierDeliveryStatus2["HOLD"] = "HOLD";
351
- CourierDeliveryStatus2["UNKNOWN"] = "UNKNOWN";
352
- return CourierDeliveryStatus2;
353
- })(CourierDeliveryStatus || {});
739
+ var import_CourierDeliveryStatus = __toESM(require_CourierDeliveryStatus(), 1);
740
+ var export_CourierDeliveryStatus = import_CourierDeliveryStatus.CourierDeliveryStatus;
354
741
  export {
742
+ AccountsResource,
355
743
  ApiError,
356
- CourierDeliveryStatus,
357
- DeliveryAPIClient
744
+ export_CourierDeliveryStatus as CourierDeliveryStatus,
745
+ CourierResource,
746
+ DeliveriesResource,
747
+ DeliveryAPIClient,
748
+ HistoriesResource,
749
+ PrintResource
358
750
  };
359
751
  //# sourceMappingURL=index.js.map