deliveryapi 1.0.1 → 1.2.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.d.cts CHANGED
@@ -227,8 +227,8 @@ interface CreateEndpointParams {
227
227
  * 등록 시 서버에서 테스트 POST 요청을 전송하여 URL을 검증합니다.
228
228
  */
229
229
  url: string;
230
- /** 엔드포인트 이름 (선택, 관리용) */
231
- name?: string;
230
+ /** 엔드포인트 이름 (관리용) */
231
+ name: string;
232
232
  /**
233
233
  * 서명 시크릿 직접 지정 (선택)
234
234
  *
@@ -610,28 +610,6 @@ interface AuthCredentials {
610
610
  secretKey: string;
611
611
  }
612
612
 
613
- /**
614
- * 택배 조회 리소스
615
- *
616
- * 송장번호로 배송 정보를 즉시 조회합니다.
617
- * 단건/다건을 모두 지원하며, 여러 택배사를 한 번의 요청으로 조회할 수 있습니다.
618
- *
619
- * @example
620
- * const client = new DeliveryAPIClient({ apiKey: '...', secretKey: '...' })
621
- *
622
- * // 단건 조회
623
- * const result = await client.tracking.trace({
624
- * items: [{ courierCode: 'cj', trackingNumber: '1234567890' }],
625
- * })
626
- *
627
- * // 다건 조회 (여러 택배사 혼합 가능)
628
- * const result = await client.tracking.trace({
629
- * items: [
630
- * { courierCode: 'cj', trackingNumber: '1111111111', clientId: 'order_001' },
631
- * { courierCode: 'lotte', trackingNumber: '2222222222', clientId: 'order_002' },
632
- * ],
633
- * })
634
- */
635
613
  declare class TrackingResource {
636
614
  private readonly auth;
637
615
  constructor(auth: AuthCredentials);
@@ -640,8 +618,6 @@ declare class TrackingResource {
640
618
  *
641
619
  * 택배사 코드(`trackingApiCode`)는 `trace()`의 `courierCode` 파라미터에 사용합니다.
642
620
  *
643
- * @returns 지원 택배사 목록 및 총 수
644
- *
645
621
  * @example
646
622
  * const { couriers } = await client.tracking.getCouriers()
647
623
  * // couriers: [{ trackingApiCode: 'cj', displayName: 'CJ대한통운' }, ...]
@@ -650,25 +626,22 @@ declare class TrackingResource {
650
626
  /**
651
627
  * 송장번호로 배송 정보를 조회합니다.
652
628
  *
653
- * - 요청당 여러 건을 배열로 전달할 수 있습니다.
629
+ * - 여러 건을 배열로 전달할 수 있습니다.
654
630
  * - 결과는 요청 순서와 동일한 인덱스로 반환됩니다.
655
631
  * - 일부 아이템이 실패해도 전체 요청이 실패하지 않습니다. `results[].success`로 건별 확인하세요.
656
632
  *
657
633
  * **과금 안내**: `NOT_FOUND` 에러는 과금됩니다. `results[].error.billable`로 확인하세요.
658
634
  *
659
- * @param params 조회 파라미터
660
- * @returns 아이템별 조회 결과 집계 요약
635
+ * @param items 조회할 택배 목록
636
+ * @param includeProgresses 배송 진행 내역 포함 여부 (기본값: true)
661
637
  *
662
638
  * @throws {ApiError} API 인증 실패, 요청 한도 초과 등 전체 요청 실패 시
663
639
  *
664
640
  * @example
665
- * const { results, summary } = await client.tracking.trace({
666
- * items: [
667
- * { courierCode: 'cj', trackingNumber: '1234567890', clientId: 'order_001' },
668
- * { courierCode: 'lotte', trackingNumber: '9876543210', clientId: 'order_002' },
669
- * ],
670
- * includeProgresses: true,
671
- * })
641
+ * const { results } = await client.tracking.trace([
642
+ * { courierCode: 'cj', trackingNumber: '1234567890', clientId: 'order_001' },
643
+ * { courierCode: 'lotte', trackingNumber: '9876543210', clientId: 'order_002' },
644
+ * ])
672
645
  *
673
646
  * for (const result of results) {
674
647
  * if (result.success) {
@@ -677,39 +650,15 @@ declare class TrackingResource {
677
650
  * console.warn(result.error?.code) // 'NOT_FOUND'
678
651
  * }
679
652
  * }
680
- *
681
- * console.log(`성공: ${summary.successful} / 전체: ${summary.total}`)
682
653
  */
683
- trace(params: TraceParams): Promise<TraceResponse>;
654
+ trace(items: {
655
+ courierCode: string;
656
+ trackingNumber: string;
657
+ clientId?: string;
658
+ }[], includeProgresses?: boolean): Promise<TraceResponse>;
684
659
  }
685
660
 
686
- /**
687
- * 웹훅 리소스
688
- *
689
- * **엔드포인트 관리**: 웹훅을 수신할 URL을 등록/관리합니다.
690
- * **구독 관리**: 특정 택배를 추적하고 상태 변경 시 웹훅을 수신합니다.
691
- *
692
- * @example
693
- * const client = new DeliveryAPIClient({ apiKey: '...', secretKey: '...' })
694
- *
695
- * // 1. 엔드포인트 등록
696
- * const endpoint = await client.webhooks.createEndpoint({
697
- * url: 'https://my-server.com/webhook',
698
- * name: '운영 서버',
699
- * })
700
- * // ⚠️ endpoint.webhookSecret 을 안전하게 보관하세요!
701
- *
702
- * // 2. 택배 추적 구독
703
- * const sub = await client.webhooks.register({
704
- * endpointId: endpoint.endpointId,
705
- * items: [{ courierCode: 'cj', trackingNumber: '1234567890', clientId: 'order_001' }],
706
- * recurring: true,
707
- * })
708
- *
709
- * // 3. 구독 상태 조회
710
- * const detail = await client.webhooks.getSubscription(sub.requestId)
711
- */
712
- declare class WebhooksResource {
661
+ declare class EndpointsResource {
713
662
  private readonly auth;
714
663
  constructor(auth: AuthCredentials);
715
664
  /**
@@ -719,57 +668,54 @@ declare class WebhooksResource {
719
668
  * 응답의 `webhookSecret`은 **이 응답에서만 평문으로 반환**됩니다.
720
669
  * 분실 시 `rotateSecret()`으로 재발급해야 합니다.
721
670
  *
722
- * @param params 엔드포인트 등록 파라미터
723
- * @returns 생성된 엔드포인트 정보 (webhookSecret 포함)
671
+ * @param url 웹훅을 수신할 URL (`https://` 필수)
672
+ * @param name 엔드포인트 이름 (관리용)
673
+ * @param webhookSecret 서명 시크릿 직접 지정 (미제공 시 서버 자동 생성, 최소 5자)
724
674
  *
725
675
  * @throws {ApiError} `WEBHOOK_ENDPOINT_LIMIT` — 엔드포인트 등록 한도 초과
726
676
  *
727
677
  * @example
728
- * const endpoint = await client.webhooks.createEndpoint({
729
- * url: 'https://my-server.com/webhook',
730
- * name: '운영 서버',
731
- * })
678
+ * const endpoint = await client.webhooks.endpoints.create(
679
+ * 'https://my-server.com/webhook',
680
+ * '운영 서버',
681
+ * )
732
682
  * console.log(endpoint.endpointId) // 'ep_xxxx'
733
683
  * console.log(endpoint.webhookSecret) // 반드시 저장하세요!
734
684
  */
735
- createEndpoint(params: CreateEndpointParams): Promise<CreateEndpointResponse>;
685
+ create(url: string, name: string, webhookSecret?: string): Promise<CreateEndpointResponse>;
736
686
  /**
737
687
  * 등록된 웹훅 엔드포인트 목록을 조회합니다.
738
688
  *
739
- * @returns 엔드포인트 목록 및 총 수
740
- *
741
689
  * @example
742
- * const { endpoints } = await client.webhooks.listEndpoints()
690
+ * const { endpoints } = await client.webhooks.endpoints.list()
743
691
  * const active = endpoints.filter(ep => ep.status === 'active')
744
692
  */
745
- listEndpoints(): Promise<ListEndpointsResponse>;
693
+ list(): Promise<ListEndpointsResponse>;
746
694
  /**
747
695
  * 웹훅 엔드포인트 이름을 수정합니다.
748
696
  *
749
- * URL은 변경할 수 없습니다. URL을 변경해야 한다면 엔드포인트를 삭제 후 재등록하세요.
697
+ * URL은 변경할 수 없습니다. URL을 변경해야 한다면 삭제 후 재등록하세요.
750
698
  *
751
699
  * @param endpointId 수정할 엔드포인트 ID
752
- * @param params 수정 내용
700
+ * @param name 이름
753
701
  *
754
702
  * @throws {ApiError} `NOT_FOUND` — 존재하지 않는 엔드포인트
755
703
  *
756
704
  * @example
757
- * await client.webhooks.updateEndpoint('ep_xxxx', { name: '스테이징 서버' })
705
+ * await client.webhooks.endpoints.update('ep_xxxx', '스테이징 서버')
758
706
  */
759
- updateEndpoint(endpointId: string, params: UpdateEndpointParams): Promise<void>;
707
+ update(endpointId: string, name: string): Promise<void>;
760
708
  /**
761
709
  * 웹훅 엔드포인트를 삭제합니다.
762
710
  *
763
711
  * 해당 엔드포인트에 연결된 구독도 함께 삭제됩니다 (cascade).
764
712
  *
765
- * @param endpointId 삭제할 엔드포인트 ID
766
- *
767
713
  * @throws {ApiError} `NOT_FOUND` — 존재하지 않는 엔드포인트
768
714
  *
769
715
  * @example
770
- * await client.webhooks.deleteEndpoint('ep_xxxx')
716
+ * await client.webhooks.endpoints.delete('ep_xxxx')
771
717
  */
772
- deleteEndpoint(endpointId: string): Promise<void>;
718
+ delete(endpointId: string): Promise<void>;
773
719
  /**
774
720
  * 웹훅 서명 시크릿을 재발급합니다.
775
721
  *
@@ -777,16 +723,20 @@ declare class WebhooksResource {
777
723
  * 새 시크릿은 **이 응답에서만 평문으로 반환**됩니다.
778
724
  *
779
725
  * @param endpointId 대상 엔드포인트 ID
780
- * @param params 새 시크릿 (선택, 미제공 시 서버 생성)
781
- * @returns 새 웹훅 시크릿
726
+ * @param webhookSecret 새 시크릿 직접 지정 (미제공 시 서버 자동 생성)
782
727
  *
783
728
  * @throws {ApiError} `NOT_FOUND` — 존재하지 않는 엔드포인트
784
729
  *
785
730
  * @example
786
- * const { webhookSecret } = await client.webhooks.rotateSecret('ep_xxxx')
731
+ * const { webhookSecret } = await client.webhooks.endpoints.rotateSecret('ep_xxxx')
787
732
  * console.log(webhookSecret) // 새 시크릿 — 반드시 저장하세요!
788
733
  */
789
- rotateSecret(endpointId: string, params?: RotateSecretParams): Promise<RotateSecretResponse>;
734
+ rotateSecret(endpointId: string, webhookSecret?: string): Promise<RotateSecretResponse>;
735
+ }
736
+
737
+ declare class SubscriptionsResource {
738
+ private readonly auth;
739
+ constructor(auth: AuthCredentials);
790
740
  /**
791
741
  * 택배 추적 구독을 등록합니다.
792
742
  *
@@ -794,104 +744,141 @@ declare class WebhooksResource {
794
744
  * 상태 변경 시 `endpointId`로 웹훅을 발송합니다.
795
745
  *
796
746
  * **일회성** (`recurring: false`): 등록 즉시 1회 크롤 후 종료합니다.
797
- * `endpointId` 없이 사용하면 결과를 `getSubscription(requestId)`으로 직접 조회할 수 있습니다.
747
+ * `endpointId` 없이 사용하면 결과를 `get(requestId)`으로 직접 조회할 수 있습니다.
798
748
  *
799
- * @param params 구독 등록 파라미터
800
- * @returns 구독 ID (`requestId`) 기본 정보
749
+ * @param items 추적할 택배 목록
750
+ * @param recurring true: 반복 구독, false: 1회성
751
+ * @param endpointId 웹훅 수신 엔드포인트 ID (선택)
801
752
  *
802
753
  * @example
803
754
  * // 구독형 — 상태 변경 시 웹훅 수신
804
- * const sub = await client.webhooks.register({
805
- * endpointId: 'ep_xxxx',
806
- * items: [
807
- * { courierCode: 'cj', trackingNumber: '1234567890', clientId: 'order_001' },
808
- * ],
809
- * recurring: true,
810
- * })
755
+ * const sub = await client.webhooks.subscriptions.register(
756
+ * [{ courierCode: 'cj', trackingNumber: '1234567890', clientId: 'order_001' }],
757
+ * true,
758
+ * 'ep_xxxx',
759
+ * )
811
760
  *
812
761
  * @example
813
- * // 일회성 즉시 조회 — 웹훅 없이 결과를 직접 폴링
814
- * const req = await client.webhooks.register({
815
- * items: [{ courierCode: 'lotte', trackingNumber: '9876543210' }],
816
- * recurring: false,
817
- * })
818
- * const detail = await client.webhooks.getSubscription(req.requestId)
819
- */
820
- register(params: RegisterParams): Promise<RegisterResponse>;
762
+ * // 일회성 — 웹훅 없이 결과를 직접 조회
763
+ * const req = await client.webhooks.subscriptions.register(
764
+ * [{ courierCode: 'lotte', trackingNumber: '9876543210' }],
765
+ * false,
766
+ * )
767
+ * const detail = await client.webhooks.subscriptions.get(req.requestId)
768
+ */
769
+ register(items: {
770
+ courierCode: string;
771
+ trackingNumber: string;
772
+ clientId?: string;
773
+ }[], recurring: boolean, endpointId?: string): Promise<RegisterResponse>;
821
774
  /**
822
775
  * 구독 목록을 조회합니다.
823
776
  *
824
777
  * 커서 기반 페이지네이션을 지원합니다.
825
778
  * 다음 페이지가 있으면 응답의 `nextCursor`를 다음 호출의 `cursor` 파라미터로 전달하세요.
826
779
  *
827
- * @param params 페이지네이션 파라미터 (선택)
828
- * @returns 구독 목록 및 다음 페이지 커서
829
- *
830
780
  * @example
831
- * // 전체 구독 목록 순회
832
781
  * let cursor: string | undefined
833
782
  * do {
834
- * const page = await client.webhooks.listSubscriptions({ cursor, limit: 50 })
783
+ * const page = await client.webhooks.subscriptions.list({ cursor, limit: 50 })
835
784
  * for (const sub of page.subscriptions) {
836
785
  * console.log(sub.requestId, sub.isActive)
837
786
  * }
838
787
  * cursor = page.nextCursor
839
788
  * } while (cursor)
840
789
  */
841
- listSubscriptions(params?: ListSubscriptionsParams): Promise<ListSubscriptionsResponse>;
790
+ list(params?: ListSubscriptionsParams): Promise<ListSubscriptionsResponse>;
842
791
  /**
843
792
  * 구독 상세 정보를 조회합니다.
844
793
  *
845
- * 각 택배별 현재 상태 및 최신 배송 데이터를 포함합니다.
846
- *
847
- * @param requestId `register()` 응답의 `requestId`
848
- * @returns 구독 상세 (아이템별 상태 포함)
849
- *
850
794
  * @throws {ApiError} `NOT_FOUND` — 존재하지 않는 구독
851
795
  *
852
796
  * @example
853
- * const detail = await client.webhooks.getSubscription('req_xxxx')
854
- *
797
+ * const detail = await client.webhooks.subscriptions.get('req_xxxx')
855
798
  * for (const item of detail.items) {
856
799
  * console.log(item.trackingNumber, item.currentStatus)
857
800
  * }
858
801
  */
859
- getSubscription(requestId: string): Promise<SubscriptionDetail>;
802
+ get(requestId: string): Promise<SubscriptionDetail>;
860
803
  /**
861
804
  * 구독을 취소합니다.
862
805
  *
863
- * 취소된 구독은 더 이상 폴링되지 않으며 웹훅도 발송되지 않습니다.
864
- *
865
- * @param requestId 취소할 구독 ID
866
- *
867
806
  * @throws {ApiError} `NOT_FOUND` — 존재하지 않는 구독
868
807
  *
869
808
  * @example
870
- * await client.webhooks.cancelSubscription('req_xxxx')
809
+ * await client.webhooks.subscriptions.cancel('req_xxxx')
871
810
  */
872
- cancelSubscription(requestId: string): Promise<void>;
811
+ cancel(requestId: string): Promise<void>;
873
812
  /**
874
813
  * 여러 송장번호의 최신 배송 정보를 한 번에 조회합니다.
875
814
  *
876
- * 구독 ID 없이 택배사 코드 + 송장번호로 검색합니다.
877
- * 해당 계정에 등록된 구독 중 일치하는 아이템을 반환합니다.
815
+ * 해당 계정에 등록된 구독 일치하는 아이템의 최신 상태를 반환합니다.
878
816
  *
879
- * @param params 조회할 아이템 목록
880
- * @returns 아이템별 최신 배송 정보
817
+ * @param items 조회할 택배 목록
881
818
  *
882
819
  * @example
883
- * const { results } = await client.webhooks.batchResults({
884
- * items: [
885
- * { courierCode: 'cj', trackingNumber: '1111111111' },
886
- * { courierCode: 'lotte', trackingNumber: '2222222222' },
887
- * ],
888
- * })
889
- *
820
+ * const { results } = await client.webhooks.subscriptions.batchResults([
821
+ * { courierCode: 'cj', trackingNumber: '1111111111' },
822
+ * { courierCode: 'lotte', trackingNumber: '2222222222' },
823
+ * ])
890
824
  * for (const r of results) {
891
825
  * console.log(r.currentStatus, r.isDelivered)
892
826
  * }
893
827
  */
894
- batchResults(params: BatchResultsParams): Promise<BatchResultsResponse>;
828
+ batchResults(items: {
829
+ courierCode: string;
830
+ trackingNumber: string;
831
+ }[]): Promise<BatchResultsResponse>;
832
+ }
833
+
834
+ /**
835
+ * 웹훅 리소스
836
+ *
837
+ * - `endpoints` — 웹훅 수신 URL 등록/관리
838
+ * - `subscriptions` — 택배 추적 구독 등록/관리
839
+ *
840
+ * @example
841
+ * const client = new DeliveryAPIClient({ apiKey: '...', secretKey: '...' })
842
+ *
843
+ * // 1. 엔드포인트 등록
844
+ * const endpoint = await client.webhooks.endpoints.create({
845
+ * url: 'https://my-server.com/webhook',
846
+ * name: '운영 서버',
847
+ * })
848
+ * // ⚠️ endpoint.webhookSecret 을 안전하게 보관하세요!
849
+ *
850
+ * // 2. 택배 추적 구독
851
+ * const sub = await client.webhooks.subscriptions.register({
852
+ * endpointId: endpoint.endpointId,
853
+ * items: [{ courierCode: 'cj', trackingNumber: '1234567890', clientId: 'order_001' }],
854
+ * recurring: true,
855
+ * })
856
+ *
857
+ * // 3. 구독 상태 조회
858
+ * const detail = await client.webhooks.subscriptions.get(sub.requestId)
859
+ */
860
+ declare class WebhooksResource {
861
+ /**
862
+ * 웹훅 엔드포인트 관리
863
+ *
864
+ * - `create()` — 수신 URL 등록
865
+ * - `list()` — 목록 조회
866
+ * - `update()` — 이름 수정
867
+ * - `delete()` — 삭제
868
+ * - `rotateSecret()` — 서명 시크릿 재발급
869
+ */
870
+ readonly endpoints: EndpointsResource;
871
+ /**
872
+ * 웹훅 구독 관리
873
+ *
874
+ * - `register()` — 택배 추적 구독 등록
875
+ * - `list()` — 구독 목록
876
+ * - `get()` — 구독 상세
877
+ * - `cancel()` — 구독 취소
878
+ * - `batchResults()` — 다건 최신 상태 조회
879
+ */
880
+ readonly subscriptions: SubscriptionsResource;
881
+ constructor(auth: AuthCredentials);
895
882
  }
896
883
 
897
884
  /** `DeliveryAPIClient` 생성 옵션 */
@@ -951,19 +938,8 @@ declare class DeliveryAPIClient {
951
938
  *
952
939
  * 배송 상태 변경 시 웹훅으로 알림을 받습니다.
953
940
  *
954
- * **엔드포인트 관리**:
955
- * - `createEndpoint()` 수신 URL 등록
956
- * - `listEndpoints()` — 목록 조회
957
- * - `updateEndpoint()` — 이름 수정
958
- * - `deleteEndpoint()` — 삭제
959
- * - `rotateSecret()` — 서명 시크릿 재발급
960
- *
961
- * **구독 관리**:
962
- * - `register()` — 택배 추적 구독 등록
963
- * - `listSubscriptions()` — 구독 목록
964
- * - `getSubscription()` — 구독 상세
965
- * - `cancelSubscription()` — 구독 취소
966
- * - `batchResults()` — 다건 최신 상태 조회
941
+ * **`webhooks.endpoints`** — 수신 URL 등록/관리
942
+ * **`webhooks.subscriptions`**택배 추적 구독 등록/관리
967
943
  */
968
944
  readonly webhooks: WebhooksResource;
969
945
  /** API Base URL (`https://api.deliveryapi.co.kr`) */