From f5b255b7ee3653733948569bf6db42c7fc4db463 Mon Sep 17 00:00:00 2001 From: Alex Matthews Date: Wed, 15 May 2024 14:56:02 -0500 Subject: [PATCH 1/7] Converts most of the app to ts --- out/package.json | 90 ++++ out/src/constants.js | 35 ++ out/src/easypost.js | 447 ++++++++++++++++ out/src/errors/api/api_error.js | 46 ++ out/src/errors/api/bad_request_error.js | 38 ++ out/src/errors/api/external_api_error.js | 36 ++ out/src/errors/api/forbidden_error.js | 38 ++ out/src/errors/api/gateway_timeout_error.js | 38 ++ out/src/errors/api/http_error.js | 37 ++ out/src/errors/api/index.js | 34 ++ out/src/errors/api/internal_server_error.js | 38 ++ out/src/errors/api/invalid_request_error.js | 38 ++ .../errors/api/method_not_allowed_error.js | 38 ++ out/src/errors/api/not_found_error.js | 38 ++ out/src/errors/api/payment_error.js | 38 ++ out/src/errors/api/rate_limit_error.js | 38 ++ out/src/errors/api/redirect_error.js | 38 ++ .../errors/api/service_unavailable_error.js | 38 ++ out/src/errors/api/timeout_error.js | 38 ++ out/src/errors/api/unauthorized_error.js | 38 ++ out/src/errors/api/unknown_api_error.js | 38 ++ out/src/errors/easypost_error.js | 34 ++ out/src/errors/error_handler.js | 148 ++++++ .../errors/general/end_of_pagination_error.js | 36 ++ out/src/errors/general/filtering_error.js | 35 ++ out/src/errors/general/index.js | 22 + .../errors/general/invalid_object_error.js | 35 ++ .../errors/general/invalid_parameter_error.js | 35 ++ .../errors/general/missing_parameter_error.js | 35 ++ .../general/signature_verification_error.js | 35 ++ out/src/errors/index.js | 20 + out/src/index.js | 7 + out/src/services/address_service/Address.js | 2 + .../AddressCreateParameters.js | 2 + .../address_service/AddressListParameters.js | 2 + .../services/address_service/Verification.js | 2 + .../address_service/VerificationDetails.js | 2 + .../services/address_service/Verifications.js | 3 + out/src/services/address_service/index.js | 217 ++++++++ out/src/services/api_key_service/ApiKey.js | 2 + out/src/services/api_key_service/index.js | 142 ++++++ out/src/services/base_service.js | 192 +++++++ out/src/services/batch_service/Batch.js | 2 + .../batch_service/BatchCreateParameters.js | 2 + .../batch_service/BatchListParameters.js | 2 + .../services/batch_service/BatchShipment.js | 2 + out/src/services/batch_service/BatchState.js | 2 + out/src/services/batch_service/BatchStatus.js | 2 + .../services/batch_service/BatchStatuses.js | 2 + out/src/services/batch_service/index.js | 293 +++++++++++ out/src/services/beta_rate_service/index.js | 99 ++++ .../beta_referral_customer_service/index.js | 142 ++++++ .../services/billing_service/PaymentMethod.js | 2 + out/src/services/billing_service/index.js | 203 ++++++++ .../carrier_account_service/CarrierAccount.js | 2 + .../CarrierAccountCreateParameters.js | 2 + .../CarrierAccountField.js | 2 + .../CarrierAccountFields.js | 2 + .../services/carrier_account_service/index.js | 216 ++++++++ .../CarrierMetadata.js | 2 + .../carrier_metadata_service/index.js | 124 +++++ .../carrier_type_service/CarrierType.js | 2 + .../CarrierTypeCredentials.js | 2 + .../carrier_type_service/CarrierTypeFields.js | 2 + .../services/carrier_type_service/index.js | 116 +++++ .../customs_info_service/CustomsInfo.js | 2 + .../CustomsInfoCreateParameters.js | 2 + .../services/customs_info_service/index.js | 119 +++++ .../customs_item_service/CustomsItem.js | 2 + .../CustomsItemCreateParameters.js | 2 + .../services/customs_item_service/index.js | 119 +++++ .../end_shipper_service/EndShipper.js | 2 + .../EndShipperCreateParameters.js | 2 + .../EndShipperListParameters.js | 2 + out/src/services/end_shipper_service/index.js | 164 ++++++ out/src/services/event_service/Event.js | 2 + .../event_service/EventListParameters.js | 2 + .../services/event_service/Payload/Payload.js | 2 + .../Payload/PayloadListParameters.js | 2 + .../services/event_service/Payload/index.js | 17 + out/src/services/event_service/index.js | 191 +++++++ out/src/services/index.js | 43 ++ out/src/services/insurance_service/Fee.js | 2 + out/src/services/insurance_service/FeeType.js | 2 + .../services/insurance_service/Insurance.js | 2 + .../InsuranceCreateParameters.js | 2 + .../insurance_service/InsuranceStatus.js | 2 + out/src/services/insurance_service/index.js | 154 ++++++ out/src/services/order_service/Order.js | 2 + .../order_service/OrderCreateParameters.js | 2 + out/src/services/order_service/index.js | 178 +++++++ out/src/services/parcel_service/Parcel.js | 2 + .../parcel_service/ParcelCreateParameters.js | 2 + out/src/services/parcel_service/index.js | 119 +++++ out/src/services/pickup_service/Pickup.js | 2 + .../pickup_service/PickupCreateParameters.js | 2 + .../pickup_service/PickupListParameters.js | 2 + out/src/services/pickup_service/PickupRate.js | 2 + out/src/services/pickup_service/index.js | 194 +++++++ out/src/services/rate_service/Rate.js | 2 + out/src/services/rate_service/index.js | 100 ++++ .../referral_customer_service/Referral.js | 2 + .../ReferralCreateParameters.js | 2 + .../ReferralListParameters.js | 2 + .../referral_customer_service/index.js | 295 +++++++++++ out/src/services/refund_service/Refund.js | 2 + .../refund_service/RefundCreateParameters.js | 2 + .../refund_service/RefundListParameters.js | 2 + out/src/services/refund_service/index.js | 152 ++++++ out/src/services/report_service/Report.js | 2 + .../report_service/ReportCreateParameters.js | 2 + .../report_service/ReportListParameters.js | 2 + .../report_service/ReportObjectType.js | 2 + out/src/services/report_service/index.js | 177 +++++++ .../services/scan_form_service/ScanForm.js | 2 + .../ScanFormCreateParameters.js | 2 + .../ScanFormListParameters.js | 2 + out/src/services/scan_form_service/index.js | 163 ++++++ out/src/services/shipment_service/Form.js | 2 + out/src/services/shipment_service/Message.js | 2 + .../shipment_service/Options/LabelFormat.js | 2 + .../shipment_service/Options/Options.js | 2 + .../Options/PrintCustomCode.js | 2 + .../shipment_service/Options/index.js | 19 + .../services/shipment_service/PostageLabel.js | 2 + out/src/services/shipment_service/Shipment.js | 2 + .../ShipmentCreateParameters.js | 2 + .../ShipmentListParameters.js | 2 + out/src/services/shipment_service/index.js | 479 +++++++++++++++++ .../services/tracker_service/CarrierDetail.js | 2 + out/src/services/tracker_service/Tracker.js | 2 + .../TrackerCreateParameters.js | 2 + .../tracker_service/TrackerListParameters.js | 2 + .../services/tracker_service/TrackerStatus.js | 2 + .../tracker_service/TrackerStatusDetail.js | 2 + .../tracker_service/TrackingDetail.js | 2 + .../tracker_service/TrackingLocation.js | 2 + out/src/services/tracker_service/index.js | 179 +++++++ out/src/services/user_service/Brand.js | 2 + out/src/services/user_service/User.js | 2 + .../user_service/UserCreateParameters.js | 2 + out/src/services/user_service/index.js | 294 +++++++++++ out/src/services/webhook_service/Webhook.js | 2 + .../WebhookCreateParameters.js | 2 + .../webhook_service/WebhookListParameters.js | 2 + out/src/services/webhook_service/index.js | 194 +++++++ out/src/utils/errors/Error.js | 2 + out/src/utils/errors/ErrorCode.js | 2 + out/src/utils/errors/FieldError.js | 2 + out/src/utils/errors/index.js | 19 + out/src/utils/types.js | 3 + out/src/utils/util.js | 199 ++++++++ package-lock.json | 34 +- package.json | 6 +- src/constants.js | 25 - src/constants.ts | 28 + src/easypost.js | 384 -------------- src/easypost.ts | 482 ++++++++++++++++++ src/errors/api/{api_error.js => api_error.ts} | 19 +- ..._request_error.js => bad_request_error.ts} | 2 +- ...nal_api_error.js => external_api_error.ts} | 2 +- ...{forbidden_error.js => forbidden_error.ts} | 2 +- ...eout_error.js => gateway_timeout_error.ts} | 2 +- .../api/{http_error.js => http_error.ts} | 2 +- src/errors/api/index.ts | 18 + ...rver_error.js => internal_server_error.ts} | 2 +- ...uest_error.js => invalid_request_error.ts} | 2 +- ...d_error.js => method_not_allowed_error.ts} | 2 +- ...{not_found_error.js => not_found_error.ts} | 2 +- .../{payment_error.js => payment_error.ts} | 2 +- ...ate_limit_error.js => rate_limit_error.ts} | 2 +- .../{redirect_error.js => redirect_error.ts} | 2 +- ..._error.js => service_unavailable_error.ts} | 2 +- .../{timeout_error.js => timeout_error.ts} | 2 +- ...horized_error.js => unauthorized_error.ts} | 2 +- ...nown_api_error.js => unknown_api_error.ts} | 2 +- .../{easypost_error.js => easypost_error.ts} | 4 +- src/errors/error_handler.js | 99 ---- src/errors/error_handler.ts | 132 +++++ ...on_error.js => end_of_pagination_error.ts} | 4 +- ...{filtering_error.js => filtering_error.ts} | 2 +- src/errors/general/index.ts | 6 + ...bject_error.js => invalid_object_error.ts} | 2 +- ...er_error.js => invalid_parameter_error.ts} | 2 +- ...er_error.js => missing_parameter_error.ts} | 2 +- ...ror.js => signature_verification_error.ts} | 2 +- src/errors/index.ts | 4 + src/index.ts | 3 + src/models/address.js | 24 - src/models/api_key.js | 11 - src/models/batch.js | 17 - src/models/brand.js | 18 - src/models/carrier_account.js | 17 - src/models/carrier_type.js | 11 - src/models/customs_info.js | 19 - src/models/customs_item.js | 17 - src/models/easypost_object.js | 13 - src/models/end_shipper.js | 19 - src/models/event.js | 15 - src/models/form.js | 12 - src/models/insurance.js | 21 - src/models/order.js | 33 -- src/models/parcel.js | 14 - src/models/payload.js | 10 - src/models/pickup.js | 36 -- src/models/pickup_rate.js | 14 - src/models/postage_label.js | 18 - src/models/rate.js | 22 - src/models/refund.js | 14 - src/models/report.js | 16 - src/models/scan_form.js | 16 - src/models/shipment.js | 49 -- src/models/tracker.js | 21 - src/models/user.js | 22 - src/models/webhook.js | 11 - src/services/address_service.js | 107 ---- src/services/address_service/Address.ts | 87 ++++ .../AddressCreateParameters.ts | 12 +- .../address_service/AddressListParameters.ts | 6 + .../services/address_service/Verification.ts | 8 +- .../address_service/VerificationDetails.ts | 4 +- .../services/address_service/Verifications.ts | 8 +- src/services/address_service/index.ts | 124 +++++ src/services/api_key_service/ApiKey.ts | 24 + .../index.ts} | 41 +- src/services/base_service.js | 231 --------- src/services/base_service.ts | 131 +++++ src/services/batch_service/Batch.ts | 56 ++ .../batch_service/BatchCreateParameters.ts | 5 + .../batch_service/BatchListParameters.ts | 6 + .../services/batch_service/BatchShipment.ts | 6 +- src/services/batch_service/BatchState.ts | 9 + src/services/batch_service/BatchStatus.ts | 6 + src/services/batch_service/BatchStatuses.ts | 3 + .../index.ts} | 105 ++-- src/services/beta_rate_service.js | 27 - src/services/beta_rate_service/index.ts | 32 ++ .../beta_referral_customer_service.js | 61 --- .../beta_referral_customer_service/index.ts | 68 +++ .../services/billing_service/PaymentMethod.ts | 21 +- .../index.ts} | 56 +- .../carrier_account_service/CarrierAccount.ts | 63 +++ .../CarrierAccountCreateParameters.ts | 7 + .../CarrierAccountField.ts | 4 +- .../CarrierAccountFields.ts | 6 +- .../index.ts} | 87 ++-- src/services/carrier_metadata_service.js | 28 - .../CarrierMetadata.ts | 26 +- .../carrier_metadata_service/index.ts | 36 ++ src/services/carrier_type_service.js | 26 - .../carrier_type_service/CarrierType.ts | 24 +- .../CarrierTypeCredentials.ts | 6 +- .../carrier_type_service/CarrierTypeFields.ts | 6 +- src/services/carrier_type_service/index.ts | 35 ++ .../customs_info_service/CustomsInfo.ts | 70 +++ .../CustomsInfoCreateParameters.ts | 7 + .../index.ts} | 28 +- .../customs_item_service/CustomsItem.ts | 55 ++ .../CustomsItemCreateParameters.ts | 7 + .../index.ts} | 28 +- .../end_shipper_service/EndShipper.ts | 62 +++ .../EndShipperCreateParameters.ts | 7 + .../EndShipperListParameters.ts | 6 + .../index.ts} | 54 +- src/services/event_service.js | 80 --- src/services/event_service/Event.ts | 46 ++ .../event_service/EventListParameters.ts | 6 + src/services/event_service/Payload/Payload.ts | 15 + .../Payload/PayloadListParameters.ts | 6 + src/services/event_service/Payload/index.ts | 1 + src/services/event_service/index.ts | 95 ++++ src/services/index.ts | 27 + .../services/insurance_service/Fee.ts | 16 +- src/services/insurance_service/FeeType.ts | 5 + src/services/insurance_service/Insurance.ts | 85 +++ .../InsuranceCreateParameters.ts | 6 +- .../insurance_service/InsuranceStatus.ts | 6 + .../index.ts} | 62 +-- src/services/order_service/Order.ts | 62 +++ .../order_service/OrderCreateParameters.ts | 10 +- .../index.ts} | 52 +- src/services/parcel_service/Parcel.ts | 43 ++ .../parcel_service/ParcelCreateParameters.ts | 11 +- .../index.ts} | 28 +- src/services/pickup_service.js | 96 ---- src/services/pickup_service/Pickup.ts | 89 ++++ .../pickup_service/PickupCreateParameters.ts | 30 ++ .../pickup_service/PickupListParameters.ts | 6 + src/services/pickup_service/PickupRate.ts | 32 ++ src/services/pickup_service/index.ts | 108 ++++ src/services/rate_service/Rate.ts | 83 +++ .../index.ts} | 12 +- src/services/referral_customer_service.js | 185 ------- .../referral_customer_service/Referral.ts | 8 + .../ReferralCreateParameters.ts | 7 + .../ReferralListParameters.ts | 6 + .../referral_customer_service/index.ts | 216 ++++++++ src/services/refund_service.js | 59 --- src/services/refund_service/Refund.ts | 36 ++ .../refund_service/RefundCreateParameters.ts | 4 +- .../refund_service/RefundListParameters.ts | 6 + src/services/refund_service/index.ts | 72 +++ src/services/report_service.js | 68 --- src/services/report_service/Report.ts | 59 +++ .../report_service/ReportCreateParameters.ts | 7 +- .../report_service/ReportListParameters.ts | 9 + .../report_service/ReportObjectType.ts | 15 + src/services/report_service/index.ts | 87 ++++ src/services/scan_form_service.js | 71 --- src/services/scan_form_service/ScanForm.ts | 54 ++ .../ScanFormCreateParameters.ts | 8 + .../ScanFormListParameters.ts | 6 + src/services/scan_form_service/index.ts | 87 ++++ src/services/shipment_service.js | 261 ---------- src/services/shipment_service/Form.ts | 31 ++ .../services/shipment_service/Message.ts | 4 +- .../shipment_service/Options/LabelFormat.ts | 1 + .../shipment_service/Options/Options.ts | 100 ++-- .../Options/PrintCustomCode.ts | 44 +- .../shipment_service/Options/index.ts | 3 + src/services/shipment_service/PostageLabel.ts | 19 + src/services/shipment_service/Shipment.ts | 151 ++++++ .../ShipmentCreateParameters.ts | 14 +- .../ShipmentListParameters.ts | 10 +- src/services/shipment_service/index.ts | 344 +++++++++++++ src/services/tracker_service.js | 71 --- .../services/tracker_service/CarrierDetail.ts | 8 +- src/services/tracker_service/Tracker.ts | 98 ++++ .../TrackerCreateParameters.ts | 4 +- .../tracker_service/TrackerListParameters.ts | 10 +- src/services/tracker_service/TrackerStatus.ts | 11 + .../tracker_service/TrackerStatusDetail.ts | 29 ++ .../tracker_service/TrackingDetail.ts | 10 +- .../tracker_service/TrackingLocation.ts | 6 +- src/services/tracker_service/index.ts | 92 ++++ .../services/user_service/Brand.ts | 33 +- src/services/user_service/User.ts | 76 +++ .../user_service/UserCreateParameters.ts | 4 + .../index.ts} | 101 ++-- src/services/webhook_service/Webhook.ts | 30 ++ .../WebhookCreateParameters.ts | 3 + .../webhook_service/WebhookListParameters.ts | 6 + .../index.ts} | 56 +- .../Error.d.ts => src/utils/errors/Error.ts | 8 +- src/utils/errors/ErrorCode.ts | 174 +++++++ .../utils/errors/FieldError.ts | 4 +- src/utils/errors/index.ts | 3 + src/utils/internal_util.js | 7 - types/utils.d.ts => src/utils/types.ts | 46 +- src/utils/util.js | 150 ------ src/utils/util.ts | 178 +++++++ test/services/address.test.js | 27 +- test/services/api_key.test.js | 9 +- test/services/base_service.test.js | 4 +- test/services/batch.test.js | 15 +- test/services/beta_rate.test.js | 7 +- test/services/beta_referral_customer.test.js | 2 +- test/services/billing.test.js | 2 +- test/services/carrier_account.test.js | 11 +- test/services/carrier_metadata.test.js | 2 +- test/services/carrier_type.test.js | 5 +- test/services/customs_info.test.js | 7 +- test/services/customs_item.test.js | 7 +- test/services/easypost.test.js | 4 +- test/services/end_shipper.test.js | 11 +- test/services/error.test.js | 30 +- test/services/event.test.js | 14 +- test/services/insurance.test.js | 13 +- test/services/order.test.js | 12 +- test/services/parcel.test.js | 7 +- test/services/pickup.test.js | 17 +- test/services/rate.test.js | 5 +- test/services/referral_customer.test.js | 9 +- test/services/refund.test.js | 11 +- test/services/report.test.js | 15 +- test/services/scan_form.test.js | 11 +- test/services/shipment.test.js | 24 +- test/services/tracker.test.js | 11 +- test/services/user.test.js | 18 +- test/services/webhook.test.js | 13 +- tsconfig.json | 12 + types/.eslintrc | 9 - types/Address/Address.d.ts | 192 ------- types/Address/AddressListParameters.d.ts | 6 - types/Address/index.d.ts | 5 - types/ApiKey/ApiKey.d.ts | 39 -- types/ApiKey/index.d.ts | 1 - types/Batch/Batch.d.ts | 179 ------- types/Batch/BatchCreateParameters.d.ts | 5 - types/Batch/BatchListParameters.d.ts | 6 - types/Batch/BatchState.d.ts | 9 - types/Batch/BatchStatus.d.ts | 6 - types/Batch/BatchStatuses.d.ts | 3 - types/Batch/index.d.ts | 6 - types/Billing/Billing.d.ts | 35 -- types/Billing/index.d.ts | 1 - types/Brand/index.d.ts | 1 - .../CarrierAccount/CarrierAccount.d.ts | 139 ----- .../CarrierAccountCreateParameters.d.ts | 5 - types/Carrier/CarrierAccount/index.d.ts | 4 - types/Carrier/CarrierMetadata/index.d.ts | 1 - types/Carrier/CarrierType/index.d.ts | 3 - types/Carrier/index.d.ts | 3 - types/Customs/CustomsInfo/CustomsInfo.d.ts | 107 ---- .../CustomsInfoCreateParameters.d.ts | 5 - types/Customs/CustomsInfo/index.d.ts | 1 - types/Customs/CustomsItem/CustomsItem.d.ts | 94 ---- .../CustomsItemCreateParameters.d.ts | 5 - types/Customs/CustomsItem/index.d.ts | 1 - types/Customs/index.d.ts | 2 - types/EasyPost.d.ts | 127 ----- types/EndShipper/EndShipper.d.ts | 130 ----- .../EndShipperCreateParameters.d.ts | 5 - .../EndShipper/EndShipperListParameters.d.ts | 6 - types/EndShipper/index.d.ts | 2 - types/Event/Event.d.ts | 92 ---- types/Event/EventListParameters.d.ts | 6 - types/Event/Payload/Payload.d.ts | 45 -- .../Event/Payload/PayloadListParameters.d.ts | 6 - types/Event/Payload/index.d.ts | 1 - types/Event/index.d.ts | 1 - types/Fee/FeeType.d.ts | 1 - types/Fee/index.d.ts | 2 - types/Insurance/Insurance.d.ts | 174 ------- types/Insurance/InsuranceStatus.d.ts | 1 - types/Insurance/index.d.ts | 3 - types/Order/Order.d.ts | 135 ----- types/Order/index.d.ts | 2 - types/Parcel/Parcel.d.ts | 82 --- types/Parcel/index.d.ts | 1 - types/PaymentMethod/index.d.ts | 1 - types/Pickup/Pickup.d.ts | 199 -------- types/Pickup/PickupCreateParameters.d.ts | 28 - types/Pickup/PickupListParameters.d.ts | 6 - types/Pickup/PickupRate.d.ts | 31 -- types/Pickup/index.d.ts | 3 - types/Rate/Rate.d.ts | 93 ---- types/Rate/index.d.ts | 1 - types/Referral/Referral.d.ts | 115 ----- types/Referral/ReferralCreateParameters.d.ts | 5 - types/Referral/ReferralListParameters.d.ts | 6 - types/Referral/index.d.ts | 2 - types/Refund/Refund.d.ts | 100 ---- types/Refund/RefundListParameters.d.ts | 6 - types/Refund/index.d.ts | 2 - types/Report/Report.d.ts | 133 ----- types/Report/ReportListParameters.d.ts | 6 - types/Report/ReportObjectType.d.ts | 7 - types/Report/index.d.ts | 2 - types/ScanForm/ScanForm.d.ts | 126 ----- types/ScanForm/ScanFormCreateParameters.d.ts | 6 - types/ScanForm/ScanFormListParameters.d.ts | 6 - types/ScanForm/index.d.ts | 1 - types/Shipment/Form.d.ts | 30 -- types/Shipment/Options/LabelFormat.d.ts | 1 - types/Shipment/Options/index.d.ts | 3 - types/Shipment/PostageLabel.d.ts | 18 - types/Shipment/Rate.d.ts | 83 --- types/Shipment/Shipment.d.ts | 346 ------------- types/Shipment/index.d.ts | 8 - types/Tracker/Tracker.d.ts | 184 ------- types/Tracker/TrackerStatus.d.ts | 11 - types/Tracker/TrackerStatusDetail.d.ts | 29 -- types/Tracker/index.d.ts | 7 - types/User/User.d.ts | 190 ------- types/User/UserCreateParameters.d.ts | 4 - types/User/index.d.ts | 1 - types/Utility/Utils.d.ts | 47 -- types/Utility/index.d.ts | 1 - types/Webhook/Webhook.d.ts | 93 ---- types/Webhook/WebhookCreateParameters.d.ts | 3 - types/Webhook/WebhookListParameters.d.ts | 6 - types/Webhook/index.d.ts | 2 - types/base.d.ts | 32 -- types/demo/README.md | 3 - types/demo/index.ts | 10 - types/demo/package-lock.json | 322 ------------ types/demo/package.json | 19 - types/errors/ErrorCode.d.ts | 174 ------- types/errors/index.d.ts | 3 - types/index.d.ts | 27 - webpack.config.babel.js | 6 +- 482 files changed, 12341 insertions(+), 7536 deletions(-) create mode 100644 out/package.json create mode 100644 out/src/constants.js create mode 100644 out/src/easypost.js create mode 100644 out/src/errors/api/api_error.js create mode 100644 out/src/errors/api/bad_request_error.js create mode 100644 out/src/errors/api/external_api_error.js create mode 100644 out/src/errors/api/forbidden_error.js create mode 100644 out/src/errors/api/gateway_timeout_error.js create mode 100644 out/src/errors/api/http_error.js create mode 100644 out/src/errors/api/index.js create mode 100644 out/src/errors/api/internal_server_error.js create mode 100644 out/src/errors/api/invalid_request_error.js create mode 100644 out/src/errors/api/method_not_allowed_error.js create mode 100644 out/src/errors/api/not_found_error.js create mode 100644 out/src/errors/api/payment_error.js create mode 100644 out/src/errors/api/rate_limit_error.js create mode 100644 out/src/errors/api/redirect_error.js create mode 100644 out/src/errors/api/service_unavailable_error.js create mode 100644 out/src/errors/api/timeout_error.js create mode 100644 out/src/errors/api/unauthorized_error.js create mode 100644 out/src/errors/api/unknown_api_error.js create mode 100644 out/src/errors/easypost_error.js create mode 100644 out/src/errors/error_handler.js create mode 100644 out/src/errors/general/end_of_pagination_error.js create mode 100644 out/src/errors/general/filtering_error.js create mode 100644 out/src/errors/general/index.js create mode 100644 out/src/errors/general/invalid_object_error.js create mode 100644 out/src/errors/general/invalid_parameter_error.js create mode 100644 out/src/errors/general/missing_parameter_error.js create mode 100644 out/src/errors/general/signature_verification_error.js create mode 100644 out/src/errors/index.js create mode 100644 out/src/index.js create mode 100644 out/src/services/address_service/Address.js create mode 100644 out/src/services/address_service/AddressCreateParameters.js create mode 100644 out/src/services/address_service/AddressListParameters.js create mode 100644 out/src/services/address_service/Verification.js create mode 100644 out/src/services/address_service/VerificationDetails.js create mode 100644 out/src/services/address_service/Verifications.js create mode 100644 out/src/services/address_service/index.js create mode 100644 out/src/services/api_key_service/ApiKey.js create mode 100644 out/src/services/api_key_service/index.js create mode 100644 out/src/services/base_service.js create mode 100644 out/src/services/batch_service/Batch.js create mode 100644 out/src/services/batch_service/BatchCreateParameters.js create mode 100644 out/src/services/batch_service/BatchListParameters.js create mode 100644 out/src/services/batch_service/BatchShipment.js create mode 100644 out/src/services/batch_service/BatchState.js create mode 100644 out/src/services/batch_service/BatchStatus.js create mode 100644 out/src/services/batch_service/BatchStatuses.js create mode 100644 out/src/services/batch_service/index.js create mode 100644 out/src/services/beta_rate_service/index.js create mode 100644 out/src/services/beta_referral_customer_service/index.js create mode 100644 out/src/services/billing_service/PaymentMethod.js create mode 100644 out/src/services/billing_service/index.js create mode 100644 out/src/services/carrier_account_service/CarrierAccount.js create mode 100644 out/src/services/carrier_account_service/CarrierAccountCreateParameters.js create mode 100644 out/src/services/carrier_account_service/CarrierAccountField.js create mode 100644 out/src/services/carrier_account_service/CarrierAccountFields.js create mode 100644 out/src/services/carrier_account_service/index.js create mode 100644 out/src/services/carrier_metadata_service/CarrierMetadata.js create mode 100644 out/src/services/carrier_metadata_service/index.js create mode 100644 out/src/services/carrier_type_service/CarrierType.js create mode 100644 out/src/services/carrier_type_service/CarrierTypeCredentials.js create mode 100644 out/src/services/carrier_type_service/CarrierTypeFields.js create mode 100644 out/src/services/carrier_type_service/index.js create mode 100644 out/src/services/customs_info_service/CustomsInfo.js create mode 100644 out/src/services/customs_info_service/CustomsInfoCreateParameters.js create mode 100644 out/src/services/customs_info_service/index.js create mode 100644 out/src/services/customs_item_service/CustomsItem.js create mode 100644 out/src/services/customs_item_service/CustomsItemCreateParameters.js create mode 100644 out/src/services/customs_item_service/index.js create mode 100644 out/src/services/end_shipper_service/EndShipper.js create mode 100644 out/src/services/end_shipper_service/EndShipperCreateParameters.js create mode 100644 out/src/services/end_shipper_service/EndShipperListParameters.js create mode 100644 out/src/services/end_shipper_service/index.js create mode 100644 out/src/services/event_service/Event.js create mode 100644 out/src/services/event_service/EventListParameters.js create mode 100644 out/src/services/event_service/Payload/Payload.js create mode 100644 out/src/services/event_service/Payload/PayloadListParameters.js create mode 100644 out/src/services/event_service/Payload/index.js create mode 100644 out/src/services/event_service/index.js create mode 100644 out/src/services/index.js create mode 100644 out/src/services/insurance_service/Fee.js create mode 100644 out/src/services/insurance_service/FeeType.js create mode 100644 out/src/services/insurance_service/Insurance.js create mode 100644 out/src/services/insurance_service/InsuranceCreateParameters.js create mode 100644 out/src/services/insurance_service/InsuranceStatus.js create mode 100644 out/src/services/insurance_service/index.js create mode 100644 out/src/services/order_service/Order.js create mode 100644 out/src/services/order_service/OrderCreateParameters.js create mode 100644 out/src/services/order_service/index.js create mode 100644 out/src/services/parcel_service/Parcel.js create mode 100644 out/src/services/parcel_service/ParcelCreateParameters.js create mode 100644 out/src/services/parcel_service/index.js create mode 100644 out/src/services/pickup_service/Pickup.js create mode 100644 out/src/services/pickup_service/PickupCreateParameters.js create mode 100644 out/src/services/pickup_service/PickupListParameters.js create mode 100644 out/src/services/pickup_service/PickupRate.js create mode 100644 out/src/services/pickup_service/index.js create mode 100644 out/src/services/rate_service/Rate.js create mode 100644 out/src/services/rate_service/index.js create mode 100644 out/src/services/referral_customer_service/Referral.js create mode 100644 out/src/services/referral_customer_service/ReferralCreateParameters.js create mode 100644 out/src/services/referral_customer_service/ReferralListParameters.js create mode 100644 out/src/services/referral_customer_service/index.js create mode 100644 out/src/services/refund_service/Refund.js create mode 100644 out/src/services/refund_service/RefundCreateParameters.js create mode 100644 out/src/services/refund_service/RefundListParameters.js create mode 100644 out/src/services/refund_service/index.js create mode 100644 out/src/services/report_service/Report.js create mode 100644 out/src/services/report_service/ReportCreateParameters.js create mode 100644 out/src/services/report_service/ReportListParameters.js create mode 100644 out/src/services/report_service/ReportObjectType.js create mode 100644 out/src/services/report_service/index.js create mode 100644 out/src/services/scan_form_service/ScanForm.js create mode 100644 out/src/services/scan_form_service/ScanFormCreateParameters.js create mode 100644 out/src/services/scan_form_service/ScanFormListParameters.js create mode 100644 out/src/services/scan_form_service/index.js create mode 100644 out/src/services/shipment_service/Form.js create mode 100644 out/src/services/shipment_service/Message.js create mode 100644 out/src/services/shipment_service/Options/LabelFormat.js create mode 100644 out/src/services/shipment_service/Options/Options.js create mode 100644 out/src/services/shipment_service/Options/PrintCustomCode.js create mode 100644 out/src/services/shipment_service/Options/index.js create mode 100644 out/src/services/shipment_service/PostageLabel.js create mode 100644 out/src/services/shipment_service/Shipment.js create mode 100644 out/src/services/shipment_service/ShipmentCreateParameters.js create mode 100644 out/src/services/shipment_service/ShipmentListParameters.js create mode 100644 out/src/services/shipment_service/index.js create mode 100644 out/src/services/tracker_service/CarrierDetail.js create mode 100644 out/src/services/tracker_service/Tracker.js create mode 100644 out/src/services/tracker_service/TrackerCreateParameters.js create mode 100644 out/src/services/tracker_service/TrackerListParameters.js create mode 100644 out/src/services/tracker_service/TrackerStatus.js create mode 100644 out/src/services/tracker_service/TrackerStatusDetail.js create mode 100644 out/src/services/tracker_service/TrackingDetail.js create mode 100644 out/src/services/tracker_service/TrackingLocation.js create mode 100644 out/src/services/tracker_service/index.js create mode 100644 out/src/services/user_service/Brand.js create mode 100644 out/src/services/user_service/User.js create mode 100644 out/src/services/user_service/UserCreateParameters.js create mode 100644 out/src/services/user_service/index.js create mode 100644 out/src/services/webhook_service/Webhook.js create mode 100644 out/src/services/webhook_service/WebhookCreateParameters.js create mode 100644 out/src/services/webhook_service/WebhookListParameters.js create mode 100644 out/src/services/webhook_service/index.js create mode 100644 out/src/utils/errors/Error.js create mode 100644 out/src/utils/errors/ErrorCode.js create mode 100644 out/src/utils/errors/FieldError.js create mode 100644 out/src/utils/errors/index.js create mode 100644 out/src/utils/types.js create mode 100644 out/src/utils/util.js delete mode 100644 src/constants.js create mode 100644 src/constants.ts delete mode 100644 src/easypost.js create mode 100644 src/easypost.ts rename src/errors/api/{api_error.js => api_error.ts} (68%) rename src/errors/api/{bad_request_error.js => bad_request_error.ts} (93%) rename src/errors/api/{external_api_error.js => external_api_error.ts} (91%) rename src/errors/api/{forbidden_error.js => forbidden_error.ts} (93%) rename src/errors/api/{gateway_timeout_error.js => gateway_timeout_error.ts} (94%) rename src/errors/api/{http_error.js => http_error.ts} (93%) create mode 100644 src/errors/api/index.ts rename src/errors/api/{internal_server_error.js => internal_server_error.ts} (94%) rename src/errors/api/{invalid_request_error.js => invalid_request_error.ts} (94%) rename src/errors/api/{method_not_allowed_error.js => method_not_allowed_error.ts} (94%) rename src/errors/api/{not_found_error.js => not_found_error.ts} (93%) rename src/errors/api/{payment_error.js => payment_error.ts} (93%) rename src/errors/api/{rate_limit_error.js => rate_limit_error.ts} (93%) rename src/errors/api/{redirect_error.js => redirect_error.ts} (93%) rename src/errors/api/{service_unavailable_error.js => service_unavailable_error.ts} (94%) rename src/errors/api/{timeout_error.js => timeout_error.ts} (93%) rename src/errors/api/{unauthorized_error.js => unauthorized_error.ts} (93%) rename src/errors/api/{unknown_api_error.js => unknown_api_error.ts} (94%) rename src/errors/{easypost_error.js => easypost_error.ts} (67%) delete mode 100644 src/errors/error_handler.js create mode 100644 src/errors/error_handler.ts rename src/errors/general/{end_of_pagination_error.js => end_of_pagination_error.ts} (80%) rename src/errors/general/{filtering_error.js => filtering_error.ts} (86%) create mode 100644 src/errors/general/index.ts rename src/errors/general/{invalid_object_error.js => invalid_object_error.ts} (87%) rename src/errors/general/{invalid_parameter_error.js => invalid_parameter_error.ts} (86%) rename src/errors/general/{missing_parameter_error.js => missing_parameter_error.ts} (86%) rename src/errors/general/{signature_verification_error.js => signature_verification_error.ts} (88%) create mode 100644 src/errors/index.ts create mode 100644 src/index.ts delete mode 100644 src/models/address.js delete mode 100644 src/models/api_key.js delete mode 100644 src/models/batch.js delete mode 100644 src/models/brand.js delete mode 100644 src/models/carrier_account.js delete mode 100644 src/models/carrier_type.js delete mode 100644 src/models/customs_info.js delete mode 100644 src/models/customs_item.js delete mode 100644 src/models/easypost_object.js delete mode 100644 src/models/end_shipper.js delete mode 100644 src/models/event.js delete mode 100644 src/models/form.js delete mode 100644 src/models/insurance.js delete mode 100644 src/models/order.js delete mode 100644 src/models/parcel.js delete mode 100644 src/models/payload.js delete mode 100644 src/models/pickup.js delete mode 100644 src/models/pickup_rate.js delete mode 100644 src/models/postage_label.js delete mode 100644 src/models/rate.js delete mode 100644 src/models/refund.js delete mode 100644 src/models/report.js delete mode 100644 src/models/scan_form.js delete mode 100644 src/models/shipment.js delete mode 100644 src/models/tracker.js delete mode 100644 src/models/user.js delete mode 100644 src/models/webhook.js delete mode 100644 src/services/address_service.js create mode 100644 src/services/address_service/Address.ts rename {types/Address => src/services/address_service}/AddressCreateParameters.ts (69%) create mode 100644 src/services/address_service/AddressListParameters.ts rename types/Address/Verification.d.ts => src/services/address_service/Verification.ts (69%) rename types/Address/VerificationDetails.d.ts => src/services/address_service/VerificationDetails.ts (86%) rename types/Address/Verifications.d.ts => src/services/address_service/Verifications.ts (78%) create mode 100644 src/services/address_service/index.ts create mode 100644 src/services/api_key_service/ApiKey.ts rename src/services/{api_key_service.js => api_key_service/index.ts} (51%) delete mode 100644 src/services/base_service.js create mode 100644 src/services/base_service.ts create mode 100644 src/services/batch_service/Batch.ts create mode 100644 src/services/batch_service/BatchCreateParameters.ts create mode 100644 src/services/batch_service/BatchListParameters.ts rename types/Batch/BatchShipment.d.ts => src/services/batch_service/BatchShipment.ts (86%) create mode 100644 src/services/batch_service/BatchState.ts create mode 100644 src/services/batch_service/BatchStatus.ts create mode 100644 src/services/batch_service/BatchStatuses.ts rename src/services/{batch_service.js => batch_service/index.ts} (53%) delete mode 100644 src/services/beta_rate_service.js create mode 100644 src/services/beta_rate_service/index.ts delete mode 100644 src/services/beta_referral_customer_service.js create mode 100644 src/services/beta_referral_customer_service/index.ts rename types/PaymentMethod/PaymentMethod.d.ts => src/services/billing_service/PaymentMethod.ts (64%) rename src/services/{billing_service.js => billing_service/index.ts} (64%) create mode 100644 src/services/carrier_account_service/CarrierAccount.ts create mode 100644 src/services/carrier_account_service/CarrierAccountCreateParameters.ts rename types/Carrier/CarrierAccount/CarrierAccountField.d.ts => src/services/carrier_account_service/CarrierAccountField.ts (92%) rename types/Carrier/CarrierAccount/CarrierAccountFields.d.ts => src/services/carrier_account_service/CarrierAccountFields.ts (82%) rename src/services/{carrier_account_service.js => carrier_account_service/index.ts} (52%) delete mode 100644 src/services/carrier_metadata_service.js rename types/Carrier/CarrierMetadata/CarrierMetadata.d.ts => src/services/carrier_metadata_service/CarrierMetadata.ts (52%) create mode 100644 src/services/carrier_metadata_service/index.ts delete mode 100644 src/services/carrier_type_service.js rename types/Carrier/CarrierType/CarrierType.d.ts => src/services/carrier_type_service/CarrierType.ts (69%) rename types/Carrier/CarrierType/CarrierTypeCredentials.d.ts => src/services/carrier_type_service/CarrierTypeCredentials.ts (82%) rename types/Carrier/CarrierType/CarrierTypeFields.d.ts => src/services/carrier_type_service/CarrierTypeFields.ts (88%) create mode 100644 src/services/carrier_type_service/index.ts create mode 100644 src/services/customs_info_service/CustomsInfo.ts create mode 100644 src/services/customs_info_service/CustomsInfoCreateParameters.ts rename src/services/{customs_info_service.js => customs_info_service/index.ts} (52%) create mode 100644 src/services/customs_item_service/CustomsItem.ts create mode 100644 src/services/customs_item_service/CustomsItemCreateParameters.ts rename src/services/{customs_item_service.js => customs_item_service/index.ts} (51%) create mode 100644 src/services/end_shipper_service/EndShipper.ts create mode 100644 src/services/end_shipper_service/EndShipperCreateParameters.ts create mode 100644 src/services/end_shipper_service/EndShipperListParameters.ts rename src/services/{end_shipper_service.js => end_shipper_service/index.ts} (50%) delete mode 100644 src/services/event_service.js create mode 100644 src/services/event_service/Event.ts create mode 100644 src/services/event_service/EventListParameters.ts create mode 100644 src/services/event_service/Payload/Payload.ts create mode 100644 src/services/event_service/Payload/PayloadListParameters.ts create mode 100644 src/services/event_service/Payload/index.ts create mode 100644 src/services/event_service/index.ts create mode 100644 src/services/index.ts rename types/Fee/Fee.d.ts => src/services/insurance_service/Fee.ts (80%) create mode 100644 src/services/insurance_service/FeeType.ts create mode 100644 src/services/insurance_service/Insurance.ts rename types/Insurance/InsuranceCreateParameters.d.ts => src/services/insurance_service/InsuranceCreateParameters.ts (85%) create mode 100644 src/services/insurance_service/InsuranceStatus.ts rename src/services/{insurance_service.js => insurance_service/index.ts} (54%) create mode 100644 src/services/order_service/Order.ts rename types/Order/OrderCreateParameters.d.ts => src/services/order_service/OrderCreateParameters.ts (54%) rename src/services/{order_service.js => order_service/index.ts} (53%) create mode 100644 src/services/parcel_service/Parcel.ts rename types/Parcel/ParcelCreateParameters.d.ts => src/services/parcel_service/ParcelCreateParameters.ts (67%) rename src/services/{parcel_service.js => parcel_service/index.ts} (52%) delete mode 100644 src/services/pickup_service.js create mode 100644 src/services/pickup_service/Pickup.ts create mode 100644 src/services/pickup_service/PickupCreateParameters.ts create mode 100644 src/services/pickup_service/PickupListParameters.ts create mode 100644 src/services/pickup_service/PickupRate.ts create mode 100644 src/services/pickup_service/index.ts create mode 100644 src/services/rate_service/Rate.ts rename src/services/{rate_service.js => rate_service/index.ts} (70%) delete mode 100644 src/services/referral_customer_service.js create mode 100644 src/services/referral_customer_service/Referral.ts create mode 100644 src/services/referral_customer_service/ReferralCreateParameters.ts create mode 100644 src/services/referral_customer_service/ReferralListParameters.ts create mode 100644 src/services/referral_customer_service/index.ts delete mode 100644 src/services/refund_service.js create mode 100644 src/services/refund_service/Refund.ts rename types/Refund/RefundCreateParameters.d.ts => src/services/refund_service/RefundCreateParameters.ts (85%) create mode 100644 src/services/refund_service/RefundListParameters.ts create mode 100644 src/services/refund_service/index.ts delete mode 100644 src/services/report_service.js create mode 100644 src/services/report_service/Report.ts rename types/Report/ReportCreateParameters.d.ts => src/services/report_service/ReportCreateParameters.ts (62%) create mode 100644 src/services/report_service/ReportListParameters.ts create mode 100644 src/services/report_service/ReportObjectType.ts create mode 100644 src/services/report_service/index.ts delete mode 100644 src/services/scan_form_service.js create mode 100644 src/services/scan_form_service/ScanForm.ts create mode 100644 src/services/scan_form_service/ScanFormCreateParameters.ts create mode 100644 src/services/scan_form_service/ScanFormListParameters.ts create mode 100644 src/services/scan_form_service/index.ts delete mode 100644 src/services/shipment_service.js create mode 100644 src/services/shipment_service/Form.ts rename types/Shipment/Message.d.ts => src/services/shipment_service/Message.ts (96%) create mode 100644 src/services/shipment_service/Options/LabelFormat.ts rename types/Shipment/Options/Options.d.ts => src/services/shipment_service/Options/Options.ts (89%) rename types/Shipment/Options/PrintCustomCode.d.ts => src/services/shipment_service/Options/PrintCustomCode.ts (83%) create mode 100644 src/services/shipment_service/Options/index.ts create mode 100644 src/services/shipment_service/PostageLabel.ts create mode 100644 src/services/shipment_service/Shipment.ts rename types/Shipment/ShipmentCreateParameters.d.ts => src/services/shipment_service/ShipmentCreateParameters.ts (54%) rename types/Shipment/ShipmentListParameters.d.ts => src/services/shipment_service/ShipmentListParameters.ts (56%) create mode 100644 src/services/shipment_service/index.ts delete mode 100644 src/services/tracker_service.js rename types/Tracker/CarrierDetail.d.ts => src/services/tracker_service/CarrierDetail.ts (90%) create mode 100644 src/services/tracker_service/Tracker.ts rename types/Tracker/TrackerCreateParameters.d.ts => src/services/tracker_service/TrackerCreateParameters.ts (83%) rename types/Tracker/TrackerListParameters.d.ts => src/services/tracker_service/TrackerListParameters.ts (53%) create mode 100644 src/services/tracker_service/TrackerStatus.ts create mode 100644 src/services/tracker_service/TrackerStatusDetail.ts rename types/Tracker/TrackingDetail.d.ts => src/services/tracker_service/TrackingDetail.ts (75%) rename types/Tracker/TrackingLocation.d.ts => src/services/tracker_service/TrackingLocation.ts (77%) create mode 100644 src/services/tracker_service/index.ts rename types/Brand/Brand.d.ts => src/services/user_service/Brand.ts (52%) create mode 100644 src/services/user_service/User.ts create mode 100644 src/services/user_service/UserCreateParameters.ts rename src/services/{user_service.js => user_service/index.ts} (51%) create mode 100644 src/services/webhook_service/Webhook.ts create mode 100644 src/services/webhook_service/WebhookCreateParameters.ts create mode 100644 src/services/webhook_service/WebhookListParameters.ts rename src/services/{webhook_service.js => webhook_service/index.ts} (54%) rename types/errors/Error.d.ts => src/utils/errors/Error.ts (86%) create mode 100644 src/utils/errors/ErrorCode.ts rename types/errors/FieldError.d.ts => src/utils/errors/FieldError.ts (79%) create mode 100644 src/utils/errors/index.ts delete mode 100644 src/utils/internal_util.js rename types/utils.d.ts => src/utils/types.ts (52%) delete mode 100644 src/utils/util.js create mode 100644 src/utils/util.ts create mode 100644 tsconfig.json delete mode 100644 types/.eslintrc delete mode 100644 types/Address/Address.d.ts delete mode 100644 types/Address/AddressListParameters.d.ts delete mode 100644 types/Address/index.d.ts delete mode 100644 types/ApiKey/ApiKey.d.ts delete mode 100644 types/ApiKey/index.d.ts delete mode 100644 types/Batch/Batch.d.ts delete mode 100644 types/Batch/BatchCreateParameters.d.ts delete mode 100644 types/Batch/BatchListParameters.d.ts delete mode 100644 types/Batch/BatchState.d.ts delete mode 100644 types/Batch/BatchStatus.d.ts delete mode 100644 types/Batch/BatchStatuses.d.ts delete mode 100644 types/Batch/index.d.ts delete mode 100644 types/Billing/Billing.d.ts delete mode 100644 types/Billing/index.d.ts delete mode 100644 types/Brand/index.d.ts delete mode 100644 types/Carrier/CarrierAccount/CarrierAccount.d.ts delete mode 100644 types/Carrier/CarrierAccount/CarrierAccountCreateParameters.d.ts delete mode 100644 types/Carrier/CarrierAccount/index.d.ts delete mode 100644 types/Carrier/CarrierMetadata/index.d.ts delete mode 100644 types/Carrier/CarrierType/index.d.ts delete mode 100644 types/Carrier/index.d.ts delete mode 100644 types/Customs/CustomsInfo/CustomsInfo.d.ts delete mode 100644 types/Customs/CustomsInfo/CustomsInfoCreateParameters.d.ts delete mode 100644 types/Customs/CustomsInfo/index.d.ts delete mode 100644 types/Customs/CustomsItem/CustomsItem.d.ts delete mode 100644 types/Customs/CustomsItem/CustomsItemCreateParameters.d.ts delete mode 100644 types/Customs/CustomsItem/index.d.ts delete mode 100644 types/Customs/index.d.ts delete mode 100644 types/EasyPost.d.ts delete mode 100644 types/EndShipper/EndShipper.d.ts delete mode 100644 types/EndShipper/EndShipperCreateParameters.d.ts delete mode 100644 types/EndShipper/EndShipperListParameters.d.ts delete mode 100644 types/EndShipper/index.d.ts delete mode 100644 types/Event/Event.d.ts delete mode 100644 types/Event/EventListParameters.d.ts delete mode 100644 types/Event/Payload/Payload.d.ts delete mode 100644 types/Event/Payload/PayloadListParameters.d.ts delete mode 100644 types/Event/Payload/index.d.ts delete mode 100644 types/Event/index.d.ts delete mode 100644 types/Fee/FeeType.d.ts delete mode 100644 types/Fee/index.d.ts delete mode 100644 types/Insurance/Insurance.d.ts delete mode 100644 types/Insurance/InsuranceStatus.d.ts delete mode 100644 types/Insurance/index.d.ts delete mode 100644 types/Order/Order.d.ts delete mode 100644 types/Order/index.d.ts delete mode 100644 types/Parcel/Parcel.d.ts delete mode 100644 types/Parcel/index.d.ts delete mode 100644 types/PaymentMethod/index.d.ts delete mode 100644 types/Pickup/Pickup.d.ts delete mode 100644 types/Pickup/PickupCreateParameters.d.ts delete mode 100644 types/Pickup/PickupListParameters.d.ts delete mode 100644 types/Pickup/PickupRate.d.ts delete mode 100644 types/Pickup/index.d.ts delete mode 100644 types/Rate/Rate.d.ts delete mode 100644 types/Rate/index.d.ts delete mode 100644 types/Referral/Referral.d.ts delete mode 100644 types/Referral/ReferralCreateParameters.d.ts delete mode 100644 types/Referral/ReferralListParameters.d.ts delete mode 100644 types/Referral/index.d.ts delete mode 100644 types/Refund/Refund.d.ts delete mode 100644 types/Refund/RefundListParameters.d.ts delete mode 100644 types/Refund/index.d.ts delete mode 100644 types/Report/Report.d.ts delete mode 100644 types/Report/ReportListParameters.d.ts delete mode 100644 types/Report/ReportObjectType.d.ts delete mode 100644 types/Report/index.d.ts delete mode 100644 types/ScanForm/ScanForm.d.ts delete mode 100644 types/ScanForm/ScanFormCreateParameters.d.ts delete mode 100644 types/ScanForm/ScanFormListParameters.d.ts delete mode 100644 types/ScanForm/index.d.ts delete mode 100644 types/Shipment/Form.d.ts delete mode 100644 types/Shipment/Options/LabelFormat.d.ts delete mode 100644 types/Shipment/Options/index.d.ts delete mode 100644 types/Shipment/PostageLabel.d.ts delete mode 100644 types/Shipment/Rate.d.ts delete mode 100644 types/Shipment/Shipment.d.ts delete mode 100644 types/Shipment/index.d.ts delete mode 100644 types/Tracker/Tracker.d.ts delete mode 100644 types/Tracker/TrackerStatus.d.ts delete mode 100644 types/Tracker/TrackerStatusDetail.d.ts delete mode 100644 types/Tracker/index.d.ts delete mode 100644 types/User/User.d.ts delete mode 100644 types/User/UserCreateParameters.d.ts delete mode 100644 types/User/index.d.ts delete mode 100644 types/Utility/Utils.d.ts delete mode 100644 types/Utility/index.d.ts delete mode 100644 types/Webhook/Webhook.d.ts delete mode 100644 types/Webhook/WebhookCreateParameters.d.ts delete mode 100644 types/Webhook/WebhookListParameters.d.ts delete mode 100644 types/Webhook/index.d.ts delete mode 100644 types/base.d.ts delete mode 100644 types/demo/README.md delete mode 100644 types/demo/index.ts delete mode 100644 types/demo/package-lock.json delete mode 100644 types/demo/package.json delete mode 100644 types/errors/ErrorCode.d.ts delete mode 100644 types/errors/index.d.ts delete mode 100644 types/index.d.ts diff --git a/out/package.json b/out/package.json new file mode 100644 index 000000000..0009749e2 --- /dev/null +++ b/out/package.json @@ -0,0 +1,90 @@ +{ + "name": "@easypost/api", + "description": "EasyPost Node Client Library", + "version": "7.3.0", + "author": "Easypost Engineering ", + "homepage": "https://easypost.com", + "bin": { + "easypost": "./repl.js" + }, + "repository": { + "type": "git", + "url": "git://github.com/easypost/easypost-node.git" + }, + "main": "index.js", + "types": "types/index.d.ts", + "license": "MIT", + "engines": { + "node": ">= 12.0" + }, + "scripts": { + "build": "npm run build:typescript && npm run build:webpack", + "build:webpack": "webpack --config webpack.config.babel.js", + "build:typescript": "tsc", + "clean": "rm -rf ./dist ./nyc_output ./node_modules/.cache ./coverage", + "coverage": "cross-env NODE_ENV=test nyc npm run test", + "docs": "./node_modules/.bin/jsdoc src/models src/services src/errors src/utils -d docs", + "format": "prettier --write .", + "formatCheck": "prettier --check .", + "lint": "eslint --ext .js,.ts .", + "lintFix": "eslint --ext .js,.ts --fix .", + "prepublishOnly": "npm run clean && npm run build && npm run test && npm run lint && npm run formatCheck", + "repl": "./repl.js --local easypost.js", + "scan": "npx audit-ci -m --config ./audit-ci.jsonc", + "test": "cross-env NODE_ENV=test mocha --timeout 10000 --require @babel/register --require ./test/helpers/common.js --recursive ./test", + "watch": "webpack --config webpack.config.babel.js --watch" + }, + "dependencies": { + "core-js": "~3.30.2", + "nodent-runtime": "~3.2.1", + "regenerator-runtime": "~0.13.11", + "source-map-support": "~0.5.21", + "superagent": "~8.0.9", + "uuid": "^9.0.0", + "yargs": "~17.7.2", + "yargs-parser": "~21.1.1" + }, + "devDependencies": { + "@babel/core": "^7.21.8", + "@babel/eslint-parser": "^7.21.8", + "@babel/plugin-proposal-class-properties": "^7.18.6", + "@babel/plugin-proposal-export-default-from": "^7.18.10", + "@babel/plugin-proposal-export-namespace-from": "^7.18.9", + "@babel/plugin-transform-react-constant-elements": "^7.21.3", + "@babel/plugin-transform-react-inline-elements": "^7.21.0", + "@babel/preset-env": "^7.21.5", + "@babel/register": "^7.21.0", + "@pollyjs/adapter-node-http": "^6.0.5", + "@pollyjs/core": "^6.0.5", + "@pollyjs/persister-fs": "^6.0.5", + "@types/superagent": "^8.1.7", + "@types/uuid": "^9.0.8", + "@typescript-eslint/eslint-plugin": "^5.59.5", + "@typescript-eslint/parser": "^5.59.5", + "audit-ci": "^6.6.1", + "babel-loader": "^8.2.5", + "babel-plugin-istanbul": "^6.1.1", + "babel-plugin-transform-export-extensions": "^6.22.0", + "babel-preset-minify": "^0.5.2", + "chai": "4.3.10", + "chai-as-promised": "^7.1.1", + "cross-env": "^7.0.3", + "eslint": "^8.40.0", + "eslint-config-prettier": "^8.8.0", + "eslint-import-resolver-webpack": "^0.13.2", + "eslint-plugin-babel": "^5.3.1", + "eslint-plugin-import": "^2.27.5", + "eslint-plugin-jest": "^27.2.1", + "eslint-plugin-jsx-a11y": "^6.7.1", + "eslint-plugin-react": "^7.32.1", + "jsdoc": "^4.0.2", + "mocha": "^10.2.0", + "nyc": "^15.1.0", + "prettier": "^2.8.8", + "typescript": "^4.9.5 || ~5.0.0", + "vows": "^0.8.3", + "webpack": "^5.76.3", + "webpack-cli": "^5.0.1", + "webpack-node-externals": "^3.0.0" + } +} diff --git a/out/src/constants.js b/out/src/constants.js new file mode 100644 index 000000000..4ad9d1601 --- /dev/null +++ b/out/src/constants.js @@ -0,0 +1,35 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var util_1 = __importDefault(require("./utils/util")); +/** + * A class containing constants used throughout the EasyPost Node.js client library. + */ +var Constants = /** @class */ (function () { + function Constants() { + } + Object.defineProperty(Constants, "CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS", { + get: function () { + return ["FedexAccount", "FedexSmartpostAccount", "UpsAccount"]; + }, + enumerable: false, + configurable: true + }); + Constants.EXTERNAL_API_CALL_FAILED = "Communication with %s failed, please try again later"; + Constants.INVALID_API_KEY_TYPE = "Invalid API key type."; + Constants.INVALID_PARAMETER = "Invalid parameter: %s."; + Constants.INVALID_PAYMENT = "The chosen payment method is not a credit card. Please try again."; + Constants.INVALID_WEBHOOK_SIGNATURE = "Webhook does not contain a valid HMAC signature."; + Constants.MISSING_REQUIRED_PARAMETER = "Missing required parameter: %s."; + Constants.NO_OBJECT_FOUND = "No %s found."; + Constants.NO_PAYMENT_METHODS = "No payment methods are set up. Please add a payment method and try again."; + Constants.API_DID_NOT_RETURN_ERROR_DETAILS = "API did not return error details."; + Constants.WEBHOOK_DOES_NOT_MATCH = "Webhook received did not originate from EasyPost or had a webhook secret mismatch."; + Constants.END_OF_PAGINATION = "There are no more pages to retrieve."; + Constants.ERROR_DESERIALIZATION = "Error deserializing JSON response"; + Constants.Utils = new util_1.default(); + return Constants; +}()); +exports.default = Constants; diff --git a/out/src/easypost.js b/out/src/easypost.js new file mode 100644 index 000000000..be355b05e --- /dev/null +++ b/out/src/easypost.js @@ -0,0 +1,447 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __read = (this && this.__read) || function (o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +}; +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.METHODS = exports.DEFAULT_HEADERS = exports.DEFAULT_BASE_URL = exports.DEFAULT_TIMEOUT = exports.MS_SECOND = void 0; +var os_1 = __importDefault(require("os")); +var superagent_1 = __importDefault(require("superagent")); +var uuid_1 = require("uuid"); +var package_json_1 = __importDefault(require("../package.json")); +var constants_1 = __importDefault(require("./constants")); +var error_handler_1 = __importDefault(require("./errors/error_handler")); +var missing_parameter_error_1 = __importDefault(require("./errors/general/missing_parameter_error")); +var address_service_1 = __importDefault(require("./services/address_service")); +var api_key_service_1 = __importDefault(require("./services/api_key_service")); +var batch_service_1 = __importDefault(require("./services/batch_service")); +var beta_rate_service_1 = __importDefault(require("./services/beta_rate_service")); +var beta_referral_customer_service_1 = __importDefault(require("./services/beta_referral_customer_service")); +var billing_service_1 = __importDefault(require("./services/billing_service")); +var carrier_account_service_1 = __importDefault(require("./services/carrier_account_service")); +var carrier_metadata_service_1 = __importDefault(require("./services/carrier_metadata_service")); +var carrier_type_service_1 = __importDefault(require("./services/carrier_type_service")); +var customs_info_service_1 = __importDefault(require("./services/customs_info_service")); +var customs_item_service_1 = __importDefault(require("./services/customs_item_service")); +var end_shipper_service_1 = __importDefault(require("./services/end_shipper_service")); +var event_service_1 = __importDefault(require("./services/event_service")); +var insurance_service_1 = __importDefault(require("./services/insurance_service")); +var order_service_1 = __importDefault(require("./services/order_service")); +var parcel_service_1 = __importDefault(require("./services/parcel_service")); +var pickup_service_1 = __importDefault(require("./services/pickup_service")); +var rate_service_1 = __importDefault(require("./services/rate_service")); +var referral_customer_service_1 = __importDefault(require("./services/referral_customer_service")); +var refund_service_1 = __importDefault(require("./services/refund_service")); +var report_service_1 = __importDefault(require("./services/report_service")); +var scan_form_service_1 = __importDefault(require("./services/scan_form_service")); +var shipment_service_1 = __importDefault(require("./services/shipment_service")); +var tracker_service_1 = __importDefault(require("./services/tracker_service")); +var user_service_1 = __importDefault(require("./services/user_service")); +var webhook_service_1 = __importDefault(require("./services/webhook_service")); +var util_1 = __importDefault(require("./utils/util")); +var node_util_1 = __importDefault(require("node:util")); +__exportStar(require("./errors"), exports); +__exportStar(require("./services"), exports); +__exportStar(require("./utils/errors"), exports); +__exportStar(require("./constants"), exports); +/** How many milliseconds in a second. */ +exports.MS_SECOND = 1000; +/** The default timeout for all EasyPost API requests. */ +exports.DEFAULT_TIMEOUT = 60 * exports.MS_SECOND; +/** The default base URL for all production EasyPost API requests. */ +exports.DEFAULT_BASE_URL = "https://api.easypost.com/v2/"; +/** The default headers used for all EasyPost API requests. */ +exports.DEFAULT_HEADERS = { + Accept: "application/json", + "Content-Type": "application/json", + "User-Agent": "EasyPost/v2 NodejsClient/".concat(package_json_1.default.version, " Nodejs/").concat(process.versions.node, " OS/").concat(os_1.default.platform(), " OSVersion/").concat(os_1.default.release(), " OSArch/").concat(os_1.default.arch()), +}; +/** A map of HTTP methods to their corresponding string values (for use with superagent). */ +exports.METHODS = { + GET: "get", + POST: "post", + PUT: "put", + PATCH: "patch", + DELETE: "del", +}; +/** + * The client used to access services of the EasyPost API. + * This client is configured to use the latest production version of the EasyPost API. + * @param {string} key The API key to use for API requests made by this client. + * @param {EasyPostClientOptions} [options] Additional options to use for the underlying HTTP client (e.g. superagent, middleware, proxy configuration). + */ +var EasyPostClient = /** @class */ (function () { + function EasyPostClient(key, options) { + if (options === void 0) { options = {}; } + var useProxy = options.useProxy, timeout = options.timeout, baseUrl = options.baseUrl, superagentMiddleware = options.superagentMiddleware, requestMiddleware = options.requestMiddleware, agent = options.agent; + if (!key && !useProxy) { + throw new missing_parameter_error_1.default({ + message: node_util_1.default.format(constants_1.default.MISSING_REQUIRED_PARAMETER, "API Key"), + }); + } + this.key = key; + this.useProxy = useProxy || false; + this.timeout = timeout || exports.DEFAULT_TIMEOUT; + this.baseUrl = baseUrl || exports.DEFAULT_BASE_URL; + this.agent = agent || superagent_1.default; + this.requestMiddleware = requestMiddleware; + this.requestHooks = []; + this.responseHooks = []; + this.Utils = new util_1.default(); + if (superagentMiddleware) { + this.agent = superagentMiddleware(this.agent); + } + this.Address = (0, address_service_1.default)(this); + this.ApiKey = (0, api_key_service_1.default)(this); + this.Batch = (0, batch_service_1.default)(this); + this.BetaRate = (0, beta_rate_service_1.default)(this); + this.BetaReferralCustomer = (0, beta_referral_customer_service_1.default)(this); + this.Billing = (0, billing_service_1.default)(this); + this.CarrierAccount = (0, carrier_account_service_1.default)(this); + this.CarrierMetadata = (0, carrier_metadata_service_1.default)(this); + this.CarrierType = (0, carrier_type_service_1.default)(this); + this.CustomsInfo = (0, customs_info_service_1.default)(this); + this.CustomsItem = (0, customs_item_service_1.default)(this); + this.EndShipper = (0, end_shipper_service_1.default)(this); + this.Event = (0, event_service_1.default)(this); + this.Insurance = (0, insurance_service_1.default)(this); + this.Order = (0, order_service_1.default)(this); + this.Parcel = (0, parcel_service_1.default)(this); + this.Pickup = (0, pickup_service_1.default)(this); + this.Rate = (0, rate_service_1.default)(this); + this.ReferralCustomer = (0, referral_customer_service_1.default)(this); + this.Refund = (0, refund_service_1.default)(this); + this.Report = (0, report_service_1.default)(this); + this.ScanForm = (0, scan_form_service_1.default)(this); + this.Shipment = (0, shipment_service_1.default)(this); + this.Tracker = (0, tracker_service_1.default)(this); + this.User = (0, user_service_1.default)(this); + this.Webhook = (0, webhook_service_1.default)(this); + } + /** + * Add a request hook function. + * @param {(config: object) => void} hook + */ + EasyPostClient.prototype.addRequestHook = function (hook) { + this.requestHooks = __spreadArray(__spreadArray([], __read(this.requestHooks), false), [hook], false); + }; + /** + * Remove a request hook function. + * @param {(config: object) => void} hook + */ + EasyPostClient.prototype.removeRequestHook = function (hook) { + this.requestHooks = this.requestHooks.filter(function (h) { return h !== hook; }); + }; + /** + * Clear all request hooks. + */ + EasyPostClient.prototype.clearRequestHooks = function () { + this.requestHooks = []; + }; + /** + * Add a response hook function. + * @param {(config: object) => void} hook + */ + EasyPostClient.prototype.addResponseHook = function (hook) { + this.responseHooks = __spreadArray(__spreadArray([], __read(this.responseHooks), false), [hook], false); + }; + /** + * Remove a response hook function. + * @param {(config: object) => void} hook + */ + EasyPostClient.prototype.removeResponseHook = function (hook) { + this.responseHooks = this.responseHooks.filter(function (h) { return h !== hook; }); + }; + /** + * Clear all response hooks. + */ + EasyPostClient.prototype.clearResponseHooks = function () { + this.responseHooks = []; + }; + /** + * Create a copy of an {@link EasyPostClient} with overridden options. + * @param {EasyPostClient} client The `EasyPostClient` instance to clone. + * @param {Object} [options] The options to override. + * @returns {EasyPostClient} A new `EasyPostClient` instance. + */ + EasyPostClient.copyClient = function (client, options) { + if (options === void 0) { options = {}; } + var apiKey = options.apiKey, useProxy = options.useProxy, timeout = options.timeout, baseUrl = options.baseUrl, superagentMiddleware = options.superagentMiddleware, requestMiddleware = options.requestMiddleware; + var agent = superagentMiddleware + ? superagentMiddleware(client.agent) + : client.agent; + return new EasyPostClient(apiKey || client.key, { + useProxy: useProxy || client.useProxy, + timeout: timeout || client.timeout, + baseUrl: baseUrl || client.baseUrl, + agent: agent, + requestMiddleware: requestMiddleware || client.requestMiddleware, + }); + }; + /** + * Build request headers to be sent with each EasyPost API request, combined (or overridden) by any additional headers + * @param {Object} [additionalHeaders] Additional headers to combine or override with the default headers. + * @returns {Object} The headers to use for the request. + */ + EasyPostClient._buildHeaders = function (additionalHeaders) { + if (additionalHeaders === void 0) { additionalHeaders = {}; } + return __assign(__assign({}, exports.DEFAULT_HEADERS), additionalHeaders); + }; + /** + * If the path passed in is a full URI, use it; otherwise, prepend the base url from the api. + * @param {string} path - The path to build. + * @returns {string} The full path to use for the HTTP request. + */ + EasyPostClient.prototype._buildPath = function (path) { + if (path === void 0) { path = ""; } + if (path.indexOf("http") === 0) { + return path; + } + var completePath = this.baseUrl + path; + completePath = path.includes("beta") + ? completePath.replace("v2", "") + : completePath; + return completePath; + }; + /** + * Create a value to be passed to the responseHooks, based on the requestHooks + * value and the response. + * @param {Object} baseHooksValue - the value being passed the requestHooks + * @param {Object} response - the response from the superagent request + * @returns {Object} - the value to be passed to the responseHooks + */ + EasyPostClient.prototype._createResponseHooksValue = function (baseHooksValue, response) { + return __assign(__assign({}, baseHooksValue), { requestHeaders: baseHooksValue.headers, httpStatus: response.status, responseBody: response.body, headers: response.headers, responseTimestamp: Date.now() }); + }; + /** + * Make an HTTP request. + * @param [path] - The partial path to append to the base url for the request. + * @param [method] - The HTTP method to use for the request, defaults to GET. + * @param [params] - The parameters to send with the request. + * @param [headers] - Additional headers to send with the request. + * @returns The response from the HTTP request. + * @throws {ApiError} If the request fails. + */ + EasyPostClient.prototype._request = function (path, method, params, headers) { + if (path === void 0) { path = ""; } + if (method === void 0) { method = exports.METHODS.GET; } + if (params === void 0) { params = {}; } + if (headers === void 0) { headers = {}; } + return __awaiter(this, void 0, void 0, function () { + var urlPath, requestHeaders, request, url, baseHooksValue, response, responseHooksValue_1, error_1, responseHooksValue_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + urlPath = this._buildPath(path); + requestHeaders = EasyPostClient._buildHeaders(headers); + request = this.agent[method](urlPath).set(requestHeaders); + if (this.requestMiddleware) { + request = this.requestMiddleware(request); + } + if (this.key) { + request.auth(this.key, "", { type: "basic" }); + } + url = new URL(urlPath); + if (params !== undefined) { + if (method === exports.METHODS.GET || method === exports.METHODS.DELETE) { + request.query(params); + Object.entries(params).forEach(function (_a) { + var _b = __read(_a, 2), key = _b[0], value = _b[1]; + url.searchParams.append(key, "".concat(value)); + }); + } + else { + request.send(params); + } + } + baseHooksValue = { + method: method, + path: url.toString(), + // a hack to get the body of the request in the hooks + requestBody: request._data, + headers: requestHeaders, + requestTimestamp: Date.now(), + requestUUID: (0, uuid_1.v4)(), + }; + this.requestHooks.forEach(function (fn) { return fn(baseHooksValue); }); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, request]; + case 2: + response = _a.sent(); + if (this.responseHooks.length > 0) { + responseHooksValue_1 = this._createResponseHooksValue(baseHooksValue, response); + this.responseHooks.forEach(function (fn) { return fn(responseHooksValue_1); }); + } + return [2 /*return*/, response]; + case 3: + error_1 = _a.sent(); + if (!error_1 || typeof error_1 !== "object") { + throw error_1; + } + if ("response" in error_1 && + error_1.response && + typeof error_1.response === "object" && + "body" in error_1.response && + error_1.response.body) { + responseHooksValue_2 = this._createResponseHooksValue(baseHooksValue, error_1.response); + this.responseHooks.forEach(function (fn) { return fn(responseHooksValue_2); }); + if (error_handler_1.default.isAPIError(error_1.response)) { + throw error_handler_1.default.handleApiError(error_1.response); + } + } + throw error_1; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Make a GET HTTP request. + * @param path - The partial path to append to the base url for the request. + * @param [params] - The parameters to send with the request. + * @param [headers] - Additional headers to send with the request. + * @returns The response from the HTTP request. + */ + EasyPostClient.prototype._get = function (path, params, headers) { + if (params === void 0) { params = {}; } + if (headers === void 0) { headers = {}; } + return this._request(path, exports.METHODS.GET, params, headers); + }; + /** + * Make a POST HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + EasyPostClient.prototype._post = function (path, params, headers) { + if (params === void 0) { params = {}; } + if (headers === void 0) { headers = {}; } + return this._request(path, exports.METHODS.POST, params, headers); + }; + /** + * Make a PUT HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + EasyPostClient.prototype._put = function (path, params, headers) { + if (params === void 0) { params = {}; } + if (headers === void 0) { headers = {}; } + return this._request(path, exports.METHODS.PUT, params, headers); + }; + /** + * Make a PATCH HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + EasyPostClient.prototype._patch = function (path, params, headers) { + if (params === void 0) { params = {}; } + if (headers === void 0) { headers = {}; } + return this._request(path, exports.METHODS.PATCH, params, headers); + }; + /** + * Make a DELETE HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + EasyPostClient.prototype._delete = function (path, params, headers) { + if (params === void 0) { params = {}; } + if (headers === void 0) { headers = {}; } + return this._request(path, exports.METHODS.DELETE, params, headers); + }; + return EasyPostClient; +}()); +exports.default = EasyPostClient; diff --git a/out/src/errors/api/api_error.js b/out/src/errors/api/api_error.js new file mode 100644 index 000000000..fa72b8d72 --- /dev/null +++ b/out/src/errors/api/api_error.js @@ -0,0 +1,46 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var easypost_error_1 = __importDefault(require("../easypost_error")); +/** + * The ApiError class is used to represent errors that occurred while communicating with the EasyPost API. + * This class should not be instantiated directly. + * @internal + * @abstract + * @extends EasyPostError + * @property {string} [message] - The message to be displayed when the error is logged. + * @property {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @property {number} [statusCode] - The HTTP status code returned by the HTTP request to the EasyPost API. + * @property {EasyPostError[]} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var ApiError = /** @class */ (function (_super) { + __extends(ApiError, _super); + function ApiError(_a) { + var _b = _a === void 0 ? {} : _a, message = _b.message, code = _b.code, statusCode = _b.statusCode, errors = _b.errors; + var _this = _super.call(this, { message: message }) || this; + _this.code = code; + _this.errors = errors; + _this.message = message; + _this.statusCode = statusCode; + return _this; + } + return ApiError; +}(easypost_error_1.default)); +exports.default = ApiError; diff --git a/out/src/errors/api/bad_request_error.js b/out/src/errors/api/bad_request_error.js new file mode 100644 index 000000000..11511de36 --- /dev/null +++ b/out/src/errors/api/bad_request_error.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The BadRequestError class is used to represent a 400 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var BadRequestError = /** @class */ (function (_super) { + __extends(BadRequestError, _super); + function BadRequestError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return BadRequestError; +}(api_error_1.default)); +exports.default = BadRequestError; diff --git a/out/src/errors/api/external_api_error.js b/out/src/errors/api/external_api_error.js new file mode 100644 index 000000000..848e0ccee --- /dev/null +++ b/out/src/errors/api/external_api_error.js @@ -0,0 +1,36 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The ExternalApiError class is used to represent errors that occurred while communicating with an external API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + */ +var ExternalApiError = /** @class */ (function (_super) { + __extends(ExternalApiError, _super); + function ExternalApiError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return ExternalApiError; +}(api_error_1.default)); +exports.default = ExternalApiError; diff --git a/out/src/errors/api/forbidden_error.js b/out/src/errors/api/forbidden_error.js new file mode 100644 index 000000000..99034fb0f --- /dev/null +++ b/out/src/errors/api/forbidden_error.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The ForbiddenError class is used to represent a 403 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var ForbiddenError = /** @class */ (function (_super) { + __extends(ForbiddenError, _super); + function ForbiddenError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return ForbiddenError; +}(api_error_1.default)); +exports.default = ForbiddenError; diff --git a/out/src/errors/api/gateway_timeout_error.js b/out/src/errors/api/gateway_timeout_error.js new file mode 100644 index 000000000..10fb43e44 --- /dev/null +++ b/out/src/errors/api/gateway_timeout_error.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The GatewayTimeoutError class is used to represent a 504 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var GatewayTimeoutError = /** @class */ (function (_super) { + __extends(GatewayTimeoutError, _super); + function GatewayTimeoutError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return GatewayTimeoutError; +}(api_error_1.default)); +exports.default = GatewayTimeoutError; diff --git a/out/src/errors/api/http_error.js b/out/src/errors/api/http_error.js new file mode 100644 index 000000000..f0c829ec2 --- /dev/null +++ b/out/src/errors/api/http_error.js @@ -0,0 +1,37 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The HttpError class is used to represent a generic HTTP-related error that occurred while communicating with the EasyPost API. + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var HTTPError = /** @class */ (function (_super) { + __extends(HTTPError, _super); + function HTTPError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return HTTPError; +}(api_error_1.default)); +exports.default = HTTPError; diff --git a/out/src/errors/api/index.js b/out/src/errors/api/index.js new file mode 100644 index 000000000..b22a03bd7 --- /dev/null +++ b/out/src/errors/api/index.js @@ -0,0 +1,34 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./api_error"), exports); +__exportStar(require("./bad_request_error"), exports); +__exportStar(require("./external_api_error"), exports); +__exportStar(require("./forbidden_error"), exports); +__exportStar(require("./gateway_timeout_error"), exports); +__exportStar(require("./http_error"), exports); +__exportStar(require("./index"), exports); +__exportStar(require("./internal_server_error"), exports); +__exportStar(require("./invalid_request_error"), exports); +__exportStar(require("./method_not_allowed_error"), exports); +__exportStar(require("./not_found_error"), exports); +__exportStar(require("./payment_error"), exports); +__exportStar(require("./rate_limit_error"), exports); +__exportStar(require("./redirect_error"), exports); +__exportStar(require("./service_unavailable_error"), exports); +__exportStar(require("./timeout_error"), exports); +__exportStar(require("./unauthorized_error"), exports); +__exportStar(require("./unknown_api_error"), exports); diff --git a/out/src/errors/api/internal_server_error.js b/out/src/errors/api/internal_server_error.js new file mode 100644 index 000000000..781b23e2f --- /dev/null +++ b/out/src/errors/api/internal_server_error.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The InternalServerError class is used to represent a 500 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var InternalServerError = /** @class */ (function (_super) { + __extends(InternalServerError, _super); + function InternalServerError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return InternalServerError; +}(api_error_1.default)); +exports.default = InternalServerError; diff --git a/out/src/errors/api/invalid_request_error.js b/out/src/errors/api/invalid_request_error.js new file mode 100644 index 000000000..7aa9018a6 --- /dev/null +++ b/out/src/errors/api/invalid_request_error.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The InvalidRequestError class is used to represent a 422 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var InvalidRequestError = /** @class */ (function (_super) { + __extends(InvalidRequestError, _super); + function InvalidRequestError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return InvalidRequestError; +}(api_error_1.default)); +exports.default = InvalidRequestError; diff --git a/out/src/errors/api/method_not_allowed_error.js b/out/src/errors/api/method_not_allowed_error.js new file mode 100644 index 000000000..1e67cf4a2 --- /dev/null +++ b/out/src/errors/api/method_not_allowed_error.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The MethodNotAllowedError class is used to represent a 405 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var MethodNotAllowedError = /** @class */ (function (_super) { + __extends(MethodNotAllowedError, _super); + function MethodNotAllowedError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return MethodNotAllowedError; +}(api_error_1.default)); +exports.default = MethodNotAllowedError; diff --git a/out/src/errors/api/not_found_error.js b/out/src/errors/api/not_found_error.js new file mode 100644 index 000000000..681604e77 --- /dev/null +++ b/out/src/errors/api/not_found_error.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The NotFoundError class is used to represent a 404 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var NotFoundError = /** @class */ (function (_super) { + __extends(NotFoundError, _super); + function NotFoundError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return NotFoundError; +}(api_error_1.default)); +exports.default = NotFoundError; diff --git a/out/src/errors/api/payment_error.js b/out/src/errors/api/payment_error.js new file mode 100644 index 000000000..a97ee8c26 --- /dev/null +++ b/out/src/errors/api/payment_error.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The PaymentError class is used to represent a 402 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var PaymentError = /** @class */ (function (_super) { + __extends(PaymentError, _super); + function PaymentError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return PaymentError; +}(api_error_1.default)); +exports.default = PaymentError; diff --git a/out/src/errors/api/rate_limit_error.js b/out/src/errors/api/rate_limit_error.js new file mode 100644 index 000000000..6af009b0c --- /dev/null +++ b/out/src/errors/api/rate_limit_error.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The RateLimitError class is used to represent a 429 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var RateLimitError = /** @class */ (function (_super) { + __extends(RateLimitError, _super); + function RateLimitError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return RateLimitError; +}(api_error_1.default)); +exports.default = RateLimitError; diff --git a/out/src/errors/api/redirect_error.js b/out/src/errors/api/redirect_error.js new file mode 100644 index 000000000..d6df4fcc8 --- /dev/null +++ b/out/src/errors/api/redirect_error.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The RedirectError class is used to represent a 3xx error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var RedirectError = /** @class */ (function (_super) { + __extends(RedirectError, _super); + function RedirectError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return RedirectError; +}(api_error_1.default)); +exports.default = RedirectError; diff --git a/out/src/errors/api/service_unavailable_error.js b/out/src/errors/api/service_unavailable_error.js new file mode 100644 index 000000000..21c24865c --- /dev/null +++ b/out/src/errors/api/service_unavailable_error.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The ServiceUnavailableError class is used to represent a 503 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var ServiceUnavailableError = /** @class */ (function (_super) { + __extends(ServiceUnavailableError, _super); + function ServiceUnavailableError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return ServiceUnavailableError; +}(api_error_1.default)); +exports.default = ServiceUnavailableError; diff --git a/out/src/errors/api/timeout_error.js b/out/src/errors/api/timeout_error.js new file mode 100644 index 000000000..c4de69b53 --- /dev/null +++ b/out/src/errors/api/timeout_error.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The TimeoutError class is used to represent a 408 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var TimeoutError = /** @class */ (function (_super) { + __extends(TimeoutError, _super); + function TimeoutError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return TimeoutError; +}(api_error_1.default)); +exports.default = TimeoutError; diff --git a/out/src/errors/api/unauthorized_error.js b/out/src/errors/api/unauthorized_error.js new file mode 100644 index 000000000..feabd0510 --- /dev/null +++ b/out/src/errors/api/unauthorized_error.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The UnauthorizedError class is used to represent a 401 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var UnauthorizedError = /** @class */ (function (_super) { + __extends(UnauthorizedError, _super); + function UnauthorizedError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return UnauthorizedError; +}(api_error_1.default)); +exports.default = UnauthorizedError; diff --git a/out/src/errors/api/unknown_api_error.js b/out/src/errors/api/unknown_api_error.js new file mode 100644 index 000000000..08b17e0fa --- /dev/null +++ b/out/src/errors/api/unknown_api_error.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var api_error_1 = __importDefault(require("./api_error")); +/** + * The UnknownApiError class is used to represent a generic, unexpected error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +var UnknownApiError = /** @class */ (function (_super) { + __extends(UnknownApiError, _super); + function UnknownApiError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return UnknownApiError; +}(api_error_1.default)); +exports.default = UnknownApiError; diff --git a/out/src/errors/easypost_error.js b/out/src/errors/easypost_error.js new file mode 100644 index 000000000..739fb7b8b --- /dev/null +++ b/out/src/errors/easypost_error.js @@ -0,0 +1,34 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * The EasyPostError class is the base class for all errors that occur in the EasyPost Node.js client library. + * This class should not be instantiated directly. + * @internal + * @abstract + * @extends Error + * @param {string} [message] - The message to be displayed when the error is logged. + */ +var EasyPostError = /** @class */ (function (_super) { + __extends(EasyPostError, _super); + function EasyPostError(_a) { + var _b = _a === void 0 ? {} : _a, message = _b.message; + return _super.call(this, message) || this; + } + return EasyPostError; +}(Error)); +exports.default = EasyPostError; diff --git a/out/src/errors/error_handler.js b/out/src/errors/error_handler.js new file mode 100644 index 000000000..fb506c0ae --- /dev/null +++ b/out/src/errors/error_handler.js @@ -0,0 +1,148 @@ +"use strict"; +var __values = (this && this.__values) || function(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function () { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var constants_1 = __importDefault(require("../constants")); +var bad_request_error_1 = __importDefault(require("./api/bad_request_error")); +var forbidden_error_1 = __importDefault(require("./api/forbidden_error")); +var gateway_timeout_error_1 = __importDefault(require("./api/gateway_timeout_error")); +var internal_server_error_1 = __importDefault(require("./api/internal_server_error")); +var invalid_request_error_1 = __importDefault(require("./api/invalid_request_error")); +var method_not_allowed_error_1 = __importDefault(require("./api/method_not_allowed_error")); +var not_found_error_1 = __importDefault(require("./api/not_found_error")); +var payment_error_1 = __importDefault(require("./api/payment_error")); +var rate_limit_error_1 = __importDefault(require("./api/rate_limit_error")); +var redirect_error_1 = __importDefault(require("./api/redirect_error")); +var service_unavailable_error_1 = __importDefault(require("./api/service_unavailable_error")); +var timeout_error_1 = __importDefault(require("./api/timeout_error")); +var unauthorized_error_1 = __importDefault(require("./api/unauthorized_error")); +var unknown_api_error_1 = __importDefault(require("./api/unknown_api_error")); +var easypost_error_1 = __importDefault(require("./easypost_error")); +var ErrorHandler = /** @class */ (function () { + function ErrorHandler() { + } + /** + * Recursively traverses a JSON object or array and extracts error messages + * as strings. Adds the extracted messages to the specified messagesList array. + * + * @param {JSONParsableError} errorMessage - The JSON object or array to traverse. + */ + ErrorHandler.traverseJsonElement = function (errorMessage) { + var e_1, _a, e_2, _b; + var messages = []; + if (errorMessage instanceof Array) { + try { + for (var errorMessage_1 = __values(errorMessage), errorMessage_1_1 = errorMessage_1.next(); !errorMessage_1_1.done; errorMessage_1_1 = errorMessage_1.next()) { + var value = errorMessage_1_1.value; + messages = messages.concat(this.traverseJsonElement(value)); + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (errorMessage_1_1 && !errorMessage_1_1.done && (_a = errorMessage_1.return)) _a.call(errorMessage_1); + } + finally { if (e_1) throw e_1.error; } + } + } + else if (errorMessage instanceof Object) { + try { + for (var _c = __values(Object.values(errorMessage)), _d = _c.next(); !_d.done; _d = _c.next()) { + var value = _d.value; + messages = messages.concat(this.traverseJsonElement(value)); + } + } + catch (e_2_1) { e_2 = { error: e_2_1 }; } + finally { + try { + if (_d && !_d.done && (_b = _c.return)) _b.call(_c); + } + finally { if (e_2) throw e_2.error; } + } + } + else { + messages.push(errorMessage.toString()); + } + return messages; + }; + ErrorHandler.isAPIError = function (error) { + return (error && + typeof error.statusCode === "number" && + typeof error.body === "object" && + typeof error.body.error === "object" && + typeof error.body.error.code === "string" && + error.body.error.message && + error.body.error.errors); + }; + /** + * Calculate and generate the appropriate {@link ApiError} based on a received HTTP response error. + * @param {*} error - The errored HTTP response. + * @returns {ApiError} The `ApiError`-based error corresponding to the HTTP status code. + */ + ErrorHandler.handleApiError = function (error) { + var statusCode = error.statusCode; + var _a = error.body.error, code = _a.code, message = _a.message, errors = _a.errors; + var errorParams = { + message: "", + code: code, + statusCode: statusCode, + errors: errors, + }; + try { + var messages = this.traverseJsonElement(message); + errorParams.message = messages.join(", "); + } + catch (e) { + var errorParams_1 = { + message: constants_1.default.ERROR_DESERIALIZATION, + code: "ERROR_DESERIALIZATION_ERROR", + }; + return new easypost_error_1.default(errorParams_1); + } + if (statusCode >= 300 && statusCode < 400) { + return new redirect_error_1.default(errorParams); + } + switch (statusCode) { + case 400: + return new bad_request_error_1.default(errorParams); + case 401: + return new unauthorized_error_1.default(errorParams); + case 402: + return new payment_error_1.default(errorParams); + case 403: + return new forbidden_error_1.default(errorParams); + case 404: + return new not_found_error_1.default(errorParams); + case 405: + return new method_not_allowed_error_1.default(errorParams); + case 408: + return new timeout_error_1.default(errorParams); + case 422: + return new invalid_request_error_1.default(errorParams); + case 429: + return new rate_limit_error_1.default(errorParams); + case 500: + return new internal_server_error_1.default(errorParams); + case 503: + return new service_unavailable_error_1.default(errorParams); + case 504: + return new gateway_timeout_error_1.default(errorParams); + default: + return new unknown_api_error_1.default(errorParams); + } + }; + return ErrorHandler; +}()); +exports.default = ErrorHandler; diff --git a/out/src/errors/general/end_of_pagination_error.js b/out/src/errors/general/end_of_pagination_error.js new file mode 100644 index 000000000..4969a4ab6 --- /dev/null +++ b/out/src/errors/general/end_of_pagination_error.js @@ -0,0 +1,36 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var constants_1 = __importDefault(require("../../constants")); +var easypost_error_1 = __importDefault(require("../easypost_error")); +/** + * The EndOfPaginationError class is used to represent an error that no more page can be retrieved + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +var EndOfPaginationError = /** @class */ (function (_super) { + __extends(EndOfPaginationError, _super); + function EndOfPaginationError() { + return _super.call(this, { message: constants_1.default.END_OF_PAGINATION }) || this; + } + return EndOfPaginationError; +}(easypost_error_1.default)); +exports.default = EndOfPaginationError; diff --git a/out/src/errors/general/filtering_error.js b/out/src/errors/general/filtering_error.js new file mode 100644 index 000000000..58f0ebc2f --- /dev/null +++ b/out/src/errors/general/filtering_error.js @@ -0,0 +1,35 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var easypost_error_1 = __importDefault(require("../easypost_error")); +/** + * The FilteringError class is used to represent an error that occurred while filtering a list (e.g. a list of rates). + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +var FilteringError = /** @class */ (function (_super) { + __extends(FilteringError, _super); + function FilteringError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return FilteringError; +}(easypost_error_1.default)); +exports.default = FilteringError; diff --git a/out/src/errors/general/index.js b/out/src/errors/general/index.js new file mode 100644 index 000000000..4474c83dc --- /dev/null +++ b/out/src/errors/general/index.js @@ -0,0 +1,22 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./end_of_pagination_error"), exports); +__exportStar(require("./filtering_error"), exports); +__exportStar(require("./invalid_object_error"), exports); +__exportStar(require("./invalid_parameter_error"), exports); +__exportStar(require("./missing_parameter_error"), exports); +__exportStar(require("./signature_verification_error"), exports); diff --git a/out/src/errors/general/invalid_object_error.js b/out/src/errors/general/invalid_object_error.js new file mode 100644 index 000000000..4eec5af61 --- /dev/null +++ b/out/src/errors/general/invalid_object_error.js @@ -0,0 +1,35 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var easypost_error_1 = __importDefault(require("../easypost_error")); +/** + * The InvalidObjectError class is used to represent an error due to an invalid object (e.g. missing an expected property). + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +var InvalidObjectError = /** @class */ (function (_super) { + __extends(InvalidObjectError, _super); + function InvalidObjectError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return InvalidObjectError; +}(easypost_error_1.default)); +exports.default = InvalidObjectError; diff --git a/out/src/errors/general/invalid_parameter_error.js b/out/src/errors/general/invalid_parameter_error.js new file mode 100644 index 000000000..a70d99d51 --- /dev/null +++ b/out/src/errors/general/invalid_parameter_error.js @@ -0,0 +1,35 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var easypost_error_1 = __importDefault(require("../easypost_error")); +/** + * The InvalidParameterError class is used to represent an error due to an invalid function parameter. + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +var InvalidParameterError = /** @class */ (function (_super) { + __extends(InvalidParameterError, _super); + function InvalidParameterError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return InvalidParameterError; +}(easypost_error_1.default)); +exports.default = InvalidParameterError; diff --git a/out/src/errors/general/missing_parameter_error.js b/out/src/errors/general/missing_parameter_error.js new file mode 100644 index 000000000..5dd36613e --- /dev/null +++ b/out/src/errors/general/missing_parameter_error.js @@ -0,0 +1,35 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var easypost_error_1 = __importDefault(require("../easypost_error")); +/** + * The MissingParameterError class is used to represent an error due to a missing expected function parameter. + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +var MissingParameterError = /** @class */ (function (_super) { + __extends(MissingParameterError, _super); + function MissingParameterError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return MissingParameterError; +}(easypost_error_1.default)); +exports.default = MissingParameterError; diff --git a/out/src/errors/general/signature_verification_error.js b/out/src/errors/general/signature_verification_error.js new file mode 100644 index 000000000..e5ed2a2ee --- /dev/null +++ b/out/src/errors/general/signature_verification_error.js @@ -0,0 +1,35 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var easypost_error_1 = __importDefault(require("../easypost_error")); +/** + * The SignatureVerificationError class is used to represent an error due to a failed signature verification (e.g. a webhook HMAC signature). + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +var SignatureVerificationError = /** @class */ (function (_super) { + __extends(SignatureVerificationError, _super); + function SignatureVerificationError() { + return _super !== null && _super.apply(this, arguments) || this; + } + return SignatureVerificationError; +}(easypost_error_1.default)); +exports.default = SignatureVerificationError; diff --git a/out/src/errors/index.js b/out/src/errors/index.js new file mode 100644 index 000000000..fdb97728b --- /dev/null +++ b/out/src/errors/index.js @@ -0,0 +1,20 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./api"), exports); +__exportStar(require("./general"), exports); +__exportStar(require("./easypost_error"), exports); +__exportStar(require("./error_handler"), exports); diff --git a/out/src/index.js b/out/src/index.js new file mode 100644 index 000000000..6135d506d --- /dev/null +++ b/out/src/index.js @@ -0,0 +1,7 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var easypost_1 = __importDefault(require("./easypost")); +exports.default = easypost_1.default; diff --git a/out/src/services/address_service/Address.js b/out/src/services/address_service/Address.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/address_service/Address.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/address_service/AddressCreateParameters.js b/out/src/services/address_service/AddressCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/address_service/AddressCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/address_service/AddressListParameters.js b/out/src/services/address_service/AddressListParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/address_service/AddressListParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/address_service/Verification.js b/out/src/services/address_service/Verification.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/address_service/Verification.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/address_service/VerificationDetails.js b/out/src/services/address_service/VerificationDetails.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/address_service/VerificationDetails.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/address_service/Verifications.js b/out/src/services/address_service/Verifications.js new file mode 100644 index 000000000..2367d855d --- /dev/null +++ b/out/src/services/address_service/Verifications.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = {}; diff --git a/out/src/services/address_service/index.js b/out/src/services/address_service/index.js new file mode 100644 index 000000000..36c9fed6c --- /dev/null +++ b/out/src/services/address_service/index.js @@ -0,0 +1,217 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./Address"), exports); +__exportStar(require("./AddressCreateParameters"), exports); +__exportStar(require("./Verification"), exports); +__exportStar(require("./VerificationDetails"), exports); +__exportStar(require("./Verifications"), exports); +exports.default = (function (easypostClient) { + /** + * The AddressService class provides methods for interacting with EasyPost {@link Address} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(AddressService, _super); + function AddressService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create an {@link Address address}. + * See {@link https://www.easypost.com/docs/api/node#create-an-address EasyPost API Documentation} for more information. + * @param params - Parameters for the address to be created. + * @returns - The created address. + */ + AddressService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "addresses"; + wrappedParams = { + address: params, + }; + if (params.verify) { + wrappedParams.verify = params.verify; + delete params.verify; + } + if (params.verify_strict) { + wrappedParams.verify_strict = params.verify_strict; + delete params.verify_strict; + } + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Create and verify an {@link Address address} in a single request. + * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. + * @param params - Parameters for the address to be created. + * @returns - The created and verified address. + */ + AddressService.createAndVerify = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "addresses/create_and_verify"; + wrappedParams = { address: params }; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body.address, wrappedParams)]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve all {@link Address addresses} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-addresses EasyPost API Documentation} for more information. + * @param params - Parameters to filter the list of addresses. + * @returns - An object containing a list of {@link Address addresses} and pagination information. + */ + AddressService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "addresses"; + return [2 /*return*/, this._all(url, params)]; + }); + }); + }; + /** + * Retrieve the next page of Address collection. + * @param addresses An object containing a list of {@link Address addresses} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + AddressService.getNextPage = function (addresses, pageSize) { + if (pageSize === void 0) { pageSize = null; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "addresses"; + return [2 /*return*/, this._getNextPage(url, "addresses", addresses, pageSize)]; + }); + }); + }; + /** + * Retrieve an {@link Address address} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-address EasyPost API Documentation} for more information. + * @param id - The ID of the address to retrieve. + * @returns - The retrieved address. + */ + AddressService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "addresses/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + /** + * Verify an {@link Address address} by its ID. + * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. + * @param id - The ID of the address to verify. + * @returns - The verified address. + */ + AddressService.verifyAddress = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, response, e_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 2, , 3]); + url = "addresses/".concat(id, "/verify"); + return [4 /*yield*/, easypostClient._get(url)]; + case 1: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body.address)]; + case 2: + e_2 = _a.sent(); + return [2 /*return*/, Promise.reject(e_2)]; + case 3: return [2 /*return*/]; + } + }); + }); + }; + return AddressService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/api_key_service/ApiKey.js b/out/src/services/api_key_service/ApiKey.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/api_key_service/ApiKey.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/api_key_service/index.js b/out/src/services/api_key_service/index.js new file mode 100644 index 000000000..5c7ee05c0 --- /dev/null +++ b/out/src/services/api_key_service/index.js @@ -0,0 +1,142 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var node_util_1 = __importDefault(require("node:util")); +var base_service_1 = __importDefault(require("../base_service")); +var constants_1 = __importDefault(require("../../constants")); +var filtering_error_1 = __importDefault(require("../../errors/general/filtering_error")); +__exportStar(require("./ApiKey"), exports); +exports.default = (function (easypostClient) { + /** + * The ApiKeyService class provides methods for interacting with EasyPost {@link ApiKey} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(ApiKeyService, _super); + function ApiKeyService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Retrieve all {@link ApiKey API keys} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. + * @returns - An object containing the API keys associated with the current authenticated user and its child users. + */ + ApiKeyService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "api_keys"; + return [2 /*return*/, this._all(url, params)]; + }); + }); + }; + /** + * Retrieve API Keys for a specified {@link User user}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. + * @param id - The ID of the user to retrieve keys for. + * @returns - List of associated API Keys. + * @throws {FilteringError} If user or API Keys are not found. + */ + ApiKeyService.retrieveApiKeysForUser = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, response, user, childUser, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "api_keys"; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._get(url)]; + case 2: + response = _a.sent(); + user = this._convertToEasyPostObject(response.body); + if (user.id == id) { + return [2 /*return*/, user.keys]; + } + childUser = user.children.find(function (child) { return child.id === id; }); + if (childUser) { + return [2 /*return*/, childUser.keys]; + } + return [3 /*break*/, 4]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: throw new filtering_error_1.default({ + message: node_util_1.default.format(constants_1.default.NO_OBJECT_FOUND, "child"), + }); + } + }); + }); + }; + return ApiKeyService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/base_service.js b/out/src/services/base_service.js new file mode 100644 index 000000000..201503911 --- /dev/null +++ b/out/src/services/base_service.js @@ -0,0 +1,192 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var end_of_pagination_error_1 = __importDefault(require("../errors/general/end_of_pagination_error")); +exports.default = (function (easypostClient) { + /** + * The base class for all EasyPost client library services. + * @param {EasyPostClient} easypostClient The {@link EasyPostClient} instance to use for API calls. + */ + return /** @class */ (function () { + function BaseService() { + } + /** + * Converts a JSON response and all its nested elements to associated {@link EasyPostObject}-based class instances. + * @internal + * @param {*} response The JSON response to convert (usually a `Map` or `Array`). + * @param {*} params The parameters passed when fetching the response + * @returns {*} An {@link EasyPostObject}-based class instance or an `Array` of {@link EasyPostObject}-based class instances. + */ + BaseService._convertToEasyPostObject = function (response, params) { + var newResponse = response; + newResponse._params = params; + return newResponse; + }; + /** + * Creates an EasyPost Object via the API. + * @internal + * @param url The URL to send the API request to. + * @param params The parameters to send with the API request. + * @returns The created {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + BaseService._create = function (url, params) { + return __awaiter(this, void 0, void 0, function () { + var response, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 2, , 3]); + return [4 /*yield*/, easypostClient._post(url, params)]; + case 1: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body, params)]; + case 2: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 3: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve a list of records from the API. + * @internal + * @param url The URL to send the API request to. + * @param params The parameters to send with the API request. + * @returns The retrieved {@link EasyPostObject}-based class instance(s), or a `Promise` that rejects with an error. + */ + BaseService._all = function (url, params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var response, e_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 2, , 3]); + return [4 /*yield*/, easypostClient._get(url, params)]; + case 1: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body, params)]; + case 2: + e_2 = _a.sent(); + return [2 /*return*/, Promise.reject(e_2)]; + case 3: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve a record from the API. + * @internal + * @param url The URL to send the API request to. + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + BaseService._retrieve = function (url) { + return __awaiter(this, void 0, void 0, function () { + var response, e_3; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 2, , 3]); + return [4 /*yield*/, easypostClient._get(url)]; + case 1: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body)]; + case 2: + e_3 = _a.sent(); + return [2 /*return*/, Promise.reject(e_3)]; + case 3: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve the next page of specific collection of object + * @internal + * @param url The URL to send the API request to. + * @param collection The collection of a specific object. + * @param pageSize The number of records to return on each page. + * @param optionalParams The optional param for additional value in the query string. + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + * TODO: Implement this function in EndShippers and Batches once the API supports them properly. + */ + BaseService._getNextPage = function (url, key, collection, pageSize, optionalParams) { + var _a, _b, _c; + if (pageSize === void 0) { pageSize = null; } + if (optionalParams === void 0) { optionalParams = {}; } + return __awaiter(this, void 0, void 0, function () { + var collectionArray, defaultParams, params, response; + return __generator(this, function (_d) { + switch (_d.label) { + case 0: + collectionArray = collection[key]; + if (collectionArray == undefined || + collectionArray.length == 0 || + !collection.has_more) { + throw new end_of_pagination_error_1.default(); + } + defaultParams = (_b = (_a = collection._params) !== null && _a !== void 0 ? _a : collectionArray[0]._params) !== null && _b !== void 0 ? _b : {}; + params = __assign(__assign(__assign({}, defaultParams), { page_size: (_c = defaultParams.page_size) !== null && _c !== void 0 ? _c : pageSize, before_id: collectionArray[collectionArray.length - 1].id }), optionalParams); + return [4 /*yield*/, this._all(url, params)]; + case 1: + response = _d.sent(); + if (response == undefined || response[key].length == 0) { + throw new end_of_pagination_error_1.default(); + } + return [2 /*return*/, response]; + } + }); + }); + }; + return BaseService; + }()); +}); diff --git a/out/src/services/batch_service/Batch.js b/out/src/services/batch_service/Batch.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/batch_service/Batch.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/batch_service/BatchCreateParameters.js b/out/src/services/batch_service/BatchCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/batch_service/BatchCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/batch_service/BatchListParameters.js b/out/src/services/batch_service/BatchListParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/batch_service/BatchListParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/batch_service/BatchShipment.js b/out/src/services/batch_service/BatchShipment.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/batch_service/BatchShipment.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/batch_service/BatchState.js b/out/src/services/batch_service/BatchState.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/batch_service/BatchState.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/batch_service/BatchStatus.js b/out/src/services/batch_service/BatchStatus.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/batch_service/BatchStatus.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/batch_service/BatchStatuses.js b/out/src/services/batch_service/BatchStatuses.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/batch_service/BatchStatuses.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/batch_service/index.js b/out/src/services/batch_service/index.js new file mode 100644 index 000000000..4fe17ea0a --- /dev/null +++ b/out/src/services/batch_service/index.js @@ -0,0 +1,293 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DEFAULT_LABEL_FORMAT = void 0; +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./Batch"), exports); +__exportStar(require("./BatchCreateParameters"), exports); +__exportStar(require("./BatchListParameters"), exports); +__exportStar(require("./BatchShipment"), exports); +__exportStar(require("./BatchState"), exports); +__exportStar(require("./BatchStatus"), exports); +__exportStar(require("./BatchStatuses"), exports); +exports.DEFAULT_LABEL_FORMAT = "pdf"; +exports.default = (function (easypostClient) { + /** + * The BatchService class provides methods for interacting with EasyPost {@link Batch} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(BatchService, _super); + function BatchService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#create-a-batch EasyPost API Documentation} for more information. + * @param params - Parameters for the batch to be created. + * @returns - The created batch. + */ + BatchService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "batches"; + wrappedParams = { + batch: params, + }; + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Add {@link Shipment shipments} to a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#add-shipments-to-a-batch EasyPost API Documentation} for more information. + * @param id - The id of the batch to add shipments to. + * @param shipmentIds - The ids of the shipments to add to the batch. + * @returns - The updated batch. + */ + BatchService.addShipments = function (id, shipmentIds) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "batches/".concat(id, "/add_shipments"); + wrappedParams = { + shipments: shipmentIds.map(function (s) { return ({ id: s }); }), + }; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Removes {@link Shipment shipments} from a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#remove-shipments-from-a-batch EasyPost API Documentation} for more information. + * @param id - The id of the batch to remove shipments from. + * @param shipmentIds - The ids of the shipments to remove from the batch. + * @returns - The updated batch. + */ + BatchService.removeShipments = function (id, shipmentIds) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, e_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "batches/".concat(id, "/remove_shipments"); + wrappedParams = { + shipments: shipmentIds.map(function (s) { return ({ id: s }); }), + }; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; + case 3: + e_2 = _a.sent(); + return [2 /*return*/, Promise.reject(e_2)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Generate a label for a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#batch-labels EasyPost API Documentation} for more information. + * @param id - The id of the batch to generate a label for. + * @param fileFormat - The format of the label to generate. Defaults to 'pdf'. + * @returns - The updated batch. + */ + BatchService.generateLabel = function (id, fileFormat) { + if (fileFormat === void 0) { fileFormat = exports.DEFAULT_LABEL_FORMAT; } + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, e_3; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "batches/".concat(id, "/label"); + wrappedParams = { file_format: fileFormat }; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; + case 3: + e_3 = _a.sent(); + return [2 /*return*/, Promise.reject(e_3)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Create a {@link ScanForm scan form} for a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#manifesting-scan-form EasyPost API Documentation} for more information. + * @param id - The id of the batch to create a scan form for. + * @returns - The updated batch. + */ + BatchService.createScanForm = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, response, e_4; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "batches/".concat(id, "/scan_form"); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body)]; + case 3: + e_4 = _a.sent(); + return [2 /*return*/, Promise.reject(e_4)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Purchase a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-batch EasyPost API Documentation} for more information. + * @param id - The id of the batch to purchase. + * @returns - The purchased batch. + */ + BatchService.buy = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, response, e_5; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "batches/".concat(id, "/buy"); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body)]; + case 3: + e_5 = _a.sent(); + return [2 /*return*/, Promise.reject(e_5)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve all {@link Batch batches} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#list-all-batches EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of batches. + * @returns - An object containing a list of {@link Batch batches} and pagination information. + */ + BatchService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "batches"; + return [2 /*return*/, this._all(url, params)]; + }); + }); + }; + /** + * Retrieve a {@link Batch batch} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-batch EasyPost API Documentation} for more information. + * @param id - The ID of the batch to retrieve. + * @returns - The retrieved batch. + */ + BatchService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "batches/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return BatchService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/beta_rate_service/index.js b/out/src/services/beta_rate_service/index.js new file mode 100644 index 000000000..cdc29c696 --- /dev/null +++ b/out/src/services/beta_rate_service/index.js @@ -0,0 +1,99 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +/** + * @extends baseService + */ +exports.default = (function (easypostClient) { + return /** @class */ (function (_super) { + __extends(BetaRateService, _super); + function BetaRateService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Retrieve a list of stateless {@link Rate rates} based on the provided parameters. + * @param params - Map of parameters for the API call + * @returns - List of stateless rates + */ + BetaRateService.retrieveStatelessRates = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "beta/rates"; + wrappedParams = { + shipment: params, + }; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body.rates, wrappedParams)]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + return BetaRateService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/beta_referral_customer_service/index.js b/out/src/services/beta_referral_customer_service/index.js new file mode 100644 index 000000000..6ed1cce5b --- /dev/null +++ b/out/src/services/beta_referral_customer_service/index.js @@ -0,0 +1,142 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +exports.default = (function (easypostClient) { + return /** @class */ (function (_super) { + __extends(BetaReferralCustomerService, _super); + function BetaReferralCustomerService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Add an existing Stripe payment method to a {@link User referral customer's} account. + * @param stripeCustomerId - The Stripe account's ID. + * @param paymentMethodReference - Reference of Stripe payment method. + * @param [priority] - Which priority to set the payment method to ('primary' or 'secondary'). + * @returns - A JSON object representing the payment method. + */ + BetaReferralCustomerService.addPaymentMethod = function (stripeCustomerId, paymentMethodReference, priority) { + if (priority === void 0) { priority = "primary"; } + return __awaiter(this, void 0, void 0, function () { + var wrappedParams, url, response; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + wrappedParams = { + payment_method: { + stripe_customer_id: stripeCustomerId, + payment_method_reference: paymentMethodReference, + priority: priority, + }, + }; + url = "beta/referral_customers/payment_method"; + return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; + case 1: + response = _a.sent(); + return [2 /*return*/, response]; + } + }); + }); + }; + /** + * Refund by amount for a recent payment. + * @param refundAmount - Amount to be refunded by cents. + * @returns - A JSON object representing the refund. + */ + BetaReferralCustomerService.refundByAmount = function (refundAmount) { + return __awaiter(this, void 0, void 0, function () { + var params, url, response; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + params = { + refund_amount: refundAmount, + }; + url = "beta/referral_customers/refunds"; + return [4 /*yield*/, easypostClient._post(url, params)]; + case 1: + response = _a.sent(); + return [2 /*return*/, response]; + } + }); + }); + }; + /** + * Refund a payment by a payment log ID. + * @param paymentLogId - ID of the payment log. + * @returns - Returns BetaPaymentRefund object. + */ + BetaReferralCustomerService.refundByPaymentLog = function (paymentLogId) { + return __awaiter(this, void 0, void 0, function () { + var params, url, response; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + params = { + payment_log_id: paymentLogId, + }; + url = "beta/referral_customers/refunds"; + return [4 /*yield*/, easypostClient._post(url, params)]; + case 1: + response = _a.sent(); + return [2 /*return*/, response]; + } + }); + }); + }; + return BetaReferralCustomerService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/billing_service/PaymentMethod.js b/out/src/services/billing_service/PaymentMethod.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/billing_service/PaymentMethod.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/billing_service/index.js b/out/src/services/billing_service/index.js new file mode 100644 index 000000000..b1ccd20f1 --- /dev/null +++ b/out/src/services/billing_service/index.js @@ -0,0 +1,203 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var constants_1 = __importDefault(require("../../constants")); +var invalid_object_error_1 = __importDefault(require("../../errors/general/invalid_object_error")); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./PaymentMethod"), exports); +exports.default = (function (easypostClient) { + /** + * The BillingService class provides methods for interacting with EasyPost's billing capabilities. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(BillingService, _super); + function BillingService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Fund your EasyPost wallet by charging your primary or secondary payment method on file. + * See {@link https://www.easypost.com/docs/api/node#add-funds-to-your-wallet-one-time-charge EasyPost API Documentation} for more information. + * @param amount - The amount to charge to your payment method. + * @param priority - The priority of the payment method to charge. Can be either 'primary' or 'secondary'. + */ + BillingService.fundWallet = function (amount, priority) { + if (priority === void 0) { priority = "primary"; } + return __awaiter(this, void 0, void 0, function () { + var paymentInfo, endpoint, paymentMethodID, url, wrappedParams; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this._getPaymentInfo(priority.toLowerCase())]; + case 1: + paymentInfo = _a.sent(); + endpoint = paymentInfo[0]; + paymentMethodID = paymentInfo[1]; + url = "".concat(endpoint, "/").concat(paymentMethodID, "/charges"); + wrappedParams = { amount: amount }; + return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; + case 2: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + /** + * Delete a payment method from the current authenticated user's account. + * See {@link https://www.easypost.com/docs/api/node#delete-a-payment-method EasyPost API Documentation} for more information. + * @param priority - The priority of the payment method to delete. Can be either 'primary' or 'secondary'. + */ + BillingService.deletePaymentMethod = function (priority) { + return __awaiter(this, void 0, void 0, function () { + var paymentInfo, endpoint, paymentMethodID, url; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this._getPaymentInfo(priority.toLowerCase())]; + case 1: + paymentInfo = _a.sent(); + endpoint = paymentInfo[0]; + paymentMethodID = paymentInfo[1]; + url = "".concat(endpoint, "/").concat(paymentMethodID); + return [4 /*yield*/, easypostClient._delete(url)]; + case 2: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve all payment methods associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-payment-methods EasyPost API Documentation} for more information. + * @returns {Object} - An object containing the payment methods associated with the current authenticated user. + */ + BillingService.retrievePaymentMethods = function () { + return __awaiter(this, void 0, void 0, function () { + var url, res; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "payment_methods"; + return [4 /*yield*/, easypostClient._get(url)]; + case 1: + res = _a.sent(); + if (res.body.id === null) { + throw new invalid_object_error_1.default({ message: constants_1.default.NO_PAYMENT_METHODS }); + } + return [2 /*return*/, res.body]; + } + }); + }); + }; + /** + * Get payment info (type of the payment method and ID of the payment method) + * This function is intended for internal use only, please avoid using this function + * @private + * @param {String} priority - The priority of the payment method to retrieve. Can be either 'primary' or 'secondary'. + * @returns {string[]} - An array of two strings, the first being the endpoint of the payment method and the second being the ID of the payment method. + */ + BillingService._getPaymentInfo = function (priority) { + return __awaiter(this, void 0, void 0, function () { + var paymentMethods, paymentMethodMap, paymentMethodToUse, paymentMethodID, endpoint, errorString; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.retrievePaymentMethods()]; + case 1: + paymentMethods = _a.sent(); + paymentMethodMap = { + primary: "primary_payment_method", + secondary: "secondary_payment_method", + }; + paymentMethodToUse = paymentMethodMap[priority]; + errorString = "The chosen payment method is not valid. Please try again."; + if (paymentMethodToUse !== undefined && + paymentMethods[paymentMethodToUse] !== null) { + paymentMethodID = paymentMethods[paymentMethodToUse].id; + if (paymentMethodID.startsWith("card_")) { + endpoint = "credit_cards"; + } + else if (paymentMethodID.startsWith("bank_")) { + endpoint = "bank_accounts"; + } + else { + throw new invalid_object_error_1.default({ message: errorString }); + } + } + else { + throw new invalid_object_error_1.default({ message: errorString }); + } + return [2 /*return*/, [endpoint, paymentMethodID]]; + } + }); + }); + }; + return BillingService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/carrier_account_service/CarrierAccount.js b/out/src/services/carrier_account_service/CarrierAccount.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/carrier_account_service/CarrierAccount.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_account_service/CarrierAccountCreateParameters.js b/out/src/services/carrier_account_service/CarrierAccountCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/carrier_account_service/CarrierAccountCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_account_service/CarrierAccountField.js b/out/src/services/carrier_account_service/CarrierAccountField.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/carrier_account_service/CarrierAccountField.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_account_service/CarrierAccountFields.js b/out/src/services/carrier_account_service/CarrierAccountFields.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/carrier_account_service/CarrierAccountFields.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_account_service/index.js b/out/src/services/carrier_account_service/index.js new file mode 100644 index 000000000..e0581a34e --- /dev/null +++ b/out/src/services/carrier_account_service/index.js @@ -0,0 +1,216 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var node_util_1 = __importDefault(require("node:util")); +var base_service_1 = __importDefault(require("../base_service")); +var constants_1 = __importDefault(require("../../constants")); +var invalid_parameter_error_1 = __importDefault(require("../../errors/general/invalid_parameter_error")); +__exportStar(require("./CarrierAccount"), exports); +__exportStar(require("./CarrierAccountCreateParameters"), exports); +__exportStar(require("./CarrierAccountField"), exports); +__exportStar(require("./CarrierAccountFields"), exports); +exports.default = (function (easypostClient) { + /** + * The CarrierAccountService class provides methods for interacting with EasyPost @{link CarrierAccount} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(CarrierAccountService, _super); + function CarrierAccountService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create a {@link CarrierAccount carrier account}. + * See {@link https://www.easypost.com/docs/api/node#create-a-carrier-account EasyPost API Documentation} for more information. + * @param params - Parameters for the carrier account to be created. + * @returns - The created carrier account. + */ + CarrierAccountService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var carrierAccountType, endpoint, wrappedParams; + return __generator(this, function (_a) { + carrierAccountType = params.type; + if (!carrierAccountType) { + throw new invalid_parameter_error_1.default({ + message: node_util_1.default.format(constants_1.default.MISSING_REQUIRED_PARAMETER, "CarrierAccount type"), + }); + } + endpoint = this._selectCarrierAccountCreationEndpoint(carrierAccountType); + wrappedParams = { carrier_account: params }; + return [2 /*return*/, this._create(endpoint, wrappedParams)]; + }); + }); + }; + /** + * Update a {@link CarrierAccount carrier account}. + * See {@link https://www.easypost.com/docs/api/node#update-a-carrieraccount EasyPost API Documentation} for more information. + * @param id - The id of the carrier account to be updated. + * @param params - Parameters for the carrier account to be updated. + * @returns - The updated carrier account. + */ + CarrierAccountService.update = function (id, params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "carrier_accounts/".concat(id); + wrappedParams = { + carrier_account: params, + }; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._patch(url, wrappedParams)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Delete a {@link CarrierAccount carrier account}. + * See {@link https://www.easypost.com/docs/api/node#delete-a-carrier-account EasyPost API Documentation} for more information. + * @param id - The id of the carrier account to be deleted. + * @returns - A promise that resolves when the carrier account has been deleted. + */ + CarrierAccountService.delete = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, e_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "carrier_accounts/".concat(id); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._delete(url)]; + case 2: + _a.sent(); + return [2 /*return*/, Promise.resolve()]; + case 3: + e_2 = _a.sent(); + return [2 /*return*/, Promise.reject(e_2)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Returns the correct carrier_account endpoint when creating a record based on the type. + * @private + * @param {string} carrierAccountType - The type of carrier account to be created. + * @returns {string} - The endpoint to be used for the carrier account creation request. + */ + CarrierAccountService._selectCarrierAccountCreationEndpoint = function (carrierAccountType) { + if (constants_1.default.CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS.includes(carrierAccountType)) { + return "carrier_accounts/register"; + } + return "carrier_accounts"; + }; + /** + * Retrieve all {@link CarrierAccount carrier accounts} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#list-all-carrier-accounts EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of carrier accounts. + * @returns - An object containing a list of {@link CarrierAccount carrier accounts} and pagination information. + */ + CarrierAccountService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "carrier_accounts"; + return [2 /*return*/, this._all(url, params)]; + }); + }); + }; + /** + * Retrieve a {@link CarrierAccount carrier account} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-carrieraccount EasyPost API Documentation} for more information. + * @param id - The ID of the carrier account to retrieve. + * @returns - The retrieved carrier account. + */ + CarrierAccountService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "carrier_accounts/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return CarrierAccountService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/carrier_metadata_service/CarrierMetadata.js b/out/src/services/carrier_metadata_service/CarrierMetadata.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/carrier_metadata_service/CarrierMetadata.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_metadata_service/index.js b/out/src/services/carrier_metadata_service/index.js new file mode 100644 index 000000000..b67458d12 --- /dev/null +++ b/out/src/services/carrier_metadata_service/index.js @@ -0,0 +1,124 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./CarrierMetadata"), exports); +exports.default = (function (easypostClient) { + return /** @class */ (function (_super) { + __extends(CarrierMetadataService, _super); + function CarrierMetadataService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Retrieve a list of carrier metadata based on the provided parameters. + * @param carriers - List of carrier in string + * @param type - List of types in string + * @returns - List of carrier metadata + */ + CarrierMetadataService.retrieve = function (carriers, types) { + if (carriers === void 0) { carriers = null; } + if (types === void 0) { types = null; } + return __awaiter(this, void 0, void 0, function () { + var url, params, response, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "metadata/carriers"; + params = __assign(__assign({}, (carriers && + carriers.length > 0 && { carriers: carriers.join(",") })), (types && types.length > 0 && { types: types.join(",") })); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._get(url, params)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body.carriers || [], params)]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + return CarrierMetadataService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/carrier_type_service/CarrierType.js b/out/src/services/carrier_type_service/CarrierType.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/carrier_type_service/CarrierType.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_type_service/CarrierTypeCredentials.js b/out/src/services/carrier_type_service/CarrierTypeCredentials.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/carrier_type_service/CarrierTypeCredentials.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_type_service/CarrierTypeFields.js b/out/src/services/carrier_type_service/CarrierTypeFields.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/carrier_type_service/CarrierTypeFields.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_type_service/index.js b/out/src/services/carrier_type_service/index.js new file mode 100644 index 000000000..cf05d13d8 --- /dev/null +++ b/out/src/services/carrier_type_service/index.js @@ -0,0 +1,116 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./CarrierType"), exports); +__exportStar(require("./CarrierTypeCredentials"), exports); +__exportStar(require("./CarrierTypeFields"), exports); +exports.default = (function (easypostClient) { + /** + * The CarrierTypeService class provides methods for interacting with EasyPost {@link CarrierType} objects. + * @param easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(CarrierTypeService, _super); + function CarrierTypeService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Retrieve all {@link CarrierType carrier types} available to the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-available-carrier-types EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of carrier types. + * @returns - A list of {@link CarrierType carrier types}. + */ + CarrierTypeService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url, response, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "carrier_types"; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._get(url, params)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body, params)]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + return CarrierTypeService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/customs_info_service/CustomsInfo.js b/out/src/services/customs_info_service/CustomsInfo.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/customs_info_service/CustomsInfo.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/customs_info_service/CustomsInfoCreateParameters.js b/out/src/services/customs_info_service/CustomsInfoCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/customs_info_service/CustomsInfoCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/customs_info_service/index.js b/out/src/services/customs_info_service/index.js new file mode 100644 index 000000000..db2c553ed --- /dev/null +++ b/out/src/services/customs_info_service/index.js @@ -0,0 +1,119 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./CustomsInfo"), exports); +__exportStar(require("./CustomsInfoCreateParameters"), exports); +exports.default = (function (easypostClient) { + /** + * The CustomsInfoService class provides methods for interacting with EasyPost {@link CustomsInfo} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(CustomsInfoService, _super); + function CustomsInfoService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create a {@link CustomsInfo customs info} record. + * See {@link https://www.easypost.com/docs/api/node#create-a-customsinfo EasyPost API Documentation} for more information. + * @param params - Parameters for the customs info to be created. + * @returns - The created customs info. + */ + CustomsInfoService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "customs_infos"; + wrappedParams = { + customs_info: params, + }; + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Retrieve a {@link CustomsInfo customs info} record by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-customsinfo EasyPost API Documentation} for more information. + * @param id - The ID of the customs info to retrieve. + * @returns - The retrieved customs info. + */ + CustomsInfoService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "customs_infos/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return CustomsInfoService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/customs_item_service/CustomsItem.js b/out/src/services/customs_item_service/CustomsItem.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/customs_item_service/CustomsItem.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/customs_item_service/CustomsItemCreateParameters.js b/out/src/services/customs_item_service/CustomsItemCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/customs_item_service/CustomsItemCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/customs_item_service/index.js b/out/src/services/customs_item_service/index.js new file mode 100644 index 000000000..2bf4f0fd7 --- /dev/null +++ b/out/src/services/customs_item_service/index.js @@ -0,0 +1,119 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./CustomsItem"), exports); +__exportStar(require("./CustomsItemCreateParameters"), exports); +exports.default = (function (easypostClient) { + /** + * The CustomsItemService class provides methods for interacting with EasyPost {@link CustomsItem} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(CustomsItemService, _super); + function CustomsItemService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create a {@link CustomsItem customs item}. + * See {@link https://www.easypost.com/docs/api/node#create-a-customsitem EasyPost API Documentation} for more information. + * @param params - Parameters for the customs item to be created. + * @returns - The created customs item. + */ + CustomsItemService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "customs_items"; + wrappedParams = { + customs_item: params, + }; + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Retrieve a {@link CustomsItem customs item} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-customsitem EasyPost API Documentation} for more information. + * @param id - The ID of the customs item to retrieve. + * @returns - The retrieved customs item. + */ + CustomsItemService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "customs_items/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return CustomsItemService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/end_shipper_service/EndShipper.js b/out/src/services/end_shipper_service/EndShipper.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/end_shipper_service/EndShipper.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/end_shipper_service/EndShipperCreateParameters.js b/out/src/services/end_shipper_service/EndShipperCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/end_shipper_service/EndShipperCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/end_shipper_service/EndShipperListParameters.js b/out/src/services/end_shipper_service/EndShipperListParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/end_shipper_service/EndShipperListParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/end_shipper_service/index.js b/out/src/services/end_shipper_service/index.js new file mode 100644 index 000000000..0f03b9124 --- /dev/null +++ b/out/src/services/end_shipper_service/index.js @@ -0,0 +1,164 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./EndShipper"), exports); +__exportStar(require("./EndShipperCreateParameters"), exports); +__exportStar(require("./EndShipperListParameters"), exports); +exports.default = (function (easypostClient) { + /** + * The EndShipperService class provides methods for interacting with EasyPost {@link EndShipper} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(EndShipperService, _super); + function EndShipperService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create an {@link EndShipper end shipper}. + * See {@link https://www.easypost.com/docs/api/node#create-an-endshipper EasyPost API Documentation} for more information. + * @param params - Parameters for the end shipper to be created. + * @returns - The created end shipper. + */ + EndShipperService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "end_shippers"; + wrappedParams = { address: params }; + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Update an {@link EndShipper end shipper}. + * See {@link https://www.easypost.com/docs/api/node#update-an-endshipper EasyPost API Documentation} for more information. + * @param id - The ID of the end shipper to update. + * @param params - Parameters for the end shipper to be updated. + * @returns - The updated end shipper. + */ + EndShipperService.update = function (id, params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "end_shippers/".concat(id); + wrappedParams = { address: params }; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._put(url, wrappedParams)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve an {@link EndShipper end shipper} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-endshipper EasyPost API Documentation} for more information. + * @param id - The ID of the end shipper to retrieve. + * @returns - The retrieved end shipper. + */ + EndShipperService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "end_shippers/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + /** + * Retrieve all {@link EndShipper end shippers} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-endshippers EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of end shippers. + * @returns - An object containing a list of {@link EndShipper end shippers} and pagination information. + */ + EndShipperService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "end_shippers"; + return [2 /*return*/, this._all(url, params)]; + }); + }); + }; + return EndShipperService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/event_service/Event.js b/out/src/services/event_service/Event.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/event_service/Event.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/event_service/EventListParameters.js b/out/src/services/event_service/EventListParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/event_service/EventListParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/event_service/Payload/Payload.js b/out/src/services/event_service/Payload/Payload.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/event_service/Payload/Payload.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/event_service/Payload/PayloadListParameters.js b/out/src/services/event_service/Payload/PayloadListParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/event_service/Payload/PayloadListParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/event_service/Payload/index.js b/out/src/services/event_service/Payload/index.js new file mode 100644 index 000000000..95ced6379 --- /dev/null +++ b/out/src/services/event_service/Payload/index.js @@ -0,0 +1,17 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./Payload"), exports); diff --git a/out/src/services/event_service/index.js b/out/src/services/event_service/index.js new file mode 100644 index 000000000..4a74872a4 --- /dev/null +++ b/out/src/services/event_service/index.js @@ -0,0 +1,191 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./Event"), exports); +__exportStar(require("./EventListParameters"), exports); +__exportStar(require("./Payload"), exports); +exports.default = (function (easypostClient) { + /** + * The EventService class provides methods for interacting with EasyPost {@link Event} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(EventService, _super); + function EventService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Retrieve all {@link Payload payloads} for an {@link Event event}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads EasyPost API Documentation} for more information. + * @param id - The ID of the event to retrieve payloads for. + * @returns - A list of {@link Payload payloads} for the event. + */ + EventService.retrieveAllPayloads = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, response, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "events/".concat(id, "/payloads"); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._get(url)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body.payloads)]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve a specific {@link Payload payload} for an {@link Event event}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-payload EasyPost API Documentation} for more information. + * @param id - The ID of the event to retrieve the payload for. + * @param payloadId - The ID of the payload to retrieve. + * @returns - The {@link Payload payload} for the event. + */ + EventService.retrievePayload = function (id, payloadId) { + return __awaiter(this, void 0, void 0, function () { + var url, response, e_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "events/".concat(id, "/payloads/").concat(payloadId); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._get(url)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body)]; + case 3: + e_2 = _a.sent(); + return [2 /*return*/, Promise.reject(e_2)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve all {@link Event events} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-events EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of events. + * @returns - An object containing the list of {@link Event events} and pagination information. + */ + EventService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "events"; + return [2 /*return*/, this._all(url, params)]; + }); + }); + }; + /** + * Retrieve the next page of Event collection. + * @param events An object containing a list of {@link Event events} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + EventService.getNextPage = function (events, pageSize) { + if (pageSize === void 0) { pageSize = null; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "events"; + return [2 /*return*/, this._getNextPage(url, "events", events, pageSize)]; + }); + }); + }; + /** + * Retrieve an {@link Event event} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-event EasyPost API Documentation} for more information. + * @param id - The ID of the event to retrieve. + * @returns - The retrieved event. + */ + EventService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "events/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return EventService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/index.js b/out/src/services/index.js new file mode 100644 index 000000000..4ff245c5a --- /dev/null +++ b/out/src/services/index.js @@ -0,0 +1,43 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./address_service"), exports); +__exportStar(require("./api_key_service"), exports); +__exportStar(require("./batch_service"), exports); +__exportStar(require("./beta_rate_service"), exports); +__exportStar(require("./beta_referral_customer_service"), exports); +__exportStar(require("./billing_service"), exports); +__exportStar(require("./carrier_account_service"), exports); +__exportStar(require("./carrier_metadata_service"), exports); +__exportStar(require("./carrier_type_service"), exports); +__exportStar(require("./customs_info_service"), exports); +__exportStar(require("./customs_item_service"), exports); +__exportStar(require("./end_shipper_service"), exports); +__exportStar(require("./event_service"), exports); +__exportStar(require("./insurance_service"), exports); +__exportStar(require("./order_service"), exports); +__exportStar(require("./parcel_service"), exports); +__exportStar(require("./pickup_service"), exports); +__exportStar(require("./rate_service"), exports); +__exportStar(require("./referral_customer_service"), exports); +__exportStar(require("./refund_service"), exports); +__exportStar(require("./report_service"), exports); +__exportStar(require("./scan_form_service"), exports); +__exportStar(require("./shipment_service"), exports); +__exportStar(require("./tracker_service"), exports); +__exportStar(require("./user_service"), exports); +__exportStar(require("./webhook_service"), exports); +__exportStar(require("./base_service"), exports); diff --git a/out/src/services/insurance_service/Fee.js b/out/src/services/insurance_service/Fee.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/insurance_service/Fee.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/insurance_service/FeeType.js b/out/src/services/insurance_service/FeeType.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/insurance_service/FeeType.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/insurance_service/Insurance.js b/out/src/services/insurance_service/Insurance.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/insurance_service/Insurance.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/insurance_service/InsuranceCreateParameters.js b/out/src/services/insurance_service/InsuranceCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/insurance_service/InsuranceCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/insurance_service/InsuranceStatus.js b/out/src/services/insurance_service/InsuranceStatus.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/insurance_service/InsuranceStatus.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/insurance_service/index.js b/out/src/services/insurance_service/index.js new file mode 100644 index 000000000..55847d2f1 --- /dev/null +++ b/out/src/services/insurance_service/index.js @@ -0,0 +1,154 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./Fee"), exports); +__exportStar(require("./FeeType"), exports); +__exportStar(require("./Insurance"), exports); +__exportStar(require("./InsuranceCreateParameters"), exports); +__exportStar(require("./InsuranceStatus"), exports); +exports.default = (function (easypostClient) { + /** + * The InsuranceService class provides methods for interacting with EasyPost {@link Insurance} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(InsuranceService, _super); + function InsuranceService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create an {@link Insurance insurance} record. + * See {@link https://www.easypost.com/docs/api/node#create-an-insurance EasyPost API Documentation} for more information. + * @param params - Parameters for the insurance to be created. + * @returns - The created insurance. + */ + InsuranceService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "insurances"; + wrappedParams = { + insurance: params, + }; + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Retrieve all {@link Insurance} records associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-insurances EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the insurance records. + * @returns - An object containing the list of {@link Insurance insurance} records and pagination information. + */ + InsuranceService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "insurances"; + return [2 /*return*/, this._all(url, params)]; + }); + }); + }; + /** + * Retrieve the next page of Insurance collection. + * @param {Object} insurances An object containing a list of {@link Insurance insurances} and pagination information. + * @param {Number} pageSize The number of records to return on each page + * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + InsuranceService.getNextPage = function (insurances, pageSize) { + if (pageSize === void 0) { pageSize = null; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "insurances"; + return [2 /*return*/, this._getNextPage(url, "insurances", insurances, pageSize)]; + }); + }); + }; + /** + * Retrieve an {@link Insurance insurance} record by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-insurance EasyPost API Documentation} for more information. + * @param {string} id - The ID of the insurance to retrieve. + * @returns {Insurance} - The retrieved insurance. + */ + InsuranceService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "insurances/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return InsuranceService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/order_service/Order.js b/out/src/services/order_service/Order.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/order_service/Order.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/order_service/OrderCreateParameters.js b/out/src/services/order_service/OrderCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/order_service/OrderCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/order_service/index.js b/out/src/services/order_service/index.js new file mode 100644 index 000000000..78a48713f --- /dev/null +++ b/out/src/services/order_service/index.js @@ -0,0 +1,178 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./Order"), exports); +__exportStar(require("./OrderCreateParameters"), exports); +exports.default = (function (easypostClient) { + /** + * The OrderService class provides methods for interacting with EasyPost {@link Order} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(OrderService, _super); + function OrderService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create an {@link Order order}. + * See {@link https://www.easypost.com/docs/api/node#create-an-order EasyPost API Documentation} for more information. + * @param params - The parameters to create an order with. + * @returns - The created order. + */ + OrderService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "orders"; + wrappedParams = { + order: params, + }; + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Purchase an {@link Order order}. + * See {@link https://www.easypost.com/docs/api/node#buy-an-order EasyPost API Documentation} for more information. + * @param id - The ID of the order to buy. + * @param carrier - The carrier to use for the order purchase. + * @param service - The service to use for the order purchase. + * @returns - The purchased order. + */ + OrderService.buy = function (id, carrier, service) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "orders/".concat(id, "/buy"); + wrappedParams = { carrier: carrier, service: service }; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Get updated rates for an {@link Order order}. + * See {@link https://www.easypost.com/docs/api/node#orders EasyPost API Documentation} for more information. + * @param id - The ID of the order to get rates for. + * @returns - The order with rates. + */ + OrderService.getRates = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, response, e_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "orders/".concat(id, "/rates"); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._get(url)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body)]; + case 3: + e_2 = _a.sent(); + return [2 /*return*/, Promise.reject(e_2)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve an {@link Order order} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-order EasyPost API Documentation} for more information. + * @param id - The ID of the order to retrieve. + * @returns - The retrieved order. + */ + OrderService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "orders/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return OrderService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/parcel_service/Parcel.js b/out/src/services/parcel_service/Parcel.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/parcel_service/Parcel.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/parcel_service/ParcelCreateParameters.js b/out/src/services/parcel_service/ParcelCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/parcel_service/ParcelCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/parcel_service/index.js b/out/src/services/parcel_service/index.js new file mode 100644 index 000000000..0f05745c5 --- /dev/null +++ b/out/src/services/parcel_service/index.js @@ -0,0 +1,119 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./Parcel"), exports); +__exportStar(require("./ParcelCreateParameters"), exports); +exports.default = (function (easypostClient) { + /** + * The ParcelService class provides methods for interacting with EasyPost {@link Parcel} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(ParcelService, _super); + function ParcelService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create a {@link Parcel parcel}. + * See {@link https://www.easypost.com/docs/api/node#create-a-parcel EasyPost API Documentation} for more information. + * @param params - The parameters to create a parcel with. + * @returns - The created parcel. + */ + ParcelService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "parcels"; + wrappedParams = { + parcel: params, + }; + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Retrieve a {@link Parcel parcel} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-parcel EasyPost API Documentation} for more information. + * @param id - The ID of the parcel to retrieve. + * @returns - The retrieved parcel. + */ + ParcelService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "parcels/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return ParcelService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/pickup_service/Pickup.js b/out/src/services/pickup_service/Pickup.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/pickup_service/Pickup.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/pickup_service/PickupCreateParameters.js b/out/src/services/pickup_service/PickupCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/pickup_service/PickupCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/pickup_service/PickupListParameters.js b/out/src/services/pickup_service/PickupListParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/pickup_service/PickupListParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/pickup_service/PickupRate.js b/out/src/services/pickup_service/PickupRate.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/pickup_service/PickupRate.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/pickup_service/index.js b/out/src/services/pickup_service/index.js new file mode 100644 index 000000000..f37102cd0 --- /dev/null +++ b/out/src/services/pickup_service/index.js @@ -0,0 +1,194 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +exports.default = (function (easypostClient) { + /** + * The PickupService class provides methods for interacting with EasyPost {@link Pickup} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(PickupService, _super); + function PickupService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create a {@link Pickup pickup}. + * See {@link https://www.easypost.com/docs/api/node#create-a-pickup EasyPost API Documentation} for more information. + * @param params - The parameters to create a pickup with. + * @returns - The created pickup. + */ + PickupService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "pickups"; + wrappedParams = { + pickup: params, + }; + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Purchase a {@link Pickup pickup}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-pickup EasyPost API Documentation} for more information. + * @param id - The ID of the pickup to purchase. + * @param carrier - The carrier to purchase the pickup with. + * @param service - The service to purchase the pickup with. + * @returns - The purchased pickup. + */ + PickupService.buy = function (id, carrier, service) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "pickups/".concat(id, "/buy"); + wrappedParams = { carrier: carrier, service: service }; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Cancel a {@link Pickup pickup}. + * See {@link https://www.easypost.com/docs/api/node#cancel-a-pickup EasyPost API Documentation} for more information. + * @param id - The ID of the pickup to cancel. + * @returns - The cancelled pickup. + */ + PickupService.cancel = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, response, e_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "pickups/".concat(id, "/cancel"); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body)]; + case 3: + e_2 = _a.sent(); + return [2 /*return*/, Promise.reject(e_2)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve all {@link Pickup pickups} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the pickups by. + * @returns - An object containing a list of {@link Pickup pickups} and pagination information. + */ + PickupService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "pickups"; + return [2 /*return*/, this._all(url, params)]; + }); + }); + }; + /** + * Retrieve the next page of Pickup collection. + * @param pickups An object containing a list of {@link Pickup pickups} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + PickupService.getNextPage = function (pickups, pageSize) { + if (pageSize === void 0) { pageSize = null; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "pickups"; + return [2 /*return*/, this._getNextPage(url, "pickups", pickups, pageSize)]; + }); + }); + }; + /** + * Retrieve a {@link Pickup pickup} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-pickup EasyPost API Documentation} for more information. + * @param id - The ID of the pickup to retrieve. + * @returns - The retrieved pickup. + */ + PickupService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "pickups/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return PickupService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/rate_service/Rate.js b/out/src/services/rate_service/Rate.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/rate_service/Rate.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/rate_service/index.js b/out/src/services/rate_service/index.js new file mode 100644 index 000000000..5e3ce949d --- /dev/null +++ b/out/src/services/rate_service/index.js @@ -0,0 +1,100 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./Rate"), exports); +exports.default = (function (easypostClient) { + /** + * The RateService class provides methods for interacting with EasyPost {@link Rate} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(RateService, _super); + function RateService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Retrieve a {@link Rate rate} by its ID. + * See {@link https://www.easypost.com/docs/api/node#rates EasyPost API Documentation} for more information. + * @param {string} id - The ID of the rate to retrieve. + * @returns {Rate} - The retrieved rate. + */ + RateService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "rates/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return RateService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/referral_customer_service/Referral.js b/out/src/services/referral_customer_service/Referral.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/referral_customer_service/Referral.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/referral_customer_service/ReferralCreateParameters.js b/out/src/services/referral_customer_service/ReferralCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/referral_customer_service/ReferralCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/referral_customer_service/ReferralListParameters.js b/out/src/services/referral_customer_service/ReferralListParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/referral_customer_service/ReferralListParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/referral_customer_service/index.js b/out/src/services/referral_customer_service/index.js new file mode 100644 index 000000000..771d93b9e --- /dev/null +++ b/out/src/services/referral_customer_service/index.js @@ -0,0 +1,295 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var node_util_1 = __importDefault(require("node:util")); +var superagent_1 = __importDefault(require("superagent")); +var constants_1 = __importDefault(require("../../constants")); +var easypost_1 = __importDefault(require("../../easypost")); +var external_api_error_1 = __importDefault(require("../../errors/api/external_api_error")); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./Referral"), exports); +__exportStar(require("./ReferralCreateParameters"), exports); +__exportStar(require("./ReferralListParameters"), exports); +/** + * Get an instance of the EasyPostClient using the referral user's API key. + * @private + * @param client - The EasyPostClient to copy. + * @param referralApiKey - The referral user's API key. + * @returns - An instance of the EasyPostClient. + */ +function _getReferralClient(client, referralApiKey) { + return easypost_1.default.copyClient(client, { + apiKey: referralApiKey, + }); +} +/** + * Get EasyPost's Stripe API key used to create credit cards on Stripe's servers. + * @private + * @param easypostClient - The EasyPostClient to use. + * @returns - The Stripe API key. + */ +function _getEasyPostStripeKey(easypostClient) { + return __awaiter(this, void 0, void 0, function () { + var url, response; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "partners/stripe_public_key"; + return [4 /*yield*/, easypostClient._get(url)]; + case 1: + response = _a.sent(); + return [2 /*return*/, response.body.public_key]; + } + }); + }); +} +/** + * Send the credit card details to Stripe to get a Stripe credit card token. + * @private + * @param stripeKey - The Stripe API key. + * @param number - Credit card number. + * @param expirationMonth - Credit card expiration month. + * @param expirationYear - Credit card expiration year. + * @param cvc - Credit card CVC. + * @returns - Stripe credit card token. + */ +function _sendCardDetailsToStripe(stripeKey, number, expirationMonth, expirationYear, cvc) { + return __awaiter(this, void 0, void 0, function () { + var url, request, response, error_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "https://api.stripe.com/v1/tokens?card[number]=".concat(number, "&card[exp_month]=").concat(expirationMonth, "&card[exp_year]=").concat(expirationYear, "&card[cvc]=").concat(cvc); + request = superagent_1.default.post(url).set({ + Authorization: "Bearer ".concat(stripeKey), + "Content-Type": "application/x-www-form-urlencoded", + }); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, request]; + case 2: + response = _a.sent(); + return [2 /*return*/, response.body.id]; + case 3: + error_1 = _a.sent(); + throw new external_api_error_1.default({ + message: node_util_1.default.format(constants_1.default.EXTERNAL_API_CALL_FAILED, "Stripe"), + }); + case 4: return [2 /*return*/]; + } + }); + }); +} +/** + * Send the Stripe credit card token to EasyPost to add the card to the user's account. + * @private + * @param client - The EasyPostClient to use. + * @param referralApiKey - The referral user's production API key. + * @param stripeCreditCardToken - Stripe credit card token. + * @param priority - Whether to add the card as the 'primary' or 'secondary' card. + * @returns - Response body (EasyPost payment method object). + */ +function _sendCardDetailsToEasyPost(client, referralApiKey, stripeCreditCardToken, priority) { + return __awaiter(this, void 0, void 0, function () { + var _client, url, params, response; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _client = _getReferralClient(client, referralApiKey); + url = "credit_cards"; + params = { + credit_card: { stripe_object_id: stripeCreditCardToken, priority: priority }, + }; + return [4 /*yield*/, _client._post(url, params)]; + case 1: + response = _a.sent(); + return [2 /*return*/, response.body]; + } + }); + }); +} +exports.default = (function (easypostClient) { + /** + * The ReferralCustomerService class provides methods for interacting with EasyPost {@link User referral customer} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(ReferralCustomerService, _super); + function ReferralCustomerService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create a {@link User referral customer}. + * See {@link https://www.easypost.com/docs/api/node#create-a-referral-customer EasyPost API Documentation} for more information. + * @param params - The referral customer's information. + * @returns - The newly created referral customer. + */ + ReferralCustomerService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "referral_customers"; + wrappedParams = { + user: params, + }; + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Update a {@link User referral customer's} email address. + * See {@link https://www.easypost.com/docs/api/node#update-a-referral-customer EasyPost API Documentation} for more information. + * @param referralUserId - The ID of the referral customer to update. + * @param email - The new email address. + * @returns - Returns true if the referral was updated successfully, false otherwise. + */ + ReferralCustomerService.updateEmail = function (referralUserId, email) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "referral_customers/".concat(referralUserId); + wrappedParams = { user: { email: email } }; + return [4 /*yield*/, easypostClient._put(url, wrappedParams)]; + case 1: + _a.sent(); // will throw if there's an error + return [2 /*return*/, true]; + } + }); + }); + }; + /** + * Add a credit card to a {@link User referral customer's} account. + * See {@link https://www.easypost.com/docs/api/node#create-credit-card EasyPost API Documentation} for more information. + * @param referralApiKey - The referral customer's production API key. + * @param number - The credit card number. + * @param expirationMonth - The credit card expiration month. + * @param expirationYear - The credit card expiration year. + * @param cvc - The credit card CVC. + * @param priority - Whether to add the card as 'primary' or 'secondary' payment method (defaults to 'primary'). + * @returns - An object representing the newly-added credit card. + */ + ReferralCustomerService.addCreditCard = function (referralApiKey, number, expirationMonth, expirationYear, cvc, priority) { + if (priority === void 0) { priority = "primary"; } + return __awaiter(this, void 0, void 0, function () { + var stripeKey, stripeCreditCardId, paymentMethod; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, _getEasyPostStripeKey(easypostClient)]; + case 1: + stripeKey = _a.sent(); + return [4 /*yield*/, _sendCardDetailsToStripe(stripeKey, number, expirationMonth, expirationYear, cvc)]; + case 2: + stripeCreditCardId = _a.sent(); + return [4 /*yield*/, _sendCardDetailsToEasyPost(easypostClient, referralApiKey, stripeCreditCardId, priority)]; + case 3: + paymentMethod = _a.sent(); + return [2 /*return*/, paymentMethod]; + } + }); + }); + }; + /** + * Retrieve all {@link User referral customers} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the referral customers by. + * @returns - An object containing a list of {@link User referral customers} and pagination information. + */ + ReferralCustomerService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "referral_customers"; + return [2 /*return*/, this._all(url, params)]; + }); + }); + }; + /** + * Retrieve the next page of Referral Customer collection. + * @param referralCustomers An object containing a list of {@link referral referralCustomers} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + ReferralCustomerService.getNextPage = function (referralCustomers, pageSize) { + if (pageSize === void 0) { pageSize = null; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "referral_customers"; + return [2 /*return*/, this._getNextPage(url, "referral_customers", referralCustomers, pageSize)]; + }); + }); + }; + return ReferralCustomerService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/refund_service/Refund.js b/out/src/services/refund_service/Refund.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/refund_service/Refund.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/refund_service/RefundCreateParameters.js b/out/src/services/refund_service/RefundCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/refund_service/RefundCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/refund_service/RefundListParameters.js b/out/src/services/refund_service/RefundListParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/refund_service/RefundListParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/refund_service/index.js b/out/src/services/refund_service/index.js new file mode 100644 index 000000000..8e6324a0d --- /dev/null +++ b/out/src/services/refund_service/index.js @@ -0,0 +1,152 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./Refund"), exports); +__exportStar(require("./RefundCreateParameters"), exports); +__exportStar(require("./RefundListParameters"), exports); +exports.default = (function (easypostClient) { + /** + * The RefundService class provides methods for interacting with EasyPost {@link Refund} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(RefundService, _super); + function RefundService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create a {@link Refund refund}. + * See {@link https://www.easypost.com/docs/api/node#create-a-refund EasyPost API Documentation} for more information. + * @param params - The parameters to create a refund with. + * @returns - The created refund. + */ + RefundService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "refunds"; + wrappedParams = { + refund: params, + }; + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Retrieve all {@link Refund refunds} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the refunds by. + * @returns - An object containing the list of {@link Refund refunds} and pagination information. + */ + RefundService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "refunds"; + return [2 /*return*/, this._all(url, params)]; + }); + }); + }; + /** + * Retrieve the next page of Refund collection. + * @param refunds An object containing a list of {@link Refund refunds} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + RefundService.getNextPage = function (refunds, pageSize) { + if (pageSize === void 0) { pageSize = null; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "refunds"; + return [2 /*return*/, this._getNextPage(url, "refunds", refunds, pageSize)]; + }); + }); + }; + /** + * Retrieve a {@link Refund refund} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-refund EasyPost API Documentation} for more information. + * @param id - The ID of the refund to retrieve. + * @returns - The retrieved refund. + */ + RefundService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "refunds/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return RefundService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/report_service/Report.js b/out/src/services/report_service/Report.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/report_service/Report.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/report_service/ReportCreateParameters.js b/out/src/services/report_service/ReportCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/report_service/ReportCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/report_service/ReportListParameters.js b/out/src/services/report_service/ReportListParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/report_service/ReportListParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/report_service/ReportObjectType.js b/out/src/services/report_service/ReportObjectType.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/report_service/ReportObjectType.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/report_service/index.js b/out/src/services/report_service/index.js new file mode 100644 index 000000000..a56b614d4 --- /dev/null +++ b/out/src/services/report_service/index.js @@ -0,0 +1,177 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./Report"), exports); +__exportStar(require("./ReportCreateParameters"), exports); +__exportStar(require("./ReportListParameters"), exports); +__exportStar(require("./ReportObjectType"), exports); +exports.default = (function (easypostClient) { + /** + * The ReportService class provides methods for interacting with EasyPost {@link Report} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(ReportService, _super); + function ReportService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create a {@link Report report}. + * See {@link https://www.easypost.com/docs/api/node#create-a-report EasyPost API Documentation} for more information. + * @param params - The parameters to create a report with. + * @returns - The created report. + */ + ReportService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "reports/".concat(params.type); + return [2 /*return*/, this._create(url, params)]; + }); + }); + }; + /** + * Retrieve all {@link Report reports} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-reports EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the reports by. + * @returns - An object containing the list of {@link Report reports} and pagination information. + */ + ReportService.all = function (params) { + return __awaiter(this, void 0, void 0, function () { + var type, url, apiParams, response, responseObject, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + type = params.type; + url = "reports/".concat(type); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + apiParams = __assign({}, params); + delete apiParams.type; + return [4 /*yield*/, easypostClient._get(url, apiParams)]; + case 2: + response = _a.sent(); + responseObject = this._convertToEasyPostObject(response.body, params); + return [2 /*return*/, responseObject]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve the next page of Report collection. + * @param reports An object containing a list of {@link Report reports} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + ReportService.getNextPage = function (reports, pageSize) { + if (pageSize === void 0) { pageSize = null; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "reports/".concat(reports.reports[0]._params.type); + return [2 /*return*/, this._getNextPage(url, "reports", reports, pageSize)]; + }); + }); + }; + /** + * Retrieve a {@link Report report} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-report EasyPost API Documentation} for more information. + * @param id - The ID of the report to retrieve. + * @returns - The retrieved report. + */ + ReportService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "reports/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return ReportService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/scan_form_service/ScanForm.js b/out/src/services/scan_form_service/ScanForm.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/scan_form_service/ScanForm.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/scan_form_service/ScanFormCreateParameters.js b/out/src/services/scan_form_service/ScanFormCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/scan_form_service/ScanFormCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/scan_form_service/ScanFormListParameters.js b/out/src/services/scan_form_service/ScanFormListParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/scan_form_service/ScanFormListParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/scan_form_service/index.js b/out/src/services/scan_form_service/index.js new file mode 100644 index 000000000..83e8e3572 --- /dev/null +++ b/out/src/services/scan_form_service/index.js @@ -0,0 +1,163 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./ScanForm"), exports); +__exportStar(require("./ScanFormCreateParameters"), exports); +__exportStar(require("./ScanFormListParameters"), exports); +exports.default = (function (easypostClient) { + /** + * The ScanFormService class provides methods for interacting with EasyPost {@link ScanForm} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(ScanFormService, _super); + function ScanFormService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create a {@link ScanForm scan form}. + * See {@link https://www.easypost.com/docs/api/node#create-a-scanform EasyPost API Documentation} for more information. + * @param params - The parameters to create a scan form with. + * @returns - The created scan form. + */ + ScanFormService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "scan_forms"; + // wraps up params in `shipments` if the user didn't do it + // turn a list of shipment objects into a map of shipment ids + if (params.shipments) { + // eslint-disable-next-line no-param-reassign + params.shipments = params.shipments.map(function (s) { + if (typeof s === "string") { + return { id: s }; + } + return { id: s.id }; + }); + } + wrappedParams = { + scan_form: params, + }; + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Retrieve all {@link ScanForm scan forms} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-scanforms EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the scan forms by. + * @returns - An object containing the list of {@link ScanForm scan forms} and pagination information. + */ + ScanFormService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "scan_forms"; + return [2 /*return*/, this._all(url, params)]; + }); + }); + }; + /** + * Retrieve the next page of ScanForm collection. + * @param scanForms An object containing a list of {@link ScanForm scanForms} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + ScanFormService.getNextPage = function (scanForms, pageSize) { + if (pageSize === void 0) { pageSize = null; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "scan_forms"; + return [2 /*return*/, this._getNextPage(url, "scan_forms", scanForms, pageSize)]; + }); + }); + }; + /** + * Retrieve a {@link ScanForm scan form} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-scanform EasyPost API Documentation} for more information. + * @param id - The ID of the scan form to retrieve. + * @returns - The retrieved scan form. + */ + ScanFormService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "scan_forms/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return ScanFormService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/shipment_service/Form.js b/out/src/services/shipment_service/Form.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/shipment_service/Form.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/Message.js b/out/src/services/shipment_service/Message.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/shipment_service/Message.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/Options/LabelFormat.js b/out/src/services/shipment_service/Options/LabelFormat.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/shipment_service/Options/LabelFormat.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/Options/Options.js b/out/src/services/shipment_service/Options/Options.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/shipment_service/Options/Options.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/Options/PrintCustomCode.js b/out/src/services/shipment_service/Options/PrintCustomCode.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/shipment_service/Options/PrintCustomCode.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/Options/index.js b/out/src/services/shipment_service/Options/index.js new file mode 100644 index 000000000..969981b8e --- /dev/null +++ b/out/src/services/shipment_service/Options/index.js @@ -0,0 +1,19 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./LabelFormat"), exports); +__exportStar(require("./Options"), exports); +__exportStar(require("./PrintCustomCode"), exports); diff --git a/out/src/services/shipment_service/PostageLabel.js b/out/src/services/shipment_service/PostageLabel.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/shipment_service/PostageLabel.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/Shipment.js b/out/src/services/shipment_service/Shipment.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/shipment_service/Shipment.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/ShipmentCreateParameters.js b/out/src/services/shipment_service/ShipmentCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/shipment_service/ShipmentCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/ShipmentListParameters.js b/out/src/services/shipment_service/ShipmentListParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/shipment_service/ShipmentListParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/index.js b/out/src/services/shipment_service/index.js new file mode 100644 index 000000000..042a0dd22 --- /dev/null +++ b/out/src/services/shipment_service/index.js @@ -0,0 +1,479 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var constants_1 = __importDefault(require("../../constants")); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./Form"), exports); +__exportStar(require("./Message"), exports); +__exportStar(require("./PostageLabel"), exports); +__exportStar(require("./Shipment"), exports); +__exportStar(require("./ShipmentCreateParameters"), exports); +__exportStar(require("./ShipmentListParameters"), exports); +__exportStar(require("./Options"), exports); +var addLowestRateToShipment = function (shipment) { + return __assign(__assign({}, shipment), { lowestRate: function (carriers, services) { + return constants_1.default.Utils.getLowestRate(shipment.rates, carriers, services); + } }); +}; +exports.default = (function (easypostClient) { + /** + * The ShipmentService class provides methods for interacting with EasyPost {@link Shipment} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(ShipmentService, _super); + function ShipmentService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#create-a-shipment EasyPost API Documentation} for more information. + * @param params - The parameters to create a shipment with. + * @returns - The created shipment. + */ + ShipmentService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, shipment; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "shipments"; + wrappedParams = { + shipment: params, + }; + return [4 /*yield*/, this._create(url, wrappedParams)]; + case 1: + shipment = _a.sent(); + return [2 /*return*/, addLowestRateToShipment(shipment)]; + } + }); + }); + }; + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */ + ShipmentService.buy = function (id, rate, insuranceAmount, endShipperId) { + if (insuranceAmount === void 0) { insuranceAmount = null; } + if (endShipperId === void 0) { endShipperId = null; } + return __awaiter(this, void 0, void 0, function () { + var rateId, url, wrappedParams, response, shipment, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + rateId = typeof rate === "object" ? rate.id : rate; + url = "shipments/".concat(id, "/buy"); + wrappedParams = { + rate: { + id: rateId, + }, + }; + if (insuranceAmount) { + wrappedParams.insurance = insuranceAmount; + } + if (endShipperId) { + wrappedParams.end_shipper_id = endShipperId; + } + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; + case 2: + response = _a.sent(); + shipment = this._convertToEasyPostObject(response.body, wrappedParams); + return [2 /*return*/, addLowestRateToShipment(shipment)]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Convert the label format of a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#convert-the-label-format-of-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to convert the label format of. + * @param format - The format to convert the label to. + * @returns - The shipment with the converted label format. + */ + ShipmentService.convertLabelFormat = function (id, format) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, shipment, e_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "shipments/".concat(id, "/label"); + wrappedParams = { file_format: format }; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._get(url, wrappedParams)]; + case 2: + response = _a.sent(); + shipment = this._convertToEasyPostObject(response.body, wrappedParams); + return [2 /*return*/, addLowestRateToShipment(shipment)]; + case 3: + e_2 = _a.sent(); + return [2 /*return*/, Promise.reject(e_2)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Regenerate {@link Rate rates} for a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#regenerate-rates-for-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to regenerate rates for. + * @returns - The shipment with regenerated rates. + */ + ShipmentService.regenerateRates = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, shipment, e_3; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "shipments/".concat(id, "/rerate"); + wrappedParams = {}; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; + case 2: + response = _a.sent(); + shipment = this._convertToEasyPostObject(response.body, wrappedParams); + return [2 /*return*/, addLowestRateToShipment(shipment)]; + case 3: + e_3 = _a.sent(); + return [2 /*return*/, Promise.reject(e_3)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Get SmartRates for a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-time-in-transit-statistics-across-all-rates-for-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to get SmartRates for. + * @returns - The SmartRates for the shipment. + */ + ShipmentService.getSmartRates = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, response, e_4; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "shipments/".concat(id, "/smartrate"); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._get(url)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body.result)]; + case 3: + e_4 = _a.sent(); + return [2 /*return*/, Promise.reject(e_4)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Insure a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#insure-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to insure. + * @param amount - The amount to insure the shipment for. + * @returns - The insured shipment. + */ + ShipmentService.insure = function (id, amount) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, shipment, e_5; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "shipments/".concat(id, "/insure"); + wrappedParams = { amount: amount }; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; + case 2: + response = _a.sent(); + shipment = this._convertToEasyPostObject(response.body, wrappedParams); + return [2 /*return*/, addLowestRateToShipment(shipment)]; + case 3: + e_5 = _a.sent(); + return [2 /*return*/, Promise.reject(e_5)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Generate a form for a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#create-form EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to generate a form for. + * @param formType - The type of form to generate. + * @param [formOptions] - Options for the form. + * @returns - The shipment with the generated form attached. + */ + ShipmentService.generateForm = function (id, formType, formOptions) { + if (formOptions === void 0) { formOptions = {}; } + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, shipment, e_6; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "shipments/".concat(id, "/forms"); + wrappedParams = { + form: __assign(__assign({}, formOptions), { type: formType }), + }; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; + case 2: + response = _a.sent(); + shipment = this._convertToEasyPostObject(response.body, wrappedParams); + return [2 /*return*/, addLowestRateToShipment(shipment)]; + case 3: + e_6 = _a.sent(); + return [2 /*return*/, Promise.reject(e_6)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Refund a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#refund-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to refund. + * @returns - The refunded shipment. + */ + ShipmentService.refund = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, response, shipment, e_7; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "shipments/".concat(id, "/refund"); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._post(url)]; + case 2: + response = _a.sent(); + shipment = this._convertToEasyPostObject(response.body); + return [2 /*return*/, addLowestRateToShipment(shipment)]; + case 3: + e_7 = _a.sent(); + return [2 /*return*/, Promise.reject(e_7)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Get the lowest SmartRate of a shipment. + * @param id - The ID of the shipment to get the lowest SmartRate of. + * @param deliveryDays - The number of days the shipment will take to deliver. + * @param deliveryAccuracy - The accuracy of the delivery days. + * @returns - The lowest SmartRate of the shipment. + */ + ShipmentService.lowestSmartRate = function (id, deliveryDays, deliveryAccuracy) { + return __awaiter(this, void 0, void 0, function () { + var smartRates; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.getSmartRates(id)]; + case 1: + smartRates = _a.sent(); + return [2 /*return*/, constants_1.default.Utils.getLowestSmartRate(smartRates, deliveryDays, deliveryAccuracy.toLowerCase())]; + } + }); + }); + }; + /** + * Retrieve all {@link Shipment shipments} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the shipments by. + * @returns - An object containing a list of {@link Shipment shipments} and pagination information. + */ + ShipmentService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url, result; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "shipments"; + return [4 /*yield*/, this._all(url, params)]; + case 1: + result = _a.sent(); + return [2 /*return*/, __assign(__assign({}, result), { shipments: result.shipments.map(addLowestRateToShipment) })]; + } + }); + }); + }; + /** + * Retrieve the next page of Shipment collection. + * @param shipments An object containing a list of {@link Shipment shipments} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + ShipmentService.getNextPage = function (shipments, pageSize) { + if (pageSize === void 0) { pageSize = null; } + return __awaiter(this, void 0, void 0, function () { + var url, result; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "shipments"; + return [4 /*yield*/, this._getNextPage(url, "shipments", shipments, pageSize)]; + case 1: + result = _a.sent(); + return [2 /*return*/, __assign(__assign({}, result), { shipments: result.shipments.map(addLowestRateToShipment) })]; + } + }); + }); + }; + /** + * Retrieve a {@link Shipment shipment} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to retrieve. + * @returns - The shipment with the given ID. + */ + ShipmentService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, shipment; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "shipments/".concat(id); + return [4 /*yield*/, this._retrieve(url)]; + case 1: + shipment = _a.sent(); + return [2 /*return*/, addLowestRateToShipment(shipment)]; + } + }); + }); + }; + /** + * Retrieves the estimated delivery date of each Rate via SmartRate. + * @param id + * @param plannedShipDate + * @returns - An array of the estimated delivery date and rates. + */ + ShipmentService.retrieveEstimatedDeliveryDate = function (id, plannedShipDate) { + var _a; + return __awaiter(this, void 0, void 0, function () { + var url, params, response, e_8; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + url = "shipments/".concat(id, "/smartrate/delivery_date"); + params = { + planned_ship_date: plannedShipDate, + }; + _b.label = 1; + case 1: + _b.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._get(url, params)]; + case 2: + response = _b.sent(); + return [2 /*return*/, this._convertToEasyPostObject((_a = response.body.rates) !== null && _a !== void 0 ? _a : [], params)]; + case 3: + e_8 = _b.sent(); + return [2 /*return*/, Promise.reject(e_8)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + return ShipmentService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/tracker_service/CarrierDetail.js b/out/src/services/tracker_service/CarrierDetail.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/tracker_service/CarrierDetail.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/Tracker.js b/out/src/services/tracker_service/Tracker.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/tracker_service/Tracker.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/TrackerCreateParameters.js b/out/src/services/tracker_service/TrackerCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/tracker_service/TrackerCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/TrackerListParameters.js b/out/src/services/tracker_service/TrackerListParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/tracker_service/TrackerListParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/TrackerStatus.js b/out/src/services/tracker_service/TrackerStatus.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/tracker_service/TrackerStatus.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/TrackerStatusDetail.js b/out/src/services/tracker_service/TrackerStatusDetail.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/tracker_service/TrackerStatusDetail.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/TrackingDetail.js b/out/src/services/tracker_service/TrackingDetail.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/tracker_service/TrackingDetail.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/TrackingLocation.js b/out/src/services/tracker_service/TrackingLocation.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/tracker_service/TrackingLocation.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/index.js b/out/src/services/tracker_service/index.js new file mode 100644 index 000000000..3202ed517 --- /dev/null +++ b/out/src/services/tracker_service/index.js @@ -0,0 +1,179 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./CarrierDetail"), exports); +__exportStar(require("./Tracker"), exports); +__exportStar(require("./TrackerCreateParameters"), exports); +__exportStar(require("./TrackerListParameters"), exports); +__exportStar(require("./TrackerStatus"), exports); +__exportStar(require("./TrackerStatusDetail"), exports); +__exportStar(require("./TrackingDetail"), exports); +__exportStar(require("./TrackingLocation"), exports); +exports.default = (function (easypostClient) { + /** + * The TrackerService class provides methods for interacting with EasyPost {@link Tracker} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(TrackerService, _super); + function TrackerService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create a {@link Tracker tracker}. + * See {@link https://www.easypost.com/docs/api/node#create-a-tracker EasyPost API Documentation} for more information. + * @param params - The parameters to create a tracker with. + * @returns - The created tracker. + */ + TrackerService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "trackers"; + wrappedParams = { + tracker: params, + }; + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Create multiple {@link Tracker trackers} in a single request. + * See {@link https://www.easypost.com/docs/api/node#trackers EasyPost API Documentation} for more information. + * @param [params] - The parameters to create trackers with. + */ + TrackerService.createList = function (params) { + if (params === void 0) { params = []; } + return __awaiter(this, void 0, void 0, function () { + var newParams, url; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + newParams = { trackers: params }; + url = "trackers/create_list"; + return [4 /*yield*/, easypostClient._post(url, newParams)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve all {@link Tracker trackers} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-trackers EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the trackers by. + * @returns - An object containing the list of {@link Tracker trackers} and pagination information. + */ + TrackerService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "trackers"; + return [2 /*return*/, this._all(url, params)]; + }); + }); + }; + /** + * Retrieve the next page of Tracker collection. + * @param trackers An object containing a list of {@link Tracker trackers} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + TrackerService.getNextPage = function (trackers, pageSize) { + if (pageSize === void 0) { pageSize = null; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "trackers"; + return [2 /*return*/, this._getNextPage(url, "trackers", trackers, pageSize)]; + }); + }); + }; + /** + * Retrieve a {@link Tracker tracker} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-tracker EasyPost API Documentation} for more information. + * @param id - The ID of the tracker to retrieve. + * @returns - The retrieved tracker. + */ + TrackerService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "trackers/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return TrackerService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/user_service/Brand.js b/out/src/services/user_service/Brand.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/user_service/Brand.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/user_service/User.js b/out/src/services/user_service/User.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/user_service/User.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/user_service/UserCreateParameters.js b/out/src/services/user_service/UserCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/user_service/UserCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/user_service/index.js b/out/src/services/user_service/index.js new file mode 100644 index 000000000..285f7445d --- /dev/null +++ b/out/src/services/user_service/index.js @@ -0,0 +1,294 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./Brand"), exports); +__exportStar(require("./User"), exports); +__exportStar(require("./UserCreateParameters"), exports); +exports.default = (function (easypostClient) { + /** + * The UserService class provides methods for interacting with EasyPost {@link User} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(UserService, _super); + function UserService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create a {@link User child user}. + * See {@link https://www.easypost.com/docs/api/node#create-a-child-user EasyPost API Documentation} for more information. + * @param params - The parameters to create a child user with. + * @returns - The created child user. + */ + UserService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "users"; + wrappedParams = { + user: params, + }; + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Update a {@link User user}. + * See {@link https://www.easypost.com/docs/api/node#update-a-user EasyPost API Documentation} for more information. + * @param id - The ID of the user to update (either the current authenticated user or a child user). + * @param params - The parameters to update the user with. + * @returns - The updated user. + */ + UserService.update = function (id, params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "users/".concat(id); + wrappedParams = { + user: params, + }; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._patch(url, wrappedParams)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve a {@link User child user}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-user EasyPost API Documentation} for more information. + * @param id - The ID of the child user to retrieve. + * @returns - The retrieved child user. + */ + UserService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, response, e_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "users/".concat(id); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._get(url)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body)]; + case 3: + e_2 = _a.sent(); + return [2 /*return*/, Promise.reject(e_2)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve the {@link User current authenticated user}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-user EasyPost API Documentation} for more information. + * @returns - The retrieved user. + */ + UserService.retrieveMe = function () { + return __awaiter(this, void 0, void 0, function () { + var url, response, e_3; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "users"; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._get(url)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body)]; + case 3: + e_3 = _a.sent(); + return [2 /*return*/, Promise.reject(e_3)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Delete a {@link User child user}. + * See {@link https://www.easypost.com/docs/api/node#delete-a-child-user EasyPost API Documentation} for more information. + * @param id - The ID of the child user to delete. + * @returns - A promise that resolves when the child user is deleted successfully. + */ + UserService.delete = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, e_4; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "users/".concat(id); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._delete(url)]; + case 2: + _a.sent(); + return [2 /*return*/, Promise.resolve()]; + case 3: + e_4 = _a.sent(); + return [2 /*return*/, Promise.reject(e_4)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Update the brand of a {@link User user}. + * See {@link https://www.easypost.com/docs/api/node#update-a-brand EasyPost API Documentation} for more information. + * @param id - The ID of the user to update the brand of. + * @param params - The parameters to update the brand with. + * @returns - The updated brand. + */ + UserService.updateBrand = function (id, params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams, response, e_5; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "users/".concat(id, "/brand"); + wrappedParams = { brand: params }; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._patch(url, wrappedParams)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; + case 3: + e_5 = _a.sent(); + return [2 /*return*/, Promise.reject(e_5)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve a paginated list of children user {@link User user}. + * See {@link https://www.easypost.com/docs/api/node#child-users EasyPost API Documentation} for more information. + * @param params - Parameters to filter the list of children users. + * @returns - An object containing a list of {@link Children User} and pagination information. + */ + UserService.allChildren = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, response, e_6; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "users/children"; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._get(url, params)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body, params)]; + case 3: + e_6 = _a.sent(); + return [2 /*return*/, Promise.reject(e_6)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve the next page of children collection. + * @param children An object containing a list of {@link Children children} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + UserService.getNextPage = function (children, pageSize) { + if (pageSize === void 0) { pageSize = null; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "users/children"; + return [2 /*return*/, this._getNextPage(url, "children", children, pageSize)]; + }); + }); + }; + return UserService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/services/webhook_service/Webhook.js b/out/src/services/webhook_service/Webhook.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/webhook_service/Webhook.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/webhook_service/WebhookCreateParameters.js b/out/src/services/webhook_service/WebhookCreateParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/webhook_service/WebhookCreateParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/webhook_service/WebhookListParameters.js b/out/src/services/webhook_service/WebhookListParameters.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/services/webhook_service/WebhookListParameters.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/webhook_service/index.js b/out/src/services/webhook_service/index.js new file mode 100644 index 000000000..6896bafa7 --- /dev/null +++ b/out/src/services/webhook_service/index.js @@ -0,0 +1,194 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var base_service_1 = __importDefault(require("../base_service")); +__exportStar(require("./Webhook"), exports); +__exportStar(require("./WebhookCreateParameters"), exports); +__exportStar(require("./WebhookListParameters"), exports); +exports.default = (function (easypostClient) { + /** + * The WebhookService class provides methods for interacting with EasyPost {@link Webhook} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + return /** @class */ (function (_super) { + __extends(WebhookService, _super); + function WebhookService() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * Create a {@link Webhook webhook}. + * See {@link https://www.easypost.com/docs/api/node#create-a-webhook EasyPost API Documentation} for more information. + * @param params - The parameters to create a webhook with. + * @returns - The created webhook. + */ + WebhookService.create = function (params) { + return __awaiter(this, void 0, void 0, function () { + var url, wrappedParams; + return __generator(this, function (_a) { + url = "webhooks"; + wrappedParams = { + webhook: params, + }; + return [2 /*return*/, this._create(url, wrappedParams)]; + }); + }); + }; + /** + * Update a {@link Webhook webhook}. + * A disabled webhook will be re-enabled if it is updated. + * See {@link https://www.easypost.com/docs/api/node#update-a-webhook EasyPost API Documentation} for more information. + * @param id - The ID of the webhook to update. + * @param params - The parameters to update the webhook with. + * @returns - The updated webhook. + */ + WebhookService.update = function (id, params) { + return __awaiter(this, void 0, void 0, function () { + var url, response, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "webhooks/".concat(id); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._patch(url, params)]; + case 2: + response = _a.sent(); + return [2 /*return*/, this._convertToEasyPostObject(response.body, params)]; + case 3: + e_1 = _a.sent(); + return [2 /*return*/, Promise.reject(e_1)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Delete a {@link Webhook webhook}. + * See {@link https://www.easypost.com/docs/api/node#delete-a-webhook EasyPost API Documentation} for more information. + * @param id - The ID of the webhook to delete. + * @returns - A promise that resolves if the webhook was successfully deleted. + */ + WebhookService.delete = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url, e_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = "webhooks/".concat(id); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, easypostClient._delete(url)]; + case 2: + _a.sent(); + return [2 /*return*/, Promise.resolve()]; + case 3: + e_2 = _a.sent(); + return [2 /*return*/, Promise.reject(e_2)]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + /** + * Retrieve all {@link Webhook webhooks} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#list-a-webhooks EasyPost API Documentation} for more information. + * @param [params] + * @returns + */ + WebhookService.all = function (params) { + if (params === void 0) { params = {}; } + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "webhooks"; + return [2 /*return*/, this._all(url, params)]; + }); + }); + }; + /** + * Retrieve a {@link Webhook webhook} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-webhook EasyPost API Documentation} for more information. + * @param id - The ID of the webhook to retrieve. + * @returns - The retrieved webhook. + */ + WebhookService.retrieve = function (id) { + return __awaiter(this, void 0, void 0, function () { + var url; + return __generator(this, function (_a) { + url = "webhooks/".concat(id); + return [2 /*return*/, this._retrieve(url)]; + }); + }); + }; + return WebhookService; + }((0, base_service_1.default)(easypostClient))); +}); diff --git a/out/src/utils/errors/Error.js b/out/src/utils/errors/Error.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/utils/errors/Error.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/utils/errors/ErrorCode.js b/out/src/utils/errors/ErrorCode.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/utils/errors/ErrorCode.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/utils/errors/FieldError.js b/out/src/utils/errors/FieldError.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/out/src/utils/errors/FieldError.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/utils/errors/index.js b/out/src/utils/errors/index.js new file mode 100644 index 000000000..a90757778 --- /dev/null +++ b/out/src/utils/errors/index.js @@ -0,0 +1,19 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./Error"), exports); +__exportStar(require("./ErrorCode"), exports); +__exportStar(require("./FieldError"), exports); diff --git a/out/src/utils/types.js b/out/src/utils/types.js new file mode 100644 index 000000000..2367d855d --- /dev/null +++ b/out/src/utils/types.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = {}; diff --git a/out/src/utils/util.js b/out/src/utils/util.js new file mode 100644 index 000000000..05806eac1 --- /dev/null +++ b/out/src/utils/util.js @@ -0,0 +1,199 @@ +"use strict"; +var __read = (this && this.__read) || function (o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +}; +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +}; +var __values = (this && this.__values) || function(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function () { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var node_crypto_1 = __importDefault(require("node:crypto")); +var node_util_1 = __importDefault(require("node:util")); +var constants_1 = __importDefault(require("../constants")); +var filtering_error_1 = __importDefault(require("../errors/general/filtering_error")); +var invalid_parameter_error_1 = __importDefault(require("../errors/general/invalid_parameter_error")); +var signature_verification_error_1 = __importDefault(require("../errors/general/signature_verification_error")); +/** + * Utility class of various publicly-available helper functions. + * @public + * @type {Utils} + */ +var Utils = /** @class */ (function () { + function Utils() { + } + /** + * Get the lowest SmartRate from a provided list of SmartRates. + * @public + * @param smartRates - List of SmartRates to filter through + * @param deliveryDays - The maximum number of days allowed for delivery + * @param deliveryAccuracy - The target level of accuracy for the delivery days (e.g. 'percentile_50') + * @returns - The lowest SmartRate + * @throws {FilteringError} - If no applicable rates are found + * @throws {InvalidParameterError} - If the deliveryAccuracy value is invalid + */ + Utils.prototype.getLowestSmartRate = function (smartRates, deliveryDays, deliveryAccuracy) { + var e_1, _a; + var validDeliveryAccuracyValues = new Set([ + "percentile_50", + "percentile_75", + "percentile_85", + "percentile_90", + "percentile_95", + "percentile_97", + "percentile_99", + ]); + var lowestSmartRate = null; + var lowercaseDeliveryAccuracy = deliveryAccuracy.toLowerCase(); + if (!validDeliveryAccuracyValues.has(lowercaseDeliveryAccuracy)) { + throw new invalid_parameter_error_1.default({ + message: "Invalid deliveryAccuracy value, must be one of: ".concat(__spreadArray([], __read(validDeliveryAccuracyValues), false).join(", ")), + }); + } + try { + for (var smartRates_1 = __values(smartRates), smartRates_1_1 = smartRates_1.next(); !smartRates_1_1.done; smartRates_1_1 = smartRates_1.next()) { + var rate = smartRates_1_1.value; + if (rate.time_in_transit[lowercaseDeliveryAccuracy] > Number(deliveryDays)) { + // eslint-disable-next-line no-continue + continue; + } + else if (lowestSmartRate === null || + parseFloat(rate.rate) < parseFloat(lowestSmartRate.rate)) { + lowestSmartRate = rate; + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (smartRates_1_1 && !smartRates_1_1.done && (_a = smartRates_1.return)) _a.call(smartRates_1); + } + finally { if (e_1) throw e_1.error; } + } + if (lowestSmartRate === null) { + throw new filtering_error_1.default({ + message: node_util_1.default.format(constants_1.default.NO_OBJECT_FOUND, "rates"), + }); + } + return lowestSmartRate; + }; + /** + * Get the lowest rate from a provided list of rates. + * @public + * @param rates - List of rates to filter through + * @param [carriers] - List of allowed carriers to filter by + * @param [services] - List of allowed services to filter by + * @returns - The lowest rate + * @throws {FilteringError} - If no applicable rates are found + */ + Utils.prototype.getLowestRate = function (rates, carriers, services) { + if (carriers === void 0) { carriers = null; } + if (services === void 0) { services = null; } + if (carriers) { + var carriersLower_1 = carriers.map(function (carrier) { return carrier.toLowerCase(); }); + // eslint-disable-next-line no-param-reassign + rates = rates.filter(function (rate) { + return carriersLower_1.includes(rate.carrier.toLowerCase()); + }); + } + if (services) { + var servicesLower_1 = services.map(function (service) { return service.toLowerCase(); }); + // eslint-disable-next-line no-param-reassign + rates = rates.filter(function (rate) { + return servicesLower_1.includes(rate.service.toLowerCase()); + }); + } + if (rates.length === 0) { + throw new filtering_error_1.default({ + message: node_util_1.default.format(constants_1.default.NO_OBJECT_FOUND, "rates"), + }); + } + return rates.reduce(function (lowest, rate) { + if (parseFloat(rate.rate) < parseFloat(lowest.rate)) { + return rate; + } + return lowest; + }, rates[0]); + }; + /** + * Validate a webhook by comparing the HMAC signature header sent from EasyPost to your shared secret. + * If the signatures do not match, an error will be raised signifying the webhook either did not originate + * from EasyPost or the secrets do not match. If the signatures do match, the `event_body` will be returned + * as JSON. + * @public + * @param eventBody - The raw body of the webhook event + * @param headers - The headers of the webhook HTTP request + * @param webhookSecret - The webhook secret shared between EasyPost and your application + * @returns - The JSON-parsed webhook event body if the signature could be verified + * @throws {SignatureVerificationError} - If the signature could not be verified + */ + Utils.prototype.validateWebhook = function (eventBody, headers, webhookSecret) { + var _a, _b; + var webhook = {}; + var easypostHmacSignature = (_b = (_a = headers["X-Hmac-Signature"]) !== null && _a !== void 0 ? _a : headers["x-hmac-signature"]) !== null && _b !== void 0 ? _b : null; + if (easypostHmacSignature != null) { + var normalizedSecret = webhookSecret.normalize("NFKD"); + var encodedSecret = Buffer.from(normalizedSecret, "utf8"); + var expectedSignature = node_crypto_1.default + .createHmac("sha256", encodedSecret) + // @ts-ignore buffers are weird + .update(eventBody, "utf-8") + .digest("hex"); + var digest = "hmac-sha256-hex=".concat(expectedSignature); + try { + if (node_crypto_1.default.timingSafeEqual(Buffer.from(easypostHmacSignature, "utf8"), Buffer.from(digest, "utf8"))) { + webhook = JSON.parse(eventBody.toString()); + } + else { + throw new signature_verification_error_1.default({ + message: constants_1.default.WEBHOOK_DOES_NOT_MATCH, + }); + } + } + catch (e) { + throw new signature_verification_error_1.default({ + message: constants_1.default.WEBHOOK_DOES_NOT_MATCH, + }); + } + } + else { + throw new signature_verification_error_1.default({ + message: constants_1.default.INVALID_WEBHOOK_SIGNATURE, + }); + } + return webhook; + }; + return Utils; +}()); +exports.default = Utils; diff --git a/package-lock.json b/package-lock.json index d7bd45279..7dbc87305 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,8 @@ "@pollyjs/adapter-node-http": "^6.0.5", "@pollyjs/core": "^6.0.5", "@pollyjs/persister-fs": "^6.0.5", + "@types/superagent": "^8.1.7", + "@types/uuid": "^9.0.8", "@typescript-eslint/eslint-plugin": "^5.59.5", "@typescript-eslint/parser": "^5.59.5", "audit-ci": "^6.6.1", @@ -2167,6 +2169,12 @@ "node": ">=10" } }, + "node_modules/@types/cookiejar": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.5.tgz", + "integrity": "sha512-he+DHOWReW0nghN24E1WUqM0efK4kI9oTqDm6XmK8ZPe2djZ90BSNdGnIyCLzCPw7/pogPlGbzI2wHGGmi4O/Q==", + "dev": true + }, "node_modules/@types/eslint": { "version": "8.56.1", "dev": true, @@ -2219,6 +2227,12 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/methods": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@types/methods/-/methods-1.1.4.tgz", + "integrity": "sha512-ymXWVrDiCxTBE3+RIrrP533E70eA+9qu7zdWoHuOmGujkYtzf4HQF96b8nwHLqhuf4ykX61IGRIB38CC6/sImQ==", + "dev": true + }, "node_modules/@types/node": { "version": "20.10.7", "dev": true, @@ -2240,6 +2254,23 @@ "@types/node": "*" } }, + "node_modules/@types/superagent": { + "version": "8.1.7", + "resolved": "https://registry.npmjs.org/@types/superagent/-/superagent-8.1.7.tgz", + "integrity": "sha512-NmIsd0Yj4DDhftfWvvAku482PZum4DBW7U51OvS8gvOkDDY0WT1jsVyDV3hK+vplrsYw8oDwi9QxOM7U68iwww==", + "dev": true, + "dependencies": { + "@types/cookiejar": "^2.1.5", + "@types/methods": "^1.1.4", + "@types/node": "*" + } + }, + "node_modules/@types/uuid": { + "version": "9.0.8", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.8.tgz", + "integrity": "sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==", + "dev": true + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "5.62.0", "dev": true, @@ -9232,8 +9263,9 @@ }, "node_modules/typescript": { "version": "5.0.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", + "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", "dev": true, - "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index cfd951605..a020aad19 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,9 @@ "node": ">= 12.0" }, "scripts": { - "build": "webpack --config webpack.config.babel.js", + "build": "npm run build:typescript && npm run build:webpack", + "build:webpack": "webpack --config webpack.config.babel.js", + "build:typescript": "tsc", "clean": "rm -rf ./dist ./nyc_output ./node_modules/.cache ./coverage", "coverage": "cross-env NODE_ENV=test nyc npm run test", "docs": "./node_modules/.bin/jsdoc src/models src/services src/errors src/utils -d docs", @@ -55,6 +57,8 @@ "@pollyjs/adapter-node-http": "^6.0.5", "@pollyjs/core": "^6.0.5", "@pollyjs/persister-fs": "^6.0.5", + "@types/superagent": "^8.1.7", + "@types/uuid": "^9.0.8", "@typescript-eslint/eslint-plugin": "^5.59.5", "@typescript-eslint/parser": "^5.59.5", "audit-ci": "^6.6.1", diff --git a/src/constants.js b/src/constants.js deleted file mode 100644 index b522179be..000000000 --- a/src/constants.js +++ /dev/null @@ -1,25 +0,0 @@ -import Utils from './utils/util'; - -/** - * A class containing constants used throughout the EasyPost Node.js client library. - */ -export default class Constants { - static get CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS() { - return ['FedexAccount', 'FedexSmartpostAccount', 'UpsAccount']; - } - static EXTERNAL_API_CALL_FAILED = 'Communication with %s failed, please try again later'; - static INVALID_API_KEY_TYPE = 'Invalid API key type.'; - static INVALID_PARAMETER = 'Invalid parameter: %s.'; - static INVALID_PAYMENT = 'The chosen payment method is not a credit card. Please try again.'; - static INVALID_WEBHOOK_SIGNATURE = 'Webhook does not contain a valid HMAC signature.'; - static MISSING_REQUIRED_PARAMETER = 'Missing required parameter: %s.'; - static NO_OBJECT_FOUND = 'No %s found.'; - static NO_PAYMENT_METHODS = - 'No payment methods are set up. Please add a payment method and try again.'; - static API_DID_NOT_RETURN_ERROR_DETAILS = 'API did not return error details.'; - static WEBHOOK_DOES_NOT_MATCH = - 'Webhook received did not originate from EasyPost or had a webhook secret mismatch.'; - static END_OF_PAGINATION = 'There are no more pages to retrieve.'; - static ERROR_DESERIALIZATION = 'Error deserializing JSON response'; - static Utils = new Utils(); -} diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 000000000..a8c0199a3 --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,28 @@ +import Utils from "./utils/util"; + +/** + * A class containing constants used throughout the EasyPost Node.js client library. + */ +export default class Constants { + static get CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS() { + return ["FedexAccount", "FedexSmartpostAccount", "UpsAccount"]; + } + static EXTERNAL_API_CALL_FAILED = + "Communication with %s failed, please try again later"; + static INVALID_API_KEY_TYPE = "Invalid API key type."; + static INVALID_PARAMETER = "Invalid parameter: %s."; + static INVALID_PAYMENT = + "The chosen payment method is not a credit card. Please try again."; + static INVALID_WEBHOOK_SIGNATURE = + "Webhook does not contain a valid HMAC signature."; + static MISSING_REQUIRED_PARAMETER = "Missing required parameter: %s."; + static NO_OBJECT_FOUND = "No %s found."; + static NO_PAYMENT_METHODS = + "No payment methods are set up. Please add a payment method and try again."; + static API_DID_NOT_RETURN_ERROR_DETAILS = "API did not return error details."; + static WEBHOOK_DOES_NOT_MATCH = + "Webhook received did not originate from EasyPost or had a webhook secret mismatch."; + static END_OF_PAGINATION = "There are no more pages to retrieve."; + static ERROR_DESERIALIZATION = "Error deserializing JSON response"; + static Utils = new Utils(); +} diff --git a/src/easypost.js b/src/easypost.js deleted file mode 100644 index e41be459c..000000000 --- a/src/easypost.js +++ /dev/null @@ -1,384 +0,0 @@ -import os from 'os'; -import superagent from 'superagent'; -import { v4 as uuid } from 'uuid'; - -import pkg from '../package.json'; -import Constants from './constants'; -import ErrorHandler from './errors/error_handler'; -import MissingParameterError from './errors/general/missing_parameter_error'; -import AddressService from './services/address_service'; -import ApiKeyService from './services/api_key_service'; -import BatchService from './services/batch_service'; -import BetaRateService from './services/beta_rate_service'; -import BetaReferralCustomerService from './services/beta_referral_customer_service'; -import BillingService from './services/billing_service'; -import CarrierAccountService from './services/carrier_account_service'; -import CarrierMetadataService from './services/carrier_metadata_service'; -import CarrierTypeService from './services/carrier_type_service'; -import CustomsInfoService from './services/customs_info_service'; -import CustomsItemService from './services/customs_item_service'; -import EndShipperService from './services/end_shipper_service'; -import EventService from './services/event_service'; -import InsuranceService from './services/insurance_service'; -import OrderService from './services/order_service'; -import ParcelService from './services/parcel_service'; -import PickupService from './services/pickup_service'; -import RateService from './services/rate_service'; -import ReferralCustomerService from './services/referral_customer_service'; -import RefundService from './services/refund_service'; -import ReportService from './services/report_service'; -import ScanFormService from './services/scan_form_service'; -import ShipmentService from './services/shipment_service'; -import TrackerService from './services/tracker_service'; -import UserService from './services/user_service'; -import WebhookService from './services/webhook_service'; -import Utils from './utils/util'; - -const util = require('util'); - -/** - * How many milliseconds in a second. - * @type {number} - */ -export const MS_SECOND = 1000; - -/** - * The default timeout for all EasyPost API requests. - * @type {number} - */ -export const DEFAULT_TIMEOUT = 60 * MS_SECOND; - -/** - * The default base URL for all production EasyPost API requests. - * @type {string} - */ -export const DEFAULT_BASE_URL = 'https://api.easypost.com/v2/'; - -/** - * The default headers used for all EasyPost API requests. - * @type {{'Accept': string, 'Content-Type': string, 'User-Agent': string}} - */ -export const DEFAULT_HEADERS = { - Accept: 'application/json', - 'Content-Type': 'application/json', - 'User-Agent': `EasyPost/v2 NodejsClient/${pkg.version} Nodejs/${ - process.versions.node - } OS/${os.platform()} OSVersion/${os.release()} OSArch/${os.arch()}`, -}; - -/** - * A map of HTTP methods to their corresponding string values (for use with superagent). - * @type {{DELETE: string, POST: string, GET: string, PUT: string, PATCH: string}} - */ -export const METHODS = { - GET: 'get', - POST: 'post', - PUT: 'put', - PATCH: 'patch', - DELETE: 'del', -}; - -/** - * The services available for the client (end-user-facing name corresponding to a `BaseService`-based class). - * @type {Map} - */ -export const SERVICES = { - Address: AddressService, - ApiKey: ApiKeyService, - Batch: BatchService, - BetaRate: BetaRateService, - BetaReferralCustomer: BetaReferralCustomerService, - Billing: BillingService, - CarrierAccount: CarrierAccountService, - CarrierMetadata: CarrierMetadataService, - CarrierType: CarrierTypeService, - CustomsInfo: CustomsInfoService, - CustomsItem: CustomsItemService, - EndShipper: EndShipperService, - Event: EventService, - Insurance: InsuranceService, - Order: OrderService, - Parcel: ParcelService, - Pickup: PickupService, - Rate: RateService, - ReferralCustomer: ReferralCustomerService, - Refund: RefundService, - Report: ReportService, - ScanForm: ScanFormService, - Shipment: ShipmentService, - Tracker: TrackerService, - User: UserService, - Webhook: WebhookService, -}; - -/** - * The client used to access services of the EasyPost API. - * This client is configured to use the latest production version of the EasyPost API. - * @param {string} key The API key to use for API requests made by this client. - * @param {Object} [options] Additional options to use for the underlying HTTP client (e.g. superagent, middleware, proxy configuration). - */ -export default class EasyPostClient { - constructor(key, options = {}) { - const { useProxy, timeout, baseUrl, superagentMiddleware, requestMiddleware } = options; - - if (!key && !useProxy) { - throw new MissingParameterError({ - message: util.format(Constants.MISSING_REQUIRED_PARAMETER, 'API Key'), - }); - } - - this.key = key; - this.timeout = timeout || DEFAULT_TIMEOUT; - this.baseUrl = baseUrl || DEFAULT_BASE_URL; - this.agent = superagent; - this.requestMiddleware = requestMiddleware; - this.requestHooks = []; - this.responseHooks = []; - this.Utils = new Utils(); - - if (superagentMiddleware) { - this.agent = superagentMiddleware(this.agent); - } - - this._attachServices(SERVICES); - } - - /** - * Add a request hook function. - * @param {(config: object) => void} hook - */ - addRequestHook(hook) { - this.requestHooks = [...this.requestHooks, hook]; - } - /** - * Remove a request hook function. - * @param {(config: object) => void} hook - */ - removeRequestHook(hook) { - this.requestHooks = this.requestHooks.filter((h) => h !== hook); - } - /** - * Clear all request hooks. - */ - clearRequestHooks() { - this.requestHooks = []; - } - - /** - * Add a response hook function. - * @param {(config: object) => void} hook - */ - addResponseHook(hook) { - this.responseHooks = [...this.responseHooks, hook]; - } - /** - * Remove a response hook function. - * @param {(config: object) => void} hook - */ - removeResponseHook(hook) { - this.responseHooks = this.responseHooks.filter((h) => h !== hook); - } - /** - * Clear all response hooks. - */ - clearResponseHooks() { - this.responseHooks = []; - } - - /** - * Create a copy of an {@link EasyPostClient} with overridden options. - * @param {EasyPostClient} client The `EasyPostClient` instance to clone. - * @param {Object} [options] The options to override. - * @returns {EasyPostClient} A new `EasyPostClient` instance. - */ - static copyClient(client, options = {}) { - const { apiKey, useProxy, timeout, baseUrl, superagentMiddleware, requestMiddleware } = options; - const agent = superagentMiddleware ? superagentMiddleware(client.agent) : client.agent; - - return new EasyPostClient(apiKey || client.key, { - useProxy: useProxy || client.useProxy, - timeout: timeout || client.timeout, - baseUrl: baseUrl || client.baseUrl, - agent, - requestMiddleware: requestMiddleware || client.requestMiddleware, - }); - } - - /** - * Build request headers to be sent with each EasyPost API request, combined (or overridden) by any additional headers - * @param {Object} [additionalHeaders] Additional headers to combine or override with the default headers. - * @returns {Object} The headers to use for the request. - */ - static _buildHeaders(additionalHeaders = {}) { - return { - ...DEFAULT_HEADERS, - ...additionalHeaders, - }; - } - - /** - * Attach services to an {@link EasyPostClient} instance. - * @param {Map} services - A map of {@link BaseService}-based service classes to construct and attach to the client. - */ - _attachServices(services) { - Object.keys(services).forEach((s) => { - this[s] = services[s](this); - }); - } - - /** - * If the path passed in is a full URI, use it; otherwise, prepend the base url from the api. - * @param {string} path - The path to build. - * @returns {string} The full path to use for the HTTP request. - */ - _buildPath(path = '') { - if (path.indexOf('http') === 0) { - return path; - } - - let completePath = this.baseUrl + path; - completePath = path.includes('beta') ? completePath.replace('v2', '') : completePath; - - return completePath; - } - - /** - * Create a value to be passed to the responseHooks, based on the requestHooks - * value and the response. - * @param {Object} baseHooksValue - the value being passed the requestHooks - * @param {Object} response - the response from the superagent request - * @returns {Object} - the value to be passed to the responseHooks - */ - _createResponseHooksValue(baseHooksValue, response) { - return { - ...baseHooksValue, - httpStatus: response.status, - responseBody: response.body, - headers: response.headers, - responseTimestamp: Date.now(), - }; - } - - /** - * Make an HTTP request. - * @param {string} [path] - The partial path to append to the base url for the request. - * @param {string} [method] - The HTTP method to use for the request, defaults to GET. - * @param {Object} [params] - The parameters to send with the request. - * @param {Object} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - * @throws {ApiError} If the request fails. - */ - async _request(path = '', method = METHODS.GET, params = {}, headers = {}) { - const urlPath = this._buildPath(path); - const requestHeaders = EasyPostClient._buildHeaders(headers); - let request = this.agent[method](urlPath).set(requestHeaders); - - if (this.requestMiddleware) { - request = this.requestMiddleware(request); - } - - if (this.key) { - request.auth(this.key); - } - - // it would be ideal if this "full url with params" could be gotten from superagent directly, - // but it doesn't seem to be possible - const url = new URL(urlPath); - - if (params !== undefined) { - if (method === METHODS.GET || method === METHODS.DELETE) { - request.query(params); - Object.entries(params).forEach(([key, value]) => { - url.searchParams.append(key, value); - }); - } else { - request.send(params); - } - } - - const baseHooksValue = { - method, - path: url.toString(), - requestBody: request._data, - headers: requestHeaders, - requestTimestamp: Date.now(), - requestUUID: uuid(), - }; - - this.requestHooks.forEach((fn) => fn(baseHooksValue)); - - try { - const response = await request; - - if (this.responseHooks.length > 0) { - const responseHooksValue = this._createResponseHooksValue(baseHooksValue, response); - this.responseHooks.forEach((fn) => fn(responseHooksValue)); - } - - return response; - } catch (error) { - if (error.response && error.response.body) { - const responseHooksValue = this._createResponseHooksValue(baseHooksValue, error.response); - this.responseHooks.forEach((fn) => fn(responseHooksValue)); - throw ErrorHandler.handleApiError(error.response); - } else { - throw error; - } - } - } - - /** - * Make a GET HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {Object} [params] - The parameters to send with the request. - * @param {Object} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - _get(path, params = {}, headers = {}) { - return this._request(path, METHODS.GET, params, headers); - } - - /** - * Make a POST HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {Object} [params] - The parameters to send with the request. - * @param {Object} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - _post(path, params = {}, headers = {}) { - return this._request(path, METHODS.POST, params, headers); - } - - /** - * Make a PUT HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {Object} [params] - The parameters to send with the request. - * @param {Object} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - _put(path, params = {}, headers = {}) { - return this._request(path, METHODS.PUT, params, headers); - } - - /** - * Make a PATCH HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {Object} [params] - The parameters to send with the request. - * @param {Object} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - _patch(path, params = {}, headers = {}) { - return this._request(path, METHODS.PATCH, params, headers); - } - - /** - * Make a DELETE HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {Object} [params] - The parameters to send with the request. - * @param {Object} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - _delete(path, params = {}, headers = {}) { - return this._request(path, METHODS.DELETE, params, headers); - } -} diff --git a/src/easypost.ts b/src/easypost.ts new file mode 100644 index 000000000..a340dac00 --- /dev/null +++ b/src/easypost.ts @@ -0,0 +1,482 @@ +import os from "os"; +import superagent, { SuperAgentStatic, Request, Response } from "superagent"; +import { v4 as uuid } from "uuid"; + +import pkg from "../package.json"; +import Constants from "./constants"; +import ErrorHandler from "./errors/error_handler"; +import MissingParameterError from "./errors/general/missing_parameter_error"; +import AddressService from "./services/address_service"; +import ApiKeyService from "./services/api_key_service"; +import BatchService from "./services/batch_service"; +import BetaRateService from "./services/beta_rate_service"; +import BetaReferralCustomerService from "./services/beta_referral_customer_service"; +import BillingService from "./services/billing_service"; +import CarrierAccountService from "./services/carrier_account_service"; +import CarrierMetadataService from "./services/carrier_metadata_service"; +import CarrierTypeService from "./services/carrier_type_service"; +import CustomsInfoService from "./services/customs_info_service"; +import CustomsItemService from "./services/customs_item_service"; +import EndShipperService from "./services/end_shipper_service"; +import EventService from "./services/event_service"; +import InsuranceService from "./services/insurance_service"; +import OrderService from "./services/order_service"; +import ParcelService from "./services/parcel_service"; +import PickupService from "./services/pickup_service"; +import RateService from "./services/rate_service"; +import ReferralCustomerService from "./services/referral_customer_service"; +import RefundService from "./services/refund_service"; +import ReportService from "./services/report_service"; +import ScanFormService from "./services/scan_form_service"; +import ShipmentService from "./services/shipment_service"; +import TrackerService from "./services/tracker_service"; +import UserService from "./services/user_service"; +import WebhookService from "./services/webhook_service"; +import Utils from "./utils/util"; + +import util from "node:util"; + +export * from "./errors"; +export * from "./services"; +export * from "./utils/errors"; +export * from "./constants"; + +/** How many milliseconds in a second. */ +export const MS_SECOND = 1000; + +/** The default timeout for all EasyPost API requests. */ +export const DEFAULT_TIMEOUT = 60 * MS_SECOND; + +/** The default base URL for all production EasyPost API requests. */ +export const DEFAULT_BASE_URL = "https://api.easypost.com/v2/"; + +/** The default headers used for all EasyPost API requests. */ +export const DEFAULT_HEADERS = { + Accept: "application/json", + "Content-Type": "application/json", + "User-Agent": `EasyPost/v2 NodejsClient/${pkg.version} Nodejs/${ + process.versions.node + } OS/${os.platform()} OSVersion/${os.release()} OSArch/${os.arch()}`, +}; + +/** A map of HTTP methods to their corresponding string values (for use with superagent). */ +export const METHODS = { + GET: "get", + POST: "post", + PUT: "put", + PATCH: "patch", + DELETE: "del", +} as const; + +export type EasyPostClientOptions = { + useProxy?: boolean; + timeout?: number; + baseUrl?: string; + superagentMiddleware?: ( + agent: SuperAgentStatic + ) => SuperAgentStatic; + requestMiddleware?: (request: Request) => Request; + + agent?: SuperAgentStatic; +}; + +export type RequestHookData = { + method: (typeof METHODS)[keyof typeof METHODS]; + path: string; + requestBody: any; + headers: Record; + requestTimestamp: number; + requestUUID: string; +}; +export type RequestHook = (data: RequestHookData) => void; +export type ResponseHookData = RequestHookData & { + requestHeaders: Record; + httpStatus: Response["status"]; + responseBody: Response["body"]; + headers: Response["headers"]; + responseTimestamp: number; +}; +export type ResponseHook = (data: ResponseHookData) => void; + +/** + * The client used to access services of the EasyPost API. + * This client is configured to use the latest production version of the EasyPost API. + * @param {string} key The API key to use for API requests made by this client. + * @param {EasyPostClientOptions} [options] Additional options to use for the underlying HTTP client (e.g. superagent, middleware, proxy configuration). + */ +export default class EasyPostClient { + useProxy: boolean; + key: string; + timeout: number; + baseUrl: string; + agent: SuperAgentStatic; + requestMiddleware: ((request: Request) => Request) | undefined; + requestHooks: RequestHook[]; + responseHooks: ResponseHook[]; + Utils: Utils; + + Address: ReturnType; + ApiKey: ReturnType; + Batch: ReturnType; + BetaRate: ReturnType; + BetaReferralCustomer: ReturnType; + Billing: ReturnType; + CarrierAccount: ReturnType; + CarrierMetadata: ReturnType; + CarrierType: ReturnType; + CustomsInfo: ReturnType; + CustomsItem: ReturnType; + EndShipper: ReturnType; + Event: ReturnType; + Insurance: ReturnType; + Order: ReturnType; + Parcel: ReturnType; + Pickup: ReturnType; + Rate: ReturnType; + ReferralCustomer: ReturnType; + Refund: ReturnType; + Report: ReturnType; + ScanForm: ReturnType; + Shipment: ReturnType; + Tracker: ReturnType; + User: ReturnType; + Webhook: ReturnType; + + constructor(key: string, options: EasyPostClientOptions = {}) { + const { + useProxy, + timeout, + baseUrl, + superagentMiddleware, + requestMiddleware, + agent, + } = options; + + if (!key && !useProxy) { + throw new MissingParameterError({ + message: util.format(Constants.MISSING_REQUIRED_PARAMETER, "API Key"), + }); + } + + this.key = key; + this.useProxy = useProxy || false; + this.timeout = timeout || DEFAULT_TIMEOUT; + this.baseUrl = baseUrl || DEFAULT_BASE_URL; + this.agent = agent || superagent; + this.requestMiddleware = requestMiddleware; + this.requestHooks = []; + this.responseHooks = []; + this.Utils = new Utils(); + + if (superagentMiddleware) { + this.agent = superagentMiddleware(this.agent); + } + + this.Address = AddressService(this); + this.ApiKey = ApiKeyService(this); + this.Batch = BatchService(this); + this.BetaRate = BetaRateService(this); + this.BetaReferralCustomer = BetaReferralCustomerService(this); + this.Billing = BillingService(this); + this.CarrierAccount = CarrierAccountService(this); + this.CarrierMetadata = CarrierMetadataService(this); + this.CarrierType = CarrierTypeService(this); + this.CustomsInfo = CustomsInfoService(this); + this.CustomsItem = CustomsItemService(this); + this.EndShipper = EndShipperService(this); + this.Event = EventService(this); + this.Insurance = InsuranceService(this); + this.Order = OrderService(this); + this.Parcel = ParcelService(this); + this.Pickup = PickupService(this); + this.Rate = RateService(this); + this.ReferralCustomer = ReferralCustomerService(this); + this.Refund = RefundService(this); + this.Report = ReportService(this); + this.ScanForm = ScanFormService(this); + this.Shipment = ShipmentService(this); + this.Tracker = TrackerService(this); + this.User = UserService(this); + this.Webhook = WebhookService(this); + } + + /** + * Add a request hook function. + * @param {(config: object) => void} hook + */ + addRequestHook(hook: RequestHook) { + this.requestHooks = [...this.requestHooks, hook]; + } + /** + * Remove a request hook function. + * @param {(config: object) => void} hook + */ + removeRequestHook(hook: RequestHook) { + this.requestHooks = this.requestHooks.filter((h) => h !== hook); + } + /** + * Clear all request hooks. + */ + clearRequestHooks() { + this.requestHooks = []; + } + + /** + * Add a response hook function. + * @param {(config: object) => void} hook + */ + addResponseHook(hook: ResponseHook) { + this.responseHooks = [...this.responseHooks, hook]; + } + /** + * Remove a response hook function. + * @param {(config: object) => void} hook + */ + removeResponseHook(hook: ResponseHook) { + this.responseHooks = this.responseHooks.filter((h) => h !== hook); + } + /** + * Clear all response hooks. + */ + clearResponseHooks() { + this.responseHooks = []; + } + + /** + * Create a copy of an {@link EasyPostClient} with overridden options. + * @param {EasyPostClient} client The `EasyPostClient` instance to clone. + * @param {Object} [options] The options to override. + * @returns {EasyPostClient} A new `EasyPostClient` instance. + */ + static copyClient( + client: EasyPostClient, + options: EasyPostClientOptions & { apiKey?: string } = {} + ) { + const { + apiKey, + useProxy, + timeout, + baseUrl, + superagentMiddleware, + requestMiddleware, + } = options; + const agent = superagentMiddleware + ? superagentMiddleware(client.agent) + : client.agent; + + return new EasyPostClient(apiKey || client.key, { + useProxy: useProxy || client.useProxy, + timeout: timeout || client.timeout, + baseUrl: baseUrl || client.baseUrl, + agent, + requestMiddleware: requestMiddleware || client.requestMiddleware, + }); + } + + /** + * Build request headers to be sent with each EasyPost API request, combined (or overridden) by any additional headers + * @param {Object} [additionalHeaders] Additional headers to combine or override with the default headers. + * @returns {Object} The headers to use for the request. + */ + static _buildHeaders(additionalHeaders = {}) { + return { + ...DEFAULT_HEADERS, + ...additionalHeaders, + }; + } + + /** + * If the path passed in is a full URI, use it; otherwise, prepend the base url from the api. + * @param {string} path - The path to build. + * @returns {string} The full path to use for the HTTP request. + */ + _buildPath(path: string = ""): string { + if (path.indexOf("http") === 0) { + return path; + } + + let completePath = this.baseUrl + path; + completePath = path.includes("beta") + ? completePath.replace("v2", "") + : completePath; + + return completePath; + } + + /** + * Create a value to be passed to the responseHooks, based on the requestHooks + * value and the response. + * @param {Object} baseHooksValue - the value being passed the requestHooks + * @param {Object} response - the response from the superagent request + * @returns {Object} - the value to be passed to the responseHooks + */ + _createResponseHooksValue( + baseHooksValue: RequestHookData, + response: Response + ): ResponseHookData { + return { + ...baseHooksValue, + requestHeaders: baseHooksValue.headers, + httpStatus: response.status, + responseBody: response.body, + headers: response.headers, + responseTimestamp: Date.now(), + }; + } + + /** + * Make an HTTP request. + * @param [path] - The partial path to append to the base url for the request. + * @param [method] - The HTTP method to use for the request, defaults to GET. + * @param [params] - The parameters to send with the request. + * @param [headers] - Additional headers to send with the request. + * @returns The response from the HTTP request. + * @throws {ApiError} If the request fails. + */ + async _request( + path = "", + method: (typeof METHODS)[keyof typeof METHODS] = METHODS.GET, + params: Record = {}, + headers: Record = {} + ) { + const urlPath = this._buildPath(path); + const requestHeaders = EasyPostClient._buildHeaders(headers); + let request = this.agent[method](urlPath).set(requestHeaders); + + if (this.requestMiddleware) { + request = this.requestMiddleware(request); + } + + if (this.key) { + request.auth(this.key, "", { type: "basic" }); + } + + // it would be ideal if this "full url with params" could be gotten from superagent directly, + // but it doesn't seem to be possible + const url = new URL(urlPath); + + if (params !== undefined) { + if (method === METHODS.GET || method === METHODS.DELETE) { + request.query(params); + Object.entries(params).forEach(([key, value]) => { + url.searchParams.append(key, `${value}`); + }); + } else { + request.send(params); + } + } + + const baseHooksValue: RequestHookData = { + method, + path: url.toString(), + // a hack to get the body of the request in the hooks + requestBody: (request as any)._data, + headers: requestHeaders, + requestTimestamp: Date.now(), + requestUUID: uuid(), + }; + + this.requestHooks.forEach((fn) => fn(baseHooksValue)); + + try { + const response = await request; + + if (this.responseHooks.length > 0) { + const responseHooksValue = this._createResponseHooksValue( + baseHooksValue, + response + ); + this.responseHooks.forEach((fn) => fn(responseHooksValue)); + } + + return response; + } catch (error) { + if (!error || typeof error !== "object") { + throw error; + } + + if ( + "response" in error && + error.response && + typeof error.response === "object" && + "body" in error.response && + error.response.body + ) { + const responseHooksValue = this._createResponseHooksValue( + baseHooksValue, + error.response as any + ); + this.responseHooks.forEach((fn) => fn(responseHooksValue)); + + if (ErrorHandler.isAPIError(error.response)) { + throw ErrorHandler.handleApiError(error.response); + } + } + + throw error; + } + } + + /** + * Make a GET HTTP request. + * @param path - The partial path to append to the base url for the request. + * @param [params] - The parameters to send with the request. + * @param [headers] - Additional headers to send with the request. + * @returns The response from the HTTP request. + */ + _get( + path: string, + params: Record = {}, + headers: Record = {} + ) { + return this._request(path, METHODS.GET, params, headers); + } + + /** + * Make a POST HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + _post(path: string, params: any = {}, headers: Record = {}) { + return this._request(path, METHODS.POST, params, headers); + } + + /** + * Make a PUT HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + _put(path: string, params: any = {}, headers: Record = {}) { + return this._request(path, METHODS.PUT, params, headers); + } + + /** + * Make a PATCH HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + _patch(path: string, params: any = {}, headers: Record = {}) { + return this._request(path, METHODS.PATCH, params, headers); + } + + /** + * Make a DELETE HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + _delete( + path: string, + params: any = {}, + headers: Record = {} + ) { + return this._request(path, METHODS.DELETE, params, headers); + } +} diff --git a/src/errors/api/api_error.js b/src/errors/api/api_error.ts similarity index 68% rename from src/errors/api/api_error.js rename to src/errors/api/api_error.ts index 3c28ae696..8988198ac 100644 --- a/src/errors/api/api_error.js +++ b/src/errors/api/api_error.ts @@ -1,4 +1,4 @@ -import EasyPostError from '../easypost_error'; +import EasyPostError from "../easypost_error"; /** * The ApiError class is used to represent errors that occurred while communicating with the EasyPost API. @@ -12,7 +12,22 @@ import EasyPostError from '../easypost_error'; * @property {EasyPostError[]} [errors] - An array of sub-errors returned by the EasyPost API. */ export default class ApiError extends EasyPostError { - constructor({ message, code, statusCode, errors } = {}) { + code: string | undefined; + errors: EasyPostError[] | undefined; + message: string | undefined; + statusCode: number | undefined; + + constructor({ + message, + code, + statusCode, + errors, + }: { + message?: string; + code?: string; + statusCode?: number; + errors?: EasyPostError[]; + } = {}) { super({ message }); this.code = code; this.errors = errors; diff --git a/src/errors/api/bad_request_error.js b/src/errors/api/bad_request_error.ts similarity index 93% rename from src/errors/api/bad_request_error.js rename to src/errors/api/bad_request_error.ts index 4a3b61355..2598a71cb 100644 --- a/src/errors/api/bad_request_error.js +++ b/src/errors/api/bad_request_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The BadRequestError class is used to represent a 400 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/external_api_error.js b/src/errors/api/external_api_error.ts similarity index 91% rename from src/errors/api/external_api_error.js rename to src/errors/api/external_api_error.ts index 5e1d03656..c41513994 100644 --- a/src/errors/api/external_api_error.js +++ b/src/errors/api/external_api_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The ExternalApiError class is used to represent errors that occurred while communicating with an external API. diff --git a/src/errors/api/forbidden_error.js b/src/errors/api/forbidden_error.ts similarity index 93% rename from src/errors/api/forbidden_error.js rename to src/errors/api/forbidden_error.ts index dd6e3e9cb..92dc519c4 100644 --- a/src/errors/api/forbidden_error.js +++ b/src/errors/api/forbidden_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The ForbiddenError class is used to represent a 403 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/gateway_timeout_error.js b/src/errors/api/gateway_timeout_error.ts similarity index 94% rename from src/errors/api/gateway_timeout_error.js rename to src/errors/api/gateway_timeout_error.ts index 6932a94c5..c64ce762e 100644 --- a/src/errors/api/gateway_timeout_error.js +++ b/src/errors/api/gateway_timeout_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The GatewayTimeoutError class is used to represent a 504 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/http_error.js b/src/errors/api/http_error.ts similarity index 93% rename from src/errors/api/http_error.js rename to src/errors/api/http_error.ts index e9fa5d59f..1a0bde9aa 100644 --- a/src/errors/api/http_error.js +++ b/src/errors/api/http_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The HttpError class is used to represent a generic HTTP-related error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/index.ts b/src/errors/api/index.ts new file mode 100644 index 000000000..2c5f2f741 --- /dev/null +++ b/src/errors/api/index.ts @@ -0,0 +1,18 @@ +export * from "./api_error"; +export * from "./bad_request_error"; +export * from "./external_api_error"; +export * from "./forbidden_error"; +export * from "./gateway_timeout_error"; +export * from "./http_error"; +export * from "./index"; +export * from "./internal_server_error"; +export * from "./invalid_request_error"; +export * from "./method_not_allowed_error"; +export * from "./not_found_error"; +export * from "./payment_error"; +export * from "./rate_limit_error"; +export * from "./redirect_error"; +export * from "./service_unavailable_error"; +export * from "./timeout_error"; +export * from "./unauthorized_error"; +export * from "./unknown_api_error"; diff --git a/src/errors/api/internal_server_error.js b/src/errors/api/internal_server_error.ts similarity index 94% rename from src/errors/api/internal_server_error.js rename to src/errors/api/internal_server_error.ts index 2fd678117..1fc945241 100644 --- a/src/errors/api/internal_server_error.js +++ b/src/errors/api/internal_server_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The InternalServerError class is used to represent a 500 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/invalid_request_error.js b/src/errors/api/invalid_request_error.ts similarity index 94% rename from src/errors/api/invalid_request_error.js rename to src/errors/api/invalid_request_error.ts index 91c92f0be..a93ca5e50 100644 --- a/src/errors/api/invalid_request_error.js +++ b/src/errors/api/invalid_request_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The InvalidRequestError class is used to represent a 422 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/method_not_allowed_error.js b/src/errors/api/method_not_allowed_error.ts similarity index 94% rename from src/errors/api/method_not_allowed_error.js rename to src/errors/api/method_not_allowed_error.ts index 2b886f62a..417b2ae16 100644 --- a/src/errors/api/method_not_allowed_error.js +++ b/src/errors/api/method_not_allowed_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The MethodNotAllowedError class is used to represent a 405 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/not_found_error.js b/src/errors/api/not_found_error.ts similarity index 93% rename from src/errors/api/not_found_error.js rename to src/errors/api/not_found_error.ts index 0af4c2fdf..3e515f598 100644 --- a/src/errors/api/not_found_error.js +++ b/src/errors/api/not_found_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The NotFoundError class is used to represent a 404 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/payment_error.js b/src/errors/api/payment_error.ts similarity index 93% rename from src/errors/api/payment_error.js rename to src/errors/api/payment_error.ts index 92a40c77c..d76ad8b0f 100644 --- a/src/errors/api/payment_error.js +++ b/src/errors/api/payment_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The PaymentError class is used to represent a 402 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/rate_limit_error.js b/src/errors/api/rate_limit_error.ts similarity index 93% rename from src/errors/api/rate_limit_error.js rename to src/errors/api/rate_limit_error.ts index 3fe9bd6d3..b0253f634 100644 --- a/src/errors/api/rate_limit_error.js +++ b/src/errors/api/rate_limit_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The RateLimitError class is used to represent a 429 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/redirect_error.js b/src/errors/api/redirect_error.ts similarity index 93% rename from src/errors/api/redirect_error.js rename to src/errors/api/redirect_error.ts index 9bab9b9d3..96c650507 100644 --- a/src/errors/api/redirect_error.js +++ b/src/errors/api/redirect_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The RedirectError class is used to represent a 3xx error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/service_unavailable_error.js b/src/errors/api/service_unavailable_error.ts similarity index 94% rename from src/errors/api/service_unavailable_error.js rename to src/errors/api/service_unavailable_error.ts index 56c0c1412..2acbce1e3 100644 --- a/src/errors/api/service_unavailable_error.js +++ b/src/errors/api/service_unavailable_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The ServiceUnavailableError class is used to represent a 503 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/timeout_error.js b/src/errors/api/timeout_error.ts similarity index 93% rename from src/errors/api/timeout_error.js rename to src/errors/api/timeout_error.ts index 5bed1efbf..7ae1e47b9 100644 --- a/src/errors/api/timeout_error.js +++ b/src/errors/api/timeout_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The TimeoutError class is used to represent a 408 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/unauthorized_error.js b/src/errors/api/unauthorized_error.ts similarity index 93% rename from src/errors/api/unauthorized_error.js rename to src/errors/api/unauthorized_error.ts index 24ac74f21..2c6664412 100644 --- a/src/errors/api/unauthorized_error.js +++ b/src/errors/api/unauthorized_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The UnauthorizedError class is used to represent a 401 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/unknown_api_error.js b/src/errors/api/unknown_api_error.ts similarity index 94% rename from src/errors/api/unknown_api_error.js rename to src/errors/api/unknown_api_error.ts index d551069d6..82ef025da 100644 --- a/src/errors/api/unknown_api_error.js +++ b/src/errors/api/unknown_api_error.ts @@ -1,4 +1,4 @@ -import ApiError from './api_error'; +import ApiError from "./api_error"; /** * The UnknownApiError class is used to represent a generic, unexpected error that occurred while communicating with the EasyPost API. diff --git a/src/errors/easypost_error.js b/src/errors/easypost_error.ts similarity index 67% rename from src/errors/easypost_error.js rename to src/errors/easypost_error.ts index 8dff8c9b7..329f6d565 100644 --- a/src/errors/easypost_error.js +++ b/src/errors/easypost_error.ts @@ -7,7 +7,9 @@ * @param {string} [message] - The message to be displayed when the error is logged. */ export default class EasyPostError extends Error { - constructor({ message } = {}) { + // @ts-expect-error message is not required for our errors, but is a default error property + message: string | undefined; + constructor({ message }: { message?: string } = {}) { super(message); } } diff --git a/src/errors/error_handler.js b/src/errors/error_handler.js deleted file mode 100644 index 4ecf9c24d..000000000 --- a/src/errors/error_handler.js +++ /dev/null @@ -1,99 +0,0 @@ -import Constants from '../constants'; -import BadRequestError from './api/bad_request_error'; -import ForbiddenError from './api/forbidden_error'; -import GatewayTimeoutError from './api/gateway_timeout_error'; -import InternalServerError from './api/internal_server_error'; -import InvalidRequestError from './api/invalid_request_error'; -import MethodNotAllowedError from './api/method_not_allowed_error'; -import NotFoundError from './api/not_found_error'; -import PaymentError from './api/payment_error'; -import RateLimitError from './api/rate_limit_error'; -import RedirectError from './api/redirect_error'; -import ServiceUnavailableError from './api/service_unavailable_error'; -import TimeoutError from './api/timeout_error'; -import UnauthorizedError from './api/unauthorized_error'; -import UnknownApiError from './api/unknown_api_error'; -import EasyPostError from './easypost_error'; - -export default class ErrorHandler { - /** - * Recursively traverses a JSON object or array and extracts error messages - * as strings. Adds the extracted messages to the specified messagesList array. - * - * @param {object|array|string} errorMessage - The JSON object or array to traverse. - * @param {array} messagesList - The array to which extracted error messages will be added. - */ - static traverseJsonElement(errorMessage, messagesList) { - if (errorMessage instanceof Object) { - for (const value of Object.values(errorMessage)) { - this.traverseJsonElement(value, messagesList); - } - } else if (errorMessage instanceof Array) { - for (const value of errorMessage) { - this.traverseJsonElement(value, messagesList); - } - } else { - messagesList.push(errorMessage.toString()); - } - } - /** - * Calculate and generate the appropriate {@link ApiError} based on a received HTTP response error. - * @param {*} error - The errored HTTP response. - * @returns {ApiError} The `ApiError`-based error corresponding to the HTTP status code. - */ - static handleApiError(error) { - const { statusCode } = error; - const { code, message, errors } = error.body.error; - const errorParams = { - message, - code, - statusCode, - errors, - }; - - try { - const messages = []; - this.traverseJsonElement(errorParams.message, messages); - errorParams.message = messages.join(', '); - } catch (e) { - const errorParams = { - message: Constants.ERROR_DESERIALIZATION, - code: 'ERROR_DESERIALIZATION_ERROR', - }; - return new EasyPostError(errorParams); - } - - if (statusCode >= 300 && statusCode < 400) { - return new RedirectError(errorParams); - } - - switch (statusCode) { - case 400: - return new BadRequestError(errorParams); - case 401: - return new UnauthorizedError(errorParams); - case 402: - return new PaymentError(errorParams); - case 403: - return new ForbiddenError(errorParams); - case 404: - return new NotFoundError(errorParams); - case 405: - return new MethodNotAllowedError(errorParams); - case 408: - return new TimeoutError(errorParams); - case 422: - return new InvalidRequestError(errorParams); - case 429: - return new RateLimitError(errorParams); - case 500: - return new InternalServerError(errorParams); - case 503: - return new ServiceUnavailableError(errorParams); - case 504: - return new GatewayTimeoutError(errorParams); - default: - return new UnknownApiError(errorParams); - } - } -} diff --git a/src/errors/error_handler.ts b/src/errors/error_handler.ts new file mode 100644 index 000000000..301afe805 --- /dev/null +++ b/src/errors/error_handler.ts @@ -0,0 +1,132 @@ +import Constants from "../constants"; +import ApiError from "./api/api_error"; +import BadRequestError from "./api/bad_request_error"; +import ForbiddenError from "./api/forbidden_error"; +import GatewayTimeoutError from "./api/gateway_timeout_error"; +import InternalServerError from "./api/internal_server_error"; +import InvalidRequestError from "./api/invalid_request_error"; +import MethodNotAllowedError from "./api/method_not_allowed_error"; +import NotFoundError from "./api/not_found_error"; +import PaymentError from "./api/payment_error"; +import RateLimitError from "./api/rate_limit_error"; +import RedirectError from "./api/redirect_error"; +import ServiceUnavailableError from "./api/service_unavailable_error"; +import TimeoutError from "./api/timeout_error"; +import UnauthorizedError from "./api/unauthorized_error"; +import UnknownApiError from "./api/unknown_api_error"; +import EasyPostError from "./easypost_error"; + +export type RawAPIError = { + statusCode: number; + body: { + error: { + code: string; + message: JSONParsableError; + errors: EasyPostError[]; + }; + }; +}; + +type JSONParsableError = string | number | JSONObject | JSONArray; +type JSONObject = { + [key: string]: JSONParsableError; +}; +type JSONArray = JSONParsableError[]; + +export default class ErrorHandler { + /** + * Recursively traverses a JSON object or array and extracts error messages + * as strings. Adds the extracted messages to the specified messagesList array. + * + * @param {JSONParsableError} errorMessage - The JSON object or array to traverse. + */ + static traverseJsonElement(errorMessage: JSONParsableError): string[] { + let messages: string[] = []; + + if (errorMessage instanceof Array) { + for (const value of errorMessage) { + messages = messages.concat(this.traverseJsonElement(value)); + } + } else if (errorMessage instanceof Object) { + for (const value of Object.values(errorMessage)) { + messages = messages.concat(this.traverseJsonElement(value)); + } + } else { + messages.push(errorMessage.toString()); + } + + return messages; + } + + static isAPIError(error: any): error is RawAPIError { + return ( + error && + typeof error.statusCode === "number" && + typeof error.body === "object" && + typeof error.body.error === "object" && + typeof error.body.error.code === "string" && + error.body.error.message && + error.body.error.errors + ); + } + + /** + * Calculate and generate the appropriate {@link ApiError} based on a received HTTP response error. + * @param {*} error - The errored HTTP response. + * @returns {ApiError} The `ApiError`-based error corresponding to the HTTP status code. + */ + static handleApiError(error: RawAPIError): EasyPostError { + const { statusCode } = error; + const { code, message, errors } = error.body.error; + const errorParams = { + message: "", + code, + statusCode, + errors, + }; + + try { + const messages = this.traverseJsonElement(message); + errorParams.message = messages.join(", "); + } catch (e) { + const errorParams = { + message: Constants.ERROR_DESERIALIZATION, + code: "ERROR_DESERIALIZATION_ERROR", + }; + return new EasyPostError(errorParams); + } + + if (statusCode >= 300 && statusCode < 400) { + return new RedirectError(errorParams); + } + + switch (statusCode) { + case 400: + return new BadRequestError(errorParams); + case 401: + return new UnauthorizedError(errorParams); + case 402: + return new PaymentError(errorParams); + case 403: + return new ForbiddenError(errorParams); + case 404: + return new NotFoundError(errorParams); + case 405: + return new MethodNotAllowedError(errorParams); + case 408: + return new TimeoutError(errorParams); + case 422: + return new InvalidRequestError(errorParams); + case 429: + return new RateLimitError(errorParams); + case 500: + return new InternalServerError(errorParams); + case 503: + return new ServiceUnavailableError(errorParams); + case 504: + return new GatewayTimeoutError(errorParams); + default: + return new UnknownApiError(errorParams); + } + } +} diff --git a/src/errors/general/end_of_pagination_error.js b/src/errors/general/end_of_pagination_error.ts similarity index 80% rename from src/errors/general/end_of_pagination_error.js rename to src/errors/general/end_of_pagination_error.ts index b2be10785..4cd5241d4 100644 --- a/src/errors/general/end_of_pagination_error.js +++ b/src/errors/general/end_of_pagination_error.ts @@ -1,5 +1,5 @@ -import Constants from '../../constants'; -import EasyPostError from '../easypost_error'; +import Constants from "../../constants"; +import EasyPostError from "../easypost_error"; /** * The EndOfPaginationError class is used to represent an error that no more page can be retrieved diff --git a/src/errors/general/filtering_error.js b/src/errors/general/filtering_error.ts similarity index 86% rename from src/errors/general/filtering_error.js rename to src/errors/general/filtering_error.ts index 7b0be3426..b85795a6b 100644 --- a/src/errors/general/filtering_error.js +++ b/src/errors/general/filtering_error.ts @@ -1,4 +1,4 @@ -import EasyPostError from '../easypost_error'; +import EasyPostError from "../easypost_error"; /** * The FilteringError class is used to represent an error that occurred while filtering a list (e.g. a list of rates). diff --git a/src/errors/general/index.ts b/src/errors/general/index.ts new file mode 100644 index 000000000..43927ff68 --- /dev/null +++ b/src/errors/general/index.ts @@ -0,0 +1,6 @@ +export * from "./end_of_pagination_error"; +export * from "./filtering_error"; +export * from "./invalid_object_error"; +export * from "./invalid_parameter_error"; +export * from "./missing_parameter_error"; +export * from "./signature_verification_error"; diff --git a/src/errors/general/invalid_object_error.js b/src/errors/general/invalid_object_error.ts similarity index 87% rename from src/errors/general/invalid_object_error.js rename to src/errors/general/invalid_object_error.ts index 14d3bc387..b9cf35423 100644 --- a/src/errors/general/invalid_object_error.js +++ b/src/errors/general/invalid_object_error.ts @@ -1,4 +1,4 @@ -import EasyPostError from '../easypost_error'; +import EasyPostError from "../easypost_error"; /** * The InvalidObjectError class is used to represent an error due to an invalid object (e.g. missing an expected property). diff --git a/src/errors/general/invalid_parameter_error.js b/src/errors/general/invalid_parameter_error.ts similarity index 86% rename from src/errors/general/invalid_parameter_error.js rename to src/errors/general/invalid_parameter_error.ts index b55a4b14c..38eee3050 100644 --- a/src/errors/general/invalid_parameter_error.js +++ b/src/errors/general/invalid_parameter_error.ts @@ -1,4 +1,4 @@ -import EasyPostError from '../easypost_error'; +import EasyPostError from "../easypost_error"; /** * The InvalidParameterError class is used to represent an error due to an invalid function parameter. diff --git a/src/errors/general/missing_parameter_error.js b/src/errors/general/missing_parameter_error.ts similarity index 86% rename from src/errors/general/missing_parameter_error.js rename to src/errors/general/missing_parameter_error.ts index 586b28065..a0a98e38e 100644 --- a/src/errors/general/missing_parameter_error.js +++ b/src/errors/general/missing_parameter_error.ts @@ -1,4 +1,4 @@ -import EasyPostError from '../easypost_error'; +import EasyPostError from "../easypost_error"; /** * The MissingParameterError class is used to represent an error due to a missing expected function parameter. diff --git a/src/errors/general/signature_verification_error.js b/src/errors/general/signature_verification_error.ts similarity index 88% rename from src/errors/general/signature_verification_error.js rename to src/errors/general/signature_verification_error.ts index c3029e331..9e03fa0c5 100644 --- a/src/errors/general/signature_verification_error.js +++ b/src/errors/general/signature_verification_error.ts @@ -1,4 +1,4 @@ -import EasyPostError from '../easypost_error'; +import EasyPostError from "../easypost_error"; /** * The SignatureVerificationError class is used to represent an error due to a failed signature verification (e.g. a webhook HMAC signature). diff --git a/src/errors/index.ts b/src/errors/index.ts new file mode 100644 index 000000000..170d5bd99 --- /dev/null +++ b/src/errors/index.ts @@ -0,0 +1,4 @@ +export * from "./api"; +export * from "./general"; +export * from "./easypost_error"; +export * from "./error_handler"; diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 000000000..fa2a470df --- /dev/null +++ b/src/index.ts @@ -0,0 +1,3 @@ +import EasyPost from "./easypost"; + +export default EasyPost; diff --git a/src/models/address.js b/src/models/address.js deleted file mode 100644 index 4442336bf..000000000 --- a/src/models/address.js +++ /dev/null @@ -1,24 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * An {@link https://www.easypost.com/docs/api/node#addresses Address} represents people, places, and organizations in a number of contexts. - * @public - * @extends EasyPostObject - */ -export default class Address extends EasyPostObject { - static street1; - static street2; - static city; - static state; - static zip; - static country; - static residential; - static carrier_facility; - static name; - static company; - static phone; - static email; - static federal_tax_id; - static state_tax_id; - static verifications; -} diff --git a/src/models/api_key.js b/src/models/api_key.js deleted file mode 100644 index a1133b82c..000000000 --- a/src/models/api_key.js +++ /dev/null @@ -1,11 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * An {@link https://www.easypost.com/docs/api/node#api-keys ApiKey} represents an authentication token that can be used to make requests to the EasyPost API. - * @public - * @extends EasyPostObject - */ -export default class ApiKey extends EasyPostObject { - static active; - static key; -} diff --git a/src/models/batch.js b/src/models/batch.js deleted file mode 100644 index b6d1d7bb9..000000000 --- a/src/models/batch.js +++ /dev/null @@ -1,17 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#batches Batch} represents a collection of {@link Shipment shipments} that can be processed together. - * @public - * @extends EasyPostObject - */ -export default class Batch extends EasyPostObject { - static label_url; - static num_shipments; - static pickup; - static reference; - static scan_form; - static shipments; - static state; - static status; -} diff --git a/src/models/brand.js b/src/models/brand.js deleted file mode 100644 index 1c4a57f30..000000000 --- a/src/models/brand.js +++ /dev/null @@ -1,18 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#brand Brand} represents custom branding for an EasyPost user's public-facing tracking details page. - * @public - * @extends EasyPostObject - */ -export default class Brand extends EasyPostObject { - static ad_href; - static ad; - static background_color; - static color; - static logo_href; - static logo; - static name; - static theme; - static user_id; -} diff --git a/src/models/carrier_account.js b/src/models/carrier_account.js deleted file mode 100644 index 6f3c75a65..000000000 --- a/src/models/carrier_account.js +++ /dev/null @@ -1,17 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#carrier-accounts CarrierAccount} represents details about a specific enabled carrier, including credentials and other information. - * @public - * @extends EasyPostObject - */ -export default class CarrierAccount extends EasyPostObject { - static billing_type; - static clone; - static credentials; - static description; - static fields; - static readable; - static reference; - static test_credentials; -} diff --git a/src/models/carrier_type.js b/src/models/carrier_type.js deleted file mode 100644 index 04fe2799b..000000000 --- a/src/models/carrier_type.js +++ /dev/null @@ -1,11 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#carrier-types CarrierType} represents the valid fields for a {@link CarrierAccount carrier account}. - * @public - * @extends EasyPostObject - */ -export default class CarrierType extends EasyPostObject { - static fields; - static type; -} diff --git a/src/models/customs_info.js b/src/models/customs_info.js deleted file mode 100644 index 1734147c5..000000000 --- a/src/models/customs_info.js +++ /dev/null @@ -1,19 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#customs-infos CustomsInfo} represents a collection of {@link CustomsItem CustomsItems} and associated information for generating international shipping customs forms. - * @public - * @extends EasyPostObject - */ -export default class CustomsInfo extends EasyPostObject { - static content_explanation; - static contents_type; - static customs_certify; - static customs_items; - static customs_signer; - static declaration; - static eel_pfc; - static non_delivery_option; - static restriction_comments; - static restriction_type; -} diff --git a/src/models/customs_item.js b/src/models/customs_item.js deleted file mode 100644 index ebb4763d3..000000000 --- a/src/models/customs_item.js +++ /dev/null @@ -1,17 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#customs-item CustomsItem} represents a single item being shipped internationally. - * @public - * @extends EasyPostObject - */ -export default class CustomsItem extends EasyPostObject { - static code; - static currency; - static description; - static hs_tariff_number; - static origin_country; - static quantity; - static value; - static weight; -} diff --git a/src/models/easypost_object.js b/src/models/easypost_object.js deleted file mode 100644 index d84435fb6..000000000 --- a/src/models/easypost_object.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * An EasyPostObject is the base class for all EasyPost API resources. - * @internal - * @abstract - */ -export default class EasyPostObject { - static id; - static object; - static mode; - static created_at; - static updated_at; - static _params; -} diff --git a/src/models/end_shipper.js b/src/models/end_shipper.js deleted file mode 100644 index 5017fe6b4..000000000 --- a/src/models/end_shipper.js +++ /dev/null @@ -1,19 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * An {@link https://www.easypost.com/docs/api/node#endshipper EndShipper} represents a person or business entity that is authorized to purchase postage on behalf of another person and is ultimately responsible for the shipment. - * @public - * @extends EasyPostObject - */ -export default class EndShipper extends EasyPostObject { - static street1; - static street2; - static city; - static state; - static zip; - static country; - static name; - static company; - static phone; - static email; -} diff --git a/src/models/event.js b/src/models/event.js deleted file mode 100644 index d43b9719b..000000000 --- a/src/models/event.js +++ /dev/null @@ -1,15 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * An {@link https://www.easypost.com/docs/api/node#events Event} represents a change in state for elements such as {@link Shipment shipments} and {@link Tracker trackers}, that triggers a {@link Webhook webhook}. - * @public - * @extends EasyPostObject - */ -export default class Event extends EasyPostObject { - static completed_urls; - static description; - static pending_urls; - static previous_attributes; - static result; - static status; -} diff --git a/src/models/form.js b/src/models/form.js deleted file mode 100644 index b042591e1..000000000 --- a/src/models/form.js +++ /dev/null @@ -1,12 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#forms Form} represents a printable form for a {@link Shipment shipment}, such as a return packing slip, QR code or international shipping form. - * @public - * @extends EasyPostObject - */ -export default class Form extends EasyPostObject { - static form_type; - static form_url; - static submitted_electronically; -} diff --git a/src/models/insurance.js b/src/models/insurance.js deleted file mode 100644 index 29dbcf196..000000000 --- a/src/models/insurance.js +++ /dev/null @@ -1,21 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * An {@link https://www.easypost.com/docs/api/node#api-keys Insurance} object represents insurance for a {@link Shipment shipment}. - * @public - * @extends EasyPostObject - */ -export default class Insurance extends EasyPostObject { - static amount; - static fee; - static from_address; - static messages; - static provider_id; - static provider; - static reference; - static shipment_id; - static status; - static to_address; - static tracking_code; - static tracker; -} diff --git a/src/models/order.js b/src/models/order.js deleted file mode 100644 index b4db435f9..000000000 --- a/src/models/order.js +++ /dev/null @@ -1,33 +0,0 @@ -import Constants from '../constants'; -import EasyPostObject from './easypost_object'; - -/** - * An {@link https://www.easypost.com/docs/api/node#orders Order} represents a collection of packages, intended only for multi-parcel shipments. - * @public - * @extends EasyPostObject - */ -export default class Order extends EasyPostObject { - static buyer_address; - static from_address; - static is_return; - static messages; - static rates; - static reference; - static return_address; - static shipments; - static to_address; - - /** - * Get the lowest rate for this {@link Order}. - * @public - * @param {string[]} [carriers] - List of allowed carriers to filter by - * @param {string[]} [services] - List of allowed services to filter by - * @returns {Rate} - The lowest rate - * @throws {FilteringError} - If no applicable rates are found - */ - lowestRate(carriers, services) { - const rates = this.rates || []; - - return Constants.Utils.getLowestRate(rates, carriers, services); - } -} diff --git a/src/models/parcel.js b/src/models/parcel.js deleted file mode 100644 index c7be50849..000000000 --- a/src/models/parcel.js +++ /dev/null @@ -1,14 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#parcels Parcel} represents a physical container being shipped, such as a box or envelope, with corresponding dimensions and weight. - * @public - * @extends EasyPostObject - */ -export default class Parcel extends EasyPostObject { - static height; - static length; - static predefined_package; - static weight; - static width; -} diff --git a/src/models/payload.js b/src/models/payload.js deleted file mode 100644 index a4ac8c8f1..000000000 --- a/src/models/payload.js +++ /dev/null @@ -1,10 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#payloads Payload} represents an attempt by EasyPost to send an {@link Event event} to a {@link Webhook webhook}. - * @public - * @extends EasyPostObject - */ -export default class Payload extends EasyPostObject { - static response_body; -} diff --git a/src/models/pickup.js b/src/models/pickup.js deleted file mode 100644 index a600f77b3..000000000 --- a/src/models/pickup.js +++ /dev/null @@ -1,36 +0,0 @@ -import Constants from '../constants'; -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#pickups Pickup} represents a scheduled carrier pickup of packages from an {@link https://www.easypost.com/docs/api/node#addresses Address}. - * @public - * @extends EasyPostObject - */ -export default class Pickup extends EasyPostObject { - static address; - static carrier_accounts; - static confirmation; - static instructions; - static is_account_address; - static max_datetime; - static messages; - static min_datetime; - static pickup_rates; - static reference; - static shipment; - static status; - - /** - * Get the lowest rate for this {@link Pickup}. - * @public - * @param {string[]} [carriers] - List of allowed carriers to filter by - * @param {string[]} [services] - List of allowed services to filter by - * @returns {Rate} - The lowest rate - * @throws {FilteringError} - If no applicable rates are found - */ - lowestRate(carriers, services) { - const rates = this.pickup_rates || []; - - return Constants.Utils.getLowestRate(rates, carriers, services); - } -} diff --git a/src/models/pickup_rate.js b/src/models/pickup_rate.js deleted file mode 100644 index 4e52d5765..000000000 --- a/src/models/pickup_rate.js +++ /dev/null @@ -1,14 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link PickupRate} represents a {@link Rate rate} for a {@link Pickup pickup}. - * @public - * @extends EasyPostObject - */ -export default class PickupRate extends EasyPostObject { - static carrier; - static currency; - static pickup_id; - static rate; - static service; -} diff --git a/src/models/postage_label.js b/src/models/postage_label.js deleted file mode 100644 index e72a55252..000000000 --- a/src/models/postage_label.js +++ /dev/null @@ -1,18 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link PostageLabel} represents a physical label to affix to a {@link Parcel parcel} when shipping. - * @public - * @extends EasyPostObject - */ -export default class PostageLabel extends EasyPostObject { - static label_date; - static label_epl2_url; - static label_file_type; - static label_pdf_url; - static label_resolution; - static label_size; - static label_type; - static label_url; - static label_zpl_url; -} diff --git a/src/models/rate.js b/src/models/rate.js deleted file mode 100644 index a63e8b4aa..000000000 --- a/src/models/rate.js +++ /dev/null @@ -1,22 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#rates Rate} represents pricing information for shipping a specific {@link Parcel} with a specific carrier and service level. - * @public - * @extends EasyPostObject - */ -export default class Rate extends EasyPostObject { - static billing_type; - static carrier_account_id; - static carrier; - static currency; - static delivery_date_guaranteed; - static delivery_days; - static list_currency; - static list_rate; - static rate; - static retail_currency; - static retail_rate; - static service; - static shipment_id; -} diff --git a/src/models/refund.js b/src/models/refund.js deleted file mode 100644 index 28af6c6a1..000000000 --- a/src/models/refund.js +++ /dev/null @@ -1,14 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#refunds Refund} represents a refunded {@link Shipment}. - * @public - * @extends EasyPostObject - */ -export default class Refund extends EasyPostObject { - static carrier; - static confirmation_number; - static shipment_id; - static status; - static tracking_code; -} diff --git a/src/models/report.js b/src/models/report.js deleted file mode 100644 index 92b65d1ba..000000000 --- a/src/models/report.js +++ /dev/null @@ -1,16 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#reports Report} represents a CSV file containing a log of all objects within a specific time frame. - * @public - * @extends EasyPostObject - */ -export default class Report extends EasyPostObject { - static end_date; - static include_children; - static send_email; - static start_date; - static status; - static url_expires_at; - static url; -} diff --git a/src/models/scan_form.js b/src/models/scan_form.js deleted file mode 100644 index e2a92ed0d..000000000 --- a/src/models/scan_form.js +++ /dev/null @@ -1,16 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#scan-form ScanForm} represents a single document that can be scanned to mark all included tracking codes as "Accepted for Shipment" by the carrier. - * @public - * @extends EasyPostObject - */ -export default class ScanForm extends EasyPostObject { - static address; - static batch_id; - static form_file_type; - static form_url; - static message; - static status; - static tracking_codes; -} diff --git a/src/models/shipment.js b/src/models/shipment.js deleted file mode 100644 index 270e57c2c..000000000 --- a/src/models/shipment.js +++ /dev/null @@ -1,49 +0,0 @@ -import Constants from '../constants'; -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#shipments Shipment} represents a physical {@link Parcel}, the origin and destination {@link Address Addresses}, and any associated {@link CustomsInfo}. - * @public - * @extends EasyPostObject - */ -export default class Shipment extends EasyPostObject { - static batch_id; - static batch_message; - static batch_status; - static buyer_address; - static customs_info; - static fees; - static forms; - static from_address; - static insurance; - static is_return; - static messages; - static options; - static parcel; - static postage_label; - static rates; - static reference; - static refund_status; - static return_address; - static scan_form; - static selected_rate; - static status; - static to_address; - static tracker; - static tracking_code; - static usps_zone; - - /** - * Get the lowest rate for this {@link Shipment}. - * @public - * @param {string[]} [carriers] - List of allowed carriers to filter by - * @param {string[]} [services] - List of allowed services to filter by - * @returns {Rate} - The lowest rate - * @throws {FilteringError} - If no applicable rates are found - */ - lowestRate(carriers, services) { - const rates = this.rates || []; - - return Constants.Utils.getLowestRate(rates, carriers, services); - } -} diff --git a/src/models/tracker.js b/src/models/tracker.js deleted file mode 100644 index 5b3b00d4f..000000000 --- a/src/models/tracker.js +++ /dev/null @@ -1,21 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#trackers Tracker} represents the available tracking information for a package. - * @public - * @extends EasyPostObject - */ -export default class Tracker extends EasyPostObject { - static carrier_details; - static carrier; - static est_delivery_date; - static fees; - static public_url; - static shipment_id; - static signed_by; - static status; - static status_detail; - static tracking_code; - static tracking_details; - static weight; -} diff --git a/src/models/user.js b/src/models/user.js deleted file mode 100644 index 5dc0071ed..000000000 --- a/src/models/user.js +++ /dev/null @@ -1,22 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#user ApiKey} represents an EasyPost account or child account. - * @public - * @extends EasyPostObject - */ -export default class User extends EasyPostObject { - static api_keys; - static balance; - static cc_fee_rate; - static children; - static email; - static insurance_fee_minimum; - static insurance_fee_rate; - static name; - static parent_id; - static phone_number; - static price_per_shipment; - static recharge_amount; - static secondary_recharge_amount; -} diff --git a/src/models/webhook.js b/src/models/webhook.js deleted file mode 100644 index 333d51cb6..000000000 --- a/src/models/webhook.js +++ /dev/null @@ -1,11 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://www.easypost.com/docs/api/node#webhooks Webhook} represents a URL that will receive notifications when certain {@link Event} occur. - * @public - * @extends EasyPostObject - */ -export default class Webhook extends EasyPostObject { - static disabled_at; - static url; -} diff --git a/src/services/address_service.js b/src/services/address_service.js deleted file mode 100644 index afd6b4507..000000000 --- a/src/services/address_service.js +++ /dev/null @@ -1,107 +0,0 @@ -import baseService from './base_service'; - -export default (easypostClient) => - /** - * The AddressService class provides methods for interacting with EasyPost {@link Address} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - class AddressService extends baseService(easypostClient) { - /** - * Create an {@link Address address}. - * See {@link https://www.easypost.com/docs/api/node#create-an-address EasyPost API Documentation} for more information. - * @param {Object} params - Parameters for the address to be created. - * @returns {Address} - The created address. - */ - static async create(params) { - const url = 'addresses'; - - const wrappedParams = { - address: params, - }; - - if (params.verify) { - const clone = params; - wrappedParams.verify = params.verify; - delete clone.verify; - } - - if (params.verify_strict) { - const clone = params; - wrappedParams.verify_strict = params.verify_strict; - delete clone.verify_strict; - } - - return this._create(url, wrappedParams); - } - - /** - * Create and verify an {@link Address address} in a single request. - * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. - * @param {Object} params - Parameters for the address to be created. - * @returns {Address} - The created and verified address. - */ - static async createAndVerify(params) { - const url = `addresses/create_and_verify`; - const wrappedParams = { address: params }; - - try { - const response = await easypostClient._post(url, wrappedParams); - - return this._convertToEasyPostObject(response.body.address, wrappedParams); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Retrieve all {@link Address addresses} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-addresses EasyPost API Documentation} for more information. - * @param {Object} [params] - Parameters to filter the list of addresses. - * @returns {Object} - An object containing a list of {@link Address addresses} and pagination information. - */ - static async all(params = {}) { - const url = 'addresses'; - - return this._all(url, params); - } - - /** - * Retrieve the next page of Address collection. - * @param {Object} addresses An object containing a list of {@link Address addresses} and pagination information. - * @param {Number} pageSize The number of records to return on each page - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - static async getNextPage(addresses, pageSize = null) { - const url = 'addresses'; - return this._getNextPage(url, 'addresses', addresses, pageSize); - } - - /** - * Retrieve an {@link Address address} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-address EasyPost API Documentation} for more information. - * @param {string} id - The ID of the address to retrieve. - * @returns {Address} - The retrieved address. - */ - static async retrieve(id) { - const url = `addresses/${id}`; - - return this._retrieve(url); - } - - /** - * Verify an {@link Address address} by its ID. - * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. - * @param {string} id - The ID of the address to verify. - * @returns {Address} - The verified address. - */ - static async verifyAddress(id) { - try { - const url = `addresses/${id}/verify`; - const response = await easypostClient._get(url); - - return this._convertToEasyPostObject(response.body.address); - } catch (e) { - return Promise.reject(e); - } - } - }; diff --git a/src/services/address_service/Address.ts b/src/services/address_service/Address.ts new file mode 100644 index 000000000..1889d611f --- /dev/null +++ b/src/services/address_service/Address.ts @@ -0,0 +1,87 @@ +import { IVerifications } from "./Verifications"; +import { IObjectWithId } from "../../utils/types"; + +/** + * Address objects are used to represent people, places, and organizations in a number of contexts. + * For example, a Shipment requires a to_address and from_address to accurately calculate rates and generate postage. + * + * Additionally, EasyPost offers several verification tools that can be used to detect deliverability issues, correct minor errors in spelling/formatting, and determine if an Address is residential or not (which has a significant effect on Shipment rating for many carriers). + * + * @see https://www.easypost.com/docs/api/node#address-object + */ +export type IAddress = IObjectWithId<"Address"> & { + /** + * First line of the address + */ + street1?: string | null; + + /** + * Second line of the address + */ + street2?: string | null; + + /** + * City the address is located in + */ + city?: string | null; + + /** + * State or province the address is located in + */ + state?: string | null; + + /** + * ZIP or postal code the address is located in + */ + zip: string; + + /** + * ISO 3166 country code for the country the address is located in + */ + country: string; + + /** + * Whether or not this address would be considered residential + */ + residential?: boolean | null; + + /** + * The specific designation for the address (only relevant if the address is a carrier facility) + */ + carrier_facility?: string | null; + + /** + * Name of the person. Both name and company can be included + */ + name?: string | null; + + /** + * Name of the organization. Both name and company can be included + */ + company?: string | null; + + /** + * Phone number to reach the person or organization + */ + phone?: string | null; + + /** + * Email to reach the person or organization + */ + email?: string | null; + + /** + * Federal tax identifier of the person or organization + */ + federal_tax_id?: string | null; + + /** + * State tax identifier of the person or organization + */ + state_tax_id?: string | null; + + /** + * The result of any verifications requested + */ + verifications: IVerifications; +}; diff --git a/types/Address/AddressCreateParameters.ts b/src/services/address_service/AddressCreateParameters.ts similarity index 69% rename from types/Address/AddressCreateParameters.ts rename to src/services/address_service/AddressCreateParameters.ts index b29bd06f8..b041de7f3 100644 --- a/types/Address/AddressCreateParameters.ts +++ b/src/services/address_service/AddressCreateParameters.ts @@ -1,11 +1,13 @@ -import { ParametersToOmitOnCreate } from '../utils'; -import { IAddress } from './Address'; +import { ParametersToOmitOnCreate } from "../../utils/types"; +import { IAddress } from "./Address"; /** * @see https://www.easypost.com/docs/api/node#create-and-verify-addresses */ -export declare interface IAddressCreateParameters - extends Omit { +export type IAddressCreateParameters = Omit< + IAddress, + ParametersToOmitOnCreate | "verifications" +> & { /** * The verifications to perform when creating. * verify_strict takes precedence. @@ -19,4 +21,4 @@ export declare interface IAddressCreateParameters * true will perform both delivery and zip code. */ verify_strict?: boolean | null; -} +}; diff --git a/src/services/address_service/AddressListParameters.ts b/src/services/address_service/AddressListParameters.ts new file mode 100644 index 000000000..c2a965a5b --- /dev/null +++ b/src/services/address_service/AddressListParameters.ts @@ -0,0 +1,6 @@ +import { IAllMethodParameters } from "../../utils/types"; + +/** + * @see https://www.easypost.com/docs/api#retrieve-a-list-of-addresses + */ +export type IAddressListParameters = IAllMethodParameters; diff --git a/types/Address/Verification.d.ts b/src/services/address_service/Verification.ts similarity index 69% rename from types/Address/Verification.d.ts rename to src/services/address_service/Verification.ts index 6eecb63db..bf8560808 100644 --- a/types/Address/Verification.d.ts +++ b/src/services/address_service/Verification.ts @@ -1,10 +1,10 @@ -import { IFieldError } from '../errors'; -import { IVerificationDetails } from './VerificationDetails'; +import { IFieldError } from "../../utils/errors"; +import { IVerificationDetails } from "./VerificationDetails"; /** * @see https://www.easypost.com/docs/api/node#verification-object */ -export declare interface IVerification { +export type IVerification = { /** * The success of the verification */ @@ -19,4 +19,4 @@ export declare interface IVerification { * Extra data related to the verification */ details: IVerificationDetails; -} +}; diff --git a/types/Address/VerificationDetails.d.ts b/src/services/address_service/VerificationDetails.ts similarity index 86% rename from types/Address/VerificationDetails.d.ts rename to src/services/address_service/VerificationDetails.ts index dbe668415..b75c071ec 100644 --- a/types/Address/VerificationDetails.d.ts +++ b/src/services/address_service/VerificationDetails.ts @@ -1,7 +1,7 @@ /** * @see https://www.easypost.com/docs/api/node#verification_details-object */ -export declare interface IVerificationDetails { +export type IVerificationDetails = { /** * The latitude of an Address. */ @@ -16,4 +16,4 @@ export declare interface IVerificationDetails { * The time zone the address is located in, IE: America/Los_Angeles */ time_zone: string; -} +}; diff --git a/types/Address/Verifications.d.ts b/src/services/address_service/Verifications.ts similarity index 78% rename from types/Address/Verifications.d.ts rename to src/services/address_service/Verifications.ts index 0bd339755..6ed85596b 100644 --- a/types/Address/Verifications.d.ts +++ b/src/services/address_service/Verifications.ts @@ -1,9 +1,9 @@ -import { IVerification } from './Verification'; +import { IVerification } from "./Verification"; /** * @see https://www.easypost.com/docs/api/node#verifications-object */ -export declare interface IVerifications { +export type IVerifications = { /** * Only applicable to US addresses - checks and sets the ZIP+4 */ @@ -12,4 +12,6 @@ export declare interface IVerifications { * Checks that the address is deliverable and makes minor corrections to spelling/format. US addresses will also have their "residential" status checked and set. */ delivery: IVerification; -} +}; + +export default {}; diff --git a/src/services/address_service/index.ts b/src/services/address_service/index.ts new file mode 100644 index 000000000..a3312d44d --- /dev/null +++ b/src/services/address_service/index.ts @@ -0,0 +1,124 @@ +import EasyPost from "../.."; +import baseService from "../base_service"; +import { IAddress } from "./Address"; +import { IAddressCreateParameters } from "./AddressCreateParameters"; +import { IAddressListParameters } from "./AddressListParameters"; + +export * from "./Address"; +export * from "./AddressCreateParameters"; +export * from "./Verification"; +export * from "./VerificationDetails"; +export * from "./Verifications"; + +export default (easypostClient: EasyPost) => + /** + * The AddressService class provides methods for interacting with EasyPost {@link Address} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + class AddressService extends baseService(easypostClient) { + /** + * Create an {@link Address address}. + * See {@link https://www.easypost.com/docs/api/node#create-an-address EasyPost API Documentation} for more information. + * @param params - Parameters for the address to be created. + * @returns - The created address. + */ + static async create(params: IAddressCreateParameters) { + const url = "addresses"; + + const wrappedParams: { address: IAddressCreateParameters } & Pick< + IAddressCreateParameters, + "verify" | "verify_strict" + > = { + address: params, + }; + + if (params.verify) { + wrappedParams.verify = params.verify; + delete params.verify; + } + + if (params.verify_strict) { + wrappedParams.verify_strict = params.verify_strict; + delete params.verify_strict; + } + + return this._create(url, wrappedParams); + } + + /** + * Create and verify an {@link Address address} in a single request. + * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. + * @param params - Parameters for the address to be created. + * @returns - The created and verified address. + */ + static async createAndVerify(params: IAddressCreateParameters) { + const url = `addresses/create_and_verify`; + const wrappedParams = { address: params }; + + try { + const response = await easypostClient._post(url, wrappedParams); + + return this._convertToEasyPostObject( + response.body.address, + wrappedParams + ); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Retrieve all {@link Address addresses} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-addresses EasyPost API Documentation} for more information. + * @param params - Parameters to filter the list of addresses. + * @returns - An object containing a list of {@link Address addresses} and pagination information. + */ + static async all(params: IAddressListParameters = {}) { + const url = "addresses"; + + return this._all(url, params); + } + + /** + * Retrieve the next page of Address collection. + * @param addresses An object containing a list of {@link Address addresses} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + static async getNextPage( + addresses: { addresses: IAddress[] }, + pageSize: number | null = null + ) { + const url = "addresses"; + return this._getNextPage(url, "addresses", addresses, pageSize); + } + + /** + * Retrieve an {@link Address address} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-address EasyPost API Documentation} for more information. + * @param id - The ID of the address to retrieve. + * @returns - The retrieved address. + */ + static async retrieve(id: string) { + const url = `addresses/${id}`; + + return this._retrieve(url); + } + + /** + * Verify an {@link Address address} by its ID. + * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. + * @param id - The ID of the address to verify. + * @returns - The verified address. + */ + static async verifyAddress(id: string) { + try { + const url = `addresses/${id}/verify`; + const response = await easypostClient._get(url); + + return this._convertToEasyPostObject(response.body.address); + } catch (e) { + return Promise.reject(e); + } + } + }; diff --git a/src/services/api_key_service/ApiKey.ts b/src/services/api_key_service/ApiKey.ts new file mode 100644 index 000000000..4d828c8a5 --- /dev/null +++ b/src/services/api_key_service/ApiKey.ts @@ -0,0 +1,24 @@ +import { IObjectWithId } from "../../utils/types"; + +export type IApiKey = IObjectWithId<"ApiKey"> & { + /** + * The actual key value to use for authentication + */ + key: string; + + /** + * When the API key was created + */ + created_at: string; + + /** + * Whether the API key is active or not + */ + active: boolean; +}; + +export type UserAPIKeys = { + id: string; + keys: IApiKey[]; + children: UserAPIKeys[]; +}; diff --git a/src/services/api_key_service.js b/src/services/api_key_service/index.ts similarity index 51% rename from src/services/api_key_service.js rename to src/services/api_key_service/index.ts index 4b904082b..cdbe8dbee 100644 --- a/src/services/api_key_service.js +++ b/src/services/api_key_service/index.ts @@ -1,10 +1,13 @@ -import baseService from './base_service'; -import Constants from '../constants'; -import FilteringError from '../errors/general/filtering_error'; +import util from "node:util"; +import baseService from "../base_service"; +import Constants from "../../constants"; +import FilteringError from "../../errors/general/filtering_error"; +import EasyPost from "../.."; +import { IApiKey, UserAPIKeys } from "./ApiKey"; -const util = require('util'); +export * from "./ApiKey"; -export default (easypostClient) => +export default (easypostClient: EasyPost) => /** * The ApiKeyService class provides methods for interacting with EasyPost {@link ApiKey} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -13,41 +16,43 @@ export default (easypostClient) => /** * Retrieve all {@link ApiKey API keys} associated with the current authenticated user. * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. - * @returns {Object} - An object containing the API keys associated with the current authenticated user and its child users. + * @returns - An object containing the API keys associated with the current authenticated user and its child users. */ static async all(params = {}) { - const url = 'api_keys'; + const url = "api_keys"; - return this._all(url, params); + return this._all(url, params); } /** * Retrieve API Keys for a specified {@link User user}. * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. - * @param {string} id - The ID of the user to retrieve keys for. - * @returns {Array} - List of associated API Keys. + * @param id - The ID of the user to retrieve keys for. + * @returns - List of associated API Keys. * @throws {FilteringError} If user or API Keys are not found. */ - static async retrieveApiKeysForUser(id) { + static async retrieveApiKeysForUser(id: string) { const url = `api_keys`; try { const response = await easypostClient._get(url); - const user = this._convertToEasyPostObject(response.body); + const user = this._convertToEasyPostObject(response.body); if (user.id == id) { return user.keys; } - user.children.forEach((child) => { - if (child.id == id) { - return child.keys; - } - }); + const childUser = user.children.find((child) => child.id === id); + + if (childUser) { + return childUser.keys; + } } catch (e) { return Promise.reject(e); } - throw new FilteringError({ message: util.format(Constants.NO_OBJECT_FOUND, 'child') }); + throw new FilteringError({ + message: util.format(Constants.NO_OBJECT_FOUND, "child"), + }); } }; diff --git a/src/services/base_service.js b/src/services/base_service.js deleted file mode 100644 index 0572d2e79..000000000 --- a/src/services/base_service.js +++ /dev/null @@ -1,231 +0,0 @@ -import Address from '../models/address'; -import ApiKey from '../models/api_key'; -import Batch from '../models/batch'; -import Brand from '../models/brand'; -import CarrierAccount from '../models/carrier_account'; -import CarrierType from '../models/carrier_type'; -import CustomsInfo from '../models/customs_info'; -import CustomsItem from '../models/customs_item'; -import EasyPostObject from '../models/easypost_object'; -import EndShipper from '../models/end_shipper'; -import Event from '../models/event'; -import Form from '../models/form'; -import Insurance from '../models/insurance'; -import Order from '../models/order'; -import Parcel from '../models/parcel'; -import Payload from '../models/payload'; -import Pickup from '../models/pickup'; -import PickupRate from '../models/pickup_rate'; -import PostageLabel from '../models/postage_label'; -import Rate from '../models/rate'; -import Refund from '../models/refund'; -import Report from '../models/report'; -import ScanForm from '../models/scan_form'; -import Shipment from '../models/shipment'; -import Tracker from '../models/tracker'; -import User from '../models/user'; -import Webhook from '../models/webhook'; -import EndOfPaginationError from '../errors/general/end_of_pagination_error'; - -/** - * A map of EasyPost object ID prefixes to their associated class names. - */ -const EASYPOST_OBJECT_ID_PREFIX_TO_CLASS_NAME_MAP = { - adr: Address, - ak: ApiKey, - batch: Batch, - brd: Brand, - ca: CarrierAccount, - cfrep: Report, - cstinfo: CustomsInfo, - cstitem: CustomsItem, - es: EndShipper, - evt: Event, - hook: Webhook, - ins: Insurance, - order: Order, - payload: Payload, - pickup: Pickup, - pickuprate: PickupRate, - pl: PostageLabel, - plrep: Report, - prcl: Parcel, - rate: Rate, - refrep: Report, - rfnd: Refund, - sf: ScanForm, - shp: Shipment, - shpinvrep: Report, - shprep: Report, - trk: Tracker, - trkrep: Report, - user: User, -}; - -/** - * A map of EasyPost services available to the client. - */ -const RESOURCES = { - Address, - ApiKey, - Batch, - Brand, - CarrierAccount, - CarrierType, - CustomsInfo, - CustomsItem, - EasyPostObject, - EndShipper, - Event, - Form, - Insurance, - Order, - Parcel, - Payload, - Pickup, - PickupRate, - PostageLabel, - Rate, - Refund, - Report, - ScanForm, - Shipment, - Tracker, - User, - Webhook, -}; - -export default (easypostClient) => - /** - * The base class for all EasyPost client library services. - * @param {EasyPostClient} easypostClient The {@link EasyPostClient} instance to use for API calls. - */ - class BaseService { - /** - * Converts a JSON response and all its nested elements to associated {@link EasyPostObject}-based class instances. - * @internal - * @param {*} response The JSON response to convert (usually a `Map` or `Array`). - * @param {*} params The parameters passed when fetching the response - * @returns {*} An {@link EasyPostObject}-based class instance or an `Array` of {@link EasyPostObject}-based class instances. - */ - static _convertToEasyPostObject(response, params) { - if (Array.isArray(response)) { - return response.map((value) => { - if (typeof value === 'object') { - return this._convertToEasyPostObject(value, params); - } - return value; - }); - } - - if (typeof response === 'object' && response !== null) { - let classObject; - if (RESOURCES[response.object] !== undefined) { - classObject = new RESOURCES[response.object](); - } else if ( - response.id !== undefined && - EASYPOST_OBJECT_ID_PREFIX_TO_CLASS_NAME_MAP[ - response.id.substr(0, response.id.indexOf('_')) - ] !== undefined - ) { - const className = response.id.substr(0, response.id.indexOf('_')); - classObject = new EASYPOST_OBJECT_ID_PREFIX_TO_CLASS_NAME_MAP[className](); - } else { - classObject = new EasyPostObject(); - } - - Object.keys(response).forEach((key) => { - classObject[key] = this._convertToEasyPostObject(response[key], params); - }); - - classObject._params = params; - - return classObject; - } - return response; - } - - /** - * Creates an EasyPost Object via the API. - * @internal - * @param {string} url The URL to send the API request to. - * @param {Object} params The parameters to send with the API request. - * @returns {EasyPostObject|Promise} The created {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - static async _create(url, params) { - try { - const response = await easypostClient._post(url, params); - - return this._convertToEasyPostObject(response.body, params); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Retrieve a list of records from the API. - * @internal - * @param {string} url The URL to send the API request to. - * @param {Object} [params] The parameters to send with the API request. - * @returns {EasyPostObject|EasyPostObject[]|Promise} The retrieved {@link EasyPostObject}-based class instance(s), or a `Promise` that rejects with an error. - */ - static async _all(url, params = {}) { - try { - // eslint-disable-next-line no-param-reassign - const response = await easypostClient._get(url, params); - - return this._convertToEasyPostObject(response.body, params); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Retrieve a record from the API. - * @internal - * @param {string} url The URL to send the API request to. - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - static async _retrieve(url) { - try { - const response = await easypostClient._get(url); - - return this._convertToEasyPostObject(response.body); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Retrieve the next page of specific collection of object - * @internal - * @param {string} url The URL to send the API request to. - * @param {Object} collection The collection of a specific object. - * @param {Number} pageSize The number of records to return on each page. - * @param {Object} optionalParams The optional param for additional value in the query string. - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - * TODO: Implement this function in EndShippers and Batches once the API supports them properly. - */ - static async _getNextPage(url, key, collection, pageSize = null, optionalParams = {}) { - const collectionArray = collection[key]; - if (collectionArray == undefined || collectionArray.length == 0 || !collection.has_more) { - throw new EndOfPaginationError(); - } - - const defaultParams = collection._params ?? collectionArray[0]._params ?? {}; - - const params = { - ...defaultParams, - page_size: defaultParams.page_size ?? pageSize, - before_id: collectionArray[collectionArray.length - 1].id, - ...optionalParams, - }; - - const response = await this._all(url, params); - if (response == undefined || response[key].length == 0) { - throw new EndOfPaginationError(); - } - - return response; - } - }; diff --git a/src/services/base_service.ts b/src/services/base_service.ts new file mode 100644 index 000000000..34c9992ae --- /dev/null +++ b/src/services/base_service.ts @@ -0,0 +1,131 @@ +import EasyPostClient from "../easypost"; +import EndOfPaginationError from "../errors/general/end_of_pagination_error"; + +export type EasyPostObject = A & { + _params: any; +}; + +export default (easypostClient: EasyPostClient) => + /** + * The base class for all EasyPost client library services. + * @param {EasyPostClient} easypostClient The {@link EasyPostClient} instance to use for API calls. + */ + class BaseService { + /** + * Converts a JSON response and all its nested elements to associated {@link EasyPostObject}-based class instances. + * @internal + * @param {*} response The JSON response to convert (usually a `Map` or `Array`). + * @param {*} params The parameters passed when fetching the response + * @returns {*} An {@link EasyPostObject}-based class instance or an `Array` of {@link EasyPostObject}-based class instances. + */ + static _convertToEasyPostObject( + response: A, + params?: any + ): EasyPostObject { + const newResponse = response as EasyPostObject; + newResponse._params = params; + + return newResponse; + } + + /** + * Creates an EasyPost Object via the API. + * @internal + * @param url The URL to send the API request to. + * @param params The parameters to send with the API request. + * @returns The created {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + static async _create( + url: string, + params: object + ): Promise> { + try { + const response = await easypostClient._post(url, params); + + return this._convertToEasyPostObject(response.body, params); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Retrieve a list of records from the API. + * @internal + * @param url The URL to send the API request to. + * @param params The parameters to send with the API request. + * @returns The retrieved {@link EasyPostObject}-based class instance(s), or a `Promise` that rejects with an error. + */ + static async _all( + url: string, + params: Record = {} + ): Promise & { has_more: boolean }> { + try { + // eslint-disable-next-line no-param-reassign + const response = await easypostClient._get(url, params); + + return this._convertToEasyPostObject(response.body, params); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Retrieve a record from the API. + * @internal + * @param url The URL to send the API request to. + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + static async _retrieve(url: string): Promise> { + try { + const response = await easypostClient._get(url); + + return this._convertToEasyPostObject(response.body); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Retrieve the next page of specific collection of object + * @internal + * @param url The URL to send the API request to. + * @param collection The collection of a specific object. + * @param pageSize The number of records to return on each page. + * @param optionalParams The optional param for additional value in the query string. + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + * TODO: Implement this function in EndShippers and Batches once the API supports them properly. + */ + static async _getNextPage>( + url: string, + key: keyof A, + collection: A, + pageSize: number | null = null, + optionalParams: Record = {} + ): Promise & { has_more: boolean }> { + const collectionArray = collection[key]; + if ( + collectionArray == undefined || + collectionArray.length == 0 || + !collection.has_more + ) { + throw new EndOfPaginationError(); + } + + const defaultParams = + collection._params ?? collectionArray[0]._params ?? {}; + + const params = { + ...defaultParams, + page_size: defaultParams.page_size ?? pageSize, + before_id: collectionArray[collectionArray.length - 1].id, + ...optionalParams, + }; + + const response = await this._all(url, params); + if (response == undefined || response[key].length == 0) { + throw new EndOfPaginationError(); + } + + return response; + } + }; diff --git a/src/services/batch_service/Batch.ts b/src/services/batch_service/Batch.ts new file mode 100644 index 000000000..be0c53097 --- /dev/null +++ b/src/services/batch_service/Batch.ts @@ -0,0 +1,56 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { IPickup } from "../pickup_service/Pickup"; +import { IScanForm } from "../scan_form_service"; +import { IBatchShipment } from "./BatchShipment"; +import { TBatchState } from "./BatchState"; +import { TBatchStatuses } from "./BatchStatuses"; + +/** + * The Batch object allows you to perform operations on multiple Shipments at once. + * This includes scheduling a Pickup, creating a ScanForm and consolidating labels. + * Operations performed on Batches are asynchronous and take advantage of our webhook infrastructure. + * + * @see https://www.easypost.com/docs/api/node#batch-object + */ +export type IBatch = IObjectWithId<"Batch"> & + IDatedObject & { + /** + * An optional field that may be used in place of ID in some API endpoints + */ + reference?: string | null; + + /** + * The overall state. Possible values are "creating", "creation_failed", "created", "purchasing", "purchase_failed", "purchased", "label_generating", and "label_generated" + */ + state: TBatchState; + + /** + * The number of shipments added + */ + num_shipments: number; + + /** + * An array of batch shipments + */ + shipments: IBatchShipment[]; + + /** + * A map of BatchShipment statuses to the count of BatchShipments with that status. Valid statuses are "postage_purchased", "postage_purchase_failed", "queued_for_purchase", and "creation_failed" + */ + status: TBatchStatuses; + + /** + * The label image url + */ + label_url?: string | null; + + /** + * The created ScanForm + */ + scan_form: IScanForm; + + /** + * The created Pickup + */ + pickup: IPickup; + }; diff --git a/src/services/batch_service/BatchCreateParameters.ts b/src/services/batch_service/BatchCreateParameters.ts new file mode 100644 index 000000000..eae32ace5 --- /dev/null +++ b/src/services/batch_service/BatchCreateParameters.ts @@ -0,0 +1,5 @@ +import { IShipment } from "../shipment_service"; + +export type IBatchCreateParameters = { + shipments?: ({ id: string } | string)[]; +}; diff --git a/src/services/batch_service/BatchListParameters.ts b/src/services/batch_service/BatchListParameters.ts new file mode 100644 index 000000000..1e7343515 --- /dev/null +++ b/src/services/batch_service/BatchListParameters.ts @@ -0,0 +1,6 @@ +import { IAllMethodParameters } from "../../utils/types"; + +/** + * @see https://www.easypost.com/docs/api/node#list-all-batches + */ +export type IBatchListParameters = IAllMethodParameters; diff --git a/types/Batch/BatchShipment.d.ts b/src/services/batch_service/BatchShipment.ts similarity index 86% rename from types/Batch/BatchShipment.d.ts rename to src/services/batch_service/BatchShipment.ts index 7c57eefe3..108c095f3 100644 --- a/types/Batch/BatchShipment.d.ts +++ b/src/services/batch_service/BatchShipment.ts @@ -1,9 +1,9 @@ -import { TBatchStatus } from './BatchStatus'; +import { TBatchStatus } from "./BatchStatus"; /** * @see https://www.easypost.com/docs/api/node#batch-shipment-object */ -export declare interface IBatchShipment { +export type IBatchShipment = { /** * The id of the Shipment. Unique, begins with "shp_" */ @@ -23,4 +23,4 @@ export declare interface IBatchShipment { * A human readable message for any errors that occurred during the Batch's life cycle */ batch_message: string; -} +}; diff --git a/src/services/batch_service/BatchState.ts b/src/services/batch_service/BatchState.ts new file mode 100644 index 000000000..02f0cfc0f --- /dev/null +++ b/src/services/batch_service/BatchState.ts @@ -0,0 +1,9 @@ +export type TBatchState = + | "creating" + | "creation_failed" + | "created" + | "purchasing" + | "purchase_failed" + | "purchased" + | "label_generating" + | "label_generated"; diff --git a/src/services/batch_service/BatchStatus.ts b/src/services/batch_service/BatchStatus.ts new file mode 100644 index 000000000..642a50231 --- /dev/null +++ b/src/services/batch_service/BatchStatus.ts @@ -0,0 +1,6 @@ +export type TBatchStatus = + | "postage_purchased" + | "postage_purchase_failed" + | "queued_for_purchase" + | "creation_failed" + | "created"; diff --git a/src/services/batch_service/BatchStatuses.ts b/src/services/batch_service/BatchStatuses.ts new file mode 100644 index 000000000..545cf0396 --- /dev/null +++ b/src/services/batch_service/BatchStatuses.ts @@ -0,0 +1,3 @@ +import { TBatchStatus } from "./BatchStatus"; + +export type TBatchStatuses = { [key in TBatchStatus]: number }; diff --git a/src/services/batch_service.js b/src/services/batch_service/index.ts similarity index 53% rename from src/services/batch_service.js rename to src/services/batch_service/index.ts index 5db04c49f..1a391bea8 100644 --- a/src/services/batch_service.js +++ b/src/services/batch_service/index.ts @@ -1,8 +1,20 @@ -import baseService from './base_service'; - -export const DEFAULT_LABEL_FORMAT = 'pdf'; - -export default (easypostClient) => +import EasyPost from "../.."; +import baseService from "../base_service"; +import { IBatch } from "./Batch"; +import { IBatchCreateParameters } from "./BatchCreateParameters"; +import { IBatchListParameters } from "./BatchListParameters"; + +export * from "./Batch"; +export * from "./BatchCreateParameters"; +export * from "./BatchListParameters"; +export * from "./BatchShipment"; +export * from "./BatchState"; +export * from "./BatchStatus"; +export * from "./BatchStatuses"; + +export const DEFAULT_LABEL_FORMAT = "pdf"; + +export default (easypostClient: EasyPost) => /** * The BatchService class provides methods for interacting with EasyPost {@link Batch} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -11,27 +23,27 @@ export default (easypostClient) => /** * Create a {@link Batch batch}. * See {@link https://www.easypost.com/docs/api/node#create-a-batch EasyPost API Documentation} for more information. - * @param {Object} params - Parameters for the batch to be created. - * @returns {Batch} - The created batch. + * @param params - Parameters for the batch to be created. + * @returns - The created batch. */ - static async create(params) { - const url = 'batches'; + static async create(params: IBatchCreateParameters) { + const url = "batches"; const wrappedParams = { batch: params, }; - return this._create(url, wrappedParams); + return this._create(url, wrappedParams); } /** * Add {@link Shipment shipments} to a {@link Batch batch}. * See {@link https://www.easypost.com/docs/api/node#add-shipments-to-a-batch EasyPost API Documentation} for more information. - * @param {string} id - The id of the batch to add shipments to. - * @param {Array} shipmentIds - The ids of the shipments to add to the batch. - * @returns {Batch} - The updated batch. + * @param id - The id of the batch to add shipments to. + * @param shipmentIds - The ids of the shipments to add to the batch. + * @returns - The updated batch. */ - static async addShipments(id, shipmentIds) { + static async addShipments(id: string, shipmentIds: string[]) { const url = `batches/${id}/add_shipments`; const wrappedParams = { shipments: shipmentIds.map((s) => ({ id: s })), @@ -39,7 +51,10 @@ export default (easypostClient) => try { const response = await easypostClient._post(url, wrappedParams); - return this._convertToEasyPostObject(response.body, wrappedParams); + return this._convertToEasyPostObject( + response.body, + wrappedParams + ); } catch (e) { return Promise.reject(e); } @@ -48,11 +63,11 @@ export default (easypostClient) => /** * Removes {@link Shipment shipments} from a {@link Batch batch}. * See {@link https://www.easypost.com/docs/api/node#remove-shipments-from-a-batch EasyPost API Documentation} for more information. - * @param {string} id - The id of the batch to remove shipments from. - * @param {Array} shipmentIds - The ids of the shipments to remove from the batch. - * @returns {Batch} - The updated batch. + * @param id - The id of the batch to remove shipments from. + * @param shipmentIds - The ids of the shipments to remove from the batch. + * @returns - The updated batch. */ - static async removeShipments(id, shipmentIds) { + static async removeShipments(id: string, shipmentIds: string[]) { const url = `batches/${id}/remove_shipments`; const wrappedParams = { shipments: shipmentIds.map((s) => ({ id: s })), @@ -61,7 +76,10 @@ export default (easypostClient) => try { const response = await easypostClient._post(url, wrappedParams); - return this._convertToEasyPostObject(response.body, wrappedParams); + return this._convertToEasyPostObject( + response.body, + wrappedParams + ); } catch (e) { return Promise.reject(e); } @@ -70,18 +88,21 @@ export default (easypostClient) => /** * Generate a label for a {@link Batch batch}. * See {@link https://www.easypost.com/docs/api/node#batch-labels EasyPost API Documentation} for more information. - * @param {string} id - The id of the batch to generate a label for. - * @param {string} fileFormat - The format of the label to generate. Defaults to 'pdf'. - * @returns {Batch} - The updated batch. + * @param id - The id of the batch to generate a label for. + * @param fileFormat - The format of the label to generate. Defaults to 'pdf'. + * @returns - The updated batch. */ - static async generateLabel(id, fileFormat = DEFAULT_LABEL_FORMAT) { + static async generateLabel(id: string, fileFormat = DEFAULT_LABEL_FORMAT) { const url = `batches/${id}/label`; const wrappedParams = { file_format: fileFormat }; try { const response = await easypostClient._post(url, wrappedParams); - return this._convertToEasyPostObject(response.body, wrappedParams); + return this._convertToEasyPostObject( + response.body, + wrappedParams + ); } catch (e) { return Promise.reject(e); } @@ -90,16 +111,16 @@ export default (easypostClient) => /** * Create a {@link ScanForm scan form} for a {@link Batch batch}. * See {@link https://www.easypost.com/docs/api/node#manifesting-scan-form EasyPost API Documentation} for more information. - * @param {string} id - The id of the batch to create a scan form for. - * @returns {Batch} - The updated batch. + * @param id - The id of the batch to create a scan form for. + * @returns - The updated batch. */ - static async createScanForm(id) { + static async createScanForm(id: string) { const url = `batches/${id}/scan_form`; try { const response = await easypostClient._post(url); - return this._convertToEasyPostObject(response.body); + return this._convertToEasyPostObject(response.body); } catch (e) { return Promise.reject(e); } @@ -108,16 +129,16 @@ export default (easypostClient) => /** * Purchase a {@link Batch batch}. * See {@link https://www.easypost.com/docs/api/node#buy-a-batch EasyPost API Documentation} for more information. - * @param {string} id - The id of the batch to purchase. - * @returns {Batch} - The purchased batch. + * @param id - The id of the batch to purchase. + * @returns - The purchased batch. */ - static async buy(id) { + static async buy(id: string) { const url = `batches/${id}/buy`; try { const response = await easypostClient._post(url); - return this._convertToEasyPostObject(response.body); + return this._convertToEasyPostObject(response.body); } catch (e) { return Promise.reject(e); } @@ -126,24 +147,24 @@ export default (easypostClient) => /** * Retrieve all {@link Batch batches} associated with the current authenticated user. * See {@link https://www.easypost.com/docs/api/node#list-all-batches EasyPost API Documentation} for more information. - * @param {Object} [params] - Parameters to filter the list of batches. - * @returns {Object} - An object containing a list of {@link Batch batches} and pagination information. + * @param [params] - Parameters to filter the list of batches. + * @returns - An object containing a list of {@link Batch batches} and pagination information. */ - static async all(params = {}) { - const url = 'batches'; + static async all(params: IBatchListParameters = {}) { + const url = "batches"; - return this._all(url, params); + return this._all(url, params); } /** * Retrieve a {@link Batch batch} by its ID. * See {@link https://www.easypost.com/docs/api/node#retrieve-batch EasyPost API Documentation} for more information. - * @param {string} id - The ID of the batch to retrieve. - * @returns {Batch} - The retrieved batch. + * @param id - The ID of the batch to retrieve. + * @returns - The retrieved batch. */ - static async retrieve(id) { + static async retrieve(id: string) { const url = `batches/${id}`; - return this._retrieve(url); + return this._retrieve(url); } }; diff --git a/src/services/beta_rate_service.js b/src/services/beta_rate_service.js deleted file mode 100644 index bca4f3bb7..000000000 --- a/src/services/beta_rate_service.js +++ /dev/null @@ -1,27 +0,0 @@ -import baseService from './base_service'; - -/** - * @extends baseService - */ -export default (easypostClient) => - class BetaRateService extends baseService(easypostClient) { - /** - * Retrieve a list of stateless {@link Rate rates} based on the provided parameters. - * @param {Object} params - Map of parameters for the API call - * @returns {Rate[]} - List of stateless rates - */ - static async retrieveStatelessRates(params) { - const url = 'beta/rates'; - const wrappedParams = { - shipment: params, - }; - - try { - const response = await easypostClient._post(url, wrappedParams); - - return this._convertToEasyPostObject(response.body.rates, wrappedParams); - } catch (e) { - return Promise.reject(e); - } - } - }; diff --git a/src/services/beta_rate_service/index.ts b/src/services/beta_rate_service/index.ts new file mode 100644 index 000000000..2693ee5d1 --- /dev/null +++ b/src/services/beta_rate_service/index.ts @@ -0,0 +1,32 @@ +import EasyPost from "../.."; +import baseService from "../base_service"; +import { IRate } from "../rate_service/Rate"; + +/** + * @extends baseService + */ +export default (easypostClient: EasyPost) => + class BetaRateService extends baseService(easypostClient) { + /** + * Retrieve a list of stateless {@link Rate rates} based on the provided parameters. + * @param params - Map of parameters for the API call + * @returns - List of stateless rates + */ + static async retrieveStatelessRates(params: any) { + const url = "beta/rates"; + const wrappedParams = { + shipment: params, + }; + + try { + const response = await easypostClient._post(url, wrappedParams); + + return this._convertToEasyPostObject( + response.body.rates, + wrappedParams + ); + } catch (e) { + return Promise.reject(e); + } + } + }; diff --git a/src/services/beta_referral_customer_service.js b/src/services/beta_referral_customer_service.js deleted file mode 100644 index a7f8c74dc..000000000 --- a/src/services/beta_referral_customer_service.js +++ /dev/null @@ -1,61 +0,0 @@ -import baseService from './base_service'; - -export default (easypostClient) => - class BetaReferralCustomerService extends baseService(easypostClient) { - /** - * Add an existing Stripe payment method to a {@link User referral customer's} account. - * @param {string} stripeCustomerId - The Stripe account's ID. - * @param {string} paymentMethodReference - Reference of Stripe payment method. - * @param {string} [priority] - Which priority to set the payment method to ('primary' or 'secondary'). - * @returns {Object} - A JSON object representing the payment method. - */ - static async addPaymentMethod(stripeCustomerId, paymentMethodReference, priority = 'primary') { - const wrappedParams = { - payment_method: { - stripe_customer_id: stripeCustomerId, - payment_method_reference: paymentMethodReference, - priority, - }, - }; - - const url = 'beta/referral_customers/payment_method'; - - const response = await easypostClient._post(url, wrappedParams); - - return response; - } - - /** - * Refund by amount for a recent payment. - * @param {number} refundAmount - Amount to be refunded by cents. - * @returns {Object} - A JSON object representing the refund. - */ - static async refundByAmount(refundAmount) { - const params = { - refund_amount: refundAmount, - }; - - const url = 'beta/referral_customers/refunds'; - - const response = await easypostClient._post(url, params); - - return response; - } - - /** - * Refund a payment by a payment log ID. - * @param {string} paymentLogId - ID of the payment log. - * @returns {object} - Returns BetaPaymentRefund object. - */ - static async refundByPaymentLog(paymentLogId) { - const params = { - payment_log_id: paymentLogId, - }; - - const url = 'beta/referral_customers/refunds'; - - const response = await easypostClient._post(url, params); - - return response; - } - }; diff --git a/src/services/beta_referral_customer_service/index.ts b/src/services/beta_referral_customer_service/index.ts new file mode 100644 index 000000000..836e9223a --- /dev/null +++ b/src/services/beta_referral_customer_service/index.ts @@ -0,0 +1,68 @@ +import EasyPost from "../.."; +import baseService from "../base_service"; +import { IPaymentMethod } from "../billing_service"; +import { IRefund } from "../refund_service"; + +export default (easypostClient: EasyPost) => + class BetaReferralCustomerService extends baseService(easypostClient) { + /** + * Add an existing Stripe payment method to a {@link User referral customer's} account. + * @param stripeCustomerId - The Stripe account's ID. + * @param paymentMethodReference - Reference of Stripe payment method. + * @param [priority] - Which priority to set the payment method to ('primary' or 'secondary'). + * @returns - A JSON object representing the payment method. + */ + static async addPaymentMethod( + stripeCustomerId: string, + paymentMethodReference: string, + priority: "primary" | "secondary" = "primary" + ) { + const wrappedParams = { + payment_method: { + stripe_customer_id: stripeCustomerId, + payment_method_reference: paymentMethodReference, + priority, + }, + }; + + const url = "beta/referral_customers/payment_method"; + + const response = await easypostClient._post(url, wrappedParams); + + return response as any as IPaymentMethod; + } + + /** + * Refund by amount for a recent payment. + * @param refundAmount - Amount to be refunded by cents. + * @returns - A JSON object representing the refund. + */ + static async refundByAmount(refundAmount: number) { + const params = { + refund_amount: refundAmount, + }; + + const url = "beta/referral_customers/refunds"; + + const response = await easypostClient._post(url, params); + + return response as any as IRefund; + } + + /** + * Refund a payment by a payment log ID. + * @param paymentLogId - ID of the payment log. + * @returns - Returns BetaPaymentRefund object. + */ + static async refundByPaymentLog(paymentLogId: string) { + const params = { + payment_log_id: paymentLogId, + }; + + const url = "beta/referral_customers/refunds"; + + const response = await easypostClient._post(url, params); + + return response; + } + }; diff --git a/types/PaymentMethod/PaymentMethod.d.ts b/src/services/billing_service/PaymentMethod.ts similarity index 64% rename from types/PaymentMethod/PaymentMethod.d.ts rename to src/services/billing_service/PaymentMethod.ts index 245992faf..8211a7fcd 100644 --- a/types/PaymentMethod/PaymentMethod.d.ts +++ b/src/services/billing_service/PaymentMethod.ts @@ -1,11 +1,11 @@ -import { IObjectWithId } from '../base'; +import { IObjectWithId } from "../../utils/types"; /** * The Payment method object can be either credit card or bank account. * * TODO: Add the link to the API doc once its updated */ -export declare interface IPaymentMethod extends IObjectWithId<'PaymentMethod'> { +export type IPaymentMethod = IObjectWithId<"PaymentMethod"> & { /** * Country of the bank account */ @@ -50,19 +50,4 @@ export declare interface IPaymentMethod extends IObjectWithId<'PaymentMethod'> { * Whether the bank account is verified or not */ verified: boolean; -} - -export declare class PaymentMethod implements IPaymentMethod { - id: string; - mode: 'test' | 'production'; - object: 'PaymentMethod'; - country: string; - bank_name: string; - brand: string; - disabled_at: string; - exp_month: number; - exp_year: number; - last4: string; - name: string; - verified: boolean; -} +}; diff --git a/src/services/billing_service.js b/src/services/billing_service/index.ts similarity index 64% rename from src/services/billing_service.js rename to src/services/billing_service/index.ts index 6807fdd05..c188a0fe6 100644 --- a/src/services/billing_service.js +++ b/src/services/billing_service/index.ts @@ -1,8 +1,12 @@ -import Constants from '../constants'; -import InvalidObjectError from '../errors/general/invalid_object_error'; -import baseService from './base_service'; +import EasyPost from "../.."; +import Constants from "../../constants"; +import InvalidObjectError from "../../errors/general/invalid_object_error"; +import baseService from "../base_service"; -export default (easypostClient) => +export * from "./PaymentMethod"; +export type Priority = "primary" | "secondary"; + +export default (easypostClient: EasyPost) => /** * The BillingService class provides methods for interacting with EasyPost's billing capabilities. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -11,11 +15,13 @@ export default (easypostClient) => /** * Fund your EasyPost wallet by charging your primary or secondary payment method on file. * See {@link https://www.easypost.com/docs/api/node#add-funds-to-your-wallet-one-time-charge EasyPost API Documentation} for more information. - * @param {String} amount - The amount to charge to your payment method. - * @param {String} priority - The priority of the payment method to charge. Can be either 'primary' or 'secondary'. + * @param amount - The amount to charge to your payment method. + * @param priority - The priority of the payment method to charge. Can be either 'primary' or 'secondary'. */ - static async fundWallet(amount, priority = 'primary') { - const paymentInfo = await this._getPaymentInfo(priority.toLowerCase()); + static async fundWallet(amount: string, priority: Priority = "primary") { + const paymentInfo = await this._getPaymentInfo( + priority.toLowerCase() as Priority + ); const endpoint = paymentInfo[0]; const paymentMethodID = paymentInfo[1]; @@ -28,10 +34,12 @@ export default (easypostClient) => /** * Delete a payment method from the current authenticated user's account. * See {@link https://www.easypost.com/docs/api/node#delete-a-payment-method EasyPost API Documentation} for more information. - * @param {String} priority - The priority of the payment method to delete. Can be either 'primary' or 'secondary'. + * @param priority - The priority of the payment method to delete. Can be either 'primary' or 'secondary'. */ - static async deletePaymentMethod(priority) { - const paymentInfo = await this._getPaymentInfo(priority.toLowerCase()); + static async deletePaymentMethod(priority: Priority) { + const paymentInfo = await this._getPaymentInfo( + priority.toLowerCase() as Priority + ); const endpoint = paymentInfo[0]; const paymentMethodID = paymentInfo[1]; @@ -46,7 +54,7 @@ export default (easypostClient) => * @returns {Object} - An object containing the payment methods associated with the current authenticated user. */ static async retrievePaymentMethods() { - const url = 'payment_methods'; + const url = "payment_methods"; const res = await easypostClient._get(url); @@ -64,26 +72,28 @@ export default (easypostClient) => * @param {String} priority - The priority of the payment method to retrieve. Can be either 'primary' or 'secondary'. * @returns {string[]} - An array of two strings, the first being the endpoint of the payment method and the second being the ID of the payment method. */ - static async _getPaymentInfo(priority) { + static async _getPaymentInfo(priority: Priority) { const paymentMethods = await this.retrievePaymentMethods(); const paymentMethodMap = { - primary: 'primary_payment_method', - secondary: 'secondary_payment_method', + primary: "primary_payment_method", + secondary: "secondary_payment_method", }; const paymentMethodToUse = paymentMethodMap[priority]; let paymentMethodID; - let paymentMethodObjectType; let endpoint; - const errorString = 'The chosen payment method is not valid. Please try again.'; + const errorString = + "The chosen payment method is not valid. Please try again."; - if (paymentMethodToUse !== undefined && paymentMethods[paymentMethodToUse] !== null) { + if ( + paymentMethodToUse !== undefined && + paymentMethods[paymentMethodToUse] !== null + ) { paymentMethodID = paymentMethods[paymentMethodToUse].id; - paymentMethodObjectType = paymentMethods[paymentMethodToUse].object; - if (paymentMethodObjectType === 'CreditCard') { - endpoint = 'credit_cards'; - } else if (paymentMethodObjectType === 'BankAccount') { - endpoint = 'bank_accounts'; + if (paymentMethodID.startsWith("card_")) { + endpoint = "credit_cards"; + } else if (paymentMethodID.startsWith("bank_")) { + endpoint = "bank_accounts"; } else { throw new InvalidObjectError({ message: errorString }); } diff --git a/src/services/carrier_account_service/CarrierAccount.ts b/src/services/carrier_account_service/CarrierAccount.ts new file mode 100644 index 000000000..e42a80211 --- /dev/null +++ b/src/services/carrier_account_service/CarrierAccount.ts @@ -0,0 +1,63 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { ICarrierAccountCreateParameters } from "./CarrierAccountCreateParameters"; +import { ICarrierAccountFields } from "./CarrierAccountFields"; + +/** + * A CarrierAccount encapsulates your credentials with the carrier. + * The CarrierAccount object provides CRUD operations for all CarrierAccounts. + * + * Each EasyPost account is automatically provided a USPS account managed by EasyPost. + * + * Other operations, such as Shipment creation, can reference CarrierAccounts to reduce the scope of data returned. + * For instance, you may have multiple warehouses that need to use distinct FedEx SmartPost credentials to request the correct rates. + * Rate objects will include a `carrier_account_id` field which can be used to determine the account used for rating. + * + * @see https://www.easypost.com/docs/api/node#carrier-account-object + */ +export type ICarrierAccount = IObjectWithId<"CarrierAccount"> & + IDatedObject & { + /** + * The name of the carrier type. + */ + type: string; + + /** + * Contains "credentials" and/or "test_credentials", or may be empty + */ + fields: ICarrierAccountFields; + + /** + * If clone is true, only the reference and description are possible to update + */ + clone?: boolean | null; + + /** + * An optional, user-readable field to help distinguish accounts + */ + description?: string | null; + + /** + * An optional field that may be used in place of carrier_account_id in other API endpoints + */ + reference?: string | null; + + /** + * The name used when displaying a readable value for the type of the account + */ + readable: string; + + /** + * Unlike the "credentials" object contained in "fields", this nullable object contains just raw credential pairs for client library consumption + */ + credentials?: object | null; + + /** + * Unlike the "test_credentials" object contained in "fields", this nullable object contains just raw test_credential pairs for client library consumption + */ + test_credentials?: object | null; + + /** + * Billing type of the carrier account + */ + billing_type: string | null; + }; diff --git a/src/services/carrier_account_service/CarrierAccountCreateParameters.ts b/src/services/carrier_account_service/CarrierAccountCreateParameters.ts new file mode 100644 index 000000000..7891ae539 --- /dev/null +++ b/src/services/carrier_account_service/CarrierAccountCreateParameters.ts @@ -0,0 +1,7 @@ +import { ParametersToOmitOnCreate } from "../../utils/types"; +import { ICarrierAccount } from "./CarrierAccount"; + +export type ICarrierAccountCreateParameters = Omit< + ICarrierAccount, + ParametersToOmitOnCreate +>; diff --git a/types/Carrier/CarrierAccount/CarrierAccountField.d.ts b/src/services/carrier_account_service/CarrierAccountField.ts similarity index 92% rename from types/Carrier/CarrierAccount/CarrierAccountField.d.ts rename to src/services/carrier_account_service/CarrierAccountField.ts index b2170dcba..3e54fd44d 100644 --- a/types/Carrier/CarrierAccount/CarrierAccountField.d.ts +++ b/src/services/carrier_account_service/CarrierAccountField.ts @@ -1,7 +1,7 @@ /** * @see https://www.easypost.com/docs/api/node#carrier-account-field-object */ -export declare interface ICarrierAccountField { +export type ICarrierAccountField = { /** * Each key in the sub-objects of a CarrierAccount's fields is the name of a settable field */ @@ -21,4 +21,4 @@ export declare interface ICarrierAccountField { * Checkbox fields use "0" and "1" as False and True, all other field types present plaintext, partly-masked, or masked credential data for reference */ value: string; -} +}; diff --git a/types/Carrier/CarrierAccount/CarrierAccountFields.d.ts b/src/services/carrier_account_service/CarrierAccountFields.ts similarity index 82% rename from types/Carrier/CarrierAccount/CarrierAccountFields.d.ts rename to src/services/carrier_account_service/CarrierAccountFields.ts index f7922f954..c7c21b04f 100644 --- a/types/Carrier/CarrierAccount/CarrierAccountFields.d.ts +++ b/src/services/carrier_account_service/CarrierAccountFields.ts @@ -1,9 +1,9 @@ -import { ICarrierAccountField } from './CarrierAccountField'; +import { ICarrierAccountField } from "./CarrierAccountField"; /** * @see https://www.easypost.com/docs/api/node#carrier-account-fields-object */ -export declare interface ICarrierAccountFields { +export type ICarrierAccountFields = { /** * Credentials used in the production environment. */ @@ -23,4 +23,4 @@ export declare interface ICarrierAccountFields { * When present, a separate authentication process will be required through the UI to link this account type. */ custom_workflow: boolean; -} +}; diff --git a/src/services/carrier_account_service.js b/src/services/carrier_account_service/index.ts similarity index 52% rename from src/services/carrier_account_service.js rename to src/services/carrier_account_service/index.ts index 71a25560a..87a47b3bb 100644 --- a/src/services/carrier_account_service.js +++ b/src/services/carrier_account_service/index.ts @@ -1,10 +1,17 @@ -import baseService from './base_service'; -import Constants from '../constants'; -import InvalidParameterError from '../errors/general/invalid_parameter_error'; - -const util = require('util'); - -export default (easypostClient) => +import util from "node:util"; +import baseService from "../base_service"; +import Constants from "../../constants"; +import InvalidParameterError from "../../errors/general/invalid_parameter_error"; +import EasyPost from "../.."; +import { ICarrierAccount } from "./CarrierAccount"; +import { ICarrierAccountCreateParameters } from "./CarrierAccountCreateParameters"; + +export * from "./CarrierAccount"; +export * from "./CarrierAccountCreateParameters"; +export * from "./CarrierAccountField"; +export * from "./CarrierAccountFields"; + +export default (easypostClient: EasyPost) => /** * The CarrierAccountService class provides methods for interacting with EasyPost @{link CarrierAccount} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -13,33 +20,40 @@ export default (easypostClient) => /** * Create a {@link CarrierAccount carrier account}. * See {@link https://www.easypost.com/docs/api/node#create-a-carrier-account EasyPost API Documentation} for more information. - * @param {Object} params - Parameters for the carrier account to be created. - * @returns {CarrierAccount} - The created carrier account. + * @param params - Parameters for the carrier account to be created. + * @returns - The created carrier account. */ - static async create(params) { + static async create(params: ICarrierAccountCreateParameters) { const carrierAccountType = params.type; if (!carrierAccountType) { throw new InvalidParameterError({ - message: util.format(Constants.MISSING_REQUIRED_PARAMETER, 'CarrierAccount type'), + message: util.format( + Constants.MISSING_REQUIRED_PARAMETER, + "CarrierAccount type" + ), }); } - const endpoint = this._selectCarrierAccountCreationEndpoint(carrierAccountType); + const endpoint = + this._selectCarrierAccountCreationEndpoint(carrierAccountType); const wrappedParams = { carrier_account: params }; - return this._create(endpoint, wrappedParams); + return this._create(endpoint, wrappedParams); } /** * Update a {@link CarrierAccount carrier account}. * See {@link https://www.easypost.com/docs/api/node#update-a-carrieraccount EasyPost API Documentation} for more information. - * @param {string} id - The id of the carrier account to be updated. - * @param {Object} params - Parameters for the carrier account to be updated. - * @returns {CarrierAccount} - The updated carrier account. + * @param id - The id of the carrier account to be updated. + * @param params - Parameters for the carrier account to be updated. + * @returns - The updated carrier account. */ - static async update(id, params) { + static async update( + id: string, + params: Partial + ) { const url = `carrier_accounts/${id}`; const wrappedParams = { carrier_account: params, @@ -48,7 +62,10 @@ export default (easypostClient) => try { const response = await easypostClient._patch(url, wrappedParams); - return this._convertToEasyPostObject(response.body, wrappedParams); + return this._convertToEasyPostObject( + response.body, + wrappedParams + ); } catch (e) { return Promise.reject(e); } @@ -57,10 +74,10 @@ export default (easypostClient) => /** * Delete a {@link CarrierAccount carrier account}. * See {@link https://www.easypost.com/docs/api/node#delete-a-carrier-account EasyPost API Documentation} for more information. - * @param {string} id - The id of the carrier account to be deleted. - * @returns {Promise|Promise} - A promise that resolves when the carrier account has been deleted. + * @param id - The id of the carrier account to be deleted. + * @returns - A promise that resolves when the carrier account has been deleted. */ - static async delete(id) { + static async delete(id: string) { const url = `carrier_accounts/${id}`; try { @@ -78,34 +95,38 @@ export default (easypostClient) => * @param {string} carrierAccountType - The type of carrier account to be created. * @returns {string} - The endpoint to be used for the carrier account creation request. */ - static _selectCarrierAccountCreationEndpoint(carrierAccountType) { - if (Constants.CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS.includes(carrierAccountType)) { - return 'carrier_accounts/register'; + static _selectCarrierAccountCreationEndpoint(carrierAccountType: string) { + if ( + Constants.CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS.includes( + carrierAccountType + ) + ) { + return "carrier_accounts/register"; } - return 'carrier_accounts'; + return "carrier_accounts"; } /** * Retrieve all {@link CarrierAccount carrier accounts} associated with the current authenticated user. * See {@link https://www.easypost.com/docs/api/node#list-all-carrier-accounts EasyPost API Documentation} for more information. - * @param {Object} [params] - Parameters to filter the list of carrier accounts. - * @returns {Object} - An object containing a list of {@link CarrierAccount carrier accounts} and pagination information. + * @param [params] - Parameters to filter the list of carrier accounts. + * @returns - An object containing a list of {@link CarrierAccount carrier accounts} and pagination information. */ static async all(params = {}) { - const url = 'carrier_accounts'; + const url = "carrier_accounts"; - return this._all(url, params); + return this._all(url, params); } /** * Retrieve a {@link CarrierAccount carrier account} by its ID. * See {@link https://www.easypost.com/docs/api/node#retrieve-a-carrieraccount EasyPost API Documentation} for more information. - * @param {string} id - The ID of the carrier account to retrieve. - * @returns {CarrierAccount} - The retrieved carrier account. + * @param id - The ID of the carrier account to retrieve. + * @returns - The retrieved carrier account. */ - static async retrieve(id) { + static async retrieve(id: string) { const url = `carrier_accounts/${id}`; - return this._retrieve(url); + return this._retrieve(url); } }; diff --git a/src/services/carrier_metadata_service.js b/src/services/carrier_metadata_service.js deleted file mode 100644 index 13a4ba81e..000000000 --- a/src/services/carrier_metadata_service.js +++ /dev/null @@ -1,28 +0,0 @@ -import baseService from './base_service'; - -/** - * @extends baseService - */ -export default (easypostClient) => - class CarrierMetadataService extends baseService(easypostClient) { - /** - * Retrieve a list of carrier metadata based on the provided parameters. - * @param {Array} carriers - List of carrier in string - * @param {Array} type - List of types in string - * @returns {Object[]} - List of carrier metadata - */ - static async retrieve(carriers = null, types = null) { - const url = 'metadata/carriers'; - const params = { - ...(carriers && carriers.length > 0 && { carriers: carriers.join(',') }), - ...(types && types.length > 0 && { types: types.join(',') }), - }; - - try { - const response = await easypostClient._get(url, params); - return this._convertToEasyPostObject(response.body.carriers || [], params); - } catch (e) { - return Promise.reject(e); - } - } - }; diff --git a/types/Carrier/CarrierMetadata/CarrierMetadata.d.ts b/src/services/carrier_metadata_service/CarrierMetadata.ts similarity index 52% rename from types/Carrier/CarrierMetadata/CarrierMetadata.d.ts rename to src/services/carrier_metadata_service/CarrierMetadata.ts index fb74d8f2c..155bad93f 100644 --- a/types/Carrier/CarrierMetadata/CarrierMetadata.d.ts +++ b/src/services/carrier_metadata_service/CarrierMetadata.ts @@ -6,7 +6,7 @@ * * @see https://www.easypost.com/docs/api/node#carriermetadata-object */ -export declare interface ICarrierMetadata { +export type ICarrierMetadata = { /** * The single-word name of a carrier such as "royalmail" */ @@ -36,26 +36,4 @@ export declare interface ICarrierMetadata { * A list of shipment option objects for this carrier */ shipment_options?: Array | null; -} - -export declare class CarrierMetadata implements ICarrierMetadata { - carrier: string; - human_readable?: string | null; - service_levels?: Array | null; - predefined_packages?: Array | null; - supported_features?: Array | null; - shipment_options?: Array | null; - - /** - * Retrieve all Carrier Metadata for all carriers on the EasyPost platform. Optionally, - * filter the response by specifying a list of carriers or metadata types. - * - * @param {Array} carriers A comma-delimited list of single-word carriers you'd like to filter the response by - * @param {Array} types A comma-delimited list of the metadata types you'd like to filter the response by - * - * @see https://www.easypost.com/docs/api/node#retrieve-carrier-metadata - * - * @returns {Promise} The {@link CarrierMetadata} object. - */ - static retrieve(carriers: Array, types: Array): Promise; -} +}; diff --git a/src/services/carrier_metadata_service/index.ts b/src/services/carrier_metadata_service/index.ts new file mode 100644 index 000000000..5179cfc06 --- /dev/null +++ b/src/services/carrier_metadata_service/index.ts @@ -0,0 +1,36 @@ +import EasyPost from "../.."; +import baseService from "../base_service"; +import { ICarrierMetadata } from "./CarrierMetadata"; + +export * from "./CarrierMetadata"; + +export default (easypostClient: EasyPost) => + class CarrierMetadataService extends baseService(easypostClient) { + /** + * Retrieve a list of carrier metadata based on the provided parameters. + * @param carriers - List of carrier in string + * @param type - List of types in string + * @returns - List of carrier metadata + */ + static async retrieve( + carriers: string[] | null = null, + types: string[] | null = null + ) { + const url = "metadata/carriers"; + const params = { + ...(carriers && + carriers.length > 0 && { carriers: carriers.join(",") }), + ...(types && types.length > 0 && { types: types.join(",") }), + }; + + try { + const response = await easypostClient._get(url, params); + return this._convertToEasyPostObject( + response.body.carriers || [], + params + ); + } catch (e) { + return Promise.reject(e); + } + } + }; diff --git a/src/services/carrier_type_service.js b/src/services/carrier_type_service.js deleted file mode 100644 index cad3e3ddf..000000000 --- a/src/services/carrier_type_service.js +++ /dev/null @@ -1,26 +0,0 @@ -import baseService from './base_service'; - -export default (easypostClient) => - /** - * The CarrierTypeService class provides methods for interacting with EasyPost {@link CarrierType} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - class CarrierTypeService extends baseService(easypostClient) { - /** - * Retrieve all {@link CarrierType carrier types} available to the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-available-carrier-types EasyPost API Documentation} for more information. - * @param {Object} [params] - Parameters to filter the list of carrier types. - * @returns {CarrierType[]} - A list of {@link CarrierType carrier types}. - */ - static async all(params = {}) { - const url = 'carrier_types'; - - try { - const response = await easypostClient._get(url, params); - - return this._convertToEasyPostObject(response.body, params); - } catch (e) { - return Promise.reject(e); - } - } - }; diff --git a/types/Carrier/CarrierType/CarrierType.d.ts b/src/services/carrier_type_service/CarrierType.ts similarity index 69% rename from types/Carrier/CarrierType/CarrierType.d.ts rename to src/services/carrier_type_service/CarrierType.ts index 347b33437..fa8156eee 100644 --- a/types/Carrier/CarrierType/CarrierType.d.ts +++ b/src/services/carrier_type_service/CarrierType.ts @@ -1,5 +1,5 @@ -import { IBaseObject } from '../../base'; -import { ICarrierTypeFields } from './CarrierTypeFields'; +import { IBaseObject } from "../../utils/types"; +import { ICarrierTypeFields } from "./CarrierTypeFields"; /** * The CarrierType object provides an export declare interface for determining the valid fields of a CarrierAccount. @@ -16,7 +16,7 @@ import { ICarrierTypeFields } from './CarrierTypeFields'; * * @see https://www.easypost.com/docs/api/node#carrier-type-object */ -export declare interface ICarrierType extends IBaseObject<'CarrierType'> { +export type ICarrierType = IBaseObject<"CarrierType"> & { /** * Specifies the CarrierAccount type. */ @@ -26,20 +26,4 @@ export declare interface ICarrierType extends IBaseObject<'CarrierType'> { * Contains at least one of the following keys: "auto_link", "credentials", "test_credentials", and "custom_workflow" */ fields: ICarrierTypeFields; -} - -export declare class CarrierType implements ICarrierType { - type: string; - fields: ICarrierTypeFields; - object: 'CarrierType'; - - /** - * The CarrierType list is an unpaginated list of all carrier types available to the account of the given API key. - * - * @see https://www.easypost.com/docs/api/node#retrieve-available-carrier-types - * @requires production API Key. - * - * @returns {Object} - An object containing a list of {@link CarrierType carrier types}. - */ - static all(): Promise; -} +}; diff --git a/types/Carrier/CarrierType/CarrierTypeCredentials.d.ts b/src/services/carrier_type_service/CarrierTypeCredentials.ts similarity index 82% rename from types/Carrier/CarrierType/CarrierTypeCredentials.d.ts rename to src/services/carrier_type_service/CarrierTypeCredentials.ts index ba47cfb1f..2e8725d34 100644 --- a/types/Carrier/CarrierType/CarrierTypeCredentials.d.ts +++ b/src/services/carrier_type_service/CarrierTypeCredentials.ts @@ -1,7 +1,7 @@ /** * @see https://www.easypost.com/docs/api/node#carrier-type-credentials-object */ -export declare interface ICarrierTypeCredentials { +export type ICarrierTypeCredentials = { /** * The key for each attribute sub-object within credentials is the name of the attribute for submission on CarrierAccounts */ @@ -10,10 +10,10 @@ export declare interface ICarrierTypeCredentials { /** * There are five possible values, which encode the security need and storage type for each attribute: "visible", "checkbox", "fake", "password", and "masked" */ - visibility: 'visible' | 'checkbox' | 'fake' | 'password' | 'masked'; + visibility: "visible" | "checkbox" | "fake" | "password" | "masked"; /** * Most attributes have generic names, so for clarity a "label" value is provided for clearer representation when rendering forms */ label: string; -} +}; diff --git a/types/Carrier/CarrierType/CarrierTypeFields.d.ts b/src/services/carrier_type_service/CarrierTypeFields.ts similarity index 88% rename from types/Carrier/CarrierType/CarrierTypeFields.d.ts rename to src/services/carrier_type_service/CarrierTypeFields.ts index fea487750..386047506 100644 --- a/types/Carrier/CarrierType/CarrierTypeFields.d.ts +++ b/src/services/carrier_type_service/CarrierTypeFields.ts @@ -1,9 +1,9 @@ -import { ICarrierTypeCredentials } from './CarrierTypeCredentials'; +import { ICarrierTypeCredentials } from "./CarrierTypeCredentials"; /** * @see https://www.easypost.com/docs/api/node#carrier-type-fields-object */ -export declare interface ICarrierTypeFields { +export type ICarrierTypeFields = { /** * If this key is present with the value of true, no other attributes are needed for CarrierAccount creation */ @@ -24,4 +24,4 @@ export declare interface ICarrierTypeFields { * It is not required for CarrierAccount creation if you do not plan on using the carrier account for test mode */ test_credentials: ICarrierTypeCredentials; -} +}; diff --git a/src/services/carrier_type_service/index.ts b/src/services/carrier_type_service/index.ts new file mode 100644 index 000000000..5343c55de --- /dev/null +++ b/src/services/carrier_type_service/index.ts @@ -0,0 +1,35 @@ +import EasyPost from "../.."; +import baseService from "../base_service"; +import { ICarrierType } from "./CarrierType"; + +export * from "./CarrierType"; +export * from "./CarrierTypeCredentials"; +export * from "./CarrierTypeFields"; + +export default (easypostClient: EasyPost) => + /** + * The CarrierTypeService class provides methods for interacting with EasyPost {@link CarrierType} objects. + * @param easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + class CarrierTypeService extends baseService(easypostClient) { + /** + * Retrieve all {@link CarrierType carrier types} available to the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-available-carrier-types EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of carrier types. + * @returns - A list of {@link CarrierType carrier types}. + */ + static async all(params = {}) { + const url = "carrier_types"; + + try { + const response = await easypostClient._get(url, params); + + return this._convertToEasyPostObject( + response.body, + params + ); + } catch (e) { + return Promise.reject(e); + } + } + }; diff --git a/src/services/customs_info_service/CustomsInfo.ts b/src/services/customs_info_service/CustomsInfo.ts new file mode 100644 index 000000000..2ea4fffde --- /dev/null +++ b/src/services/customs_info_service/CustomsInfo.ts @@ -0,0 +1,70 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { ICustomsItem } from "../customs_item_service"; + +/** + * CustomsInfo objects contain CustomsItem objects and all necessary information for the generation of customs forms required for international shipping. + * + * Please see the Shipments documentation for examples of including a CustomsInfo object in a shipment. + * + * @see https://www.easypost.com/docs/api/node#customs-info-object + */ +export type ICustomsInfo = IObjectWithId<"CustomsInfo"> & + IDatedObject & { + /** + * "EEL" or "PFC" + * value less than $2500: "NOEEI 30.37(a)" + * value greater than $2500: see [Customs Guide](https://www.easypost.com/customs-guide) + */ + eel_pfc?: string | null; + + /** + * "documents", "gift", "merchandise", "returned_goods", "sample", or "other" + */ + contents_type?: string | null; + + /** + * (max 255 characters) Human readable description of content. + * Required for certain carriers and always required if contents_type is "other" + */ + contents_explanation?: string | null; + + /** + * Electronically certify the information provided + */ + customs_certify?: boolean | null; + + /** + * Required if customs_certify is true + */ + customs_signer?: string | null; + + /** + * "abandon" or "return", defaults to "return" + */ + non_delivery_option?: "abandon" | "return" | null; + + /** + * "none", "other", "quarantine", or "sanitary_phytosanitary_inspection" + */ + restriction_type?: + | "none" + | "other" + | "quarantine" + | "sanitary_phytosanitary_inspection" + | null; + + /** + * Required if restriction_type is not "none" + */ + restriction_comments?: string | null; + + /** + * Describes the products being shipped + */ + customs_items: ICustomsItem[]; + + /** + * A customs declaration message, available for eligible carriers + */ + declaration?: string | null; + }; diff --git a/src/services/customs_info_service/CustomsInfoCreateParameters.ts b/src/services/customs_info_service/CustomsInfoCreateParameters.ts new file mode 100644 index 000000000..9fb83e1d7 --- /dev/null +++ b/src/services/customs_info_service/CustomsInfoCreateParameters.ts @@ -0,0 +1,7 @@ +import { ParametersToOmitOnCreate } from "../../utils/types"; +import { ICustomsInfo } from "./CustomsInfo"; + +export type ICustomsInfoCreateParameters = Omit< + ICustomsInfo, + ParametersToOmitOnCreate +>; diff --git a/src/services/customs_info_service.js b/src/services/customs_info_service/index.ts similarity index 52% rename from src/services/customs_info_service.js rename to src/services/customs_info_service/index.ts index 0c36e56a7..dae448388 100644 --- a/src/services/customs_info_service.js +++ b/src/services/customs_info_service/index.ts @@ -1,6 +1,12 @@ -import baseService from './base_service'; +import EasyPost from "../.."; +import baseService from "../base_service"; +import { ICustomsInfo } from "./CustomsInfo"; +import { ICustomsInfoCreateParameters } from "./CustomsInfoCreateParameters"; -export default (easypostClient) => +export * from "./CustomsInfo"; +export * from "./CustomsInfoCreateParameters"; + +export default (easypostClient: EasyPost) => /** * The CustomsInfoService class provides methods for interacting with EasyPost {@link CustomsInfo} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -9,28 +15,28 @@ export default (easypostClient) => /** * Create a {@link CustomsInfo customs info} record. * See {@link https://www.easypost.com/docs/api/node#create-a-customsinfo EasyPost API Documentation} for more information. - * @param {Object} params - Parameters for the customs info to be created. - * @returns {CustomsInfo} - The created customs info. + * @param params - Parameters for the customs info to be created. + * @returns - The created customs info. */ - static async create(params) { - const url = 'customs_infos'; + static async create(params: ICustomsInfoCreateParameters) { + const url = "customs_infos"; const wrappedParams = { customs_info: params, }; - return this._create(url, wrappedParams); + return this._create(url, wrappedParams); } /** * Retrieve a {@link CustomsInfo customs info} record by its ID. * See {@link https://www.easypost.com/docs/api/node#retrieve-a-customsinfo EasyPost API Documentation} for more information. - * @param {string} id - The ID of the customs info to retrieve. - * @returns {CustomsInfo} - The retrieved customs info. + * @param id - The ID of the customs info to retrieve. + * @returns - The retrieved customs info. */ - static async retrieve(id) { + static async retrieve(id: string) { const url = `customs_infos/${id}`; - return this._retrieve(url); + return this._retrieve(url); } }; diff --git a/src/services/customs_item_service/CustomsItem.ts b/src/services/customs_item_service/CustomsItem.ts new file mode 100644 index 000000000..8dd543fb0 --- /dev/null +++ b/src/services/customs_item_service/CustomsItem.ts @@ -0,0 +1,55 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { ICustomsItemCreateParameters } from "./CustomsItemCreateParameters"; + +/** + * A CustomsItem object describes goods for international shipment and should be created then included in a CustomsInfo object. + * + * @see https://www.easypost.com/docs/api/node#customs-item-object + */ +export type ICustomsItem = IObjectWithId<"CustomsItem"> & + IDatedObject & { + /** + * Required, description of item being shipped + */ + description: string; + + /** + * Required, greater than zero + * float + */ + quantity: number; + + /** + * Required, greater than zero, total value (unit value * quantity) + * float (USD) + */ + value: number; + + /** + * Required, greater than zero, total weight (unit weight * quantity) + * float (oz) + */ + weight: number; + + /** + * Harmonized Tariff Schedule, e.g. "6109.10.0012" for Men's T-shirts + * + * @see https://hts.usitc.gov/ + */ + hs_tariff_number?: string | null; + + /** + * SKU/UPC or other product identifier + */ + code?: string | null; + + /** + * Required, 2 char country code + */ + origin_country: string; + + /** + * 3 char currency code, default USD + */ + currency?: string | null; + }; diff --git a/src/services/customs_item_service/CustomsItemCreateParameters.ts b/src/services/customs_item_service/CustomsItemCreateParameters.ts new file mode 100644 index 000000000..074bf1087 --- /dev/null +++ b/src/services/customs_item_service/CustomsItemCreateParameters.ts @@ -0,0 +1,7 @@ +import { ParametersToOmitOnCreate } from "../../utils/types"; +import { ICustomsItem } from "./CustomsItem"; + +export type ICustomsItemCreateParameters = Omit< + ICustomsItem, + ParametersToOmitOnCreate +>; diff --git a/src/services/customs_item_service.js b/src/services/customs_item_service/index.ts similarity index 51% rename from src/services/customs_item_service.js rename to src/services/customs_item_service/index.ts index ae36b7fce..3dbdd4019 100644 --- a/src/services/customs_item_service.js +++ b/src/services/customs_item_service/index.ts @@ -1,6 +1,12 @@ -import baseService from './base_service'; +import EasyPost from "../.."; +import baseService from "../base_service"; +import { ICustomsItem } from "./CustomsItem"; +import { ICustomsItemCreateParameters } from "./CustomsItemCreateParameters"; -export default (easypostClient) => +export * from "./CustomsItem"; +export * from "./CustomsItemCreateParameters"; + +export default (easypostClient: EasyPost) => /** * The CustomsItemService class provides methods for interacting with EasyPost {@link CustomsItem} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -9,28 +15,28 @@ export default (easypostClient) => /** * Create a {@link CustomsItem customs item}. * See {@link https://www.easypost.com/docs/api/node#create-a-customsitem EasyPost API Documentation} for more information. - * @param {Object} params - Parameters for the customs item to be created. - * @returns {CustomsItem} - The created customs item. + * @param params - Parameters for the customs item to be created. + * @returns - The created customs item. */ - static async create(params) { - const url = 'customs_items'; + static async create(params: ICustomsItemCreateParameters) { + const url = "customs_items"; const wrappedParams = { customs_item: params, }; - return this._create(url, wrappedParams); + return this._create(url, wrappedParams); } /** * Retrieve a {@link CustomsItem customs item} by its ID. * See {@link https://www.easypost.com/docs/api/node#retrieve-a-customsitem EasyPost API Documentation} for more information. - * @param {string} id - The ID of the customs item to retrieve. - * @returns {CustomsItem} - The retrieved customs item. + * @param id - The ID of the customs item to retrieve. + * @returns - The retrieved customs item. */ - static async retrieve(id) { + static async retrieve(id: string) { const url = `customs_items/${id}`; - return this._retrieve(url); + return this._retrieve(url); } }; diff --git a/src/services/end_shipper_service/EndShipper.ts b/src/services/end_shipper_service/EndShipper.ts new file mode 100644 index 000000000..44799ff30 --- /dev/null +++ b/src/services/end_shipper_service/EndShipper.ts @@ -0,0 +1,62 @@ +import { IObjectWithId } from "../../utils/types"; + +/** + * The EndShipper API is for platforms purchasing postage on behalf of their users, the EndShipper. + * Platforms must assert the EndShipper details, as the EndShipper is ultimately responsible for what is in the box. + * Multiple labels purchased for the same EndShipper must use the same EndShipper identity (API object). + * EndShipper objects must be created prior to buying a Shipment. Once EndShipper objects have been created, + * you must keep track of their public id in order to use them during a label buy. + * + * @see https://www.easypost.com/docs/api/node#endshipper + */ +export type IEndshipper = IObjectWithId<"EndShipper"> & { + /** + * Name of responsible person (conditionally required) + */ + name?: string | null; + + /** + * Name of responsible company (conditionally required) + */ + company?: string | null; + + /** + * First line of the address + */ + street1?: string | null; + + /** + * Second line of the address + */ + street2?: string | null; + + /** + * City the address is located in + */ + city?: string | null; + + /** + * State or province the address is located in + */ + state?: string | null; + + /** + * ZIP or postal code the address is located in + */ + zip: string; + + /** + * ISO 3166 country code for the country the address is located in + */ + country?: string; + + /** + * Phone number to reach the person or organization + */ + phone?: string | null; + + /** + * Email to reach the person or organization + */ + email?: string | null; +}; diff --git a/src/services/end_shipper_service/EndShipperCreateParameters.ts b/src/services/end_shipper_service/EndShipperCreateParameters.ts new file mode 100644 index 000000000..0c4c3116a --- /dev/null +++ b/src/services/end_shipper_service/EndShipperCreateParameters.ts @@ -0,0 +1,7 @@ +import { ParametersToOmitOnCreate } from "../../utils/types"; +import { IEndshipper } from "./EndShipper"; + +export type IEndShipperCreateParameters = Omit< + IEndshipper, + ParametersToOmitOnCreate +>; diff --git a/src/services/end_shipper_service/EndShipperListParameters.ts b/src/services/end_shipper_service/EndShipperListParameters.ts new file mode 100644 index 000000000..7422bc550 --- /dev/null +++ b/src/services/end_shipper_service/EndShipperListParameters.ts @@ -0,0 +1,6 @@ +import { IAllMethodParameters } from "../../utils/types"; + +/** + * @see https://www.easypost.com/docs/api#endshipper + */ +export type IEndShipperListParameters = IAllMethodParameters; diff --git a/src/services/end_shipper_service.js b/src/services/end_shipper_service/index.ts similarity index 50% rename from src/services/end_shipper_service.js rename to src/services/end_shipper_service/index.ts index 1aefe88b1..5e82ae875 100644 --- a/src/services/end_shipper_service.js +++ b/src/services/end_shipper_service/index.ts @@ -1,6 +1,14 @@ -import baseService from './base_service'; +import EasyPost from "../.."; +import baseService from "../base_service"; +import { IEndshipper } from "./EndShipper"; +import { IEndShipperCreateParameters } from "./EndShipperCreateParameters"; +import { IEndShipperListParameters } from "./EndShipperListParameters"; -export default (easypostClient) => +export * from "./EndShipper"; +export * from "./EndShipperCreateParameters"; +export * from "./EndShipperListParameters"; + +export default (easypostClient: EasyPost) => /** * The EndShipperService class provides methods for interacting with EasyPost {@link EndShipper} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -9,31 +17,37 @@ export default (easypostClient) => /** * Create an {@link EndShipper end shipper}. * See {@link https://www.easypost.com/docs/api/node#create-an-endshipper EasyPost API Documentation} for more information. - * @param {Object} params - Parameters for the end shipper to be created. - * @returns {EndShipper} - The created end shipper. + * @param params - Parameters for the end shipper to be created. + * @returns - The created end shipper. */ - static async create(params) { - const url = 'end_shippers'; + static async create(params: IEndShipperCreateParameters) { + const url = "end_shippers"; const wrappedParams = { address: params }; - return this._create(url, wrappedParams); + return this._create(url, wrappedParams); } /** * Update an {@link EndShipper end shipper}. * See {@link https://www.easypost.com/docs/api/node#update-an-endshipper EasyPost API Documentation} for more information. - * @param {string} id - The ID of the end shipper to update. - * @param {Object} params - Parameters for the end shipper to be updated. - * @returns {EndShipper} - The updated end shipper. + * @param id - The ID of the end shipper to update. + * @param params - Parameters for the end shipper to be updated. + * @returns - The updated end shipper. */ - static async update(id, params) { + static async update( + id: string, + params: Partial + ) { const url = `end_shippers/${id}`; const wrappedParams = { address: params }; try { const response = await easypostClient._put(url, wrappedParams); - return this._convertToEasyPostObject(response.body, wrappedParams); + return this._convertToEasyPostObject( + response.body, + wrappedParams + ); } catch (e) { return Promise.reject(e); } @@ -42,23 +56,23 @@ export default (easypostClient) => /** * Retrieve an {@link EndShipper end shipper} by its ID. * See {@link https://www.easypost.com/docs/api/node#retrieve-an-endshipper EasyPost API Documentation} for more information. - * @param {string} id - The ID of the end shipper to retrieve. - * @returns {EndShipper} - The retrieved end shipper. + * @param id - The ID of the end shipper to retrieve. + * @returns - The retrieved end shipper. */ - static async retrieve(id) { + static async retrieve(id: string) { const url = `end_shippers/${id}`; - return this._retrieve(url); + return this._retrieve(url); } /** * Retrieve all {@link EndShipper end shippers} associated with the current authenticated user. * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-endshippers EasyPost API Documentation} for more information. - * @param {Object} [params] - Parameters to filter the list of end shippers. - * @returns {Object} - An object containing a list of {@link EndShipper end shippers} and pagination information. + * @param [params] - Parameters to filter the list of end shippers. + * @returns - An object containing a list of {@link EndShipper end shippers} and pagination information. */ - static async all(params = {}) { - const url = 'end_shippers'; + static async all(params: IEndShipperListParameters = {}) { + const url = "end_shippers"; return this._all(url, params); } diff --git a/src/services/event_service.js b/src/services/event_service.js deleted file mode 100644 index 6bcd8fa63..000000000 --- a/src/services/event_service.js +++ /dev/null @@ -1,80 +0,0 @@ -import baseService from './base_service'; - -export default (easypostClient) => - /** - * The EventService class provides methods for interacting with EasyPost {@link Event} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - class EventService extends baseService(easypostClient) { - /** - * Retrieve all {@link Payload payloads} for an {@link Event event}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads EasyPost API Documentation} for more information. - * @param {string} id - The ID of the event to retrieve payloads for. - * @returns {Payload[]} - A list of {@link Payload payloads} for the event. - */ - static async retrieveAllPayloads(id) { - const url = `events/${id}/payloads`; - - try { - const response = await easypostClient._get(url); - - return this._convertToEasyPostObject(response.body.payloads); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Retrieve a specific {@link Payload payload} for an {@link Event event}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-payload EasyPost API Documentation} for more information. - * @param {string} id - The ID of the event to retrieve the payload for. - * @param {string} payloadId - The ID of the payload to retrieve. - * @returns {Payload} - The {@link Payload payload} for the event. - */ - static async retrievePayload(id, payloadId) { - const url = `events/${id}/payloads/${payloadId}`; - - try { - const response = await easypostClient._get(url); - - return this._convertToEasyPostObject(response.body); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Retrieve all {@link Event events} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-events EasyPost API Documentation} for more information. - * @param {Object} [params] - Parameters to filter the list of events. - * @returns {Object} - An object containing the list of {@link Event events} and pagination information. - */ - static async all(params = {}) { - const url = 'events'; - - return this._all(url, params); - } - - /** - * Retrieve the next page of Event collection. - * @param {Object} events An object containing a list of {@link Event events} and pagination information. - * @param {Number} pageSize The number of records to return on each page - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - static async getNextPage(events, pageSize = null) { - const url = 'events'; - return this._getNextPage(url, 'events', events, pageSize); - } - - /** - * Retrieve an {@link Event event} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-event EasyPost API Documentation} for more information. - * @param {string} id - The ID of the event to retrieve. - * @returns {Event} - The retrieved event. - */ - static async retrieve(id) { - const url = `events/${id}`; - - return this._retrieve(url); - } - }; diff --git a/src/services/event_service/Event.ts b/src/services/event_service/Event.ts new file mode 100644 index 000000000..415983e2e --- /dev/null +++ b/src/services/event_service/Event.ts @@ -0,0 +1,46 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; + +/** + * Webhook Events are triggered by changes in objects you've created via the API. + * Every time an Event related to one of your objects is created, EasyPost guarantees at least one POST request will be sent to each of the webhook URLs set up for your account. + * For this reason, we strongly encourage your webhook handler to be idempotent. + * See the webhooks guide for more information. + * + * @see https://www.easypost.com/docs/api/node#events + */ +export type IEvent = IObjectWithId<"Event"> & + IDatedObject & { + /** + * Result type and event name, see the "Possible Event Types" section for more information + */ + description: string; + + /** + * Previous values of relevant result attributes + */ + previous_attributes: any; + + /** + * The object associated with the Event. See the "object" attribute on the result to determine its specific type. + * This field will not be returned when retrieving events directly from the API + */ + result: any; + + /** + * The current status of the event. Possible values are "completed", "failed", "in_queue", "retrying", or "pending" (deprecated) + * + * @deprecated + */ + status: "completed" | "failed" | "in_queue" | "retrying" | "pending"; + + /** + * Webhook URLs that have not yet been successfully notified as of the time this webhook event was sent. + * The URL receiving the Event will still be listed in pending_urls, as will any other URLs that receive the Event at the same time + */ + pending_urls: string[]; + + /** + * Webhook URLs that have already been successfully notified as of the time this webhook was sent + */ + completed_urls: string[]; + }; diff --git a/src/services/event_service/EventListParameters.ts b/src/services/event_service/EventListParameters.ts new file mode 100644 index 000000000..9197b2b6e --- /dev/null +++ b/src/services/event_service/EventListParameters.ts @@ -0,0 +1,6 @@ +import { IAllMethodParameters } from "../../utils/types"; + +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-events + */ +export type IEventListParameters = IAllMethodParameters; diff --git a/src/services/event_service/Payload/Payload.ts b/src/services/event_service/Payload/Payload.ts new file mode 100644 index 000000000..90efefd19 --- /dev/null +++ b/src/services/event_service/Payload/Payload.ts @@ -0,0 +1,15 @@ +import { IDatedObject, IObjectWithId } from "../../../utils/types"; + +/** + * A Payload represents an attempt by EasyPost to send an Event to a Webhook. + * An Event can have multiple Payloads. For instance, if there is a failure to deliver a Webhook, + * an Event would have multiple payloads, one for each attempt to deliver the Event to the Webhook. + * Payload can be useful for debugging webhook delivery and when initially setting up EasyPost webhooks. + */ +export type IPayload = IObjectWithId<"Payload"> & + IDatedObject & { + /** + * The body of the Payload response + */ + response_body: string | null; + }; diff --git a/src/services/event_service/Payload/PayloadListParameters.ts b/src/services/event_service/Payload/PayloadListParameters.ts new file mode 100644 index 000000000..7e9b86192 --- /dev/null +++ b/src/services/event_service/Payload/PayloadListParameters.ts @@ -0,0 +1,6 @@ +import { IAllMethodParameters } from "../../../utils/types"; + +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads + */ +export type IPayloadListParameters = IAllMethodParameters; diff --git a/src/services/event_service/Payload/index.ts b/src/services/event_service/Payload/index.ts new file mode 100644 index 000000000..25d8d8816 --- /dev/null +++ b/src/services/event_service/Payload/index.ts @@ -0,0 +1 @@ +export * from "./Payload"; diff --git a/src/services/event_service/index.ts b/src/services/event_service/index.ts new file mode 100644 index 000000000..9aeef41c1 --- /dev/null +++ b/src/services/event_service/index.ts @@ -0,0 +1,95 @@ +import EasyPost from "../.."; +import baseService from "../base_service"; +import { IEvent } from "./Event"; +import { IEventListParameters } from "./EventListParameters"; +import { IPayload } from "./Payload"; + +export * from "./Event"; +export * from "./EventListParameters"; +export * from "./Payload"; + +export default (easypostClient: EasyPost) => + /** + * The EventService class provides methods for interacting with EasyPost {@link Event} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + class EventService extends baseService(easypostClient) { + /** + * Retrieve all {@link Payload payloads} for an {@link Event event}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads EasyPost API Documentation} for more information. + * @param id - The ID of the event to retrieve payloads for. + * @returns - A list of {@link Payload payloads} for the event. + */ + static async retrieveAllPayloads(id: string) { + const url = `events/${id}/payloads`; + + try { + const response = await easypostClient._get(url); + + return this._convertToEasyPostObject( + response.body.payloads + ); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Retrieve a specific {@link Payload payload} for an {@link Event event}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-payload EasyPost API Documentation} for more information. + * @param id - The ID of the event to retrieve the payload for. + * @param payloadId - The ID of the payload to retrieve. + * @returns - The {@link Payload payload} for the event. + */ + static async retrievePayload(id: string, payloadId: string) { + const url = `events/${id}/payloads/${payloadId}`; + + try { + const response = await easypostClient._get(url); + + return this._convertToEasyPostObject(response.body); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Retrieve all {@link Event events} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-events EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of events. + * @returns - An object containing the list of {@link Event events} and pagination information. + */ + static async all(params: IEventListParameters = {}) { + const url = "events"; + + return this._all(url, params); + } + + /** + * Retrieve the next page of Event collection. + * @param events An object containing a list of {@link Event events} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + static async getNextPage(events: any, pageSize: number | null = null) { + const url = "events"; + return this._getNextPage<{ events: IEvent[] }>( + url, + "events", + events, + pageSize + ); + } + + /** + * Retrieve an {@link Event event} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-event EasyPost API Documentation} for more information. + * @param id - The ID of the event to retrieve. + * @returns - The retrieved event. + */ + static async retrieve(id: string) { + const url = `events/${id}`; + + return this._retrieve(url); + } + }; diff --git a/src/services/index.ts b/src/services/index.ts new file mode 100644 index 000000000..1d54b3ad2 --- /dev/null +++ b/src/services/index.ts @@ -0,0 +1,27 @@ +export * from "./address_service"; +export * from "./api_key_service"; +export * from "./batch_service"; +export * from "./beta_rate_service"; +export * from "./beta_referral_customer_service"; +export * from "./billing_service"; +export * from "./carrier_account_service"; +export * from "./carrier_metadata_service"; +export * from "./carrier_type_service"; +export * from "./customs_info_service"; +export * from "./customs_item_service"; +export * from "./end_shipper_service"; +export * from "./event_service"; +export * from "./insurance_service"; +export * from "./order_service"; +export * from "./parcel_service"; +export * from "./pickup_service"; +export * from "./rate_service"; +export * from "./referral_customer_service"; +export * from "./refund_service"; +export * from "./report_service"; +export * from "./scan_form_service"; +export * from "./shipment_service"; +export * from "./tracker_service"; +export * from "./user_service"; +export * from "./webhook_service"; +export * from "./base_service"; diff --git a/types/Fee/Fee.d.ts b/src/services/insurance_service/Fee.ts similarity index 80% rename from types/Fee/Fee.d.ts rename to src/services/insurance_service/Fee.ts index eb9373246..9a66644ec 100644 --- a/types/Fee/Fee.d.ts +++ b/src/services/insurance_service/Fee.ts @@ -1,5 +1,5 @@ -import { IBaseObject } from '../base'; -import { TFeeType } from './FeeType'; +import { IBaseObject } from "../../utils/types"; +import { TFeeType } from "./FeeType"; /** * Fee objects are used to represent the breakdown of charges made when purchasing an item on EasyPost. @@ -12,7 +12,7 @@ import { TFeeType } from './FeeType'; * * @see https://www.easypost.com/docs/api/node#fee-object */ -export declare interface IFee extends IBaseObject<'Fee'> { +export type IFee = IBaseObject<"Fee"> & { /** * The name of the category of fee. Possible types are "LabelFee", "PostageFee", "InsuranceFee", and "TrackerFee" */ @@ -32,12 +32,4 @@ export declare interface IFee extends IBaseObject<'Fee'> { * Whether the Fee has been refunded successfully */ refunded: boolean; -} - -export declare class Fee implements IFee { - object: 'Fee'; - type: TFeeType; - amount: string; - charged: boolean; - refunded: boolean; -} +}; diff --git a/src/services/insurance_service/FeeType.ts b/src/services/insurance_service/FeeType.ts new file mode 100644 index 000000000..0a4f1b822 --- /dev/null +++ b/src/services/insurance_service/FeeType.ts @@ -0,0 +1,5 @@ +export type TFeeType = + | "InsuranceFee" + | "LabelFee" + | "PostageFee" + | "TrackerFee"; diff --git a/src/services/insurance_service/Insurance.ts b/src/services/insurance_service/Insurance.ts new file mode 100644 index 000000000..42a75b266 --- /dev/null +++ b/src/services/insurance_service/Insurance.ts @@ -0,0 +1,85 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { IAddress } from "../address_service"; +import { ITracker } from "../tracker_service"; +import { IFee } from "./Fee"; +import { TInsuranceStatus } from "./InsuranceStatus"; + +/** + * An Insurance object represents insurance for packages purchased both via the EasyPost API as well as shipments purchased through third parties and later registered with EasyPost. + * An Insurance is created automatically whenever you buy a Shipment through EasyPost and pass insurance options during the Buy call or in a later call to Insure a Shipment. + * + * Insurance purchased through the Shipment Buy or Insure endpoints is immediately insured - there is no possibility of rejection based on tracking information, as the package was just created. + * On the other hand, Insurance purchased on shipments purchased outside of EasyPost requires creation with a tracking code so that EasyPost may confirm the package existence and current shipping status at the time of purchase. + * + * Standalone insurance is created in a pending state to help distinguish it from insurance purchased for an EasyPost Shipment. + * Both kinds of Insurance use the Tracking system to receive periodic updates, and will report those updates to any appropriate Webhooks on file. + * Standalone insurance will cancel itself if the tracking information for the given tracking code shows evidence of having been shipped anytime before the insurance was purchased. + * + * Unlike Shipments within EasyPost, Insurance objects register To and From Address objects according to the destination and ship-from locations of the package. + * This means that a Shipment with "is_return: true" actually ships to the listed From Address. + * Insurance does not have a concept of "is_return", so all insurance records refer to their true package destination as "to_address", regardless of whether or not the shipment is a return. + * + * @see https://www.easypost.com/docs/api/node#insurance-object + */ +export type IInsurance = IObjectWithId<"Insurance"> & + IDatedObject & { + /** + * The unique reference for this Insurance, if any + */ + reference?: string | null; + + /** + * USD value of insured goods with sub-cent precision + */ + amount: string; + + /** + * The insurance provider used by EasyPost + */ + provider: string; + + /** + * An identifying number for some insurance providers used by EasyPost + */ + provider_id: string; + + /** + * The ID of the Shipment in EasyPost, if postage was purchased via EasyPost + */ + shipment_id: string; + + /** + * The tracking code of either the shipment within EasyPost, or provided by you during creation + */ + tracking_code: string; + + /** + * The current status of the insurance, possible values are "new", "pending", "purchased", "failed", or "cancelled" + */ + status: TInsuranceStatus; + + /** + * The associated Tracker object + */ + tracker: ITracker; + + /** + * The associated Address object for destination + */ + to_address: IAddress; + + /** + * The associated Address object for origin + */ + from_address: IAddress; + + /** + * The associated InsuranceFee object if any + */ + fee: IFee; + + /** + * The list of errors encountered during attempted purchase of the insurance + */ + messages: string[]; + }; diff --git a/types/Insurance/InsuranceCreateParameters.d.ts b/src/services/insurance_service/InsuranceCreateParameters.ts similarity index 85% rename from types/Insurance/InsuranceCreateParameters.d.ts rename to src/services/insurance_service/InsuranceCreateParameters.ts index e467ef25c..932ecb25e 100644 --- a/types/Insurance/InsuranceCreateParameters.d.ts +++ b/src/services/insurance_service/InsuranceCreateParameters.ts @@ -1,6 +1,6 @@ -import { IAddress } from '../Address'; +import { IAddress } from "../address_service"; -export declare interface IInsuranceCreateParameters { +export type IInsuranceCreateParameters = { reference?: string | null; to_address: IAddress | string; from_address: IAddress | string; @@ -23,4 +23,4 @@ export declare interface IInsuranceCreateParameters { * @example 100.00 */ amount: string; -} +}; diff --git a/src/services/insurance_service/InsuranceStatus.ts b/src/services/insurance_service/InsuranceStatus.ts new file mode 100644 index 000000000..7b816e18d --- /dev/null +++ b/src/services/insurance_service/InsuranceStatus.ts @@ -0,0 +1,6 @@ +export type TInsuranceStatus = + | "new" + | "pending" + | "purchased" + | "failed" + | "cancelled"; diff --git a/src/services/insurance_service.js b/src/services/insurance_service/index.ts similarity index 54% rename from src/services/insurance_service.js rename to src/services/insurance_service/index.ts index 0946ede97..3b7618771 100644 --- a/src/services/insurance_service.js +++ b/src/services/insurance_service/index.ts @@ -1,6 +1,16 @@ -import baseService from './base_service'; +import EasyPost from "../.."; +import { IAllMethodParameters } from "../../utils/types"; +import baseService from "../base_service"; +import { IInsurance } from "./Insurance"; +import { IInsuranceCreateParameters } from "./InsuranceCreateParameters"; -export default (easypostClient) => +export * from "./Fee"; +export * from "./FeeType"; +export * from "./Insurance"; +export * from "./InsuranceCreateParameters"; +export * from "./InsuranceStatus"; + +export default (easypostClient: EasyPost) => /** * The InsuranceService class provides methods for interacting with EasyPost {@link Insurance} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -9,29 +19,29 @@ export default (easypostClient) => /** * Create an {@link Insurance insurance} record. * See {@link https://www.easypost.com/docs/api/node#create-an-insurance EasyPost API Documentation} for more information. - * @param {Object} params - Parameters for the insurance to be created. - * @returns {Insurance} - The created insurance. + * @param params - Parameters for the insurance to be created. + * @returns - The created insurance. */ - static async create(params) { - const url = 'insurances'; + static async create(params: IInsuranceCreateParameters) { + const url = "insurances"; const wrappedParams = { insurance: params, }; - return this._create(url, wrappedParams); + return this._create(url, wrappedParams); } /** * Retrieve all {@link Insurance} records associated with the current authenticated user. * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-insurances EasyPost API Documentation} for more information. - * @param {Object} [params] - Parameters to filter the insurance records. - * @returns {Object} - An object containing the list of {@link Insurance insurance} records and pagination information. + * @param [params] - Parameters to filter the insurance records. + * @returns - An object containing the list of {@link Insurance insurance} records and pagination information. */ - static async all(params = {}) { - const url = 'insurances'; + static async all(params: IAllMethodParameters = {}) { + const url = "insurances"; - return this._all(url, params); + return this._all(url, params); } /** @@ -40,9 +50,14 @@ export default (easypostClient) => * @param {Number} pageSize The number of records to return on each page * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage(insurances, pageSize = null) { - const url = 'insurances'; - return this._getNextPage(url, 'insurances', insurances, pageSize); + static async getNextPage(insurances: any, pageSize: number | null = null) { + const url = "insurances"; + return this._getNextPage<{ insurances: IInsurance[] }>( + url, + "insurances", + insurances, + pageSize + ); } /** @@ -51,22 +66,9 @@ export default (easypostClient) => * @param {string} id - The ID of the insurance to retrieve. * @returns {Insurance} - The retrieved insurance. */ - static async retrieve(id) { + static async retrieve(id: string) { const url = `insurances/${id}`; - return this._retrieve(url); - } - - /** - * Refund an {@link Insurance insurance} record by its ID. - * See {@link https://www.easypost.com/docs/api/node#refund-an-insurance EasyPost API Documentation} for more information. - * @param {string} id - The ID of the insurance to be refunded. - * @returns {Insurance} - The refunded insurance. - */ - static async refund(id) { - const url = `insurances/${id}/refund`; - const response = await easypostClient._post(url); - - return this._convertToEasyPostObject(response.body); + return this._retrieve(url); } }; diff --git a/src/services/order_service/Order.ts b/src/services/order_service/Order.ts new file mode 100644 index 000000000..bafeb4861 --- /dev/null +++ b/src/services/order_service/Order.ts @@ -0,0 +1,62 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { IAddress } from "../address_service"; +import { IRate } from "../rate_service"; +import { IMessage, IShipment } from "../shipment_service"; + +/** + * The Order object represents a collection of packages and can be used for Multi-Piece Shipments. + * Like a single Shipment each Order consists of a "to" and "from" Address to be used for each Shipment within the Order. + * These Addresses will be copied to each Shipment so there is no need to specify them multiple times. + * Each Shipment must then specify its Parcel, Options, and CustomsInfo. + * + * An Order created with valid Address Objects and Parcel data nested within the Order's Shipment object will automatically retrieve available shipping Rate options. + * + * @see https://www.easypost.com/docs/api/node#order-object + */ +export type IOrder = IObjectWithId<"Order"> & + IDatedObject & { + /** + * An optional field that may be used in place of id in other API endpoints + */ + reference?: string | null; + + /** + * The destination address + */ + to_address: IAddress; + + /** + * The origin address + */ + from_address: IAddress; + + /** + * The shipper's address, defaults to from_address + */ + return_address?: IAddress | null; + + /** + * The buyer's address, defaults to to_address + */ + buyer_address?: IAddress | null; + + /** + * All associated Shipment objects. Maximum of 100. + */ + shipments: IShipment[]; + + /** + * All associated Rate objects + */ + rates: IRate[]; + + /** + * Any carrier errors encountered during rating + */ + messages: IMessage[]; + + /** + * Set true to create as a return + */ + is_return?: boolean | null; + }; diff --git a/types/Order/OrderCreateParameters.d.ts b/src/services/order_service/OrderCreateParameters.ts similarity index 54% rename from types/Order/OrderCreateParameters.d.ts rename to src/services/order_service/OrderCreateParameters.ts index 05fce62b9..e5f3efcfd 100644 --- a/types/Order/OrderCreateParameters.d.ts +++ b/src/services/order_service/OrderCreateParameters.ts @@ -1,14 +1,14 @@ -import { IAddress } from '../Address'; -import { Shipment } from '../Shipment'; +import { IAddress } from "../address_service"; +import { IShipment } from "../shipment_service"; -export declare interface IOrderCreateParameters { +export type IOrderCreateParameters = { reference?: string | null; to_address: IAddress | string; from_address: IAddress | string; - shipments: Shipment[]; + shipments: IShipment[]; /** * optional array of ids that begin with "ca_" */ carrier_accounts?: string[] | null; -} +}; diff --git a/src/services/order_service.js b/src/services/order_service/index.ts similarity index 53% rename from src/services/order_service.js rename to src/services/order_service/index.ts index a65e57127..12c879515 100644 --- a/src/services/order_service.js +++ b/src/services/order_service/index.ts @@ -1,6 +1,13 @@ -import baseService from './base_service'; +import EasyPost from "../.."; +import baseService from "../base_service"; +import { IRate } from "../rate_service"; +import { IOrder } from "./Order"; +import { IOrderCreateParameters } from "./OrderCreateParameters"; -export default (easypostClient) => +export * from "./Order"; +export * from "./OrderCreateParameters"; + +export default (easypostClient: EasyPost) => /** * The OrderService class provides methods for interacting with EasyPost {@link Order} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -9,34 +16,37 @@ export default (easypostClient) => /** * Create an {@link Order order}. * See {@link https://www.easypost.com/docs/api/node#create-an-order EasyPost API Documentation} for more information. - * @param {Object} params - The parameters to create an order with. - * @returns {Order} - The created order. + * @param params - The parameters to create an order with. + * @returns - The created order. */ - static async create(params) { - const url = 'orders'; + static async create(params: IOrderCreateParameters) { + const url = "orders"; const wrappedParams = { order: params, }; - return this._create(url, wrappedParams); + return this._create(url, wrappedParams); } /** * Purchase an {@link Order order}. * See {@link https://www.easypost.com/docs/api/node#buy-an-order EasyPost API Documentation} for more information. - * @param {string} id - The ID of the order to buy. - * @param {string} carrier - The carrier to use for the order purchase. - * @param {string} service - The service to use for the order purchase. - * @returns {Order} - The purchased order. + * @param id - The ID of the order to buy. + * @param carrier - The carrier to use for the order purchase. + * @param service - The service to use for the order purchase. + * @returns - The purchased order. */ - static async buy(id, carrier, service) { + static async buy(id: string, carrier: string, service: string) { const url = `orders/${id}/buy`; const wrappedParams = { carrier, service }; try { const response = await easypostClient._post(url, wrappedParams); - return this._convertToEasyPostObject(response.body, wrappedParams); + return this._convertToEasyPostObject( + response.body, + wrappedParams + ); } catch (e) { return Promise.reject(e); } @@ -45,16 +55,16 @@ export default (easypostClient) => /** * Get updated rates for an {@link Order order}. * See {@link https://www.easypost.com/docs/api/node#orders EasyPost API Documentation} for more information. - * @param {string} id - The ID of the order to get rates for. - * @returns {Order} - The order with rates. + * @param id - The ID of the order to get rates for. + * @returns - The order with rates. */ - static async getRates(id) { + static async getRates(id: string) { const url = `orders/${id}/rates`; try { const response = await easypostClient._get(url); - return this._convertToEasyPostObject(response.body); + return this._convertToEasyPostObject(response.body); } catch (e) { return Promise.reject(e); } @@ -63,12 +73,12 @@ export default (easypostClient) => /** * Retrieve an {@link Order order} by its ID. * See {@link https://www.easypost.com/docs/api/node#retrieve-an-order EasyPost API Documentation} for more information. - * @param {string} id - The ID of the order to retrieve. - * @returns {Order} - The retrieved order. + * @param id - The ID of the order to retrieve. + * @returns - The retrieved order. */ - static async retrieve(id) { + static async retrieve(id: string) { const url = `orders/${id}`; - return this._retrieve(url); + return this._retrieve(url); } }; diff --git a/src/services/parcel_service/Parcel.ts b/src/services/parcel_service/Parcel.ts new file mode 100644 index 000000000..177ff5b44 --- /dev/null +++ b/src/services/parcel_service/Parcel.ts @@ -0,0 +1,43 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; + +/** + * Parcel objects represent the physical container being shipped. + * Dimensions can be supplied either as length, width, and height dimensions, or a predefined_package string. + * Only weight is required, but since many carriers charge different rates for packages with large dimensions, we strongly recommend including all dimensions if available. + * + * Weights are in OUNCES (OZ) and go to one decimal point. + * Dimensions are in INCHES (IN) and go to one decimal point. + * + * @see https://www.easypost.com/docs/api/node#parcel-object + */ +export type IParcel = IObjectWithId<"Parcel"> & + IDatedObject & { + /** + * Required if width and/or height are present + * float (inches) + */ + length?: number | null; + + /** + * Required if width and/or height are present + * float (inches) + */ + width?: number | null; + + /** + * Required if width and/or height are present + * float (inches) + */ + height?: number | null; + + /** + * Always required + * float (oz) + */ + weight: number; + + /** + * Optional, one of our predefined_packages + */ + predefined_package?: string | null; + }; diff --git a/types/Parcel/ParcelCreateParameters.d.ts b/src/services/parcel_service/ParcelCreateParameters.ts similarity index 67% rename from types/Parcel/ParcelCreateParameters.d.ts rename to src/services/parcel_service/ParcelCreateParameters.ts index 22e3ae711..838842e75 100644 --- a/types/Parcel/ParcelCreateParameters.d.ts +++ b/src/services/parcel_service/ParcelCreateParameters.ts @@ -1,7 +1,10 @@ -import { ParametersToOmitOnCreate } from '../utils'; -import { IParcel } from './Parcel'; +import { ParametersToOmitOnCreate } from "../../utils/types"; +import { IParcel } from "./Parcel"; -export declare interface IParcelCreateParameters extends Omit { +export type IParcelCreateParameters = Omit< + IParcel, + ParametersToOmitOnCreate +> & { /** * Required if width and/or height are present * float (inches) @@ -25,4 +28,4 @@ export declare interface IParcelCreateParameters extends Omit +export * from "./Parcel"; +export * from "./ParcelCreateParameters"; + +export default (easypostClient: EasyPost) => /** * The ParcelService class provides methods for interacting with EasyPost {@link Parcel} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -9,28 +15,28 @@ export default (easypostClient) => /** * Create a {@link Parcel parcel}. * See {@link https://www.easypost.com/docs/api/node#create-a-parcel EasyPost API Documentation} for more information. - * @param {Object} params - The parameters to create a parcel with. - * @returns {Parcel} - The created parcel. + * @param params - The parameters to create a parcel with. + * @returns - The created parcel. */ - static async create(params) { - const url = 'parcels'; + static async create(params: IParcelCreateParameters) { + const url = "parcels"; const wrappedParams = { parcel: params, }; - return this._create(url, wrappedParams); + return this._create(url, wrappedParams); } /** * Retrieve a {@link Parcel parcel} by its ID. * See {@link https://www.easypost.com/docs/api/node#retrieve-a-parcel EasyPost API Documentation} for more information. - * @param {string} id - The ID of the parcel to retrieve. - * @returns {Parcel} - The retrieved parcel. + * @param id - The ID of the parcel to retrieve. + * @returns - The retrieved parcel. */ - static async retrieve(id) { + static async retrieve(id: string) { const url = `parcels/${id}`; - return this._retrieve(url); + return this._retrieve(url); } }; diff --git a/src/services/pickup_service.js b/src/services/pickup_service.js deleted file mode 100644 index aa595c533..000000000 --- a/src/services/pickup_service.js +++ /dev/null @@ -1,96 +0,0 @@ -import baseService from './base_service'; - -export default (easypostClient) => - /** - * The PickupService class provides methods for interacting with EasyPost {@link Pickup} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - class PickupService extends baseService(easypostClient) { - /** - * Create a {@link Pickup pickup}. - * See {@link https://www.easypost.com/docs/api/node#create-a-pickup EasyPost API Documentation} for more information. - * @param {Object} params - The parameters to create a pickup with. - * @returns {Pickup} - The created pickup. - */ - static async create(params) { - const url = 'pickups'; - - const wrappedParams = { - pickup: params, - }; - - return this._create(url, wrappedParams); - } - - /** - * Purchase a {@link Pickup pickup}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-pickup EasyPost API Documentation} for more information. - * @param {string} id - The ID of the pickup to purchase. - * @param {string} carrier - The carrier to purchase the pickup with. - * @param {string} service - The service to purchase the pickup with. - * @returns {Pickup} - The purchased pickup. - */ - static async buy(id, carrier, service) { - const url = `pickups/${id}/buy`; - const wrappedParams = { carrier, service }; - try { - const response = await easypostClient._post(url, wrappedParams); - - return this._convertToEasyPostObject(response.body, wrappedParams); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Cancel a {@link Pickup pickup}. - * See {@link https://www.easypost.com/docs/api/node#cancel-a-pickup EasyPost API Documentation} for more information. - * @param {string} id - The ID of the pickup to cancel. - * @returns {Pickup} - The cancelled pickup. - */ - static async cancel(id) { - const url = `pickups/${id}/cancel`; - try { - const response = await easypostClient._post(url); - - return this._convertToEasyPostObject(response.body); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Retrieve all {@link Pickup pickups} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups EasyPost API Documentation} for more information. - * @param {Object} [params] - The parameters to filter the pickups by. - * @returns {Object} - An object containing a list of {@link Pickup pickups} and pagination information. - */ - static async all(params = {}) { - const url = 'pickups'; - - return this._all(url, params); - } - - /** - * Retrieve the next page of Pickup collection. - * @param {Object} pickups An object containing a list of {@link Pickup pickups} and pagination information. - * @param {Number} pageSize The number of records to return on each page - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - static async getNextPage(pickups, pageSize = null) { - const url = 'pickups'; - return this._getNextPage(url, 'pickups', pickups, pageSize); - } - - /** - * Retrieve a {@link Pickup pickup} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-pickup EasyPost API Documentation} for more information. - * @param {string} id - The ID of the pickup to retrieve. - * @returns {Pickup} - The retrieved pickup. - */ - static async retrieve(id) { - const url = `pickups/${id}`; - - return this._retrieve(url); - } - }; diff --git a/src/services/pickup_service/Pickup.ts b/src/services/pickup_service/Pickup.ts new file mode 100644 index 000000000..8f40336cd --- /dev/null +++ b/src/services/pickup_service/Pickup.ts @@ -0,0 +1,89 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { IAddress } from "../address_service"; +import { ICarrierAccount } from "../carrier_account_service"; +import { IMessage, IShipment } from "../shipment_service"; +import { IPickupRate } from "./PickupRate"; + +/** + * The Pickup object allows you to schedule a pickup from your carrier from your customer's residence or place of business. + * Supported carriers include: + * - Canada Post + * - Canpar + * - DHL Express + * - FedEx + * - Lasership + * - Loomis Express + * - LSO + * - Ontrac + * - UPS + * - USPS + * - Veho + * + * After a Pickup is successfully created, it will automatically fetch PickupRates for each CarrierAccount specified that supports scheduled pickups. + * Then a PickupRate must be selected and purchased before the pickup can be successfully scheduled. + * + * @see https://www.easypost.com/docs/api/node#pickup-object + */ +export type IPickup = IObjectWithId<"Pickup"> & + IDatedObject & { + /** + * An optional field that may be used in place of ID in some API endpoints + */ + reference?: string | null; + + /** + * One of: "unknown", "scheduled", or "canceled" + */ + status: "unknown" | "scheduled" | "canceled"; + + /** + * The earliest time at which the package is available to pick up + */ + min_datetime: string; + + /** + * The latest time at which the package is available to pick up. + * Must be later than the min_datetime + */ + max_datetime: string; + + /** + * Is the pickup address the account's address? + */ + is_account_address?: boolean | null; + + /** + * Additional text to help the driver successfully obtain the package + */ + instructions?: string | null; + + /** + * A list of messages containing carrier errors encountered during pickup rate generation + */ + messages: IMessage[]; + + /** + * The confirmation number for a booked pickup from the carrier + */ + confirmation: string; + + /** + * The associated Shipment + */ + shipment: IShipment; + + /** + * The associated Address + */ + address: IAddress; + + /** + * The list of carriers (if empty, all carriers were used) used to generate pickup rates + */ + carrier_accounts?: ICarrierAccount[] | null; + + /** + * The list of different pickup rates across valid carrier accounts for the shipment + */ + pickup_rates: IPickupRate[]; + }; diff --git a/src/services/pickup_service/PickupCreateParameters.ts b/src/services/pickup_service/PickupCreateParameters.ts new file mode 100644 index 000000000..aaf4911d2 --- /dev/null +++ b/src/services/pickup_service/PickupCreateParameters.ts @@ -0,0 +1,30 @@ +import { IAddress } from "../address_service"; +import { IBatch } from "../batch_service"; +import { ICarrierAccount } from "../carrier_account_service"; +import { IShipment } from "../shipment_service"; +import { IPickupRate } from "./PickupRate"; + +type BasePickupCreateParameters = { + address: IAddress | string; + carrier_accounts?: ICarrierAccount[] | null; + confirmation?: string | null; + instructions?: string | null; + is_account_address?: boolean | null; + max_datetime: string; + min_datetime: string; + pickup_rates: IPickupRate; + reference?: string | null; + status: string; +}; + +type ShipmentPickupCreateParameters = BasePickupCreateParameters & { + shipment?: IShipment | { id: string } | string | null; +}; + +type BatchPickupCreateParameters = BasePickupCreateParameters & { + batch?: IBatch | { id: string } | string | null; +}; + +export type IPickupCreateParameters = + | ShipmentPickupCreateParameters + | BatchPickupCreateParameters; diff --git a/src/services/pickup_service/PickupListParameters.ts b/src/services/pickup_service/PickupListParameters.ts new file mode 100644 index 000000000..1a37b76fd --- /dev/null +++ b/src/services/pickup_service/PickupListParameters.ts @@ -0,0 +1,6 @@ +import { IAllMethodParameters } from "../../utils/types"; + +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups + */ +export type IPickupListParameters = IAllMethodParameters; diff --git a/src/services/pickup_service/PickupRate.ts b/src/services/pickup_service/PickupRate.ts new file mode 100644 index 000000000..f05698b95 --- /dev/null +++ b/src/services/pickup_service/PickupRate.ts @@ -0,0 +1,32 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; + +/** + * @see https://www.easypost.com/docs/api/node#pickup-rate-object + */ +export type IPickupRate = IObjectWithId<"PickupRate"> & + IDatedObject & { + /** + * service name + */ + service: string; + + /** + * name of carrier + */ + carrier: string; + + /** + * the actual rate quote for this service + */ + rate: string; + + /** + * currency for the rate + */ + currency: string; + + /** + * the ID of the pickup this is a quote for + */ + pickup_id: string; + }; diff --git a/src/services/pickup_service/index.ts b/src/services/pickup_service/index.ts new file mode 100644 index 000000000..98dc1a601 --- /dev/null +++ b/src/services/pickup_service/index.ts @@ -0,0 +1,108 @@ +import EasyPost from "../.."; +import baseService from "../base_service"; +import { IPickup } from "./Pickup"; +import { IPickupCreateParameters } from "./PickupCreateParameters"; +import { IPickupListParameters } from "./PickupListParameters"; + +export default (easypostClient: EasyPost) => + /** + * The PickupService class provides methods for interacting with EasyPost {@link Pickup} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + class PickupService extends baseService(easypostClient) { + /** + * Create a {@link Pickup pickup}. + * See {@link https://www.easypost.com/docs/api/node#create-a-pickup EasyPost API Documentation} for more information. + * @param params - The parameters to create a pickup with. + * @returns - The created pickup. + */ + static async create(params: IPickupCreateParameters) { + const url = "pickups"; + + const wrappedParams = { + pickup: params, + }; + + return this._create(url, wrappedParams); + } + + /** + * Purchase a {@link Pickup pickup}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-pickup EasyPost API Documentation} for more information. + * @param id - The ID of the pickup to purchase. + * @param carrier - The carrier to purchase the pickup with. + * @param service - The service to purchase the pickup with. + * @returns - The purchased pickup. + */ + static async buy(id: string, carrier: string, service: string) { + const url = `pickups/${id}/buy`; + const wrappedParams = { carrier, service }; + try { + const response = await easypostClient._post(url, wrappedParams); + + return this._convertToEasyPostObject( + response.body, + wrappedParams + ); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Cancel a {@link Pickup pickup}. + * See {@link https://www.easypost.com/docs/api/node#cancel-a-pickup EasyPost API Documentation} for more information. + * @param id - The ID of the pickup to cancel. + * @returns - The cancelled pickup. + */ + static async cancel(id: string) { + const url = `pickups/${id}/cancel`; + try { + const response = await easypostClient._post(url); + + return this._convertToEasyPostObject(response.body); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Retrieve all {@link Pickup pickups} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the pickups by. + * @returns - An object containing a list of {@link Pickup pickups} and pagination information. + */ + static async all(params: IPickupListParameters = {}) { + const url = "pickups"; + + return this._all(url, params); + } + + /** + * Retrieve the next page of Pickup collection. + * @param pickups An object containing a list of {@link Pickup pickups} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + static async getNextPage(pickups: any, pageSize: number | null = null) { + const url = "pickups"; + return this._getNextPage<{ pickups: IPickup[] }>( + url, + "pickups", + pickups, + pageSize + ); + } + + /** + * Retrieve a {@link Pickup pickup} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-pickup EasyPost API Documentation} for more information. + * @param id - The ID of the pickup to retrieve. + * @returns - The retrieved pickup. + */ + static async retrieve(id: string) { + const url = `pickups/${id}`; + + return this._retrieve(url); + } + }; diff --git a/src/services/rate_service/Rate.ts b/src/services/rate_service/Rate.ts new file mode 100644 index 000000000..1675fae97 --- /dev/null +++ b/src/services/rate_service/Rate.ts @@ -0,0 +1,83 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; + +/** + * The Rate class represents a summary of the price and details of a delivery service quote. + * + * @see https://www.easypost.com/docs/api/node#rates + */ +export type IRate = IObjectWithId<"Rate"> & + IDatedObject & { + /** + * The service level of the rate. + */ + service: string; + /** + * The carrier of the rate. + */ + carrier: string; + /** + * The ID of the carrier account associated with this rate. + */ + carrier_account_id: string; + /** + * The ID of the shipment associated with this rate. + */ + shipment_id: string; + /** + * The quote price of the rate. + */ + rate: string; + /** + * The currency of the rate. + */ + currency: string; + /** + * The in-store retail rate given with no account. + */ + retail_rate: string; + /** + * The currency of the retail rate. + */ + retail_currency: string; + /** + * The non-negotiated rate given for having an account with the carrier. + */ + list_rate: string; + /** + * The currency of the list rate. + */ + list_currency: string; + /** + * The number of days in transit for this rate. + */ + delivery_days: number; + /** + * The delivery date for this rate. + */ + delivery_date: string; + /** + * Whether the delivery window is guaranteed. + */ + delivery_date_guaranteed: boolean; + /** + * The earliest delivery date for this rate. + * This is deprecated and should be ignored. + */ + est_delivery_days: number; + /** + * The billing type of the rate. + */ + billing_type: string; + }; + +export type ISmartRate = IRate & { + time_in_transit: { + percentile_50: number; + percentile_75: number; + percentile_85: number; + percentile_90: number; + percentile_95: number; + percentile_97: number; + percentile_99: number; + }; +}; diff --git a/src/services/rate_service.js b/src/services/rate_service/index.ts similarity index 70% rename from src/services/rate_service.js rename to src/services/rate_service/index.ts index 34d33bfeb..852764e49 100644 --- a/src/services/rate_service.js +++ b/src/services/rate_service/index.ts @@ -1,6 +1,10 @@ -import baseService from './base_service'; +import EasyPost from "../.."; +import baseService from "../base_service"; +import { IRate } from "./Rate"; -export default (easypostClient) => +export * from "./Rate"; + +export default (easypostClient: EasyPost) => /** * The RateService class provides methods for interacting with EasyPost {@link Rate} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -12,9 +16,9 @@ export default (easypostClient) => * @param {string} id - The ID of the rate to retrieve. * @returns {Rate} - The retrieved rate. */ - static async retrieve(id) { + static async retrieve(id: string) { const url = `rates/${id}`; - return this._retrieve(url); + return this._retrieve(url); } }; diff --git a/src/services/referral_customer_service.js b/src/services/referral_customer_service.js deleted file mode 100644 index 365497ac3..000000000 --- a/src/services/referral_customer_service.js +++ /dev/null @@ -1,185 +0,0 @@ -import superagent from 'superagent'; - -import Constants from '../constants'; -import EasyPostClient from '../easypost'; -import ExternalApiError from '../errors/api/external_api_error'; -import baseService from './base_service'; - -const util = require('util'); - -/** - * Get an instance of the EasyPostClient using the referral user's API key. - * @private - * @param {EasyPostClient} client - The EasyPostClient to copy. - * @param {string} referralApiKey - The referral user's API key. - * @returns {EasyPostClient} - An instance of the EasyPostClient. - */ -function _getReferralClient(client, referralApiKey) { - return EasyPostClient.copyClient(client, { - apiKey: referralApiKey, - }); -} - -/** - * Get EasyPost's Stripe API key used to create credit cards on Stripe's servers. - * @private - * @param {EasyPostClient} easypostClient - The EasyPostClient to use. - * @returns {string} - The Stripe API key. - */ -async function _getEasyPostStripeKey(easypostClient) { - const url = 'partners/stripe_public_key'; - - const response = await easypostClient._get(url); - - return response.body.public_key; -} - -/** - * Send the credit card details to Stripe to get a Stripe credit card token. - * @private - * @param {string} stripeKey - The Stripe API key. - * @param {string} number - Credit card number. - * @param {string} expirationMonth - Credit card expiration month. - * @param {string} expirationYear - Credit card expiration year. - * @param {string} cvc - Credit card CVC. - * @returns {Promise} - Stripe credit card token. - */ -async function _sendCardDetailsToStripe(stripeKey, number, expirationMonth, expirationYear, cvc) { - // Stripe's endpoint requires form-encoded requests - const url = `https://api.stripe.com/v1/tokens?card[number]=${number}&card[exp_month]=${expirationMonth}&card[exp_year]=${expirationYear}&card[cvc]=${cvc}`; - - const request = superagent.post(url).set({ - Authorization: `Bearer ${stripeKey}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }); - - try { - const response = await request; - - return response.body.id; - } catch (error) { - throw new ExternalApiError({ - message: util.format(Constants.EXTERNAL_API_CALL_FAILED, 'Stripe'), - }); - } -} - -/** - * Send the Stripe credit card token to EasyPost to add the card to the user's account. - * @private - * @param {EasyPostClient} client - The EasyPostClient to use. - * @param {string} referralApiKey - The referral user's production API key. - * @param {string} stripeCreditCardToken - Stripe credit card token. - * @param {string} priority - Whether to add the card as the 'primary' or 'secondary' card. - * @returns {Object} - Response body (EasyPost payment method object). - */ -async function _sendCardDetailsToEasyPost(client, referralApiKey, stripeCreditCardToken, priority) { - const _client = _getReferralClient(client, referralApiKey); - const url = 'credit_cards'; - const params = { credit_card: { stripe_object_id: stripeCreditCardToken, priority } }; - - const response = await _client._post(url, params); - - return response.body; -} - -export default (easypostClient) => - /** - * The ReferralCustomerService class provides methods for interacting with EasyPost {@link User referral customer} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - class ReferralCustomerService extends baseService(easypostClient) { - /** - * Create a {@link User referral customer}. - * See {@link https://www.easypost.com/docs/api/node#create-a-referral-customer EasyPost API Documentation} for more information. - * @param {Object} params - The referral customer's information. - * @returns {User} - The newly created referral customer. - */ - static async create(params) { - const url = 'referral_customers'; - - const wrappedParams = { - user: params, - }; - - return this._create(url, wrappedParams); - } - - /** - * Update a {@link User referral customer's} email address. - * See {@link https://www.easypost.com/docs/api/node#update-a-referral-customer EasyPost API Documentation} for more information. - * @param {string} referralUserId - The ID of the referral customer to update. - * @param {string} email - The new email address. - * @returns {boolean} - Returns true if the referral was updated successfully, false otherwise. - */ - static async updateEmail(referralUserId, email) { - const url = `referral_customers/${referralUserId}`; - const wrappedParams = { user: { email } }; - - await easypostClient._put(url, wrappedParams); // will throw if there's an error - - return true; - } - - /** - * Add a credit card to a {@link User referral customer's} account. - * See {@link https://www.easypost.com/docs/api/node#create-credit-card EasyPost API Documentation} for more information. - * @param {string} referralApiKey - The referral customer's production API key. - * @param {string} number - The credit card number. - * @param {string} expirationMonth - The credit card expiration month. - * @param {string} expirationYear - The credit card expiration year. - * @param {string} cvc - The credit card CVC. - * @param {string} priority - Whether to add the card as 'primary' or 'secondary' payment method (defaults to 'primary'). - * @returns {Object} - An object representing the newly-added credit card. - */ - static async addCreditCard( - referralApiKey, - number, - expirationMonth, - expirationYear, - cvc, - priority = 'primary', - ) { - const stripeKey = await _getEasyPostStripeKey(easypostClient); // will throw if there's an error - - const stripeCreditCardId = await _sendCardDetailsToStripe( - stripeKey, - number, - expirationMonth, - expirationYear, - cvc, - ); // will throw if there's an error - - const paymentMethod = await _sendCardDetailsToEasyPost( - easypostClient, - referralApiKey, - stripeCreditCardId, - priority, - ); // will throw if there's an error - - return paymentMethod; - } - - /** - * Retrieve all {@link User referral customers} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers EasyPost API Documentation} for more information. - * @param {Object} [params] - Parameters to filter the referral customers by. - * @returns {Object} - An object containing a list of {@link User referral customers} and pagination information. - */ - static async all(params = {}) { - const url = 'referral_customers'; - - return this._all(url, params); - } - - /** - * Retrieve the next page of Referral Customer collection. - * @param {Object} referralCustomers An object containing a list of {@link referral referralCustomers} and pagination information. - * @param {Number} pageSize The number of records to return on each page - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - static async getNextPage(referralCustomers, pageSize = null) { - const url = 'referral_customers'; - return this._getNextPage(url, 'referral_customers', referralCustomers, pageSize); - } - }; diff --git a/src/services/referral_customer_service/Referral.ts b/src/services/referral_customer_service/Referral.ts new file mode 100644 index 000000000..fba39db93 --- /dev/null +++ b/src/services/referral_customer_service/Referral.ts @@ -0,0 +1,8 @@ +import { IUser } from "../user_service"; + +/** + * A Referral represents a sub-user under a Partner or white-label account. + * + * @see https://www.easypost.com/docs/api/node#referral-customers + */ +export declare interface IReferral extends IUser {} diff --git a/src/services/referral_customer_service/ReferralCreateParameters.ts b/src/services/referral_customer_service/ReferralCreateParameters.ts new file mode 100644 index 000000000..ec28e1f5c --- /dev/null +++ b/src/services/referral_customer_service/ReferralCreateParameters.ts @@ -0,0 +1,7 @@ +import { ParametersToOmitOnCreate } from "../../utils/types"; +import { IReferral } from "./Referral"; + +export type IReferralCreateParameters = Omit< + IReferral, + ParametersToOmitOnCreate +>; diff --git a/src/services/referral_customer_service/ReferralListParameters.ts b/src/services/referral_customer_service/ReferralListParameters.ts new file mode 100644 index 000000000..dc6f19597 --- /dev/null +++ b/src/services/referral_customer_service/ReferralListParameters.ts @@ -0,0 +1,6 @@ +import { IAllMethodParameters } from "../../utils/types"; + +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers + */ +export type IReferralListParameters = IAllMethodParameters; diff --git a/src/services/referral_customer_service/index.ts b/src/services/referral_customer_service/index.ts new file mode 100644 index 000000000..0612c3926 --- /dev/null +++ b/src/services/referral_customer_service/index.ts @@ -0,0 +1,216 @@ +import util from "node:util"; +import superagent from "superagent"; + +import Constants from "../../constants"; +import EasyPostClient from "../../easypost"; +import ExternalApiError from "../../errors/api/external_api_error"; +import baseService from "../base_service"; +import EasyPost from "../.."; +import { IReferralCreateParameters } from "./ReferralCreateParameters"; +import { IReferral } from "./Referral"; +import { IReferralListParameters } from "./ReferralListParameters"; +import { IPaymentMethod } from "../billing_service"; + +export * from "./Referral"; +export * from "./ReferralCreateParameters"; +export * from "./ReferralListParameters"; + +/** + * Get an instance of the EasyPostClient using the referral user's API key. + * @private + * @param client - The EasyPostClient to copy. + * @param referralApiKey - The referral user's API key. + * @returns - An instance of the EasyPostClient. + */ +function _getReferralClient(client: EasyPost, referralApiKey: string) { + return EasyPostClient.copyClient(client, { + apiKey: referralApiKey, + }); +} + +/** + * Get EasyPost's Stripe API key used to create credit cards on Stripe's servers. + * @private + * @param easypostClient - The EasyPostClient to use. + * @returns - The Stripe API key. + */ +async function _getEasyPostStripeKey( + easypostClient: EasyPost +): Promise { + const url = "partners/stripe_public_key"; + + const response = await easypostClient._get(url); + + return response.body.public_key; +} + +/** + * Send the credit card details to Stripe to get a Stripe credit card token. + * @private + * @param stripeKey - The Stripe API key. + * @param number - Credit card number. + * @param expirationMonth - Credit card expiration month. + * @param expirationYear - Credit card expiration year. + * @param cvc - Credit card CVC. + * @returns - Stripe credit card token. + */ +async function _sendCardDetailsToStripe( + stripeKey: string, + number: string, + expirationMonth: string, + expirationYear: string, + cvc: string +): Promise { + // Stripe's endpoint requires form-encoded requests + const url = `https://api.stripe.com/v1/tokens?card[number]=${number}&card[exp_month]=${expirationMonth}&card[exp_year]=${expirationYear}&card[cvc]=${cvc}`; + + const request = superagent.post(url).set({ + Authorization: `Bearer ${stripeKey}`, + "Content-Type": "application/x-www-form-urlencoded", + }); + + try { + const response = await request; + + return response.body.id; + } catch (error) { + throw new ExternalApiError({ + message: util.format(Constants.EXTERNAL_API_CALL_FAILED, "Stripe"), + }); + } +} + +/** + * Send the Stripe credit card token to EasyPost to add the card to the user's account. + * @private + * @param client - The EasyPostClient to use. + * @param referralApiKey - The referral user's production API key. + * @param stripeCreditCardToken - Stripe credit card token. + * @param priority - Whether to add the card as the 'primary' or 'secondary' card. + * @returns - Response body (EasyPost payment method object). + */ +async function _sendCardDetailsToEasyPost( + client: EasyPostClient, + referralApiKey: string, + stripeCreditCardToken: string, + priority: string +): Promise { + const _client = _getReferralClient(client, referralApiKey); + const url = "credit_cards"; + const params = { + credit_card: { stripe_object_id: stripeCreditCardToken, priority }, + }; + + const response = await _client._post(url, params); + + return response.body; +} + +export default (easypostClient: EasyPost) => + /** + * The ReferralCustomerService class provides methods for interacting with EasyPost {@link User referral customer} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + class ReferralCustomerService extends baseService(easypostClient) { + /** + * Create a {@link User referral customer}. + * See {@link https://www.easypost.com/docs/api/node#create-a-referral-customer EasyPost API Documentation} for more information. + * @param params - The referral customer's information. + * @returns - The newly created referral customer. + */ + static async create(params: IReferralCreateParameters) { + const url = "referral_customers"; + + const wrappedParams = { + user: params, + }; + + return this._create(url, wrappedParams); + } + + /** + * Update a {@link User referral customer's} email address. + * See {@link https://www.easypost.com/docs/api/node#update-a-referral-customer EasyPost API Documentation} for more information. + * @param referralUserId - The ID of the referral customer to update. + * @param email - The new email address. + * @returns - Returns true if the referral was updated successfully, false otherwise. + */ + static async updateEmail(referralUserId: string, email: string) { + const url = `referral_customers/${referralUserId}`; + const wrappedParams = { user: { email } }; + + await easypostClient._put(url, wrappedParams); // will throw if there's an error + + return true; + } + + /** + * Add a credit card to a {@link User referral customer's} account. + * See {@link https://www.easypost.com/docs/api/node#create-credit-card EasyPost API Documentation} for more information. + * @param referralApiKey - The referral customer's production API key. + * @param number - The credit card number. + * @param expirationMonth - The credit card expiration month. + * @param expirationYear - The credit card expiration year. + * @param cvc - The credit card CVC. + * @param priority - Whether to add the card as 'primary' or 'secondary' payment method (defaults to 'primary'). + * @returns - An object representing the newly-added credit card. + */ + static async addCreditCard( + referralApiKey: string, + number: string, + expirationMonth: string, + expirationYear: string, + cvc: string, + priority: "primary" | "secondary" = "primary" + ) { + const stripeKey = await _getEasyPostStripeKey(easypostClient); // will throw if there's an error + + const stripeCreditCardId = await _sendCardDetailsToStripe( + stripeKey, + number, + expirationMonth, + expirationYear, + cvc + ); // will throw if there's an error + + const paymentMethod = await _sendCardDetailsToEasyPost( + easypostClient, + referralApiKey, + stripeCreditCardId, + priority + ); // will throw if there's an error + + return paymentMethod; + } + + /** + * Retrieve all {@link User referral customers} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the referral customers by. + * @returns - An object containing a list of {@link User referral customers} and pagination information. + */ + static async all(params: IReferralListParameters = {}) { + const url = "referral_customers"; + + return this._all(url, params); + } + + /** + * Retrieve the next page of Referral Customer collection. + * @param referralCustomers An object containing a list of {@link referral referralCustomers} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + static async getNextPage( + referralCustomers: any, + pageSize: number | null = null + ) { + const url = "referral_customers"; + return this._getNextPage<{ referral_customers: IReferral[] }>( + url, + "referral_customers", + referralCustomers, + pageSize + ); + } + }; diff --git a/src/services/refund_service.js b/src/services/refund_service.js deleted file mode 100644 index 6c388be02..000000000 --- a/src/services/refund_service.js +++ /dev/null @@ -1,59 +0,0 @@ -import baseService from './base_service'; - -export default (easypostClient) => - /** - * The RefundService class provides methods for interacting with EasyPost {@link Refund} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - class RefundService extends baseService(easypostClient) { - /** - * Create a {@link Refund refund}. - * See {@link https://www.easypost.com/docs/api/node#create-a-refund EasyPost API Documentation} for more information. - * @param {Object} params - The parameters to create a refund with. - * @returns {Refund} - The created refund. - */ - static async create(params) { - const url = 'refunds'; - - const wrappedParams = { - refund: params, - }; - - return this._create(url, wrappedParams); - } - - /** - * Retrieve all {@link Refund refunds} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds EasyPost API Documentation} for more information. - * @param {Object} [params] - The parameters to filter the refunds by. - * @returns {Object} - An object containing the list of {@link Refund refunds} and pagination information. - */ - static async all(params = {}) { - const url = 'refunds'; - - return this._all(url, params); - } - - /** - * Retrieve the next page of Refund collection. - * @param {Object} refunds An object containing a list of {@link Refund refunds} and pagination information. - * @param {Number} pageSize The number of records to return on each page - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - static async getNextPage(refunds, pageSize = null) { - const url = 'refunds'; - return this._getNextPage(url, 'refunds', refunds, pageSize); - } - - /** - * Retrieve a {@link Refund refund} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-refund EasyPost API Documentation} for more information. - * @param {string} id - The ID of the refund to retrieve. - * @returns {Refund} - The retrieved refund. - */ - static async retrieve(id) { - const url = `refunds/${id}`; - - return this._retrieve(url); - } - }; diff --git a/src/services/refund_service/Refund.ts b/src/services/refund_service/Refund.ts new file mode 100644 index 000000000..f2c90edea --- /dev/null +++ b/src/services/refund_service/Refund.ts @@ -0,0 +1,36 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; + +/** + * The Refund object represents a refunded shipment, and includes details about the related Shipment and tracking code. + * USPS shipping labels can be refunded if requested within 30 days of generation. + * The processing time is at least 15 days, after which the funds will return to your EasyPost balance. + * EasyPost fees will also be refunded. To qualify, a shipment must not have been scanned by the USPS. + * UPS and FedEx shipping labels may be refunded within 90 days of creation. + */ +export type IRefund = IObjectWithId<"Refund"> & + IDatedObject & { + /** + * The tracking code of the related Shipment + */ + tracking_code: string; + + /** + * The confirmation number for the refund request to the carrier + */ + confirmation_number: string; + + /** + * The status of the refund request, reported by the carrier. Possible values are "submitted", "refunded", or "rejected" + */ + status: "submitted" | "refunded" | "rejected"; + + /** + * The carrier the refund request was submitted to + */ + carrier: string; + + /** + * The ID of the related Shipment being refunded + */ + shipment_id: string; + }; diff --git a/types/Refund/RefundCreateParameters.d.ts b/src/services/refund_service/RefundCreateParameters.ts similarity index 85% rename from types/Refund/RefundCreateParameters.d.ts rename to src/services/refund_service/RefundCreateParameters.ts index 9340be75f..4ef6308ae 100644 --- a/types/Refund/RefundCreateParameters.d.ts +++ b/src/services/refund_service/RefundCreateParameters.ts @@ -1,7 +1,7 @@ /** * @see https://www.easypost.com/docs/api/node#create-a-refund */ -export declare interface IRefundCreateParameters { +export type IRefundCreateParameters = { /** * The carrier to request a refund from */ @@ -11,4 +11,4 @@ export declare interface IRefundCreateParameters { * A list of tracking codes to request refunds for. Even for a single tracking code, it needs to be submitted as a list. */ tracking_codes: string[]; -} +}; diff --git a/src/services/refund_service/RefundListParameters.ts b/src/services/refund_service/RefundListParameters.ts new file mode 100644 index 000000000..96e264b34 --- /dev/null +++ b/src/services/refund_service/RefundListParameters.ts @@ -0,0 +1,6 @@ +import { IAllMethodParameters } from "../../utils/types"; + +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds + */ +export type IRefundListParameters = IAllMethodParameters; diff --git a/src/services/refund_service/index.ts b/src/services/refund_service/index.ts new file mode 100644 index 000000000..9cc3da710 --- /dev/null +++ b/src/services/refund_service/index.ts @@ -0,0 +1,72 @@ +import EasyPost from "../.."; +import baseService from "../base_service"; +import { IRefund } from "./Refund"; +import { IRefundCreateParameters } from "./RefundCreateParameters"; +import { IRefundListParameters } from "./RefundListParameters"; + +export * from "./Refund"; +export * from "./RefundCreateParameters"; +export * from "./RefundListParameters"; + +export default (easypostClient: EasyPost) => + /** + * The RefundService class provides methods for interacting with EasyPost {@link Refund} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + class RefundService extends baseService(easypostClient) { + /** + * Create a {@link Refund refund}. + * See {@link https://www.easypost.com/docs/api/node#create-a-refund EasyPost API Documentation} for more information. + * @param params - The parameters to create a refund with. + * @returns - The created refund. + */ + static async create(params: IRefundCreateParameters) { + const url = "refunds"; + + const wrappedParams = { + refund: params, + }; + + return this._create(url, wrappedParams); + } + + /** + * Retrieve all {@link Refund refunds} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the refunds by. + * @returns - An object containing the list of {@link Refund refunds} and pagination information. + */ + static async all(params: IRefundListParameters = {}) { + const url = "refunds"; + + return this._all<{ refunds: IRefund[] }>(url, params); + } + + /** + * Retrieve the next page of Refund collection. + * @param refunds An object containing a list of {@link Refund refunds} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + static async getNextPage(refunds: any, pageSize: number | null = null) { + const url = "refunds"; + return this._getNextPage<{ refunds: IRefund[] }>( + url, + "refunds", + refunds, + pageSize + ); + } + + /** + * Retrieve a {@link Refund refund} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-refund EasyPost API Documentation} for more information. + * @param id - The ID of the refund to retrieve. + * @returns - The retrieved refund. + */ + static async retrieve(id: string) { + const url = `refunds/${id}`; + + return this._retrieve(url); + } + }; diff --git a/src/services/report_service.js b/src/services/report_service.js deleted file mode 100644 index c78bf07bd..000000000 --- a/src/services/report_service.js +++ /dev/null @@ -1,68 +0,0 @@ -import baseService from './base_service'; - -export default (easypostClient) => - /** - * The ReportService class provides methods for interacting with EasyPost {@link Report} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - class ReportService extends baseService(easypostClient) { - /** - * Create a {@link Report report}. - * See {@link https://www.easypost.com/docs/api/node#create-a-report EasyPost API Documentation} for more information. - * @param {Object} params - The parameters to create a report with. - * @returns {Report} - The created report. - */ - static async create(params) { - const url = `reports/${params.type}`; - return this._create(url, params); - } - - /** - * Retrieve all {@link Report reports} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-reports EasyPost API Documentation} for more information. - * @param {Object} [params] - The parameters to filter the reports by. - * @returns {Object} - An object containing the list of {@link Report reports} and pagination information. - */ - static async all(params = {}) { - const type = params.type; - const url = `reports/${type}`; - - // delete "type" from params, so it doesn't get sent to the API - // eslint-disable-next-line no-param-reassign - delete params.type; - - try { - const response = await easypostClient._get(url, params); - // we want to add it back in here so that it can be used in the - // "getNextPage" call below - const responseObject = this._convertToEasyPostObject(response.body, { ...params, type }); - - return responseObject; - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Retrieve the next page of Report collection. - * @param {Object} reports An object containing a list of {@link Report reports} and pagination information. - * @param {Number} pageSize The number of records to return on each page - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - static async getNextPage(reports, pageSize = null) { - const url = `reports/${reports.reports[0]._params.type}`; - return this._getNextPage(url, 'reports', reports, pageSize); - } - - /** - * Retrieve a {@link Report report} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-report EasyPost API Documentation} for more information. - * @param {string} id - The ID of the report to retrieve. - * @returns {Report} - The retrieved report. - */ - static async retrieve(id) { - const url = `reports/${id}`; - - return this._retrieve(url); - } - }; diff --git a/src/services/report_service/Report.ts b/src/services/report_service/Report.ts new file mode 100644 index 000000000..7e9647875 --- /dev/null +++ b/src/services/report_service/Report.ts @@ -0,0 +1,59 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { TReportObjectType } from "./ReportObjectType"; + +/** + * A Report contains a csv that is a log of all the objects created within a certain time frame. + * + * Reports can be generated using the Reports Endpoint. + * You can create and view Reports created between any time frame defined between the start_date and end_date. + * + * The Report api can be categorized into several types. + * These types determine which EasyPost Object to produce a Report for, and should be passed as the type in our libraries: + * - cash_flow + * - insurance + * - payment_log + * - refund + * - shipment + * - shipment_invoice + * - tracker + * + * @see https://www.easypost.com/docs/api/node#report-object + */ +export type IReport = IObjectWithId & + IDatedObject & { + /** + * "new", "available", "failed", or null + */ + status: "new" | "available" | "failed" | null; + + /** + * A date string in YYYY-MM-DD form eg: "2016-02-02" + */ + start_date: string; + + /** + * A date string in YYYY-MM-DD form eg: "2016-02-03" + */ + end_date: string; + + /** + * Set true if you would like to include Refunds /Shipments /Trackers created by child users + */ + include_children?: boolean | null; + + /** + * A url that contains a link to the Report. + * Expires 30 seconds after retrieving this object + */ + url: string; + + /** + * Url expiring time + */ + url_expires_at: string; + + /** + * Set true if you would like to send an email containing the Report + */ + send_email?: boolean | null; + }; diff --git a/types/Report/ReportCreateParameters.d.ts b/src/services/report_service/ReportCreateParameters.ts similarity index 62% rename from types/Report/ReportCreateParameters.d.ts rename to src/services/report_service/ReportCreateParameters.ts index 43ec64bad..09243c2b8 100644 --- a/types/Report/ReportCreateParameters.d.ts +++ b/src/services/report_service/ReportCreateParameters.ts @@ -1,8 +1,11 @@ -export declare interface IReportCreateParameters { +import { TReportType } from "./ReportObjectType"; + +export type IReportCreateParameters = { + type: TReportType; start_date: string | null; end_date?: string | null; include_children?: boolean | null; send_email?: boolean | null; columns?: string[] | null; additional_columns?: string[] | null; -} +}; diff --git a/src/services/report_service/ReportListParameters.ts b/src/services/report_service/ReportListParameters.ts new file mode 100644 index 000000000..969f91aa0 --- /dev/null +++ b/src/services/report_service/ReportListParameters.ts @@ -0,0 +1,9 @@ +import { IAllMethodParameters } from "../../utils/types"; +import { TReportType } from "./ReportObjectType"; + +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds + */ +export type IReportListParameters = IAllMethodParameters & { + type: TReportType; +}; diff --git a/src/services/report_service/ReportObjectType.ts b/src/services/report_service/ReportObjectType.ts new file mode 100644 index 000000000..b58bbde44 --- /dev/null +++ b/src/services/report_service/ReportObjectType.ts @@ -0,0 +1,15 @@ +export type TReportObjectType = + | "CashFlowReport" + | "PaymentLogReport" + | "RefundReport" + | "ShipmentReport" + | "ShipmentInvoiceReport" + | "TrackerReport"; + +export type TReportType = + | "cash_flow" + | "payment_log" + | "refund" + | "shipment" + | "shipment_invoice" + | "tracker"; diff --git a/src/services/report_service/index.ts b/src/services/report_service/index.ts new file mode 100644 index 000000000..bc43165df --- /dev/null +++ b/src/services/report_service/index.ts @@ -0,0 +1,87 @@ +import EasyPost from "../.."; +import baseService from "../base_service"; +import { IReport } from "./Report"; +import { IReportCreateParameters } from "./ReportCreateParameters"; +import { IReportListParameters } from "./ReportListParameters"; + +export * from "./Report"; +export * from "./ReportCreateParameters"; +export * from "./ReportListParameters"; +export * from "./ReportObjectType"; + +export default (easypostClient: EasyPost) => + /** + * The ReportService class provides methods for interacting with EasyPost {@link Report} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + class ReportService extends baseService(easypostClient) { + /** + * Create a {@link Report report}. + * See {@link https://www.easypost.com/docs/api/node#create-a-report EasyPost API Documentation} for more information. + * @param params - The parameters to create a report with. + * @returns - The created report. + */ + static async create(params: IReportCreateParameters) { + const url = `reports/${params.type}`; + return this._create(url, params); + } + + /** + * Retrieve all {@link Report reports} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-reports EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the reports by. + * @returns - An object containing the list of {@link Report reports} and pagination information. + */ + static async all(params: IReportListParameters) { + const type = params.type; + const url = `reports/${type}`; + + try { + // don't send "type" param to API + const apiParams = { ...params } as Omit< + IReportListParameters, + "type" + > & { type?: any }; + delete apiParams.type; + + const response = await easypostClient._get(url, apiParams); + + const responseObject = this._convertToEasyPostObject( + response.body, + params + ); + + return responseObject; + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Retrieve the next page of Report collection. + * @param reports An object containing a list of {@link Report reports} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + static async getNextPage(reports: any, pageSize: number | null = null) { + const url = `reports/${reports.reports[0]._params.type}`; + return this._getNextPage<{ reports: IReport[] }>( + url, + "reports", + reports, + pageSize + ); + } + + /** + * Retrieve a {@link Report report} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-report EasyPost API Documentation} for more information. + * @param id - The ID of the report to retrieve. + * @returns - The retrieved report. + */ + static async retrieve(id: string) { + const url = `reports/${id}`; + + return this._retrieve(url); + } + }; diff --git a/src/services/scan_form_service.js b/src/services/scan_form_service.js deleted file mode 100644 index 51dfb3a88..000000000 --- a/src/services/scan_form_service.js +++ /dev/null @@ -1,71 +0,0 @@ -import baseService from './base_service'; - -export default (easypostClient) => - /** - * The ScanFormService class provides methods for interacting with EasyPost {@link ScanForm} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - class ScanFormService extends baseService(easypostClient) { - /** - * Create a {@link ScanForm scan form}. - * See {@link https://www.easypost.com/docs/api/node#create-a-scanform EasyPost API Documentation} for more information. - * @param {Object} params - The parameters to create a scan form with. - * @returns {ScanForm} - The created scan form. - */ - static async create(params) { - const url = 'scan_forms'; - - // wraps up params in `shipments` if the user didn't do it - // turn a list of shipment objects into a map of shipment ids - if (params.shipments) { - // eslint-disable-next-line no-param-reassign - params.shipments = params.shipments.map((s) => { - if (typeof s === 'string') { - return { id: s }; - } - return { id: s.id }; - }); - } - - const wrappedParams = { - scan_form: params, - }; - - return this._create(url, wrappedParams); - } - - /** - * Retrieve all {@link ScanForm scan forms} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-scanforms EasyPost API Documentation} for more information. - * @param {Object} [params] - The parameters to filter the scan forms by. - * @returns {Object} - An object containing the list of {@link ScanForm scan forms} and pagination information. - */ - static async all(params = {}) { - const url = 'scan_forms'; - - return this._all(url, params); - } - - /** - * Retrieve the next page of ScanForm collection. - * @param {Object} scanforms An object containing a list of {@link ScanForm scanforms} and pagination information. - * @param {Number} pageSize The number of records to return on each page - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - static async getNextPage(scanforms, pageSize = null) { - const url = 'scan_forms'; - return this._getNextPage(url, 'scan_forms', scanforms, pageSize); - } - - /** - * Retrieve a {@link ScanForm scan form} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-scanform EasyPost API Documentation} for more information. - * @param {string} id - The ID of the scan form to retrieve. - * @returns {ScanForm} - The retrieved scan form. - */ - static async retrieve(id) { - const url = `scan_forms/${id}`; - - return this._retrieve(url); - } - }; diff --git a/src/services/scan_form_service/ScanForm.ts b/src/services/scan_form_service/ScanForm.ts new file mode 100644 index 000000000..7975e9e8d --- /dev/null +++ b/src/services/scan_form_service/ScanForm.ts @@ -0,0 +1,54 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { IAddress } from "../address_service"; + +/** + * A ScanForm can be created to speed up and simplify the carrier pickup process. + * The ScanForm is one document that can be scanned to mark all included tracking codes as "Accepted for Shipment" by the carrier. + * The following criteria must met before creation: + * - Refunded Shipments cannot be added + * - Each Shipment must have the same origin address + * - Shipments must all be dated (using the label_date option) on or after the date the form is generated + * - Shipments cannot be added to more than one ScanForm + * - Existing ScanForms may not be updated with additional Shipments. If a ScanForm already exists, and new Shipments need to be added, a new ScanForm must be created. + * - Shipments should be provided in the form of an array + * + * @see https://www.easypost.com/docs/api/node#scan-form-object + */ +export type IScanForm = IObjectWithId<"ScanForm"> & + IDatedObject & { + /** + * Current status. + * Possible values are "creating", "created" and "failed" + */ + status: "creating" | "created" | "failed"; + + /** + * Human-readable message explaining any failures + */ + message: string; + + /** + * Address that the Shipments will be shipped from + */ + address: IAddress; + + /** + * Tracking codes included on the ScanForm + */ + tracking_codes: string[]; + + /** + * Url of the document + */ + form_url: string; + + /** + * File format of the document + */ + form_file_type: string; + + /** + * The id of the associated Batch. Unique, starts with "batch_" + */ + batch_id: string; + }; diff --git a/src/services/scan_form_service/ScanFormCreateParameters.ts b/src/services/scan_form_service/ScanFormCreateParameters.ts new file mode 100644 index 000000000..20f3ad90e --- /dev/null +++ b/src/services/scan_form_service/ScanFormCreateParameters.ts @@ -0,0 +1,8 @@ +import { DeepPartial } from "../../utils/types"; +import { IShipmentCreateParameters } from "../shipment_service"; + +export type IScanFormCreateParameters = { + shipments: + | (DeepPartial & { id: string })[] + | string[]; +}; diff --git a/src/services/scan_form_service/ScanFormListParameters.ts b/src/services/scan_form_service/ScanFormListParameters.ts new file mode 100644 index 000000000..703134e6c --- /dev/null +++ b/src/services/scan_form_service/ScanFormListParameters.ts @@ -0,0 +1,6 @@ +import { IAllMethodParameters } from "../../utils/types"; + +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-scan-forms + */ +export type IScanFormListParameters = IAllMethodParameters; diff --git a/src/services/scan_form_service/index.ts b/src/services/scan_form_service/index.ts new file mode 100644 index 000000000..3df6de47d --- /dev/null +++ b/src/services/scan_form_service/index.ts @@ -0,0 +1,87 @@ +import EasyPost from "../.."; +import baseService from "../base_service"; +import { IScanForm } from "./ScanForm"; +import { IScanFormCreateParameters } from "./ScanFormCreateParameters"; +import { IScanFormListParameters } from "./ScanFormListParameters"; + +export * from "./ScanForm"; +export * from "./ScanFormCreateParameters"; +export * from "./ScanFormListParameters"; + +export default (easypostClient: EasyPost) => + /** + * The ScanFormService class provides methods for interacting with EasyPost {@link ScanForm} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + class ScanFormService extends baseService(easypostClient) { + /** + * Create a {@link ScanForm scan form}. + * See {@link https://www.easypost.com/docs/api/node#create-a-scanform EasyPost API Documentation} for more information. + * @param params - The parameters to create a scan form with. + * @returns - The created scan form. + */ + static async create(params: IScanFormCreateParameters) { + const url = "scan_forms"; + + // wraps up params in `shipments` if the user didn't do it + // turn a list of shipment objects into a map of shipment ids + if (params.shipments) { + // eslint-disable-next-line no-param-reassign + params.shipments = params.shipments.map((s) => { + if (typeof s === "string") { + return { id: s }; + } + return { id: s.id }; + }); + } + + const wrappedParams = { + scan_form: params, + }; + + return this._create(url, wrappedParams); + } + + /** + * Retrieve all {@link ScanForm scan forms} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-scanforms EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the scan forms by. + * @returns - An object containing the list of {@link ScanForm scan forms} and pagination information. + */ + static async all(params: IScanFormListParameters = {}) { + const url = "scan_forms"; + + return this._all<{ scan_forms: IScanForm[] }>(url, params); + } + + /** + * Retrieve the next page of ScanForm collection. + * @param scanForms An object containing a list of {@link ScanForm scanForms} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + static async getNextPage( + scanForms: { scan_forms: any[] }, + pageSize: number | null = null + ) { + const url = "scan_forms"; + return this._getNextPage<{ scan_forms: IScanForm[] }>( + url, + "scan_forms", + scanForms, + pageSize + ); + } + + /** + * Retrieve a {@link ScanForm scan form} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-scanform EasyPost API Documentation} for more information. + * @param id - The ID of the scan form to retrieve. + * @returns - The retrieved scan form. + */ + static async retrieve(id: string) { + const url = `scan_forms/${id}`; + + return this._retrieve(url); + } + }; diff --git a/src/services/shipment_service.js b/src/services/shipment_service.js deleted file mode 100644 index 5dcecddd8..000000000 --- a/src/services/shipment_service.js +++ /dev/null @@ -1,261 +0,0 @@ -import Constants from '../constants'; -import baseService from './base_service'; - -export default (easypostClient) => - /** - * The ShipmentService class provides methods for interacting with EasyPost {@link Shipment} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - class ShipmentService extends baseService(easypostClient) { - /** - * Create a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#create-a-shipment EasyPost API Documentation} for more information. - * @param {Object} params - The parameters to create a shipment with. - * @returns {Shipment} - The created shipment. - */ - static async create(params) { - const url = 'shipments'; - - const wrappedParams = { - shipment: params, - }; - - return this._create(url, wrappedParams); - } - - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param {string} id - The ID of the shipment to purchase. - * @param {Rate} rate - The rate to purchase the shipment with. - * @param {number|null} [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param {string|null} [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns {Shipment} - The purchased shipment. - */ - static async buy(id, rate, insuranceAmount = null, endShipperId = null) { - let rateId = rate; - - if (typeof rate === 'object') { - rateId = rate.id; - } - - const url = `shipments/${id}/buy`; - - const wrappedParams = { - rate: { - id: rateId, - }, - }; - - if (insuranceAmount) { - wrappedParams.insurance = insuranceAmount; - } - - if (endShipperId) { - wrappedParams.end_shipper_id = endShipperId; - } - - try { - const response = await easypostClient._post(url, wrappedParams); - - return this._convertToEasyPostObject(response.body, wrappedParams); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Convert the label format of a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#convert-the-label-format-of-a-shipment EasyPost API Documentation} for more information. - * @param {string} id - The ID of the shipment to convert the label format of. - * @param {string} format - The format to convert the label to. - * @returns {Shipment} - The shipment with the converted label format. - */ - static async convertLabelFormat(id, format) { - const url = `shipments/${id}/label`; - const wrappedParams = { file_format: format }; - - try { - const response = await easypostClient._get(url, wrappedParams); - - return this._convertToEasyPostObject(response.body, wrappedParams); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Regenerate {@link Rate rates} for a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#regenerate-rates-for-a-shipment EasyPost API Documentation} for more information. - * @param {string} id - The ID of the shipment to regenerate rates for. - * @returns {Shipment} - The shipment with regenerated rates. - */ - static async regenerateRates(id) { - const url = `shipments/${id}/rerate`; - const wrappedParams = {}; - - try { - const response = await easypostClient._post(url, wrappedParams); - - return this._convertToEasyPostObject(response.body, wrappedParams); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Get SmartRates for a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-time-in-transit-statistics-across-all-rates-for-a-shipment EasyPost API Documentation} for more information. - * @param {string} id - The ID of the shipment to get SmartRates for. - * @returns {Rate[]} - The SmartRates for the shipment. - */ - static async getSmartRates(id) { - const url = `shipments/${id}/smartrate`; - - try { - const response = await easypostClient._get(url); - - return this._convertToEasyPostObject(response.body.result); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Insure a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#insure-a-shipment EasyPost API Documentation} for more information. - * @param {string} id - The ID of the shipment to insure. - * @param {number|string} amount - The amount to insure the shipment for. - * @returns {Shipment} - The insured shipment. - */ - static async insure(id, amount) { - const url = `shipments/${id}/insure`; - const wrappedParams = { amount }; - - try { - const response = await easypostClient._post(url, wrappedParams); - - return this._convertToEasyPostObject(response.body, wrappedParams); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Generate a form for a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#create-form EasyPost API Documentation} for more information. - * @param {string} id - The ID of the shipment to generate a form for. - * @param {string} formType - The type of form to generate. - * @param {Map} [formOptions] - Options for the form. - * @returns {Shipment} - The shipment with the generated form attached. - */ - static async generateForm(id, formType, formOptions = {}) { - const url = `shipments/${id}/forms`; - const wrappedParams = { - form: { - ...formOptions, - type: formType, - }, - }; - - try { - const response = await easypostClient._post(url, wrappedParams); - - return this._convertToEasyPostObject(response.body, wrappedParams); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Refund a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#refund-a-shipment EasyPost API Documentation} for more information. - * @param {string} id - The ID of the shipment to refund. - * @returns {Shipment} - The refunded shipment. - */ - static async refund(id) { - const url = `shipments/${id}/refund`; - - try { - const response = await easypostClient._post(url); - - return this._convertToEasyPostObject(response.body); - } catch (e) { - return Promise.reject(e); - } - } - - /** - * Get the lowest SmartRate of a shipment. - * @param {string} id - The ID of the shipment to get the lowest SmartRate of. - * @param {number} deliveryDays - The number of days the shipment will take to deliver. - * @param {string} deliveryAccuracy - The accuracy of the delivery days. - * @returns {Rate} - The lowest SmartRate of the shipment. - */ - static async lowestSmartRate(id, deliveryDays, deliveryAccuracy) { - const smartRates = await this.getSmartRates(id); - return Constants.Utils.getLowestSmartRate( - smartRates, - deliveryDays, - deliveryAccuracy.toLowerCase(), - ); - } - - /** - * Retrieve all {@link Shipment shipments} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments EasyPost API Documentation} for more information. - * @param {Object} [params] - Parameters to filter the shipments by. - * @returns {Object} - An object containing a list of {@link Shipment shipments} and pagination information. - */ - static async all(params = {}) { - const url = 'shipments'; - - return this._all(url, params); - } - - /** - * Retrieve the next page of Shipment collection. - * @param {Object} shipments An object containing a list of {@link Shipment shipments} and pagination information. - * @param {Number} pageSize The number of records to return on each page - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - static async getNextPage(shipments, pageSize = null) { - const url = 'shipments'; - - return this._getNextPage(url, 'shipments', shipments, pageSize); - } - - /** - * Retrieve a {@link Shipment shipment} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-shipment EasyPost API Documentation} for more information. - * @param {string} id - The ID of the shipment to retrieve. - * @returns {Shipment} - The shipment with the given ID. - */ - static async retrieve(id) { - const url = `shipments/${id}`; - - return this._retrieve(url); - } - - /** - * Retrieves the estimated delivery date of each Rate via SmartRate. - * @param {string} id - * @param {string} plannedShipDate - * @returns {Array} - An array of the estimated delivery date and rates. - */ - static async retrieveEstimatedDeliveryDate(id, plannedShipDate) { - const url = `shipments/${id}/smartrate/delivery_date`; - - const params = { - planned_ship_date: plannedShipDate, - }; - - try { - const response = await easypostClient._get(url, params); - - return this._convertToEasyPostObject(response.body.rates ?? [], params); - } catch (e) { - return Promise.reject(e); - } - } - }; diff --git a/src/services/shipment_service/Form.ts b/src/services/shipment_service/Form.ts new file mode 100644 index 000000000..7b5782bef --- /dev/null +++ b/src/services/shipment_service/Form.ts @@ -0,0 +1,31 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; + +/** + * @see https://www.easypost.com/docs/api/node#form-object + */ +export type IForm = IObjectWithId<"Form"> & + IDatedObject & { + /** + * The type of form that we returned, can be one of "cn22", "cod_return_label", "commercial_invoice", "high_value_report", "label_qr_code", "nafta_certificate_of_origin", "order_summary", "return_packing_slip", "rma_qr_code" + */ + form_type: + | "cn22" + | "cod_return_label" + | "commercial_invoice" + | "high_value_report" + | "label_qr_code" + | "nafta_certificate_of_origin" + | "order_summary" + | "return_packing_slip" + | "rma_qr_code"; + + /** + * The address we return the form back at + */ + form_url: string; + + /** + * If we have submitted the form to the carrier on behalf of the customer + */ + submitted_electronically: boolean; + }; diff --git a/types/Shipment/Message.d.ts b/src/services/shipment_service/Message.ts similarity index 96% rename from types/Shipment/Message.d.ts rename to src/services/shipment_service/Message.ts index 131cd22c3..5ff422582 100644 --- a/types/Shipment/Message.d.ts +++ b/src/services/shipment_service/Message.ts @@ -7,7 +7,7 @@ * * @see https://www.easypost.com/docs/api/node#message-object */ -export declare interface IMessage { +export type IMessage = { /** * the name of the carrier generating the error, e.g. "UPS" */ @@ -27,4 +27,4 @@ export declare interface IMessage { * the account id of the carrier. Useful if you have multiple accounts with the same carrier */ carrier_account_id: string; -} +}; diff --git a/src/services/shipment_service/Options/LabelFormat.ts b/src/services/shipment_service/Options/LabelFormat.ts new file mode 100644 index 000000000..e1b8d74a8 --- /dev/null +++ b/src/services/shipment_service/Options/LabelFormat.ts @@ -0,0 +1 @@ +export declare type LabelFormat = "PNG" | "PDF" | "ZPL" | "EPL2"; diff --git a/types/Shipment/Options/Options.d.ts b/src/services/shipment_service/Options/Options.ts similarity index 89% rename from types/Shipment/Options/Options.d.ts rename to src/services/shipment_service/Options/Options.ts index f7ec2ad86..69a6404dc 100644 --- a/types/Shipment/Options/Options.d.ts +++ b/src/services/shipment_service/Options/Options.ts @@ -1,5 +1,5 @@ -import { LabelFormat } from './LabelFormat'; -import { TPrintCustomCode } from './PrintCustomCode'; +import { LabelFormat } from "./LabelFormat"; +import { TPrintCustomCode } from "./PrintCustomCode"; /** * Shipments can have a variety of additional options which you can specify when creating a shipment. @@ -7,7 +7,7 @@ import { TPrintCustomCode } from './PrintCustomCode'; * * @see https://www.easypost.com/docs/api/node#options-object */ -export declare interface IOptions { +export type IOptions = { /** * Setting this option to true, will add an additional handling charge. * An Additional Handling charge may be applied to the following: @@ -50,7 +50,7 @@ export declare interface IOptions { /** * Method for payment. "CASH", "CHECK", "MONEY_ORDER" */ - cod_method?: 'CASH' | 'CHECK' | 'MONEY_ORDER' | null; + cod_method?: "CASH" | "CHECK" | "MONEY_ORDER" | null; /** * The ID of the Address to which the COD payment should be returned. @@ -84,12 +84,12 @@ export declare interface IOptions { * - "NO_SIGNATURE" - DHL Express Signature Release */ delivery_confirmation?: - | 'ADULT_SIGNATURE' - | 'SIGNATURE' - | 'NO_SIGNATURE' - | 'INDIRECT_SIGNATURE' - | 'ADULT_SIGNATURE_RESTRICTED' - | 'SIGNATURE_RESTRICTED' + | "ADULT_SIGNATURE" + | "SIGNATURE" + | "NO_SIGNATURE" + | "INDIRECT_SIGNATURE" + | "ADULT_SIGNATURE_RESTRICTED" + | "SIGNATURE_RESTRICTED" | null; /** @@ -104,13 +104,13 @@ export declare interface IOptions { * - "DROP_BOX" - "DROP_BOX" */ dropoff_type?: - | 'REGULAR_PICKUP' - | 'SCHEDULED_PICKUP' - | 'RETAIL_LOCATION' - | 'STATION' - | 'DROP_BOX' - | 'REQUEST_COURIER' - | 'BUSINESS_SERVICE_CENTER' + | "REGULAR_PICKUP" + | "SCHEDULED_PICKUP" + | "RETAIL_LOCATION" + | "STATION" + | "DROP_BOX" + | "REQUEST_COURIER" + | "BUSINESS_SERVICE_CENTER" | null; /** @@ -144,23 +144,23 @@ export declare interface IOptions { * - country - (string) Setting country code that the account is based in. * - postal_code - (string) Setting postal code that the account is based in. */ - duty_payment: object | null; + duty_payment?: object | null; /** * Possible values "ADDRESS_SERVICE_REQUESTED", "FORWARDING_SERVICE_REQUESTED", "CHANGE_SERVICE_REQUESTED", "RETURN_SERVICE_REQUESTED", "LEAVE_IF_NO_RESPONSE" */ endorsement?: - | 'ADDRESS_SERVICE_REQUESTED' - | 'FORWARDING_SERVICE_REQUESTED' - | 'CHANGE_SERVICE_REQUESTED' - | 'RETURN_SERVICE_REQUESTED' - | 'LEAVE_IF_NO_RESPONSE' + | "ADDRESS_SERVICE_REQUESTED" + | "FORWARDING_SERVICE_REQUESTED" + | "CHANGE_SERVICE_REQUESTED" + | "RETURN_SERVICE_REQUESTED" + | "LEAVE_IF_NO_RESPONSE" | null; /** * Specify the responsible EndShipper for the shipment by passing in an EndShipper ID. */ - end_shipper_id: string | null; + end_shipper_id?: string | null; /** * Additional cost to be added to the invoice of this shipment. @@ -179,15 +179,15 @@ export declare interface IOptions { * Applies to USPS, FedEx and DHL eCommerce. */ hazmat?: - | 'PRIMARY_CONTAINED' - | 'PRIMARY_PACKED' - | 'PRIMARY' - | 'SECONDARY_CONTAINED' - | 'SECONDARY_PACKED' - | 'SECONDARY' - | 'ORMD' - | 'LIMITED_QUANTITY' - | 'LITHIUM' + | "PRIMARY_CONTAINED" + | "PRIMARY_PACKED" + | "PRIMARY" + | "SECONDARY_CONTAINED" + | "SECONDARY_PACKED" + | "SECONDARY" + | "ORMD" + | "LIMITED_QUANTITY" + | "LITHIUM" | null; /** @@ -201,17 +201,17 @@ export declare interface IOptions { * Setting this value to anything other than "DDP" will pass the cost and responsibility of duties on to the recipient of the package(s), as specified by Incoterms rules */ incoterm?: - | 'EXW' - | 'FCA' - | 'CPT' - | 'CIP' - | 'DAT' - | 'DAP' - | 'DDP' - | 'FAS' - | 'FOB' - | 'CFR' - | 'CIF' + | "EXW" + | "FCA" + | "CPT" + | "CIP" + | "DAT" + | "DAP" + | "DDP" + | "FAS" + | "FOB" + | "CFR" + | "CIF" | null; /** @@ -242,11 +242,11 @@ export declare interface IOptions { /** * Setting payment type to bill the correct account for purchasing postage. */ - payment: { + payment?: { /** * Supported values are "SENDER", "THIRD_PARTY", "RECEIVER", "COLLECT". Defaults to SENDER. */ - type?: 'SENDER' | 'THIRD_PARTY' | 'RECEIVER' | 'COLLECT' | null; + type?: "SENDER" | "THIRD_PARTY" | "RECEIVER" | "COLLECT" | null; /** * Setting account number. @@ -270,12 +270,12 @@ export declare interface IOptions { /** * The earliest a package should be picked up. Supported carriers vary. */ - pickup_min_datetime: string | null; + pickup_min_datetime?: string | null; /** * The latest a package should be picked up. Supported carriers vary. */ - pickup_man_datetime: string | null; + pickup_man_datetime?: string | null; /** * You can optionally print custom messages on labels. @@ -335,7 +335,7 @@ export declare interface IOptions { * This option allows you to request restrictive rates from USPS. * Can set to 'USPS.MEDIAMAIL' or 'USPS.LIBRARYMAIL'. */ - special_rates_eligibility?: 'USPS.MEDIAMAIL' | 'USPS.LIBRARYMAIL' | null; + special_rates_eligibility?: "USPS.MEDIAMAIL" | "USPS.LIBRARYMAIL" | null; /** * You can use this to override the hub ID you have on your account. @@ -373,4 +373,4 @@ export declare interface IOptions { * Only applies to the USPS. */ return_receipt?: boolean | null; -} +}; diff --git a/types/Shipment/Options/PrintCustomCode.d.ts b/src/services/shipment_service/Options/PrintCustomCode.ts similarity index 83% rename from types/Shipment/Options/PrintCustomCode.d.ts rename to src/services/shipment_service/Options/PrintCustomCode.ts index 4933056eb..dac99fec8 100644 --- a/types/Shipment/Options/PrintCustomCode.d.ts +++ b/src/services/shipment_service/Options/PrintCustomCode.ts @@ -28,25 +28,25 @@ * - TJ - Federal Taxpayer ID No. */ export declare type TPrintCustomCode = - | 'PO' - | 'DP' - | 'RMA' - | 'AJ' - | 'AT' - | 'BM' - | '9V' - | 'ON' - | '3Q' - | 'IK' - | 'MK' - | 'MJ' - | 'PM' - | 'PC' - | 'RQ' - | 'RZ' - | 'SA' - | 'SE' - | 'ST' - | 'TN' - | 'EI' - | 'TJ'; + | "PO" + | "DP" + | "RMA" + | "AJ" + | "AT" + | "BM" + | "9V" + | "ON" + | "3Q" + | "IK" + | "MK" + | "MJ" + | "PM" + | "PC" + | "RQ" + | "RZ" + | "SA" + | "SE" + | "ST" + | "TN" + | "EI" + | "TJ"; diff --git a/src/services/shipment_service/Options/index.ts b/src/services/shipment_service/Options/index.ts new file mode 100644 index 000000000..fcb86e974 --- /dev/null +++ b/src/services/shipment_service/Options/index.ts @@ -0,0 +1,3 @@ +export * from "./LabelFormat"; +export * from "./Options"; +export * from "./PrintCustomCode"; diff --git a/src/services/shipment_service/PostageLabel.ts b/src/services/shipment_service/PostageLabel.ts new file mode 100644 index 000000000..93b2b1a91 --- /dev/null +++ b/src/services/shipment_service/PostageLabel.ts @@ -0,0 +1,19 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; + +/** + * PostageLabel Object + */ +export type IPostageLabel = IObjectWithId<"PostageLabel"> & + IDatedObject & { + date_advance: number; + integrated_form: string; + label_date: string; + label_resolution: number; + label_size: string; + label_type: string; + label_url: string; + label_file_type: string; + label_pdf_url: string; + label_epl2_url: string; + label_zpl_url: string; + }; diff --git a/src/services/shipment_service/Shipment.ts b/src/services/shipment_service/Shipment.ts new file mode 100644 index 000000000..97bc3541a --- /dev/null +++ b/src/services/shipment_service/Shipment.ts @@ -0,0 +1,151 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { IAddress } from "../address_service"; +import { TBatchStatus } from "../batch_service"; +import { ICustomsInfo } from "../customs_info_service"; +import { IFee, IInsurance } from "../insurance_service"; +import { IParcel } from "../parcel_service"; +import { IRate } from "../rate_service"; +import { IScanForm } from "../scan_form_service"; +import { ITracker } from "../tracker_service"; +import { IForm } from "./Form"; +import { IMessage } from "./Message"; +import { IOptions, LabelFormat } from "./Options"; +import { IPostageLabel } from "./PostageLabel"; +import { IShipmentCreateParameters } from "./ShipmentCreateParameters"; +import { IShipmentListParameters } from "./ShipmentListParameters"; + +/** + * The workhorse of the EasyPost API, a Shipment is made up of a "to" and "from" Address, the Parcel being shipped, and any customs forms required for international deliveries. + * Once created a Shipment object is used to retrieve shipping Rates and purchase a label. + * + * A Shipment created with a valid to_address, from_address, and parcel will automatically populate its rates attribute. + * + * @see https://www.easypost.com/docs/api/node#shipment-object + */ +export type IShipment = IObjectWithId<"Shipment"> & + IDatedObject & { + /** + * An optional field that may be used in place of id in other API endpoints + */ + reference?: string | null; + + /** + * The destination address + */ + to_address: IAddress; + + /** + * The origin address + */ + from_address: IAddress; + + /** + * The shipper's address, defaults to from_address + */ + return_address?: IAddress | null; + + /** + * The buyer's address, defaults to to_address + */ + buyer_address?: IAddress | null; + + /** + * The dimensions and weight of the package + */ + parcel: IParcel; + + /** + * Information for the processing of customs + */ + customs_info?: ICustomsInfo | null; + + /** + * Document created to manifest and scan multiple shipments + */ + scan_form: IScanForm; + + /** + * All associated Form objects + */ + forms: IForm[]; + + /** + * The associated Insurance object + */ + insurance: IInsurance; + + /** + * All associated Rate objects + */ + rates: IRate[]; + + /** + * The specific rate purchased for the shipment, or null if unpurchased or purchased through another mechanism + */ + selected_rate: IRate; + + /** + * The associated PostageLabel object + */ + postage_label: IPostageLabel; + + /** + * Any carrier errors encountered during rating, discussed in more depth below + */ + messages: IMessage[]; + + /** + * All the options passed to the shipment, discussed in more depth below + */ + options?: IOptions | null; + + /** + * Set true to create as a return, discussed in more depth below + */ + is_return?: boolean | null; + + /** + * If purchased, the tracking code will appear here as well as within the Tracker object + */ + tracking_code: string; + + /** + * The USPS zone of the shipment, if purchased with USPS + */ + usps_zone: string; + + /** + * The current tracking status of the shipment + */ + status: string; + + /** + * The associated Tracker object + */ + tracker: ITracker; + + /** + * The associated Fee objects charged to the billing user account + */ + fees: IFee[]; + + /** + * The current status of the shipment refund process. Possible values are "submitted", "refunded", "rejected". + */ + refund_status: "submitted" | "refunded" | "rejected"; + + /** + * The ID of the batch that contains this shipment, if any + */ + batch_id: string; + + /** + * The current status of the associated BatchShipment + */ + batch_status: TBatchStatus; + + /** + * The current message of the associated BatchShipment + */ + batch_message: string; + }; diff --git a/types/Shipment/ShipmentCreateParameters.d.ts b/src/services/shipment_service/ShipmentCreateParameters.ts similarity index 54% rename from types/Shipment/ShipmentCreateParameters.d.ts rename to src/services/shipment_service/ShipmentCreateParameters.ts index 8665c34e0..1de69a12a 100644 --- a/types/Shipment/ShipmentCreateParameters.d.ts +++ b/src/services/shipment_service/ShipmentCreateParameters.ts @@ -1,10 +1,10 @@ -import { IAddressCreateParameters } from '../Address'; -import { ICustomsInfo } from '../Customs/CustomsInfo/CustomsInfo'; -import { IParcelCreateParameters } from '../Parcel/ParcelCreateParameters'; -import { DeepPartial } from '../utils'; -import { IOptions } from './Options'; +import { DeepPartial } from "../../utils/types"; +import { IAddressCreateParameters } from "../address_service"; +import { ICustomsInfo } from "../customs_info_service"; +import { IParcelCreateParameters } from "../parcel_service"; +import { IOptions } from "./Options"; -export declare interface IShipmentCreateParameters { +export type IShipmentCreateParameters = { reference?: string | null; to_address: DeepPartial | string; from_address: DeepPartial | string; @@ -17,4 +17,4 @@ export declare interface IShipmentCreateParameters { customs_info?: DeepPartial | null; options?: DeepPartial | null; -} +}; diff --git a/types/Shipment/ShipmentListParameters.d.ts b/src/services/shipment_service/ShipmentListParameters.ts similarity index 56% rename from types/Shipment/ShipmentListParameters.d.ts rename to src/services/shipment_service/ShipmentListParameters.ts index 35bc53513..9eeb76638 100644 --- a/types/Shipment/ShipmentListParameters.d.ts +++ b/src/services/shipment_service/ShipmentListParameters.ts @@ -1,18 +1,18 @@ -import { IAllMethodParameters } from '../utils'; +import { IAllMethodParameters } from "../../utils/types"; /** * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments */ -export declare interface IShipmentListParameters extends IAllMethodParameters { +export type IShipmentListParameters = IAllMethodParameters & { /** * Only include Shipments that have been purchased. * Default is true */ - purchased?: boolean | null; + purchased?: boolean; /** * Also include Shipments created by Child Users. * Defaults to false */ - include_children?: boolean | null; -} + include_children?: boolean; +}; diff --git a/src/services/shipment_service/index.ts b/src/services/shipment_service/index.ts new file mode 100644 index 000000000..8028875c8 --- /dev/null +++ b/src/services/shipment_service/index.ts @@ -0,0 +1,344 @@ +import EasyPost from "../.."; +import Constants from "../../constants"; +import baseService from "../base_service"; +import { IRate, ISmartRate } from "../rate_service"; +import { IOptions, LabelFormat } from "./Options"; +import { IShipment } from "./Shipment"; +import { IShipmentCreateParameters } from "./ShipmentCreateParameters"; +import { IShipmentListParameters } from "./ShipmentListParameters"; + +export * from "./Form"; +export * from "./Message"; +export * from "./PostageLabel"; +export * from "./Shipment"; +export * from "./ShipmentCreateParameters"; +export * from "./ShipmentListParameters"; +export * from "./Options"; + +const addLowestRateToShipment = ( + shipment: IShipment +): IShipment & { + lowestRate: (carriers?: string[], services?: string[]) => IRate; +} => { + return { + ...shipment, + lowestRate: (carriers?: string[], services?: string[]) => + Constants.Utils.getLowestRate(shipment.rates, carriers, services), + }; +}; + +export default (easypostClient: EasyPost) => + /** + * The ShipmentService class provides methods for interacting with EasyPost {@link Shipment} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + class ShipmentService extends baseService(easypostClient) { + /** + * Create a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#create-a-shipment EasyPost API Documentation} for more information. + * @param params - The parameters to create a shipment with. + * @returns - The created shipment. + */ + static async create(params: IShipmentCreateParameters) { + const url = "shipments"; + + const wrappedParams = { + shipment: params, + }; + + const shipment = await this._create(url, wrappedParams); + + return addLowestRateToShipment(shipment); + } + + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */ + static async buy( + id: string, + rate: IRate | string, + insuranceAmount: number | null = null, + endShipperId: string | null = null + ) { + const rateId = typeof rate === "object" ? rate.id : rate; + + const url = `shipments/${id}/buy`; + + const wrappedParams: Record = { + rate: { + id: rateId, + }, + }; + + if (insuranceAmount) { + wrappedParams.insurance = insuranceAmount; + } + + if (endShipperId) { + wrappedParams.end_shipper_id = endShipperId; + } + + try { + const response = await easypostClient._post(url, wrappedParams); + + const shipment = this._convertToEasyPostObject( + response.body, + wrappedParams + ); + + return addLowestRateToShipment(shipment); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Convert the label format of a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#convert-the-label-format-of-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to convert the label format of. + * @param format - The format to convert the label to. + * @returns - The shipment with the converted label format. + */ + static async convertLabelFormat(id: string, format: LabelFormat) { + const url = `shipments/${id}/label`; + const wrappedParams = { file_format: format }; + + try { + const response = await easypostClient._get(url, wrappedParams); + + const shipment = this._convertToEasyPostObject( + response.body, + wrappedParams + ); + return addLowestRateToShipment(shipment); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Regenerate {@link Rate rates} for a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#regenerate-rates-for-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to regenerate rates for. + * @returns - The shipment with regenerated rates. + */ + static async regenerateRates(id: string) { + const url = `shipments/${id}/rerate`; + const wrappedParams = {}; + + try { + const response = await easypostClient._post(url, wrappedParams); + + const shipment = this._convertToEasyPostObject( + response.body, + wrappedParams + ); + return addLowestRateToShipment(shipment); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Get SmartRates for a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-time-in-transit-statistics-across-all-rates-for-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to get SmartRates for. + * @returns - The SmartRates for the shipment. + */ + static async getSmartRates(id: string) { + const url = `shipments/${id}/smartrate`; + + try { + const response = await easypostClient._get(url); + + return this._convertToEasyPostObject( + response.body.result + ); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Insure a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#insure-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to insure. + * @param amount - The amount to insure the shipment for. + * @returns - The insured shipment. + */ + static async insure(id: string, amount: number | string) { + const url = `shipments/${id}/insure`; + const wrappedParams = { amount }; + + try { + const response = await easypostClient._post(url, wrappedParams); + + const shipment = this._convertToEasyPostObject( + response.body, + wrappedParams + ); + return addLowestRateToShipment(shipment); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Generate a form for a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#create-form EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to generate a form for. + * @param formType - The type of form to generate. + * @param [formOptions] - Options for the form. + * @returns - The shipment with the generated form attached. + */ + static async generateForm( + id: string, + formType: string, + formOptions: IOptions = {} + ) { + const url = `shipments/${id}/forms`; + const wrappedParams = { + form: { + ...formOptions, + type: formType, + }, + }; + + try { + const response = await easypostClient._post(url, wrappedParams); + + const shipment = this._convertToEasyPostObject( + response.body, + wrappedParams + ); + return addLowestRateToShipment(shipment); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Refund a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#refund-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to refund. + * @returns - The refunded shipment. + */ + static async refund(id: string) { + const url = `shipments/${id}/refund`; + + try { + const response = await easypostClient._post(url); + + const shipment = this._convertToEasyPostObject( + response.body + ); + return addLowestRateToShipment(shipment); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * Get the lowest SmartRate of a shipment. + * @param id - The ID of the shipment to get the lowest SmartRate of. + * @param deliveryDays - The number of days the shipment will take to deliver. + * @param deliveryAccuracy - The accuracy of the delivery days. + * @returns - The lowest SmartRate of the shipment. + */ + static async lowestSmartRate( + id: string, + deliveryDays: number, + deliveryAccuracy: keyof ISmartRate["time_in_transit"] + ) { + const smartRates = await this.getSmartRates(id); + return Constants.Utils.getLowestSmartRate( + smartRates, + deliveryDays, + deliveryAccuracy.toLowerCase() as keyof ISmartRate["time_in_transit"] + ); + } + + /** + * Retrieve all {@link Shipment shipments} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the shipments by. + * @returns - An object containing a list of {@link Shipment shipments} and pagination information. + */ + static async all(params: IShipmentListParameters = {}) { + const url = "shipments"; + + const result = await this._all<{ shipments: IShipment[] }>(url, params); + return { + ...result, + shipments: result.shipments.map(addLowestRateToShipment), + }; + } + + /** + * Retrieve the next page of Shipment collection. + * @param shipments An object containing a list of {@link Shipment shipments} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + static async getNextPage(shipments: { shipments: any[] }, pageSize = null) { + const url = "shipments"; + + const result = await this._getNextPage<{ shipments: IShipment[] }>( + url, + "shipments", + shipments, + pageSize + ); + return { + ...result, + shipments: result.shipments.map(addLowestRateToShipment), + }; + } + + /** + * Retrieve a {@link Shipment shipment} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to retrieve. + * @returns - The shipment with the given ID. + */ + static async retrieve(id: string) { + const url = `shipments/${id}`; + + const shipment = await this._retrieve(url); + return addLowestRateToShipment(shipment); + } + + /** + * Retrieves the estimated delivery date of each Rate via SmartRate. + * @param id + * @param plannedShipDate + * @returns - An array of the estimated delivery date and rates. + */ + static async retrieveEstimatedDeliveryDate( + id: string, + plannedShipDate: string + ) { + const url = `shipments/${id}/smartrate/delivery_date`; + + const params = { + planned_ship_date: plannedShipDate, + }; + + try { + const response = await easypostClient._get(url, params); + + return this._convertToEasyPostObject( + response.body.rates ?? [], + params + ); + } catch (e) { + return Promise.reject(e); + } + } + }; diff --git a/src/services/tracker_service.js b/src/services/tracker_service.js deleted file mode 100644 index f64f094df..000000000 --- a/src/services/tracker_service.js +++ /dev/null @@ -1,71 +0,0 @@ -import baseService from './base_service'; - -export default (easypostClient) => - /** - * The TrackerService class provides methods for interacting with EasyPost {@link Tracker} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - class TrackerService extends baseService(easypostClient) { - /** - * Create a {@link Tracker tracker}. - * See {@link https://www.easypost.com/docs/api/node#create-a-tracker EasyPost API Documentation} for more information. - * @param {Object} params - The parameters to create a tracker with. - * @returns {Tracker} - The created tracker. - */ - static async create(params) { - const url = 'trackers'; - - const wrappedParams = { - tracker: params, - }; - - return this._create(url, wrappedParams); - } - - /** - * Create multiple {@link Tracker trackers} in a single request. - * See {@link https://www.easypost.com/docs/api/node#trackers EasyPost API Documentation} for more information. - * @param {Object} [params] - The parameters to create trackers with. - */ - static async createList(params = {}) { - const newParams = { trackers: params }; - const url = 'trackers/create_list'; - await easypostClient._post(url, newParams); - } - - /** - * Retrieve all {@link Tracker trackers} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-trackers EasyPost API Documentation} for more information. - * @param {Object} [params] - The parameters to filter the trackers by. - * @returns {Object} - An object containing the list of {@link Tracker trackers} and pagination information. - */ - static async all(params = {}) { - const url = 'trackers'; - - return this._all(url, params); - } - - /** - * Retrieve the next page of Tracker collection. - * @param {Object} trackers An object containing a list of {@link Tracker trackers} and pagination information. - * @param {Number} pageSize The number of records to return on each page - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - static async getNextPage(trackers, pageSize = null) { - const url = 'trackers'; - - return this._getNextPage(url, 'trackers', trackers, pageSize); - } - - /** - * Retrieve a {@link Tracker tracker} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-tracker EasyPost API Documentation} for more information. - * @param {string} id - The ID of the tracker to retrieve. - * @returns {Tracker} - The retrieved tracker. - */ - static async retrieve(id) { - const url = `trackers/${id}`; - - return this._retrieve(url); - } - }; diff --git a/types/Tracker/CarrierDetail.d.ts b/src/services/tracker_service/CarrierDetail.ts similarity index 90% rename from types/Tracker/CarrierDetail.d.ts rename to src/services/tracker_service/CarrierDetail.ts index 4ef685664..115e8cf3c 100644 --- a/types/Tracker/CarrierDetail.d.ts +++ b/src/services/tracker_service/CarrierDetail.ts @@ -1,10 +1,10 @@ -import { IBaseObject } from '../base'; -import { ITrackingLocation } from './TrackingLocation'; +import { IBaseObject } from "../../utils/types"; +import { ITrackingLocation } from "./TrackingLocation"; /** * @see https://www.easypost.com/docs/api/node#carrier-detail-object */ -export declare interface ICarrierDetail extends IBaseObject<'CarrierDetail'> { +export type ICarrierDetail = IBaseObject<"CarrierDetail"> & { /** * The service level the associated shipment was shipped with (if available) */ @@ -59,4 +59,4 @@ export declare interface ICarrierDetail extends IBaseObject<'CarrierDetail'> { * The date and time of the first attempt by the carrier to deliver the package (if available) */ initial_delivery_attempt: string; -} +}; diff --git a/src/services/tracker_service/Tracker.ts b/src/services/tracker_service/Tracker.ts new file mode 100644 index 000000000..449babb29 --- /dev/null +++ b/src/services/tracker_service/Tracker.ts @@ -0,0 +1,98 @@ +import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { IFee } from "../insurance_service"; +import { ICarrierDetail } from "./CarrierDetail"; +import { ITrackerStatus } from "./TrackerStatus"; +import { ITrackerStatusDetail } from "./TrackerStatusDetail"; +import { ITrackingDetail } from "./TrackingDetail"; + +/** + * A Tracker object contains all the tracking information for a package. + * A Tracker is created automatically whenever you buy a Shipment through EasyPost. + * If you don't use EasyPost to purchase your shipping labels, you can still track packages through our API by creating a Tracker object directly. + * Each Tracker is continually updated in the background as the package moves through its life cycle, regardless of whether or not the label was purchased through EasyPost. + * + * After creation, a Tracker object will be updated periodically based on when the carrier provides EasyPost with new tracking information. + * This information can be consumed by using our webhooks infrastructure. + * Every time a Tracker is updated a webhook Event will be sent. + * + * The Tracker object contains both the current information about the package and previous updates. + * All the previous updates are stored in the tracking_details array. + * Each TrackingDetail object contains the status, the message from the carrier, and a TrackingLocation. + * + * The TrackingLocation contains city, state, country, and zip information about the location where the package was scanned. + * The information each carrier provides is different, so some carriers may not make use of all these fields. + * + * Some Tracker objects may also contain a CarrierDetail, which stores some additional information about the Tracker that the carrier has made available to EasyPost. + * The CarrierDetail object contains the service and container_type of the package. + * Additionally, it also stores the `est_delivery_date_local` and `est_delivery_time_local`, which provide information about the local delivery time. + * + * It's worth noting that tracking_codes are not globally unique. + * Each carrier promises uniqueness for a given `tracking_code` for a certain period of time, but the length of time varies greatly based on the specific carrier and service level. + * The carriers do eventually recycle `tracking_codes`, and for this reason enforcing uniqueness on the `tracking_code` field is not recommended. + * EasyPost does, however, prevent the creation of duplicate Trackers based on tracking_code and carrier; duplicate requests by the same User will simply return the original Tracker. + * + * @see https://www.easypost.com/docs/api/node#tracker-object + */ +export type ITracker = IObjectWithId<"Tracker"> & + IDatedObject & { + /** + * The tracking code provided by the carrier + */ + tracking_code: string; + + /** + * The current status of the package, possible values are "unknown", "pre_transit", "in_transit", "out_for_delivery", "delivered", "available_for_pickup", "return_to_sender", "failure", "cancelled" or "error" + */ + status: ITrackerStatus; + + /** + * Additional details about the current status, possible values are "unknown", "status_update", "departed_facility", "arrived_at_facility", "out_for_delivery", "arrived_at_destination" + */ + status_detail: ITrackerStatusDetail; + + /** + * The name of the person who signed for the package (if available) + */ + signed_by: string; + + /** + * The weight of the package as measured by the carrier in ounces (if available) + * float (oz) + */ + weight: number; + + /** + * The estimated delivery date provided by the carrier (if available) + */ + est_delivery_date: string; // TODO maybe type should be Date? + + /** + * The id of the EasyPost Shipment object associated with the Tracker (if any) + */ + shipment_id: string; + + /** + * The name of the carrier handling the shipment + */ + carrier: string; + + /** + * Array of the associated TrackingDetail objects + */ + tracking_details: ITrackingDetail[]; + + /** + * The associated CarrierDetail object (if available) + */ + carrier_detail: ICarrierDetail; + + /** + * URL to a publicly-accessible html page that shows tracking details for this tracker + */ + public_url: string; + + /** + * Array of the associated Fee objects + */ + fees: IFee[]; + }; diff --git a/types/Tracker/TrackerCreateParameters.d.ts b/src/services/tracker_service/TrackerCreateParameters.ts similarity index 83% rename from types/Tracker/TrackerCreateParameters.d.ts rename to src/services/tracker_service/TrackerCreateParameters.ts index 7a46b5275..e5753fa31 100644 --- a/types/Tracker/TrackerCreateParameters.d.ts +++ b/src/services/tracker_service/TrackerCreateParameters.ts @@ -1,4 +1,4 @@ -export declare interface ITrackerCreateParameters { +export type ITrackerCreateParameters = { /** * The tracking code associated with the package you'd like to track */ @@ -9,4 +9,4 @@ export declare interface ITrackerCreateParameters { * The carrier will get auto-detected if none is provided */ carrier?: string; -} +}; diff --git a/types/Tracker/TrackerListParameters.d.ts b/src/services/tracker_service/TrackerListParameters.ts similarity index 53% rename from types/Tracker/TrackerListParameters.d.ts rename to src/services/tracker_service/TrackerListParameters.ts index cdf301653..4bba76146 100644 --- a/types/Tracker/TrackerListParameters.d.ts +++ b/src/services/tracker_service/TrackerListParameters.ts @@ -1,14 +1,14 @@ -import { IAllMethodParameters } from '../utils'; +import { IAllMethodParameters } from "../../utils/types"; -export declare interface ITrackerListParameters extends IAllMethodParameters { +export type ITrackerListParameters = IAllMethodParameters & { /** * Only returns Trackers with the given tracking_code. * Useful for retrieving an individual Tracker by tracking_code rather than by ID */ - tracking_code?: string | null; + tracking_code?: string; /** * Only returns Trackers with the given carrier value */ - carrier?: string | null; -} + carrier?: string; +}; diff --git a/src/services/tracker_service/TrackerStatus.ts b/src/services/tracker_service/TrackerStatus.ts new file mode 100644 index 000000000..7e11a0ad2 --- /dev/null +++ b/src/services/tracker_service/TrackerStatus.ts @@ -0,0 +1,11 @@ +export type ITrackerStatus = + | "unknown" + | "pre_transit" + | "in_transit" + | "out_for_delivery" + | "delivered" + | "available_for_pickup" + | "return_to_sender" + | "failure" + | "cancelled" + | "error"; diff --git a/src/services/tracker_service/TrackerStatusDetail.ts b/src/services/tracker_service/TrackerStatusDetail.ts new file mode 100644 index 000000000..5e9128596 --- /dev/null +++ b/src/services/tracker_service/TrackerStatusDetail.ts @@ -0,0 +1,29 @@ +export type ITrackerStatusDetail = + | "address_correction" + | "arrived_at_destination" + | "arrived_at_facility" + | "arrived_at_pickup_location" + | "awaiting_information" + | "cancelled" + | "damaged" + | "delayed" + | "delivery_exception" + | "departed_facility" + | "departed_origin_facility" + | "expired" + | "failure" + | "held" + | "in_transit" + | "label_created" + | "lost" + | "missorted" + | "out_for_delivery" + | "received_at_destination_facility" + | "received_at_origin_facility" + | "refused" + | "return" + | "status_update" + | "transferred_to_destination_carrier" + | "transit_exception" + | "unknown" + | "weather_delay"; diff --git a/types/Tracker/TrackingDetail.d.ts b/src/services/tracker_service/TrackingDetail.ts similarity index 75% rename from types/Tracker/TrackingDetail.d.ts rename to src/services/tracker_service/TrackingDetail.ts index bf2391ff2..9185bf1c0 100644 --- a/types/Tracker/TrackingDetail.d.ts +++ b/src/services/tracker_service/TrackingDetail.ts @@ -1,11 +1,11 @@ -import { IBaseObject } from '../base'; -import { ITrackerStatus } from './TrackerStatus'; -import { ITrackingLocation } from './TrackingLocation'; +import { IBaseObject } from "../../utils/types"; +import { ITrackerStatus } from "./TrackerStatus"; +import { ITrackingLocation } from "./TrackingLocation"; /** * @see https://www.easypost.com/docs/api/node#tracking-detail-object */ -export declare interface ITrackingDetail extends IBaseObject<'TrackingDetail'> { +export type ITrackingDetail = IBaseObject<"TrackingDetail"> & { /** * Description of the scan event */ @@ -30,4 +30,4 @@ export declare interface ITrackingDetail extends IBaseObject<'TrackingDetail'> { * The location associated with the scan event */ tracking_location: ITrackingLocation; -} +}; diff --git a/types/Tracker/TrackingLocation.d.ts b/src/services/tracker_service/TrackingLocation.ts similarity index 77% rename from types/Tracker/TrackingLocation.d.ts rename to src/services/tracker_service/TrackingLocation.ts index d621343a1..288471bf7 100644 --- a/types/Tracker/TrackingLocation.d.ts +++ b/src/services/tracker_service/TrackingLocation.ts @@ -1,9 +1,9 @@ -import { IBaseObject } from '../base'; +import { IBaseObject } from "../../utils/types"; /** * @see https://www.easypost.com/docs/api/node#tracking-location-object */ -export declare interface ITrackingLocation extends IBaseObject<'TrackingLocation'> { +export type ITrackingLocation = IBaseObject<"TrackingLocation"> & { /** * The city where the scan event occurred (if available) */ @@ -23,4 +23,4 @@ export declare interface ITrackingLocation extends IBaseObject<'TrackingLocation * The postal code where the scan event occurred (if available) */ zip: string; -} +}; diff --git a/src/services/tracker_service/index.ts b/src/services/tracker_service/index.ts new file mode 100644 index 000000000..9740633ae --- /dev/null +++ b/src/services/tracker_service/index.ts @@ -0,0 +1,92 @@ +import EasyPost from "../.."; +import baseService from "../base_service"; +import { ITracker } from "./Tracker"; +import { ITrackerCreateParameters } from "./TrackerCreateParameters"; +import { ITrackerListParameters } from "./TrackerListParameters"; + +export * from "./CarrierDetail"; +export * from "./Tracker"; +export * from "./TrackerCreateParameters"; +export * from "./TrackerListParameters"; +export * from "./TrackerStatus"; +export * from "./TrackerStatusDetail"; +export * from "./TrackingDetail"; +export * from "./TrackingLocation"; + +export default (easypostClient: EasyPost) => + /** + * The TrackerService class provides methods for interacting with EasyPost {@link Tracker} objects. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + class TrackerService extends baseService(easypostClient) { + /** + * Create a {@link Tracker tracker}. + * See {@link https://www.easypost.com/docs/api/node#create-a-tracker EasyPost API Documentation} for more information. + * @param params - The parameters to create a tracker with. + * @returns - The created tracker. + */ + static async create(params: ITrackerCreateParameters) { + const url = "trackers"; + + const wrappedParams = { + tracker: params, + }; + + return this._create(url, wrappedParams); + } + + /** + * Create multiple {@link Tracker trackers} in a single request. + * See {@link https://www.easypost.com/docs/api/node#trackers EasyPost API Documentation} for more information. + * @param [params] - The parameters to create trackers with. + */ + static async createList(params: ITrackerCreateParameters[] = []) { + const newParams = { trackers: params }; + const url = "trackers/create_list"; + await easypostClient._post(url, newParams); + } + + /** + * Retrieve all {@link Tracker trackers} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-trackers EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the trackers by. + * @returns - An object containing the list of {@link Tracker trackers} and pagination information. + */ + static async all(params: ITrackerListParameters = {}) { + const url = "trackers"; + + return this._all<{ trackers: ITracker[] }>(url, params); + } + + /** + * Retrieve the next page of Tracker collection. + * @param trackers An object containing a list of {@link Tracker trackers} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + static async getNextPage( + trackers: { trackers: any[] }, + pageSize: number | null = null + ) { + const url = "trackers"; + + return this._getNextPage<{ trackers: ITracker[] }>( + url, + "trackers", + trackers, + pageSize + ); + } + + /** + * Retrieve a {@link Tracker tracker} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-tracker EasyPost API Documentation} for more information. + * @param id - The ID of the tracker to retrieve. + * @returns - The retrieved tracker. + */ + static async retrieve(id: string) { + const url = `trackers/${id}`; + + return this._retrieve(url); + } + }; diff --git a/types/Brand/Brand.d.ts b/src/services/user_service/Brand.ts similarity index 52% rename from types/Brand/Brand.d.ts rename to src/services/user_service/Brand.ts index ef5432675..848a7765a 100644 --- a/types/Brand/Brand.d.ts +++ b/src/services/user_service/Brand.ts @@ -1,11 +1,11 @@ -import { IObjectWithId } from '../base'; +import { IObjectWithId } from "../../utils/types"; /** * The Brand class represents the public-accessible information about a user's brand, including logos, colors and themes. * * @see https://www.easypost.com/docs/api/node#brand */ -export declare interface IBrand extends IObjectWithId<'Brand'> { +export type IBrand = IObjectWithId<"Brand"> & { /** * The background color of the brand, as a hex code. */ @@ -44,30 +44,5 @@ export declare interface IBrand extends IObjectWithId<'Brand'> { /** * The name of the current theme. */ - theme: 'theme1' | 'theme2'; -} - -export declare class Brand implements IBrand { - id: string; - mode: 'test' | 'production'; - object: 'Brand'; - reference?: string | null; - ad: string; - ad_href: string; - background_color: string; - color: string; - logo: string; - logo_href: string; - theme: 'theme1' | 'theme2'; - user_id: string; - - /** - * Update the brand of the current authenticated user. - * - * @see https://www.easypost.com/docs/api/node#update-a-brand - * - * @param params The parameters to update the {@link Brand} with - * @returns {Promise} The updated Brand. - */ - static updateBrand(params: object): Promise; -} + theme: "theme1" | "theme2"; +}; diff --git a/src/services/user_service/User.ts b/src/services/user_service/User.ts new file mode 100644 index 000000000..216d6750e --- /dev/null +++ b/src/services/user_service/User.ts @@ -0,0 +1,76 @@ +import { IObjectWithId } from "../../utils/types"; + +/** + * The User object can be used to manage your own account and to create child accounts. + * Only a Production mode API key can be used to make requests against the Users API. + * + * Balance and recharge values on User objects are expressed in higher precision USD. + * + * @see https://www.easypost.com/docs/api/node#user-object + */ +export type IUser = IObjectWithId<"User"> & { + /** + * The ID of the parent user object. + * Top-level users are defined as users with no parent + */ + parent_id: string; + + /** + * First and last name required + */ + name: string; + + /** + * Required + */ + email: string; + + /** + * Optional + */ + phone_number?: string | null; + + /** + * Formatted as string "XX.XXXXX" + */ + balance: string; + + /** + * Cost per shipment purchase, formatted as string "XX.XXXXX" + */ + price_per_shipment: string; + /** + * USD formatted dollars and cents, delimited by a decimal point + */ + recharge_amount: string; + + /** + * USD formatted dollars and cents, delimited by a decimal point + */ + secondary_recharge_amount: string; + + /** + * Number of cents USD that when your balance drops below, we automatically recharge your account with your primary payment method. + */ + recharge_threshold: string; + + /** + * The fee rate for convenience fees + */ + cc_fee_rate: string; + + /** + * The fee rate for insurance purchases + */ + insurance_fee_rate: string; + + /** + * The minimum cost for insurance purchases + */ + insurance_fee_minimum: string; + + /** + * All associated children + */ + children: IUser[]; +}; diff --git a/src/services/user_service/UserCreateParameters.ts b/src/services/user_service/UserCreateParameters.ts new file mode 100644 index 000000000..758264e25 --- /dev/null +++ b/src/services/user_service/UserCreateParameters.ts @@ -0,0 +1,4 @@ +import { ParametersToOmitOnCreate } from "../../utils/types"; +import { IUser } from "./User"; + +export type IUserCreateParameters = Omit; diff --git a/src/services/user_service.js b/src/services/user_service/index.ts similarity index 51% rename from src/services/user_service.js rename to src/services/user_service/index.ts index ffa103d4d..677fb9218 100644 --- a/src/services/user_service.js +++ b/src/services/user_service/index.ts @@ -1,6 +1,14 @@ -import baseService from './base_service'; +import EasyPost from "../.."; +import baseService from "../base_service"; +import { IBrand } from "./Brand"; +import { IUser } from "./User"; +import { IUserCreateParameters } from "./UserCreateParameters"; -export default (easypostClient) => +export * from "./Brand"; +export * from "./User"; +export * from "./UserCreateParameters"; + +export default (easypostClient: EasyPost) => /** * The UserService class provides methods for interacting with EasyPost {@link User} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -9,27 +17,27 @@ export default (easypostClient) => /** * Create a {@link User child user}. * See {@link https://www.easypost.com/docs/api/node#create-a-child-user EasyPost API Documentation} for more information. - * @param {Object} params - The parameters to create a child user with. - * @returns {User} - The created child user. + * @param params - The parameters to create a child user with. + * @returns - The created child user. */ - static async create(params) { - const url = 'users'; + static async create(params: IUserCreateParameters) { + const url = "users"; const wrappedParams = { user: params, }; - return this._create(url, wrappedParams); + return this._create(url, wrappedParams); } /** * Update a {@link User user}. * See {@link https://www.easypost.com/docs/api/node#update-a-user EasyPost API Documentation} for more information. - * @param {string} id - The ID of the user to update (either the current authenticated user or a child user). - * @param {Object} params - The parameters to update the user with. - * @returns {User} - The updated user. + * @param id - The ID of the user to update (either the current authenticated user or a child user). + * @param params - The parameters to update the user with. + * @returns - The updated user. */ - static async update(id, params) { + static async update(id: string, params: Partial) { const url = `users/${id}`; const wrappedParams = { user: params, @@ -38,7 +46,10 @@ export default (easypostClient) => try { const response = await easypostClient._patch(url, wrappedParams); - return this._convertToEasyPostObject(response.body, wrappedParams); + return this._convertToEasyPostObject( + response.body, + wrappedParams + ); } catch (e) { return Promise.reject(e); } @@ -47,16 +58,16 @@ export default (easypostClient) => /** * Retrieve a {@link User child user}. * See {@link https://www.easypost.com/docs/api/node#retrieve-a-user EasyPost API Documentation} for more information. - * @param {string} id - The ID of the child user to retrieve. - * @returns {User} - The retrieved child user. + * @param id - The ID of the child user to retrieve. + * @returns - The retrieved child user. */ - static async retrieve(id) { + static async retrieve(id: string) { const url = `users/${id}`; try { const response = await easypostClient._get(url); - return this._convertToEasyPostObject(response.body); + return this._convertToEasyPostObject(response.body); } catch (e) { return Promise.reject(e); } @@ -65,15 +76,15 @@ export default (easypostClient) => /** * Retrieve the {@link User current authenticated user}. * See {@link https://www.easypost.com/docs/api/node#retrieve-a-user EasyPost API Documentation} for more information. - * @returns {User} - The retrieved user. + * @returns - The retrieved user. */ static async retrieveMe() { - const url = 'users'; + const url = "users"; try { const response = await easypostClient._get(url); - return this._convertToEasyPostObject(response.body); + return this._convertToEasyPostObject(response.body); } catch (e) { return Promise.reject(e); } @@ -82,10 +93,10 @@ export default (easypostClient) => /** * Delete a {@link User child user}. * See {@link https://www.easypost.com/docs/api/node#delete-a-child-user EasyPost API Documentation} for more information. - * @param {string} id - The ID of the child user to delete. - * @returns {Promise|Promise} - A promise that resolves when the child user is deleted successfully. + * @param id - The ID of the child user to delete. + * @returns - A promise that resolves when the child user is deleted successfully. */ - static async delete(id) { + static async delete(id: string) { const url = `users/${id}`; try { @@ -100,18 +111,21 @@ export default (easypostClient) => /** * Update the brand of a {@link User user}. * See {@link https://www.easypost.com/docs/api/node#update-a-brand EasyPost API Documentation} for more information. - * @param {string} id - The ID of the user to update the brand of. - * @param {Object} params - The parameters to update the brand with. - * @returns {Brand} - The updated brand. + * @param id - The ID of the user to update the brand of. + * @param params - The parameters to update the brand with. + * @returns - The updated brand. */ - static async updateBrand(id, params) { + static async updateBrand(id: string, params: Partial) { const url = `users/${id}/brand`; const wrappedParams = { brand: params }; try { const response = await easypostClient._patch(url, wrappedParams); - return this._convertToEasyPostObject(response.body, wrappedParams); + return this._convertToEasyPostObject( + response.body, + wrappedParams + ); } catch (e) { return Promise.reject(e); } @@ -120,16 +134,19 @@ export default (easypostClient) => /** * Retrieve a paginated list of children user {@link User user}. * See {@link https://www.easypost.com/docs/api/node#child-users EasyPost API Documentation} for more information. - * @param {Object} params - Parameters to filter the list of children users. - * @returns {Object} - An object containing a list of {@link Children User} and pagination information. + * @param params - Parameters to filter the list of children users. + * @returns - An object containing a list of {@link Children User} and pagination information. */ - static async allChildren(params) { - const url = 'users/children'; + static async allChildren(params: any) { + const url = "users/children"; try { const response = await easypostClient._get(url, params); - return this._convertToEasyPostObject(response.body, params); + return this._convertToEasyPostObject<{ children: IUser[] }>( + response.body, + params + ); } catch (e) { return Promise.reject(e); } @@ -137,12 +154,20 @@ export default (easypostClient) => /** * Retrieve the next page of children collection. - * @param {Object} children An object containing a list of {@link Children children} and pagination information. - * @param {Number} pageSize The number of records to return on each page - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + * @param children An object containing a list of {@link Children children} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage(children, pageSize = null) { - const url = 'users/children'; - return this._getNextPage(url, 'children', children, pageSize); + static async getNextPage( + children: { children: any[] }, + pageSize: number | null = null + ) { + const url = "users/children"; + return this._getNextPage<{ children: IUser[] }>( + url, + "children", + children, + pageSize + ); } }; diff --git a/src/services/webhook_service/Webhook.ts b/src/services/webhook_service/Webhook.ts new file mode 100644 index 000000000..4a95308ec --- /dev/null +++ b/src/services/webhook_service/Webhook.ts @@ -0,0 +1,30 @@ +import { IObjectWithId } from "../../utils/types"; + +/** + * Each Webhook contains the url which EasyPost will notify whenever an object in our system updates. + * Several types of objects are processed asynchronously in the EasyPost system, so whenever an object updates, an Event is sent via HTTP POST to each configured webhook URL. + * The Webhook object provides CRUD operations for all Webhooks. + * + * Currently, our recommended best practice for securing Webhooks involves using basic authentication and HTTPS on your endpoint. + * This will help prevent any altering of any information communicated to you by EasyPost, prevent any third parties from seeing your webhooks in transit, and will prevent any third parties from masquerading as EasyPost and sending fraudulent data. + * EasyPost performs certificate validation and requires any TLS-enabled (HTTPS) webhook recipients to have a certificate signed by a public trusted certification authority. + * We do not support sending webhooks to over SSLv2, SSLv3, or any connection using so-called export-grade ciphers. + * For documentation on how to set up your server with TLS, we recommend Mozilla's guide to Server-Side TLS and Qualys's SSL/TLS deployment best practices guide. + * + * In general, a Webhook's endpoint should return a status code of 2XX. + * A 200 is preferred, but any 2XX status will indicate to our system that the Webhook request was successful. + * Endpoints that return a large volume and rate of failures over a period of time will get automatically disabled by the system; a disabled Webhook can be re-enabled using the Webhook update endpoint. + * + * @see https://www.easypost.com/docs/api/node#webhook-object + */ +export type IWebhook = IObjectWithId<"Webhook"> & { + /** + * http://example.com + */ + url: string; + + /** + * the timestamp at which the webhook was most recently disabled (if any) + */ + disabled_at: string; +}; diff --git a/src/services/webhook_service/WebhookCreateParameters.ts b/src/services/webhook_service/WebhookCreateParameters.ts new file mode 100644 index 000000000..e5eb2aee2 --- /dev/null +++ b/src/services/webhook_service/WebhookCreateParameters.ts @@ -0,0 +1,3 @@ +export type IWebhookCreateParameters = { + url: string; +}; diff --git a/src/services/webhook_service/WebhookListParameters.ts b/src/services/webhook_service/WebhookListParameters.ts new file mode 100644 index 000000000..d542b3788 --- /dev/null +++ b/src/services/webhook_service/WebhookListParameters.ts @@ -0,0 +1,6 @@ +import { IAllMethodParameters } from "../../utils/types"; + +/** + * @see https://www.easypost.com/docs/api/node#list-a-webhooks + */ +export type IWebhookListParameters = IAllMethodParameters; diff --git a/src/services/webhook_service.js b/src/services/webhook_service/index.ts similarity index 54% rename from src/services/webhook_service.js rename to src/services/webhook_service/index.ts index 83bc8eb0f..1f9871c61 100644 --- a/src/services/webhook_service.js +++ b/src/services/webhook_service/index.ts @@ -1,6 +1,14 @@ -import baseService from './base_service'; +import EasyPost from "../.."; +import baseService from "../base_service"; +import { IWebhook } from "./Webhook"; +import { IWebhookCreateParameters } from "./WebhookCreateParameters"; +import { IWebhookListParameters } from "./WebhookListParameters"; -export default (easypostClient) => +export * from "./Webhook"; +export * from "./WebhookCreateParameters"; +export * from "./WebhookListParameters"; + +export default (easypostClient: EasyPost) => /** * The WebhookService class provides methods for interacting with EasyPost {@link Webhook} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -9,33 +17,33 @@ export default (easypostClient) => /** * Create a {@link Webhook webhook}. * See {@link https://www.easypost.com/docs/api/node#create-a-webhook EasyPost API Documentation} for more information. - * @param {Object} params - The parameters to create a webhook with. - * @returns {Webhook} - The created webhook. + * @param params - The parameters to create a webhook with. + * @returns - The created webhook. */ - static async create(params) { - const url = 'webhooks'; + static async create(params: IWebhookCreateParameters) { + const url = "webhooks"; const wrappedParams = { webhook: params, }; - return this._create(url, wrappedParams); + return this._create(url, wrappedParams); } /** * Update a {@link Webhook webhook}. * A disabled webhook will be re-enabled if it is updated. * See {@link https://www.easypost.com/docs/api/node#update-a-webhook EasyPost API Documentation} for more information. - * @param {string} id - The ID of the webhook to update. - * @param {Object} params - The parameters to update the webhook with. - * @returns {Webhook} - The updated webhook. + * @param id - The ID of the webhook to update. + * @param params - The parameters to update the webhook with. + * @returns - The updated webhook. */ - static async update(id, params) { + static async update(id: string, params: Partial) { const url = `webhooks/${id}`; try { const response = await easypostClient._patch(url, params); - return this._convertToEasyPostObject(response.body, params); + return this._convertToEasyPostObject(response.body, params); } catch (e) { return Promise.reject(e); } @@ -44,10 +52,10 @@ export default (easypostClient) => /** * Delete a {@link Webhook webhook}. * See {@link https://www.easypost.com/docs/api/node#delete-a-webhook EasyPost API Documentation} for more information. - * @param {string} id - The ID of the webhook to delete. - * @returns {Promise|Promise} - A promise that resolves if the webhook was successfully deleted. + * @param id - The ID of the webhook to delete. + * @returns - A promise that resolves if the webhook was successfully deleted. */ - static async delete(id) { + static async delete(id: string) { const url = `webhooks/${id}`; try { @@ -62,24 +70,24 @@ export default (easypostClient) => /** * Retrieve all {@link Webhook webhooks} associated with the current authenticated user. * See {@link https://www.easypost.com/docs/api/node#list-a-webhooks EasyPost API Documentation} for more information. - * @param {Object} [params] - * @returns {Webhook[]} + * @param [params] + * @returns */ - static async all(params = {}) { - const url = 'webhooks'; + static async all(params: IWebhookListParameters = {}) { + const url = "webhooks"; - return this._all(url, params); + return this._all<{ webhooks: IWebhook[] }>(url, params); } /** * Retrieve a {@link Webhook webhook} by its ID. * See {@link https://www.easypost.com/docs/api/node#retrieve-a-webhook EasyPost API Documentation} for more information. - * @param {string} id - The ID of the webhook to retrieve. - * @returns {Webhook} - The retrieved webhook. + * @param id - The ID of the webhook to retrieve. + * @returns - The retrieved webhook. */ - static async retrieve(id) { + static async retrieve(id: string) { const url = `webhooks/${id}`; - return this._retrieve(url); + return this._retrieve(url); } }; diff --git a/types/errors/Error.d.ts b/src/utils/errors/Error.ts similarity index 86% rename from types/errors/Error.d.ts rename to src/utils/errors/Error.ts index b19e66278..89475bc74 100644 --- a/types/errors/Error.d.ts +++ b/src/utils/errors/Error.ts @@ -1,5 +1,5 @@ -import { TErrorCode } from './ErrorCode'; -import { IFieldError } from './FieldError'; +import { TErrorCode } from "./ErrorCode"; +import { IFieldError } from "./FieldError"; /** * In the event of a client or server error, the response will contain the standard 4xx or 5xx respectively, accompanied by a well-formed JSON body describing the issue, e.g., a required field was omitted, a purchase failed, etc. @@ -9,7 +9,7 @@ import { IFieldError } from './FieldError'; * * @see https://www.easypost.com/docs/api/node#error-object */ -export declare interface IError { +export type IError = { /** * Machine readable description of the problem */ @@ -24,4 +24,4 @@ export declare interface IError { * Breakdown of errors for specific fields in the request */ errors: IFieldError[]; -} +}; diff --git a/src/utils/errors/ErrorCode.ts b/src/utils/errors/ErrorCode.ts new file mode 100644 index 000000000..a8ad19352 --- /dev/null +++ b/src/utils/errors/ErrorCode.ts @@ -0,0 +1,174 @@ +// TODO: there seems to be a lot of duplicate codes listed here https://www.easypost.com/errors-guide +export type TErrorCode = + | "ADDRESS.COUNTRY.INVALID" + | "ADDRESS.PARAMETERS.INVALID_CHARACTER" + | "ADDRESS.PARAMETERS.INVALID" + | "ADDRESS.VERIFICATION.FAILURE" + | "ADDRESS.VERIFICATION.INVALID" + | "ADDRESS.VERIFICATION.NOT_FOUND" + | "ADDRESS.VERIFY.CARRIER_INVALID" + | "ADDRESS.VERIFY.FAILURE" + | "ADDRESS.VERIFY.INTL_NOT_ENABLED" + | "ADDRESS.VERIFY.MISSING_CITY_STATE_ZIP" + | "ADDRESS.VERIFY.MISSING_STREET" + | "ADDRESS.VERIFY.ONLY_US" + | "ADDRESS.VERIFY.UNAVAILABLE" + | "ADDRESS.VERIFY.UPSTREAM_UNAVAILABLE" + | "BAD_REQUEST" + | "BANK_ACCOUNT.CHARGE.FAILURE" + | "BANK_ACCOUNT.VERIFY.FAILURE" + /** + * The typo "FORAMT" is in both the docs and api error response. + * @link https://github.com/EasyPost/easypost-node/pull/156#discussion_r819811282 + */ + | "BATCH.FILE_FORAMT.INVALID" + | "BATCH.PARAMS.INVALID" + | "BATCH.SHIPMENT.MISSING" + | "BATCH.SHIPMENT.TOO_LARGE" + | "BATCH.SHIPMENTS.REQUIRED" + | "BATCH.STATE.ALREADY_PURCHASED" + | "BATCH.STATE.CREATING" + | "BATCH.STATE.CREATION_FAILED" + | "BATCH.STATE.NOT_PURCHASED" + | "CARRIER_ACCOUNT.INVALID" + | "CARRIER_ACCOUNT.PARAMETERS.INVALID" + | "CARRIER_ACCOUNT.REGISTRATION.FAILED" + | "CARRIER_ACCOUNT.TYPE.EXISTS" + | "CARRIER_ACCOUNT.TYPE.UNKNOWN" + | "CONTAINER.DIMENSION.REQUIRED" + | "CONTAINER.NAME.REQUIRED" + | "CONTAINER.TYPE.INVALID" + | "CREDIT_CARD.CHARGE.FAILURE" + | "CREDIT_CARD.INVALID" + | "CUSTOMS_INFO.PARAMETERS.INVALID" + | "CUSTOMS_ITEM.CURRENCY.ONE_CURRENCY_SUPPORTED" + | "CUSTOMS_ITEM.ORIGIN_COUNTRY.REQUIRED" + | "CUSTOMS_ITEM.PARAMETERS.INVALID" + | "DATE.PARSE.FAILURE" + | "DHLGM.ACCESS_TOKEN.GENERATION_FAILED" + | "DHLGM.GIRTH_MAX" + | "DHLGM.LABEL.FAILURE" + | "DHLGM.LETTER_NOT_SUPPORTED" + | "DHLGM.NO_ALCOHOL" + | "DHLGM.NO_INTERNATIONAL" + | "DHLGM.RATE_TABLE.NOT_FOUND" + | "DHLGM.RETURN.AUTHORIZATION_NUMBER_REQUIRED" + | "DHLGM.SCAN_FORM.GENERATION_FAILED" + | "DOCUMENT.COMMERCIAL_INVOICE.FAILURE" + | "DOCUMENT.CONVERSION.FAILURE" + | "EMAIL_VERIFICATION.EXPIRED" + | "EMAIL_VERIFICATION.NOT_FOUND" + | "EMAIL_VERIFICATION.USED" + | "FORBIDDEN" + | "IMAGE.CONVERSION.FAILURE" + | "IMAGE.WIDTH.INVALID" + | "INSURANCE.AMOUNT.ABOVE_MAXIMUM" + | "INSURANCE.AMOUNT.BELOW_MINIMUM" + | "INSURANCE.AMOUNT.REQUIRED" + | "INSURANCE.CREATE.FAILURE" + | "INSURANCE.PARAMETERS.INVALID" + | "INSURANCE.PURCHASE.FAILED" + | "INSURANCE.PURCHASE.NOT_ALLOWED" + | "INTERNAL_SERVER_ERROR" + | "ITEM.HEIGHT.REQUIRED" + | "ITEM.LENGTH.REQUIRED" + | "ITEM.NAME.REQUIRED" + | "ITEM.VALUE.REQUIRED" + | "ITEM.WEIGHT.REQUIRED" + | "ITEM.WIDTH.REQUIRED" + | "MODE.CONFLICT" + | "MODE.UNAUTHORIZED" + | "NOT_ACCEPTABLE" + | "NOT_FOUND" + | "ORDER.CARRIER_ACCOUNTS.CONFLICT" + | "ORDER.CARRIER.REQUIRED" + | "ORDER.FROM_ADDRESS.REQUIRED" + | "ORDER.INVALID" + | "ORDER.LABEL_DATE.INVALID" + | "ORDER.OPTIONS.INVALID" + | "ORDER.PARAMS.REQUIRED" + | "ORDER.RATE.UNAVAILABLE" + | "ORDER.SERVICE.REQUIRED" + | "ORDER.SHIPMENTS.REQUIRED" + | "ORDER.TO_ADDRESS.REQUIRED" + | "PARAMETER.FORBIDDEN" + | "PARAMETER.REQUIRED" + | "PARCEL.PARAMETERS.INVALID" + | "PARCEL.PREDEFINED_PACKAGE.INVALID" + | "PAYMENT_GATEWAY.ERROR" + | "PAYMENT_REQUIRED" + | "PICKUP.ADDRESS.INVALID" + | "PICKUP.ADDRESS.REQUIRED" + | "PICKUP.BATCH_CARRIER.INCONSISTENT" + | "PICKUP.BATCH.INVALID" + | "PICKUP.BATCH.REQUIRED" + | "PICKUP.BUY.FAILED" + | "PICKUP.BUY.FORBIDDEN" + | "PICKUP.BUY.NO_MATCHING_RATES" + | "PICKUP.CANCEL.FAILED" + | "PICKUP.CARRIER.REQUIRED" + | "PICKUP.IS_ACCOUNT_ADDRESS.REQUIRED" + | "PICKUP.MAX_DATETIME.REQUIRED" + | "PICKUP.MIN_DATETIME.REQUIRED" + | "PICKUP.REQUEST.INVALID" + | "PICKUP.SERVICE.REQUIRED" + | "PICKUP.SHIPMENT_COUNTRY.INVALID" + | "PICKUP.SHIPMENT_SERVICE.INVALID" + | "PICKUP.STATUS.INVALID" + | "REFUND.FAILURE" + | "REFUND.NO_RESPONSE" + | "REFUND.TRACKING_CODE.NOT_FOUND" + | "REFUND.TRACKING_CODES.INVALID" + | "SCAN_FORM.BATCH.MULTIPLE_CARRIERS" + | "SCAN_FORM.BATCH.NOT_PURCHASED" + | "SCAN_FORM.CREATE.CARRIER_NOT_SUPPORTED" + | "SCAN_FORM.CREATE.FAILURE" + | "SCAN_FORM.FAILURE" + | "SCAN_FORM.SHIPMENTS.INVALID" + | "SCAN_FORM.SHIPMENTS.REQUIRED" + | "SHIPMENT_REPORT.ALREADY_IN_PROGRESS" + | "SHIPMENT_REPORT.DATE_RANGE.INVALID" + | "SHIPMENT_REPORT.DATE_RANGE.TOO_LONG" + | "SHIPMENT.CARRIER_ACCOUNTS.CONFLICT" + | "SHIPMENT.CUSTOMS_INFO.DESCRIPTION_REQUIRED" + | "SHIPMENT.CUSTOMS_INFO.REQUIRED" + | "SHIPMENT.INSURANCE.ALREADY_PURCHASED" + | "SHIPMENT.INVALID_PARAMS" + | "SHIPMENT.INVALID" + | "SHIPMENT.MISSING_INFORMATION" + | "SHIPMENT.MISSING_RATE" + | "SHIPMENT.OPTIONS.INVALID" + | "SHIPMENT.POSTAGE.ASCII" + | "SHIPMENT.POSTAGE.EXISTS" + | "SHIPMENT.POSTAGE.FAILURE" + | "SHIPMENT.POSTAGE.FORMAT_UNAVAILABLE" + | "SHIPMENT.POSTAGE.INVALID_FORMAT" + | "SHIPMENT.POSTAGE.NO_RESPONSE" + | "SHIPMENT.POSTAGE.REQUIRED" + | "SHIPMENT.PURCHASE.FAILURE" + | "SHIPMENT.PURCHASE.IN_PROGRESS" + | "SHIPMENT.RATE.BARCODE_UNAVAILABLE" + | "SHIPMENT.RATE.CARRIER_ACCOUNT_INVALID" + | "SHIPMENT.RATE.STAMP_UNAVAILABLE" + | "SHIPMENT.RATES.UNAVAILABLE" + | "SHIPMENT.REFUND.FAILURE" + | "SHIPMENT.REFUND.UNAVAILABLE" + | "SHIPMENT.TRACKING_CODE.INVALID_CARRIER" + | "TRACKER.CARRIER_CODE_MISMATCH" + | "TRACKER.CREATE.ERROR" + | "TRACKER.INVALID_PARAMS" + | "TRACKER.INVALID_TEST_CODE" + | "TRACKER.MULTIPLE_CARRIERS_FOR_CODE" + | "TRACKER.NO_CARRIER_ACCOUNT" + | "TRACKER.NO_CARRIER_FOR_CODE" + | "TRACKER.NOT_FOUND" + | "TRACKER.RETRIEVE.ERROR" + | "TRACKER.RUN.ERROR" + | "TRACKER.UNSUPPORTED_CARRIER" + | "UNAUTHORIZED" + | "USER.CHARGE.NOT_ALLOWED" + | "USER.INVALID" + | "USER.PARENT.INVALID" + | "USER.UNAUTHORIZED" + | "WEBHOOK.EVENT.INVALID" + | "WEBHOOK.INVALID"; diff --git a/types/errors/FieldError.d.ts b/src/utils/errors/FieldError.ts similarity index 79% rename from types/errors/FieldError.d.ts rename to src/utils/errors/FieldError.ts index 3935d33d4..b160078fa 100644 --- a/types/errors/FieldError.d.ts +++ b/src/utils/errors/FieldError.ts @@ -1,4 +1,4 @@ -export declare interface IFieldError { +export type IFieldError = { /** * Field of the request that the error describes */ @@ -8,4 +8,4 @@ export declare interface IFieldError { * Human readable description of the problem */ message: string; -} +}; diff --git a/src/utils/errors/index.ts b/src/utils/errors/index.ts new file mode 100644 index 000000000..2f9c81d69 --- /dev/null +++ b/src/utils/errors/index.ts @@ -0,0 +1,3 @@ +export * from "./Error"; +export * from "./ErrorCode"; +export * from "./FieldError"; diff --git a/src/utils/internal_util.js b/src/utils/internal_util.js deleted file mode 100644 index 99385e7d2..000000000 --- a/src/utils/internal_util.js +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Utility class of various internal helper functions. - * This class is not designed to be used directly by consumers of the library. - * @internal - * @type {InternalUtils} - */ -export default class InternalUtils {} diff --git a/types/utils.d.ts b/src/utils/types.ts similarity index 52% rename from types/utils.d.ts rename to src/utils/types.ts index 0346ce471..57edee93e 100644 --- a/types/utils.d.ts +++ b/src/utils/types.ts @@ -2,9 +2,14 @@ export type DeepPartial = { [P in keyof T]?: DeepPartial; }; -export type ParametersToOmitOnCreate = 'id' | 'object' | 'mode' | 'created_at' | 'updated_at'; +export type ParametersToOmitOnCreate = + | "id" + | "object" + | "mode" + | "created_at" + | "updated_at"; -export declare interface IAllMethodParameters { +export type IAllMethodParameters = { /** * Optional pagination parameter. * Only records created before the given ID will be included. @@ -36,4 +41,39 @@ export declare interface IAllMethodParameters { * The maximum value is 100 */ page_size?: number; -} +}; + +export type IDatedObject = { + /** + * Date ISO String + */ + created_at: string; + + /** + * Date ISO String + */ + updated_at: string; +}; + +export type IBaseObject = { + object: ObjectName; +}; + +export type IObjectWithId = IBaseObject & { + /** + * Unique identifier, begins with "adr_" / "prcl_" / "ins_" / "trk_" / "batch_" / "cstinfo_" / etc + */ + id: string; + + /** + * Set based on which api-key you used, either "test" or "production" + */ + mode: "test" | "production"; + + /** + * The object name, e.g. "Address", "Rate", "Shipment", etc + */ + object: ObjectName; +}; + +export default {}; diff --git a/src/utils/util.js b/src/utils/util.js deleted file mode 100644 index 2153d8bb5..000000000 --- a/src/utils/util.js +++ /dev/null @@ -1,150 +0,0 @@ -import Constants from '../constants'; -import FilteringError from '../errors/general/filtering_error'; -import InvalidParameterError from '../errors/general/invalid_parameter_error'; -import SignatureVerificationError from '../errors/general/signature_verification_error'; - -const crypto = require('crypto'); -const util = require('util'); - -/** - * Utility class of various publicly-available helper functions. - * @public - * @type {Utils} - */ -export default class Utils { - /** - * Get the lowest SmartRate from a provided list of SmartRates. - * @public - * @param {Rate[]} smartrates - List of SmartRates to filter through - * @param {number} deliveryDays - The maximum number of days allowed for delivery - * @param {string} deliveryAccuracy - The target level of accuracy for the delivery days (e.g. 'percentile_50') - * @returns {Rate} - The lowest SmartRate - * @throws {FilteringError} - If no applicable rates are found - * @throws {InvalidParameterError} - If the deliveryAccuracy value is invalid - */ - getLowestSmartRate(smartrates, deliveryDays, deliveryAccuracy) { - const validDeliveryAccuracyValues = new Set([ - 'percentile_50', - 'percentile_75', - 'percentile_85', - 'percentile_90', - 'percentile_95', - 'percentile_97', - 'percentile_99', - ]); - let lowestSmartRate = null; - const lowercaseDeliveryAccuracy = deliveryAccuracy.toLowerCase(); - - if (!validDeliveryAccuracyValues.has(lowercaseDeliveryAccuracy)) { - throw new InvalidParameterError({ - message: `Invalid deliveryAccuracy value, must be one of: ${new Array( - ...validDeliveryAccuracyValues, - ).join(', ')}`, - }); - } - - for (let i = 0; i < smartrates.length; i += 1) { - const rate = smartrates[i]; - - if (rate.time_in_transit[lowercaseDeliveryAccuracy] > parseInt(deliveryDays, 10)) { - // eslint-disable-next-line no-continue - continue; - } else if ( - lowestSmartRate === null || - parseFloat(rate.rate) < parseFloat(lowestSmartRate.rate) - ) { - lowestSmartRate = rate; - } - } - - if (lowestSmartRate === null) { - throw new FilteringError({ message: util.format(Constants.NO_OBJECT_FOUND, 'rates') }); - } - - return lowestSmartRate; - } - - /** - * Get the lowest rate from a provided list of rates. - * @public - * @param {Rate[]} rates - List of rates to filter through - * @param {string[]} [carriers] - List of allowed carriers to filter by - * @param {string[]} [services] - List of allowed services to filter by - * @returns {Rate} - The lowest rate - * @throws {FilteringError} - If no applicable rates are found - */ - getLowestRate(rates, carriers = null, services = null) { - if (carriers) { - const carriersLower = carriers.map((carrier) => carrier.toLowerCase()); - // eslint-disable-next-line no-param-reassign - rates = rates.filter((rate) => carriersLower.includes(rate.carrier.toLowerCase())); - } - - if (services) { - const servicesLower = services.map((service) => service.toLowerCase()); - // eslint-disable-next-line no-param-reassign - rates = rates.filter((rate) => servicesLower.includes(rate.service.toLowerCase())); - } - - if (rates.length === 0) { - throw new FilteringError({ message: util.format(Constants.NO_OBJECT_FOUND, 'rates') }); - } - - return rates.reduce((lowest, rate) => { - if (parseFloat(rate.rate) < parseFloat(lowest.rate)) { - return rate; - } - - return lowest; - }, rates[0]); - } - - /** - * Validate a webhook by comparing the HMAC signature header sent from EasyPost to your shared secret. - * If the signatures do not match, an error will be raised signifying the webhook either did not originate - * from EasyPost or the secrets do not match. If the signatures do match, the `event_body` will be returned - * as JSON. - * @public - * @param {buffer} eventBody - The raw body of the webhook event - * @param {Object} headers - The headers of the webhook HTTP request - * @param {string} webhookSecret - The webhook secret shared between EasyPost and your application - * @returns {object} - The JSON-parsed webhook event body if the signature could be verified - * @throws {SignatureVerificationError} - If the signature could not be verified - */ - validateWebhook(eventBody, headers, webhookSecret) { - let webhook = {}; - const easypostHmacSignature = - headers['X-Hmac-Signature'] ?? headers['x-hmac-signature'] ?? null; - - if (easypostHmacSignature != null) { - const normalizedSecret = webhookSecret.normalize('NFKD'); - const encodedSecret = Buffer.from(normalizedSecret, 'utf8'); - - const expectedSignature = crypto - .createHmac('sha256', encodedSecret) - .update(eventBody, 'utf-8') - .digest('hex'); - - const digest = `hmac-sha256-hex=${expectedSignature}`; - - try { - if ( - crypto.timingSafeEqual( - Buffer.from(easypostHmacSignature, 'utf8'), - Buffer.from(digest, 'utf8'), - ) - ) { - webhook = JSON.parse(eventBody.toString()); - } else { - throw new SignatureVerificationError({ message: Constants.WEBHOOK_DOES_NOT_MATCH }); - } - } catch (e) { - throw new SignatureVerificationError({ message: Constants.WEBHOOK_DOES_NOT_MATCH }); - } - } else { - throw new SignatureVerificationError({ message: Constants.INVALID_WEBHOOK_SIGNATURE }); - } - - return webhook; - } -} diff --git a/src/utils/util.ts b/src/utils/util.ts new file mode 100644 index 000000000..aad3877e0 --- /dev/null +++ b/src/utils/util.ts @@ -0,0 +1,178 @@ +import crypto from "node:crypto"; +import util from "node:util"; +import Constants from "../constants"; +import FilteringError from "../errors/general/filtering_error"; +import InvalidParameterError from "../errors/general/invalid_parameter_error"; +import SignatureVerificationError from "../errors/general/signature_verification_error"; +import { IRate, ISmartRate } from "../services/rate_service"; + +/** + * Utility class of various publicly-available helper functions. + * @public + * @type {Utils} + */ +export default class Utils { + /** + * Get the lowest SmartRate from a provided list of SmartRates. + * @public + * @param smartRates - List of SmartRates to filter through + * @param deliveryDays - The maximum number of days allowed for delivery + * @param deliveryAccuracy - The target level of accuracy for the delivery days (e.g. 'percentile_50') + * @returns - The lowest SmartRate + * @throws {FilteringError} - If no applicable rates are found + * @throws {InvalidParameterError} - If the deliveryAccuracy value is invalid + */ + getLowestSmartRate( + smartRates: ISmartRate[], + deliveryDays: number, + deliveryAccuracy: keyof ISmartRate["time_in_transit"] + ): ISmartRate { + const validDeliveryAccuracyValues = new Set([ + "percentile_50", + "percentile_75", + "percentile_85", + "percentile_90", + "percentile_95", + "percentile_97", + "percentile_99", + ]); + let lowestSmartRate: ISmartRate | null = null; + const lowercaseDeliveryAccuracy = + deliveryAccuracy.toLowerCase() as keyof ISmartRate["time_in_transit"]; + + if (!validDeliveryAccuracyValues.has(lowercaseDeliveryAccuracy)) { + throw new InvalidParameterError({ + message: `Invalid deliveryAccuracy value, must be one of: ${[ + ...validDeliveryAccuracyValues, + ].join(", ")}`, + }); + } + + for (const rate of smartRates) { + if ( + rate.time_in_transit[lowercaseDeliveryAccuracy] > Number(deliveryDays) + ) { + // eslint-disable-next-line no-continue + continue; + } else if ( + lowestSmartRate === null || + parseFloat(rate.rate) < parseFloat(lowestSmartRate.rate) + ) { + lowestSmartRate = rate; + } + } + + if (lowestSmartRate === null) { + throw new FilteringError({ + message: util.format(Constants.NO_OBJECT_FOUND, "rates"), + }); + } + + return lowestSmartRate; + } + + /** + * Get the lowest rate from a provided list of rates. + * @public + * @param rates - List of rates to filter through + * @param [carriers] - List of allowed carriers to filter by + * @param [services] - List of allowed services to filter by + * @returns - The lowest rate + * @throws {FilteringError} - If no applicable rates are found + */ + getLowestRate( + rates: IRate[], + carriers: string[] | null = null, + services: string[] | null = null + ): IRate { + if (carriers) { + const carriersLower = carriers.map((carrier) => carrier.toLowerCase()); + // eslint-disable-next-line no-param-reassign + rates = rates.filter((rate) => + carriersLower.includes(rate.carrier.toLowerCase()) + ); + } + + if (services) { + const servicesLower = services.map((service) => service.toLowerCase()); + // eslint-disable-next-line no-param-reassign + rates = rates.filter((rate) => + servicesLower.includes(rate.service.toLowerCase()) + ); + } + + if (rates.length === 0) { + throw new FilteringError({ + message: util.format(Constants.NO_OBJECT_FOUND, "rates"), + }); + } + + return rates.reduce((lowest, rate) => { + if (parseFloat(rate.rate) < parseFloat(lowest.rate)) { + return rate; + } + + return lowest; + }, rates[0]); + } + + /** + * Validate a webhook by comparing the HMAC signature header sent from EasyPost to your shared secret. + * If the signatures do not match, an error will be raised signifying the webhook either did not originate + * from EasyPost or the secrets do not match. If the signatures do match, the `event_body` will be returned + * as JSON. + * @public + * @param eventBody - The raw body of the webhook event + * @param headers - The headers of the webhook HTTP request + * @param webhookSecret - The webhook secret shared between EasyPost and your application + * @returns - The JSON-parsed webhook event body if the signature could be verified + * @throws {SignatureVerificationError} - If the signature could not be verified + */ + validateWebhook( + eventBody: Buffer, + headers: Record, + webhookSecret: string + ): any { + let webhook = {}; + const easypostHmacSignature = + headers["X-Hmac-Signature"] ?? headers["x-hmac-signature"] ?? null; + + if (easypostHmacSignature != null) { + const normalizedSecret = webhookSecret.normalize("NFKD"); + const encodedSecret = Buffer.from(normalizedSecret, "utf8"); + + const expectedSignature = crypto + .createHmac("sha256", encodedSecret) + // @ts-ignore buffers are weird + .update(eventBody, "utf-8") + .digest("hex"); + + const digest = `hmac-sha256-hex=${expectedSignature}`; + + try { + if ( + crypto.timingSafeEqual( + Buffer.from(easypostHmacSignature, "utf8"), + Buffer.from(digest, "utf8") + ) + ) { + webhook = JSON.parse(eventBody.toString()); + } else { + throw new SignatureVerificationError({ + message: Constants.WEBHOOK_DOES_NOT_MATCH, + }); + } + } catch (e) { + throw new SignatureVerificationError({ + message: Constants.WEBHOOK_DOES_NOT_MATCH, + }); + } + } else { + throw new SignatureVerificationError({ + message: Constants.INVALID_WEBHOOK_SIGNATURE, + }); + } + + return webhook; + } +} diff --git a/test/services/address.test.js b/test/services/address.test.js index 3e633c2c3..bf6fe1950 100644 --- a/test/services/address.test.js +++ b/test/services/address.test.js @@ -1,9 +1,8 @@ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import InvalidRequestError from '../../src/errors/api/invalid_request_error'; -import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; -import Address from '../../src/models/address'; +import EasyPostClient from '../../out/src/easypost'; +import InvalidRequestError from '../../out/src/errors/api/invalid_request_error'; +import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; @@ -24,7 +23,7 @@ describe('Address Service', function () { it('creates an address', async function () { const address = await this.client.Address.create(Fixture.caAddress1()); - expect(address).to.be.an.instanceOf(Address); + expect(address.object).to.be.equal('Address'); expect(address.id).to.match(/^adr_/); expect(address.street1).to.equal('388 Townsend St'); }); @@ -35,14 +34,14 @@ describe('Address Service', function () { // Creating normally (without specifying "verify") will make the address, perform no verifications let address = await this.client.Address.create(addressData); - expect(address).to.be.an.instanceOf(Address); + expect(address.object).to.be.equal('Address'); expect(address.verifications.delivery).to.be.undefined; // Creating with verify = true will make the address, perform verifications addressData.verify = true; address = await this.client.Address.create(addressData); - expect(address).to.be.an.instanceOf(Address); + expect(address.object).to.be.equal('Address'); expect(address.verifications.delivery.success).to.be.false; }); @@ -52,7 +51,7 @@ describe('Address Service', function () { const address = await this.client.Address.create(addressData); - expect(address).to.be.an.instanceOf(Address); + expect(address.object).to.be.equal('Address'); expect(address.id).to.match(/^adr_/); expect(address.street1).to.equal('179 N HARBOR DR'); }); @@ -63,14 +62,14 @@ describe('Address Service', function () { // Creating normally (without specifying "verify") will make the address, perform no verifications let address = await this.client.Address.create(addressData); - expect(address).to.be.an.instanceOf(Address); + expect(address.object).to.be.equal('Address'); expect(address.verifications.delivery).to.be.undefined; // Creating with verify = true will make the address, perform verifications addressData.verify = [true]; address = await this.client.Address.create(addressData); - expect(address).to.be.an.instanceOf(Address); + expect(address.object).to.be.equal('Address'); expect(address.verifications.delivery.success).to.be.false; }); @@ -78,7 +77,7 @@ describe('Address Service', function () { const address = await this.client.Address.create(Fixture.caAddress1()); const retrievedAddress = await this.client.Address.retrieve(address.id); - expect(retrievedAddress).to.be.an.instanceOf(Address); + expect(retrievedAddress.object).to.be.equal('Address'); expect(withoutParams(retrievedAddress)).to.deep.include(withoutParams(address)); }); @@ -90,7 +89,7 @@ describe('Address Service', function () { expect(addressesArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(addresses.has_more).to.exist; addressesArray.forEach((address) => { - expect(address).to.be.an.instanceOf(Address); + expect(address.object).to.be.equal('Address'); }); }); @@ -115,7 +114,7 @@ describe('Address Service', function () { const address = await this.client.Address.createAndVerify(addressData); - expect(address).to.be.an.instanceOf(Address); + expect(address.object).to.be.equal('Address'); expect(address.id).to.match(/^adr_/); expect(address.street1).to.equal('179 N HARBOR DR'); }); @@ -133,7 +132,7 @@ describe('Address Service', function () { const address = await this.client.Address.create(Fixture.caAddress2()); const verifiedAddress = await this.client.Address.verifyAddress(address.id); - expect(verifiedAddress).to.be.an.instanceOf(Address); + expect(verifiedAddress.object).to.be.equal('Address'); expect(verifiedAddress.id).to.match(/^adr_/); expect(verifiedAddress.street1).to.equal('179 N HARBOR DR'); }); diff --git a/test/services/api_key.test.js b/test/services/api_key.test.js index 8fdff004b..7b428e822 100644 --- a/test/services/api_key.test.js +++ b/test/services/api_key.test.js @@ -1,10 +1,9 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import ApiKey from '../../src/models/api_key'; +import EasyPostClient from '../../out/src/easypost'; import * as setupPolly from '../helpers/setup_polly'; -import FilteringError from '../../src/errors/general/filtering_error'; +import FilteringError from '../../out/src/errors/general/filtering_error'; describe('ApiKey Service', function () { setupPolly.startPolly(); @@ -22,7 +21,7 @@ describe('ApiKey Service', function () { const apiKeys = await this.client.ApiKey.all(); apiKeys.keys.forEach((apiKey) => { - expect(apiKey).to.be.an.instanceOf(ApiKey); + expect(apiKey.object).to.be.equal('ApiKey'); }); }); @@ -30,7 +29,7 @@ describe('ApiKey Service', function () { const user = await this.client.User.retrieveMe(); const keys = await this.client.ApiKey.retrieveApiKeysForUser(user.id); - expect(keys).to.be.an.instanceOf(Array); + expect(keys.object).to.be.equal('Array'); }); it("throws FilteringError when trying to retrieve child user's API keys", async function () { diff --git a/test/services/base_service.test.js b/test/services/base_service.test.js index 49e1dc3d7..2cfadb736 100644 --- a/test/services/base_service.test.js +++ b/test/services/base_service.test.js @@ -1,8 +1,8 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; +import EasyPostClient from '../../out/src/easypost'; +import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; import * as setupPolly from '../helpers/setup_polly'; import { MockMiddleware, diff --git a/test/services/batch.test.js b/test/services/batch.test.js index 954fa4c04..2827c3c92 100644 --- a/test/services/batch.test.js +++ b/test/services/batch.test.js @@ -3,8 +3,7 @@ import fs from 'fs'; import { resolve } from 'path'; import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import Batch from '../../src/models/batch'; +import EasyPostClient from '../../out/src/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; @@ -25,7 +24,7 @@ describe('Batch Service', function () { shipments: [Fixture.oneCallBuyShipment()], }); - expect(batch).to.be.an.instanceOf(Batch); + expect(batch.object).to.be.equal('Batch'); expect(batch.id).to.match(/^batch_/); expect(batch.shipments).to.exist; }); @@ -37,7 +36,7 @@ describe('Batch Service', function () { const retrievedBatch = await this.client.Batch.retrieve(batch.id); - expect(retrievedBatch).to.be.an.instanceOf(Batch); + expect(retrievedBatch.object).to.be.equal('Batch'); expect(retrievedBatch.id).to.equal(batch.id); }); @@ -49,7 +48,7 @@ describe('Batch Service', function () { expect(addressesArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(batches.has_more).to.exist; addressesArray.forEach((batch) => { - expect(batch).to.be.an.instanceOf(Batch); + expect(batch.object).to.be.equal('Batch'); }); }); @@ -60,7 +59,7 @@ describe('Batch Service', function () { const boughtBatch = await this.client.Batch.buy(batch.id); - expect(boughtBatch).to.be.an.instanceOf(Batch); + expect(boughtBatch.object).to.be.equal('Batch'); expect(boughtBatch.num_shipments).to.equal(1); }); @@ -85,7 +84,7 @@ describe('Batch Service', function () { const batchWithScanForm = await this.client.Batch.createScanForm(boughtBatch.id); // We can't assert anything meaningful here because the scanform gets queued for generation and may not be immediately available - expect(batchWithScanForm).to.be.an.instanceOf(Batch); + expect(batchWithScanForm.object).to.be.equal('Batch'); }); it('adds and removes shipments from a batch', async function () { @@ -122,6 +121,6 @@ describe('Batch Service', function () { const batchWithLabel = await this.client.Batch.generateLabel(boughtBatch.id, 'ZPL'); // We can't assert anything meaningful here because the label gets queued for generation and may not be immediately available - expect(batchWithLabel).to.be.an.instanceOf(Batch); + expect(batchWithLabel.object).to.be.equal('Batch'); }); }); diff --git a/test/services/beta_rate.test.js b/test/services/beta_rate.test.js index 5960790de..f58cbcea8 100644 --- a/test/services/beta_rate.test.js +++ b/test/services/beta_rate.test.js @@ -1,8 +1,7 @@ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import FilteringError from '../../src/errors/general/filtering_error'; -import Rate from '../../src/models/rate'; +import EasyPostClient from '../../out/src/easypost'; +import FilteringError from '../../out/src/errors/general/filtering_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; @@ -25,7 +24,7 @@ describe('BetaRateService', function () { ); statelessRates.forEach((rate) => { - expect(rate).to.be.an.instanceOf(Rate); + expect(rate.object).to.be.equal('Rate'); expect(rate).to.not.have.property('id'); }); }); diff --git a/test/services/beta_referral_customer.test.js b/test/services/beta_referral_customer.test.js index 44819a21e..7551c4602 100644 --- a/test/services/beta_referral_customer.test.js +++ b/test/services/beta_referral_customer.test.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; +import EasyPostClient from '../../out/src/easypost'; import * as setupPolly from '../helpers/setup_polly'; describe('BetaReferralCustomerService', function () { diff --git a/test/services/billing.test.js b/test/services/billing.test.js index 27a395dde..aad0e608a 100644 --- a/test/services/billing.test.js +++ b/test/services/billing.test.js @@ -1,7 +1,7 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; +import EasyPostClient from '../../out/src/easypost'; import { MockMiddleware, MockRequest, diff --git a/test/services/carrier_account.test.js b/test/services/carrier_account.test.js index 31b3b9367..c857cde94 100644 --- a/test/services/carrier_account.test.js +++ b/test/services/carrier_account.test.js @@ -1,8 +1,7 @@ /* eslint-disable no-param-reassign */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import CarrierAccount from '../../src/models/carrier_account'; +import EasyPostClient from '../../out/src/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; @@ -23,7 +22,7 @@ describe('CarrierAccount Service', function () { it('creates a carrier account', async function () { const carrierAccount = await this.client.CarrierAccount.create(Fixture.basicCarrierAccount()); - expect(carrierAccount).to.be.an.instanceOf(CarrierAccount); + expect(carrierAccount.object).to.be.equal('CarrierAccount'); expect(carrierAccount.id).to.match(/^ca_/); expect(carrierAccount.type).to.equal('DhlEcsAccount'); @@ -60,7 +59,7 @@ describe('CarrierAccount Service', function () { const carrierAccount = await this.client.CarrierAccount.create(Fixture.basicCarrierAccount()); const retrievedCarrierAccount = await this.client.CarrierAccount.retrieve(carrierAccount.id); - expect(retrievedCarrierAccount).to.be.an.instanceOf(CarrierAccount); + expect(retrievedCarrierAccount.object).to.be.equal('CarrierAccount'); expect(withoutParams(retrievedCarrierAccount)).to.deep.include(withoutParams(carrierAccount)); // Remove the carrier account once we have tested it so we don't pollute the account with test accounts @@ -71,7 +70,7 @@ describe('CarrierAccount Service', function () { const carrierAccounts = await this.client.CarrierAccount.all(); carrierAccounts.forEach((carrierAccount) => { - expect(carrierAccount).to.be.an.instanceOf(CarrierAccount); + expect(carrierAccount.object).to.be.equal('CarrierAccount'); }); }); @@ -88,7 +87,7 @@ describe('CarrierAccount Service', function () { params, ); - expect(updatedCarrierAccount).to.be.an.instanceOf(CarrierAccount); + expect(updatedCarrierAccount.object).to.be.equal('CarrierAccount'); expect(updatedCarrierAccount.id).to.match(/^ca_/); expect(updatedCarrierAccount.description).to.equal(testDescription); }); diff --git a/test/services/carrier_metadata.test.js b/test/services/carrier_metadata.test.js index c2b565a4d..eb4aa000e 100644 --- a/test/services/carrier_metadata.test.js +++ b/test/services/carrier_metadata.test.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; +import EasyPostClient from '../../out/src/easypost'; import * as setupPolly from '../helpers/setup_polly'; /* eslint-disable func-names */ diff --git a/test/services/carrier_type.test.js b/test/services/carrier_type.test.js index c6c8a7222..8232aff8e 100644 --- a/test/services/carrier_type.test.js +++ b/test/services/carrier_type.test.js @@ -1,8 +1,7 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import CarrierType from '../../src/models/carrier_type'; +import EasyPostClient from '../../out/src/easypost'; import * as setupPolly from '../helpers/setup_polly'; describe('CarrierType Service', function () { @@ -21,7 +20,7 @@ describe('CarrierType Service', function () { const carrierTypes = await this.client.CarrierType.all(); carrierTypes.forEach((type) => { - expect(type).to.be.an.instanceOf(CarrierType); + expect(type.object).to.be.equal('CarrierType'); }); }); }); diff --git a/test/services/customs_info.test.js b/test/services/customs_info.test.js index d194cf16d..4550f4489 100644 --- a/test/services/customs_info.test.js +++ b/test/services/customs_info.test.js @@ -1,8 +1,7 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import CustomsInfo from '../../src/models/customs_info'; +import EasyPostClient from '../../out/src/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; @@ -22,7 +21,7 @@ describe('CustomsInfo Service', function () { it('creates a customs info', async function () { const customsInfo = await this.client.CustomsInfo.create(Fixture.basicCustomsInfo()); - expect(customsInfo).to.be.an.instanceOf(CustomsInfo); + expect(customsInfo.object).to.be.equal('CustomsInfo'); expect(customsInfo.id).to.match(/^cstinfo_/); expect(customsInfo.eel_pfc).to.equal('NOEEI 30.37(a)'); }); @@ -31,7 +30,7 @@ describe('CustomsInfo Service', function () { const customsInfo = await this.client.CustomsInfo.create(Fixture.basicCustomsInfo()); const retrievedCustomsInfo = await this.client.CustomsInfo.retrieve(customsInfo.id); - expect(customsInfo).to.be.an.instanceOf(CustomsInfo); + expect(customsInfo.object).to.be.equal('CustomsInfo'); expect(withoutParams(retrievedCustomsInfo)).to.deep.include(withoutParams(customsInfo)); }); }); diff --git a/test/services/customs_item.test.js b/test/services/customs_item.test.js index 1501e9184..871e08c52 100644 --- a/test/services/customs_item.test.js +++ b/test/services/customs_item.test.js @@ -1,8 +1,7 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPost from '../../src/easypost'; -import CustomsItem from '../../src/models/customs_item'; +import EasyPost from '../../out/src/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; @@ -22,7 +21,7 @@ describe('CustomsItem Service', function () { it('creates a customs item', async function () { const customsItem = await this.client.CustomsItem.create(Fixture.basicCustomsItem()); - expect(customsItem).to.be.an.instanceOf(CustomsItem); + expect(customsItem.object).to.be.equal('CustomsItem'); expect(customsItem.id).to.match(/^cstitem_/); expect(customsItem.value).to.equal('23.25'); }); @@ -31,7 +30,7 @@ describe('CustomsItem Service', function () { const customsItem = await this.client.CustomsItem.create(Fixture.basicCustomsItem()); const retrievedCustomsInfo = await this.client.CustomsItem.retrieve(customsItem.id); - expect(customsItem).to.be.an.instanceOf(CustomsItem); + expect(customsItem.object).to.be.equal('CustomsItem'); expect(withoutParams(retrievedCustomsInfo)).to.deep.include(withoutParams(customsItem)); }); }); diff --git a/test/services/easypost.test.js b/test/services/easypost.test.js index 81a0dee2d..efd738a4e 100644 --- a/test/services/easypost.test.js +++ b/test/services/easypost.test.js @@ -1,7 +1,7 @@ import { expect } from 'chai'; -import EasyPost, { METHODS } from '../../src/easypost'; -import MissingParameterError from '../../src/errors/general/missing_parameter_error'; +import EasyPost, { METHODS } from '../../out/src/easypost'; +import MissingParameterError from '../../out/src/errors/general/missing_parameter_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; diff --git a/test/services/end_shipper.test.js b/test/services/end_shipper.test.js index 83b635290..bf466fb07 100644 --- a/test/services/end_shipper.test.js +++ b/test/services/end_shipper.test.js @@ -1,7 +1,6 @@ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import EndShipper from '../../src/models/end_shipper'; +import EasyPostClient from '../../out/src/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; @@ -20,7 +19,7 @@ describe('EndShipper Service', function () { it('creates an EndShipper object', async function () { const endShipper = await this.client.EndShipper.create(Fixture.caAddress1()); - expect(endShipper).to.be.an.instanceOf(EndShipper); + expect(endShipper.object).to.be.equal('EndShipper'); expect(endShipper.id).to.match(/^es_/); expect(endShipper.street1).to.equal('388 TOWNSEND ST APT 20'); }); @@ -29,7 +28,7 @@ describe('EndShipper Service', function () { const endShipper = await this.client.EndShipper.create(Fixture.caAddress2()); const retrievedEndShipper = await this.client.EndShipper.retrieve(endShipper.id); - expect(retrievedEndShipper).to.be.an.instanceOf(EndShipper); + expect(retrievedEndShipper.object).to.be.equal('EndShipper'); expect(endShipper.street1).to.equal(retrievedEndShipper.street1); }); @@ -41,7 +40,7 @@ describe('EndShipper Service', function () { expect(endShippersArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(endShippers.has_more).to.exist; endShippersArray.forEach((endShipper) => { - expect(endShipper).to.be.an.instanceOf(EndShipper); + expect(endShipper.object).to.be.equal('EndShipper'); }); }); @@ -63,7 +62,7 @@ describe('EndShipper Service', function () { const updatedEndShipper = await this.client.EndShipper.update(endShipper.id, params); - expect(updatedEndShipper).to.be.an.instanceOf(EndShipper); + expect(updatedEndShipper.object).to.be.equal('EndShipper'); expect(updatedEndShipper.name).to.equal(newName.toUpperCase()); }); }); diff --git a/test/services/error.test.js b/test/services/error.test.js index 09b575ff2..fea61daad 100644 --- a/test/services/error.test.js +++ b/test/services/error.test.js @@ -1,20 +1,20 @@ import { assert, expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import ForbiddenError from '../../src/errors/api/forbidden_error'; -import GatewayTimeoutError from '../../src/errors/api/gateway_timeout_error'; -import InternalServerError from '../../src/errors/api/internal_server_error'; -import InvalidRequestError from '../../src/errors/api/invalid_request_error'; -import MethodNotAllowedError from '../../src/errors/api/method_not_allowed_error'; -import NotFoundError from '../../src/errors/api/not_found_error'; -import PaymentError from '../../src/errors/api/payment_error'; -import RateLimitError from '../../src/errors/api/rate_limit_error'; -import RedirectError from '../../src/errors/api/redirect_error'; -import ServiceUnavailableError from '../../src/errors/api/service_unavailable_error'; -import TimeoutError from '../../src/errors/api/timeout_error'; -import UnauthorizedError from '../../src/errors/api/unauthorized_error'; -import UnknownApiError from '../../src/errors/api/unknown_api_error'; -import ErrorHandler from '../../src/errors/error_handler'; +import EasyPostClient from '../../out/src/easypost'; +import ForbiddenError from '../../out/src/errors/api/forbidden_error'; +import GatewayTimeoutError from '../../out/src/errors/api/gateway_timeout_error'; +import InternalServerError from '../../out/src/errors/api/internal_server_error'; +import InvalidRequestError from '../../out/src/errors/api/invalid_request_error'; +import MethodNotAllowedError from '../../out/src/errors/api/method_not_allowed_error'; +import NotFoundError from '../../out/src/errors/api/not_found_error'; +import PaymentError from '../../out/src/errors/api/payment_error'; +import RateLimitError from '../../out/src/errors/api/rate_limit_error'; +import RedirectError from '../../out/src/errors/api/redirect_error'; +import ServiceUnavailableError from '../../out/src/errors/api/service_unavailable_error'; +import TimeoutError from '../../out/src/errors/api/timeout_error'; +import UnauthorizedError from '../../out/src/errors/api/unauthorized_error'; +import UnknownApiError from '../../out/src/errors/api/unknown_api_error'; +import ErrorHandler from '../../out/src/errors/error_handler'; import * as setupPolly from '../helpers/setup_polly'; describe('Error Service', function () { diff --git a/test/services/event.test.js b/test/services/event.test.js index 0ba92ce26..91cda1eb6 100644 --- a/test/services/event.test.js +++ b/test/services/event.test.js @@ -3,13 +3,11 @@ import fs from 'fs'; import { resolve } from 'path'; import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import Event from '../../src/models/event'; -import Payload from '../../src/models/payload'; +import EasyPostClient from '../../out/src/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; -import NotFoundError from '../../src/errors/api/not_found_error'; -import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; +import NotFoundError from '../../out/src/errors/api/not_found_error'; +import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; describe('Event Service', function () { setupPolly.startPolly(); @@ -30,7 +28,7 @@ describe('Event Service', function () { const retrievedEvent = await this.client.Event.retrieve(events.events[0].id); - expect(retrievedEvent).to.be.an.instanceOf(Event); + expect(retrievedEvent.object).to.be.equal('Event'); expect(retrievedEvent.id).to.match(/^evt_/); }); @@ -44,7 +42,7 @@ describe('Event Service', function () { expect(eventsArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(events.has_more).to.exist; eventsArray.forEach((event) => { - expect(event).to.be.an.instanceOf(Event); + expect(event.object).to.be.equal('Event'); }); }); @@ -95,7 +93,7 @@ describe('Event Service', function () { const payloads = await this.client.Event.retrieveAllPayloads(event.id); payloads.forEach((payload) => { - expect(payload).to.be.an.instanceOf(Payload); + expect(payload.object).to.be.an.instanceOf('Payload'); }); // Remove the webhook once we are done testing diff --git a/test/services/insurance.test.js b/test/services/insurance.test.js index 340c838ee..71cfa9ad7 100644 --- a/test/services/insurance.test.js +++ b/test/services/insurance.test.js @@ -1,9 +1,8 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; -import Insurance from '../../src/models/insurance'; +import EasyPostClient from '../../out/src/easypost'; +import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; @@ -27,7 +26,7 @@ describe('Insurance Service', function () { const insurance = await this.client.Insurance.create(insuranceData); - expect(insurance).to.be.an.instanceOf(Insurance); + expect(insurance.object).to.be.equal('Insurance'); expect(insurance.id).to.match(/^ins_/); expect(insurance.amount).to.equal('100.00000'); }); @@ -42,7 +41,7 @@ describe('Insurance Service', function () { const retrievedInsurance = await this.client.Insurance.retrieve(insurance.id); - expect(retrievedInsurance).to.be.an.instanceOf(Insurance); + expect(retrievedInsurance.object).to.be.equal('Insurance'); expect(retrievedInsurance.id).to.equal(insurance.id); }); @@ -56,7 +55,7 @@ describe('Insurance Service', function () { expect(insuranceArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(insurance.has_more).to.exist; insuranceArray.forEach((event) => { - expect(event).to.be.an.instanceOf(Insurance); + expect(event.object).to.be.equal('Insurance'); }); }); @@ -83,7 +82,7 @@ describe('Insurance Service', function () { const insurance = await this.client.Insurance.create(insuranceData); const cancelledInsurance = await this.client.Insurance.refund(insurance.id); - expect(cancelledInsurance).to.be.an.instanceOf(Insurance); + expect(cancelledInsurance.object).to.be.equal('Insurance'); expect(cancelledInsurance.id).to.match(/^ins_/); expect(cancelledInsurance.status).to.equal('cancelled'); expect(cancelledInsurance.messages[0]).to.equal('Insurance was cancelled by the user.'); diff --git a/test/services/order.test.js b/test/services/order.test.js index 2beb948c5..3c6943931 100644 --- a/test/services/order.test.js +++ b/test/services/order.test.js @@ -1,10 +1,8 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import FilteringError from '../../src/errors/general/filtering_error'; -import Order from '../../src/models/order'; -import Rate from '../../src/models/rate'; +import EasyPostClient from '../../out/src/easypost'; +import FilteringError from '../../out/src/errors/general/filtering_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; @@ -23,7 +21,7 @@ describe('Order Service', function () { it('creates an order', async function () { const order = await this.client.Order.create(Fixture.basicOrder()); - expect(order).to.be.an.instanceOf(Order); + expect(order.object).to.be.equal('Order'); expect(order.id).to.match(/^order_/); expect(order.rates).to.exist; }); @@ -33,7 +31,7 @@ describe('Order Service', function () { const retrievedOrder = await this.client.Order.retrieve(order.id); - expect(retrievedOrder).to.be.an.instanceOf(Order); + expect(retrievedOrder.object).to.be.equal('Order'); expect(retrievedOrder.id).to.equal(order.id); }); @@ -46,7 +44,7 @@ describe('Order Service', function () { expect(ratesArray).to.be.an.instanceOf(Array); ratesArray.forEach((rate) => { - expect(rate).to.be.an.instanceOf(Rate); + expect(rate.object).to.be.equal('Rate'); }); }); diff --git a/test/services/parcel.test.js b/test/services/parcel.test.js index 8d750da00..6b8e6aa9c 100644 --- a/test/services/parcel.test.js +++ b/test/services/parcel.test.js @@ -1,8 +1,7 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import Parcel from '../../src/models/parcel'; +import EasyPostClient from '../../out/src/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; @@ -22,7 +21,7 @@ describe('Parcel Service', function () { it('creates a parcel', async function () { const parcel = await this.client.Parcel.create(Fixture.basicParcel()); - expect(parcel).to.be.an.instanceOf(Parcel); + expect(parcel.object).to.be.equal('Parcel'); expect(parcel.id).to.match(/^prcl_/); expect(parcel.weight).to.equal(15.4); }); @@ -31,7 +30,7 @@ describe('Parcel Service', function () { const parcel = await this.client.Parcel.create(Fixture.basicParcel()); const retrievedParcel = await this.client.Parcel.retrieve(parcel.id); - expect(parcel).to.be.an.instanceOf(Parcel); + expect(parcel.object).to.be.equal('Parcel'); expect(withoutParams(retrievedParcel)).to.deep.include(withoutParams(parcel)); }); }); diff --git a/test/services/pickup.test.js b/test/services/pickup.test.js index b604083f4..8cd95f15b 100644 --- a/test/services/pickup.test.js +++ b/test/services/pickup.test.js @@ -1,12 +1,11 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import Pickup from '../../src/models/pickup'; +import EasyPostClient from '../../out/src/easypost'; import Fixture from '../helpers/fixture'; -import FilteringError from '../../src/errors/general/filtering_error'; +import FilteringError from '../../out/src/errors/general/filtering_error'; import * as setupPolly from '../helpers/setup_polly'; -import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; +import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; import { withoutParams } from '../helpers/utils'; describe('Pickup Service', function () { @@ -29,7 +28,7 @@ describe('Pickup Service', function () { const pickup = await this.client.Pickup.create(pickupData); - expect(pickup).to.be.an.instanceOf(Pickup); + expect(pickup.object).to.be.equal('Pickup'); expect(pickup.id).to.match(/^pickup_/); expect(pickup.pickup_rates).to.exist; }); @@ -44,7 +43,7 @@ describe('Pickup Service', function () { const retrievedPickup = await this.client.Pickup.retrieve(pickup.id); - expect(retrievedPickup).to.be.an.instanceOf(Pickup); + expect(retrievedPickup.object).to.be.equal('Pickup'); expect(withoutParams(retrievedPickup)).to.deep.include(withoutParams(pickup)); }); @@ -56,7 +55,7 @@ describe('Pickup Service', function () { expect(pickupsArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(pickups.has_more).to.exist; pickupsArray.forEach((pickup) => { - expect(pickup).to.be.an.instanceOf(Pickup); + expect(pickup.object).to.be.equal('Pickup'); }); }); @@ -90,7 +89,7 @@ describe('Pickup Service', function () { Fixture.pickupService(), ); - expect(boughtPickup).to.be.an.instanceOf(Pickup); + expect(boughtPickup.object).to.be.equal('Pickup'); expect(boughtPickup.id).to.match(/^pickup_/); expect(boughtPickup.confirmation).to.exist; expect(boughtPickup.status).to.equal('scheduled'); @@ -111,7 +110,7 @@ describe('Pickup Service', function () { const cancelledPickup = await this.client.Pickup.cancel(boughtPickup.id); - expect(cancelledPickup).to.be.an.instanceOf(Pickup); + expect(cancelledPickup.object).to.be.equal('Pickup'); expect(cancelledPickup.id).to.match(/^pickup_/); expect(cancelledPickup.status).to.equal('canceled'); }); diff --git a/test/services/rate.test.js b/test/services/rate.test.js index 6d6c33aeb..c6018929e 100644 --- a/test/services/rate.test.js +++ b/test/services/rate.test.js @@ -1,8 +1,7 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import Rate from '../../src/models/rate'; +import EasyPostClient from '../../out/src/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; @@ -23,7 +22,7 @@ describe('Rate Service', function () { const rate = await this.client.Rate.retrieve(shipment.rates[0].id); - expect(rate).to.be.an.instanceOf(Rate); + expect(rate.object).to.be.equal('Rate'); expect(rate.id).to.match(/^rate_/); }); }); diff --git a/test/services/referral_customer.test.js b/test/services/referral_customer.test.js index 0ac7bde5f..e563d189a 100644 --- a/test/services/referral_customer.test.js +++ b/test/services/referral_customer.test.js @@ -1,8 +1,7 @@ import { expect } from 'chai'; -import EasyPost from '../../src/easypost'; -import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; -import User from '../../src/models/user'; +import EasyPost from '../../out/src/easypost'; +import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; @@ -27,7 +26,7 @@ describe('ReferralCustomer Service', function () { phone: '1111111111', }); - expect(referral).to.be.an.instanceOf(User); + expect(referral.object).to.be.equal('User'); expect(referral.id).to.match(/^user_/); expect(referral.name).to.equal('Test Referral'); }); @@ -40,7 +39,7 @@ describe('ReferralCustomer Service', function () { expect(referralsArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(referrals.has_more).to.exist; referralsArray.forEach((referral) => { - expect(referral).to.be.an.instanceOf(User); + expect(referral.object).to.be.equal('User'); }); }); diff --git a/test/services/refund.test.js b/test/services/refund.test.js index dcc68370a..3d9434a92 100644 --- a/test/services/refund.test.js +++ b/test/services/refund.test.js @@ -1,9 +1,8 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; -import Refund from '../../src/models/refund'; +import EasyPostClient from '../../out/src/easypost'; +import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; @@ -34,7 +33,7 @@ describe('Refund Service', function () { const refunds = await this.client.Refund.create(refundData); refunds.forEach((pickup) => { - expect(pickup).to.be.an.instanceOf(Refund); + expect(pickup.object).to.be.equal('Refund'); }); expect(refunds[0].id).to.match(/^rfnd_/); expect(refunds[0].status).to.equal('submitted'); @@ -48,7 +47,7 @@ describe('Refund Service', function () { expect(refundsArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(refunds.has_more).to.exist; refundsArray.forEach((refund) => { - expect(refund).to.be.an.instanceOf(Refund); + expect(refund.object).to.be.equal('Refund'); }); }); @@ -73,7 +72,7 @@ describe('Refund Service', function () { const retrieveRefund = await this.client.Refund.retrieve(refunds.refunds[0].id); - expect(retrieveRefund).to.be.an.instanceOf(Refund); + expect(retrieveRefund.object).to.be.equal('Refund'); expect(withoutParams(retrieveRefund)).to.deep.include(withoutParams(refunds.refunds[0])); }); }); diff --git a/test/services/report.test.js b/test/services/report.test.js index dc6045ad2..11dd410f0 100644 --- a/test/services/report.test.js +++ b/test/services/report.test.js @@ -1,9 +1,8 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; -import Report from '../../src/models/report'; +import EasyPostClient from '../../out/src/easypost'; +import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; @@ -26,7 +25,7 @@ describe('Report Service', function () { type: Fixture.reportType(), }); - expect(report).to.be.an.instanceOf(Report); + expect(report.object).to.be.equal('Report'); expect(report.id).to.match(/^shprep_/); }); @@ -40,7 +39,7 @@ describe('Report Service', function () { // Reports are queued, so we can't wait for completion. // Verifying columns would require parsing CSV. Verify correct parameters via URL in cassette - expect(report).to.be.an.instanceOf(Report); + expect(report.object).to.be.equal('Report'); }); it(`creates a report with additional columns`, async function () { @@ -53,7 +52,7 @@ describe('Report Service', function () { // Reports are queued, so we can't wait for completion. // Verifying columns would require parsing CSV. Verify correct parameters via URL in cassette - expect(report).to.be.an.instanceOf(Report); + expect(report.object).to.be.equal('Report'); }); it('retrieves a shipment report', async function () { @@ -65,7 +64,7 @@ describe('Report Service', function () { const retrievedReport = await this.client.Report.retrieve(report.id); - expect(retrievedReport).to.be.an.instanceOf(Report); + expect(retrievedReport.object).to.be.equal('Report'); expect(retrievedReport.start_date).to.equal(report.start_date); expect(retrievedReport.end_date).to.equal(report.end_date); }); @@ -81,7 +80,7 @@ describe('Report Service', function () { expect(reportsArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(reports.has_more).to.exist; reportsArray.forEach((report) => { - expect(report).to.be.an.instanceOf(Report); + expect(report.object).to.be.equal('Report'); }); }); diff --git a/test/services/scan_form.test.js b/test/services/scan_form.test.js index ebe0f7b78..0c77c0e83 100644 --- a/test/services/scan_form.test.js +++ b/test/services/scan_form.test.js @@ -1,9 +1,8 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; -import ScanForm from '../../src/models/scan_form'; +import EasyPostClient from '../../out/src/easypost'; +import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; @@ -27,7 +26,7 @@ describe('ScanForm Service', function () { shipments: [shipment], }); - expect(scanform).to.be.an.instanceOf(ScanForm); + expect(scanform.object).to.be.equal('ScanForm'); expect(scanform.id).to.match(/^sf_/); }); @@ -40,7 +39,7 @@ describe('ScanForm Service', function () { const retrievedScanform = await this.client.ScanForm.retrieve(scanform.id); - expect(retrievedScanform).to.be.an.instanceOf(ScanForm); + expect(retrievedScanform.object).to.be.equal('ScanForm'); expect(withoutParams(retrievedScanform)).to.deep.include(withoutParams(scanform)); }); @@ -54,7 +53,7 @@ describe('ScanForm Service', function () { expect(scanformsArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(scanforms.has_more).to.exist; scanformsArray.forEach((scanform) => { - expect(scanform).to.be.an.instanceOf(ScanForm); + expect(scanform.object).to.be.equal('ScanForm'); }); }); diff --git a/test/services/shipment.test.js b/test/services/shipment.test.js index dc2cc123e..6a642ea7c 100644 --- a/test/services/shipment.test.js +++ b/test/services/shipment.test.js @@ -1,11 +1,9 @@ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; -import FilteringError from '../../src/errors/general/filtering_error'; -import InvalidParameterError from '../../src/errors/general/invalid_parameter_error'; -import Rate from '../../src/models/rate'; -import Shipment from '../../src/models/shipment'; +import EasyPostClient from '../../out/src/easypost'; +import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; +import FilteringError from '../../out/src/errors/general/filtering_error'; +import InvalidParameterError from '../../out/src/errors/general/invalid_parameter_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; @@ -25,7 +23,7 @@ describe('Shipment Service', function () { it('creates a shipment', async function () { const shipment = await this.client.Shipment.create(Fixture.fullShipment()); - expect(shipment).to.be.an.instanceOf(Shipment); + expect(shipment.object).to.be.equal('Shipment'); expect(shipment.id).to.match(/^shp_/); expect(shipment.rates).to.exist; expect(shipment.options.label_format).to.equal('PNG'); @@ -42,7 +40,7 @@ describe('Shipment Service', function () { const shipment = await this.client.Shipment.create(shipmentData); - expect(shipment).to.be.an.instanceOf(Shipment); + expect(shipment.object).to.be.equal('Shipment'); expect(shipment.id).to.match(/^shp_/); expect(shipment.options).to.exist; // The EasyPostClient API populates some default values here expect(shipment.customs_info).to.be.null; @@ -56,7 +54,7 @@ describe('Shipment Service', function () { const shipment = await this.client.Shipment.create(shipmentData); - expect(shipment).to.be.an.instanceOf(Shipment); + expect(shipment.object).to.be.equal('Shipment'); expect(shipment.id).to.match(/^shp_/); expect(shipment.tax_identifiers[0].tax_id_type).to.equal('IOSS'); }); @@ -72,7 +70,7 @@ describe('Shipment Service', function () { parcel: { id: parcel.id }, }); - expect(shipment).to.be.an.instanceOf(Shipment); + expect(shipment.object).to.be.equal('Shipment'); expect(shipment.id).to.match(/^shp_/); expect(shipment.from_address.id).to.match(/^adr_/); expect(shipment.to_address.id).to.match(/^adr_/); @@ -85,7 +83,7 @@ describe('Shipment Service', function () { const retrievedShipment = await this.client.Shipment.retrieve(shipment.id); - expect(retrievedShipment).to.be.an.instanceOf(Shipment); + expect(retrievedShipment.object).to.be.equal('Shipment'); expect(retrievedShipment.id).to.equal(shipment.id); }); @@ -99,7 +97,7 @@ describe('Shipment Service', function () { expect(shipmentsArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(shipments.has_more).to.exist; shipmentsArray.forEach((shipment) => { - expect(shipment).to.be.an.instanceOf(Shipment); + expect(shipment.object).to.be.equal('Shipment'); }); }); @@ -136,7 +134,7 @@ describe('Shipment Service', function () { expect(ratesArray).to.be.an.instanceOf(Array); ratesArray.forEach((rate) => { - expect(rate).to.be.an.instanceOf(Rate); + expect(rate.object).to.be.equal('Rate'); }); }); diff --git a/test/services/tracker.test.js b/test/services/tracker.test.js index 8859216b2..f2bee23f7 100644 --- a/test/services/tracker.test.js +++ b/test/services/tracker.test.js @@ -1,9 +1,8 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; -import Tracker from '../../src/models/tracker'; +import EasyPostClient from '../../out/src/easypost'; +import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; @@ -24,7 +23,7 @@ describe('Tracker Service', function () { tracking_code: 'EZ1000000001', }); - expect(tracker).to.be.an.instanceOf(Tracker); + expect(tracker.object).to.be.equal('Tracker'); expect(tracker.id).to.match(/^trk_/); expect(tracker.status).to.equal('pre_transit'); }); @@ -36,7 +35,7 @@ describe('Tracker Service', function () { const retrievedTracker = await this.client.Tracker.retrieve(tracker.id); - expect(retrievedTracker).to.be.an.instanceOf(Tracker); + expect(retrievedTracker.object).to.be.equal('Tracker'); expect(retrievedTracker.id).to.equal(tracker.id); }); @@ -50,7 +49,7 @@ describe('Tracker Service', function () { expect(trackersArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(trackers.has_more).to.exist; trackersArray.forEach((tracker) => { - expect(tracker).to.be.an.instanceOf(Tracker); + expect(tracker.object).to.be.equal('Tracker'); }); }); diff --git a/test/services/user.test.js b/test/services/user.test.js index d538cc919..3ccc7ee6b 100644 --- a/test/services/user.test.js +++ b/test/services/user.test.js @@ -1,12 +1,10 @@ /* eslint-disable no-param-reassign */ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import Brand from '../../src/models/brand'; -import User from '../../src/models/user'; +import EasyPostClient from '../../out/src/easypost'; import * as setupPolly from '../helpers/setup_polly'; import Fixture from '../helpers/fixture'; -import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; +import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; /* eslint-disable func-names */ describe('User Service', function () { @@ -26,7 +24,7 @@ describe('User Service', function () { name: 'Test User', }); - expect(user).to.be.an.instanceOf(User); + expect(user.object).to.be.equal('User'); expect(user.id).to.match(/^user_/); expect(user.name).to.equal('Test User'); @@ -38,14 +36,14 @@ describe('User Service', function () { const user = await this.client.User.retrieve(authenticatedUser.id); - expect(user).to.be.an.instanceOf(User); + expect(user.object).to.be.equal('User'); expect(user.id).to.match(/^user_/); }); it('retrieves the authenticated user', async function () { const user = await this.client.User.retrieveMe(); - expect(user).to.be.an.instanceOf(User); + expect(user.object).to.be.equal('User'); expect(user.id).to.match(/^user_/); }); @@ -57,7 +55,7 @@ describe('User Service', function () { params.name = testName; const updatedUser = await this.client.User.update(user.id, params); - expect(updatedUser).to.be.an.instanceOf(User); + expect(updatedUser.object).to.be.equal('User'); expect(updatedUser.id).to.match(/^user_/); expect(updatedUser.name).to.equal(testName); }); @@ -82,7 +80,7 @@ describe('User Service', function () { const brand = await this.client.User.updateBrand(user.id, { color }); - expect(brand).to.be.an.instanceOf(Brand); + expect(brand.object).to.be.equal('Brand'); expect(brand.id).to.match(/^brd_/); expect(brand.color).to.equal(color); }); @@ -95,7 +93,7 @@ describe('User Service', function () { expect(childrenArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(response.has_more).to.exist; childrenArray.forEach((children) => { - expect(children).to.be.an.instanceOf(User); + expect(children.object).to.be.equal('User'); }); }); diff --git a/test/services/webhook.test.js b/test/services/webhook.test.js index 3d1a1811e..71a9be80b 100644 --- a/test/services/webhook.test.js +++ b/test/services/webhook.test.js @@ -1,9 +1,8 @@ import { expect } from 'chai'; -import EasyPostClient from '../../src/easypost'; -import Webhook from '../../src/models/webhook'; +import EasyPostClient from '../../out/src/easypost'; import Fixture from '../helpers/fixture'; -import SignatureVerificationError from '../../src/errors/general/signature_verification_error'; +import SignatureVerificationError from '../../out/src/errors/general/signature_verification_error'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; @@ -26,7 +25,7 @@ describe('Webhook Service', function () { url: Fixture.webhookUrl(), }); - expect(webhook).to.be.an.instanceOf(Webhook); + expect(webhook.object).to.be.equal('Webhook'); expect(webhook.id).to.match(/^hook_/); expect(webhook.url).to.equal(Fixture.webhookUrl()); @@ -41,7 +40,7 @@ describe('Webhook Service', function () { const retrievedWebhook = await this.client.Webhook.retrieve(webhook.id); - expect(retrievedWebhook).to.be.an.instanceOf(Webhook); + expect(retrievedWebhook.object).to.be.equal('Webhook'); expect(withoutParams(retrievedWebhook)).to.deep.include(withoutParams(webhook)); // Remove the webhook once we have tested it so we don't pollute the account with test webhooks @@ -57,7 +56,7 @@ describe('Webhook Service', function () { expect(webhooksArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); webhooksArray.forEach((webhook) => { - expect(webhook).to.be.an.instanceOf(Webhook); + expect(webhook.object).to.be.equal('Webhook'); }); }); @@ -68,7 +67,7 @@ describe('Webhook Service', function () { const updatedWebhook = await this.client.Webhook.update(webhook.id); - expect(updatedWebhook).to.be.an.instanceOf(Webhook); + expect(updatedWebhook.object).to.be.equal('Webhook'); // Remove the webhook once we have tested it so we don't pollute the account with test webhooks await this.client.Webhook.delete(updatedWebhook.id); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..265b221e0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "esModuleInterop": true, + "strict": true, + "skipLibCheck": true, + "resolveJsonModule": true, + "strictPropertyInitialization": false, + "downlevelIteration": true, + "outDir": "./out" + }, + "include": ["./src"] +} diff --git a/types/.eslintrc b/types/.eslintrc deleted file mode 100644 index bbe18a1d1..000000000 --- a/types/.eslintrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "root": true, - "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint"], - "extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended"], - "rules": { - "no-unused-vars": "off" - } -} diff --git a/types/Address/Address.d.ts b/types/Address/Address.d.ts deleted file mode 100644 index db7f1a008..000000000 --- a/types/Address/Address.d.ts +++ /dev/null @@ -1,192 +0,0 @@ -import { IObjectWithId } from '../base'; -import { DeepPartial } from '../utils'; -import { IAddressCreateParameters } from './AddressCreateParameters'; -import { IVerifications } from './Verifications'; -import { IAddressListParameters } from './AddressListParameters'; - -/** - * Address objects are used to represent people, places, and organizations in a number of contexts. - * For example, a Shipment requires a to_address and from_address to accurately calculate rates and generate postage. - * - * Additionally, EasyPost offers several verification tools that can be used to detect deliverability issues, correct minor errors in spelling/formatting, and determine if an Address is residential or not (which has a significant effect on Shipment rating for many carriers). - * - * @see https://www.easypost.com/docs/api/node#address-object - */ -export declare interface IAddress extends IObjectWithId<'Address'> { - /** - * First line of the address - */ - street1?: string | null; - - /** - * Second line of the address - */ - street2?: string | null; - - /** - * City the address is located in - */ - city?: string | null; - - /** - * State or province the address is located in - */ - state?: string | null; - - /** - * ZIP or postal code the address is located in - */ - zip: string; - - /** - * ISO 3166 country code for the country the address is located in - */ - country: string; - - /** - * Whether or not this address would be considered residential - */ - residential?: boolean | null; - - /** - * The specific designation for the address (only relevant if the address is a carrier facility) - */ - carrier_facility?: string | null; - - /** - * Name of the person. Both name and company can be included - */ - name?: string | null; - - /** - * Name of the organization. Both name and company can be included - */ - company?: string | null; - - /** - * Phone number to reach the person or organization - */ - phone?: string | null; - - /** - * Email to reach the person or organization - */ - email?: string | null; - - /** - * Federal tax identifier of the person or organization - */ - federal_tax_id?: string | null; - - /** - * State tax identifier of the person or organization - */ - state_tax_id?: string | null; - - /** - * The result of any verifications requested - */ - verifications: IVerifications; -} - -export declare class Address implements IAddress { - public constructor(input: DeepPartial); - - id: string; - mode: 'test' | 'production'; - object: 'Address'; - street1?: string | null; - street2?: string | null; - city?: string | null; - state?: string | null; - zip: string; - country: string; - residential?: boolean | null; - carrier_facility?: string | null; - name?: string | null; - company?: string | null; - phone?: string | null; - email?: string | null; - federal_tax_id?: string | null; - state_tax_id?: string | null; - verifications: IVerifications; - - /** - * Create an {@link Address address}. - * @see https://www.easypost.com/docs/api/node#create-an-address - * @param {Object} params - Parameters for the address to be created. - * @returns {Address} - The created address. - */ - static create(params: Object): Promise
; - - /** - * Retrieve a list of all Addresses. - * - * The Address List is a paginated list of all {@link Address} objects associated with the given API Key. - * It accepts a variety of parameters which can be used to modify the scope. - * The has_more attribute indicates whether additional pages can be requested. - * The recommended way of paginating is to use either the `before_id` or `after_id` parameter to specify where the next page begins. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-addresses - * - * @param {Object} params - The parameters to use for the request. - * @returns {Object} - An object containing a list of {@link Address addresses} and pagination information. - */ - static all(params?: IAddressListParameters): Promise<{ addresses: Address[]; has_more: boolean }>; - - /** - * Create and verify a new {@link Address} in one API call. - * - * Verify an {@link Address} - * - Verifying an {@link Address} before you ship is a great way to reduce issues with delivery. - * Creating a verified Address is as simple as including an enumerated list of the verifications you'd like EasyPost to perform in the `verify` or `verify_strict` url parameters. - * If any of the verification checks included in the `verify_strict` list fail an error will be returned from the API. - * The example below demonstrates the most common verification: "delivery", which checks that the address is deliverable and sets its residential delivery indicator. - * - * - The most effective time to perform address verification is when your customer, or the person entering the delivery address, is present. - * When designing a shopping cart it is recommended to ask the shopper for their address and verify it on the spot. - * If verification fails, ask them to double-check their input; if they confirm that their data is correct, assume they know their address more correctly than the verification process. - * - * @see https://www.easypost.com/docs/api/node#create-and-verify-addresses - * - * @param {Object} params The parameters to create an {@link Address} with. - * @returns {Promise
} The created and verified {@link Address}. - */ - static createAndVerify(params: Object): Promise
; - - /** - * Verify an {@link Address}. - * - * @see https://www.easypost.com/docs/api/node#create-and-verify-addresses - * - * @param addressId Unique, begins with "adr_" - * @returns {Promise
} The verified {@link Address}. - */ - static verifyAddress(addressId: string): Promise
; - - /** - * An Address can be retrieved by its id. - * - * @see https://www.easypost.com/docs/api/node#retrieve-an-address - * - * @param addressId Unique, begins with "adr_" - * @returns {Promise
} The verified {@link Address} address. - */ - static retrieve(addressId: string): Promise
; - - /** - * Retrieve the next page of {@link Address addresses}. - * - * This automatically reuses the parameters from the previous call or the original {@link Address.all} call. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-addresses - * - * @param {Object} addresses - The previous page of addresses (the response from the last {@link Address.getNextPage} or {@link Address.all} call). - * @param {number} [pageSize] - The number of addresses to retrieve per page, optional. Defaults to server-side default. - * @returns {Object} - An object containing a list of {@link Address addresses} and pagination information. - */ - static getNextPage( - addresses: Object, - pageSize?: number, - ): Promise<{ addresses: Address[]; has_more: boolean }>; -} diff --git a/types/Address/AddressListParameters.d.ts b/types/Address/AddressListParameters.d.ts deleted file mode 100644 index 23bf72b08..000000000 --- a/types/Address/AddressListParameters.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IAllMethodParameters } from '../utils'; - -/** - * @see https://www.easypost.com/docs/api#retrieve-a-list-of-addresses - */ -export declare interface IAddressListParameters extends IAllMethodParameters {} diff --git a/types/Address/index.d.ts b/types/Address/index.d.ts deleted file mode 100644 index 645d630e4..000000000 --- a/types/Address/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './Address'; -export * from './AddressCreateParameters'; -export * from './Verification'; -export * from './VerificationDetails'; -export * from './Verifications'; diff --git a/types/ApiKey/ApiKey.d.ts b/types/ApiKey/ApiKey.d.ts deleted file mode 100644 index 3d7a0e041..000000000 --- a/types/ApiKey/ApiKey.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { IObjectWithId } from '../base'; -import { DeepPartial } from '../utils'; - -export declare interface IApiKey extends IObjectWithId<'ApiKey'> { - /** - * The actual key value to use for authentication - */ - key: string; - - /** - * When the API key was created - */ - created_at: string; - - /** - * Whether the API key is active or not - */ - active: boolean; -} - -export declare class ApiKey implements IApiKey { - id: string; - mode: 'test' | 'production'; - object: 'ApiKey'; - key: string; - created_at: string; - active: boolean; - - /** - * Both production and test keys will be returned for a User and all of its children. - * If the request is authenticated as a Child, only the API Keys for that Child will be returned. - * - * @see https://www.easypost.com/docs/api/node#retrieve-an-api-key - * - * @param apiKeyId Unique, begins with "user_" - * @returns {Promise} The verified {@link ApiKey}. - */ - static retrieve(apiKeyId: string): Promise; -} diff --git a/types/ApiKey/index.d.ts b/types/ApiKey/index.d.ts deleted file mode 100644 index 3af301f48..000000000 --- a/types/ApiKey/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './ApiKey'; diff --git a/types/Batch/Batch.d.ts b/types/Batch/Batch.d.ts deleted file mode 100644 index 7665ad47c..000000000 --- a/types/Batch/Batch.d.ts +++ /dev/null @@ -1,179 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../base'; -import { IPickup } from '../Pickup'; -import { IScanForm } from '../ScanForm'; -import { LabelFormat } from '../Shipment'; -import { IBatchCreateParameters } from './BatchCreateParameters'; -import { IBatchListParameters } from './BatchListParameters'; -import { IBatchShipment } from './BatchShipment'; -import { TBatchState } from './BatchState'; -import { TBatchStatuses } from './BatchStatuses'; - -/** - * The Batch object allows you to perform operations on multiple Shipments at once. - * This includes scheduling a Pickup, creating a ScanForm and consolidating labels. - * Operations performed on Batches are asynchronous and take advantage of our webhook infrastructure. - * - * @see https://www.easypost.com/docs/api/node#batch-object - */ -export declare interface IBatch extends IObjectWithId<'Batch'>, IDatedObject { - /** - * An optional field that may be used in place of ID in some API endpoints - */ - reference?: string | null; - - /** - * The overall state. Possible values are "creating", "creation_failed", "created", "purchasing", "purchase_failed", "purchased", "label_generating", and "label_generated" - */ - state: TBatchState; - - /** - * The number of shipments added - */ - num_shipments: number; - - /** - * An array of batch shipments - */ - shipments: IBatchShipment[]; - - /** - * A map of BatchShipment statuses to the count of BatchShipments with that status. Valid statuses are "postage_purchased", "postage_purchase_failed", "queued_for_purchase", and "creation_failed" - */ - status: TBatchStatuses; - - /** - * The label image url - */ - label_url?: string | null; - - /** - * The created ScanForm - */ - scan_form: IScanForm; - - /** - * The created Pickup - */ - pickup: IPickup; -} - -export declare class Batch implements IBatch { - public constructor(input: IBatchCreateParameters); - - id: string; - mode: 'test' | 'production'; - object: 'Batch'; - reference?: string | null; - state: TBatchState; - num_shipments: number; - shipments: IBatchShipment[]; - status: TBatchStatuses; - label_url?: string | null; - scan_form: IScanForm; - pickup: IPickup; - created_at: string; - updated_at: string; - - /** - * A Batch can be created with or without Shipments. - * When created with Shipments the initial state will be creating. - * Once the state changes to created a webhook Event will be sent. - * When created with no Shipments the initial state will be created and webhook will be sent. - * - * @see https://www.easypost.com/docs/api/node#create-a-batch - * - * @param {Object} params The parameters to create an {@link Batch} with. - * @returns {Promise} The {@link Batch}. - */ - static create(params: Object): Promise; - - /** - * A Batch can be retrieved by its id. - * - * @see https://www.easypost.com/docs/api/node#retrieve-batch - * - * @param batchId Unique, begins with "batch_" - * - * @returns {Promise} The {@link Batch}. - */ - static retrieve(batchId: string): Promise; - - /** - * Shipments can be added to a Batch throughout its life cycle. - * Just remember that the state change of a Batch is asynchronous and will fire a webhook Event when the state change is completed. - * - * @see https://www.easypost.com/docs/api/node#add-shipments-to-a-batch - * - * @param id Unique, begins with "batch_" - * @param shipments An array of shipments - * - * @returns {Promise} The {@link Batch}. - */ - static addShipments(id: string, shipments: IBatchCreateParameters['shipments']): Promise; - - /** - * There could be times when a Shipment needs to be removed from the Batch during its life cycle. - * Removing a Shipment does not remove it from the consolidated label or ScanForm. - * - * @see https://www.easypost.com/docs/api/node#remove-shipments-from-a-batch - * - * @param id Unique, begins with "batch_" - * @param shipments An array of shipments - * - * @returns {Promise} The {@link Batch}. - */ - static removeShipments( - id: string, - shipments: IBatchCreateParameters['shipments'], - ): Promise; - - /** - * One of the advantages of processing Shipments in batches is the ability to consolidate the PostageLabel into one file. - * This can only be done once for each batch and all Shipments must have a status of postage_purchased. - * - * Available label formats are 'pdf', 'zpl' or 'epl2' format. - * Like converting a PostageLabel format, if this process will change the format of the labels they must have been created as PNGs. - * - * @see https://www.easypost.com/docs/api/node#batch-labels - * - * @param id Unique, begins with "batch_" - * @param labelFormat The format of label - * - * @returns {Promise} The {@link Batch}. - */ - static generateLabel(id: string, labelFormat: LabelFormat): Promise; - - /** - * See [Scan Form](https://www.easypost.com/docs/api/node#scan-form) rules and [Object Definition](https://www.easypost.com/docs/api/node#scan-form-object). - * - * @see https://www.easypost.com/docs/api/node#manifesting-scan-form - * - * @param id Unique, begins with "batch_" - * - * @returns {Promise} The {@link Batch}. - */ - static createScanForm(id: string): Promise; - - /** - * Once you have added all of your Shipments to a Batch, issue a buy request to enqueue a background job to purchase the shipments and generate all necessary labels. - * Purchasing may take anywhere from a few seconds to an hour, depending on the size of the batch, the carrier, and Internet weather. - * - * @see https://www.easypost.com/docs/api/node#buy-a-batch - * - * @param id Unique, begins with "batch_" - * @returns {Promise} The {@link Batch}. - */ - static buy(id: string): Promise; - - /** - * The Batch List is a paginated list of all Batch objects associated with the given API Key. - * See the Pagination section of our docs for more details on retrieving all records when - * multiple pages are available. - * - * @see https://www.easypost.com/docs/api/node#list-all-batches - * - * @param {Object} params - The parameters to use for the request. - * @returns {Object} - An object containing a list of {@link Batch batches} and pagination information. - */ - static all(params?: IBatchListParameters): Promise<{ batches: Batch[]; has_more: boolean }>; -} diff --git a/types/Batch/BatchCreateParameters.d.ts b/types/Batch/BatchCreateParameters.d.ts deleted file mode 100644 index 92849b98e..000000000 --- a/types/Batch/BatchCreateParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Shipment } from '../Shipment'; - -export declare interface IBatchCreateParameters { - shipments?: Array; -} diff --git a/types/Batch/BatchListParameters.d.ts b/types/Batch/BatchListParameters.d.ts deleted file mode 100644 index 74cbdcfe6..000000000 --- a/types/Batch/BatchListParameters.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IAllMethodParameters } from '../utils'; - -/** - * @see https://www.easypost.com/docs/api/node#list-all-batches - */ -export declare interface IBatchListParameters extends IAllMethodParameters {} diff --git a/types/Batch/BatchState.d.ts b/types/Batch/BatchState.d.ts deleted file mode 100644 index 7de25d436..000000000 --- a/types/Batch/BatchState.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -export declare type TBatchState = - | 'creating' - | 'creation_failed' - | 'created' - | 'purchasing' - | 'purchase_failed' - | 'purchased' - | 'label_generating' - | 'label_generated'; diff --git a/types/Batch/BatchStatus.d.ts b/types/Batch/BatchStatus.d.ts deleted file mode 100644 index ecd5eb553..000000000 --- a/types/Batch/BatchStatus.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export declare type TBatchStatus = - | 'postage_purchased' - | 'postage_purchase_failed' - | 'queued_for_purchase' - | 'creation_failed' - | 'created'; diff --git a/types/Batch/BatchStatuses.d.ts b/types/Batch/BatchStatuses.d.ts deleted file mode 100644 index 24e6470ca..000000000 --- a/types/Batch/BatchStatuses.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { TBatchStatus } from './BatchStatus'; - -export declare type TBatchStatuses = { [key in TBatchStatus]: number }; diff --git a/types/Batch/index.d.ts b/types/Batch/index.d.ts deleted file mode 100644 index 00cf085aa..000000000 --- a/types/Batch/index.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from './Batch'; -export * from './BatchState'; -export * from './BatchStatus'; -export * from './BatchStatuses'; -export * from './BatchShipment'; -export * from './BatchCreateParameters'; diff --git a/types/Billing/Billing.d.ts b/types/Billing/Billing.d.ts deleted file mode 100644 index 2e71f8a7b..000000000 --- a/types/Billing/Billing.d.ts +++ /dev/null @@ -1,35 +0,0 @@ -/** - * The Billing class allow you to fund wallet by using primary or secondary payment method, - * delete a existing payment method, and retrieve all payment methods associated to the user. - * - * @see https://www.easypost.com/docs/api/node#billing - */ -export declare class Billing { - /** - * Fund your EasyPost wallet by charging your primary or secondary payment method on file. - * - * @see https://www.easypost.com/docs/api/node#add-funds-to-your-wallet-one-time-charge - * @requires production API Key. - * - * @param amount Amount in cents to be deposited into the user's wallet. Amount must be greater than or equal to the user's current balance. - * @param priority The payment method from your account, either primary or secondary. - */ - static fundWallet(amount: string, priority?: string): void; - - /** - * Delete a payment method from your account. - * @see https://www.easypost.com/docs/api/node#delete-a-payment-method - * @requires production API Key. - * - * @param priority The payment method from your account, either primary or secondary. - */ - static deletePaymentMethod(priority: string): void; - - /** - * Retrieve all payment methods. - * - * @see https://www.easypost.com/docs/api/node#retrieve-payment-methods - * @requires production API Key. - */ - static retrievePaymentMethods(): object; -} diff --git a/types/Billing/index.d.ts b/types/Billing/index.d.ts deleted file mode 100644 index 6da3db555..000000000 --- a/types/Billing/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './Billing'; diff --git a/types/Brand/index.d.ts b/types/Brand/index.d.ts deleted file mode 100644 index 731d929af..000000000 --- a/types/Brand/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './Brand'; diff --git a/types/Carrier/CarrierAccount/CarrierAccount.d.ts b/types/Carrier/CarrierAccount/CarrierAccount.d.ts deleted file mode 100644 index 478ceaeec..000000000 --- a/types/Carrier/CarrierAccount/CarrierAccount.d.ts +++ /dev/null @@ -1,139 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../base'; -import { DeepPartial } from '../../utils'; -import { ICarrierAccountCreateParameters } from './CarrierAccountCreateParameters'; -import { ICarrierAccountFields } from './CarrierAccountFields'; - -/** - * A CarrierAccount encapsulates your credentials with the carrier. - * The CarrierAccount object provides CRUD operations for all CarrierAccounts. - * - * Each EasyPost account is automatically provided a USPS account managed by EasyPost. - * - * Other operations, such as Shipment creation, can reference CarrierAccounts to reduce the scope of data returned. - * For instance, you may have multiple warehouses that need to use distinct FedEx SmartPost credentials to request the correct rates. - * Rate objects will include a `carrier_account_id` field which can be used to determine the account used for rating. - * - * @see https://www.easypost.com/docs/api/node#carrier-account-object - */ -export declare interface ICarrierAccount extends IObjectWithId<'CarrierAccount'>, IDatedObject { - /** - * The name of the carrier type. - */ - type: string; - - /** - * Contains "credentials" and/or "test_credentials", or may be empty - */ - fields: ICarrierAccountFields; - - /** - * If clone is true, only the reference and description are possible to update - */ - clone?: boolean | null; - - /** - * An optional, user-readable field to help distinguish accounts - */ - description?: string | null; - - /** - * An optional field that may be used in place of carrier_account_id in other API endpoints - */ - reference?: string | null; - - /** - * The name used when displaying a readable value for the type of the account - */ - readable: string; - - /** - * Unlike the "credentials" object contained in "fields", this nullable object contains just raw credential pairs for client library consumption - */ - credentials?: object | null; - - /** - * Unlike the "test_credentials" object contained in "fields", this nullable object contains just raw test_credential pairs for client library consumption - */ - test_credentials?: object | null; - - /** - * Billing type of the carrier account - */ - billing_type: string | null; -} - -export declare class CarrierAccount implements ICarrierAccount { - public constructor(input: DeepPartial); - - id: string; - mode: 'test' | 'production'; - object: 'CarrierAccount'; - type: string; - fields: ICarrierAccountFields; - clone?: boolean | null; - description?: string | null; - reference?: string | null; - readable: string; - credentials?: object | null; - test_credentials?: object | null; - billing_type: string | null; - created_at: string; - updated_at: string; - - /** - * CarrierAccount objects may be managed through the EasyPost API using the Production mode API key only. - * Multiple accounts can be added for a single carrier. - * - * The CarrierType of the preferred CarrierAccount should be consulted before attempting to create a new CarrierAccount, as it will inform you of the field names expected by a certain carrier. - * - * @see https://www.easypost.com/docs/api/node#create-a-carrier-account - * @requires production API Key. - * - * @param {Object} params The parameters to create an {@link CarrierAccount} with - * @returns {Promise} The created and verified {@link CarrierAccount}. - */ - static create(params: Object): Promise; - - /** - * @see https://www.easypost.com/docs/api/node#update-a-carrieraccount - * - * @param carrierAccountId Unique, begins with "ca_" - * @param {Object} params The parameters to create an {@link CarrierAccount} with - * @returns {Promise} The created and verified {@link CarrierAccount}. - */ - static update(carrierAccountId: string, params: Object): Promise; - - /** - * Retrieve an unpaginated list of all CarrierAccounts available to the authenticated account. - * Only Production API keys may be used to retrieve this list, as there is no test mode equivalent. - * - * @see https://www.easypost.com/docs/api/node#list-all-carrier-accounts - * @requires production API Key. - * - * @returns {Object} - An object containing a list of {@link CarrierAccount carrier accounts}. - */ - static all(): Promise; - - /** - * Retrieve a CarrierAccount by either its id or reference. - * However it is recommended to use EasyPost's provided identifiers because we do not enforce a unique reference. - * - * @param carrierAccountId Unique, begins with "ca_" - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-carrieraccount - * @requires production API Key. - * - * @returns {Promise} The {@link CarrierAccount} object. - */ - static retrieve(carrierAccountId: string): Promise; - - /** - * CarrierAccount objects may be removed from your account when they become out of date or no longer useful. - * - * @see https://www.easypost.com/docs/api/node#delete-a-carrier-account - * @requires production API Key. - * - * @param carrierAccountId Unique, begins with "ca_" - */ - static delete(carrierAccountId: string): void; -} diff --git a/types/Carrier/CarrierAccount/CarrierAccountCreateParameters.d.ts b/types/Carrier/CarrierAccount/CarrierAccountCreateParameters.d.ts deleted file mode 100644 index 53975e1c5..000000000 --- a/types/Carrier/CarrierAccount/CarrierAccountCreateParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils'; -import { ICarrierAccount } from './CarrierAccount'; - -export declare interface ICarrierAccountCreateParameters - extends Omit {} diff --git a/types/Carrier/CarrierAccount/index.d.ts b/types/Carrier/CarrierAccount/index.d.ts deleted file mode 100644 index 054b8b901..000000000 --- a/types/Carrier/CarrierAccount/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './CarrierAccount'; -export * from './CarrierAccountFields'; -export * from './CarrierAccountField'; -export * from './CarrierAccountCreateParameters'; diff --git a/types/Carrier/CarrierMetadata/index.d.ts b/types/Carrier/CarrierMetadata/index.d.ts deleted file mode 100644 index 109e687de..000000000 --- a/types/Carrier/CarrierMetadata/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './CarrierMetadata'; diff --git a/types/Carrier/CarrierType/index.d.ts b/types/Carrier/CarrierType/index.d.ts deleted file mode 100644 index 58e4783b4..000000000 --- a/types/Carrier/CarrierType/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './CarrierType'; -export * from './CarrierTypeFields'; -export * from './CarrierTypeCredentials'; diff --git a/types/Carrier/index.d.ts b/types/Carrier/index.d.ts deleted file mode 100644 index 8a86777f2..000000000 --- a/types/Carrier/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './CarrierAccount'; -export * from './CarrierMetadata'; -export * from './CarrierType'; diff --git a/types/Customs/CustomsInfo/CustomsInfo.d.ts b/types/Customs/CustomsInfo/CustomsInfo.d.ts deleted file mode 100644 index 353dfae7f..000000000 --- a/types/Customs/CustomsInfo/CustomsInfo.d.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../base'; -import { DeepPartial } from '../../utils'; -import { ICustomsItem } from '../CustomsItem/CustomsItem'; -import { ICustomsInfoCreateParameters } from './CustomsInfoCreateParameters'; - -/** - * CustomsInfo objects contain CustomsItem objects and all necessary information for the generation of customs forms required for international shipping. - * - * Please see the Shipments documentation for examples of including a CustomsInfo object in a shipment. - * - * @see https://www.easypost.com/docs/api/node#customs-info-object - */ -export declare interface ICustomsInfo extends IObjectWithId<'CustomsInfo'>, IDatedObject { - /** - * "EEL" or "PFC" - * value less than $2500: "NOEEI 30.37(a)" - * value greater than $2500: see [Customs Guide](https://www.easypost.com/customs-guide) - */ - eel_pfc?: string | null; - - /** - * "documents", "gift", "merchandise", "returned_goods", "sample", or "other" - */ - contents_type?: string | null; - - /** - * (max 255 characters) Human readable description of content. - * Required for certain carriers and always required if contents_type is "other" - */ - contents_explanation?: string | null; - - /** - * Electronically certify the information provided - */ - customs_certify?: boolean | null; - - /** - * Required if customs_certify is true - */ - customs_signer?: string | null; - - /** - * "abandon" or "return", defaults to "return" - */ - non_delivery_option?: 'abandon' | 'return' | null; - - /** - * "none", "other", "quarantine", or "sanitary_phytosanitary_inspection" - */ - restriction_type?: 'none' | 'other' | 'quarantine' | 'sanitary_phytosanitary_inspection' | null; - - /** - * Required if restriction_type is not "none" - */ - restriction_comments?: string | null; - - /** - * Describes the products being shipped - */ - customs_items: ICustomsItem[]; - - /** - * A customs declaration message, available for eligible carriers - */ - declaration?: string | null; -} - -export declare class CustomsInfo implements ICustomsInfo { - public constructor(input: DeepPartial); - - id: string; - mode: 'test' | 'production'; - object: 'CustomsInfo'; - eel_pfc?: string | null; - contents_type?: string | null; - contents_explanation?: string | null; - customs_certify?: boolean | null; - customs_signer?: string | null; - non_delivery_option?: 'abandon' | 'return' | null; - restriction_type?: 'none' | 'other' | 'quarantine' | 'sanitary_phytosanitary_inspection' | null; - restriction_comments?: string | null; - customs_items: ICustomsItem[]; - declaration?: string | null; - created_at: string; - updated_at: string; - - /** - * A CustomsInfo object contains all administrative information for processing customs, as well as a list of CustomsItems. When creating a CustomsInfo, you may store the ID from the response for use later in shipment creation. - * - * @see https://www.easypost.com/docs/api#create-a-customs-info - * - * @param {Object} params The parameters to create an {@link CustomsInfo} with. - * @returns {Promise} The {@link CustomsInfo}. - */ - static create(params: Object): Promise; - - /** - * A CustomsInfo can be retrieved by its id. - * - * @param CustomsInfoId Unique, begins with "cstinfo_" - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-customs-info - * - * @returns {Promise} The {@link CustomsInfo}. - */ - static retrieve(CustomsInfoId: string): Promise; -} diff --git a/types/Customs/CustomsInfo/CustomsInfoCreateParameters.d.ts b/types/Customs/CustomsInfo/CustomsInfoCreateParameters.d.ts deleted file mode 100644 index 3e0063905..000000000 --- a/types/Customs/CustomsInfo/CustomsInfoCreateParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils'; -import { ICustomsInfo } from './CustomsInfo'; - -export declare interface ICustomsInfoCreateParameters - extends Omit {} diff --git a/types/Customs/CustomsInfo/index.d.ts b/types/Customs/CustomsInfo/index.d.ts deleted file mode 100644 index 2f558baf3..000000000 --- a/types/Customs/CustomsInfo/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './CustomsInfo'; diff --git a/types/Customs/CustomsItem/CustomsItem.d.ts b/types/Customs/CustomsItem/CustomsItem.d.ts deleted file mode 100644 index f81a258f8..000000000 --- a/types/Customs/CustomsItem/CustomsItem.d.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../base'; -import { DeepPartial } from '../../utils'; -import { ICustomsItemCreateParameters } from './CustomsItemCreateParameters'; - -/** - * A CustomsItem object describes goods for international shipment and should be created then included in a CustomsInfo object. - * - * @see https://www.easypost.com/docs/api/node#customs-item-object - */ -export declare interface ICustomsItem extends IObjectWithId<'CustomsItem'>, IDatedObject { - /** - * Required, description of item being shipped - */ - description: string; - - /** - * Required, greater than zero - * float - */ - quantity: number; - - /** - * Required, greater than zero, total value (unit value * quantity) - * float (USD) - */ - value: number; - - /** - * Required, greater than zero, total weight (unit weight * quantity) - * float (oz) - */ - weight: number; - - /** - * Harmonized Tariff Schedule, e.g. "6109.10.0012" for Men's T-shirts - * - * @see https://hts.usitc.gov/ - */ - hs_tariff_number?: string | null; - - /** - * SKU/UPC or other product identifier - */ - code?: string | null; - - /** - * Required, 2 char country code - */ - origin_country: string; - - /** - * 3 char currency code, default USD - */ - currency?: string | null; -} - -export declare class CustomsItem implements ICustomsItem { - public constructor(input: DeepPartial); - - id: string; - mode: 'test' | 'production'; - object: 'CustomsItem'; - description: string; - quantity: number; - value: number; - weight: number; - hs_tariff_number?: string | null; - code?: string | null; - origin_country: string; - currency?: string | null; - created_at: string; - updated_at: string; - - /** - * A CustomsItem contains information relating to each product within the package. When creating a customs item, you may store the ID from the response for use later in CustomsInfo creation. - * - * @see https://www.easypost.com/docs/api#create-a-customs-item - * - * @param {Object} params The parameters to create an {@link CustomsItem} with. - * @returns {Promise} The {@link CustomsItem}. - */ - static create(params: Object): Promise; - - /** - * A CustomsItem can be retrieved by its id. - * - * @param CustomsItemId Unique, begins with "cstitem_" - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-customs-item - * - * @returns {Promise} The {@link CustomsItem}. - */ - static retrieve(CustomsItemId: string): Promise; -} diff --git a/types/Customs/CustomsItem/CustomsItemCreateParameters.d.ts b/types/Customs/CustomsItem/CustomsItemCreateParameters.d.ts deleted file mode 100644 index 220fb5f9b..000000000 --- a/types/Customs/CustomsItem/CustomsItemCreateParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils'; -import { ICustomsItem } from './CustomsItem'; - -export declare interface ICustomsItemCreateParameters - extends Omit {} diff --git a/types/Customs/CustomsItem/index.d.ts b/types/Customs/CustomsItem/index.d.ts deleted file mode 100644 index 38bfcd6b0..000000000 --- a/types/Customs/CustomsItem/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './CustomsItem'; diff --git a/types/Customs/index.d.ts b/types/Customs/index.d.ts deleted file mode 100644 index f1640b6d8..000000000 --- a/types/Customs/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './CustomsInfo'; -export * from './CustomsItem'; diff --git a/types/EasyPost.d.ts b/types/EasyPost.d.ts deleted file mode 100644 index 9f131c9d9..000000000 --- a/types/EasyPost.d.ts +++ /dev/null @@ -1,127 +0,0 @@ -import { Address } from './Address'; -import { ApiKey } from './ApiKey'; -import { Batch } from './Batch'; -import { Billing } from './Billing'; -import { Brand } from './Brand'; -import { CarrierAccount, CarrierMetadata, CarrierType } from './Carrier'; -import { CustomsInfo, CustomsItem } from './Customs'; -import { EndShipper } from './EndShipper'; -import { Event } from './Event'; -import { Fee } from './Fee'; -import { Insurance } from './Insurance'; -import { Order } from './Order'; -import { Parcel } from './Parcel'; -import { PaymentMethod } from './PaymentMethod'; -import { Pickup } from './Pickup'; -import { Rate } from './Rate'; -import { Referral } from './Referral'; -import { Refund } from './Refund'; -import { Report } from './Report'; -import { ScanForm } from './ScanForm'; -import { Shipment } from './Shipment'; -import { Tracker } from './Tracker'; -import { User } from './User'; -import { Utils } from './Utility'; -import { Webhook } from './Webhook'; - -export interface IEasyPostRequest { - method: 'get' | 'post' | 'put' | 'patch' | 'del'; - path: string; - requestBody: any; - headers: Record; - requestTimestamp: number; - requestUUID: string; -} -export interface IEasyPostResponse extends IEasyPostRequest { - httpStatus: number; - responseBody: any; - responseTimestamp: number; -} - -export interface IEasyPostOptions { - /** - * Time in milliseconds that should fail requests. - */ - timeout?: number; - - /** - * Change the base URL that the API library uses. Useful if you proxy requests from a frontend through a server. - * @example https://api.easypost.com/v2/ - */ - baseUrl?: string; - - /** - * Disable using the API key. Useful if you proxy requests from a frontend through a server. - */ - useProxy?: boolean; - - /** - * Function that takes `superagent` and returns `superagent`. - * Useful if you need to wrap superagent in a function, such as many superagent libraries do. - */ - superagentMiddleware?: (agent: any) => any; - - /** - * Function that takes a superagent `request` and returns that request. - * Useful if you need to hook into a request: - */ - requestMiddleware?: (request: any) => any; -} - -export default class EasyPost { - public Address: typeof Address; - public ApiKey: typeof ApiKey; - public Batch: typeof Batch; - public Billing: typeof Billing; - public Brand: typeof Brand; - public CarrierAccount: typeof CarrierAccount; - public CarrierMetadata: typeof CarrierMetadata; - public CarrierType: typeof CarrierType; - public CustomsInfo: typeof CustomsInfo; - public CustomsItem: typeof CustomsItem; - public EndShipper: typeof EndShipper; - public Event: typeof Event; - public Fee: typeof Fee; // TODO: Fix IFee - public Insurance: typeof Insurance; - public Order: typeof Order; - public Parcel: typeof Parcel; - public PaymentMethod: typeof PaymentMethod; - public Pickup: typeof Pickup; - public Rate: typeof Rate; - public Referral: typeof Referral; - public Refund: typeof Refund; - public Report: typeof Report; - public ScanForm: typeof ScanForm; - public Shipment: typeof Shipment; - public Tracker: typeof Tracker; - public User: typeof User; - public Utils: typeof Utils; - public Webhook: typeof Webhook; - - public constructor(apiKey: string, options?: IEasyPostOptions); - - /** - * Adds a request hook to the EasyPost client. Useful for logging or debugging. - */ - public addRequestHook(fn: (config: IEasyPostRequest) => void): void; - /** - * Removes a request hook from the EasyPost client. - */ - public removeRequestHook(fn: (config: IEasyPostRequest) => void): void; - /** - * Clears all request hooks from the EasyPost client. - */ - public clearRequestHooks(): void; - /** - * Adds a response hook to the EasyPost client. Useful for logging or debugging. - */ - public addResponseHook(fn: (config: IEasyPostResponse) => void): void; - /** - * Removes a response hook from the EasyPost client. - */ - public removeResponseHook(fn: (config: IEasyPostResponse) => void): void; - /** - * Clears all response hooks from the EasyPost client. - */ - public clearResponseHooks(): void; -} diff --git a/types/EndShipper/EndShipper.d.ts b/types/EndShipper/EndShipper.d.ts deleted file mode 100644 index ffc020930..000000000 --- a/types/EndShipper/EndShipper.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -import { IObjectWithId } from '../base'; -import { DeepPartial } from '../utils'; -import { IEndShipperCreateParameters } from './EndShipperCreateParameters'; -import { IEndShipperListParameters } from './EndShipperListParameters'; - -/** - * The EndShipper API is for platforms purchasing postage on behalf of their users, the EndShipper. - * Platforms must assert the EndShipper details, as the EndShipper is ultimately responsible for what is in the box. - * Multiple labels purchased for the same EndShipper must use the same EndShipper identity (API object). - * EndShipper objects must be created prior to buying a Shipment. Once EndShipper objects have been created, - * you must keep track of their public id in order to use them during a label buy. - * - * @see https://www.easypost.com/docs/api/node#endshipper - */ -export declare interface IEndshipper extends IObjectWithId<'EndShipper'> { - /** - * Name of responsible person (conditionally required) - */ - name?: string | null; - - /** - * Name of responsible company (conditionally required) - */ - company?: string | null; - - /** - * First line of the address - */ - street1?: string | null; - - /** - * Second line of the address - */ - street2?: string | null; - - /** - * City the address is located in - */ - city?: string | null; - - /** - * State or province the address is located in - */ - state?: string | null; - - /** - * ZIP or postal code the address is located in - */ - zip: string; - - /** - * ISO 3166 country code for the country the address is located in - */ - country?: string; - - /** - * Phone number to reach the person or organization - */ - phone?: string | null; - - /** - * Email to reach the person or organization - */ - email?: string | null; -} - -export declare class EndShipper implements IEndshipper { - public constructor(input: DeepPartial); - id: string; - mode: 'test' | 'production'; - object: 'EndShipper'; - street1?: string | null; - street2?: string | null; - city?: string | null; - state?: string | null; - zip: string; - country: string; - name?: string | null; - company?: string | null; - phone?: string | null; - email?: string | null; - - /** - * The EndShipper object is meant to represent the person or business entity responsible for the - * shipment and not necessarily the shipping location. - * EndShipper objects are fully-qualified Address objects and require every field to be filled with two exceptions: - * name and company fields. At least one of these fields must be filled (when both are present, name will take precedence). - * street2 field. This fieldcan be empty if the address does not include multiple lines. - * - * @see https://www.easypost.com/docs/api/node#create-an-endshipper - * - * @param {Object} params The parameters to create an {@link EndShipper} with. - * @returns {Promise} The created and verified {@link EndShipper}. - */ - static create(params: Object): Promise; - - /** - * An EndShipper object may be updated using the EndShipper API. - * All required fields for creating an EndShipper are required in an update request. Partial updates are not supported. - * - * @see https://www.easypost.com/docs/api/node#update-an-endshipper - * - * @param id Unique, start with "es_". - * @param params The parameters to update an {@link EndShipper} with. - * @returns {Promise} The updated {@link EndShipper}. - */ - static update(id: string, params: Object): Promise; - - /** - * Similar to retrieving a list of EndShippers, you can retrieve an individual EndShipper. - * - * @see https://www.easypost.com/docs/api/node#retrieve-an-endshipper - * - * @param id Unique, start with "es_". - * @returns {Promise} The retrieved {@link EndShipper}. - */ - static retrieve(id: string): Promise; - - /** - * List the EndShippers that have been created. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-endshippers - * - * @param params - The parameters to use for the request. - * @returns {Object} - An object containing a list of {@link EndShipper endshippers} and pagination information. - */ - static all( - params: IEndShipperListParameters, - ): Promise<{ endshippers: EndShipper[]; has_more: boolean }>; -} diff --git a/types/EndShipper/EndShipperCreateParameters.d.ts b/types/EndShipper/EndShipperCreateParameters.d.ts deleted file mode 100644 index 30662caea..000000000 --- a/types/EndShipper/EndShipperCreateParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ParametersToOmitOnCreate } from '../utils'; -import { IEndshipper } from './EndShipper'; - -export declare interface IEndShipperCreateParameters - extends Omit {} diff --git a/types/EndShipper/EndShipperListParameters.d.ts b/types/EndShipper/EndShipperListParameters.d.ts deleted file mode 100644 index 43720d66c..000000000 --- a/types/EndShipper/EndShipperListParameters.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IAllMethodParameters } from '../utils'; - -/** - * @see https://www.easypost.com/docs/api#endshipper - */ -export declare interface IEndShipperListParameters extends IAllMethodParameters {} diff --git a/types/EndShipper/index.d.ts b/types/EndShipper/index.d.ts deleted file mode 100644 index 8cccc97ed..000000000 --- a/types/EndShipper/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './EndShipper'; -export * from './EndShipperCreateParameters'; diff --git a/types/Event/Event.d.ts b/types/Event/Event.d.ts deleted file mode 100644 index 32786466c..000000000 --- a/types/Event/Event.d.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../base'; -import { IEventListParameters } from './EventListParameters'; - -/** - * Webhook Events are triggered by changes in objects you've created via the API. - * Every time an Event related to one of your objects is created, EasyPost guarantees at least one POST request will be sent to each of the webhook URLs set up for your account. - * For this reason, we strongly encourage your webhook handler to be idempotent. - * See the webhooks guide for more information. - * - * @see https://www.easypost.com/docs/api/node#events - */ -export declare interface IEvent extends IObjectWithId<'Event'>, IDatedObject { - /** - * Result type and event name, see the "Possible Event Types" section for more information - */ - description: string; - - /** - * Previous values of relevant result attributes - */ - previous_attributes: any; - - /** - * The object associated with the Event. See the "object" attribute on the result to determine its specific type. - * This field will not be returned when retrieving events directly from the API - */ - result: any; - - /** - * The current status of the event. Possible values are "completed", "failed", "in_queue", "retrying", or "pending" (deprecated) - * - * @deprecated - */ - status: 'completed' | 'failed' | 'in_queue' | 'retrying' | 'pending'; - - /** - * Webhook URLs that have not yet been successfully notified as of the time this webhook event was sent. - * The URL receiving the Event will still be listed in pending_urls, as will any other URLs that receive the Event at the same time - */ - pending_urls: string[]; - - /** - * Webhook URLs that have already been successfully notified as of the time this webhook was sent - */ - completed_urls: string[]; -} - -export declare class Event implements IEvent { - id: string; - mode: 'test' | 'production'; - object: 'Event'; - description: string; - previous_attributes: any; - result: any; - status: 'completed' | 'failed' | 'in_queue' | 'retrying' | 'pending'; - pending_urls: string[]; - completed_urls: string[]; - created_at: string; - updated_at: string; - - /** - * Events can be retrieved by their ID. - * - * @param eventId the ID of the event object. - * @returns {Promise} The retrieved {@link Event}. - */ - static retrieve(eventId: string): Promise; - - /** - * Retrieve all event objects. - * - * @param {Object} params - The parameters to use for the request. - * @returns {Object} - An object containing a list of {@link Event events} and pagination information. - */ - static all(params: IEventListParameters): Promise<{ events: Event[]; has_more: boolean }>; - - /** - * Retrieve the next page of {@link Event events}. - * - * This automatically reuses the parameters from the previous call or the original {@link Event.all} call. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-events - * - * @param {Object} events - The previous page of events (the response from the last {@link Event.getNextPage} or {@link Event.all} call). - * @param {number} [pageSize] - The number of events to retrieve per page, optional. Defaults to server-side default. - * @returns {Object} - An object containing a list of {@link Event events} and pagination information. - */ - static getNextPage( - events: Object, - pageSize?: number, - ): Promise<{ events: Event[]; has_more: boolean }>; -} diff --git a/types/Event/EventListParameters.d.ts b/types/Event/EventListParameters.d.ts deleted file mode 100644 index cce9b08c0..000000000 --- a/types/Event/EventListParameters.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IAllMethodParameters } from '../utils'; - -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-events - */ -export declare interface IEventListParameters extends IAllMethodParameters {} diff --git a/types/Event/Payload/Payload.d.ts b/types/Event/Payload/Payload.d.ts deleted file mode 100644 index 2155c8425..000000000 --- a/types/Event/Payload/Payload.d.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../base'; -import { IPayloadListParameters } from './PayloadListParameters'; - -/** - * A Payload represents an attempt by EasyPost to send an Event to a Webhook. - * An Event can have multiple Payloads. For instance, if there is a failure to deliver a Webhook, - * an Event would have multiple payloads, one for each attempt to deliver the Event to the Webhook. - * Payload can be useful for debugging webhook delivery and when initially setting up EasyPost webhooks. - */ -export declare interface IPayload extends IObjectWithId<'Payload'>, IDatedObject { - /** - * The body of the Payload response - */ - response_body: string | null; -} - -export declare class Payload implements IPayload { - id: string; - mode: 'test' | 'production'; - object: 'Payload'; - response_body: string; - created_at: string; - updated_at: string; - - /** - * Payload can be retrieved by their ID. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-payload - * - * @param eventId the ID of the event object. - * @param payloadId the ID of the payload. - * @returns {Promise} The retrieved {@link Payload payload}. - */ - static retrieve(eventId: string, payloadId: string): Promise; - - /** - * Retrieve all payload objects. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads - * - * @param params - The parameters to use for the request. - * @returns {Object} - An object containing a list of {@link Payload payloads} and pagination information. - */ - static all(params: IPayloadListParameters): Promise<{ payloads: Payload[] }>; -} diff --git a/types/Event/Payload/PayloadListParameters.d.ts b/types/Event/Payload/PayloadListParameters.d.ts deleted file mode 100644 index 572af796d..000000000 --- a/types/Event/Payload/PayloadListParameters.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IAllMethodParameters } from '../../utils'; - -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads - */ -export declare interface IPayloadListParameters extends IAllMethodParameters {} diff --git a/types/Event/Payload/index.d.ts b/types/Event/Payload/index.d.ts deleted file mode 100644 index b1fd98702..000000000 --- a/types/Event/Payload/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './Payload'; diff --git a/types/Event/index.d.ts b/types/Event/index.d.ts deleted file mode 100644 index e59a11981..000000000 --- a/types/Event/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './Event'; diff --git a/types/Fee/FeeType.d.ts b/types/Fee/FeeType.d.ts deleted file mode 100644 index 04fe55530..000000000 --- a/types/Fee/FeeType.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare type TFeeType = 'InsuranceFee' | 'LabelFee' | 'PostageFee' | 'TrackerFee'; diff --git a/types/Fee/index.d.ts b/types/Fee/index.d.ts deleted file mode 100644 index bcaf739f4..000000000 --- a/types/Fee/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './Fee'; -export * from './FeeType'; diff --git a/types/Insurance/Insurance.d.ts b/types/Insurance/Insurance.d.ts deleted file mode 100644 index e3ae9e1e5..000000000 --- a/types/Insurance/Insurance.d.ts +++ /dev/null @@ -1,174 +0,0 @@ -import { IAddress } from '../Address'; -import { IDatedObject, IObjectWithId } from '../base'; -import { IFee } from '../Fee'; -import { ITracker } from '../Tracker'; -import { IAllMethodParameters } from '../utils'; -import { IInsuranceCreateParameters } from './InsuranceCreateParameters'; -import { TInsuranceStatus } from './InsuranceStatus'; - -/** - * An Insurance object represents insurance for packages purchased both via the EasyPost API as well as shipments purchased through third parties and later registered with EasyPost. - * An Insurance is created automatically whenever you buy a Shipment through EasyPost and pass insurance options during the Buy call or in a later call to Insure a Shipment. - * - * Insurance purchased through the Shipment Buy or Insure endpoints is immediately insured - there is no possibility of rejection based on tracking information, as the package was just created. - * On the other hand, Insurance purchased on shipments purchased outside of EasyPost requires creation with a tracking code so that EasyPost may confirm the package existence and current shipping status at the time of purchase. - * - * Standalone insurance is created in a pending state to help distinguish it from insurance purchased for an EasyPost Shipment. - * Both kinds of Insurance use the Tracking system to receive periodic updates, and will report those updates to any appropriate Webhooks on file. - * Standalone insurance will cancel itself if the tracking information for the given tracking code shows evidence of having been shipped anytime before the insurance was purchased. - * - * Unlike Shipments within EasyPost, Insurance objects register To and From Address objects according to the destination and ship-from locations of the package. - * This means that a Shipment with "is_return: true" actually ships to the listed From Address. - * Insurance does not have a concept of "is_return", so all insurance records refer to their true package destination as "to_address", regardless of whether or not the shipment is a return. - * - * @see https://www.easypost.com/docs/api/node#insurance-object - */ -export declare interface IInsurance extends IObjectWithId<'Insurance'>, IDatedObject { - /** - * The unique reference for this Insurance, if any - */ - reference?: string | null; - - /** - * USD value of insured goods with sub-cent precision - */ - amount: string; - - /** - * The insurance provider used by EasyPost - */ - provider: string; - - /** - * An identifying number for some insurance providers used by EasyPost - */ - provider_id: string; - - /** - * The ID of the Shipment in EasyPost, if postage was purchased via EasyPost - */ - shipment_id: string; - - /** - * The tracking code of either the shipment within EasyPost, or provided by you during creation - */ - tracking_code: string; - - /** - * The current status of the insurance, possible values are "new", "pending", "purchased", "failed", or "cancelled" - */ - status: TInsuranceStatus; - - /** - * The associated Tracker object - */ - tracker: ITracker; - - /** - * The associated Address object for destination - */ - to_address: IAddress; - - /** - * The associated Address object for origin - */ - from_address: IAddress; - - /** - * The associated InsuranceFee object if any - */ - fee: IFee; - - /** - * The list of errors encountered during attempted purchase of the insurance - */ - messages: string[]; -} - -export declare class Insurance implements IInsurance { - public constructor(input: IInsuranceCreateParameters); - - id: string; - mode: 'test' | 'production'; - object: 'Insurance'; - reference?: string | null; - amount: string; - provider: string; - provider_id: string; - shipment_id: string; - tracking_code: string; - status: TInsuranceStatus; - tracker: ITracker; - to_address: IAddress; - from_address: IAddress; - fee: IFee; - messages: string[]; - created_at: string; - updated_at: string; - - /** - * An Insurance created via this endpoint must belong to a shipment purchased outside of EasyPost. - * Insurance for Shipments created within EasyPost must be created via the Shipment Buy or Insure endpoints. - * When creating Insurance for a non-EasyPost shipment, you must provide `to_address`, `from_address`, `tracking_code`, and `amount` information. - * Optionally, you can provide the carrier parameter, which will help EasyPost identify the carrier the package was shipped with. - * If no carrier is provided, EasyPost will attempt to determine the carrier based on the tracking_code provided. - * Providing a carrier parameter is recommended, since some tracking_codes are ambiguous and may match with more than one carrier. - * In addition, not having to auto-match the carrier will significantly speed up the response time. - * - * @see https://www.easypost.com/docs/api/node#create-an-insurance - * - * @param {Object} params The parameters to create an {@link Insurance} with. - * @returns {Promise} The created and verified {@link Insurance}. - */ - static create(params: Object): Promise; - - /** - * The Insurance List is a paginated list of all Insurance objects associated with the given API Key. - * It accepts a variety of parameters which can be used to modify the scope. - * The has_more attribute indicates whether or not additional pages can be requested. - * The recommended way of paginating is to use either the `before_id` or `after_id` parameter to specify where the next page begins. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-insurances - * - * @returns {Object} - An object containing a list of {@link Insurance insurance} and pagination information. - */ - static all( - params?: IAllMethodParameters, - ): Promise<{ insurances: Insurance[]; has_more: boolean }>; - - /** - * Retrieve an Insurance by id. - * - * @see https://www.easypost.com/docs/api/node#retrieve-an-insurance - * - * @param insuranceId Unique, starts with "ins_" - * @returns {Promise} The retrieved {@link Insurance}. - */ - static retrieve(insuranceId: string): Promise; - - /** - * Retrieve the next page of {@link Insurance insurances}. - * - * This automatically reuses the parameters from the previous call or the original {@link Insurance.all} call. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-insurances - * - * @param {Object} insurances - The previous page of insurances (the response from the last {@link Insurance.getNextPage} or {@link Insurance.all} call). - * @param {number} [pageSize] - The number of insurances to retrieve per page, optional. Defaults to server-side default. - * @returns {Object} - An object containing a list of {@link Insurance insurances} and pagination information. - */ - static getNextPage( - insurances: Object, - pageSize?: number, - ): Promise<{ insurances: Insurance[]; has_more: boolean }>; - - /** - * Refund an Insurance by id. - * - * @see https://www.easypost.com/docs/api/node#refund-an-insurance - * - * @param insuranceId Unique, starts with "ins_" - * @returns {Promise} The refunded {@link Insurance}. - */ - static refund(insuranceId: string): Promise; -} diff --git a/types/Insurance/InsuranceStatus.d.ts b/types/Insurance/InsuranceStatus.d.ts deleted file mode 100644 index 80ad8f4ef..000000000 --- a/types/Insurance/InsuranceStatus.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare type TInsuranceStatus = 'new' | 'pending' | 'purchased' | 'failed' | 'cancelled'; diff --git a/types/Insurance/index.d.ts b/types/Insurance/index.d.ts deleted file mode 100644 index 198f8684d..000000000 --- a/types/Insurance/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './Insurance'; -export * from './InsuranceStatus'; -export * from './InsuranceCreateParameters'; diff --git a/types/Order/Order.d.ts b/types/Order/Order.d.ts deleted file mode 100644 index 7858e2847..000000000 --- a/types/Order/Order.d.ts +++ /dev/null @@ -1,135 +0,0 @@ -import { IAddress } from '../Address'; -import { IDatedObject, IObjectWithId } from '../base'; -import { IRate } from '../Rate'; -import { IMessage, IShipment } from '../Shipment'; -import { IOrderCreateParameters } from './OrderCreateParameters'; - -/** - * The Order object represents a collection of packages and can be used for Multi-Piece Shipments. - * Like a single Shipment each Order consists of a "to" and "from" Address to be used for each Shipment within the Order. - * These Addresses will be copied to each Shipment so there is no need to specify them multiple times. - * Each Shipment must then specify its Parcel, Options, and CustomsInfo. - * - * An Order created with valid Address Objects and Parcel data nested within the Order's Shipment object will automatically retrieve available shipping Rate options. - * - * @see https://www.easypost.com/docs/api/node#order-object - */ -export declare interface IOrder extends IObjectWithId<'Order'>, IDatedObject { - /** - * An optional field that may be used in place of id in other API endpoints - */ - reference?: string | null; - - /** - * The destination address - */ - to_address: IAddress; - - /** - * The origin address - */ - from_address: IAddress; - - /** - * The shipper's address, defaults to from_address - */ - return_address?: IAddress | null; - - /** - * The buyer's address, defaults to to_address - */ - buyer_address?: IAddress | null; - - /** - * All associated Shipment objects. Maximum of 100. - */ - shipments: IShipment[]; - - /** - * All associated Rate objects - */ - rates: IRate[]; - - /** - * Any carrier errors encountered during rating - */ - messages: IMessage[]; - - /** - * Set true to create as a return - */ - is_return?: boolean | null; -} - -export declare class Order implements IOrder { - public constructor(input: IOrderCreateParameters); - - id: string; - mode: 'test' | 'production'; - object: 'Order'; - reference?: string; - to_address: IAddress; - from_address: IAddress; - return_address: IAddress; - buyer_address: IAddress; - shipments: IShipment[]; - rates: IRate[]; - messages: IMessage[]; - is_return: boolean; - created_at: string; - updated_at: string; - - /** - * An Order is almost exclusively a container for other objects, and thus an Order may reuse many of these objects. - * Alternatively, all the objects contained within an Order may be created at the same time. - * - * You can limit the CarrierAccounts to use for rating by passing the carrier_accounts parameter. - * - * @see https://www.easypost.com/docs/api/node#create-an-order - * - * @param {Object} params The parameters to create an {@link Order} with. - * @returns {Promise} The created and verified {@link Order}. - */ - static create(params: Object): Promise; - - /** - * An Order can be retrieved by either its id or reference. - * However it is recommended to use EasyPost's provided identifiers because uniqueness on reference is not enforced. - * - * @see https://www.easypost.com/docs/api/node#retrieve-an-order - * - * @param orderId Unique, begins with "order_" - * @returns {Promise} The retrieved {@link Order}. - */ - static retrieve(orderId: string): Promise; - - /** - * To purchase an Order you only need to specify the carrier and service to purchase. - * This operation populates the `tracking_code` and `postage_label` attributes of each Shipment. - * - * @see https://www.easypost.com/docs/api/node#buy-an-order - * - * @param orderId Unique, begins with "order_" - * @param carrier Carrier (UPS, FedEx, USPS) - * @param service Service of the carrier - * - * @returns {Promise} The {@link Order} object. - */ - static buy(orderId: string, carrier: string, service: string): Promise; - - /** - * Returns the rates of an Order. - * - * @param orderId Unique, begins with "order_" - * @returns {Promise} The list of {@link IRate[]}. - */ - static getRates(orderId: string): Promise; - - /** - * - * @param carriers a list of carriers to filter rates for. - * @param services a list of services to filter rates for. - * @returns {Rate} The lowest {@link Rate}. - */ - lowestRate(carriers?: string[], services?: string[]): IRate; -} diff --git a/types/Order/index.d.ts b/types/Order/index.d.ts deleted file mode 100644 index aead5d7cb..000000000 --- a/types/Order/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './Order'; -export * from './OrderCreateParameters'; diff --git a/types/Parcel/Parcel.d.ts b/types/Parcel/Parcel.d.ts deleted file mode 100644 index 49b051af1..000000000 --- a/types/Parcel/Parcel.d.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../base'; -import { DeepPartial } from '../utils'; -import { IParcelCreateParameters } from './ParcelCreateParameters'; - -/** - * Parcel objects represent the physical container being shipped. - * Dimensions can be supplied either as length, width, and height dimensions, or a predefined_package string. - * Only weight is required, but since many carriers charge different rates for packages with large dimensions, we strongly recommend including all dimensions if available. - * - * Weights are in OUNCES (OZ) and go to one decimal point. - * Dimensions are in INCHES (IN) and go to one decimal point. - * - * @see https://www.easypost.com/docs/api/node#parcel-object - */ -export declare interface IParcel extends IObjectWithId<'Parcel'>, IDatedObject { - /** - * Required if width and/or height are present - * float (inches) - */ - length?: number | null; - - /** - * Required if width and/or height are present - * float (inches) - */ - width?: number | null; - - /** - * Required if width and/or height are present - * float (inches) - */ - height?: number | null; - - /** - * Always required - * float (oz) - */ - weight: number; - - /** - * Optional, one of our predefined_packages - */ - predefined_package?: string | null; -} - -export declare class Parcel implements IParcel { - public constructor(input: DeepPartial); - - id: string; - mode: 'test' | 'production'; - object: 'Parcel'; - length?: number | null; - width?: number | null; - height?: number | null; - predefined_package?: string | null; - weight: number; - created_at: string; - updated_at: string; - - /** - * Include the `weight`, and either a `predefined_package` or `length`, `width` and `height` if applicable. - * - * @see https://www.easypost.com/docs/api/node#create-a-parcel - * - * @param {Object} params The parameters to create an {@link Parcel} with. - * @returns {Promise} The created and verified {@link Parcel}. - */ - static create(params: Object): Promise; - - /** - * Get a Parcel by its id. - * In general you should not need to use this in your automated solution. - * A Parcel's id can be inlined into the creation call to other objects. - * This allows you to only create one Parcel for each package you will be using. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-parcel - * - * @param parcelId Unique, begins with "prcl_" - * @returns {Promise} The retrieved {@link Parcel}. - */ - static retrieve(parcelId: string): Promise; -} diff --git a/types/Parcel/index.d.ts b/types/Parcel/index.d.ts deleted file mode 100644 index f4ffd66ec..000000000 --- a/types/Parcel/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './Parcel'; diff --git a/types/PaymentMethod/index.d.ts b/types/PaymentMethod/index.d.ts deleted file mode 100644 index ce53190ca..000000000 --- a/types/PaymentMethod/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './PaymentMethod'; diff --git a/types/Pickup/Pickup.d.ts b/types/Pickup/Pickup.d.ts deleted file mode 100644 index 258494697..000000000 --- a/types/Pickup/Pickup.d.ts +++ /dev/null @@ -1,199 +0,0 @@ -import { IAddress } from '../Address'; -import { IDatedObject, IObjectWithId } from '../base'; -import { ICarrierAccount } from '../Carrier'; -import { IRate } from '../Rate'; -import { IMessage, IShipment } from '../Shipment'; -import { IPickupCreateParameters } from './PickupCreateParameters'; -import { IPickupListParameters } from './PickupListParameters'; -import { IPickupRate } from './PickupRate'; - -/** - * The Pickup object allows you to schedule a pickup from your carrier from your customer's residence or place of business. - * Supported carriers include: - * - Canada Post - * - Canpar - * - DHL Express - * - FedEx - * - Lasership - * - Loomis Express - * - LSO - * - Ontrac - * - UPS - * - USPS - * - Veho - * - * After a Pickup is successfully created, it will automatically fetch PickupRates for each CarrierAccount specified that supports scheduled pickups. - * Then a PickupRate must be selected and purchased before the pickup can be successfully scheduled. - * - * @see https://www.easypost.com/docs/api/node#pickup-object - */ -export declare interface IPickup extends IObjectWithId<'Pickup'>, IDatedObject { - /** - * An optional field that may be used in place of ID in some API endpoints - */ - reference?: string | null; - - /** - * One of: "unknown", "scheduled", or "canceled" - */ - status: 'unknown' | 'scheduled' | 'canceled'; - - /** - * The earliest time at which the package is available to pick up - */ - min_datetime: string; - - /** - * The latest time at which the package is available to pick up. - * Must be later than the min_datetime - */ - max_datetime: string; - - /** - * Is the pickup address the account's address? - */ - is_account_address?: boolean | null; - - /** - * Additional text to help the driver successfully obtain the package - */ - instructions?: string | null; - - /** - * A list of messages containing carrier errors encountered during pickup rate generation - */ - messages: IMessage[]; - - /** - * The confirmation number for a booked pickup from the carrier - */ - confirmation: string; - - /** - * The associated Shipment - */ - shipment: IShipment; - - /** - * The associated Address - */ - address: IAddress; - - /** - * The list of carriers (if empty, all carriers were used) used to generate pickup rates - */ - carrier_accounts?: ICarrierAccount[] | null; - - /** - * The list of different pickup rates across valid carrier accounts for the shipment - */ - pickup_rates: IPickupRate[]; -} - -export declare class Pickup implements IPickup { - public constructor(input: IPickupCreateParameters); - - id: string; - mode: 'test' | 'production'; - object: 'Pickup'; - reference?: string | null; - status: 'unknown' | 'scheduled' | 'canceled'; - min_datetime: string; - max_datetime: string; - is_account_address?: boolean | null; - instructions: string; - messages: IMessage[]; - confirmation: string; - shipment: IShipment; - address: IAddress; - carrier_accounts?: ICarrierAccount[] | null; - pickup_rates: IPickupRate[]; - created_at: string; - updated_at: string; - - /** - * Creating a Pickup will automatically fetch rates for the given time frame and location. - * - * Pickups work with existing shipments or a batch and either a fully-specified Address object or id. - * The examples below assume that a shipment and address have both already been created. - * - * @see https://www.easypost.com/docs/api/node#create-a-pickup - * - * @param {Object} params The parameters to create an {@link Pickup} with. - * @returns {Promise} The created and verified {@link Pickup}. - */ - static create(params: Object): Promise; - - /** - * The Pickup List is a paginated list of all Pickup objects associated with the given API Key. - * It accepts a variety of parameters which can be used to modify the scope. - * The has_more attribute indicates whether additional pages can be requested. - * The recommended way of paginating is to use either the before_id or after_id parameter to specify where the next page begins. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups - * - * @param params - The parameters to use for the request. - * @returns {Object} - An object containing a list of {@link Pickup pickups} and pagination information. - */ - static all(params?: IPickupListParameters): Promise<{ pickups: Pickup[]; has_more: boolean }>; - - /** - * A Pickup object can be retrieved by either an id or reference. - * However it is recommended to use EasyPost's provided identifiers because uniqueness on reference is not enforced. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-pickup - * - * @param pickupId Unique, starts with "pickup_" - * @returns {Promise} The created and verified {@link Pickup}. - */ - static retrieve(pickupId: string): Promise; - - /** - * To purchase a Pickup a PickupRate must be specified by its carrier and service name, instead of its id. - * The client libraries will handle this automatically if a PickupRate is provided. - * - * @see https://www.easypost.com/docs/api/node#buy-a-pickup - * - * @param pickupId Unique, begins with "pickup_" - * @param carrier Carrier (UPS, FedEx, USPS) - * @param service Service of the carrier - * @returns {Promise} The created and verified {@link Pickup}. - */ - static buy(pickupId: string, carrier: string, service: string): Promise; - - /** - * You may cancel a Pickup anytime before it has been completed. - * It requires no additional parameters other than the id or reference. - * The status will change to "canceled" on success. - * - * @see https://www.easypost.com/docs/api/node#cancel-a-pickup - * - * @param pickupId Unique, begins with "pickup_" - * @returns {Promise} The created and verified {@link Pickup}. - */ - static cancel(pickupId: string): Promise; - - /** - * Retrieve the next page of {@link Pickup pickups}. - * - * This automatically reuses the parameters from the previous call or the original {@link Pickup.all} call. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups - * - * @param {Object} pickups - The previous page of pickups (the response from the last {@link Pickup.getNextPage} or {@link Pickup.all} call). - * @param {number} [pageSize] - The number of pickups to retrieve per page, optional. Defaults to server-side default. - * @returns {Object} - An object containing a list of {@link Pickup pickups} and pagination information. - */ - static getNextPage( - pickups: Object, - pageSize?: number, - ): Promise<{ pickups: Pickup[]; has_more: boolean }>; - - /** - * - * @param carriers a list of carriers to filter rates for. - * @param services a list of services to filter rates for. - * @returns {Rate} The lowest {@link Rate}. - */ - lowestRate(carriers?: string[], services?: string[]): IRate; -} diff --git a/types/Pickup/PickupCreateParameters.d.ts b/types/Pickup/PickupCreateParameters.d.ts deleted file mode 100644 index 109fe09bc..000000000 --- a/types/Pickup/PickupCreateParameters.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { IPickupRate } from './PickupRate'; -import { Address } from '../Address'; -import { Batch } from '../Batch'; -import { CarrierAccount } from '../Carrier'; -import { Shipment } from '../Shipment'; - -interface BasePickupCreateParameters { - address: Address | string; - carrier_accounts?: CarrierAccount[] | null; - confirmation?: string | null; - instructions?: string | null; - is_account_address?: boolean | null; - max_datetime: string; - min_datetime: string; - pickup_rates: IPickupRate; - reference?: string | null; - status: string; -} - -interface ShipmentPickupCreateParameters extends BasePickupCreateParameters { - shipment?: Shipment | string | null; -} - -interface BatchPickupCreateParameters extends BasePickupCreateParameters { - batch?: Batch | string | null; -} - -export type IPickupCreateParameters = ShipmentPickupCreateParameters | BatchPickupCreateParameters; diff --git a/types/Pickup/PickupListParameters.d.ts b/types/Pickup/PickupListParameters.d.ts deleted file mode 100644 index 35bfff86e..000000000 --- a/types/Pickup/PickupListParameters.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IAllMethodParameters } from '../utils'; - -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups - */ -export declare interface IPickupListParameters extends IAllMethodParameters {} diff --git a/types/Pickup/PickupRate.d.ts b/types/Pickup/PickupRate.d.ts deleted file mode 100644 index 3d2177b36..000000000 --- a/types/Pickup/PickupRate.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../base'; - -/** - * @see https://www.easypost.com/docs/api/node#pickup-rate-object - */ -export declare interface IPickupRate extends IObjectWithId<'PickupRate'>, IDatedObject { - /** - * service name - */ - service: string; - - /** - * name of carrier - */ - carrier: string; - - /** - * the actual rate quote for this service - */ - rate: string; - - /** - * currency for the rate - */ - currency: string; - - /** - * the ID of the pickup this is a quote for - */ - pickup_id: string; -} diff --git a/types/Pickup/index.d.ts b/types/Pickup/index.d.ts deleted file mode 100644 index 99968d8e0..000000000 --- a/types/Pickup/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './Pickup'; -export * from './PickupRate'; -export * from './PickupCreateParameters'; diff --git a/types/Rate/Rate.d.ts b/types/Rate/Rate.d.ts deleted file mode 100644 index 15922b3dd..000000000 --- a/types/Rate/Rate.d.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../base'; - -/** - * The Rate class represents a summary of the price and details of a delivery service quote. - * - * @see https://www.easypost.com/docs/api/node#rates - */ -export declare interface IRate extends IObjectWithId<'Rate'>, IDatedObject { - /** - * The service level of the rate. - */ - service: string; - /** - * The carrier of the rate. - */ - carrier: string; - /** - * The ID of the carrier account associated with this rate. - */ - carrier_account_id: string; - /** - * The ID of the shipment associated with this rate. - */ - shipment_id: string; - /** - * The quote price of the rate. - */ - rate: string; - /** - * The currency of the rate. - */ - currency: string; - /** - * The in-store retail rate given with no account. - */ - retail_rate: string; - /** - * The currency of the retail rate. - */ - retail_currency: string; - /** - * The non-negotiated rate given for having an account with the carrier. - */ - list_rate: string; - /** - * The currency of the list rate. - */ - list_currency: string; - /** - * The number of days in transit for this rate. - */ - delivery_days: number; - /** - * The delivery date for this rate. - */ - delivery_date: string; - /** - * Whether the delivery window is guaranteed. - */ - delivery_date_guaranteed: boolean; - /** - * The earliest delivery date for this rate. - * This is deprecated and should be ignored. - */ - est_delivery_days: number; - /** - * The billing type of the rate. - */ - billing_type: string; -} - -export declare class Rate implements IRate { - billing_type: string; - carrier: string; - carrier_account_id: string; - created_at: string; - currency: string; - delivery_date: string; - delivery_date_guaranteed: boolean; - delivery_days: number; - est_delivery_days: number; - id: string; - list_currency: string; - list_rate: string; - mode: 'test' | 'production'; - object: 'Rate'; - rate: string; - retail_currency: string; - retail_rate: string; - service: string; - shipment_id: string; - updated_at: string; -} diff --git a/types/Rate/index.d.ts b/types/Rate/index.d.ts deleted file mode 100644 index 9ef03ab5e..000000000 --- a/types/Rate/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './Rate'; diff --git a/types/Referral/Referral.d.ts b/types/Referral/Referral.d.ts deleted file mode 100644 index 2150e1a51..000000000 --- a/types/Referral/Referral.d.ts +++ /dev/null @@ -1,115 +0,0 @@ -import { IUser } from '../User'; -import { IReferralCreateParameters } from './ReferralCreateParameters'; -import { IReferralListParameters } from './ReferralListParameters'; - -/** - * A Referral represents a sub-user under a Partner or white-label account. - * - * @see https://www.easypost.com/docs/api/node#referral-customers - */ -export declare interface IReferral extends IUser {} - -export declare class Referral implements IReferral { - public constructor(input: IReferralCreateParameters); - - id: string; - mode: 'test' | 'production'; - // @ts-ignore Suppress warning about "object" override - object: 'Referral'; - reference?: string | null; - parent_id: string; - name: string; - email: string; - phone_number?: string | null; - balance: string; - recharge_amount: string; - secondary_recharge_amount: string; - recharge_threshold: string; - children: IUser[]; - - /** - * Creates a referral customer. - * - * @see https://www.easypost.com/docs/api/node#create-a-referral-customer - * - * @param {Object} params The parameters to create an {@link Referral} with. - * @returns {Promise} The created Referral. - */ - static create(params: Object): Promise; - - /** - * The Referral List is a paginated list of all Referral objects associated with the given API Key. - * It accepts a variety of parameters which can be used to modify the scope. - * The `has_more` attribute indicates whether additional pages can be requested. - * The recommended way of paginating is to use either the `before_id` or `after_id` parameter to specify where the next page begins. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers - * - * @param params - The parameters to use for the request. - * @returns {Object} - An object containing a list of {@link Referral referral customers} and pagination information. - */ - static all( - params?: IReferralListParameters, - ): Promise<{ referral_customers: Referral[]; has_more: boolean }>; - - /** - * Update a Referral's email address. - * - * @see https://www.easypost.com/docs/api/node#update-a-referral-customer - * - * @param {string} referralUserId ID of the referral user to update - * @param {string} email New email address for the referral user - * @returns {Promise} Whether the update was successful - */ - static updateEmail(referralUserId: string, email: string): Promise; - - /** - * Add Stripe payment method to referral customer. - * - * @see https://www.easypost.com/docs/api/node#add-payment-method-to-referral-user - * - * @param {string} stripeCustomerId Stripe customer ID - * @param {string} paymentMethodReference Reference for the Stripe payment method - * @param {string} priority Whether the payment method is primary or secondary - * @returns {object} Object representing the newly-added payment method - */ - static addPaymentMethod( - stripeCustomerId: string, - paymentMethodReference: string, - priority?: string, - ): object; - - /** - * Refund by amount for a recent payment. - * @see https://www.easypost.com/docs/api/node#refund-a-referral-user - * - * @param {number} refundAmount Amount to refund - * @returns {object} Object representing the newly-added payment method - */ - static refundByAmount(refundAmount: number): object; - - /** - * Refund a payment by a payment log ID. - * @see https://www.easypost.com/docs/api/node#refund-a-referral-user - * - * @param {string} paymentLogId ID of the payment log to refund - * @returns {object} Object representing the newly-added payment method - */ - static refundByPaymentLog(paymentLogId: string): object; - - /** - * Retrieve the next page of {@link Referral referrals}. - * - * This automatically reuses the parameters from the previous call or the original {@link Referral.all} call. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers - * - * @param {Object} referralCustomers - The previous page of referrals (the response from the last {@link Referral.getNextPage} or {@link Referral.all} call). - * @param {number} [pageSize] - The number of referrals to retrieve per page, optional. Defaults to server-side default. - * @returns {Object} - An object containing a list of {@link Referral referrals} and pagination information. - */ - static getNextPage( - referralCustomers: Object, - pageSize?: number, - ): Promise<{ referrals: Referral[]; has_more: boolean }>; -} diff --git a/types/Referral/ReferralCreateParameters.d.ts b/types/Referral/ReferralCreateParameters.d.ts deleted file mode 100644 index 8af7261b4..000000000 --- a/types/Referral/ReferralCreateParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ParametersToOmitOnCreate } from '../utils'; -import { IReferral } from './Referral'; - -export declare interface IReferralCreateParameters - extends Omit {} diff --git a/types/Referral/ReferralListParameters.d.ts b/types/Referral/ReferralListParameters.d.ts deleted file mode 100644 index a317e3967..000000000 --- a/types/Referral/ReferralListParameters.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IAllMethodParameters } from '../utils'; - -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers - */ -export declare interface IReferralListParameters extends IAllMethodParameters {} diff --git a/types/Referral/index.d.ts b/types/Referral/index.d.ts deleted file mode 100644 index 4f93470e0..000000000 --- a/types/Referral/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './Referral'; -export * from './ReferralCreateParameters'; diff --git a/types/Refund/Refund.d.ts b/types/Refund/Refund.d.ts deleted file mode 100644 index 30e2731a3..000000000 --- a/types/Refund/Refund.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../base'; -import { IRefundCreateParameters } from './RefundCreateParameters'; -import { IRefundListParameters } from './RefundListParameters'; - -/** - * The Refund object represents a refunded shipment, and includes details about the related Shipment and tracking code. - * USPS shipping labels can be refunded if requested within 30 days of generation. - * The processing time is at least 15 days, after which the funds will return to your EasyPost balance. - * EasyPost fees will also be refunded. To qualify, a shipment must not have been scanned by the USPS. - * UPS and FedEx shipping labels may be refunded within 90 days of creation. - */ -export declare interface IRefund extends IObjectWithId<'Refund'>, IDatedObject { - /** - * The tracking code of the related Shipment - */ - tracking_code: string; - - /** - * The confirmation number for the refund request to the carrier - */ - confirmation_number: string; - - /** - * The status of the refund request, reported by the carrier. Possible values are "submitted", "refunded", or "rejected" - */ - status: 'submitted' | 'refunded' | 'rejected'; - - /** - * The carrier the refund request was submitted to - */ - carrier: string; - - /** - * The ID of the related Shipment being refunded - */ - shipment_id: string; -} - -export declare class Refund implements IRefund { - public constructor(input: IRefundCreateParameters); - - id: string; - mode: 'test' | 'production'; - object: 'Refund'; - tracking_code: string; - confirmation_number: string; - status: 'submitted' | 'refunded' | 'rejected'; - carrier: string; - shipment_id: string; - created_at: string; - updated_at: string; - - /** - * This endpoint is intended to be used to bulk-process multiple refunds; as a result, this endpoint will return a list of Refund objects. - * To refund a single shipment, use the Refund a Shipment endpoint instead. - * - * @see https://www.easypost.com/docs/api/node#create-a-refund - * - * @param {Object} params The parameters to create an {@link Refund} with. - * @returns {Promise} The created and verified {@link Refund}. - */ - static create(params: Object): Promise; - - /** - * Retrieve a paginated list of all Refunds associated with the given API Key. - * See the Pagination section of our docs for more details on retrieving all records when multiple pages are available. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds - * - * @param params - The parameters to use for the request. - * @returns {Object} - An object containing a list of {@link Refund refunds} and pagination information. - */ - static all(params?: IRefundListParameters): Promise<{ refunds: Refund[]; has_more: boolean }>; - - /** - * Retrieve a Refund by id. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-refund - * - * @param refundId Unique, starts with "refund_" - * @returns {Promise} The created and verified {@link Refund}. - */ - static retrieve(refundId: string): Promise; - - /** - * Retrieve the next page of {@link Refund refunds}. - * - * This automatically reuses the parameters from the previous call or the original {@link Refund.all} call. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds - * - * @param {Object} refunds - The previous page of refunds (the response from the last {@link Refund.getNextPage} or {@link Refund.all} call). - * @param {number} [pageSize] - The number of refunds to retrieve per page, optional. Defaults to server-side default. - * @returns {Object} - An object containing a list of {@link Refund refunds} and pagination information. - */ - static getNextPage( - refunds: Object, - pageSize?: number, - ): Promise<{ refunds: Refund[]; has_more: boolean }>; -} diff --git a/types/Refund/RefundListParameters.d.ts b/types/Refund/RefundListParameters.d.ts deleted file mode 100644 index cfbee60c8..000000000 --- a/types/Refund/RefundListParameters.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IAllMethodParameters } from '../utils'; - -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds - */ -export declare interface IRefundListParameters extends IAllMethodParameters {} diff --git a/types/Refund/index.d.ts b/types/Refund/index.d.ts deleted file mode 100644 index 109195cc5..000000000 --- a/types/Refund/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './Refund'; -export * from './RefundCreateParameters'; diff --git a/types/Report/Report.d.ts b/types/Report/Report.d.ts deleted file mode 100644 index 665ee2e5a..000000000 --- a/types/Report/Report.d.ts +++ /dev/null @@ -1,133 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../base'; -import { IReportCreateParameters } from './ReportCreateParameters'; -import { IReportListParameters } from './ReportListParameters'; -import { TReportObjectType } from './ReportObjectType'; - -/** - * A Report contains a csv that is a log of all the objects created within a certain time frame. - * - * Reports can be generated using the Reports Endpoint. - * You can create and view Reports created between any time frame defined between the start_date and end_date. - * - * The Report api can be categorized into several types. - * These types determine which EasyPost Object to produce a Report for, and should be passed as the type in our libraries: - * - cash_flow - * - insurance - * - payment_log - * - refund - * - shipment - * - shipment_invoice - * - tracker - * - * @see https://www.easypost.com/docs/api/node#report-object - */ -export declare interface IReport extends IObjectWithId, IDatedObject { - /** - * "new", "available", "failed", or null - */ - status: 'new' | 'available' | 'failed' | null; - - /** - * A date string in YYYY-MM-DD form eg: "2016-02-02" - */ - start_date: string; - - /** - * A date string in YYYY-MM-DD form eg: "2016-02-03" - */ - end_date: string; - - /** - * Set true if you would like to include Refunds /Shipments /Trackers created by child users - */ - include_children?: boolean | null; - - /** - * A url that contains a link to the Report. - * Expires 30 seconds after retrieving this object - */ - url: string; - - /** - * Url expiring time - */ - url_expires_at: string; - - /** - * Set true if you would like to send an email containing the Report - */ - send_email?: boolean | null; -} - -export declare class Report implements IReport { - public constructor(input: IReportCreateParameters); - - id: string; - mode: 'test' | 'production'; - object: TReportObjectType; - status: 'new' | 'available' | 'failed' | null; - start_date: 'unknown' | 'scheduled' | 'canceled'; - end_date: string; - include_children?: boolean | null; - url: string; - url_expires_at: string; - send_email?: boolean | null; - created_at: string; - updated_at: string; - - /** - * To create a Report, provide a `start_date` and `end_date` that are less than 31 days apart along with any other - * optional parameter that you would like to specify. A detailed list of Report Object attributes are provided below. - * - * The expiry on url is 30 seconds. The default status on each new Report is "new". It changes to "available" if the - * csv file is created successfully or to "failed" when csv creation is unsuccessful, or to "empty" if the report - * does not include any data for the specified date range. Additionally, null could also be a status. - * - * When a Report's status changes, a webhook will be created. See our Webhooks Guide for help on Event handling. - * - * @see https://www.easypost.com/docs/api/node#create-a-report - * - * @param {Object} params The parameters to create an {@link Report} with. - * @returns {Promise} The created and verified {@link Report}. - */ - static create(params: Object): Promise; - - /** - * The Report List is a paginated list of all Report objects associated with the given API Key. It accepts a variety of - * parameters which can be used to modify the scope. The `has_more` attribute indicates whether or not additional pages can - * be requested. The recommended way of paginating is to use either the `before_id` or `after_id` parameter to specify where - * the next page begins. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-reports - * - * @param params - The parameters to use for the request. - * @returns {Object} - An object containing a list of {@link Report reports} and pagination information. - */ - static all(params?: IReportListParameters): Promise<{ reports: Report[]; has_more: boolean }>; - - /** - * Retrieve a Report by id. - * - * @param reportId Unique, starts with the prefix for that particular report, - * eg: "cfrep_", "plrep_", "refrep_", "shprep_", "shpinvrep_", "trkrep_" - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-report - */ - static retrieve(reportId: string): Promise; - - /** - * Retrieve the next page of {@link Report reports}. - * - * This automatically reuses the parameters from the previous call or the original {@link Report.all} call. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-reports - * - * @param {Object} reports - The previous page of reports (the response from the last {@link Report.getNextPage} or {@link Report.all} call). - * @param {number} [pageSize] - The number of reports to retrieve per page, optional. Defaults to server-side default. - * @returns {Object} - An object containing a list of {@link Report reports} and pagination information. - */ - static getNextPage( - reports: Object, - pageSize?: number, - ): Promise<{ reports: Report[]; has_more: boolean }>; -} diff --git a/types/Report/ReportListParameters.d.ts b/types/Report/ReportListParameters.d.ts deleted file mode 100644 index d36b03bc1..000000000 --- a/types/Report/ReportListParameters.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IAllMethodParameters } from '../utils'; - -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds - */ -export declare interface IReportListParameters extends IAllMethodParameters {} diff --git a/types/Report/ReportObjectType.d.ts b/types/Report/ReportObjectType.d.ts deleted file mode 100644 index c9cc99059..000000000 --- a/types/Report/ReportObjectType.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -export declare type TReportObjectType = - | 'CashFlowReport' - | 'PaymentLogReport' - | 'RefundReport' - | 'ShipmentReport' - | 'ShipmentInvoiceReport' - | 'TrackerReport'; diff --git a/types/Report/index.d.ts b/types/Report/index.d.ts deleted file mode 100644 index d0c66d61c..000000000 --- a/types/Report/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './Report'; -export * from './ReportObjectType'; diff --git a/types/ScanForm/ScanForm.d.ts b/types/ScanForm/ScanForm.d.ts deleted file mode 100644 index 91502e07b..000000000 --- a/types/ScanForm/ScanForm.d.ts +++ /dev/null @@ -1,126 +0,0 @@ -import { IAddress } from '../Address'; -import { IDatedObject, IObjectWithId } from '../base'; -import { IScanFormCreateParameters } from './ScanFormCreateParameters'; -import { IScanFormListParameters } from './ScanFormListParameters'; - -/** - * A ScanForm can be created to speed up and simplify the carrier pickup process. - * The ScanForm is one document that can be scanned to mark all included tracking codes as "Accepted for Shipment" by the carrier. - * The following criteria must met before creation: - * - Refunded Shipments cannot be added - * - Each Shipment must have the same origin address - * - Shipments must all be dated (using the label_date option) on or after the date the form is generated - * - Shipments cannot be added to more than one ScanForm - * - Existing ScanForms may not be updated with additional Shipments. If a ScanForm already exists, and new Shipments need to be added, a new ScanForm must be created. - * - Shipments should be provided in the form of an array - * - * @see https://www.easypost.com/docs/api/node#scan-form-object - */ -export declare interface IScanForm extends IObjectWithId<'ScanForm'>, IDatedObject { - /** - * Current status. - * Possible values are "creating", "created" and "failed" - */ - status: 'creating' | 'created' | 'failed'; - - /** - * Human-readable message explaining any failures - */ - message: string; - - /** - * Address that the Shipments will be shipped from - */ - address: IAddress; - - /** - * Tracking codes included on the ScanForm - */ - tracking_codes: string[]; - - /** - * Url of the document - */ - form_url: string; - - /** - * File format of the document - */ - form_file_type: string; - - /** - * The id of the associated Batch. Unique, starts with "batch_" - */ - batch_id: string; -} - -export declare class ScanForm implements IScanForm { - public constructor(input: IScanFormCreateParameters); - - address: IAddress; - batch_id: string; - created_at: string; - form_file_type: string; - form_url: string; - id: string; - message: string; - mode: 'test' | 'production'; - object: 'ScanForm'; - status: 'creating' | 'created' | 'failed'; - tracking_codes: string[]; - updated_at: string; - - /** - * A ScanForm can be created to speed up and simplify the carrier pickup process. - * The Scan Form is one document that can be scanned to mark all included tracking codes as "Accepted for Shipment" by the carrier. - * - * @see https://www.easypost.com/docs/api/node#scan-form - * - * @returns {Promise} The created ScanForm - * - * @param {Object} params The parameters to create an {@link ScanForm} with. - * @returns {Promise} The created and verified {@link ScanForm}. - */ - static create(params: Object): Promise; - - /** - * The ScanForm List is a paginated list of all ScanForm objects associated with the given API Key. - * It accepts a variety of parameters which can be used to modify the scope. - * The `has_more` attribute indicates whether additional pages can be requested. - * The recommended way of paginating is to use either the `before_id` or `after_id` parameter to specify where the next page begins. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-scan-forms - * - * @param {object} params The parameters to use for the request. - * @returns {Object} - An object containing a list of {@link ScanForm scanforms} and pagination information. - */ - static all( - params?: IScanFormListParameters, - ): Promise<{ scan_forms: ScanForm[]; has_more: boolean }>; - - /** - * A ScanForm can be retrieved by either its id or reference. - * However, it is recommended to use EasyPost's provided identifiers because uniqueness on reference is not enforced. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-scan-form - * - * @param {string} scanFormId Unique, begins with "sf_". - */ - static retrieve(scanFormId: string): Promise; - - /** - * Retrieve the next page of {@link ScanForm scan forms}. - * - * This automatically reuses the parameters from the previous call or the original {@link ScanForm.all} call. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-scanforms - * - * @param {Object} scanforms - The previous page of scan forms (the response from the last {@link ScanForm.getNextPage} or {@link ScanForm.all} call). - * @param {number} [pageSize] - The number of scan forms to retrieve per page, optional. Defaults to server-side default. - * @returns {Object} - An object containing a list of {@link ScanForm scan forms} and pagination information. - */ - static getNextPage( - scanforms: Object, - pageSize?: number, - ): Promise<{ scanforms: ScanForm[]; has_more: boolean }>; -} diff --git a/types/ScanForm/ScanFormCreateParameters.d.ts b/types/ScanForm/ScanFormCreateParameters.d.ts deleted file mode 100644 index e5cc97a1e..000000000 --- a/types/ScanForm/ScanFormCreateParameters.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { DeepPartial } from '../utils'; -import { IShipmentCreateParameters } from '../Shipment'; - -export declare interface IScanFormCreateParameters { - shipments: Array>; -} diff --git a/types/ScanForm/ScanFormListParameters.d.ts b/types/ScanForm/ScanFormListParameters.d.ts deleted file mode 100644 index 9558603a6..000000000 --- a/types/ScanForm/ScanFormListParameters.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IAllMethodParameters } from '../utils'; - -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-scan-forms - */ -export declare interface IScanFormListParameters extends IAllMethodParameters {} diff --git a/types/ScanForm/index.d.ts b/types/ScanForm/index.d.ts deleted file mode 100644 index 3851190d8..000000000 --- a/types/ScanForm/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './ScanForm'; diff --git a/types/Shipment/Form.d.ts b/types/Shipment/Form.d.ts deleted file mode 100644 index bb42ba8c8..000000000 --- a/types/Shipment/Form.d.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../base'; - -/** - * @see https://www.easypost.com/docs/api/node#form-object - */ -export declare interface IForm extends IObjectWithId<'Form'>, IDatedObject { - /** - * The type of form that we returned, can be one of "cn22", "cod_return_label", "commercial_invoice", "high_value_report", "label_qr_code", "nafta_certificate_of_origin", "order_summary", "return_packing_slip", "rma_qr_code" - */ - form_type: - | 'cn22' - | 'cod_return_label' - | 'commercial_invoice' - | 'high_value_report' - | 'label_qr_code' - | 'nafta_certificate_of_origin' - | 'order_summary' - | 'return_packing_slip' - | 'rma_qr_code'; - - /** - * The address we return the form back at - */ - form_url: string; - - /** - * If we have submitted the form to the carrier on behalf of the customer - */ - submitted_electronically: boolean; -} diff --git a/types/Shipment/Options/LabelFormat.d.ts b/types/Shipment/Options/LabelFormat.d.ts deleted file mode 100644 index cc3a84031..000000000 --- a/types/Shipment/Options/LabelFormat.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare type LabelFormat = 'PNG' | 'PDF' | 'ZPL' | 'EPL2'; diff --git a/types/Shipment/Options/index.d.ts b/types/Shipment/Options/index.d.ts deleted file mode 100644 index 349426b0d..000000000 --- a/types/Shipment/Options/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './LabelFormat'; -export * from './Options'; -export * from './PrintCustomCode'; diff --git a/types/Shipment/PostageLabel.d.ts b/types/Shipment/PostageLabel.d.ts deleted file mode 100644 index 9f8717b97..000000000 --- a/types/Shipment/PostageLabel.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../base'; - -/** - * PostageLabel Object - */ -export declare interface IPostageLabel extends IObjectWithId<'PostageLabel'>, IDatedObject { - date_advance: number; - integrated_form: string; - label_date: string; - label_resolution: number; - label_size: string; - label_type: string; - label_url: string; - label_file_type: string; - label_pdf_url: string; - label_epl2_url: string; - label_zpl_url: string; -} diff --git a/types/Shipment/Rate.d.ts b/types/Shipment/Rate.d.ts deleted file mode 100644 index d818d6639..000000000 --- a/types/Shipment/Rate.d.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../base'; -import { ICarbonOffset } from '../CarbonOffset'; - -/** - * After a Shipment is successfully created, it will automatically fetch Rates. - * You can limit the CarrierAccounts to use for rating by passing the carrier_accounts parameter upon Shipment creation. - * - * There are three rate types: the actual rate that will be purchased, rate and currency, the published non-discounted rate, list_rate and list_currency, and the rate if purchased from the post office, retail_rate and retail_currency. - * - * @see https://www.easypost.com/docs/api/node#rate-object - */ -export declare interface IRate extends IObjectWithId<'Rate'>, IDatedObject { - /** - * service level/name - * @see https://www.easypost.com/docs/api/node#service-levels - */ - service: string; - - /** - * name of carrier - */ - carrier: string; - - /** - * ID of the CarrierAccount record used to generate this rate - */ - carrier_account_id: string; - - /** - * ID of the Shipment this rate belongs to - */ - shipment_id: string; - - /** - * the actual rate quote for this service - */ - rate: string; - - /** - * currency for the rate - */ - currency: string; - - /** - * the retail rate is the in-store rate given with no account - */ - retail_rate: string; - - /** - * currency for the retail rate - */ - retail_currency: string; - - /** - * the list rate is the non-negotiated rate given for having an account with the carrier - */ - list_rate: string; - - /** - * currency for the list rate - */ - list_currency: string; - - /** - * delivery days for this service - */ - delivery_days: number; - - /** - * date for delivery - */ - delivery_date: string; - - /** - * indicates if delivery window is guaranteed (true) or not (false) - */ - delivery_date_guaranteed: boolean; - - /** - * Indicate if a rate includes a carbon offset fee - */ - carbon_offset: ICarbonOffset; -} diff --git a/types/Shipment/Shipment.d.ts b/types/Shipment/Shipment.d.ts deleted file mode 100644 index 9b20d406d..000000000 --- a/types/Shipment/Shipment.d.ts +++ /dev/null @@ -1,346 +0,0 @@ -import { IAddress } from '../Address'; -import { IDatedObject, IObjectWithId } from '../base'; -import { TBatchStatus } from '../Batch'; -import { ICustomsInfo } from '../Customs'; -import { IFee } from '../Fee'; -import { IInsurance } from '../Insurance'; -import { IParcel } from '../Parcel'; -import { IScanForm } from '../ScanForm'; -import { ITracker } from '../Tracker'; -import { IForm } from './Form'; -import { IMessage } from './Message'; -import { IOptions, LabelFormat } from './Options'; -import { IPostageLabel } from './PostageLabel'; -import { IRate } from './Rate'; -import { IShipmentCreateParameters } from './ShipmentCreateParameters'; -import { IShipmentListParameters } from './ShipmentListParameters'; - -/** - * The workhorse of the EasyPost API, a Shipment is made up of a "to" and "from" Address, the Parcel being shipped, and any customs forms required for international deliveries. - * Once created a Shipment object is used to retrieve shipping Rates and purchase a label. - * - * A Shipment created with a valid to_address, from_address, and parcel will automatically populate its rates attribute. - * - * @see https://www.easypost.com/docs/api/node#shipment-object - */ -export declare interface IShipment extends IObjectWithId<'Shipment'>, IDatedObject { - /** - * An optional field that may be used in place of id in other API endpoints - */ - reference?: string | null; - - /** - * The destination address - */ - to_address: IAddress; - - /** - * The origin address - */ - from_address: IAddress; - - /** - * The shipper's address, defaults to from_address - */ - return_address?: IAddress | null; - - /** - * The buyer's address, defaults to to_address - */ - buyer_address?: IAddress | null; - - /** - * The dimensions and weight of the package - */ - parcel: IParcel; - - /** - * Information for the processing of customs - */ - customs_info?: ICustomsInfo | null; - - /** - * Document created to manifest and scan multiple shipments - */ - scan_form: IScanForm; - - /** - * All associated Form objects - */ - forms: IForm[]; - - /** - * The associated Insurance object - */ - insurance: IInsurance; - - /** - * All associated Rate objects - */ - rates: IRate[]; - - /** - * The specific rate purchased for the shipment, or null if unpurchased or purchased through another mechanism - */ - selected_rate: IRate; - - /** - * The associated PostageLabel object - */ - postage_label: IPostageLabel; - - /** - * Any carrier errors encountered during rating, discussed in more depth below - */ - messages: IMessage[]; - - /** - * All the options passed to the shipment, discussed in more depth below - */ - options?: IOptions | null; - - /** - * Set true to create as a return, discussed in more depth below - */ - is_return?: boolean | null; - - /** - * If purchased, the tracking code will appear here as well as within the Tracker object - */ - tracking_code: string; - - /** - * The USPS zone of the shipment, if purchased with USPS - */ - usps_zone: string; - - /** - * The current tracking status of the shipment - */ - status: string; - - /** - * The associated Tracker object - */ - tracker: ITracker; - - /** - * The associated Fee objects charged to the billing user account - */ - fees: IFee[]; - - /** - * The current status of the shipment refund process. Possible values are "submitted", "refunded", "rejected". - */ - refund_status: 'submitted' | 'refunded' | 'rejected'; - - /** - * The ID of the batch that contains this shipment, if any - */ - batch_id: string; - - /** - * The current status of the associated BatchShipment - */ - batch_status: TBatchStatus; - - /** - * The current message of the associated BatchShipment - */ - batch_message: string; -} - -export declare class Shipment implements IShipment { - public constructor(input: IShipmentCreateParameters); - - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - reference?: string | null; - to_address: IAddress; - from_address: IAddress; - return_address?: IAddress | null; - buyer_address?: IAddress | null; - parcel: IParcel; - customs_info?: ICustomsInfo | null; - scan_form: IScanForm; - forms: IForm[]; - insurance: IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: IPostageLabel; - messages: IMessage[]; - options?: IOptions | null; - is_return?: boolean | null; - tracking_code: string; - usps_zone: string; - status: string; - tracker: ITracker; - fees: IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: TBatchStatus; - batch_message: string; - created_at: string; - updated_at: string; - - /** - * A Shipment is almost exclusively a container for other objects, and thus a Shipment may reuse many of these objects. - * Additionally, all the objects contained within a Shipment may be created at the same time. - * - * The origin/destination Address and Parcel are required for rating. - * CustomsInfo is required to rate an international Shipment, this includes when the destination is a US Territory. - * The associated Tracker, Fees, and Rates are generated by EasyPost and cannot be modified by the user. - * - * You can limit the CarrierAccounts to use for rating by passing the carrier_accounts parameter. - * - * @see https://www.easypost.com/docs/api/node#create-a-shipment - * - * @param {Object} params The parameters to create an {@link Shipment} with. - * @returns {Promise} The created {@link Shipment}. - */ - static create(params: Object): Promise; - - /** - * The Shipment List is a paginated list of all Shipment objects associated with the given API Key. - * It accepts a variety of parameters which can be used to modify the scope. - * The `has_more` attribute indicates whether additional pages can be requested. - * The recommended way of paginating is to use either the `before_id` or `after_id` parameter to specify where the next page begins. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments - * - * @param params - The parameters to use for the request. - * @returns {Object} - An object containing a list of {@link Shipment shipments} and pagination information. - */ - static all( - params?: IShipmentListParameters, - ): Promise<{ shipments: Shipment[]; has_more: boolean }>; - - /** - * A Shipment can be retrieved by either its id or reference. - * However, it is recommended to use EasyPost's provided identifiers because uniqueness on reference is not enforced. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-shipment - * - * @param {string} id Unique, begins with "shp_". - * @returns {Promise} The created {@link Shipment}. - */ - static retrieve(id: string): Promise; - - /** - * To purchase a Shipment you only need to specify the Rate to purchase. - * This operation populates the `tracking_code` and `postage_label` attributes. - * The default image format of the associated PostageLabel is PNG. - * To change this default see the label_format option. - * - * Additionally, insurance may be added during the purchase. - * To specify an amount to insure, pass the insurance attribute as a string. - * The currency of all insurance is USD. - * - * @see https://www.easypost.com/docs/api/node#buy-a-shipment - * - * @param id shipment id (begins with "shp_"). - * @param rate rate id (begins with "rate_") or rate object. - * @param insuranceAmount amount to insure the shipment for. - * @returns {Promise} The created {@link Shipment}. - */ - static buy(id: string, rate: string | IRate, insuranceAmount?: number): Promise; - - /** - * Refunding a Shipment is available for many carriers supported by EasyPost. - * Once the refund has been submitted, refund_status attribute of the Shipment will be populated with one of the possible values: "submitted", "refunded", "rejected". - * The most common initial status is "submitted". - * Many carriers require that the refund be processed before the `refund_status` will move to "refunded". - * The length of this process depends on the carrier, but no greater than 30 days. - * - * Refunds created very shortly after a label is generated may be improperly flagged as invalid, but you may retry a refund with the "rejected" status by submitting the same request again. - * Carriers that are bill-on-scan tend to have refunds attempts return as "not_applicable", which will not change with multiple retries. - * - * @see https://www.easypost.com/docs/api/node#refund-a-shipment - * - * @param id shipment id (begins with "shp_"). - * @returns {Promise} The created {@link Shipment}. - */ - static refund(id: string): Promise; - - /** - * - * @param carriers a list of carriers to filter rates for. - * @param services a list of services to filter rates for. - * @returns {Rate} The lowest {@link Rate}. - */ - lowestRate(carriers?: string[], services?: string[]): IRate; - - /** - * A Shipment's PostageLabel can be converted from PNG to other formats. - * If the PostageLabel was originally generated in a format other than PNG it cannot be converted. - * - * @see https://www.easypost.com/docs/api/node#convert-the-label-format-of-a-shipment - * - * @param id shipment id (begins with "shp_"). - * @param format Format of the label ("PNG", "PDF", "ZPL", and "EPL2"). - * @returns {Promise} The created {@link Shipment}. - */ - static convertLabelFormat(id: string, format: LabelFormat): Promise; - - /** - * You can update the Rates of a Shipment at any time. - * This operation respects the `carrier_accounts` attribute. - * - * @see https://www.easypost.com/docs/api/node#regenerate-rates-for-a-shipment - * - * @param id shipment id (begins with "shp_"). - * @returns {Promise} The created {@link Shipment}. - */ - static regenerateRates(id: string): Promise; - - /** - * Insuring your Shipment is as simple as sending us the value of the contents. - * We charge 1% of the value, with a $1 minimum, and handle all the claims. - * All our claims are paid out within 10 days. - * - * To buy insurance, first purchase the Shipment, then make the insurance call before the package begins being handled by the carrier. - * - * @see https://www.easypost.com/docs/api/node#insure-a-shipment - * - * @param id shipment id (begins with "shp_"). - * @param amount amount to insure the shipment for. - * @returns {Promise} The created {@link Shipment}. - */ - static insure(id: string, amount: number): Promise; - - /** - * Generate a specific type of form for the Shipment, using the provided form options. - * - * @param id shipment id (begins with "shp_"). - * @param formType The type of form to generate. - * @param formOptions Additional options to use when generating the form. - * @returns {Promise} The created {@link Shipment}. - */ - static generateForm(id: string, formType: string, formOptions?: object): Promise; - - /** - * Retrieves the estimated delivery date of each Rate via SmartRate. - * - * @param id shipment id (begins with "shp_"). - * @param plannedShipDate The planned ship date in format YYYY-MM-DD - * @returns {Promise>} The array of estimated delivery dates and rates. - */ - static retrieveEstimatedDeliveryDate(id: string, plannedShipDate: string): Promise>; - - /** - * Retrieve the next page of {@link Shipment shipments}. - * - * This automatically reuses the parameters from the previous call or the original {@link Shipment.all} call. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments - * - * @param {Object} shipments - The previous page of shipments (the response from the last {@link Shipment.getNextPage} or {@link Shipment.all} call). - * @param {number} [pageSize] - The number of shipments to retrieve per page, optional. Defaults to server-side default. - * @returns {Object} - An object containing a list of {@link Shipment shipments} and pagination information. - */ - static getNextPage( - shipments: Object, - pageSize?: number, - ): Promise<{ shipments: Shipment[]; has_more: boolean }>; -} diff --git a/types/Shipment/index.d.ts b/types/Shipment/index.d.ts deleted file mode 100644 index b500d0186..000000000 --- a/types/Shipment/index.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -export * from './Form'; -export * from './Message'; -export * from './Options'; -export * from './PostageLabel'; -export * from './Rate'; -export * from './Shipment'; -export * from './ShipmentCreateParameters'; -export * from './ShipmentListParameters'; diff --git a/types/Tracker/Tracker.d.ts b/types/Tracker/Tracker.d.ts deleted file mode 100644 index 74e85f86b..000000000 --- a/types/Tracker/Tracker.d.ts +++ /dev/null @@ -1,184 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../base'; -import { IFee } from '../Fee'; -import { ICarrierDetail } from './CarrierDetail'; -import { ITrackerCreateParameters } from './TrackerCreateParameters'; -import { ITrackerListParameters } from './TrackerListParameters'; -import { ITrackerStatus } from './TrackerStatus'; -import { ITrackerStatusDetail } from './TrackerStatusDetail'; -import { ITrackingDetail } from './TrackingDetail'; - -/** - * A Tracker object contains all the tracking information for a package. - * A Tracker is created automatically whenever you buy a Shipment through EasyPost. - * If you don't use EasyPost to purchase your shipping labels, you can still track packages through our API by creating a Tracker object directly. - * Each Tracker is continually updated in the background as the package moves through its life cycle, regardless of whether or not the label was purchased through EasyPost. - * - * After creation, a Tracker object will be updated periodically based on when the carrier provides EasyPost with new tracking information. - * This information can be consumed by using our webhooks infrastructure. - * Every time a Tracker is updated a webhook Event will be sent. - * - * The Tracker object contains both the current information about the package and previous updates. - * All the previous updates are stored in the tracking_details array. - * Each TrackingDetail object contains the status, the message from the carrier, and a TrackingLocation. - * - * The TrackingLocation contains city, state, country, and zip information about the location where the package was scanned. - * The information each carrier provides is different, so some carriers may not make use of all these fields. - * - * Some Tracker objects may also contain a CarrierDetail, which stores some additional information about the Tracker that the carrier has made available to EasyPost. - * The CarrierDetail object contains the service and container_type of the package. - * Additionally, it also stores the `est_delivery_date_local` and `est_delivery_time_local`, which provide information about the local delivery time. - * - * It's worth noting that tracking_codes are not globally unique. - * Each carrier promises uniqueness for a given `tracking_code` for a certain period of time, but the length of time varies greatly based on the specific carrier and service level. - * The carriers do eventually recycle `tracking_codes`, and for this reason enforcing uniqueness on the `tracking_code` field is not recommended. - * EasyPost does, however, prevent the creation of duplicate Trackers based on tracking_code and carrier; duplicate requests by the same User will simply return the original Tracker. - * - * @see https://www.easypost.com/docs/api/node#tracker-object - */ -export declare interface ITracker extends IObjectWithId<'Tracker'>, IDatedObject { - /** - * The tracking code provided by the carrier - */ - tracking_code: string; - - /** - * The current status of the package, possible values are "unknown", "pre_transit", "in_transit", "out_for_delivery", "delivered", "available_for_pickup", "return_to_sender", "failure", "cancelled" or "error" - */ - status: ITrackerStatus; - - /** - * Additional details about the current status, possible values are "unknown", "status_update", "departed_facility", "arrived_at_facility", "out_for_delivery", "arrived_at_destination" - */ - status_detail: ITrackerStatusDetail; - - /** - * The name of the person who signed for the package (if available) - */ - signed_by: string; - - /** - * The weight of the package as measured by the carrier in ounces (if available) - * float (oz) - */ - weight: number; - - /** - * The estimated delivery date provided by the carrier (if available) - */ - est_delivery_date: string; // TODO maybe type should be Date? - - /** - * The id of the EasyPost Shipment object associated with the Tracker (if any) - */ - shipment_id: string; - - /** - * The name of the carrier handling the shipment - */ - carrier: string; - - /** - * Array of the associated TrackingDetail objects - */ - tracking_details: ITrackingDetail[]; - - /** - * The associated CarrierDetail object (if available) - */ - carrier_detail: ICarrierDetail; - - /** - * URL to a publicly-accessible html page that shows tracking details for this tracker - */ - public_url: string; - - /** - * Array of the associated Fee objects - */ - fees: IFee[]; -} - -export declare class Tracker implements ITracker { - public constructor(input: ITrackerCreateParameters); - - id: string; - mode: 'test' | 'production'; - object: 'Tracker'; - tracking_code: string; - status: ITrackerStatus; - status_detail: ITrackerStatusDetail; - signed_by: string; - weight: number; - est_delivery_date: string; - shipment_id: string; - carrier: string; - tracking_details: ITrackingDetail[]; - carrier_detail: ICarrierDetail; - public_url: string; - fees: IFee[]; - created_at: string; - updated_at: string; - - /** - * A Tracker can be created with only a tracking_code. - * Optionally, you can provide the carrier parameter, which indicates the carrier the package was shipped with. - * If no carrier is provided, EasyPost will attempt to determine the carrier based on the tracking_code provided. - * Providing a carrier parameter is recommended, since some tracking_codes are ambiguous and may match with more than one carrier. - * In addition, not having to auto-match the carrier will significantly speed up the response time. - * - * In an effort to reduce wasted resources, EasyPost prevents the creation of duplicate Trackers. - * A Tracker is considered to be a duplicate if another Tracker with the same tracking_code and carrier was created by the same User in the last three months. - * In the case where a duplicate request is submitted, the original Tracker will be returned. - * - * @see https://www.easypost.com/docs/api/node#create-a-tracker - * - * @param {Object} params The parameters to create an {@link Tracker} with. - * @returns {Promise} The {@link Tracker}. - */ - static create(params: Object): Promise; - - /** - * The Tracker List is a paginated list of all Tracker objects associated with the given API Key. - * It accepts a variety of parameters which can be used to modify the scope. - * The `has_more` attribute indicates whether or not additional pages can be requested. - * The recommended way of paginating is to use either the `before_id` or `after_id` parameter to specify where the next page begins. - * - * Using the Tracker List endpoint is the recommended way of retrieving a Tracker by `tracking_code` or `carrier`. - * Unlike the retrieving a Tracker using the Retrieve endpoint, which accepts an id, the List endpoint accepts the tracking_code as the search parameter. - * Normally, you'll only have one Tracker with a given `tracking_code`, but it is also possible to further filter those results by including the carrier parameter in your request. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-trackers - * - * @param params - The parameters to use for the request. - * @returns {Object} - An object containing a list of {@link Tracker trackers} and pagination information. - */ - static all(params?: ITrackerListParameters): Promise<{ trackers: Tracker[]; has_more: boolean }>; - - /** - * Retrieve a Tracker by id. - * - * @param trackerId Unique, starts with "trk_" - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-tracker - * - * @param trackerId The id of tracker, starts with "trk_" - * @returns {Promise} The retrieved {@link Tracker}. - */ - static retrieve(trackerId: string): Promise; - - /** - * Retrieve the next page of {@link Tracker trackers}. - * - * This automatically reuses the parameters from the previous call or the original {@link Tracker.all} call. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-trackers - * - * @param {Object} trackers - The previous page of trackers (the response from the last {@link Tracker.getNextPage} or {@link Tracker.all} call). - * @param {number} [pageSize] - The number of trackers to retrieve per page, optional. Defaults to server-side default. - * @returns {Object} - An object containing a list of {@link Tracker trackers} and pagination information. - */ - static getNextPage( - trackers: Object, - pageSize?: number, - ): Promise<{ trackers: Tracker[]; has_more: boolean }>; -} diff --git a/types/Tracker/TrackerStatus.d.ts b/types/Tracker/TrackerStatus.d.ts deleted file mode 100644 index 2b2291981..000000000 --- a/types/Tracker/TrackerStatus.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export declare type ITrackerStatus = - | 'unknown' - | 'pre_transit' - | 'in_transit' - | 'out_for_delivery' - | 'delivered' - | 'available_for_pickup' - | 'return_to_sender' - | 'failure' - | 'cancelled' - | 'error'; diff --git a/types/Tracker/TrackerStatusDetail.d.ts b/types/Tracker/TrackerStatusDetail.d.ts deleted file mode 100644 index 7f7d5e3a8..000000000 --- a/types/Tracker/TrackerStatusDetail.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -export declare type ITrackerStatusDetail = - | 'address_correction' - | 'arrived_at_destination' - | 'arrived_at_facility' - | 'arrived_at_pickup_location' - | 'awaiting_information' - | 'cancelled' - | 'damaged' - | 'delayed' - | 'delivery_exception' - | 'departed_facility' - | 'departed_origin_facility' - | 'expired' - | 'failure' - | 'held' - | 'in_transit' - | 'label_created' - | 'lost' - | 'missorted' - | 'out_for_delivery' - | 'received_at_destination_facility' - | 'received_at_origin_facility' - | 'refused' - | 'return' - | 'status_update' - | 'transferred_to_destination_carrier' - | 'transit_exception' - | 'unknown' - | 'weather_delay'; diff --git a/types/Tracker/index.d.ts b/types/Tracker/index.d.ts deleted file mode 100644 index 984c3f378..000000000 --- a/types/Tracker/index.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -export * from './CarrierDetail'; -export * from './Tracker'; -export * from './TrackerStatus'; -export * from './TrackingDetail'; -export * from './TrackingLocation'; -export * from './TrackerCreateParameters'; -export * from './TrackerListParameters'; diff --git a/types/User/User.d.ts b/types/User/User.d.ts deleted file mode 100644 index 5e2a7ec47..000000000 --- a/types/User/User.d.ts +++ /dev/null @@ -1,190 +0,0 @@ -import { IObjectWithId } from '../base'; -import { IUserCreateParameters } from './UserCreateParameters'; - -/** - * The User object can be used to manage your own account and to create child accounts. - * Only a Production mode API key can be used to make requests against the Users API. - * - * Balance and recharge values on User objects are expressed in higher precision USD. - * - * @see https://www.easypost.com/docs/api/node#user-object - */ -export declare interface IUser extends IObjectWithId<'User'> { - /** - * The ID of the parent user object. - * Top-level users are defined as users with no parent - */ - parent_id: string; - - /** - * First and last name required - */ - name: string; - - /** - * Required - */ - email: string; - - /** - * Optional - */ - phone_number?: string | null; - - /** - * Formatted as string "XX.XXXXX" - */ - balance: string; - - /** - * Cost per shipment purchase, formatted as string "XX.XXXXX" - */ - price_per_shipment: string; - /** - * USD formatted dollars and cents, delimited by a decimal point - */ - recharge_amount: string; - - /** - * USD formatted dollars and cents, delimited by a decimal point - */ - secondary_recharge_amount: string; - - /** - * Number of cents USD that when your balance drops below, we automatically recharge your account with your primary payment method. - */ - recharge_threshold: string; - - /** - * The fee rate for convenience fees - */ - cc_fee_rate: string; - - /** - * The fee rate for insurance purchases - */ - insurance_fee_rate: string; - - /** - * The minimum cost for insurance purchases - */ - insurance_fee_minimum: string; - - /** - * All associated children - */ - children: IUser[]; -} - -export declare class User implements IUser { - public constructor(input: IUserCreateParameters); - - id: string; - mode: 'test' | 'production'; - object: 'User'; - reference?: string | null; - parent_id: string; - name: string; - email: string; - phone_number?: string | null; - balance: string; - price_per_shipment: string; - recharge_amount: string; - secondary_recharge_amount: string; - recharge_threshold: string; - cc_fee_rate: string; - insurance_fee_rate: string; - insurance_fee_minimum: string; - children: IUser[]; - - /** - * Creates a child user. - * - * @see https://www.easypost.com/docs/api/node#create-a-child-user - * @requires production API Key. - * - * @param {Object} params The parameters to create an {@link User} with. - * @returns {Promise} The created User. - */ - static create(params: Object): Promise; - - /** - * Retrieve a child user. - * @requires production API Key. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-user - * - * @param {string} id ID of the child user to retrieve - * @param urlPrefix Override the prefix to use for the request URL, optional - * @returns {Promise} The associated User. - */ - static retrieve(id: string, urlPrefix: string): Promise; - - /** - * Retrieve the current authenticated user. - * @requires production API Key. - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-user - * - * @returns {Promise} The current authenticated user. - */ - static retrieveMe(): Promise; - - /** - * Just like retrieving a User they can be updated using the same patterns. - * Passing an id will allow the update of a child or the authenticated User. - * Passing no id will update the authenticated User. - * Since children also have the ability to authenticate themselves they can be updated without passing an id. - * Children may only have their "name" field updated, all other fields are ignored. - * Update requests for Users are partial updates. Only attributes specifically passed in will be updated. - * The current_password attribute is required when updating email or password. - * - * @see https://www.easypost.com/docs/api/node#update-a-user - * @requires production API Key. - * - * @param id The id of the user - * @param params The parameters to update the {@link User} with - * @returns {Promise} The associated User. - */ - static update(id: string, params: Object): Promise; - - /** - * Childen may be removed from its parent. The parent account's Production API key must be used for the request, - * a child may not remove itself from its parent. - * A successful delete will return HTTP status 204 and an empty object for JSON content. - * @param id The id of the users - * @requires production API Key. - */ - static delete(id: string): void; - - /** - * Retrieve a list of all children user. - * - * The Children List is a paginated list of all {@link User} objects associated with the given API Key. - * It accepts a variety of parameters which can be used to modify the scope. - * The has_more attribute indicates whether additional pages can be requested. - * The recommended way of paginating is to use either the `before_id` or `after_id` parameter to specify where the next page begins. - * - * @see https://www.easypost.com/docs/api/node#child-users - * - * @param {Object} params - The parameters to use for the request. - * @returns {Object} - An object containing a list of {@link Children children} and pagination information. - */ - static allChildren(params: Object): Promise<{ children: User[]; has_more: boolean }>; - - /** - * Retrieve the next page of {@link User child users}. - * - * This automatically reuses the parameters from the previous call or the original {@link User.allChildren} call. - * - * @see https://www.easypost.com/docs/api/node#child-users - * - * @param {Object} children - The previous page of child users (the response from the last {@link User.getNextPage} or {@link User.allChildren} call). - * @param {number} [pageSize] - The number of child users to retrieve per page, optional. Defaults to server-side default. - * @returns {Object} - An object containing a list of {@link User child users} and pagination information. - */ - static getNextPage( - children: Object, - pageSize?: number, - ): Promise<{ children: User[]; has_more: boolean }>; -} diff --git a/types/User/UserCreateParameters.d.ts b/types/User/UserCreateParameters.d.ts deleted file mode 100644 index d9bc3cc78..000000000 --- a/types/User/UserCreateParameters.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { ParametersToOmitOnCreate } from '../utils'; -import { IUser } from './User'; - -export declare interface IUserCreateParameters extends Omit {} diff --git a/types/User/index.d.ts b/types/User/index.d.ts deleted file mode 100644 index f6b9f36c6..000000000 --- a/types/User/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './User'; diff --git a/types/Utility/Utils.d.ts b/types/Utility/Utils.d.ts deleted file mode 100644 index 12912e396..000000000 --- a/types/Utility/Utils.d.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Rate } from '../Rate'; - -/** - * The Utils class represents a number of helper methods for the client library. - */ -export declare class Utils { - /** - * Get the lowest SmartRate from a provided list of SmartRates. - * @public - * @param smartrates List of SmartRates to filter through - * @param deliveryDays The maximum number of days allowed for delivery - * @param deliveryAccuracy The target level of accuracy for the delivery days (e.g. 'percentile_95') - * @returns The lowest SmartRate - * @throws FilteringError If no applicable rates are found - * @throws InvalidParameterError If the deliveryAccuracy value is invalid - */ - static getLowestSmartRate( - smartrates: Rate[], - deliveryDays: number, - deliveryAccuracy: string, - ): Rate; - - /** - * Get the lowest rate from a provided list of rates. - * @public - * @param rates List of rates to filter through - * @param carriers List of carriers to filter by - * @param services List of services to filter by - * @returns The lowest rate - * @throws FilteringError If no applicable rates are found - */ - static getLowestRate(rates: Rate[], carriers?: string[], services?: string[]): Rate; - - /** - * Validate a webhook by comparing the HMAC signature header sent from EasyPost to your shared secret. - * If the signatures do not match, an error will be raised signifying the webhook either did not originate - * from EasyPost or the secrets do not match. If the signatures do match, the `event_body` will be returned - * as JSON. - * @public - * @param eventBody The raw body of the webhook event - * @param headers The headers of the webhook HTTP request - * @param webhookSecret The webhook secret shared between EasyPost and your application - * @returns The JSON-parsed webhook event body if the signature could be verified - * @throws SignatureVerificationError If the signature could not be verified - */ - static validateWebhook(eventBody: Buffer, headers: object, webhookSecret: string): object; -} diff --git a/types/Utility/index.d.ts b/types/Utility/index.d.ts deleted file mode 100644 index 6a46623dc..000000000 --- a/types/Utility/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './Utils'; diff --git a/types/Webhook/Webhook.d.ts b/types/Webhook/Webhook.d.ts deleted file mode 100644 index 168de8988..000000000 --- a/types/Webhook/Webhook.d.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { IObjectWithId } from '../base'; -import { IWebhookCreateParameters } from './WebhookCreateParameters'; -import { IWebhookListParameters } from './WebhookListParameters'; - -/** - * Each Webhook contains the url which EasyPost will notify whenever an object in our system updates. - * Several types of objects are processed asynchronously in the EasyPost system, so whenever an object updates, an Event is sent via HTTP POST to each configured webhook URL. - * The Webhook object provides CRUD operations for all Webhooks. - * - * Currently, our recommended best practice for securing Webhooks involves using basic authentication and HTTPS on your endpoint. - * This will help prevent any altering of any information communicated to you by EasyPost, prevent any third parties from seeing your webhooks in transit, and will prevent any third parties from masquerading as EasyPost and sending fraudulent data. - * EasyPost performs certificate validation and requires any TLS-enabled (HTTPS) webhook recipients to have a certificate signed by a public trusted certification authority. - * We do not support sending webhooks to over SSLv2, SSLv3, or any connection using so-called export-grade ciphers. - * For documentation on how to set up your server with TLS, we recommend Mozilla's guide to Server-Side TLS and Qualys's SSL/TLS deployment best practices guide. - * - * In general, a Webhook's endpoint should return a status code of 2XX. - * A 200 is preferred, but any 2XX status will indicate to our system that the Webhook request was successful. - * Endpoints that return a large volume and rate of failures over a period of time will get automatically disabled by the system; a disabled Webhook can be re-enabled using the Webhook update endpoint. - * - * @see https://www.easypost.com/docs/api/node#webhook-object - */ -export declare interface IWebhook extends IObjectWithId<'Webhook'> { - /** - * http://example.com - */ - url: string; - - /** - * the timestamp at which the webhook was most recently disabled (if any) - */ - disabled_at: string; -} - -export declare class Webhook implements IWebhook { - public constructor(input: IWebhookCreateParameters); - - url: string; - disabled_at: string; - id: string; - mode: 'test' | 'production'; - object: 'Webhook'; - - /** - * To create a Webhook, you simply need to provide a url parameter that you wish to receive notifications to. - * - * @see https://www.easypost.com/docs/api/node#create-a-webhook - * - * @param {Object} params The parameters to create an {@link Webhook} with - * @returns {Promise} The created and verified {@link Webhook} - */ - static create(params: Object): Promise; - - /** - * Enables a Webhook that has been disabled. You can also secure your webhook by adding a webhook_secret. - * - * @see https://www.easypost.com/docs/api/node#update-a-webhook - * - * @param webhookId Unique, starts with "hook_" - * @param params The parameters to update an {@link Webhook} with - * @returns {Promise} The created and verified {@link Webhook} - */ - static update(webhookId: string, params: Object): Promise; - - /** - * Retrieve an unpaginated list of all Webhooks available to the authenticated account. - * - * @see https://www.easypost.com/docs/api/node#list-a-webhooks - * - * @param {Object} params - The parameters to use for the request. - * @returns {Object} - An object containing a list of {@link Webhook webhooks} and pagination information. - */ - static all(params?: IWebhookListParameters): Promise<{ webhooks: Webhook[] }>; - - /** - * Retrieve a Webhook by id. - * - * @param webhookId Unique, starts with "hook_" - * - * @see https://www.easypost.com/docs/api/node#retrieve-a-webhook - * - * @returns {Promise} The created and verified {@link Webhook} - */ - static retrieve(webhookId: string): Promise; - - /** - * Delete a Webhook by id. - * - * @param webhookId Unique, starts with "hook_" - * - * @see https://www.easypost.com/docs/api/node#delete-a-webhook - */ - static delete(webhookId: string): void; -} diff --git a/types/Webhook/WebhookCreateParameters.d.ts b/types/Webhook/WebhookCreateParameters.d.ts deleted file mode 100644 index 0c22692f9..000000000 --- a/types/Webhook/WebhookCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export declare interface IWebhookCreateParameters { - url: string; -} diff --git a/types/Webhook/WebhookListParameters.d.ts b/types/Webhook/WebhookListParameters.d.ts deleted file mode 100644 index 3307e35ad..000000000 --- a/types/Webhook/WebhookListParameters.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IAllMethodParameters } from '../utils'; - -/** - * @see https://www.easypost.com/docs/api/node#list-a-webhooks - */ -export declare interface IWebhookListParameters extends IAllMethodParameters {} diff --git a/types/Webhook/index.d.ts b/types/Webhook/index.d.ts deleted file mode 100644 index 38a45b80b..000000000 --- a/types/Webhook/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './Webhook'; -export * from './WebhookCreateParameters'; diff --git a/types/base.d.ts b/types/base.d.ts deleted file mode 100644 index 3a47f43c7..000000000 --- a/types/base.d.ts +++ /dev/null @@ -1,32 +0,0 @@ -export declare interface IDatedObject { - /** - * Date ISO String - */ - created_at: string; - - /** - * Date ISO String - */ - updated_at: string; -} - -export declare interface IBaseObject { - object: ObjectName; -} - -export declare interface IObjectWithId extends IBaseObject { - /** - * Unique identifier, begins with "adr_" / "prcl_" / "ins_" / "trk_" / "batch_" / "cstinfo_" / etc - */ - id: string; - - /** - * Set based on which api-key you used, either "test" or "production" - */ - mode: 'test' | 'production'; - - /** - * The object name, e.g. "Address", "Rate", "Shipment", etc - */ - object: ObjectName; -} diff --git a/types/demo/README.md b/types/demo/README.md deleted file mode 100644 index 61eb856f1..000000000 --- a/types/demo/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Typescript Demo - -This is a simple project to demonstrate and test how to use the EasyPost Typescript definitions. diff --git a/types/demo/index.ts b/types/demo/index.ts deleted file mode 100644 index a977310c0..000000000 --- a/types/demo/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import EasyPostClient from '@easypost/api'; - -// This file is intended to demo how you could use the EasyPost Typescript definitions. -(async () => { - const client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); - - const customsInfo = await client.CustomsInfo.retrieve('cstinfo_...'); - - console.log(customsInfo); -})(); diff --git a/types/demo/package-lock.json b/types/demo/package-lock.json deleted file mode 100644 index e43f9686d..000000000 --- a/types/demo/package-lock.json +++ /dev/null @@ -1,322 +0,0 @@ -{ - "name": "demo", - "version": "1.0.0", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "name": "demo", - "version": "1.0.0", - "license": "ISC", - "dependencies": { - "@easypost/api": "file:../" - }, - "devDependencies": { - "ts-node": "10.7.0", - "typescript": "4.6.3" - } - }, - "..": {}, - "node_modules/@cspotcode/source-map-consumer": { - "version": "0.8.0", - "resolved": "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz", - "integrity": "sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==", - "dev": true, - "engines": { - "node": ">= 12" - } - }, - "node_modules/@cspotcode/source-map-support": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz", - "integrity": "sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==", - "dev": true, - "dependencies": { - "@cspotcode/source-map-consumer": "0.8.0" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/@easypost/api": { - "resolved": "..", - "link": true - }, - "node_modules/@tsconfig/node10": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", - "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", - "dev": true - }, - "node_modules/@tsconfig/node12": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", - "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", - "dev": true - }, - "node_modules/@tsconfig/node14": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", - "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", - "dev": true - }, - "node_modules/@tsconfig/node16": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.3.tgz", - "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", - "dev": true - }, - "node_modules/@types/node": { - "version": "18.11.18", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz", - "integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==", - "dev": true, - "peer": true - }, - "node_modules/acorn": { - "version": "8.8.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz", - "integrity": "sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==", - "dev": true, - "bin": { - "acorn": "bin/acorn" - }, - "engines": { - "node": ">=0.4.0" - } - }, - "node_modules/acorn-walk": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", - "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", - "dev": true, - "engines": { - "node": ">=0.4.0" - } - }, - "node_modules/arg": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", - "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", - "dev": true - }, - "node_modules/create-require": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", - "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", - "dev": true - }, - "node_modules/diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", - "dev": true, - "engines": { - "node": ">=0.3.1" - } - }, - "node_modules/make-error": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", - "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", - "dev": true - }, - "node_modules/ts-node": { - "version": "10.7.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.7.0.tgz", - "integrity": "sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A==", - "dev": true, - "dependencies": { - "@cspotcode/source-map-support": "0.7.0", - "@tsconfig/node10": "^1.0.7", - "@tsconfig/node12": "^1.0.7", - "@tsconfig/node14": "^1.0.0", - "@tsconfig/node16": "^1.0.2", - "acorn": "^8.4.1", - "acorn-walk": "^8.1.1", - "arg": "^4.1.0", - "create-require": "^1.1.0", - "diff": "^4.0.1", - "make-error": "^1.1.1", - "v8-compile-cache-lib": "^3.0.0", - "yn": "3.1.1" - }, - "bin": { - "ts-node": "dist/bin.js", - "ts-node-cwd": "dist/bin-cwd.js", - "ts-node-esm": "dist/bin-esm.js", - "ts-node-script": "dist/bin-script.js", - "ts-node-transpile-only": "dist/bin-transpile.js", - "ts-script": "dist/bin-script-deprecated.js" - }, - "peerDependencies": { - "@swc/core": ">=1.2.50", - "@swc/wasm": ">=1.2.50", - "@types/node": "*", - "typescript": ">=2.7" - }, - "peerDependenciesMeta": { - "@swc/core": { - "optional": true - }, - "@swc/wasm": { - "optional": true - } - } - }, - "node_modules/typescript": { - "version": "4.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", - "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=4.2.0" - } - }, - "node_modules/v8-compile-cache-lib": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", - "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", - "dev": true - }, - "node_modules/yn": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", - "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", - "dev": true, - "engines": { - "node": ">=6" - } - } - }, - "dependencies": { - "@cspotcode/source-map-consumer": { - "version": "0.8.0", - "resolved": "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz", - "integrity": "sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==", - "dev": true - }, - "@cspotcode/source-map-support": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz", - "integrity": "sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==", - "dev": true, - "requires": { - "@cspotcode/source-map-consumer": "0.8.0" - } - }, - "@easypost/api": { - "version": "file:.." - }, - "@tsconfig/node10": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", - "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", - "dev": true - }, - "@tsconfig/node12": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", - "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", - "dev": true - }, - "@tsconfig/node14": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", - "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", - "dev": true - }, - "@tsconfig/node16": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.3.tgz", - "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", - "dev": true - }, - "@types/node": { - "version": "18.11.18", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz", - "integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==", - "dev": true, - "peer": true - }, - "acorn": { - "version": "8.8.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz", - "integrity": "sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==", - "dev": true - }, - "acorn-walk": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", - "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", - "dev": true - }, - "arg": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", - "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", - "dev": true - }, - "create-require": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", - "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", - "dev": true - }, - "diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", - "dev": true - }, - "make-error": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", - "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", - "dev": true - }, - "ts-node": { - "version": "10.7.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.7.0.tgz", - "integrity": "sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A==", - "dev": true, - "requires": { - "@cspotcode/source-map-support": "0.7.0", - "@tsconfig/node10": "^1.0.7", - "@tsconfig/node12": "^1.0.7", - "@tsconfig/node14": "^1.0.0", - "@tsconfig/node16": "^1.0.2", - "acorn": "^8.4.1", - "acorn-walk": "^8.1.1", - "arg": "^4.1.0", - "create-require": "^1.1.0", - "diff": "^4.0.1", - "make-error": "^1.1.1", - "v8-compile-cache-lib": "^3.0.0", - "yn": "3.1.1" - } - }, - "typescript": { - "version": "4.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", - "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==", - "dev": true - }, - "v8-compile-cache-lib": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", - "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", - "dev": true - }, - "yn": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", - "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", - "dev": true - } - } -} diff --git a/types/demo/package.json b/types/demo/package.json deleted file mode 100644 index d4a6c7c13..000000000 --- a/types/demo/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "demo", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "ts-node src/index.ts" - }, - "keywords": [], - "author": "", - "license": "ISC", - "dependencies": { - "@easypost/api": "file:../" - }, - "devDependencies": { - "typescript": "4.6.3", - "ts-node": "10.7.0" - } -} diff --git a/types/errors/ErrorCode.d.ts b/types/errors/ErrorCode.d.ts deleted file mode 100644 index 7fef599e2..000000000 --- a/types/errors/ErrorCode.d.ts +++ /dev/null @@ -1,174 +0,0 @@ -// TODO: there seems to be a lot of duplicate codes listed here https://www.easypost.com/errors-guide -export declare type TErrorCode = - | 'ADDRESS.COUNTRY.INVALID' - | 'ADDRESS.PARAMETERS.INVALID_CHARACTER' - | 'ADDRESS.PARAMETERS.INVALID' - | 'ADDRESS.VERIFICATION.FAILURE' - | 'ADDRESS.VERIFICATION.INVALID' - | 'ADDRESS.VERIFICATION.NOT_FOUND' - | 'ADDRESS.VERIFY.CARRIER_INVALID' - | 'ADDRESS.VERIFY.FAILURE' - | 'ADDRESS.VERIFY.INTL_NOT_ENABLED' - | 'ADDRESS.VERIFY.MISSING_CITY_STATE_ZIP' - | 'ADDRESS.VERIFY.MISSING_STREET' - | 'ADDRESS.VERIFY.ONLY_US' - | 'ADDRESS.VERIFY.UNAVAILABLE' - | 'ADDRESS.VERIFY.UPSTREAM_UNAVAILABLE' - | 'BAD_REQUEST' - | 'BANK_ACCOUNT.CHARGE.FAILURE' - | 'BANK_ACCOUNT.VERIFY.FAILURE' - /** - * The typo "FORAMT" is in both the docs and api error response. - * @link https://github.com/EasyPost/easypost-node/pull/156#discussion_r819811282 - */ - | 'BATCH.FILE_FORAMT.INVALID' - | 'BATCH.PARAMS.INVALID' - | 'BATCH.SHIPMENT.MISSING' - | 'BATCH.SHIPMENT.TOO_LARGE' - | 'BATCH.SHIPMENTS.REQUIRED' - | 'BATCH.STATE.ALREADY_PURCHASED' - | 'BATCH.STATE.CREATING' - | 'BATCH.STATE.CREATION_FAILED' - | 'BATCH.STATE.NOT_PURCHASED' - | 'CARRIER_ACCOUNT.INVALID' - | 'CARRIER_ACCOUNT.PARAMETERS.INVALID' - | 'CARRIER_ACCOUNT.REGISTRATION.FAILED' - | 'CARRIER_ACCOUNT.TYPE.EXISTS' - | 'CARRIER_ACCOUNT.TYPE.UNKNOWN' - | 'CONTAINER.DIMENSION.REQUIRED' - | 'CONTAINER.NAME.REQUIRED' - | 'CONTAINER.TYPE.INVALID' - | 'CREDIT_CARD.CHARGE.FAILURE' - | 'CREDIT_CARD.INVALID' - | 'CUSTOMS_INFO.PARAMETERS.INVALID' - | 'CUSTOMS_ITEM.CURRENCY.ONE_CURRENCY_SUPPORTED' - | 'CUSTOMS_ITEM.ORIGIN_COUNTRY.REQUIRED' - | 'CUSTOMS_ITEM.PARAMETERS.INVALID' - | 'DATE.PARSE.FAILURE' - | 'DHLGM.ACCESS_TOKEN.GENERATION_FAILED' - | 'DHLGM.GIRTH_MAX' - | 'DHLGM.LABEL.FAILURE' - | 'DHLGM.LETTER_NOT_SUPPORTED' - | 'DHLGM.NO_ALCOHOL' - | 'DHLGM.NO_INTERNATIONAL' - | 'DHLGM.RATE_TABLE.NOT_FOUND' - | 'DHLGM.RETURN.AUTHORIZATION_NUMBER_REQUIRED' - | 'DHLGM.SCAN_FORM.GENERATION_FAILED' - | 'DOCUMENT.COMMERCIAL_INVOICE.FAILURE' - | 'DOCUMENT.CONVERSION.FAILURE' - | 'EMAIL_VERIFICATION.EXPIRED' - | 'EMAIL_VERIFICATION.NOT_FOUND' - | 'EMAIL_VERIFICATION.USED' - | 'FORBIDDEN' - | 'IMAGE.CONVERSION.FAILURE' - | 'IMAGE.WIDTH.INVALID' - | 'INSURANCE.AMOUNT.ABOVE_MAXIMUM' - | 'INSURANCE.AMOUNT.BELOW_MINIMUM' - | 'INSURANCE.AMOUNT.REQUIRED' - | 'INSURANCE.CREATE.FAILURE' - | 'INSURANCE.PARAMETERS.INVALID' - | 'INSURANCE.PURCHASE.FAILED' - | 'INSURANCE.PURCHASE.NOT_ALLOWED' - | 'INTERNAL_SERVER_ERROR' - | 'ITEM.HEIGHT.REQUIRED' - | 'ITEM.LENGTH.REQUIRED' - | 'ITEM.NAME.REQUIRED' - | 'ITEM.VALUE.REQUIRED' - | 'ITEM.WEIGHT.REQUIRED' - | 'ITEM.WIDTH.REQUIRED' - | 'MODE.CONFLICT' - | 'MODE.UNAUTHORIZED' - | 'NOT_ACCEPTABLE' - | 'NOT_FOUND' - | 'ORDER.CARRIER_ACCOUNTS.CONFLICT' - | 'ORDER.CARRIER.REQUIRED' - | 'ORDER.FROM_ADDRESS.REQUIRED' - | 'ORDER.INVALID' - | 'ORDER.LABEL_DATE.INVALID' - | 'ORDER.OPTIONS.INVALID' - | 'ORDER.PARAMS.REQUIRED' - | 'ORDER.RATE.UNAVAILABLE' - | 'ORDER.SERVICE.REQUIRED' - | 'ORDER.SHIPMENTS.REQUIRED' - | 'ORDER.TO_ADDRESS.REQUIRED' - | 'PARAMETER.FORBIDDEN' - | 'PARAMETER.REQUIRED' - | 'PARCEL.PARAMETERS.INVALID' - | 'PARCEL.PREDEFINED_PACKAGE.INVALID' - | 'PAYMENT_GATEWAY.ERROR' - | 'PAYMENT_REQUIRED' - | 'PICKUP.ADDRESS.INVALID' - | 'PICKUP.ADDRESS.REQUIRED' - | 'PICKUP.BATCH_CARRIER.INCONSISTENT' - | 'PICKUP.BATCH.INVALID' - | 'PICKUP.BATCH.REQUIRED' - | 'PICKUP.BUY.FAILED' - | 'PICKUP.BUY.FORBIDDEN' - | 'PICKUP.BUY.NO_MATCHING_RATES' - | 'PICKUP.CANCEL.FAILED' - | 'PICKUP.CARRIER.REQUIRED' - | 'PICKUP.IS_ACCOUNT_ADDRESS.REQUIRED' - | 'PICKUP.MAX_DATETIME.REQUIRED' - | 'PICKUP.MIN_DATETIME.REQUIRED' - | 'PICKUP.REQUEST.INVALID' - | 'PICKUP.SERVICE.REQUIRED' - | 'PICKUP.SHIPMENT_COUNTRY.INVALID' - | 'PICKUP.SHIPMENT_SERVICE.INVALID' - | 'PICKUP.STATUS.INVALID' - | 'REFUND.FAILURE' - | 'REFUND.NO_RESPONSE' - | 'REFUND.TRACKING_CODE.NOT_FOUND' - | 'REFUND.TRACKING_CODES.INVALID' - | 'SCAN_FORM.BATCH.MULTIPLE_CARRIERS' - | 'SCAN_FORM.BATCH.NOT_PURCHASED' - | 'SCAN_FORM.CREATE.CARRIER_NOT_SUPPORTED' - | 'SCAN_FORM.CREATE.FAILURE' - | 'SCAN_FORM.FAILURE' - | 'SCAN_FORM.SHIPMENTS.INVALID' - | 'SCAN_FORM.SHIPMENTS.REQUIRED' - | 'SHIPMENT_REPORT.ALREADY_IN_PROGRESS' - | 'SHIPMENT_REPORT.DATE_RANGE.INVALID' - | 'SHIPMENT_REPORT.DATE_RANGE.TOO_LONG' - | 'SHIPMENT.CARRIER_ACCOUNTS.CONFLICT' - | 'SHIPMENT.CUSTOMS_INFO.DESCRIPTION_REQUIRED' - | 'SHIPMENT.CUSTOMS_INFO.REQUIRED' - | 'SHIPMENT.INSURANCE.ALREADY_PURCHASED' - | 'SHIPMENT.INVALID_PARAMS' - | 'SHIPMENT.INVALID' - | 'SHIPMENT.MISSING_INFORMATION' - | 'SHIPMENT.MISSING_RATE' - | 'SHIPMENT.OPTIONS.INVALID' - | 'SHIPMENT.POSTAGE.ASCII' - | 'SHIPMENT.POSTAGE.EXISTS' - | 'SHIPMENT.POSTAGE.FAILURE' - | 'SHIPMENT.POSTAGE.FORMAT_UNAVAILABLE' - | 'SHIPMENT.POSTAGE.INVALID_FORMAT' - | 'SHIPMENT.POSTAGE.NO_RESPONSE' - | 'SHIPMENT.POSTAGE.REQUIRED' - | 'SHIPMENT.PURCHASE.FAILURE' - | 'SHIPMENT.PURCHASE.IN_PROGRESS' - | 'SHIPMENT.RATE.BARCODE_UNAVAILABLE' - | 'SHIPMENT.RATE.CARRIER_ACCOUNT_INVALID' - | 'SHIPMENT.RATE.STAMP_UNAVAILABLE' - | 'SHIPMENT.RATES.UNAVAILABLE' - | 'SHIPMENT.REFUND.FAILURE' - | 'SHIPMENT.REFUND.UNAVAILABLE' - | 'SHIPMENT.TRACKING_CODE.INVALID_CARRIER' - | 'TRACKER.CARRIER_CODE_MISMATCH' - | 'TRACKER.CREATE.ERROR' - | 'TRACKER.INVALID_PARAMS' - | 'TRACKER.INVALID_TEST_CODE' - | 'TRACKER.MULTIPLE_CARRIERS_FOR_CODE' - | 'TRACKER.NO_CARRIER_ACCOUNT' - | 'TRACKER.NO_CARRIER_FOR_CODE' - | 'TRACKER.NOT_FOUND' - | 'TRACKER.RETRIEVE.ERROR' - | 'TRACKER.RUN.ERROR' - | 'TRACKER.UNSUPPORTED_CARRIER' - | 'UNAUTHORIZED' - | 'USER.CHARGE.NOT_ALLOWED' - | 'USER.INVALID' - | 'USER.PARENT.INVALID' - | 'USER.UNAUTHORIZED' - | 'WEBHOOK.EVENT.INVALID' - | 'WEBHOOK.INVALID'; diff --git a/types/errors/index.d.ts b/types/errors/index.d.ts deleted file mode 100644 index d6c2ac5d8..000000000 --- a/types/errors/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './Error'; -export * from './ErrorCode'; -export * from './FieldError'; diff --git a/types/index.d.ts b/types/index.d.ts deleted file mode 100644 index 00404f2bb..000000000 --- a/types/index.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -export * from './Address'; -export * from './Batch'; -export * from './Billing'; -export * from './Brand'; -export * from './CarbonOffset'; -export * from './Carrier'; -export * from './Customs'; -export * from './EndShipper'; -export * from './errors'; -export * from './Event'; -export * from './Fee'; -export * from './Insurance'; -export * from './Order'; -export * from './Parcel'; -export * from './Parcel'; -export * from './PaymentMethod'; -export * from './Pickup'; -export * from './Refund'; -export * from './Report'; -export * from './ScanForm'; -export * from './Shipment'; -export * from './Tracker'; -export * from './User'; -export * from './utils'; -export * from './Utility'; -export * from './Webhook'; -export { default, IEasyPostOptions } from './EasyPost'; diff --git a/webpack.config.babel.js b/webpack.config.babel.js index f8027bc78..a1fe9c09e 100644 --- a/webpack.config.babel.js +++ b/webpack.config.babel.js @@ -5,7 +5,7 @@ const mode = process.env.NODE_ENV || 'development'; const isDev = mode === 'development'; module.exports = { - entry: path.resolve(__dirname, 'src', 'easypost.js'), + entry: path.resolve(__dirname, 'out/src/easypost.js'), output: { path: path.resolve(__dirname, 'dist'), filename: 'easypost.js', @@ -13,7 +13,7 @@ module.exports = { type: 'commonjs', }, }, - context: path.resolve(__dirname, 'src'), + context: path.resolve(__dirname, 'out/src'), mode, cache: isDev, devtool: isDev ? 'source-map' : undefined, @@ -32,6 +32,6 @@ module.exports = { }, resolve: { extensions: ['.js'], - modules: [path.resolve(__dirname, 'src'), path.resolve(__dirname, './node_modules')], + modules: [path.resolve(__dirname, 'out/src'), path.resolve(__dirname, './node_modules')], }, }; From da8f7d1709ea4b7aed08daf126b1e8a5dbdf18f8 Mon Sep 17 00:00:00 2001 From: Alex Matthews Date: Wed, 15 May 2024 15:08:15 -0500 Subject: [PATCH 2/7] Runs prettier --- .gitignore | 1 + out/package.json | 90 --- out/src/constants.js | 35 - out/src/easypost.js | 447 ------------- out/src/errors/api/api_error.js | 46 -- out/src/errors/api/bad_request_error.js | 38 -- out/src/errors/api/external_api_error.js | 36 -- out/src/errors/api/forbidden_error.js | 38 -- out/src/errors/api/gateway_timeout_error.js | 38 -- out/src/errors/api/http_error.js | 37 -- out/src/errors/api/index.js | 34 - out/src/errors/api/internal_server_error.js | 38 -- out/src/errors/api/invalid_request_error.js | 38 -- .../errors/api/method_not_allowed_error.js | 38 -- out/src/errors/api/not_found_error.js | 38 -- out/src/errors/api/payment_error.js | 38 -- out/src/errors/api/rate_limit_error.js | 38 -- out/src/errors/api/redirect_error.js | 38 -- .../errors/api/service_unavailable_error.js | 38 -- out/src/errors/api/timeout_error.js | 38 -- out/src/errors/api/unauthorized_error.js | 38 -- out/src/errors/api/unknown_api_error.js | 38 -- out/src/errors/easypost_error.js | 34 - out/src/errors/error_handler.js | 148 ----- .../errors/general/end_of_pagination_error.js | 36 -- out/src/errors/general/filtering_error.js | 35 - out/src/errors/general/index.js | 22 - .../errors/general/invalid_object_error.js | 35 - .../errors/general/invalid_parameter_error.js | 35 - .../errors/general/missing_parameter_error.js | 35 - .../general/signature_verification_error.js | 35 - out/src/errors/index.js | 20 - out/src/index.js | 7 - out/src/services/address_service/Address.js | 2 - .../AddressCreateParameters.js | 2 - .../address_service/AddressListParameters.js | 2 - .../services/address_service/Verification.js | 2 - .../address_service/VerificationDetails.js | 2 - .../services/address_service/Verifications.js | 3 - out/src/services/address_service/index.js | 217 ------- out/src/services/api_key_service/ApiKey.js | 2 - out/src/services/api_key_service/index.js | 142 ---- out/src/services/base_service.js | 192 ------ out/src/services/batch_service/Batch.js | 2 - .../batch_service/BatchCreateParameters.js | 2 - .../batch_service/BatchListParameters.js | 2 - .../services/batch_service/BatchShipment.js | 2 - out/src/services/batch_service/BatchState.js | 2 - out/src/services/batch_service/BatchStatus.js | 2 - .../services/batch_service/BatchStatuses.js | 2 - out/src/services/batch_service/index.js | 293 --------- out/src/services/beta_rate_service/index.js | 99 --- .../beta_referral_customer_service/index.js | 142 ---- .../services/billing_service/PaymentMethod.js | 2 - out/src/services/billing_service/index.js | 203 ------ .../carrier_account_service/CarrierAccount.js | 2 - .../CarrierAccountCreateParameters.js | 2 - .../CarrierAccountField.js | 2 - .../CarrierAccountFields.js | 2 - .../services/carrier_account_service/index.js | 216 ------- .../CarrierMetadata.js | 2 - .../carrier_metadata_service/index.js | 124 ---- .../carrier_type_service/CarrierType.js | 2 - .../CarrierTypeCredentials.js | 2 - .../carrier_type_service/CarrierTypeFields.js | 2 - .../services/carrier_type_service/index.js | 116 ---- .../customs_info_service/CustomsInfo.js | 2 - .../CustomsInfoCreateParameters.js | 2 - .../services/customs_info_service/index.js | 119 ---- .../customs_item_service/CustomsItem.js | 2 - .../CustomsItemCreateParameters.js | 2 - .../services/customs_item_service/index.js | 119 ---- .../end_shipper_service/EndShipper.js | 2 - .../EndShipperCreateParameters.js | 2 - .../EndShipperListParameters.js | 2 - out/src/services/end_shipper_service/index.js | 164 ----- out/src/services/event_service/Event.js | 2 - .../event_service/EventListParameters.js | 2 - .../services/event_service/Payload/Payload.js | 2 - .../Payload/PayloadListParameters.js | 2 - .../services/event_service/Payload/index.js | 17 - out/src/services/event_service/index.js | 191 ------ out/src/services/index.js | 43 -- out/src/services/insurance_service/Fee.js | 2 - out/src/services/insurance_service/FeeType.js | 2 - .../services/insurance_service/Insurance.js | 2 - .../InsuranceCreateParameters.js | 2 - .../insurance_service/InsuranceStatus.js | 2 - out/src/services/insurance_service/index.js | 154 ----- out/src/services/order_service/Order.js | 2 - .../order_service/OrderCreateParameters.js | 2 - out/src/services/order_service/index.js | 178 ------ out/src/services/parcel_service/Parcel.js | 2 - .../parcel_service/ParcelCreateParameters.js | 2 - out/src/services/parcel_service/index.js | 119 ---- out/src/services/pickup_service/Pickup.js | 2 - .../pickup_service/PickupCreateParameters.js | 2 - .../pickup_service/PickupListParameters.js | 2 - out/src/services/pickup_service/PickupRate.js | 2 - out/src/services/pickup_service/index.js | 194 ------ out/src/services/rate_service/Rate.js | 2 - out/src/services/rate_service/index.js | 100 --- .../referral_customer_service/Referral.js | 2 - .../ReferralCreateParameters.js | 2 - .../ReferralListParameters.js | 2 - .../referral_customer_service/index.js | 295 --------- out/src/services/refund_service/Refund.js | 2 - .../refund_service/RefundCreateParameters.js | 2 - .../refund_service/RefundListParameters.js | 2 - out/src/services/refund_service/index.js | 152 ----- out/src/services/report_service/Report.js | 2 - .../report_service/ReportCreateParameters.js | 2 - .../report_service/ReportListParameters.js | 2 - .../report_service/ReportObjectType.js | 2 - out/src/services/report_service/index.js | 177 ----- .../services/scan_form_service/ScanForm.js | 2 - .../ScanFormCreateParameters.js | 2 - .../ScanFormListParameters.js | 2 - out/src/services/scan_form_service/index.js | 163 ----- out/src/services/shipment_service/Form.js | 2 - out/src/services/shipment_service/Message.js | 2 - .../shipment_service/Options/LabelFormat.js | 2 - .../shipment_service/Options/Options.js | 2 - .../Options/PrintCustomCode.js | 2 - .../shipment_service/Options/index.js | 19 - .../services/shipment_service/PostageLabel.js | 2 - out/src/services/shipment_service/Shipment.js | 2 - .../ShipmentCreateParameters.js | 2 - .../ShipmentListParameters.js | 2 - out/src/services/shipment_service/index.js | 479 -------------- .../services/tracker_service/CarrierDetail.js | 2 - out/src/services/tracker_service/Tracker.js | 2 - .../TrackerCreateParameters.js | 2 - .../tracker_service/TrackerListParameters.js | 2 - .../services/tracker_service/TrackerStatus.js | 2 - .../tracker_service/TrackerStatusDetail.js | 2 - .../tracker_service/TrackingDetail.js | 2 - .../tracker_service/TrackingLocation.js | 2 - out/src/services/tracker_service/index.js | 179 ------ out/src/services/user_service/Brand.js | 2 - out/src/services/user_service/User.js | 2 - .../user_service/UserCreateParameters.js | 2 - out/src/services/user_service/index.js | 294 --------- out/src/services/webhook_service/Webhook.js | 2 - .../WebhookCreateParameters.js | 2 - .../webhook_service/WebhookListParameters.js | 2 - out/src/services/webhook_service/index.js | 194 ------ out/src/utils/errors/Error.js | 2 - out/src/utils/errors/ErrorCode.js | 2 - out/src/utils/errors/FieldError.js | 2 - out/src/utils/errors/index.js | 19 - out/src/utils/types.js | 3 - out/src/utils/util.js | 199 ------ src/constants.ts | 31 +- src/easypost.ts | 175 ++--- src/errors/api/api_error.ts | 2 +- src/errors/api/bad_request_error.ts | 2 +- src/errors/api/external_api_error.ts | 2 +- src/errors/api/forbidden_error.ts | 2 +- src/errors/api/gateway_timeout_error.ts | 2 +- src/errors/api/http_error.ts | 2 +- src/errors/api/index.ts | 36 +- src/errors/api/internal_server_error.ts | 2 +- src/errors/api/invalid_request_error.ts | 2 +- src/errors/api/method_not_allowed_error.ts | 2 +- src/errors/api/not_found_error.ts | 2 +- src/errors/api/payment_error.ts | 2 +- src/errors/api/rate_limit_error.ts | 2 +- src/errors/api/redirect_error.ts | 2 +- src/errors/api/service_unavailable_error.ts | 2 +- src/errors/api/timeout_error.ts | 2 +- src/errors/api/unauthorized_error.ts | 2 +- src/errors/api/unknown_api_error.ts | 2 +- src/errors/error_handler.ts | 48 +- src/errors/general/end_of_pagination_error.ts | 4 +- src/errors/general/filtering_error.ts | 2 +- src/errors/general/index.ts | 12 +- src/errors/general/invalid_object_error.ts | 2 +- src/errors/general/invalid_parameter_error.ts | 2 +- src/errors/general/missing_parameter_error.ts | 2 +- .../general/signature_verification_error.ts | 2 +- src/errors/index.ts | 8 +- src/index.ts | 3 - src/services/address_service/Address.ts | 6 +- .../AddressCreateParameters.ts | 6 +- .../address_service/AddressListParameters.ts | 2 +- src/services/address_service/Verification.ts | 4 +- src/services/address_service/Verifications.ts | 2 +- src/services/address_service/index.ts | 42 +- src/services/api_key_service/ApiKey.ts | 4 +- src/services/api_key_service/index.ts | 18 +- src/services/base_service.ts | 27 +- src/services/batch_service/Batch.ts | 14 +- .../batch_service/BatchCreateParameters.ts | 2 +- .../batch_service/BatchListParameters.ts | 2 +- src/services/batch_service/BatchShipment.ts | 2 +- src/services/batch_service/BatchState.ts | 16 +- src/services/batch_service/BatchStatus.ts | 10 +- src/services/batch_service/BatchStatuses.ts | 2 +- src/services/batch_service/index.ts | 49 +- src/services/beta_rate_service/index.ts | 13 +- .../beta_referral_customer_service/index.ts | 16 +- src/services/billing_service/PaymentMethod.ts | 4 +- src/services/billing_service/index.ts | 44 +- .../carrier_account_service/CarrierAccount.ts | 8 +- .../CarrierAccountCreateParameters.ts | 9 +- .../CarrierAccountFields.ts | 2 +- src/services/carrier_account_service/index.ts | 54 +- .../carrier_metadata_service/index.ts | 22 +- .../carrier_type_service/CarrierType.ts | 6 +- .../CarrierTypeCredentials.ts | 2 +- .../carrier_type_service/CarrierTypeFields.ts | 2 +- src/services/carrier_type_service/index.ts | 19 +- .../customs_info_service/CustomsInfo.ts | 15 +- .../CustomsInfoCreateParameters.ts | 9 +- src/services/customs_info_service/index.ts | 14 +- .../customs_item_service/CustomsItem.ts | 6 +- .../CustomsItemCreateParameters.ts | 9 +- src/services/customs_item_service/index.ts | 14 +- .../end_shipper_service/EndShipper.ts | 4 +- .../EndShipperCreateParameters.ts | 9 +- .../EndShipperListParameters.ts | 2 +- src/services/end_shipper_service/index.ts | 30 +- src/services/event_service/Event.ts | 6 +- .../event_service/EventListParameters.ts | 2 +- src/services/event_service/Payload/Payload.ts | 4 +- .../Payload/PayloadListParameters.ts | 2 +- src/services/event_service/Payload/index.ts | 2 +- src/services/event_service/index.ts | 31 +- src/services/index.ts | 54 +- src/services/insurance_service/Fee.ts | 6 +- src/services/insurance_service/FeeType.ts | 6 +- src/services/insurance_service/Insurance.ts | 12 +- .../InsuranceCreateParameters.ts | 2 +- .../insurance_service/InsuranceStatus.ts | 7 +- src/services/insurance_service/index.ts | 30 +- src/services/order_service/Order.ts | 10 +- .../order_service/OrderCreateParameters.ts | 4 +- src/services/order_service/index.ts | 21 +- src/services/parcel_service/Parcel.ts | 4 +- .../parcel_service/ParcelCreateParameters.ts | 9 +- src/services/parcel_service/index.ts | 14 +- src/services/pickup_service/Pickup.ts | 14 +- .../pickup_service/PickupCreateParameters.ts | 14 +- .../pickup_service/PickupListParameters.ts | 2 +- src/services/pickup_service/PickupRate.ts | 4 +- src/services/pickup_service/index.ts | 28 +- src/services/rate_service/Rate.ts | 4 +- src/services/rate_service/index.ts | 8 +- .../referral_customer_service/Referral.ts | 2 +- .../ReferralCreateParameters.ts | 9 +- .../ReferralListParameters.ts | 2 +- .../referral_customer_service/index.ts | 69 +- src/services/refund_service/Refund.ts | 6 +- .../refund_service/RefundListParameters.ts | 2 +- src/services/refund_service/index.ts | 29 +- src/services/report_service/Report.ts | 6 +- .../report_service/ReportCreateParameters.ts | 2 +- .../report_service/ReportListParameters.ts | 4 +- .../report_service/ReportObjectType.ts | 24 +- src/services/report_service/index.ts | 35 +- src/services/scan_form_service/ScanForm.ts | 8 +- .../ScanFormCreateParameters.ts | 8 +- .../ScanFormListParameters.ts | 2 +- src/services/scan_form_service/index.ts | 36 +- src/services/shipment_service/Form.ts | 22 +- .../shipment_service/Options/LabelFormat.ts | 2 +- .../shipment_service/Options/Options.ts | 86 +-- .../Options/PrintCustomCode.ts | 44 +- .../shipment_service/Options/index.ts | 6 +- src/services/shipment_service/PostageLabel.ts | 4 +- src/services/shipment_service/Shipment.ts | 34 +- .../ShipmentCreateParameters.ts | 10 +- .../ShipmentListParameters.ts | 2 +- src/services/shipment_service/index.ts | 101 ++- src/services/tracker_service/CarrierDetail.ts | 6 +- src/services/tracker_service/Tracker.ts | 14 +- .../tracker_service/TrackerListParameters.ts | 2 +- src/services/tracker_service/TrackerStatus.ts | 20 +- .../tracker_service/TrackerStatusDetail.ts | 56 +- .../tracker_service/TrackingDetail.ts | 8 +- .../tracker_service/TrackingLocation.ts | 4 +- src/services/tracker_service/index.ts | 46 +- src/services/user_service/Brand.ts | 6 +- src/services/user_service/User.ts | 4 +- .../user_service/UserCreateParameters.ts | 4 +- src/services/user_service/index.ts | 51 +- src/services/webhook_service/Webhook.ts | 4 +- .../webhook_service/WebhookListParameters.ts | 2 +- src/services/webhook_service/index.ts | 20 +- src/utils/errors/Error.ts | 4 +- src/utils/errors/ErrorCode.ts | 336 +++++----- src/utils/errors/index.ts | 6 +- src/utils/types.ts | 9 +- src/utils/util.ts | 74 +-- test/services/address.test.js | 6 +- test/services/api_key.test.js | 4 +- test/services/base_service.test.js | 4 +- test/services/batch.test.js | 2 +- test/services/beta_rate.test.js | 4 +- test/services/beta_referral_customer.test.js | 2 +- test/services/billing.test.js | 2 +- test/services/carrier_account.test.js | 2 +- test/services/carrier_metadata.test.js | 2 +- test/services/carrier_type.test.js | 2 +- test/services/customs_info.test.js | 2 +- test/services/customs_item.test.js | 2 +- test/services/easypost.test.js | 4 +- test/services/end_shipper.test.js | 2 +- test/services/error.test.js | 30 +- test/services/event.test.js | 6 +- test/services/insurance.test.js | 4 +- test/services/order.test.js | 4 +- test/services/parcel.test.js | 2 +- test/services/pickup.test.js | 6 +- test/services/rate.test.js | 2 +- test/services/referral_customer.test.js | 4 +- test/services/refund.test.js | 4 +- test/services/report.test.js | 4 +- test/services/scan_form.test.js | 4 +- test/services/shipment.test.js | 8 +- test/services/tracker.test.js | 4 +- test/services/user.test.js | 4 +- test/services/webhook.test.js | 4 +- tsconfig.json | 5 +- types/constants.d.ts | 20 + types/easypost.d.ts | 260 ++++++++ types/errors/api/api_error.d.ts | 29 + types/errors/api/bad_request_error.d.ts | 11 + types/errors/api/external_api_error.d.ts | 9 + types/errors/api/forbidden_error.d.ts | 11 + types/errors/api/gateway_timeout_error.d.ts | 11 + types/errors/api/http_error.d.ts | 10 + types/errors/api/index.d.ts | 18 + types/errors/api/internal_server_error.d.ts | 11 + types/errors/api/invalid_request_error.d.ts | 11 + .../errors/api/method_not_allowed_error.d.ts | 11 + types/errors/api/not_found_error.d.ts | 11 + types/errors/api/payment_error.d.ts | 11 + types/errors/api/rate_limit_error.d.ts | 11 + types/errors/api/redirect_error.d.ts | 11 + .../errors/api/service_unavailable_error.d.ts | 11 + types/errors/api/timeout_error.d.ts | 11 + types/errors/api/unauthorized_error.d.ts | 11 + types/errors/api/unknown_api_error.d.ts | 11 + types/errors/easypost_error.d.ts | 12 + types/errors/error_handler.d.ts | 33 + .../general/end_of_pagination_error.d.ts | 10 + types/errors/general/filtering_error.d.ts | 8 + types/errors/general/index.d.ts | 6 + .../errors/general/invalid_object_error.d.ts | 8 + .../general/invalid_parameter_error.d.ts | 8 + .../general/missing_parameter_error.d.ts | 8 + .../general/signature_verification_error.d.ts | 8 + types/errors/index.d.ts | 4 + types/index.d.ts | 2 + types/services/address_service/Address.d.ts | 72 +++ .../AddressCreateParameters.d.ts | 22 + .../AddressListParameters.d.ts | 5 + .../address_service/Verification.d.ts | 19 + .../address_service/VerificationDetails.d.ts | 17 + .../address_service/Verifications.d.ts | 16 + types/services/address_service/index.d.ts | 105 +++ types/services/api_key_service/ApiKey.d.ts | 20 + types/services/api_key_service/index.d.ts | 71 ++ types/services/base_service.d.ts | 71 ++ types/services/batch_service/Batch.d.ts | 48 ++ .../batch_service/BatchCreateParameters.d.ts | 8 + .../batch_service/BatchListParameters.d.ts | 5 + .../services/batch_service/BatchShipment.d.ts | 22 + types/services/batch_service/BatchState.d.ts | 9 + types/services/batch_service/BatchStatus.d.ts | 6 + .../services/batch_service/BatchStatuses.d.ts | 4 + types/services/batch_service/index.d.ts | 132 ++++ types/services/beta_rate_service/index.d.ts | 44 ++ .../beta_referral_customer_service/index.d.ts | 60 ++ .../billing_service/PaymentMethod.d.ts | 44 ++ types/services/billing_service/index.d.ts | 63 ++ .../CarrierAccount.d.ts | 53 ++ .../CarrierAccountCreateParameters.d.ts | 3 + .../CarrierAccountField.d.ts | 21 + .../CarrierAccountFields.d.ts | 22 + .../carrier_account_service/index.d.ts | 116 ++++ .../CarrierMetadata.d.ts | 34 + .../carrier_metadata_service/index.d.ts | 46 ++ .../carrier_type_service/CarrierType.d.ts | 27 + .../CarrierTypeCredentials.d.ts | 17 + .../CarrierTypeFields.d.ts | 23 + .../services/carrier_type_service/index.d.ts | 45 ++ .../customs_info_service/CustomsInfo.d.ts | 55 ++ .../CustomsInfoCreateParameters.d.ts | 3 + .../services/customs_info_service/index.d.ts | 54 ++ .../customs_item_service/CustomsItem.d.ts | 46 ++ .../CustomsItemCreateParameters.d.ts | 3 + .../services/customs_item_service/index.d.ts | 54 ++ .../end_shipper_service/EndShipper.d.ts | 52 ++ .../EndShipperCreateParameters.d.ts | 3 + .../EndShipperListParameters.d.ts | 5 + types/services/end_shipper_service/index.d.ts | 80 +++ types/services/event_service/Event.d.ts | 40 ++ .../event_service/EventListParameters.d.ts | 5 + .../event_service/Payload/Payload.d.ts | 14 + .../Payload/PayloadListParameters.d.ts | 5 + .../services/event_service/Payload/index.d.ts | 1 + types/services/event_service/index.d.ts | 96 +++ types/services/index.d.ts | 27 + types/services/insurance_service/Fee.d.ts | 31 + types/services/insurance_service/FeeType.d.ts | 1 + .../services/insurance_service/Insurance.d.ts | 73 +++ .../InsuranceCreateParameters.d.ts | 22 + .../insurance_service/InsuranceStatus.d.ts | 1 + types/services/insurance_service/index.d.ts | 89 +++ types/services/order_service/Order.d.ts | 53 ++ .../order_service/OrderCreateParameters.d.ts | 12 + types/services/order_service/index.d.ts | 79 +++ types/services/parcel_service/Parcel.d.ts | 38 ++ .../ParcelCreateParameters.d.ts | 24 + types/services/parcel_service/index.d.ts | 54 ++ types/services/pickup_service/Pickup.d.ts | 77 +++ .../PickupCreateParameters.d.ts | 37 ++ .../pickup_service/PickupListParameters.d.ts | 5 + types/services/pickup_service/PickupRate.d.ts | 27 + types/services/pickup_service/index.d.ts | 110 ++++ types/services/rate_service/Rate.d.ts | 81 +++ types/services/rate_service/index.d.ts | 43 ++ .../referral_customer_service/Referral.d.ts | 7 + .../ReferralCreateParameters.d.ts | 3 + .../ReferralListParameters.d.ts | 5 + .../referral_customer_service/index.d.ts | 108 ++++ types/services/refund_service/Refund.d.ts | 31 + .../RefundCreateParameters.d.ts | 13 + .../refund_service/RefundListParameters.d.ts | 5 + types/services/refund_service/index.d.ts | 89 +++ types/services/report_service/Report.d.ts | 52 ++ .../ReportCreateParameters.d.ts | 10 + .../report_service/ReportListParameters.d.ts | 8 + .../report_service/ReportObjectType.d.ts | 14 + types/services/report_service/index.d.ts | 82 +++ .../services/scan_form_service/ScanForm.d.ts | 47 ++ .../ScanFormCreateParameters.d.ts | 9 + .../ScanFormListParameters.d.ts | 5 + types/services/scan_form_service/index.d.ts | 91 +++ types/services/shipment_service/Form.d.ts | 28 + types/services/shipment_service/Message.d.ts | 27 + .../shipment_service/Options/LabelFormat.d.ts | 1 + .../shipment_service/Options/Options.d.ts | 325 ++++++++++ .../Options/PrintCustomCode.d.ts | 52 ++ .../shipment_service/Options/index.d.ts | 3 + .../shipment_service/PostageLabel.d.ts | 18 + types/services/shipment_service/Shipment.d.ts | 124 ++++ .../ShipmentCreateParameters.d.ts | 17 + .../ShipmentListParameters.d.ts | 16 + types/services/shipment_service/index.d.ts | 605 ++++++++++++++++++ .../tracker_service/CarrierDetail.d.ts | 51 ++ types/services/tracker_service/Tracker.d.ts | 86 +++ .../TrackerCreateParameters.d.ts | 11 + .../TrackerListParameters.d.ts | 12 + .../tracker_service/TrackerStatus.d.ts | 11 + .../tracker_service/TrackerStatusDetail.d.ts | 29 + .../tracker_service/TrackingDetail.d.ts | 28 + .../tracker_service/TrackingLocation.d.ts | 22 + types/services/tracker_service/index.d.ts | 102 +++ types/services/user_service/Brand.d.ts | 40 ++ types/services/user_service/User.d.ts | 64 ++ .../user_service/UserCreateParameters.d.ts | 3 + types/services/user_service/index.d.ts | 126 ++++ types/services/webhook_service/Webhook.d.ts | 28 + .../WebhookCreateParameters.d.ts | 3 + .../WebhookListParameters.d.ts | 5 + types/services/webhook_service/index.d.ts | 90 +++ types/src/constants.d.ts | 20 + types/src/easypost.d.ts | 260 ++++++++ types/src/errors/api/api_error.d.ts | 29 + types/src/errors/api/bad_request_error.d.ts | 11 + types/src/errors/api/external_api_error.d.ts | 9 + types/src/errors/api/forbidden_error.d.ts | 11 + .../src/errors/api/gateway_timeout_error.d.ts | 11 + types/src/errors/api/http_error.d.ts | 10 + types/src/errors/api/index.d.ts | 18 + .../src/errors/api/internal_server_error.d.ts | 11 + .../src/errors/api/invalid_request_error.d.ts | 11 + .../errors/api/method_not_allowed_error.d.ts | 11 + types/src/errors/api/not_found_error.d.ts | 11 + types/src/errors/api/payment_error.d.ts | 11 + types/src/errors/api/rate_limit_error.d.ts | 11 + types/src/errors/api/redirect_error.d.ts | 11 + .../errors/api/service_unavailable_error.d.ts | 11 + types/src/errors/api/timeout_error.d.ts | 11 + types/src/errors/api/unauthorized_error.d.ts | 11 + types/src/errors/api/unknown_api_error.d.ts | 11 + types/src/errors/easypost_error.d.ts | 12 + types/src/errors/error_handler.d.ts | 33 + .../general/end_of_pagination_error.d.ts | 10 + types/src/errors/general/filtering_error.d.ts | 8 + types/src/errors/general/index.d.ts | 6 + .../errors/general/invalid_object_error.d.ts | 8 + .../general/invalid_parameter_error.d.ts | 8 + .../general/missing_parameter_error.d.ts | 8 + .../general/signature_verification_error.d.ts | 8 + types/src/errors/index.d.ts | 4 + types/src/index.d.ts | 2 + .../src/services/address_service/Address.d.ts | 72 +++ .../AddressCreateParameters.d.ts | 22 + .../AddressListParameters.d.ts | 5 + .../address_service/Verification.d.ts | 19 + .../address_service/VerificationDetails.d.ts | 17 + .../address_service/Verifications.d.ts | 16 + types/src/services/address_service/index.d.ts | 105 +++ .../src/services/api_key_service/ApiKey.d.ts | 20 + types/src/services/api_key_service/index.d.ts | 71 ++ types/src/services/base_service.d.ts | 71 ++ types/src/services/batch_service/Batch.d.ts | 48 ++ .../batch_service/BatchCreateParameters.d.ts | 8 + .../batch_service/BatchListParameters.d.ts | 5 + .../services/batch_service/BatchShipment.d.ts | 22 + .../services/batch_service/BatchState.d.ts | 9 + .../services/batch_service/BatchStatus.d.ts | 6 + .../services/batch_service/BatchStatuses.d.ts | 4 + types/src/services/batch_service/index.d.ts | 132 ++++ .../src/services/beta_rate_service/index.d.ts | 44 ++ .../beta_referral_customer_service/index.d.ts | 60 ++ .../billing_service/PaymentMethod.d.ts | 44 ++ types/src/services/billing_service/index.d.ts | 63 ++ .../CarrierAccount.d.ts | 53 ++ .../CarrierAccountCreateParameters.d.ts | 3 + .../CarrierAccountField.d.ts | 21 + .../CarrierAccountFields.d.ts | 22 + .../carrier_account_service/index.d.ts | 116 ++++ .../CarrierMetadata.d.ts | 34 + .../carrier_metadata_service/index.d.ts | 46 ++ .../carrier_type_service/CarrierType.d.ts | 27 + .../CarrierTypeCredentials.d.ts | 17 + .../CarrierTypeFields.d.ts | 23 + .../services/carrier_type_service/index.d.ts | 45 ++ .../customs_info_service/CustomsInfo.d.ts | 55 ++ .../CustomsInfoCreateParameters.d.ts | 3 + .../services/customs_info_service/index.d.ts | 54 ++ .../customs_item_service/CustomsItem.d.ts | 46 ++ .../CustomsItemCreateParameters.d.ts | 3 + .../services/customs_item_service/index.d.ts | 54 ++ .../end_shipper_service/EndShipper.d.ts | 52 ++ .../EndShipperCreateParameters.d.ts | 3 + .../EndShipperListParameters.d.ts | 5 + .../services/end_shipper_service/index.d.ts | 80 +++ types/src/services/event_service/Event.d.ts | 40 ++ .../event_service/EventListParameters.d.ts | 5 + .../event_service/Payload/Payload.d.ts | 14 + .../Payload/PayloadListParameters.d.ts | 5 + .../services/event_service/Payload/index.d.ts | 1 + types/src/services/event_service/index.d.ts | 96 +++ types/src/services/index.d.ts | 27 + types/src/services/insurance_service/Fee.d.ts | 31 + .../services/insurance_service/FeeType.d.ts | 1 + .../services/insurance_service/Insurance.d.ts | 73 +++ .../InsuranceCreateParameters.d.ts | 22 + .../insurance_service/InsuranceStatus.d.ts | 1 + .../src/services/insurance_service/index.d.ts | 89 +++ types/src/services/order_service/Order.d.ts | 53 ++ .../order_service/OrderCreateParameters.d.ts | 12 + types/src/services/order_service/index.d.ts | 79 +++ types/src/services/parcel_service/Parcel.d.ts | 38 ++ .../ParcelCreateParameters.d.ts | 24 + types/src/services/parcel_service/index.d.ts | 54 ++ types/src/services/pickup_service/Pickup.d.ts | 77 +++ .../PickupCreateParameters.d.ts | 37 ++ .../pickup_service/PickupListParameters.d.ts | 5 + .../services/pickup_service/PickupRate.d.ts | 27 + types/src/services/pickup_service/index.d.ts | 110 ++++ types/src/services/rate_service/Rate.d.ts | 81 +++ types/src/services/rate_service/index.d.ts | 43 ++ .../referral_customer_service/Referral.d.ts | 7 + .../ReferralCreateParameters.d.ts | 3 + .../ReferralListParameters.d.ts | 5 + .../referral_customer_service/index.d.ts | 108 ++++ types/src/services/refund_service/Refund.d.ts | 31 + .../RefundCreateParameters.d.ts | 13 + .../refund_service/RefundListParameters.d.ts | 5 + types/src/services/refund_service/index.d.ts | 89 +++ types/src/services/report_service/Report.d.ts | 52 ++ .../ReportCreateParameters.d.ts | 10 + .../report_service/ReportListParameters.d.ts | 8 + .../report_service/ReportObjectType.d.ts | 14 + types/src/services/report_service/index.d.ts | 82 +++ .../services/scan_form_service/ScanForm.d.ts | 47 ++ .../ScanFormCreateParameters.d.ts | 9 + .../ScanFormListParameters.d.ts | 5 + .../src/services/scan_form_service/index.d.ts | 91 +++ types/src/services/shipment_service/Form.d.ts | 28 + .../services/shipment_service/Message.d.ts | 27 + .../shipment_service/Options/LabelFormat.d.ts | 1 + .../shipment_service/Options/Options.d.ts | 325 ++++++++++ .../Options/PrintCustomCode.d.ts | 52 ++ .../shipment_service/Options/index.d.ts | 3 + .../shipment_service/PostageLabel.d.ts | 18 + .../services/shipment_service/Shipment.d.ts | 124 ++++ .../ShipmentCreateParameters.d.ts | 17 + .../ShipmentListParameters.d.ts | 16 + .../src/services/shipment_service/index.d.ts | 605 ++++++++++++++++++ .../tracker_service/CarrierDetail.d.ts | 51 ++ .../src/services/tracker_service/Tracker.d.ts | 86 +++ .../TrackerCreateParameters.d.ts | 11 + .../TrackerListParameters.d.ts | 12 + .../tracker_service/TrackerStatus.d.ts | 11 + .../tracker_service/TrackerStatusDetail.d.ts | 29 + .../tracker_service/TrackingDetail.d.ts | 28 + .../tracker_service/TrackingLocation.d.ts | 22 + types/src/services/tracker_service/index.d.ts | 102 +++ types/src/services/user_service/Brand.d.ts | 40 ++ types/src/services/user_service/User.d.ts | 64 ++ .../user_service/UserCreateParameters.d.ts | 3 + types/src/services/user_service/index.d.ts | 126 ++++ .../src/services/webhook_service/Webhook.d.ts | 28 + .../WebhookCreateParameters.d.ts | 3 + .../WebhookListParameters.d.ts | 5 + types/src/services/webhook_service/index.d.ts | 90 +++ types/src/utils/errors/Error.d.ts | 24 + types/src/utils/errors/ErrorCode.d.ts | 173 +++++ types/src/utils/errors/FieldError.d.ts | 10 + types/src/utils/errors/index.d.ts | 3 + types/src/utils/types.d.ts | 62 ++ types/src/utils/util.d.ts | 47 ++ types/utils/errors/Error.d.ts | 24 + types/utils/errors/ErrorCode.d.ts | 173 +++++ types/utils/errors/FieldError.d.ts | 10 + types/utils/errors/index.d.ts | 3 + types/utils/types.d.ts | 62 ++ types/utils/util.d.ts | 47 ++ 627 files changed, 13352 insertions(+), 8590 deletions(-) delete mode 100644 out/package.json delete mode 100644 out/src/constants.js delete mode 100644 out/src/easypost.js delete mode 100644 out/src/errors/api/api_error.js delete mode 100644 out/src/errors/api/bad_request_error.js delete mode 100644 out/src/errors/api/external_api_error.js delete mode 100644 out/src/errors/api/forbidden_error.js delete mode 100644 out/src/errors/api/gateway_timeout_error.js delete mode 100644 out/src/errors/api/http_error.js delete mode 100644 out/src/errors/api/index.js delete mode 100644 out/src/errors/api/internal_server_error.js delete mode 100644 out/src/errors/api/invalid_request_error.js delete mode 100644 out/src/errors/api/method_not_allowed_error.js delete mode 100644 out/src/errors/api/not_found_error.js delete mode 100644 out/src/errors/api/payment_error.js delete mode 100644 out/src/errors/api/rate_limit_error.js delete mode 100644 out/src/errors/api/redirect_error.js delete mode 100644 out/src/errors/api/service_unavailable_error.js delete mode 100644 out/src/errors/api/timeout_error.js delete mode 100644 out/src/errors/api/unauthorized_error.js delete mode 100644 out/src/errors/api/unknown_api_error.js delete mode 100644 out/src/errors/easypost_error.js delete mode 100644 out/src/errors/error_handler.js delete mode 100644 out/src/errors/general/end_of_pagination_error.js delete mode 100644 out/src/errors/general/filtering_error.js delete mode 100644 out/src/errors/general/index.js delete mode 100644 out/src/errors/general/invalid_object_error.js delete mode 100644 out/src/errors/general/invalid_parameter_error.js delete mode 100644 out/src/errors/general/missing_parameter_error.js delete mode 100644 out/src/errors/general/signature_verification_error.js delete mode 100644 out/src/errors/index.js delete mode 100644 out/src/index.js delete mode 100644 out/src/services/address_service/Address.js delete mode 100644 out/src/services/address_service/AddressCreateParameters.js delete mode 100644 out/src/services/address_service/AddressListParameters.js delete mode 100644 out/src/services/address_service/Verification.js delete mode 100644 out/src/services/address_service/VerificationDetails.js delete mode 100644 out/src/services/address_service/Verifications.js delete mode 100644 out/src/services/address_service/index.js delete mode 100644 out/src/services/api_key_service/ApiKey.js delete mode 100644 out/src/services/api_key_service/index.js delete mode 100644 out/src/services/base_service.js delete mode 100644 out/src/services/batch_service/Batch.js delete mode 100644 out/src/services/batch_service/BatchCreateParameters.js delete mode 100644 out/src/services/batch_service/BatchListParameters.js delete mode 100644 out/src/services/batch_service/BatchShipment.js delete mode 100644 out/src/services/batch_service/BatchState.js delete mode 100644 out/src/services/batch_service/BatchStatus.js delete mode 100644 out/src/services/batch_service/BatchStatuses.js delete mode 100644 out/src/services/batch_service/index.js delete mode 100644 out/src/services/beta_rate_service/index.js delete mode 100644 out/src/services/beta_referral_customer_service/index.js delete mode 100644 out/src/services/billing_service/PaymentMethod.js delete mode 100644 out/src/services/billing_service/index.js delete mode 100644 out/src/services/carrier_account_service/CarrierAccount.js delete mode 100644 out/src/services/carrier_account_service/CarrierAccountCreateParameters.js delete mode 100644 out/src/services/carrier_account_service/CarrierAccountField.js delete mode 100644 out/src/services/carrier_account_service/CarrierAccountFields.js delete mode 100644 out/src/services/carrier_account_service/index.js delete mode 100644 out/src/services/carrier_metadata_service/CarrierMetadata.js delete mode 100644 out/src/services/carrier_metadata_service/index.js delete mode 100644 out/src/services/carrier_type_service/CarrierType.js delete mode 100644 out/src/services/carrier_type_service/CarrierTypeCredentials.js delete mode 100644 out/src/services/carrier_type_service/CarrierTypeFields.js delete mode 100644 out/src/services/carrier_type_service/index.js delete mode 100644 out/src/services/customs_info_service/CustomsInfo.js delete mode 100644 out/src/services/customs_info_service/CustomsInfoCreateParameters.js delete mode 100644 out/src/services/customs_info_service/index.js delete mode 100644 out/src/services/customs_item_service/CustomsItem.js delete mode 100644 out/src/services/customs_item_service/CustomsItemCreateParameters.js delete mode 100644 out/src/services/customs_item_service/index.js delete mode 100644 out/src/services/end_shipper_service/EndShipper.js delete mode 100644 out/src/services/end_shipper_service/EndShipperCreateParameters.js delete mode 100644 out/src/services/end_shipper_service/EndShipperListParameters.js delete mode 100644 out/src/services/end_shipper_service/index.js delete mode 100644 out/src/services/event_service/Event.js delete mode 100644 out/src/services/event_service/EventListParameters.js delete mode 100644 out/src/services/event_service/Payload/Payload.js delete mode 100644 out/src/services/event_service/Payload/PayloadListParameters.js delete mode 100644 out/src/services/event_service/Payload/index.js delete mode 100644 out/src/services/event_service/index.js delete mode 100644 out/src/services/index.js delete mode 100644 out/src/services/insurance_service/Fee.js delete mode 100644 out/src/services/insurance_service/FeeType.js delete mode 100644 out/src/services/insurance_service/Insurance.js delete mode 100644 out/src/services/insurance_service/InsuranceCreateParameters.js delete mode 100644 out/src/services/insurance_service/InsuranceStatus.js delete mode 100644 out/src/services/insurance_service/index.js delete mode 100644 out/src/services/order_service/Order.js delete mode 100644 out/src/services/order_service/OrderCreateParameters.js delete mode 100644 out/src/services/order_service/index.js delete mode 100644 out/src/services/parcel_service/Parcel.js delete mode 100644 out/src/services/parcel_service/ParcelCreateParameters.js delete mode 100644 out/src/services/parcel_service/index.js delete mode 100644 out/src/services/pickup_service/Pickup.js delete mode 100644 out/src/services/pickup_service/PickupCreateParameters.js delete mode 100644 out/src/services/pickup_service/PickupListParameters.js delete mode 100644 out/src/services/pickup_service/PickupRate.js delete mode 100644 out/src/services/pickup_service/index.js delete mode 100644 out/src/services/rate_service/Rate.js delete mode 100644 out/src/services/rate_service/index.js delete mode 100644 out/src/services/referral_customer_service/Referral.js delete mode 100644 out/src/services/referral_customer_service/ReferralCreateParameters.js delete mode 100644 out/src/services/referral_customer_service/ReferralListParameters.js delete mode 100644 out/src/services/referral_customer_service/index.js delete mode 100644 out/src/services/refund_service/Refund.js delete mode 100644 out/src/services/refund_service/RefundCreateParameters.js delete mode 100644 out/src/services/refund_service/RefundListParameters.js delete mode 100644 out/src/services/refund_service/index.js delete mode 100644 out/src/services/report_service/Report.js delete mode 100644 out/src/services/report_service/ReportCreateParameters.js delete mode 100644 out/src/services/report_service/ReportListParameters.js delete mode 100644 out/src/services/report_service/ReportObjectType.js delete mode 100644 out/src/services/report_service/index.js delete mode 100644 out/src/services/scan_form_service/ScanForm.js delete mode 100644 out/src/services/scan_form_service/ScanFormCreateParameters.js delete mode 100644 out/src/services/scan_form_service/ScanFormListParameters.js delete mode 100644 out/src/services/scan_form_service/index.js delete mode 100644 out/src/services/shipment_service/Form.js delete mode 100644 out/src/services/shipment_service/Message.js delete mode 100644 out/src/services/shipment_service/Options/LabelFormat.js delete mode 100644 out/src/services/shipment_service/Options/Options.js delete mode 100644 out/src/services/shipment_service/Options/PrintCustomCode.js delete mode 100644 out/src/services/shipment_service/Options/index.js delete mode 100644 out/src/services/shipment_service/PostageLabel.js delete mode 100644 out/src/services/shipment_service/Shipment.js delete mode 100644 out/src/services/shipment_service/ShipmentCreateParameters.js delete mode 100644 out/src/services/shipment_service/ShipmentListParameters.js delete mode 100644 out/src/services/shipment_service/index.js delete mode 100644 out/src/services/tracker_service/CarrierDetail.js delete mode 100644 out/src/services/tracker_service/Tracker.js delete mode 100644 out/src/services/tracker_service/TrackerCreateParameters.js delete mode 100644 out/src/services/tracker_service/TrackerListParameters.js delete mode 100644 out/src/services/tracker_service/TrackerStatus.js delete mode 100644 out/src/services/tracker_service/TrackerStatusDetail.js delete mode 100644 out/src/services/tracker_service/TrackingDetail.js delete mode 100644 out/src/services/tracker_service/TrackingLocation.js delete mode 100644 out/src/services/tracker_service/index.js delete mode 100644 out/src/services/user_service/Brand.js delete mode 100644 out/src/services/user_service/User.js delete mode 100644 out/src/services/user_service/UserCreateParameters.js delete mode 100644 out/src/services/user_service/index.js delete mode 100644 out/src/services/webhook_service/Webhook.js delete mode 100644 out/src/services/webhook_service/WebhookCreateParameters.js delete mode 100644 out/src/services/webhook_service/WebhookListParameters.js delete mode 100644 out/src/services/webhook_service/index.js delete mode 100644 out/src/utils/errors/Error.js delete mode 100644 out/src/utils/errors/ErrorCode.js delete mode 100644 out/src/utils/errors/FieldError.js delete mode 100644 out/src/utils/errors/index.js delete mode 100644 out/src/utils/types.js delete mode 100644 out/src/utils/util.js delete mode 100644 src/index.ts create mode 100644 types/constants.d.ts create mode 100644 types/easypost.d.ts create mode 100644 types/errors/api/api_error.d.ts create mode 100644 types/errors/api/bad_request_error.d.ts create mode 100644 types/errors/api/external_api_error.d.ts create mode 100644 types/errors/api/forbidden_error.d.ts create mode 100644 types/errors/api/gateway_timeout_error.d.ts create mode 100644 types/errors/api/http_error.d.ts create mode 100644 types/errors/api/index.d.ts create mode 100644 types/errors/api/internal_server_error.d.ts create mode 100644 types/errors/api/invalid_request_error.d.ts create mode 100644 types/errors/api/method_not_allowed_error.d.ts create mode 100644 types/errors/api/not_found_error.d.ts create mode 100644 types/errors/api/payment_error.d.ts create mode 100644 types/errors/api/rate_limit_error.d.ts create mode 100644 types/errors/api/redirect_error.d.ts create mode 100644 types/errors/api/service_unavailable_error.d.ts create mode 100644 types/errors/api/timeout_error.d.ts create mode 100644 types/errors/api/unauthorized_error.d.ts create mode 100644 types/errors/api/unknown_api_error.d.ts create mode 100644 types/errors/easypost_error.d.ts create mode 100644 types/errors/error_handler.d.ts create mode 100644 types/errors/general/end_of_pagination_error.d.ts create mode 100644 types/errors/general/filtering_error.d.ts create mode 100644 types/errors/general/index.d.ts create mode 100644 types/errors/general/invalid_object_error.d.ts create mode 100644 types/errors/general/invalid_parameter_error.d.ts create mode 100644 types/errors/general/missing_parameter_error.d.ts create mode 100644 types/errors/general/signature_verification_error.d.ts create mode 100644 types/errors/index.d.ts create mode 100644 types/index.d.ts create mode 100644 types/services/address_service/Address.d.ts create mode 100644 types/services/address_service/AddressCreateParameters.d.ts create mode 100644 types/services/address_service/AddressListParameters.d.ts create mode 100644 types/services/address_service/Verification.d.ts create mode 100644 types/services/address_service/VerificationDetails.d.ts create mode 100644 types/services/address_service/Verifications.d.ts create mode 100644 types/services/address_service/index.d.ts create mode 100644 types/services/api_key_service/ApiKey.d.ts create mode 100644 types/services/api_key_service/index.d.ts create mode 100644 types/services/base_service.d.ts create mode 100644 types/services/batch_service/Batch.d.ts create mode 100644 types/services/batch_service/BatchCreateParameters.d.ts create mode 100644 types/services/batch_service/BatchListParameters.d.ts create mode 100644 types/services/batch_service/BatchShipment.d.ts create mode 100644 types/services/batch_service/BatchState.d.ts create mode 100644 types/services/batch_service/BatchStatus.d.ts create mode 100644 types/services/batch_service/BatchStatuses.d.ts create mode 100644 types/services/batch_service/index.d.ts create mode 100644 types/services/beta_rate_service/index.d.ts create mode 100644 types/services/beta_referral_customer_service/index.d.ts create mode 100644 types/services/billing_service/PaymentMethod.d.ts create mode 100644 types/services/billing_service/index.d.ts create mode 100644 types/services/carrier_account_service/CarrierAccount.d.ts create mode 100644 types/services/carrier_account_service/CarrierAccountCreateParameters.d.ts create mode 100644 types/services/carrier_account_service/CarrierAccountField.d.ts create mode 100644 types/services/carrier_account_service/CarrierAccountFields.d.ts create mode 100644 types/services/carrier_account_service/index.d.ts create mode 100644 types/services/carrier_metadata_service/CarrierMetadata.d.ts create mode 100644 types/services/carrier_metadata_service/index.d.ts create mode 100644 types/services/carrier_type_service/CarrierType.d.ts create mode 100644 types/services/carrier_type_service/CarrierTypeCredentials.d.ts create mode 100644 types/services/carrier_type_service/CarrierTypeFields.d.ts create mode 100644 types/services/carrier_type_service/index.d.ts create mode 100644 types/services/customs_info_service/CustomsInfo.d.ts create mode 100644 types/services/customs_info_service/CustomsInfoCreateParameters.d.ts create mode 100644 types/services/customs_info_service/index.d.ts create mode 100644 types/services/customs_item_service/CustomsItem.d.ts create mode 100644 types/services/customs_item_service/CustomsItemCreateParameters.d.ts create mode 100644 types/services/customs_item_service/index.d.ts create mode 100644 types/services/end_shipper_service/EndShipper.d.ts create mode 100644 types/services/end_shipper_service/EndShipperCreateParameters.d.ts create mode 100644 types/services/end_shipper_service/EndShipperListParameters.d.ts create mode 100644 types/services/end_shipper_service/index.d.ts create mode 100644 types/services/event_service/Event.d.ts create mode 100644 types/services/event_service/EventListParameters.d.ts create mode 100644 types/services/event_service/Payload/Payload.d.ts create mode 100644 types/services/event_service/Payload/PayloadListParameters.d.ts create mode 100644 types/services/event_service/Payload/index.d.ts create mode 100644 types/services/event_service/index.d.ts create mode 100644 types/services/index.d.ts create mode 100644 types/services/insurance_service/Fee.d.ts create mode 100644 types/services/insurance_service/FeeType.d.ts create mode 100644 types/services/insurance_service/Insurance.d.ts create mode 100644 types/services/insurance_service/InsuranceCreateParameters.d.ts create mode 100644 types/services/insurance_service/InsuranceStatus.d.ts create mode 100644 types/services/insurance_service/index.d.ts create mode 100644 types/services/order_service/Order.d.ts create mode 100644 types/services/order_service/OrderCreateParameters.d.ts create mode 100644 types/services/order_service/index.d.ts create mode 100644 types/services/parcel_service/Parcel.d.ts create mode 100644 types/services/parcel_service/ParcelCreateParameters.d.ts create mode 100644 types/services/parcel_service/index.d.ts create mode 100644 types/services/pickup_service/Pickup.d.ts create mode 100644 types/services/pickup_service/PickupCreateParameters.d.ts create mode 100644 types/services/pickup_service/PickupListParameters.d.ts create mode 100644 types/services/pickup_service/PickupRate.d.ts create mode 100644 types/services/pickup_service/index.d.ts create mode 100644 types/services/rate_service/Rate.d.ts create mode 100644 types/services/rate_service/index.d.ts create mode 100644 types/services/referral_customer_service/Referral.d.ts create mode 100644 types/services/referral_customer_service/ReferralCreateParameters.d.ts create mode 100644 types/services/referral_customer_service/ReferralListParameters.d.ts create mode 100644 types/services/referral_customer_service/index.d.ts create mode 100644 types/services/refund_service/Refund.d.ts create mode 100644 types/services/refund_service/RefundCreateParameters.d.ts create mode 100644 types/services/refund_service/RefundListParameters.d.ts create mode 100644 types/services/refund_service/index.d.ts create mode 100644 types/services/report_service/Report.d.ts create mode 100644 types/services/report_service/ReportCreateParameters.d.ts create mode 100644 types/services/report_service/ReportListParameters.d.ts create mode 100644 types/services/report_service/ReportObjectType.d.ts create mode 100644 types/services/report_service/index.d.ts create mode 100644 types/services/scan_form_service/ScanForm.d.ts create mode 100644 types/services/scan_form_service/ScanFormCreateParameters.d.ts create mode 100644 types/services/scan_form_service/ScanFormListParameters.d.ts create mode 100644 types/services/scan_form_service/index.d.ts create mode 100644 types/services/shipment_service/Form.d.ts create mode 100644 types/services/shipment_service/Message.d.ts create mode 100644 types/services/shipment_service/Options/LabelFormat.d.ts create mode 100644 types/services/shipment_service/Options/Options.d.ts create mode 100644 types/services/shipment_service/Options/PrintCustomCode.d.ts create mode 100644 types/services/shipment_service/Options/index.d.ts create mode 100644 types/services/shipment_service/PostageLabel.d.ts create mode 100644 types/services/shipment_service/Shipment.d.ts create mode 100644 types/services/shipment_service/ShipmentCreateParameters.d.ts create mode 100644 types/services/shipment_service/ShipmentListParameters.d.ts create mode 100644 types/services/shipment_service/index.d.ts create mode 100644 types/services/tracker_service/CarrierDetail.d.ts create mode 100644 types/services/tracker_service/Tracker.d.ts create mode 100644 types/services/tracker_service/TrackerCreateParameters.d.ts create mode 100644 types/services/tracker_service/TrackerListParameters.d.ts create mode 100644 types/services/tracker_service/TrackerStatus.d.ts create mode 100644 types/services/tracker_service/TrackerStatusDetail.d.ts create mode 100644 types/services/tracker_service/TrackingDetail.d.ts create mode 100644 types/services/tracker_service/TrackingLocation.d.ts create mode 100644 types/services/tracker_service/index.d.ts create mode 100644 types/services/user_service/Brand.d.ts create mode 100644 types/services/user_service/User.d.ts create mode 100644 types/services/user_service/UserCreateParameters.d.ts create mode 100644 types/services/user_service/index.d.ts create mode 100644 types/services/webhook_service/Webhook.d.ts create mode 100644 types/services/webhook_service/WebhookCreateParameters.d.ts create mode 100644 types/services/webhook_service/WebhookListParameters.d.ts create mode 100644 types/services/webhook_service/index.d.ts create mode 100644 types/src/constants.d.ts create mode 100644 types/src/easypost.d.ts create mode 100644 types/src/errors/api/api_error.d.ts create mode 100644 types/src/errors/api/bad_request_error.d.ts create mode 100644 types/src/errors/api/external_api_error.d.ts create mode 100644 types/src/errors/api/forbidden_error.d.ts create mode 100644 types/src/errors/api/gateway_timeout_error.d.ts create mode 100644 types/src/errors/api/http_error.d.ts create mode 100644 types/src/errors/api/index.d.ts create mode 100644 types/src/errors/api/internal_server_error.d.ts create mode 100644 types/src/errors/api/invalid_request_error.d.ts create mode 100644 types/src/errors/api/method_not_allowed_error.d.ts create mode 100644 types/src/errors/api/not_found_error.d.ts create mode 100644 types/src/errors/api/payment_error.d.ts create mode 100644 types/src/errors/api/rate_limit_error.d.ts create mode 100644 types/src/errors/api/redirect_error.d.ts create mode 100644 types/src/errors/api/service_unavailable_error.d.ts create mode 100644 types/src/errors/api/timeout_error.d.ts create mode 100644 types/src/errors/api/unauthorized_error.d.ts create mode 100644 types/src/errors/api/unknown_api_error.d.ts create mode 100644 types/src/errors/easypost_error.d.ts create mode 100644 types/src/errors/error_handler.d.ts create mode 100644 types/src/errors/general/end_of_pagination_error.d.ts create mode 100644 types/src/errors/general/filtering_error.d.ts create mode 100644 types/src/errors/general/index.d.ts create mode 100644 types/src/errors/general/invalid_object_error.d.ts create mode 100644 types/src/errors/general/invalid_parameter_error.d.ts create mode 100644 types/src/errors/general/missing_parameter_error.d.ts create mode 100644 types/src/errors/general/signature_verification_error.d.ts create mode 100644 types/src/errors/index.d.ts create mode 100644 types/src/index.d.ts create mode 100644 types/src/services/address_service/Address.d.ts create mode 100644 types/src/services/address_service/AddressCreateParameters.d.ts create mode 100644 types/src/services/address_service/AddressListParameters.d.ts create mode 100644 types/src/services/address_service/Verification.d.ts create mode 100644 types/src/services/address_service/VerificationDetails.d.ts create mode 100644 types/src/services/address_service/Verifications.d.ts create mode 100644 types/src/services/address_service/index.d.ts create mode 100644 types/src/services/api_key_service/ApiKey.d.ts create mode 100644 types/src/services/api_key_service/index.d.ts create mode 100644 types/src/services/base_service.d.ts create mode 100644 types/src/services/batch_service/Batch.d.ts create mode 100644 types/src/services/batch_service/BatchCreateParameters.d.ts create mode 100644 types/src/services/batch_service/BatchListParameters.d.ts create mode 100644 types/src/services/batch_service/BatchShipment.d.ts create mode 100644 types/src/services/batch_service/BatchState.d.ts create mode 100644 types/src/services/batch_service/BatchStatus.d.ts create mode 100644 types/src/services/batch_service/BatchStatuses.d.ts create mode 100644 types/src/services/batch_service/index.d.ts create mode 100644 types/src/services/beta_rate_service/index.d.ts create mode 100644 types/src/services/beta_referral_customer_service/index.d.ts create mode 100644 types/src/services/billing_service/PaymentMethod.d.ts create mode 100644 types/src/services/billing_service/index.d.ts create mode 100644 types/src/services/carrier_account_service/CarrierAccount.d.ts create mode 100644 types/src/services/carrier_account_service/CarrierAccountCreateParameters.d.ts create mode 100644 types/src/services/carrier_account_service/CarrierAccountField.d.ts create mode 100644 types/src/services/carrier_account_service/CarrierAccountFields.d.ts create mode 100644 types/src/services/carrier_account_service/index.d.ts create mode 100644 types/src/services/carrier_metadata_service/CarrierMetadata.d.ts create mode 100644 types/src/services/carrier_metadata_service/index.d.ts create mode 100644 types/src/services/carrier_type_service/CarrierType.d.ts create mode 100644 types/src/services/carrier_type_service/CarrierTypeCredentials.d.ts create mode 100644 types/src/services/carrier_type_service/CarrierTypeFields.d.ts create mode 100644 types/src/services/carrier_type_service/index.d.ts create mode 100644 types/src/services/customs_info_service/CustomsInfo.d.ts create mode 100644 types/src/services/customs_info_service/CustomsInfoCreateParameters.d.ts create mode 100644 types/src/services/customs_info_service/index.d.ts create mode 100644 types/src/services/customs_item_service/CustomsItem.d.ts create mode 100644 types/src/services/customs_item_service/CustomsItemCreateParameters.d.ts create mode 100644 types/src/services/customs_item_service/index.d.ts create mode 100644 types/src/services/end_shipper_service/EndShipper.d.ts create mode 100644 types/src/services/end_shipper_service/EndShipperCreateParameters.d.ts create mode 100644 types/src/services/end_shipper_service/EndShipperListParameters.d.ts create mode 100644 types/src/services/end_shipper_service/index.d.ts create mode 100644 types/src/services/event_service/Event.d.ts create mode 100644 types/src/services/event_service/EventListParameters.d.ts create mode 100644 types/src/services/event_service/Payload/Payload.d.ts create mode 100644 types/src/services/event_service/Payload/PayloadListParameters.d.ts create mode 100644 types/src/services/event_service/Payload/index.d.ts create mode 100644 types/src/services/event_service/index.d.ts create mode 100644 types/src/services/index.d.ts create mode 100644 types/src/services/insurance_service/Fee.d.ts create mode 100644 types/src/services/insurance_service/FeeType.d.ts create mode 100644 types/src/services/insurance_service/Insurance.d.ts create mode 100644 types/src/services/insurance_service/InsuranceCreateParameters.d.ts create mode 100644 types/src/services/insurance_service/InsuranceStatus.d.ts create mode 100644 types/src/services/insurance_service/index.d.ts create mode 100644 types/src/services/order_service/Order.d.ts create mode 100644 types/src/services/order_service/OrderCreateParameters.d.ts create mode 100644 types/src/services/order_service/index.d.ts create mode 100644 types/src/services/parcel_service/Parcel.d.ts create mode 100644 types/src/services/parcel_service/ParcelCreateParameters.d.ts create mode 100644 types/src/services/parcel_service/index.d.ts create mode 100644 types/src/services/pickup_service/Pickup.d.ts create mode 100644 types/src/services/pickup_service/PickupCreateParameters.d.ts create mode 100644 types/src/services/pickup_service/PickupListParameters.d.ts create mode 100644 types/src/services/pickup_service/PickupRate.d.ts create mode 100644 types/src/services/pickup_service/index.d.ts create mode 100644 types/src/services/rate_service/Rate.d.ts create mode 100644 types/src/services/rate_service/index.d.ts create mode 100644 types/src/services/referral_customer_service/Referral.d.ts create mode 100644 types/src/services/referral_customer_service/ReferralCreateParameters.d.ts create mode 100644 types/src/services/referral_customer_service/ReferralListParameters.d.ts create mode 100644 types/src/services/referral_customer_service/index.d.ts create mode 100644 types/src/services/refund_service/Refund.d.ts create mode 100644 types/src/services/refund_service/RefundCreateParameters.d.ts create mode 100644 types/src/services/refund_service/RefundListParameters.d.ts create mode 100644 types/src/services/refund_service/index.d.ts create mode 100644 types/src/services/report_service/Report.d.ts create mode 100644 types/src/services/report_service/ReportCreateParameters.d.ts create mode 100644 types/src/services/report_service/ReportListParameters.d.ts create mode 100644 types/src/services/report_service/ReportObjectType.d.ts create mode 100644 types/src/services/report_service/index.d.ts create mode 100644 types/src/services/scan_form_service/ScanForm.d.ts create mode 100644 types/src/services/scan_form_service/ScanFormCreateParameters.d.ts create mode 100644 types/src/services/scan_form_service/ScanFormListParameters.d.ts create mode 100644 types/src/services/scan_form_service/index.d.ts create mode 100644 types/src/services/shipment_service/Form.d.ts create mode 100644 types/src/services/shipment_service/Message.d.ts create mode 100644 types/src/services/shipment_service/Options/LabelFormat.d.ts create mode 100644 types/src/services/shipment_service/Options/Options.d.ts create mode 100644 types/src/services/shipment_service/Options/PrintCustomCode.d.ts create mode 100644 types/src/services/shipment_service/Options/index.d.ts create mode 100644 types/src/services/shipment_service/PostageLabel.d.ts create mode 100644 types/src/services/shipment_service/Shipment.d.ts create mode 100644 types/src/services/shipment_service/ShipmentCreateParameters.d.ts create mode 100644 types/src/services/shipment_service/ShipmentListParameters.d.ts create mode 100644 types/src/services/shipment_service/index.d.ts create mode 100644 types/src/services/tracker_service/CarrierDetail.d.ts create mode 100644 types/src/services/tracker_service/Tracker.d.ts create mode 100644 types/src/services/tracker_service/TrackerCreateParameters.d.ts create mode 100644 types/src/services/tracker_service/TrackerListParameters.d.ts create mode 100644 types/src/services/tracker_service/TrackerStatus.d.ts create mode 100644 types/src/services/tracker_service/TrackerStatusDetail.d.ts create mode 100644 types/src/services/tracker_service/TrackingDetail.d.ts create mode 100644 types/src/services/tracker_service/TrackingLocation.d.ts create mode 100644 types/src/services/tracker_service/index.d.ts create mode 100644 types/src/services/user_service/Brand.d.ts create mode 100644 types/src/services/user_service/User.d.ts create mode 100644 types/src/services/user_service/UserCreateParameters.d.ts create mode 100644 types/src/services/user_service/index.d.ts create mode 100644 types/src/services/webhook_service/Webhook.d.ts create mode 100644 types/src/services/webhook_service/WebhookCreateParameters.d.ts create mode 100644 types/src/services/webhook_service/WebhookListParameters.d.ts create mode 100644 types/src/services/webhook_service/index.d.ts create mode 100644 types/src/utils/errors/Error.d.ts create mode 100644 types/src/utils/errors/ErrorCode.d.ts create mode 100644 types/src/utils/errors/FieldError.d.ts create mode 100644 types/src/utils/errors/index.d.ts create mode 100644 types/src/utils/types.d.ts create mode 100644 types/src/utils/util.d.ts create mode 100644 types/utils/errors/Error.d.ts create mode 100644 types/utils/errors/ErrorCode.d.ts create mode 100644 types/utils/errors/FieldError.d.ts create mode 100644 types/utils/errors/index.d.ts create mode 100644 types/utils/types.d.ts create mode 100644 types/utils/util.d.ts diff --git a/.gitignore b/.gitignore index 8092032e8..79d7f9795 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ docs Icon node_modules npm-debug.log +out /.eslintrc /.eslintignore /.prettierrc.yml diff --git a/out/package.json b/out/package.json deleted file mode 100644 index 0009749e2..000000000 --- a/out/package.json +++ /dev/null @@ -1,90 +0,0 @@ -{ - "name": "@easypost/api", - "description": "EasyPost Node Client Library", - "version": "7.3.0", - "author": "Easypost Engineering ", - "homepage": "https://easypost.com", - "bin": { - "easypost": "./repl.js" - }, - "repository": { - "type": "git", - "url": "git://github.com/easypost/easypost-node.git" - }, - "main": "index.js", - "types": "types/index.d.ts", - "license": "MIT", - "engines": { - "node": ">= 12.0" - }, - "scripts": { - "build": "npm run build:typescript && npm run build:webpack", - "build:webpack": "webpack --config webpack.config.babel.js", - "build:typescript": "tsc", - "clean": "rm -rf ./dist ./nyc_output ./node_modules/.cache ./coverage", - "coverage": "cross-env NODE_ENV=test nyc npm run test", - "docs": "./node_modules/.bin/jsdoc src/models src/services src/errors src/utils -d docs", - "format": "prettier --write .", - "formatCheck": "prettier --check .", - "lint": "eslint --ext .js,.ts .", - "lintFix": "eslint --ext .js,.ts --fix .", - "prepublishOnly": "npm run clean && npm run build && npm run test && npm run lint && npm run formatCheck", - "repl": "./repl.js --local easypost.js", - "scan": "npx audit-ci -m --config ./audit-ci.jsonc", - "test": "cross-env NODE_ENV=test mocha --timeout 10000 --require @babel/register --require ./test/helpers/common.js --recursive ./test", - "watch": "webpack --config webpack.config.babel.js --watch" - }, - "dependencies": { - "core-js": "~3.30.2", - "nodent-runtime": "~3.2.1", - "regenerator-runtime": "~0.13.11", - "source-map-support": "~0.5.21", - "superagent": "~8.0.9", - "uuid": "^9.0.0", - "yargs": "~17.7.2", - "yargs-parser": "~21.1.1" - }, - "devDependencies": { - "@babel/core": "^7.21.8", - "@babel/eslint-parser": "^7.21.8", - "@babel/plugin-proposal-class-properties": "^7.18.6", - "@babel/plugin-proposal-export-default-from": "^7.18.10", - "@babel/plugin-proposal-export-namespace-from": "^7.18.9", - "@babel/plugin-transform-react-constant-elements": "^7.21.3", - "@babel/plugin-transform-react-inline-elements": "^7.21.0", - "@babel/preset-env": "^7.21.5", - "@babel/register": "^7.21.0", - "@pollyjs/adapter-node-http": "^6.0.5", - "@pollyjs/core": "^6.0.5", - "@pollyjs/persister-fs": "^6.0.5", - "@types/superagent": "^8.1.7", - "@types/uuid": "^9.0.8", - "@typescript-eslint/eslint-plugin": "^5.59.5", - "@typescript-eslint/parser": "^5.59.5", - "audit-ci": "^6.6.1", - "babel-loader": "^8.2.5", - "babel-plugin-istanbul": "^6.1.1", - "babel-plugin-transform-export-extensions": "^6.22.0", - "babel-preset-minify": "^0.5.2", - "chai": "4.3.10", - "chai-as-promised": "^7.1.1", - "cross-env": "^7.0.3", - "eslint": "^8.40.0", - "eslint-config-prettier": "^8.8.0", - "eslint-import-resolver-webpack": "^0.13.2", - "eslint-plugin-babel": "^5.3.1", - "eslint-plugin-import": "^2.27.5", - "eslint-plugin-jest": "^27.2.1", - "eslint-plugin-jsx-a11y": "^6.7.1", - "eslint-plugin-react": "^7.32.1", - "jsdoc": "^4.0.2", - "mocha": "^10.2.0", - "nyc": "^15.1.0", - "prettier": "^2.8.8", - "typescript": "^4.9.5 || ~5.0.0", - "vows": "^0.8.3", - "webpack": "^5.76.3", - "webpack-cli": "^5.0.1", - "webpack-node-externals": "^3.0.0" - } -} diff --git a/out/src/constants.js b/out/src/constants.js deleted file mode 100644 index 4ad9d1601..000000000 --- a/out/src/constants.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var util_1 = __importDefault(require("./utils/util")); -/** - * A class containing constants used throughout the EasyPost Node.js client library. - */ -var Constants = /** @class */ (function () { - function Constants() { - } - Object.defineProperty(Constants, "CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS", { - get: function () { - return ["FedexAccount", "FedexSmartpostAccount", "UpsAccount"]; - }, - enumerable: false, - configurable: true - }); - Constants.EXTERNAL_API_CALL_FAILED = "Communication with %s failed, please try again later"; - Constants.INVALID_API_KEY_TYPE = "Invalid API key type."; - Constants.INVALID_PARAMETER = "Invalid parameter: %s."; - Constants.INVALID_PAYMENT = "The chosen payment method is not a credit card. Please try again."; - Constants.INVALID_WEBHOOK_SIGNATURE = "Webhook does not contain a valid HMAC signature."; - Constants.MISSING_REQUIRED_PARAMETER = "Missing required parameter: %s."; - Constants.NO_OBJECT_FOUND = "No %s found."; - Constants.NO_PAYMENT_METHODS = "No payment methods are set up. Please add a payment method and try again."; - Constants.API_DID_NOT_RETURN_ERROR_DETAILS = "API did not return error details."; - Constants.WEBHOOK_DOES_NOT_MATCH = "Webhook received did not originate from EasyPost or had a webhook secret mismatch."; - Constants.END_OF_PAGINATION = "There are no more pages to retrieve."; - Constants.ERROR_DESERIALIZATION = "Error deserializing JSON response"; - Constants.Utils = new util_1.default(); - return Constants; -}()); -exports.default = Constants; diff --git a/out/src/easypost.js b/out/src/easypost.js deleted file mode 100644 index be355b05e..000000000 --- a/out/src/easypost.js +++ /dev/null @@ -1,447 +0,0 @@ -"use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.METHODS = exports.DEFAULT_HEADERS = exports.DEFAULT_BASE_URL = exports.DEFAULT_TIMEOUT = exports.MS_SECOND = void 0; -var os_1 = __importDefault(require("os")); -var superagent_1 = __importDefault(require("superagent")); -var uuid_1 = require("uuid"); -var package_json_1 = __importDefault(require("../package.json")); -var constants_1 = __importDefault(require("./constants")); -var error_handler_1 = __importDefault(require("./errors/error_handler")); -var missing_parameter_error_1 = __importDefault(require("./errors/general/missing_parameter_error")); -var address_service_1 = __importDefault(require("./services/address_service")); -var api_key_service_1 = __importDefault(require("./services/api_key_service")); -var batch_service_1 = __importDefault(require("./services/batch_service")); -var beta_rate_service_1 = __importDefault(require("./services/beta_rate_service")); -var beta_referral_customer_service_1 = __importDefault(require("./services/beta_referral_customer_service")); -var billing_service_1 = __importDefault(require("./services/billing_service")); -var carrier_account_service_1 = __importDefault(require("./services/carrier_account_service")); -var carrier_metadata_service_1 = __importDefault(require("./services/carrier_metadata_service")); -var carrier_type_service_1 = __importDefault(require("./services/carrier_type_service")); -var customs_info_service_1 = __importDefault(require("./services/customs_info_service")); -var customs_item_service_1 = __importDefault(require("./services/customs_item_service")); -var end_shipper_service_1 = __importDefault(require("./services/end_shipper_service")); -var event_service_1 = __importDefault(require("./services/event_service")); -var insurance_service_1 = __importDefault(require("./services/insurance_service")); -var order_service_1 = __importDefault(require("./services/order_service")); -var parcel_service_1 = __importDefault(require("./services/parcel_service")); -var pickup_service_1 = __importDefault(require("./services/pickup_service")); -var rate_service_1 = __importDefault(require("./services/rate_service")); -var referral_customer_service_1 = __importDefault(require("./services/referral_customer_service")); -var refund_service_1 = __importDefault(require("./services/refund_service")); -var report_service_1 = __importDefault(require("./services/report_service")); -var scan_form_service_1 = __importDefault(require("./services/scan_form_service")); -var shipment_service_1 = __importDefault(require("./services/shipment_service")); -var tracker_service_1 = __importDefault(require("./services/tracker_service")); -var user_service_1 = __importDefault(require("./services/user_service")); -var webhook_service_1 = __importDefault(require("./services/webhook_service")); -var util_1 = __importDefault(require("./utils/util")); -var node_util_1 = __importDefault(require("node:util")); -__exportStar(require("./errors"), exports); -__exportStar(require("./services"), exports); -__exportStar(require("./utils/errors"), exports); -__exportStar(require("./constants"), exports); -/** How many milliseconds in a second. */ -exports.MS_SECOND = 1000; -/** The default timeout for all EasyPost API requests. */ -exports.DEFAULT_TIMEOUT = 60 * exports.MS_SECOND; -/** The default base URL for all production EasyPost API requests. */ -exports.DEFAULT_BASE_URL = "https://api.easypost.com/v2/"; -/** The default headers used for all EasyPost API requests. */ -exports.DEFAULT_HEADERS = { - Accept: "application/json", - "Content-Type": "application/json", - "User-Agent": "EasyPost/v2 NodejsClient/".concat(package_json_1.default.version, " Nodejs/").concat(process.versions.node, " OS/").concat(os_1.default.platform(), " OSVersion/").concat(os_1.default.release(), " OSArch/").concat(os_1.default.arch()), -}; -/** A map of HTTP methods to their corresponding string values (for use with superagent). */ -exports.METHODS = { - GET: "get", - POST: "post", - PUT: "put", - PATCH: "patch", - DELETE: "del", -}; -/** - * The client used to access services of the EasyPost API. - * This client is configured to use the latest production version of the EasyPost API. - * @param {string} key The API key to use for API requests made by this client. - * @param {EasyPostClientOptions} [options] Additional options to use for the underlying HTTP client (e.g. superagent, middleware, proxy configuration). - */ -var EasyPostClient = /** @class */ (function () { - function EasyPostClient(key, options) { - if (options === void 0) { options = {}; } - var useProxy = options.useProxy, timeout = options.timeout, baseUrl = options.baseUrl, superagentMiddleware = options.superagentMiddleware, requestMiddleware = options.requestMiddleware, agent = options.agent; - if (!key && !useProxy) { - throw new missing_parameter_error_1.default({ - message: node_util_1.default.format(constants_1.default.MISSING_REQUIRED_PARAMETER, "API Key"), - }); - } - this.key = key; - this.useProxy = useProxy || false; - this.timeout = timeout || exports.DEFAULT_TIMEOUT; - this.baseUrl = baseUrl || exports.DEFAULT_BASE_URL; - this.agent = agent || superagent_1.default; - this.requestMiddleware = requestMiddleware; - this.requestHooks = []; - this.responseHooks = []; - this.Utils = new util_1.default(); - if (superagentMiddleware) { - this.agent = superagentMiddleware(this.agent); - } - this.Address = (0, address_service_1.default)(this); - this.ApiKey = (0, api_key_service_1.default)(this); - this.Batch = (0, batch_service_1.default)(this); - this.BetaRate = (0, beta_rate_service_1.default)(this); - this.BetaReferralCustomer = (0, beta_referral_customer_service_1.default)(this); - this.Billing = (0, billing_service_1.default)(this); - this.CarrierAccount = (0, carrier_account_service_1.default)(this); - this.CarrierMetadata = (0, carrier_metadata_service_1.default)(this); - this.CarrierType = (0, carrier_type_service_1.default)(this); - this.CustomsInfo = (0, customs_info_service_1.default)(this); - this.CustomsItem = (0, customs_item_service_1.default)(this); - this.EndShipper = (0, end_shipper_service_1.default)(this); - this.Event = (0, event_service_1.default)(this); - this.Insurance = (0, insurance_service_1.default)(this); - this.Order = (0, order_service_1.default)(this); - this.Parcel = (0, parcel_service_1.default)(this); - this.Pickup = (0, pickup_service_1.default)(this); - this.Rate = (0, rate_service_1.default)(this); - this.ReferralCustomer = (0, referral_customer_service_1.default)(this); - this.Refund = (0, refund_service_1.default)(this); - this.Report = (0, report_service_1.default)(this); - this.ScanForm = (0, scan_form_service_1.default)(this); - this.Shipment = (0, shipment_service_1.default)(this); - this.Tracker = (0, tracker_service_1.default)(this); - this.User = (0, user_service_1.default)(this); - this.Webhook = (0, webhook_service_1.default)(this); - } - /** - * Add a request hook function. - * @param {(config: object) => void} hook - */ - EasyPostClient.prototype.addRequestHook = function (hook) { - this.requestHooks = __spreadArray(__spreadArray([], __read(this.requestHooks), false), [hook], false); - }; - /** - * Remove a request hook function. - * @param {(config: object) => void} hook - */ - EasyPostClient.prototype.removeRequestHook = function (hook) { - this.requestHooks = this.requestHooks.filter(function (h) { return h !== hook; }); - }; - /** - * Clear all request hooks. - */ - EasyPostClient.prototype.clearRequestHooks = function () { - this.requestHooks = []; - }; - /** - * Add a response hook function. - * @param {(config: object) => void} hook - */ - EasyPostClient.prototype.addResponseHook = function (hook) { - this.responseHooks = __spreadArray(__spreadArray([], __read(this.responseHooks), false), [hook], false); - }; - /** - * Remove a response hook function. - * @param {(config: object) => void} hook - */ - EasyPostClient.prototype.removeResponseHook = function (hook) { - this.responseHooks = this.responseHooks.filter(function (h) { return h !== hook; }); - }; - /** - * Clear all response hooks. - */ - EasyPostClient.prototype.clearResponseHooks = function () { - this.responseHooks = []; - }; - /** - * Create a copy of an {@link EasyPostClient} with overridden options. - * @param {EasyPostClient} client The `EasyPostClient` instance to clone. - * @param {Object} [options] The options to override. - * @returns {EasyPostClient} A new `EasyPostClient` instance. - */ - EasyPostClient.copyClient = function (client, options) { - if (options === void 0) { options = {}; } - var apiKey = options.apiKey, useProxy = options.useProxy, timeout = options.timeout, baseUrl = options.baseUrl, superagentMiddleware = options.superagentMiddleware, requestMiddleware = options.requestMiddleware; - var agent = superagentMiddleware - ? superagentMiddleware(client.agent) - : client.agent; - return new EasyPostClient(apiKey || client.key, { - useProxy: useProxy || client.useProxy, - timeout: timeout || client.timeout, - baseUrl: baseUrl || client.baseUrl, - agent: agent, - requestMiddleware: requestMiddleware || client.requestMiddleware, - }); - }; - /** - * Build request headers to be sent with each EasyPost API request, combined (or overridden) by any additional headers - * @param {Object} [additionalHeaders] Additional headers to combine or override with the default headers. - * @returns {Object} The headers to use for the request. - */ - EasyPostClient._buildHeaders = function (additionalHeaders) { - if (additionalHeaders === void 0) { additionalHeaders = {}; } - return __assign(__assign({}, exports.DEFAULT_HEADERS), additionalHeaders); - }; - /** - * If the path passed in is a full URI, use it; otherwise, prepend the base url from the api. - * @param {string} path - The path to build. - * @returns {string} The full path to use for the HTTP request. - */ - EasyPostClient.prototype._buildPath = function (path) { - if (path === void 0) { path = ""; } - if (path.indexOf("http") === 0) { - return path; - } - var completePath = this.baseUrl + path; - completePath = path.includes("beta") - ? completePath.replace("v2", "") - : completePath; - return completePath; - }; - /** - * Create a value to be passed to the responseHooks, based on the requestHooks - * value and the response. - * @param {Object} baseHooksValue - the value being passed the requestHooks - * @param {Object} response - the response from the superagent request - * @returns {Object} - the value to be passed to the responseHooks - */ - EasyPostClient.prototype._createResponseHooksValue = function (baseHooksValue, response) { - return __assign(__assign({}, baseHooksValue), { requestHeaders: baseHooksValue.headers, httpStatus: response.status, responseBody: response.body, headers: response.headers, responseTimestamp: Date.now() }); - }; - /** - * Make an HTTP request. - * @param [path] - The partial path to append to the base url for the request. - * @param [method] - The HTTP method to use for the request, defaults to GET. - * @param [params] - The parameters to send with the request. - * @param [headers] - Additional headers to send with the request. - * @returns The response from the HTTP request. - * @throws {ApiError} If the request fails. - */ - EasyPostClient.prototype._request = function (path, method, params, headers) { - if (path === void 0) { path = ""; } - if (method === void 0) { method = exports.METHODS.GET; } - if (params === void 0) { params = {}; } - if (headers === void 0) { headers = {}; } - return __awaiter(this, void 0, void 0, function () { - var urlPath, requestHeaders, request, url, baseHooksValue, response, responseHooksValue_1, error_1, responseHooksValue_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - urlPath = this._buildPath(path); - requestHeaders = EasyPostClient._buildHeaders(headers); - request = this.agent[method](urlPath).set(requestHeaders); - if (this.requestMiddleware) { - request = this.requestMiddleware(request); - } - if (this.key) { - request.auth(this.key, "", { type: "basic" }); - } - url = new URL(urlPath); - if (params !== undefined) { - if (method === exports.METHODS.GET || method === exports.METHODS.DELETE) { - request.query(params); - Object.entries(params).forEach(function (_a) { - var _b = __read(_a, 2), key = _b[0], value = _b[1]; - url.searchParams.append(key, "".concat(value)); - }); - } - else { - request.send(params); - } - } - baseHooksValue = { - method: method, - path: url.toString(), - // a hack to get the body of the request in the hooks - requestBody: request._data, - headers: requestHeaders, - requestTimestamp: Date.now(), - requestUUID: (0, uuid_1.v4)(), - }; - this.requestHooks.forEach(function (fn) { return fn(baseHooksValue); }); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, request]; - case 2: - response = _a.sent(); - if (this.responseHooks.length > 0) { - responseHooksValue_1 = this._createResponseHooksValue(baseHooksValue, response); - this.responseHooks.forEach(function (fn) { return fn(responseHooksValue_1); }); - } - return [2 /*return*/, response]; - case 3: - error_1 = _a.sent(); - if (!error_1 || typeof error_1 !== "object") { - throw error_1; - } - if ("response" in error_1 && - error_1.response && - typeof error_1.response === "object" && - "body" in error_1.response && - error_1.response.body) { - responseHooksValue_2 = this._createResponseHooksValue(baseHooksValue, error_1.response); - this.responseHooks.forEach(function (fn) { return fn(responseHooksValue_2); }); - if (error_handler_1.default.isAPIError(error_1.response)) { - throw error_handler_1.default.handleApiError(error_1.response); - } - } - throw error_1; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Make a GET HTTP request. - * @param path - The partial path to append to the base url for the request. - * @param [params] - The parameters to send with the request. - * @param [headers] - Additional headers to send with the request. - * @returns The response from the HTTP request. - */ - EasyPostClient.prototype._get = function (path, params, headers) { - if (params === void 0) { params = {}; } - if (headers === void 0) { headers = {}; } - return this._request(path, exports.METHODS.GET, params, headers); - }; - /** - * Make a POST HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {any} [params] - The parameters to send with the request. - * @param {Record} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - EasyPostClient.prototype._post = function (path, params, headers) { - if (params === void 0) { params = {}; } - if (headers === void 0) { headers = {}; } - return this._request(path, exports.METHODS.POST, params, headers); - }; - /** - * Make a PUT HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {any} [params] - The parameters to send with the request. - * @param {Record} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - EasyPostClient.prototype._put = function (path, params, headers) { - if (params === void 0) { params = {}; } - if (headers === void 0) { headers = {}; } - return this._request(path, exports.METHODS.PUT, params, headers); - }; - /** - * Make a PATCH HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {any} [params] - The parameters to send with the request. - * @param {Record} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - EasyPostClient.prototype._patch = function (path, params, headers) { - if (params === void 0) { params = {}; } - if (headers === void 0) { headers = {}; } - return this._request(path, exports.METHODS.PATCH, params, headers); - }; - /** - * Make a DELETE HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {any} [params] - The parameters to send with the request. - * @param {Record} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - EasyPostClient.prototype._delete = function (path, params, headers) { - if (params === void 0) { params = {}; } - if (headers === void 0) { headers = {}; } - return this._request(path, exports.METHODS.DELETE, params, headers); - }; - return EasyPostClient; -}()); -exports.default = EasyPostClient; diff --git a/out/src/errors/api/api_error.js b/out/src/errors/api/api_error.js deleted file mode 100644 index fa72b8d72..000000000 --- a/out/src/errors/api/api_error.js +++ /dev/null @@ -1,46 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var easypost_error_1 = __importDefault(require("../easypost_error")); -/** - * The ApiError class is used to represent errors that occurred while communicating with the EasyPost API. - * This class should not be instantiated directly. - * @internal - * @abstract - * @extends EasyPostError - * @property {string} [message] - The message to be displayed when the error is logged. - * @property {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @property {number} [statusCode] - The HTTP status code returned by the HTTP request to the EasyPost API. - * @property {EasyPostError[]} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var ApiError = /** @class */ (function (_super) { - __extends(ApiError, _super); - function ApiError(_a) { - var _b = _a === void 0 ? {} : _a, message = _b.message, code = _b.code, statusCode = _b.statusCode, errors = _b.errors; - var _this = _super.call(this, { message: message }) || this; - _this.code = code; - _this.errors = errors; - _this.message = message; - _this.statusCode = statusCode; - return _this; - } - return ApiError; -}(easypost_error_1.default)); -exports.default = ApiError; diff --git a/out/src/errors/api/bad_request_error.js b/out/src/errors/api/bad_request_error.js deleted file mode 100644 index 11511de36..000000000 --- a/out/src/errors/api/bad_request_error.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The BadRequestError class is used to represent a 400 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var BadRequestError = /** @class */ (function (_super) { - __extends(BadRequestError, _super); - function BadRequestError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return BadRequestError; -}(api_error_1.default)); -exports.default = BadRequestError; diff --git a/out/src/errors/api/external_api_error.js b/out/src/errors/api/external_api_error.js deleted file mode 100644 index 848e0ccee..000000000 --- a/out/src/errors/api/external_api_error.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The ExternalApiError class is used to represent errors that occurred while communicating with an external API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - */ -var ExternalApiError = /** @class */ (function (_super) { - __extends(ExternalApiError, _super); - function ExternalApiError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return ExternalApiError; -}(api_error_1.default)); -exports.default = ExternalApiError; diff --git a/out/src/errors/api/forbidden_error.js b/out/src/errors/api/forbidden_error.js deleted file mode 100644 index 99034fb0f..000000000 --- a/out/src/errors/api/forbidden_error.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The ForbiddenError class is used to represent a 403 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var ForbiddenError = /** @class */ (function (_super) { - __extends(ForbiddenError, _super); - function ForbiddenError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return ForbiddenError; -}(api_error_1.default)); -exports.default = ForbiddenError; diff --git a/out/src/errors/api/gateway_timeout_error.js b/out/src/errors/api/gateway_timeout_error.js deleted file mode 100644 index 10fb43e44..000000000 --- a/out/src/errors/api/gateway_timeout_error.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The GatewayTimeoutError class is used to represent a 504 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var GatewayTimeoutError = /** @class */ (function (_super) { - __extends(GatewayTimeoutError, _super); - function GatewayTimeoutError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return GatewayTimeoutError; -}(api_error_1.default)); -exports.default = GatewayTimeoutError; diff --git a/out/src/errors/api/http_error.js b/out/src/errors/api/http_error.js deleted file mode 100644 index f0c829ec2..000000000 --- a/out/src/errors/api/http_error.js +++ /dev/null @@ -1,37 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The HttpError class is used to represent a generic HTTP-related error that occurred while communicating with the EasyPost API. - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var HTTPError = /** @class */ (function (_super) { - __extends(HTTPError, _super); - function HTTPError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return HTTPError; -}(api_error_1.default)); -exports.default = HTTPError; diff --git a/out/src/errors/api/index.js b/out/src/errors/api/index.js deleted file mode 100644 index b22a03bd7..000000000 --- a/out/src/errors/api/index.js +++ /dev/null @@ -1,34 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./api_error"), exports); -__exportStar(require("./bad_request_error"), exports); -__exportStar(require("./external_api_error"), exports); -__exportStar(require("./forbidden_error"), exports); -__exportStar(require("./gateway_timeout_error"), exports); -__exportStar(require("./http_error"), exports); -__exportStar(require("./index"), exports); -__exportStar(require("./internal_server_error"), exports); -__exportStar(require("./invalid_request_error"), exports); -__exportStar(require("./method_not_allowed_error"), exports); -__exportStar(require("./not_found_error"), exports); -__exportStar(require("./payment_error"), exports); -__exportStar(require("./rate_limit_error"), exports); -__exportStar(require("./redirect_error"), exports); -__exportStar(require("./service_unavailable_error"), exports); -__exportStar(require("./timeout_error"), exports); -__exportStar(require("./unauthorized_error"), exports); -__exportStar(require("./unknown_api_error"), exports); diff --git a/out/src/errors/api/internal_server_error.js b/out/src/errors/api/internal_server_error.js deleted file mode 100644 index 781b23e2f..000000000 --- a/out/src/errors/api/internal_server_error.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The InternalServerError class is used to represent a 500 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var InternalServerError = /** @class */ (function (_super) { - __extends(InternalServerError, _super); - function InternalServerError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return InternalServerError; -}(api_error_1.default)); -exports.default = InternalServerError; diff --git a/out/src/errors/api/invalid_request_error.js b/out/src/errors/api/invalid_request_error.js deleted file mode 100644 index 7aa9018a6..000000000 --- a/out/src/errors/api/invalid_request_error.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The InvalidRequestError class is used to represent a 422 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var InvalidRequestError = /** @class */ (function (_super) { - __extends(InvalidRequestError, _super); - function InvalidRequestError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return InvalidRequestError; -}(api_error_1.default)); -exports.default = InvalidRequestError; diff --git a/out/src/errors/api/method_not_allowed_error.js b/out/src/errors/api/method_not_allowed_error.js deleted file mode 100644 index 1e67cf4a2..000000000 --- a/out/src/errors/api/method_not_allowed_error.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The MethodNotAllowedError class is used to represent a 405 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var MethodNotAllowedError = /** @class */ (function (_super) { - __extends(MethodNotAllowedError, _super); - function MethodNotAllowedError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return MethodNotAllowedError; -}(api_error_1.default)); -exports.default = MethodNotAllowedError; diff --git a/out/src/errors/api/not_found_error.js b/out/src/errors/api/not_found_error.js deleted file mode 100644 index 681604e77..000000000 --- a/out/src/errors/api/not_found_error.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The NotFoundError class is used to represent a 404 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var NotFoundError = /** @class */ (function (_super) { - __extends(NotFoundError, _super); - function NotFoundError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return NotFoundError; -}(api_error_1.default)); -exports.default = NotFoundError; diff --git a/out/src/errors/api/payment_error.js b/out/src/errors/api/payment_error.js deleted file mode 100644 index a97ee8c26..000000000 --- a/out/src/errors/api/payment_error.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The PaymentError class is used to represent a 402 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var PaymentError = /** @class */ (function (_super) { - __extends(PaymentError, _super); - function PaymentError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return PaymentError; -}(api_error_1.default)); -exports.default = PaymentError; diff --git a/out/src/errors/api/rate_limit_error.js b/out/src/errors/api/rate_limit_error.js deleted file mode 100644 index 6af009b0c..000000000 --- a/out/src/errors/api/rate_limit_error.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The RateLimitError class is used to represent a 429 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var RateLimitError = /** @class */ (function (_super) { - __extends(RateLimitError, _super); - function RateLimitError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return RateLimitError; -}(api_error_1.default)); -exports.default = RateLimitError; diff --git a/out/src/errors/api/redirect_error.js b/out/src/errors/api/redirect_error.js deleted file mode 100644 index d6df4fcc8..000000000 --- a/out/src/errors/api/redirect_error.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The RedirectError class is used to represent a 3xx error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var RedirectError = /** @class */ (function (_super) { - __extends(RedirectError, _super); - function RedirectError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return RedirectError; -}(api_error_1.default)); -exports.default = RedirectError; diff --git a/out/src/errors/api/service_unavailable_error.js b/out/src/errors/api/service_unavailable_error.js deleted file mode 100644 index 21c24865c..000000000 --- a/out/src/errors/api/service_unavailable_error.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The ServiceUnavailableError class is used to represent a 503 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var ServiceUnavailableError = /** @class */ (function (_super) { - __extends(ServiceUnavailableError, _super); - function ServiceUnavailableError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return ServiceUnavailableError; -}(api_error_1.default)); -exports.default = ServiceUnavailableError; diff --git a/out/src/errors/api/timeout_error.js b/out/src/errors/api/timeout_error.js deleted file mode 100644 index c4de69b53..000000000 --- a/out/src/errors/api/timeout_error.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The TimeoutError class is used to represent a 408 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var TimeoutError = /** @class */ (function (_super) { - __extends(TimeoutError, _super); - function TimeoutError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return TimeoutError; -}(api_error_1.default)); -exports.default = TimeoutError; diff --git a/out/src/errors/api/unauthorized_error.js b/out/src/errors/api/unauthorized_error.js deleted file mode 100644 index feabd0510..000000000 --- a/out/src/errors/api/unauthorized_error.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The UnauthorizedError class is used to represent a 401 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var UnauthorizedError = /** @class */ (function (_super) { - __extends(UnauthorizedError, _super); - function UnauthorizedError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return UnauthorizedError; -}(api_error_1.default)); -exports.default = UnauthorizedError; diff --git a/out/src/errors/api/unknown_api_error.js b/out/src/errors/api/unknown_api_error.js deleted file mode 100644 index 08b17e0fa..000000000 --- a/out/src/errors/api/unknown_api_error.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var api_error_1 = __importDefault(require("./api_error")); -/** - * The UnknownApiError class is used to represent a generic, unexpected error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -var UnknownApiError = /** @class */ (function (_super) { - __extends(UnknownApiError, _super); - function UnknownApiError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return UnknownApiError; -}(api_error_1.default)); -exports.default = UnknownApiError; diff --git a/out/src/errors/easypost_error.js b/out/src/errors/easypost_error.js deleted file mode 100644 index 739fb7b8b..000000000 --- a/out/src/errors/easypost_error.js +++ /dev/null @@ -1,34 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -/** - * The EasyPostError class is the base class for all errors that occur in the EasyPost Node.js client library. - * This class should not be instantiated directly. - * @internal - * @abstract - * @extends Error - * @param {string} [message] - The message to be displayed when the error is logged. - */ -var EasyPostError = /** @class */ (function (_super) { - __extends(EasyPostError, _super); - function EasyPostError(_a) { - var _b = _a === void 0 ? {} : _a, message = _b.message; - return _super.call(this, message) || this; - } - return EasyPostError; -}(Error)); -exports.default = EasyPostError; diff --git a/out/src/errors/error_handler.js b/out/src/errors/error_handler.js deleted file mode 100644 index fb506c0ae..000000000 --- a/out/src/errors/error_handler.js +++ /dev/null @@ -1,148 +0,0 @@ -"use strict"; -var __values = (this && this.__values) || function(o) { - var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; - if (m) return m.call(o); - if (o && typeof o.length === "number") return { - next: function () { - if (o && i >= o.length) o = void 0; - return { value: o && o[i++], done: !o }; - } - }; - throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var constants_1 = __importDefault(require("../constants")); -var bad_request_error_1 = __importDefault(require("./api/bad_request_error")); -var forbidden_error_1 = __importDefault(require("./api/forbidden_error")); -var gateway_timeout_error_1 = __importDefault(require("./api/gateway_timeout_error")); -var internal_server_error_1 = __importDefault(require("./api/internal_server_error")); -var invalid_request_error_1 = __importDefault(require("./api/invalid_request_error")); -var method_not_allowed_error_1 = __importDefault(require("./api/method_not_allowed_error")); -var not_found_error_1 = __importDefault(require("./api/not_found_error")); -var payment_error_1 = __importDefault(require("./api/payment_error")); -var rate_limit_error_1 = __importDefault(require("./api/rate_limit_error")); -var redirect_error_1 = __importDefault(require("./api/redirect_error")); -var service_unavailable_error_1 = __importDefault(require("./api/service_unavailable_error")); -var timeout_error_1 = __importDefault(require("./api/timeout_error")); -var unauthorized_error_1 = __importDefault(require("./api/unauthorized_error")); -var unknown_api_error_1 = __importDefault(require("./api/unknown_api_error")); -var easypost_error_1 = __importDefault(require("./easypost_error")); -var ErrorHandler = /** @class */ (function () { - function ErrorHandler() { - } - /** - * Recursively traverses a JSON object or array and extracts error messages - * as strings. Adds the extracted messages to the specified messagesList array. - * - * @param {JSONParsableError} errorMessage - The JSON object or array to traverse. - */ - ErrorHandler.traverseJsonElement = function (errorMessage) { - var e_1, _a, e_2, _b; - var messages = []; - if (errorMessage instanceof Array) { - try { - for (var errorMessage_1 = __values(errorMessage), errorMessage_1_1 = errorMessage_1.next(); !errorMessage_1_1.done; errorMessage_1_1 = errorMessage_1.next()) { - var value = errorMessage_1_1.value; - messages = messages.concat(this.traverseJsonElement(value)); - } - } - catch (e_1_1) { e_1 = { error: e_1_1 }; } - finally { - try { - if (errorMessage_1_1 && !errorMessage_1_1.done && (_a = errorMessage_1.return)) _a.call(errorMessage_1); - } - finally { if (e_1) throw e_1.error; } - } - } - else if (errorMessage instanceof Object) { - try { - for (var _c = __values(Object.values(errorMessage)), _d = _c.next(); !_d.done; _d = _c.next()) { - var value = _d.value; - messages = messages.concat(this.traverseJsonElement(value)); - } - } - catch (e_2_1) { e_2 = { error: e_2_1 }; } - finally { - try { - if (_d && !_d.done && (_b = _c.return)) _b.call(_c); - } - finally { if (e_2) throw e_2.error; } - } - } - else { - messages.push(errorMessage.toString()); - } - return messages; - }; - ErrorHandler.isAPIError = function (error) { - return (error && - typeof error.statusCode === "number" && - typeof error.body === "object" && - typeof error.body.error === "object" && - typeof error.body.error.code === "string" && - error.body.error.message && - error.body.error.errors); - }; - /** - * Calculate and generate the appropriate {@link ApiError} based on a received HTTP response error. - * @param {*} error - The errored HTTP response. - * @returns {ApiError} The `ApiError`-based error corresponding to the HTTP status code. - */ - ErrorHandler.handleApiError = function (error) { - var statusCode = error.statusCode; - var _a = error.body.error, code = _a.code, message = _a.message, errors = _a.errors; - var errorParams = { - message: "", - code: code, - statusCode: statusCode, - errors: errors, - }; - try { - var messages = this.traverseJsonElement(message); - errorParams.message = messages.join(", "); - } - catch (e) { - var errorParams_1 = { - message: constants_1.default.ERROR_DESERIALIZATION, - code: "ERROR_DESERIALIZATION_ERROR", - }; - return new easypost_error_1.default(errorParams_1); - } - if (statusCode >= 300 && statusCode < 400) { - return new redirect_error_1.default(errorParams); - } - switch (statusCode) { - case 400: - return new bad_request_error_1.default(errorParams); - case 401: - return new unauthorized_error_1.default(errorParams); - case 402: - return new payment_error_1.default(errorParams); - case 403: - return new forbidden_error_1.default(errorParams); - case 404: - return new not_found_error_1.default(errorParams); - case 405: - return new method_not_allowed_error_1.default(errorParams); - case 408: - return new timeout_error_1.default(errorParams); - case 422: - return new invalid_request_error_1.default(errorParams); - case 429: - return new rate_limit_error_1.default(errorParams); - case 500: - return new internal_server_error_1.default(errorParams); - case 503: - return new service_unavailable_error_1.default(errorParams); - case 504: - return new gateway_timeout_error_1.default(errorParams); - default: - return new unknown_api_error_1.default(errorParams); - } - }; - return ErrorHandler; -}()); -exports.default = ErrorHandler; diff --git a/out/src/errors/general/end_of_pagination_error.js b/out/src/errors/general/end_of_pagination_error.js deleted file mode 100644 index 4969a4ab6..000000000 --- a/out/src/errors/general/end_of_pagination_error.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var constants_1 = __importDefault(require("../../constants")); -var easypost_error_1 = __importDefault(require("../easypost_error")); -/** - * The EndOfPaginationError class is used to represent an error that no more page can be retrieved - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -var EndOfPaginationError = /** @class */ (function (_super) { - __extends(EndOfPaginationError, _super); - function EndOfPaginationError() { - return _super.call(this, { message: constants_1.default.END_OF_PAGINATION }) || this; - } - return EndOfPaginationError; -}(easypost_error_1.default)); -exports.default = EndOfPaginationError; diff --git a/out/src/errors/general/filtering_error.js b/out/src/errors/general/filtering_error.js deleted file mode 100644 index 58f0ebc2f..000000000 --- a/out/src/errors/general/filtering_error.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var easypost_error_1 = __importDefault(require("../easypost_error")); -/** - * The FilteringError class is used to represent an error that occurred while filtering a list (e.g. a list of rates). - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -var FilteringError = /** @class */ (function (_super) { - __extends(FilteringError, _super); - function FilteringError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return FilteringError; -}(easypost_error_1.default)); -exports.default = FilteringError; diff --git a/out/src/errors/general/index.js b/out/src/errors/general/index.js deleted file mode 100644 index 4474c83dc..000000000 --- a/out/src/errors/general/index.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./end_of_pagination_error"), exports); -__exportStar(require("./filtering_error"), exports); -__exportStar(require("./invalid_object_error"), exports); -__exportStar(require("./invalid_parameter_error"), exports); -__exportStar(require("./missing_parameter_error"), exports); -__exportStar(require("./signature_verification_error"), exports); diff --git a/out/src/errors/general/invalid_object_error.js b/out/src/errors/general/invalid_object_error.js deleted file mode 100644 index 4eec5af61..000000000 --- a/out/src/errors/general/invalid_object_error.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var easypost_error_1 = __importDefault(require("../easypost_error")); -/** - * The InvalidObjectError class is used to represent an error due to an invalid object (e.g. missing an expected property). - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -var InvalidObjectError = /** @class */ (function (_super) { - __extends(InvalidObjectError, _super); - function InvalidObjectError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return InvalidObjectError; -}(easypost_error_1.default)); -exports.default = InvalidObjectError; diff --git a/out/src/errors/general/invalid_parameter_error.js b/out/src/errors/general/invalid_parameter_error.js deleted file mode 100644 index a70d99d51..000000000 --- a/out/src/errors/general/invalid_parameter_error.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var easypost_error_1 = __importDefault(require("../easypost_error")); -/** - * The InvalidParameterError class is used to represent an error due to an invalid function parameter. - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -var InvalidParameterError = /** @class */ (function (_super) { - __extends(InvalidParameterError, _super); - function InvalidParameterError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return InvalidParameterError; -}(easypost_error_1.default)); -exports.default = InvalidParameterError; diff --git a/out/src/errors/general/missing_parameter_error.js b/out/src/errors/general/missing_parameter_error.js deleted file mode 100644 index 5dd36613e..000000000 --- a/out/src/errors/general/missing_parameter_error.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var easypost_error_1 = __importDefault(require("../easypost_error")); -/** - * The MissingParameterError class is used to represent an error due to a missing expected function parameter. - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -var MissingParameterError = /** @class */ (function (_super) { - __extends(MissingParameterError, _super); - function MissingParameterError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return MissingParameterError; -}(easypost_error_1.default)); -exports.default = MissingParameterError; diff --git a/out/src/errors/general/signature_verification_error.js b/out/src/errors/general/signature_verification_error.js deleted file mode 100644 index e5ed2a2ee..000000000 --- a/out/src/errors/general/signature_verification_error.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var easypost_error_1 = __importDefault(require("../easypost_error")); -/** - * The SignatureVerificationError class is used to represent an error due to a failed signature verification (e.g. a webhook HMAC signature). - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -var SignatureVerificationError = /** @class */ (function (_super) { - __extends(SignatureVerificationError, _super); - function SignatureVerificationError() { - return _super !== null && _super.apply(this, arguments) || this; - } - return SignatureVerificationError; -}(easypost_error_1.default)); -exports.default = SignatureVerificationError; diff --git a/out/src/errors/index.js b/out/src/errors/index.js deleted file mode 100644 index fdb97728b..000000000 --- a/out/src/errors/index.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./api"), exports); -__exportStar(require("./general"), exports); -__exportStar(require("./easypost_error"), exports); -__exportStar(require("./error_handler"), exports); diff --git a/out/src/index.js b/out/src/index.js deleted file mode 100644 index 6135d506d..000000000 --- a/out/src/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var easypost_1 = __importDefault(require("./easypost")); -exports.default = easypost_1.default; diff --git a/out/src/services/address_service/Address.js b/out/src/services/address_service/Address.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/address_service/Address.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/address_service/AddressCreateParameters.js b/out/src/services/address_service/AddressCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/address_service/AddressCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/address_service/AddressListParameters.js b/out/src/services/address_service/AddressListParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/address_service/AddressListParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/address_service/Verification.js b/out/src/services/address_service/Verification.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/address_service/Verification.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/address_service/VerificationDetails.js b/out/src/services/address_service/VerificationDetails.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/address_service/VerificationDetails.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/address_service/Verifications.js b/out/src/services/address_service/Verifications.js deleted file mode 100644 index 2367d855d..000000000 --- a/out/src/services/address_service/Verifications.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = {}; diff --git a/out/src/services/address_service/index.js b/out/src/services/address_service/index.js deleted file mode 100644 index 36c9fed6c..000000000 --- a/out/src/services/address_service/index.js +++ /dev/null @@ -1,217 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./Address"), exports); -__exportStar(require("./AddressCreateParameters"), exports); -__exportStar(require("./Verification"), exports); -__exportStar(require("./VerificationDetails"), exports); -__exportStar(require("./Verifications"), exports); -exports.default = (function (easypostClient) { - /** - * The AddressService class provides methods for interacting with EasyPost {@link Address} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(AddressService, _super); - function AddressService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create an {@link Address address}. - * See {@link https://www.easypost.com/docs/api/node#create-an-address EasyPost API Documentation} for more information. - * @param params - Parameters for the address to be created. - * @returns - The created address. - */ - AddressService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "addresses"; - wrappedParams = { - address: params, - }; - if (params.verify) { - wrappedParams.verify = params.verify; - delete params.verify; - } - if (params.verify_strict) { - wrappedParams.verify_strict = params.verify_strict; - delete params.verify_strict; - } - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Create and verify an {@link Address address} in a single request. - * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. - * @param params - Parameters for the address to be created. - * @returns - The created and verified address. - */ - AddressService.createAndVerify = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "addresses/create_and_verify"; - wrappedParams = { address: params }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body.address, wrappedParams)]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve all {@link Address addresses} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-addresses EasyPost API Documentation} for more information. - * @param params - Parameters to filter the list of addresses. - * @returns - An object containing a list of {@link Address addresses} and pagination information. - */ - AddressService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "addresses"; - return [2 /*return*/, this._all(url, params)]; - }); - }); - }; - /** - * Retrieve the next page of Address collection. - * @param addresses An object containing a list of {@link Address addresses} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - AddressService.getNextPage = function (addresses, pageSize) { - if (pageSize === void 0) { pageSize = null; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "addresses"; - return [2 /*return*/, this._getNextPage(url, "addresses", addresses, pageSize)]; - }); - }); - }; - /** - * Retrieve an {@link Address address} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-address EasyPost API Documentation} for more information. - * @param id - The ID of the address to retrieve. - * @returns - The retrieved address. - */ - AddressService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "addresses/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - /** - * Verify an {@link Address address} by its ID. - * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. - * @param id - The ID of the address to verify. - * @returns - The verified address. - */ - AddressService.verifyAddress = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, response, e_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - _a.trys.push([0, 2, , 3]); - url = "addresses/".concat(id, "/verify"); - return [4 /*yield*/, easypostClient._get(url)]; - case 1: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body.address)]; - case 2: - e_2 = _a.sent(); - return [2 /*return*/, Promise.reject(e_2)]; - case 3: return [2 /*return*/]; - } - }); - }); - }; - return AddressService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/api_key_service/ApiKey.js b/out/src/services/api_key_service/ApiKey.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/api_key_service/ApiKey.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/api_key_service/index.js b/out/src/services/api_key_service/index.js deleted file mode 100644 index 5c7ee05c0..000000000 --- a/out/src/services/api_key_service/index.js +++ /dev/null @@ -1,142 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var node_util_1 = __importDefault(require("node:util")); -var base_service_1 = __importDefault(require("../base_service")); -var constants_1 = __importDefault(require("../../constants")); -var filtering_error_1 = __importDefault(require("../../errors/general/filtering_error")); -__exportStar(require("./ApiKey"), exports); -exports.default = (function (easypostClient) { - /** - * The ApiKeyService class provides methods for interacting with EasyPost {@link ApiKey} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(ApiKeyService, _super); - function ApiKeyService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Retrieve all {@link ApiKey API keys} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. - * @returns - An object containing the API keys associated with the current authenticated user and its child users. - */ - ApiKeyService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "api_keys"; - return [2 /*return*/, this._all(url, params)]; - }); - }); - }; - /** - * Retrieve API Keys for a specified {@link User user}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. - * @param id - The ID of the user to retrieve keys for. - * @returns - List of associated API Keys. - * @throws {FilteringError} If user or API Keys are not found. - */ - ApiKeyService.retrieveApiKeysForUser = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, response, user, childUser, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "api_keys"; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._get(url)]; - case 2: - response = _a.sent(); - user = this._convertToEasyPostObject(response.body); - if (user.id == id) { - return [2 /*return*/, user.keys]; - } - childUser = user.children.find(function (child) { return child.id === id; }); - if (childUser) { - return [2 /*return*/, childUser.keys]; - } - return [3 /*break*/, 4]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: throw new filtering_error_1.default({ - message: node_util_1.default.format(constants_1.default.NO_OBJECT_FOUND, "child"), - }); - } - }); - }); - }; - return ApiKeyService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/base_service.js b/out/src/services/base_service.js deleted file mode 100644 index 201503911..000000000 --- a/out/src/services/base_service.js +++ /dev/null @@ -1,192 +0,0 @@ -"use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var end_of_pagination_error_1 = __importDefault(require("../errors/general/end_of_pagination_error")); -exports.default = (function (easypostClient) { - /** - * The base class for all EasyPost client library services. - * @param {EasyPostClient} easypostClient The {@link EasyPostClient} instance to use for API calls. - */ - return /** @class */ (function () { - function BaseService() { - } - /** - * Converts a JSON response and all its nested elements to associated {@link EasyPostObject}-based class instances. - * @internal - * @param {*} response The JSON response to convert (usually a `Map` or `Array`). - * @param {*} params The parameters passed when fetching the response - * @returns {*} An {@link EasyPostObject}-based class instance or an `Array` of {@link EasyPostObject}-based class instances. - */ - BaseService._convertToEasyPostObject = function (response, params) { - var newResponse = response; - newResponse._params = params; - return newResponse; - }; - /** - * Creates an EasyPost Object via the API. - * @internal - * @param url The URL to send the API request to. - * @param params The parameters to send with the API request. - * @returns The created {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - BaseService._create = function (url, params) { - return __awaiter(this, void 0, void 0, function () { - var response, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - _a.trys.push([0, 2, , 3]); - return [4 /*yield*/, easypostClient._post(url, params)]; - case 1: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body, params)]; - case 2: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 3: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve a list of records from the API. - * @internal - * @param url The URL to send the API request to. - * @param params The parameters to send with the API request. - * @returns The retrieved {@link EasyPostObject}-based class instance(s), or a `Promise` that rejects with an error. - */ - BaseService._all = function (url, params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var response, e_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - _a.trys.push([0, 2, , 3]); - return [4 /*yield*/, easypostClient._get(url, params)]; - case 1: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body, params)]; - case 2: - e_2 = _a.sent(); - return [2 /*return*/, Promise.reject(e_2)]; - case 3: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve a record from the API. - * @internal - * @param url The URL to send the API request to. - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - BaseService._retrieve = function (url) { - return __awaiter(this, void 0, void 0, function () { - var response, e_3; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - _a.trys.push([0, 2, , 3]); - return [4 /*yield*/, easypostClient._get(url)]; - case 1: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body)]; - case 2: - e_3 = _a.sent(); - return [2 /*return*/, Promise.reject(e_3)]; - case 3: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve the next page of specific collection of object - * @internal - * @param url The URL to send the API request to. - * @param collection The collection of a specific object. - * @param pageSize The number of records to return on each page. - * @param optionalParams The optional param for additional value in the query string. - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - * TODO: Implement this function in EndShippers and Batches once the API supports them properly. - */ - BaseService._getNextPage = function (url, key, collection, pageSize, optionalParams) { - var _a, _b, _c; - if (pageSize === void 0) { pageSize = null; } - if (optionalParams === void 0) { optionalParams = {}; } - return __awaiter(this, void 0, void 0, function () { - var collectionArray, defaultParams, params, response; - return __generator(this, function (_d) { - switch (_d.label) { - case 0: - collectionArray = collection[key]; - if (collectionArray == undefined || - collectionArray.length == 0 || - !collection.has_more) { - throw new end_of_pagination_error_1.default(); - } - defaultParams = (_b = (_a = collection._params) !== null && _a !== void 0 ? _a : collectionArray[0]._params) !== null && _b !== void 0 ? _b : {}; - params = __assign(__assign(__assign({}, defaultParams), { page_size: (_c = defaultParams.page_size) !== null && _c !== void 0 ? _c : pageSize, before_id: collectionArray[collectionArray.length - 1].id }), optionalParams); - return [4 /*yield*/, this._all(url, params)]; - case 1: - response = _d.sent(); - if (response == undefined || response[key].length == 0) { - throw new end_of_pagination_error_1.default(); - } - return [2 /*return*/, response]; - } - }); - }); - }; - return BaseService; - }()); -}); diff --git a/out/src/services/batch_service/Batch.js b/out/src/services/batch_service/Batch.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/batch_service/Batch.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/batch_service/BatchCreateParameters.js b/out/src/services/batch_service/BatchCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/batch_service/BatchCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/batch_service/BatchListParameters.js b/out/src/services/batch_service/BatchListParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/batch_service/BatchListParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/batch_service/BatchShipment.js b/out/src/services/batch_service/BatchShipment.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/batch_service/BatchShipment.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/batch_service/BatchState.js b/out/src/services/batch_service/BatchState.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/batch_service/BatchState.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/batch_service/BatchStatus.js b/out/src/services/batch_service/BatchStatus.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/batch_service/BatchStatus.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/batch_service/BatchStatuses.js b/out/src/services/batch_service/BatchStatuses.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/batch_service/BatchStatuses.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/batch_service/index.js b/out/src/services/batch_service/index.js deleted file mode 100644 index 4fe17ea0a..000000000 --- a/out/src/services/batch_service/index.js +++ /dev/null @@ -1,293 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.DEFAULT_LABEL_FORMAT = void 0; -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./Batch"), exports); -__exportStar(require("./BatchCreateParameters"), exports); -__exportStar(require("./BatchListParameters"), exports); -__exportStar(require("./BatchShipment"), exports); -__exportStar(require("./BatchState"), exports); -__exportStar(require("./BatchStatus"), exports); -__exportStar(require("./BatchStatuses"), exports); -exports.DEFAULT_LABEL_FORMAT = "pdf"; -exports.default = (function (easypostClient) { - /** - * The BatchService class provides methods for interacting with EasyPost {@link Batch} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(BatchService, _super); - function BatchService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#create-a-batch EasyPost API Documentation} for more information. - * @param params - Parameters for the batch to be created. - * @returns - The created batch. - */ - BatchService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "batches"; - wrappedParams = { - batch: params, - }; - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Add {@link Shipment shipments} to a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#add-shipments-to-a-batch EasyPost API Documentation} for more information. - * @param id - The id of the batch to add shipments to. - * @param shipmentIds - The ids of the shipments to add to the batch. - * @returns - The updated batch. - */ - BatchService.addShipments = function (id, shipmentIds) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "batches/".concat(id, "/add_shipments"); - wrappedParams = { - shipments: shipmentIds.map(function (s) { return ({ id: s }); }), - }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Removes {@link Shipment shipments} from a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#remove-shipments-from-a-batch EasyPost API Documentation} for more information. - * @param id - The id of the batch to remove shipments from. - * @param shipmentIds - The ids of the shipments to remove from the batch. - * @returns - The updated batch. - */ - BatchService.removeShipments = function (id, shipmentIds) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, e_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "batches/".concat(id, "/remove_shipments"); - wrappedParams = { - shipments: shipmentIds.map(function (s) { return ({ id: s }); }), - }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; - case 3: - e_2 = _a.sent(); - return [2 /*return*/, Promise.reject(e_2)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Generate a label for a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#batch-labels EasyPost API Documentation} for more information. - * @param id - The id of the batch to generate a label for. - * @param fileFormat - The format of the label to generate. Defaults to 'pdf'. - * @returns - The updated batch. - */ - BatchService.generateLabel = function (id, fileFormat) { - if (fileFormat === void 0) { fileFormat = exports.DEFAULT_LABEL_FORMAT; } - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, e_3; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "batches/".concat(id, "/label"); - wrappedParams = { file_format: fileFormat }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; - case 3: - e_3 = _a.sent(); - return [2 /*return*/, Promise.reject(e_3)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Create a {@link ScanForm scan form} for a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#manifesting-scan-form EasyPost API Documentation} for more information. - * @param id - The id of the batch to create a scan form for. - * @returns - The updated batch. - */ - BatchService.createScanForm = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, response, e_4; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "batches/".concat(id, "/scan_form"); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body)]; - case 3: - e_4 = _a.sent(); - return [2 /*return*/, Promise.reject(e_4)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Purchase a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-batch EasyPost API Documentation} for more information. - * @param id - The id of the batch to purchase. - * @returns - The purchased batch. - */ - BatchService.buy = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, response, e_5; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "batches/".concat(id, "/buy"); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body)]; - case 3: - e_5 = _a.sent(); - return [2 /*return*/, Promise.reject(e_5)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve all {@link Batch batches} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#list-all-batches EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of batches. - * @returns - An object containing a list of {@link Batch batches} and pagination information. - */ - BatchService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "batches"; - return [2 /*return*/, this._all(url, params)]; - }); - }); - }; - /** - * Retrieve a {@link Batch batch} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-batch EasyPost API Documentation} for more information. - * @param id - The ID of the batch to retrieve. - * @returns - The retrieved batch. - */ - BatchService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "batches/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return BatchService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/beta_rate_service/index.js b/out/src/services/beta_rate_service/index.js deleted file mode 100644 index cdc29c696..000000000 --- a/out/src/services/beta_rate_service/index.js +++ /dev/null @@ -1,99 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -/** - * @extends baseService - */ -exports.default = (function (easypostClient) { - return /** @class */ (function (_super) { - __extends(BetaRateService, _super); - function BetaRateService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Retrieve a list of stateless {@link Rate rates} based on the provided parameters. - * @param params - Map of parameters for the API call - * @returns - List of stateless rates - */ - BetaRateService.retrieveStatelessRates = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "beta/rates"; - wrappedParams = { - shipment: params, - }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body.rates, wrappedParams)]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - return BetaRateService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/beta_referral_customer_service/index.js b/out/src/services/beta_referral_customer_service/index.js deleted file mode 100644 index 6ed1cce5b..000000000 --- a/out/src/services/beta_referral_customer_service/index.js +++ /dev/null @@ -1,142 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -exports.default = (function (easypostClient) { - return /** @class */ (function (_super) { - __extends(BetaReferralCustomerService, _super); - function BetaReferralCustomerService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Add an existing Stripe payment method to a {@link User referral customer's} account. - * @param stripeCustomerId - The Stripe account's ID. - * @param paymentMethodReference - Reference of Stripe payment method. - * @param [priority] - Which priority to set the payment method to ('primary' or 'secondary'). - * @returns - A JSON object representing the payment method. - */ - BetaReferralCustomerService.addPaymentMethod = function (stripeCustomerId, paymentMethodReference, priority) { - if (priority === void 0) { priority = "primary"; } - return __awaiter(this, void 0, void 0, function () { - var wrappedParams, url, response; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - wrappedParams = { - payment_method: { - stripe_customer_id: stripeCustomerId, - payment_method_reference: paymentMethodReference, - priority: priority, - }, - }; - url = "beta/referral_customers/payment_method"; - return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; - case 1: - response = _a.sent(); - return [2 /*return*/, response]; - } - }); - }); - }; - /** - * Refund by amount for a recent payment. - * @param refundAmount - Amount to be refunded by cents. - * @returns - A JSON object representing the refund. - */ - BetaReferralCustomerService.refundByAmount = function (refundAmount) { - return __awaiter(this, void 0, void 0, function () { - var params, url, response; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - params = { - refund_amount: refundAmount, - }; - url = "beta/referral_customers/refunds"; - return [4 /*yield*/, easypostClient._post(url, params)]; - case 1: - response = _a.sent(); - return [2 /*return*/, response]; - } - }); - }); - }; - /** - * Refund a payment by a payment log ID. - * @param paymentLogId - ID of the payment log. - * @returns - Returns BetaPaymentRefund object. - */ - BetaReferralCustomerService.refundByPaymentLog = function (paymentLogId) { - return __awaiter(this, void 0, void 0, function () { - var params, url, response; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - params = { - payment_log_id: paymentLogId, - }; - url = "beta/referral_customers/refunds"; - return [4 /*yield*/, easypostClient._post(url, params)]; - case 1: - response = _a.sent(); - return [2 /*return*/, response]; - } - }); - }); - }; - return BetaReferralCustomerService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/billing_service/PaymentMethod.js b/out/src/services/billing_service/PaymentMethod.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/billing_service/PaymentMethod.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/billing_service/index.js b/out/src/services/billing_service/index.js deleted file mode 100644 index b1ccd20f1..000000000 --- a/out/src/services/billing_service/index.js +++ /dev/null @@ -1,203 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var constants_1 = __importDefault(require("../../constants")); -var invalid_object_error_1 = __importDefault(require("../../errors/general/invalid_object_error")); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./PaymentMethod"), exports); -exports.default = (function (easypostClient) { - /** - * The BillingService class provides methods for interacting with EasyPost's billing capabilities. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(BillingService, _super); - function BillingService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Fund your EasyPost wallet by charging your primary or secondary payment method on file. - * See {@link https://www.easypost.com/docs/api/node#add-funds-to-your-wallet-one-time-charge EasyPost API Documentation} for more information. - * @param amount - The amount to charge to your payment method. - * @param priority - The priority of the payment method to charge. Can be either 'primary' or 'secondary'. - */ - BillingService.fundWallet = function (amount, priority) { - if (priority === void 0) { priority = "primary"; } - return __awaiter(this, void 0, void 0, function () { - var paymentInfo, endpoint, paymentMethodID, url, wrappedParams; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this._getPaymentInfo(priority.toLowerCase())]; - case 1: - paymentInfo = _a.sent(); - endpoint = paymentInfo[0]; - paymentMethodID = paymentInfo[1]; - url = "".concat(endpoint, "/").concat(paymentMethodID, "/charges"); - wrappedParams = { amount: amount }; - return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; - case 2: - _a.sent(); - return [2 /*return*/]; - } - }); - }); - }; - /** - * Delete a payment method from the current authenticated user's account. - * See {@link https://www.easypost.com/docs/api/node#delete-a-payment-method EasyPost API Documentation} for more information. - * @param priority - The priority of the payment method to delete. Can be either 'primary' or 'secondary'. - */ - BillingService.deletePaymentMethod = function (priority) { - return __awaiter(this, void 0, void 0, function () { - var paymentInfo, endpoint, paymentMethodID, url; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this._getPaymentInfo(priority.toLowerCase())]; - case 1: - paymentInfo = _a.sent(); - endpoint = paymentInfo[0]; - paymentMethodID = paymentInfo[1]; - url = "".concat(endpoint, "/").concat(paymentMethodID); - return [4 /*yield*/, easypostClient._delete(url)]; - case 2: - _a.sent(); - return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve all payment methods associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-payment-methods EasyPost API Documentation} for more information. - * @returns {Object} - An object containing the payment methods associated with the current authenticated user. - */ - BillingService.retrievePaymentMethods = function () { - return __awaiter(this, void 0, void 0, function () { - var url, res; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "payment_methods"; - return [4 /*yield*/, easypostClient._get(url)]; - case 1: - res = _a.sent(); - if (res.body.id === null) { - throw new invalid_object_error_1.default({ message: constants_1.default.NO_PAYMENT_METHODS }); - } - return [2 /*return*/, res.body]; - } - }); - }); - }; - /** - * Get payment info (type of the payment method and ID of the payment method) - * This function is intended for internal use only, please avoid using this function - * @private - * @param {String} priority - The priority of the payment method to retrieve. Can be either 'primary' or 'secondary'. - * @returns {string[]} - An array of two strings, the first being the endpoint of the payment method and the second being the ID of the payment method. - */ - BillingService._getPaymentInfo = function (priority) { - return __awaiter(this, void 0, void 0, function () { - var paymentMethods, paymentMethodMap, paymentMethodToUse, paymentMethodID, endpoint, errorString; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.retrievePaymentMethods()]; - case 1: - paymentMethods = _a.sent(); - paymentMethodMap = { - primary: "primary_payment_method", - secondary: "secondary_payment_method", - }; - paymentMethodToUse = paymentMethodMap[priority]; - errorString = "The chosen payment method is not valid. Please try again."; - if (paymentMethodToUse !== undefined && - paymentMethods[paymentMethodToUse] !== null) { - paymentMethodID = paymentMethods[paymentMethodToUse].id; - if (paymentMethodID.startsWith("card_")) { - endpoint = "credit_cards"; - } - else if (paymentMethodID.startsWith("bank_")) { - endpoint = "bank_accounts"; - } - else { - throw new invalid_object_error_1.default({ message: errorString }); - } - } - else { - throw new invalid_object_error_1.default({ message: errorString }); - } - return [2 /*return*/, [endpoint, paymentMethodID]]; - } - }); - }); - }; - return BillingService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/carrier_account_service/CarrierAccount.js b/out/src/services/carrier_account_service/CarrierAccount.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/carrier_account_service/CarrierAccount.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_account_service/CarrierAccountCreateParameters.js b/out/src/services/carrier_account_service/CarrierAccountCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/carrier_account_service/CarrierAccountCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_account_service/CarrierAccountField.js b/out/src/services/carrier_account_service/CarrierAccountField.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/carrier_account_service/CarrierAccountField.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_account_service/CarrierAccountFields.js b/out/src/services/carrier_account_service/CarrierAccountFields.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/carrier_account_service/CarrierAccountFields.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_account_service/index.js b/out/src/services/carrier_account_service/index.js deleted file mode 100644 index e0581a34e..000000000 --- a/out/src/services/carrier_account_service/index.js +++ /dev/null @@ -1,216 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var node_util_1 = __importDefault(require("node:util")); -var base_service_1 = __importDefault(require("../base_service")); -var constants_1 = __importDefault(require("../../constants")); -var invalid_parameter_error_1 = __importDefault(require("../../errors/general/invalid_parameter_error")); -__exportStar(require("./CarrierAccount"), exports); -__exportStar(require("./CarrierAccountCreateParameters"), exports); -__exportStar(require("./CarrierAccountField"), exports); -__exportStar(require("./CarrierAccountFields"), exports); -exports.default = (function (easypostClient) { - /** - * The CarrierAccountService class provides methods for interacting with EasyPost @{link CarrierAccount} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(CarrierAccountService, _super); - function CarrierAccountService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create a {@link CarrierAccount carrier account}. - * See {@link https://www.easypost.com/docs/api/node#create-a-carrier-account EasyPost API Documentation} for more information. - * @param params - Parameters for the carrier account to be created. - * @returns - The created carrier account. - */ - CarrierAccountService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var carrierAccountType, endpoint, wrappedParams; - return __generator(this, function (_a) { - carrierAccountType = params.type; - if (!carrierAccountType) { - throw new invalid_parameter_error_1.default({ - message: node_util_1.default.format(constants_1.default.MISSING_REQUIRED_PARAMETER, "CarrierAccount type"), - }); - } - endpoint = this._selectCarrierAccountCreationEndpoint(carrierAccountType); - wrappedParams = { carrier_account: params }; - return [2 /*return*/, this._create(endpoint, wrappedParams)]; - }); - }); - }; - /** - * Update a {@link CarrierAccount carrier account}. - * See {@link https://www.easypost.com/docs/api/node#update-a-carrieraccount EasyPost API Documentation} for more information. - * @param id - The id of the carrier account to be updated. - * @param params - Parameters for the carrier account to be updated. - * @returns - The updated carrier account. - */ - CarrierAccountService.update = function (id, params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "carrier_accounts/".concat(id); - wrappedParams = { - carrier_account: params, - }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._patch(url, wrappedParams)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Delete a {@link CarrierAccount carrier account}. - * See {@link https://www.easypost.com/docs/api/node#delete-a-carrier-account EasyPost API Documentation} for more information. - * @param id - The id of the carrier account to be deleted. - * @returns - A promise that resolves when the carrier account has been deleted. - */ - CarrierAccountService.delete = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, e_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "carrier_accounts/".concat(id); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._delete(url)]; - case 2: - _a.sent(); - return [2 /*return*/, Promise.resolve()]; - case 3: - e_2 = _a.sent(); - return [2 /*return*/, Promise.reject(e_2)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Returns the correct carrier_account endpoint when creating a record based on the type. - * @private - * @param {string} carrierAccountType - The type of carrier account to be created. - * @returns {string} - The endpoint to be used for the carrier account creation request. - */ - CarrierAccountService._selectCarrierAccountCreationEndpoint = function (carrierAccountType) { - if (constants_1.default.CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS.includes(carrierAccountType)) { - return "carrier_accounts/register"; - } - return "carrier_accounts"; - }; - /** - * Retrieve all {@link CarrierAccount carrier accounts} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#list-all-carrier-accounts EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of carrier accounts. - * @returns - An object containing a list of {@link CarrierAccount carrier accounts} and pagination information. - */ - CarrierAccountService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "carrier_accounts"; - return [2 /*return*/, this._all(url, params)]; - }); - }); - }; - /** - * Retrieve a {@link CarrierAccount carrier account} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-carrieraccount EasyPost API Documentation} for more information. - * @param id - The ID of the carrier account to retrieve. - * @returns - The retrieved carrier account. - */ - CarrierAccountService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "carrier_accounts/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return CarrierAccountService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/carrier_metadata_service/CarrierMetadata.js b/out/src/services/carrier_metadata_service/CarrierMetadata.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/carrier_metadata_service/CarrierMetadata.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_metadata_service/index.js b/out/src/services/carrier_metadata_service/index.js deleted file mode 100644 index b67458d12..000000000 --- a/out/src/services/carrier_metadata_service/index.js +++ /dev/null @@ -1,124 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./CarrierMetadata"), exports); -exports.default = (function (easypostClient) { - return /** @class */ (function (_super) { - __extends(CarrierMetadataService, _super); - function CarrierMetadataService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Retrieve a list of carrier metadata based on the provided parameters. - * @param carriers - List of carrier in string - * @param type - List of types in string - * @returns - List of carrier metadata - */ - CarrierMetadataService.retrieve = function (carriers, types) { - if (carriers === void 0) { carriers = null; } - if (types === void 0) { types = null; } - return __awaiter(this, void 0, void 0, function () { - var url, params, response, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "metadata/carriers"; - params = __assign(__assign({}, (carriers && - carriers.length > 0 && { carriers: carriers.join(",") })), (types && types.length > 0 && { types: types.join(",") })); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._get(url, params)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body.carriers || [], params)]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - return CarrierMetadataService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/carrier_type_service/CarrierType.js b/out/src/services/carrier_type_service/CarrierType.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/carrier_type_service/CarrierType.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_type_service/CarrierTypeCredentials.js b/out/src/services/carrier_type_service/CarrierTypeCredentials.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/carrier_type_service/CarrierTypeCredentials.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_type_service/CarrierTypeFields.js b/out/src/services/carrier_type_service/CarrierTypeFields.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/carrier_type_service/CarrierTypeFields.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/carrier_type_service/index.js b/out/src/services/carrier_type_service/index.js deleted file mode 100644 index cf05d13d8..000000000 --- a/out/src/services/carrier_type_service/index.js +++ /dev/null @@ -1,116 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./CarrierType"), exports); -__exportStar(require("./CarrierTypeCredentials"), exports); -__exportStar(require("./CarrierTypeFields"), exports); -exports.default = (function (easypostClient) { - /** - * The CarrierTypeService class provides methods for interacting with EasyPost {@link CarrierType} objects. - * @param easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(CarrierTypeService, _super); - function CarrierTypeService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Retrieve all {@link CarrierType carrier types} available to the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-available-carrier-types EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of carrier types. - * @returns - A list of {@link CarrierType carrier types}. - */ - CarrierTypeService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url, response, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "carrier_types"; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._get(url, params)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body, params)]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - return CarrierTypeService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/customs_info_service/CustomsInfo.js b/out/src/services/customs_info_service/CustomsInfo.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/customs_info_service/CustomsInfo.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/customs_info_service/CustomsInfoCreateParameters.js b/out/src/services/customs_info_service/CustomsInfoCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/customs_info_service/CustomsInfoCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/customs_info_service/index.js b/out/src/services/customs_info_service/index.js deleted file mode 100644 index db2c553ed..000000000 --- a/out/src/services/customs_info_service/index.js +++ /dev/null @@ -1,119 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./CustomsInfo"), exports); -__exportStar(require("./CustomsInfoCreateParameters"), exports); -exports.default = (function (easypostClient) { - /** - * The CustomsInfoService class provides methods for interacting with EasyPost {@link CustomsInfo} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(CustomsInfoService, _super); - function CustomsInfoService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create a {@link CustomsInfo customs info} record. - * See {@link https://www.easypost.com/docs/api/node#create-a-customsinfo EasyPost API Documentation} for more information. - * @param params - Parameters for the customs info to be created. - * @returns - The created customs info. - */ - CustomsInfoService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "customs_infos"; - wrappedParams = { - customs_info: params, - }; - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Retrieve a {@link CustomsInfo customs info} record by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-customsinfo EasyPost API Documentation} for more information. - * @param id - The ID of the customs info to retrieve. - * @returns - The retrieved customs info. - */ - CustomsInfoService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "customs_infos/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return CustomsInfoService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/customs_item_service/CustomsItem.js b/out/src/services/customs_item_service/CustomsItem.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/customs_item_service/CustomsItem.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/customs_item_service/CustomsItemCreateParameters.js b/out/src/services/customs_item_service/CustomsItemCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/customs_item_service/CustomsItemCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/customs_item_service/index.js b/out/src/services/customs_item_service/index.js deleted file mode 100644 index 2bf4f0fd7..000000000 --- a/out/src/services/customs_item_service/index.js +++ /dev/null @@ -1,119 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./CustomsItem"), exports); -__exportStar(require("./CustomsItemCreateParameters"), exports); -exports.default = (function (easypostClient) { - /** - * The CustomsItemService class provides methods for interacting with EasyPost {@link CustomsItem} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(CustomsItemService, _super); - function CustomsItemService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create a {@link CustomsItem customs item}. - * See {@link https://www.easypost.com/docs/api/node#create-a-customsitem EasyPost API Documentation} for more information. - * @param params - Parameters for the customs item to be created. - * @returns - The created customs item. - */ - CustomsItemService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "customs_items"; - wrappedParams = { - customs_item: params, - }; - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Retrieve a {@link CustomsItem customs item} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-customsitem EasyPost API Documentation} for more information. - * @param id - The ID of the customs item to retrieve. - * @returns - The retrieved customs item. - */ - CustomsItemService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "customs_items/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return CustomsItemService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/end_shipper_service/EndShipper.js b/out/src/services/end_shipper_service/EndShipper.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/end_shipper_service/EndShipper.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/end_shipper_service/EndShipperCreateParameters.js b/out/src/services/end_shipper_service/EndShipperCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/end_shipper_service/EndShipperCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/end_shipper_service/EndShipperListParameters.js b/out/src/services/end_shipper_service/EndShipperListParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/end_shipper_service/EndShipperListParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/end_shipper_service/index.js b/out/src/services/end_shipper_service/index.js deleted file mode 100644 index 0f03b9124..000000000 --- a/out/src/services/end_shipper_service/index.js +++ /dev/null @@ -1,164 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./EndShipper"), exports); -__exportStar(require("./EndShipperCreateParameters"), exports); -__exportStar(require("./EndShipperListParameters"), exports); -exports.default = (function (easypostClient) { - /** - * The EndShipperService class provides methods for interacting with EasyPost {@link EndShipper} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(EndShipperService, _super); - function EndShipperService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create an {@link EndShipper end shipper}. - * See {@link https://www.easypost.com/docs/api/node#create-an-endshipper EasyPost API Documentation} for more information. - * @param params - Parameters for the end shipper to be created. - * @returns - The created end shipper. - */ - EndShipperService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "end_shippers"; - wrappedParams = { address: params }; - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Update an {@link EndShipper end shipper}. - * See {@link https://www.easypost.com/docs/api/node#update-an-endshipper EasyPost API Documentation} for more information. - * @param id - The ID of the end shipper to update. - * @param params - Parameters for the end shipper to be updated. - * @returns - The updated end shipper. - */ - EndShipperService.update = function (id, params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "end_shippers/".concat(id); - wrappedParams = { address: params }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._put(url, wrappedParams)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve an {@link EndShipper end shipper} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-endshipper EasyPost API Documentation} for more information. - * @param id - The ID of the end shipper to retrieve. - * @returns - The retrieved end shipper. - */ - EndShipperService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "end_shippers/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - /** - * Retrieve all {@link EndShipper end shippers} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-endshippers EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of end shippers. - * @returns - An object containing a list of {@link EndShipper end shippers} and pagination information. - */ - EndShipperService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "end_shippers"; - return [2 /*return*/, this._all(url, params)]; - }); - }); - }; - return EndShipperService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/event_service/Event.js b/out/src/services/event_service/Event.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/event_service/Event.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/event_service/EventListParameters.js b/out/src/services/event_service/EventListParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/event_service/EventListParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/event_service/Payload/Payload.js b/out/src/services/event_service/Payload/Payload.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/event_service/Payload/Payload.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/event_service/Payload/PayloadListParameters.js b/out/src/services/event_service/Payload/PayloadListParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/event_service/Payload/PayloadListParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/event_service/Payload/index.js b/out/src/services/event_service/Payload/index.js deleted file mode 100644 index 95ced6379..000000000 --- a/out/src/services/event_service/Payload/index.js +++ /dev/null @@ -1,17 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./Payload"), exports); diff --git a/out/src/services/event_service/index.js b/out/src/services/event_service/index.js deleted file mode 100644 index 4a74872a4..000000000 --- a/out/src/services/event_service/index.js +++ /dev/null @@ -1,191 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./Event"), exports); -__exportStar(require("./EventListParameters"), exports); -__exportStar(require("./Payload"), exports); -exports.default = (function (easypostClient) { - /** - * The EventService class provides methods for interacting with EasyPost {@link Event} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(EventService, _super); - function EventService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Retrieve all {@link Payload payloads} for an {@link Event event}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads EasyPost API Documentation} for more information. - * @param id - The ID of the event to retrieve payloads for. - * @returns - A list of {@link Payload payloads} for the event. - */ - EventService.retrieveAllPayloads = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, response, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "events/".concat(id, "/payloads"); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._get(url)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body.payloads)]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve a specific {@link Payload payload} for an {@link Event event}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-payload EasyPost API Documentation} for more information. - * @param id - The ID of the event to retrieve the payload for. - * @param payloadId - The ID of the payload to retrieve. - * @returns - The {@link Payload payload} for the event. - */ - EventService.retrievePayload = function (id, payloadId) { - return __awaiter(this, void 0, void 0, function () { - var url, response, e_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "events/".concat(id, "/payloads/").concat(payloadId); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._get(url)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body)]; - case 3: - e_2 = _a.sent(); - return [2 /*return*/, Promise.reject(e_2)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve all {@link Event events} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-events EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of events. - * @returns - An object containing the list of {@link Event events} and pagination information. - */ - EventService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "events"; - return [2 /*return*/, this._all(url, params)]; - }); - }); - }; - /** - * Retrieve the next page of Event collection. - * @param events An object containing a list of {@link Event events} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - EventService.getNextPage = function (events, pageSize) { - if (pageSize === void 0) { pageSize = null; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "events"; - return [2 /*return*/, this._getNextPage(url, "events", events, pageSize)]; - }); - }); - }; - /** - * Retrieve an {@link Event event} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-event EasyPost API Documentation} for more information. - * @param id - The ID of the event to retrieve. - * @returns - The retrieved event. - */ - EventService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "events/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return EventService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/index.js b/out/src/services/index.js deleted file mode 100644 index 4ff245c5a..000000000 --- a/out/src/services/index.js +++ /dev/null @@ -1,43 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./address_service"), exports); -__exportStar(require("./api_key_service"), exports); -__exportStar(require("./batch_service"), exports); -__exportStar(require("./beta_rate_service"), exports); -__exportStar(require("./beta_referral_customer_service"), exports); -__exportStar(require("./billing_service"), exports); -__exportStar(require("./carrier_account_service"), exports); -__exportStar(require("./carrier_metadata_service"), exports); -__exportStar(require("./carrier_type_service"), exports); -__exportStar(require("./customs_info_service"), exports); -__exportStar(require("./customs_item_service"), exports); -__exportStar(require("./end_shipper_service"), exports); -__exportStar(require("./event_service"), exports); -__exportStar(require("./insurance_service"), exports); -__exportStar(require("./order_service"), exports); -__exportStar(require("./parcel_service"), exports); -__exportStar(require("./pickup_service"), exports); -__exportStar(require("./rate_service"), exports); -__exportStar(require("./referral_customer_service"), exports); -__exportStar(require("./refund_service"), exports); -__exportStar(require("./report_service"), exports); -__exportStar(require("./scan_form_service"), exports); -__exportStar(require("./shipment_service"), exports); -__exportStar(require("./tracker_service"), exports); -__exportStar(require("./user_service"), exports); -__exportStar(require("./webhook_service"), exports); -__exportStar(require("./base_service"), exports); diff --git a/out/src/services/insurance_service/Fee.js b/out/src/services/insurance_service/Fee.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/insurance_service/Fee.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/insurance_service/FeeType.js b/out/src/services/insurance_service/FeeType.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/insurance_service/FeeType.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/insurance_service/Insurance.js b/out/src/services/insurance_service/Insurance.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/insurance_service/Insurance.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/insurance_service/InsuranceCreateParameters.js b/out/src/services/insurance_service/InsuranceCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/insurance_service/InsuranceCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/insurance_service/InsuranceStatus.js b/out/src/services/insurance_service/InsuranceStatus.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/insurance_service/InsuranceStatus.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/insurance_service/index.js b/out/src/services/insurance_service/index.js deleted file mode 100644 index 55847d2f1..000000000 --- a/out/src/services/insurance_service/index.js +++ /dev/null @@ -1,154 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./Fee"), exports); -__exportStar(require("./FeeType"), exports); -__exportStar(require("./Insurance"), exports); -__exportStar(require("./InsuranceCreateParameters"), exports); -__exportStar(require("./InsuranceStatus"), exports); -exports.default = (function (easypostClient) { - /** - * The InsuranceService class provides methods for interacting with EasyPost {@link Insurance} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(InsuranceService, _super); - function InsuranceService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create an {@link Insurance insurance} record. - * See {@link https://www.easypost.com/docs/api/node#create-an-insurance EasyPost API Documentation} for more information. - * @param params - Parameters for the insurance to be created. - * @returns - The created insurance. - */ - InsuranceService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "insurances"; - wrappedParams = { - insurance: params, - }; - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Retrieve all {@link Insurance} records associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-insurances EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the insurance records. - * @returns - An object containing the list of {@link Insurance insurance} records and pagination information. - */ - InsuranceService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "insurances"; - return [2 /*return*/, this._all(url, params)]; - }); - }); - }; - /** - * Retrieve the next page of Insurance collection. - * @param {Object} insurances An object containing a list of {@link Insurance insurances} and pagination information. - * @param {Number} pageSize The number of records to return on each page - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - InsuranceService.getNextPage = function (insurances, pageSize) { - if (pageSize === void 0) { pageSize = null; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "insurances"; - return [2 /*return*/, this._getNextPage(url, "insurances", insurances, pageSize)]; - }); - }); - }; - /** - * Retrieve an {@link Insurance insurance} record by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-insurance EasyPost API Documentation} for more information. - * @param {string} id - The ID of the insurance to retrieve. - * @returns {Insurance} - The retrieved insurance. - */ - InsuranceService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "insurances/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return InsuranceService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/order_service/Order.js b/out/src/services/order_service/Order.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/order_service/Order.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/order_service/OrderCreateParameters.js b/out/src/services/order_service/OrderCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/order_service/OrderCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/order_service/index.js b/out/src/services/order_service/index.js deleted file mode 100644 index 78a48713f..000000000 --- a/out/src/services/order_service/index.js +++ /dev/null @@ -1,178 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./Order"), exports); -__exportStar(require("./OrderCreateParameters"), exports); -exports.default = (function (easypostClient) { - /** - * The OrderService class provides methods for interacting with EasyPost {@link Order} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(OrderService, _super); - function OrderService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create an {@link Order order}. - * See {@link https://www.easypost.com/docs/api/node#create-an-order EasyPost API Documentation} for more information. - * @param params - The parameters to create an order with. - * @returns - The created order. - */ - OrderService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "orders"; - wrappedParams = { - order: params, - }; - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Purchase an {@link Order order}. - * See {@link https://www.easypost.com/docs/api/node#buy-an-order EasyPost API Documentation} for more information. - * @param id - The ID of the order to buy. - * @param carrier - The carrier to use for the order purchase. - * @param service - The service to use for the order purchase. - * @returns - The purchased order. - */ - OrderService.buy = function (id, carrier, service) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "orders/".concat(id, "/buy"); - wrappedParams = { carrier: carrier, service: service }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Get updated rates for an {@link Order order}. - * See {@link https://www.easypost.com/docs/api/node#orders EasyPost API Documentation} for more information. - * @param id - The ID of the order to get rates for. - * @returns - The order with rates. - */ - OrderService.getRates = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, response, e_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "orders/".concat(id, "/rates"); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._get(url)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body)]; - case 3: - e_2 = _a.sent(); - return [2 /*return*/, Promise.reject(e_2)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve an {@link Order order} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-order EasyPost API Documentation} for more information. - * @param id - The ID of the order to retrieve. - * @returns - The retrieved order. - */ - OrderService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "orders/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return OrderService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/parcel_service/Parcel.js b/out/src/services/parcel_service/Parcel.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/parcel_service/Parcel.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/parcel_service/ParcelCreateParameters.js b/out/src/services/parcel_service/ParcelCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/parcel_service/ParcelCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/parcel_service/index.js b/out/src/services/parcel_service/index.js deleted file mode 100644 index 0f05745c5..000000000 --- a/out/src/services/parcel_service/index.js +++ /dev/null @@ -1,119 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./Parcel"), exports); -__exportStar(require("./ParcelCreateParameters"), exports); -exports.default = (function (easypostClient) { - /** - * The ParcelService class provides methods for interacting with EasyPost {@link Parcel} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(ParcelService, _super); - function ParcelService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create a {@link Parcel parcel}. - * See {@link https://www.easypost.com/docs/api/node#create-a-parcel EasyPost API Documentation} for more information. - * @param params - The parameters to create a parcel with. - * @returns - The created parcel. - */ - ParcelService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "parcels"; - wrappedParams = { - parcel: params, - }; - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Retrieve a {@link Parcel parcel} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-parcel EasyPost API Documentation} for more information. - * @param id - The ID of the parcel to retrieve. - * @returns - The retrieved parcel. - */ - ParcelService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "parcels/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return ParcelService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/pickup_service/Pickup.js b/out/src/services/pickup_service/Pickup.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/pickup_service/Pickup.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/pickup_service/PickupCreateParameters.js b/out/src/services/pickup_service/PickupCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/pickup_service/PickupCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/pickup_service/PickupListParameters.js b/out/src/services/pickup_service/PickupListParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/pickup_service/PickupListParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/pickup_service/PickupRate.js b/out/src/services/pickup_service/PickupRate.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/pickup_service/PickupRate.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/pickup_service/index.js b/out/src/services/pickup_service/index.js deleted file mode 100644 index f37102cd0..000000000 --- a/out/src/services/pickup_service/index.js +++ /dev/null @@ -1,194 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -exports.default = (function (easypostClient) { - /** - * The PickupService class provides methods for interacting with EasyPost {@link Pickup} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(PickupService, _super); - function PickupService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create a {@link Pickup pickup}. - * See {@link https://www.easypost.com/docs/api/node#create-a-pickup EasyPost API Documentation} for more information. - * @param params - The parameters to create a pickup with. - * @returns - The created pickup. - */ - PickupService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "pickups"; - wrappedParams = { - pickup: params, - }; - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Purchase a {@link Pickup pickup}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-pickup EasyPost API Documentation} for more information. - * @param id - The ID of the pickup to purchase. - * @param carrier - The carrier to purchase the pickup with. - * @param service - The service to purchase the pickup with. - * @returns - The purchased pickup. - */ - PickupService.buy = function (id, carrier, service) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "pickups/".concat(id, "/buy"); - wrappedParams = { carrier: carrier, service: service }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Cancel a {@link Pickup pickup}. - * See {@link https://www.easypost.com/docs/api/node#cancel-a-pickup EasyPost API Documentation} for more information. - * @param id - The ID of the pickup to cancel. - * @returns - The cancelled pickup. - */ - PickupService.cancel = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, response, e_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "pickups/".concat(id, "/cancel"); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body)]; - case 3: - e_2 = _a.sent(); - return [2 /*return*/, Promise.reject(e_2)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve all {@link Pickup pickups} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the pickups by. - * @returns - An object containing a list of {@link Pickup pickups} and pagination information. - */ - PickupService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "pickups"; - return [2 /*return*/, this._all(url, params)]; - }); - }); - }; - /** - * Retrieve the next page of Pickup collection. - * @param pickups An object containing a list of {@link Pickup pickups} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - PickupService.getNextPage = function (pickups, pageSize) { - if (pageSize === void 0) { pageSize = null; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "pickups"; - return [2 /*return*/, this._getNextPage(url, "pickups", pickups, pageSize)]; - }); - }); - }; - /** - * Retrieve a {@link Pickup pickup} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-pickup EasyPost API Documentation} for more information. - * @param id - The ID of the pickup to retrieve. - * @returns - The retrieved pickup. - */ - PickupService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "pickups/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return PickupService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/rate_service/Rate.js b/out/src/services/rate_service/Rate.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/rate_service/Rate.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/rate_service/index.js b/out/src/services/rate_service/index.js deleted file mode 100644 index 5e3ce949d..000000000 --- a/out/src/services/rate_service/index.js +++ /dev/null @@ -1,100 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./Rate"), exports); -exports.default = (function (easypostClient) { - /** - * The RateService class provides methods for interacting with EasyPost {@link Rate} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(RateService, _super); - function RateService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Retrieve a {@link Rate rate} by its ID. - * See {@link https://www.easypost.com/docs/api/node#rates EasyPost API Documentation} for more information. - * @param {string} id - The ID of the rate to retrieve. - * @returns {Rate} - The retrieved rate. - */ - RateService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "rates/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return RateService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/referral_customer_service/Referral.js b/out/src/services/referral_customer_service/Referral.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/referral_customer_service/Referral.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/referral_customer_service/ReferralCreateParameters.js b/out/src/services/referral_customer_service/ReferralCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/referral_customer_service/ReferralCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/referral_customer_service/ReferralListParameters.js b/out/src/services/referral_customer_service/ReferralListParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/referral_customer_service/ReferralListParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/referral_customer_service/index.js b/out/src/services/referral_customer_service/index.js deleted file mode 100644 index 771d93b9e..000000000 --- a/out/src/services/referral_customer_service/index.js +++ /dev/null @@ -1,295 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var node_util_1 = __importDefault(require("node:util")); -var superagent_1 = __importDefault(require("superagent")); -var constants_1 = __importDefault(require("../../constants")); -var easypost_1 = __importDefault(require("../../easypost")); -var external_api_error_1 = __importDefault(require("../../errors/api/external_api_error")); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./Referral"), exports); -__exportStar(require("./ReferralCreateParameters"), exports); -__exportStar(require("./ReferralListParameters"), exports); -/** - * Get an instance of the EasyPostClient using the referral user's API key. - * @private - * @param client - The EasyPostClient to copy. - * @param referralApiKey - The referral user's API key. - * @returns - An instance of the EasyPostClient. - */ -function _getReferralClient(client, referralApiKey) { - return easypost_1.default.copyClient(client, { - apiKey: referralApiKey, - }); -} -/** - * Get EasyPost's Stripe API key used to create credit cards on Stripe's servers. - * @private - * @param easypostClient - The EasyPostClient to use. - * @returns - The Stripe API key. - */ -function _getEasyPostStripeKey(easypostClient) { - return __awaiter(this, void 0, void 0, function () { - var url, response; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "partners/stripe_public_key"; - return [4 /*yield*/, easypostClient._get(url)]; - case 1: - response = _a.sent(); - return [2 /*return*/, response.body.public_key]; - } - }); - }); -} -/** - * Send the credit card details to Stripe to get a Stripe credit card token. - * @private - * @param stripeKey - The Stripe API key. - * @param number - Credit card number. - * @param expirationMonth - Credit card expiration month. - * @param expirationYear - Credit card expiration year. - * @param cvc - Credit card CVC. - * @returns - Stripe credit card token. - */ -function _sendCardDetailsToStripe(stripeKey, number, expirationMonth, expirationYear, cvc) { - return __awaiter(this, void 0, void 0, function () { - var url, request, response, error_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "https://api.stripe.com/v1/tokens?card[number]=".concat(number, "&card[exp_month]=").concat(expirationMonth, "&card[exp_year]=").concat(expirationYear, "&card[cvc]=").concat(cvc); - request = superagent_1.default.post(url).set({ - Authorization: "Bearer ".concat(stripeKey), - "Content-Type": "application/x-www-form-urlencoded", - }); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, request]; - case 2: - response = _a.sent(); - return [2 /*return*/, response.body.id]; - case 3: - error_1 = _a.sent(); - throw new external_api_error_1.default({ - message: node_util_1.default.format(constants_1.default.EXTERNAL_API_CALL_FAILED, "Stripe"), - }); - case 4: return [2 /*return*/]; - } - }); - }); -} -/** - * Send the Stripe credit card token to EasyPost to add the card to the user's account. - * @private - * @param client - The EasyPostClient to use. - * @param referralApiKey - The referral user's production API key. - * @param stripeCreditCardToken - Stripe credit card token. - * @param priority - Whether to add the card as the 'primary' or 'secondary' card. - * @returns - Response body (EasyPost payment method object). - */ -function _sendCardDetailsToEasyPost(client, referralApiKey, stripeCreditCardToken, priority) { - return __awaiter(this, void 0, void 0, function () { - var _client, url, params, response; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - _client = _getReferralClient(client, referralApiKey); - url = "credit_cards"; - params = { - credit_card: { stripe_object_id: stripeCreditCardToken, priority: priority }, - }; - return [4 /*yield*/, _client._post(url, params)]; - case 1: - response = _a.sent(); - return [2 /*return*/, response.body]; - } - }); - }); -} -exports.default = (function (easypostClient) { - /** - * The ReferralCustomerService class provides methods for interacting with EasyPost {@link User referral customer} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(ReferralCustomerService, _super); - function ReferralCustomerService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create a {@link User referral customer}. - * See {@link https://www.easypost.com/docs/api/node#create-a-referral-customer EasyPost API Documentation} for more information. - * @param params - The referral customer's information. - * @returns - The newly created referral customer. - */ - ReferralCustomerService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "referral_customers"; - wrappedParams = { - user: params, - }; - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Update a {@link User referral customer's} email address. - * See {@link https://www.easypost.com/docs/api/node#update-a-referral-customer EasyPost API Documentation} for more information. - * @param referralUserId - The ID of the referral customer to update. - * @param email - The new email address. - * @returns - Returns true if the referral was updated successfully, false otherwise. - */ - ReferralCustomerService.updateEmail = function (referralUserId, email) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "referral_customers/".concat(referralUserId); - wrappedParams = { user: { email: email } }; - return [4 /*yield*/, easypostClient._put(url, wrappedParams)]; - case 1: - _a.sent(); // will throw if there's an error - return [2 /*return*/, true]; - } - }); - }); - }; - /** - * Add a credit card to a {@link User referral customer's} account. - * See {@link https://www.easypost.com/docs/api/node#create-credit-card EasyPost API Documentation} for more information. - * @param referralApiKey - The referral customer's production API key. - * @param number - The credit card number. - * @param expirationMonth - The credit card expiration month. - * @param expirationYear - The credit card expiration year. - * @param cvc - The credit card CVC. - * @param priority - Whether to add the card as 'primary' or 'secondary' payment method (defaults to 'primary'). - * @returns - An object representing the newly-added credit card. - */ - ReferralCustomerService.addCreditCard = function (referralApiKey, number, expirationMonth, expirationYear, cvc, priority) { - if (priority === void 0) { priority = "primary"; } - return __awaiter(this, void 0, void 0, function () { - var stripeKey, stripeCreditCardId, paymentMethod; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, _getEasyPostStripeKey(easypostClient)]; - case 1: - stripeKey = _a.sent(); - return [4 /*yield*/, _sendCardDetailsToStripe(stripeKey, number, expirationMonth, expirationYear, cvc)]; - case 2: - stripeCreditCardId = _a.sent(); - return [4 /*yield*/, _sendCardDetailsToEasyPost(easypostClient, referralApiKey, stripeCreditCardId, priority)]; - case 3: - paymentMethod = _a.sent(); - return [2 /*return*/, paymentMethod]; - } - }); - }); - }; - /** - * Retrieve all {@link User referral customers} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the referral customers by. - * @returns - An object containing a list of {@link User referral customers} and pagination information. - */ - ReferralCustomerService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "referral_customers"; - return [2 /*return*/, this._all(url, params)]; - }); - }); - }; - /** - * Retrieve the next page of Referral Customer collection. - * @param referralCustomers An object containing a list of {@link referral referralCustomers} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - ReferralCustomerService.getNextPage = function (referralCustomers, pageSize) { - if (pageSize === void 0) { pageSize = null; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "referral_customers"; - return [2 /*return*/, this._getNextPage(url, "referral_customers", referralCustomers, pageSize)]; - }); - }); - }; - return ReferralCustomerService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/refund_service/Refund.js b/out/src/services/refund_service/Refund.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/refund_service/Refund.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/refund_service/RefundCreateParameters.js b/out/src/services/refund_service/RefundCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/refund_service/RefundCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/refund_service/RefundListParameters.js b/out/src/services/refund_service/RefundListParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/refund_service/RefundListParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/refund_service/index.js b/out/src/services/refund_service/index.js deleted file mode 100644 index 8e6324a0d..000000000 --- a/out/src/services/refund_service/index.js +++ /dev/null @@ -1,152 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./Refund"), exports); -__exportStar(require("./RefundCreateParameters"), exports); -__exportStar(require("./RefundListParameters"), exports); -exports.default = (function (easypostClient) { - /** - * The RefundService class provides methods for interacting with EasyPost {@link Refund} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(RefundService, _super); - function RefundService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create a {@link Refund refund}. - * See {@link https://www.easypost.com/docs/api/node#create-a-refund EasyPost API Documentation} for more information. - * @param params - The parameters to create a refund with. - * @returns - The created refund. - */ - RefundService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "refunds"; - wrappedParams = { - refund: params, - }; - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Retrieve all {@link Refund refunds} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the refunds by. - * @returns - An object containing the list of {@link Refund refunds} and pagination information. - */ - RefundService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "refunds"; - return [2 /*return*/, this._all(url, params)]; - }); - }); - }; - /** - * Retrieve the next page of Refund collection. - * @param refunds An object containing a list of {@link Refund refunds} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - RefundService.getNextPage = function (refunds, pageSize) { - if (pageSize === void 0) { pageSize = null; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "refunds"; - return [2 /*return*/, this._getNextPage(url, "refunds", refunds, pageSize)]; - }); - }); - }; - /** - * Retrieve a {@link Refund refund} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-refund EasyPost API Documentation} for more information. - * @param id - The ID of the refund to retrieve. - * @returns - The retrieved refund. - */ - RefundService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "refunds/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return RefundService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/report_service/Report.js b/out/src/services/report_service/Report.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/report_service/Report.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/report_service/ReportCreateParameters.js b/out/src/services/report_service/ReportCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/report_service/ReportCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/report_service/ReportListParameters.js b/out/src/services/report_service/ReportListParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/report_service/ReportListParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/report_service/ReportObjectType.js b/out/src/services/report_service/ReportObjectType.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/report_service/ReportObjectType.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/report_service/index.js b/out/src/services/report_service/index.js deleted file mode 100644 index a56b614d4..000000000 --- a/out/src/services/report_service/index.js +++ /dev/null @@ -1,177 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./Report"), exports); -__exportStar(require("./ReportCreateParameters"), exports); -__exportStar(require("./ReportListParameters"), exports); -__exportStar(require("./ReportObjectType"), exports); -exports.default = (function (easypostClient) { - /** - * The ReportService class provides methods for interacting with EasyPost {@link Report} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(ReportService, _super); - function ReportService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create a {@link Report report}. - * See {@link https://www.easypost.com/docs/api/node#create-a-report EasyPost API Documentation} for more information. - * @param params - The parameters to create a report with. - * @returns - The created report. - */ - ReportService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "reports/".concat(params.type); - return [2 /*return*/, this._create(url, params)]; - }); - }); - }; - /** - * Retrieve all {@link Report reports} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-reports EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the reports by. - * @returns - An object containing the list of {@link Report reports} and pagination information. - */ - ReportService.all = function (params) { - return __awaiter(this, void 0, void 0, function () { - var type, url, apiParams, response, responseObject, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - type = params.type; - url = "reports/".concat(type); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - apiParams = __assign({}, params); - delete apiParams.type; - return [4 /*yield*/, easypostClient._get(url, apiParams)]; - case 2: - response = _a.sent(); - responseObject = this._convertToEasyPostObject(response.body, params); - return [2 /*return*/, responseObject]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve the next page of Report collection. - * @param reports An object containing a list of {@link Report reports} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - ReportService.getNextPage = function (reports, pageSize) { - if (pageSize === void 0) { pageSize = null; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "reports/".concat(reports.reports[0]._params.type); - return [2 /*return*/, this._getNextPage(url, "reports", reports, pageSize)]; - }); - }); - }; - /** - * Retrieve a {@link Report report} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-report EasyPost API Documentation} for more information. - * @param id - The ID of the report to retrieve. - * @returns - The retrieved report. - */ - ReportService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "reports/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return ReportService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/scan_form_service/ScanForm.js b/out/src/services/scan_form_service/ScanForm.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/scan_form_service/ScanForm.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/scan_form_service/ScanFormCreateParameters.js b/out/src/services/scan_form_service/ScanFormCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/scan_form_service/ScanFormCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/scan_form_service/ScanFormListParameters.js b/out/src/services/scan_form_service/ScanFormListParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/scan_form_service/ScanFormListParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/scan_form_service/index.js b/out/src/services/scan_form_service/index.js deleted file mode 100644 index 83e8e3572..000000000 --- a/out/src/services/scan_form_service/index.js +++ /dev/null @@ -1,163 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./ScanForm"), exports); -__exportStar(require("./ScanFormCreateParameters"), exports); -__exportStar(require("./ScanFormListParameters"), exports); -exports.default = (function (easypostClient) { - /** - * The ScanFormService class provides methods for interacting with EasyPost {@link ScanForm} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(ScanFormService, _super); - function ScanFormService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create a {@link ScanForm scan form}. - * See {@link https://www.easypost.com/docs/api/node#create-a-scanform EasyPost API Documentation} for more information. - * @param params - The parameters to create a scan form with. - * @returns - The created scan form. - */ - ScanFormService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "scan_forms"; - // wraps up params in `shipments` if the user didn't do it - // turn a list of shipment objects into a map of shipment ids - if (params.shipments) { - // eslint-disable-next-line no-param-reassign - params.shipments = params.shipments.map(function (s) { - if (typeof s === "string") { - return { id: s }; - } - return { id: s.id }; - }); - } - wrappedParams = { - scan_form: params, - }; - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Retrieve all {@link ScanForm scan forms} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-scanforms EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the scan forms by. - * @returns - An object containing the list of {@link ScanForm scan forms} and pagination information. - */ - ScanFormService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "scan_forms"; - return [2 /*return*/, this._all(url, params)]; - }); - }); - }; - /** - * Retrieve the next page of ScanForm collection. - * @param scanForms An object containing a list of {@link ScanForm scanForms} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - ScanFormService.getNextPage = function (scanForms, pageSize) { - if (pageSize === void 0) { pageSize = null; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "scan_forms"; - return [2 /*return*/, this._getNextPage(url, "scan_forms", scanForms, pageSize)]; - }); - }); - }; - /** - * Retrieve a {@link ScanForm scan form} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-scanform EasyPost API Documentation} for more information. - * @param id - The ID of the scan form to retrieve. - * @returns - The retrieved scan form. - */ - ScanFormService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "scan_forms/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return ScanFormService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/shipment_service/Form.js b/out/src/services/shipment_service/Form.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/shipment_service/Form.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/Message.js b/out/src/services/shipment_service/Message.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/shipment_service/Message.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/Options/LabelFormat.js b/out/src/services/shipment_service/Options/LabelFormat.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/shipment_service/Options/LabelFormat.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/Options/Options.js b/out/src/services/shipment_service/Options/Options.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/shipment_service/Options/Options.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/Options/PrintCustomCode.js b/out/src/services/shipment_service/Options/PrintCustomCode.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/shipment_service/Options/PrintCustomCode.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/Options/index.js b/out/src/services/shipment_service/Options/index.js deleted file mode 100644 index 969981b8e..000000000 --- a/out/src/services/shipment_service/Options/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./LabelFormat"), exports); -__exportStar(require("./Options"), exports); -__exportStar(require("./PrintCustomCode"), exports); diff --git a/out/src/services/shipment_service/PostageLabel.js b/out/src/services/shipment_service/PostageLabel.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/shipment_service/PostageLabel.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/Shipment.js b/out/src/services/shipment_service/Shipment.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/shipment_service/Shipment.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/ShipmentCreateParameters.js b/out/src/services/shipment_service/ShipmentCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/shipment_service/ShipmentCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/ShipmentListParameters.js b/out/src/services/shipment_service/ShipmentListParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/shipment_service/ShipmentListParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/shipment_service/index.js b/out/src/services/shipment_service/index.js deleted file mode 100644 index 042a0dd22..000000000 --- a/out/src/services/shipment_service/index.js +++ /dev/null @@ -1,479 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var constants_1 = __importDefault(require("../../constants")); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./Form"), exports); -__exportStar(require("./Message"), exports); -__exportStar(require("./PostageLabel"), exports); -__exportStar(require("./Shipment"), exports); -__exportStar(require("./ShipmentCreateParameters"), exports); -__exportStar(require("./ShipmentListParameters"), exports); -__exportStar(require("./Options"), exports); -var addLowestRateToShipment = function (shipment) { - return __assign(__assign({}, shipment), { lowestRate: function (carriers, services) { - return constants_1.default.Utils.getLowestRate(shipment.rates, carriers, services); - } }); -}; -exports.default = (function (easypostClient) { - /** - * The ShipmentService class provides methods for interacting with EasyPost {@link Shipment} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(ShipmentService, _super); - function ShipmentService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#create-a-shipment EasyPost API Documentation} for more information. - * @param params - The parameters to create a shipment with. - * @returns - The created shipment. - */ - ShipmentService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, shipment; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "shipments"; - wrappedParams = { - shipment: params, - }; - return [4 /*yield*/, this._create(url, wrappedParams)]; - case 1: - shipment = _a.sent(); - return [2 /*return*/, addLowestRateToShipment(shipment)]; - } - }); - }); - }; - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */ - ShipmentService.buy = function (id, rate, insuranceAmount, endShipperId) { - if (insuranceAmount === void 0) { insuranceAmount = null; } - if (endShipperId === void 0) { endShipperId = null; } - return __awaiter(this, void 0, void 0, function () { - var rateId, url, wrappedParams, response, shipment, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - rateId = typeof rate === "object" ? rate.id : rate; - url = "shipments/".concat(id, "/buy"); - wrappedParams = { - rate: { - id: rateId, - }, - }; - if (insuranceAmount) { - wrappedParams.insurance = insuranceAmount; - } - if (endShipperId) { - wrappedParams.end_shipper_id = endShipperId; - } - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; - case 2: - response = _a.sent(); - shipment = this._convertToEasyPostObject(response.body, wrappedParams); - return [2 /*return*/, addLowestRateToShipment(shipment)]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Convert the label format of a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#convert-the-label-format-of-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to convert the label format of. - * @param format - The format to convert the label to. - * @returns - The shipment with the converted label format. - */ - ShipmentService.convertLabelFormat = function (id, format) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, shipment, e_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "shipments/".concat(id, "/label"); - wrappedParams = { file_format: format }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._get(url, wrappedParams)]; - case 2: - response = _a.sent(); - shipment = this._convertToEasyPostObject(response.body, wrappedParams); - return [2 /*return*/, addLowestRateToShipment(shipment)]; - case 3: - e_2 = _a.sent(); - return [2 /*return*/, Promise.reject(e_2)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Regenerate {@link Rate rates} for a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#regenerate-rates-for-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to regenerate rates for. - * @returns - The shipment with regenerated rates. - */ - ShipmentService.regenerateRates = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, shipment, e_3; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "shipments/".concat(id, "/rerate"); - wrappedParams = {}; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; - case 2: - response = _a.sent(); - shipment = this._convertToEasyPostObject(response.body, wrappedParams); - return [2 /*return*/, addLowestRateToShipment(shipment)]; - case 3: - e_3 = _a.sent(); - return [2 /*return*/, Promise.reject(e_3)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Get SmartRates for a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-time-in-transit-statistics-across-all-rates-for-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to get SmartRates for. - * @returns - The SmartRates for the shipment. - */ - ShipmentService.getSmartRates = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, response, e_4; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "shipments/".concat(id, "/smartrate"); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._get(url)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body.result)]; - case 3: - e_4 = _a.sent(); - return [2 /*return*/, Promise.reject(e_4)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Insure a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#insure-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to insure. - * @param amount - The amount to insure the shipment for. - * @returns - The insured shipment. - */ - ShipmentService.insure = function (id, amount) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, shipment, e_5; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "shipments/".concat(id, "/insure"); - wrappedParams = { amount: amount }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; - case 2: - response = _a.sent(); - shipment = this._convertToEasyPostObject(response.body, wrappedParams); - return [2 /*return*/, addLowestRateToShipment(shipment)]; - case 3: - e_5 = _a.sent(); - return [2 /*return*/, Promise.reject(e_5)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Generate a form for a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#create-form EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to generate a form for. - * @param formType - The type of form to generate. - * @param [formOptions] - Options for the form. - * @returns - The shipment with the generated form attached. - */ - ShipmentService.generateForm = function (id, formType, formOptions) { - if (formOptions === void 0) { formOptions = {}; } - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, shipment, e_6; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "shipments/".concat(id, "/forms"); - wrappedParams = { - form: __assign(__assign({}, formOptions), { type: formType }), - }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url, wrappedParams)]; - case 2: - response = _a.sent(); - shipment = this._convertToEasyPostObject(response.body, wrappedParams); - return [2 /*return*/, addLowestRateToShipment(shipment)]; - case 3: - e_6 = _a.sent(); - return [2 /*return*/, Promise.reject(e_6)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Refund a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#refund-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to refund. - * @returns - The refunded shipment. - */ - ShipmentService.refund = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, response, shipment, e_7; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "shipments/".concat(id, "/refund"); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._post(url)]; - case 2: - response = _a.sent(); - shipment = this._convertToEasyPostObject(response.body); - return [2 /*return*/, addLowestRateToShipment(shipment)]; - case 3: - e_7 = _a.sent(); - return [2 /*return*/, Promise.reject(e_7)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Get the lowest SmartRate of a shipment. - * @param id - The ID of the shipment to get the lowest SmartRate of. - * @param deliveryDays - The number of days the shipment will take to deliver. - * @param deliveryAccuracy - The accuracy of the delivery days. - * @returns - The lowest SmartRate of the shipment. - */ - ShipmentService.lowestSmartRate = function (id, deliveryDays, deliveryAccuracy) { - return __awaiter(this, void 0, void 0, function () { - var smartRates; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.getSmartRates(id)]; - case 1: - smartRates = _a.sent(); - return [2 /*return*/, constants_1.default.Utils.getLowestSmartRate(smartRates, deliveryDays, deliveryAccuracy.toLowerCase())]; - } - }); - }); - }; - /** - * Retrieve all {@link Shipment shipments} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the shipments by. - * @returns - An object containing a list of {@link Shipment shipments} and pagination information. - */ - ShipmentService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url, result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "shipments"; - return [4 /*yield*/, this._all(url, params)]; - case 1: - result = _a.sent(); - return [2 /*return*/, __assign(__assign({}, result), { shipments: result.shipments.map(addLowestRateToShipment) })]; - } - }); - }); - }; - /** - * Retrieve the next page of Shipment collection. - * @param shipments An object containing a list of {@link Shipment shipments} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - ShipmentService.getNextPage = function (shipments, pageSize) { - if (pageSize === void 0) { pageSize = null; } - return __awaiter(this, void 0, void 0, function () { - var url, result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "shipments"; - return [4 /*yield*/, this._getNextPage(url, "shipments", shipments, pageSize)]; - case 1: - result = _a.sent(); - return [2 /*return*/, __assign(__assign({}, result), { shipments: result.shipments.map(addLowestRateToShipment) })]; - } - }); - }); - }; - /** - * Retrieve a {@link Shipment shipment} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to retrieve. - * @returns - The shipment with the given ID. - */ - ShipmentService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, shipment; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "shipments/".concat(id); - return [4 /*yield*/, this._retrieve(url)]; - case 1: - shipment = _a.sent(); - return [2 /*return*/, addLowestRateToShipment(shipment)]; - } - }); - }); - }; - /** - * Retrieves the estimated delivery date of each Rate via SmartRate. - * @param id - * @param plannedShipDate - * @returns - An array of the estimated delivery date and rates. - */ - ShipmentService.retrieveEstimatedDeliveryDate = function (id, plannedShipDate) { - var _a; - return __awaiter(this, void 0, void 0, function () { - var url, params, response, e_8; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - url = "shipments/".concat(id, "/smartrate/delivery_date"); - params = { - planned_ship_date: plannedShipDate, - }; - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._get(url, params)]; - case 2: - response = _b.sent(); - return [2 /*return*/, this._convertToEasyPostObject((_a = response.body.rates) !== null && _a !== void 0 ? _a : [], params)]; - case 3: - e_8 = _b.sent(); - return [2 /*return*/, Promise.reject(e_8)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - return ShipmentService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/tracker_service/CarrierDetail.js b/out/src/services/tracker_service/CarrierDetail.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/tracker_service/CarrierDetail.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/Tracker.js b/out/src/services/tracker_service/Tracker.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/tracker_service/Tracker.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/TrackerCreateParameters.js b/out/src/services/tracker_service/TrackerCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/tracker_service/TrackerCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/TrackerListParameters.js b/out/src/services/tracker_service/TrackerListParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/tracker_service/TrackerListParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/TrackerStatus.js b/out/src/services/tracker_service/TrackerStatus.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/tracker_service/TrackerStatus.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/TrackerStatusDetail.js b/out/src/services/tracker_service/TrackerStatusDetail.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/tracker_service/TrackerStatusDetail.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/TrackingDetail.js b/out/src/services/tracker_service/TrackingDetail.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/tracker_service/TrackingDetail.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/TrackingLocation.js b/out/src/services/tracker_service/TrackingLocation.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/tracker_service/TrackingLocation.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/tracker_service/index.js b/out/src/services/tracker_service/index.js deleted file mode 100644 index 3202ed517..000000000 --- a/out/src/services/tracker_service/index.js +++ /dev/null @@ -1,179 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./CarrierDetail"), exports); -__exportStar(require("./Tracker"), exports); -__exportStar(require("./TrackerCreateParameters"), exports); -__exportStar(require("./TrackerListParameters"), exports); -__exportStar(require("./TrackerStatus"), exports); -__exportStar(require("./TrackerStatusDetail"), exports); -__exportStar(require("./TrackingDetail"), exports); -__exportStar(require("./TrackingLocation"), exports); -exports.default = (function (easypostClient) { - /** - * The TrackerService class provides methods for interacting with EasyPost {@link Tracker} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(TrackerService, _super); - function TrackerService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create a {@link Tracker tracker}. - * See {@link https://www.easypost.com/docs/api/node#create-a-tracker EasyPost API Documentation} for more information. - * @param params - The parameters to create a tracker with. - * @returns - The created tracker. - */ - TrackerService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "trackers"; - wrappedParams = { - tracker: params, - }; - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Create multiple {@link Tracker trackers} in a single request. - * See {@link https://www.easypost.com/docs/api/node#trackers EasyPost API Documentation} for more information. - * @param [params] - The parameters to create trackers with. - */ - TrackerService.createList = function (params) { - if (params === void 0) { params = []; } - return __awaiter(this, void 0, void 0, function () { - var newParams, url; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - newParams = { trackers: params }; - url = "trackers/create_list"; - return [4 /*yield*/, easypostClient._post(url, newParams)]; - case 1: - _a.sent(); - return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve all {@link Tracker trackers} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-trackers EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the trackers by. - * @returns - An object containing the list of {@link Tracker trackers} and pagination information. - */ - TrackerService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "trackers"; - return [2 /*return*/, this._all(url, params)]; - }); - }); - }; - /** - * Retrieve the next page of Tracker collection. - * @param trackers An object containing a list of {@link Tracker trackers} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - TrackerService.getNextPage = function (trackers, pageSize) { - if (pageSize === void 0) { pageSize = null; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "trackers"; - return [2 /*return*/, this._getNextPage(url, "trackers", trackers, pageSize)]; - }); - }); - }; - /** - * Retrieve a {@link Tracker tracker} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-tracker EasyPost API Documentation} for more information. - * @param id - The ID of the tracker to retrieve. - * @returns - The retrieved tracker. - */ - TrackerService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "trackers/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return TrackerService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/user_service/Brand.js b/out/src/services/user_service/Brand.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/user_service/Brand.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/user_service/User.js b/out/src/services/user_service/User.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/user_service/User.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/user_service/UserCreateParameters.js b/out/src/services/user_service/UserCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/user_service/UserCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/user_service/index.js b/out/src/services/user_service/index.js deleted file mode 100644 index 285f7445d..000000000 --- a/out/src/services/user_service/index.js +++ /dev/null @@ -1,294 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./Brand"), exports); -__exportStar(require("./User"), exports); -__exportStar(require("./UserCreateParameters"), exports); -exports.default = (function (easypostClient) { - /** - * The UserService class provides methods for interacting with EasyPost {@link User} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(UserService, _super); - function UserService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create a {@link User child user}. - * See {@link https://www.easypost.com/docs/api/node#create-a-child-user EasyPost API Documentation} for more information. - * @param params - The parameters to create a child user with. - * @returns - The created child user. - */ - UserService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "users"; - wrappedParams = { - user: params, - }; - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Update a {@link User user}. - * See {@link https://www.easypost.com/docs/api/node#update-a-user EasyPost API Documentation} for more information. - * @param id - The ID of the user to update (either the current authenticated user or a child user). - * @param params - The parameters to update the user with. - * @returns - The updated user. - */ - UserService.update = function (id, params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "users/".concat(id); - wrappedParams = { - user: params, - }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._patch(url, wrappedParams)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve a {@link User child user}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-user EasyPost API Documentation} for more information. - * @param id - The ID of the child user to retrieve. - * @returns - The retrieved child user. - */ - UserService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, response, e_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "users/".concat(id); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._get(url)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body)]; - case 3: - e_2 = _a.sent(); - return [2 /*return*/, Promise.reject(e_2)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve the {@link User current authenticated user}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-user EasyPost API Documentation} for more information. - * @returns - The retrieved user. - */ - UserService.retrieveMe = function () { - return __awaiter(this, void 0, void 0, function () { - var url, response, e_3; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "users"; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._get(url)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body)]; - case 3: - e_3 = _a.sent(); - return [2 /*return*/, Promise.reject(e_3)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Delete a {@link User child user}. - * See {@link https://www.easypost.com/docs/api/node#delete-a-child-user EasyPost API Documentation} for more information. - * @param id - The ID of the child user to delete. - * @returns - A promise that resolves when the child user is deleted successfully. - */ - UserService.delete = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, e_4; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "users/".concat(id); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._delete(url)]; - case 2: - _a.sent(); - return [2 /*return*/, Promise.resolve()]; - case 3: - e_4 = _a.sent(); - return [2 /*return*/, Promise.reject(e_4)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Update the brand of a {@link User user}. - * See {@link https://www.easypost.com/docs/api/node#update-a-brand EasyPost API Documentation} for more information. - * @param id - The ID of the user to update the brand of. - * @param params - The parameters to update the brand with. - * @returns - The updated brand. - */ - UserService.updateBrand = function (id, params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams, response, e_5; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "users/".concat(id, "/brand"); - wrappedParams = { brand: params }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._patch(url, wrappedParams)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body, wrappedParams)]; - case 3: - e_5 = _a.sent(); - return [2 /*return*/, Promise.reject(e_5)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve a paginated list of children user {@link User user}. - * See {@link https://www.easypost.com/docs/api/node#child-users EasyPost API Documentation} for more information. - * @param params - Parameters to filter the list of children users. - * @returns - An object containing a list of {@link Children User} and pagination information. - */ - UserService.allChildren = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, response, e_6; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "users/children"; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._get(url, params)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body, params)]; - case 3: - e_6 = _a.sent(); - return [2 /*return*/, Promise.reject(e_6)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve the next page of children collection. - * @param children An object containing a list of {@link Children children} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - UserService.getNextPage = function (children, pageSize) { - if (pageSize === void 0) { pageSize = null; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "users/children"; - return [2 /*return*/, this._getNextPage(url, "children", children, pageSize)]; - }); - }); - }; - return UserService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/services/webhook_service/Webhook.js b/out/src/services/webhook_service/Webhook.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/webhook_service/Webhook.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/webhook_service/WebhookCreateParameters.js b/out/src/services/webhook_service/WebhookCreateParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/webhook_service/WebhookCreateParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/webhook_service/WebhookListParameters.js b/out/src/services/webhook_service/WebhookListParameters.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/services/webhook_service/WebhookListParameters.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/services/webhook_service/index.js b/out/src/services/webhook_service/index.js deleted file mode 100644 index 6896bafa7..000000000 --- a/out/src/services/webhook_service/index.js +++ /dev/null @@ -1,194 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var base_service_1 = __importDefault(require("../base_service")); -__exportStar(require("./Webhook"), exports); -__exportStar(require("./WebhookCreateParameters"), exports); -__exportStar(require("./WebhookListParameters"), exports); -exports.default = (function (easypostClient) { - /** - * The WebhookService class provides methods for interacting with EasyPost {@link Webhook} objects. - * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. - */ - return /** @class */ (function (_super) { - __extends(WebhookService, _super); - function WebhookService() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - * Create a {@link Webhook webhook}. - * See {@link https://www.easypost.com/docs/api/node#create-a-webhook EasyPost API Documentation} for more information. - * @param params - The parameters to create a webhook with. - * @returns - The created webhook. - */ - WebhookService.create = function (params) { - return __awaiter(this, void 0, void 0, function () { - var url, wrappedParams; - return __generator(this, function (_a) { - url = "webhooks"; - wrappedParams = { - webhook: params, - }; - return [2 /*return*/, this._create(url, wrappedParams)]; - }); - }); - }; - /** - * Update a {@link Webhook webhook}. - * A disabled webhook will be re-enabled if it is updated. - * See {@link https://www.easypost.com/docs/api/node#update-a-webhook EasyPost API Documentation} for more information. - * @param id - The ID of the webhook to update. - * @param params - The parameters to update the webhook with. - * @returns - The updated webhook. - */ - WebhookService.update = function (id, params) { - return __awaiter(this, void 0, void 0, function () { - var url, response, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "webhooks/".concat(id); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._patch(url, params)]; - case 2: - response = _a.sent(); - return [2 /*return*/, this._convertToEasyPostObject(response.body, params)]; - case 3: - e_1 = _a.sent(); - return [2 /*return*/, Promise.reject(e_1)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Delete a {@link Webhook webhook}. - * See {@link https://www.easypost.com/docs/api/node#delete-a-webhook EasyPost API Documentation} for more information. - * @param id - The ID of the webhook to delete. - * @returns - A promise that resolves if the webhook was successfully deleted. - */ - WebhookService.delete = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url, e_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - url = "webhooks/".concat(id); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, easypostClient._delete(url)]; - case 2: - _a.sent(); - return [2 /*return*/, Promise.resolve()]; - case 3: - e_2 = _a.sent(); - return [2 /*return*/, Promise.reject(e_2)]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Retrieve all {@link Webhook webhooks} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#list-a-webhooks EasyPost API Documentation} for more information. - * @param [params] - * @returns - */ - WebhookService.all = function (params) { - if (params === void 0) { params = {}; } - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "webhooks"; - return [2 /*return*/, this._all(url, params)]; - }); - }); - }; - /** - * Retrieve a {@link Webhook webhook} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-webhook EasyPost API Documentation} for more information. - * @param id - The ID of the webhook to retrieve. - * @returns - The retrieved webhook. - */ - WebhookService.retrieve = function (id) { - return __awaiter(this, void 0, void 0, function () { - var url; - return __generator(this, function (_a) { - url = "webhooks/".concat(id); - return [2 /*return*/, this._retrieve(url)]; - }); - }); - }; - return WebhookService; - }((0, base_service_1.default)(easypostClient))); -}); diff --git a/out/src/utils/errors/Error.js b/out/src/utils/errors/Error.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/utils/errors/Error.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/utils/errors/ErrorCode.js b/out/src/utils/errors/ErrorCode.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/utils/errors/ErrorCode.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/utils/errors/FieldError.js b/out/src/utils/errors/FieldError.js deleted file mode 100644 index c8ad2e549..000000000 --- a/out/src/utils/errors/FieldError.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/out/src/utils/errors/index.js b/out/src/utils/errors/index.js deleted file mode 100644 index a90757778..000000000 --- a/out/src/utils/errors/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./Error"), exports); -__exportStar(require("./ErrorCode"), exports); -__exportStar(require("./FieldError"), exports); diff --git a/out/src/utils/types.js b/out/src/utils/types.js deleted file mode 100644 index 2367d855d..000000000 --- a/out/src/utils/types.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = {}; diff --git a/out/src/utils/util.js b/out/src/utils/util.js deleted file mode 100644 index 05806eac1..000000000 --- a/out/src/utils/util.js +++ /dev/null @@ -1,199 +0,0 @@ -"use strict"; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; -var __values = (this && this.__values) || function(o) { - var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; - if (m) return m.call(o); - if (o && typeof o.length === "number") return { - next: function () { - if (o && i >= o.length) o = void 0; - return { value: o && o[i++], done: !o }; - } - }; - throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var node_crypto_1 = __importDefault(require("node:crypto")); -var node_util_1 = __importDefault(require("node:util")); -var constants_1 = __importDefault(require("../constants")); -var filtering_error_1 = __importDefault(require("../errors/general/filtering_error")); -var invalid_parameter_error_1 = __importDefault(require("../errors/general/invalid_parameter_error")); -var signature_verification_error_1 = __importDefault(require("../errors/general/signature_verification_error")); -/** - * Utility class of various publicly-available helper functions. - * @public - * @type {Utils} - */ -var Utils = /** @class */ (function () { - function Utils() { - } - /** - * Get the lowest SmartRate from a provided list of SmartRates. - * @public - * @param smartRates - List of SmartRates to filter through - * @param deliveryDays - The maximum number of days allowed for delivery - * @param deliveryAccuracy - The target level of accuracy for the delivery days (e.g. 'percentile_50') - * @returns - The lowest SmartRate - * @throws {FilteringError} - If no applicable rates are found - * @throws {InvalidParameterError} - If the deliveryAccuracy value is invalid - */ - Utils.prototype.getLowestSmartRate = function (smartRates, deliveryDays, deliveryAccuracy) { - var e_1, _a; - var validDeliveryAccuracyValues = new Set([ - "percentile_50", - "percentile_75", - "percentile_85", - "percentile_90", - "percentile_95", - "percentile_97", - "percentile_99", - ]); - var lowestSmartRate = null; - var lowercaseDeliveryAccuracy = deliveryAccuracy.toLowerCase(); - if (!validDeliveryAccuracyValues.has(lowercaseDeliveryAccuracy)) { - throw new invalid_parameter_error_1.default({ - message: "Invalid deliveryAccuracy value, must be one of: ".concat(__spreadArray([], __read(validDeliveryAccuracyValues), false).join(", ")), - }); - } - try { - for (var smartRates_1 = __values(smartRates), smartRates_1_1 = smartRates_1.next(); !smartRates_1_1.done; smartRates_1_1 = smartRates_1.next()) { - var rate = smartRates_1_1.value; - if (rate.time_in_transit[lowercaseDeliveryAccuracy] > Number(deliveryDays)) { - // eslint-disable-next-line no-continue - continue; - } - else if (lowestSmartRate === null || - parseFloat(rate.rate) < parseFloat(lowestSmartRate.rate)) { - lowestSmartRate = rate; - } - } - } - catch (e_1_1) { e_1 = { error: e_1_1 }; } - finally { - try { - if (smartRates_1_1 && !smartRates_1_1.done && (_a = smartRates_1.return)) _a.call(smartRates_1); - } - finally { if (e_1) throw e_1.error; } - } - if (lowestSmartRate === null) { - throw new filtering_error_1.default({ - message: node_util_1.default.format(constants_1.default.NO_OBJECT_FOUND, "rates"), - }); - } - return lowestSmartRate; - }; - /** - * Get the lowest rate from a provided list of rates. - * @public - * @param rates - List of rates to filter through - * @param [carriers] - List of allowed carriers to filter by - * @param [services] - List of allowed services to filter by - * @returns - The lowest rate - * @throws {FilteringError} - If no applicable rates are found - */ - Utils.prototype.getLowestRate = function (rates, carriers, services) { - if (carriers === void 0) { carriers = null; } - if (services === void 0) { services = null; } - if (carriers) { - var carriersLower_1 = carriers.map(function (carrier) { return carrier.toLowerCase(); }); - // eslint-disable-next-line no-param-reassign - rates = rates.filter(function (rate) { - return carriersLower_1.includes(rate.carrier.toLowerCase()); - }); - } - if (services) { - var servicesLower_1 = services.map(function (service) { return service.toLowerCase(); }); - // eslint-disable-next-line no-param-reassign - rates = rates.filter(function (rate) { - return servicesLower_1.includes(rate.service.toLowerCase()); - }); - } - if (rates.length === 0) { - throw new filtering_error_1.default({ - message: node_util_1.default.format(constants_1.default.NO_OBJECT_FOUND, "rates"), - }); - } - return rates.reduce(function (lowest, rate) { - if (parseFloat(rate.rate) < parseFloat(lowest.rate)) { - return rate; - } - return lowest; - }, rates[0]); - }; - /** - * Validate a webhook by comparing the HMAC signature header sent from EasyPost to your shared secret. - * If the signatures do not match, an error will be raised signifying the webhook either did not originate - * from EasyPost or the secrets do not match. If the signatures do match, the `event_body` will be returned - * as JSON. - * @public - * @param eventBody - The raw body of the webhook event - * @param headers - The headers of the webhook HTTP request - * @param webhookSecret - The webhook secret shared between EasyPost and your application - * @returns - The JSON-parsed webhook event body if the signature could be verified - * @throws {SignatureVerificationError} - If the signature could not be verified - */ - Utils.prototype.validateWebhook = function (eventBody, headers, webhookSecret) { - var _a, _b; - var webhook = {}; - var easypostHmacSignature = (_b = (_a = headers["X-Hmac-Signature"]) !== null && _a !== void 0 ? _a : headers["x-hmac-signature"]) !== null && _b !== void 0 ? _b : null; - if (easypostHmacSignature != null) { - var normalizedSecret = webhookSecret.normalize("NFKD"); - var encodedSecret = Buffer.from(normalizedSecret, "utf8"); - var expectedSignature = node_crypto_1.default - .createHmac("sha256", encodedSecret) - // @ts-ignore buffers are weird - .update(eventBody, "utf-8") - .digest("hex"); - var digest = "hmac-sha256-hex=".concat(expectedSignature); - try { - if (node_crypto_1.default.timingSafeEqual(Buffer.from(easypostHmacSignature, "utf8"), Buffer.from(digest, "utf8"))) { - webhook = JSON.parse(eventBody.toString()); - } - else { - throw new signature_verification_error_1.default({ - message: constants_1.default.WEBHOOK_DOES_NOT_MATCH, - }); - } - } - catch (e) { - throw new signature_verification_error_1.default({ - message: constants_1.default.WEBHOOK_DOES_NOT_MATCH, - }); - } - } - else { - throw new signature_verification_error_1.default({ - message: constants_1.default.INVALID_WEBHOOK_SIGNATURE, - }); - } - return webhook; - }; - return Utils; -}()); -exports.default = Utils; diff --git a/src/constants.ts b/src/constants.ts index a8c0199a3..b522179be 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,28 +1,25 @@ -import Utils from "./utils/util"; +import Utils from './utils/util'; /** * A class containing constants used throughout the EasyPost Node.js client library. */ export default class Constants { static get CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS() { - return ["FedexAccount", "FedexSmartpostAccount", "UpsAccount"]; + return ['FedexAccount', 'FedexSmartpostAccount', 'UpsAccount']; } - static EXTERNAL_API_CALL_FAILED = - "Communication with %s failed, please try again later"; - static INVALID_API_KEY_TYPE = "Invalid API key type."; - static INVALID_PARAMETER = "Invalid parameter: %s."; - static INVALID_PAYMENT = - "The chosen payment method is not a credit card. Please try again."; - static INVALID_WEBHOOK_SIGNATURE = - "Webhook does not contain a valid HMAC signature."; - static MISSING_REQUIRED_PARAMETER = "Missing required parameter: %s."; - static NO_OBJECT_FOUND = "No %s found."; + static EXTERNAL_API_CALL_FAILED = 'Communication with %s failed, please try again later'; + static INVALID_API_KEY_TYPE = 'Invalid API key type.'; + static INVALID_PARAMETER = 'Invalid parameter: %s.'; + static INVALID_PAYMENT = 'The chosen payment method is not a credit card. Please try again.'; + static INVALID_WEBHOOK_SIGNATURE = 'Webhook does not contain a valid HMAC signature.'; + static MISSING_REQUIRED_PARAMETER = 'Missing required parameter: %s.'; + static NO_OBJECT_FOUND = 'No %s found.'; static NO_PAYMENT_METHODS = - "No payment methods are set up. Please add a payment method and try again."; - static API_DID_NOT_RETURN_ERROR_DETAILS = "API did not return error details."; + 'No payment methods are set up. Please add a payment method and try again.'; + static API_DID_NOT_RETURN_ERROR_DETAILS = 'API did not return error details.'; static WEBHOOK_DOES_NOT_MATCH = - "Webhook received did not originate from EasyPost or had a webhook secret mismatch."; - static END_OF_PAGINATION = "There are no more pages to retrieve."; - static ERROR_DESERIALIZATION = "Error deserializing JSON response"; + 'Webhook received did not originate from EasyPost or had a webhook secret mismatch.'; + static END_OF_PAGINATION = 'There are no more pages to retrieve.'; + static ERROR_DESERIALIZATION = 'Error deserializing JSON response'; static Utils = new Utils(); } diff --git a/src/easypost.ts b/src/easypost.ts index a340dac00..b1850f8e8 100644 --- a/src/easypost.ts +++ b/src/easypost.ts @@ -1,45 +1,40 @@ -import os from "os"; -import superagent, { SuperAgentStatic, Request, Response } from "superagent"; -import { v4 as uuid } from "uuid"; - -import pkg from "../package.json"; -import Constants from "./constants"; -import ErrorHandler from "./errors/error_handler"; -import MissingParameterError from "./errors/general/missing_parameter_error"; -import AddressService from "./services/address_service"; -import ApiKeyService from "./services/api_key_service"; -import BatchService from "./services/batch_service"; -import BetaRateService from "./services/beta_rate_service"; -import BetaReferralCustomerService from "./services/beta_referral_customer_service"; -import BillingService from "./services/billing_service"; -import CarrierAccountService from "./services/carrier_account_service"; -import CarrierMetadataService from "./services/carrier_metadata_service"; -import CarrierTypeService from "./services/carrier_type_service"; -import CustomsInfoService from "./services/customs_info_service"; -import CustomsItemService from "./services/customs_item_service"; -import EndShipperService from "./services/end_shipper_service"; -import EventService from "./services/event_service"; -import InsuranceService from "./services/insurance_service"; -import OrderService from "./services/order_service"; -import ParcelService from "./services/parcel_service"; -import PickupService from "./services/pickup_service"; -import RateService from "./services/rate_service"; -import ReferralCustomerService from "./services/referral_customer_service"; -import RefundService from "./services/refund_service"; -import ReportService from "./services/report_service"; -import ScanFormService from "./services/scan_form_service"; -import ShipmentService from "./services/shipment_service"; -import TrackerService from "./services/tracker_service"; -import UserService from "./services/user_service"; -import WebhookService from "./services/webhook_service"; -import Utils from "./utils/util"; - -import util from "node:util"; - -export * from "./errors"; -export * from "./services"; -export * from "./utils/errors"; -export * from "./constants"; +import os from 'os'; +import superagent, { SuperAgentStatic, Request, Response } from 'superagent'; +import { v4 as uuid } from 'uuid'; + +import pkg from '../package.json'; +import Constants from './constants'; +import ErrorHandler from './errors/error_handler'; +import MissingParameterError from './errors/general/missing_parameter_error'; +import AddressService from './services/address_service'; +import ApiKeyService from './services/api_key_service'; +import BatchService from './services/batch_service'; +import BetaRateService from './services/beta_rate_service'; +import BetaReferralCustomerService from './services/beta_referral_customer_service'; +import BillingService from './services/billing_service'; +import CarrierAccountService from './services/carrier_account_service'; +import CarrierMetadataService from './services/carrier_metadata_service'; +import CarrierTypeService from './services/carrier_type_service'; +import CustomsInfoService from './services/customs_info_service'; +import CustomsItemService from './services/customs_item_service'; +import EndShipperService from './services/end_shipper_service'; +import EventService from './services/event_service'; +import InsuranceService from './services/insurance_service'; +import OrderService from './services/order_service'; +import ParcelService from './services/parcel_service'; +import PickupService from './services/pickup_service'; +import RateService from './services/rate_service'; +import ReferralCustomerService from './services/referral_customer_service'; +import RefundService from './services/refund_service'; +import ReportService from './services/report_service'; +import ScanFormService from './services/scan_form_service'; +import ShipmentService from './services/shipment_service'; +import TrackerService from './services/tracker_service'; +import UserService from './services/user_service'; +import WebhookService from './services/webhook_service'; +import Utils from './utils/util'; + +import util from 'node:util'; /** How many milliseconds in a second. */ export const MS_SECOND = 1000; @@ -48,33 +43,31 @@ export const MS_SECOND = 1000; export const DEFAULT_TIMEOUT = 60 * MS_SECOND; /** The default base URL for all production EasyPost API requests. */ -export const DEFAULT_BASE_URL = "https://api.easypost.com/v2/"; +export const DEFAULT_BASE_URL = 'https://api.easypost.com/v2/'; /** The default headers used for all EasyPost API requests. */ export const DEFAULT_HEADERS = { - Accept: "application/json", - "Content-Type": "application/json", - "User-Agent": `EasyPost/v2 NodejsClient/${pkg.version} Nodejs/${ + Accept: 'application/json', + 'Content-Type': 'application/json', + 'User-Agent': `EasyPost/v2 NodejsClient/${pkg.version} Nodejs/${ process.versions.node } OS/${os.platform()} OSVersion/${os.release()} OSArch/${os.arch()}`, }; /** A map of HTTP methods to their corresponding string values (for use with superagent). */ export const METHODS = { - GET: "get", - POST: "post", - PUT: "put", - PATCH: "patch", - DELETE: "del", + GET: 'get', + POST: 'post', + PUT: 'put', + PATCH: 'patch', + DELETE: 'del', } as const; export type EasyPostClientOptions = { useProxy?: boolean; timeout?: number; baseUrl?: string; - superagentMiddleware?: ( - agent: SuperAgentStatic - ) => SuperAgentStatic; + superagentMiddleware?: (agent: SuperAgentStatic) => SuperAgentStatic; requestMiddleware?: (request: Request) => Request; agent?: SuperAgentStatic; @@ -91,9 +84,9 @@ export type RequestHookData = { export type RequestHook = (data: RequestHookData) => void; export type ResponseHookData = RequestHookData & { requestHeaders: Record; - httpStatus: Response["status"]; - responseBody: Response["body"]; - headers: Response["headers"]; + httpStatus: Response['status']; + responseBody: Response['body']; + headers: Response['headers']; responseTimestamp: number; }; export type ResponseHook = (data: ResponseHookData) => void; @@ -143,18 +136,11 @@ export default class EasyPostClient { Webhook: ReturnType; constructor(key: string, options: EasyPostClientOptions = {}) { - const { - useProxy, - timeout, - baseUrl, - superagentMiddleware, - requestMiddleware, - agent, - } = options; + const { useProxy, timeout, baseUrl, superagentMiddleware, requestMiddleware, agent } = options; if (!key && !useProxy) { throw new MissingParameterError({ - message: util.format(Constants.MISSING_REQUIRED_PARAMETER, "API Key"), + message: util.format(Constants.MISSING_REQUIRED_PARAMETER, 'API Key'), }); } @@ -250,19 +236,10 @@ export default class EasyPostClient { */ static copyClient( client: EasyPostClient, - options: EasyPostClientOptions & { apiKey?: string } = {} + options: EasyPostClientOptions & { apiKey?: string } = {}, ) { - const { - apiKey, - useProxy, - timeout, - baseUrl, - superagentMiddleware, - requestMiddleware, - } = options; - const agent = superagentMiddleware - ? superagentMiddleware(client.agent) - : client.agent; + const { apiKey, useProxy, timeout, baseUrl, superagentMiddleware, requestMiddleware } = options; + const agent = superagentMiddleware ? superagentMiddleware(client.agent) : client.agent; return new EasyPostClient(apiKey || client.key, { useProxy: useProxy || client.useProxy, @@ -290,15 +267,13 @@ export default class EasyPostClient { * @param {string} path - The path to build. * @returns {string} The full path to use for the HTTP request. */ - _buildPath(path: string = ""): string { - if (path.indexOf("http") === 0) { + _buildPath(path: string = ''): string { + if (path.indexOf('http') === 0) { return path; } let completePath = this.baseUrl + path; - completePath = path.includes("beta") - ? completePath.replace("v2", "") - : completePath; + completePath = path.includes('beta') ? completePath.replace('v2', '') : completePath; return completePath; } @@ -310,10 +285,7 @@ export default class EasyPostClient { * @param {Object} response - the response from the superagent request * @returns {Object} - the value to be passed to the responseHooks */ - _createResponseHooksValue( - baseHooksValue: RequestHookData, - response: Response - ): ResponseHookData { + _createResponseHooksValue(baseHooksValue: RequestHookData, response: Response): ResponseHookData { return { ...baseHooksValue, requestHeaders: baseHooksValue.headers, @@ -334,10 +306,10 @@ export default class EasyPostClient { * @throws {ApiError} If the request fails. */ async _request( - path = "", + path = '', method: (typeof METHODS)[keyof typeof METHODS] = METHODS.GET, params: Record = {}, - headers: Record = {} + headers: Record = {}, ) { const urlPath = this._buildPath(path); const requestHeaders = EasyPostClient._buildHeaders(headers); @@ -348,7 +320,7 @@ export default class EasyPostClient { } if (this.key) { - request.auth(this.key, "", { type: "basic" }); + request.auth(this.key, '', { type: 'basic' }); } // it would be ideal if this "full url with params" could be gotten from superagent directly, @@ -382,29 +354,26 @@ export default class EasyPostClient { const response = await request; if (this.responseHooks.length > 0) { - const responseHooksValue = this._createResponseHooksValue( - baseHooksValue, - response - ); + const responseHooksValue = this._createResponseHooksValue(baseHooksValue, response); this.responseHooks.forEach((fn) => fn(responseHooksValue)); } return response; } catch (error) { - if (!error || typeof error !== "object") { + if (!error || typeof error !== 'object') { throw error; } if ( - "response" in error && + 'response' in error && error.response && - typeof error.response === "object" && - "body" in error.response && + typeof error.response === 'object' && + 'body' in error.response && error.response.body ) { const responseHooksValue = this._createResponseHooksValue( baseHooksValue, - error.response as any + error.response as any, ); this.responseHooks.forEach((fn) => fn(responseHooksValue)); @@ -427,7 +396,7 @@ export default class EasyPostClient { _get( path: string, params: Record = {}, - headers: Record = {} + headers: Record = {}, ) { return this._request(path, METHODS.GET, params, headers); } @@ -472,11 +441,7 @@ export default class EasyPostClient { * @param {Record} [headers] - Additional headers to send with the request. * @returns {*} The response from the HTTP request. */ - _delete( - path: string, - params: any = {}, - headers: Record = {} - ) { + _delete(path: string, params: any = {}, headers: Record = {}) { return this._request(path, METHODS.DELETE, params, headers); } } diff --git a/src/errors/api/api_error.ts b/src/errors/api/api_error.ts index 8988198ac..5857153af 100644 --- a/src/errors/api/api_error.ts +++ b/src/errors/api/api_error.ts @@ -1,4 +1,4 @@ -import EasyPostError from "../easypost_error"; +import EasyPostError from '../easypost_error'; /** * The ApiError class is used to represent errors that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/bad_request_error.ts b/src/errors/api/bad_request_error.ts index 2598a71cb..4a3b61355 100644 --- a/src/errors/api/bad_request_error.ts +++ b/src/errors/api/bad_request_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The BadRequestError class is used to represent a 400 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/external_api_error.ts b/src/errors/api/external_api_error.ts index c41513994..5e1d03656 100644 --- a/src/errors/api/external_api_error.ts +++ b/src/errors/api/external_api_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The ExternalApiError class is used to represent errors that occurred while communicating with an external API. diff --git a/src/errors/api/forbidden_error.ts b/src/errors/api/forbidden_error.ts index 92dc519c4..dd6e3e9cb 100644 --- a/src/errors/api/forbidden_error.ts +++ b/src/errors/api/forbidden_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The ForbiddenError class is used to represent a 403 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/gateway_timeout_error.ts b/src/errors/api/gateway_timeout_error.ts index c64ce762e..6932a94c5 100644 --- a/src/errors/api/gateway_timeout_error.ts +++ b/src/errors/api/gateway_timeout_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The GatewayTimeoutError class is used to represent a 504 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/http_error.ts b/src/errors/api/http_error.ts index 1a0bde9aa..e9fa5d59f 100644 --- a/src/errors/api/http_error.ts +++ b/src/errors/api/http_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The HttpError class is used to represent a generic HTTP-related error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/index.ts b/src/errors/api/index.ts index 2c5f2f741..6ac9ac6b3 100644 --- a/src/errors/api/index.ts +++ b/src/errors/api/index.ts @@ -1,18 +1,18 @@ -export * from "./api_error"; -export * from "./bad_request_error"; -export * from "./external_api_error"; -export * from "./forbidden_error"; -export * from "./gateway_timeout_error"; -export * from "./http_error"; -export * from "./index"; -export * from "./internal_server_error"; -export * from "./invalid_request_error"; -export * from "./method_not_allowed_error"; -export * from "./not_found_error"; -export * from "./payment_error"; -export * from "./rate_limit_error"; -export * from "./redirect_error"; -export * from "./service_unavailable_error"; -export * from "./timeout_error"; -export * from "./unauthorized_error"; -export * from "./unknown_api_error"; +export * from './api_error'; +export * from './bad_request_error'; +export * from './external_api_error'; +export * from './forbidden_error'; +export * from './gateway_timeout_error'; +export * from './http_error'; +export * from './index'; +export * from './internal_server_error'; +export * from './invalid_request_error'; +export * from './method_not_allowed_error'; +export * from './not_found_error'; +export * from './payment_error'; +export * from './rate_limit_error'; +export * from './redirect_error'; +export * from './service_unavailable_error'; +export * from './timeout_error'; +export * from './unauthorized_error'; +export * from './unknown_api_error'; diff --git a/src/errors/api/internal_server_error.ts b/src/errors/api/internal_server_error.ts index 1fc945241..2fd678117 100644 --- a/src/errors/api/internal_server_error.ts +++ b/src/errors/api/internal_server_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The InternalServerError class is used to represent a 500 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/invalid_request_error.ts b/src/errors/api/invalid_request_error.ts index a93ca5e50..91c92f0be 100644 --- a/src/errors/api/invalid_request_error.ts +++ b/src/errors/api/invalid_request_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The InvalidRequestError class is used to represent a 422 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/method_not_allowed_error.ts b/src/errors/api/method_not_allowed_error.ts index 417b2ae16..2b886f62a 100644 --- a/src/errors/api/method_not_allowed_error.ts +++ b/src/errors/api/method_not_allowed_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The MethodNotAllowedError class is used to represent a 405 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/not_found_error.ts b/src/errors/api/not_found_error.ts index 3e515f598..0af4c2fdf 100644 --- a/src/errors/api/not_found_error.ts +++ b/src/errors/api/not_found_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The NotFoundError class is used to represent a 404 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/payment_error.ts b/src/errors/api/payment_error.ts index d76ad8b0f..92a40c77c 100644 --- a/src/errors/api/payment_error.ts +++ b/src/errors/api/payment_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The PaymentError class is used to represent a 402 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/rate_limit_error.ts b/src/errors/api/rate_limit_error.ts index b0253f634..3fe9bd6d3 100644 --- a/src/errors/api/rate_limit_error.ts +++ b/src/errors/api/rate_limit_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The RateLimitError class is used to represent a 429 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/redirect_error.ts b/src/errors/api/redirect_error.ts index 96c650507..9bab9b9d3 100644 --- a/src/errors/api/redirect_error.ts +++ b/src/errors/api/redirect_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The RedirectError class is used to represent a 3xx error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/service_unavailable_error.ts b/src/errors/api/service_unavailable_error.ts index 2acbce1e3..56c0c1412 100644 --- a/src/errors/api/service_unavailable_error.ts +++ b/src/errors/api/service_unavailable_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The ServiceUnavailableError class is used to represent a 503 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/timeout_error.ts b/src/errors/api/timeout_error.ts index 7ae1e47b9..5bed1efbf 100644 --- a/src/errors/api/timeout_error.ts +++ b/src/errors/api/timeout_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The TimeoutError class is used to represent a 408 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/unauthorized_error.ts b/src/errors/api/unauthorized_error.ts index 2c6664412..24ac74f21 100644 --- a/src/errors/api/unauthorized_error.ts +++ b/src/errors/api/unauthorized_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The UnauthorizedError class is used to represent a 401 error that occurred while communicating with the EasyPost API. diff --git a/src/errors/api/unknown_api_error.ts b/src/errors/api/unknown_api_error.ts index 82ef025da..d551069d6 100644 --- a/src/errors/api/unknown_api_error.ts +++ b/src/errors/api/unknown_api_error.ts @@ -1,4 +1,4 @@ -import ApiError from "./api_error"; +import ApiError from './api_error'; /** * The UnknownApiError class is used to represent a generic, unexpected error that occurred while communicating with the EasyPost API. diff --git a/src/errors/error_handler.ts b/src/errors/error_handler.ts index 301afe805..5c77e79f2 100644 --- a/src/errors/error_handler.ts +++ b/src/errors/error_handler.ts @@ -1,20 +1,20 @@ -import Constants from "../constants"; -import ApiError from "./api/api_error"; -import BadRequestError from "./api/bad_request_error"; -import ForbiddenError from "./api/forbidden_error"; -import GatewayTimeoutError from "./api/gateway_timeout_error"; -import InternalServerError from "./api/internal_server_error"; -import InvalidRequestError from "./api/invalid_request_error"; -import MethodNotAllowedError from "./api/method_not_allowed_error"; -import NotFoundError from "./api/not_found_error"; -import PaymentError from "./api/payment_error"; -import RateLimitError from "./api/rate_limit_error"; -import RedirectError from "./api/redirect_error"; -import ServiceUnavailableError from "./api/service_unavailable_error"; -import TimeoutError from "./api/timeout_error"; -import UnauthorizedError from "./api/unauthorized_error"; -import UnknownApiError from "./api/unknown_api_error"; -import EasyPostError from "./easypost_error"; +import Constants from '../constants'; +import ApiError from './api/api_error'; +import BadRequestError from './api/bad_request_error'; +import ForbiddenError from './api/forbidden_error'; +import GatewayTimeoutError from './api/gateway_timeout_error'; +import InternalServerError from './api/internal_server_error'; +import InvalidRequestError from './api/invalid_request_error'; +import MethodNotAllowedError from './api/method_not_allowed_error'; +import NotFoundError from './api/not_found_error'; +import PaymentError from './api/payment_error'; +import RateLimitError from './api/rate_limit_error'; +import RedirectError from './api/redirect_error'; +import ServiceUnavailableError from './api/service_unavailable_error'; +import TimeoutError from './api/timeout_error'; +import UnauthorizedError from './api/unauthorized_error'; +import UnknownApiError from './api/unknown_api_error'; +import EasyPostError from './easypost_error'; export type RawAPIError = { statusCode: number; @@ -61,10 +61,10 @@ export default class ErrorHandler { static isAPIError(error: any): error is RawAPIError { return ( error && - typeof error.statusCode === "number" && - typeof error.body === "object" && - typeof error.body.error === "object" && - typeof error.body.error.code === "string" && + typeof error.statusCode === 'number' && + typeof error.body === 'object' && + typeof error.body.error === 'object' && + typeof error.body.error.code === 'string' && error.body.error.message && error.body.error.errors ); @@ -79,7 +79,7 @@ export default class ErrorHandler { const { statusCode } = error; const { code, message, errors } = error.body.error; const errorParams = { - message: "", + message: '', code, statusCode, errors, @@ -87,11 +87,11 @@ export default class ErrorHandler { try { const messages = this.traverseJsonElement(message); - errorParams.message = messages.join(", "); + errorParams.message = messages.join(', '); } catch (e) { const errorParams = { message: Constants.ERROR_DESERIALIZATION, - code: "ERROR_DESERIALIZATION_ERROR", + code: 'ERROR_DESERIALIZATION_ERROR', }; return new EasyPostError(errorParams); } diff --git a/src/errors/general/end_of_pagination_error.ts b/src/errors/general/end_of_pagination_error.ts index 4cd5241d4..b2be10785 100644 --- a/src/errors/general/end_of_pagination_error.ts +++ b/src/errors/general/end_of_pagination_error.ts @@ -1,5 +1,5 @@ -import Constants from "../../constants"; -import EasyPostError from "../easypost_error"; +import Constants from '../../constants'; +import EasyPostError from '../easypost_error'; /** * The EndOfPaginationError class is used to represent an error that no more page can be retrieved diff --git a/src/errors/general/filtering_error.ts b/src/errors/general/filtering_error.ts index b85795a6b..7b0be3426 100644 --- a/src/errors/general/filtering_error.ts +++ b/src/errors/general/filtering_error.ts @@ -1,4 +1,4 @@ -import EasyPostError from "../easypost_error"; +import EasyPostError from '../easypost_error'; /** * The FilteringError class is used to represent an error that occurred while filtering a list (e.g. a list of rates). diff --git a/src/errors/general/index.ts b/src/errors/general/index.ts index 43927ff68..04c30fdb2 100644 --- a/src/errors/general/index.ts +++ b/src/errors/general/index.ts @@ -1,6 +1,6 @@ -export * from "./end_of_pagination_error"; -export * from "./filtering_error"; -export * from "./invalid_object_error"; -export * from "./invalid_parameter_error"; -export * from "./missing_parameter_error"; -export * from "./signature_verification_error"; +export * from './end_of_pagination_error'; +export * from './filtering_error'; +export * from './invalid_object_error'; +export * from './invalid_parameter_error'; +export * from './missing_parameter_error'; +export * from './signature_verification_error'; diff --git a/src/errors/general/invalid_object_error.ts b/src/errors/general/invalid_object_error.ts index b9cf35423..14d3bc387 100644 --- a/src/errors/general/invalid_object_error.ts +++ b/src/errors/general/invalid_object_error.ts @@ -1,4 +1,4 @@ -import EasyPostError from "../easypost_error"; +import EasyPostError from '../easypost_error'; /** * The InvalidObjectError class is used to represent an error due to an invalid object (e.g. missing an expected property). diff --git a/src/errors/general/invalid_parameter_error.ts b/src/errors/general/invalid_parameter_error.ts index 38eee3050..b55a4b14c 100644 --- a/src/errors/general/invalid_parameter_error.ts +++ b/src/errors/general/invalid_parameter_error.ts @@ -1,4 +1,4 @@ -import EasyPostError from "../easypost_error"; +import EasyPostError from '../easypost_error'; /** * The InvalidParameterError class is used to represent an error due to an invalid function parameter. diff --git a/src/errors/general/missing_parameter_error.ts b/src/errors/general/missing_parameter_error.ts index a0a98e38e..586b28065 100644 --- a/src/errors/general/missing_parameter_error.ts +++ b/src/errors/general/missing_parameter_error.ts @@ -1,4 +1,4 @@ -import EasyPostError from "../easypost_error"; +import EasyPostError from '../easypost_error'; /** * The MissingParameterError class is used to represent an error due to a missing expected function parameter. diff --git a/src/errors/general/signature_verification_error.ts b/src/errors/general/signature_verification_error.ts index 9e03fa0c5..c3029e331 100644 --- a/src/errors/general/signature_verification_error.ts +++ b/src/errors/general/signature_verification_error.ts @@ -1,4 +1,4 @@ -import EasyPostError from "../easypost_error"; +import EasyPostError from '../easypost_error'; /** * The SignatureVerificationError class is used to represent an error due to a failed signature verification (e.g. a webhook HMAC signature). diff --git a/src/errors/index.ts b/src/errors/index.ts index 170d5bd99..a8d312a93 100644 --- a/src/errors/index.ts +++ b/src/errors/index.ts @@ -1,4 +1,4 @@ -export * from "./api"; -export * from "./general"; -export * from "./easypost_error"; -export * from "./error_handler"; +export * from './api'; +export * from './general'; +export * from './easypost_error'; +export * from './error_handler'; diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index fa2a470df..000000000 --- a/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import EasyPost from "./easypost"; - -export default EasyPost; diff --git a/src/services/address_service/Address.ts b/src/services/address_service/Address.ts index 1889d611f..403c5bc3a 100644 --- a/src/services/address_service/Address.ts +++ b/src/services/address_service/Address.ts @@ -1,5 +1,5 @@ -import { IVerifications } from "./Verifications"; -import { IObjectWithId } from "../../utils/types"; +import { IVerifications } from './Verifications'; +import { IObjectWithId } from '../../utils/types'; /** * Address objects are used to represent people, places, and organizations in a number of contexts. @@ -9,7 +9,7 @@ import { IObjectWithId } from "../../utils/types"; * * @see https://www.easypost.com/docs/api/node#address-object */ -export type IAddress = IObjectWithId<"Address"> & { +export type IAddress = IObjectWithId<'Address'> & { /** * First line of the address */ diff --git a/src/services/address_service/AddressCreateParameters.ts b/src/services/address_service/AddressCreateParameters.ts index b041de7f3..49dccafda 100644 --- a/src/services/address_service/AddressCreateParameters.ts +++ b/src/services/address_service/AddressCreateParameters.ts @@ -1,12 +1,12 @@ -import { ParametersToOmitOnCreate } from "../../utils/types"; -import { IAddress } from "./Address"; +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IAddress } from './Address'; /** * @see https://www.easypost.com/docs/api/node#create-and-verify-addresses */ export type IAddressCreateParameters = Omit< IAddress, - ParametersToOmitOnCreate | "verifications" + ParametersToOmitOnCreate | 'verifications' > & { /** * The verifications to perform when creating. diff --git a/src/services/address_service/AddressListParameters.ts b/src/services/address_service/AddressListParameters.ts index c2a965a5b..1ec17fa5a 100644 --- a/src/services/address_service/AddressListParameters.ts +++ b/src/services/address_service/AddressListParameters.ts @@ -1,4 +1,4 @@ -import { IAllMethodParameters } from "../../utils/types"; +import { IAllMethodParameters } from '../../utils/types'; /** * @see https://www.easypost.com/docs/api#retrieve-a-list-of-addresses diff --git a/src/services/address_service/Verification.ts b/src/services/address_service/Verification.ts index bf8560808..e8fa9b749 100644 --- a/src/services/address_service/Verification.ts +++ b/src/services/address_service/Verification.ts @@ -1,5 +1,5 @@ -import { IFieldError } from "../../utils/errors"; -import { IVerificationDetails } from "./VerificationDetails"; +import { IFieldError } from '../../utils/errors'; +import { IVerificationDetails } from './VerificationDetails'; /** * @see https://www.easypost.com/docs/api/node#verification-object diff --git a/src/services/address_service/Verifications.ts b/src/services/address_service/Verifications.ts index 6ed85596b..3bd0c090f 100644 --- a/src/services/address_service/Verifications.ts +++ b/src/services/address_service/Verifications.ts @@ -1,4 +1,4 @@ -import { IVerification } from "./Verification"; +import { IVerification } from './Verification'; /** * @see https://www.easypost.com/docs/api/node#verifications-object diff --git a/src/services/address_service/index.ts b/src/services/address_service/index.ts index a3312d44d..5247d8ba2 100644 --- a/src/services/address_service/index.ts +++ b/src/services/address_service/index.ts @@ -1,14 +1,14 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IAddress } from "./Address"; -import { IAddressCreateParameters } from "./AddressCreateParameters"; -import { IAddressListParameters } from "./AddressListParameters"; - -export * from "./Address"; -export * from "./AddressCreateParameters"; -export * from "./Verification"; -export * from "./VerificationDetails"; -export * from "./Verifications"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IAddress } from './Address'; +import { IAddressCreateParameters } from './AddressCreateParameters'; +import { IAddressListParameters } from './AddressListParameters'; + +export * from './Address'; +export * from './AddressCreateParameters'; +export * from './Verification'; +export * from './VerificationDetails'; +export * from './Verifications'; export default (easypostClient: EasyPost) => /** @@ -23,11 +23,11 @@ export default (easypostClient: EasyPost) => * @returns - The created address. */ static async create(params: IAddressCreateParameters) { - const url = "addresses"; + const url = 'addresses'; const wrappedParams: { address: IAddressCreateParameters } & Pick< IAddressCreateParameters, - "verify" | "verify_strict" + 'verify' | 'verify_strict' > = { address: params, }; @@ -58,10 +58,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url, wrappedParams); - return this._convertToEasyPostObject( - response.body.address, - wrappedParams - ); + return this._convertToEasyPostObject(response.body.address, wrappedParams); } catch (e) { return Promise.reject(e); } @@ -74,7 +71,7 @@ export default (easypostClient: EasyPost) => * @returns - An object containing a list of {@link Address addresses} and pagination information. */ static async all(params: IAddressListParameters = {}) { - const url = "addresses"; + const url = 'addresses'; return this._all(url, params); } @@ -85,12 +82,9 @@ export default (easypostClient: EasyPost) => * @param pageSize The number of records to return on each page * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage( - addresses: { addresses: IAddress[] }, - pageSize: number | null = null - ) { - const url = "addresses"; - return this._getNextPage(url, "addresses", addresses, pageSize); + static async getNextPage(addresses: { addresses: IAddress[] }, pageSize: number | null = null) { + const url = 'addresses'; + return this._getNextPage(url, 'addresses', addresses, pageSize); } /** diff --git a/src/services/api_key_service/ApiKey.ts b/src/services/api_key_service/ApiKey.ts index 4d828c8a5..bad9eff2f 100644 --- a/src/services/api_key_service/ApiKey.ts +++ b/src/services/api_key_service/ApiKey.ts @@ -1,6 +1,6 @@ -import { IObjectWithId } from "../../utils/types"; +import { IObjectWithId } from '../../utils/types'; -export type IApiKey = IObjectWithId<"ApiKey"> & { +export type IApiKey = IObjectWithId<'ApiKey'> & { /** * The actual key value to use for authentication */ diff --git a/src/services/api_key_service/index.ts b/src/services/api_key_service/index.ts index cdbe8dbee..31cda71ba 100644 --- a/src/services/api_key_service/index.ts +++ b/src/services/api_key_service/index.ts @@ -1,11 +1,11 @@ -import util from "node:util"; -import baseService from "../base_service"; -import Constants from "../../constants"; -import FilteringError from "../../errors/general/filtering_error"; -import EasyPost from "../.."; -import { IApiKey, UserAPIKeys } from "./ApiKey"; +import util from 'node:util'; +import baseService from '../base_service'; +import Constants from '../../constants'; +import FilteringError from '../../errors/general/filtering_error'; +import EasyPost from '../..'; +import { IApiKey, UserAPIKeys } from './ApiKey'; -export * from "./ApiKey"; +export * from './ApiKey'; export default (easypostClient: EasyPost) => /** @@ -19,7 +19,7 @@ export default (easypostClient: EasyPost) => * @returns - An object containing the API keys associated with the current authenticated user and its child users. */ static async all(params = {}) { - const url = "api_keys"; + const url = 'api_keys'; return this._all(url, params); } @@ -52,7 +52,7 @@ export default (easypostClient: EasyPost) => } throw new FilteringError({ - message: util.format(Constants.NO_OBJECT_FOUND, "child"), + message: util.format(Constants.NO_OBJECT_FOUND, 'child'), }); } }; diff --git a/src/services/base_service.ts b/src/services/base_service.ts index 34c9992ae..16a1f1832 100644 --- a/src/services/base_service.ts +++ b/src/services/base_service.ts @@ -1,5 +1,5 @@ -import EasyPostClient from "../easypost"; -import EndOfPaginationError from "../errors/general/end_of_pagination_error"; +import EasyPostClient from '../easypost'; +import EndOfPaginationError from '../errors/general/end_of_pagination_error'; export type EasyPostObject = A & { _params: any; @@ -18,10 +18,7 @@ export default (easypostClient: EasyPostClient) => * @param {*} params The parameters passed when fetching the response * @returns {*} An {@link EasyPostObject}-based class instance or an `Array` of {@link EasyPostObject}-based class instances. */ - static _convertToEasyPostObject( - response: A, - params?: any - ): EasyPostObject { + static _convertToEasyPostObject(response: A, params?: any): EasyPostObject { const newResponse = response as EasyPostObject; newResponse._params = params; @@ -35,10 +32,7 @@ export default (easypostClient: EasyPostClient) => * @param params The parameters to send with the API request. * @returns The created {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async _create( - url: string, - params: object - ): Promise> { + static async _create(url: string, params: object): Promise> { try { const response = await easypostClient._post(url, params); @@ -57,7 +51,7 @@ export default (easypostClient: EasyPostClient) => */ static async _all( url: string, - params: Record = {} + params: Record = {}, ): Promise & { has_more: boolean }> { try { // eslint-disable-next-line no-param-reassign @@ -100,19 +94,14 @@ export default (easypostClient: EasyPostClient) => key: keyof A, collection: A, pageSize: number | null = null, - optionalParams: Record = {} + optionalParams: Record = {}, ): Promise & { has_more: boolean }> { const collectionArray = collection[key]; - if ( - collectionArray == undefined || - collectionArray.length == 0 || - !collection.has_more - ) { + if (collectionArray == undefined || collectionArray.length == 0 || !collection.has_more) { throw new EndOfPaginationError(); } - const defaultParams = - collection._params ?? collectionArray[0]._params ?? {}; + const defaultParams = collection._params ?? collectionArray[0]._params ?? {}; const params = { ...defaultParams, diff --git a/src/services/batch_service/Batch.ts b/src/services/batch_service/Batch.ts index be0c53097..a5c458d8a 100644 --- a/src/services/batch_service/Batch.ts +++ b/src/services/batch_service/Batch.ts @@ -1,9 +1,9 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; -import { IPickup } from "../pickup_service/Pickup"; -import { IScanForm } from "../scan_form_service"; -import { IBatchShipment } from "./BatchShipment"; -import { TBatchState } from "./BatchState"; -import { TBatchStatuses } from "./BatchStatuses"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IPickup } from '../pickup_service/Pickup'; +import { IScanForm } from '../scan_form_service'; +import { IBatchShipment } from './BatchShipment'; +import { TBatchState } from './BatchState'; +import { TBatchStatuses } from './BatchStatuses'; /** * The Batch object allows you to perform operations on multiple Shipments at once. @@ -12,7 +12,7 @@ import { TBatchStatuses } from "./BatchStatuses"; * * @see https://www.easypost.com/docs/api/node#batch-object */ -export type IBatch = IObjectWithId<"Batch"> & +export type IBatch = IObjectWithId<'Batch'> & IDatedObject & { /** * An optional field that may be used in place of ID in some API endpoints diff --git a/src/services/batch_service/BatchCreateParameters.ts b/src/services/batch_service/BatchCreateParameters.ts index eae32ace5..0662e066e 100644 --- a/src/services/batch_service/BatchCreateParameters.ts +++ b/src/services/batch_service/BatchCreateParameters.ts @@ -1,4 +1,4 @@ -import { IShipment } from "../shipment_service"; +import { IShipment } from '../shipment_service'; export type IBatchCreateParameters = { shipments?: ({ id: string } | string)[]; diff --git a/src/services/batch_service/BatchListParameters.ts b/src/services/batch_service/BatchListParameters.ts index 1e7343515..d8dfdfe2b 100644 --- a/src/services/batch_service/BatchListParameters.ts +++ b/src/services/batch_service/BatchListParameters.ts @@ -1,4 +1,4 @@ -import { IAllMethodParameters } from "../../utils/types"; +import { IAllMethodParameters } from '../../utils/types'; /** * @see https://www.easypost.com/docs/api/node#list-all-batches diff --git a/src/services/batch_service/BatchShipment.ts b/src/services/batch_service/BatchShipment.ts index 108c095f3..ee4baf008 100644 --- a/src/services/batch_service/BatchShipment.ts +++ b/src/services/batch_service/BatchShipment.ts @@ -1,4 +1,4 @@ -import { TBatchStatus } from "./BatchStatus"; +import { TBatchStatus } from './BatchStatus'; /** * @see https://www.easypost.com/docs/api/node#batch-shipment-object diff --git a/src/services/batch_service/BatchState.ts b/src/services/batch_service/BatchState.ts index 02f0cfc0f..41fa51e7a 100644 --- a/src/services/batch_service/BatchState.ts +++ b/src/services/batch_service/BatchState.ts @@ -1,9 +1,9 @@ export type TBatchState = - | "creating" - | "creation_failed" - | "created" - | "purchasing" - | "purchase_failed" - | "purchased" - | "label_generating" - | "label_generated"; + | 'creating' + | 'creation_failed' + | 'created' + | 'purchasing' + | 'purchase_failed' + | 'purchased' + | 'label_generating' + | 'label_generated'; diff --git a/src/services/batch_service/BatchStatus.ts b/src/services/batch_service/BatchStatus.ts index 642a50231..c85d419dc 100644 --- a/src/services/batch_service/BatchStatus.ts +++ b/src/services/batch_service/BatchStatus.ts @@ -1,6 +1,6 @@ export type TBatchStatus = - | "postage_purchased" - | "postage_purchase_failed" - | "queued_for_purchase" - | "creation_failed" - | "created"; + | 'postage_purchased' + | 'postage_purchase_failed' + | 'queued_for_purchase' + | 'creation_failed' + | 'created'; diff --git a/src/services/batch_service/BatchStatuses.ts b/src/services/batch_service/BatchStatuses.ts index 545cf0396..cd639f296 100644 --- a/src/services/batch_service/BatchStatuses.ts +++ b/src/services/batch_service/BatchStatuses.ts @@ -1,3 +1,3 @@ -import { TBatchStatus } from "./BatchStatus"; +import { TBatchStatus } from './BatchStatus'; export type TBatchStatuses = { [key in TBatchStatus]: number }; diff --git a/src/services/batch_service/index.ts b/src/services/batch_service/index.ts index 1a391bea8..52423a0e8 100644 --- a/src/services/batch_service/index.ts +++ b/src/services/batch_service/index.ts @@ -1,18 +1,18 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IBatch } from "./Batch"; -import { IBatchCreateParameters } from "./BatchCreateParameters"; -import { IBatchListParameters } from "./BatchListParameters"; - -export * from "./Batch"; -export * from "./BatchCreateParameters"; -export * from "./BatchListParameters"; -export * from "./BatchShipment"; -export * from "./BatchState"; -export * from "./BatchStatus"; -export * from "./BatchStatuses"; - -export const DEFAULT_LABEL_FORMAT = "pdf"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IBatch } from './Batch'; +import { IBatchCreateParameters } from './BatchCreateParameters'; +import { IBatchListParameters } from './BatchListParameters'; + +export * from './Batch'; +export * from './BatchCreateParameters'; +export * from './BatchListParameters'; +export * from './BatchShipment'; +export * from './BatchState'; +export * from './BatchStatus'; +export * from './BatchStatuses'; + +export const DEFAULT_LABEL_FORMAT = 'pdf'; export default (easypostClient: EasyPost) => /** @@ -27,7 +27,7 @@ export default (easypostClient: EasyPost) => * @returns - The created batch. */ static async create(params: IBatchCreateParameters) { - const url = "batches"; + const url = 'batches'; const wrappedParams = { batch: params, @@ -51,10 +51,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url, wrappedParams); - return this._convertToEasyPostObject( - response.body, - wrappedParams - ); + return this._convertToEasyPostObject(response.body, wrappedParams); } catch (e) { return Promise.reject(e); } @@ -76,10 +73,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url, wrappedParams); - return this._convertToEasyPostObject( - response.body, - wrappedParams - ); + return this._convertToEasyPostObject(response.body, wrappedParams); } catch (e) { return Promise.reject(e); } @@ -99,10 +93,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url, wrappedParams); - return this._convertToEasyPostObject( - response.body, - wrappedParams - ); + return this._convertToEasyPostObject(response.body, wrappedParams); } catch (e) { return Promise.reject(e); } @@ -151,7 +142,7 @@ export default (easypostClient: EasyPost) => * @returns - An object containing a list of {@link Batch batches} and pagination information. */ static async all(params: IBatchListParameters = {}) { - const url = "batches"; + const url = 'batches'; return this._all(url, params); } diff --git a/src/services/beta_rate_service/index.ts b/src/services/beta_rate_service/index.ts index 2693ee5d1..85ab989b0 100644 --- a/src/services/beta_rate_service/index.ts +++ b/src/services/beta_rate_service/index.ts @@ -1,6 +1,6 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IRate } from "../rate_service/Rate"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IRate } from '../rate_service/Rate'; /** * @extends baseService @@ -13,7 +13,7 @@ export default (easypostClient: EasyPost) => * @returns - List of stateless rates */ static async retrieveStatelessRates(params: any) { - const url = "beta/rates"; + const url = 'beta/rates'; const wrappedParams = { shipment: params, }; @@ -21,10 +21,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url, wrappedParams); - return this._convertToEasyPostObject( - response.body.rates, - wrappedParams - ); + return this._convertToEasyPostObject(response.body.rates, wrappedParams); } catch (e) { return Promise.reject(e); } diff --git a/src/services/beta_referral_customer_service/index.ts b/src/services/beta_referral_customer_service/index.ts index 836e9223a..afe54ed85 100644 --- a/src/services/beta_referral_customer_service/index.ts +++ b/src/services/beta_referral_customer_service/index.ts @@ -1,7 +1,7 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IPaymentMethod } from "../billing_service"; -import { IRefund } from "../refund_service"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IPaymentMethod } from '../billing_service'; +import { IRefund } from '../refund_service'; export default (easypostClient: EasyPost) => class BetaReferralCustomerService extends baseService(easypostClient) { @@ -15,7 +15,7 @@ export default (easypostClient: EasyPost) => static async addPaymentMethod( stripeCustomerId: string, paymentMethodReference: string, - priority: "primary" | "secondary" = "primary" + priority: 'primary' | 'secondary' = 'primary', ) { const wrappedParams = { payment_method: { @@ -25,7 +25,7 @@ export default (easypostClient: EasyPost) => }, }; - const url = "beta/referral_customers/payment_method"; + const url = 'beta/referral_customers/payment_method'; const response = await easypostClient._post(url, wrappedParams); @@ -42,7 +42,7 @@ export default (easypostClient: EasyPost) => refund_amount: refundAmount, }; - const url = "beta/referral_customers/refunds"; + const url = 'beta/referral_customers/refunds'; const response = await easypostClient._post(url, params); @@ -59,7 +59,7 @@ export default (easypostClient: EasyPost) => payment_log_id: paymentLogId, }; - const url = "beta/referral_customers/refunds"; + const url = 'beta/referral_customers/refunds'; const response = await easypostClient._post(url, params); diff --git a/src/services/billing_service/PaymentMethod.ts b/src/services/billing_service/PaymentMethod.ts index 8211a7fcd..b6c1856dd 100644 --- a/src/services/billing_service/PaymentMethod.ts +++ b/src/services/billing_service/PaymentMethod.ts @@ -1,11 +1,11 @@ -import { IObjectWithId } from "../../utils/types"; +import { IObjectWithId } from '../../utils/types'; /** * The Payment method object can be either credit card or bank account. * * TODO: Add the link to the API doc once its updated */ -export type IPaymentMethod = IObjectWithId<"PaymentMethod"> & { +export type IPaymentMethod = IObjectWithId<'PaymentMethod'> & { /** * Country of the bank account */ diff --git a/src/services/billing_service/index.ts b/src/services/billing_service/index.ts index c188a0fe6..a24ca08e2 100644 --- a/src/services/billing_service/index.ts +++ b/src/services/billing_service/index.ts @@ -1,10 +1,10 @@ -import EasyPost from "../.."; -import Constants from "../../constants"; -import InvalidObjectError from "../../errors/general/invalid_object_error"; -import baseService from "../base_service"; +import EasyPost from '../..'; +import Constants from '../../constants'; +import InvalidObjectError from '../../errors/general/invalid_object_error'; +import baseService from '../base_service'; -export * from "./PaymentMethod"; -export type Priority = "primary" | "secondary"; +export * from './PaymentMethod'; +export type Priority = 'primary' | 'secondary'; export default (easypostClient: EasyPost) => /** @@ -18,10 +18,8 @@ export default (easypostClient: EasyPost) => * @param amount - The amount to charge to your payment method. * @param priority - The priority of the payment method to charge. Can be either 'primary' or 'secondary'. */ - static async fundWallet(amount: string, priority: Priority = "primary") { - const paymentInfo = await this._getPaymentInfo( - priority.toLowerCase() as Priority - ); + static async fundWallet(amount: string, priority: Priority = 'primary') { + const paymentInfo = await this._getPaymentInfo(priority.toLowerCase() as Priority); const endpoint = paymentInfo[0]; const paymentMethodID = paymentInfo[1]; @@ -37,9 +35,7 @@ export default (easypostClient: EasyPost) => * @param priority - The priority of the payment method to delete. Can be either 'primary' or 'secondary'. */ static async deletePaymentMethod(priority: Priority) { - const paymentInfo = await this._getPaymentInfo( - priority.toLowerCase() as Priority - ); + const paymentInfo = await this._getPaymentInfo(priority.toLowerCase() as Priority); const endpoint = paymentInfo[0]; const paymentMethodID = paymentInfo[1]; @@ -54,7 +50,7 @@ export default (easypostClient: EasyPost) => * @returns {Object} - An object containing the payment methods associated with the current authenticated user. */ static async retrievePaymentMethods() { - const url = "payment_methods"; + const url = 'payment_methods'; const res = await easypostClient._get(url); @@ -75,25 +71,21 @@ export default (easypostClient: EasyPost) => static async _getPaymentInfo(priority: Priority) { const paymentMethods = await this.retrievePaymentMethods(); const paymentMethodMap = { - primary: "primary_payment_method", - secondary: "secondary_payment_method", + primary: 'primary_payment_method', + secondary: 'secondary_payment_method', }; const paymentMethodToUse = paymentMethodMap[priority]; let paymentMethodID; let endpoint; - const errorString = - "The chosen payment method is not valid. Please try again."; + const errorString = 'The chosen payment method is not valid. Please try again.'; - if ( - paymentMethodToUse !== undefined && - paymentMethods[paymentMethodToUse] !== null - ) { + if (paymentMethodToUse !== undefined && paymentMethods[paymentMethodToUse] !== null) { paymentMethodID = paymentMethods[paymentMethodToUse].id; - if (paymentMethodID.startsWith("card_")) { - endpoint = "credit_cards"; - } else if (paymentMethodID.startsWith("bank_")) { - endpoint = "bank_accounts"; + if (paymentMethodID.startsWith('card_')) { + endpoint = 'credit_cards'; + } else if (paymentMethodID.startsWith('bank_')) { + endpoint = 'bank_accounts'; } else { throw new InvalidObjectError({ message: errorString }); } diff --git a/src/services/carrier_account_service/CarrierAccount.ts b/src/services/carrier_account_service/CarrierAccount.ts index e42a80211..a2e66ab7f 100644 --- a/src/services/carrier_account_service/CarrierAccount.ts +++ b/src/services/carrier_account_service/CarrierAccount.ts @@ -1,6 +1,6 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; -import { ICarrierAccountCreateParameters } from "./CarrierAccountCreateParameters"; -import { ICarrierAccountFields } from "./CarrierAccountFields"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { ICarrierAccountCreateParameters } from './CarrierAccountCreateParameters'; +import { ICarrierAccountFields } from './CarrierAccountFields'; /** * A CarrierAccount encapsulates your credentials with the carrier. @@ -14,7 +14,7 @@ import { ICarrierAccountFields } from "./CarrierAccountFields"; * * @see https://www.easypost.com/docs/api/node#carrier-account-object */ -export type ICarrierAccount = IObjectWithId<"CarrierAccount"> & +export type ICarrierAccount = IObjectWithId<'CarrierAccount'> & IDatedObject & { /** * The name of the carrier type. diff --git a/src/services/carrier_account_service/CarrierAccountCreateParameters.ts b/src/services/carrier_account_service/CarrierAccountCreateParameters.ts index 7891ae539..7fa7f827f 100644 --- a/src/services/carrier_account_service/CarrierAccountCreateParameters.ts +++ b/src/services/carrier_account_service/CarrierAccountCreateParameters.ts @@ -1,7 +1,4 @@ -import { ParametersToOmitOnCreate } from "../../utils/types"; -import { ICarrierAccount } from "./CarrierAccount"; +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { ICarrierAccount } from './CarrierAccount'; -export type ICarrierAccountCreateParameters = Omit< - ICarrierAccount, - ParametersToOmitOnCreate ->; +export type ICarrierAccountCreateParameters = Omit; diff --git a/src/services/carrier_account_service/CarrierAccountFields.ts b/src/services/carrier_account_service/CarrierAccountFields.ts index c7c21b04f..a30ffe625 100644 --- a/src/services/carrier_account_service/CarrierAccountFields.ts +++ b/src/services/carrier_account_service/CarrierAccountFields.ts @@ -1,4 +1,4 @@ -import { ICarrierAccountField } from "./CarrierAccountField"; +import { ICarrierAccountField } from './CarrierAccountField'; /** * @see https://www.easypost.com/docs/api/node#carrier-account-fields-object diff --git a/src/services/carrier_account_service/index.ts b/src/services/carrier_account_service/index.ts index 87a47b3bb..1679da9cb 100644 --- a/src/services/carrier_account_service/index.ts +++ b/src/services/carrier_account_service/index.ts @@ -1,15 +1,15 @@ -import util from "node:util"; -import baseService from "../base_service"; -import Constants from "../../constants"; -import InvalidParameterError from "../../errors/general/invalid_parameter_error"; -import EasyPost from "../.."; -import { ICarrierAccount } from "./CarrierAccount"; -import { ICarrierAccountCreateParameters } from "./CarrierAccountCreateParameters"; - -export * from "./CarrierAccount"; -export * from "./CarrierAccountCreateParameters"; -export * from "./CarrierAccountField"; -export * from "./CarrierAccountFields"; +import util from 'node:util'; +import baseService from '../base_service'; +import Constants from '../../constants'; +import InvalidParameterError from '../../errors/general/invalid_parameter_error'; +import EasyPost from '../..'; +import { ICarrierAccount } from './CarrierAccount'; +import { ICarrierAccountCreateParameters } from './CarrierAccountCreateParameters'; + +export * from './CarrierAccount'; +export * from './CarrierAccountCreateParameters'; +export * from './CarrierAccountField'; +export * from './CarrierAccountFields'; export default (easypostClient: EasyPost) => /** @@ -28,15 +28,11 @@ export default (easypostClient: EasyPost) => if (!carrierAccountType) { throw new InvalidParameterError({ - message: util.format( - Constants.MISSING_REQUIRED_PARAMETER, - "CarrierAccount type" - ), + message: util.format(Constants.MISSING_REQUIRED_PARAMETER, 'CarrierAccount type'), }); } - const endpoint = - this._selectCarrierAccountCreationEndpoint(carrierAccountType); + const endpoint = this._selectCarrierAccountCreationEndpoint(carrierAccountType); const wrappedParams = { carrier_account: params }; @@ -50,10 +46,7 @@ export default (easypostClient: EasyPost) => * @param params - Parameters for the carrier account to be updated. * @returns - The updated carrier account. */ - static async update( - id: string, - params: Partial - ) { + static async update(id: string, params: Partial) { const url = `carrier_accounts/${id}`; const wrappedParams = { carrier_account: params, @@ -62,10 +55,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._patch(url, wrappedParams); - return this._convertToEasyPostObject( - response.body, - wrappedParams - ); + return this._convertToEasyPostObject(response.body, wrappedParams); } catch (e) { return Promise.reject(e); } @@ -96,14 +86,10 @@ export default (easypostClient: EasyPost) => * @returns {string} - The endpoint to be used for the carrier account creation request. */ static _selectCarrierAccountCreationEndpoint(carrierAccountType: string) { - if ( - Constants.CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS.includes( - carrierAccountType - ) - ) { - return "carrier_accounts/register"; + if (Constants.CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS.includes(carrierAccountType)) { + return 'carrier_accounts/register'; } - return "carrier_accounts"; + return 'carrier_accounts'; } /** @@ -113,7 +99,7 @@ export default (easypostClient: EasyPost) => * @returns - An object containing a list of {@link CarrierAccount carrier accounts} and pagination information. */ static async all(params = {}) { - const url = "carrier_accounts"; + const url = 'carrier_accounts'; return this._all(url, params); } diff --git a/src/services/carrier_metadata_service/index.ts b/src/services/carrier_metadata_service/index.ts index 5179cfc06..16c6b709c 100644 --- a/src/services/carrier_metadata_service/index.ts +++ b/src/services/carrier_metadata_service/index.ts @@ -1,8 +1,8 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { ICarrierMetadata } from "./CarrierMetadata"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { ICarrierMetadata } from './CarrierMetadata'; -export * from "./CarrierMetadata"; +export * from './CarrierMetadata'; export default (easypostClient: EasyPost) => class CarrierMetadataService extends baseService(easypostClient) { @@ -12,22 +12,18 @@ export default (easypostClient: EasyPost) => * @param type - List of types in string * @returns - List of carrier metadata */ - static async retrieve( - carriers: string[] | null = null, - types: string[] | null = null - ) { - const url = "metadata/carriers"; + static async retrieve(carriers: string[] | null = null, types: string[] | null = null) { + const url = 'metadata/carriers'; const params = { - ...(carriers && - carriers.length > 0 && { carriers: carriers.join(",") }), - ...(types && types.length > 0 && { types: types.join(",") }), + ...(carriers && carriers.length > 0 && { carriers: carriers.join(',') }), + ...(types && types.length > 0 && { types: types.join(',') }), }; try { const response = await easypostClient._get(url, params); return this._convertToEasyPostObject( response.body.carriers || [], - params + params, ); } catch (e) { return Promise.reject(e); diff --git a/src/services/carrier_type_service/CarrierType.ts b/src/services/carrier_type_service/CarrierType.ts index fa8156eee..a2480d47e 100644 --- a/src/services/carrier_type_service/CarrierType.ts +++ b/src/services/carrier_type_service/CarrierType.ts @@ -1,5 +1,5 @@ -import { IBaseObject } from "../../utils/types"; -import { ICarrierTypeFields } from "./CarrierTypeFields"; +import { IBaseObject } from '../../utils/types'; +import { ICarrierTypeFields } from './CarrierTypeFields'; /** * The CarrierType object provides an export declare interface for determining the valid fields of a CarrierAccount. @@ -16,7 +16,7 @@ import { ICarrierTypeFields } from "./CarrierTypeFields"; * * @see https://www.easypost.com/docs/api/node#carrier-type-object */ -export type ICarrierType = IBaseObject<"CarrierType"> & { +export type ICarrierType = IBaseObject<'CarrierType'> & { /** * Specifies the CarrierAccount type. */ diff --git a/src/services/carrier_type_service/CarrierTypeCredentials.ts b/src/services/carrier_type_service/CarrierTypeCredentials.ts index 2e8725d34..4afd06419 100644 --- a/src/services/carrier_type_service/CarrierTypeCredentials.ts +++ b/src/services/carrier_type_service/CarrierTypeCredentials.ts @@ -10,7 +10,7 @@ export type ICarrierTypeCredentials = { /** * There are five possible values, which encode the security need and storage type for each attribute: "visible", "checkbox", "fake", "password", and "masked" */ - visibility: "visible" | "checkbox" | "fake" | "password" | "masked"; + visibility: 'visible' | 'checkbox' | 'fake' | 'password' | 'masked'; /** * Most attributes have generic names, so for clarity a "label" value is provided for clearer representation when rendering forms diff --git a/src/services/carrier_type_service/CarrierTypeFields.ts b/src/services/carrier_type_service/CarrierTypeFields.ts index 386047506..7a2197ec7 100644 --- a/src/services/carrier_type_service/CarrierTypeFields.ts +++ b/src/services/carrier_type_service/CarrierTypeFields.ts @@ -1,4 +1,4 @@ -import { ICarrierTypeCredentials } from "./CarrierTypeCredentials"; +import { ICarrierTypeCredentials } from './CarrierTypeCredentials'; /** * @see https://www.easypost.com/docs/api/node#carrier-type-fields-object diff --git a/src/services/carrier_type_service/index.ts b/src/services/carrier_type_service/index.ts index 5343c55de..e24efdaba 100644 --- a/src/services/carrier_type_service/index.ts +++ b/src/services/carrier_type_service/index.ts @@ -1,10 +1,10 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { ICarrierType } from "./CarrierType"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { ICarrierType } from './CarrierType'; -export * from "./CarrierType"; -export * from "./CarrierTypeCredentials"; -export * from "./CarrierTypeFields"; +export * from './CarrierType'; +export * from './CarrierTypeCredentials'; +export * from './CarrierTypeFields'; export default (easypostClient: EasyPost) => /** @@ -19,15 +19,12 @@ export default (easypostClient: EasyPost) => * @returns - A list of {@link CarrierType carrier types}. */ static async all(params = {}) { - const url = "carrier_types"; + const url = 'carrier_types'; try { const response = await easypostClient._get(url, params); - return this._convertToEasyPostObject( - response.body, - params - ); + return this._convertToEasyPostObject(response.body, params); } catch (e) { return Promise.reject(e); } diff --git a/src/services/customs_info_service/CustomsInfo.ts b/src/services/customs_info_service/CustomsInfo.ts index 2ea4fffde..72ef04c7c 100644 --- a/src/services/customs_info_service/CustomsInfo.ts +++ b/src/services/customs_info_service/CustomsInfo.ts @@ -1,5 +1,5 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; -import { ICustomsItem } from "../customs_item_service"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { ICustomsItem } from '../customs_item_service'; /** * CustomsInfo objects contain CustomsItem objects and all necessary information for the generation of customs forms required for international shipping. @@ -8,7 +8,7 @@ import { ICustomsItem } from "../customs_item_service"; * * @see https://www.easypost.com/docs/api/node#customs-info-object */ -export type ICustomsInfo = IObjectWithId<"CustomsInfo"> & +export type ICustomsInfo = IObjectWithId<'CustomsInfo'> & IDatedObject & { /** * "EEL" or "PFC" @@ -41,17 +41,12 @@ export type ICustomsInfo = IObjectWithId<"CustomsInfo"> & /** * "abandon" or "return", defaults to "return" */ - non_delivery_option?: "abandon" | "return" | null; + non_delivery_option?: 'abandon' | 'return' | null; /** * "none", "other", "quarantine", or "sanitary_phytosanitary_inspection" */ - restriction_type?: - | "none" - | "other" - | "quarantine" - | "sanitary_phytosanitary_inspection" - | null; + restriction_type?: 'none' | 'other' | 'quarantine' | 'sanitary_phytosanitary_inspection' | null; /** * Required if restriction_type is not "none" diff --git a/src/services/customs_info_service/CustomsInfoCreateParameters.ts b/src/services/customs_info_service/CustomsInfoCreateParameters.ts index 9fb83e1d7..5ad3a4682 100644 --- a/src/services/customs_info_service/CustomsInfoCreateParameters.ts +++ b/src/services/customs_info_service/CustomsInfoCreateParameters.ts @@ -1,7 +1,4 @@ -import { ParametersToOmitOnCreate } from "../../utils/types"; -import { ICustomsInfo } from "./CustomsInfo"; +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { ICustomsInfo } from './CustomsInfo'; -export type ICustomsInfoCreateParameters = Omit< - ICustomsInfo, - ParametersToOmitOnCreate ->; +export type ICustomsInfoCreateParameters = Omit; diff --git a/src/services/customs_info_service/index.ts b/src/services/customs_info_service/index.ts index dae448388..94e4a34a7 100644 --- a/src/services/customs_info_service/index.ts +++ b/src/services/customs_info_service/index.ts @@ -1,10 +1,10 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { ICustomsInfo } from "./CustomsInfo"; -import { ICustomsInfoCreateParameters } from "./CustomsInfoCreateParameters"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { ICustomsInfo } from './CustomsInfo'; +import { ICustomsInfoCreateParameters } from './CustomsInfoCreateParameters'; -export * from "./CustomsInfo"; -export * from "./CustomsInfoCreateParameters"; +export * from './CustomsInfo'; +export * from './CustomsInfoCreateParameters'; export default (easypostClient: EasyPost) => /** @@ -19,7 +19,7 @@ export default (easypostClient: EasyPost) => * @returns - The created customs info. */ static async create(params: ICustomsInfoCreateParameters) { - const url = "customs_infos"; + const url = 'customs_infos'; const wrappedParams = { customs_info: params, diff --git a/src/services/customs_item_service/CustomsItem.ts b/src/services/customs_item_service/CustomsItem.ts index 8dd543fb0..738b5cffb 100644 --- a/src/services/customs_item_service/CustomsItem.ts +++ b/src/services/customs_item_service/CustomsItem.ts @@ -1,12 +1,12 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; -import { ICustomsItemCreateParameters } from "./CustomsItemCreateParameters"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { ICustomsItemCreateParameters } from './CustomsItemCreateParameters'; /** * A CustomsItem object describes goods for international shipment and should be created then included in a CustomsInfo object. * * @see https://www.easypost.com/docs/api/node#customs-item-object */ -export type ICustomsItem = IObjectWithId<"CustomsItem"> & +export type ICustomsItem = IObjectWithId<'CustomsItem'> & IDatedObject & { /** * Required, description of item being shipped diff --git a/src/services/customs_item_service/CustomsItemCreateParameters.ts b/src/services/customs_item_service/CustomsItemCreateParameters.ts index 074bf1087..39d85817a 100644 --- a/src/services/customs_item_service/CustomsItemCreateParameters.ts +++ b/src/services/customs_item_service/CustomsItemCreateParameters.ts @@ -1,7 +1,4 @@ -import { ParametersToOmitOnCreate } from "../../utils/types"; -import { ICustomsItem } from "./CustomsItem"; +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { ICustomsItem } from './CustomsItem'; -export type ICustomsItemCreateParameters = Omit< - ICustomsItem, - ParametersToOmitOnCreate ->; +export type ICustomsItemCreateParameters = Omit; diff --git a/src/services/customs_item_service/index.ts b/src/services/customs_item_service/index.ts index 3dbdd4019..370efa079 100644 --- a/src/services/customs_item_service/index.ts +++ b/src/services/customs_item_service/index.ts @@ -1,10 +1,10 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { ICustomsItem } from "./CustomsItem"; -import { ICustomsItemCreateParameters } from "./CustomsItemCreateParameters"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { ICustomsItem } from './CustomsItem'; +import { ICustomsItemCreateParameters } from './CustomsItemCreateParameters'; -export * from "./CustomsItem"; -export * from "./CustomsItemCreateParameters"; +export * from './CustomsItem'; +export * from './CustomsItemCreateParameters'; export default (easypostClient: EasyPost) => /** @@ -19,7 +19,7 @@ export default (easypostClient: EasyPost) => * @returns - The created customs item. */ static async create(params: ICustomsItemCreateParameters) { - const url = "customs_items"; + const url = 'customs_items'; const wrappedParams = { customs_item: params, diff --git a/src/services/end_shipper_service/EndShipper.ts b/src/services/end_shipper_service/EndShipper.ts index 44799ff30..eee5485a6 100644 --- a/src/services/end_shipper_service/EndShipper.ts +++ b/src/services/end_shipper_service/EndShipper.ts @@ -1,4 +1,4 @@ -import { IObjectWithId } from "../../utils/types"; +import { IObjectWithId } from '../../utils/types'; /** * The EndShipper API is for platforms purchasing postage on behalf of their users, the EndShipper. @@ -9,7 +9,7 @@ import { IObjectWithId } from "../../utils/types"; * * @see https://www.easypost.com/docs/api/node#endshipper */ -export type IEndshipper = IObjectWithId<"EndShipper"> & { +export type IEndshipper = IObjectWithId<'EndShipper'> & { /** * Name of responsible person (conditionally required) */ diff --git a/src/services/end_shipper_service/EndShipperCreateParameters.ts b/src/services/end_shipper_service/EndShipperCreateParameters.ts index 0c4c3116a..854ed3c64 100644 --- a/src/services/end_shipper_service/EndShipperCreateParameters.ts +++ b/src/services/end_shipper_service/EndShipperCreateParameters.ts @@ -1,7 +1,4 @@ -import { ParametersToOmitOnCreate } from "../../utils/types"; -import { IEndshipper } from "./EndShipper"; +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IEndshipper } from './EndShipper'; -export type IEndShipperCreateParameters = Omit< - IEndshipper, - ParametersToOmitOnCreate ->; +export type IEndShipperCreateParameters = Omit; diff --git a/src/services/end_shipper_service/EndShipperListParameters.ts b/src/services/end_shipper_service/EndShipperListParameters.ts index 7422bc550..6b5c16954 100644 --- a/src/services/end_shipper_service/EndShipperListParameters.ts +++ b/src/services/end_shipper_service/EndShipperListParameters.ts @@ -1,4 +1,4 @@ -import { IAllMethodParameters } from "../../utils/types"; +import { IAllMethodParameters } from '../../utils/types'; /** * @see https://www.easypost.com/docs/api#endshipper diff --git a/src/services/end_shipper_service/index.ts b/src/services/end_shipper_service/index.ts index 5e82ae875..3b46fc629 100644 --- a/src/services/end_shipper_service/index.ts +++ b/src/services/end_shipper_service/index.ts @@ -1,12 +1,12 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IEndshipper } from "./EndShipper"; -import { IEndShipperCreateParameters } from "./EndShipperCreateParameters"; -import { IEndShipperListParameters } from "./EndShipperListParameters"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IEndshipper } from './EndShipper'; +import { IEndShipperCreateParameters } from './EndShipperCreateParameters'; +import { IEndShipperListParameters } from './EndShipperListParameters'; -export * from "./EndShipper"; -export * from "./EndShipperCreateParameters"; -export * from "./EndShipperListParameters"; +export * from './EndShipper'; +export * from './EndShipperCreateParameters'; +export * from './EndShipperListParameters'; export default (easypostClient: EasyPost) => /** @@ -21,7 +21,7 @@ export default (easypostClient: EasyPost) => * @returns - The created end shipper. */ static async create(params: IEndShipperCreateParameters) { - const url = "end_shippers"; + const url = 'end_shippers'; const wrappedParams = { address: params }; return this._create(url, wrappedParams); @@ -34,20 +34,14 @@ export default (easypostClient: EasyPost) => * @param params - Parameters for the end shipper to be updated. * @returns - The updated end shipper. */ - static async update( - id: string, - params: Partial - ) { + static async update(id: string, params: Partial) { const url = `end_shippers/${id}`; const wrappedParams = { address: params }; try { const response = await easypostClient._put(url, wrappedParams); - return this._convertToEasyPostObject( - response.body, - wrappedParams - ); + return this._convertToEasyPostObject(response.body, wrappedParams); } catch (e) { return Promise.reject(e); } @@ -72,7 +66,7 @@ export default (easypostClient: EasyPost) => * @returns - An object containing a list of {@link EndShipper end shippers} and pagination information. */ static async all(params: IEndShipperListParameters = {}) { - const url = "end_shippers"; + const url = 'end_shippers'; return this._all(url, params); } diff --git a/src/services/event_service/Event.ts b/src/services/event_service/Event.ts index 415983e2e..445fb3e9a 100644 --- a/src/services/event_service/Event.ts +++ b/src/services/event_service/Event.ts @@ -1,4 +1,4 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; /** * Webhook Events are triggered by changes in objects you've created via the API. @@ -8,7 +8,7 @@ import { IDatedObject, IObjectWithId } from "../../utils/types"; * * @see https://www.easypost.com/docs/api/node#events */ -export type IEvent = IObjectWithId<"Event"> & +export type IEvent = IObjectWithId<'Event'> & IDatedObject & { /** * Result type and event name, see the "Possible Event Types" section for more information @@ -31,7 +31,7 @@ export type IEvent = IObjectWithId<"Event"> & * * @deprecated */ - status: "completed" | "failed" | "in_queue" | "retrying" | "pending"; + status: 'completed' | 'failed' | 'in_queue' | 'retrying' | 'pending'; /** * Webhook URLs that have not yet been successfully notified as of the time this webhook event was sent. diff --git a/src/services/event_service/EventListParameters.ts b/src/services/event_service/EventListParameters.ts index 9197b2b6e..835778a7a 100644 --- a/src/services/event_service/EventListParameters.ts +++ b/src/services/event_service/EventListParameters.ts @@ -1,4 +1,4 @@ -import { IAllMethodParameters } from "../../utils/types"; +import { IAllMethodParameters } from '../../utils/types'; /** * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-events diff --git a/src/services/event_service/Payload/Payload.ts b/src/services/event_service/Payload/Payload.ts index 90efefd19..41f0d69d9 100644 --- a/src/services/event_service/Payload/Payload.ts +++ b/src/services/event_service/Payload/Payload.ts @@ -1,4 +1,4 @@ -import { IDatedObject, IObjectWithId } from "../../../utils/types"; +import { IDatedObject, IObjectWithId } from '../../../utils/types'; /** * A Payload represents an attempt by EasyPost to send an Event to a Webhook. @@ -6,7 +6,7 @@ import { IDatedObject, IObjectWithId } from "../../../utils/types"; * an Event would have multiple payloads, one for each attempt to deliver the Event to the Webhook. * Payload can be useful for debugging webhook delivery and when initially setting up EasyPost webhooks. */ -export type IPayload = IObjectWithId<"Payload"> & +export type IPayload = IObjectWithId<'Payload'> & IDatedObject & { /** * The body of the Payload response diff --git a/src/services/event_service/Payload/PayloadListParameters.ts b/src/services/event_service/Payload/PayloadListParameters.ts index 7e9b86192..370ad41f8 100644 --- a/src/services/event_service/Payload/PayloadListParameters.ts +++ b/src/services/event_service/Payload/PayloadListParameters.ts @@ -1,4 +1,4 @@ -import { IAllMethodParameters } from "../../../utils/types"; +import { IAllMethodParameters } from '../../../utils/types'; /** * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads diff --git a/src/services/event_service/Payload/index.ts b/src/services/event_service/Payload/index.ts index 25d8d8816..b1fd98702 100644 --- a/src/services/event_service/Payload/index.ts +++ b/src/services/event_service/Payload/index.ts @@ -1 +1 @@ -export * from "./Payload"; +export * from './Payload'; diff --git a/src/services/event_service/index.ts b/src/services/event_service/index.ts index 9aeef41c1..ab150f3af 100644 --- a/src/services/event_service/index.ts +++ b/src/services/event_service/index.ts @@ -1,12 +1,12 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IEvent } from "./Event"; -import { IEventListParameters } from "./EventListParameters"; -import { IPayload } from "./Payload"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IEvent } from './Event'; +import { IEventListParameters } from './EventListParameters'; +import { IPayload } from './Payload'; -export * from "./Event"; -export * from "./EventListParameters"; -export * from "./Payload"; +export * from './Event'; +export * from './EventListParameters'; +export * from './Payload'; export default (easypostClient: EasyPost) => /** @@ -26,9 +26,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._get(url); - return this._convertToEasyPostObject( - response.body.payloads - ); + return this._convertToEasyPostObject(response.body.payloads); } catch (e) { return Promise.reject(e); } @@ -60,7 +58,7 @@ export default (easypostClient: EasyPost) => * @returns - An object containing the list of {@link Event events} and pagination information. */ static async all(params: IEventListParameters = {}) { - const url = "events"; + const url = 'events'; return this._all(url, params); } @@ -72,13 +70,8 @@ export default (easypostClient: EasyPost) => * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ static async getNextPage(events: any, pageSize: number | null = null) { - const url = "events"; - return this._getNextPage<{ events: IEvent[] }>( - url, - "events", - events, - pageSize - ); + const url = 'events'; + return this._getNextPage<{ events: IEvent[] }>(url, 'events', events, pageSize); } /** diff --git a/src/services/index.ts b/src/services/index.ts index 1d54b3ad2..229b1e3fa 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1,27 +1,27 @@ -export * from "./address_service"; -export * from "./api_key_service"; -export * from "./batch_service"; -export * from "./beta_rate_service"; -export * from "./beta_referral_customer_service"; -export * from "./billing_service"; -export * from "./carrier_account_service"; -export * from "./carrier_metadata_service"; -export * from "./carrier_type_service"; -export * from "./customs_info_service"; -export * from "./customs_item_service"; -export * from "./end_shipper_service"; -export * from "./event_service"; -export * from "./insurance_service"; -export * from "./order_service"; -export * from "./parcel_service"; -export * from "./pickup_service"; -export * from "./rate_service"; -export * from "./referral_customer_service"; -export * from "./refund_service"; -export * from "./report_service"; -export * from "./scan_form_service"; -export * from "./shipment_service"; -export * from "./tracker_service"; -export * from "./user_service"; -export * from "./webhook_service"; -export * from "./base_service"; +export * from './address_service'; +export * from './api_key_service'; +export * from './batch_service'; +export * from './beta_rate_service'; +export * from './beta_referral_customer_service'; +export * from './billing_service'; +export * from './carrier_account_service'; +export * from './carrier_metadata_service'; +export * from './carrier_type_service'; +export * from './customs_info_service'; +export * from './customs_item_service'; +export * from './end_shipper_service'; +export * from './event_service'; +export * from './insurance_service'; +export * from './order_service'; +export * from './parcel_service'; +export * from './pickup_service'; +export * from './rate_service'; +export * from './referral_customer_service'; +export * from './refund_service'; +export * from './report_service'; +export * from './scan_form_service'; +export * from './shipment_service'; +export * from './tracker_service'; +export * from './user_service'; +export * from './webhook_service'; +export * from './base_service'; diff --git a/src/services/insurance_service/Fee.ts b/src/services/insurance_service/Fee.ts index 9a66644ec..e9204eaa8 100644 --- a/src/services/insurance_service/Fee.ts +++ b/src/services/insurance_service/Fee.ts @@ -1,5 +1,5 @@ -import { IBaseObject } from "../../utils/types"; -import { TFeeType } from "./FeeType"; +import { IBaseObject } from '../../utils/types'; +import { TFeeType } from './FeeType'; /** * Fee objects are used to represent the breakdown of charges made when purchasing an item on EasyPost. @@ -12,7 +12,7 @@ import { TFeeType } from "./FeeType"; * * @see https://www.easypost.com/docs/api/node#fee-object */ -export type IFee = IBaseObject<"Fee"> & { +export type IFee = IBaseObject<'Fee'> & { /** * The name of the category of fee. Possible types are "LabelFee", "PostageFee", "InsuranceFee", and "TrackerFee" */ diff --git a/src/services/insurance_service/FeeType.ts b/src/services/insurance_service/FeeType.ts index 0a4f1b822..980a39a05 100644 --- a/src/services/insurance_service/FeeType.ts +++ b/src/services/insurance_service/FeeType.ts @@ -1,5 +1 @@ -export type TFeeType = - | "InsuranceFee" - | "LabelFee" - | "PostageFee" - | "TrackerFee"; +export type TFeeType = 'InsuranceFee' | 'LabelFee' | 'PostageFee' | 'TrackerFee'; diff --git a/src/services/insurance_service/Insurance.ts b/src/services/insurance_service/Insurance.ts index 42a75b266..0d3962958 100644 --- a/src/services/insurance_service/Insurance.ts +++ b/src/services/insurance_service/Insurance.ts @@ -1,8 +1,8 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; -import { IAddress } from "../address_service"; -import { ITracker } from "../tracker_service"; -import { IFee } from "./Fee"; -import { TInsuranceStatus } from "./InsuranceStatus"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; +import { ITracker } from '../tracker_service'; +import { IFee } from './Fee'; +import { TInsuranceStatus } from './InsuranceStatus'; /** * An Insurance object represents insurance for packages purchased both via the EasyPost API as well as shipments purchased through third parties and later registered with EasyPost. @@ -21,7 +21,7 @@ import { TInsuranceStatus } from "./InsuranceStatus"; * * @see https://www.easypost.com/docs/api/node#insurance-object */ -export type IInsurance = IObjectWithId<"Insurance"> & +export type IInsurance = IObjectWithId<'Insurance'> & IDatedObject & { /** * The unique reference for this Insurance, if any diff --git a/src/services/insurance_service/InsuranceCreateParameters.ts b/src/services/insurance_service/InsuranceCreateParameters.ts index 932ecb25e..9bc6d6438 100644 --- a/src/services/insurance_service/InsuranceCreateParameters.ts +++ b/src/services/insurance_service/InsuranceCreateParameters.ts @@ -1,4 +1,4 @@ -import { IAddress } from "../address_service"; +import { IAddress } from '../address_service'; export type IInsuranceCreateParameters = { reference?: string | null; diff --git a/src/services/insurance_service/InsuranceStatus.ts b/src/services/insurance_service/InsuranceStatus.ts index 7b816e18d..139db60a2 100644 --- a/src/services/insurance_service/InsuranceStatus.ts +++ b/src/services/insurance_service/InsuranceStatus.ts @@ -1,6 +1 @@ -export type TInsuranceStatus = - | "new" - | "pending" - | "purchased" - | "failed" - | "cancelled"; +export type TInsuranceStatus = 'new' | 'pending' | 'purchased' | 'failed' | 'cancelled'; diff --git a/src/services/insurance_service/index.ts b/src/services/insurance_service/index.ts index 3b7618771..9e32e40ad 100644 --- a/src/services/insurance_service/index.ts +++ b/src/services/insurance_service/index.ts @@ -1,14 +1,14 @@ -import EasyPost from "../.."; -import { IAllMethodParameters } from "../../utils/types"; -import baseService from "../base_service"; -import { IInsurance } from "./Insurance"; -import { IInsuranceCreateParameters } from "./InsuranceCreateParameters"; +import EasyPost from '../..'; +import { IAllMethodParameters } from '../../utils/types'; +import baseService from '../base_service'; +import { IInsurance } from './Insurance'; +import { IInsuranceCreateParameters } from './InsuranceCreateParameters'; -export * from "./Fee"; -export * from "./FeeType"; -export * from "./Insurance"; -export * from "./InsuranceCreateParameters"; -export * from "./InsuranceStatus"; +export * from './Fee'; +export * from './FeeType'; +export * from './Insurance'; +export * from './InsuranceCreateParameters'; +export * from './InsuranceStatus'; export default (easypostClient: EasyPost) => /** @@ -23,7 +23,7 @@ export default (easypostClient: EasyPost) => * @returns - The created insurance. */ static async create(params: IInsuranceCreateParameters) { - const url = "insurances"; + const url = 'insurances'; const wrappedParams = { insurance: params, @@ -39,7 +39,7 @@ export default (easypostClient: EasyPost) => * @returns - An object containing the list of {@link Insurance insurance} records and pagination information. */ static async all(params: IAllMethodParameters = {}) { - const url = "insurances"; + const url = 'insurances'; return this._all(url, params); } @@ -51,12 +51,12 @@ export default (easypostClient: EasyPost) => * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ static async getNextPage(insurances: any, pageSize: number | null = null) { - const url = "insurances"; + const url = 'insurances'; return this._getNextPage<{ insurances: IInsurance[] }>( url, - "insurances", + 'insurances', insurances, - pageSize + pageSize, ); } diff --git a/src/services/order_service/Order.ts b/src/services/order_service/Order.ts index bafeb4861..8efbadaa3 100644 --- a/src/services/order_service/Order.ts +++ b/src/services/order_service/Order.ts @@ -1,7 +1,7 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; -import { IAddress } from "../address_service"; -import { IRate } from "../rate_service"; -import { IMessage, IShipment } from "../shipment_service"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; +import { IRate } from '../rate_service'; +import { IMessage, IShipment } from '../shipment_service'; /** * The Order object represents a collection of packages and can be used for Multi-Piece Shipments. @@ -13,7 +13,7 @@ import { IMessage, IShipment } from "../shipment_service"; * * @see https://www.easypost.com/docs/api/node#order-object */ -export type IOrder = IObjectWithId<"Order"> & +export type IOrder = IObjectWithId<'Order'> & IDatedObject & { /** * An optional field that may be used in place of id in other API endpoints diff --git a/src/services/order_service/OrderCreateParameters.ts b/src/services/order_service/OrderCreateParameters.ts index e5f3efcfd..f79ab28dc 100644 --- a/src/services/order_service/OrderCreateParameters.ts +++ b/src/services/order_service/OrderCreateParameters.ts @@ -1,5 +1,5 @@ -import { IAddress } from "../address_service"; -import { IShipment } from "../shipment_service"; +import { IAddress } from '../address_service'; +import { IShipment } from '../shipment_service'; export type IOrderCreateParameters = { reference?: string | null; diff --git a/src/services/order_service/index.ts b/src/services/order_service/index.ts index 12c879515..ab2a4a067 100644 --- a/src/services/order_service/index.ts +++ b/src/services/order_service/index.ts @@ -1,11 +1,11 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IRate } from "../rate_service"; -import { IOrder } from "./Order"; -import { IOrderCreateParameters } from "./OrderCreateParameters"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IRate } from '../rate_service'; +import { IOrder } from './Order'; +import { IOrderCreateParameters } from './OrderCreateParameters'; -export * from "./Order"; -export * from "./OrderCreateParameters"; +export * from './Order'; +export * from './OrderCreateParameters'; export default (easypostClient: EasyPost) => /** @@ -20,7 +20,7 @@ export default (easypostClient: EasyPost) => * @returns - The created order. */ static async create(params: IOrderCreateParameters) { - const url = "orders"; + const url = 'orders'; const wrappedParams = { order: params, @@ -43,10 +43,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url, wrappedParams); - return this._convertToEasyPostObject( - response.body, - wrappedParams - ); + return this._convertToEasyPostObject(response.body, wrappedParams); } catch (e) { return Promise.reject(e); } diff --git a/src/services/parcel_service/Parcel.ts b/src/services/parcel_service/Parcel.ts index 177ff5b44..360c10a19 100644 --- a/src/services/parcel_service/Parcel.ts +++ b/src/services/parcel_service/Parcel.ts @@ -1,4 +1,4 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; /** * Parcel objects represent the physical container being shipped. @@ -10,7 +10,7 @@ import { IDatedObject, IObjectWithId } from "../../utils/types"; * * @see https://www.easypost.com/docs/api/node#parcel-object */ -export type IParcel = IObjectWithId<"Parcel"> & +export type IParcel = IObjectWithId<'Parcel'> & IDatedObject & { /** * Required if width and/or height are present diff --git a/src/services/parcel_service/ParcelCreateParameters.ts b/src/services/parcel_service/ParcelCreateParameters.ts index 838842e75..eef639b35 100644 --- a/src/services/parcel_service/ParcelCreateParameters.ts +++ b/src/services/parcel_service/ParcelCreateParameters.ts @@ -1,10 +1,7 @@ -import { ParametersToOmitOnCreate } from "../../utils/types"; -import { IParcel } from "./Parcel"; +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IParcel } from './Parcel'; -export type IParcelCreateParameters = Omit< - IParcel, - ParametersToOmitOnCreate -> & { +export type IParcelCreateParameters = Omit & { /** * Required if width and/or height are present * float (inches) diff --git a/src/services/parcel_service/index.ts b/src/services/parcel_service/index.ts index 2114af0ad..73d3b4644 100644 --- a/src/services/parcel_service/index.ts +++ b/src/services/parcel_service/index.ts @@ -1,10 +1,10 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IParcel } from "./Parcel"; -import { IParcelCreateParameters } from "./ParcelCreateParameters"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IParcel } from './Parcel'; +import { IParcelCreateParameters } from './ParcelCreateParameters'; -export * from "./Parcel"; -export * from "./ParcelCreateParameters"; +export * from './Parcel'; +export * from './ParcelCreateParameters'; export default (easypostClient: EasyPost) => /** @@ -19,7 +19,7 @@ export default (easypostClient: EasyPost) => * @returns - The created parcel. */ static async create(params: IParcelCreateParameters) { - const url = "parcels"; + const url = 'parcels'; const wrappedParams = { parcel: params, diff --git a/src/services/pickup_service/Pickup.ts b/src/services/pickup_service/Pickup.ts index 8f40336cd..16da1240f 100644 --- a/src/services/pickup_service/Pickup.ts +++ b/src/services/pickup_service/Pickup.ts @@ -1,8 +1,8 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; -import { IAddress } from "../address_service"; -import { ICarrierAccount } from "../carrier_account_service"; -import { IMessage, IShipment } from "../shipment_service"; -import { IPickupRate } from "./PickupRate"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; +import { ICarrierAccount } from '../carrier_account_service'; +import { IMessage, IShipment } from '../shipment_service'; +import { IPickupRate } from './PickupRate'; /** * The Pickup object allows you to schedule a pickup from your carrier from your customer's residence or place of business. @@ -24,7 +24,7 @@ import { IPickupRate } from "./PickupRate"; * * @see https://www.easypost.com/docs/api/node#pickup-object */ -export type IPickup = IObjectWithId<"Pickup"> & +export type IPickup = IObjectWithId<'Pickup'> & IDatedObject & { /** * An optional field that may be used in place of ID in some API endpoints @@ -34,7 +34,7 @@ export type IPickup = IObjectWithId<"Pickup"> & /** * One of: "unknown", "scheduled", or "canceled" */ - status: "unknown" | "scheduled" | "canceled"; + status: 'unknown' | 'scheduled' | 'canceled'; /** * The earliest time at which the package is available to pick up diff --git a/src/services/pickup_service/PickupCreateParameters.ts b/src/services/pickup_service/PickupCreateParameters.ts index aaf4911d2..89683e1e1 100644 --- a/src/services/pickup_service/PickupCreateParameters.ts +++ b/src/services/pickup_service/PickupCreateParameters.ts @@ -1,8 +1,8 @@ -import { IAddress } from "../address_service"; -import { IBatch } from "../batch_service"; -import { ICarrierAccount } from "../carrier_account_service"; -import { IShipment } from "../shipment_service"; -import { IPickupRate } from "./PickupRate"; +import { IAddress } from '../address_service'; +import { IBatch } from '../batch_service'; +import { ICarrierAccount } from '../carrier_account_service'; +import { IShipment } from '../shipment_service'; +import { IPickupRate } from './PickupRate'; type BasePickupCreateParameters = { address: IAddress | string; @@ -25,6 +25,4 @@ type BatchPickupCreateParameters = BasePickupCreateParameters & { batch?: IBatch | { id: string } | string | null; }; -export type IPickupCreateParameters = - | ShipmentPickupCreateParameters - | BatchPickupCreateParameters; +export type IPickupCreateParameters = ShipmentPickupCreateParameters | BatchPickupCreateParameters; diff --git a/src/services/pickup_service/PickupListParameters.ts b/src/services/pickup_service/PickupListParameters.ts index 1a37b76fd..315c0b4cc 100644 --- a/src/services/pickup_service/PickupListParameters.ts +++ b/src/services/pickup_service/PickupListParameters.ts @@ -1,4 +1,4 @@ -import { IAllMethodParameters } from "../../utils/types"; +import { IAllMethodParameters } from '../../utils/types'; /** * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups diff --git a/src/services/pickup_service/PickupRate.ts b/src/services/pickup_service/PickupRate.ts index f05698b95..a44bdba33 100644 --- a/src/services/pickup_service/PickupRate.ts +++ b/src/services/pickup_service/PickupRate.ts @@ -1,9 +1,9 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; /** * @see https://www.easypost.com/docs/api/node#pickup-rate-object */ -export type IPickupRate = IObjectWithId<"PickupRate"> & +export type IPickupRate = IObjectWithId<'PickupRate'> & IDatedObject & { /** * service name diff --git a/src/services/pickup_service/index.ts b/src/services/pickup_service/index.ts index 98dc1a601..813e6efd8 100644 --- a/src/services/pickup_service/index.ts +++ b/src/services/pickup_service/index.ts @@ -1,8 +1,8 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IPickup } from "./Pickup"; -import { IPickupCreateParameters } from "./PickupCreateParameters"; -import { IPickupListParameters } from "./PickupListParameters"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IPickup } from './Pickup'; +import { IPickupCreateParameters } from './PickupCreateParameters'; +import { IPickupListParameters } from './PickupListParameters'; export default (easypostClient: EasyPost) => /** @@ -17,7 +17,7 @@ export default (easypostClient: EasyPost) => * @returns - The created pickup. */ static async create(params: IPickupCreateParameters) { - const url = "pickups"; + const url = 'pickups'; const wrappedParams = { pickup: params, @@ -40,10 +40,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url, wrappedParams); - return this._convertToEasyPostObject( - response.body, - wrappedParams - ); + return this._convertToEasyPostObject(response.body, wrappedParams); } catch (e) { return Promise.reject(e); } @@ -73,7 +70,7 @@ export default (easypostClient: EasyPost) => * @returns - An object containing a list of {@link Pickup pickups} and pagination information. */ static async all(params: IPickupListParameters = {}) { - const url = "pickups"; + const url = 'pickups'; return this._all(url, params); } @@ -85,13 +82,8 @@ export default (easypostClient: EasyPost) => * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ static async getNextPage(pickups: any, pageSize: number | null = null) { - const url = "pickups"; - return this._getNextPage<{ pickups: IPickup[] }>( - url, - "pickups", - pickups, - pageSize - ); + const url = 'pickups'; + return this._getNextPage<{ pickups: IPickup[] }>(url, 'pickups', pickups, pageSize); } /** diff --git a/src/services/rate_service/Rate.ts b/src/services/rate_service/Rate.ts index 1675fae97..1660c3fe7 100644 --- a/src/services/rate_service/Rate.ts +++ b/src/services/rate_service/Rate.ts @@ -1,11 +1,11 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; /** * The Rate class represents a summary of the price and details of a delivery service quote. * * @see https://www.easypost.com/docs/api/node#rates */ -export type IRate = IObjectWithId<"Rate"> & +export type IRate = IObjectWithId<'Rate'> & IDatedObject & { /** * The service level of the rate. diff --git a/src/services/rate_service/index.ts b/src/services/rate_service/index.ts index 852764e49..ee90f3a68 100644 --- a/src/services/rate_service/index.ts +++ b/src/services/rate_service/index.ts @@ -1,8 +1,8 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IRate } from "./Rate"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IRate } from './Rate'; -export * from "./Rate"; +export * from './Rate'; export default (easypostClient: EasyPost) => /** diff --git a/src/services/referral_customer_service/Referral.ts b/src/services/referral_customer_service/Referral.ts index fba39db93..1e8e6eaee 100644 --- a/src/services/referral_customer_service/Referral.ts +++ b/src/services/referral_customer_service/Referral.ts @@ -1,4 +1,4 @@ -import { IUser } from "../user_service"; +import { IUser } from '../user_service'; /** * A Referral represents a sub-user under a Partner or white-label account. diff --git a/src/services/referral_customer_service/ReferralCreateParameters.ts b/src/services/referral_customer_service/ReferralCreateParameters.ts index ec28e1f5c..497cc4882 100644 --- a/src/services/referral_customer_service/ReferralCreateParameters.ts +++ b/src/services/referral_customer_service/ReferralCreateParameters.ts @@ -1,7 +1,4 @@ -import { ParametersToOmitOnCreate } from "../../utils/types"; -import { IReferral } from "./Referral"; +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IReferral } from './Referral'; -export type IReferralCreateParameters = Omit< - IReferral, - ParametersToOmitOnCreate ->; +export type IReferralCreateParameters = Omit; diff --git a/src/services/referral_customer_service/ReferralListParameters.ts b/src/services/referral_customer_service/ReferralListParameters.ts index dc6f19597..3a91223e2 100644 --- a/src/services/referral_customer_service/ReferralListParameters.ts +++ b/src/services/referral_customer_service/ReferralListParameters.ts @@ -1,4 +1,4 @@ -import { IAllMethodParameters } from "../../utils/types"; +import { IAllMethodParameters } from '../../utils/types'; /** * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers diff --git a/src/services/referral_customer_service/index.ts b/src/services/referral_customer_service/index.ts index 0612c3926..9daadd9e6 100644 --- a/src/services/referral_customer_service/index.ts +++ b/src/services/referral_customer_service/index.ts @@ -1,19 +1,19 @@ -import util from "node:util"; -import superagent from "superagent"; - -import Constants from "../../constants"; -import EasyPostClient from "../../easypost"; -import ExternalApiError from "../../errors/api/external_api_error"; -import baseService from "../base_service"; -import EasyPost from "../.."; -import { IReferralCreateParameters } from "./ReferralCreateParameters"; -import { IReferral } from "./Referral"; -import { IReferralListParameters } from "./ReferralListParameters"; -import { IPaymentMethod } from "../billing_service"; - -export * from "./Referral"; -export * from "./ReferralCreateParameters"; -export * from "./ReferralListParameters"; +import util from 'node:util'; +import superagent from 'superagent'; + +import Constants from '../../constants'; +import EasyPostClient from '../../easypost'; +import ExternalApiError from '../../errors/api/external_api_error'; +import baseService from '../base_service'; +import EasyPost from '../..'; +import { IReferralCreateParameters } from './ReferralCreateParameters'; +import { IReferral } from './Referral'; +import { IReferralListParameters } from './ReferralListParameters'; +import { IPaymentMethod } from '../billing_service'; + +export * from './Referral'; +export * from './ReferralCreateParameters'; +export * from './ReferralListParameters'; /** * Get an instance of the EasyPostClient using the referral user's API key. @@ -34,10 +34,8 @@ function _getReferralClient(client: EasyPost, referralApiKey: string) { * @param easypostClient - The EasyPostClient to use. * @returns - The Stripe API key. */ -async function _getEasyPostStripeKey( - easypostClient: EasyPost -): Promise { - const url = "partners/stripe_public_key"; +async function _getEasyPostStripeKey(easypostClient: EasyPost): Promise { + const url = 'partners/stripe_public_key'; const response = await easypostClient._get(url); @@ -59,14 +57,14 @@ async function _sendCardDetailsToStripe( number: string, expirationMonth: string, expirationYear: string, - cvc: string + cvc: string, ): Promise { // Stripe's endpoint requires form-encoded requests const url = `https://api.stripe.com/v1/tokens?card[number]=${number}&card[exp_month]=${expirationMonth}&card[exp_year]=${expirationYear}&card[cvc]=${cvc}`; const request = superagent.post(url).set({ Authorization: `Bearer ${stripeKey}`, - "Content-Type": "application/x-www-form-urlencoded", + 'Content-Type': 'application/x-www-form-urlencoded', }); try { @@ -75,7 +73,7 @@ async function _sendCardDetailsToStripe( return response.body.id; } catch (error) { throw new ExternalApiError({ - message: util.format(Constants.EXTERNAL_API_CALL_FAILED, "Stripe"), + message: util.format(Constants.EXTERNAL_API_CALL_FAILED, 'Stripe'), }); } } @@ -93,10 +91,10 @@ async function _sendCardDetailsToEasyPost( client: EasyPostClient, referralApiKey: string, stripeCreditCardToken: string, - priority: string + priority: string, ): Promise { const _client = _getReferralClient(client, referralApiKey); - const url = "credit_cards"; + const url = 'credit_cards'; const params = { credit_card: { stripe_object_id: stripeCreditCardToken, priority }, }; @@ -119,7 +117,7 @@ export default (easypostClient: EasyPost) => * @returns - The newly created referral customer. */ static async create(params: IReferralCreateParameters) { - const url = "referral_customers"; + const url = 'referral_customers'; const wrappedParams = { user: params, @@ -161,7 +159,7 @@ export default (easypostClient: EasyPost) => expirationMonth: string, expirationYear: string, cvc: string, - priority: "primary" | "secondary" = "primary" + priority: 'primary' | 'secondary' = 'primary', ) { const stripeKey = await _getEasyPostStripeKey(easypostClient); // will throw if there's an error @@ -170,14 +168,14 @@ export default (easypostClient: EasyPost) => number, expirationMonth, expirationYear, - cvc + cvc, ); // will throw if there's an error const paymentMethod = await _sendCardDetailsToEasyPost( easypostClient, referralApiKey, stripeCreditCardId, - priority + priority, ); // will throw if there's an error return paymentMethod; @@ -190,7 +188,7 @@ export default (easypostClient: EasyPost) => * @returns - An object containing a list of {@link User referral customers} and pagination information. */ static async all(params: IReferralListParameters = {}) { - const url = "referral_customers"; + const url = 'referral_customers'; return this._all(url, params); } @@ -201,16 +199,13 @@ export default (easypostClient: EasyPost) => * @param pageSize The number of records to return on each page * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage( - referralCustomers: any, - pageSize: number | null = null - ) { - const url = "referral_customers"; + static async getNextPage(referralCustomers: any, pageSize: number | null = null) { + const url = 'referral_customers'; return this._getNextPage<{ referral_customers: IReferral[] }>( url, - "referral_customers", + 'referral_customers', referralCustomers, - pageSize + pageSize, ); } }; diff --git a/src/services/refund_service/Refund.ts b/src/services/refund_service/Refund.ts index f2c90edea..7c4115cf6 100644 --- a/src/services/refund_service/Refund.ts +++ b/src/services/refund_service/Refund.ts @@ -1,4 +1,4 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; /** * The Refund object represents a refunded shipment, and includes details about the related Shipment and tracking code. @@ -7,7 +7,7 @@ import { IDatedObject, IObjectWithId } from "../../utils/types"; * EasyPost fees will also be refunded. To qualify, a shipment must not have been scanned by the USPS. * UPS and FedEx shipping labels may be refunded within 90 days of creation. */ -export type IRefund = IObjectWithId<"Refund"> & +export type IRefund = IObjectWithId<'Refund'> & IDatedObject & { /** * The tracking code of the related Shipment @@ -22,7 +22,7 @@ export type IRefund = IObjectWithId<"Refund"> & /** * The status of the refund request, reported by the carrier. Possible values are "submitted", "refunded", or "rejected" */ - status: "submitted" | "refunded" | "rejected"; + status: 'submitted' | 'refunded' | 'rejected'; /** * The carrier the refund request was submitted to diff --git a/src/services/refund_service/RefundListParameters.ts b/src/services/refund_service/RefundListParameters.ts index 96e264b34..220ee9fd8 100644 --- a/src/services/refund_service/RefundListParameters.ts +++ b/src/services/refund_service/RefundListParameters.ts @@ -1,4 +1,4 @@ -import { IAllMethodParameters } from "../../utils/types"; +import { IAllMethodParameters } from '../../utils/types'; /** * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds diff --git a/src/services/refund_service/index.ts b/src/services/refund_service/index.ts index 9cc3da710..a1053aef0 100644 --- a/src/services/refund_service/index.ts +++ b/src/services/refund_service/index.ts @@ -1,12 +1,12 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IRefund } from "./Refund"; -import { IRefundCreateParameters } from "./RefundCreateParameters"; -import { IRefundListParameters } from "./RefundListParameters"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IRefund } from './Refund'; +import { IRefundCreateParameters } from './RefundCreateParameters'; +import { IRefundListParameters } from './RefundListParameters'; -export * from "./Refund"; -export * from "./RefundCreateParameters"; -export * from "./RefundListParameters"; +export * from './Refund'; +export * from './RefundCreateParameters'; +export * from './RefundListParameters'; export default (easypostClient: EasyPost) => /** @@ -21,7 +21,7 @@ export default (easypostClient: EasyPost) => * @returns - The created refund. */ static async create(params: IRefundCreateParameters) { - const url = "refunds"; + const url = 'refunds'; const wrappedParams = { refund: params, @@ -37,7 +37,7 @@ export default (easypostClient: EasyPost) => * @returns - An object containing the list of {@link Refund refunds} and pagination information. */ static async all(params: IRefundListParameters = {}) { - const url = "refunds"; + const url = 'refunds'; return this._all<{ refunds: IRefund[] }>(url, params); } @@ -49,13 +49,8 @@ export default (easypostClient: EasyPost) => * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ static async getNextPage(refunds: any, pageSize: number | null = null) { - const url = "refunds"; - return this._getNextPage<{ refunds: IRefund[] }>( - url, - "refunds", - refunds, - pageSize - ); + const url = 'refunds'; + return this._getNextPage<{ refunds: IRefund[] }>(url, 'refunds', refunds, pageSize); } /** diff --git a/src/services/report_service/Report.ts b/src/services/report_service/Report.ts index 7e9647875..7e72426e8 100644 --- a/src/services/report_service/Report.ts +++ b/src/services/report_service/Report.ts @@ -1,5 +1,5 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; -import { TReportObjectType } from "./ReportObjectType"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { TReportObjectType } from './ReportObjectType'; /** * A Report contains a csv that is a log of all the objects created within a certain time frame. @@ -24,7 +24,7 @@ export type IReport = IObjectWithId & /** * "new", "available", "failed", or null */ - status: "new" | "available" | "failed" | null; + status: 'new' | 'available' | 'failed' | null; /** * A date string in YYYY-MM-DD form eg: "2016-02-02" diff --git a/src/services/report_service/ReportCreateParameters.ts b/src/services/report_service/ReportCreateParameters.ts index 09243c2b8..024eab7b6 100644 --- a/src/services/report_service/ReportCreateParameters.ts +++ b/src/services/report_service/ReportCreateParameters.ts @@ -1,4 +1,4 @@ -import { TReportType } from "./ReportObjectType"; +import { TReportType } from './ReportObjectType'; export type IReportCreateParameters = { type: TReportType; diff --git a/src/services/report_service/ReportListParameters.ts b/src/services/report_service/ReportListParameters.ts index 969f91aa0..c78c83fe1 100644 --- a/src/services/report_service/ReportListParameters.ts +++ b/src/services/report_service/ReportListParameters.ts @@ -1,5 +1,5 @@ -import { IAllMethodParameters } from "../../utils/types"; -import { TReportType } from "./ReportObjectType"; +import { IAllMethodParameters } from '../../utils/types'; +import { TReportType } from './ReportObjectType'; /** * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds diff --git a/src/services/report_service/ReportObjectType.ts b/src/services/report_service/ReportObjectType.ts index b58bbde44..6ebd27259 100644 --- a/src/services/report_service/ReportObjectType.ts +++ b/src/services/report_service/ReportObjectType.ts @@ -1,15 +1,15 @@ export type TReportObjectType = - | "CashFlowReport" - | "PaymentLogReport" - | "RefundReport" - | "ShipmentReport" - | "ShipmentInvoiceReport" - | "TrackerReport"; + | 'CashFlowReport' + | 'PaymentLogReport' + | 'RefundReport' + | 'ShipmentReport' + | 'ShipmentInvoiceReport' + | 'TrackerReport'; export type TReportType = - | "cash_flow" - | "payment_log" - | "refund" - | "shipment" - | "shipment_invoice" - | "tracker"; + | 'cash_flow' + | 'payment_log' + | 'refund' + | 'shipment' + | 'shipment_invoice' + | 'tracker'; diff --git a/src/services/report_service/index.ts b/src/services/report_service/index.ts index bc43165df..f22473d18 100644 --- a/src/services/report_service/index.ts +++ b/src/services/report_service/index.ts @@ -1,13 +1,13 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IReport } from "./Report"; -import { IReportCreateParameters } from "./ReportCreateParameters"; -import { IReportListParameters } from "./ReportListParameters"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IReport } from './Report'; +import { IReportCreateParameters } from './ReportCreateParameters'; +import { IReportListParameters } from './ReportListParameters'; -export * from "./Report"; -export * from "./ReportCreateParameters"; -export * from "./ReportListParameters"; -export * from "./ReportObjectType"; +export * from './Report'; +export * from './ReportCreateParameters'; +export * from './ReportListParameters'; +export * from './ReportObjectType'; export default (easypostClient: EasyPost) => /** @@ -38,18 +38,12 @@ export default (easypostClient: EasyPost) => try { // don't send "type" param to API - const apiParams = { ...params } as Omit< - IReportListParameters, - "type" - > & { type?: any }; + const apiParams = { ...params } as Omit & { type?: any }; delete apiParams.type; const response = await easypostClient._get(url, apiParams); - const responseObject = this._convertToEasyPostObject( - response.body, - params - ); + const responseObject = this._convertToEasyPostObject(response.body, params); return responseObject; } catch (e) { @@ -65,12 +59,7 @@ export default (easypostClient: EasyPost) => */ static async getNextPage(reports: any, pageSize: number | null = null) { const url = `reports/${reports.reports[0]._params.type}`; - return this._getNextPage<{ reports: IReport[] }>( - url, - "reports", - reports, - pageSize - ); + return this._getNextPage<{ reports: IReport[] }>(url, 'reports', reports, pageSize); } /** diff --git a/src/services/scan_form_service/ScanForm.ts b/src/services/scan_form_service/ScanForm.ts index 7975e9e8d..0bec81b8c 100644 --- a/src/services/scan_form_service/ScanForm.ts +++ b/src/services/scan_form_service/ScanForm.ts @@ -1,5 +1,5 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; -import { IAddress } from "../address_service"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; /** * A ScanForm can be created to speed up and simplify the carrier pickup process. @@ -14,13 +14,13 @@ import { IAddress } from "../address_service"; * * @see https://www.easypost.com/docs/api/node#scan-form-object */ -export type IScanForm = IObjectWithId<"ScanForm"> & +export type IScanForm = IObjectWithId<'ScanForm'> & IDatedObject & { /** * Current status. * Possible values are "creating", "created" and "failed" */ - status: "creating" | "created" | "failed"; + status: 'creating' | 'created' | 'failed'; /** * Human-readable message explaining any failures diff --git a/src/services/scan_form_service/ScanFormCreateParameters.ts b/src/services/scan_form_service/ScanFormCreateParameters.ts index 20f3ad90e..87266e658 100644 --- a/src/services/scan_form_service/ScanFormCreateParameters.ts +++ b/src/services/scan_form_service/ScanFormCreateParameters.ts @@ -1,8 +1,6 @@ -import { DeepPartial } from "../../utils/types"; -import { IShipmentCreateParameters } from "../shipment_service"; +import { DeepPartial } from '../../utils/types'; +import { IShipmentCreateParameters } from '../shipment_service'; export type IScanFormCreateParameters = { - shipments: - | (DeepPartial & { id: string })[] - | string[]; + shipments: (DeepPartial & { id: string })[] | string[]; }; diff --git a/src/services/scan_form_service/ScanFormListParameters.ts b/src/services/scan_form_service/ScanFormListParameters.ts index 703134e6c..b4deffb0a 100644 --- a/src/services/scan_form_service/ScanFormListParameters.ts +++ b/src/services/scan_form_service/ScanFormListParameters.ts @@ -1,4 +1,4 @@ -import { IAllMethodParameters } from "../../utils/types"; +import { IAllMethodParameters } from '../../utils/types'; /** * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-scan-forms diff --git a/src/services/scan_form_service/index.ts b/src/services/scan_form_service/index.ts index 3df6de47d..4c47fbde8 100644 --- a/src/services/scan_form_service/index.ts +++ b/src/services/scan_form_service/index.ts @@ -1,12 +1,12 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IScanForm } from "./ScanForm"; -import { IScanFormCreateParameters } from "./ScanFormCreateParameters"; -import { IScanFormListParameters } from "./ScanFormListParameters"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IScanForm } from './ScanForm'; +import { IScanFormCreateParameters } from './ScanFormCreateParameters'; +import { IScanFormListParameters } from './ScanFormListParameters'; -export * from "./ScanForm"; -export * from "./ScanFormCreateParameters"; -export * from "./ScanFormListParameters"; +export * from './ScanForm'; +export * from './ScanFormCreateParameters'; +export * from './ScanFormListParameters'; export default (easypostClient: EasyPost) => /** @@ -21,14 +21,14 @@ export default (easypostClient: EasyPost) => * @returns - The created scan form. */ static async create(params: IScanFormCreateParameters) { - const url = "scan_forms"; + const url = 'scan_forms'; // wraps up params in `shipments` if the user didn't do it // turn a list of shipment objects into a map of shipment ids if (params.shipments) { // eslint-disable-next-line no-param-reassign params.shipments = params.shipments.map((s) => { - if (typeof s === "string") { + if (typeof s === 'string') { return { id: s }; } return { id: s.id }; @@ -49,7 +49,7 @@ export default (easypostClient: EasyPost) => * @returns - An object containing the list of {@link ScanForm scan forms} and pagination information. */ static async all(params: IScanFormListParameters = {}) { - const url = "scan_forms"; + const url = 'scan_forms'; return this._all<{ scan_forms: IScanForm[] }>(url, params); } @@ -60,17 +60,9 @@ export default (easypostClient: EasyPost) => * @param pageSize The number of records to return on each page * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage( - scanForms: { scan_forms: any[] }, - pageSize: number | null = null - ) { - const url = "scan_forms"; - return this._getNextPage<{ scan_forms: IScanForm[] }>( - url, - "scan_forms", - scanForms, - pageSize - ); + static async getNextPage(scanForms: { scan_forms: any[] }, pageSize: number | null = null) { + const url = 'scan_forms'; + return this._getNextPage<{ scan_forms: IScanForm[] }>(url, 'scan_forms', scanForms, pageSize); } /** diff --git a/src/services/shipment_service/Form.ts b/src/services/shipment_service/Form.ts index 7b5782bef..9a784a189 100644 --- a/src/services/shipment_service/Form.ts +++ b/src/services/shipment_service/Form.ts @@ -1,23 +1,23 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; /** * @see https://www.easypost.com/docs/api/node#form-object */ -export type IForm = IObjectWithId<"Form"> & +export type IForm = IObjectWithId<'Form'> & IDatedObject & { /** * The type of form that we returned, can be one of "cn22", "cod_return_label", "commercial_invoice", "high_value_report", "label_qr_code", "nafta_certificate_of_origin", "order_summary", "return_packing_slip", "rma_qr_code" */ form_type: - | "cn22" - | "cod_return_label" - | "commercial_invoice" - | "high_value_report" - | "label_qr_code" - | "nafta_certificate_of_origin" - | "order_summary" - | "return_packing_slip" - | "rma_qr_code"; + | 'cn22' + | 'cod_return_label' + | 'commercial_invoice' + | 'high_value_report' + | 'label_qr_code' + | 'nafta_certificate_of_origin' + | 'order_summary' + | 'return_packing_slip' + | 'rma_qr_code'; /** * The address we return the form back at diff --git a/src/services/shipment_service/Options/LabelFormat.ts b/src/services/shipment_service/Options/LabelFormat.ts index e1b8d74a8..cc3a84031 100644 --- a/src/services/shipment_service/Options/LabelFormat.ts +++ b/src/services/shipment_service/Options/LabelFormat.ts @@ -1 +1 @@ -export declare type LabelFormat = "PNG" | "PDF" | "ZPL" | "EPL2"; +export declare type LabelFormat = 'PNG' | 'PDF' | 'ZPL' | 'EPL2'; diff --git a/src/services/shipment_service/Options/Options.ts b/src/services/shipment_service/Options/Options.ts index 69a6404dc..8cdab27f5 100644 --- a/src/services/shipment_service/Options/Options.ts +++ b/src/services/shipment_service/Options/Options.ts @@ -1,5 +1,5 @@ -import { LabelFormat } from "./LabelFormat"; -import { TPrintCustomCode } from "./PrintCustomCode"; +import { LabelFormat } from './LabelFormat'; +import { TPrintCustomCode } from './PrintCustomCode'; /** * Shipments can have a variety of additional options which you can specify when creating a shipment. @@ -50,7 +50,7 @@ export type IOptions = { /** * Method for payment. "CASH", "CHECK", "MONEY_ORDER" */ - cod_method?: "CASH" | "CHECK" | "MONEY_ORDER" | null; + cod_method?: 'CASH' | 'CHECK' | 'MONEY_ORDER' | null; /** * The ID of the Address to which the COD payment should be returned. @@ -84,12 +84,12 @@ export type IOptions = { * - "NO_SIGNATURE" - DHL Express Signature Release */ delivery_confirmation?: - | "ADULT_SIGNATURE" - | "SIGNATURE" - | "NO_SIGNATURE" - | "INDIRECT_SIGNATURE" - | "ADULT_SIGNATURE_RESTRICTED" - | "SIGNATURE_RESTRICTED" + | 'ADULT_SIGNATURE' + | 'SIGNATURE' + | 'NO_SIGNATURE' + | 'INDIRECT_SIGNATURE' + | 'ADULT_SIGNATURE_RESTRICTED' + | 'SIGNATURE_RESTRICTED' | null; /** @@ -104,13 +104,13 @@ export type IOptions = { * - "DROP_BOX" - "DROP_BOX" */ dropoff_type?: - | "REGULAR_PICKUP" - | "SCHEDULED_PICKUP" - | "RETAIL_LOCATION" - | "STATION" - | "DROP_BOX" - | "REQUEST_COURIER" - | "BUSINESS_SERVICE_CENTER" + | 'REGULAR_PICKUP' + | 'SCHEDULED_PICKUP' + | 'RETAIL_LOCATION' + | 'STATION' + | 'DROP_BOX' + | 'REQUEST_COURIER' + | 'BUSINESS_SERVICE_CENTER' | null; /** @@ -150,11 +150,11 @@ export type IOptions = { * Possible values "ADDRESS_SERVICE_REQUESTED", "FORWARDING_SERVICE_REQUESTED", "CHANGE_SERVICE_REQUESTED", "RETURN_SERVICE_REQUESTED", "LEAVE_IF_NO_RESPONSE" */ endorsement?: - | "ADDRESS_SERVICE_REQUESTED" - | "FORWARDING_SERVICE_REQUESTED" - | "CHANGE_SERVICE_REQUESTED" - | "RETURN_SERVICE_REQUESTED" - | "LEAVE_IF_NO_RESPONSE" + | 'ADDRESS_SERVICE_REQUESTED' + | 'FORWARDING_SERVICE_REQUESTED' + | 'CHANGE_SERVICE_REQUESTED' + | 'RETURN_SERVICE_REQUESTED' + | 'LEAVE_IF_NO_RESPONSE' | null; /** @@ -179,15 +179,15 @@ export type IOptions = { * Applies to USPS, FedEx and DHL eCommerce. */ hazmat?: - | "PRIMARY_CONTAINED" - | "PRIMARY_PACKED" - | "PRIMARY" - | "SECONDARY_CONTAINED" - | "SECONDARY_PACKED" - | "SECONDARY" - | "ORMD" - | "LIMITED_QUANTITY" - | "LITHIUM" + | 'PRIMARY_CONTAINED' + | 'PRIMARY_PACKED' + | 'PRIMARY' + | 'SECONDARY_CONTAINED' + | 'SECONDARY_PACKED' + | 'SECONDARY' + | 'ORMD' + | 'LIMITED_QUANTITY' + | 'LITHIUM' | null; /** @@ -201,17 +201,17 @@ export type IOptions = { * Setting this value to anything other than "DDP" will pass the cost and responsibility of duties on to the recipient of the package(s), as specified by Incoterms rules */ incoterm?: - | "EXW" - | "FCA" - | "CPT" - | "CIP" - | "DAT" - | "DAP" - | "DDP" - | "FAS" - | "FOB" - | "CFR" - | "CIF" + | 'EXW' + | 'FCA' + | 'CPT' + | 'CIP' + | 'DAT' + | 'DAP' + | 'DDP' + | 'FAS' + | 'FOB' + | 'CFR' + | 'CIF' | null; /** @@ -246,7 +246,7 @@ export type IOptions = { /** * Supported values are "SENDER", "THIRD_PARTY", "RECEIVER", "COLLECT". Defaults to SENDER. */ - type?: "SENDER" | "THIRD_PARTY" | "RECEIVER" | "COLLECT" | null; + type?: 'SENDER' | 'THIRD_PARTY' | 'RECEIVER' | 'COLLECT' | null; /** * Setting account number. @@ -335,7 +335,7 @@ export type IOptions = { * This option allows you to request restrictive rates from USPS. * Can set to 'USPS.MEDIAMAIL' or 'USPS.LIBRARYMAIL'. */ - special_rates_eligibility?: "USPS.MEDIAMAIL" | "USPS.LIBRARYMAIL" | null; + special_rates_eligibility?: 'USPS.MEDIAMAIL' | 'USPS.LIBRARYMAIL' | null; /** * You can use this to override the hub ID you have on your account. diff --git a/src/services/shipment_service/Options/PrintCustomCode.ts b/src/services/shipment_service/Options/PrintCustomCode.ts index dac99fec8..4933056eb 100644 --- a/src/services/shipment_service/Options/PrintCustomCode.ts +++ b/src/services/shipment_service/Options/PrintCustomCode.ts @@ -28,25 +28,25 @@ * - TJ - Federal Taxpayer ID No. */ export declare type TPrintCustomCode = - | "PO" - | "DP" - | "RMA" - | "AJ" - | "AT" - | "BM" - | "9V" - | "ON" - | "3Q" - | "IK" - | "MK" - | "MJ" - | "PM" - | "PC" - | "RQ" - | "RZ" - | "SA" - | "SE" - | "ST" - | "TN" - | "EI" - | "TJ"; + | 'PO' + | 'DP' + | 'RMA' + | 'AJ' + | 'AT' + | 'BM' + | '9V' + | 'ON' + | '3Q' + | 'IK' + | 'MK' + | 'MJ' + | 'PM' + | 'PC' + | 'RQ' + | 'RZ' + | 'SA' + | 'SE' + | 'ST' + | 'TN' + | 'EI' + | 'TJ'; diff --git a/src/services/shipment_service/Options/index.ts b/src/services/shipment_service/Options/index.ts index fcb86e974..349426b0d 100644 --- a/src/services/shipment_service/Options/index.ts +++ b/src/services/shipment_service/Options/index.ts @@ -1,3 +1,3 @@ -export * from "./LabelFormat"; -export * from "./Options"; -export * from "./PrintCustomCode"; +export * from './LabelFormat'; +export * from './Options'; +export * from './PrintCustomCode'; diff --git a/src/services/shipment_service/PostageLabel.ts b/src/services/shipment_service/PostageLabel.ts index 93b2b1a91..a047f61c2 100644 --- a/src/services/shipment_service/PostageLabel.ts +++ b/src/services/shipment_service/PostageLabel.ts @@ -1,9 +1,9 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; /** * PostageLabel Object */ -export type IPostageLabel = IObjectWithId<"PostageLabel"> & +export type IPostageLabel = IObjectWithId<'PostageLabel'> & IDatedObject & { date_advance: number; integrated_form: string; diff --git a/src/services/shipment_service/Shipment.ts b/src/services/shipment_service/Shipment.ts index 97bc3541a..acc1580c9 100644 --- a/src/services/shipment_service/Shipment.ts +++ b/src/services/shipment_service/Shipment.ts @@ -1,18 +1,18 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; -import { IAddress } from "../address_service"; -import { TBatchStatus } from "../batch_service"; -import { ICustomsInfo } from "../customs_info_service"; -import { IFee, IInsurance } from "../insurance_service"; -import { IParcel } from "../parcel_service"; -import { IRate } from "../rate_service"; -import { IScanForm } from "../scan_form_service"; -import { ITracker } from "../tracker_service"; -import { IForm } from "./Form"; -import { IMessage } from "./Message"; -import { IOptions, LabelFormat } from "./Options"; -import { IPostageLabel } from "./PostageLabel"; -import { IShipmentCreateParameters } from "./ShipmentCreateParameters"; -import { IShipmentListParameters } from "./ShipmentListParameters"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; +import { TBatchStatus } from '../batch_service'; +import { ICustomsInfo } from '../customs_info_service'; +import { IFee, IInsurance } from '../insurance_service'; +import { IParcel } from '../parcel_service'; +import { IRate } from '../rate_service'; +import { IScanForm } from '../scan_form_service'; +import { ITracker } from '../tracker_service'; +import { IForm } from './Form'; +import { IMessage } from './Message'; +import { IOptions, LabelFormat } from './Options'; +import { IPostageLabel } from './PostageLabel'; +import { IShipmentCreateParameters } from './ShipmentCreateParameters'; +import { IShipmentListParameters } from './ShipmentListParameters'; /** * The workhorse of the EasyPost API, a Shipment is made up of a "to" and "from" Address, the Parcel being shipped, and any customs forms required for international deliveries. @@ -22,7 +22,7 @@ import { IShipmentListParameters } from "./ShipmentListParameters"; * * @see https://www.easypost.com/docs/api/node#shipment-object */ -export type IShipment = IObjectWithId<"Shipment"> & +export type IShipment = IObjectWithId<'Shipment'> & IDatedObject & { /** * An optional field that may be used in place of id in other API endpoints @@ -132,7 +132,7 @@ export type IShipment = IObjectWithId<"Shipment"> & /** * The current status of the shipment refund process. Possible values are "submitted", "refunded", "rejected". */ - refund_status: "submitted" | "refunded" | "rejected"; + refund_status: 'submitted' | 'refunded' | 'rejected'; /** * The ID of the batch that contains this shipment, if any diff --git a/src/services/shipment_service/ShipmentCreateParameters.ts b/src/services/shipment_service/ShipmentCreateParameters.ts index 1de69a12a..9589a8d15 100644 --- a/src/services/shipment_service/ShipmentCreateParameters.ts +++ b/src/services/shipment_service/ShipmentCreateParameters.ts @@ -1,8 +1,8 @@ -import { DeepPartial } from "../../utils/types"; -import { IAddressCreateParameters } from "../address_service"; -import { ICustomsInfo } from "../customs_info_service"; -import { IParcelCreateParameters } from "../parcel_service"; -import { IOptions } from "./Options"; +import { DeepPartial } from '../../utils/types'; +import { IAddressCreateParameters } from '../address_service'; +import { ICustomsInfo } from '../customs_info_service'; +import { IParcelCreateParameters } from '../parcel_service'; +import { IOptions } from './Options'; export type IShipmentCreateParameters = { reference?: string | null; diff --git a/src/services/shipment_service/ShipmentListParameters.ts b/src/services/shipment_service/ShipmentListParameters.ts index 9eeb76638..c1f8732a4 100644 --- a/src/services/shipment_service/ShipmentListParameters.ts +++ b/src/services/shipment_service/ShipmentListParameters.ts @@ -1,4 +1,4 @@ -import { IAllMethodParameters } from "../../utils/types"; +import { IAllMethodParameters } from '../../utils/types'; /** * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments diff --git a/src/services/shipment_service/index.ts b/src/services/shipment_service/index.ts index 8028875c8..c550268ee 100644 --- a/src/services/shipment_service/index.ts +++ b/src/services/shipment_service/index.ts @@ -1,22 +1,22 @@ -import EasyPost from "../.."; -import Constants from "../../constants"; -import baseService from "../base_service"; -import { IRate, ISmartRate } from "../rate_service"; -import { IOptions, LabelFormat } from "./Options"; -import { IShipment } from "./Shipment"; -import { IShipmentCreateParameters } from "./ShipmentCreateParameters"; -import { IShipmentListParameters } from "./ShipmentListParameters"; - -export * from "./Form"; -export * from "./Message"; -export * from "./PostageLabel"; -export * from "./Shipment"; -export * from "./ShipmentCreateParameters"; -export * from "./ShipmentListParameters"; -export * from "./Options"; +import EasyPost from '../..'; +import Constants from '../../constants'; +import baseService from '../base_service'; +import { IRate, ISmartRate } from '../rate_service'; +import { IOptions, LabelFormat } from './Options'; +import { IShipment } from './Shipment'; +import { IShipmentCreateParameters } from './ShipmentCreateParameters'; +import { IShipmentListParameters } from './ShipmentListParameters'; + +export * from './Form'; +export * from './Message'; +export * from './PostageLabel'; +export * from './Shipment'; +export * from './ShipmentCreateParameters'; +export * from './ShipmentListParameters'; +export * from './Options'; const addLowestRateToShipment = ( - shipment: IShipment + shipment: IShipment, ): IShipment & { lowestRate: (carriers?: string[], services?: string[]) => IRate; } => { @@ -40,7 +40,7 @@ export default (easypostClient: EasyPost) => * @returns - The created shipment. */ static async create(params: IShipmentCreateParameters) { - const url = "shipments"; + const url = 'shipments'; const wrappedParams = { shipment: params, @@ -64,9 +64,9 @@ export default (easypostClient: EasyPost) => id: string, rate: IRate | string, insuranceAmount: number | null = null, - endShipperId: string | null = null + endShipperId: string | null = null, ) { - const rateId = typeof rate === "object" ? rate.id : rate; + const rateId = typeof rate === 'object' ? rate.id : rate; const url = `shipments/${id}/buy`; @@ -87,10 +87,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url, wrappedParams); - const shipment = this._convertToEasyPostObject( - response.body, - wrappedParams - ); + const shipment = this._convertToEasyPostObject(response.body, wrappedParams); return addLowestRateToShipment(shipment); } catch (e) { @@ -112,10 +109,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._get(url, wrappedParams); - const shipment = this._convertToEasyPostObject( - response.body, - wrappedParams - ); + const shipment = this._convertToEasyPostObject(response.body, wrappedParams); return addLowestRateToShipment(shipment); } catch (e) { return Promise.reject(e); @@ -135,10 +129,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url, wrappedParams); - const shipment = this._convertToEasyPostObject( - response.body, - wrappedParams - ); + const shipment = this._convertToEasyPostObject(response.body, wrappedParams); return addLowestRateToShipment(shipment); } catch (e) { return Promise.reject(e); @@ -157,9 +148,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._get(url); - return this._convertToEasyPostObject( - response.body.result - ); + return this._convertToEasyPostObject(response.body.result); } catch (e) { return Promise.reject(e); } @@ -179,10 +168,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url, wrappedParams); - const shipment = this._convertToEasyPostObject( - response.body, - wrappedParams - ); + const shipment = this._convertToEasyPostObject(response.body, wrappedParams); return addLowestRateToShipment(shipment); } catch (e) { return Promise.reject(e); @@ -197,11 +183,7 @@ export default (easypostClient: EasyPost) => * @param [formOptions] - Options for the form. * @returns - The shipment with the generated form attached. */ - static async generateForm( - id: string, - formType: string, - formOptions: IOptions = {} - ) { + static async generateForm(id: string, formType: string, formOptions: IOptions = {}) { const url = `shipments/${id}/forms`; const wrappedParams = { form: { @@ -213,10 +195,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url, wrappedParams); - const shipment = this._convertToEasyPostObject( - response.body, - wrappedParams - ); + const shipment = this._convertToEasyPostObject(response.body, wrappedParams); return addLowestRateToShipment(shipment); } catch (e) { return Promise.reject(e); @@ -235,9 +214,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url); - const shipment = this._convertToEasyPostObject( - response.body - ); + const shipment = this._convertToEasyPostObject(response.body); return addLowestRateToShipment(shipment); } catch (e) { return Promise.reject(e); @@ -254,13 +231,13 @@ export default (easypostClient: EasyPost) => static async lowestSmartRate( id: string, deliveryDays: number, - deliveryAccuracy: keyof ISmartRate["time_in_transit"] + deliveryAccuracy: keyof ISmartRate['time_in_transit'], ) { const smartRates = await this.getSmartRates(id); return Constants.Utils.getLowestSmartRate( smartRates, deliveryDays, - deliveryAccuracy.toLowerCase() as keyof ISmartRate["time_in_transit"] + deliveryAccuracy.toLowerCase() as keyof ISmartRate['time_in_transit'], ); } @@ -271,7 +248,7 @@ export default (easypostClient: EasyPost) => * @returns - An object containing a list of {@link Shipment shipments} and pagination information. */ static async all(params: IShipmentListParameters = {}) { - const url = "shipments"; + const url = 'shipments'; const result = await this._all<{ shipments: IShipment[] }>(url, params); return { @@ -287,13 +264,13 @@ export default (easypostClient: EasyPost) => * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ static async getNextPage(shipments: { shipments: any[] }, pageSize = null) { - const url = "shipments"; + const url = 'shipments'; const result = await this._getNextPage<{ shipments: IShipment[] }>( url, - "shipments", + 'shipments', shipments, - pageSize + pageSize, ); return { ...result, @@ -320,10 +297,7 @@ export default (easypostClient: EasyPost) => * @param plannedShipDate * @returns - An array of the estimated delivery date and rates. */ - static async retrieveEstimatedDeliveryDate( - id: string, - plannedShipDate: string - ) { + static async retrieveEstimatedDeliveryDate(id: string, plannedShipDate: string) { const url = `shipments/${id}/smartrate/delivery_date`; const params = { @@ -333,10 +307,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._get(url, params); - return this._convertToEasyPostObject( - response.body.rates ?? [], - params - ); + return this._convertToEasyPostObject(response.body.rates ?? [], params); } catch (e) { return Promise.reject(e); } diff --git a/src/services/tracker_service/CarrierDetail.ts b/src/services/tracker_service/CarrierDetail.ts index 115e8cf3c..aa5b15285 100644 --- a/src/services/tracker_service/CarrierDetail.ts +++ b/src/services/tracker_service/CarrierDetail.ts @@ -1,10 +1,10 @@ -import { IBaseObject } from "../../utils/types"; -import { ITrackingLocation } from "./TrackingLocation"; +import { IBaseObject } from '../../utils/types'; +import { ITrackingLocation } from './TrackingLocation'; /** * @see https://www.easypost.com/docs/api/node#carrier-detail-object */ -export type ICarrierDetail = IBaseObject<"CarrierDetail"> & { +export type ICarrierDetail = IBaseObject<'CarrierDetail'> & { /** * The service level the associated shipment was shipped with (if available) */ diff --git a/src/services/tracker_service/Tracker.ts b/src/services/tracker_service/Tracker.ts index 449babb29..f4116ad0a 100644 --- a/src/services/tracker_service/Tracker.ts +++ b/src/services/tracker_service/Tracker.ts @@ -1,9 +1,9 @@ -import { IDatedObject, IObjectWithId } from "../../utils/types"; -import { IFee } from "../insurance_service"; -import { ICarrierDetail } from "./CarrierDetail"; -import { ITrackerStatus } from "./TrackerStatus"; -import { ITrackerStatusDetail } from "./TrackerStatusDetail"; -import { ITrackingDetail } from "./TrackingDetail"; +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IFee } from '../insurance_service'; +import { ICarrierDetail } from './CarrierDetail'; +import { ITrackerStatus } from './TrackerStatus'; +import { ITrackerStatusDetail } from './TrackerStatusDetail'; +import { ITrackingDetail } from './TrackingDetail'; /** * A Tracker object contains all the tracking information for a package. @@ -33,7 +33,7 @@ import { ITrackingDetail } from "./TrackingDetail"; * * @see https://www.easypost.com/docs/api/node#tracker-object */ -export type ITracker = IObjectWithId<"Tracker"> & +export type ITracker = IObjectWithId<'Tracker'> & IDatedObject & { /** * The tracking code provided by the carrier diff --git a/src/services/tracker_service/TrackerListParameters.ts b/src/services/tracker_service/TrackerListParameters.ts index 4bba76146..14f39f889 100644 --- a/src/services/tracker_service/TrackerListParameters.ts +++ b/src/services/tracker_service/TrackerListParameters.ts @@ -1,4 +1,4 @@ -import { IAllMethodParameters } from "../../utils/types"; +import { IAllMethodParameters } from '../../utils/types'; export type ITrackerListParameters = IAllMethodParameters & { /** diff --git a/src/services/tracker_service/TrackerStatus.ts b/src/services/tracker_service/TrackerStatus.ts index 7e11a0ad2..11b490ca1 100644 --- a/src/services/tracker_service/TrackerStatus.ts +++ b/src/services/tracker_service/TrackerStatus.ts @@ -1,11 +1,11 @@ export type ITrackerStatus = - | "unknown" - | "pre_transit" - | "in_transit" - | "out_for_delivery" - | "delivered" - | "available_for_pickup" - | "return_to_sender" - | "failure" - | "cancelled" - | "error"; + | 'unknown' + | 'pre_transit' + | 'in_transit' + | 'out_for_delivery' + | 'delivered' + | 'available_for_pickup' + | 'return_to_sender' + | 'failure' + | 'cancelled' + | 'error'; diff --git a/src/services/tracker_service/TrackerStatusDetail.ts b/src/services/tracker_service/TrackerStatusDetail.ts index 5e9128596..d36c4690c 100644 --- a/src/services/tracker_service/TrackerStatusDetail.ts +++ b/src/services/tracker_service/TrackerStatusDetail.ts @@ -1,29 +1,29 @@ export type ITrackerStatusDetail = - | "address_correction" - | "arrived_at_destination" - | "arrived_at_facility" - | "arrived_at_pickup_location" - | "awaiting_information" - | "cancelled" - | "damaged" - | "delayed" - | "delivery_exception" - | "departed_facility" - | "departed_origin_facility" - | "expired" - | "failure" - | "held" - | "in_transit" - | "label_created" - | "lost" - | "missorted" - | "out_for_delivery" - | "received_at_destination_facility" - | "received_at_origin_facility" - | "refused" - | "return" - | "status_update" - | "transferred_to_destination_carrier" - | "transit_exception" - | "unknown" - | "weather_delay"; + | 'address_correction' + | 'arrived_at_destination' + | 'arrived_at_facility' + | 'arrived_at_pickup_location' + | 'awaiting_information' + | 'cancelled' + | 'damaged' + | 'delayed' + | 'delivery_exception' + | 'departed_facility' + | 'departed_origin_facility' + | 'expired' + | 'failure' + | 'held' + | 'in_transit' + | 'label_created' + | 'lost' + | 'missorted' + | 'out_for_delivery' + | 'received_at_destination_facility' + | 'received_at_origin_facility' + | 'refused' + | 'return' + | 'status_update' + | 'transferred_to_destination_carrier' + | 'transit_exception' + | 'unknown' + | 'weather_delay'; diff --git a/src/services/tracker_service/TrackingDetail.ts b/src/services/tracker_service/TrackingDetail.ts index 9185bf1c0..92ad5e074 100644 --- a/src/services/tracker_service/TrackingDetail.ts +++ b/src/services/tracker_service/TrackingDetail.ts @@ -1,11 +1,11 @@ -import { IBaseObject } from "../../utils/types"; -import { ITrackerStatus } from "./TrackerStatus"; -import { ITrackingLocation } from "./TrackingLocation"; +import { IBaseObject } from '../../utils/types'; +import { ITrackerStatus } from './TrackerStatus'; +import { ITrackingLocation } from './TrackingLocation'; /** * @see https://www.easypost.com/docs/api/node#tracking-detail-object */ -export type ITrackingDetail = IBaseObject<"TrackingDetail"> & { +export type ITrackingDetail = IBaseObject<'TrackingDetail'> & { /** * Description of the scan event */ diff --git a/src/services/tracker_service/TrackingLocation.ts b/src/services/tracker_service/TrackingLocation.ts index 288471bf7..f7df53cf6 100644 --- a/src/services/tracker_service/TrackingLocation.ts +++ b/src/services/tracker_service/TrackingLocation.ts @@ -1,9 +1,9 @@ -import { IBaseObject } from "../../utils/types"; +import { IBaseObject } from '../../utils/types'; /** * @see https://www.easypost.com/docs/api/node#tracking-location-object */ -export type ITrackingLocation = IBaseObject<"TrackingLocation"> & { +export type ITrackingLocation = IBaseObject<'TrackingLocation'> & { /** * The city where the scan event occurred (if available) */ diff --git a/src/services/tracker_service/index.ts b/src/services/tracker_service/index.ts index 9740633ae..47cc51fc7 100644 --- a/src/services/tracker_service/index.ts +++ b/src/services/tracker_service/index.ts @@ -1,17 +1,17 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { ITracker } from "./Tracker"; -import { ITrackerCreateParameters } from "./TrackerCreateParameters"; -import { ITrackerListParameters } from "./TrackerListParameters"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { ITracker } from './Tracker'; +import { ITrackerCreateParameters } from './TrackerCreateParameters'; +import { ITrackerListParameters } from './TrackerListParameters'; -export * from "./CarrierDetail"; -export * from "./Tracker"; -export * from "./TrackerCreateParameters"; -export * from "./TrackerListParameters"; -export * from "./TrackerStatus"; -export * from "./TrackerStatusDetail"; -export * from "./TrackingDetail"; -export * from "./TrackingLocation"; +export * from './CarrierDetail'; +export * from './Tracker'; +export * from './TrackerCreateParameters'; +export * from './TrackerListParameters'; +export * from './TrackerStatus'; +export * from './TrackerStatusDetail'; +export * from './TrackingDetail'; +export * from './TrackingLocation'; export default (easypostClient: EasyPost) => /** @@ -26,7 +26,7 @@ export default (easypostClient: EasyPost) => * @returns - The created tracker. */ static async create(params: ITrackerCreateParameters) { - const url = "trackers"; + const url = 'trackers'; const wrappedParams = { tracker: params, @@ -42,7 +42,7 @@ export default (easypostClient: EasyPost) => */ static async createList(params: ITrackerCreateParameters[] = []) { const newParams = { trackers: params }; - const url = "trackers/create_list"; + const url = 'trackers/create_list'; await easypostClient._post(url, newParams); } @@ -53,7 +53,7 @@ export default (easypostClient: EasyPost) => * @returns - An object containing the list of {@link Tracker trackers} and pagination information. */ static async all(params: ITrackerListParameters = {}) { - const url = "trackers"; + const url = 'trackers'; return this._all<{ trackers: ITracker[] }>(url, params); } @@ -64,18 +64,10 @@ export default (easypostClient: EasyPost) => * @param pageSize The number of records to return on each page * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage( - trackers: { trackers: any[] }, - pageSize: number | null = null - ) { - const url = "trackers"; + static async getNextPage(trackers: { trackers: any[] }, pageSize: number | null = null) { + const url = 'trackers'; - return this._getNextPage<{ trackers: ITracker[] }>( - url, - "trackers", - trackers, - pageSize - ); + return this._getNextPage<{ trackers: ITracker[] }>(url, 'trackers', trackers, pageSize); } /** diff --git a/src/services/user_service/Brand.ts b/src/services/user_service/Brand.ts index 848a7765a..e10ddfe65 100644 --- a/src/services/user_service/Brand.ts +++ b/src/services/user_service/Brand.ts @@ -1,11 +1,11 @@ -import { IObjectWithId } from "../../utils/types"; +import { IObjectWithId } from '../../utils/types'; /** * The Brand class represents the public-accessible information about a user's brand, including logos, colors and themes. * * @see https://www.easypost.com/docs/api/node#brand */ -export type IBrand = IObjectWithId<"Brand"> & { +export type IBrand = IObjectWithId<'Brand'> & { /** * The background color of the brand, as a hex code. */ @@ -44,5 +44,5 @@ export type IBrand = IObjectWithId<"Brand"> & { /** * The name of the current theme. */ - theme: "theme1" | "theme2"; + theme: 'theme1' | 'theme2'; }; diff --git a/src/services/user_service/User.ts b/src/services/user_service/User.ts index 216d6750e..bedbd8d76 100644 --- a/src/services/user_service/User.ts +++ b/src/services/user_service/User.ts @@ -1,4 +1,4 @@ -import { IObjectWithId } from "../../utils/types"; +import { IObjectWithId } from '../../utils/types'; /** * The User object can be used to manage your own account and to create child accounts. @@ -8,7 +8,7 @@ import { IObjectWithId } from "../../utils/types"; * * @see https://www.easypost.com/docs/api/node#user-object */ -export type IUser = IObjectWithId<"User"> & { +export type IUser = IObjectWithId<'User'> & { /** * The ID of the parent user object. * Top-level users are defined as users with no parent diff --git a/src/services/user_service/UserCreateParameters.ts b/src/services/user_service/UserCreateParameters.ts index 758264e25..32d273b54 100644 --- a/src/services/user_service/UserCreateParameters.ts +++ b/src/services/user_service/UserCreateParameters.ts @@ -1,4 +1,4 @@ -import { ParametersToOmitOnCreate } from "../../utils/types"; -import { IUser } from "./User"; +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IUser } from './User'; export type IUserCreateParameters = Omit; diff --git a/src/services/user_service/index.ts b/src/services/user_service/index.ts index 677fb9218..84e06953a 100644 --- a/src/services/user_service/index.ts +++ b/src/services/user_service/index.ts @@ -1,12 +1,12 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IBrand } from "./Brand"; -import { IUser } from "./User"; -import { IUserCreateParameters } from "./UserCreateParameters"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IBrand } from './Brand'; +import { IUser } from './User'; +import { IUserCreateParameters } from './UserCreateParameters'; -export * from "./Brand"; -export * from "./User"; -export * from "./UserCreateParameters"; +export * from './Brand'; +export * from './User'; +export * from './UserCreateParameters'; export default (easypostClient: EasyPost) => /** @@ -21,7 +21,7 @@ export default (easypostClient: EasyPost) => * @returns - The created child user. */ static async create(params: IUserCreateParameters) { - const url = "users"; + const url = 'users'; const wrappedParams = { user: params, @@ -46,10 +46,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._patch(url, wrappedParams); - return this._convertToEasyPostObject( - response.body, - wrappedParams - ); + return this._convertToEasyPostObject(response.body, wrappedParams); } catch (e) { return Promise.reject(e); } @@ -79,7 +76,7 @@ export default (easypostClient: EasyPost) => * @returns - The retrieved user. */ static async retrieveMe() { - const url = "users"; + const url = 'users'; try { const response = await easypostClient._get(url); @@ -122,10 +119,7 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._patch(url, wrappedParams); - return this._convertToEasyPostObject( - response.body, - wrappedParams - ); + return this._convertToEasyPostObject(response.body, wrappedParams); } catch (e) { return Promise.reject(e); } @@ -138,15 +132,12 @@ export default (easypostClient: EasyPost) => * @returns - An object containing a list of {@link Children User} and pagination information. */ static async allChildren(params: any) { - const url = "users/children"; + const url = 'users/children'; try { const response = await easypostClient._get(url, params); - return this._convertToEasyPostObject<{ children: IUser[] }>( - response.body, - params - ); + return this._convertToEasyPostObject<{ children: IUser[] }>(response.body, params); } catch (e) { return Promise.reject(e); } @@ -158,16 +149,8 @@ export default (easypostClient: EasyPost) => * @param pageSize The number of records to return on each page * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage( - children: { children: any[] }, - pageSize: number | null = null - ) { - const url = "users/children"; - return this._getNextPage<{ children: IUser[] }>( - url, - "children", - children, - pageSize - ); + static async getNextPage(children: { children: any[] }, pageSize: number | null = null) { + const url = 'users/children'; + return this._getNextPage<{ children: IUser[] }>(url, 'children', children, pageSize); } }; diff --git a/src/services/webhook_service/Webhook.ts b/src/services/webhook_service/Webhook.ts index 4a95308ec..89cfbe444 100644 --- a/src/services/webhook_service/Webhook.ts +++ b/src/services/webhook_service/Webhook.ts @@ -1,4 +1,4 @@ -import { IObjectWithId } from "../../utils/types"; +import { IObjectWithId } from '../../utils/types'; /** * Each Webhook contains the url which EasyPost will notify whenever an object in our system updates. @@ -17,7 +17,7 @@ import { IObjectWithId } from "../../utils/types"; * * @see https://www.easypost.com/docs/api/node#webhook-object */ -export type IWebhook = IObjectWithId<"Webhook"> & { +export type IWebhook = IObjectWithId<'Webhook'> & { /** * http://example.com */ diff --git a/src/services/webhook_service/WebhookListParameters.ts b/src/services/webhook_service/WebhookListParameters.ts index d542b3788..c782c740d 100644 --- a/src/services/webhook_service/WebhookListParameters.ts +++ b/src/services/webhook_service/WebhookListParameters.ts @@ -1,4 +1,4 @@ -import { IAllMethodParameters } from "../../utils/types"; +import { IAllMethodParameters } from '../../utils/types'; /** * @see https://www.easypost.com/docs/api/node#list-a-webhooks diff --git a/src/services/webhook_service/index.ts b/src/services/webhook_service/index.ts index 1f9871c61..64e535c96 100644 --- a/src/services/webhook_service/index.ts +++ b/src/services/webhook_service/index.ts @@ -1,12 +1,12 @@ -import EasyPost from "../.."; -import baseService from "../base_service"; -import { IWebhook } from "./Webhook"; -import { IWebhookCreateParameters } from "./WebhookCreateParameters"; -import { IWebhookListParameters } from "./WebhookListParameters"; +import EasyPost from '../..'; +import baseService from '../base_service'; +import { IWebhook } from './Webhook'; +import { IWebhookCreateParameters } from './WebhookCreateParameters'; +import { IWebhookListParameters } from './WebhookListParameters'; -export * from "./Webhook"; -export * from "./WebhookCreateParameters"; -export * from "./WebhookListParameters"; +export * from './Webhook'; +export * from './WebhookCreateParameters'; +export * from './WebhookListParameters'; export default (easypostClient: EasyPost) => /** @@ -21,7 +21,7 @@ export default (easypostClient: EasyPost) => * @returns - The created webhook. */ static async create(params: IWebhookCreateParameters) { - const url = "webhooks"; + const url = 'webhooks'; const wrappedParams = { webhook: params, @@ -74,7 +74,7 @@ export default (easypostClient: EasyPost) => * @returns */ static async all(params: IWebhookListParameters = {}) { - const url = "webhooks"; + const url = 'webhooks'; return this._all<{ webhooks: IWebhook[] }>(url, params); } diff --git a/src/utils/errors/Error.ts b/src/utils/errors/Error.ts index 89475bc74..53eac721a 100644 --- a/src/utils/errors/Error.ts +++ b/src/utils/errors/Error.ts @@ -1,5 +1,5 @@ -import { TErrorCode } from "./ErrorCode"; -import { IFieldError } from "./FieldError"; +import { TErrorCode } from './ErrorCode'; +import { IFieldError } from './FieldError'; /** * In the event of a client or server error, the response will contain the standard 4xx or 5xx respectively, accompanied by a well-formed JSON body describing the issue, e.g., a required field was omitted, a purchase failed, etc. diff --git a/src/utils/errors/ErrorCode.ts b/src/utils/errors/ErrorCode.ts index a8ad19352..08de3af5c 100644 --- a/src/utils/errors/ErrorCode.ts +++ b/src/utils/errors/ErrorCode.ts @@ -1,174 +1,174 @@ // TODO: there seems to be a lot of duplicate codes listed here https://www.easypost.com/errors-guide export type TErrorCode = - | "ADDRESS.COUNTRY.INVALID" - | "ADDRESS.PARAMETERS.INVALID_CHARACTER" - | "ADDRESS.PARAMETERS.INVALID" - | "ADDRESS.VERIFICATION.FAILURE" - | "ADDRESS.VERIFICATION.INVALID" - | "ADDRESS.VERIFICATION.NOT_FOUND" - | "ADDRESS.VERIFY.CARRIER_INVALID" - | "ADDRESS.VERIFY.FAILURE" - | "ADDRESS.VERIFY.INTL_NOT_ENABLED" - | "ADDRESS.VERIFY.MISSING_CITY_STATE_ZIP" - | "ADDRESS.VERIFY.MISSING_STREET" - | "ADDRESS.VERIFY.ONLY_US" - | "ADDRESS.VERIFY.UNAVAILABLE" - | "ADDRESS.VERIFY.UPSTREAM_UNAVAILABLE" - | "BAD_REQUEST" - | "BANK_ACCOUNT.CHARGE.FAILURE" - | "BANK_ACCOUNT.VERIFY.FAILURE" + | 'ADDRESS.COUNTRY.INVALID' + | 'ADDRESS.PARAMETERS.INVALID_CHARACTER' + | 'ADDRESS.PARAMETERS.INVALID' + | 'ADDRESS.VERIFICATION.FAILURE' + | 'ADDRESS.VERIFICATION.INVALID' + | 'ADDRESS.VERIFICATION.NOT_FOUND' + | 'ADDRESS.VERIFY.CARRIER_INVALID' + | 'ADDRESS.VERIFY.FAILURE' + | 'ADDRESS.VERIFY.INTL_NOT_ENABLED' + | 'ADDRESS.VERIFY.MISSING_CITY_STATE_ZIP' + | 'ADDRESS.VERIFY.MISSING_STREET' + | 'ADDRESS.VERIFY.ONLY_US' + | 'ADDRESS.VERIFY.UNAVAILABLE' + | 'ADDRESS.VERIFY.UPSTREAM_UNAVAILABLE' + | 'BAD_REQUEST' + | 'BANK_ACCOUNT.CHARGE.FAILURE' + | 'BANK_ACCOUNT.VERIFY.FAILURE' /** * The typo "FORAMT" is in both the docs and api error response. * @link https://github.com/EasyPost/easypost-node/pull/156#discussion_r819811282 */ - | "BATCH.FILE_FORAMT.INVALID" - | "BATCH.PARAMS.INVALID" - | "BATCH.SHIPMENT.MISSING" - | "BATCH.SHIPMENT.TOO_LARGE" - | "BATCH.SHIPMENTS.REQUIRED" - | "BATCH.STATE.ALREADY_PURCHASED" - | "BATCH.STATE.CREATING" - | "BATCH.STATE.CREATION_FAILED" - | "BATCH.STATE.NOT_PURCHASED" - | "CARRIER_ACCOUNT.INVALID" - | "CARRIER_ACCOUNT.PARAMETERS.INVALID" - | "CARRIER_ACCOUNT.REGISTRATION.FAILED" - | "CARRIER_ACCOUNT.TYPE.EXISTS" - | "CARRIER_ACCOUNT.TYPE.UNKNOWN" - | "CONTAINER.DIMENSION.REQUIRED" - | "CONTAINER.NAME.REQUIRED" - | "CONTAINER.TYPE.INVALID" - | "CREDIT_CARD.CHARGE.FAILURE" - | "CREDIT_CARD.INVALID" - | "CUSTOMS_INFO.PARAMETERS.INVALID" - | "CUSTOMS_ITEM.CURRENCY.ONE_CURRENCY_SUPPORTED" - | "CUSTOMS_ITEM.ORIGIN_COUNTRY.REQUIRED" - | "CUSTOMS_ITEM.PARAMETERS.INVALID" - | "DATE.PARSE.FAILURE" - | "DHLGM.ACCESS_TOKEN.GENERATION_FAILED" - | "DHLGM.GIRTH_MAX" - | "DHLGM.LABEL.FAILURE" - | "DHLGM.LETTER_NOT_SUPPORTED" - | "DHLGM.NO_ALCOHOL" - | "DHLGM.NO_INTERNATIONAL" - | "DHLGM.RATE_TABLE.NOT_FOUND" - | "DHLGM.RETURN.AUTHORIZATION_NUMBER_REQUIRED" - | "DHLGM.SCAN_FORM.GENERATION_FAILED" - | "DOCUMENT.COMMERCIAL_INVOICE.FAILURE" - | "DOCUMENT.CONVERSION.FAILURE" - | "EMAIL_VERIFICATION.EXPIRED" - | "EMAIL_VERIFICATION.NOT_FOUND" - | "EMAIL_VERIFICATION.USED" - | "FORBIDDEN" - | "IMAGE.CONVERSION.FAILURE" - | "IMAGE.WIDTH.INVALID" - | "INSURANCE.AMOUNT.ABOVE_MAXIMUM" - | "INSURANCE.AMOUNT.BELOW_MINIMUM" - | "INSURANCE.AMOUNT.REQUIRED" - | "INSURANCE.CREATE.FAILURE" - | "INSURANCE.PARAMETERS.INVALID" - | "INSURANCE.PURCHASE.FAILED" - | "INSURANCE.PURCHASE.NOT_ALLOWED" - | "INTERNAL_SERVER_ERROR" - | "ITEM.HEIGHT.REQUIRED" - | "ITEM.LENGTH.REQUIRED" - | "ITEM.NAME.REQUIRED" - | "ITEM.VALUE.REQUIRED" - | "ITEM.WEIGHT.REQUIRED" - | "ITEM.WIDTH.REQUIRED" - | "MODE.CONFLICT" - | "MODE.UNAUTHORIZED" - | "NOT_ACCEPTABLE" - | "NOT_FOUND" - | "ORDER.CARRIER_ACCOUNTS.CONFLICT" - | "ORDER.CARRIER.REQUIRED" - | "ORDER.FROM_ADDRESS.REQUIRED" - | "ORDER.INVALID" - | "ORDER.LABEL_DATE.INVALID" - | "ORDER.OPTIONS.INVALID" - | "ORDER.PARAMS.REQUIRED" - | "ORDER.RATE.UNAVAILABLE" - | "ORDER.SERVICE.REQUIRED" - | "ORDER.SHIPMENTS.REQUIRED" - | "ORDER.TO_ADDRESS.REQUIRED" - | "PARAMETER.FORBIDDEN" - | "PARAMETER.REQUIRED" - | "PARCEL.PARAMETERS.INVALID" - | "PARCEL.PREDEFINED_PACKAGE.INVALID" - | "PAYMENT_GATEWAY.ERROR" - | "PAYMENT_REQUIRED" - | "PICKUP.ADDRESS.INVALID" - | "PICKUP.ADDRESS.REQUIRED" - | "PICKUP.BATCH_CARRIER.INCONSISTENT" - | "PICKUP.BATCH.INVALID" - | "PICKUP.BATCH.REQUIRED" - | "PICKUP.BUY.FAILED" - | "PICKUP.BUY.FORBIDDEN" - | "PICKUP.BUY.NO_MATCHING_RATES" - | "PICKUP.CANCEL.FAILED" - | "PICKUP.CARRIER.REQUIRED" - | "PICKUP.IS_ACCOUNT_ADDRESS.REQUIRED" - | "PICKUP.MAX_DATETIME.REQUIRED" - | "PICKUP.MIN_DATETIME.REQUIRED" - | "PICKUP.REQUEST.INVALID" - | "PICKUP.SERVICE.REQUIRED" - | "PICKUP.SHIPMENT_COUNTRY.INVALID" - | "PICKUP.SHIPMENT_SERVICE.INVALID" - | "PICKUP.STATUS.INVALID" - | "REFUND.FAILURE" - | "REFUND.NO_RESPONSE" - | "REFUND.TRACKING_CODE.NOT_FOUND" - | "REFUND.TRACKING_CODES.INVALID" - | "SCAN_FORM.BATCH.MULTIPLE_CARRIERS" - | "SCAN_FORM.BATCH.NOT_PURCHASED" - | "SCAN_FORM.CREATE.CARRIER_NOT_SUPPORTED" - | "SCAN_FORM.CREATE.FAILURE" - | "SCAN_FORM.FAILURE" - | "SCAN_FORM.SHIPMENTS.INVALID" - | "SCAN_FORM.SHIPMENTS.REQUIRED" - | "SHIPMENT_REPORT.ALREADY_IN_PROGRESS" - | "SHIPMENT_REPORT.DATE_RANGE.INVALID" - | "SHIPMENT_REPORT.DATE_RANGE.TOO_LONG" - | "SHIPMENT.CARRIER_ACCOUNTS.CONFLICT" - | "SHIPMENT.CUSTOMS_INFO.DESCRIPTION_REQUIRED" - | "SHIPMENT.CUSTOMS_INFO.REQUIRED" - | "SHIPMENT.INSURANCE.ALREADY_PURCHASED" - | "SHIPMENT.INVALID_PARAMS" - | "SHIPMENT.INVALID" - | "SHIPMENT.MISSING_INFORMATION" - | "SHIPMENT.MISSING_RATE" - | "SHIPMENT.OPTIONS.INVALID" - | "SHIPMENT.POSTAGE.ASCII" - | "SHIPMENT.POSTAGE.EXISTS" - | "SHIPMENT.POSTAGE.FAILURE" - | "SHIPMENT.POSTAGE.FORMAT_UNAVAILABLE" - | "SHIPMENT.POSTAGE.INVALID_FORMAT" - | "SHIPMENT.POSTAGE.NO_RESPONSE" - | "SHIPMENT.POSTAGE.REQUIRED" - | "SHIPMENT.PURCHASE.FAILURE" - | "SHIPMENT.PURCHASE.IN_PROGRESS" - | "SHIPMENT.RATE.BARCODE_UNAVAILABLE" - | "SHIPMENT.RATE.CARRIER_ACCOUNT_INVALID" - | "SHIPMENT.RATE.STAMP_UNAVAILABLE" - | "SHIPMENT.RATES.UNAVAILABLE" - | "SHIPMENT.REFUND.FAILURE" - | "SHIPMENT.REFUND.UNAVAILABLE" - | "SHIPMENT.TRACKING_CODE.INVALID_CARRIER" - | "TRACKER.CARRIER_CODE_MISMATCH" - | "TRACKER.CREATE.ERROR" - | "TRACKER.INVALID_PARAMS" - | "TRACKER.INVALID_TEST_CODE" - | "TRACKER.MULTIPLE_CARRIERS_FOR_CODE" - | "TRACKER.NO_CARRIER_ACCOUNT" - | "TRACKER.NO_CARRIER_FOR_CODE" - | "TRACKER.NOT_FOUND" - | "TRACKER.RETRIEVE.ERROR" - | "TRACKER.RUN.ERROR" - | "TRACKER.UNSUPPORTED_CARRIER" - | "UNAUTHORIZED" - | "USER.CHARGE.NOT_ALLOWED" - | "USER.INVALID" - | "USER.PARENT.INVALID" - | "USER.UNAUTHORIZED" - | "WEBHOOK.EVENT.INVALID" - | "WEBHOOK.INVALID"; + | 'BATCH.FILE_FORAMT.INVALID' + | 'BATCH.PARAMS.INVALID' + | 'BATCH.SHIPMENT.MISSING' + | 'BATCH.SHIPMENT.TOO_LARGE' + | 'BATCH.SHIPMENTS.REQUIRED' + | 'BATCH.STATE.ALREADY_PURCHASED' + | 'BATCH.STATE.CREATING' + | 'BATCH.STATE.CREATION_FAILED' + | 'BATCH.STATE.NOT_PURCHASED' + | 'CARRIER_ACCOUNT.INVALID' + | 'CARRIER_ACCOUNT.PARAMETERS.INVALID' + | 'CARRIER_ACCOUNT.REGISTRATION.FAILED' + | 'CARRIER_ACCOUNT.TYPE.EXISTS' + | 'CARRIER_ACCOUNT.TYPE.UNKNOWN' + | 'CONTAINER.DIMENSION.REQUIRED' + | 'CONTAINER.NAME.REQUIRED' + | 'CONTAINER.TYPE.INVALID' + | 'CREDIT_CARD.CHARGE.FAILURE' + | 'CREDIT_CARD.INVALID' + | 'CUSTOMS_INFO.PARAMETERS.INVALID' + | 'CUSTOMS_ITEM.CURRENCY.ONE_CURRENCY_SUPPORTED' + | 'CUSTOMS_ITEM.ORIGIN_COUNTRY.REQUIRED' + | 'CUSTOMS_ITEM.PARAMETERS.INVALID' + | 'DATE.PARSE.FAILURE' + | 'DHLGM.ACCESS_TOKEN.GENERATION_FAILED' + | 'DHLGM.GIRTH_MAX' + | 'DHLGM.LABEL.FAILURE' + | 'DHLGM.LETTER_NOT_SUPPORTED' + | 'DHLGM.NO_ALCOHOL' + | 'DHLGM.NO_INTERNATIONAL' + | 'DHLGM.RATE_TABLE.NOT_FOUND' + | 'DHLGM.RETURN.AUTHORIZATION_NUMBER_REQUIRED' + | 'DHLGM.SCAN_FORM.GENERATION_FAILED' + | 'DOCUMENT.COMMERCIAL_INVOICE.FAILURE' + | 'DOCUMENT.CONVERSION.FAILURE' + | 'EMAIL_VERIFICATION.EXPIRED' + | 'EMAIL_VERIFICATION.NOT_FOUND' + | 'EMAIL_VERIFICATION.USED' + | 'FORBIDDEN' + | 'IMAGE.CONVERSION.FAILURE' + | 'IMAGE.WIDTH.INVALID' + | 'INSURANCE.AMOUNT.ABOVE_MAXIMUM' + | 'INSURANCE.AMOUNT.BELOW_MINIMUM' + | 'INSURANCE.AMOUNT.REQUIRED' + | 'INSURANCE.CREATE.FAILURE' + | 'INSURANCE.PARAMETERS.INVALID' + | 'INSURANCE.PURCHASE.FAILED' + | 'INSURANCE.PURCHASE.NOT_ALLOWED' + | 'INTERNAL_SERVER_ERROR' + | 'ITEM.HEIGHT.REQUIRED' + | 'ITEM.LENGTH.REQUIRED' + | 'ITEM.NAME.REQUIRED' + | 'ITEM.VALUE.REQUIRED' + | 'ITEM.WEIGHT.REQUIRED' + | 'ITEM.WIDTH.REQUIRED' + | 'MODE.CONFLICT' + | 'MODE.UNAUTHORIZED' + | 'NOT_ACCEPTABLE' + | 'NOT_FOUND' + | 'ORDER.CARRIER_ACCOUNTS.CONFLICT' + | 'ORDER.CARRIER.REQUIRED' + | 'ORDER.FROM_ADDRESS.REQUIRED' + | 'ORDER.INVALID' + | 'ORDER.LABEL_DATE.INVALID' + | 'ORDER.OPTIONS.INVALID' + | 'ORDER.PARAMS.REQUIRED' + | 'ORDER.RATE.UNAVAILABLE' + | 'ORDER.SERVICE.REQUIRED' + | 'ORDER.SHIPMENTS.REQUIRED' + | 'ORDER.TO_ADDRESS.REQUIRED' + | 'PARAMETER.FORBIDDEN' + | 'PARAMETER.REQUIRED' + | 'PARCEL.PARAMETERS.INVALID' + | 'PARCEL.PREDEFINED_PACKAGE.INVALID' + | 'PAYMENT_GATEWAY.ERROR' + | 'PAYMENT_REQUIRED' + | 'PICKUP.ADDRESS.INVALID' + | 'PICKUP.ADDRESS.REQUIRED' + | 'PICKUP.BATCH_CARRIER.INCONSISTENT' + | 'PICKUP.BATCH.INVALID' + | 'PICKUP.BATCH.REQUIRED' + | 'PICKUP.BUY.FAILED' + | 'PICKUP.BUY.FORBIDDEN' + | 'PICKUP.BUY.NO_MATCHING_RATES' + | 'PICKUP.CANCEL.FAILED' + | 'PICKUP.CARRIER.REQUIRED' + | 'PICKUP.IS_ACCOUNT_ADDRESS.REQUIRED' + | 'PICKUP.MAX_DATETIME.REQUIRED' + | 'PICKUP.MIN_DATETIME.REQUIRED' + | 'PICKUP.REQUEST.INVALID' + | 'PICKUP.SERVICE.REQUIRED' + | 'PICKUP.SHIPMENT_COUNTRY.INVALID' + | 'PICKUP.SHIPMENT_SERVICE.INVALID' + | 'PICKUP.STATUS.INVALID' + | 'REFUND.FAILURE' + | 'REFUND.NO_RESPONSE' + | 'REFUND.TRACKING_CODE.NOT_FOUND' + | 'REFUND.TRACKING_CODES.INVALID' + | 'SCAN_FORM.BATCH.MULTIPLE_CARRIERS' + | 'SCAN_FORM.BATCH.NOT_PURCHASED' + | 'SCAN_FORM.CREATE.CARRIER_NOT_SUPPORTED' + | 'SCAN_FORM.CREATE.FAILURE' + | 'SCAN_FORM.FAILURE' + | 'SCAN_FORM.SHIPMENTS.INVALID' + | 'SCAN_FORM.SHIPMENTS.REQUIRED' + | 'SHIPMENT_REPORT.ALREADY_IN_PROGRESS' + | 'SHIPMENT_REPORT.DATE_RANGE.INVALID' + | 'SHIPMENT_REPORT.DATE_RANGE.TOO_LONG' + | 'SHIPMENT.CARRIER_ACCOUNTS.CONFLICT' + | 'SHIPMENT.CUSTOMS_INFO.DESCRIPTION_REQUIRED' + | 'SHIPMENT.CUSTOMS_INFO.REQUIRED' + | 'SHIPMENT.INSURANCE.ALREADY_PURCHASED' + | 'SHIPMENT.INVALID_PARAMS' + | 'SHIPMENT.INVALID' + | 'SHIPMENT.MISSING_INFORMATION' + | 'SHIPMENT.MISSING_RATE' + | 'SHIPMENT.OPTIONS.INVALID' + | 'SHIPMENT.POSTAGE.ASCII' + | 'SHIPMENT.POSTAGE.EXISTS' + | 'SHIPMENT.POSTAGE.FAILURE' + | 'SHIPMENT.POSTAGE.FORMAT_UNAVAILABLE' + | 'SHIPMENT.POSTAGE.INVALID_FORMAT' + | 'SHIPMENT.POSTAGE.NO_RESPONSE' + | 'SHIPMENT.POSTAGE.REQUIRED' + | 'SHIPMENT.PURCHASE.FAILURE' + | 'SHIPMENT.PURCHASE.IN_PROGRESS' + | 'SHIPMENT.RATE.BARCODE_UNAVAILABLE' + | 'SHIPMENT.RATE.CARRIER_ACCOUNT_INVALID' + | 'SHIPMENT.RATE.STAMP_UNAVAILABLE' + | 'SHIPMENT.RATES.UNAVAILABLE' + | 'SHIPMENT.REFUND.FAILURE' + | 'SHIPMENT.REFUND.UNAVAILABLE' + | 'SHIPMENT.TRACKING_CODE.INVALID_CARRIER' + | 'TRACKER.CARRIER_CODE_MISMATCH' + | 'TRACKER.CREATE.ERROR' + | 'TRACKER.INVALID_PARAMS' + | 'TRACKER.INVALID_TEST_CODE' + | 'TRACKER.MULTIPLE_CARRIERS_FOR_CODE' + | 'TRACKER.NO_CARRIER_ACCOUNT' + | 'TRACKER.NO_CARRIER_FOR_CODE' + | 'TRACKER.NOT_FOUND' + | 'TRACKER.RETRIEVE.ERROR' + | 'TRACKER.RUN.ERROR' + | 'TRACKER.UNSUPPORTED_CARRIER' + | 'UNAUTHORIZED' + | 'USER.CHARGE.NOT_ALLOWED' + | 'USER.INVALID' + | 'USER.PARENT.INVALID' + | 'USER.UNAUTHORIZED' + | 'WEBHOOK.EVENT.INVALID' + | 'WEBHOOK.INVALID'; diff --git a/src/utils/errors/index.ts b/src/utils/errors/index.ts index 2f9c81d69..d6c2ac5d8 100644 --- a/src/utils/errors/index.ts +++ b/src/utils/errors/index.ts @@ -1,3 +1,3 @@ -export * from "./Error"; -export * from "./ErrorCode"; -export * from "./FieldError"; +export * from './Error'; +export * from './ErrorCode'; +export * from './FieldError'; diff --git a/src/utils/types.ts b/src/utils/types.ts index 57edee93e..dcc31ad83 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -2,12 +2,7 @@ export type DeepPartial = { [P in keyof T]?: DeepPartial; }; -export type ParametersToOmitOnCreate = - | "id" - | "object" - | "mode" - | "created_at" - | "updated_at"; +export type ParametersToOmitOnCreate = 'id' | 'object' | 'mode' | 'created_at' | 'updated_at'; export type IAllMethodParameters = { /** @@ -68,7 +63,7 @@ export type IObjectWithId = IBaseObject & { /** * Set based on which api-key you used, either "test" or "production" */ - mode: "test" | "production"; + mode: 'test' | 'production'; /** * The object name, e.g. "Address", "Rate", "Shipment", etc diff --git a/src/utils/util.ts b/src/utils/util.ts index aad3877e0..2b7e35d47 100644 --- a/src/utils/util.ts +++ b/src/utils/util.ts @@ -1,10 +1,10 @@ -import crypto from "node:crypto"; -import util from "node:util"; -import Constants from "../constants"; -import FilteringError from "../errors/general/filtering_error"; -import InvalidParameterError from "../errors/general/invalid_parameter_error"; -import SignatureVerificationError from "../errors/general/signature_verification_error"; -import { IRate, ISmartRate } from "../services/rate_service"; +import crypto from 'node:crypto'; +import util from 'node:util'; +import Constants from '../constants'; +import FilteringError from '../errors/general/filtering_error'; +import InvalidParameterError from '../errors/general/invalid_parameter_error'; +import SignatureVerificationError from '../errors/general/signature_verification_error'; +import { IRate, ISmartRate } from '../services/rate_service'; /** * Utility class of various publicly-available helper functions. @@ -25,33 +25,31 @@ export default class Utils { getLowestSmartRate( smartRates: ISmartRate[], deliveryDays: number, - deliveryAccuracy: keyof ISmartRate["time_in_transit"] + deliveryAccuracy: keyof ISmartRate['time_in_transit'], ): ISmartRate { const validDeliveryAccuracyValues = new Set([ - "percentile_50", - "percentile_75", - "percentile_85", - "percentile_90", - "percentile_95", - "percentile_97", - "percentile_99", + 'percentile_50', + 'percentile_75', + 'percentile_85', + 'percentile_90', + 'percentile_95', + 'percentile_97', + 'percentile_99', ]); let lowestSmartRate: ISmartRate | null = null; const lowercaseDeliveryAccuracy = - deliveryAccuracy.toLowerCase() as keyof ISmartRate["time_in_transit"]; + deliveryAccuracy.toLowerCase() as keyof ISmartRate['time_in_transit']; if (!validDeliveryAccuracyValues.has(lowercaseDeliveryAccuracy)) { throw new InvalidParameterError({ message: `Invalid deliveryAccuracy value, must be one of: ${[ ...validDeliveryAccuracyValues, - ].join(", ")}`, + ].join(', ')}`, }); } for (const rate of smartRates) { - if ( - rate.time_in_transit[lowercaseDeliveryAccuracy] > Number(deliveryDays) - ) { + if (rate.time_in_transit[lowercaseDeliveryAccuracy] > Number(deliveryDays)) { // eslint-disable-next-line no-continue continue; } else if ( @@ -64,7 +62,7 @@ export default class Utils { if (lowestSmartRate === null) { throw new FilteringError({ - message: util.format(Constants.NO_OBJECT_FOUND, "rates"), + message: util.format(Constants.NO_OBJECT_FOUND, 'rates'), }); } @@ -83,27 +81,23 @@ export default class Utils { getLowestRate( rates: IRate[], carriers: string[] | null = null, - services: string[] | null = null + services: string[] | null = null, ): IRate { if (carriers) { const carriersLower = carriers.map((carrier) => carrier.toLowerCase()); // eslint-disable-next-line no-param-reassign - rates = rates.filter((rate) => - carriersLower.includes(rate.carrier.toLowerCase()) - ); + rates = rates.filter((rate) => carriersLower.includes(rate.carrier.toLowerCase())); } if (services) { const servicesLower = services.map((service) => service.toLowerCase()); // eslint-disable-next-line no-param-reassign - rates = rates.filter((rate) => - servicesLower.includes(rate.service.toLowerCase()) - ); + rates = rates.filter((rate) => servicesLower.includes(rate.service.toLowerCase())); } if (rates.length === 0) { throw new FilteringError({ - message: util.format(Constants.NO_OBJECT_FOUND, "rates"), + message: util.format(Constants.NO_OBJECT_FOUND, 'rates'), }); } @@ -128,32 +122,28 @@ export default class Utils { * @returns - The JSON-parsed webhook event body if the signature could be verified * @throws {SignatureVerificationError} - If the signature could not be verified */ - validateWebhook( - eventBody: Buffer, - headers: Record, - webhookSecret: string - ): any { + validateWebhook(eventBody: Buffer, headers: Record, webhookSecret: string): any { let webhook = {}; const easypostHmacSignature = - headers["X-Hmac-Signature"] ?? headers["x-hmac-signature"] ?? null; + headers['X-Hmac-Signature'] ?? headers['x-hmac-signature'] ?? null; if (easypostHmacSignature != null) { - const normalizedSecret = webhookSecret.normalize("NFKD"); - const encodedSecret = Buffer.from(normalizedSecret, "utf8"); + const normalizedSecret = webhookSecret.normalize('NFKD'); + const encodedSecret = Buffer.from(normalizedSecret, 'utf8'); const expectedSignature = crypto - .createHmac("sha256", encodedSecret) + .createHmac('sha256', encodedSecret) // @ts-ignore buffers are weird - .update(eventBody, "utf-8") - .digest("hex"); + .update(eventBody, 'utf-8') + .digest('hex'); const digest = `hmac-sha256-hex=${expectedSignature}`; try { if ( crypto.timingSafeEqual( - Buffer.from(easypostHmacSignature, "utf8"), - Buffer.from(digest, "utf8") + Buffer.from(easypostHmacSignature, 'utf8'), + Buffer.from(digest, 'utf8'), ) ) { webhook = JSON.parse(eventBody.toString()); diff --git a/test/services/address.test.js b/test/services/address.test.js index bf6fe1950..fd22ed505 100644 --- a/test/services/address.test.js +++ b/test/services/address.test.js @@ -1,8 +1,8 @@ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; -import InvalidRequestError from '../../out/src/errors/api/invalid_request_error'; -import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; +import EasyPostClient from '../../out/easypost'; +import InvalidRequestError from '../../out/errors/api/invalid_request_error'; +import EndOfPaginationError from '../../out/errors/general/end_of_pagination_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; diff --git a/test/services/api_key.test.js b/test/services/api_key.test.js index 7b428e822..88fd88c93 100644 --- a/test/services/api_key.test.js +++ b/test/services/api_key.test.js @@ -1,9 +1,9 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import * as setupPolly from '../helpers/setup_polly'; -import FilteringError from '../../out/src/errors/general/filtering_error'; +import FilteringError from '../../out/errors/general/filtering_error'; describe('ApiKey Service', function () { setupPolly.startPolly(); diff --git a/test/services/base_service.test.js b/test/services/base_service.test.js index 2cfadb736..18ea983bd 100644 --- a/test/services/base_service.test.js +++ b/test/services/base_service.test.js @@ -1,8 +1,8 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; -import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; +import EasyPostClient from '../../out/easypost'; +import EndOfPaginationError from '../../out/errors/general/end_of_pagination_error'; import * as setupPolly from '../helpers/setup_polly'; import { MockMiddleware, diff --git a/test/services/batch.test.js b/test/services/batch.test.js index 2827c3c92..fe69bb344 100644 --- a/test/services/batch.test.js +++ b/test/services/batch.test.js @@ -3,7 +3,7 @@ import fs from 'fs'; import { resolve } from 'path'; import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; diff --git a/test/services/beta_rate.test.js b/test/services/beta_rate.test.js index f58cbcea8..a2f91bb0f 100644 --- a/test/services/beta_rate.test.js +++ b/test/services/beta_rate.test.js @@ -1,7 +1,7 @@ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; -import FilteringError from '../../out/src/errors/general/filtering_error'; +import EasyPostClient from '../../out/easypost'; +import FilteringError from '../../out/errors/general/filtering_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; diff --git a/test/services/beta_referral_customer.test.js b/test/services/beta_referral_customer.test.js index 7551c4602..f768b63ab 100644 --- a/test/services/beta_referral_customer.test.js +++ b/test/services/beta_referral_customer.test.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import * as setupPolly from '../helpers/setup_polly'; describe('BetaReferralCustomerService', function () { diff --git a/test/services/billing.test.js b/test/services/billing.test.js index aad0e608a..32f92df6b 100644 --- a/test/services/billing.test.js +++ b/test/services/billing.test.js @@ -1,7 +1,7 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import { MockMiddleware, MockRequest, diff --git a/test/services/carrier_account.test.js b/test/services/carrier_account.test.js index c857cde94..89a496115 100644 --- a/test/services/carrier_account.test.js +++ b/test/services/carrier_account.test.js @@ -1,7 +1,7 @@ /* eslint-disable no-param-reassign */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; diff --git a/test/services/carrier_metadata.test.js b/test/services/carrier_metadata.test.js index eb4aa000e..c616f847a 100644 --- a/test/services/carrier_metadata.test.js +++ b/test/services/carrier_metadata.test.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import * as setupPolly from '../helpers/setup_polly'; /* eslint-disable func-names */ diff --git a/test/services/carrier_type.test.js b/test/services/carrier_type.test.js index 8232aff8e..407225909 100644 --- a/test/services/carrier_type.test.js +++ b/test/services/carrier_type.test.js @@ -1,7 +1,7 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import * as setupPolly from '../helpers/setup_polly'; describe('CarrierType Service', function () { diff --git a/test/services/customs_info.test.js b/test/services/customs_info.test.js index 4550f4489..bc042f876 100644 --- a/test/services/customs_info.test.js +++ b/test/services/customs_info.test.js @@ -1,7 +1,7 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; diff --git a/test/services/customs_item.test.js b/test/services/customs_item.test.js index 871e08c52..e14ac58bd 100644 --- a/test/services/customs_item.test.js +++ b/test/services/customs_item.test.js @@ -1,7 +1,7 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPost from '../../out/src/easypost'; +import EasyPost from '../../out/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; diff --git a/test/services/easypost.test.js b/test/services/easypost.test.js index efd738a4e..2f573a70b 100644 --- a/test/services/easypost.test.js +++ b/test/services/easypost.test.js @@ -1,7 +1,7 @@ import { expect } from 'chai'; -import EasyPost, { METHODS } from '../../out/src/easypost'; -import MissingParameterError from '../../out/src/errors/general/missing_parameter_error'; +import EasyPost, { METHODS } from '../../out/easypost'; +import MissingParameterError from '../../out/errors/general/missing_parameter_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; diff --git a/test/services/end_shipper.test.js b/test/services/end_shipper.test.js index bf466fb07..eb70832e0 100644 --- a/test/services/end_shipper.test.js +++ b/test/services/end_shipper.test.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; diff --git a/test/services/error.test.js b/test/services/error.test.js index fea61daad..dd8907bc0 100644 --- a/test/services/error.test.js +++ b/test/services/error.test.js @@ -1,20 +1,20 @@ import { assert, expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; -import ForbiddenError from '../../out/src/errors/api/forbidden_error'; -import GatewayTimeoutError from '../../out/src/errors/api/gateway_timeout_error'; -import InternalServerError from '../../out/src/errors/api/internal_server_error'; -import InvalidRequestError from '../../out/src/errors/api/invalid_request_error'; -import MethodNotAllowedError from '../../out/src/errors/api/method_not_allowed_error'; -import NotFoundError from '../../out/src/errors/api/not_found_error'; -import PaymentError from '../../out/src/errors/api/payment_error'; -import RateLimitError from '../../out/src/errors/api/rate_limit_error'; -import RedirectError from '../../out/src/errors/api/redirect_error'; -import ServiceUnavailableError from '../../out/src/errors/api/service_unavailable_error'; -import TimeoutError from '../../out/src/errors/api/timeout_error'; -import UnauthorizedError from '../../out/src/errors/api/unauthorized_error'; -import UnknownApiError from '../../out/src/errors/api/unknown_api_error'; -import ErrorHandler from '../../out/src/errors/error_handler'; +import EasyPostClient from '../../out/easypost'; +import ForbiddenError from '../../out/errors/api/forbidden_error'; +import GatewayTimeoutError from '../../out/errors/api/gateway_timeout_error'; +import InternalServerError from '../../out/errors/api/internal_server_error'; +import InvalidRequestError from '../../out/errors/api/invalid_request_error'; +import MethodNotAllowedError from '../../out/errors/api/method_not_allowed_error'; +import NotFoundError from '../../out/errors/api/not_found_error'; +import PaymentError from '../../out/errors/api/payment_error'; +import RateLimitError from '../../out/errors/api/rate_limit_error'; +import RedirectError from '../../out/errors/api/redirect_error'; +import ServiceUnavailableError from '../../out/errors/api/service_unavailable_error'; +import TimeoutError from '../../out/errors/api/timeout_error'; +import UnauthorizedError from '../../out/errors/api/unauthorized_error'; +import UnknownApiError from '../../out/errors/api/unknown_api_error'; +import ErrorHandler from '../../out/errors/error_handler'; import * as setupPolly from '../helpers/setup_polly'; describe('Error Service', function () { diff --git a/test/services/event.test.js b/test/services/event.test.js index 91cda1eb6..4273ae696 100644 --- a/test/services/event.test.js +++ b/test/services/event.test.js @@ -3,11 +3,11 @@ import fs from 'fs'; import { resolve } from 'path'; import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; -import NotFoundError from '../../out/src/errors/api/not_found_error'; -import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; +import NotFoundError from '../../out/errors/api/not_found_error'; +import EndOfPaginationError from '../../out/errors/general/end_of_pagination_error'; describe('Event Service', function () { setupPolly.startPolly(); diff --git a/test/services/insurance.test.js b/test/services/insurance.test.js index 71cfa9ad7..95775fd8d 100644 --- a/test/services/insurance.test.js +++ b/test/services/insurance.test.js @@ -1,8 +1,8 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; -import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; +import EasyPostClient from '../../out/easypost'; +import EndOfPaginationError from '../../out/errors/general/end_of_pagination_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; diff --git a/test/services/order.test.js b/test/services/order.test.js index 3c6943931..c3e0df67a 100644 --- a/test/services/order.test.js +++ b/test/services/order.test.js @@ -1,8 +1,8 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; -import FilteringError from '../../out/src/errors/general/filtering_error'; +import EasyPostClient from '../../out/easypost'; +import FilteringError from '../../out/errors/general/filtering_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; diff --git a/test/services/parcel.test.js b/test/services/parcel.test.js index 6b8e6aa9c..f6ddd5a55 100644 --- a/test/services/parcel.test.js +++ b/test/services/parcel.test.js @@ -1,7 +1,7 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; diff --git a/test/services/pickup.test.js b/test/services/pickup.test.js index 8cd95f15b..70ebc4020 100644 --- a/test/services/pickup.test.js +++ b/test/services/pickup.test.js @@ -1,11 +1,11 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import Fixture from '../helpers/fixture'; -import FilteringError from '../../out/src/errors/general/filtering_error'; +import FilteringError from '../../out/errors/general/filtering_error'; import * as setupPolly from '../helpers/setup_polly'; -import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; +import EndOfPaginationError from '../../out/errors/general/end_of_pagination_error'; import { withoutParams } from '../helpers/utils'; describe('Pickup Service', function () { diff --git a/test/services/rate.test.js b/test/services/rate.test.js index c6018929e..be198c7b6 100644 --- a/test/services/rate.test.js +++ b/test/services/rate.test.js @@ -1,7 +1,7 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; diff --git a/test/services/referral_customer.test.js b/test/services/referral_customer.test.js index e563d189a..276742ac3 100644 --- a/test/services/referral_customer.test.js +++ b/test/services/referral_customer.test.js @@ -1,7 +1,7 @@ import { expect } from 'chai'; -import EasyPost from '../../out/src/easypost'; -import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; +import EasyPost from '../../out/easypost'; +import EndOfPaginationError from '../../out/errors/general/end_of_pagination_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; diff --git a/test/services/refund.test.js b/test/services/refund.test.js index 3d9434a92..4eafb9710 100644 --- a/test/services/refund.test.js +++ b/test/services/refund.test.js @@ -1,8 +1,8 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; -import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; +import EasyPostClient from '../../out/easypost'; +import EndOfPaginationError from '../../out/errors/general/end_of_pagination_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; diff --git a/test/services/report.test.js b/test/services/report.test.js index 11dd410f0..6c72f2910 100644 --- a/test/services/report.test.js +++ b/test/services/report.test.js @@ -1,8 +1,8 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; -import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; +import EasyPostClient from '../../out/easypost'; +import EndOfPaginationError from '../../out/errors/general/end_of_pagination_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; diff --git a/test/services/scan_form.test.js b/test/services/scan_form.test.js index 0c77c0e83..b9f1694de 100644 --- a/test/services/scan_form.test.js +++ b/test/services/scan_form.test.js @@ -1,8 +1,8 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; -import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; +import EasyPostClient from '../../out/easypost'; +import EndOfPaginationError from '../../out/errors/general/end_of_pagination_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; diff --git a/test/services/shipment.test.js b/test/services/shipment.test.js index 6a642ea7c..a9e980184 100644 --- a/test/services/shipment.test.js +++ b/test/services/shipment.test.js @@ -1,9 +1,9 @@ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; -import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; -import FilteringError from '../../out/src/errors/general/filtering_error'; -import InvalidParameterError from '../../out/src/errors/general/invalid_parameter_error'; +import EasyPostClient from '../../out/easypost'; +import EndOfPaginationError from '../../out/errors/general/end_of_pagination_error'; +import FilteringError from '../../out/errors/general/filtering_error'; +import InvalidParameterError from '../../out/errors/general/invalid_parameter_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; diff --git a/test/services/tracker.test.js b/test/services/tracker.test.js index f2bee23f7..92554210d 100644 --- a/test/services/tracker.test.js +++ b/test/services/tracker.test.js @@ -1,8 +1,8 @@ /* eslint-disable func-names */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; -import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; +import EasyPostClient from '../../out/easypost'; +import EndOfPaginationError from '../../out/errors/general/end_of_pagination_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; diff --git a/test/services/user.test.js b/test/services/user.test.js index 3ccc7ee6b..426b0a740 100644 --- a/test/services/user.test.js +++ b/test/services/user.test.js @@ -1,10 +1,10 @@ /* eslint-disable no-param-reassign */ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import * as setupPolly from '../helpers/setup_polly'; import Fixture from '../helpers/fixture'; -import EndOfPaginationError from '../../out/src/errors/general/end_of_pagination_error'; +import EndOfPaginationError from '../../out/errors/general/end_of_pagination_error'; /* eslint-disable func-names */ describe('User Service', function () { diff --git a/test/services/webhook.test.js b/test/services/webhook.test.js index 71a9be80b..533011d58 100644 --- a/test/services/webhook.test.js +++ b/test/services/webhook.test.js @@ -1,8 +1,8 @@ import { expect } from 'chai'; -import EasyPostClient from '../../out/src/easypost'; +import EasyPostClient from '../../out/easypost'; import Fixture from '../helpers/fixture'; -import SignatureVerificationError from '../../out/src/errors/general/signature_verification_error'; +import SignatureVerificationError from '../../out/errors/general/signature_verification_error'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; diff --git a/tsconfig.json b/tsconfig.json index 265b221e0..aaf2751e8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,10 @@ "resolveJsonModule": true, "strictPropertyInitialization": false, "downlevelIteration": true, - "outDir": "./out" + "outDir": "./out", + "declaration": true, + "declarationDir": "./types", + "rootDir": "./src" }, "include": ["./src"] } diff --git a/types/constants.d.ts b/types/constants.d.ts new file mode 100644 index 000000000..2e9caa299 --- /dev/null +++ b/types/constants.d.ts @@ -0,0 +1,20 @@ +import Utils from './utils/util'; +/** + * A class containing constants used throughout the EasyPost Node.js client library. + */ +export default class Constants { + static get CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS(): string[]; + static EXTERNAL_API_CALL_FAILED: string; + static INVALID_API_KEY_TYPE: string; + static INVALID_PARAMETER: string; + static INVALID_PAYMENT: string; + static INVALID_WEBHOOK_SIGNATURE: string; + static MISSING_REQUIRED_PARAMETER: string; + static NO_OBJECT_FOUND: string; + static NO_PAYMENT_METHODS: string; + static API_DID_NOT_RETURN_ERROR_DETAILS: string; + static WEBHOOK_DOES_NOT_MATCH: string; + static END_OF_PAGINATION: string; + static ERROR_DESERIALIZATION: string; + static Utils: Utils; +} diff --git a/types/easypost.d.ts b/types/easypost.d.ts new file mode 100644 index 000000000..e9b390ae5 --- /dev/null +++ b/types/easypost.d.ts @@ -0,0 +1,260 @@ +import { SuperAgentStatic, Request, Response } from 'superagent'; +import AddressService from './services/address_service'; +import ApiKeyService from './services/api_key_service'; +import BatchService from './services/batch_service'; +import BetaRateService from './services/beta_rate_service'; +import BetaReferralCustomerService from './services/beta_referral_customer_service'; +import BillingService from './services/billing_service'; +import CarrierAccountService from './services/carrier_account_service'; +import CarrierMetadataService from './services/carrier_metadata_service'; +import CarrierTypeService from './services/carrier_type_service'; +import CustomsInfoService from './services/customs_info_service'; +import CustomsItemService from './services/customs_item_service'; +import EndShipperService from './services/end_shipper_service'; +import EventService from './services/event_service'; +import InsuranceService from './services/insurance_service'; +import OrderService from './services/order_service'; +import ParcelService from './services/parcel_service'; +import PickupService from './services/pickup_service'; +import RateService from './services/rate_service'; +import ReferralCustomerService from './services/referral_customer_service'; +import RefundService from './services/refund_service'; +import ReportService from './services/report_service'; +import ScanFormService from './services/scan_form_service'; +import ShipmentService from './services/shipment_service'; +import TrackerService from './services/tracker_service'; +import UserService from './services/user_service'; +import WebhookService from './services/webhook_service'; +import Utils from './utils/util'; +export * from './errors'; +export * from './services'; +export * from './utils/errors'; +export * from './constants'; +/** How many milliseconds in a second. */ +export declare const MS_SECOND = 1000; +/** The default timeout for all EasyPost API requests. */ +export declare const DEFAULT_TIMEOUT: number; +/** The default base URL for all production EasyPost API requests. */ +export declare const DEFAULT_BASE_URL = 'https://api.easypost.com/v2/'; +/** The default headers used for all EasyPost API requests. */ +export declare const DEFAULT_HEADERS: { + Accept: string; + 'Content-Type': string; + 'User-Agent': string; +}; +/** A map of HTTP methods to their corresponding string values (for use with superagent). */ +export declare const METHODS: { + readonly GET: 'get'; + readonly POST: 'post'; + readonly PUT: 'put'; + readonly PATCH: 'patch'; + readonly DELETE: 'del'; +}; +export type EasyPostClientOptions = { + useProxy?: boolean; + timeout?: number; + baseUrl?: string; + superagentMiddleware?: (agent: SuperAgentStatic) => SuperAgentStatic; + requestMiddleware?: (request: Request) => Request; + agent?: SuperAgentStatic; +}; +export type RequestHookData = { + method: (typeof METHODS)[keyof typeof METHODS]; + path: string; + requestBody: any; + headers: Record; + requestTimestamp: number; + requestUUID: string; +}; +export type RequestHook = (data: RequestHookData) => void; +export type ResponseHookData = RequestHookData & { + requestHeaders: Record; + httpStatus: Response['status']; + responseBody: Response['body']; + headers: Response['headers']; + responseTimestamp: number; +}; +export type ResponseHook = (data: ResponseHookData) => void; +/** + * The client used to access services of the EasyPost API. + * This client is configured to use the latest production version of the EasyPost API. + * @param {string} key The API key to use for API requests made by this client. + * @param {EasyPostClientOptions} [options] Additional options to use for the underlying HTTP client (e.g. superagent, middleware, proxy configuration). + */ +export default class EasyPostClient { + useProxy: boolean; + key: string; + timeout: number; + baseUrl: string; + agent: SuperAgentStatic; + requestMiddleware: ((request: Request) => Request) | undefined; + requestHooks: RequestHook[]; + responseHooks: ResponseHook[]; + Utils: Utils; + Address: ReturnType; + ApiKey: ReturnType; + Batch: ReturnType; + BetaRate: ReturnType; + BetaReferralCustomer: ReturnType; + Billing: ReturnType; + CarrierAccount: ReturnType; + CarrierMetadata: ReturnType; + CarrierType: ReturnType; + CustomsInfo: ReturnType; + CustomsItem: ReturnType; + EndShipper: ReturnType; + Event: ReturnType; + Insurance: ReturnType; + Order: ReturnType; + Parcel: ReturnType; + Pickup: ReturnType; + Rate: ReturnType; + ReferralCustomer: ReturnType; + Refund: ReturnType; + Report: ReturnType; + ScanForm: ReturnType; + Shipment: ReturnType; + Tracker: ReturnType; + User: ReturnType; + Webhook: ReturnType; + constructor(key: string, options?: EasyPostClientOptions); + /** + * Add a request hook function. + * @param {(config: object) => void} hook + */ + addRequestHook(hook: RequestHook): void; + /** + * Remove a request hook function. + * @param {(config: object) => void} hook + */ + removeRequestHook(hook: RequestHook): void; + /** + * Clear all request hooks. + */ + clearRequestHooks(): void; + /** + * Add a response hook function. + * @param {(config: object) => void} hook + */ + addResponseHook(hook: ResponseHook): void; + /** + * Remove a response hook function. + * @param {(config: object) => void} hook + */ + removeResponseHook(hook: ResponseHook): void; + /** + * Clear all response hooks. + */ + clearResponseHooks(): void; + /** + * Create a copy of an {@link EasyPostClient} with overridden options. + * @param {EasyPostClient} client The `EasyPostClient` instance to clone. + * @param {Object} [options] The options to override. + * @returns {EasyPostClient} A new `EasyPostClient` instance. + */ + static copyClient( + client: EasyPostClient, + options?: EasyPostClientOptions & { + apiKey?: string; + }, + ): EasyPostClient; + /** + * Build request headers to be sent with each EasyPost API request, combined (or overridden) by any additional headers + * @param {Object} [additionalHeaders] Additional headers to combine or override with the default headers. + * @returns {Object} The headers to use for the request. + */ + static _buildHeaders(additionalHeaders?: {}): { + Accept: string; + 'Content-Type': string; + 'User-Agent': string; + }; + /** + * If the path passed in is a full URI, use it; otherwise, prepend the base url from the api. + * @param {string} path - The path to build. + * @returns {string} The full path to use for the HTTP request. + */ + _buildPath(path?: string): string; + /** + * Create a value to be passed to the responseHooks, based on the requestHooks + * value and the response. + * @param {Object} baseHooksValue - the value being passed the requestHooks + * @param {Object} response - the response from the superagent request + * @returns {Object} - the value to be passed to the responseHooks + */ + _createResponseHooksValue(baseHooksValue: RequestHookData, response: Response): ResponseHookData; + /** + * Make an HTTP request. + * @param [path] - The partial path to append to the base url for the request. + * @param [method] - The HTTP method to use for the request, defaults to GET. + * @param [params] - The parameters to send with the request. + * @param [headers] - Additional headers to send with the request. + * @returns The response from the HTTP request. + * @throws {ApiError} If the request fails. + */ + _request( + path?: string, + method?: (typeof METHODS)[keyof typeof METHODS], + params?: Record, + headers?: Record, + ): Promise; + /** + * Make a GET HTTP request. + * @param path - The partial path to append to the base url for the request. + * @param [params] - The parameters to send with the request. + * @param [headers] - Additional headers to send with the request. + * @returns The response from the HTTP request. + */ + _get( + path: string, + params?: Record, + headers?: Record, + ): Promise; + /** + * Make a POST HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + _post( + path: string, + params?: any, + headers?: Record, + ): Promise; + /** + * Make a PUT HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + _put( + path: string, + params?: any, + headers?: Record, + ): Promise; + /** + * Make a PATCH HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + _patch( + path: string, + params?: any, + headers?: Record, + ): Promise; + /** + * Make a DELETE HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + _delete( + path: string, + params?: any, + headers?: Record, + ): Promise; +} diff --git a/types/errors/api/api_error.d.ts b/types/errors/api/api_error.d.ts new file mode 100644 index 000000000..1c0e08efb --- /dev/null +++ b/types/errors/api/api_error.d.ts @@ -0,0 +1,29 @@ +import EasyPostError from '../easypost_error'; +/** + * The ApiError class is used to represent errors that occurred while communicating with the EasyPost API. + * This class should not be instantiated directly. + * @internal + * @abstract + * @extends EasyPostError + * @property {string} [message] - The message to be displayed when the error is logged. + * @property {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @property {number} [statusCode] - The HTTP status code returned by the HTTP request to the EasyPost API. + * @property {EasyPostError[]} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class ApiError extends EasyPostError { + code: string | undefined; + errors: EasyPostError[] | undefined; + message: string | undefined; + statusCode: number | undefined; + constructor({ + message, + code, + statusCode, + errors, + }?: { + message?: string; + code?: string; + statusCode?: number; + errors?: EasyPostError[]; + }); +} diff --git a/types/errors/api/bad_request_error.d.ts b/types/errors/api/bad_request_error.d.ts new file mode 100644 index 000000000..a8a3391a5 --- /dev/null +++ b/types/errors/api/bad_request_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The BadRequestError class is used to represent a 400 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class BadRequestError extends ApiError {} diff --git a/types/errors/api/external_api_error.d.ts b/types/errors/api/external_api_error.d.ts new file mode 100644 index 000000000..c3bb01401 --- /dev/null +++ b/types/errors/api/external_api_error.d.ts @@ -0,0 +1,9 @@ +import ApiError from './api_error'; +/** + * The ExternalApiError class is used to represent errors that occurred while communicating with an external API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + */ +export default class ExternalApiError extends ApiError {} diff --git a/types/errors/api/forbidden_error.d.ts b/types/errors/api/forbidden_error.d.ts new file mode 100644 index 000000000..f8d9b064e --- /dev/null +++ b/types/errors/api/forbidden_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The ForbiddenError class is used to represent a 403 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class ForbiddenError extends ApiError {} diff --git a/types/errors/api/gateway_timeout_error.d.ts b/types/errors/api/gateway_timeout_error.d.ts new file mode 100644 index 000000000..1ceec87e7 --- /dev/null +++ b/types/errors/api/gateway_timeout_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The GatewayTimeoutError class is used to represent a 504 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class GatewayTimeoutError extends ApiError {} diff --git a/types/errors/api/http_error.d.ts b/types/errors/api/http_error.d.ts new file mode 100644 index 000000000..acaac4c4b --- /dev/null +++ b/types/errors/api/http_error.d.ts @@ -0,0 +1,10 @@ +import ApiError from './api_error'; +/** + * The HttpError class is used to represent a generic HTTP-related error that occurred while communicating with the EasyPost API. + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class HTTPError extends ApiError {} diff --git a/types/errors/api/index.d.ts b/types/errors/api/index.d.ts new file mode 100644 index 000000000..6ac9ac6b3 --- /dev/null +++ b/types/errors/api/index.d.ts @@ -0,0 +1,18 @@ +export * from './api_error'; +export * from './bad_request_error'; +export * from './external_api_error'; +export * from './forbidden_error'; +export * from './gateway_timeout_error'; +export * from './http_error'; +export * from './index'; +export * from './internal_server_error'; +export * from './invalid_request_error'; +export * from './method_not_allowed_error'; +export * from './not_found_error'; +export * from './payment_error'; +export * from './rate_limit_error'; +export * from './redirect_error'; +export * from './service_unavailable_error'; +export * from './timeout_error'; +export * from './unauthorized_error'; +export * from './unknown_api_error'; diff --git a/types/errors/api/internal_server_error.d.ts b/types/errors/api/internal_server_error.d.ts new file mode 100644 index 000000000..946d7e0fa --- /dev/null +++ b/types/errors/api/internal_server_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The InternalServerError class is used to represent a 500 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class InternalServerError extends ApiError {} diff --git a/types/errors/api/invalid_request_error.d.ts b/types/errors/api/invalid_request_error.d.ts new file mode 100644 index 000000000..0e87d346d --- /dev/null +++ b/types/errors/api/invalid_request_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The InvalidRequestError class is used to represent a 422 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class InvalidRequestError extends ApiError {} diff --git a/types/errors/api/method_not_allowed_error.d.ts b/types/errors/api/method_not_allowed_error.d.ts new file mode 100644 index 000000000..fd29b3cbc --- /dev/null +++ b/types/errors/api/method_not_allowed_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The MethodNotAllowedError class is used to represent a 405 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class MethodNotAllowedError extends ApiError {} diff --git a/types/errors/api/not_found_error.d.ts b/types/errors/api/not_found_error.d.ts new file mode 100644 index 000000000..5e2a4262b --- /dev/null +++ b/types/errors/api/not_found_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The NotFoundError class is used to represent a 404 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class NotFoundError extends ApiError {} diff --git a/types/errors/api/payment_error.d.ts b/types/errors/api/payment_error.d.ts new file mode 100644 index 000000000..081039ad8 --- /dev/null +++ b/types/errors/api/payment_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The PaymentError class is used to represent a 402 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class PaymentError extends ApiError {} diff --git a/types/errors/api/rate_limit_error.d.ts b/types/errors/api/rate_limit_error.d.ts new file mode 100644 index 000000000..3ae7f08f9 --- /dev/null +++ b/types/errors/api/rate_limit_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The RateLimitError class is used to represent a 429 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class RateLimitError extends ApiError {} diff --git a/types/errors/api/redirect_error.d.ts b/types/errors/api/redirect_error.d.ts new file mode 100644 index 000000000..004604f69 --- /dev/null +++ b/types/errors/api/redirect_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The RedirectError class is used to represent a 3xx error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class RedirectError extends ApiError {} diff --git a/types/errors/api/service_unavailable_error.d.ts b/types/errors/api/service_unavailable_error.d.ts new file mode 100644 index 000000000..e667d5952 --- /dev/null +++ b/types/errors/api/service_unavailable_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The ServiceUnavailableError class is used to represent a 503 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class ServiceUnavailableError extends ApiError {} diff --git a/types/errors/api/timeout_error.d.ts b/types/errors/api/timeout_error.d.ts new file mode 100644 index 000000000..5775f87ed --- /dev/null +++ b/types/errors/api/timeout_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The TimeoutError class is used to represent a 408 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class TimeoutError extends ApiError {} diff --git a/types/errors/api/unauthorized_error.d.ts b/types/errors/api/unauthorized_error.d.ts new file mode 100644 index 000000000..bad09b743 --- /dev/null +++ b/types/errors/api/unauthorized_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The UnauthorizedError class is used to represent a 401 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class UnauthorizedError extends ApiError {} diff --git a/types/errors/api/unknown_api_error.d.ts b/types/errors/api/unknown_api_error.d.ts new file mode 100644 index 000000000..8ddc33bbd --- /dev/null +++ b/types/errors/api/unknown_api_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The UnknownApiError class is used to represent a generic, unexpected error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class UnknownApiError extends ApiError {} diff --git a/types/errors/easypost_error.d.ts b/types/errors/easypost_error.d.ts new file mode 100644 index 000000000..db97aca67 --- /dev/null +++ b/types/errors/easypost_error.d.ts @@ -0,0 +1,12 @@ +/** + * The EasyPostError class is the base class for all errors that occur in the EasyPost Node.js client library. + * This class should not be instantiated directly. + * @internal + * @abstract + * @extends Error + * @param {string} [message] - The message to be displayed when the error is logged. + */ +export default class EasyPostError extends Error { + message: string | undefined; + constructor({ message }?: { message?: string }); +} diff --git a/types/errors/error_handler.d.ts b/types/errors/error_handler.d.ts new file mode 100644 index 000000000..b5aed46ce --- /dev/null +++ b/types/errors/error_handler.d.ts @@ -0,0 +1,33 @@ +import EasyPostError from './easypost_error'; +export type RawAPIError = { + statusCode: number; + body: { + error: { + code: string; + message: JSONParsableError; + errors: EasyPostError[]; + }; + }; +}; +type JSONParsableError = string | number | JSONObject | JSONArray; +type JSONObject = { + [key: string]: JSONParsableError; +}; +type JSONArray = JSONParsableError[]; +export default class ErrorHandler { + /** + * Recursively traverses a JSON object or array and extracts error messages + * as strings. Adds the extracted messages to the specified messagesList array. + * + * @param {JSONParsableError} errorMessage - The JSON object or array to traverse. + */ + static traverseJsonElement(errorMessage: JSONParsableError): string[]; + static isAPIError(error: any): error is RawAPIError; + /** + * Calculate and generate the appropriate {@link ApiError} based on a received HTTP response error. + * @param {*} error - The errored HTTP response. + * @returns {ApiError} The `ApiError`-based error corresponding to the HTTP status code. + */ + static handleApiError(error: RawAPIError): EasyPostError; +} +export {}; diff --git a/types/errors/general/end_of_pagination_error.d.ts b/types/errors/general/end_of_pagination_error.d.ts new file mode 100644 index 000000000..1ae894a77 --- /dev/null +++ b/types/errors/general/end_of_pagination_error.d.ts @@ -0,0 +1,10 @@ +import EasyPostError from '../easypost_error'; +/** + * The EndOfPaginationError class is used to represent an error that no more page can be retrieved + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +export default class EndOfPaginationError extends EasyPostError { + constructor(); +} diff --git a/types/errors/general/filtering_error.d.ts b/types/errors/general/filtering_error.d.ts new file mode 100644 index 000000000..3f96a1925 --- /dev/null +++ b/types/errors/general/filtering_error.d.ts @@ -0,0 +1,8 @@ +import EasyPostError from '../easypost_error'; +/** + * The FilteringError class is used to represent an error that occurred while filtering a list (e.g. a list of rates). + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +export default class FilteringError extends EasyPostError {} diff --git a/types/errors/general/index.d.ts b/types/errors/general/index.d.ts new file mode 100644 index 000000000..04c30fdb2 --- /dev/null +++ b/types/errors/general/index.d.ts @@ -0,0 +1,6 @@ +export * from './end_of_pagination_error'; +export * from './filtering_error'; +export * from './invalid_object_error'; +export * from './invalid_parameter_error'; +export * from './missing_parameter_error'; +export * from './signature_verification_error'; diff --git a/types/errors/general/invalid_object_error.d.ts b/types/errors/general/invalid_object_error.d.ts new file mode 100644 index 000000000..be11f59bd --- /dev/null +++ b/types/errors/general/invalid_object_error.d.ts @@ -0,0 +1,8 @@ +import EasyPostError from '../easypost_error'; +/** + * The InvalidObjectError class is used to represent an error due to an invalid object (e.g. missing an expected property). + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +export default class InvalidObjectError extends EasyPostError {} diff --git a/types/errors/general/invalid_parameter_error.d.ts b/types/errors/general/invalid_parameter_error.d.ts new file mode 100644 index 000000000..9931b6a18 --- /dev/null +++ b/types/errors/general/invalid_parameter_error.d.ts @@ -0,0 +1,8 @@ +import EasyPostError from '../easypost_error'; +/** + * The InvalidParameterError class is used to represent an error due to an invalid function parameter. + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +export default class InvalidParameterError extends EasyPostError {} diff --git a/types/errors/general/missing_parameter_error.d.ts b/types/errors/general/missing_parameter_error.d.ts new file mode 100644 index 000000000..858616524 --- /dev/null +++ b/types/errors/general/missing_parameter_error.d.ts @@ -0,0 +1,8 @@ +import EasyPostError from '../easypost_error'; +/** + * The MissingParameterError class is used to represent an error due to a missing expected function parameter. + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +export default class MissingParameterError extends EasyPostError {} diff --git a/types/errors/general/signature_verification_error.d.ts b/types/errors/general/signature_verification_error.d.ts new file mode 100644 index 000000000..0d73da0d7 --- /dev/null +++ b/types/errors/general/signature_verification_error.d.ts @@ -0,0 +1,8 @@ +import EasyPostError from '../easypost_error'; +/** + * The SignatureVerificationError class is used to represent an error due to a failed signature verification (e.g. a webhook HMAC signature). + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +export default class SignatureVerificationError extends EasyPostError {} diff --git a/types/errors/index.d.ts b/types/errors/index.d.ts new file mode 100644 index 000000000..a8d312a93 --- /dev/null +++ b/types/errors/index.d.ts @@ -0,0 +1,4 @@ +export * from './api'; +export * from './general'; +export * from './easypost_error'; +export * from './error_handler'; diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 000000000..310d378d1 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,2 @@ +import EasyPost from './easypost'; +export default EasyPost; diff --git a/types/services/address_service/Address.d.ts b/types/services/address_service/Address.d.ts new file mode 100644 index 000000000..3de9d7439 --- /dev/null +++ b/types/services/address_service/Address.d.ts @@ -0,0 +1,72 @@ +import { IVerifications } from './Verifications'; +import { IObjectWithId } from '../../utils/types'; +/** + * Address objects are used to represent people, places, and organizations in a number of contexts. + * For example, a Shipment requires a to_address and from_address to accurately calculate rates and generate postage. + * + * Additionally, EasyPost offers several verification tools that can be used to detect deliverability issues, correct minor errors in spelling/formatting, and determine if an Address is residential or not (which has a significant effect on Shipment rating for many carriers). + * + * @see https://www.easypost.com/docs/api/node#address-object + */ +export type IAddress = IObjectWithId<'Address'> & { + /** + * First line of the address + */ + street1?: string | null; + /** + * Second line of the address + */ + street2?: string | null; + /** + * City the address is located in + */ + city?: string | null; + /** + * State or province the address is located in + */ + state?: string | null; + /** + * ZIP or postal code the address is located in + */ + zip: string; + /** + * ISO 3166 country code for the country the address is located in + */ + country: string; + /** + * Whether or not this address would be considered residential + */ + residential?: boolean | null; + /** + * The specific designation for the address (only relevant if the address is a carrier facility) + */ + carrier_facility?: string | null; + /** + * Name of the person. Both name and company can be included + */ + name?: string | null; + /** + * Name of the organization. Both name and company can be included + */ + company?: string | null; + /** + * Phone number to reach the person or organization + */ + phone?: string | null; + /** + * Email to reach the person or organization + */ + email?: string | null; + /** + * Federal tax identifier of the person or organization + */ + federal_tax_id?: string | null; + /** + * State tax identifier of the person or organization + */ + state_tax_id?: string | null; + /** + * The result of any verifications requested + */ + verifications: IVerifications; +}; diff --git a/types/services/address_service/AddressCreateParameters.d.ts b/types/services/address_service/AddressCreateParameters.d.ts new file mode 100644 index 000000000..67b6a50ff --- /dev/null +++ b/types/services/address_service/AddressCreateParameters.d.ts @@ -0,0 +1,22 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IAddress } from './Address'; +/** + * @see https://www.easypost.com/docs/api/node#create-and-verify-addresses + */ +export type IAddressCreateParameters = Omit< + IAddress, + ParametersToOmitOnCreate | 'verifications' +> & { + /** + * The verifications to perform when creating. + * verify_strict takes precedence. + * true will perform both delivery and zip code. + */ + verify?: boolean | null; + /** + * The verifications to perform when creating. + * The failure of any of these verifications causes the whole request to fail. + * true will perform both delivery and zip code. + */ + verify_strict?: boolean | null; +}; diff --git a/types/services/address_service/AddressListParameters.d.ts b/types/services/address_service/AddressListParameters.d.ts new file mode 100644 index 000000000..cb9b95716 --- /dev/null +++ b/types/services/address_service/AddressListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api#retrieve-a-list-of-addresses + */ +export type IAddressListParameters = IAllMethodParameters; diff --git a/types/services/address_service/Verification.d.ts b/types/services/address_service/Verification.d.ts new file mode 100644 index 000000000..6e547eb54 --- /dev/null +++ b/types/services/address_service/Verification.d.ts @@ -0,0 +1,19 @@ +import { IFieldError } from '../../utils/errors'; +import { IVerificationDetails } from './VerificationDetails'; +/** + * @see https://www.easypost.com/docs/api/node#verification-object + */ +export type IVerification = { + /** + * The success of the verification + */ + success: boolean; + /** + * All errors that caused the verification to fail + */ + errors: IFieldError[]; + /** + * Extra data related to the verification + */ + details: IVerificationDetails; +}; diff --git a/types/services/address_service/VerificationDetails.d.ts b/types/services/address_service/VerificationDetails.d.ts new file mode 100644 index 000000000..6ce352800 --- /dev/null +++ b/types/services/address_service/VerificationDetails.d.ts @@ -0,0 +1,17 @@ +/** + * @see https://www.easypost.com/docs/api/node#verification_details-object + */ +export type IVerificationDetails = { + /** + * The latitude of an Address. + */ + latitude: number; + /** + * The longitude of an Address. + */ + longitude: number; + /** + * The time zone the address is located in, IE: America/Los_Angeles + */ + time_zone: string; +}; diff --git a/types/services/address_service/Verifications.d.ts b/types/services/address_service/Verifications.d.ts new file mode 100644 index 000000000..85ea98d5b --- /dev/null +++ b/types/services/address_service/Verifications.d.ts @@ -0,0 +1,16 @@ +import { IVerification } from './Verification'; +/** + * @see https://www.easypost.com/docs/api/node#verifications-object + */ +export type IVerifications = { + /** + * Only applicable to US addresses - checks and sets the ZIP+4 + */ + zip4: IVerification; + /** + * Checks that the address is deliverable and makes minor corrections to spelling/format. US addresses will also have their "residential" status checked and set. + */ + delivery: IVerification; +}; +declare const _default: {}; +export default _default; diff --git a/types/services/address_service/index.d.ts b/types/services/address_service/index.d.ts new file mode 100644 index 000000000..ab557c1c7 --- /dev/null +++ b/types/services/address_service/index.d.ts @@ -0,0 +1,105 @@ +import EasyPost from '../..'; +import { IAddress } from './Address'; +import { IAddressCreateParameters } from './AddressCreateParameters'; +import { IAddressListParameters } from './AddressListParameters'; +export * from './Address'; +export * from './AddressCreateParameters'; +export * from './Verification'; +export * from './VerificationDetails'; +export * from './Verifications'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create an {@link Address address}. + * See {@link https://www.easypost.com/docs/api/node#create-an-address EasyPost API Documentation} for more information. + * @param params - Parameters for the address to be created. + * @returns - The created address. + */ + create( + params: IAddressCreateParameters, + ): Promise>; + /** + * Create and verify an {@link Address address} in a single request. + * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. + * @param params - Parameters for the address to be created. + * @returns - The created and verified address. + */ + createAndVerify(params: IAddressCreateParameters): Promise; + /** + * Retrieve all {@link Address addresses} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-addresses EasyPost API Documentation} for more information. + * @param params - Parameters to filter the list of addresses. + * @returns - An object containing a list of {@link Address addresses} and pagination information. + */ + all(params?: IAddressListParameters): Promise< + { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of Address collection. + * @param addresses An object containing a list of {@link Address addresses} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + addresses: { + addresses: IAddress[]; + }, + pageSize?: number | null, + ): Promise< + { + addresses: IAddress[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve an {@link Address address} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-address EasyPost API Documentation} for more information. + * @param id - The ID of the address to retrieve. + * @returns - The retrieved address. + */ + retrieve(id: string): Promise>; + /** + * Verify an {@link Address address} by its ID. + * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. + * @param id - The ID of the address to verify. + * @returns - The verified address. + */ + verifyAddress(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/api_key_service/ApiKey.d.ts b/types/services/api_key_service/ApiKey.d.ts new file mode 100644 index 000000000..c11cf642e --- /dev/null +++ b/types/services/api_key_service/ApiKey.d.ts @@ -0,0 +1,20 @@ +import { IObjectWithId } from '../../utils/types'; +export type IApiKey = IObjectWithId<'ApiKey'> & { + /** + * The actual key value to use for authentication + */ + key: string; + /** + * When the API key was created + */ + created_at: string; + /** + * Whether the API key is active or not + */ + active: boolean; +}; +export type UserAPIKeys = { + id: string; + keys: IApiKey[]; + children: UserAPIKeys[]; +}; diff --git a/types/services/api_key_service/index.d.ts b/types/services/api_key_service/index.d.ts new file mode 100644 index 000000000..972a59b27 --- /dev/null +++ b/types/services/api_key_service/index.d.ts @@ -0,0 +1,71 @@ +import EasyPost from '../..'; +import { IApiKey } from './ApiKey'; +export * from './ApiKey'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Retrieve all {@link ApiKey API keys} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. + * @returns - An object containing the API keys associated with the current authenticated user and its child users. + */ + all(params?: {}): Promise< + import('../../utils/types').IBaseObject<'ApiKey'> & { + id: string; + mode: 'test' | 'production'; + object: 'ApiKey'; + } & { + key: string; + created_at: string; + active: boolean; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve API Keys for a specified {@link User user}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. + * @param id - The ID of the user to retrieve keys for. + * @returns - List of associated API Keys. + * @throws {FilteringError} If user or API Keys are not found. + */ + retrieveApiKeysForUser(id: string): Promise; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject + /** + * Retrieve API Keys for a specified {@link User user}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. + * @param id - The ID of the user to retrieve keys for. + * @returns - List of associated API Keys. + * @throws {FilteringError} If user or API Keys are not found. + */; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/base_service.d.ts b/types/services/base_service.d.ts new file mode 100644 index 000000000..51048730a --- /dev/null +++ b/types/services/base_service.d.ts @@ -0,0 +1,71 @@ +import EasyPostClient from '../easypost'; +export type EasyPostObject = A & { + _params: any; +}; +declare const _default: (easypostClient: EasyPostClient) => { + new (): {}; + /** + * Converts a JSON response and all its nested elements to associated {@link EasyPostObject}-based class instances. + * @internal + * @param {*} response The JSON response to convert (usually a `Map` or `Array`). + * @param {*} params The parameters passed when fetching the response + * @returns {*} An {@link EasyPostObject}-based class instance or an `Array` of {@link EasyPostObject}-based class instances. + */ + _convertToEasyPostObject(response: A, params?: any): EasyPostObject; + /** + * Creates an EasyPost Object via the API. + * @internal + * @param url The URL to send the API request to. + * @param params The parameters to send with the API request. + * @returns The created {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + _create(url: string, params: object): Promise>; + /** + * Retrieve a list of records from the API. + * @internal + * @param url The URL to send the API request to. + * @param params The parameters to send with the API request. + * @returns The retrieved {@link EasyPostObject}-based class instance(s), or a `Promise` that rejects with an error. + */ + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a record from the API. + * @internal + * @param url The URL to send the API request to. + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + _retrieve(url: string): Promise>; + /** + * Retrieve the next page of specific collection of object + * @internal + * @param url The URL to send the API request to. + * @param collection The collection of a specific object. + * @param pageSize The number of records to return on each page. + * @param optionalParams The optional param for additional value in the query string. + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + * TODO: Implement this function in EndShippers and Batches once the API supports them properly. + */ + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/batch_service/Batch.d.ts b/types/services/batch_service/Batch.d.ts new file mode 100644 index 000000000..cdd5ee354 --- /dev/null +++ b/types/services/batch_service/Batch.d.ts @@ -0,0 +1,48 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IPickup } from '../pickup_service/Pickup'; +import { IScanForm } from '../scan_form_service'; +import { IBatchShipment } from './BatchShipment'; +import { TBatchState } from './BatchState'; +import { TBatchStatuses } from './BatchStatuses'; +/** + * The Batch object allows you to perform operations on multiple Shipments at once. + * This includes scheduling a Pickup, creating a ScanForm and consolidating labels. + * Operations performed on Batches are asynchronous and take advantage of our webhook infrastructure. + * + * @see https://www.easypost.com/docs/api/node#batch-object + */ +export type IBatch = IObjectWithId<'Batch'> & + IDatedObject & { + /** + * An optional field that may be used in place of ID in some API endpoints + */ + reference?: string | null; + /** + * The overall state. Possible values are "creating", "creation_failed", "created", "purchasing", "purchase_failed", "purchased", "label_generating", and "label_generated" + */ + state: TBatchState; + /** + * The number of shipments added + */ + num_shipments: number; + /** + * An array of batch shipments + */ + shipments: IBatchShipment[]; + /** + * A map of BatchShipment statuses to the count of BatchShipments with that status. Valid statuses are "postage_purchased", "postage_purchase_failed", "queued_for_purchase", and "creation_failed" + */ + status: TBatchStatuses; + /** + * The label image url + */ + label_url?: string | null; + /** + * The created ScanForm + */ + scan_form: IScanForm; + /** + * The created Pickup + */ + pickup: IPickup; + }; diff --git a/types/services/batch_service/BatchCreateParameters.d.ts b/types/services/batch_service/BatchCreateParameters.d.ts new file mode 100644 index 000000000..b778883b5 --- /dev/null +++ b/types/services/batch_service/BatchCreateParameters.d.ts @@ -0,0 +1,8 @@ +export type IBatchCreateParameters = { + shipments?: ( + | { + id: string; + } + | string + )[]; +}; diff --git a/types/services/batch_service/BatchListParameters.d.ts b/types/services/batch_service/BatchListParameters.d.ts new file mode 100644 index 000000000..38f453d9f --- /dev/null +++ b/types/services/batch_service/BatchListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#list-all-batches + */ +export type IBatchListParameters = IAllMethodParameters; diff --git a/types/services/batch_service/BatchShipment.d.ts b/types/services/batch_service/BatchShipment.d.ts new file mode 100644 index 000000000..48c669792 --- /dev/null +++ b/types/services/batch_service/BatchShipment.d.ts @@ -0,0 +1,22 @@ +import { TBatchStatus } from './BatchStatus'; +/** + * @see https://www.easypost.com/docs/api/node#batch-shipment-object + */ +export type IBatchShipment = { + /** + * The id of the Shipment. Unique, begins with "shp_" + */ + id: string; + /** + * An optional field that may be used in place of ID in some API endpoints + */ + reference?: string | null; + /** + * The current status. Possible values are "postage_purchased", "postage_purchase_failed", "queued_for_purchase", "creation_failed", and "created" + */ + batch_status: TBatchStatus; + /** + * A human readable message for any errors that occurred during the Batch's life cycle + */ + batch_message: string; +}; diff --git a/types/services/batch_service/BatchState.d.ts b/types/services/batch_service/BatchState.d.ts new file mode 100644 index 000000000..41fa51e7a --- /dev/null +++ b/types/services/batch_service/BatchState.d.ts @@ -0,0 +1,9 @@ +export type TBatchState = + | 'creating' + | 'creation_failed' + | 'created' + | 'purchasing' + | 'purchase_failed' + | 'purchased' + | 'label_generating' + | 'label_generated'; diff --git a/types/services/batch_service/BatchStatus.d.ts b/types/services/batch_service/BatchStatus.d.ts new file mode 100644 index 000000000..c85d419dc --- /dev/null +++ b/types/services/batch_service/BatchStatus.d.ts @@ -0,0 +1,6 @@ +export type TBatchStatus = + | 'postage_purchased' + | 'postage_purchase_failed' + | 'queued_for_purchase' + | 'creation_failed' + | 'created'; diff --git a/types/services/batch_service/BatchStatuses.d.ts b/types/services/batch_service/BatchStatuses.d.ts new file mode 100644 index 000000000..7795213f7 --- /dev/null +++ b/types/services/batch_service/BatchStatuses.d.ts @@ -0,0 +1,4 @@ +import { TBatchStatus } from './BatchStatus'; +export type TBatchStatuses = { + [key in TBatchStatus]: number; +}; diff --git a/types/services/batch_service/index.d.ts b/types/services/batch_service/index.d.ts new file mode 100644 index 000000000..b815b9db2 --- /dev/null +++ b/types/services/batch_service/index.d.ts @@ -0,0 +1,132 @@ +import EasyPost from '../..'; +import { IBatch } from './Batch'; +import { IBatchCreateParameters } from './BatchCreateParameters'; +import { IBatchListParameters } from './BatchListParameters'; +export * from './Batch'; +export * from './BatchCreateParameters'; +export * from './BatchListParameters'; +export * from './BatchShipment'; +export * from './BatchState'; +export * from './BatchStatus'; +export * from './BatchStatuses'; +export declare const DEFAULT_LABEL_FORMAT = 'pdf'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#create-a-batch EasyPost API Documentation} for more information. + * @param params - Parameters for the batch to be created. + * @returns - The created batch. + */ + create(params: IBatchCreateParameters): Promise>; + /** + * Add {@link Shipment shipments} to a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#add-shipments-to-a-batch EasyPost API Documentation} for more information. + * @param id - The id of the batch to add shipments to. + * @param shipmentIds - The ids of the shipments to add to the batch. + * @returns - The updated batch. + */ + addShipments( + id: string, + shipmentIds: string[], + ): Promise>; + /** + * Removes {@link Shipment shipments} from a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#remove-shipments-from-a-batch EasyPost API Documentation} for more information. + * @param id - The id of the batch to remove shipments from. + * @param shipmentIds - The ids of the shipments to remove from the batch. + * @returns - The updated batch. + */ + removeShipments( + id: string, + shipmentIds: string[], + ): Promise>; + /** + * Generate a label for a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#batch-labels EasyPost API Documentation} for more information. + * @param id - The id of the batch to generate a label for. + * @param fileFormat - The format of the label to generate. Defaults to 'pdf'. + * @returns - The updated batch. + */ + generateLabel( + id: string, + fileFormat?: string, + ): Promise>; + /** + * Create a {@link ScanForm scan form} for a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#manifesting-scan-form EasyPost API Documentation} for more information. + * @param id - The id of the batch to create a scan form for. + * @returns - The updated batch. + */ + createScanForm(id: string): Promise>; + /** + * Purchase a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-batch EasyPost API Documentation} for more information. + * @param id - The id of the batch to purchase. + * @returns - The purchased batch. + */ + buy(id: string): Promise>; + /** + * Retrieve all {@link Batch batches} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#list-all-batches EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of batches. + * @returns - An object containing a list of {@link Batch batches} and pagination information. + */ + all(params?: IBatchListParameters): Promise< + import('../../utils/types').IBaseObject<'Batch'> & { + id: string; + mode: 'test' | 'production'; + object: 'Batch'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + state: import('./BatchState').TBatchState; + num_shipments: number; + shipments: import('./BatchShipment').IBatchShipment[]; + status: import('./BatchStatuses').TBatchStatuses; + label_url?: string | null | undefined; + scan_form: import('..').IScanForm; + pickup: import('../pickup_service/Pickup').IPickup; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link Batch batch} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-batch EasyPost API Documentation} for more information. + * @param id - The ID of the batch to retrieve. + * @returns - The retrieved batch. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/beta_rate_service/index.d.ts b/types/services/beta_rate_service/index.d.ts new file mode 100644 index 000000000..bc4eeca1e --- /dev/null +++ b/types/services/beta_rate_service/index.d.ts @@ -0,0 +1,44 @@ +import EasyPost from '../..'; +import { IRate } from '../rate_service/Rate'; +/** + * @extends baseService + */ +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Retrieve a list of stateless {@link Rate rates} based on the provided parameters. + * @param params - Map of parameters for the API call + * @returns - List of stateless rates + */ + retrieveStatelessRates(params: any): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/beta_referral_customer_service/index.d.ts b/types/services/beta_referral_customer_service/index.d.ts new file mode 100644 index 000000000..dd8a712ae --- /dev/null +++ b/types/services/beta_referral_customer_service/index.d.ts @@ -0,0 +1,60 @@ +import EasyPost from '../..'; +import { IPaymentMethod } from '../billing_service'; +import { IRefund } from '../refund_service'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Add an existing Stripe payment method to a {@link User referral customer's} account. + * @param stripeCustomerId - The Stripe account's ID. + * @param paymentMethodReference - Reference of Stripe payment method. + * @param [priority] - Which priority to set the payment method to ('primary' or 'secondary'). + * @returns - A JSON object representing the payment method. + */ + addPaymentMethod( + stripeCustomerId: string, + paymentMethodReference: string, + priority?: 'primary' | 'secondary', + ): Promise; + /** + * Refund by amount for a recent payment. + * @param refundAmount - Amount to be refunded by cents. + * @returns - A JSON object representing the refund. + */ + refundByAmount(refundAmount: number): Promise; + /** + * Refund a payment by a payment log ID. + * @param paymentLogId - ID of the payment log. + * @returns - Returns BetaPaymentRefund object. + */ + refundByPaymentLog(paymentLogId: string): Promise; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/billing_service/PaymentMethod.d.ts b/types/services/billing_service/PaymentMethod.d.ts new file mode 100644 index 000000000..5680f3db0 --- /dev/null +++ b/types/services/billing_service/PaymentMethod.d.ts @@ -0,0 +1,44 @@ +import { IObjectWithId } from '../../utils/types'; +/** + * The Payment method object can be either credit card or bank account. + * + * TODO: Add the link to the API doc once its updated + */ +export type IPaymentMethod = IObjectWithId<'PaymentMethod'> & { + /** + * Country of the bank account + */ + country: string; + /** + * Name of the bank + */ + bank_name: string; + /** + * Brand of the credit card + */ + brand: string; + /** + * Whether the payment method(credit card or bank account) is disabled or not + */ + disabled_at: string; + /** + * Expiration month of the credit card + */ + exp_month: number; + /** + * Expiration year of the credit card + */ + exp_year: number; + /** + * Last four of the credit card + */ + last4: string; + /** + * Name of the credit card + */ + name: string; + /** + * Whether the bank account is verified or not + */ + verified: boolean; +}; diff --git a/types/services/billing_service/index.d.ts b/types/services/billing_service/index.d.ts new file mode 100644 index 000000000..dc097c109 --- /dev/null +++ b/types/services/billing_service/index.d.ts @@ -0,0 +1,63 @@ +import EasyPost from '../..'; +export * from './PaymentMethod'; +export type Priority = 'primary' | 'secondary'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Fund your EasyPost wallet by charging your primary or secondary payment method on file. + * See {@link https://www.easypost.com/docs/api/node#add-funds-to-your-wallet-one-time-charge EasyPost API Documentation} for more information. + * @param amount - The amount to charge to your payment method. + * @param priority - The priority of the payment method to charge. Can be either 'primary' or 'secondary'. + */ + fundWallet(amount: string, priority?: Priority): Promise; + /** + * Delete a payment method from the current authenticated user's account. + * See {@link https://www.easypost.com/docs/api/node#delete-a-payment-method EasyPost API Documentation} for more information. + * @param priority - The priority of the payment method to delete. Can be either 'primary' or 'secondary'. + */ + deletePaymentMethod(priority: Priority): Promise; + /** + * Retrieve all payment methods associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-payment-methods EasyPost API Documentation} for more information. + * @returns {Object} - An object containing the payment methods associated with the current authenticated user. + */ + retrievePaymentMethods(): Promise; + /** + * Get payment info (type of the payment method and ID of the payment method) + * This function is intended for internal use only, please avoid using this function + * @private + * @param {String} priority - The priority of the payment method to retrieve. Can be either 'primary' or 'secondary'. + * @returns {string[]} - An array of two strings, the first being the endpoint of the payment method and the second being the ID of the payment method. + */ + _getPaymentInfo(priority: Priority): Promise; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/carrier_account_service/CarrierAccount.d.ts b/types/services/carrier_account_service/CarrierAccount.d.ts new file mode 100644 index 000000000..18d31c329 --- /dev/null +++ b/types/services/carrier_account_service/CarrierAccount.d.ts @@ -0,0 +1,53 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { ICarrierAccountFields } from './CarrierAccountFields'; +/** + * A CarrierAccount encapsulates your credentials with the carrier. + * The CarrierAccount object provides CRUD operations for all CarrierAccounts. + * + * Each EasyPost account is automatically provided a USPS account managed by EasyPost. + * + * Other operations, such as Shipment creation, can reference CarrierAccounts to reduce the scope of data returned. + * For instance, you may have multiple warehouses that need to use distinct FedEx SmartPost credentials to request the correct rates. + * Rate objects will include a `carrier_account_id` field which can be used to determine the account used for rating. + * + * @see https://www.easypost.com/docs/api/node#carrier-account-object + */ +export type ICarrierAccount = IObjectWithId<'CarrierAccount'> & + IDatedObject & { + /** + * The name of the carrier type. + */ + type: string; + /** + * Contains "credentials" and/or "test_credentials", or may be empty + */ + fields: ICarrierAccountFields; + /** + * If clone is true, only the reference and description are possible to update + */ + clone?: boolean | null; + /** + * An optional, user-readable field to help distinguish accounts + */ + description?: string | null; + /** + * An optional field that may be used in place of carrier_account_id in other API endpoints + */ + reference?: string | null; + /** + * The name used when displaying a readable value for the type of the account + */ + readable: string; + /** + * Unlike the "credentials" object contained in "fields", this nullable object contains just raw credential pairs for client library consumption + */ + credentials?: object | null; + /** + * Unlike the "test_credentials" object contained in "fields", this nullable object contains just raw test_credential pairs for client library consumption + */ + test_credentials?: object | null; + /** + * Billing type of the carrier account + */ + billing_type: string | null; + }; diff --git a/types/services/carrier_account_service/CarrierAccountCreateParameters.d.ts b/types/services/carrier_account_service/CarrierAccountCreateParameters.d.ts new file mode 100644 index 000000000..c92ebd574 --- /dev/null +++ b/types/services/carrier_account_service/CarrierAccountCreateParameters.d.ts @@ -0,0 +1,3 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { ICarrierAccount } from './CarrierAccount'; +export type ICarrierAccountCreateParameters = Omit; diff --git a/types/services/carrier_account_service/CarrierAccountField.d.ts b/types/services/carrier_account_service/CarrierAccountField.d.ts new file mode 100644 index 000000000..3d13bf156 --- /dev/null +++ b/types/services/carrier_account_service/CarrierAccountField.d.ts @@ -0,0 +1,21 @@ +/** + * @see https://www.easypost.com/docs/api/node#carrier-account-field-object + */ +export type ICarrierAccountField = { + /** + * Each key in the sub-objects of a CarrierAccount's fields is the name of a settable field + */ + key: string; + /** + * The visibility value is used to control form field types, and is discussed in the CarrierType section + */ + visibility: string; + /** + * The label value is used in form rendering to display a more precise field name + */ + label: string; + /** + * Checkbox fields use "0" and "1" as False and True, all other field types present plaintext, partly-masked, or masked credential data for reference + */ + value: string; +}; diff --git a/types/services/carrier_account_service/CarrierAccountFields.d.ts b/types/services/carrier_account_service/CarrierAccountFields.d.ts new file mode 100644 index 000000000..4371a867f --- /dev/null +++ b/types/services/carrier_account_service/CarrierAccountFields.d.ts @@ -0,0 +1,22 @@ +import { ICarrierAccountField } from './CarrierAccountField'; +/** + * @see https://www.easypost.com/docs/api/node#carrier-account-fields-object + */ +export type ICarrierAccountFields = { + /** + * Credentials used in the production environment. + */ + credentials: ICarrierAccountField; + /** + * Credentials used in the test environment. + */ + test_credentials: ICarrierAccountField; + /** + * For USPS this designates that no credentials are required. + */ + auto_link: boolean; + /** + * When present, a separate authentication process will be required through the UI to link this account type. + */ + custom_workflow: boolean; +}; diff --git a/types/services/carrier_account_service/index.d.ts b/types/services/carrier_account_service/index.d.ts new file mode 100644 index 000000000..8415d712a --- /dev/null +++ b/types/services/carrier_account_service/index.d.ts @@ -0,0 +1,116 @@ +import EasyPost from '../..'; +import { ICarrierAccount } from './CarrierAccount'; +import { ICarrierAccountCreateParameters } from './CarrierAccountCreateParameters'; +export * from './CarrierAccount'; +export * from './CarrierAccountCreateParameters'; +export * from './CarrierAccountField'; +export * from './CarrierAccountFields'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link CarrierAccount carrier account}. + * See {@link https://www.easypost.com/docs/api/node#create-a-carrier-account EasyPost API Documentation} for more information. + * @param params - Parameters for the carrier account to be created. + * @returns - The created carrier account. + */ + create( + params: ICarrierAccountCreateParameters, + ): Promise>; + /** + * Update a {@link CarrierAccount carrier account}. + * See {@link https://www.easypost.com/docs/api/node#update-a-carrieraccount EasyPost API Documentation} for more information. + * @param id - The id of the carrier account to be updated. + * @param params - Parameters for the carrier account to be updated. + * @returns - The updated carrier account. + */ + update( + id: string, + params: Partial, + ): Promise>; + /** + * Delete a {@link CarrierAccount carrier account}. + * See {@link https://www.easypost.com/docs/api/node#delete-a-carrier-account EasyPost API Documentation} for more information. + * @param id - The id of the carrier account to be deleted. + * @returns - A promise that resolves when the carrier account has been deleted. + */ + delete(id: string): Promise; + /** + * Returns the correct carrier_account endpoint when creating a record based on the type. + * @private + * @param {string} carrierAccountType - The type of carrier account to be created. + * @returns {string} - The endpoint to be used for the carrier account creation request. + */ + _selectCarrierAccountCreationEndpoint( + carrierAccountType: string, + ): 'carrier_accounts/register' | 'carrier_accounts'; + /** + * Retrieve all {@link CarrierAccount carrier accounts} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#list-all-carrier-accounts EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of carrier accounts. + * @returns - An object containing a list of {@link CarrierAccount carrier accounts} and pagination information. + */ + all(params?: {}): Promise< + import('../../utils/types').IBaseObject<'CarrierAccount'> & { + id: string; + mode: 'test' | 'production'; + object: 'CarrierAccount'; + } & import('../../utils/types').IDatedObject & { + type: string; + fields: import('./CarrierAccountFields').ICarrierAccountFields; + clone?: boolean | null | undefined; + description?: string | null | undefined; + reference?: string | null | undefined; + readable: string; + credentials?: object | null | undefined; + test_credentials?: object | null | undefined; + billing_type: string | null; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link CarrierAccount carrier account} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-carrieraccount EasyPost API Documentation} for more information. + * @param id - The ID of the carrier account to retrieve. + * @returns - The retrieved carrier account. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean + /** + * Retrieve all {@link CarrierAccount carrier accounts} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#list-all-carrier-accounts EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of carrier accounts. + * @returns - An object containing a list of {@link CarrierAccount carrier accounts} and pagination information. + */; + } + >; +}; +export default _default; diff --git a/types/services/carrier_metadata_service/CarrierMetadata.d.ts b/types/services/carrier_metadata_service/CarrierMetadata.d.ts new file mode 100644 index 000000000..4f76eebc3 --- /dev/null +++ b/types/services/carrier_metadata_service/CarrierMetadata.d.ts @@ -0,0 +1,34 @@ +/** + * The Carrier Metadata endpoint returns information about all the carriers available on the EasyPost platform. + * This information may include service levels, predefined packages, shipment options, supported features, and + * more that are available per carrier. This metadata can be useful during onboarding and integration or when + * determining the ideal carrier mix for your setup. + * + * @see https://www.easypost.com/docs/api/node#carriermetadata-object + */ +export type ICarrierMetadata = { + /** + * The single-word name of a carrier such as "royalmail" + */ + carrier: string; + /** + * The human-readable name of the carrier + */ + human_readable?: string | null; + /** + * A list of service level objects for this carrier + */ + service_levels?: Array | null; + /** + * A list of predefined package objects for this carrier + */ + predefined_packages?: Array | null; + /** + * A list of supported feature objects for this carrier + */ + supported_features?: Array | null; + /** + * A list of shipment option objects for this carrier + */ + shipment_options?: Array | null; +}; diff --git a/types/services/carrier_metadata_service/index.d.ts b/types/services/carrier_metadata_service/index.d.ts new file mode 100644 index 000000000..91a1f62e3 --- /dev/null +++ b/types/services/carrier_metadata_service/index.d.ts @@ -0,0 +1,46 @@ +import EasyPost from '../..'; +import { ICarrierMetadata } from './CarrierMetadata'; +export * from './CarrierMetadata'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Retrieve a list of carrier metadata based on the provided parameters. + * @param carriers - List of carrier in string + * @param type - List of types in string + * @returns - List of carrier metadata + */ + retrieve( + carriers?: string[] | null, + types?: string[] | null, + ): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/carrier_type_service/CarrierType.d.ts b/types/services/carrier_type_service/CarrierType.d.ts new file mode 100644 index 000000000..755c25a0e --- /dev/null +++ b/types/services/carrier_type_service/CarrierType.d.ts @@ -0,0 +1,27 @@ +import { IBaseObject } from '../../utils/types'; +import { ICarrierTypeFields } from './CarrierTypeFields'; +/** + * The CarrierType object provides an export declare interface for determining the valid fields of a CarrierAccount. + * The list of CarrierType objects only changes when a new carrier is added to EasyPost. + * + * The CarrierType objects consist of their top level attributes as well as a fields object that contains credentials and sometimes test_credentials sub-objects, + * which themselves are collections of attributes for CarrierAccount creation as well as metadata about presentation and the naming of said attributes. + * + * There are a couple special case CarrierAccounts, with structures differing somewhat from the norm. + * For instance, instead of credentials for UspsAccount, it has only auto_link: true, which indicates that it is an account that can be added or removed without any carrier-specific fields. + * + * The other custom option in the fields list is custom_workflow: true, which indicates that the EasyPost website export declare interface includes special processing for signups for the associated CarrierType. + * Carriers with a custom workflow will also present their normal credential rules, but it is considered unsafe to directly add a CarrierAccount of this type with these attributes filled out via another source than the EasyPost custom workflow. + * + * @see https://www.easypost.com/docs/api/node#carrier-type-object + */ +export type ICarrierType = IBaseObject<'CarrierType'> & { + /** + * Specifies the CarrierAccount type. + */ + type: string; + /** + * Contains at least one of the following keys: "auto_link", "credentials", "test_credentials", and "custom_workflow" + */ + fields: ICarrierTypeFields; +}; diff --git a/types/services/carrier_type_service/CarrierTypeCredentials.d.ts b/types/services/carrier_type_service/CarrierTypeCredentials.d.ts new file mode 100644 index 000000000..53653ec07 --- /dev/null +++ b/types/services/carrier_type_service/CarrierTypeCredentials.d.ts @@ -0,0 +1,17 @@ +/** + * @see https://www.easypost.com/docs/api/node#carrier-type-credentials-object + */ +export type ICarrierTypeCredentials = { + /** + * The key for each attribute sub-object within credentials is the name of the attribute for submission on CarrierAccounts + */ + name: string; + /** + * There are five possible values, which encode the security need and storage type for each attribute: "visible", "checkbox", "fake", "password", and "masked" + */ + visibility: 'visible' | 'checkbox' | 'fake' | 'password' | 'masked'; + /** + * Most attributes have generic names, so for clarity a "label" value is provided for clearer representation when rendering forms + */ + label: string; +}; diff --git a/types/services/carrier_type_service/CarrierTypeFields.d.ts b/types/services/carrier_type_service/CarrierTypeFields.d.ts new file mode 100644 index 000000000..0eea6b8cc --- /dev/null +++ b/types/services/carrier_type_service/CarrierTypeFields.d.ts @@ -0,0 +1,23 @@ +import { ICarrierTypeCredentials } from './CarrierTypeCredentials'; +/** + * @see https://www.easypost.com/docs/api/node#carrier-type-fields-object + */ +export type ICarrierTypeFields = { + /** + * If this key is present with the value of true, no other attributes are needed for CarrierAccount creation + */ + auto_link: boolean; + /** + * If this key is present with the value of true, CarrierAccount creation of this type requires extra work not handled by the CarrierAccount standard API + */ + custom_workflow: boolean; + /** + * If this object is present, required attribute names and their metadata are presented inside + */ + credentials: ICarrierTypeCredentials; + /** + * If this object is present, it contains attribute names and metadata just as the credentials object. + * It is not required for CarrierAccount creation if you do not plan on using the carrier account for test mode + */ + test_credentials: ICarrierTypeCredentials; +}; diff --git a/types/services/carrier_type_service/index.d.ts b/types/services/carrier_type_service/index.d.ts new file mode 100644 index 000000000..f220bcf91 --- /dev/null +++ b/types/services/carrier_type_service/index.d.ts @@ -0,0 +1,45 @@ +import EasyPost from '../..'; +import { ICarrierType } from './CarrierType'; +export * from './CarrierType'; +export * from './CarrierTypeCredentials'; +export * from './CarrierTypeFields'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Retrieve all {@link CarrierType carrier types} available to the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-available-carrier-types EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of carrier types. + * @returns - A list of {@link CarrierType carrier types}. + */ + all(params?: {}): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/customs_info_service/CustomsInfo.d.ts b/types/services/customs_info_service/CustomsInfo.d.ts new file mode 100644 index 000000000..ce91e3287 --- /dev/null +++ b/types/services/customs_info_service/CustomsInfo.d.ts @@ -0,0 +1,55 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { ICustomsItem } from '../customs_item_service'; +/** + * CustomsInfo objects contain CustomsItem objects and all necessary information for the generation of customs forms required for international shipping. + * + * Please see the Shipments documentation for examples of including a CustomsInfo object in a shipment. + * + * @see https://www.easypost.com/docs/api/node#customs-info-object + */ +export type ICustomsInfo = IObjectWithId<'CustomsInfo'> & + IDatedObject & { + /** + * "EEL" or "PFC" + * value less than $2500: "NOEEI 30.37(a)" + * value greater than $2500: see [Customs Guide](https://www.easypost.com/customs-guide) + */ + eel_pfc?: string | null; + /** + * "documents", "gift", "merchandise", "returned_goods", "sample", or "other" + */ + contents_type?: string | null; + /** + * (max 255 characters) Human readable description of content. + * Required for certain carriers and always required if contents_type is "other" + */ + contents_explanation?: string | null; + /** + * Electronically certify the information provided + */ + customs_certify?: boolean | null; + /** + * Required if customs_certify is true + */ + customs_signer?: string | null; + /** + * "abandon" or "return", defaults to "return" + */ + non_delivery_option?: 'abandon' | 'return' | null; + /** + * "none", "other", "quarantine", or "sanitary_phytosanitary_inspection" + */ + restriction_type?: 'none' | 'other' | 'quarantine' | 'sanitary_phytosanitary_inspection' | null; + /** + * Required if restriction_type is not "none" + */ + restriction_comments?: string | null; + /** + * Describes the products being shipped + */ + customs_items: ICustomsItem[]; + /** + * A customs declaration message, available for eligible carriers + */ + declaration?: string | null; + }; diff --git a/types/services/customs_info_service/CustomsInfoCreateParameters.d.ts b/types/services/customs_info_service/CustomsInfoCreateParameters.d.ts new file mode 100644 index 000000000..c3a689c41 --- /dev/null +++ b/types/services/customs_info_service/CustomsInfoCreateParameters.d.ts @@ -0,0 +1,3 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { ICustomsInfo } from './CustomsInfo'; +export type ICustomsInfoCreateParameters = Omit; diff --git a/types/services/customs_info_service/index.d.ts b/types/services/customs_info_service/index.d.ts new file mode 100644 index 000000000..718ff65af --- /dev/null +++ b/types/services/customs_info_service/index.d.ts @@ -0,0 +1,54 @@ +import EasyPost from '../..'; +import { ICustomsInfo } from './CustomsInfo'; +import { ICustomsInfoCreateParameters } from './CustomsInfoCreateParameters'; +export * from './CustomsInfo'; +export * from './CustomsInfoCreateParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link CustomsInfo customs info} record. + * See {@link https://www.easypost.com/docs/api/node#create-a-customsinfo EasyPost API Documentation} for more information. + * @param params - Parameters for the customs info to be created. + * @returns - The created customs info. + */ + create( + params: ICustomsInfoCreateParameters, + ): Promise>; + /** + * Retrieve a {@link CustomsInfo customs info} record by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-customsinfo EasyPost API Documentation} for more information. + * @param id - The ID of the customs info to retrieve. + * @returns - The retrieved customs info. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/customs_item_service/CustomsItem.d.ts b/types/services/customs_item_service/CustomsItem.d.ts new file mode 100644 index 000000000..2852a841b --- /dev/null +++ b/types/services/customs_item_service/CustomsItem.d.ts @@ -0,0 +1,46 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * A CustomsItem object describes goods for international shipment and should be created then included in a CustomsInfo object. + * + * @see https://www.easypost.com/docs/api/node#customs-item-object + */ +export type ICustomsItem = IObjectWithId<'CustomsItem'> & + IDatedObject & { + /** + * Required, description of item being shipped + */ + description: string; + /** + * Required, greater than zero + * float + */ + quantity: number; + /** + * Required, greater than zero, total value (unit value * quantity) + * float (USD) + */ + value: number; + /** + * Required, greater than zero, total weight (unit weight * quantity) + * float (oz) + */ + weight: number; + /** + * Harmonized Tariff Schedule, e.g. "6109.10.0012" for Men's T-shirts + * + * @see https://hts.usitc.gov/ + */ + hs_tariff_number?: string | null; + /** + * SKU/UPC or other product identifier + */ + code?: string | null; + /** + * Required, 2 char country code + */ + origin_country: string; + /** + * 3 char currency code, default USD + */ + currency?: string | null; + }; diff --git a/types/services/customs_item_service/CustomsItemCreateParameters.d.ts b/types/services/customs_item_service/CustomsItemCreateParameters.d.ts new file mode 100644 index 000000000..4ac2ff6d7 --- /dev/null +++ b/types/services/customs_item_service/CustomsItemCreateParameters.d.ts @@ -0,0 +1,3 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { ICustomsItem } from './CustomsItem'; +export type ICustomsItemCreateParameters = Omit; diff --git a/types/services/customs_item_service/index.d.ts b/types/services/customs_item_service/index.d.ts new file mode 100644 index 000000000..c8d46b2d2 --- /dev/null +++ b/types/services/customs_item_service/index.d.ts @@ -0,0 +1,54 @@ +import EasyPost from '../..'; +import { ICustomsItem } from './CustomsItem'; +import { ICustomsItemCreateParameters } from './CustomsItemCreateParameters'; +export * from './CustomsItem'; +export * from './CustomsItemCreateParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link CustomsItem customs item}. + * See {@link https://www.easypost.com/docs/api/node#create-a-customsitem EasyPost API Documentation} for more information. + * @param params - Parameters for the customs item to be created. + * @returns - The created customs item. + */ + create( + params: ICustomsItemCreateParameters, + ): Promise>; + /** + * Retrieve a {@link CustomsItem customs item} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-customsitem EasyPost API Documentation} for more information. + * @param id - The ID of the customs item to retrieve. + * @returns - The retrieved customs item. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/end_shipper_service/EndShipper.d.ts b/types/services/end_shipper_service/EndShipper.d.ts new file mode 100644 index 000000000..5e5b37489 --- /dev/null +++ b/types/services/end_shipper_service/EndShipper.d.ts @@ -0,0 +1,52 @@ +import { IObjectWithId } from '../../utils/types'; +/** + * The EndShipper API is for platforms purchasing postage on behalf of their users, the EndShipper. + * Platforms must assert the EndShipper details, as the EndShipper is ultimately responsible for what is in the box. + * Multiple labels purchased for the same EndShipper must use the same EndShipper identity (API object). + * EndShipper objects must be created prior to buying a Shipment. Once EndShipper objects have been created, + * you must keep track of their public id in order to use them during a label buy. + * + * @see https://www.easypost.com/docs/api/node#endshipper + */ +export type IEndshipper = IObjectWithId<'EndShipper'> & { + /** + * Name of responsible person (conditionally required) + */ + name?: string | null; + /** + * Name of responsible company (conditionally required) + */ + company?: string | null; + /** + * First line of the address + */ + street1?: string | null; + /** + * Second line of the address + */ + street2?: string | null; + /** + * City the address is located in + */ + city?: string | null; + /** + * State or province the address is located in + */ + state?: string | null; + /** + * ZIP or postal code the address is located in + */ + zip: string; + /** + * ISO 3166 country code for the country the address is located in + */ + country?: string; + /** + * Phone number to reach the person or organization + */ + phone?: string | null; + /** + * Email to reach the person or organization + */ + email?: string | null; +}; diff --git a/types/services/end_shipper_service/EndShipperCreateParameters.d.ts b/types/services/end_shipper_service/EndShipperCreateParameters.d.ts new file mode 100644 index 000000000..11276c69a --- /dev/null +++ b/types/services/end_shipper_service/EndShipperCreateParameters.d.ts @@ -0,0 +1,3 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IEndshipper } from './EndShipper'; +export type IEndShipperCreateParameters = Omit; diff --git a/types/services/end_shipper_service/EndShipperListParameters.d.ts b/types/services/end_shipper_service/EndShipperListParameters.d.ts new file mode 100644 index 000000000..c806a475e --- /dev/null +++ b/types/services/end_shipper_service/EndShipperListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api#endshipper + */ +export type IEndShipperListParameters = IAllMethodParameters; diff --git a/types/services/end_shipper_service/index.d.ts b/types/services/end_shipper_service/index.d.ts new file mode 100644 index 000000000..138577854 --- /dev/null +++ b/types/services/end_shipper_service/index.d.ts @@ -0,0 +1,80 @@ +import EasyPost from '../..'; +import { IEndshipper } from './EndShipper'; +import { IEndShipperCreateParameters } from './EndShipperCreateParameters'; +import { IEndShipperListParameters } from './EndShipperListParameters'; +export * from './EndShipper'; +export * from './EndShipperCreateParameters'; +export * from './EndShipperListParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create an {@link EndShipper end shipper}. + * See {@link https://www.easypost.com/docs/api/node#create-an-endshipper EasyPost API Documentation} for more information. + * @param params - Parameters for the end shipper to be created. + * @returns - The created end shipper. + */ + create( + params: IEndShipperCreateParameters, + ): Promise>; + /** + * Update an {@link EndShipper end shipper}. + * See {@link https://www.easypost.com/docs/api/node#update-an-endshipper EasyPost API Documentation} for more information. + * @param id - The ID of the end shipper to update. + * @param params - Parameters for the end shipper to be updated. + * @returns - The updated end shipper. + */ + update( + id: string, + params: Partial, + ): Promise>; + /** + * Retrieve an {@link EndShipper end shipper} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-endshipper EasyPost API Documentation} for more information. + * @param id - The ID of the end shipper to retrieve. + * @returns - The retrieved end shipper. + */ + retrieve(id: string): Promise>; + /** + * Retrieve all {@link EndShipper end shippers} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-endshippers EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of end shippers. + * @returns - An object containing a list of {@link EndShipper end shippers} and pagination information. + */ + all(params?: IEndShipperListParameters): Promise< + { + _params: any; + } & { + has_more: boolean; + } + >; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/event_service/Event.d.ts b/types/services/event_service/Event.d.ts new file mode 100644 index 000000000..9da8a5e69 --- /dev/null +++ b/types/services/event_service/Event.d.ts @@ -0,0 +1,40 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * Webhook Events are triggered by changes in objects you've created via the API. + * Every time an Event related to one of your objects is created, EasyPost guarantees at least one POST request will be sent to each of the webhook URLs set up for your account. + * For this reason, we strongly encourage your webhook handler to be idempotent. + * See the webhooks guide for more information. + * + * @see https://www.easypost.com/docs/api/node#events + */ +export type IEvent = IObjectWithId<'Event'> & + IDatedObject & { + /** + * Result type and event name, see the "Possible Event Types" section for more information + */ + description: string; + /** + * Previous values of relevant result attributes + */ + previous_attributes: any; + /** + * The object associated with the Event. See the "object" attribute on the result to determine its specific type. + * This field will not be returned when retrieving events directly from the API + */ + result: any; + /** + * The current status of the event. Possible values are "completed", "failed", "in_queue", "retrying", or "pending" (deprecated) + * + * @deprecated + */ + status: 'completed' | 'failed' | 'in_queue' | 'retrying' | 'pending'; + /** + * Webhook URLs that have not yet been successfully notified as of the time this webhook event was sent. + * The URL receiving the Event will still be listed in pending_urls, as will any other URLs that receive the Event at the same time + */ + pending_urls: string[]; + /** + * Webhook URLs that have already been successfully notified as of the time this webhook was sent + */ + completed_urls: string[]; + }; diff --git a/types/services/event_service/EventListParameters.d.ts b/types/services/event_service/EventListParameters.d.ts new file mode 100644 index 000000000..9bdf71607 --- /dev/null +++ b/types/services/event_service/EventListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-events + */ +export type IEventListParameters = IAllMethodParameters; diff --git a/types/services/event_service/Payload/Payload.d.ts b/types/services/event_service/Payload/Payload.d.ts new file mode 100644 index 000000000..d52fba6e9 --- /dev/null +++ b/types/services/event_service/Payload/Payload.d.ts @@ -0,0 +1,14 @@ +import { IDatedObject, IObjectWithId } from '../../../utils/types'; +/** + * A Payload represents an attempt by EasyPost to send an Event to a Webhook. + * An Event can have multiple Payloads. For instance, if there is a failure to deliver a Webhook, + * an Event would have multiple payloads, one for each attempt to deliver the Event to the Webhook. + * Payload can be useful for debugging webhook delivery and when initially setting up EasyPost webhooks. + */ +export type IPayload = IObjectWithId<'Payload'> & + IDatedObject & { + /** + * The body of the Payload response + */ + response_body: string | null; + }; diff --git a/types/services/event_service/Payload/PayloadListParameters.d.ts b/types/services/event_service/Payload/PayloadListParameters.d.ts new file mode 100644 index 000000000..1286fdbbc --- /dev/null +++ b/types/services/event_service/Payload/PayloadListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads + */ +export type IPayloadListParameters = IAllMethodParameters; diff --git a/types/services/event_service/Payload/index.d.ts b/types/services/event_service/Payload/index.d.ts new file mode 100644 index 000000000..b1fd98702 --- /dev/null +++ b/types/services/event_service/Payload/index.d.ts @@ -0,0 +1 @@ +export * from './Payload'; diff --git a/types/services/event_service/index.d.ts b/types/services/event_service/index.d.ts new file mode 100644 index 000000000..cf8d41b21 --- /dev/null +++ b/types/services/event_service/index.d.ts @@ -0,0 +1,96 @@ +import EasyPost from '../..'; +import { IEvent } from './Event'; +import { IEventListParameters } from './EventListParameters'; +import { IPayload } from './Payload'; +export * from './Event'; +export * from './EventListParameters'; +export * from './Payload'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Retrieve all {@link Payload payloads} for an {@link Event event}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads EasyPost API Documentation} for more information. + * @param id - The ID of the event to retrieve payloads for. + * @returns - A list of {@link Payload payloads} for the event. + */ + retrieveAllPayloads(id: string): Promise>; + /** + * Retrieve a specific {@link Payload payload} for an {@link Event event}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-payload EasyPost API Documentation} for more information. + * @param id - The ID of the event to retrieve the payload for. + * @param payloadId - The ID of the payload to retrieve. + * @returns - The {@link Payload payload} for the event. + */ + retrievePayload( + id: string, + payloadId: string, + ): Promise>; + /** + * Retrieve all {@link Event events} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-events EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of events. + * @returns - An object containing the list of {@link Event events} and pagination information. + */ + all(params?: IEventListParameters): Promise< + { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of Event collection. + * @param events An object containing a list of {@link Event events} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + events: any, + pageSize?: number | null, + ): Promise< + { + events: IEvent[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve an {@link Event event} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-event EasyPost API Documentation} for more information. + * @param id - The ID of the event to retrieve. + * @returns - The retrieved event. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/index.d.ts b/types/services/index.d.ts new file mode 100644 index 000000000..229b1e3fa --- /dev/null +++ b/types/services/index.d.ts @@ -0,0 +1,27 @@ +export * from './address_service'; +export * from './api_key_service'; +export * from './batch_service'; +export * from './beta_rate_service'; +export * from './beta_referral_customer_service'; +export * from './billing_service'; +export * from './carrier_account_service'; +export * from './carrier_metadata_service'; +export * from './carrier_type_service'; +export * from './customs_info_service'; +export * from './customs_item_service'; +export * from './end_shipper_service'; +export * from './event_service'; +export * from './insurance_service'; +export * from './order_service'; +export * from './parcel_service'; +export * from './pickup_service'; +export * from './rate_service'; +export * from './referral_customer_service'; +export * from './refund_service'; +export * from './report_service'; +export * from './scan_form_service'; +export * from './shipment_service'; +export * from './tracker_service'; +export * from './user_service'; +export * from './webhook_service'; +export * from './base_service'; diff --git a/types/services/insurance_service/Fee.d.ts b/types/services/insurance_service/Fee.d.ts new file mode 100644 index 000000000..2149b267a --- /dev/null +++ b/types/services/insurance_service/Fee.d.ts @@ -0,0 +1,31 @@ +import { IBaseObject } from '../../utils/types'; +import { TFeeType } from './FeeType'; +/** + * Fee objects are used to represent the breakdown of charges made when purchasing an item on EasyPost. + * Shipments and Trackers both have associations to Fee objects. + * + * Each Shipment object will have a Fee of type "LabelFee" to represent the label fee charged by EasyPost for the service. + * Shipments with postage collected by EasyPost (as opposed to shipments with postage collected directly by the carrier) will have a "PostageFee" according to the postage amount. + * Insurance on a Shipment will add an "InsuranceFee" with the insurance premium (not the covered value) for the amount. + * Tracker objects will have a "TrackerFee" with the price, even when a Tracker is free. + * + * @see https://www.easypost.com/docs/api/node#fee-object + */ +export type IFee = IBaseObject<'Fee'> & { + /** + * The name of the category of fee. Possible types are "LabelFee", "PostageFee", "InsuranceFee", and "TrackerFee" + */ + type: TFeeType; + /** + * USD value with sub-cent precision + */ + amount: string; + /** + * Whether EasyPost has successfully charged your account for the fee + */ + charged: boolean; + /** + * Whether the Fee has been refunded successfully + */ + refunded: boolean; +}; diff --git a/types/services/insurance_service/FeeType.d.ts b/types/services/insurance_service/FeeType.d.ts new file mode 100644 index 000000000..980a39a05 --- /dev/null +++ b/types/services/insurance_service/FeeType.d.ts @@ -0,0 +1 @@ +export type TFeeType = 'InsuranceFee' | 'LabelFee' | 'PostageFee' | 'TrackerFee'; diff --git a/types/services/insurance_service/Insurance.d.ts b/types/services/insurance_service/Insurance.d.ts new file mode 100644 index 000000000..af0418285 --- /dev/null +++ b/types/services/insurance_service/Insurance.d.ts @@ -0,0 +1,73 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; +import { ITracker } from '../tracker_service'; +import { IFee } from './Fee'; +import { TInsuranceStatus } from './InsuranceStatus'; +/** + * An Insurance object represents insurance for packages purchased both via the EasyPost API as well as shipments purchased through third parties and later registered with EasyPost. + * An Insurance is created automatically whenever you buy a Shipment through EasyPost and pass insurance options during the Buy call or in a later call to Insure a Shipment. + * + * Insurance purchased through the Shipment Buy or Insure endpoints is immediately insured - there is no possibility of rejection based on tracking information, as the package was just created. + * On the other hand, Insurance purchased on shipments purchased outside of EasyPost requires creation with a tracking code so that EasyPost may confirm the package existence and current shipping status at the time of purchase. + * + * Standalone insurance is created in a pending state to help distinguish it from insurance purchased for an EasyPost Shipment. + * Both kinds of Insurance use the Tracking system to receive periodic updates, and will report those updates to any appropriate Webhooks on file. + * Standalone insurance will cancel itself if the tracking information for the given tracking code shows evidence of having been shipped anytime before the insurance was purchased. + * + * Unlike Shipments within EasyPost, Insurance objects register To and From Address objects according to the destination and ship-from locations of the package. + * This means that a Shipment with "is_return: true" actually ships to the listed From Address. + * Insurance does not have a concept of "is_return", so all insurance records refer to their true package destination as "to_address", regardless of whether or not the shipment is a return. + * + * @see https://www.easypost.com/docs/api/node#insurance-object + */ +export type IInsurance = IObjectWithId<'Insurance'> & + IDatedObject & { + /** + * The unique reference for this Insurance, if any + */ + reference?: string | null; + /** + * USD value of insured goods with sub-cent precision + */ + amount: string; + /** + * The insurance provider used by EasyPost + */ + provider: string; + /** + * An identifying number for some insurance providers used by EasyPost + */ + provider_id: string; + /** + * The ID of the Shipment in EasyPost, if postage was purchased via EasyPost + */ + shipment_id: string; + /** + * The tracking code of either the shipment within EasyPost, or provided by you during creation + */ + tracking_code: string; + /** + * The current status of the insurance, possible values are "new", "pending", "purchased", "failed", or "cancelled" + */ + status: TInsuranceStatus; + /** + * The associated Tracker object + */ + tracker: ITracker; + /** + * The associated Address object for destination + */ + to_address: IAddress; + /** + * The associated Address object for origin + */ + from_address: IAddress; + /** + * The associated InsuranceFee object if any + */ + fee: IFee; + /** + * The list of errors encountered during attempted purchase of the insurance + */ + messages: string[]; + }; diff --git a/types/services/insurance_service/InsuranceCreateParameters.d.ts b/types/services/insurance_service/InsuranceCreateParameters.d.ts new file mode 100644 index 000000000..537dc6ef8 --- /dev/null +++ b/types/services/insurance_service/InsuranceCreateParameters.d.ts @@ -0,0 +1,22 @@ +import { IAddress } from '../address_service'; +export type IInsuranceCreateParameters = { + reference?: string | null; + to_address: IAddress | string; + from_address: IAddress | string; + /** + * The carrier associated with the tracking_code you provided. + * The carrier will get auto-detected if none is provided + */ + carrier?: string | null; + /** + * The tracking code associated with the non-EasyPost-purchased package you'd like to insure. + */ + tracking_code: string; + /** + * The USD value of contents you would like to insure. + * Currently the maximum is $5000 + * + * @example 100.00 + */ + amount: string; +}; diff --git a/types/services/insurance_service/InsuranceStatus.d.ts b/types/services/insurance_service/InsuranceStatus.d.ts new file mode 100644 index 000000000..139db60a2 --- /dev/null +++ b/types/services/insurance_service/InsuranceStatus.d.ts @@ -0,0 +1 @@ +export type TInsuranceStatus = 'new' | 'pending' | 'purchased' | 'failed' | 'cancelled'; diff --git a/types/services/insurance_service/index.d.ts b/types/services/insurance_service/index.d.ts new file mode 100644 index 000000000..bb320ba54 --- /dev/null +++ b/types/services/insurance_service/index.d.ts @@ -0,0 +1,89 @@ +import EasyPost from '../..'; +import { IAllMethodParameters } from '../../utils/types'; +import { IInsurance } from './Insurance'; +import { IInsuranceCreateParameters } from './InsuranceCreateParameters'; +export * from './Fee'; +export * from './FeeType'; +export * from './Insurance'; +export * from './InsuranceCreateParameters'; +export * from './InsuranceStatus'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create an {@link Insurance insurance} record. + * See {@link https://www.easypost.com/docs/api/node#create-an-insurance EasyPost API Documentation} for more information. + * @param params - Parameters for the insurance to be created. + * @returns - The created insurance. + */ + create( + params: IInsuranceCreateParameters, + ): Promise>; + /** + * Retrieve all {@link Insurance} records associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-insurances EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the insurance records. + * @returns - An object containing the list of {@link Insurance insurance} records and pagination information. + */ + all(params?: IAllMethodParameters): Promise< + IInsurance[] & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of Insurance collection. + * @param {Object} insurances An object containing a list of {@link Insurance insurances} and pagination information. + * @param {Number} pageSize The number of records to return on each page + * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + insurances: any, + pageSize?: number | null, + ): Promise< + { + insurances: IInsurance[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve an {@link Insurance insurance} record by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-insurance EasyPost API Documentation} for more information. + * @param {string} id - The ID of the insurance to retrieve. + * @returns {Insurance} - The retrieved insurance. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/order_service/Order.d.ts b/types/services/order_service/Order.d.ts new file mode 100644 index 000000000..0b9a96406 --- /dev/null +++ b/types/services/order_service/Order.d.ts @@ -0,0 +1,53 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; +import { IRate } from '../rate_service'; +import { IMessage, IShipment } from '../shipment_service'; +/** + * The Order object represents a collection of packages and can be used for Multi-Piece Shipments. + * Like a single Shipment each Order consists of a "to" and "from" Address to be used for each Shipment within the Order. + * These Addresses will be copied to each Shipment so there is no need to specify them multiple times. + * Each Shipment must then specify its Parcel, Options, and CustomsInfo. + * + * An Order created with valid Address Objects and Parcel data nested within the Order's Shipment object will automatically retrieve available shipping Rate options. + * + * @see https://www.easypost.com/docs/api/node#order-object + */ +export type IOrder = IObjectWithId<'Order'> & + IDatedObject & { + /** + * An optional field that may be used in place of id in other API endpoints + */ + reference?: string | null; + /** + * The destination address + */ + to_address: IAddress; + /** + * The origin address + */ + from_address: IAddress; + /** + * The shipper's address, defaults to from_address + */ + return_address?: IAddress | null; + /** + * The buyer's address, defaults to to_address + */ + buyer_address?: IAddress | null; + /** + * All associated Shipment objects. Maximum of 100. + */ + shipments: IShipment[]; + /** + * All associated Rate objects + */ + rates: IRate[]; + /** + * Any carrier errors encountered during rating + */ + messages: IMessage[]; + /** + * Set true to create as a return + */ + is_return?: boolean | null; + }; diff --git a/types/services/order_service/OrderCreateParameters.d.ts b/types/services/order_service/OrderCreateParameters.d.ts new file mode 100644 index 000000000..8368b1d68 --- /dev/null +++ b/types/services/order_service/OrderCreateParameters.d.ts @@ -0,0 +1,12 @@ +import { IAddress } from '../address_service'; +import { IShipment } from '../shipment_service'; +export type IOrderCreateParameters = { + reference?: string | null; + to_address: IAddress | string; + from_address: IAddress | string; + shipments: IShipment[]; + /** + * optional array of ids that begin with "ca_" + */ + carrier_accounts?: string[] | null; +}; diff --git a/types/services/order_service/index.d.ts b/types/services/order_service/index.d.ts new file mode 100644 index 000000000..4d07b7efe --- /dev/null +++ b/types/services/order_service/index.d.ts @@ -0,0 +1,79 @@ +import EasyPost from '../..'; +import { IRate } from '../rate_service'; +import { IOrder } from './Order'; +import { IOrderCreateParameters } from './OrderCreateParameters'; +export * from './Order'; +export * from './OrderCreateParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create an {@link Order order}. + * See {@link https://www.easypost.com/docs/api/node#create-an-order EasyPost API Documentation} for more information. + * @param params - The parameters to create an order with. + * @returns - The created order. + */ + create(params: IOrderCreateParameters): Promise>; + /** + * Purchase an {@link Order order}. + * See {@link https://www.easypost.com/docs/api/node#buy-an-order EasyPost API Documentation} for more information. + * @param id - The ID of the order to buy. + * @param carrier - The carrier to use for the order purchase. + * @param service - The service to use for the order purchase. + * @returns - The purchased order. + */ + buy( + id: string, + carrier: string, + service: string, + ): Promise>; + /** + * Get updated rates for an {@link Order order}. + * See {@link https://www.easypost.com/docs/api/node#orders EasyPost API Documentation} for more information. + * @param id - The ID of the order to get rates for. + * @returns - The order with rates. + */ + getRates(id: string): Promise>; + /** + * Retrieve an {@link Order order} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-order EasyPost API Documentation} for more information. + * @param id - The ID of the order to retrieve. + * @returns - The retrieved order. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + > + /** + * Retrieve an {@link Order order} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-order EasyPost API Documentation} for more information. + * @param id - The ID of the order to retrieve. + * @returns - The retrieved order. + */; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/parcel_service/Parcel.d.ts b/types/services/parcel_service/Parcel.d.ts new file mode 100644 index 000000000..f0c7c6535 --- /dev/null +++ b/types/services/parcel_service/Parcel.d.ts @@ -0,0 +1,38 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * Parcel objects represent the physical container being shipped. + * Dimensions can be supplied either as length, width, and height dimensions, or a predefined_package string. + * Only weight is required, but since many carriers charge different rates for packages with large dimensions, we strongly recommend including all dimensions if available. + * + * Weights are in OUNCES (OZ) and go to one decimal point. + * Dimensions are in INCHES (IN) and go to one decimal point. + * + * @see https://www.easypost.com/docs/api/node#parcel-object + */ +export type IParcel = IObjectWithId<'Parcel'> & + IDatedObject & { + /** + * Required if width and/or height are present + * float (inches) + */ + length?: number | null; + /** + * Required if width and/or height are present + * float (inches) + */ + width?: number | null; + /** + * Required if width and/or height are present + * float (inches) + */ + height?: number | null; + /** + * Always required + * float (oz) + */ + weight: number; + /** + * Optional, one of our predefined_packages + */ + predefined_package?: string | null; + }; diff --git a/types/services/parcel_service/ParcelCreateParameters.d.ts b/types/services/parcel_service/ParcelCreateParameters.d.ts new file mode 100644 index 000000000..35f07b297 --- /dev/null +++ b/types/services/parcel_service/ParcelCreateParameters.d.ts @@ -0,0 +1,24 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IParcel } from './Parcel'; +export type IParcelCreateParameters = Omit & { + /** + * Required if width and/or height are present + * float (inches) + */ + length?: number | null; + /** + * Required if width and/or height are present + * float (inches) + */ + width?: number | null; + /** + * Required if width and/or height are present + * float (inches) + */ + height?: number | null; + /** + * Always required + * float (oz) + */ + weight: number; +}; diff --git a/types/services/parcel_service/index.d.ts b/types/services/parcel_service/index.d.ts new file mode 100644 index 000000000..cd23ad71e --- /dev/null +++ b/types/services/parcel_service/index.d.ts @@ -0,0 +1,54 @@ +import EasyPost from '../..'; +import { IParcel } from './Parcel'; +import { IParcelCreateParameters } from './ParcelCreateParameters'; +export * from './Parcel'; +export * from './ParcelCreateParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Parcel parcel}. + * See {@link https://www.easypost.com/docs/api/node#create-a-parcel EasyPost API Documentation} for more information. + * @param params - The parameters to create a parcel with. + * @returns - The created parcel. + */ + create( + params: IParcelCreateParameters, + ): Promise>; + /** + * Retrieve a {@link Parcel parcel} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-parcel EasyPost API Documentation} for more information. + * @param id - The ID of the parcel to retrieve. + * @returns - The retrieved parcel. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/pickup_service/Pickup.d.ts b/types/services/pickup_service/Pickup.d.ts new file mode 100644 index 000000000..ae6a57f4f --- /dev/null +++ b/types/services/pickup_service/Pickup.d.ts @@ -0,0 +1,77 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; +import { ICarrierAccount } from '../carrier_account_service'; +import { IMessage, IShipment } from '../shipment_service'; +import { IPickupRate } from './PickupRate'; +/** + * The Pickup object allows you to schedule a pickup from your carrier from your customer's residence or place of business. + * Supported carriers include: + * - Canada Post + * - Canpar + * - DHL Express + * - FedEx + * - Lasership + * - Loomis Express + * - LSO + * - Ontrac + * - UPS + * - USPS + * - Veho + * + * After a Pickup is successfully created, it will automatically fetch PickupRates for each CarrierAccount specified that supports scheduled pickups. + * Then a PickupRate must be selected and purchased before the pickup can be successfully scheduled. + * + * @see https://www.easypost.com/docs/api/node#pickup-object + */ +export type IPickup = IObjectWithId<'Pickup'> & + IDatedObject & { + /** + * An optional field that may be used in place of ID in some API endpoints + */ + reference?: string | null; + /** + * One of: "unknown", "scheduled", or "canceled" + */ + status: 'unknown' | 'scheduled' | 'canceled'; + /** + * The earliest time at which the package is available to pick up + */ + min_datetime: string; + /** + * The latest time at which the package is available to pick up. + * Must be later than the min_datetime + */ + max_datetime: string; + /** + * Is the pickup address the account's address? + */ + is_account_address?: boolean | null; + /** + * Additional text to help the driver successfully obtain the package + */ + instructions?: string | null; + /** + * A list of messages containing carrier errors encountered during pickup rate generation + */ + messages: IMessage[]; + /** + * The confirmation number for a booked pickup from the carrier + */ + confirmation: string; + /** + * The associated Shipment + */ + shipment: IShipment; + /** + * The associated Address + */ + address: IAddress; + /** + * The list of carriers (if empty, all carriers were used) used to generate pickup rates + */ + carrier_accounts?: ICarrierAccount[] | null; + /** + * The list of different pickup rates across valid carrier accounts for the shipment + */ + pickup_rates: IPickupRate[]; + }; diff --git a/types/services/pickup_service/PickupCreateParameters.d.ts b/types/services/pickup_service/PickupCreateParameters.d.ts new file mode 100644 index 000000000..d4c180dcc --- /dev/null +++ b/types/services/pickup_service/PickupCreateParameters.d.ts @@ -0,0 +1,37 @@ +import { IAddress } from '../address_service'; +import { IBatch } from '../batch_service'; +import { ICarrierAccount } from '../carrier_account_service'; +import { IShipment } from '../shipment_service'; +import { IPickupRate } from './PickupRate'; +type BasePickupCreateParameters = { + address: IAddress | string; + carrier_accounts?: ICarrierAccount[] | null; + confirmation?: string | null; + instructions?: string | null; + is_account_address?: boolean | null; + max_datetime: string; + min_datetime: string; + pickup_rates: IPickupRate; + reference?: string | null; + status: string; +}; +type ShipmentPickupCreateParameters = BasePickupCreateParameters & { + shipment?: + | IShipment + | { + id: string; + } + | string + | null; +}; +type BatchPickupCreateParameters = BasePickupCreateParameters & { + batch?: + | IBatch + | { + id: string; + } + | string + | null; +}; +export type IPickupCreateParameters = ShipmentPickupCreateParameters | BatchPickupCreateParameters; +export {}; diff --git a/types/services/pickup_service/PickupListParameters.d.ts b/types/services/pickup_service/PickupListParameters.d.ts new file mode 100644 index 000000000..806edf7f0 --- /dev/null +++ b/types/services/pickup_service/PickupListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups + */ +export type IPickupListParameters = IAllMethodParameters; diff --git a/types/services/pickup_service/PickupRate.d.ts b/types/services/pickup_service/PickupRate.d.ts new file mode 100644 index 000000000..53983d86e --- /dev/null +++ b/types/services/pickup_service/PickupRate.d.ts @@ -0,0 +1,27 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#pickup-rate-object + */ +export type IPickupRate = IObjectWithId<'PickupRate'> & + IDatedObject & { + /** + * service name + */ + service: string; + /** + * name of carrier + */ + carrier: string; + /** + * the actual rate quote for this service + */ + rate: string; + /** + * currency for the rate + */ + currency: string; + /** + * the ID of the pickup this is a quote for + */ + pickup_id: string; + }; diff --git a/types/services/pickup_service/index.d.ts b/types/services/pickup_service/index.d.ts new file mode 100644 index 000000000..bbab7e5c2 --- /dev/null +++ b/types/services/pickup_service/index.d.ts @@ -0,0 +1,110 @@ +import EasyPost from '../..'; +import { IPickup } from './Pickup'; +import { IPickupCreateParameters } from './PickupCreateParameters'; +import { IPickupListParameters } from './PickupListParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Pickup pickup}. + * See {@link https://www.easypost.com/docs/api/node#create-a-pickup EasyPost API Documentation} for more information. + * @param params - The parameters to create a pickup with. + * @returns - The created pickup. + */ + create( + params: IPickupCreateParameters, + ): Promise>; + /** + * Purchase a {@link Pickup pickup}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-pickup EasyPost API Documentation} for more information. + * @param id - The ID of the pickup to purchase. + * @param carrier - The carrier to purchase the pickup with. + * @param service - The service to purchase the pickup with. + * @returns - The purchased pickup. + */ + buy( + id: string, + carrier: string, + service: string, + ): Promise>; + /** + * Cancel a {@link Pickup pickup}. + * See {@link https://www.easypost.com/docs/api/node#cancel-a-pickup EasyPost API Documentation} for more information. + * @param id - The ID of the pickup to cancel. + * @returns - The cancelled pickup. + */ + cancel(id: string): Promise>; + /** + * Retrieve all {@link Pickup pickups} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the pickups by. + * @returns - An object containing a list of {@link Pickup pickups} and pagination information. + */ + all(params?: IPickupListParameters): Promise< + IPickup[] & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of Pickup collection. + * @param pickups An object containing a list of {@link Pickup pickups} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + pickups: any, + pageSize?: number | null, + ): Promise< + { + pickups: IPickup[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link Pickup pickup} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-pickup EasyPost API Documentation} for more information. + * @param id - The ID of the pickup to retrieve. + * @returns - The retrieved pickup. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise> + /** + * Retrieve the next page of Pickup collection. + * @param pickups An object containing a list of {@link Pickup pickups} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/rate_service/Rate.d.ts b/types/services/rate_service/Rate.d.ts new file mode 100644 index 000000000..d53e172de --- /dev/null +++ b/types/services/rate_service/Rate.d.ts @@ -0,0 +1,81 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * The Rate class represents a summary of the price and details of a delivery service quote. + * + * @see https://www.easypost.com/docs/api/node#rates + */ +export type IRate = IObjectWithId<'Rate'> & + IDatedObject & { + /** + * The service level of the rate. + */ + service: string; + /** + * The carrier of the rate. + */ + carrier: string; + /** + * The ID of the carrier account associated with this rate. + */ + carrier_account_id: string; + /** + * The ID of the shipment associated with this rate. + */ + shipment_id: string; + /** + * The quote price of the rate. + */ + rate: string; + /** + * The currency of the rate. + */ + currency: string; + /** + * The in-store retail rate given with no account. + */ + retail_rate: string; + /** + * The currency of the retail rate. + */ + retail_currency: string; + /** + * The non-negotiated rate given for having an account with the carrier. + */ + list_rate: string; + /** + * The currency of the list rate. + */ + list_currency: string; + /** + * The number of days in transit for this rate. + */ + delivery_days: number; + /** + * The delivery date for this rate. + */ + delivery_date: string; + /** + * Whether the delivery window is guaranteed. + */ + delivery_date_guaranteed: boolean; + /** + * The earliest delivery date for this rate. + * This is deprecated and should be ignored. + */ + est_delivery_days: number; + /** + * The billing type of the rate. + */ + billing_type: string; + }; +export type ISmartRate = IRate & { + time_in_transit: { + percentile_50: number; + percentile_75: number; + percentile_85: number; + percentile_90: number; + percentile_95: number; + percentile_97: number; + percentile_99: number; + }; +}; diff --git a/types/services/rate_service/index.d.ts b/types/services/rate_service/index.d.ts new file mode 100644 index 000000000..b51193687 --- /dev/null +++ b/types/services/rate_service/index.d.ts @@ -0,0 +1,43 @@ +import EasyPost from '../..'; +import { IRate } from './Rate'; +export * from './Rate'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Retrieve a {@link Rate rate} by its ID. + * See {@link https://www.easypost.com/docs/api/node#rates EasyPost API Documentation} for more information. + * @param {string} id - The ID of the rate to retrieve. + * @returns {Rate} - The retrieved rate. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/referral_customer_service/Referral.d.ts b/types/services/referral_customer_service/Referral.d.ts new file mode 100644 index 000000000..b83dfa0a6 --- /dev/null +++ b/types/services/referral_customer_service/Referral.d.ts @@ -0,0 +1,7 @@ +import { IUser } from '../user_service'; +/** + * A Referral represents a sub-user under a Partner or white-label account. + * + * @see https://www.easypost.com/docs/api/node#referral-customers + */ +export declare interface IReferral extends IUser {} diff --git a/types/services/referral_customer_service/ReferralCreateParameters.d.ts b/types/services/referral_customer_service/ReferralCreateParameters.d.ts new file mode 100644 index 000000000..7035f552d --- /dev/null +++ b/types/services/referral_customer_service/ReferralCreateParameters.d.ts @@ -0,0 +1,3 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IReferral } from './Referral'; +export type IReferralCreateParameters = Omit; diff --git a/types/services/referral_customer_service/ReferralListParameters.d.ts b/types/services/referral_customer_service/ReferralListParameters.d.ts new file mode 100644 index 000000000..f26fe30bd --- /dev/null +++ b/types/services/referral_customer_service/ReferralListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers + */ +export type IReferralListParameters = IAllMethodParameters; diff --git a/types/services/referral_customer_service/index.d.ts b/types/services/referral_customer_service/index.d.ts new file mode 100644 index 000000000..2f4520f4e --- /dev/null +++ b/types/services/referral_customer_service/index.d.ts @@ -0,0 +1,108 @@ +import EasyPost from '../..'; +import { IReferralCreateParameters } from './ReferralCreateParameters'; +import { IReferral } from './Referral'; +import { IReferralListParameters } from './ReferralListParameters'; +import { IPaymentMethod } from '../billing_service'; +export * from './Referral'; +export * from './ReferralCreateParameters'; +export * from './ReferralListParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link User referral customer}. + * See {@link https://www.easypost.com/docs/api/node#create-a-referral-customer EasyPost API Documentation} for more information. + * @param params - The referral customer's information. + * @returns - The newly created referral customer. + */ + create( + params: IReferralCreateParameters, + ): Promise>; + /** + * Update a {@link User referral customer's} email address. + * See {@link https://www.easypost.com/docs/api/node#update-a-referral-customer EasyPost API Documentation} for more information. + * @param referralUserId - The ID of the referral customer to update. + * @param email - The new email address. + * @returns - Returns true if the referral was updated successfully, false otherwise. + */ + updateEmail(referralUserId: string, email: string): Promise; + /** + * Add a credit card to a {@link User referral customer's} account. + * See {@link https://www.easypost.com/docs/api/node#create-credit-card EasyPost API Documentation} for more information. + * @param referralApiKey - The referral customer's production API key. + * @param number - The credit card number. + * @param expirationMonth - The credit card expiration month. + * @param expirationYear - The credit card expiration year. + * @param cvc - The credit card CVC. + * @param priority - Whether to add the card as 'primary' or 'secondary' payment method (defaults to 'primary'). + * @returns - An object representing the newly-added credit card. + */ + addCreditCard( + referralApiKey: string, + number: string, + expirationMonth: string, + expirationYear: string, + cvc: string, + priority?: 'primary' | 'secondary', + ): Promise; + /** + * Retrieve all {@link User referral customers} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the referral customers by. + * @returns - An object containing a list of {@link User referral customers} and pagination information. + */ + all(params?: IReferralListParameters): Promise< + IReferral[] & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of Referral Customer collection. + * @param referralCustomers An object containing a list of {@link referral referralCustomers} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + referralCustomers: any, + pageSize?: number | null, + ): Promise< + { + referral_customers: IReferral[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/refund_service/Refund.d.ts b/types/services/refund_service/Refund.d.ts new file mode 100644 index 000000000..1765f8ccb --- /dev/null +++ b/types/services/refund_service/Refund.d.ts @@ -0,0 +1,31 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * The Refund object represents a refunded shipment, and includes details about the related Shipment and tracking code. + * USPS shipping labels can be refunded if requested within 30 days of generation. + * The processing time is at least 15 days, after which the funds will return to your EasyPost balance. + * EasyPost fees will also be refunded. To qualify, a shipment must not have been scanned by the USPS. + * UPS and FedEx shipping labels may be refunded within 90 days of creation. + */ +export type IRefund = IObjectWithId<'Refund'> & + IDatedObject & { + /** + * The tracking code of the related Shipment + */ + tracking_code: string; + /** + * The confirmation number for the refund request to the carrier + */ + confirmation_number: string; + /** + * The status of the refund request, reported by the carrier. Possible values are "submitted", "refunded", or "rejected" + */ + status: 'submitted' | 'refunded' | 'rejected'; + /** + * The carrier the refund request was submitted to + */ + carrier: string; + /** + * The ID of the related Shipment being refunded + */ + shipment_id: string; + }; diff --git a/types/services/refund_service/RefundCreateParameters.d.ts b/types/services/refund_service/RefundCreateParameters.d.ts new file mode 100644 index 000000000..56419c78e --- /dev/null +++ b/types/services/refund_service/RefundCreateParameters.d.ts @@ -0,0 +1,13 @@ +/** + * @see https://www.easypost.com/docs/api/node#create-a-refund + */ +export type IRefundCreateParameters = { + /** + * The carrier to request a refund from + */ + carrier: string; + /** + * A list of tracking codes to request refunds for. Even for a single tracking code, it needs to be submitted as a list. + */ + tracking_codes: string[]; +}; diff --git a/types/services/refund_service/RefundListParameters.d.ts b/types/services/refund_service/RefundListParameters.d.ts new file mode 100644 index 000000000..5239e02d8 --- /dev/null +++ b/types/services/refund_service/RefundListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds + */ +export type IRefundListParameters = IAllMethodParameters; diff --git a/types/services/refund_service/index.d.ts b/types/services/refund_service/index.d.ts new file mode 100644 index 000000000..d476fbfd5 --- /dev/null +++ b/types/services/refund_service/index.d.ts @@ -0,0 +1,89 @@ +import EasyPost from '../..'; +import { IRefund } from './Refund'; +import { IRefundCreateParameters } from './RefundCreateParameters'; +import { IRefundListParameters } from './RefundListParameters'; +export * from './Refund'; +export * from './RefundCreateParameters'; +export * from './RefundListParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Refund refund}. + * See {@link https://www.easypost.com/docs/api/node#create-a-refund EasyPost API Documentation} for more information. + * @param params - The parameters to create a refund with. + * @returns - The created refund. + */ + create( + params: IRefundCreateParameters, + ): Promise>; + /** + * Retrieve all {@link Refund refunds} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the refunds by. + * @returns - An object containing the list of {@link Refund refunds} and pagination information. + */ + all(params?: IRefundListParameters): Promise< + { + refunds: IRefund[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of Refund collection. + * @param refunds An object containing a list of {@link Refund refunds} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + refunds: any, + pageSize?: number | null, + ): Promise< + { + refunds: IRefund[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link Refund refund} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-refund EasyPost API Documentation} for more information. + * @param id - The ID of the refund to retrieve. + * @returns - The retrieved refund. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/report_service/Report.d.ts b/types/services/report_service/Report.d.ts new file mode 100644 index 000000000..bc01c19c3 --- /dev/null +++ b/types/services/report_service/Report.d.ts @@ -0,0 +1,52 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { TReportObjectType } from './ReportObjectType'; +/** + * A Report contains a csv that is a log of all the objects created within a certain time frame. + * + * Reports can be generated using the Reports Endpoint. + * You can create and view Reports created between any time frame defined between the start_date and end_date. + * + * The Report api can be categorized into several types. + * These types determine which EasyPost Object to produce a Report for, and should be passed as the type in our libraries: + * - cash_flow + * - insurance + * - payment_log + * - refund + * - shipment + * - shipment_invoice + * - tracker + * + * @see https://www.easypost.com/docs/api/node#report-object + */ +export type IReport = IObjectWithId & + IDatedObject & { + /** + * "new", "available", "failed", or null + */ + status: 'new' | 'available' | 'failed' | null; + /** + * A date string in YYYY-MM-DD form eg: "2016-02-02" + */ + start_date: string; + /** + * A date string in YYYY-MM-DD form eg: "2016-02-03" + */ + end_date: string; + /** + * Set true if you would like to include Refunds /Shipments /Trackers created by child users + */ + include_children?: boolean | null; + /** + * A url that contains a link to the Report. + * Expires 30 seconds after retrieving this object + */ + url: string; + /** + * Url expiring time + */ + url_expires_at: string; + /** + * Set true if you would like to send an email containing the Report + */ + send_email?: boolean | null; + }; diff --git a/types/services/report_service/ReportCreateParameters.d.ts b/types/services/report_service/ReportCreateParameters.d.ts new file mode 100644 index 000000000..909b9d4df --- /dev/null +++ b/types/services/report_service/ReportCreateParameters.d.ts @@ -0,0 +1,10 @@ +import { TReportType } from './ReportObjectType'; +export type IReportCreateParameters = { + type: TReportType; + start_date: string | null; + end_date?: string | null; + include_children?: boolean | null; + send_email?: boolean | null; + columns?: string[] | null; + additional_columns?: string[] | null; +}; diff --git a/types/services/report_service/ReportListParameters.d.ts b/types/services/report_service/ReportListParameters.d.ts new file mode 100644 index 000000000..2c8e5efe7 --- /dev/null +++ b/types/services/report_service/ReportListParameters.d.ts @@ -0,0 +1,8 @@ +import { IAllMethodParameters } from '../../utils/types'; +import { TReportType } from './ReportObjectType'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds + */ +export type IReportListParameters = IAllMethodParameters & { + type: TReportType; +}; diff --git a/types/services/report_service/ReportObjectType.d.ts b/types/services/report_service/ReportObjectType.d.ts new file mode 100644 index 000000000..918f61516 --- /dev/null +++ b/types/services/report_service/ReportObjectType.d.ts @@ -0,0 +1,14 @@ +export type TReportObjectType = + | 'CashFlowReport' + | 'PaymentLogReport' + | 'RefundReport' + | 'ShipmentReport' + | 'ShipmentInvoiceReport' + | 'TrackerReport'; +export type TReportType = + | 'cash_flow' + | 'payment_log' + | 'refund' + | 'shipment' + | 'shipment_invoice' + | 'tracker'; diff --git a/types/services/report_service/index.d.ts b/types/services/report_service/index.d.ts new file mode 100644 index 000000000..998522b84 --- /dev/null +++ b/types/services/report_service/index.d.ts @@ -0,0 +1,82 @@ +import EasyPost from '../..'; +import { IReport } from './Report'; +import { IReportCreateParameters } from './ReportCreateParameters'; +import { IReportListParameters } from './ReportListParameters'; +export * from './Report'; +export * from './ReportCreateParameters'; +export * from './ReportListParameters'; +export * from './ReportObjectType'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Report report}. + * See {@link https://www.easypost.com/docs/api/node#create-a-report EasyPost API Documentation} for more information. + * @param params - The parameters to create a report with. + * @returns - The created report. + */ + create( + params: IReportCreateParameters, + ): Promise>; + /** + * Retrieve all {@link Report reports} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-reports EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the reports by. + * @returns - An object containing the list of {@link Report reports} and pagination information. + */ + all(params: IReportListParameters): Promise; + /** + * Retrieve the next page of Report collection. + * @param reports An object containing a list of {@link Report reports} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + reports: any, + pageSize?: number | null, + ): Promise< + { + reports: IReport[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link Report report} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-report EasyPost API Documentation} for more information. + * @param id - The ID of the report to retrieve. + * @returns - The retrieved report. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/scan_form_service/ScanForm.d.ts b/types/services/scan_form_service/ScanForm.d.ts new file mode 100644 index 000000000..9cba95498 --- /dev/null +++ b/types/services/scan_form_service/ScanForm.d.ts @@ -0,0 +1,47 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; +/** + * A ScanForm can be created to speed up and simplify the carrier pickup process. + * The ScanForm is one document that can be scanned to mark all included tracking codes as "Accepted for Shipment" by the carrier. + * The following criteria must met before creation: + * - Refunded Shipments cannot be added + * - Each Shipment must have the same origin address + * - Shipments must all be dated (using the label_date option) on or after the date the form is generated + * - Shipments cannot be added to more than one ScanForm + * - Existing ScanForms may not be updated with additional Shipments. If a ScanForm already exists, and new Shipments need to be added, a new ScanForm must be created. + * - Shipments should be provided in the form of an array + * + * @see https://www.easypost.com/docs/api/node#scan-form-object + */ +export type IScanForm = IObjectWithId<'ScanForm'> & + IDatedObject & { + /** + * Current status. + * Possible values are "creating", "created" and "failed" + */ + status: 'creating' | 'created' | 'failed'; + /** + * Human-readable message explaining any failures + */ + message: string; + /** + * Address that the Shipments will be shipped from + */ + address: IAddress; + /** + * Tracking codes included on the ScanForm + */ + tracking_codes: string[]; + /** + * Url of the document + */ + form_url: string; + /** + * File format of the document + */ + form_file_type: string; + /** + * The id of the associated Batch. Unique, starts with "batch_" + */ + batch_id: string; + }; diff --git a/types/services/scan_form_service/ScanFormCreateParameters.d.ts b/types/services/scan_form_service/ScanFormCreateParameters.d.ts new file mode 100644 index 000000000..9642f1e8d --- /dev/null +++ b/types/services/scan_form_service/ScanFormCreateParameters.d.ts @@ -0,0 +1,9 @@ +import { DeepPartial } from '../../utils/types'; +import { IShipmentCreateParameters } from '../shipment_service'; +export type IScanFormCreateParameters = { + shipments: + | (DeepPartial & { + id: string; + })[] + | string[]; +}; diff --git a/types/services/scan_form_service/ScanFormListParameters.d.ts b/types/services/scan_form_service/ScanFormListParameters.d.ts new file mode 100644 index 000000000..655a0094c --- /dev/null +++ b/types/services/scan_form_service/ScanFormListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-scan-forms + */ +export type IScanFormListParameters = IAllMethodParameters; diff --git a/types/services/scan_form_service/index.d.ts b/types/services/scan_form_service/index.d.ts new file mode 100644 index 000000000..59563b781 --- /dev/null +++ b/types/services/scan_form_service/index.d.ts @@ -0,0 +1,91 @@ +import EasyPost from '../..'; +import { IScanForm } from './ScanForm'; +import { IScanFormCreateParameters } from './ScanFormCreateParameters'; +import { IScanFormListParameters } from './ScanFormListParameters'; +export * from './ScanForm'; +export * from './ScanFormCreateParameters'; +export * from './ScanFormListParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link ScanForm scan form}. + * See {@link https://www.easypost.com/docs/api/node#create-a-scanform EasyPost API Documentation} for more information. + * @param params - The parameters to create a scan form with. + * @returns - The created scan form. + */ + create( + params: IScanFormCreateParameters, + ): Promise>; + /** + * Retrieve all {@link ScanForm scan forms} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-scanforms EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the scan forms by. + * @returns - An object containing the list of {@link ScanForm scan forms} and pagination information. + */ + all(params?: IScanFormListParameters): Promise< + { + scan_forms: IScanForm[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of ScanForm collection. + * @param scanForms An object containing a list of {@link ScanForm scanForms} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + scanForms: { + scan_forms: any[]; + }, + pageSize?: number | null, + ): Promise< + { + scan_forms: IScanForm[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link ScanForm scan form} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-scanform EasyPost API Documentation} for more information. + * @param id - The ID of the scan form to retrieve. + * @returns - The retrieved scan form. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/shipment_service/Form.d.ts b/types/services/shipment_service/Form.d.ts new file mode 100644 index 000000000..c7430545a --- /dev/null +++ b/types/services/shipment_service/Form.d.ts @@ -0,0 +1,28 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#form-object + */ +export type IForm = IObjectWithId<'Form'> & + IDatedObject & { + /** + * The type of form that we returned, can be one of "cn22", "cod_return_label", "commercial_invoice", "high_value_report", "label_qr_code", "nafta_certificate_of_origin", "order_summary", "return_packing_slip", "rma_qr_code" + */ + form_type: + | 'cn22' + | 'cod_return_label' + | 'commercial_invoice' + | 'high_value_report' + | 'label_qr_code' + | 'nafta_certificate_of_origin' + | 'order_summary' + | 'return_packing_slip' + | 'rma_qr_code'; + /** + * The address we return the form back at + */ + form_url: string; + /** + * If we have submitted the form to the carrier on behalf of the customer + */ + submitted_electronically: boolean; + }; diff --git a/types/services/shipment_service/Message.d.ts b/types/services/shipment_service/Message.d.ts new file mode 100644 index 000000000..ff845b655 --- /dev/null +++ b/types/services/shipment_service/Message.d.ts @@ -0,0 +1,27 @@ +/** + * When rating a Shipment or Pickup, some carriers may fail to generate rates. + * These failures are returned as part of the Shipment or Pickup as part of their messages attribute, and follow a common object structure. + * + * It is important to note that the message value for any member of this list comes directly from the carrier, not from EasyPost. + * This means that if you see an authentication or other non-shipping error here, it is not an issue between you and EasyPost, it is an issue between you and the carrier, or an issue with the given data. + * + * @see https://www.easypost.com/docs/api/node#message-object + */ +export type IMessage = { + /** + * the name of the carrier generating the error, e.g. "UPS" + */ + carrier: string; + /** + * the category of error that occurred. Most frequently "rate_error" + */ + type: string; + /** + * the string from the carrier explaining the problem + */ + message: string; + /** + * the account id of the carrier. Useful if you have multiple accounts with the same carrier + */ + carrier_account_id: string; +}; diff --git a/types/services/shipment_service/Options/LabelFormat.d.ts b/types/services/shipment_service/Options/LabelFormat.d.ts new file mode 100644 index 000000000..cc3a84031 --- /dev/null +++ b/types/services/shipment_service/Options/LabelFormat.d.ts @@ -0,0 +1 @@ +export declare type LabelFormat = 'PNG' | 'PDF' | 'ZPL' | 'EPL2'; diff --git a/types/services/shipment_service/Options/Options.d.ts b/types/services/shipment_service/Options/Options.d.ts new file mode 100644 index 000000000..52b3a842f --- /dev/null +++ b/types/services/shipment_service/Options/Options.d.ts @@ -0,0 +1,325 @@ +import { LabelFormat } from './LabelFormat'; +import { TPrintCustomCode } from './PrintCustomCode'; +/** + * Shipments can have a variety of additional options which you can specify when creating a shipment. + * The Options object can be populated with the keys below. + * + * @see https://www.easypost.com/docs/api/node#options-object + */ +export type IOptions = { + /** + * Setting this option to true, will add an additional handling charge. + * An Additional Handling charge may be applied to the following: + * - Any article that is encased in an outside shipping container made of metal or wood. + * - Any item, such as a barrel, drum, pail or tire, that is not fully encased in a corrugated cardboard shipping container. + * - Any package with the longest side exceeding 60 inches or its second longest side exceeding 30 inches. + * - Any package with an actual weight greater than 70 pounds. + */ + additional_handling?: boolean | null; + /** + * Setting this option to "0", will allow the minimum amount of address information to pass the validation check. + * Only for USPS postage. + */ + address_validation_level?: string | null; + /** + * Set this option to true if your shipment contains alcohol. + * - UPS - only supported for US Domestic shipments + * - FedEx - only supported for US Domestic shipments + * - Canada Post - Requires adult signature 19 years or older. If you want adult signature 18 years or older, instead use delivery_confirmation: ADULT_SIGNATURE + */ + alcohol?: boolean | null; + /** + * Setting this option to true will indicate to the carrier to prefer delivery by drone, if the carrier supports drone delivery. + */ + by_drone?: boolean | null; + /** + * Setting this to true will add a charge to reduce carbon emissions. + */ + carbon_neutral?: boolean | null; + /** + * Adding an amount will have the carrier collect the specified amount from the recipient. + */ + cod_amount?: string | null; + /** + * Method for payment. "CASH", "CHECK", "MONEY_ORDER" + */ + cod_method?: 'CASH' | 'CHECK' | 'MONEY_ORDER' | null; + /** + * The ID of the Address to which the COD payment should be returned. + * Defaults to the origin address. + * Only available on FedEx shipments. + */ + cod_address_id?: string | null; + /** + * A description of the content of the shipment. + */ + content_description?: string | null; + /** + * Which currency this shipment will show for rates if carrier allows. + */ + currency?: string | null; + /** + * If you want to request a signature, you can pass "ADULT_SIGNATURE" or "SIGNATURE". + * You may also request "NO_SIGNATURE" to leave the package at the door. + * - All - some options may be limited for international shipments + * - FedEx - "INDIRECT_SIGNATURE" is also an option + * - USPS - additional options + * - "ADULT_SIGNATURE_RESTRICTED" + * - "SIGNATURE_RESTRICTED" + * - Canada Post - "DO_NOT_SAFE_DROP" - Tells the carrier to not hide the package ("safe drop"). + * - GSO - "STANDARD_SIGNATURE". + * - DHL Express - option mapping + * - "SIGNATURE" - DHL Express Direct Signature + * - "NO_SIGNATURE" - DHL Express Signature Release + */ + delivery_confirmation?: + | 'ADULT_SIGNATURE' + | 'SIGNATURE' + | 'NO_SIGNATURE' + | 'INDIRECT_SIGNATURE' + | 'ADULT_SIGNATURE_RESTRICTED' + | 'SIGNATURE_RESTRICTED' + | null; + /** + * Method the customer will use to transfer the package to the carrier. + * "REGULAR_PICKUP", "SCHEDULED_PICKUP", "RETAIL_LOCATION", "STATION" or "DROP_BOX". + * Supported carriers and their corresponding carrier dropoff codes: + * - FedEx + * - "REGULAR_PICKUP" - "REGULAR_PICKUP" (default) + * - "SCHEDULED_PICKUP" - "REQUEST_COURIER" + * - "RETAIL_LOCATION" - "BUSINESS_SERVICE_CENTER" + * - "STATION" - "STATION" + * - "DROP_BOX" - "DROP_BOX" + */ + dropoff_type?: + | 'REGULAR_PICKUP' + | 'SCHEDULED_PICKUP' + | 'RETAIL_LOCATION' + | 'STATION' + | 'DROP_BOX' + | 'REQUEST_COURIER' + | 'BUSINESS_SERVICE_CENTER' + | null; + /** + * Package contents contain dry ice. + * - UPS - Need dry_ice_weight to be set + * - UPS MailInnovations - Need dry_ice_weight to be set + * - FedEx - Need dry_ice_weight to be set + */ + dry_ice?: boolean | null; + /** + * If the dry ice is for medical use, set this option to true. + * - UPS - Need dry_ice_weight to be set + * - UPS MailInnovations - Need dry_ice_weight to be set + */ + dry_ice_medical?: boolean | null; + /** + * Weight of the dry ice in ounces. + * - UPS - Need dry_ice to be set + * - UPS MailInnovations - Need dry_ice to be set + * - FedEx - Need dry_ice to be set + */ + dry_ice_weight?: string | null; + /** + * Setting duty_payment type to bill the correct account for purchasing postage. + * This option is only available with FedEx and UPS. + * - type - (string) Supported values are "THIRD_PARTY", and "RECEIVER". + * - account - (string) Setting account number. + * - country - (string) Setting country code that the account is based in. + * - postal_code - (string) Setting postal code that the account is based in. + */ + duty_payment?: object | null; + /** + * Possible values "ADDRESS_SERVICE_REQUESTED", "FORWARDING_SERVICE_REQUESTED", "CHANGE_SERVICE_REQUESTED", "RETURN_SERVICE_REQUESTED", "LEAVE_IF_NO_RESPONSE" + */ + endorsement?: + | 'ADDRESS_SERVICE_REQUESTED' + | 'FORWARDING_SERVICE_REQUESTED' + | 'CHANGE_SERVICE_REQUESTED' + | 'RETURN_SERVICE_REQUESTED' + | 'LEAVE_IF_NO_RESPONSE' + | null; + /** + * Specify the responsible EndShipper for the shipment by passing in an EndShipper ID. + */ + end_shipper_id?: string | null; + /** + * Additional cost to be added to the invoice of this shipment. + * Only applies to UPS currently. + */ + freight_charge?: number | null; + /** + * This is to designate special instructions for the carrier like "Do not drop!". + */ + handling_instructions?: string | null; + /** + * Dangerous goods indicator. + * Possible values are "PRIMARY_CONTAINED", "PRIMARY_PACKED", "PRIMARY", "SECONDARY_CONTAINED", "SECONDARY_PACKED", "SECONDARY", "ORMD", "LIMITED_QUANTITY", "LITHIUM". + * Applies to USPS, FedEx and DHL eCommerce. + */ + hazmat?: + | 'PRIMARY_CONTAINED' + | 'PRIMARY_PACKED' + | 'PRIMARY' + | 'SECONDARY_CONTAINED' + | 'SECONDARY_PACKED' + | 'SECONDARY' + | 'ORMD' + | 'LIMITED_QUANTITY' + | 'LITHIUM' + | null; + /** + * Package will wait at carrier facility for pickup. + */ + hold_for_pickup?: boolean | null; + /** + * Incoterm negotiated for shipment. + * Supported values are "EXW", "FCA", "CPT", "CIP", "DAT", "DAP", "DDP", "FAS", "FOB", "CFR", and "CIF". + * Setting this value to anything other than "DDP" will pass the cost and responsibility of duties on to the recipient of the package(s), as specified by Incoterms rules + */ + incoterm?: + | 'EXW' + | 'FCA' + | 'CPT' + | 'CIP' + | 'DAT' + | 'DAP' + | 'DDP' + | 'FAS' + | 'FOB' + | 'CFR' + | 'CIF' + | null; + /** + * This will print an invoice number on the postage label. + */ + invoice_number?: string | null; + /** + * Set the date that will appear on the postage label. + * Accepts ISO 8601 formatted string including time zone offset. + * EasyPost stores all dates as UTC time. + */ + label_date?: string | null; + /** + * Supported label formats include "PNG", "PDF", "ZPL", and "EPL2". + * "PNG" is the only format that allows for conversion. + * + * @see https://www.easypost.com/docs/api#convert-the-label-format-of-a-shipment + */ + label_format?: LabelFormat | null; + /** + * Whether or not the parcel can be processed by the carriers equipment. + */ + machinable?: boolean | null; + /** + * Setting payment type to bill the correct account for purchasing postage. + */ + payment?: { + /** + * Supported values are "SENDER", "THIRD_PARTY", "RECEIVER", "COLLECT". Defaults to SENDER. + */ + type?: 'SENDER' | 'THIRD_PARTY' | 'RECEIVER' | 'COLLECT' | null; + /** + * Setting account number. + * Required for RECEIVER and THIRD_PARTY. + */ + account?: string | null; + /** + * Setting country code that the account is based in. + * Required for THIRD_PARTY. + */ + country?: string | null; + /** + * Setting postal code that the account is based in. + * Required for RECEIVER and THIRD_PARTY. + */ + postal_code?: string | null; + }; + /** + * The earliest a package should be picked up. Supported carriers vary. + */ + pickup_min_datetime?: string | null; + /** + * The latest a package should be picked up. Supported carriers vary. + */ + pickup_man_datetime?: string | null; + /** + * You can optionally print custom messages on labels. + * The locations of these fields show up on different spots on the carrier's labels. + */ + print_custom_1?: string | null; + /** + * An additional message on the label. Same restrictions as print_custom_1 + */ + print_custom_2?: string | null; + /** + * An additional message on the label. Same restrictions as print_custom_1 + */ + print_custom_3?: string | null; + /** + * Create a barcode for this custom reference if supported by carrier. + */ + print_custom_1_barcode?: boolean | null; + /** + * Create a barcode for this custom reference if supported by carrier. + */ + print_custom_2_barcode?: boolean | null; + /** + * Create a barcode for this custom reference if supported by carrier. + */ + print_custom_3_barcode?: boolean | null; + /** + * Specify the type of print_custom_1. + */ + print_custom_1_code?: TPrintCustomCode | null; + /** + * Specify the type of print_custom_2. + */ + print_custom_2_code?: TPrintCustomCode | null; + /** + * Specify the type of print_custom_3. + */ + print_custom_3_code?: TPrintCustomCode | null; + /** + * Set this value to true for delivery on Saturday. + * When setting the saturday_delivery option, you will only get rates for services that are eligible for saturday delivery. + * If no services are available for saturday delivery, then you will not be returned any rates. + * You may need to create 2 shipments, one with the saturday_delivery option set on one without to get all your eligible rates. + */ + saturday_delivery?: boolean | null; + /** + * This option allows you to request restrictive rates from USPS. + * Can set to 'USPS.MEDIAMAIL' or 'USPS.LIBRARYMAIL'. + */ + special_rates_eligibility?: 'USPS.MEDIAMAIL' | 'USPS.LIBRARYMAIL' | null; + /** + * You can use this to override the hub ID you have on your account. + */ + smartpost_hub?: string | null; + /** + * The manifest ID is used to group SmartPost packages onto a manifest for each trailer. + */ + smartpost_manifest?: string | null; + /** + * A reference ID for aggregating DHL eCommerce billing data. + */ + billing_ref?: string | null; + /** + * Certified Mail provides the sender with a mailing receipt and, upon request, electronic verification that an article was delivered or that a delivery attempt was made. + */ + certified_mail?: boolean | null; + /** + * Registered Mail is the most secure service that the USPS offers. + * It incorporates a system of receipts to monitor the movement of the mail from the point of acceptance to delivery + */ + registered_mail?: boolean | null; + /** + * The value of the package contents + */ + registered_mail_amount?: number | null; + /** + * An electronic return receipt may be purchased at the time of mailing and provides a shipper with evidence of delivery (to whom the mail was delivered and date of delivery), and information about the recipient's actual delivery address. + * Only applies to the USPS. + */ + return_receipt?: boolean | null; +}; diff --git a/types/services/shipment_service/Options/PrintCustomCode.d.ts b/types/services/shipment_service/Options/PrintCustomCode.d.ts new file mode 100644 index 000000000..4933056eb --- /dev/null +++ b/types/services/shipment_service/Options/PrintCustomCode.d.ts @@ -0,0 +1,52 @@ +/** + * - FedEx + * - (null) - If print_custom_1_code is not provided it defaults to Customer Reference + * - PO - Purchase Order Number + * - DP - Department Number + * - RMA - Return Merchandise Authorization + * - UPS + * - AJ - Accounts Receivable Customer Account + * - AT - Appropriation Number + * - BM - Bill of Lading Number + * - 9V - Collect on Delivery (COD) Number + * - ON - Dealer Order Number + * - DP - Department Number + * - 3Q - Food and Drug Administration (FDA) Product Code + * - IK - Invoice Number + * - MK - Manifest Key Number + * - MJ - Model Number + * - PM - Part Number + * - PC - Production Code + * - PO - Purchase Order Number + * - RQ - Purchase Request Number + * - RZ - Return Authorization Number + * - SA - Salesperson Number + * - SE - Serial Number + * - ST - Store Number + * - TN - Transaction Reference Number + * - EI - Employer's ID Number + * - TJ - Federal Taxpayer ID No. + */ +export declare type TPrintCustomCode = + | 'PO' + | 'DP' + | 'RMA' + | 'AJ' + | 'AT' + | 'BM' + | '9V' + | 'ON' + | '3Q' + | 'IK' + | 'MK' + | 'MJ' + | 'PM' + | 'PC' + | 'RQ' + | 'RZ' + | 'SA' + | 'SE' + | 'ST' + | 'TN' + | 'EI' + | 'TJ'; diff --git a/types/services/shipment_service/Options/index.d.ts b/types/services/shipment_service/Options/index.d.ts new file mode 100644 index 000000000..349426b0d --- /dev/null +++ b/types/services/shipment_service/Options/index.d.ts @@ -0,0 +1,3 @@ +export * from './LabelFormat'; +export * from './Options'; +export * from './PrintCustomCode'; diff --git a/types/services/shipment_service/PostageLabel.d.ts b/types/services/shipment_service/PostageLabel.d.ts new file mode 100644 index 000000000..0d0b2fdf6 --- /dev/null +++ b/types/services/shipment_service/PostageLabel.d.ts @@ -0,0 +1,18 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * PostageLabel Object + */ +export type IPostageLabel = IObjectWithId<'PostageLabel'> & + IDatedObject & { + date_advance: number; + integrated_form: string; + label_date: string; + label_resolution: number; + label_size: string; + label_type: string; + label_url: string; + label_file_type: string; + label_pdf_url: string; + label_epl2_url: string; + label_zpl_url: string; + }; diff --git a/types/services/shipment_service/Shipment.d.ts b/types/services/shipment_service/Shipment.d.ts new file mode 100644 index 000000000..80f7b4292 --- /dev/null +++ b/types/services/shipment_service/Shipment.d.ts @@ -0,0 +1,124 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; +import { TBatchStatus } from '../batch_service'; +import { ICustomsInfo } from '../customs_info_service'; +import { IFee, IInsurance } from '../insurance_service'; +import { IParcel } from '../parcel_service'; +import { IRate } from '../rate_service'; +import { IScanForm } from '../scan_form_service'; +import { ITracker } from '../tracker_service'; +import { IForm } from './Form'; +import { IMessage } from './Message'; +import { IOptions } from './Options'; +import { IPostageLabel } from './PostageLabel'; +/** + * The workhorse of the EasyPost API, a Shipment is made up of a "to" and "from" Address, the Parcel being shipped, and any customs forms required for international deliveries. + * Once created a Shipment object is used to retrieve shipping Rates and purchase a label. + * + * A Shipment created with a valid to_address, from_address, and parcel will automatically populate its rates attribute. + * + * @see https://www.easypost.com/docs/api/node#shipment-object + */ +export type IShipment = IObjectWithId<'Shipment'> & + IDatedObject & { + /** + * An optional field that may be used in place of id in other API endpoints + */ + reference?: string | null; + /** + * The destination address + */ + to_address: IAddress; + /** + * The origin address + */ + from_address: IAddress; + /** + * The shipper's address, defaults to from_address + */ + return_address?: IAddress | null; + /** + * The buyer's address, defaults to to_address + */ + buyer_address?: IAddress | null; + /** + * The dimensions and weight of the package + */ + parcel: IParcel; + /** + * Information for the processing of customs + */ + customs_info?: ICustomsInfo | null; + /** + * Document created to manifest and scan multiple shipments + */ + scan_form: IScanForm; + /** + * All associated Form objects + */ + forms: IForm[]; + /** + * The associated Insurance object + */ + insurance: IInsurance; + /** + * All associated Rate objects + */ + rates: IRate[]; + /** + * The specific rate purchased for the shipment, or null if unpurchased or purchased through another mechanism + */ + selected_rate: IRate; + /** + * The associated PostageLabel object + */ + postage_label: IPostageLabel; + /** + * Any carrier errors encountered during rating, discussed in more depth below + */ + messages: IMessage[]; + /** + * All the options passed to the shipment, discussed in more depth below + */ + options?: IOptions | null; + /** + * Set true to create as a return, discussed in more depth below + */ + is_return?: boolean | null; + /** + * If purchased, the tracking code will appear here as well as within the Tracker object + */ + tracking_code: string; + /** + * The USPS zone of the shipment, if purchased with USPS + */ + usps_zone: string; + /** + * The current tracking status of the shipment + */ + status: string; + /** + * The associated Tracker object + */ + tracker: ITracker; + /** + * The associated Fee objects charged to the billing user account + */ + fees: IFee[]; + /** + * The current status of the shipment refund process. Possible values are "submitted", "refunded", "rejected". + */ + refund_status: 'submitted' | 'refunded' | 'rejected'; + /** + * The ID of the batch that contains this shipment, if any + */ + batch_id: string; + /** + * The current status of the associated BatchShipment + */ + batch_status: TBatchStatus; + /** + * The current message of the associated BatchShipment + */ + batch_message: string; + }; diff --git a/types/services/shipment_service/ShipmentCreateParameters.d.ts b/types/services/shipment_service/ShipmentCreateParameters.d.ts new file mode 100644 index 000000000..4b690eead --- /dev/null +++ b/types/services/shipment_service/ShipmentCreateParameters.d.ts @@ -0,0 +1,17 @@ +import { DeepPartial } from '../../utils/types'; +import { IAddressCreateParameters } from '../address_service'; +import { ICustomsInfo } from '../customs_info_service'; +import { IParcelCreateParameters } from '../parcel_service'; +import { IOptions } from './Options'; +export type IShipmentCreateParameters = { + reference?: string | null; + to_address: DeepPartial | string; + from_address: DeepPartial | string; + parcel: Partial | string; + /** + * optional array of ids that begin with "ca_" + */ + carrier_accounts?: string[] | null; + customs_info?: DeepPartial | null; + options?: DeepPartial | null; +}; diff --git a/types/services/shipment_service/ShipmentListParameters.d.ts b/types/services/shipment_service/ShipmentListParameters.d.ts new file mode 100644 index 000000000..c875985b8 --- /dev/null +++ b/types/services/shipment_service/ShipmentListParameters.d.ts @@ -0,0 +1,16 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments + */ +export type IShipmentListParameters = IAllMethodParameters & { + /** + * Only include Shipments that have been purchased. + * Default is true + */ + purchased?: boolean; + /** + * Also include Shipments created by Child Users. + * Defaults to false + */ + include_children?: boolean; +}; diff --git a/types/services/shipment_service/index.d.ts b/types/services/shipment_service/index.d.ts new file mode 100644 index 000000000..0d14ecb05 --- /dev/null +++ b/types/services/shipment_service/index.d.ts @@ -0,0 +1,605 @@ +import EasyPost from '../..'; +import { IRate, ISmartRate } from '../rate_service'; +import { IOptions, LabelFormat } from './Options'; +import { IShipmentCreateParameters } from './ShipmentCreateParameters'; +import { IShipmentListParameters } from './ShipmentListParameters'; +export * from './Form'; +export * from './Message'; +export * from './PostageLabel'; +export * from './Shipment'; +export * from './ShipmentCreateParameters'; +export * from './ShipmentListParameters'; +export * from './Options'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#create-a-shipment EasyPost API Documentation} for more information. + * @param params - The parameters to create a shipment with. + * @returns - The created shipment. + */ + create(params: IShipmentCreateParameters): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */ + buy( + id: string, + rate: IRate | string, + insuranceAmount?: number | null, + endShipperId?: string | null, + ): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Convert the label format of a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#convert-the-label-format-of-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to convert the label format of. + * @param format - The format to convert the label to. + * @returns - The shipment with the converted label format. + */ + convertLabelFormat( + id: string, + format: LabelFormat, + ): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Regenerate {@link Rate rates} for a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#regenerate-rates-for-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to regenerate rates for. + * @returns - The shipment with regenerated rates. + */ + regenerateRates(id: string): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Get SmartRates for a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-time-in-transit-statistics-across-all-rates-for-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to get SmartRates for. + * @returns - The SmartRates for the shipment. + */ + getSmartRates(id: string): Promise>; + /** + * Insure a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#insure-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to insure. + * @param amount - The amount to insure the shipment for. + * @returns - The insured shipment. + */ + insure( + id: string, + amount: number | string, + ): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Generate a form for a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#create-form EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to generate a form for. + * @param formType - The type of form to generate. + * @param [formOptions] - Options for the form. + * @returns - The shipment with the generated form attached. + */ + generateForm( + id: string, + formType: string, + formOptions?: IOptions, + ): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Refund a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#refund-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to refund. + * @returns - The refunded shipment. + */ + refund(id: string): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Get the lowest SmartRate of a shipment. + * @param id - The ID of the shipment to get the lowest SmartRate of. + * @param deliveryDays - The number of days the shipment will take to deliver. + * @param deliveryAccuracy - The accuracy of the delivery days. + * @returns - The lowest SmartRate of the shipment. + */ + lowestSmartRate( + id: string, + deliveryDays: number, + deliveryAccuracy: keyof ISmartRate['time_in_transit'], + ): Promise; + /** + * Retrieve all {@link Shipment shipments} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the shipments by. + * @returns - An object containing a list of {@link Shipment shipments} and pagination information. + */ + all(params?: IShipmentListParameters): Promise<{ + shipments: (import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + })[]; + _params: any; + has_more: boolean; + }>; + /** + * Retrieve the next page of Shipment collection. + * @param shipments An object containing a list of {@link Shipment shipments} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + shipments: { + shipments: any[]; + }, + pageSize?: null, + ): Promise<{ + shipments: (import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + })[]; + _params: any; + has_more: boolean; + }>; + /** + * Retrieve a {@link Shipment shipment} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to retrieve. + * @returns - The shipment with the given ID. + */ + retrieve(id: string): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Retrieves the estimated delivery date of each Rate via SmartRate. + * @param id + * @param plannedShipDate + * @returns - An array of the estimated delivery date and rates. + */ + retrieveEstimatedDeliveryDate( + id: string, + plannedShipDate: string, + ): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/tracker_service/CarrierDetail.d.ts b/types/services/tracker_service/CarrierDetail.d.ts new file mode 100644 index 000000000..0cbb6a136 --- /dev/null +++ b/types/services/tracker_service/CarrierDetail.d.ts @@ -0,0 +1,51 @@ +import { IBaseObject } from '../../utils/types'; +import { ITrackingLocation } from './TrackingLocation'; +/** + * @see https://www.easypost.com/docs/api/node#carrier-detail-object + */ +export type ICarrierDetail = IBaseObject<'CarrierDetail'> & { + /** + * The service level the associated shipment was shipped with (if available) + */ + service: string; + /** + * The type of container the associated shipment was shipped in (if available) + */ + container_type: string; + /** + * The estimated delivery date as provided by the carrier, in the local time zone (if available) + */ + est_delivery_date_local: string; + /** + * The estimated delivery time as provided by the carrier, in the local time zone (if available) + */ + est_delivery_time_local: string; + /** + * The location from which the package originated, stringified for presentation (if available) + */ + origin_location: string; + /** + * The location from which the package originated, broken down by city/state/country/zip (if available) + */ + origin_tracking_location: ITrackingLocation; + /** + * The location to which the package is being sent, stringified for presentation (if available) + */ + destination_location: string; + /** + * The location to which the package is being sent, broken down by city/state/country/zip (if available) + */ + destination_tracking_location: ITrackingLocation; + /** + * The date and time the carrier guarantees the package to be delivered by (if available) + */ + guaranteed_delivery_date: string; + /** + * The alternate identifier for this package as provided by the carrier (if available) + */ + alternate_identifier: string; + /** + * The date and time of the first attempt by the carrier to deliver the package (if available) + */ + initial_delivery_attempt: string; +}; diff --git a/types/services/tracker_service/Tracker.d.ts b/types/services/tracker_service/Tracker.d.ts new file mode 100644 index 000000000..b601dc6c2 --- /dev/null +++ b/types/services/tracker_service/Tracker.d.ts @@ -0,0 +1,86 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IFee } from '../insurance_service'; +import { ICarrierDetail } from './CarrierDetail'; +import { ITrackerStatus } from './TrackerStatus'; +import { ITrackerStatusDetail } from './TrackerStatusDetail'; +import { ITrackingDetail } from './TrackingDetail'; +/** + * A Tracker object contains all the tracking information for a package. + * A Tracker is created automatically whenever you buy a Shipment through EasyPost. + * If you don't use EasyPost to purchase your shipping labels, you can still track packages through our API by creating a Tracker object directly. + * Each Tracker is continually updated in the background as the package moves through its life cycle, regardless of whether or not the label was purchased through EasyPost. + * + * After creation, a Tracker object will be updated periodically based on when the carrier provides EasyPost with new tracking information. + * This information can be consumed by using our webhooks infrastructure. + * Every time a Tracker is updated a webhook Event will be sent. + * + * The Tracker object contains both the current information about the package and previous updates. + * All the previous updates are stored in the tracking_details array. + * Each TrackingDetail object contains the status, the message from the carrier, and a TrackingLocation. + * + * The TrackingLocation contains city, state, country, and zip information about the location where the package was scanned. + * The information each carrier provides is different, so some carriers may not make use of all these fields. + * + * Some Tracker objects may also contain a CarrierDetail, which stores some additional information about the Tracker that the carrier has made available to EasyPost. + * The CarrierDetail object contains the service and container_type of the package. + * Additionally, it also stores the `est_delivery_date_local` and `est_delivery_time_local`, which provide information about the local delivery time. + * + * It's worth noting that tracking_codes are not globally unique. + * Each carrier promises uniqueness for a given `tracking_code` for a certain period of time, but the length of time varies greatly based on the specific carrier and service level. + * The carriers do eventually recycle `tracking_codes`, and for this reason enforcing uniqueness on the `tracking_code` field is not recommended. + * EasyPost does, however, prevent the creation of duplicate Trackers based on tracking_code and carrier; duplicate requests by the same User will simply return the original Tracker. + * + * @see https://www.easypost.com/docs/api/node#tracker-object + */ +export type ITracker = IObjectWithId<'Tracker'> & + IDatedObject & { + /** + * The tracking code provided by the carrier + */ + tracking_code: string; + /** + * The current status of the package, possible values are "unknown", "pre_transit", "in_transit", "out_for_delivery", "delivered", "available_for_pickup", "return_to_sender", "failure", "cancelled" or "error" + */ + status: ITrackerStatus; + /** + * Additional details about the current status, possible values are "unknown", "status_update", "departed_facility", "arrived_at_facility", "out_for_delivery", "arrived_at_destination" + */ + status_detail: ITrackerStatusDetail; + /** + * The name of the person who signed for the package (if available) + */ + signed_by: string; + /** + * The weight of the package as measured by the carrier in ounces (if available) + * float (oz) + */ + weight: number; + /** + * The estimated delivery date provided by the carrier (if available) + */ + est_delivery_date: string; + /** + * The id of the EasyPost Shipment object associated with the Tracker (if any) + */ + shipment_id: string; + /** + * The name of the carrier handling the shipment + */ + carrier: string; + /** + * Array of the associated TrackingDetail objects + */ + tracking_details: ITrackingDetail[]; + /** + * The associated CarrierDetail object (if available) + */ + carrier_detail: ICarrierDetail; + /** + * URL to a publicly-accessible html page that shows tracking details for this tracker + */ + public_url: string; + /** + * Array of the associated Fee objects + */ + fees: IFee[]; + }; diff --git a/types/services/tracker_service/TrackerCreateParameters.d.ts b/types/services/tracker_service/TrackerCreateParameters.d.ts new file mode 100644 index 000000000..242a3fcec --- /dev/null +++ b/types/services/tracker_service/TrackerCreateParameters.d.ts @@ -0,0 +1,11 @@ +export type ITrackerCreateParameters = { + /** + * The tracking code associated with the package you'd like to track + */ + tracking_code: string; + /** + * The carrier associated with the tracking_code you provided. + * The carrier will get auto-detected if none is provided + */ + carrier?: string; +}; diff --git a/types/services/tracker_service/TrackerListParameters.d.ts b/types/services/tracker_service/TrackerListParameters.d.ts new file mode 100644 index 000000000..0a831d83f --- /dev/null +++ b/types/services/tracker_service/TrackerListParameters.d.ts @@ -0,0 +1,12 @@ +import { IAllMethodParameters } from '../../utils/types'; +export type ITrackerListParameters = IAllMethodParameters & { + /** + * Only returns Trackers with the given tracking_code. + * Useful for retrieving an individual Tracker by tracking_code rather than by ID + */ + tracking_code?: string; + /** + * Only returns Trackers with the given carrier value + */ + carrier?: string; +}; diff --git a/types/services/tracker_service/TrackerStatus.d.ts b/types/services/tracker_service/TrackerStatus.d.ts new file mode 100644 index 000000000..11b490ca1 --- /dev/null +++ b/types/services/tracker_service/TrackerStatus.d.ts @@ -0,0 +1,11 @@ +export type ITrackerStatus = + | 'unknown' + | 'pre_transit' + | 'in_transit' + | 'out_for_delivery' + | 'delivered' + | 'available_for_pickup' + | 'return_to_sender' + | 'failure' + | 'cancelled' + | 'error'; diff --git a/types/services/tracker_service/TrackerStatusDetail.d.ts b/types/services/tracker_service/TrackerStatusDetail.d.ts new file mode 100644 index 000000000..d36c4690c --- /dev/null +++ b/types/services/tracker_service/TrackerStatusDetail.d.ts @@ -0,0 +1,29 @@ +export type ITrackerStatusDetail = + | 'address_correction' + | 'arrived_at_destination' + | 'arrived_at_facility' + | 'arrived_at_pickup_location' + | 'awaiting_information' + | 'cancelled' + | 'damaged' + | 'delayed' + | 'delivery_exception' + | 'departed_facility' + | 'departed_origin_facility' + | 'expired' + | 'failure' + | 'held' + | 'in_transit' + | 'label_created' + | 'lost' + | 'missorted' + | 'out_for_delivery' + | 'received_at_destination_facility' + | 'received_at_origin_facility' + | 'refused' + | 'return' + | 'status_update' + | 'transferred_to_destination_carrier' + | 'transit_exception' + | 'unknown' + | 'weather_delay'; diff --git a/types/services/tracker_service/TrackingDetail.d.ts b/types/services/tracker_service/TrackingDetail.d.ts new file mode 100644 index 000000000..c214f1d78 --- /dev/null +++ b/types/services/tracker_service/TrackingDetail.d.ts @@ -0,0 +1,28 @@ +import { IBaseObject } from '../../utils/types'; +import { ITrackerStatus } from './TrackerStatus'; +import { ITrackingLocation } from './TrackingLocation'; +/** + * @see https://www.easypost.com/docs/api/node#tracking-detail-object + */ +export type ITrackingDetail = IBaseObject<'TrackingDetail'> & { + /** + * Description of the scan event + */ + message: string; + /** + * Status of the package at the time of the scan event, possible values are "unknown", "pre_transit", "in_transit", "out_for_delivery", "delivered", "available_for_pickup", "return_to_sender", "failure", "cancelled" or "error" + */ + status: ITrackerStatus; + /** + * The timestamp when the tracking scan occurred + */ + datetime: string; + /** + * The original source of the information for this scan event, usually the carrier + */ + source: string; + /** + * The location associated with the scan event + */ + tracking_location: ITrackingLocation; +}; diff --git a/types/services/tracker_service/TrackingLocation.d.ts b/types/services/tracker_service/TrackingLocation.d.ts new file mode 100644 index 000000000..122522685 --- /dev/null +++ b/types/services/tracker_service/TrackingLocation.d.ts @@ -0,0 +1,22 @@ +import { IBaseObject } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#tracking-location-object + */ +export type ITrackingLocation = IBaseObject<'TrackingLocation'> & { + /** + * The city where the scan event occurred (if available) + */ + city: string; + /** + * The state where the scan event occurred (if available) + */ + state: string; + /** + * The country where the scan event occurred (if available) + */ + country: string; + /** + * The postal code where the scan event occurred (if available) + */ + zip: string; +}; diff --git a/types/services/tracker_service/index.d.ts b/types/services/tracker_service/index.d.ts new file mode 100644 index 000000000..10013907e --- /dev/null +++ b/types/services/tracker_service/index.d.ts @@ -0,0 +1,102 @@ +import EasyPost from '../..'; +import { ITracker } from './Tracker'; +import { ITrackerCreateParameters } from './TrackerCreateParameters'; +import { ITrackerListParameters } from './TrackerListParameters'; +export * from './CarrierDetail'; +export * from './Tracker'; +export * from './TrackerCreateParameters'; +export * from './TrackerListParameters'; +export * from './TrackerStatus'; +export * from './TrackerStatusDetail'; +export * from './TrackingDetail'; +export * from './TrackingLocation'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Tracker tracker}. + * See {@link https://www.easypost.com/docs/api/node#create-a-tracker EasyPost API Documentation} for more information. + * @param params - The parameters to create a tracker with. + * @returns - The created tracker. + */ + create( + params: ITrackerCreateParameters, + ): Promise>; + /** + * Create multiple {@link Tracker trackers} in a single request. + * See {@link https://www.easypost.com/docs/api/node#trackers EasyPost API Documentation} for more information. + * @param [params] - The parameters to create trackers with. + */ + createList(params?: ITrackerCreateParameters[]): Promise; + /** + * Retrieve all {@link Tracker trackers} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-trackers EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the trackers by. + * @returns - An object containing the list of {@link Tracker trackers} and pagination information. + */ + all(params?: ITrackerListParameters): Promise< + { + trackers: ITracker[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of Tracker collection. + * @param trackers An object containing a list of {@link Tracker trackers} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + trackers: { + trackers: any[]; + }, + pageSize?: number | null, + ): Promise< + { + trackers: ITracker[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link Tracker tracker} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-tracker EasyPost API Documentation} for more information. + * @param id - The ID of the tracker to retrieve. + * @returns - The retrieved tracker. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/user_service/Brand.d.ts b/types/services/user_service/Brand.d.ts new file mode 100644 index 000000000..fd0fc15a4 --- /dev/null +++ b/types/services/user_service/Brand.d.ts @@ -0,0 +1,40 @@ +import { IObjectWithId } from '../../utils/types'; +/** + * The Brand class represents the public-accessible information about a user's brand, including logos, colors and themes. + * + * @see https://www.easypost.com/docs/api/node#brand + */ +export type IBrand = IObjectWithId<'Brand'> & { + /** + * The background color of the brand, as a hex code. + */ + background_color: string; + /** + * The primary color of the brand, as a hex code. + */ + color: string; + /** + * The logo of the brand, as a base64-encoded PNG, GIF, JPEG or SVG. + */ + logo: string; + /** + * The URL of the brand's logo. + */ + logo_href: string; + /** + * The banner ad of the brand, as a base64-encoded PNG, GIF, JPEG or SVG. + */ + ad: string; + /** + * The URL of the brand's banner ad. + */ + ad_href: string; + /** + * The ID of the brand's associated User. + */ + user_id: string; + /** + * The name of the current theme. + */ + theme: 'theme1' | 'theme2'; +}; diff --git a/types/services/user_service/User.d.ts b/types/services/user_service/User.d.ts new file mode 100644 index 000000000..af274970f --- /dev/null +++ b/types/services/user_service/User.d.ts @@ -0,0 +1,64 @@ +import { IObjectWithId } from '../../utils/types'; +/** + * The User object can be used to manage your own account and to create child accounts. + * Only a Production mode API key can be used to make requests against the Users API. + * + * Balance and recharge values on User objects are expressed in higher precision USD. + * + * @see https://www.easypost.com/docs/api/node#user-object + */ +export type IUser = IObjectWithId<'User'> & { + /** + * The ID of the parent user object. + * Top-level users are defined as users with no parent + */ + parent_id: string; + /** + * First and last name required + */ + name: string; + /** + * Required + */ + email: string; + /** + * Optional + */ + phone_number?: string | null; + /** + * Formatted as string "XX.XXXXX" + */ + balance: string; + /** + * Cost per shipment purchase, formatted as string "XX.XXXXX" + */ + price_per_shipment: string; + /** + * USD formatted dollars and cents, delimited by a decimal point + */ + recharge_amount: string; + /** + * USD formatted dollars and cents, delimited by a decimal point + */ + secondary_recharge_amount: string; + /** + * Number of cents USD that when your balance drops below, we automatically recharge your account with your primary payment method. + */ + recharge_threshold: string; + /** + * The fee rate for convenience fees + */ + cc_fee_rate: string; + /** + * The fee rate for insurance purchases + */ + insurance_fee_rate: string; + /** + * The minimum cost for insurance purchases + */ + insurance_fee_minimum: string; + /** + * All associated children + */ + children: IUser[]; +}; diff --git a/types/services/user_service/UserCreateParameters.d.ts b/types/services/user_service/UserCreateParameters.d.ts new file mode 100644 index 000000000..78113251c --- /dev/null +++ b/types/services/user_service/UserCreateParameters.d.ts @@ -0,0 +1,3 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IUser } from './User'; +export type IUserCreateParameters = Omit; diff --git a/types/services/user_service/index.d.ts b/types/services/user_service/index.d.ts new file mode 100644 index 000000000..bd4afc937 --- /dev/null +++ b/types/services/user_service/index.d.ts @@ -0,0 +1,126 @@ +import EasyPost from '../..'; +import { IBrand } from './Brand'; +import { IUser } from './User'; +import { IUserCreateParameters } from './UserCreateParameters'; +export * from './Brand'; +export * from './User'; +export * from './UserCreateParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link User child user}. + * See {@link https://www.easypost.com/docs/api/node#create-a-child-user EasyPost API Documentation} for more information. + * @param params - The parameters to create a child user with. + * @returns - The created child user. + */ + create(params: IUserCreateParameters): Promise>; + /** + * Update a {@link User user}. + * See {@link https://www.easypost.com/docs/api/node#update-a-user EasyPost API Documentation} for more information. + * @param id - The ID of the user to update (either the current authenticated user or a child user). + * @param params - The parameters to update the user with. + * @returns - The updated user. + */ + update( + id: string, + params: Partial, + ): Promise>; + /** + * Retrieve a {@link User child user}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-user EasyPost API Documentation} for more information. + * @param id - The ID of the child user to retrieve. + * @returns - The retrieved child user. + */ + retrieve(id: string): Promise>; + /** + * Retrieve the {@link User current authenticated user}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-user EasyPost API Documentation} for more information. + * @returns - The retrieved user. + */ + retrieveMe(): Promise>; + /** + * Delete a {@link User child user}. + * See {@link https://www.easypost.com/docs/api/node#delete-a-child-user EasyPost API Documentation} for more information. + * @param id - The ID of the child user to delete. + * @returns - A promise that resolves when the child user is deleted successfully. + */ + delete(id: string): Promise; + /** + * Update the brand of a {@link User user}. + * See {@link https://www.easypost.com/docs/api/node#update-a-brand EasyPost API Documentation} for more information. + * @param id - The ID of the user to update the brand of. + * @param params - The parameters to update the brand with. + * @returns - The updated brand. + */ + updateBrand( + id: string, + params: Partial, + ): Promise>; + /** + * Retrieve a paginated list of children user {@link User user}. + * See {@link https://www.easypost.com/docs/api/node#child-users EasyPost API Documentation} for more information. + * @param params - Parameters to filter the list of children users. + * @returns - An object containing a list of {@link Children User} and pagination information. + */ + allChildren(params: any): Promise< + import('../base_service').EasyPostObject<{ + children: IUser[]; + }> + >; + /** + * Retrieve the next page of children collection. + * @param children An object containing a list of {@link Children children} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + children: { + children: any[]; + }, + pageSize?: number | null, + ): Promise< + { + children: IUser[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise> + /** + * Delete a {@link User child user}. + * See {@link https://www.easypost.com/docs/api/node#delete-a-child-user EasyPost API Documentation} for more information. + * @param id - The ID of the child user to delete. + * @returns - A promise that resolves when the child user is deleted successfully. + */; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/services/webhook_service/Webhook.d.ts b/types/services/webhook_service/Webhook.d.ts new file mode 100644 index 000000000..a7137ee4e --- /dev/null +++ b/types/services/webhook_service/Webhook.d.ts @@ -0,0 +1,28 @@ +import { IObjectWithId } from '../../utils/types'; +/** + * Each Webhook contains the url which EasyPost will notify whenever an object in our system updates. + * Several types of objects are processed asynchronously in the EasyPost system, so whenever an object updates, an Event is sent via HTTP POST to each configured webhook URL. + * The Webhook object provides CRUD operations for all Webhooks. + * + * Currently, our recommended best practice for securing Webhooks involves using basic authentication and HTTPS on your endpoint. + * This will help prevent any altering of any information communicated to you by EasyPost, prevent any third parties from seeing your webhooks in transit, and will prevent any third parties from masquerading as EasyPost and sending fraudulent data. + * EasyPost performs certificate validation and requires any TLS-enabled (HTTPS) webhook recipients to have a certificate signed by a public trusted certification authority. + * We do not support sending webhooks to over SSLv2, SSLv3, or any connection using so-called export-grade ciphers. + * For documentation on how to set up your server with TLS, we recommend Mozilla's guide to Server-Side TLS and Qualys's SSL/TLS deployment best practices guide. + * + * In general, a Webhook's endpoint should return a status code of 2XX. + * A 200 is preferred, but any 2XX status will indicate to our system that the Webhook request was successful. + * Endpoints that return a large volume and rate of failures over a period of time will get automatically disabled by the system; a disabled Webhook can be re-enabled using the Webhook update endpoint. + * + * @see https://www.easypost.com/docs/api/node#webhook-object + */ +export type IWebhook = IObjectWithId<'Webhook'> & { + /** + * http://example.com + */ + url: string; + /** + * the timestamp at which the webhook was most recently disabled (if any) + */ + disabled_at: string; +}; diff --git a/types/services/webhook_service/WebhookCreateParameters.d.ts b/types/services/webhook_service/WebhookCreateParameters.d.ts new file mode 100644 index 000000000..e5eb2aee2 --- /dev/null +++ b/types/services/webhook_service/WebhookCreateParameters.d.ts @@ -0,0 +1,3 @@ +export type IWebhookCreateParameters = { + url: string; +}; diff --git a/types/services/webhook_service/WebhookListParameters.d.ts b/types/services/webhook_service/WebhookListParameters.d.ts new file mode 100644 index 000000000..4660bde6a --- /dev/null +++ b/types/services/webhook_service/WebhookListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#list-a-webhooks + */ +export type IWebhookListParameters = IAllMethodParameters; diff --git a/types/services/webhook_service/index.d.ts b/types/services/webhook_service/index.d.ts new file mode 100644 index 000000000..a1890b6df --- /dev/null +++ b/types/services/webhook_service/index.d.ts @@ -0,0 +1,90 @@ +import EasyPost from '../..'; +import { IWebhook } from './Webhook'; +import { IWebhookCreateParameters } from './WebhookCreateParameters'; +import { IWebhookListParameters } from './WebhookListParameters'; +export * from './Webhook'; +export * from './WebhookCreateParameters'; +export * from './WebhookListParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Webhook webhook}. + * See {@link https://www.easypost.com/docs/api/node#create-a-webhook EasyPost API Documentation} for more information. + * @param params - The parameters to create a webhook with. + * @returns - The created webhook. + */ + create( + params: IWebhookCreateParameters, + ): Promise>; + /** + * Update a {@link Webhook webhook}. + * A disabled webhook will be re-enabled if it is updated. + * See {@link https://www.easypost.com/docs/api/node#update-a-webhook EasyPost API Documentation} for more information. + * @param id - The ID of the webhook to update. + * @param params - The parameters to update the webhook with. + * @returns - The updated webhook. + */ + update( + id: string, + params: Partial, + ): Promise>; + /** + * Delete a {@link Webhook webhook}. + * See {@link https://www.easypost.com/docs/api/node#delete-a-webhook EasyPost API Documentation} for more information. + * @param id - The ID of the webhook to delete. + * @returns - A promise that resolves if the webhook was successfully deleted. + */ + delete(id: string): Promise; + /** + * Retrieve all {@link Webhook webhooks} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#list-a-webhooks EasyPost API Documentation} for more information. + * @param [params] + * @returns + */ + all(params?: IWebhookListParameters): Promise< + { + webhooks: IWebhook[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link Webhook webhook} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-webhook EasyPost API Documentation} for more information. + * @param id - The ID of the webhook to retrieve. + * @returns - The retrieved webhook. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/constants.d.ts b/types/src/constants.d.ts new file mode 100644 index 000000000..2e9caa299 --- /dev/null +++ b/types/src/constants.d.ts @@ -0,0 +1,20 @@ +import Utils from './utils/util'; +/** + * A class containing constants used throughout the EasyPost Node.js client library. + */ +export default class Constants { + static get CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS(): string[]; + static EXTERNAL_API_CALL_FAILED: string; + static INVALID_API_KEY_TYPE: string; + static INVALID_PARAMETER: string; + static INVALID_PAYMENT: string; + static INVALID_WEBHOOK_SIGNATURE: string; + static MISSING_REQUIRED_PARAMETER: string; + static NO_OBJECT_FOUND: string; + static NO_PAYMENT_METHODS: string; + static API_DID_NOT_RETURN_ERROR_DETAILS: string; + static WEBHOOK_DOES_NOT_MATCH: string; + static END_OF_PAGINATION: string; + static ERROR_DESERIALIZATION: string; + static Utils: Utils; +} diff --git a/types/src/easypost.d.ts b/types/src/easypost.d.ts new file mode 100644 index 000000000..e9b390ae5 --- /dev/null +++ b/types/src/easypost.d.ts @@ -0,0 +1,260 @@ +import { SuperAgentStatic, Request, Response } from 'superagent'; +import AddressService from './services/address_service'; +import ApiKeyService from './services/api_key_service'; +import BatchService from './services/batch_service'; +import BetaRateService from './services/beta_rate_service'; +import BetaReferralCustomerService from './services/beta_referral_customer_service'; +import BillingService from './services/billing_service'; +import CarrierAccountService from './services/carrier_account_service'; +import CarrierMetadataService from './services/carrier_metadata_service'; +import CarrierTypeService from './services/carrier_type_service'; +import CustomsInfoService from './services/customs_info_service'; +import CustomsItemService from './services/customs_item_service'; +import EndShipperService from './services/end_shipper_service'; +import EventService from './services/event_service'; +import InsuranceService from './services/insurance_service'; +import OrderService from './services/order_service'; +import ParcelService from './services/parcel_service'; +import PickupService from './services/pickup_service'; +import RateService from './services/rate_service'; +import ReferralCustomerService from './services/referral_customer_service'; +import RefundService from './services/refund_service'; +import ReportService from './services/report_service'; +import ScanFormService from './services/scan_form_service'; +import ShipmentService from './services/shipment_service'; +import TrackerService from './services/tracker_service'; +import UserService from './services/user_service'; +import WebhookService from './services/webhook_service'; +import Utils from './utils/util'; +export * from './errors'; +export * from './services'; +export * from './utils/errors'; +export * from './constants'; +/** How many milliseconds in a second. */ +export declare const MS_SECOND = 1000; +/** The default timeout for all EasyPost API requests. */ +export declare const DEFAULT_TIMEOUT: number; +/** The default base URL for all production EasyPost API requests. */ +export declare const DEFAULT_BASE_URL = 'https://api.easypost.com/v2/'; +/** The default headers used for all EasyPost API requests. */ +export declare const DEFAULT_HEADERS: { + Accept: string; + 'Content-Type': string; + 'User-Agent': string; +}; +/** A map of HTTP methods to their corresponding string values (for use with superagent). */ +export declare const METHODS: { + readonly GET: 'get'; + readonly POST: 'post'; + readonly PUT: 'put'; + readonly PATCH: 'patch'; + readonly DELETE: 'del'; +}; +export type EasyPostClientOptions = { + useProxy?: boolean; + timeout?: number; + baseUrl?: string; + superagentMiddleware?: (agent: SuperAgentStatic) => SuperAgentStatic; + requestMiddleware?: (request: Request) => Request; + agent?: SuperAgentStatic; +}; +export type RequestHookData = { + method: (typeof METHODS)[keyof typeof METHODS]; + path: string; + requestBody: any; + headers: Record; + requestTimestamp: number; + requestUUID: string; +}; +export type RequestHook = (data: RequestHookData) => void; +export type ResponseHookData = RequestHookData & { + requestHeaders: Record; + httpStatus: Response['status']; + responseBody: Response['body']; + headers: Response['headers']; + responseTimestamp: number; +}; +export type ResponseHook = (data: ResponseHookData) => void; +/** + * The client used to access services of the EasyPost API. + * This client is configured to use the latest production version of the EasyPost API. + * @param {string} key The API key to use for API requests made by this client. + * @param {EasyPostClientOptions} [options] Additional options to use for the underlying HTTP client (e.g. superagent, middleware, proxy configuration). + */ +export default class EasyPostClient { + useProxy: boolean; + key: string; + timeout: number; + baseUrl: string; + agent: SuperAgentStatic; + requestMiddleware: ((request: Request) => Request) | undefined; + requestHooks: RequestHook[]; + responseHooks: ResponseHook[]; + Utils: Utils; + Address: ReturnType; + ApiKey: ReturnType; + Batch: ReturnType; + BetaRate: ReturnType; + BetaReferralCustomer: ReturnType; + Billing: ReturnType; + CarrierAccount: ReturnType; + CarrierMetadata: ReturnType; + CarrierType: ReturnType; + CustomsInfo: ReturnType; + CustomsItem: ReturnType; + EndShipper: ReturnType; + Event: ReturnType; + Insurance: ReturnType; + Order: ReturnType; + Parcel: ReturnType; + Pickup: ReturnType; + Rate: ReturnType; + ReferralCustomer: ReturnType; + Refund: ReturnType; + Report: ReturnType; + ScanForm: ReturnType; + Shipment: ReturnType; + Tracker: ReturnType; + User: ReturnType; + Webhook: ReturnType; + constructor(key: string, options?: EasyPostClientOptions); + /** + * Add a request hook function. + * @param {(config: object) => void} hook + */ + addRequestHook(hook: RequestHook): void; + /** + * Remove a request hook function. + * @param {(config: object) => void} hook + */ + removeRequestHook(hook: RequestHook): void; + /** + * Clear all request hooks. + */ + clearRequestHooks(): void; + /** + * Add a response hook function. + * @param {(config: object) => void} hook + */ + addResponseHook(hook: ResponseHook): void; + /** + * Remove a response hook function. + * @param {(config: object) => void} hook + */ + removeResponseHook(hook: ResponseHook): void; + /** + * Clear all response hooks. + */ + clearResponseHooks(): void; + /** + * Create a copy of an {@link EasyPostClient} with overridden options. + * @param {EasyPostClient} client The `EasyPostClient` instance to clone. + * @param {Object} [options] The options to override. + * @returns {EasyPostClient} A new `EasyPostClient` instance. + */ + static copyClient( + client: EasyPostClient, + options?: EasyPostClientOptions & { + apiKey?: string; + }, + ): EasyPostClient; + /** + * Build request headers to be sent with each EasyPost API request, combined (or overridden) by any additional headers + * @param {Object} [additionalHeaders] Additional headers to combine or override with the default headers. + * @returns {Object} The headers to use for the request. + */ + static _buildHeaders(additionalHeaders?: {}): { + Accept: string; + 'Content-Type': string; + 'User-Agent': string; + }; + /** + * If the path passed in is a full URI, use it; otherwise, prepend the base url from the api. + * @param {string} path - The path to build. + * @returns {string} The full path to use for the HTTP request. + */ + _buildPath(path?: string): string; + /** + * Create a value to be passed to the responseHooks, based on the requestHooks + * value and the response. + * @param {Object} baseHooksValue - the value being passed the requestHooks + * @param {Object} response - the response from the superagent request + * @returns {Object} - the value to be passed to the responseHooks + */ + _createResponseHooksValue(baseHooksValue: RequestHookData, response: Response): ResponseHookData; + /** + * Make an HTTP request. + * @param [path] - The partial path to append to the base url for the request. + * @param [method] - The HTTP method to use for the request, defaults to GET. + * @param [params] - The parameters to send with the request. + * @param [headers] - Additional headers to send with the request. + * @returns The response from the HTTP request. + * @throws {ApiError} If the request fails. + */ + _request( + path?: string, + method?: (typeof METHODS)[keyof typeof METHODS], + params?: Record, + headers?: Record, + ): Promise; + /** + * Make a GET HTTP request. + * @param path - The partial path to append to the base url for the request. + * @param [params] - The parameters to send with the request. + * @param [headers] - Additional headers to send with the request. + * @returns The response from the HTTP request. + */ + _get( + path: string, + params?: Record, + headers?: Record, + ): Promise; + /** + * Make a POST HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + _post( + path: string, + params?: any, + headers?: Record, + ): Promise; + /** + * Make a PUT HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + _put( + path: string, + params?: any, + headers?: Record, + ): Promise; + /** + * Make a PATCH HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + _patch( + path: string, + params?: any, + headers?: Record, + ): Promise; + /** + * Make a DELETE HTTP request. + * @param {string} path - The partial path to append to the base url for the request. + * @param {any} [params] - The parameters to send with the request. + * @param {Record} [headers] - Additional headers to send with the request. + * @returns {*} The response from the HTTP request. + */ + _delete( + path: string, + params?: any, + headers?: Record, + ): Promise; +} diff --git a/types/src/errors/api/api_error.d.ts b/types/src/errors/api/api_error.d.ts new file mode 100644 index 000000000..1c0e08efb --- /dev/null +++ b/types/src/errors/api/api_error.d.ts @@ -0,0 +1,29 @@ +import EasyPostError from '../easypost_error'; +/** + * The ApiError class is used to represent errors that occurred while communicating with the EasyPost API. + * This class should not be instantiated directly. + * @internal + * @abstract + * @extends EasyPostError + * @property {string} [message] - The message to be displayed when the error is logged. + * @property {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @property {number} [statusCode] - The HTTP status code returned by the HTTP request to the EasyPost API. + * @property {EasyPostError[]} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class ApiError extends EasyPostError { + code: string | undefined; + errors: EasyPostError[] | undefined; + message: string | undefined; + statusCode: number | undefined; + constructor({ + message, + code, + statusCode, + errors, + }?: { + message?: string; + code?: string; + statusCode?: number; + errors?: EasyPostError[]; + }); +} diff --git a/types/src/errors/api/bad_request_error.d.ts b/types/src/errors/api/bad_request_error.d.ts new file mode 100644 index 000000000..a8a3391a5 --- /dev/null +++ b/types/src/errors/api/bad_request_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The BadRequestError class is used to represent a 400 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class BadRequestError extends ApiError {} diff --git a/types/src/errors/api/external_api_error.d.ts b/types/src/errors/api/external_api_error.d.ts new file mode 100644 index 000000000..c3bb01401 --- /dev/null +++ b/types/src/errors/api/external_api_error.d.ts @@ -0,0 +1,9 @@ +import ApiError from './api_error'; +/** + * The ExternalApiError class is used to represent errors that occurred while communicating with an external API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + */ +export default class ExternalApiError extends ApiError {} diff --git a/types/src/errors/api/forbidden_error.d.ts b/types/src/errors/api/forbidden_error.d.ts new file mode 100644 index 000000000..f8d9b064e --- /dev/null +++ b/types/src/errors/api/forbidden_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The ForbiddenError class is used to represent a 403 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class ForbiddenError extends ApiError {} diff --git a/types/src/errors/api/gateway_timeout_error.d.ts b/types/src/errors/api/gateway_timeout_error.d.ts new file mode 100644 index 000000000..1ceec87e7 --- /dev/null +++ b/types/src/errors/api/gateway_timeout_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The GatewayTimeoutError class is used to represent a 504 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class GatewayTimeoutError extends ApiError {} diff --git a/types/src/errors/api/http_error.d.ts b/types/src/errors/api/http_error.d.ts new file mode 100644 index 000000000..acaac4c4b --- /dev/null +++ b/types/src/errors/api/http_error.d.ts @@ -0,0 +1,10 @@ +import ApiError from './api_error'; +/** + * The HttpError class is used to represent a generic HTTP-related error that occurred while communicating with the EasyPost API. + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class HTTPError extends ApiError {} diff --git a/types/src/errors/api/index.d.ts b/types/src/errors/api/index.d.ts new file mode 100644 index 000000000..6ac9ac6b3 --- /dev/null +++ b/types/src/errors/api/index.d.ts @@ -0,0 +1,18 @@ +export * from './api_error'; +export * from './bad_request_error'; +export * from './external_api_error'; +export * from './forbidden_error'; +export * from './gateway_timeout_error'; +export * from './http_error'; +export * from './index'; +export * from './internal_server_error'; +export * from './invalid_request_error'; +export * from './method_not_allowed_error'; +export * from './not_found_error'; +export * from './payment_error'; +export * from './rate_limit_error'; +export * from './redirect_error'; +export * from './service_unavailable_error'; +export * from './timeout_error'; +export * from './unauthorized_error'; +export * from './unknown_api_error'; diff --git a/types/src/errors/api/internal_server_error.d.ts b/types/src/errors/api/internal_server_error.d.ts new file mode 100644 index 000000000..946d7e0fa --- /dev/null +++ b/types/src/errors/api/internal_server_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The InternalServerError class is used to represent a 500 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class InternalServerError extends ApiError {} diff --git a/types/src/errors/api/invalid_request_error.d.ts b/types/src/errors/api/invalid_request_error.d.ts new file mode 100644 index 000000000..0e87d346d --- /dev/null +++ b/types/src/errors/api/invalid_request_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The InvalidRequestError class is used to represent a 422 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class InvalidRequestError extends ApiError {} diff --git a/types/src/errors/api/method_not_allowed_error.d.ts b/types/src/errors/api/method_not_allowed_error.d.ts new file mode 100644 index 000000000..fd29b3cbc --- /dev/null +++ b/types/src/errors/api/method_not_allowed_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The MethodNotAllowedError class is used to represent a 405 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class MethodNotAllowedError extends ApiError {} diff --git a/types/src/errors/api/not_found_error.d.ts b/types/src/errors/api/not_found_error.d.ts new file mode 100644 index 000000000..5e2a4262b --- /dev/null +++ b/types/src/errors/api/not_found_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The NotFoundError class is used to represent a 404 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class NotFoundError extends ApiError {} diff --git a/types/src/errors/api/payment_error.d.ts b/types/src/errors/api/payment_error.d.ts new file mode 100644 index 000000000..081039ad8 --- /dev/null +++ b/types/src/errors/api/payment_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The PaymentError class is used to represent a 402 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class PaymentError extends ApiError {} diff --git a/types/src/errors/api/rate_limit_error.d.ts b/types/src/errors/api/rate_limit_error.d.ts new file mode 100644 index 000000000..3ae7f08f9 --- /dev/null +++ b/types/src/errors/api/rate_limit_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The RateLimitError class is used to represent a 429 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class RateLimitError extends ApiError {} diff --git a/types/src/errors/api/redirect_error.d.ts b/types/src/errors/api/redirect_error.d.ts new file mode 100644 index 000000000..004604f69 --- /dev/null +++ b/types/src/errors/api/redirect_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The RedirectError class is used to represent a 3xx error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class RedirectError extends ApiError {} diff --git a/types/src/errors/api/service_unavailable_error.d.ts b/types/src/errors/api/service_unavailable_error.d.ts new file mode 100644 index 000000000..e667d5952 --- /dev/null +++ b/types/src/errors/api/service_unavailable_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The ServiceUnavailableError class is used to represent a 503 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class ServiceUnavailableError extends ApiError {} diff --git a/types/src/errors/api/timeout_error.d.ts b/types/src/errors/api/timeout_error.d.ts new file mode 100644 index 000000000..5775f87ed --- /dev/null +++ b/types/src/errors/api/timeout_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The TimeoutError class is used to represent a 408 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class TimeoutError extends ApiError {} diff --git a/types/src/errors/api/unauthorized_error.d.ts b/types/src/errors/api/unauthorized_error.d.ts new file mode 100644 index 000000000..bad09b743 --- /dev/null +++ b/types/src/errors/api/unauthorized_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The UnauthorizedError class is used to represent a 401 error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class UnauthorizedError extends ApiError {} diff --git a/types/src/errors/api/unknown_api_error.d.ts b/types/src/errors/api/unknown_api_error.d.ts new file mode 100644 index 000000000..8ddc33bbd --- /dev/null +++ b/types/src/errors/api/unknown_api_error.d.ts @@ -0,0 +1,11 @@ +import ApiError from './api_error'; +/** + * The UnknownApiError class is used to represent a generic, unexpected error that occurred while communicating with the EasyPost API. + * @sealed + * @extends ApiError + * @param {string} [message] - The message to be displayed when the error is logged. + * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. + * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. + * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. + */ +export default class UnknownApiError extends ApiError {} diff --git a/types/src/errors/easypost_error.d.ts b/types/src/errors/easypost_error.d.ts new file mode 100644 index 000000000..db97aca67 --- /dev/null +++ b/types/src/errors/easypost_error.d.ts @@ -0,0 +1,12 @@ +/** + * The EasyPostError class is the base class for all errors that occur in the EasyPost Node.js client library. + * This class should not be instantiated directly. + * @internal + * @abstract + * @extends Error + * @param {string} [message] - The message to be displayed when the error is logged. + */ +export default class EasyPostError extends Error { + message: string | undefined; + constructor({ message }?: { message?: string }); +} diff --git a/types/src/errors/error_handler.d.ts b/types/src/errors/error_handler.d.ts new file mode 100644 index 000000000..b5aed46ce --- /dev/null +++ b/types/src/errors/error_handler.d.ts @@ -0,0 +1,33 @@ +import EasyPostError from './easypost_error'; +export type RawAPIError = { + statusCode: number; + body: { + error: { + code: string; + message: JSONParsableError; + errors: EasyPostError[]; + }; + }; +}; +type JSONParsableError = string | number | JSONObject | JSONArray; +type JSONObject = { + [key: string]: JSONParsableError; +}; +type JSONArray = JSONParsableError[]; +export default class ErrorHandler { + /** + * Recursively traverses a JSON object or array and extracts error messages + * as strings. Adds the extracted messages to the specified messagesList array. + * + * @param {JSONParsableError} errorMessage - The JSON object or array to traverse. + */ + static traverseJsonElement(errorMessage: JSONParsableError): string[]; + static isAPIError(error: any): error is RawAPIError; + /** + * Calculate and generate the appropriate {@link ApiError} based on a received HTTP response error. + * @param {*} error - The errored HTTP response. + * @returns {ApiError} The `ApiError`-based error corresponding to the HTTP status code. + */ + static handleApiError(error: RawAPIError): EasyPostError; +} +export {}; diff --git a/types/src/errors/general/end_of_pagination_error.d.ts b/types/src/errors/general/end_of_pagination_error.d.ts new file mode 100644 index 000000000..1ae894a77 --- /dev/null +++ b/types/src/errors/general/end_of_pagination_error.d.ts @@ -0,0 +1,10 @@ +import EasyPostError from '../easypost_error'; +/** + * The EndOfPaginationError class is used to represent an error that no more page can be retrieved + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +export default class EndOfPaginationError extends EasyPostError { + constructor(); +} diff --git a/types/src/errors/general/filtering_error.d.ts b/types/src/errors/general/filtering_error.d.ts new file mode 100644 index 000000000..3f96a1925 --- /dev/null +++ b/types/src/errors/general/filtering_error.d.ts @@ -0,0 +1,8 @@ +import EasyPostError from '../easypost_error'; +/** + * The FilteringError class is used to represent an error that occurred while filtering a list (e.g. a list of rates). + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +export default class FilteringError extends EasyPostError {} diff --git a/types/src/errors/general/index.d.ts b/types/src/errors/general/index.d.ts new file mode 100644 index 000000000..04c30fdb2 --- /dev/null +++ b/types/src/errors/general/index.d.ts @@ -0,0 +1,6 @@ +export * from './end_of_pagination_error'; +export * from './filtering_error'; +export * from './invalid_object_error'; +export * from './invalid_parameter_error'; +export * from './missing_parameter_error'; +export * from './signature_verification_error'; diff --git a/types/src/errors/general/invalid_object_error.d.ts b/types/src/errors/general/invalid_object_error.d.ts new file mode 100644 index 000000000..be11f59bd --- /dev/null +++ b/types/src/errors/general/invalid_object_error.d.ts @@ -0,0 +1,8 @@ +import EasyPostError from '../easypost_error'; +/** + * The InvalidObjectError class is used to represent an error due to an invalid object (e.g. missing an expected property). + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +export default class InvalidObjectError extends EasyPostError {} diff --git a/types/src/errors/general/invalid_parameter_error.d.ts b/types/src/errors/general/invalid_parameter_error.d.ts new file mode 100644 index 000000000..9931b6a18 --- /dev/null +++ b/types/src/errors/general/invalid_parameter_error.d.ts @@ -0,0 +1,8 @@ +import EasyPostError from '../easypost_error'; +/** + * The InvalidParameterError class is used to represent an error due to an invalid function parameter. + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +export default class InvalidParameterError extends EasyPostError {} diff --git a/types/src/errors/general/missing_parameter_error.d.ts b/types/src/errors/general/missing_parameter_error.d.ts new file mode 100644 index 000000000..858616524 --- /dev/null +++ b/types/src/errors/general/missing_parameter_error.d.ts @@ -0,0 +1,8 @@ +import EasyPostError from '../easypost_error'; +/** + * The MissingParameterError class is used to represent an error due to a missing expected function parameter. + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +export default class MissingParameterError extends EasyPostError {} diff --git a/types/src/errors/general/signature_verification_error.d.ts b/types/src/errors/general/signature_verification_error.d.ts new file mode 100644 index 000000000..0d73da0d7 --- /dev/null +++ b/types/src/errors/general/signature_verification_error.d.ts @@ -0,0 +1,8 @@ +import EasyPostError from '../easypost_error'; +/** + * The SignatureVerificationError class is used to represent an error due to a failed signature verification (e.g. a webhook HMAC signature). + * @sealed + * @extends EasyPostError + * @param {string} [message] - The message to be displayed when the error is logged. + */ +export default class SignatureVerificationError extends EasyPostError {} diff --git a/types/src/errors/index.d.ts b/types/src/errors/index.d.ts new file mode 100644 index 000000000..a8d312a93 --- /dev/null +++ b/types/src/errors/index.d.ts @@ -0,0 +1,4 @@ +export * from './api'; +export * from './general'; +export * from './easypost_error'; +export * from './error_handler'; diff --git a/types/src/index.d.ts b/types/src/index.d.ts new file mode 100644 index 000000000..310d378d1 --- /dev/null +++ b/types/src/index.d.ts @@ -0,0 +1,2 @@ +import EasyPost from './easypost'; +export default EasyPost; diff --git a/types/src/services/address_service/Address.d.ts b/types/src/services/address_service/Address.d.ts new file mode 100644 index 000000000..3de9d7439 --- /dev/null +++ b/types/src/services/address_service/Address.d.ts @@ -0,0 +1,72 @@ +import { IVerifications } from './Verifications'; +import { IObjectWithId } from '../../utils/types'; +/** + * Address objects are used to represent people, places, and organizations in a number of contexts. + * For example, a Shipment requires a to_address and from_address to accurately calculate rates and generate postage. + * + * Additionally, EasyPost offers several verification tools that can be used to detect deliverability issues, correct minor errors in spelling/formatting, and determine if an Address is residential or not (which has a significant effect on Shipment rating for many carriers). + * + * @see https://www.easypost.com/docs/api/node#address-object + */ +export type IAddress = IObjectWithId<'Address'> & { + /** + * First line of the address + */ + street1?: string | null; + /** + * Second line of the address + */ + street2?: string | null; + /** + * City the address is located in + */ + city?: string | null; + /** + * State or province the address is located in + */ + state?: string | null; + /** + * ZIP or postal code the address is located in + */ + zip: string; + /** + * ISO 3166 country code for the country the address is located in + */ + country: string; + /** + * Whether or not this address would be considered residential + */ + residential?: boolean | null; + /** + * The specific designation for the address (only relevant if the address is a carrier facility) + */ + carrier_facility?: string | null; + /** + * Name of the person. Both name and company can be included + */ + name?: string | null; + /** + * Name of the organization. Both name and company can be included + */ + company?: string | null; + /** + * Phone number to reach the person or organization + */ + phone?: string | null; + /** + * Email to reach the person or organization + */ + email?: string | null; + /** + * Federal tax identifier of the person or organization + */ + federal_tax_id?: string | null; + /** + * State tax identifier of the person or organization + */ + state_tax_id?: string | null; + /** + * The result of any verifications requested + */ + verifications: IVerifications; +}; diff --git a/types/src/services/address_service/AddressCreateParameters.d.ts b/types/src/services/address_service/AddressCreateParameters.d.ts new file mode 100644 index 000000000..67b6a50ff --- /dev/null +++ b/types/src/services/address_service/AddressCreateParameters.d.ts @@ -0,0 +1,22 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IAddress } from './Address'; +/** + * @see https://www.easypost.com/docs/api/node#create-and-verify-addresses + */ +export type IAddressCreateParameters = Omit< + IAddress, + ParametersToOmitOnCreate | 'verifications' +> & { + /** + * The verifications to perform when creating. + * verify_strict takes precedence. + * true will perform both delivery and zip code. + */ + verify?: boolean | null; + /** + * The verifications to perform when creating. + * The failure of any of these verifications causes the whole request to fail. + * true will perform both delivery and zip code. + */ + verify_strict?: boolean | null; +}; diff --git a/types/src/services/address_service/AddressListParameters.d.ts b/types/src/services/address_service/AddressListParameters.d.ts new file mode 100644 index 000000000..cb9b95716 --- /dev/null +++ b/types/src/services/address_service/AddressListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api#retrieve-a-list-of-addresses + */ +export type IAddressListParameters = IAllMethodParameters; diff --git a/types/src/services/address_service/Verification.d.ts b/types/src/services/address_service/Verification.d.ts new file mode 100644 index 000000000..6e547eb54 --- /dev/null +++ b/types/src/services/address_service/Verification.d.ts @@ -0,0 +1,19 @@ +import { IFieldError } from '../../utils/errors'; +import { IVerificationDetails } from './VerificationDetails'; +/** + * @see https://www.easypost.com/docs/api/node#verification-object + */ +export type IVerification = { + /** + * The success of the verification + */ + success: boolean; + /** + * All errors that caused the verification to fail + */ + errors: IFieldError[]; + /** + * Extra data related to the verification + */ + details: IVerificationDetails; +}; diff --git a/types/src/services/address_service/VerificationDetails.d.ts b/types/src/services/address_service/VerificationDetails.d.ts new file mode 100644 index 000000000..6ce352800 --- /dev/null +++ b/types/src/services/address_service/VerificationDetails.d.ts @@ -0,0 +1,17 @@ +/** + * @see https://www.easypost.com/docs/api/node#verification_details-object + */ +export type IVerificationDetails = { + /** + * The latitude of an Address. + */ + latitude: number; + /** + * The longitude of an Address. + */ + longitude: number; + /** + * The time zone the address is located in, IE: America/Los_Angeles + */ + time_zone: string; +}; diff --git a/types/src/services/address_service/Verifications.d.ts b/types/src/services/address_service/Verifications.d.ts new file mode 100644 index 000000000..85ea98d5b --- /dev/null +++ b/types/src/services/address_service/Verifications.d.ts @@ -0,0 +1,16 @@ +import { IVerification } from './Verification'; +/** + * @see https://www.easypost.com/docs/api/node#verifications-object + */ +export type IVerifications = { + /** + * Only applicable to US addresses - checks and sets the ZIP+4 + */ + zip4: IVerification; + /** + * Checks that the address is deliverable and makes minor corrections to spelling/format. US addresses will also have their "residential" status checked and set. + */ + delivery: IVerification; +}; +declare const _default: {}; +export default _default; diff --git a/types/src/services/address_service/index.d.ts b/types/src/services/address_service/index.d.ts new file mode 100644 index 000000000..ab557c1c7 --- /dev/null +++ b/types/src/services/address_service/index.d.ts @@ -0,0 +1,105 @@ +import EasyPost from '../..'; +import { IAddress } from './Address'; +import { IAddressCreateParameters } from './AddressCreateParameters'; +import { IAddressListParameters } from './AddressListParameters'; +export * from './Address'; +export * from './AddressCreateParameters'; +export * from './Verification'; +export * from './VerificationDetails'; +export * from './Verifications'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create an {@link Address address}. + * See {@link https://www.easypost.com/docs/api/node#create-an-address EasyPost API Documentation} for more information. + * @param params - Parameters for the address to be created. + * @returns - The created address. + */ + create( + params: IAddressCreateParameters, + ): Promise>; + /** + * Create and verify an {@link Address address} in a single request. + * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. + * @param params - Parameters for the address to be created. + * @returns - The created and verified address. + */ + createAndVerify(params: IAddressCreateParameters): Promise; + /** + * Retrieve all {@link Address addresses} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-addresses EasyPost API Documentation} for more information. + * @param params - Parameters to filter the list of addresses. + * @returns - An object containing a list of {@link Address addresses} and pagination information. + */ + all(params?: IAddressListParameters): Promise< + { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of Address collection. + * @param addresses An object containing a list of {@link Address addresses} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + addresses: { + addresses: IAddress[]; + }, + pageSize?: number | null, + ): Promise< + { + addresses: IAddress[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve an {@link Address address} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-address EasyPost API Documentation} for more information. + * @param id - The ID of the address to retrieve. + * @returns - The retrieved address. + */ + retrieve(id: string): Promise>; + /** + * Verify an {@link Address address} by its ID. + * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. + * @param id - The ID of the address to verify. + * @returns - The verified address. + */ + verifyAddress(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/api_key_service/ApiKey.d.ts b/types/src/services/api_key_service/ApiKey.d.ts new file mode 100644 index 000000000..c11cf642e --- /dev/null +++ b/types/src/services/api_key_service/ApiKey.d.ts @@ -0,0 +1,20 @@ +import { IObjectWithId } from '../../utils/types'; +export type IApiKey = IObjectWithId<'ApiKey'> & { + /** + * The actual key value to use for authentication + */ + key: string; + /** + * When the API key was created + */ + created_at: string; + /** + * Whether the API key is active or not + */ + active: boolean; +}; +export type UserAPIKeys = { + id: string; + keys: IApiKey[]; + children: UserAPIKeys[]; +}; diff --git a/types/src/services/api_key_service/index.d.ts b/types/src/services/api_key_service/index.d.ts new file mode 100644 index 000000000..972a59b27 --- /dev/null +++ b/types/src/services/api_key_service/index.d.ts @@ -0,0 +1,71 @@ +import EasyPost from '../..'; +import { IApiKey } from './ApiKey'; +export * from './ApiKey'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Retrieve all {@link ApiKey API keys} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. + * @returns - An object containing the API keys associated with the current authenticated user and its child users. + */ + all(params?: {}): Promise< + import('../../utils/types').IBaseObject<'ApiKey'> & { + id: string; + mode: 'test' | 'production'; + object: 'ApiKey'; + } & { + key: string; + created_at: string; + active: boolean; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve API Keys for a specified {@link User user}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. + * @param id - The ID of the user to retrieve keys for. + * @returns - List of associated API Keys. + * @throws {FilteringError} If user or API Keys are not found. + */ + retrieveApiKeysForUser(id: string): Promise; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject + /** + * Retrieve API Keys for a specified {@link User user}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. + * @param id - The ID of the user to retrieve keys for. + * @returns - List of associated API Keys. + * @throws {FilteringError} If user or API Keys are not found. + */; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/base_service.d.ts b/types/src/services/base_service.d.ts new file mode 100644 index 000000000..51048730a --- /dev/null +++ b/types/src/services/base_service.d.ts @@ -0,0 +1,71 @@ +import EasyPostClient from '../easypost'; +export type EasyPostObject = A & { + _params: any; +}; +declare const _default: (easypostClient: EasyPostClient) => { + new (): {}; + /** + * Converts a JSON response and all its nested elements to associated {@link EasyPostObject}-based class instances. + * @internal + * @param {*} response The JSON response to convert (usually a `Map` or `Array`). + * @param {*} params The parameters passed when fetching the response + * @returns {*} An {@link EasyPostObject}-based class instance or an `Array` of {@link EasyPostObject}-based class instances. + */ + _convertToEasyPostObject(response: A, params?: any): EasyPostObject; + /** + * Creates an EasyPost Object via the API. + * @internal + * @param url The URL to send the API request to. + * @param params The parameters to send with the API request. + * @returns The created {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + _create(url: string, params: object): Promise>; + /** + * Retrieve a list of records from the API. + * @internal + * @param url The URL to send the API request to. + * @param params The parameters to send with the API request. + * @returns The retrieved {@link EasyPostObject}-based class instance(s), or a `Promise` that rejects with an error. + */ + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a record from the API. + * @internal + * @param url The URL to send the API request to. + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + _retrieve(url: string): Promise>; + /** + * Retrieve the next page of specific collection of object + * @internal + * @param url The URL to send the API request to. + * @param collection The collection of a specific object. + * @param pageSize The number of records to return on each page. + * @param optionalParams The optional param for additional value in the query string. + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + * TODO: Implement this function in EndShippers and Batches once the API supports them properly. + */ + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/batch_service/Batch.d.ts b/types/src/services/batch_service/Batch.d.ts new file mode 100644 index 000000000..cdd5ee354 --- /dev/null +++ b/types/src/services/batch_service/Batch.d.ts @@ -0,0 +1,48 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IPickup } from '../pickup_service/Pickup'; +import { IScanForm } from '../scan_form_service'; +import { IBatchShipment } from './BatchShipment'; +import { TBatchState } from './BatchState'; +import { TBatchStatuses } from './BatchStatuses'; +/** + * The Batch object allows you to perform operations on multiple Shipments at once. + * This includes scheduling a Pickup, creating a ScanForm and consolidating labels. + * Operations performed on Batches are asynchronous and take advantage of our webhook infrastructure. + * + * @see https://www.easypost.com/docs/api/node#batch-object + */ +export type IBatch = IObjectWithId<'Batch'> & + IDatedObject & { + /** + * An optional field that may be used in place of ID in some API endpoints + */ + reference?: string | null; + /** + * The overall state. Possible values are "creating", "creation_failed", "created", "purchasing", "purchase_failed", "purchased", "label_generating", and "label_generated" + */ + state: TBatchState; + /** + * The number of shipments added + */ + num_shipments: number; + /** + * An array of batch shipments + */ + shipments: IBatchShipment[]; + /** + * A map of BatchShipment statuses to the count of BatchShipments with that status. Valid statuses are "postage_purchased", "postage_purchase_failed", "queued_for_purchase", and "creation_failed" + */ + status: TBatchStatuses; + /** + * The label image url + */ + label_url?: string | null; + /** + * The created ScanForm + */ + scan_form: IScanForm; + /** + * The created Pickup + */ + pickup: IPickup; + }; diff --git a/types/src/services/batch_service/BatchCreateParameters.d.ts b/types/src/services/batch_service/BatchCreateParameters.d.ts new file mode 100644 index 000000000..b778883b5 --- /dev/null +++ b/types/src/services/batch_service/BatchCreateParameters.d.ts @@ -0,0 +1,8 @@ +export type IBatchCreateParameters = { + shipments?: ( + | { + id: string; + } + | string + )[]; +}; diff --git a/types/src/services/batch_service/BatchListParameters.d.ts b/types/src/services/batch_service/BatchListParameters.d.ts new file mode 100644 index 000000000..38f453d9f --- /dev/null +++ b/types/src/services/batch_service/BatchListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#list-all-batches + */ +export type IBatchListParameters = IAllMethodParameters; diff --git a/types/src/services/batch_service/BatchShipment.d.ts b/types/src/services/batch_service/BatchShipment.d.ts new file mode 100644 index 000000000..48c669792 --- /dev/null +++ b/types/src/services/batch_service/BatchShipment.d.ts @@ -0,0 +1,22 @@ +import { TBatchStatus } from './BatchStatus'; +/** + * @see https://www.easypost.com/docs/api/node#batch-shipment-object + */ +export type IBatchShipment = { + /** + * The id of the Shipment. Unique, begins with "shp_" + */ + id: string; + /** + * An optional field that may be used in place of ID in some API endpoints + */ + reference?: string | null; + /** + * The current status. Possible values are "postage_purchased", "postage_purchase_failed", "queued_for_purchase", "creation_failed", and "created" + */ + batch_status: TBatchStatus; + /** + * A human readable message for any errors that occurred during the Batch's life cycle + */ + batch_message: string; +}; diff --git a/types/src/services/batch_service/BatchState.d.ts b/types/src/services/batch_service/BatchState.d.ts new file mode 100644 index 000000000..41fa51e7a --- /dev/null +++ b/types/src/services/batch_service/BatchState.d.ts @@ -0,0 +1,9 @@ +export type TBatchState = + | 'creating' + | 'creation_failed' + | 'created' + | 'purchasing' + | 'purchase_failed' + | 'purchased' + | 'label_generating' + | 'label_generated'; diff --git a/types/src/services/batch_service/BatchStatus.d.ts b/types/src/services/batch_service/BatchStatus.d.ts new file mode 100644 index 000000000..c85d419dc --- /dev/null +++ b/types/src/services/batch_service/BatchStatus.d.ts @@ -0,0 +1,6 @@ +export type TBatchStatus = + | 'postage_purchased' + | 'postage_purchase_failed' + | 'queued_for_purchase' + | 'creation_failed' + | 'created'; diff --git a/types/src/services/batch_service/BatchStatuses.d.ts b/types/src/services/batch_service/BatchStatuses.d.ts new file mode 100644 index 000000000..7795213f7 --- /dev/null +++ b/types/src/services/batch_service/BatchStatuses.d.ts @@ -0,0 +1,4 @@ +import { TBatchStatus } from './BatchStatus'; +export type TBatchStatuses = { + [key in TBatchStatus]: number; +}; diff --git a/types/src/services/batch_service/index.d.ts b/types/src/services/batch_service/index.d.ts new file mode 100644 index 000000000..b815b9db2 --- /dev/null +++ b/types/src/services/batch_service/index.d.ts @@ -0,0 +1,132 @@ +import EasyPost from '../..'; +import { IBatch } from './Batch'; +import { IBatchCreateParameters } from './BatchCreateParameters'; +import { IBatchListParameters } from './BatchListParameters'; +export * from './Batch'; +export * from './BatchCreateParameters'; +export * from './BatchListParameters'; +export * from './BatchShipment'; +export * from './BatchState'; +export * from './BatchStatus'; +export * from './BatchStatuses'; +export declare const DEFAULT_LABEL_FORMAT = 'pdf'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#create-a-batch EasyPost API Documentation} for more information. + * @param params - Parameters for the batch to be created. + * @returns - The created batch. + */ + create(params: IBatchCreateParameters): Promise>; + /** + * Add {@link Shipment shipments} to a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#add-shipments-to-a-batch EasyPost API Documentation} for more information. + * @param id - The id of the batch to add shipments to. + * @param shipmentIds - The ids of the shipments to add to the batch. + * @returns - The updated batch. + */ + addShipments( + id: string, + shipmentIds: string[], + ): Promise>; + /** + * Removes {@link Shipment shipments} from a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#remove-shipments-from-a-batch EasyPost API Documentation} for more information. + * @param id - The id of the batch to remove shipments from. + * @param shipmentIds - The ids of the shipments to remove from the batch. + * @returns - The updated batch. + */ + removeShipments( + id: string, + shipmentIds: string[], + ): Promise>; + /** + * Generate a label for a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#batch-labels EasyPost API Documentation} for more information. + * @param id - The id of the batch to generate a label for. + * @param fileFormat - The format of the label to generate. Defaults to 'pdf'. + * @returns - The updated batch. + */ + generateLabel( + id: string, + fileFormat?: string, + ): Promise>; + /** + * Create a {@link ScanForm scan form} for a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#manifesting-scan-form EasyPost API Documentation} for more information. + * @param id - The id of the batch to create a scan form for. + * @returns - The updated batch. + */ + createScanForm(id: string): Promise>; + /** + * Purchase a {@link Batch batch}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-batch EasyPost API Documentation} for more information. + * @param id - The id of the batch to purchase. + * @returns - The purchased batch. + */ + buy(id: string): Promise>; + /** + * Retrieve all {@link Batch batches} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#list-all-batches EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of batches. + * @returns - An object containing a list of {@link Batch batches} and pagination information. + */ + all(params?: IBatchListParameters): Promise< + import('../../utils/types').IBaseObject<'Batch'> & { + id: string; + mode: 'test' | 'production'; + object: 'Batch'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + state: import('./BatchState').TBatchState; + num_shipments: number; + shipments: import('./BatchShipment').IBatchShipment[]; + status: import('./BatchStatuses').TBatchStatuses; + label_url?: string | null | undefined; + scan_form: import('..').IScanForm; + pickup: import('../pickup_service/Pickup').IPickup; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link Batch batch} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-batch EasyPost API Documentation} for more information. + * @param id - The ID of the batch to retrieve. + * @returns - The retrieved batch. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/beta_rate_service/index.d.ts b/types/src/services/beta_rate_service/index.d.ts new file mode 100644 index 000000000..bc4eeca1e --- /dev/null +++ b/types/src/services/beta_rate_service/index.d.ts @@ -0,0 +1,44 @@ +import EasyPost from '../..'; +import { IRate } from '../rate_service/Rate'; +/** + * @extends baseService + */ +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Retrieve a list of stateless {@link Rate rates} based on the provided parameters. + * @param params - Map of parameters for the API call + * @returns - List of stateless rates + */ + retrieveStatelessRates(params: any): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/beta_referral_customer_service/index.d.ts b/types/src/services/beta_referral_customer_service/index.d.ts new file mode 100644 index 000000000..dd8a712ae --- /dev/null +++ b/types/src/services/beta_referral_customer_service/index.d.ts @@ -0,0 +1,60 @@ +import EasyPost from '../..'; +import { IPaymentMethod } from '../billing_service'; +import { IRefund } from '../refund_service'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Add an existing Stripe payment method to a {@link User referral customer's} account. + * @param stripeCustomerId - The Stripe account's ID. + * @param paymentMethodReference - Reference of Stripe payment method. + * @param [priority] - Which priority to set the payment method to ('primary' or 'secondary'). + * @returns - A JSON object representing the payment method. + */ + addPaymentMethod( + stripeCustomerId: string, + paymentMethodReference: string, + priority?: 'primary' | 'secondary', + ): Promise; + /** + * Refund by amount for a recent payment. + * @param refundAmount - Amount to be refunded by cents. + * @returns - A JSON object representing the refund. + */ + refundByAmount(refundAmount: number): Promise; + /** + * Refund a payment by a payment log ID. + * @param paymentLogId - ID of the payment log. + * @returns - Returns BetaPaymentRefund object. + */ + refundByPaymentLog(paymentLogId: string): Promise; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/billing_service/PaymentMethod.d.ts b/types/src/services/billing_service/PaymentMethod.d.ts new file mode 100644 index 000000000..5680f3db0 --- /dev/null +++ b/types/src/services/billing_service/PaymentMethod.d.ts @@ -0,0 +1,44 @@ +import { IObjectWithId } from '../../utils/types'; +/** + * The Payment method object can be either credit card or bank account. + * + * TODO: Add the link to the API doc once its updated + */ +export type IPaymentMethod = IObjectWithId<'PaymentMethod'> & { + /** + * Country of the bank account + */ + country: string; + /** + * Name of the bank + */ + bank_name: string; + /** + * Brand of the credit card + */ + brand: string; + /** + * Whether the payment method(credit card or bank account) is disabled or not + */ + disabled_at: string; + /** + * Expiration month of the credit card + */ + exp_month: number; + /** + * Expiration year of the credit card + */ + exp_year: number; + /** + * Last four of the credit card + */ + last4: string; + /** + * Name of the credit card + */ + name: string; + /** + * Whether the bank account is verified or not + */ + verified: boolean; +}; diff --git a/types/src/services/billing_service/index.d.ts b/types/src/services/billing_service/index.d.ts new file mode 100644 index 000000000..dc097c109 --- /dev/null +++ b/types/src/services/billing_service/index.d.ts @@ -0,0 +1,63 @@ +import EasyPost from '../..'; +export * from './PaymentMethod'; +export type Priority = 'primary' | 'secondary'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Fund your EasyPost wallet by charging your primary or secondary payment method on file. + * See {@link https://www.easypost.com/docs/api/node#add-funds-to-your-wallet-one-time-charge EasyPost API Documentation} for more information. + * @param amount - The amount to charge to your payment method. + * @param priority - The priority of the payment method to charge. Can be either 'primary' or 'secondary'. + */ + fundWallet(amount: string, priority?: Priority): Promise; + /** + * Delete a payment method from the current authenticated user's account. + * See {@link https://www.easypost.com/docs/api/node#delete-a-payment-method EasyPost API Documentation} for more information. + * @param priority - The priority of the payment method to delete. Can be either 'primary' or 'secondary'. + */ + deletePaymentMethod(priority: Priority): Promise; + /** + * Retrieve all payment methods associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-payment-methods EasyPost API Documentation} for more information. + * @returns {Object} - An object containing the payment methods associated with the current authenticated user. + */ + retrievePaymentMethods(): Promise; + /** + * Get payment info (type of the payment method and ID of the payment method) + * This function is intended for internal use only, please avoid using this function + * @private + * @param {String} priority - The priority of the payment method to retrieve. Can be either 'primary' or 'secondary'. + * @returns {string[]} - An array of two strings, the first being the endpoint of the payment method and the second being the ID of the payment method. + */ + _getPaymentInfo(priority: Priority): Promise; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/carrier_account_service/CarrierAccount.d.ts b/types/src/services/carrier_account_service/CarrierAccount.d.ts new file mode 100644 index 000000000..18d31c329 --- /dev/null +++ b/types/src/services/carrier_account_service/CarrierAccount.d.ts @@ -0,0 +1,53 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { ICarrierAccountFields } from './CarrierAccountFields'; +/** + * A CarrierAccount encapsulates your credentials with the carrier. + * The CarrierAccount object provides CRUD operations for all CarrierAccounts. + * + * Each EasyPost account is automatically provided a USPS account managed by EasyPost. + * + * Other operations, such as Shipment creation, can reference CarrierAccounts to reduce the scope of data returned. + * For instance, you may have multiple warehouses that need to use distinct FedEx SmartPost credentials to request the correct rates. + * Rate objects will include a `carrier_account_id` field which can be used to determine the account used for rating. + * + * @see https://www.easypost.com/docs/api/node#carrier-account-object + */ +export type ICarrierAccount = IObjectWithId<'CarrierAccount'> & + IDatedObject & { + /** + * The name of the carrier type. + */ + type: string; + /** + * Contains "credentials" and/or "test_credentials", or may be empty + */ + fields: ICarrierAccountFields; + /** + * If clone is true, only the reference and description are possible to update + */ + clone?: boolean | null; + /** + * An optional, user-readable field to help distinguish accounts + */ + description?: string | null; + /** + * An optional field that may be used in place of carrier_account_id in other API endpoints + */ + reference?: string | null; + /** + * The name used when displaying a readable value for the type of the account + */ + readable: string; + /** + * Unlike the "credentials" object contained in "fields", this nullable object contains just raw credential pairs for client library consumption + */ + credentials?: object | null; + /** + * Unlike the "test_credentials" object contained in "fields", this nullable object contains just raw test_credential pairs for client library consumption + */ + test_credentials?: object | null; + /** + * Billing type of the carrier account + */ + billing_type: string | null; + }; diff --git a/types/src/services/carrier_account_service/CarrierAccountCreateParameters.d.ts b/types/src/services/carrier_account_service/CarrierAccountCreateParameters.d.ts new file mode 100644 index 000000000..c92ebd574 --- /dev/null +++ b/types/src/services/carrier_account_service/CarrierAccountCreateParameters.d.ts @@ -0,0 +1,3 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { ICarrierAccount } from './CarrierAccount'; +export type ICarrierAccountCreateParameters = Omit; diff --git a/types/src/services/carrier_account_service/CarrierAccountField.d.ts b/types/src/services/carrier_account_service/CarrierAccountField.d.ts new file mode 100644 index 000000000..3d13bf156 --- /dev/null +++ b/types/src/services/carrier_account_service/CarrierAccountField.d.ts @@ -0,0 +1,21 @@ +/** + * @see https://www.easypost.com/docs/api/node#carrier-account-field-object + */ +export type ICarrierAccountField = { + /** + * Each key in the sub-objects of a CarrierAccount's fields is the name of a settable field + */ + key: string; + /** + * The visibility value is used to control form field types, and is discussed in the CarrierType section + */ + visibility: string; + /** + * The label value is used in form rendering to display a more precise field name + */ + label: string; + /** + * Checkbox fields use "0" and "1" as False and True, all other field types present plaintext, partly-masked, or masked credential data for reference + */ + value: string; +}; diff --git a/types/src/services/carrier_account_service/CarrierAccountFields.d.ts b/types/src/services/carrier_account_service/CarrierAccountFields.d.ts new file mode 100644 index 000000000..4371a867f --- /dev/null +++ b/types/src/services/carrier_account_service/CarrierAccountFields.d.ts @@ -0,0 +1,22 @@ +import { ICarrierAccountField } from './CarrierAccountField'; +/** + * @see https://www.easypost.com/docs/api/node#carrier-account-fields-object + */ +export type ICarrierAccountFields = { + /** + * Credentials used in the production environment. + */ + credentials: ICarrierAccountField; + /** + * Credentials used in the test environment. + */ + test_credentials: ICarrierAccountField; + /** + * For USPS this designates that no credentials are required. + */ + auto_link: boolean; + /** + * When present, a separate authentication process will be required through the UI to link this account type. + */ + custom_workflow: boolean; +}; diff --git a/types/src/services/carrier_account_service/index.d.ts b/types/src/services/carrier_account_service/index.d.ts new file mode 100644 index 000000000..8415d712a --- /dev/null +++ b/types/src/services/carrier_account_service/index.d.ts @@ -0,0 +1,116 @@ +import EasyPost from '../..'; +import { ICarrierAccount } from './CarrierAccount'; +import { ICarrierAccountCreateParameters } from './CarrierAccountCreateParameters'; +export * from './CarrierAccount'; +export * from './CarrierAccountCreateParameters'; +export * from './CarrierAccountField'; +export * from './CarrierAccountFields'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link CarrierAccount carrier account}. + * See {@link https://www.easypost.com/docs/api/node#create-a-carrier-account EasyPost API Documentation} for more information. + * @param params - Parameters for the carrier account to be created. + * @returns - The created carrier account. + */ + create( + params: ICarrierAccountCreateParameters, + ): Promise>; + /** + * Update a {@link CarrierAccount carrier account}. + * See {@link https://www.easypost.com/docs/api/node#update-a-carrieraccount EasyPost API Documentation} for more information. + * @param id - The id of the carrier account to be updated. + * @param params - Parameters for the carrier account to be updated. + * @returns - The updated carrier account. + */ + update( + id: string, + params: Partial, + ): Promise>; + /** + * Delete a {@link CarrierAccount carrier account}. + * See {@link https://www.easypost.com/docs/api/node#delete-a-carrier-account EasyPost API Documentation} for more information. + * @param id - The id of the carrier account to be deleted. + * @returns - A promise that resolves when the carrier account has been deleted. + */ + delete(id: string): Promise; + /** + * Returns the correct carrier_account endpoint when creating a record based on the type. + * @private + * @param {string} carrierAccountType - The type of carrier account to be created. + * @returns {string} - The endpoint to be used for the carrier account creation request. + */ + _selectCarrierAccountCreationEndpoint( + carrierAccountType: string, + ): 'carrier_accounts/register' | 'carrier_accounts'; + /** + * Retrieve all {@link CarrierAccount carrier accounts} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#list-all-carrier-accounts EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of carrier accounts. + * @returns - An object containing a list of {@link CarrierAccount carrier accounts} and pagination information. + */ + all(params?: {}): Promise< + import('../../utils/types').IBaseObject<'CarrierAccount'> & { + id: string; + mode: 'test' | 'production'; + object: 'CarrierAccount'; + } & import('../../utils/types').IDatedObject & { + type: string; + fields: import('./CarrierAccountFields').ICarrierAccountFields; + clone?: boolean | null | undefined; + description?: string | null | undefined; + reference?: string | null | undefined; + readable: string; + credentials?: object | null | undefined; + test_credentials?: object | null | undefined; + billing_type: string | null; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link CarrierAccount carrier account} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-carrieraccount EasyPost API Documentation} for more information. + * @param id - The ID of the carrier account to retrieve. + * @returns - The retrieved carrier account. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean + /** + * Retrieve all {@link CarrierAccount carrier accounts} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#list-all-carrier-accounts EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of carrier accounts. + * @returns - An object containing a list of {@link CarrierAccount carrier accounts} and pagination information. + */; + } + >; +}; +export default _default; diff --git a/types/src/services/carrier_metadata_service/CarrierMetadata.d.ts b/types/src/services/carrier_metadata_service/CarrierMetadata.d.ts new file mode 100644 index 000000000..4f76eebc3 --- /dev/null +++ b/types/src/services/carrier_metadata_service/CarrierMetadata.d.ts @@ -0,0 +1,34 @@ +/** + * The Carrier Metadata endpoint returns information about all the carriers available on the EasyPost platform. + * This information may include service levels, predefined packages, shipment options, supported features, and + * more that are available per carrier. This metadata can be useful during onboarding and integration or when + * determining the ideal carrier mix for your setup. + * + * @see https://www.easypost.com/docs/api/node#carriermetadata-object + */ +export type ICarrierMetadata = { + /** + * The single-word name of a carrier such as "royalmail" + */ + carrier: string; + /** + * The human-readable name of the carrier + */ + human_readable?: string | null; + /** + * A list of service level objects for this carrier + */ + service_levels?: Array | null; + /** + * A list of predefined package objects for this carrier + */ + predefined_packages?: Array | null; + /** + * A list of supported feature objects for this carrier + */ + supported_features?: Array | null; + /** + * A list of shipment option objects for this carrier + */ + shipment_options?: Array | null; +}; diff --git a/types/src/services/carrier_metadata_service/index.d.ts b/types/src/services/carrier_metadata_service/index.d.ts new file mode 100644 index 000000000..91a1f62e3 --- /dev/null +++ b/types/src/services/carrier_metadata_service/index.d.ts @@ -0,0 +1,46 @@ +import EasyPost from '../..'; +import { ICarrierMetadata } from './CarrierMetadata'; +export * from './CarrierMetadata'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Retrieve a list of carrier metadata based on the provided parameters. + * @param carriers - List of carrier in string + * @param type - List of types in string + * @returns - List of carrier metadata + */ + retrieve( + carriers?: string[] | null, + types?: string[] | null, + ): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/carrier_type_service/CarrierType.d.ts b/types/src/services/carrier_type_service/CarrierType.d.ts new file mode 100644 index 000000000..755c25a0e --- /dev/null +++ b/types/src/services/carrier_type_service/CarrierType.d.ts @@ -0,0 +1,27 @@ +import { IBaseObject } from '../../utils/types'; +import { ICarrierTypeFields } from './CarrierTypeFields'; +/** + * The CarrierType object provides an export declare interface for determining the valid fields of a CarrierAccount. + * The list of CarrierType objects only changes when a new carrier is added to EasyPost. + * + * The CarrierType objects consist of their top level attributes as well as a fields object that contains credentials and sometimes test_credentials sub-objects, + * which themselves are collections of attributes for CarrierAccount creation as well as metadata about presentation and the naming of said attributes. + * + * There are a couple special case CarrierAccounts, with structures differing somewhat from the norm. + * For instance, instead of credentials for UspsAccount, it has only auto_link: true, which indicates that it is an account that can be added or removed without any carrier-specific fields. + * + * The other custom option in the fields list is custom_workflow: true, which indicates that the EasyPost website export declare interface includes special processing for signups for the associated CarrierType. + * Carriers with a custom workflow will also present their normal credential rules, but it is considered unsafe to directly add a CarrierAccount of this type with these attributes filled out via another source than the EasyPost custom workflow. + * + * @see https://www.easypost.com/docs/api/node#carrier-type-object + */ +export type ICarrierType = IBaseObject<'CarrierType'> & { + /** + * Specifies the CarrierAccount type. + */ + type: string; + /** + * Contains at least one of the following keys: "auto_link", "credentials", "test_credentials", and "custom_workflow" + */ + fields: ICarrierTypeFields; +}; diff --git a/types/src/services/carrier_type_service/CarrierTypeCredentials.d.ts b/types/src/services/carrier_type_service/CarrierTypeCredentials.d.ts new file mode 100644 index 000000000..53653ec07 --- /dev/null +++ b/types/src/services/carrier_type_service/CarrierTypeCredentials.d.ts @@ -0,0 +1,17 @@ +/** + * @see https://www.easypost.com/docs/api/node#carrier-type-credentials-object + */ +export type ICarrierTypeCredentials = { + /** + * The key for each attribute sub-object within credentials is the name of the attribute for submission on CarrierAccounts + */ + name: string; + /** + * There are five possible values, which encode the security need and storage type for each attribute: "visible", "checkbox", "fake", "password", and "masked" + */ + visibility: 'visible' | 'checkbox' | 'fake' | 'password' | 'masked'; + /** + * Most attributes have generic names, so for clarity a "label" value is provided for clearer representation when rendering forms + */ + label: string; +}; diff --git a/types/src/services/carrier_type_service/CarrierTypeFields.d.ts b/types/src/services/carrier_type_service/CarrierTypeFields.d.ts new file mode 100644 index 000000000..0eea6b8cc --- /dev/null +++ b/types/src/services/carrier_type_service/CarrierTypeFields.d.ts @@ -0,0 +1,23 @@ +import { ICarrierTypeCredentials } from './CarrierTypeCredentials'; +/** + * @see https://www.easypost.com/docs/api/node#carrier-type-fields-object + */ +export type ICarrierTypeFields = { + /** + * If this key is present with the value of true, no other attributes are needed for CarrierAccount creation + */ + auto_link: boolean; + /** + * If this key is present with the value of true, CarrierAccount creation of this type requires extra work not handled by the CarrierAccount standard API + */ + custom_workflow: boolean; + /** + * If this object is present, required attribute names and their metadata are presented inside + */ + credentials: ICarrierTypeCredentials; + /** + * If this object is present, it contains attribute names and metadata just as the credentials object. + * It is not required for CarrierAccount creation if you do not plan on using the carrier account for test mode + */ + test_credentials: ICarrierTypeCredentials; +}; diff --git a/types/src/services/carrier_type_service/index.d.ts b/types/src/services/carrier_type_service/index.d.ts new file mode 100644 index 000000000..f220bcf91 --- /dev/null +++ b/types/src/services/carrier_type_service/index.d.ts @@ -0,0 +1,45 @@ +import EasyPost from '../..'; +import { ICarrierType } from './CarrierType'; +export * from './CarrierType'; +export * from './CarrierTypeCredentials'; +export * from './CarrierTypeFields'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Retrieve all {@link CarrierType carrier types} available to the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-available-carrier-types EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of carrier types. + * @returns - A list of {@link CarrierType carrier types}. + */ + all(params?: {}): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/customs_info_service/CustomsInfo.d.ts b/types/src/services/customs_info_service/CustomsInfo.d.ts new file mode 100644 index 000000000..ce91e3287 --- /dev/null +++ b/types/src/services/customs_info_service/CustomsInfo.d.ts @@ -0,0 +1,55 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { ICustomsItem } from '../customs_item_service'; +/** + * CustomsInfo objects contain CustomsItem objects and all necessary information for the generation of customs forms required for international shipping. + * + * Please see the Shipments documentation for examples of including a CustomsInfo object in a shipment. + * + * @see https://www.easypost.com/docs/api/node#customs-info-object + */ +export type ICustomsInfo = IObjectWithId<'CustomsInfo'> & + IDatedObject & { + /** + * "EEL" or "PFC" + * value less than $2500: "NOEEI 30.37(a)" + * value greater than $2500: see [Customs Guide](https://www.easypost.com/customs-guide) + */ + eel_pfc?: string | null; + /** + * "documents", "gift", "merchandise", "returned_goods", "sample", or "other" + */ + contents_type?: string | null; + /** + * (max 255 characters) Human readable description of content. + * Required for certain carriers and always required if contents_type is "other" + */ + contents_explanation?: string | null; + /** + * Electronically certify the information provided + */ + customs_certify?: boolean | null; + /** + * Required if customs_certify is true + */ + customs_signer?: string | null; + /** + * "abandon" or "return", defaults to "return" + */ + non_delivery_option?: 'abandon' | 'return' | null; + /** + * "none", "other", "quarantine", or "sanitary_phytosanitary_inspection" + */ + restriction_type?: 'none' | 'other' | 'quarantine' | 'sanitary_phytosanitary_inspection' | null; + /** + * Required if restriction_type is not "none" + */ + restriction_comments?: string | null; + /** + * Describes the products being shipped + */ + customs_items: ICustomsItem[]; + /** + * A customs declaration message, available for eligible carriers + */ + declaration?: string | null; + }; diff --git a/types/src/services/customs_info_service/CustomsInfoCreateParameters.d.ts b/types/src/services/customs_info_service/CustomsInfoCreateParameters.d.ts new file mode 100644 index 000000000..c3a689c41 --- /dev/null +++ b/types/src/services/customs_info_service/CustomsInfoCreateParameters.d.ts @@ -0,0 +1,3 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { ICustomsInfo } from './CustomsInfo'; +export type ICustomsInfoCreateParameters = Omit; diff --git a/types/src/services/customs_info_service/index.d.ts b/types/src/services/customs_info_service/index.d.ts new file mode 100644 index 000000000..718ff65af --- /dev/null +++ b/types/src/services/customs_info_service/index.d.ts @@ -0,0 +1,54 @@ +import EasyPost from '../..'; +import { ICustomsInfo } from './CustomsInfo'; +import { ICustomsInfoCreateParameters } from './CustomsInfoCreateParameters'; +export * from './CustomsInfo'; +export * from './CustomsInfoCreateParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link CustomsInfo customs info} record. + * See {@link https://www.easypost.com/docs/api/node#create-a-customsinfo EasyPost API Documentation} for more information. + * @param params - Parameters for the customs info to be created. + * @returns - The created customs info. + */ + create( + params: ICustomsInfoCreateParameters, + ): Promise>; + /** + * Retrieve a {@link CustomsInfo customs info} record by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-customsinfo EasyPost API Documentation} for more information. + * @param id - The ID of the customs info to retrieve. + * @returns - The retrieved customs info. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/customs_item_service/CustomsItem.d.ts b/types/src/services/customs_item_service/CustomsItem.d.ts new file mode 100644 index 000000000..2852a841b --- /dev/null +++ b/types/src/services/customs_item_service/CustomsItem.d.ts @@ -0,0 +1,46 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * A CustomsItem object describes goods for international shipment and should be created then included in a CustomsInfo object. + * + * @see https://www.easypost.com/docs/api/node#customs-item-object + */ +export type ICustomsItem = IObjectWithId<'CustomsItem'> & + IDatedObject & { + /** + * Required, description of item being shipped + */ + description: string; + /** + * Required, greater than zero + * float + */ + quantity: number; + /** + * Required, greater than zero, total value (unit value * quantity) + * float (USD) + */ + value: number; + /** + * Required, greater than zero, total weight (unit weight * quantity) + * float (oz) + */ + weight: number; + /** + * Harmonized Tariff Schedule, e.g. "6109.10.0012" for Men's T-shirts + * + * @see https://hts.usitc.gov/ + */ + hs_tariff_number?: string | null; + /** + * SKU/UPC or other product identifier + */ + code?: string | null; + /** + * Required, 2 char country code + */ + origin_country: string; + /** + * 3 char currency code, default USD + */ + currency?: string | null; + }; diff --git a/types/src/services/customs_item_service/CustomsItemCreateParameters.d.ts b/types/src/services/customs_item_service/CustomsItemCreateParameters.d.ts new file mode 100644 index 000000000..4ac2ff6d7 --- /dev/null +++ b/types/src/services/customs_item_service/CustomsItemCreateParameters.d.ts @@ -0,0 +1,3 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { ICustomsItem } from './CustomsItem'; +export type ICustomsItemCreateParameters = Omit; diff --git a/types/src/services/customs_item_service/index.d.ts b/types/src/services/customs_item_service/index.d.ts new file mode 100644 index 000000000..c8d46b2d2 --- /dev/null +++ b/types/src/services/customs_item_service/index.d.ts @@ -0,0 +1,54 @@ +import EasyPost from '../..'; +import { ICustomsItem } from './CustomsItem'; +import { ICustomsItemCreateParameters } from './CustomsItemCreateParameters'; +export * from './CustomsItem'; +export * from './CustomsItemCreateParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link CustomsItem customs item}. + * See {@link https://www.easypost.com/docs/api/node#create-a-customsitem EasyPost API Documentation} for more information. + * @param params - Parameters for the customs item to be created. + * @returns - The created customs item. + */ + create( + params: ICustomsItemCreateParameters, + ): Promise>; + /** + * Retrieve a {@link CustomsItem customs item} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-customsitem EasyPost API Documentation} for more information. + * @param id - The ID of the customs item to retrieve. + * @returns - The retrieved customs item. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/end_shipper_service/EndShipper.d.ts b/types/src/services/end_shipper_service/EndShipper.d.ts new file mode 100644 index 000000000..5e5b37489 --- /dev/null +++ b/types/src/services/end_shipper_service/EndShipper.d.ts @@ -0,0 +1,52 @@ +import { IObjectWithId } from '../../utils/types'; +/** + * The EndShipper API is for platforms purchasing postage on behalf of their users, the EndShipper. + * Platforms must assert the EndShipper details, as the EndShipper is ultimately responsible for what is in the box. + * Multiple labels purchased for the same EndShipper must use the same EndShipper identity (API object). + * EndShipper objects must be created prior to buying a Shipment. Once EndShipper objects have been created, + * you must keep track of their public id in order to use them during a label buy. + * + * @see https://www.easypost.com/docs/api/node#endshipper + */ +export type IEndshipper = IObjectWithId<'EndShipper'> & { + /** + * Name of responsible person (conditionally required) + */ + name?: string | null; + /** + * Name of responsible company (conditionally required) + */ + company?: string | null; + /** + * First line of the address + */ + street1?: string | null; + /** + * Second line of the address + */ + street2?: string | null; + /** + * City the address is located in + */ + city?: string | null; + /** + * State or province the address is located in + */ + state?: string | null; + /** + * ZIP or postal code the address is located in + */ + zip: string; + /** + * ISO 3166 country code for the country the address is located in + */ + country?: string; + /** + * Phone number to reach the person or organization + */ + phone?: string | null; + /** + * Email to reach the person or organization + */ + email?: string | null; +}; diff --git a/types/src/services/end_shipper_service/EndShipperCreateParameters.d.ts b/types/src/services/end_shipper_service/EndShipperCreateParameters.d.ts new file mode 100644 index 000000000..11276c69a --- /dev/null +++ b/types/src/services/end_shipper_service/EndShipperCreateParameters.d.ts @@ -0,0 +1,3 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IEndshipper } from './EndShipper'; +export type IEndShipperCreateParameters = Omit; diff --git a/types/src/services/end_shipper_service/EndShipperListParameters.d.ts b/types/src/services/end_shipper_service/EndShipperListParameters.d.ts new file mode 100644 index 000000000..c806a475e --- /dev/null +++ b/types/src/services/end_shipper_service/EndShipperListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api#endshipper + */ +export type IEndShipperListParameters = IAllMethodParameters; diff --git a/types/src/services/end_shipper_service/index.d.ts b/types/src/services/end_shipper_service/index.d.ts new file mode 100644 index 000000000..138577854 --- /dev/null +++ b/types/src/services/end_shipper_service/index.d.ts @@ -0,0 +1,80 @@ +import EasyPost from '../..'; +import { IEndshipper } from './EndShipper'; +import { IEndShipperCreateParameters } from './EndShipperCreateParameters'; +import { IEndShipperListParameters } from './EndShipperListParameters'; +export * from './EndShipper'; +export * from './EndShipperCreateParameters'; +export * from './EndShipperListParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create an {@link EndShipper end shipper}. + * See {@link https://www.easypost.com/docs/api/node#create-an-endshipper EasyPost API Documentation} for more information. + * @param params - Parameters for the end shipper to be created. + * @returns - The created end shipper. + */ + create( + params: IEndShipperCreateParameters, + ): Promise>; + /** + * Update an {@link EndShipper end shipper}. + * See {@link https://www.easypost.com/docs/api/node#update-an-endshipper EasyPost API Documentation} for more information. + * @param id - The ID of the end shipper to update. + * @param params - Parameters for the end shipper to be updated. + * @returns - The updated end shipper. + */ + update( + id: string, + params: Partial, + ): Promise>; + /** + * Retrieve an {@link EndShipper end shipper} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-endshipper EasyPost API Documentation} for more information. + * @param id - The ID of the end shipper to retrieve. + * @returns - The retrieved end shipper. + */ + retrieve(id: string): Promise>; + /** + * Retrieve all {@link EndShipper end shippers} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-endshippers EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of end shippers. + * @returns - An object containing a list of {@link EndShipper end shippers} and pagination information. + */ + all(params?: IEndShipperListParameters): Promise< + { + _params: any; + } & { + has_more: boolean; + } + >; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/event_service/Event.d.ts b/types/src/services/event_service/Event.d.ts new file mode 100644 index 000000000..9da8a5e69 --- /dev/null +++ b/types/src/services/event_service/Event.d.ts @@ -0,0 +1,40 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * Webhook Events are triggered by changes in objects you've created via the API. + * Every time an Event related to one of your objects is created, EasyPost guarantees at least one POST request will be sent to each of the webhook URLs set up for your account. + * For this reason, we strongly encourage your webhook handler to be idempotent. + * See the webhooks guide for more information. + * + * @see https://www.easypost.com/docs/api/node#events + */ +export type IEvent = IObjectWithId<'Event'> & + IDatedObject & { + /** + * Result type and event name, see the "Possible Event Types" section for more information + */ + description: string; + /** + * Previous values of relevant result attributes + */ + previous_attributes: any; + /** + * The object associated with the Event. See the "object" attribute on the result to determine its specific type. + * This field will not be returned when retrieving events directly from the API + */ + result: any; + /** + * The current status of the event. Possible values are "completed", "failed", "in_queue", "retrying", or "pending" (deprecated) + * + * @deprecated + */ + status: 'completed' | 'failed' | 'in_queue' | 'retrying' | 'pending'; + /** + * Webhook URLs that have not yet been successfully notified as of the time this webhook event was sent. + * The URL receiving the Event will still be listed in pending_urls, as will any other URLs that receive the Event at the same time + */ + pending_urls: string[]; + /** + * Webhook URLs that have already been successfully notified as of the time this webhook was sent + */ + completed_urls: string[]; + }; diff --git a/types/src/services/event_service/EventListParameters.d.ts b/types/src/services/event_service/EventListParameters.d.ts new file mode 100644 index 000000000..9bdf71607 --- /dev/null +++ b/types/src/services/event_service/EventListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-events + */ +export type IEventListParameters = IAllMethodParameters; diff --git a/types/src/services/event_service/Payload/Payload.d.ts b/types/src/services/event_service/Payload/Payload.d.ts new file mode 100644 index 000000000..d52fba6e9 --- /dev/null +++ b/types/src/services/event_service/Payload/Payload.d.ts @@ -0,0 +1,14 @@ +import { IDatedObject, IObjectWithId } from '../../../utils/types'; +/** + * A Payload represents an attempt by EasyPost to send an Event to a Webhook. + * An Event can have multiple Payloads. For instance, if there is a failure to deliver a Webhook, + * an Event would have multiple payloads, one for each attempt to deliver the Event to the Webhook. + * Payload can be useful for debugging webhook delivery and when initially setting up EasyPost webhooks. + */ +export type IPayload = IObjectWithId<'Payload'> & + IDatedObject & { + /** + * The body of the Payload response + */ + response_body: string | null; + }; diff --git a/types/src/services/event_service/Payload/PayloadListParameters.d.ts b/types/src/services/event_service/Payload/PayloadListParameters.d.ts new file mode 100644 index 000000000..1286fdbbc --- /dev/null +++ b/types/src/services/event_service/Payload/PayloadListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads + */ +export type IPayloadListParameters = IAllMethodParameters; diff --git a/types/src/services/event_service/Payload/index.d.ts b/types/src/services/event_service/Payload/index.d.ts new file mode 100644 index 000000000..b1fd98702 --- /dev/null +++ b/types/src/services/event_service/Payload/index.d.ts @@ -0,0 +1 @@ +export * from './Payload'; diff --git a/types/src/services/event_service/index.d.ts b/types/src/services/event_service/index.d.ts new file mode 100644 index 000000000..cf8d41b21 --- /dev/null +++ b/types/src/services/event_service/index.d.ts @@ -0,0 +1,96 @@ +import EasyPost from '../..'; +import { IEvent } from './Event'; +import { IEventListParameters } from './EventListParameters'; +import { IPayload } from './Payload'; +export * from './Event'; +export * from './EventListParameters'; +export * from './Payload'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Retrieve all {@link Payload payloads} for an {@link Event event}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads EasyPost API Documentation} for more information. + * @param id - The ID of the event to retrieve payloads for. + * @returns - A list of {@link Payload payloads} for the event. + */ + retrieveAllPayloads(id: string): Promise>; + /** + * Retrieve a specific {@link Payload payload} for an {@link Event event}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-payload EasyPost API Documentation} for more information. + * @param id - The ID of the event to retrieve the payload for. + * @param payloadId - The ID of the payload to retrieve. + * @returns - The {@link Payload payload} for the event. + */ + retrievePayload( + id: string, + payloadId: string, + ): Promise>; + /** + * Retrieve all {@link Event events} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-events EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the list of events. + * @returns - An object containing the list of {@link Event events} and pagination information. + */ + all(params?: IEventListParameters): Promise< + { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of Event collection. + * @param events An object containing a list of {@link Event events} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + events: any, + pageSize?: number | null, + ): Promise< + { + events: IEvent[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve an {@link Event event} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-event EasyPost API Documentation} for more information. + * @param id - The ID of the event to retrieve. + * @returns - The retrieved event. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/index.d.ts b/types/src/services/index.d.ts new file mode 100644 index 000000000..229b1e3fa --- /dev/null +++ b/types/src/services/index.d.ts @@ -0,0 +1,27 @@ +export * from './address_service'; +export * from './api_key_service'; +export * from './batch_service'; +export * from './beta_rate_service'; +export * from './beta_referral_customer_service'; +export * from './billing_service'; +export * from './carrier_account_service'; +export * from './carrier_metadata_service'; +export * from './carrier_type_service'; +export * from './customs_info_service'; +export * from './customs_item_service'; +export * from './end_shipper_service'; +export * from './event_service'; +export * from './insurance_service'; +export * from './order_service'; +export * from './parcel_service'; +export * from './pickup_service'; +export * from './rate_service'; +export * from './referral_customer_service'; +export * from './refund_service'; +export * from './report_service'; +export * from './scan_form_service'; +export * from './shipment_service'; +export * from './tracker_service'; +export * from './user_service'; +export * from './webhook_service'; +export * from './base_service'; diff --git a/types/src/services/insurance_service/Fee.d.ts b/types/src/services/insurance_service/Fee.d.ts new file mode 100644 index 000000000..2149b267a --- /dev/null +++ b/types/src/services/insurance_service/Fee.d.ts @@ -0,0 +1,31 @@ +import { IBaseObject } from '../../utils/types'; +import { TFeeType } from './FeeType'; +/** + * Fee objects are used to represent the breakdown of charges made when purchasing an item on EasyPost. + * Shipments and Trackers both have associations to Fee objects. + * + * Each Shipment object will have a Fee of type "LabelFee" to represent the label fee charged by EasyPost for the service. + * Shipments with postage collected by EasyPost (as opposed to shipments with postage collected directly by the carrier) will have a "PostageFee" according to the postage amount. + * Insurance on a Shipment will add an "InsuranceFee" with the insurance premium (not the covered value) for the amount. + * Tracker objects will have a "TrackerFee" with the price, even when a Tracker is free. + * + * @see https://www.easypost.com/docs/api/node#fee-object + */ +export type IFee = IBaseObject<'Fee'> & { + /** + * The name of the category of fee. Possible types are "LabelFee", "PostageFee", "InsuranceFee", and "TrackerFee" + */ + type: TFeeType; + /** + * USD value with sub-cent precision + */ + amount: string; + /** + * Whether EasyPost has successfully charged your account for the fee + */ + charged: boolean; + /** + * Whether the Fee has been refunded successfully + */ + refunded: boolean; +}; diff --git a/types/src/services/insurance_service/FeeType.d.ts b/types/src/services/insurance_service/FeeType.d.ts new file mode 100644 index 000000000..980a39a05 --- /dev/null +++ b/types/src/services/insurance_service/FeeType.d.ts @@ -0,0 +1 @@ +export type TFeeType = 'InsuranceFee' | 'LabelFee' | 'PostageFee' | 'TrackerFee'; diff --git a/types/src/services/insurance_service/Insurance.d.ts b/types/src/services/insurance_service/Insurance.d.ts new file mode 100644 index 000000000..af0418285 --- /dev/null +++ b/types/src/services/insurance_service/Insurance.d.ts @@ -0,0 +1,73 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; +import { ITracker } from '../tracker_service'; +import { IFee } from './Fee'; +import { TInsuranceStatus } from './InsuranceStatus'; +/** + * An Insurance object represents insurance for packages purchased both via the EasyPost API as well as shipments purchased through third parties and later registered with EasyPost. + * An Insurance is created automatically whenever you buy a Shipment through EasyPost and pass insurance options during the Buy call or in a later call to Insure a Shipment. + * + * Insurance purchased through the Shipment Buy or Insure endpoints is immediately insured - there is no possibility of rejection based on tracking information, as the package was just created. + * On the other hand, Insurance purchased on shipments purchased outside of EasyPost requires creation with a tracking code so that EasyPost may confirm the package existence and current shipping status at the time of purchase. + * + * Standalone insurance is created in a pending state to help distinguish it from insurance purchased for an EasyPost Shipment. + * Both kinds of Insurance use the Tracking system to receive periodic updates, and will report those updates to any appropriate Webhooks on file. + * Standalone insurance will cancel itself if the tracking information for the given tracking code shows evidence of having been shipped anytime before the insurance was purchased. + * + * Unlike Shipments within EasyPost, Insurance objects register To and From Address objects according to the destination and ship-from locations of the package. + * This means that a Shipment with "is_return: true" actually ships to the listed From Address. + * Insurance does not have a concept of "is_return", so all insurance records refer to their true package destination as "to_address", regardless of whether or not the shipment is a return. + * + * @see https://www.easypost.com/docs/api/node#insurance-object + */ +export type IInsurance = IObjectWithId<'Insurance'> & + IDatedObject & { + /** + * The unique reference for this Insurance, if any + */ + reference?: string | null; + /** + * USD value of insured goods with sub-cent precision + */ + amount: string; + /** + * The insurance provider used by EasyPost + */ + provider: string; + /** + * An identifying number for some insurance providers used by EasyPost + */ + provider_id: string; + /** + * The ID of the Shipment in EasyPost, if postage was purchased via EasyPost + */ + shipment_id: string; + /** + * The tracking code of either the shipment within EasyPost, or provided by you during creation + */ + tracking_code: string; + /** + * The current status of the insurance, possible values are "new", "pending", "purchased", "failed", or "cancelled" + */ + status: TInsuranceStatus; + /** + * The associated Tracker object + */ + tracker: ITracker; + /** + * The associated Address object for destination + */ + to_address: IAddress; + /** + * The associated Address object for origin + */ + from_address: IAddress; + /** + * The associated InsuranceFee object if any + */ + fee: IFee; + /** + * The list of errors encountered during attempted purchase of the insurance + */ + messages: string[]; + }; diff --git a/types/src/services/insurance_service/InsuranceCreateParameters.d.ts b/types/src/services/insurance_service/InsuranceCreateParameters.d.ts new file mode 100644 index 000000000..537dc6ef8 --- /dev/null +++ b/types/src/services/insurance_service/InsuranceCreateParameters.d.ts @@ -0,0 +1,22 @@ +import { IAddress } from '../address_service'; +export type IInsuranceCreateParameters = { + reference?: string | null; + to_address: IAddress | string; + from_address: IAddress | string; + /** + * The carrier associated with the tracking_code you provided. + * The carrier will get auto-detected if none is provided + */ + carrier?: string | null; + /** + * The tracking code associated with the non-EasyPost-purchased package you'd like to insure. + */ + tracking_code: string; + /** + * The USD value of contents you would like to insure. + * Currently the maximum is $5000 + * + * @example 100.00 + */ + amount: string; +}; diff --git a/types/src/services/insurance_service/InsuranceStatus.d.ts b/types/src/services/insurance_service/InsuranceStatus.d.ts new file mode 100644 index 000000000..139db60a2 --- /dev/null +++ b/types/src/services/insurance_service/InsuranceStatus.d.ts @@ -0,0 +1 @@ +export type TInsuranceStatus = 'new' | 'pending' | 'purchased' | 'failed' | 'cancelled'; diff --git a/types/src/services/insurance_service/index.d.ts b/types/src/services/insurance_service/index.d.ts new file mode 100644 index 000000000..bb320ba54 --- /dev/null +++ b/types/src/services/insurance_service/index.d.ts @@ -0,0 +1,89 @@ +import EasyPost from '../..'; +import { IAllMethodParameters } from '../../utils/types'; +import { IInsurance } from './Insurance'; +import { IInsuranceCreateParameters } from './InsuranceCreateParameters'; +export * from './Fee'; +export * from './FeeType'; +export * from './Insurance'; +export * from './InsuranceCreateParameters'; +export * from './InsuranceStatus'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create an {@link Insurance insurance} record. + * See {@link https://www.easypost.com/docs/api/node#create-an-insurance EasyPost API Documentation} for more information. + * @param params - Parameters for the insurance to be created. + * @returns - The created insurance. + */ + create( + params: IInsuranceCreateParameters, + ): Promise>; + /** + * Retrieve all {@link Insurance} records associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-insurances EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the insurance records. + * @returns - An object containing the list of {@link Insurance insurance} records and pagination information. + */ + all(params?: IAllMethodParameters): Promise< + IInsurance[] & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of Insurance collection. + * @param {Object} insurances An object containing a list of {@link Insurance insurances} and pagination information. + * @param {Number} pageSize The number of records to return on each page + * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + insurances: any, + pageSize?: number | null, + ): Promise< + { + insurances: IInsurance[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve an {@link Insurance insurance} record by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-insurance EasyPost API Documentation} for more information. + * @param {string} id - The ID of the insurance to retrieve. + * @returns {Insurance} - The retrieved insurance. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/order_service/Order.d.ts b/types/src/services/order_service/Order.d.ts new file mode 100644 index 000000000..0b9a96406 --- /dev/null +++ b/types/src/services/order_service/Order.d.ts @@ -0,0 +1,53 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; +import { IRate } from '../rate_service'; +import { IMessage, IShipment } from '../shipment_service'; +/** + * The Order object represents a collection of packages and can be used for Multi-Piece Shipments. + * Like a single Shipment each Order consists of a "to" and "from" Address to be used for each Shipment within the Order. + * These Addresses will be copied to each Shipment so there is no need to specify them multiple times. + * Each Shipment must then specify its Parcel, Options, and CustomsInfo. + * + * An Order created with valid Address Objects and Parcel data nested within the Order's Shipment object will automatically retrieve available shipping Rate options. + * + * @see https://www.easypost.com/docs/api/node#order-object + */ +export type IOrder = IObjectWithId<'Order'> & + IDatedObject & { + /** + * An optional field that may be used in place of id in other API endpoints + */ + reference?: string | null; + /** + * The destination address + */ + to_address: IAddress; + /** + * The origin address + */ + from_address: IAddress; + /** + * The shipper's address, defaults to from_address + */ + return_address?: IAddress | null; + /** + * The buyer's address, defaults to to_address + */ + buyer_address?: IAddress | null; + /** + * All associated Shipment objects. Maximum of 100. + */ + shipments: IShipment[]; + /** + * All associated Rate objects + */ + rates: IRate[]; + /** + * Any carrier errors encountered during rating + */ + messages: IMessage[]; + /** + * Set true to create as a return + */ + is_return?: boolean | null; + }; diff --git a/types/src/services/order_service/OrderCreateParameters.d.ts b/types/src/services/order_service/OrderCreateParameters.d.ts new file mode 100644 index 000000000..8368b1d68 --- /dev/null +++ b/types/src/services/order_service/OrderCreateParameters.d.ts @@ -0,0 +1,12 @@ +import { IAddress } from '../address_service'; +import { IShipment } from '../shipment_service'; +export type IOrderCreateParameters = { + reference?: string | null; + to_address: IAddress | string; + from_address: IAddress | string; + shipments: IShipment[]; + /** + * optional array of ids that begin with "ca_" + */ + carrier_accounts?: string[] | null; +}; diff --git a/types/src/services/order_service/index.d.ts b/types/src/services/order_service/index.d.ts new file mode 100644 index 000000000..4d07b7efe --- /dev/null +++ b/types/src/services/order_service/index.d.ts @@ -0,0 +1,79 @@ +import EasyPost from '../..'; +import { IRate } from '../rate_service'; +import { IOrder } from './Order'; +import { IOrderCreateParameters } from './OrderCreateParameters'; +export * from './Order'; +export * from './OrderCreateParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create an {@link Order order}. + * See {@link https://www.easypost.com/docs/api/node#create-an-order EasyPost API Documentation} for more information. + * @param params - The parameters to create an order with. + * @returns - The created order. + */ + create(params: IOrderCreateParameters): Promise>; + /** + * Purchase an {@link Order order}. + * See {@link https://www.easypost.com/docs/api/node#buy-an-order EasyPost API Documentation} for more information. + * @param id - The ID of the order to buy. + * @param carrier - The carrier to use for the order purchase. + * @param service - The service to use for the order purchase. + * @returns - The purchased order. + */ + buy( + id: string, + carrier: string, + service: string, + ): Promise>; + /** + * Get updated rates for an {@link Order order}. + * See {@link https://www.easypost.com/docs/api/node#orders EasyPost API Documentation} for more information. + * @param id - The ID of the order to get rates for. + * @returns - The order with rates. + */ + getRates(id: string): Promise>; + /** + * Retrieve an {@link Order order} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-order EasyPost API Documentation} for more information. + * @param id - The ID of the order to retrieve. + * @returns - The retrieved order. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + > + /** + * Retrieve an {@link Order order} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-an-order EasyPost API Documentation} for more information. + * @param id - The ID of the order to retrieve. + * @returns - The retrieved order. + */; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/parcel_service/Parcel.d.ts b/types/src/services/parcel_service/Parcel.d.ts new file mode 100644 index 000000000..f0c7c6535 --- /dev/null +++ b/types/src/services/parcel_service/Parcel.d.ts @@ -0,0 +1,38 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * Parcel objects represent the physical container being shipped. + * Dimensions can be supplied either as length, width, and height dimensions, or a predefined_package string. + * Only weight is required, but since many carriers charge different rates for packages with large dimensions, we strongly recommend including all dimensions if available. + * + * Weights are in OUNCES (OZ) and go to one decimal point. + * Dimensions are in INCHES (IN) and go to one decimal point. + * + * @see https://www.easypost.com/docs/api/node#parcel-object + */ +export type IParcel = IObjectWithId<'Parcel'> & + IDatedObject & { + /** + * Required if width and/or height are present + * float (inches) + */ + length?: number | null; + /** + * Required if width and/or height are present + * float (inches) + */ + width?: number | null; + /** + * Required if width and/or height are present + * float (inches) + */ + height?: number | null; + /** + * Always required + * float (oz) + */ + weight: number; + /** + * Optional, one of our predefined_packages + */ + predefined_package?: string | null; + }; diff --git a/types/src/services/parcel_service/ParcelCreateParameters.d.ts b/types/src/services/parcel_service/ParcelCreateParameters.d.ts new file mode 100644 index 000000000..35f07b297 --- /dev/null +++ b/types/src/services/parcel_service/ParcelCreateParameters.d.ts @@ -0,0 +1,24 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IParcel } from './Parcel'; +export type IParcelCreateParameters = Omit & { + /** + * Required if width and/or height are present + * float (inches) + */ + length?: number | null; + /** + * Required if width and/or height are present + * float (inches) + */ + width?: number | null; + /** + * Required if width and/or height are present + * float (inches) + */ + height?: number | null; + /** + * Always required + * float (oz) + */ + weight: number; +}; diff --git a/types/src/services/parcel_service/index.d.ts b/types/src/services/parcel_service/index.d.ts new file mode 100644 index 000000000..cd23ad71e --- /dev/null +++ b/types/src/services/parcel_service/index.d.ts @@ -0,0 +1,54 @@ +import EasyPost from '../..'; +import { IParcel } from './Parcel'; +import { IParcelCreateParameters } from './ParcelCreateParameters'; +export * from './Parcel'; +export * from './ParcelCreateParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Parcel parcel}. + * See {@link https://www.easypost.com/docs/api/node#create-a-parcel EasyPost API Documentation} for more information. + * @param params - The parameters to create a parcel with. + * @returns - The created parcel. + */ + create( + params: IParcelCreateParameters, + ): Promise>; + /** + * Retrieve a {@link Parcel parcel} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-parcel EasyPost API Documentation} for more information. + * @param id - The ID of the parcel to retrieve. + * @returns - The retrieved parcel. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/pickup_service/Pickup.d.ts b/types/src/services/pickup_service/Pickup.d.ts new file mode 100644 index 000000000..ae6a57f4f --- /dev/null +++ b/types/src/services/pickup_service/Pickup.d.ts @@ -0,0 +1,77 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; +import { ICarrierAccount } from '../carrier_account_service'; +import { IMessage, IShipment } from '../shipment_service'; +import { IPickupRate } from './PickupRate'; +/** + * The Pickup object allows you to schedule a pickup from your carrier from your customer's residence or place of business. + * Supported carriers include: + * - Canada Post + * - Canpar + * - DHL Express + * - FedEx + * - Lasership + * - Loomis Express + * - LSO + * - Ontrac + * - UPS + * - USPS + * - Veho + * + * After a Pickup is successfully created, it will automatically fetch PickupRates for each CarrierAccount specified that supports scheduled pickups. + * Then a PickupRate must be selected and purchased before the pickup can be successfully scheduled. + * + * @see https://www.easypost.com/docs/api/node#pickup-object + */ +export type IPickup = IObjectWithId<'Pickup'> & + IDatedObject & { + /** + * An optional field that may be used in place of ID in some API endpoints + */ + reference?: string | null; + /** + * One of: "unknown", "scheduled", or "canceled" + */ + status: 'unknown' | 'scheduled' | 'canceled'; + /** + * The earliest time at which the package is available to pick up + */ + min_datetime: string; + /** + * The latest time at which the package is available to pick up. + * Must be later than the min_datetime + */ + max_datetime: string; + /** + * Is the pickup address the account's address? + */ + is_account_address?: boolean | null; + /** + * Additional text to help the driver successfully obtain the package + */ + instructions?: string | null; + /** + * A list of messages containing carrier errors encountered during pickup rate generation + */ + messages: IMessage[]; + /** + * The confirmation number for a booked pickup from the carrier + */ + confirmation: string; + /** + * The associated Shipment + */ + shipment: IShipment; + /** + * The associated Address + */ + address: IAddress; + /** + * The list of carriers (if empty, all carriers were used) used to generate pickup rates + */ + carrier_accounts?: ICarrierAccount[] | null; + /** + * The list of different pickup rates across valid carrier accounts for the shipment + */ + pickup_rates: IPickupRate[]; + }; diff --git a/types/src/services/pickup_service/PickupCreateParameters.d.ts b/types/src/services/pickup_service/PickupCreateParameters.d.ts new file mode 100644 index 000000000..d4c180dcc --- /dev/null +++ b/types/src/services/pickup_service/PickupCreateParameters.d.ts @@ -0,0 +1,37 @@ +import { IAddress } from '../address_service'; +import { IBatch } from '../batch_service'; +import { ICarrierAccount } from '../carrier_account_service'; +import { IShipment } from '../shipment_service'; +import { IPickupRate } from './PickupRate'; +type BasePickupCreateParameters = { + address: IAddress | string; + carrier_accounts?: ICarrierAccount[] | null; + confirmation?: string | null; + instructions?: string | null; + is_account_address?: boolean | null; + max_datetime: string; + min_datetime: string; + pickup_rates: IPickupRate; + reference?: string | null; + status: string; +}; +type ShipmentPickupCreateParameters = BasePickupCreateParameters & { + shipment?: + | IShipment + | { + id: string; + } + | string + | null; +}; +type BatchPickupCreateParameters = BasePickupCreateParameters & { + batch?: + | IBatch + | { + id: string; + } + | string + | null; +}; +export type IPickupCreateParameters = ShipmentPickupCreateParameters | BatchPickupCreateParameters; +export {}; diff --git a/types/src/services/pickup_service/PickupListParameters.d.ts b/types/src/services/pickup_service/PickupListParameters.d.ts new file mode 100644 index 000000000..806edf7f0 --- /dev/null +++ b/types/src/services/pickup_service/PickupListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups + */ +export type IPickupListParameters = IAllMethodParameters; diff --git a/types/src/services/pickup_service/PickupRate.d.ts b/types/src/services/pickup_service/PickupRate.d.ts new file mode 100644 index 000000000..53983d86e --- /dev/null +++ b/types/src/services/pickup_service/PickupRate.d.ts @@ -0,0 +1,27 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#pickup-rate-object + */ +export type IPickupRate = IObjectWithId<'PickupRate'> & + IDatedObject & { + /** + * service name + */ + service: string; + /** + * name of carrier + */ + carrier: string; + /** + * the actual rate quote for this service + */ + rate: string; + /** + * currency for the rate + */ + currency: string; + /** + * the ID of the pickup this is a quote for + */ + pickup_id: string; + }; diff --git a/types/src/services/pickup_service/index.d.ts b/types/src/services/pickup_service/index.d.ts new file mode 100644 index 000000000..bbab7e5c2 --- /dev/null +++ b/types/src/services/pickup_service/index.d.ts @@ -0,0 +1,110 @@ +import EasyPost from '../..'; +import { IPickup } from './Pickup'; +import { IPickupCreateParameters } from './PickupCreateParameters'; +import { IPickupListParameters } from './PickupListParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Pickup pickup}. + * See {@link https://www.easypost.com/docs/api/node#create-a-pickup EasyPost API Documentation} for more information. + * @param params - The parameters to create a pickup with. + * @returns - The created pickup. + */ + create( + params: IPickupCreateParameters, + ): Promise>; + /** + * Purchase a {@link Pickup pickup}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-pickup EasyPost API Documentation} for more information. + * @param id - The ID of the pickup to purchase. + * @param carrier - The carrier to purchase the pickup with. + * @param service - The service to purchase the pickup with. + * @returns - The purchased pickup. + */ + buy( + id: string, + carrier: string, + service: string, + ): Promise>; + /** + * Cancel a {@link Pickup pickup}. + * See {@link https://www.easypost.com/docs/api/node#cancel-a-pickup EasyPost API Documentation} for more information. + * @param id - The ID of the pickup to cancel. + * @returns - The cancelled pickup. + */ + cancel(id: string): Promise>; + /** + * Retrieve all {@link Pickup pickups} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the pickups by. + * @returns - An object containing a list of {@link Pickup pickups} and pagination information. + */ + all(params?: IPickupListParameters): Promise< + IPickup[] & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of Pickup collection. + * @param pickups An object containing a list of {@link Pickup pickups} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + pickups: any, + pageSize?: number | null, + ): Promise< + { + pickups: IPickup[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link Pickup pickup} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-pickup EasyPost API Documentation} for more information. + * @param id - The ID of the pickup to retrieve. + * @returns - The retrieved pickup. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise> + /** + * Retrieve the next page of Pickup collection. + * @param pickups An object containing a list of {@link Pickup pickups} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/rate_service/Rate.d.ts b/types/src/services/rate_service/Rate.d.ts new file mode 100644 index 000000000..d53e172de --- /dev/null +++ b/types/src/services/rate_service/Rate.d.ts @@ -0,0 +1,81 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * The Rate class represents a summary of the price and details of a delivery service quote. + * + * @see https://www.easypost.com/docs/api/node#rates + */ +export type IRate = IObjectWithId<'Rate'> & + IDatedObject & { + /** + * The service level of the rate. + */ + service: string; + /** + * The carrier of the rate. + */ + carrier: string; + /** + * The ID of the carrier account associated with this rate. + */ + carrier_account_id: string; + /** + * The ID of the shipment associated with this rate. + */ + shipment_id: string; + /** + * The quote price of the rate. + */ + rate: string; + /** + * The currency of the rate. + */ + currency: string; + /** + * The in-store retail rate given with no account. + */ + retail_rate: string; + /** + * The currency of the retail rate. + */ + retail_currency: string; + /** + * The non-negotiated rate given for having an account with the carrier. + */ + list_rate: string; + /** + * The currency of the list rate. + */ + list_currency: string; + /** + * The number of days in transit for this rate. + */ + delivery_days: number; + /** + * The delivery date for this rate. + */ + delivery_date: string; + /** + * Whether the delivery window is guaranteed. + */ + delivery_date_guaranteed: boolean; + /** + * The earliest delivery date for this rate. + * This is deprecated and should be ignored. + */ + est_delivery_days: number; + /** + * The billing type of the rate. + */ + billing_type: string; + }; +export type ISmartRate = IRate & { + time_in_transit: { + percentile_50: number; + percentile_75: number; + percentile_85: number; + percentile_90: number; + percentile_95: number; + percentile_97: number; + percentile_99: number; + }; +}; diff --git a/types/src/services/rate_service/index.d.ts b/types/src/services/rate_service/index.d.ts new file mode 100644 index 000000000..b51193687 --- /dev/null +++ b/types/src/services/rate_service/index.d.ts @@ -0,0 +1,43 @@ +import EasyPost from '../..'; +import { IRate } from './Rate'; +export * from './Rate'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Retrieve a {@link Rate rate} by its ID. + * See {@link https://www.easypost.com/docs/api/node#rates EasyPost API Documentation} for more information. + * @param {string} id - The ID of the rate to retrieve. + * @returns {Rate} - The retrieved rate. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/referral_customer_service/Referral.d.ts b/types/src/services/referral_customer_service/Referral.d.ts new file mode 100644 index 000000000..b83dfa0a6 --- /dev/null +++ b/types/src/services/referral_customer_service/Referral.d.ts @@ -0,0 +1,7 @@ +import { IUser } from '../user_service'; +/** + * A Referral represents a sub-user under a Partner or white-label account. + * + * @see https://www.easypost.com/docs/api/node#referral-customers + */ +export declare interface IReferral extends IUser {} diff --git a/types/src/services/referral_customer_service/ReferralCreateParameters.d.ts b/types/src/services/referral_customer_service/ReferralCreateParameters.d.ts new file mode 100644 index 000000000..7035f552d --- /dev/null +++ b/types/src/services/referral_customer_service/ReferralCreateParameters.d.ts @@ -0,0 +1,3 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IReferral } from './Referral'; +export type IReferralCreateParameters = Omit; diff --git a/types/src/services/referral_customer_service/ReferralListParameters.d.ts b/types/src/services/referral_customer_service/ReferralListParameters.d.ts new file mode 100644 index 000000000..f26fe30bd --- /dev/null +++ b/types/src/services/referral_customer_service/ReferralListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers + */ +export type IReferralListParameters = IAllMethodParameters; diff --git a/types/src/services/referral_customer_service/index.d.ts b/types/src/services/referral_customer_service/index.d.ts new file mode 100644 index 000000000..2f4520f4e --- /dev/null +++ b/types/src/services/referral_customer_service/index.d.ts @@ -0,0 +1,108 @@ +import EasyPost from '../..'; +import { IReferralCreateParameters } from './ReferralCreateParameters'; +import { IReferral } from './Referral'; +import { IReferralListParameters } from './ReferralListParameters'; +import { IPaymentMethod } from '../billing_service'; +export * from './Referral'; +export * from './ReferralCreateParameters'; +export * from './ReferralListParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link User referral customer}. + * See {@link https://www.easypost.com/docs/api/node#create-a-referral-customer EasyPost API Documentation} for more information. + * @param params - The referral customer's information. + * @returns - The newly created referral customer. + */ + create( + params: IReferralCreateParameters, + ): Promise>; + /** + * Update a {@link User referral customer's} email address. + * See {@link https://www.easypost.com/docs/api/node#update-a-referral-customer EasyPost API Documentation} for more information. + * @param referralUserId - The ID of the referral customer to update. + * @param email - The new email address. + * @returns - Returns true if the referral was updated successfully, false otherwise. + */ + updateEmail(referralUserId: string, email: string): Promise; + /** + * Add a credit card to a {@link User referral customer's} account. + * See {@link https://www.easypost.com/docs/api/node#create-credit-card EasyPost API Documentation} for more information. + * @param referralApiKey - The referral customer's production API key. + * @param number - The credit card number. + * @param expirationMonth - The credit card expiration month. + * @param expirationYear - The credit card expiration year. + * @param cvc - The credit card CVC. + * @param priority - Whether to add the card as 'primary' or 'secondary' payment method (defaults to 'primary'). + * @returns - An object representing the newly-added credit card. + */ + addCreditCard( + referralApiKey: string, + number: string, + expirationMonth: string, + expirationYear: string, + cvc: string, + priority?: 'primary' | 'secondary', + ): Promise; + /** + * Retrieve all {@link User referral customers} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the referral customers by. + * @returns - An object containing a list of {@link User referral customers} and pagination information. + */ + all(params?: IReferralListParameters): Promise< + IReferral[] & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of Referral Customer collection. + * @param referralCustomers An object containing a list of {@link referral referralCustomers} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + referralCustomers: any, + pageSize?: number | null, + ): Promise< + { + referral_customers: IReferral[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/refund_service/Refund.d.ts b/types/src/services/refund_service/Refund.d.ts new file mode 100644 index 000000000..1765f8ccb --- /dev/null +++ b/types/src/services/refund_service/Refund.d.ts @@ -0,0 +1,31 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * The Refund object represents a refunded shipment, and includes details about the related Shipment and tracking code. + * USPS shipping labels can be refunded if requested within 30 days of generation. + * The processing time is at least 15 days, after which the funds will return to your EasyPost balance. + * EasyPost fees will also be refunded. To qualify, a shipment must not have been scanned by the USPS. + * UPS and FedEx shipping labels may be refunded within 90 days of creation. + */ +export type IRefund = IObjectWithId<'Refund'> & + IDatedObject & { + /** + * The tracking code of the related Shipment + */ + tracking_code: string; + /** + * The confirmation number for the refund request to the carrier + */ + confirmation_number: string; + /** + * The status of the refund request, reported by the carrier. Possible values are "submitted", "refunded", or "rejected" + */ + status: 'submitted' | 'refunded' | 'rejected'; + /** + * The carrier the refund request was submitted to + */ + carrier: string; + /** + * The ID of the related Shipment being refunded + */ + shipment_id: string; + }; diff --git a/types/src/services/refund_service/RefundCreateParameters.d.ts b/types/src/services/refund_service/RefundCreateParameters.d.ts new file mode 100644 index 000000000..56419c78e --- /dev/null +++ b/types/src/services/refund_service/RefundCreateParameters.d.ts @@ -0,0 +1,13 @@ +/** + * @see https://www.easypost.com/docs/api/node#create-a-refund + */ +export type IRefundCreateParameters = { + /** + * The carrier to request a refund from + */ + carrier: string; + /** + * A list of tracking codes to request refunds for. Even for a single tracking code, it needs to be submitted as a list. + */ + tracking_codes: string[]; +}; diff --git a/types/src/services/refund_service/RefundListParameters.d.ts b/types/src/services/refund_service/RefundListParameters.d.ts new file mode 100644 index 000000000..5239e02d8 --- /dev/null +++ b/types/src/services/refund_service/RefundListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds + */ +export type IRefundListParameters = IAllMethodParameters; diff --git a/types/src/services/refund_service/index.d.ts b/types/src/services/refund_service/index.d.ts new file mode 100644 index 000000000..d476fbfd5 --- /dev/null +++ b/types/src/services/refund_service/index.d.ts @@ -0,0 +1,89 @@ +import EasyPost from '../..'; +import { IRefund } from './Refund'; +import { IRefundCreateParameters } from './RefundCreateParameters'; +import { IRefundListParameters } from './RefundListParameters'; +export * from './Refund'; +export * from './RefundCreateParameters'; +export * from './RefundListParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Refund refund}. + * See {@link https://www.easypost.com/docs/api/node#create-a-refund EasyPost API Documentation} for more information. + * @param params - The parameters to create a refund with. + * @returns - The created refund. + */ + create( + params: IRefundCreateParameters, + ): Promise>; + /** + * Retrieve all {@link Refund refunds} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the refunds by. + * @returns - An object containing the list of {@link Refund refunds} and pagination information. + */ + all(params?: IRefundListParameters): Promise< + { + refunds: IRefund[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of Refund collection. + * @param refunds An object containing a list of {@link Refund refunds} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + refunds: any, + pageSize?: number | null, + ): Promise< + { + refunds: IRefund[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link Refund refund} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-refund EasyPost API Documentation} for more information. + * @param id - The ID of the refund to retrieve. + * @returns - The retrieved refund. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/report_service/Report.d.ts b/types/src/services/report_service/Report.d.ts new file mode 100644 index 000000000..bc01c19c3 --- /dev/null +++ b/types/src/services/report_service/Report.d.ts @@ -0,0 +1,52 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { TReportObjectType } from './ReportObjectType'; +/** + * A Report contains a csv that is a log of all the objects created within a certain time frame. + * + * Reports can be generated using the Reports Endpoint. + * You can create and view Reports created between any time frame defined between the start_date and end_date. + * + * The Report api can be categorized into several types. + * These types determine which EasyPost Object to produce a Report for, and should be passed as the type in our libraries: + * - cash_flow + * - insurance + * - payment_log + * - refund + * - shipment + * - shipment_invoice + * - tracker + * + * @see https://www.easypost.com/docs/api/node#report-object + */ +export type IReport = IObjectWithId & + IDatedObject & { + /** + * "new", "available", "failed", or null + */ + status: 'new' | 'available' | 'failed' | null; + /** + * A date string in YYYY-MM-DD form eg: "2016-02-02" + */ + start_date: string; + /** + * A date string in YYYY-MM-DD form eg: "2016-02-03" + */ + end_date: string; + /** + * Set true if you would like to include Refunds /Shipments /Trackers created by child users + */ + include_children?: boolean | null; + /** + * A url that contains a link to the Report. + * Expires 30 seconds after retrieving this object + */ + url: string; + /** + * Url expiring time + */ + url_expires_at: string; + /** + * Set true if you would like to send an email containing the Report + */ + send_email?: boolean | null; + }; diff --git a/types/src/services/report_service/ReportCreateParameters.d.ts b/types/src/services/report_service/ReportCreateParameters.d.ts new file mode 100644 index 000000000..909b9d4df --- /dev/null +++ b/types/src/services/report_service/ReportCreateParameters.d.ts @@ -0,0 +1,10 @@ +import { TReportType } from './ReportObjectType'; +export type IReportCreateParameters = { + type: TReportType; + start_date: string | null; + end_date?: string | null; + include_children?: boolean | null; + send_email?: boolean | null; + columns?: string[] | null; + additional_columns?: string[] | null; +}; diff --git a/types/src/services/report_service/ReportListParameters.d.ts b/types/src/services/report_service/ReportListParameters.d.ts new file mode 100644 index 000000000..2c8e5efe7 --- /dev/null +++ b/types/src/services/report_service/ReportListParameters.d.ts @@ -0,0 +1,8 @@ +import { IAllMethodParameters } from '../../utils/types'; +import { TReportType } from './ReportObjectType'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds + */ +export type IReportListParameters = IAllMethodParameters & { + type: TReportType; +}; diff --git a/types/src/services/report_service/ReportObjectType.d.ts b/types/src/services/report_service/ReportObjectType.d.ts new file mode 100644 index 000000000..918f61516 --- /dev/null +++ b/types/src/services/report_service/ReportObjectType.d.ts @@ -0,0 +1,14 @@ +export type TReportObjectType = + | 'CashFlowReport' + | 'PaymentLogReport' + | 'RefundReport' + | 'ShipmentReport' + | 'ShipmentInvoiceReport' + | 'TrackerReport'; +export type TReportType = + | 'cash_flow' + | 'payment_log' + | 'refund' + | 'shipment' + | 'shipment_invoice' + | 'tracker'; diff --git a/types/src/services/report_service/index.d.ts b/types/src/services/report_service/index.d.ts new file mode 100644 index 000000000..998522b84 --- /dev/null +++ b/types/src/services/report_service/index.d.ts @@ -0,0 +1,82 @@ +import EasyPost from '../..'; +import { IReport } from './Report'; +import { IReportCreateParameters } from './ReportCreateParameters'; +import { IReportListParameters } from './ReportListParameters'; +export * from './Report'; +export * from './ReportCreateParameters'; +export * from './ReportListParameters'; +export * from './ReportObjectType'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Report report}. + * See {@link https://www.easypost.com/docs/api/node#create-a-report EasyPost API Documentation} for more information. + * @param params - The parameters to create a report with. + * @returns - The created report. + */ + create( + params: IReportCreateParameters, + ): Promise>; + /** + * Retrieve all {@link Report reports} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-reports EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the reports by. + * @returns - An object containing the list of {@link Report reports} and pagination information. + */ + all(params: IReportListParameters): Promise; + /** + * Retrieve the next page of Report collection. + * @param reports An object containing a list of {@link Report reports} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + reports: any, + pageSize?: number | null, + ): Promise< + { + reports: IReport[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link Report report} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-report EasyPost API Documentation} for more information. + * @param id - The ID of the report to retrieve. + * @returns - The retrieved report. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/scan_form_service/ScanForm.d.ts b/types/src/services/scan_form_service/ScanForm.d.ts new file mode 100644 index 000000000..9cba95498 --- /dev/null +++ b/types/src/services/scan_form_service/ScanForm.d.ts @@ -0,0 +1,47 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; +/** + * A ScanForm can be created to speed up and simplify the carrier pickup process. + * The ScanForm is one document that can be scanned to mark all included tracking codes as "Accepted for Shipment" by the carrier. + * The following criteria must met before creation: + * - Refunded Shipments cannot be added + * - Each Shipment must have the same origin address + * - Shipments must all be dated (using the label_date option) on or after the date the form is generated + * - Shipments cannot be added to more than one ScanForm + * - Existing ScanForms may not be updated with additional Shipments. If a ScanForm already exists, and new Shipments need to be added, a new ScanForm must be created. + * - Shipments should be provided in the form of an array + * + * @see https://www.easypost.com/docs/api/node#scan-form-object + */ +export type IScanForm = IObjectWithId<'ScanForm'> & + IDatedObject & { + /** + * Current status. + * Possible values are "creating", "created" and "failed" + */ + status: 'creating' | 'created' | 'failed'; + /** + * Human-readable message explaining any failures + */ + message: string; + /** + * Address that the Shipments will be shipped from + */ + address: IAddress; + /** + * Tracking codes included on the ScanForm + */ + tracking_codes: string[]; + /** + * Url of the document + */ + form_url: string; + /** + * File format of the document + */ + form_file_type: string; + /** + * The id of the associated Batch. Unique, starts with "batch_" + */ + batch_id: string; + }; diff --git a/types/src/services/scan_form_service/ScanFormCreateParameters.d.ts b/types/src/services/scan_form_service/ScanFormCreateParameters.d.ts new file mode 100644 index 000000000..9642f1e8d --- /dev/null +++ b/types/src/services/scan_form_service/ScanFormCreateParameters.d.ts @@ -0,0 +1,9 @@ +import { DeepPartial } from '../../utils/types'; +import { IShipmentCreateParameters } from '../shipment_service'; +export type IScanFormCreateParameters = { + shipments: + | (DeepPartial & { + id: string; + })[] + | string[]; +}; diff --git a/types/src/services/scan_form_service/ScanFormListParameters.d.ts b/types/src/services/scan_form_service/ScanFormListParameters.d.ts new file mode 100644 index 000000000..655a0094c --- /dev/null +++ b/types/src/services/scan_form_service/ScanFormListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-scan-forms + */ +export type IScanFormListParameters = IAllMethodParameters; diff --git a/types/src/services/scan_form_service/index.d.ts b/types/src/services/scan_form_service/index.d.ts new file mode 100644 index 000000000..59563b781 --- /dev/null +++ b/types/src/services/scan_form_service/index.d.ts @@ -0,0 +1,91 @@ +import EasyPost from '../..'; +import { IScanForm } from './ScanForm'; +import { IScanFormCreateParameters } from './ScanFormCreateParameters'; +import { IScanFormListParameters } from './ScanFormListParameters'; +export * from './ScanForm'; +export * from './ScanFormCreateParameters'; +export * from './ScanFormListParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link ScanForm scan form}. + * See {@link https://www.easypost.com/docs/api/node#create-a-scanform EasyPost API Documentation} for more information. + * @param params - The parameters to create a scan form with. + * @returns - The created scan form. + */ + create( + params: IScanFormCreateParameters, + ): Promise>; + /** + * Retrieve all {@link ScanForm scan forms} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-scanforms EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the scan forms by. + * @returns - An object containing the list of {@link ScanForm scan forms} and pagination information. + */ + all(params?: IScanFormListParameters): Promise< + { + scan_forms: IScanForm[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of ScanForm collection. + * @param scanForms An object containing a list of {@link ScanForm scanForms} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + scanForms: { + scan_forms: any[]; + }, + pageSize?: number | null, + ): Promise< + { + scan_forms: IScanForm[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link ScanForm scan form} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-scanform EasyPost API Documentation} for more information. + * @param id - The ID of the scan form to retrieve. + * @returns - The retrieved scan form. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/shipment_service/Form.d.ts b/types/src/services/shipment_service/Form.d.ts new file mode 100644 index 000000000..c7430545a --- /dev/null +++ b/types/src/services/shipment_service/Form.d.ts @@ -0,0 +1,28 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#form-object + */ +export type IForm = IObjectWithId<'Form'> & + IDatedObject & { + /** + * The type of form that we returned, can be one of "cn22", "cod_return_label", "commercial_invoice", "high_value_report", "label_qr_code", "nafta_certificate_of_origin", "order_summary", "return_packing_slip", "rma_qr_code" + */ + form_type: + | 'cn22' + | 'cod_return_label' + | 'commercial_invoice' + | 'high_value_report' + | 'label_qr_code' + | 'nafta_certificate_of_origin' + | 'order_summary' + | 'return_packing_slip' + | 'rma_qr_code'; + /** + * The address we return the form back at + */ + form_url: string; + /** + * If we have submitted the form to the carrier on behalf of the customer + */ + submitted_electronically: boolean; + }; diff --git a/types/src/services/shipment_service/Message.d.ts b/types/src/services/shipment_service/Message.d.ts new file mode 100644 index 000000000..ff845b655 --- /dev/null +++ b/types/src/services/shipment_service/Message.d.ts @@ -0,0 +1,27 @@ +/** + * When rating a Shipment or Pickup, some carriers may fail to generate rates. + * These failures are returned as part of the Shipment or Pickup as part of their messages attribute, and follow a common object structure. + * + * It is important to note that the message value for any member of this list comes directly from the carrier, not from EasyPost. + * This means that if you see an authentication or other non-shipping error here, it is not an issue between you and EasyPost, it is an issue between you and the carrier, or an issue with the given data. + * + * @see https://www.easypost.com/docs/api/node#message-object + */ +export type IMessage = { + /** + * the name of the carrier generating the error, e.g. "UPS" + */ + carrier: string; + /** + * the category of error that occurred. Most frequently "rate_error" + */ + type: string; + /** + * the string from the carrier explaining the problem + */ + message: string; + /** + * the account id of the carrier. Useful if you have multiple accounts with the same carrier + */ + carrier_account_id: string; +}; diff --git a/types/src/services/shipment_service/Options/LabelFormat.d.ts b/types/src/services/shipment_service/Options/LabelFormat.d.ts new file mode 100644 index 000000000..cc3a84031 --- /dev/null +++ b/types/src/services/shipment_service/Options/LabelFormat.d.ts @@ -0,0 +1 @@ +export declare type LabelFormat = 'PNG' | 'PDF' | 'ZPL' | 'EPL2'; diff --git a/types/src/services/shipment_service/Options/Options.d.ts b/types/src/services/shipment_service/Options/Options.d.ts new file mode 100644 index 000000000..52b3a842f --- /dev/null +++ b/types/src/services/shipment_service/Options/Options.d.ts @@ -0,0 +1,325 @@ +import { LabelFormat } from './LabelFormat'; +import { TPrintCustomCode } from './PrintCustomCode'; +/** + * Shipments can have a variety of additional options which you can specify when creating a shipment. + * The Options object can be populated with the keys below. + * + * @see https://www.easypost.com/docs/api/node#options-object + */ +export type IOptions = { + /** + * Setting this option to true, will add an additional handling charge. + * An Additional Handling charge may be applied to the following: + * - Any article that is encased in an outside shipping container made of metal or wood. + * - Any item, such as a barrel, drum, pail or tire, that is not fully encased in a corrugated cardboard shipping container. + * - Any package with the longest side exceeding 60 inches or its second longest side exceeding 30 inches. + * - Any package with an actual weight greater than 70 pounds. + */ + additional_handling?: boolean | null; + /** + * Setting this option to "0", will allow the minimum amount of address information to pass the validation check. + * Only for USPS postage. + */ + address_validation_level?: string | null; + /** + * Set this option to true if your shipment contains alcohol. + * - UPS - only supported for US Domestic shipments + * - FedEx - only supported for US Domestic shipments + * - Canada Post - Requires adult signature 19 years or older. If you want adult signature 18 years or older, instead use delivery_confirmation: ADULT_SIGNATURE + */ + alcohol?: boolean | null; + /** + * Setting this option to true will indicate to the carrier to prefer delivery by drone, if the carrier supports drone delivery. + */ + by_drone?: boolean | null; + /** + * Setting this to true will add a charge to reduce carbon emissions. + */ + carbon_neutral?: boolean | null; + /** + * Adding an amount will have the carrier collect the specified amount from the recipient. + */ + cod_amount?: string | null; + /** + * Method for payment. "CASH", "CHECK", "MONEY_ORDER" + */ + cod_method?: 'CASH' | 'CHECK' | 'MONEY_ORDER' | null; + /** + * The ID of the Address to which the COD payment should be returned. + * Defaults to the origin address. + * Only available on FedEx shipments. + */ + cod_address_id?: string | null; + /** + * A description of the content of the shipment. + */ + content_description?: string | null; + /** + * Which currency this shipment will show for rates if carrier allows. + */ + currency?: string | null; + /** + * If you want to request a signature, you can pass "ADULT_SIGNATURE" or "SIGNATURE". + * You may also request "NO_SIGNATURE" to leave the package at the door. + * - All - some options may be limited for international shipments + * - FedEx - "INDIRECT_SIGNATURE" is also an option + * - USPS - additional options + * - "ADULT_SIGNATURE_RESTRICTED" + * - "SIGNATURE_RESTRICTED" + * - Canada Post - "DO_NOT_SAFE_DROP" - Tells the carrier to not hide the package ("safe drop"). + * - GSO - "STANDARD_SIGNATURE". + * - DHL Express - option mapping + * - "SIGNATURE" - DHL Express Direct Signature + * - "NO_SIGNATURE" - DHL Express Signature Release + */ + delivery_confirmation?: + | 'ADULT_SIGNATURE' + | 'SIGNATURE' + | 'NO_SIGNATURE' + | 'INDIRECT_SIGNATURE' + | 'ADULT_SIGNATURE_RESTRICTED' + | 'SIGNATURE_RESTRICTED' + | null; + /** + * Method the customer will use to transfer the package to the carrier. + * "REGULAR_PICKUP", "SCHEDULED_PICKUP", "RETAIL_LOCATION", "STATION" or "DROP_BOX". + * Supported carriers and their corresponding carrier dropoff codes: + * - FedEx + * - "REGULAR_PICKUP" - "REGULAR_PICKUP" (default) + * - "SCHEDULED_PICKUP" - "REQUEST_COURIER" + * - "RETAIL_LOCATION" - "BUSINESS_SERVICE_CENTER" + * - "STATION" - "STATION" + * - "DROP_BOX" - "DROP_BOX" + */ + dropoff_type?: + | 'REGULAR_PICKUP' + | 'SCHEDULED_PICKUP' + | 'RETAIL_LOCATION' + | 'STATION' + | 'DROP_BOX' + | 'REQUEST_COURIER' + | 'BUSINESS_SERVICE_CENTER' + | null; + /** + * Package contents contain dry ice. + * - UPS - Need dry_ice_weight to be set + * - UPS MailInnovations - Need dry_ice_weight to be set + * - FedEx - Need dry_ice_weight to be set + */ + dry_ice?: boolean | null; + /** + * If the dry ice is for medical use, set this option to true. + * - UPS - Need dry_ice_weight to be set + * - UPS MailInnovations - Need dry_ice_weight to be set + */ + dry_ice_medical?: boolean | null; + /** + * Weight of the dry ice in ounces. + * - UPS - Need dry_ice to be set + * - UPS MailInnovations - Need dry_ice to be set + * - FedEx - Need dry_ice to be set + */ + dry_ice_weight?: string | null; + /** + * Setting duty_payment type to bill the correct account for purchasing postage. + * This option is only available with FedEx and UPS. + * - type - (string) Supported values are "THIRD_PARTY", and "RECEIVER". + * - account - (string) Setting account number. + * - country - (string) Setting country code that the account is based in. + * - postal_code - (string) Setting postal code that the account is based in. + */ + duty_payment?: object | null; + /** + * Possible values "ADDRESS_SERVICE_REQUESTED", "FORWARDING_SERVICE_REQUESTED", "CHANGE_SERVICE_REQUESTED", "RETURN_SERVICE_REQUESTED", "LEAVE_IF_NO_RESPONSE" + */ + endorsement?: + | 'ADDRESS_SERVICE_REQUESTED' + | 'FORWARDING_SERVICE_REQUESTED' + | 'CHANGE_SERVICE_REQUESTED' + | 'RETURN_SERVICE_REQUESTED' + | 'LEAVE_IF_NO_RESPONSE' + | null; + /** + * Specify the responsible EndShipper for the shipment by passing in an EndShipper ID. + */ + end_shipper_id?: string | null; + /** + * Additional cost to be added to the invoice of this shipment. + * Only applies to UPS currently. + */ + freight_charge?: number | null; + /** + * This is to designate special instructions for the carrier like "Do not drop!". + */ + handling_instructions?: string | null; + /** + * Dangerous goods indicator. + * Possible values are "PRIMARY_CONTAINED", "PRIMARY_PACKED", "PRIMARY", "SECONDARY_CONTAINED", "SECONDARY_PACKED", "SECONDARY", "ORMD", "LIMITED_QUANTITY", "LITHIUM". + * Applies to USPS, FedEx and DHL eCommerce. + */ + hazmat?: + | 'PRIMARY_CONTAINED' + | 'PRIMARY_PACKED' + | 'PRIMARY' + | 'SECONDARY_CONTAINED' + | 'SECONDARY_PACKED' + | 'SECONDARY' + | 'ORMD' + | 'LIMITED_QUANTITY' + | 'LITHIUM' + | null; + /** + * Package will wait at carrier facility for pickup. + */ + hold_for_pickup?: boolean | null; + /** + * Incoterm negotiated for shipment. + * Supported values are "EXW", "FCA", "CPT", "CIP", "DAT", "DAP", "DDP", "FAS", "FOB", "CFR", and "CIF". + * Setting this value to anything other than "DDP" will pass the cost and responsibility of duties on to the recipient of the package(s), as specified by Incoterms rules + */ + incoterm?: + | 'EXW' + | 'FCA' + | 'CPT' + | 'CIP' + | 'DAT' + | 'DAP' + | 'DDP' + | 'FAS' + | 'FOB' + | 'CFR' + | 'CIF' + | null; + /** + * This will print an invoice number on the postage label. + */ + invoice_number?: string | null; + /** + * Set the date that will appear on the postage label. + * Accepts ISO 8601 formatted string including time zone offset. + * EasyPost stores all dates as UTC time. + */ + label_date?: string | null; + /** + * Supported label formats include "PNG", "PDF", "ZPL", and "EPL2". + * "PNG" is the only format that allows for conversion. + * + * @see https://www.easypost.com/docs/api#convert-the-label-format-of-a-shipment + */ + label_format?: LabelFormat | null; + /** + * Whether or not the parcel can be processed by the carriers equipment. + */ + machinable?: boolean | null; + /** + * Setting payment type to bill the correct account for purchasing postage. + */ + payment?: { + /** + * Supported values are "SENDER", "THIRD_PARTY", "RECEIVER", "COLLECT". Defaults to SENDER. + */ + type?: 'SENDER' | 'THIRD_PARTY' | 'RECEIVER' | 'COLLECT' | null; + /** + * Setting account number. + * Required for RECEIVER and THIRD_PARTY. + */ + account?: string | null; + /** + * Setting country code that the account is based in. + * Required for THIRD_PARTY. + */ + country?: string | null; + /** + * Setting postal code that the account is based in. + * Required for RECEIVER and THIRD_PARTY. + */ + postal_code?: string | null; + }; + /** + * The earliest a package should be picked up. Supported carriers vary. + */ + pickup_min_datetime?: string | null; + /** + * The latest a package should be picked up. Supported carriers vary. + */ + pickup_man_datetime?: string | null; + /** + * You can optionally print custom messages on labels. + * The locations of these fields show up on different spots on the carrier's labels. + */ + print_custom_1?: string | null; + /** + * An additional message on the label. Same restrictions as print_custom_1 + */ + print_custom_2?: string | null; + /** + * An additional message on the label. Same restrictions as print_custom_1 + */ + print_custom_3?: string | null; + /** + * Create a barcode for this custom reference if supported by carrier. + */ + print_custom_1_barcode?: boolean | null; + /** + * Create a barcode for this custom reference if supported by carrier. + */ + print_custom_2_barcode?: boolean | null; + /** + * Create a barcode for this custom reference if supported by carrier. + */ + print_custom_3_barcode?: boolean | null; + /** + * Specify the type of print_custom_1. + */ + print_custom_1_code?: TPrintCustomCode | null; + /** + * Specify the type of print_custom_2. + */ + print_custom_2_code?: TPrintCustomCode | null; + /** + * Specify the type of print_custom_3. + */ + print_custom_3_code?: TPrintCustomCode | null; + /** + * Set this value to true for delivery on Saturday. + * When setting the saturday_delivery option, you will only get rates for services that are eligible for saturday delivery. + * If no services are available for saturday delivery, then you will not be returned any rates. + * You may need to create 2 shipments, one with the saturday_delivery option set on one without to get all your eligible rates. + */ + saturday_delivery?: boolean | null; + /** + * This option allows you to request restrictive rates from USPS. + * Can set to 'USPS.MEDIAMAIL' or 'USPS.LIBRARYMAIL'. + */ + special_rates_eligibility?: 'USPS.MEDIAMAIL' | 'USPS.LIBRARYMAIL' | null; + /** + * You can use this to override the hub ID you have on your account. + */ + smartpost_hub?: string | null; + /** + * The manifest ID is used to group SmartPost packages onto a manifest for each trailer. + */ + smartpost_manifest?: string | null; + /** + * A reference ID for aggregating DHL eCommerce billing data. + */ + billing_ref?: string | null; + /** + * Certified Mail provides the sender with a mailing receipt and, upon request, electronic verification that an article was delivered or that a delivery attempt was made. + */ + certified_mail?: boolean | null; + /** + * Registered Mail is the most secure service that the USPS offers. + * It incorporates a system of receipts to monitor the movement of the mail from the point of acceptance to delivery + */ + registered_mail?: boolean | null; + /** + * The value of the package contents + */ + registered_mail_amount?: number | null; + /** + * An electronic return receipt may be purchased at the time of mailing and provides a shipper with evidence of delivery (to whom the mail was delivered and date of delivery), and information about the recipient's actual delivery address. + * Only applies to the USPS. + */ + return_receipt?: boolean | null; +}; diff --git a/types/src/services/shipment_service/Options/PrintCustomCode.d.ts b/types/src/services/shipment_service/Options/PrintCustomCode.d.ts new file mode 100644 index 000000000..4933056eb --- /dev/null +++ b/types/src/services/shipment_service/Options/PrintCustomCode.d.ts @@ -0,0 +1,52 @@ +/** + * - FedEx + * - (null) - If print_custom_1_code is not provided it defaults to Customer Reference + * - PO - Purchase Order Number + * - DP - Department Number + * - RMA - Return Merchandise Authorization + * - UPS + * - AJ - Accounts Receivable Customer Account + * - AT - Appropriation Number + * - BM - Bill of Lading Number + * - 9V - Collect on Delivery (COD) Number + * - ON - Dealer Order Number + * - DP - Department Number + * - 3Q - Food and Drug Administration (FDA) Product Code + * - IK - Invoice Number + * - MK - Manifest Key Number + * - MJ - Model Number + * - PM - Part Number + * - PC - Production Code + * - PO - Purchase Order Number + * - RQ - Purchase Request Number + * - RZ - Return Authorization Number + * - SA - Salesperson Number + * - SE - Serial Number + * - ST - Store Number + * - TN - Transaction Reference Number + * - EI - Employer's ID Number + * - TJ - Federal Taxpayer ID No. + */ +export declare type TPrintCustomCode = + | 'PO' + | 'DP' + | 'RMA' + | 'AJ' + | 'AT' + | 'BM' + | '9V' + | 'ON' + | '3Q' + | 'IK' + | 'MK' + | 'MJ' + | 'PM' + | 'PC' + | 'RQ' + | 'RZ' + | 'SA' + | 'SE' + | 'ST' + | 'TN' + | 'EI' + | 'TJ'; diff --git a/types/src/services/shipment_service/Options/index.d.ts b/types/src/services/shipment_service/Options/index.d.ts new file mode 100644 index 000000000..349426b0d --- /dev/null +++ b/types/src/services/shipment_service/Options/index.d.ts @@ -0,0 +1,3 @@ +export * from './LabelFormat'; +export * from './Options'; +export * from './PrintCustomCode'; diff --git a/types/src/services/shipment_service/PostageLabel.d.ts b/types/src/services/shipment_service/PostageLabel.d.ts new file mode 100644 index 000000000..0d0b2fdf6 --- /dev/null +++ b/types/src/services/shipment_service/PostageLabel.d.ts @@ -0,0 +1,18 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +/** + * PostageLabel Object + */ +export type IPostageLabel = IObjectWithId<'PostageLabel'> & + IDatedObject & { + date_advance: number; + integrated_form: string; + label_date: string; + label_resolution: number; + label_size: string; + label_type: string; + label_url: string; + label_file_type: string; + label_pdf_url: string; + label_epl2_url: string; + label_zpl_url: string; + }; diff --git a/types/src/services/shipment_service/Shipment.d.ts b/types/src/services/shipment_service/Shipment.d.ts new file mode 100644 index 000000000..80f7b4292 --- /dev/null +++ b/types/src/services/shipment_service/Shipment.d.ts @@ -0,0 +1,124 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IAddress } from '../address_service'; +import { TBatchStatus } from '../batch_service'; +import { ICustomsInfo } from '../customs_info_service'; +import { IFee, IInsurance } from '../insurance_service'; +import { IParcel } from '../parcel_service'; +import { IRate } from '../rate_service'; +import { IScanForm } from '../scan_form_service'; +import { ITracker } from '../tracker_service'; +import { IForm } from './Form'; +import { IMessage } from './Message'; +import { IOptions } from './Options'; +import { IPostageLabel } from './PostageLabel'; +/** + * The workhorse of the EasyPost API, a Shipment is made up of a "to" and "from" Address, the Parcel being shipped, and any customs forms required for international deliveries. + * Once created a Shipment object is used to retrieve shipping Rates and purchase a label. + * + * A Shipment created with a valid to_address, from_address, and parcel will automatically populate its rates attribute. + * + * @see https://www.easypost.com/docs/api/node#shipment-object + */ +export type IShipment = IObjectWithId<'Shipment'> & + IDatedObject & { + /** + * An optional field that may be used in place of id in other API endpoints + */ + reference?: string | null; + /** + * The destination address + */ + to_address: IAddress; + /** + * The origin address + */ + from_address: IAddress; + /** + * The shipper's address, defaults to from_address + */ + return_address?: IAddress | null; + /** + * The buyer's address, defaults to to_address + */ + buyer_address?: IAddress | null; + /** + * The dimensions and weight of the package + */ + parcel: IParcel; + /** + * Information for the processing of customs + */ + customs_info?: ICustomsInfo | null; + /** + * Document created to manifest and scan multiple shipments + */ + scan_form: IScanForm; + /** + * All associated Form objects + */ + forms: IForm[]; + /** + * The associated Insurance object + */ + insurance: IInsurance; + /** + * All associated Rate objects + */ + rates: IRate[]; + /** + * The specific rate purchased for the shipment, or null if unpurchased or purchased through another mechanism + */ + selected_rate: IRate; + /** + * The associated PostageLabel object + */ + postage_label: IPostageLabel; + /** + * Any carrier errors encountered during rating, discussed in more depth below + */ + messages: IMessage[]; + /** + * All the options passed to the shipment, discussed in more depth below + */ + options?: IOptions | null; + /** + * Set true to create as a return, discussed in more depth below + */ + is_return?: boolean | null; + /** + * If purchased, the tracking code will appear here as well as within the Tracker object + */ + tracking_code: string; + /** + * The USPS zone of the shipment, if purchased with USPS + */ + usps_zone: string; + /** + * The current tracking status of the shipment + */ + status: string; + /** + * The associated Tracker object + */ + tracker: ITracker; + /** + * The associated Fee objects charged to the billing user account + */ + fees: IFee[]; + /** + * The current status of the shipment refund process. Possible values are "submitted", "refunded", "rejected". + */ + refund_status: 'submitted' | 'refunded' | 'rejected'; + /** + * The ID of the batch that contains this shipment, if any + */ + batch_id: string; + /** + * The current status of the associated BatchShipment + */ + batch_status: TBatchStatus; + /** + * The current message of the associated BatchShipment + */ + batch_message: string; + }; diff --git a/types/src/services/shipment_service/ShipmentCreateParameters.d.ts b/types/src/services/shipment_service/ShipmentCreateParameters.d.ts new file mode 100644 index 000000000..4b690eead --- /dev/null +++ b/types/src/services/shipment_service/ShipmentCreateParameters.d.ts @@ -0,0 +1,17 @@ +import { DeepPartial } from '../../utils/types'; +import { IAddressCreateParameters } from '../address_service'; +import { ICustomsInfo } from '../customs_info_service'; +import { IParcelCreateParameters } from '../parcel_service'; +import { IOptions } from './Options'; +export type IShipmentCreateParameters = { + reference?: string | null; + to_address: DeepPartial | string; + from_address: DeepPartial | string; + parcel: Partial | string; + /** + * optional array of ids that begin with "ca_" + */ + carrier_accounts?: string[] | null; + customs_info?: DeepPartial | null; + options?: DeepPartial | null; +}; diff --git a/types/src/services/shipment_service/ShipmentListParameters.d.ts b/types/src/services/shipment_service/ShipmentListParameters.d.ts new file mode 100644 index 000000000..c875985b8 --- /dev/null +++ b/types/src/services/shipment_service/ShipmentListParameters.d.ts @@ -0,0 +1,16 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments + */ +export type IShipmentListParameters = IAllMethodParameters & { + /** + * Only include Shipments that have been purchased. + * Default is true + */ + purchased?: boolean; + /** + * Also include Shipments created by Child Users. + * Defaults to false + */ + include_children?: boolean; +}; diff --git a/types/src/services/shipment_service/index.d.ts b/types/src/services/shipment_service/index.d.ts new file mode 100644 index 000000000..0d14ecb05 --- /dev/null +++ b/types/src/services/shipment_service/index.d.ts @@ -0,0 +1,605 @@ +import EasyPost from '../..'; +import { IRate, ISmartRate } from '../rate_service'; +import { IOptions, LabelFormat } from './Options'; +import { IShipmentCreateParameters } from './ShipmentCreateParameters'; +import { IShipmentListParameters } from './ShipmentListParameters'; +export * from './Form'; +export * from './Message'; +export * from './PostageLabel'; +export * from './Shipment'; +export * from './ShipmentCreateParameters'; +export * from './ShipmentListParameters'; +export * from './Options'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#create-a-shipment EasyPost API Documentation} for more information. + * @param params - The parameters to create a shipment with. + * @returns - The created shipment. + */ + create(params: IShipmentCreateParameters): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */ + buy( + id: string, + rate: IRate | string, + insuranceAmount?: number | null, + endShipperId?: string | null, + ): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Convert the label format of a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#convert-the-label-format-of-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to convert the label format of. + * @param format - The format to convert the label to. + * @returns - The shipment with the converted label format. + */ + convertLabelFormat( + id: string, + format: LabelFormat, + ): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Regenerate {@link Rate rates} for a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#regenerate-rates-for-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to regenerate rates for. + * @returns - The shipment with regenerated rates. + */ + regenerateRates(id: string): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Get SmartRates for a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-time-in-transit-statistics-across-all-rates-for-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to get SmartRates for. + * @returns - The SmartRates for the shipment. + */ + getSmartRates(id: string): Promise>; + /** + * Insure a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#insure-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to insure. + * @param amount - The amount to insure the shipment for. + * @returns - The insured shipment. + */ + insure( + id: string, + amount: number | string, + ): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Generate a form for a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#create-form EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to generate a form for. + * @param formType - The type of form to generate. + * @param [formOptions] - Options for the form. + * @returns - The shipment with the generated form attached. + */ + generateForm( + id: string, + formType: string, + formOptions?: IOptions, + ): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Refund a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#refund-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to refund. + * @returns - The refunded shipment. + */ + refund(id: string): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Get the lowest SmartRate of a shipment. + * @param id - The ID of the shipment to get the lowest SmartRate of. + * @param deliveryDays - The number of days the shipment will take to deliver. + * @param deliveryAccuracy - The accuracy of the delivery days. + * @returns - The lowest SmartRate of the shipment. + */ + lowestSmartRate( + id: string, + deliveryDays: number, + deliveryAccuracy: keyof ISmartRate['time_in_transit'], + ): Promise; + /** + * Retrieve all {@link Shipment shipments} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments EasyPost API Documentation} for more information. + * @param [params] - Parameters to filter the shipments by. + * @returns - An object containing a list of {@link Shipment shipments} and pagination information. + */ + all(params?: IShipmentListParameters): Promise<{ + shipments: (import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + })[]; + _params: any; + has_more: boolean; + }>; + /** + * Retrieve the next page of Shipment collection. + * @param shipments An object containing a list of {@link Shipment shipments} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + shipments: { + shipments: any[]; + }, + pageSize?: null, + ): Promise<{ + shipments: (import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + })[]; + _params: any; + has_more: boolean; + }>; + /** + * Retrieve a {@link Shipment shipment} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to retrieve. + * @returns - The shipment with the given ID. + */ + retrieve(id: string): Promise< + import('../../utils/types').IBaseObject<'Shipment'> & { + id: string; + mode: 'test' | 'production'; + object: 'Shipment'; + } & import('../../utils/types').IDatedObject & { + reference?: string | null | undefined; + to_address: import('..').IAddress; + from_address: import('..').IAddress; + return_address?: import('..').IAddress | null | undefined; + buyer_address?: import('..').IAddress | null | undefined; + parcel: import('..').IParcel + /** + * Purchase a {@link Shipment shipment}. + * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. + * @param id - The ID of the shipment to purchase. + * @param rate - The rate to purchase the shipment with. + * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. + * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. + * @returns - The purchased shipment. + */; + customs_info?: import('..').ICustomsInfo | null | undefined; + scan_form: import('..').IScanForm; + forms: import('./Form').IForm[]; + insurance: import('..').IInsurance; + rates: IRate[]; + selected_rate: IRate; + postage_label: import('./PostageLabel').IPostageLabel; + messages: import('./Message').IMessage[]; + options?: IOptions | null | undefined; + is_return?: boolean | null | undefined; + tracking_code: string; + usps_zone: string; + status: string; + tracker: import('..').ITracker; + fees: import('..').IFee[]; + refund_status: 'submitted' | 'refunded' | 'rejected'; + batch_id: string; + batch_status: import('..').TBatchStatus; + batch_message: string; + } & { + lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; + } + >; + /** + * Retrieves the estimated delivery date of each Rate via SmartRate. + * @param id + * @param plannedShipDate + * @returns - An array of the estimated delivery date and rates. + */ + retrieveEstimatedDeliveryDate( + id: string, + plannedShipDate: string, + ): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/tracker_service/CarrierDetail.d.ts b/types/src/services/tracker_service/CarrierDetail.d.ts new file mode 100644 index 000000000..0cbb6a136 --- /dev/null +++ b/types/src/services/tracker_service/CarrierDetail.d.ts @@ -0,0 +1,51 @@ +import { IBaseObject } from '../../utils/types'; +import { ITrackingLocation } from './TrackingLocation'; +/** + * @see https://www.easypost.com/docs/api/node#carrier-detail-object + */ +export type ICarrierDetail = IBaseObject<'CarrierDetail'> & { + /** + * The service level the associated shipment was shipped with (if available) + */ + service: string; + /** + * The type of container the associated shipment was shipped in (if available) + */ + container_type: string; + /** + * The estimated delivery date as provided by the carrier, in the local time zone (if available) + */ + est_delivery_date_local: string; + /** + * The estimated delivery time as provided by the carrier, in the local time zone (if available) + */ + est_delivery_time_local: string; + /** + * The location from which the package originated, stringified for presentation (if available) + */ + origin_location: string; + /** + * The location from which the package originated, broken down by city/state/country/zip (if available) + */ + origin_tracking_location: ITrackingLocation; + /** + * The location to which the package is being sent, stringified for presentation (if available) + */ + destination_location: string; + /** + * The location to which the package is being sent, broken down by city/state/country/zip (if available) + */ + destination_tracking_location: ITrackingLocation; + /** + * The date and time the carrier guarantees the package to be delivered by (if available) + */ + guaranteed_delivery_date: string; + /** + * The alternate identifier for this package as provided by the carrier (if available) + */ + alternate_identifier: string; + /** + * The date and time of the first attempt by the carrier to deliver the package (if available) + */ + initial_delivery_attempt: string; +}; diff --git a/types/src/services/tracker_service/Tracker.d.ts b/types/src/services/tracker_service/Tracker.d.ts new file mode 100644 index 000000000..b601dc6c2 --- /dev/null +++ b/types/src/services/tracker_service/Tracker.d.ts @@ -0,0 +1,86 @@ +import { IDatedObject, IObjectWithId } from '../../utils/types'; +import { IFee } from '../insurance_service'; +import { ICarrierDetail } from './CarrierDetail'; +import { ITrackerStatus } from './TrackerStatus'; +import { ITrackerStatusDetail } from './TrackerStatusDetail'; +import { ITrackingDetail } from './TrackingDetail'; +/** + * A Tracker object contains all the tracking information for a package. + * A Tracker is created automatically whenever you buy a Shipment through EasyPost. + * If you don't use EasyPost to purchase your shipping labels, you can still track packages through our API by creating a Tracker object directly. + * Each Tracker is continually updated in the background as the package moves through its life cycle, regardless of whether or not the label was purchased through EasyPost. + * + * After creation, a Tracker object will be updated periodically based on when the carrier provides EasyPost with new tracking information. + * This information can be consumed by using our webhooks infrastructure. + * Every time a Tracker is updated a webhook Event will be sent. + * + * The Tracker object contains both the current information about the package and previous updates. + * All the previous updates are stored in the tracking_details array. + * Each TrackingDetail object contains the status, the message from the carrier, and a TrackingLocation. + * + * The TrackingLocation contains city, state, country, and zip information about the location where the package was scanned. + * The information each carrier provides is different, so some carriers may not make use of all these fields. + * + * Some Tracker objects may also contain a CarrierDetail, which stores some additional information about the Tracker that the carrier has made available to EasyPost. + * The CarrierDetail object contains the service and container_type of the package. + * Additionally, it also stores the `est_delivery_date_local` and `est_delivery_time_local`, which provide information about the local delivery time. + * + * It's worth noting that tracking_codes are not globally unique. + * Each carrier promises uniqueness for a given `tracking_code` for a certain period of time, but the length of time varies greatly based on the specific carrier and service level. + * The carriers do eventually recycle `tracking_codes`, and for this reason enforcing uniqueness on the `tracking_code` field is not recommended. + * EasyPost does, however, prevent the creation of duplicate Trackers based on tracking_code and carrier; duplicate requests by the same User will simply return the original Tracker. + * + * @see https://www.easypost.com/docs/api/node#tracker-object + */ +export type ITracker = IObjectWithId<'Tracker'> & + IDatedObject & { + /** + * The tracking code provided by the carrier + */ + tracking_code: string; + /** + * The current status of the package, possible values are "unknown", "pre_transit", "in_transit", "out_for_delivery", "delivered", "available_for_pickup", "return_to_sender", "failure", "cancelled" or "error" + */ + status: ITrackerStatus; + /** + * Additional details about the current status, possible values are "unknown", "status_update", "departed_facility", "arrived_at_facility", "out_for_delivery", "arrived_at_destination" + */ + status_detail: ITrackerStatusDetail; + /** + * The name of the person who signed for the package (if available) + */ + signed_by: string; + /** + * The weight of the package as measured by the carrier in ounces (if available) + * float (oz) + */ + weight: number; + /** + * The estimated delivery date provided by the carrier (if available) + */ + est_delivery_date: string; + /** + * The id of the EasyPost Shipment object associated with the Tracker (if any) + */ + shipment_id: string; + /** + * The name of the carrier handling the shipment + */ + carrier: string; + /** + * Array of the associated TrackingDetail objects + */ + tracking_details: ITrackingDetail[]; + /** + * The associated CarrierDetail object (if available) + */ + carrier_detail: ICarrierDetail; + /** + * URL to a publicly-accessible html page that shows tracking details for this tracker + */ + public_url: string; + /** + * Array of the associated Fee objects + */ + fees: IFee[]; + }; diff --git a/types/src/services/tracker_service/TrackerCreateParameters.d.ts b/types/src/services/tracker_service/TrackerCreateParameters.d.ts new file mode 100644 index 000000000..242a3fcec --- /dev/null +++ b/types/src/services/tracker_service/TrackerCreateParameters.d.ts @@ -0,0 +1,11 @@ +export type ITrackerCreateParameters = { + /** + * The tracking code associated with the package you'd like to track + */ + tracking_code: string; + /** + * The carrier associated with the tracking_code you provided. + * The carrier will get auto-detected if none is provided + */ + carrier?: string; +}; diff --git a/types/src/services/tracker_service/TrackerListParameters.d.ts b/types/src/services/tracker_service/TrackerListParameters.d.ts new file mode 100644 index 000000000..0a831d83f --- /dev/null +++ b/types/src/services/tracker_service/TrackerListParameters.d.ts @@ -0,0 +1,12 @@ +import { IAllMethodParameters } from '../../utils/types'; +export type ITrackerListParameters = IAllMethodParameters & { + /** + * Only returns Trackers with the given tracking_code. + * Useful for retrieving an individual Tracker by tracking_code rather than by ID + */ + tracking_code?: string; + /** + * Only returns Trackers with the given carrier value + */ + carrier?: string; +}; diff --git a/types/src/services/tracker_service/TrackerStatus.d.ts b/types/src/services/tracker_service/TrackerStatus.d.ts new file mode 100644 index 000000000..11b490ca1 --- /dev/null +++ b/types/src/services/tracker_service/TrackerStatus.d.ts @@ -0,0 +1,11 @@ +export type ITrackerStatus = + | 'unknown' + | 'pre_transit' + | 'in_transit' + | 'out_for_delivery' + | 'delivered' + | 'available_for_pickup' + | 'return_to_sender' + | 'failure' + | 'cancelled' + | 'error'; diff --git a/types/src/services/tracker_service/TrackerStatusDetail.d.ts b/types/src/services/tracker_service/TrackerStatusDetail.d.ts new file mode 100644 index 000000000..d36c4690c --- /dev/null +++ b/types/src/services/tracker_service/TrackerStatusDetail.d.ts @@ -0,0 +1,29 @@ +export type ITrackerStatusDetail = + | 'address_correction' + | 'arrived_at_destination' + | 'arrived_at_facility' + | 'arrived_at_pickup_location' + | 'awaiting_information' + | 'cancelled' + | 'damaged' + | 'delayed' + | 'delivery_exception' + | 'departed_facility' + | 'departed_origin_facility' + | 'expired' + | 'failure' + | 'held' + | 'in_transit' + | 'label_created' + | 'lost' + | 'missorted' + | 'out_for_delivery' + | 'received_at_destination_facility' + | 'received_at_origin_facility' + | 'refused' + | 'return' + | 'status_update' + | 'transferred_to_destination_carrier' + | 'transit_exception' + | 'unknown' + | 'weather_delay'; diff --git a/types/src/services/tracker_service/TrackingDetail.d.ts b/types/src/services/tracker_service/TrackingDetail.d.ts new file mode 100644 index 000000000..c214f1d78 --- /dev/null +++ b/types/src/services/tracker_service/TrackingDetail.d.ts @@ -0,0 +1,28 @@ +import { IBaseObject } from '../../utils/types'; +import { ITrackerStatus } from './TrackerStatus'; +import { ITrackingLocation } from './TrackingLocation'; +/** + * @see https://www.easypost.com/docs/api/node#tracking-detail-object + */ +export type ITrackingDetail = IBaseObject<'TrackingDetail'> & { + /** + * Description of the scan event + */ + message: string; + /** + * Status of the package at the time of the scan event, possible values are "unknown", "pre_transit", "in_transit", "out_for_delivery", "delivered", "available_for_pickup", "return_to_sender", "failure", "cancelled" or "error" + */ + status: ITrackerStatus; + /** + * The timestamp when the tracking scan occurred + */ + datetime: string; + /** + * The original source of the information for this scan event, usually the carrier + */ + source: string; + /** + * The location associated with the scan event + */ + tracking_location: ITrackingLocation; +}; diff --git a/types/src/services/tracker_service/TrackingLocation.d.ts b/types/src/services/tracker_service/TrackingLocation.d.ts new file mode 100644 index 000000000..122522685 --- /dev/null +++ b/types/src/services/tracker_service/TrackingLocation.d.ts @@ -0,0 +1,22 @@ +import { IBaseObject } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#tracking-location-object + */ +export type ITrackingLocation = IBaseObject<'TrackingLocation'> & { + /** + * The city where the scan event occurred (if available) + */ + city: string; + /** + * The state where the scan event occurred (if available) + */ + state: string; + /** + * The country where the scan event occurred (if available) + */ + country: string; + /** + * The postal code where the scan event occurred (if available) + */ + zip: string; +}; diff --git a/types/src/services/tracker_service/index.d.ts b/types/src/services/tracker_service/index.d.ts new file mode 100644 index 000000000..10013907e --- /dev/null +++ b/types/src/services/tracker_service/index.d.ts @@ -0,0 +1,102 @@ +import EasyPost from '../..'; +import { ITracker } from './Tracker'; +import { ITrackerCreateParameters } from './TrackerCreateParameters'; +import { ITrackerListParameters } from './TrackerListParameters'; +export * from './CarrierDetail'; +export * from './Tracker'; +export * from './TrackerCreateParameters'; +export * from './TrackerListParameters'; +export * from './TrackerStatus'; +export * from './TrackerStatusDetail'; +export * from './TrackingDetail'; +export * from './TrackingLocation'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Tracker tracker}. + * See {@link https://www.easypost.com/docs/api/node#create-a-tracker EasyPost API Documentation} for more information. + * @param params - The parameters to create a tracker with. + * @returns - The created tracker. + */ + create( + params: ITrackerCreateParameters, + ): Promise>; + /** + * Create multiple {@link Tracker trackers} in a single request. + * See {@link https://www.easypost.com/docs/api/node#trackers EasyPost API Documentation} for more information. + * @param [params] - The parameters to create trackers with. + */ + createList(params?: ITrackerCreateParameters[]): Promise; + /** + * Retrieve all {@link Tracker trackers} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-trackers EasyPost API Documentation} for more information. + * @param [params] - The parameters to filter the trackers by. + * @returns - An object containing the list of {@link Tracker trackers} and pagination information. + */ + all(params?: ITrackerListParameters): Promise< + { + trackers: ITracker[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve the next page of Tracker collection. + * @param trackers An object containing a list of {@link Tracker trackers} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + trackers: { + trackers: any[]; + }, + pageSize?: number | null, + ): Promise< + { + trackers: ITracker[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link Tracker tracker} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-tracker EasyPost API Documentation} for more information. + * @param id - The ID of the tracker to retrieve. + * @returns - The retrieved tracker. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/user_service/Brand.d.ts b/types/src/services/user_service/Brand.d.ts new file mode 100644 index 000000000..fd0fc15a4 --- /dev/null +++ b/types/src/services/user_service/Brand.d.ts @@ -0,0 +1,40 @@ +import { IObjectWithId } from '../../utils/types'; +/** + * The Brand class represents the public-accessible information about a user's brand, including logos, colors and themes. + * + * @see https://www.easypost.com/docs/api/node#brand + */ +export type IBrand = IObjectWithId<'Brand'> & { + /** + * The background color of the brand, as a hex code. + */ + background_color: string; + /** + * The primary color of the brand, as a hex code. + */ + color: string; + /** + * The logo of the brand, as a base64-encoded PNG, GIF, JPEG or SVG. + */ + logo: string; + /** + * The URL of the brand's logo. + */ + logo_href: string; + /** + * The banner ad of the brand, as a base64-encoded PNG, GIF, JPEG or SVG. + */ + ad: string; + /** + * The URL of the brand's banner ad. + */ + ad_href: string; + /** + * The ID of the brand's associated User. + */ + user_id: string; + /** + * The name of the current theme. + */ + theme: 'theme1' | 'theme2'; +}; diff --git a/types/src/services/user_service/User.d.ts b/types/src/services/user_service/User.d.ts new file mode 100644 index 000000000..af274970f --- /dev/null +++ b/types/src/services/user_service/User.d.ts @@ -0,0 +1,64 @@ +import { IObjectWithId } from '../../utils/types'; +/** + * The User object can be used to manage your own account and to create child accounts. + * Only a Production mode API key can be used to make requests against the Users API. + * + * Balance and recharge values on User objects are expressed in higher precision USD. + * + * @see https://www.easypost.com/docs/api/node#user-object + */ +export type IUser = IObjectWithId<'User'> & { + /** + * The ID of the parent user object. + * Top-level users are defined as users with no parent + */ + parent_id: string; + /** + * First and last name required + */ + name: string; + /** + * Required + */ + email: string; + /** + * Optional + */ + phone_number?: string | null; + /** + * Formatted as string "XX.XXXXX" + */ + balance: string; + /** + * Cost per shipment purchase, formatted as string "XX.XXXXX" + */ + price_per_shipment: string; + /** + * USD formatted dollars and cents, delimited by a decimal point + */ + recharge_amount: string; + /** + * USD formatted dollars and cents, delimited by a decimal point + */ + secondary_recharge_amount: string; + /** + * Number of cents USD that when your balance drops below, we automatically recharge your account with your primary payment method. + */ + recharge_threshold: string; + /** + * The fee rate for convenience fees + */ + cc_fee_rate: string; + /** + * The fee rate for insurance purchases + */ + insurance_fee_rate: string; + /** + * The minimum cost for insurance purchases + */ + insurance_fee_minimum: string; + /** + * All associated children + */ + children: IUser[]; +}; diff --git a/types/src/services/user_service/UserCreateParameters.d.ts b/types/src/services/user_service/UserCreateParameters.d.ts new file mode 100644 index 000000000..78113251c --- /dev/null +++ b/types/src/services/user_service/UserCreateParameters.d.ts @@ -0,0 +1,3 @@ +import { ParametersToOmitOnCreate } from '../../utils/types'; +import { IUser } from './User'; +export type IUserCreateParameters = Omit; diff --git a/types/src/services/user_service/index.d.ts b/types/src/services/user_service/index.d.ts new file mode 100644 index 000000000..bd4afc937 --- /dev/null +++ b/types/src/services/user_service/index.d.ts @@ -0,0 +1,126 @@ +import EasyPost from '../..'; +import { IBrand } from './Brand'; +import { IUser } from './User'; +import { IUserCreateParameters } from './UserCreateParameters'; +export * from './Brand'; +export * from './User'; +export * from './UserCreateParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link User child user}. + * See {@link https://www.easypost.com/docs/api/node#create-a-child-user EasyPost API Documentation} for more information. + * @param params - The parameters to create a child user with. + * @returns - The created child user. + */ + create(params: IUserCreateParameters): Promise>; + /** + * Update a {@link User user}. + * See {@link https://www.easypost.com/docs/api/node#update-a-user EasyPost API Documentation} for more information. + * @param id - The ID of the user to update (either the current authenticated user or a child user). + * @param params - The parameters to update the user with. + * @returns - The updated user. + */ + update( + id: string, + params: Partial, + ): Promise>; + /** + * Retrieve a {@link User child user}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-user EasyPost API Documentation} for more information. + * @param id - The ID of the child user to retrieve. + * @returns - The retrieved child user. + */ + retrieve(id: string): Promise>; + /** + * Retrieve the {@link User current authenticated user}. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-user EasyPost API Documentation} for more information. + * @returns - The retrieved user. + */ + retrieveMe(): Promise>; + /** + * Delete a {@link User child user}. + * See {@link https://www.easypost.com/docs/api/node#delete-a-child-user EasyPost API Documentation} for more information. + * @param id - The ID of the child user to delete. + * @returns - A promise that resolves when the child user is deleted successfully. + */ + delete(id: string): Promise; + /** + * Update the brand of a {@link User user}. + * See {@link https://www.easypost.com/docs/api/node#update-a-brand EasyPost API Documentation} for more information. + * @param id - The ID of the user to update the brand of. + * @param params - The parameters to update the brand with. + * @returns - The updated brand. + */ + updateBrand( + id: string, + params: Partial, + ): Promise>; + /** + * Retrieve a paginated list of children user {@link User user}. + * See {@link https://www.easypost.com/docs/api/node#child-users EasyPost API Documentation} for more information. + * @param params - Parameters to filter the list of children users. + * @returns - An object containing a list of {@link Children User} and pagination information. + */ + allChildren(params: any): Promise< + import('../base_service').EasyPostObject<{ + children: IUser[]; + }> + >; + /** + * Retrieve the next page of children collection. + * @param children An object containing a list of {@link Children children} and pagination information. + * @param pageSize The number of records to return on each page + * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. + */ + getNextPage( + children: { + children: any[]; + }, + pageSize?: number | null, + ): Promise< + { + children: IUser[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise> + /** + * Delete a {@link User child user}. + * See {@link https://www.easypost.com/docs/api/node#delete-a-child-user EasyPost API Documentation} for more information. + * @param id - The ID of the child user to delete. + * @returns - A promise that resolves when the child user is deleted successfully. + */; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/services/webhook_service/Webhook.d.ts b/types/src/services/webhook_service/Webhook.d.ts new file mode 100644 index 000000000..a7137ee4e --- /dev/null +++ b/types/src/services/webhook_service/Webhook.d.ts @@ -0,0 +1,28 @@ +import { IObjectWithId } from '../../utils/types'; +/** + * Each Webhook contains the url which EasyPost will notify whenever an object in our system updates. + * Several types of objects are processed asynchronously in the EasyPost system, so whenever an object updates, an Event is sent via HTTP POST to each configured webhook URL. + * The Webhook object provides CRUD operations for all Webhooks. + * + * Currently, our recommended best practice for securing Webhooks involves using basic authentication and HTTPS on your endpoint. + * This will help prevent any altering of any information communicated to you by EasyPost, prevent any third parties from seeing your webhooks in transit, and will prevent any third parties from masquerading as EasyPost and sending fraudulent data. + * EasyPost performs certificate validation and requires any TLS-enabled (HTTPS) webhook recipients to have a certificate signed by a public trusted certification authority. + * We do not support sending webhooks to over SSLv2, SSLv3, or any connection using so-called export-grade ciphers. + * For documentation on how to set up your server with TLS, we recommend Mozilla's guide to Server-Side TLS and Qualys's SSL/TLS deployment best practices guide. + * + * In general, a Webhook's endpoint should return a status code of 2XX. + * A 200 is preferred, but any 2XX status will indicate to our system that the Webhook request was successful. + * Endpoints that return a large volume and rate of failures over a period of time will get automatically disabled by the system; a disabled Webhook can be re-enabled using the Webhook update endpoint. + * + * @see https://www.easypost.com/docs/api/node#webhook-object + */ +export type IWebhook = IObjectWithId<'Webhook'> & { + /** + * http://example.com + */ + url: string; + /** + * the timestamp at which the webhook was most recently disabled (if any) + */ + disabled_at: string; +}; diff --git a/types/src/services/webhook_service/WebhookCreateParameters.d.ts b/types/src/services/webhook_service/WebhookCreateParameters.d.ts new file mode 100644 index 000000000..e5eb2aee2 --- /dev/null +++ b/types/src/services/webhook_service/WebhookCreateParameters.d.ts @@ -0,0 +1,3 @@ +export type IWebhookCreateParameters = { + url: string; +}; diff --git a/types/src/services/webhook_service/WebhookListParameters.d.ts b/types/src/services/webhook_service/WebhookListParameters.d.ts new file mode 100644 index 000000000..4660bde6a --- /dev/null +++ b/types/src/services/webhook_service/WebhookListParameters.d.ts @@ -0,0 +1,5 @@ +import { IAllMethodParameters } from '../../utils/types'; +/** + * @see https://www.easypost.com/docs/api/node#list-a-webhooks + */ +export type IWebhookListParameters = IAllMethodParameters; diff --git a/types/src/services/webhook_service/index.d.ts b/types/src/services/webhook_service/index.d.ts new file mode 100644 index 000000000..a1890b6df --- /dev/null +++ b/types/src/services/webhook_service/index.d.ts @@ -0,0 +1,90 @@ +import EasyPost from '../..'; +import { IWebhook } from './Webhook'; +import { IWebhookCreateParameters } from './WebhookCreateParameters'; +import { IWebhookListParameters } from './WebhookListParameters'; +export * from './Webhook'; +export * from './WebhookCreateParameters'; +export * from './WebhookListParameters'; +declare const _default: (easypostClient: EasyPost) => { + new (): {}; + /** + * Create a {@link Webhook webhook}. + * See {@link https://www.easypost.com/docs/api/node#create-a-webhook EasyPost API Documentation} for more information. + * @param params - The parameters to create a webhook with. + * @returns - The created webhook. + */ + create( + params: IWebhookCreateParameters, + ): Promise>; + /** + * Update a {@link Webhook webhook}. + * A disabled webhook will be re-enabled if it is updated. + * See {@link https://www.easypost.com/docs/api/node#update-a-webhook EasyPost API Documentation} for more information. + * @param id - The ID of the webhook to update. + * @param params - The parameters to update the webhook with. + * @returns - The updated webhook. + */ + update( + id: string, + params: Partial, + ): Promise>; + /** + * Delete a {@link Webhook webhook}. + * See {@link https://www.easypost.com/docs/api/node#delete-a-webhook EasyPost API Documentation} for more information. + * @param id - The ID of the webhook to delete. + * @returns - A promise that resolves if the webhook was successfully deleted. + */ + delete(id: string): Promise; + /** + * Retrieve all {@link Webhook webhooks} associated with the current authenticated user. + * See {@link https://www.easypost.com/docs/api/node#list-a-webhooks EasyPost API Documentation} for more information. + * @param [params] + * @returns + */ + all(params?: IWebhookListParameters): Promise< + { + webhooks: IWebhook[]; + } & { + _params: any; + } & { + has_more: boolean; + } + >; + /** + * Retrieve a {@link Webhook webhook} by its ID. + * See {@link https://www.easypost.com/docs/api/node#retrieve-a-webhook EasyPost API Documentation} for more information. + * @param id - The ID of the webhook to retrieve. + * @returns - The retrieved webhook. + */ + retrieve(id: string): Promise>; + _convertToEasyPostObject( + response: A, + params?: any, + ): import('../base_service').EasyPostObject; + _create(url: string, params: object): Promise>; + _all( + url: string, + params?: Record, + ): Promise< + A_2 & { + _params: any; + } & { + has_more: boolean; + } + >; + _retrieve(url: string): Promise>; + _getNextPage>( + url: string, + key: keyof A_4, + collection: A_4, + pageSize?: number | null, + optionalParams?: Record, + ): Promise< + A_4 & { + _params: any; + } & { + has_more: boolean; + } + >; +}; +export default _default; diff --git a/types/src/utils/errors/Error.d.ts b/types/src/utils/errors/Error.d.ts new file mode 100644 index 000000000..d1289c644 --- /dev/null +++ b/types/src/utils/errors/Error.d.ts @@ -0,0 +1,24 @@ +import { TErrorCode } from './ErrorCode'; +import { IFieldError } from './FieldError'; +/** + * In the event of a client or server error, the response will contain the standard 4xx or 5xx respectively, accompanied by a well-formed JSON body describing the issue, e.g., a required field was omitted, a purchase failed, etc. + * + * Each client library will encapsulate these errors and raise an exception, in addition to other exceptional cases, such as network failures. + * It is recommended to handle exceptions gracefully and to report any issues to support@easypost.com. + * + * @see https://www.easypost.com/docs/api/node#error-object + */ +export type IError = { + /** + * Machine readable description of the problem + */ + code: TErrorCode; + /** + * Human readable description of the problem + */ + message: string; + /** + * Breakdown of errors for specific fields in the request + */ + errors: IFieldError[]; +}; diff --git a/types/src/utils/errors/ErrorCode.d.ts b/types/src/utils/errors/ErrorCode.d.ts new file mode 100644 index 000000000..04b10d2d1 --- /dev/null +++ b/types/src/utils/errors/ErrorCode.d.ts @@ -0,0 +1,173 @@ +export type TErrorCode = + | 'ADDRESS.COUNTRY.INVALID' + | 'ADDRESS.PARAMETERS.INVALID_CHARACTER' + | 'ADDRESS.PARAMETERS.INVALID' + | 'ADDRESS.VERIFICATION.FAILURE' + | 'ADDRESS.VERIFICATION.INVALID' + | 'ADDRESS.VERIFICATION.NOT_FOUND' + | 'ADDRESS.VERIFY.CARRIER_INVALID' + | 'ADDRESS.VERIFY.FAILURE' + | 'ADDRESS.VERIFY.INTL_NOT_ENABLED' + | 'ADDRESS.VERIFY.MISSING_CITY_STATE_ZIP' + | 'ADDRESS.VERIFY.MISSING_STREET' + | 'ADDRESS.VERIFY.ONLY_US' + | 'ADDRESS.VERIFY.UNAVAILABLE' + | 'ADDRESS.VERIFY.UPSTREAM_UNAVAILABLE' + | 'BAD_REQUEST' + | 'BANK_ACCOUNT.CHARGE.FAILURE' + | 'BANK_ACCOUNT.VERIFY.FAILURE' + /** + * The typo "FORAMT" is in both the docs and api error response. + * @link https://github.com/EasyPost/easypost-node/pull/156#discussion_r819811282 + */ + | 'BATCH.FILE_FORAMT.INVALID' + | 'BATCH.PARAMS.INVALID' + | 'BATCH.SHIPMENT.MISSING' + | 'BATCH.SHIPMENT.TOO_LARGE' + | 'BATCH.SHIPMENTS.REQUIRED' + | 'BATCH.STATE.ALREADY_PURCHASED' + | 'BATCH.STATE.CREATING' + | 'BATCH.STATE.CREATION_FAILED' + | 'BATCH.STATE.NOT_PURCHASED' + | 'CARRIER_ACCOUNT.INVALID' + | 'CARRIER_ACCOUNT.PARAMETERS.INVALID' + | 'CARRIER_ACCOUNT.REGISTRATION.FAILED' + | 'CARRIER_ACCOUNT.TYPE.EXISTS' + | 'CARRIER_ACCOUNT.TYPE.UNKNOWN' + | 'CONTAINER.DIMENSION.REQUIRED' + | 'CONTAINER.NAME.REQUIRED' + | 'CONTAINER.TYPE.INVALID' + | 'CREDIT_CARD.CHARGE.FAILURE' + | 'CREDIT_CARD.INVALID' + | 'CUSTOMS_INFO.PARAMETERS.INVALID' + | 'CUSTOMS_ITEM.CURRENCY.ONE_CURRENCY_SUPPORTED' + | 'CUSTOMS_ITEM.ORIGIN_COUNTRY.REQUIRED' + | 'CUSTOMS_ITEM.PARAMETERS.INVALID' + | 'DATE.PARSE.FAILURE' + | 'DHLGM.ACCESS_TOKEN.GENERATION_FAILED' + | 'DHLGM.GIRTH_MAX' + | 'DHLGM.LABEL.FAILURE' + | 'DHLGM.LETTER_NOT_SUPPORTED' + | 'DHLGM.NO_ALCOHOL' + | 'DHLGM.NO_INTERNATIONAL' + | 'DHLGM.RATE_TABLE.NOT_FOUND' + | 'DHLGM.RETURN.AUTHORIZATION_NUMBER_REQUIRED' + | 'DHLGM.SCAN_FORM.GENERATION_FAILED' + | 'DOCUMENT.COMMERCIAL_INVOICE.FAILURE' + | 'DOCUMENT.CONVERSION.FAILURE' + | 'EMAIL_VERIFICATION.EXPIRED' + | 'EMAIL_VERIFICATION.NOT_FOUND' + | 'EMAIL_VERIFICATION.USED' + | 'FORBIDDEN' + | 'IMAGE.CONVERSION.FAILURE' + | 'IMAGE.WIDTH.INVALID' + | 'INSURANCE.AMOUNT.ABOVE_MAXIMUM' + | 'INSURANCE.AMOUNT.BELOW_MINIMUM' + | 'INSURANCE.AMOUNT.REQUIRED' + | 'INSURANCE.CREATE.FAILURE' + | 'INSURANCE.PARAMETERS.INVALID' + | 'INSURANCE.PURCHASE.FAILED' + | 'INSURANCE.PURCHASE.NOT_ALLOWED' + | 'INTERNAL_SERVER_ERROR' + | 'ITEM.HEIGHT.REQUIRED' + | 'ITEM.LENGTH.REQUIRED' + | 'ITEM.NAME.REQUIRED' + | 'ITEM.VALUE.REQUIRED' + | 'ITEM.WEIGHT.REQUIRED' + | 'ITEM.WIDTH.REQUIRED' + | 'MODE.CONFLICT' + | 'MODE.UNAUTHORIZED' + | 'NOT_ACCEPTABLE' + | 'NOT_FOUND' + | 'ORDER.CARRIER_ACCOUNTS.CONFLICT' + | 'ORDER.CARRIER.REQUIRED' + | 'ORDER.FROM_ADDRESS.REQUIRED' + | 'ORDER.INVALID' + | 'ORDER.LABEL_DATE.INVALID' + | 'ORDER.OPTIONS.INVALID' + | 'ORDER.PARAMS.REQUIRED' + | 'ORDER.RATE.UNAVAILABLE' + | 'ORDER.SERVICE.REQUIRED' + | 'ORDER.SHIPMENTS.REQUIRED' + | 'ORDER.TO_ADDRESS.REQUIRED' + | 'PARAMETER.FORBIDDEN' + | 'PARAMETER.REQUIRED' + | 'PARCEL.PARAMETERS.INVALID' + | 'PARCEL.PREDEFINED_PACKAGE.INVALID' + | 'PAYMENT_GATEWAY.ERROR' + | 'PAYMENT_REQUIRED' + | 'PICKUP.ADDRESS.INVALID' + | 'PICKUP.ADDRESS.REQUIRED' + | 'PICKUP.BATCH_CARRIER.INCONSISTENT' + | 'PICKUP.BATCH.INVALID' + | 'PICKUP.BATCH.REQUIRED' + | 'PICKUP.BUY.FAILED' + | 'PICKUP.BUY.FORBIDDEN' + | 'PICKUP.BUY.NO_MATCHING_RATES' + | 'PICKUP.CANCEL.FAILED' + | 'PICKUP.CARRIER.REQUIRED' + | 'PICKUP.IS_ACCOUNT_ADDRESS.REQUIRED' + | 'PICKUP.MAX_DATETIME.REQUIRED' + | 'PICKUP.MIN_DATETIME.REQUIRED' + | 'PICKUP.REQUEST.INVALID' + | 'PICKUP.SERVICE.REQUIRED' + | 'PICKUP.SHIPMENT_COUNTRY.INVALID' + | 'PICKUP.SHIPMENT_SERVICE.INVALID' + | 'PICKUP.STATUS.INVALID' + | 'REFUND.FAILURE' + | 'REFUND.NO_RESPONSE' + | 'REFUND.TRACKING_CODE.NOT_FOUND' + | 'REFUND.TRACKING_CODES.INVALID' + | 'SCAN_FORM.BATCH.MULTIPLE_CARRIERS' + | 'SCAN_FORM.BATCH.NOT_PURCHASED' + | 'SCAN_FORM.CREATE.CARRIER_NOT_SUPPORTED' + | 'SCAN_FORM.CREATE.FAILURE' + | 'SCAN_FORM.FAILURE' + | 'SCAN_FORM.SHIPMENTS.INVALID' + | 'SCAN_FORM.SHIPMENTS.REQUIRED' + | 'SHIPMENT_REPORT.ALREADY_IN_PROGRESS' + | 'SHIPMENT_REPORT.DATE_RANGE.INVALID' + | 'SHIPMENT_REPORT.DATE_RANGE.TOO_LONG' + | 'SHIPMENT.CARRIER_ACCOUNTS.CONFLICT' + | 'SHIPMENT.CUSTOMS_INFO.DESCRIPTION_REQUIRED' + | 'SHIPMENT.CUSTOMS_INFO.REQUIRED' + | 'SHIPMENT.INSURANCE.ALREADY_PURCHASED' + | 'SHIPMENT.INVALID_PARAMS' + | 'SHIPMENT.INVALID' + | 'SHIPMENT.MISSING_INFORMATION' + | 'SHIPMENT.MISSING_RATE' + | 'SHIPMENT.OPTIONS.INVALID' + | 'SHIPMENT.POSTAGE.ASCII' + | 'SHIPMENT.POSTAGE.EXISTS' + | 'SHIPMENT.POSTAGE.FAILURE' + | 'SHIPMENT.POSTAGE.FORMAT_UNAVAILABLE' + | 'SHIPMENT.POSTAGE.INVALID_FORMAT' + | 'SHIPMENT.POSTAGE.NO_RESPONSE' + | 'SHIPMENT.POSTAGE.REQUIRED' + | 'SHIPMENT.PURCHASE.FAILURE' + | 'SHIPMENT.PURCHASE.IN_PROGRESS' + | 'SHIPMENT.RATE.BARCODE_UNAVAILABLE' + | 'SHIPMENT.RATE.CARRIER_ACCOUNT_INVALID' + | 'SHIPMENT.RATE.STAMP_UNAVAILABLE' + | 'SHIPMENT.RATES.UNAVAILABLE' + | 'SHIPMENT.REFUND.FAILURE' + | 'SHIPMENT.REFUND.UNAVAILABLE' + | 'SHIPMENT.TRACKING_CODE.INVALID_CARRIER' + | 'TRACKER.CARRIER_CODE_MISMATCH' + | 'TRACKER.CREATE.ERROR' + | 'TRACKER.INVALID_PARAMS' + | 'TRACKER.INVALID_TEST_CODE' + | 'TRACKER.MULTIPLE_CARRIERS_FOR_CODE' + | 'TRACKER.NO_CARRIER_ACCOUNT' + | 'TRACKER.NO_CARRIER_FOR_CODE' + | 'TRACKER.NOT_FOUND' + | 'TRACKER.RETRIEVE.ERROR' + | 'TRACKER.RUN.ERROR' + | 'TRACKER.UNSUPPORTED_CARRIER' + | 'UNAUTHORIZED' + | 'USER.CHARGE.NOT_ALLOWED' + | 'USER.INVALID' + | 'USER.PARENT.INVALID' + | 'USER.UNAUTHORIZED' + | 'WEBHOOK.EVENT.INVALID' + | 'WEBHOOK.INVALID'; diff --git a/types/src/utils/errors/FieldError.d.ts b/types/src/utils/errors/FieldError.d.ts new file mode 100644 index 000000000..e7ae33219 --- /dev/null +++ b/types/src/utils/errors/FieldError.d.ts @@ -0,0 +1,10 @@ +export type IFieldError = { + /** + * Field of the request that the error describes + */ + field: string; + /** + * Human readable description of the problem + */ + message: string; +}; diff --git a/types/src/utils/errors/index.d.ts b/types/src/utils/errors/index.d.ts new file mode 100644 index 000000000..d6c2ac5d8 --- /dev/null +++ b/types/src/utils/errors/index.d.ts @@ -0,0 +1,3 @@ +export * from './Error'; +export * from './ErrorCode'; +export * from './FieldError'; diff --git a/types/src/utils/types.d.ts b/types/src/utils/types.d.ts new file mode 100644 index 000000000..0dd02ce86 --- /dev/null +++ b/types/src/utils/types.d.ts @@ -0,0 +1,62 @@ +export type DeepPartial = { + [P in keyof T]?: DeepPartial; +}; +export type ParametersToOmitOnCreate = 'id' | 'object' | 'mode' | 'created_at' | 'updated_at'; +export type IAllMethodParameters = { + /** + * Optional pagination parameter. + * Only records created before the given ID will be included. + * May not be used with after_id + */ + before_id?: string; + /** + * Optional pagination parameter. + * Only records created after the given ID will be included. + * May not be used with before_id + */ + after_id?: string; + /** + * Only return records created after this timestamp. + * Defaults to 1 month ago, or 1 month before a passed end_datetime + */ + start_datetime?: string; + /** + * Only return records created before this timestamp. + * Defaults to end of the current day, or 1 month after a passed start_datetime + */ + end_datetime?: string; + /** + * The number of records to return on each page. + * The maximum value is 100 + */ + page_size?: number; +}; +export type IDatedObject = { + /** + * Date ISO String + */ + created_at: string; + /** + * Date ISO String + */ + updated_at: string; +}; +export type IBaseObject = { + object: ObjectName; +}; +export type IObjectWithId = IBaseObject & { + /** + * Unique identifier, begins with "adr_" / "prcl_" / "ins_" / "trk_" / "batch_" / "cstinfo_" / etc + */ + id: string; + /** + * Set based on which api-key you used, either "test" or "production" + */ + mode: 'test' | 'production'; + /** + * The object name, e.g. "Address", "Rate", "Shipment", etc + */ + object: ObjectName; +}; +declare const _default: {}; +export default _default; diff --git a/types/src/utils/util.d.ts b/types/src/utils/util.d.ts new file mode 100644 index 000000000..31c07616b --- /dev/null +++ b/types/src/utils/util.d.ts @@ -0,0 +1,47 @@ +/// +import { IRate, ISmartRate } from '../services/rate_service'; +/** + * Utility class of various publicly-available helper functions. + * @public + * @type {Utils} + */ +export default class Utils { + /** + * Get the lowest SmartRate from a provided list of SmartRates. + * @public + * @param smartRates - List of SmartRates to filter through + * @param deliveryDays - The maximum number of days allowed for delivery + * @param deliveryAccuracy - The target level of accuracy for the delivery days (e.g. 'percentile_50') + * @returns - The lowest SmartRate + * @throws {FilteringError} - If no applicable rates are found + * @throws {InvalidParameterError} - If the deliveryAccuracy value is invalid + */ + getLowestSmartRate( + smartRates: ISmartRate[], + deliveryDays: number, + deliveryAccuracy: keyof ISmartRate['time_in_transit'], + ): ISmartRate; + /** + * Get the lowest rate from a provided list of rates. + * @public + * @param rates - List of rates to filter through + * @param [carriers] - List of allowed carriers to filter by + * @param [services] - List of allowed services to filter by + * @returns - The lowest rate + * @throws {FilteringError} - If no applicable rates are found + */ + getLowestRate(rates: IRate[], carriers?: string[] | null, services?: string[] | null): IRate; + /** + * Validate a webhook by comparing the HMAC signature header sent from EasyPost to your shared secret. + * If the signatures do not match, an error will be raised signifying the webhook either did not originate + * from EasyPost or the secrets do not match. If the signatures do match, the `event_body` will be returned + * as JSON. + * @public + * @param eventBody - The raw body of the webhook event + * @param headers - The headers of the webhook HTTP request + * @param webhookSecret - The webhook secret shared between EasyPost and your application + * @returns - The JSON-parsed webhook event body if the signature could be verified + * @throws {SignatureVerificationError} - If the signature could not be verified + */ + validateWebhook(eventBody: Buffer, headers: Record, webhookSecret: string): any; +} diff --git a/types/utils/errors/Error.d.ts b/types/utils/errors/Error.d.ts new file mode 100644 index 000000000..d1289c644 --- /dev/null +++ b/types/utils/errors/Error.d.ts @@ -0,0 +1,24 @@ +import { TErrorCode } from './ErrorCode'; +import { IFieldError } from './FieldError'; +/** + * In the event of a client or server error, the response will contain the standard 4xx or 5xx respectively, accompanied by a well-formed JSON body describing the issue, e.g., a required field was omitted, a purchase failed, etc. + * + * Each client library will encapsulate these errors and raise an exception, in addition to other exceptional cases, such as network failures. + * It is recommended to handle exceptions gracefully and to report any issues to support@easypost.com. + * + * @see https://www.easypost.com/docs/api/node#error-object + */ +export type IError = { + /** + * Machine readable description of the problem + */ + code: TErrorCode; + /** + * Human readable description of the problem + */ + message: string; + /** + * Breakdown of errors for specific fields in the request + */ + errors: IFieldError[]; +}; diff --git a/types/utils/errors/ErrorCode.d.ts b/types/utils/errors/ErrorCode.d.ts new file mode 100644 index 000000000..04b10d2d1 --- /dev/null +++ b/types/utils/errors/ErrorCode.d.ts @@ -0,0 +1,173 @@ +export type TErrorCode = + | 'ADDRESS.COUNTRY.INVALID' + | 'ADDRESS.PARAMETERS.INVALID_CHARACTER' + | 'ADDRESS.PARAMETERS.INVALID' + | 'ADDRESS.VERIFICATION.FAILURE' + | 'ADDRESS.VERIFICATION.INVALID' + | 'ADDRESS.VERIFICATION.NOT_FOUND' + | 'ADDRESS.VERIFY.CARRIER_INVALID' + | 'ADDRESS.VERIFY.FAILURE' + | 'ADDRESS.VERIFY.INTL_NOT_ENABLED' + | 'ADDRESS.VERIFY.MISSING_CITY_STATE_ZIP' + | 'ADDRESS.VERIFY.MISSING_STREET' + | 'ADDRESS.VERIFY.ONLY_US' + | 'ADDRESS.VERIFY.UNAVAILABLE' + | 'ADDRESS.VERIFY.UPSTREAM_UNAVAILABLE' + | 'BAD_REQUEST' + | 'BANK_ACCOUNT.CHARGE.FAILURE' + | 'BANK_ACCOUNT.VERIFY.FAILURE' + /** + * The typo "FORAMT" is in both the docs and api error response. + * @link https://github.com/EasyPost/easypost-node/pull/156#discussion_r819811282 + */ + | 'BATCH.FILE_FORAMT.INVALID' + | 'BATCH.PARAMS.INVALID' + | 'BATCH.SHIPMENT.MISSING' + | 'BATCH.SHIPMENT.TOO_LARGE' + | 'BATCH.SHIPMENTS.REQUIRED' + | 'BATCH.STATE.ALREADY_PURCHASED' + | 'BATCH.STATE.CREATING' + | 'BATCH.STATE.CREATION_FAILED' + | 'BATCH.STATE.NOT_PURCHASED' + | 'CARRIER_ACCOUNT.INVALID' + | 'CARRIER_ACCOUNT.PARAMETERS.INVALID' + | 'CARRIER_ACCOUNT.REGISTRATION.FAILED' + | 'CARRIER_ACCOUNT.TYPE.EXISTS' + | 'CARRIER_ACCOUNT.TYPE.UNKNOWN' + | 'CONTAINER.DIMENSION.REQUIRED' + | 'CONTAINER.NAME.REQUIRED' + | 'CONTAINER.TYPE.INVALID' + | 'CREDIT_CARD.CHARGE.FAILURE' + | 'CREDIT_CARD.INVALID' + | 'CUSTOMS_INFO.PARAMETERS.INVALID' + | 'CUSTOMS_ITEM.CURRENCY.ONE_CURRENCY_SUPPORTED' + | 'CUSTOMS_ITEM.ORIGIN_COUNTRY.REQUIRED' + | 'CUSTOMS_ITEM.PARAMETERS.INVALID' + | 'DATE.PARSE.FAILURE' + | 'DHLGM.ACCESS_TOKEN.GENERATION_FAILED' + | 'DHLGM.GIRTH_MAX' + | 'DHLGM.LABEL.FAILURE' + | 'DHLGM.LETTER_NOT_SUPPORTED' + | 'DHLGM.NO_ALCOHOL' + | 'DHLGM.NO_INTERNATIONAL' + | 'DHLGM.RATE_TABLE.NOT_FOUND' + | 'DHLGM.RETURN.AUTHORIZATION_NUMBER_REQUIRED' + | 'DHLGM.SCAN_FORM.GENERATION_FAILED' + | 'DOCUMENT.COMMERCIAL_INVOICE.FAILURE' + | 'DOCUMENT.CONVERSION.FAILURE' + | 'EMAIL_VERIFICATION.EXPIRED' + | 'EMAIL_VERIFICATION.NOT_FOUND' + | 'EMAIL_VERIFICATION.USED' + | 'FORBIDDEN' + | 'IMAGE.CONVERSION.FAILURE' + | 'IMAGE.WIDTH.INVALID' + | 'INSURANCE.AMOUNT.ABOVE_MAXIMUM' + | 'INSURANCE.AMOUNT.BELOW_MINIMUM' + | 'INSURANCE.AMOUNT.REQUIRED' + | 'INSURANCE.CREATE.FAILURE' + | 'INSURANCE.PARAMETERS.INVALID' + | 'INSURANCE.PURCHASE.FAILED' + | 'INSURANCE.PURCHASE.NOT_ALLOWED' + | 'INTERNAL_SERVER_ERROR' + | 'ITEM.HEIGHT.REQUIRED' + | 'ITEM.LENGTH.REQUIRED' + | 'ITEM.NAME.REQUIRED' + | 'ITEM.VALUE.REQUIRED' + | 'ITEM.WEIGHT.REQUIRED' + | 'ITEM.WIDTH.REQUIRED' + | 'MODE.CONFLICT' + | 'MODE.UNAUTHORIZED' + | 'NOT_ACCEPTABLE' + | 'NOT_FOUND' + | 'ORDER.CARRIER_ACCOUNTS.CONFLICT' + | 'ORDER.CARRIER.REQUIRED' + | 'ORDER.FROM_ADDRESS.REQUIRED' + | 'ORDER.INVALID' + | 'ORDER.LABEL_DATE.INVALID' + | 'ORDER.OPTIONS.INVALID' + | 'ORDER.PARAMS.REQUIRED' + | 'ORDER.RATE.UNAVAILABLE' + | 'ORDER.SERVICE.REQUIRED' + | 'ORDER.SHIPMENTS.REQUIRED' + | 'ORDER.TO_ADDRESS.REQUIRED' + | 'PARAMETER.FORBIDDEN' + | 'PARAMETER.REQUIRED' + | 'PARCEL.PARAMETERS.INVALID' + | 'PARCEL.PREDEFINED_PACKAGE.INVALID' + | 'PAYMENT_GATEWAY.ERROR' + | 'PAYMENT_REQUIRED' + | 'PICKUP.ADDRESS.INVALID' + | 'PICKUP.ADDRESS.REQUIRED' + | 'PICKUP.BATCH_CARRIER.INCONSISTENT' + | 'PICKUP.BATCH.INVALID' + | 'PICKUP.BATCH.REQUIRED' + | 'PICKUP.BUY.FAILED' + | 'PICKUP.BUY.FORBIDDEN' + | 'PICKUP.BUY.NO_MATCHING_RATES' + | 'PICKUP.CANCEL.FAILED' + | 'PICKUP.CARRIER.REQUIRED' + | 'PICKUP.IS_ACCOUNT_ADDRESS.REQUIRED' + | 'PICKUP.MAX_DATETIME.REQUIRED' + | 'PICKUP.MIN_DATETIME.REQUIRED' + | 'PICKUP.REQUEST.INVALID' + | 'PICKUP.SERVICE.REQUIRED' + | 'PICKUP.SHIPMENT_COUNTRY.INVALID' + | 'PICKUP.SHIPMENT_SERVICE.INVALID' + | 'PICKUP.STATUS.INVALID' + | 'REFUND.FAILURE' + | 'REFUND.NO_RESPONSE' + | 'REFUND.TRACKING_CODE.NOT_FOUND' + | 'REFUND.TRACKING_CODES.INVALID' + | 'SCAN_FORM.BATCH.MULTIPLE_CARRIERS' + | 'SCAN_FORM.BATCH.NOT_PURCHASED' + | 'SCAN_FORM.CREATE.CARRIER_NOT_SUPPORTED' + | 'SCAN_FORM.CREATE.FAILURE' + | 'SCAN_FORM.FAILURE' + | 'SCAN_FORM.SHIPMENTS.INVALID' + | 'SCAN_FORM.SHIPMENTS.REQUIRED' + | 'SHIPMENT_REPORT.ALREADY_IN_PROGRESS' + | 'SHIPMENT_REPORT.DATE_RANGE.INVALID' + | 'SHIPMENT_REPORT.DATE_RANGE.TOO_LONG' + | 'SHIPMENT.CARRIER_ACCOUNTS.CONFLICT' + | 'SHIPMENT.CUSTOMS_INFO.DESCRIPTION_REQUIRED' + | 'SHIPMENT.CUSTOMS_INFO.REQUIRED' + | 'SHIPMENT.INSURANCE.ALREADY_PURCHASED' + | 'SHIPMENT.INVALID_PARAMS' + | 'SHIPMENT.INVALID' + | 'SHIPMENT.MISSING_INFORMATION' + | 'SHIPMENT.MISSING_RATE' + | 'SHIPMENT.OPTIONS.INVALID' + | 'SHIPMENT.POSTAGE.ASCII' + | 'SHIPMENT.POSTAGE.EXISTS' + | 'SHIPMENT.POSTAGE.FAILURE' + | 'SHIPMENT.POSTAGE.FORMAT_UNAVAILABLE' + | 'SHIPMENT.POSTAGE.INVALID_FORMAT' + | 'SHIPMENT.POSTAGE.NO_RESPONSE' + | 'SHIPMENT.POSTAGE.REQUIRED' + | 'SHIPMENT.PURCHASE.FAILURE' + | 'SHIPMENT.PURCHASE.IN_PROGRESS' + | 'SHIPMENT.RATE.BARCODE_UNAVAILABLE' + | 'SHIPMENT.RATE.CARRIER_ACCOUNT_INVALID' + | 'SHIPMENT.RATE.STAMP_UNAVAILABLE' + | 'SHIPMENT.RATES.UNAVAILABLE' + | 'SHIPMENT.REFUND.FAILURE' + | 'SHIPMENT.REFUND.UNAVAILABLE' + | 'SHIPMENT.TRACKING_CODE.INVALID_CARRIER' + | 'TRACKER.CARRIER_CODE_MISMATCH' + | 'TRACKER.CREATE.ERROR' + | 'TRACKER.INVALID_PARAMS' + | 'TRACKER.INVALID_TEST_CODE' + | 'TRACKER.MULTIPLE_CARRIERS_FOR_CODE' + | 'TRACKER.NO_CARRIER_ACCOUNT' + | 'TRACKER.NO_CARRIER_FOR_CODE' + | 'TRACKER.NOT_FOUND' + | 'TRACKER.RETRIEVE.ERROR' + | 'TRACKER.RUN.ERROR' + | 'TRACKER.UNSUPPORTED_CARRIER' + | 'UNAUTHORIZED' + | 'USER.CHARGE.NOT_ALLOWED' + | 'USER.INVALID' + | 'USER.PARENT.INVALID' + | 'USER.UNAUTHORIZED' + | 'WEBHOOK.EVENT.INVALID' + | 'WEBHOOK.INVALID'; diff --git a/types/utils/errors/FieldError.d.ts b/types/utils/errors/FieldError.d.ts new file mode 100644 index 000000000..e7ae33219 --- /dev/null +++ b/types/utils/errors/FieldError.d.ts @@ -0,0 +1,10 @@ +export type IFieldError = { + /** + * Field of the request that the error describes + */ + field: string; + /** + * Human readable description of the problem + */ + message: string; +}; diff --git a/types/utils/errors/index.d.ts b/types/utils/errors/index.d.ts new file mode 100644 index 000000000..d6c2ac5d8 --- /dev/null +++ b/types/utils/errors/index.d.ts @@ -0,0 +1,3 @@ +export * from './Error'; +export * from './ErrorCode'; +export * from './FieldError'; diff --git a/types/utils/types.d.ts b/types/utils/types.d.ts new file mode 100644 index 000000000..0dd02ce86 --- /dev/null +++ b/types/utils/types.d.ts @@ -0,0 +1,62 @@ +export type DeepPartial = { + [P in keyof T]?: DeepPartial; +}; +export type ParametersToOmitOnCreate = 'id' | 'object' | 'mode' | 'created_at' | 'updated_at'; +export type IAllMethodParameters = { + /** + * Optional pagination parameter. + * Only records created before the given ID will be included. + * May not be used with after_id + */ + before_id?: string; + /** + * Optional pagination parameter. + * Only records created after the given ID will be included. + * May not be used with before_id + */ + after_id?: string; + /** + * Only return records created after this timestamp. + * Defaults to 1 month ago, or 1 month before a passed end_datetime + */ + start_datetime?: string; + /** + * Only return records created before this timestamp. + * Defaults to end of the current day, or 1 month after a passed start_datetime + */ + end_datetime?: string; + /** + * The number of records to return on each page. + * The maximum value is 100 + */ + page_size?: number; +}; +export type IDatedObject = { + /** + * Date ISO String + */ + created_at: string; + /** + * Date ISO String + */ + updated_at: string; +}; +export type IBaseObject = { + object: ObjectName; +}; +export type IObjectWithId = IBaseObject & { + /** + * Unique identifier, begins with "adr_" / "prcl_" / "ins_" / "trk_" / "batch_" / "cstinfo_" / etc + */ + id: string; + /** + * Set based on which api-key you used, either "test" or "production" + */ + mode: 'test' | 'production'; + /** + * The object name, e.g. "Address", "Rate", "Shipment", etc + */ + object: ObjectName; +}; +declare const _default: {}; +export default _default; diff --git a/types/utils/util.d.ts b/types/utils/util.d.ts new file mode 100644 index 000000000..31c07616b --- /dev/null +++ b/types/utils/util.d.ts @@ -0,0 +1,47 @@ +/// +import { IRate, ISmartRate } from '../services/rate_service'; +/** + * Utility class of various publicly-available helper functions. + * @public + * @type {Utils} + */ +export default class Utils { + /** + * Get the lowest SmartRate from a provided list of SmartRates. + * @public + * @param smartRates - List of SmartRates to filter through + * @param deliveryDays - The maximum number of days allowed for delivery + * @param deliveryAccuracy - The target level of accuracy for the delivery days (e.g. 'percentile_50') + * @returns - The lowest SmartRate + * @throws {FilteringError} - If no applicable rates are found + * @throws {InvalidParameterError} - If the deliveryAccuracy value is invalid + */ + getLowestSmartRate( + smartRates: ISmartRate[], + deliveryDays: number, + deliveryAccuracy: keyof ISmartRate['time_in_transit'], + ): ISmartRate; + /** + * Get the lowest rate from a provided list of rates. + * @public + * @param rates - List of rates to filter through + * @param [carriers] - List of allowed carriers to filter by + * @param [services] - List of allowed services to filter by + * @returns - The lowest rate + * @throws {FilteringError} - If no applicable rates are found + */ + getLowestRate(rates: IRate[], carriers?: string[] | null, services?: string[] | null): IRate; + /** + * Validate a webhook by comparing the HMAC signature header sent from EasyPost to your shared secret. + * If the signatures do not match, an error will be raised signifying the webhook either did not originate + * from EasyPost or the secrets do not match. If the signatures do match, the `event_body` will be returned + * as JSON. + * @public + * @param eventBody - The raw body of the webhook event + * @param headers - The headers of the webhook HTTP request + * @param webhookSecret - The webhook secret shared between EasyPost and your application + * @returns - The JSON-parsed webhook event body if the signature could be verified + * @throws {SignatureVerificationError} - If the signature could not be verified + */ + validateWebhook(eventBody: Buffer, headers: Record, webhookSecret: string): any; +} From 80fcd4dbe239fd62fcf817c3e194ba5ba4923e5a Mon Sep 17 00:00:00 2001 From: Alex Matthews Date: Wed, 15 May 2024 15:09:35 -0500 Subject: [PATCH 3/7] Removes out and types --- .gitignore | 2 +- types/constants.d.ts | 20 - types/easypost.d.ts | 260 -------- types/errors/api/api_error.d.ts | 29 - types/errors/api/bad_request_error.d.ts | 11 - types/errors/api/external_api_error.d.ts | 9 - types/errors/api/forbidden_error.d.ts | 11 - types/errors/api/gateway_timeout_error.d.ts | 11 - types/errors/api/http_error.d.ts | 10 - types/errors/api/index.d.ts | 18 - types/errors/api/internal_server_error.d.ts | 11 - types/errors/api/invalid_request_error.d.ts | 11 - .../errors/api/method_not_allowed_error.d.ts | 11 - types/errors/api/not_found_error.d.ts | 11 - types/errors/api/payment_error.d.ts | 11 - types/errors/api/rate_limit_error.d.ts | 11 - types/errors/api/redirect_error.d.ts | 11 - .../errors/api/service_unavailable_error.d.ts | 11 - types/errors/api/timeout_error.d.ts | 11 - types/errors/api/unauthorized_error.d.ts | 11 - types/errors/api/unknown_api_error.d.ts | 11 - types/errors/easypost_error.d.ts | 12 - types/errors/error_handler.d.ts | 33 - .../general/end_of_pagination_error.d.ts | 10 - types/errors/general/filtering_error.d.ts | 8 - types/errors/general/index.d.ts | 6 - .../errors/general/invalid_object_error.d.ts | 8 - .../general/invalid_parameter_error.d.ts | 8 - .../general/missing_parameter_error.d.ts | 8 - .../general/signature_verification_error.d.ts | 8 - types/errors/index.d.ts | 4 - types/index.d.ts | 2 - types/services/address_service/Address.d.ts | 72 --- .../AddressCreateParameters.d.ts | 22 - .../AddressListParameters.d.ts | 5 - .../address_service/Verification.d.ts | 19 - .../address_service/VerificationDetails.d.ts | 17 - .../address_service/Verifications.d.ts | 16 - types/services/address_service/index.d.ts | 105 --- types/services/api_key_service/ApiKey.d.ts | 20 - types/services/api_key_service/index.d.ts | 71 -- types/services/base_service.d.ts | 71 -- types/services/batch_service/Batch.d.ts | 48 -- .../batch_service/BatchCreateParameters.d.ts | 8 - .../batch_service/BatchListParameters.d.ts | 5 - .../services/batch_service/BatchShipment.d.ts | 22 - types/services/batch_service/BatchState.d.ts | 9 - types/services/batch_service/BatchStatus.d.ts | 6 - .../services/batch_service/BatchStatuses.d.ts | 4 - types/services/batch_service/index.d.ts | 132 ---- types/services/beta_rate_service/index.d.ts | 44 -- .../beta_referral_customer_service/index.d.ts | 60 -- .../billing_service/PaymentMethod.d.ts | 44 -- types/services/billing_service/index.d.ts | 63 -- .../CarrierAccount.d.ts | 53 -- .../CarrierAccountCreateParameters.d.ts | 3 - .../CarrierAccountField.d.ts | 21 - .../CarrierAccountFields.d.ts | 22 - .../carrier_account_service/index.d.ts | 116 ---- .../CarrierMetadata.d.ts | 34 - .../carrier_metadata_service/index.d.ts | 46 -- .../carrier_type_service/CarrierType.d.ts | 27 - .../CarrierTypeCredentials.d.ts | 17 - .../CarrierTypeFields.d.ts | 23 - .../services/carrier_type_service/index.d.ts | 45 -- .../customs_info_service/CustomsInfo.d.ts | 55 -- .../CustomsInfoCreateParameters.d.ts | 3 - .../services/customs_info_service/index.d.ts | 54 -- .../customs_item_service/CustomsItem.d.ts | 46 -- .../CustomsItemCreateParameters.d.ts | 3 - .../services/customs_item_service/index.d.ts | 54 -- .../end_shipper_service/EndShipper.d.ts | 52 -- .../EndShipperCreateParameters.d.ts | 3 - .../EndShipperListParameters.d.ts | 5 - types/services/end_shipper_service/index.d.ts | 80 --- types/services/event_service/Event.d.ts | 40 -- .../event_service/EventListParameters.d.ts | 5 - .../event_service/Payload/Payload.d.ts | 14 - .../Payload/PayloadListParameters.d.ts | 5 - .../services/event_service/Payload/index.d.ts | 1 - types/services/event_service/index.d.ts | 96 --- types/services/index.d.ts | 27 - types/services/insurance_service/Fee.d.ts | 31 - types/services/insurance_service/FeeType.d.ts | 1 - .../services/insurance_service/Insurance.d.ts | 73 --- .../InsuranceCreateParameters.d.ts | 22 - .../insurance_service/InsuranceStatus.d.ts | 1 - types/services/insurance_service/index.d.ts | 89 --- types/services/order_service/Order.d.ts | 53 -- .../order_service/OrderCreateParameters.d.ts | 12 - types/services/order_service/index.d.ts | 79 --- types/services/parcel_service/Parcel.d.ts | 38 -- .../ParcelCreateParameters.d.ts | 24 - types/services/parcel_service/index.d.ts | 54 -- types/services/pickup_service/Pickup.d.ts | 77 --- .../PickupCreateParameters.d.ts | 37 -- .../pickup_service/PickupListParameters.d.ts | 5 - types/services/pickup_service/PickupRate.d.ts | 27 - types/services/pickup_service/index.d.ts | 110 ---- types/services/rate_service/Rate.d.ts | 81 --- types/services/rate_service/index.d.ts | 43 -- .../referral_customer_service/Referral.d.ts | 7 - .../ReferralCreateParameters.d.ts | 3 - .../ReferralListParameters.d.ts | 5 - .../referral_customer_service/index.d.ts | 108 ---- types/services/refund_service/Refund.d.ts | 31 - .../RefundCreateParameters.d.ts | 13 - .../refund_service/RefundListParameters.d.ts | 5 - types/services/refund_service/index.d.ts | 89 --- types/services/report_service/Report.d.ts | 52 -- .../ReportCreateParameters.d.ts | 10 - .../report_service/ReportListParameters.d.ts | 8 - .../report_service/ReportObjectType.d.ts | 14 - types/services/report_service/index.d.ts | 82 --- .../services/scan_form_service/ScanForm.d.ts | 47 -- .../ScanFormCreateParameters.d.ts | 9 - .../ScanFormListParameters.d.ts | 5 - types/services/scan_form_service/index.d.ts | 91 --- types/services/shipment_service/Form.d.ts | 28 - types/services/shipment_service/Message.d.ts | 27 - .../shipment_service/Options/LabelFormat.d.ts | 1 - .../shipment_service/Options/Options.d.ts | 325 ---------- .../Options/PrintCustomCode.d.ts | 52 -- .../shipment_service/Options/index.d.ts | 3 - .../shipment_service/PostageLabel.d.ts | 18 - types/services/shipment_service/Shipment.d.ts | 124 ---- .../ShipmentCreateParameters.d.ts | 17 - .../ShipmentListParameters.d.ts | 16 - types/services/shipment_service/index.d.ts | 605 ------------------ .../tracker_service/CarrierDetail.d.ts | 51 -- types/services/tracker_service/Tracker.d.ts | 86 --- .../TrackerCreateParameters.d.ts | 11 - .../TrackerListParameters.d.ts | 12 - .../tracker_service/TrackerStatus.d.ts | 11 - .../tracker_service/TrackerStatusDetail.d.ts | 29 - .../tracker_service/TrackingDetail.d.ts | 28 - .../tracker_service/TrackingLocation.d.ts | 22 - types/services/tracker_service/index.d.ts | 102 --- types/services/user_service/Brand.d.ts | 40 -- types/services/user_service/User.d.ts | 64 -- .../user_service/UserCreateParameters.d.ts | 3 - types/services/user_service/index.d.ts | 126 ---- types/services/webhook_service/Webhook.d.ts | 28 - .../WebhookCreateParameters.d.ts | 3 - .../WebhookListParameters.d.ts | 5 - types/services/webhook_service/index.d.ts | 90 --- types/src/constants.d.ts | 20 - types/src/easypost.d.ts | 260 -------- types/src/errors/api/api_error.d.ts | 29 - types/src/errors/api/bad_request_error.d.ts | 11 - types/src/errors/api/external_api_error.d.ts | 9 - types/src/errors/api/forbidden_error.d.ts | 11 - .../src/errors/api/gateway_timeout_error.d.ts | 11 - types/src/errors/api/http_error.d.ts | 10 - types/src/errors/api/index.d.ts | 18 - .../src/errors/api/internal_server_error.d.ts | 11 - .../src/errors/api/invalid_request_error.d.ts | 11 - .../errors/api/method_not_allowed_error.d.ts | 11 - types/src/errors/api/not_found_error.d.ts | 11 - types/src/errors/api/payment_error.d.ts | 11 - types/src/errors/api/rate_limit_error.d.ts | 11 - types/src/errors/api/redirect_error.d.ts | 11 - .../errors/api/service_unavailable_error.d.ts | 11 - types/src/errors/api/timeout_error.d.ts | 11 - types/src/errors/api/unauthorized_error.d.ts | 11 - types/src/errors/api/unknown_api_error.d.ts | 11 - types/src/errors/easypost_error.d.ts | 12 - types/src/errors/error_handler.d.ts | 33 - .../general/end_of_pagination_error.d.ts | 10 - types/src/errors/general/filtering_error.d.ts | 8 - types/src/errors/general/index.d.ts | 6 - .../errors/general/invalid_object_error.d.ts | 8 - .../general/invalid_parameter_error.d.ts | 8 - .../general/missing_parameter_error.d.ts | 8 - .../general/signature_verification_error.d.ts | 8 - types/src/errors/index.d.ts | 4 - types/src/index.d.ts | 2 - .../src/services/address_service/Address.d.ts | 72 --- .../AddressCreateParameters.d.ts | 22 - .../AddressListParameters.d.ts | 5 - .../address_service/Verification.d.ts | 19 - .../address_service/VerificationDetails.d.ts | 17 - .../address_service/Verifications.d.ts | 16 - types/src/services/address_service/index.d.ts | 105 --- .../src/services/api_key_service/ApiKey.d.ts | 20 - types/src/services/api_key_service/index.d.ts | 71 -- types/src/services/base_service.d.ts | 71 -- types/src/services/batch_service/Batch.d.ts | 48 -- .../batch_service/BatchCreateParameters.d.ts | 8 - .../batch_service/BatchListParameters.d.ts | 5 - .../services/batch_service/BatchShipment.d.ts | 22 - .../services/batch_service/BatchState.d.ts | 9 - .../services/batch_service/BatchStatus.d.ts | 6 - .../services/batch_service/BatchStatuses.d.ts | 4 - types/src/services/batch_service/index.d.ts | 132 ---- .../src/services/beta_rate_service/index.d.ts | 44 -- .../beta_referral_customer_service/index.d.ts | 60 -- .../billing_service/PaymentMethod.d.ts | 44 -- types/src/services/billing_service/index.d.ts | 63 -- .../CarrierAccount.d.ts | 53 -- .../CarrierAccountCreateParameters.d.ts | 3 - .../CarrierAccountField.d.ts | 21 - .../CarrierAccountFields.d.ts | 22 - .../carrier_account_service/index.d.ts | 116 ---- .../CarrierMetadata.d.ts | 34 - .../carrier_metadata_service/index.d.ts | 46 -- .../carrier_type_service/CarrierType.d.ts | 27 - .../CarrierTypeCredentials.d.ts | 17 - .../CarrierTypeFields.d.ts | 23 - .../services/carrier_type_service/index.d.ts | 45 -- .../customs_info_service/CustomsInfo.d.ts | 55 -- .../CustomsInfoCreateParameters.d.ts | 3 - .../services/customs_info_service/index.d.ts | 54 -- .../customs_item_service/CustomsItem.d.ts | 46 -- .../CustomsItemCreateParameters.d.ts | 3 - .../services/customs_item_service/index.d.ts | 54 -- .../end_shipper_service/EndShipper.d.ts | 52 -- .../EndShipperCreateParameters.d.ts | 3 - .../EndShipperListParameters.d.ts | 5 - .../services/end_shipper_service/index.d.ts | 80 --- types/src/services/event_service/Event.d.ts | 40 -- .../event_service/EventListParameters.d.ts | 5 - .../event_service/Payload/Payload.d.ts | 14 - .../Payload/PayloadListParameters.d.ts | 5 - .../services/event_service/Payload/index.d.ts | 1 - types/src/services/event_service/index.d.ts | 96 --- types/src/services/index.d.ts | 27 - types/src/services/insurance_service/Fee.d.ts | 31 - .../services/insurance_service/FeeType.d.ts | 1 - .../services/insurance_service/Insurance.d.ts | 73 --- .../InsuranceCreateParameters.d.ts | 22 - .../insurance_service/InsuranceStatus.d.ts | 1 - .../src/services/insurance_service/index.d.ts | 89 --- types/src/services/order_service/Order.d.ts | 53 -- .../order_service/OrderCreateParameters.d.ts | 12 - types/src/services/order_service/index.d.ts | 79 --- types/src/services/parcel_service/Parcel.d.ts | 38 -- .../ParcelCreateParameters.d.ts | 24 - types/src/services/parcel_service/index.d.ts | 54 -- types/src/services/pickup_service/Pickup.d.ts | 77 --- .../PickupCreateParameters.d.ts | 37 -- .../pickup_service/PickupListParameters.d.ts | 5 - .../services/pickup_service/PickupRate.d.ts | 27 - types/src/services/pickup_service/index.d.ts | 110 ---- types/src/services/rate_service/Rate.d.ts | 81 --- types/src/services/rate_service/index.d.ts | 43 -- .../referral_customer_service/Referral.d.ts | 7 - .../ReferralCreateParameters.d.ts | 3 - .../ReferralListParameters.d.ts | 5 - .../referral_customer_service/index.d.ts | 108 ---- types/src/services/refund_service/Refund.d.ts | 31 - .../RefundCreateParameters.d.ts | 13 - .../refund_service/RefundListParameters.d.ts | 5 - types/src/services/refund_service/index.d.ts | 89 --- types/src/services/report_service/Report.d.ts | 52 -- .../ReportCreateParameters.d.ts | 10 - .../report_service/ReportListParameters.d.ts | 8 - .../report_service/ReportObjectType.d.ts | 14 - types/src/services/report_service/index.d.ts | 82 --- .../services/scan_form_service/ScanForm.d.ts | 47 -- .../ScanFormCreateParameters.d.ts | 9 - .../ScanFormListParameters.d.ts | 5 - .../src/services/scan_form_service/index.d.ts | 91 --- types/src/services/shipment_service/Form.d.ts | 28 - .../services/shipment_service/Message.d.ts | 27 - .../shipment_service/Options/LabelFormat.d.ts | 1 - .../shipment_service/Options/Options.d.ts | 325 ---------- .../Options/PrintCustomCode.d.ts | 52 -- .../shipment_service/Options/index.d.ts | 3 - .../shipment_service/PostageLabel.d.ts | 18 - .../services/shipment_service/Shipment.d.ts | 124 ---- .../ShipmentCreateParameters.d.ts | 17 - .../ShipmentListParameters.d.ts | 16 - .../src/services/shipment_service/index.d.ts | 605 ------------------ .../tracker_service/CarrierDetail.d.ts | 51 -- .../src/services/tracker_service/Tracker.d.ts | 86 --- .../TrackerCreateParameters.d.ts | 11 - .../TrackerListParameters.d.ts | 12 - .../tracker_service/TrackerStatus.d.ts | 11 - .../tracker_service/TrackerStatusDetail.d.ts | 29 - .../tracker_service/TrackingDetail.d.ts | 28 - .../tracker_service/TrackingLocation.d.ts | 22 - types/src/services/tracker_service/index.d.ts | 102 --- types/src/services/user_service/Brand.d.ts | 40 -- types/src/services/user_service/User.d.ts | 64 -- .../user_service/UserCreateParameters.d.ts | 3 - types/src/services/user_service/index.d.ts | 126 ---- .../src/services/webhook_service/Webhook.d.ts | 28 - .../WebhookCreateParameters.d.ts | 3 - .../WebhookListParameters.d.ts | 5 - types/src/services/webhook_service/index.d.ts | 90 --- types/src/utils/errors/Error.d.ts | 24 - types/src/utils/errors/ErrorCode.d.ts | 173 ----- types/src/utils/errors/FieldError.d.ts | 10 - types/src/utils/errors/index.d.ts | 3 - types/src/utils/types.d.ts | 62 -- types/src/utils/util.d.ts | 47 -- types/utils/errors/Error.d.ts | 24 - types/utils/errors/ErrorCode.d.ts | 173 ----- types/utils/errors/FieldError.d.ts | 10 - types/utils/errors/index.d.ts | 3 - types/utils/types.d.ts | 62 -- types/utils/util.d.ts | 47 -- 303 files changed, 1 insertion(+), 12205 deletions(-) delete mode 100644 types/constants.d.ts delete mode 100644 types/easypost.d.ts delete mode 100644 types/errors/api/api_error.d.ts delete mode 100644 types/errors/api/bad_request_error.d.ts delete mode 100644 types/errors/api/external_api_error.d.ts delete mode 100644 types/errors/api/forbidden_error.d.ts delete mode 100644 types/errors/api/gateway_timeout_error.d.ts delete mode 100644 types/errors/api/http_error.d.ts delete mode 100644 types/errors/api/index.d.ts delete mode 100644 types/errors/api/internal_server_error.d.ts delete mode 100644 types/errors/api/invalid_request_error.d.ts delete mode 100644 types/errors/api/method_not_allowed_error.d.ts delete mode 100644 types/errors/api/not_found_error.d.ts delete mode 100644 types/errors/api/payment_error.d.ts delete mode 100644 types/errors/api/rate_limit_error.d.ts delete mode 100644 types/errors/api/redirect_error.d.ts delete mode 100644 types/errors/api/service_unavailable_error.d.ts delete mode 100644 types/errors/api/timeout_error.d.ts delete mode 100644 types/errors/api/unauthorized_error.d.ts delete mode 100644 types/errors/api/unknown_api_error.d.ts delete mode 100644 types/errors/easypost_error.d.ts delete mode 100644 types/errors/error_handler.d.ts delete mode 100644 types/errors/general/end_of_pagination_error.d.ts delete mode 100644 types/errors/general/filtering_error.d.ts delete mode 100644 types/errors/general/index.d.ts delete mode 100644 types/errors/general/invalid_object_error.d.ts delete mode 100644 types/errors/general/invalid_parameter_error.d.ts delete mode 100644 types/errors/general/missing_parameter_error.d.ts delete mode 100644 types/errors/general/signature_verification_error.d.ts delete mode 100644 types/errors/index.d.ts delete mode 100644 types/index.d.ts delete mode 100644 types/services/address_service/Address.d.ts delete mode 100644 types/services/address_service/AddressCreateParameters.d.ts delete mode 100644 types/services/address_service/AddressListParameters.d.ts delete mode 100644 types/services/address_service/Verification.d.ts delete mode 100644 types/services/address_service/VerificationDetails.d.ts delete mode 100644 types/services/address_service/Verifications.d.ts delete mode 100644 types/services/address_service/index.d.ts delete mode 100644 types/services/api_key_service/ApiKey.d.ts delete mode 100644 types/services/api_key_service/index.d.ts delete mode 100644 types/services/base_service.d.ts delete mode 100644 types/services/batch_service/Batch.d.ts delete mode 100644 types/services/batch_service/BatchCreateParameters.d.ts delete mode 100644 types/services/batch_service/BatchListParameters.d.ts delete mode 100644 types/services/batch_service/BatchShipment.d.ts delete mode 100644 types/services/batch_service/BatchState.d.ts delete mode 100644 types/services/batch_service/BatchStatus.d.ts delete mode 100644 types/services/batch_service/BatchStatuses.d.ts delete mode 100644 types/services/batch_service/index.d.ts delete mode 100644 types/services/beta_rate_service/index.d.ts delete mode 100644 types/services/beta_referral_customer_service/index.d.ts delete mode 100644 types/services/billing_service/PaymentMethod.d.ts delete mode 100644 types/services/billing_service/index.d.ts delete mode 100644 types/services/carrier_account_service/CarrierAccount.d.ts delete mode 100644 types/services/carrier_account_service/CarrierAccountCreateParameters.d.ts delete mode 100644 types/services/carrier_account_service/CarrierAccountField.d.ts delete mode 100644 types/services/carrier_account_service/CarrierAccountFields.d.ts delete mode 100644 types/services/carrier_account_service/index.d.ts delete mode 100644 types/services/carrier_metadata_service/CarrierMetadata.d.ts delete mode 100644 types/services/carrier_metadata_service/index.d.ts delete mode 100644 types/services/carrier_type_service/CarrierType.d.ts delete mode 100644 types/services/carrier_type_service/CarrierTypeCredentials.d.ts delete mode 100644 types/services/carrier_type_service/CarrierTypeFields.d.ts delete mode 100644 types/services/carrier_type_service/index.d.ts delete mode 100644 types/services/customs_info_service/CustomsInfo.d.ts delete mode 100644 types/services/customs_info_service/CustomsInfoCreateParameters.d.ts delete mode 100644 types/services/customs_info_service/index.d.ts delete mode 100644 types/services/customs_item_service/CustomsItem.d.ts delete mode 100644 types/services/customs_item_service/CustomsItemCreateParameters.d.ts delete mode 100644 types/services/customs_item_service/index.d.ts delete mode 100644 types/services/end_shipper_service/EndShipper.d.ts delete mode 100644 types/services/end_shipper_service/EndShipperCreateParameters.d.ts delete mode 100644 types/services/end_shipper_service/EndShipperListParameters.d.ts delete mode 100644 types/services/end_shipper_service/index.d.ts delete mode 100644 types/services/event_service/Event.d.ts delete mode 100644 types/services/event_service/EventListParameters.d.ts delete mode 100644 types/services/event_service/Payload/Payload.d.ts delete mode 100644 types/services/event_service/Payload/PayloadListParameters.d.ts delete mode 100644 types/services/event_service/Payload/index.d.ts delete mode 100644 types/services/event_service/index.d.ts delete mode 100644 types/services/index.d.ts delete mode 100644 types/services/insurance_service/Fee.d.ts delete mode 100644 types/services/insurance_service/FeeType.d.ts delete mode 100644 types/services/insurance_service/Insurance.d.ts delete mode 100644 types/services/insurance_service/InsuranceCreateParameters.d.ts delete mode 100644 types/services/insurance_service/InsuranceStatus.d.ts delete mode 100644 types/services/insurance_service/index.d.ts delete mode 100644 types/services/order_service/Order.d.ts delete mode 100644 types/services/order_service/OrderCreateParameters.d.ts delete mode 100644 types/services/order_service/index.d.ts delete mode 100644 types/services/parcel_service/Parcel.d.ts delete mode 100644 types/services/parcel_service/ParcelCreateParameters.d.ts delete mode 100644 types/services/parcel_service/index.d.ts delete mode 100644 types/services/pickup_service/Pickup.d.ts delete mode 100644 types/services/pickup_service/PickupCreateParameters.d.ts delete mode 100644 types/services/pickup_service/PickupListParameters.d.ts delete mode 100644 types/services/pickup_service/PickupRate.d.ts delete mode 100644 types/services/pickup_service/index.d.ts delete mode 100644 types/services/rate_service/Rate.d.ts delete mode 100644 types/services/rate_service/index.d.ts delete mode 100644 types/services/referral_customer_service/Referral.d.ts delete mode 100644 types/services/referral_customer_service/ReferralCreateParameters.d.ts delete mode 100644 types/services/referral_customer_service/ReferralListParameters.d.ts delete mode 100644 types/services/referral_customer_service/index.d.ts delete mode 100644 types/services/refund_service/Refund.d.ts delete mode 100644 types/services/refund_service/RefundCreateParameters.d.ts delete mode 100644 types/services/refund_service/RefundListParameters.d.ts delete mode 100644 types/services/refund_service/index.d.ts delete mode 100644 types/services/report_service/Report.d.ts delete mode 100644 types/services/report_service/ReportCreateParameters.d.ts delete mode 100644 types/services/report_service/ReportListParameters.d.ts delete mode 100644 types/services/report_service/ReportObjectType.d.ts delete mode 100644 types/services/report_service/index.d.ts delete mode 100644 types/services/scan_form_service/ScanForm.d.ts delete mode 100644 types/services/scan_form_service/ScanFormCreateParameters.d.ts delete mode 100644 types/services/scan_form_service/ScanFormListParameters.d.ts delete mode 100644 types/services/scan_form_service/index.d.ts delete mode 100644 types/services/shipment_service/Form.d.ts delete mode 100644 types/services/shipment_service/Message.d.ts delete mode 100644 types/services/shipment_service/Options/LabelFormat.d.ts delete mode 100644 types/services/shipment_service/Options/Options.d.ts delete mode 100644 types/services/shipment_service/Options/PrintCustomCode.d.ts delete mode 100644 types/services/shipment_service/Options/index.d.ts delete mode 100644 types/services/shipment_service/PostageLabel.d.ts delete mode 100644 types/services/shipment_service/Shipment.d.ts delete mode 100644 types/services/shipment_service/ShipmentCreateParameters.d.ts delete mode 100644 types/services/shipment_service/ShipmentListParameters.d.ts delete mode 100644 types/services/shipment_service/index.d.ts delete mode 100644 types/services/tracker_service/CarrierDetail.d.ts delete mode 100644 types/services/tracker_service/Tracker.d.ts delete mode 100644 types/services/tracker_service/TrackerCreateParameters.d.ts delete mode 100644 types/services/tracker_service/TrackerListParameters.d.ts delete mode 100644 types/services/tracker_service/TrackerStatus.d.ts delete mode 100644 types/services/tracker_service/TrackerStatusDetail.d.ts delete mode 100644 types/services/tracker_service/TrackingDetail.d.ts delete mode 100644 types/services/tracker_service/TrackingLocation.d.ts delete mode 100644 types/services/tracker_service/index.d.ts delete mode 100644 types/services/user_service/Brand.d.ts delete mode 100644 types/services/user_service/User.d.ts delete mode 100644 types/services/user_service/UserCreateParameters.d.ts delete mode 100644 types/services/user_service/index.d.ts delete mode 100644 types/services/webhook_service/Webhook.d.ts delete mode 100644 types/services/webhook_service/WebhookCreateParameters.d.ts delete mode 100644 types/services/webhook_service/WebhookListParameters.d.ts delete mode 100644 types/services/webhook_service/index.d.ts delete mode 100644 types/src/constants.d.ts delete mode 100644 types/src/easypost.d.ts delete mode 100644 types/src/errors/api/api_error.d.ts delete mode 100644 types/src/errors/api/bad_request_error.d.ts delete mode 100644 types/src/errors/api/external_api_error.d.ts delete mode 100644 types/src/errors/api/forbidden_error.d.ts delete mode 100644 types/src/errors/api/gateway_timeout_error.d.ts delete mode 100644 types/src/errors/api/http_error.d.ts delete mode 100644 types/src/errors/api/index.d.ts delete mode 100644 types/src/errors/api/internal_server_error.d.ts delete mode 100644 types/src/errors/api/invalid_request_error.d.ts delete mode 100644 types/src/errors/api/method_not_allowed_error.d.ts delete mode 100644 types/src/errors/api/not_found_error.d.ts delete mode 100644 types/src/errors/api/payment_error.d.ts delete mode 100644 types/src/errors/api/rate_limit_error.d.ts delete mode 100644 types/src/errors/api/redirect_error.d.ts delete mode 100644 types/src/errors/api/service_unavailable_error.d.ts delete mode 100644 types/src/errors/api/timeout_error.d.ts delete mode 100644 types/src/errors/api/unauthorized_error.d.ts delete mode 100644 types/src/errors/api/unknown_api_error.d.ts delete mode 100644 types/src/errors/easypost_error.d.ts delete mode 100644 types/src/errors/error_handler.d.ts delete mode 100644 types/src/errors/general/end_of_pagination_error.d.ts delete mode 100644 types/src/errors/general/filtering_error.d.ts delete mode 100644 types/src/errors/general/index.d.ts delete mode 100644 types/src/errors/general/invalid_object_error.d.ts delete mode 100644 types/src/errors/general/invalid_parameter_error.d.ts delete mode 100644 types/src/errors/general/missing_parameter_error.d.ts delete mode 100644 types/src/errors/general/signature_verification_error.d.ts delete mode 100644 types/src/errors/index.d.ts delete mode 100644 types/src/index.d.ts delete mode 100644 types/src/services/address_service/Address.d.ts delete mode 100644 types/src/services/address_service/AddressCreateParameters.d.ts delete mode 100644 types/src/services/address_service/AddressListParameters.d.ts delete mode 100644 types/src/services/address_service/Verification.d.ts delete mode 100644 types/src/services/address_service/VerificationDetails.d.ts delete mode 100644 types/src/services/address_service/Verifications.d.ts delete mode 100644 types/src/services/address_service/index.d.ts delete mode 100644 types/src/services/api_key_service/ApiKey.d.ts delete mode 100644 types/src/services/api_key_service/index.d.ts delete mode 100644 types/src/services/base_service.d.ts delete mode 100644 types/src/services/batch_service/Batch.d.ts delete mode 100644 types/src/services/batch_service/BatchCreateParameters.d.ts delete mode 100644 types/src/services/batch_service/BatchListParameters.d.ts delete mode 100644 types/src/services/batch_service/BatchShipment.d.ts delete mode 100644 types/src/services/batch_service/BatchState.d.ts delete mode 100644 types/src/services/batch_service/BatchStatus.d.ts delete mode 100644 types/src/services/batch_service/BatchStatuses.d.ts delete mode 100644 types/src/services/batch_service/index.d.ts delete mode 100644 types/src/services/beta_rate_service/index.d.ts delete mode 100644 types/src/services/beta_referral_customer_service/index.d.ts delete mode 100644 types/src/services/billing_service/PaymentMethod.d.ts delete mode 100644 types/src/services/billing_service/index.d.ts delete mode 100644 types/src/services/carrier_account_service/CarrierAccount.d.ts delete mode 100644 types/src/services/carrier_account_service/CarrierAccountCreateParameters.d.ts delete mode 100644 types/src/services/carrier_account_service/CarrierAccountField.d.ts delete mode 100644 types/src/services/carrier_account_service/CarrierAccountFields.d.ts delete mode 100644 types/src/services/carrier_account_service/index.d.ts delete mode 100644 types/src/services/carrier_metadata_service/CarrierMetadata.d.ts delete mode 100644 types/src/services/carrier_metadata_service/index.d.ts delete mode 100644 types/src/services/carrier_type_service/CarrierType.d.ts delete mode 100644 types/src/services/carrier_type_service/CarrierTypeCredentials.d.ts delete mode 100644 types/src/services/carrier_type_service/CarrierTypeFields.d.ts delete mode 100644 types/src/services/carrier_type_service/index.d.ts delete mode 100644 types/src/services/customs_info_service/CustomsInfo.d.ts delete mode 100644 types/src/services/customs_info_service/CustomsInfoCreateParameters.d.ts delete mode 100644 types/src/services/customs_info_service/index.d.ts delete mode 100644 types/src/services/customs_item_service/CustomsItem.d.ts delete mode 100644 types/src/services/customs_item_service/CustomsItemCreateParameters.d.ts delete mode 100644 types/src/services/customs_item_service/index.d.ts delete mode 100644 types/src/services/end_shipper_service/EndShipper.d.ts delete mode 100644 types/src/services/end_shipper_service/EndShipperCreateParameters.d.ts delete mode 100644 types/src/services/end_shipper_service/EndShipperListParameters.d.ts delete mode 100644 types/src/services/end_shipper_service/index.d.ts delete mode 100644 types/src/services/event_service/Event.d.ts delete mode 100644 types/src/services/event_service/EventListParameters.d.ts delete mode 100644 types/src/services/event_service/Payload/Payload.d.ts delete mode 100644 types/src/services/event_service/Payload/PayloadListParameters.d.ts delete mode 100644 types/src/services/event_service/Payload/index.d.ts delete mode 100644 types/src/services/event_service/index.d.ts delete mode 100644 types/src/services/index.d.ts delete mode 100644 types/src/services/insurance_service/Fee.d.ts delete mode 100644 types/src/services/insurance_service/FeeType.d.ts delete mode 100644 types/src/services/insurance_service/Insurance.d.ts delete mode 100644 types/src/services/insurance_service/InsuranceCreateParameters.d.ts delete mode 100644 types/src/services/insurance_service/InsuranceStatus.d.ts delete mode 100644 types/src/services/insurance_service/index.d.ts delete mode 100644 types/src/services/order_service/Order.d.ts delete mode 100644 types/src/services/order_service/OrderCreateParameters.d.ts delete mode 100644 types/src/services/order_service/index.d.ts delete mode 100644 types/src/services/parcel_service/Parcel.d.ts delete mode 100644 types/src/services/parcel_service/ParcelCreateParameters.d.ts delete mode 100644 types/src/services/parcel_service/index.d.ts delete mode 100644 types/src/services/pickup_service/Pickup.d.ts delete mode 100644 types/src/services/pickup_service/PickupCreateParameters.d.ts delete mode 100644 types/src/services/pickup_service/PickupListParameters.d.ts delete mode 100644 types/src/services/pickup_service/PickupRate.d.ts delete mode 100644 types/src/services/pickup_service/index.d.ts delete mode 100644 types/src/services/rate_service/Rate.d.ts delete mode 100644 types/src/services/rate_service/index.d.ts delete mode 100644 types/src/services/referral_customer_service/Referral.d.ts delete mode 100644 types/src/services/referral_customer_service/ReferralCreateParameters.d.ts delete mode 100644 types/src/services/referral_customer_service/ReferralListParameters.d.ts delete mode 100644 types/src/services/referral_customer_service/index.d.ts delete mode 100644 types/src/services/refund_service/Refund.d.ts delete mode 100644 types/src/services/refund_service/RefundCreateParameters.d.ts delete mode 100644 types/src/services/refund_service/RefundListParameters.d.ts delete mode 100644 types/src/services/refund_service/index.d.ts delete mode 100644 types/src/services/report_service/Report.d.ts delete mode 100644 types/src/services/report_service/ReportCreateParameters.d.ts delete mode 100644 types/src/services/report_service/ReportListParameters.d.ts delete mode 100644 types/src/services/report_service/ReportObjectType.d.ts delete mode 100644 types/src/services/report_service/index.d.ts delete mode 100644 types/src/services/scan_form_service/ScanForm.d.ts delete mode 100644 types/src/services/scan_form_service/ScanFormCreateParameters.d.ts delete mode 100644 types/src/services/scan_form_service/ScanFormListParameters.d.ts delete mode 100644 types/src/services/scan_form_service/index.d.ts delete mode 100644 types/src/services/shipment_service/Form.d.ts delete mode 100644 types/src/services/shipment_service/Message.d.ts delete mode 100644 types/src/services/shipment_service/Options/LabelFormat.d.ts delete mode 100644 types/src/services/shipment_service/Options/Options.d.ts delete mode 100644 types/src/services/shipment_service/Options/PrintCustomCode.d.ts delete mode 100644 types/src/services/shipment_service/Options/index.d.ts delete mode 100644 types/src/services/shipment_service/PostageLabel.d.ts delete mode 100644 types/src/services/shipment_service/Shipment.d.ts delete mode 100644 types/src/services/shipment_service/ShipmentCreateParameters.d.ts delete mode 100644 types/src/services/shipment_service/ShipmentListParameters.d.ts delete mode 100644 types/src/services/shipment_service/index.d.ts delete mode 100644 types/src/services/tracker_service/CarrierDetail.d.ts delete mode 100644 types/src/services/tracker_service/Tracker.d.ts delete mode 100644 types/src/services/tracker_service/TrackerCreateParameters.d.ts delete mode 100644 types/src/services/tracker_service/TrackerListParameters.d.ts delete mode 100644 types/src/services/tracker_service/TrackerStatus.d.ts delete mode 100644 types/src/services/tracker_service/TrackerStatusDetail.d.ts delete mode 100644 types/src/services/tracker_service/TrackingDetail.d.ts delete mode 100644 types/src/services/tracker_service/TrackingLocation.d.ts delete mode 100644 types/src/services/tracker_service/index.d.ts delete mode 100644 types/src/services/user_service/Brand.d.ts delete mode 100644 types/src/services/user_service/User.d.ts delete mode 100644 types/src/services/user_service/UserCreateParameters.d.ts delete mode 100644 types/src/services/user_service/index.d.ts delete mode 100644 types/src/services/webhook_service/Webhook.d.ts delete mode 100644 types/src/services/webhook_service/WebhookCreateParameters.d.ts delete mode 100644 types/src/services/webhook_service/WebhookListParameters.d.ts delete mode 100644 types/src/services/webhook_service/index.d.ts delete mode 100644 types/src/utils/errors/Error.d.ts delete mode 100644 types/src/utils/errors/ErrorCode.d.ts delete mode 100644 types/src/utils/errors/FieldError.d.ts delete mode 100644 types/src/utils/errors/index.d.ts delete mode 100644 types/src/utils/types.d.ts delete mode 100644 types/src/utils/util.d.ts delete mode 100644 types/utils/errors/Error.d.ts delete mode 100644 types/utils/errors/ErrorCode.d.ts delete mode 100644 types/utils/errors/FieldError.d.ts delete mode 100644 types/utils/errors/index.d.ts delete mode 100644 types/utils/types.d.ts delete mode 100644 types/utils/util.d.ts diff --git a/.gitignore b/.gitignore index 79d7f9795..146fab08f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ docs Icon node_modules npm-debug.log -out + /.eslintrc /.eslintignore /.prettierrc.yml diff --git a/types/constants.d.ts b/types/constants.d.ts deleted file mode 100644 index 2e9caa299..000000000 --- a/types/constants.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import Utils from './utils/util'; -/** - * A class containing constants used throughout the EasyPost Node.js client library. - */ -export default class Constants { - static get CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS(): string[]; - static EXTERNAL_API_CALL_FAILED: string; - static INVALID_API_KEY_TYPE: string; - static INVALID_PARAMETER: string; - static INVALID_PAYMENT: string; - static INVALID_WEBHOOK_SIGNATURE: string; - static MISSING_REQUIRED_PARAMETER: string; - static NO_OBJECT_FOUND: string; - static NO_PAYMENT_METHODS: string; - static API_DID_NOT_RETURN_ERROR_DETAILS: string; - static WEBHOOK_DOES_NOT_MATCH: string; - static END_OF_PAGINATION: string; - static ERROR_DESERIALIZATION: string; - static Utils: Utils; -} diff --git a/types/easypost.d.ts b/types/easypost.d.ts deleted file mode 100644 index e9b390ae5..000000000 --- a/types/easypost.d.ts +++ /dev/null @@ -1,260 +0,0 @@ -import { SuperAgentStatic, Request, Response } from 'superagent'; -import AddressService from './services/address_service'; -import ApiKeyService from './services/api_key_service'; -import BatchService from './services/batch_service'; -import BetaRateService from './services/beta_rate_service'; -import BetaReferralCustomerService from './services/beta_referral_customer_service'; -import BillingService from './services/billing_service'; -import CarrierAccountService from './services/carrier_account_service'; -import CarrierMetadataService from './services/carrier_metadata_service'; -import CarrierTypeService from './services/carrier_type_service'; -import CustomsInfoService from './services/customs_info_service'; -import CustomsItemService from './services/customs_item_service'; -import EndShipperService from './services/end_shipper_service'; -import EventService from './services/event_service'; -import InsuranceService from './services/insurance_service'; -import OrderService from './services/order_service'; -import ParcelService from './services/parcel_service'; -import PickupService from './services/pickup_service'; -import RateService from './services/rate_service'; -import ReferralCustomerService from './services/referral_customer_service'; -import RefundService from './services/refund_service'; -import ReportService from './services/report_service'; -import ScanFormService from './services/scan_form_service'; -import ShipmentService from './services/shipment_service'; -import TrackerService from './services/tracker_service'; -import UserService from './services/user_service'; -import WebhookService from './services/webhook_service'; -import Utils from './utils/util'; -export * from './errors'; -export * from './services'; -export * from './utils/errors'; -export * from './constants'; -/** How many milliseconds in a second. */ -export declare const MS_SECOND = 1000; -/** The default timeout for all EasyPost API requests. */ -export declare const DEFAULT_TIMEOUT: number; -/** The default base URL for all production EasyPost API requests. */ -export declare const DEFAULT_BASE_URL = 'https://api.easypost.com/v2/'; -/** The default headers used for all EasyPost API requests. */ -export declare const DEFAULT_HEADERS: { - Accept: string; - 'Content-Type': string; - 'User-Agent': string; -}; -/** A map of HTTP methods to their corresponding string values (for use with superagent). */ -export declare const METHODS: { - readonly GET: 'get'; - readonly POST: 'post'; - readonly PUT: 'put'; - readonly PATCH: 'patch'; - readonly DELETE: 'del'; -}; -export type EasyPostClientOptions = { - useProxy?: boolean; - timeout?: number; - baseUrl?: string; - superagentMiddleware?: (agent: SuperAgentStatic) => SuperAgentStatic; - requestMiddleware?: (request: Request) => Request; - agent?: SuperAgentStatic; -}; -export type RequestHookData = { - method: (typeof METHODS)[keyof typeof METHODS]; - path: string; - requestBody: any; - headers: Record; - requestTimestamp: number; - requestUUID: string; -}; -export type RequestHook = (data: RequestHookData) => void; -export type ResponseHookData = RequestHookData & { - requestHeaders: Record; - httpStatus: Response['status']; - responseBody: Response['body']; - headers: Response['headers']; - responseTimestamp: number; -}; -export type ResponseHook = (data: ResponseHookData) => void; -/** - * The client used to access services of the EasyPost API. - * This client is configured to use the latest production version of the EasyPost API. - * @param {string} key The API key to use for API requests made by this client. - * @param {EasyPostClientOptions} [options] Additional options to use for the underlying HTTP client (e.g. superagent, middleware, proxy configuration). - */ -export default class EasyPostClient { - useProxy: boolean; - key: string; - timeout: number; - baseUrl: string; - agent: SuperAgentStatic; - requestMiddleware: ((request: Request) => Request) | undefined; - requestHooks: RequestHook[]; - responseHooks: ResponseHook[]; - Utils: Utils; - Address: ReturnType; - ApiKey: ReturnType; - Batch: ReturnType; - BetaRate: ReturnType; - BetaReferralCustomer: ReturnType; - Billing: ReturnType; - CarrierAccount: ReturnType; - CarrierMetadata: ReturnType; - CarrierType: ReturnType; - CustomsInfo: ReturnType; - CustomsItem: ReturnType; - EndShipper: ReturnType; - Event: ReturnType; - Insurance: ReturnType; - Order: ReturnType; - Parcel: ReturnType; - Pickup: ReturnType; - Rate: ReturnType; - ReferralCustomer: ReturnType; - Refund: ReturnType; - Report: ReturnType; - ScanForm: ReturnType; - Shipment: ReturnType; - Tracker: ReturnType; - User: ReturnType; - Webhook: ReturnType; - constructor(key: string, options?: EasyPostClientOptions); - /** - * Add a request hook function. - * @param {(config: object) => void} hook - */ - addRequestHook(hook: RequestHook): void; - /** - * Remove a request hook function. - * @param {(config: object) => void} hook - */ - removeRequestHook(hook: RequestHook): void; - /** - * Clear all request hooks. - */ - clearRequestHooks(): void; - /** - * Add a response hook function. - * @param {(config: object) => void} hook - */ - addResponseHook(hook: ResponseHook): void; - /** - * Remove a response hook function. - * @param {(config: object) => void} hook - */ - removeResponseHook(hook: ResponseHook): void; - /** - * Clear all response hooks. - */ - clearResponseHooks(): void; - /** - * Create a copy of an {@link EasyPostClient} with overridden options. - * @param {EasyPostClient} client The `EasyPostClient` instance to clone. - * @param {Object} [options] The options to override. - * @returns {EasyPostClient} A new `EasyPostClient` instance. - */ - static copyClient( - client: EasyPostClient, - options?: EasyPostClientOptions & { - apiKey?: string; - }, - ): EasyPostClient; - /** - * Build request headers to be sent with each EasyPost API request, combined (or overridden) by any additional headers - * @param {Object} [additionalHeaders] Additional headers to combine or override with the default headers. - * @returns {Object} The headers to use for the request. - */ - static _buildHeaders(additionalHeaders?: {}): { - Accept: string; - 'Content-Type': string; - 'User-Agent': string; - }; - /** - * If the path passed in is a full URI, use it; otherwise, prepend the base url from the api. - * @param {string} path - The path to build. - * @returns {string} The full path to use for the HTTP request. - */ - _buildPath(path?: string): string; - /** - * Create a value to be passed to the responseHooks, based on the requestHooks - * value and the response. - * @param {Object} baseHooksValue - the value being passed the requestHooks - * @param {Object} response - the response from the superagent request - * @returns {Object} - the value to be passed to the responseHooks - */ - _createResponseHooksValue(baseHooksValue: RequestHookData, response: Response): ResponseHookData; - /** - * Make an HTTP request. - * @param [path] - The partial path to append to the base url for the request. - * @param [method] - The HTTP method to use for the request, defaults to GET. - * @param [params] - The parameters to send with the request. - * @param [headers] - Additional headers to send with the request. - * @returns The response from the HTTP request. - * @throws {ApiError} If the request fails. - */ - _request( - path?: string, - method?: (typeof METHODS)[keyof typeof METHODS], - params?: Record, - headers?: Record, - ): Promise; - /** - * Make a GET HTTP request. - * @param path - The partial path to append to the base url for the request. - * @param [params] - The parameters to send with the request. - * @param [headers] - Additional headers to send with the request. - * @returns The response from the HTTP request. - */ - _get( - path: string, - params?: Record, - headers?: Record, - ): Promise; - /** - * Make a POST HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {any} [params] - The parameters to send with the request. - * @param {Record} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - _post( - path: string, - params?: any, - headers?: Record, - ): Promise; - /** - * Make a PUT HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {any} [params] - The parameters to send with the request. - * @param {Record} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - _put( - path: string, - params?: any, - headers?: Record, - ): Promise; - /** - * Make a PATCH HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {any} [params] - The parameters to send with the request. - * @param {Record} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - _patch( - path: string, - params?: any, - headers?: Record, - ): Promise; - /** - * Make a DELETE HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {any} [params] - The parameters to send with the request. - * @param {Record} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - _delete( - path: string, - params?: any, - headers?: Record, - ): Promise; -} diff --git a/types/errors/api/api_error.d.ts b/types/errors/api/api_error.d.ts deleted file mode 100644 index 1c0e08efb..000000000 --- a/types/errors/api/api_error.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -import EasyPostError from '../easypost_error'; -/** - * The ApiError class is used to represent errors that occurred while communicating with the EasyPost API. - * This class should not be instantiated directly. - * @internal - * @abstract - * @extends EasyPostError - * @property {string} [message] - The message to be displayed when the error is logged. - * @property {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @property {number} [statusCode] - The HTTP status code returned by the HTTP request to the EasyPost API. - * @property {EasyPostError[]} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class ApiError extends EasyPostError { - code: string | undefined; - errors: EasyPostError[] | undefined; - message: string | undefined; - statusCode: number | undefined; - constructor({ - message, - code, - statusCode, - errors, - }?: { - message?: string; - code?: string; - statusCode?: number; - errors?: EasyPostError[]; - }); -} diff --git a/types/errors/api/bad_request_error.d.ts b/types/errors/api/bad_request_error.d.ts deleted file mode 100644 index a8a3391a5..000000000 --- a/types/errors/api/bad_request_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The BadRequestError class is used to represent a 400 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class BadRequestError extends ApiError {} diff --git a/types/errors/api/external_api_error.d.ts b/types/errors/api/external_api_error.d.ts deleted file mode 100644 index c3bb01401..000000000 --- a/types/errors/api/external_api_error.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import ApiError from './api_error'; -/** - * The ExternalApiError class is used to represent errors that occurred while communicating with an external API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - */ -export default class ExternalApiError extends ApiError {} diff --git a/types/errors/api/forbidden_error.d.ts b/types/errors/api/forbidden_error.d.ts deleted file mode 100644 index f8d9b064e..000000000 --- a/types/errors/api/forbidden_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The ForbiddenError class is used to represent a 403 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class ForbiddenError extends ApiError {} diff --git a/types/errors/api/gateway_timeout_error.d.ts b/types/errors/api/gateway_timeout_error.d.ts deleted file mode 100644 index 1ceec87e7..000000000 --- a/types/errors/api/gateway_timeout_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The GatewayTimeoutError class is used to represent a 504 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class GatewayTimeoutError extends ApiError {} diff --git a/types/errors/api/http_error.d.ts b/types/errors/api/http_error.d.ts deleted file mode 100644 index acaac4c4b..000000000 --- a/types/errors/api/http_error.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import ApiError from './api_error'; -/** - * The HttpError class is used to represent a generic HTTP-related error that occurred while communicating with the EasyPost API. - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class HTTPError extends ApiError {} diff --git a/types/errors/api/index.d.ts b/types/errors/api/index.d.ts deleted file mode 100644 index 6ac9ac6b3..000000000 --- a/types/errors/api/index.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -export * from './api_error'; -export * from './bad_request_error'; -export * from './external_api_error'; -export * from './forbidden_error'; -export * from './gateway_timeout_error'; -export * from './http_error'; -export * from './index'; -export * from './internal_server_error'; -export * from './invalid_request_error'; -export * from './method_not_allowed_error'; -export * from './not_found_error'; -export * from './payment_error'; -export * from './rate_limit_error'; -export * from './redirect_error'; -export * from './service_unavailable_error'; -export * from './timeout_error'; -export * from './unauthorized_error'; -export * from './unknown_api_error'; diff --git a/types/errors/api/internal_server_error.d.ts b/types/errors/api/internal_server_error.d.ts deleted file mode 100644 index 946d7e0fa..000000000 --- a/types/errors/api/internal_server_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The InternalServerError class is used to represent a 500 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class InternalServerError extends ApiError {} diff --git a/types/errors/api/invalid_request_error.d.ts b/types/errors/api/invalid_request_error.d.ts deleted file mode 100644 index 0e87d346d..000000000 --- a/types/errors/api/invalid_request_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The InvalidRequestError class is used to represent a 422 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class InvalidRequestError extends ApiError {} diff --git a/types/errors/api/method_not_allowed_error.d.ts b/types/errors/api/method_not_allowed_error.d.ts deleted file mode 100644 index fd29b3cbc..000000000 --- a/types/errors/api/method_not_allowed_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The MethodNotAllowedError class is used to represent a 405 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class MethodNotAllowedError extends ApiError {} diff --git a/types/errors/api/not_found_error.d.ts b/types/errors/api/not_found_error.d.ts deleted file mode 100644 index 5e2a4262b..000000000 --- a/types/errors/api/not_found_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The NotFoundError class is used to represent a 404 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class NotFoundError extends ApiError {} diff --git a/types/errors/api/payment_error.d.ts b/types/errors/api/payment_error.d.ts deleted file mode 100644 index 081039ad8..000000000 --- a/types/errors/api/payment_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The PaymentError class is used to represent a 402 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class PaymentError extends ApiError {} diff --git a/types/errors/api/rate_limit_error.d.ts b/types/errors/api/rate_limit_error.d.ts deleted file mode 100644 index 3ae7f08f9..000000000 --- a/types/errors/api/rate_limit_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The RateLimitError class is used to represent a 429 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class RateLimitError extends ApiError {} diff --git a/types/errors/api/redirect_error.d.ts b/types/errors/api/redirect_error.d.ts deleted file mode 100644 index 004604f69..000000000 --- a/types/errors/api/redirect_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The RedirectError class is used to represent a 3xx error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class RedirectError extends ApiError {} diff --git a/types/errors/api/service_unavailable_error.d.ts b/types/errors/api/service_unavailable_error.d.ts deleted file mode 100644 index e667d5952..000000000 --- a/types/errors/api/service_unavailable_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The ServiceUnavailableError class is used to represent a 503 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class ServiceUnavailableError extends ApiError {} diff --git a/types/errors/api/timeout_error.d.ts b/types/errors/api/timeout_error.d.ts deleted file mode 100644 index 5775f87ed..000000000 --- a/types/errors/api/timeout_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The TimeoutError class is used to represent a 408 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class TimeoutError extends ApiError {} diff --git a/types/errors/api/unauthorized_error.d.ts b/types/errors/api/unauthorized_error.d.ts deleted file mode 100644 index bad09b743..000000000 --- a/types/errors/api/unauthorized_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The UnauthorizedError class is used to represent a 401 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class UnauthorizedError extends ApiError {} diff --git a/types/errors/api/unknown_api_error.d.ts b/types/errors/api/unknown_api_error.d.ts deleted file mode 100644 index 8ddc33bbd..000000000 --- a/types/errors/api/unknown_api_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The UnknownApiError class is used to represent a generic, unexpected error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class UnknownApiError extends ApiError {} diff --git a/types/errors/easypost_error.d.ts b/types/errors/easypost_error.d.ts deleted file mode 100644 index db97aca67..000000000 --- a/types/errors/easypost_error.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * The EasyPostError class is the base class for all errors that occur in the EasyPost Node.js client library. - * This class should not be instantiated directly. - * @internal - * @abstract - * @extends Error - * @param {string} [message] - The message to be displayed when the error is logged. - */ -export default class EasyPostError extends Error { - message: string | undefined; - constructor({ message }?: { message?: string }); -} diff --git a/types/errors/error_handler.d.ts b/types/errors/error_handler.d.ts deleted file mode 100644 index b5aed46ce..000000000 --- a/types/errors/error_handler.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -import EasyPostError from './easypost_error'; -export type RawAPIError = { - statusCode: number; - body: { - error: { - code: string; - message: JSONParsableError; - errors: EasyPostError[]; - }; - }; -}; -type JSONParsableError = string | number | JSONObject | JSONArray; -type JSONObject = { - [key: string]: JSONParsableError; -}; -type JSONArray = JSONParsableError[]; -export default class ErrorHandler { - /** - * Recursively traverses a JSON object or array and extracts error messages - * as strings. Adds the extracted messages to the specified messagesList array. - * - * @param {JSONParsableError} errorMessage - The JSON object or array to traverse. - */ - static traverseJsonElement(errorMessage: JSONParsableError): string[]; - static isAPIError(error: any): error is RawAPIError; - /** - * Calculate and generate the appropriate {@link ApiError} based on a received HTTP response error. - * @param {*} error - The errored HTTP response. - * @returns {ApiError} The `ApiError`-based error corresponding to the HTTP status code. - */ - static handleApiError(error: RawAPIError): EasyPostError; -} -export {}; diff --git a/types/errors/general/end_of_pagination_error.d.ts b/types/errors/general/end_of_pagination_error.d.ts deleted file mode 100644 index 1ae894a77..000000000 --- a/types/errors/general/end_of_pagination_error.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import EasyPostError from '../easypost_error'; -/** - * The EndOfPaginationError class is used to represent an error that no more page can be retrieved - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -export default class EndOfPaginationError extends EasyPostError { - constructor(); -} diff --git a/types/errors/general/filtering_error.d.ts b/types/errors/general/filtering_error.d.ts deleted file mode 100644 index 3f96a1925..000000000 --- a/types/errors/general/filtering_error.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import EasyPostError from '../easypost_error'; -/** - * The FilteringError class is used to represent an error that occurred while filtering a list (e.g. a list of rates). - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -export default class FilteringError extends EasyPostError {} diff --git a/types/errors/general/index.d.ts b/types/errors/general/index.d.ts deleted file mode 100644 index 04c30fdb2..000000000 --- a/types/errors/general/index.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from './end_of_pagination_error'; -export * from './filtering_error'; -export * from './invalid_object_error'; -export * from './invalid_parameter_error'; -export * from './missing_parameter_error'; -export * from './signature_verification_error'; diff --git a/types/errors/general/invalid_object_error.d.ts b/types/errors/general/invalid_object_error.d.ts deleted file mode 100644 index be11f59bd..000000000 --- a/types/errors/general/invalid_object_error.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import EasyPostError from '../easypost_error'; -/** - * The InvalidObjectError class is used to represent an error due to an invalid object (e.g. missing an expected property). - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -export default class InvalidObjectError extends EasyPostError {} diff --git a/types/errors/general/invalid_parameter_error.d.ts b/types/errors/general/invalid_parameter_error.d.ts deleted file mode 100644 index 9931b6a18..000000000 --- a/types/errors/general/invalid_parameter_error.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import EasyPostError from '../easypost_error'; -/** - * The InvalidParameterError class is used to represent an error due to an invalid function parameter. - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -export default class InvalidParameterError extends EasyPostError {} diff --git a/types/errors/general/missing_parameter_error.d.ts b/types/errors/general/missing_parameter_error.d.ts deleted file mode 100644 index 858616524..000000000 --- a/types/errors/general/missing_parameter_error.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import EasyPostError from '../easypost_error'; -/** - * The MissingParameterError class is used to represent an error due to a missing expected function parameter. - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -export default class MissingParameterError extends EasyPostError {} diff --git a/types/errors/general/signature_verification_error.d.ts b/types/errors/general/signature_verification_error.d.ts deleted file mode 100644 index 0d73da0d7..000000000 --- a/types/errors/general/signature_verification_error.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import EasyPostError from '../easypost_error'; -/** - * The SignatureVerificationError class is used to represent an error due to a failed signature verification (e.g. a webhook HMAC signature). - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -export default class SignatureVerificationError extends EasyPostError {} diff --git a/types/errors/index.d.ts b/types/errors/index.d.ts deleted file mode 100644 index a8d312a93..000000000 --- a/types/errors/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './api'; -export * from './general'; -export * from './easypost_error'; -export * from './error_handler'; diff --git a/types/index.d.ts b/types/index.d.ts deleted file mode 100644 index 310d378d1..000000000 --- a/types/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import EasyPost from './easypost'; -export default EasyPost; diff --git a/types/services/address_service/Address.d.ts b/types/services/address_service/Address.d.ts deleted file mode 100644 index 3de9d7439..000000000 --- a/types/services/address_service/Address.d.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { IVerifications } from './Verifications'; -import { IObjectWithId } from '../../utils/types'; -/** - * Address objects are used to represent people, places, and organizations in a number of contexts. - * For example, a Shipment requires a to_address and from_address to accurately calculate rates and generate postage. - * - * Additionally, EasyPost offers several verification tools that can be used to detect deliverability issues, correct minor errors in spelling/formatting, and determine if an Address is residential or not (which has a significant effect on Shipment rating for many carriers). - * - * @see https://www.easypost.com/docs/api/node#address-object - */ -export type IAddress = IObjectWithId<'Address'> & { - /** - * First line of the address - */ - street1?: string | null; - /** - * Second line of the address - */ - street2?: string | null; - /** - * City the address is located in - */ - city?: string | null; - /** - * State or province the address is located in - */ - state?: string | null; - /** - * ZIP or postal code the address is located in - */ - zip: string; - /** - * ISO 3166 country code for the country the address is located in - */ - country: string; - /** - * Whether or not this address would be considered residential - */ - residential?: boolean | null; - /** - * The specific designation for the address (only relevant if the address is a carrier facility) - */ - carrier_facility?: string | null; - /** - * Name of the person. Both name and company can be included - */ - name?: string | null; - /** - * Name of the organization. Both name and company can be included - */ - company?: string | null; - /** - * Phone number to reach the person or organization - */ - phone?: string | null; - /** - * Email to reach the person or organization - */ - email?: string | null; - /** - * Federal tax identifier of the person or organization - */ - federal_tax_id?: string | null; - /** - * State tax identifier of the person or organization - */ - state_tax_id?: string | null; - /** - * The result of any verifications requested - */ - verifications: IVerifications; -}; diff --git a/types/services/address_service/AddressCreateParameters.d.ts b/types/services/address_service/AddressCreateParameters.d.ts deleted file mode 100644 index 67b6a50ff..000000000 --- a/types/services/address_service/AddressCreateParameters.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { IAddress } from './Address'; -/** - * @see https://www.easypost.com/docs/api/node#create-and-verify-addresses - */ -export type IAddressCreateParameters = Omit< - IAddress, - ParametersToOmitOnCreate | 'verifications' -> & { - /** - * The verifications to perform when creating. - * verify_strict takes precedence. - * true will perform both delivery and zip code. - */ - verify?: boolean | null; - /** - * The verifications to perform when creating. - * The failure of any of these verifications causes the whole request to fail. - * true will perform both delivery and zip code. - */ - verify_strict?: boolean | null; -}; diff --git a/types/services/address_service/AddressListParameters.d.ts b/types/services/address_service/AddressListParameters.d.ts deleted file mode 100644 index cb9b95716..000000000 --- a/types/services/address_service/AddressListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api#retrieve-a-list-of-addresses - */ -export type IAddressListParameters = IAllMethodParameters; diff --git a/types/services/address_service/Verification.d.ts b/types/services/address_service/Verification.d.ts deleted file mode 100644 index 6e547eb54..000000000 --- a/types/services/address_service/Verification.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { IFieldError } from '../../utils/errors'; -import { IVerificationDetails } from './VerificationDetails'; -/** - * @see https://www.easypost.com/docs/api/node#verification-object - */ -export type IVerification = { - /** - * The success of the verification - */ - success: boolean; - /** - * All errors that caused the verification to fail - */ - errors: IFieldError[]; - /** - * Extra data related to the verification - */ - details: IVerificationDetails; -}; diff --git a/types/services/address_service/VerificationDetails.d.ts b/types/services/address_service/VerificationDetails.d.ts deleted file mode 100644 index 6ce352800..000000000 --- a/types/services/address_service/VerificationDetails.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * @see https://www.easypost.com/docs/api/node#verification_details-object - */ -export type IVerificationDetails = { - /** - * The latitude of an Address. - */ - latitude: number; - /** - * The longitude of an Address. - */ - longitude: number; - /** - * The time zone the address is located in, IE: America/Los_Angeles - */ - time_zone: string; -}; diff --git a/types/services/address_service/Verifications.d.ts b/types/services/address_service/Verifications.d.ts deleted file mode 100644 index 85ea98d5b..000000000 --- a/types/services/address_service/Verifications.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { IVerification } from './Verification'; -/** - * @see https://www.easypost.com/docs/api/node#verifications-object - */ -export type IVerifications = { - /** - * Only applicable to US addresses - checks and sets the ZIP+4 - */ - zip4: IVerification; - /** - * Checks that the address is deliverable and makes minor corrections to spelling/format. US addresses will also have their "residential" status checked and set. - */ - delivery: IVerification; -}; -declare const _default: {}; -export default _default; diff --git a/types/services/address_service/index.d.ts b/types/services/address_service/index.d.ts deleted file mode 100644 index ab557c1c7..000000000 --- a/types/services/address_service/index.d.ts +++ /dev/null @@ -1,105 +0,0 @@ -import EasyPost from '../..'; -import { IAddress } from './Address'; -import { IAddressCreateParameters } from './AddressCreateParameters'; -import { IAddressListParameters } from './AddressListParameters'; -export * from './Address'; -export * from './AddressCreateParameters'; -export * from './Verification'; -export * from './VerificationDetails'; -export * from './Verifications'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create an {@link Address address}. - * See {@link https://www.easypost.com/docs/api/node#create-an-address EasyPost API Documentation} for more information. - * @param params - Parameters for the address to be created. - * @returns - The created address. - */ - create( - params: IAddressCreateParameters, - ): Promise>; - /** - * Create and verify an {@link Address address} in a single request. - * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. - * @param params - Parameters for the address to be created. - * @returns - The created and verified address. - */ - createAndVerify(params: IAddressCreateParameters): Promise; - /** - * Retrieve all {@link Address addresses} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-addresses EasyPost API Documentation} for more information. - * @param params - Parameters to filter the list of addresses. - * @returns - An object containing a list of {@link Address addresses} and pagination information. - */ - all(params?: IAddressListParameters): Promise< - { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of Address collection. - * @param addresses An object containing a list of {@link Address addresses} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - addresses: { - addresses: IAddress[]; - }, - pageSize?: number | null, - ): Promise< - { - addresses: IAddress[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve an {@link Address address} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-address EasyPost API Documentation} for more information. - * @param id - The ID of the address to retrieve. - * @returns - The retrieved address. - */ - retrieve(id: string): Promise>; - /** - * Verify an {@link Address address} by its ID. - * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. - * @param id - The ID of the address to verify. - * @returns - The verified address. - */ - verifyAddress(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/api_key_service/ApiKey.d.ts b/types/services/api_key_service/ApiKey.d.ts deleted file mode 100644 index c11cf642e..000000000 --- a/types/services/api_key_service/ApiKey.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { IObjectWithId } from '../../utils/types'; -export type IApiKey = IObjectWithId<'ApiKey'> & { - /** - * The actual key value to use for authentication - */ - key: string; - /** - * When the API key was created - */ - created_at: string; - /** - * Whether the API key is active or not - */ - active: boolean; -}; -export type UserAPIKeys = { - id: string; - keys: IApiKey[]; - children: UserAPIKeys[]; -}; diff --git a/types/services/api_key_service/index.d.ts b/types/services/api_key_service/index.d.ts deleted file mode 100644 index 972a59b27..000000000 --- a/types/services/api_key_service/index.d.ts +++ /dev/null @@ -1,71 +0,0 @@ -import EasyPost from '../..'; -import { IApiKey } from './ApiKey'; -export * from './ApiKey'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Retrieve all {@link ApiKey API keys} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. - * @returns - An object containing the API keys associated with the current authenticated user and its child users. - */ - all(params?: {}): Promise< - import('../../utils/types').IBaseObject<'ApiKey'> & { - id: string; - mode: 'test' | 'production'; - object: 'ApiKey'; - } & { - key: string; - created_at: string; - active: boolean; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve API Keys for a specified {@link User user}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. - * @param id - The ID of the user to retrieve keys for. - * @returns - List of associated API Keys. - * @throws {FilteringError} If user or API Keys are not found. - */ - retrieveApiKeysForUser(id: string): Promise; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject - /** - * Retrieve API Keys for a specified {@link User user}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. - * @param id - The ID of the user to retrieve keys for. - * @returns - List of associated API Keys. - * @throws {FilteringError} If user or API Keys are not found. - */; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/base_service.d.ts b/types/services/base_service.d.ts deleted file mode 100644 index 51048730a..000000000 --- a/types/services/base_service.d.ts +++ /dev/null @@ -1,71 +0,0 @@ -import EasyPostClient from '../easypost'; -export type EasyPostObject = A & { - _params: any; -}; -declare const _default: (easypostClient: EasyPostClient) => { - new (): {}; - /** - * Converts a JSON response and all its nested elements to associated {@link EasyPostObject}-based class instances. - * @internal - * @param {*} response The JSON response to convert (usually a `Map` or `Array`). - * @param {*} params The parameters passed when fetching the response - * @returns {*} An {@link EasyPostObject}-based class instance or an `Array` of {@link EasyPostObject}-based class instances. - */ - _convertToEasyPostObject(response: A, params?: any): EasyPostObject; - /** - * Creates an EasyPost Object via the API. - * @internal - * @param url The URL to send the API request to. - * @param params The parameters to send with the API request. - * @returns The created {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - _create(url: string, params: object): Promise>; - /** - * Retrieve a list of records from the API. - * @internal - * @param url The URL to send the API request to. - * @param params The parameters to send with the API request. - * @returns The retrieved {@link EasyPostObject}-based class instance(s), or a `Promise` that rejects with an error. - */ - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a record from the API. - * @internal - * @param url The URL to send the API request to. - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - _retrieve(url: string): Promise>; - /** - * Retrieve the next page of specific collection of object - * @internal - * @param url The URL to send the API request to. - * @param collection The collection of a specific object. - * @param pageSize The number of records to return on each page. - * @param optionalParams The optional param for additional value in the query string. - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - * TODO: Implement this function in EndShippers and Batches once the API supports them properly. - */ - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/batch_service/Batch.d.ts b/types/services/batch_service/Batch.d.ts deleted file mode 100644 index cdd5ee354..000000000 --- a/types/services/batch_service/Batch.d.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { IPickup } from '../pickup_service/Pickup'; -import { IScanForm } from '../scan_form_service'; -import { IBatchShipment } from './BatchShipment'; -import { TBatchState } from './BatchState'; -import { TBatchStatuses } from './BatchStatuses'; -/** - * The Batch object allows you to perform operations on multiple Shipments at once. - * This includes scheduling a Pickup, creating a ScanForm and consolidating labels. - * Operations performed on Batches are asynchronous and take advantage of our webhook infrastructure. - * - * @see https://www.easypost.com/docs/api/node#batch-object - */ -export type IBatch = IObjectWithId<'Batch'> & - IDatedObject & { - /** - * An optional field that may be used in place of ID in some API endpoints - */ - reference?: string | null; - /** - * The overall state. Possible values are "creating", "creation_failed", "created", "purchasing", "purchase_failed", "purchased", "label_generating", and "label_generated" - */ - state: TBatchState; - /** - * The number of shipments added - */ - num_shipments: number; - /** - * An array of batch shipments - */ - shipments: IBatchShipment[]; - /** - * A map of BatchShipment statuses to the count of BatchShipments with that status. Valid statuses are "postage_purchased", "postage_purchase_failed", "queued_for_purchase", and "creation_failed" - */ - status: TBatchStatuses; - /** - * The label image url - */ - label_url?: string | null; - /** - * The created ScanForm - */ - scan_form: IScanForm; - /** - * The created Pickup - */ - pickup: IPickup; - }; diff --git a/types/services/batch_service/BatchCreateParameters.d.ts b/types/services/batch_service/BatchCreateParameters.d.ts deleted file mode 100644 index b778883b5..000000000 --- a/types/services/batch_service/BatchCreateParameters.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -export type IBatchCreateParameters = { - shipments?: ( - | { - id: string; - } - | string - )[]; -}; diff --git a/types/services/batch_service/BatchListParameters.d.ts b/types/services/batch_service/BatchListParameters.d.ts deleted file mode 100644 index 38f453d9f..000000000 --- a/types/services/batch_service/BatchListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#list-all-batches - */ -export type IBatchListParameters = IAllMethodParameters; diff --git a/types/services/batch_service/BatchShipment.d.ts b/types/services/batch_service/BatchShipment.d.ts deleted file mode 100644 index 48c669792..000000000 --- a/types/services/batch_service/BatchShipment.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { TBatchStatus } from './BatchStatus'; -/** - * @see https://www.easypost.com/docs/api/node#batch-shipment-object - */ -export type IBatchShipment = { - /** - * The id of the Shipment. Unique, begins with "shp_" - */ - id: string; - /** - * An optional field that may be used in place of ID in some API endpoints - */ - reference?: string | null; - /** - * The current status. Possible values are "postage_purchased", "postage_purchase_failed", "queued_for_purchase", "creation_failed", and "created" - */ - batch_status: TBatchStatus; - /** - * A human readable message for any errors that occurred during the Batch's life cycle - */ - batch_message: string; -}; diff --git a/types/services/batch_service/BatchState.d.ts b/types/services/batch_service/BatchState.d.ts deleted file mode 100644 index 41fa51e7a..000000000 --- a/types/services/batch_service/BatchState.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -export type TBatchState = - | 'creating' - | 'creation_failed' - | 'created' - | 'purchasing' - | 'purchase_failed' - | 'purchased' - | 'label_generating' - | 'label_generated'; diff --git a/types/services/batch_service/BatchStatus.d.ts b/types/services/batch_service/BatchStatus.d.ts deleted file mode 100644 index c85d419dc..000000000 --- a/types/services/batch_service/BatchStatus.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export type TBatchStatus = - | 'postage_purchased' - | 'postage_purchase_failed' - | 'queued_for_purchase' - | 'creation_failed' - | 'created'; diff --git a/types/services/batch_service/BatchStatuses.d.ts b/types/services/batch_service/BatchStatuses.d.ts deleted file mode 100644 index 7795213f7..000000000 --- a/types/services/batch_service/BatchStatuses.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { TBatchStatus } from './BatchStatus'; -export type TBatchStatuses = { - [key in TBatchStatus]: number; -}; diff --git a/types/services/batch_service/index.d.ts b/types/services/batch_service/index.d.ts deleted file mode 100644 index b815b9db2..000000000 --- a/types/services/batch_service/index.d.ts +++ /dev/null @@ -1,132 +0,0 @@ -import EasyPost from '../..'; -import { IBatch } from './Batch'; -import { IBatchCreateParameters } from './BatchCreateParameters'; -import { IBatchListParameters } from './BatchListParameters'; -export * from './Batch'; -export * from './BatchCreateParameters'; -export * from './BatchListParameters'; -export * from './BatchShipment'; -export * from './BatchState'; -export * from './BatchStatus'; -export * from './BatchStatuses'; -export declare const DEFAULT_LABEL_FORMAT = 'pdf'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#create-a-batch EasyPost API Documentation} for more information. - * @param params - Parameters for the batch to be created. - * @returns - The created batch. - */ - create(params: IBatchCreateParameters): Promise>; - /** - * Add {@link Shipment shipments} to a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#add-shipments-to-a-batch EasyPost API Documentation} for more information. - * @param id - The id of the batch to add shipments to. - * @param shipmentIds - The ids of the shipments to add to the batch. - * @returns - The updated batch. - */ - addShipments( - id: string, - shipmentIds: string[], - ): Promise>; - /** - * Removes {@link Shipment shipments} from a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#remove-shipments-from-a-batch EasyPost API Documentation} for more information. - * @param id - The id of the batch to remove shipments from. - * @param shipmentIds - The ids of the shipments to remove from the batch. - * @returns - The updated batch. - */ - removeShipments( - id: string, - shipmentIds: string[], - ): Promise>; - /** - * Generate a label for a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#batch-labels EasyPost API Documentation} for more information. - * @param id - The id of the batch to generate a label for. - * @param fileFormat - The format of the label to generate. Defaults to 'pdf'. - * @returns - The updated batch. - */ - generateLabel( - id: string, - fileFormat?: string, - ): Promise>; - /** - * Create a {@link ScanForm scan form} for a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#manifesting-scan-form EasyPost API Documentation} for more information. - * @param id - The id of the batch to create a scan form for. - * @returns - The updated batch. - */ - createScanForm(id: string): Promise>; - /** - * Purchase a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-batch EasyPost API Documentation} for more information. - * @param id - The id of the batch to purchase. - * @returns - The purchased batch. - */ - buy(id: string): Promise>; - /** - * Retrieve all {@link Batch batches} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#list-all-batches EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of batches. - * @returns - An object containing a list of {@link Batch batches} and pagination information. - */ - all(params?: IBatchListParameters): Promise< - import('../../utils/types').IBaseObject<'Batch'> & { - id: string; - mode: 'test' | 'production'; - object: 'Batch'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - state: import('./BatchState').TBatchState; - num_shipments: number; - shipments: import('./BatchShipment').IBatchShipment[]; - status: import('./BatchStatuses').TBatchStatuses; - label_url?: string | null | undefined; - scan_form: import('..').IScanForm; - pickup: import('../pickup_service/Pickup').IPickup; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link Batch batch} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-batch EasyPost API Documentation} for more information. - * @param id - The ID of the batch to retrieve. - * @returns - The retrieved batch. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/beta_rate_service/index.d.ts b/types/services/beta_rate_service/index.d.ts deleted file mode 100644 index bc4eeca1e..000000000 --- a/types/services/beta_rate_service/index.d.ts +++ /dev/null @@ -1,44 +0,0 @@ -import EasyPost from '../..'; -import { IRate } from '../rate_service/Rate'; -/** - * @extends baseService - */ -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Retrieve a list of stateless {@link Rate rates} based on the provided parameters. - * @param params - Map of parameters for the API call - * @returns - List of stateless rates - */ - retrieveStatelessRates(params: any): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/beta_referral_customer_service/index.d.ts b/types/services/beta_referral_customer_service/index.d.ts deleted file mode 100644 index dd8a712ae..000000000 --- a/types/services/beta_referral_customer_service/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -import EasyPost from '../..'; -import { IPaymentMethod } from '../billing_service'; -import { IRefund } from '../refund_service'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Add an existing Stripe payment method to a {@link User referral customer's} account. - * @param stripeCustomerId - The Stripe account's ID. - * @param paymentMethodReference - Reference of Stripe payment method. - * @param [priority] - Which priority to set the payment method to ('primary' or 'secondary'). - * @returns - A JSON object representing the payment method. - */ - addPaymentMethod( - stripeCustomerId: string, - paymentMethodReference: string, - priority?: 'primary' | 'secondary', - ): Promise; - /** - * Refund by amount for a recent payment. - * @param refundAmount - Amount to be refunded by cents. - * @returns - A JSON object representing the refund. - */ - refundByAmount(refundAmount: number): Promise; - /** - * Refund a payment by a payment log ID. - * @param paymentLogId - ID of the payment log. - * @returns - Returns BetaPaymentRefund object. - */ - refundByPaymentLog(paymentLogId: string): Promise; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/billing_service/PaymentMethod.d.ts b/types/services/billing_service/PaymentMethod.d.ts deleted file mode 100644 index 5680f3db0..000000000 --- a/types/services/billing_service/PaymentMethod.d.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { IObjectWithId } from '../../utils/types'; -/** - * The Payment method object can be either credit card or bank account. - * - * TODO: Add the link to the API doc once its updated - */ -export type IPaymentMethod = IObjectWithId<'PaymentMethod'> & { - /** - * Country of the bank account - */ - country: string; - /** - * Name of the bank - */ - bank_name: string; - /** - * Brand of the credit card - */ - brand: string; - /** - * Whether the payment method(credit card or bank account) is disabled or not - */ - disabled_at: string; - /** - * Expiration month of the credit card - */ - exp_month: number; - /** - * Expiration year of the credit card - */ - exp_year: number; - /** - * Last four of the credit card - */ - last4: string; - /** - * Name of the credit card - */ - name: string; - /** - * Whether the bank account is verified or not - */ - verified: boolean; -}; diff --git a/types/services/billing_service/index.d.ts b/types/services/billing_service/index.d.ts deleted file mode 100644 index dc097c109..000000000 --- a/types/services/billing_service/index.d.ts +++ /dev/null @@ -1,63 +0,0 @@ -import EasyPost from '../..'; -export * from './PaymentMethod'; -export type Priority = 'primary' | 'secondary'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Fund your EasyPost wallet by charging your primary or secondary payment method on file. - * See {@link https://www.easypost.com/docs/api/node#add-funds-to-your-wallet-one-time-charge EasyPost API Documentation} for more information. - * @param amount - The amount to charge to your payment method. - * @param priority - The priority of the payment method to charge. Can be either 'primary' or 'secondary'. - */ - fundWallet(amount: string, priority?: Priority): Promise; - /** - * Delete a payment method from the current authenticated user's account. - * See {@link https://www.easypost.com/docs/api/node#delete-a-payment-method EasyPost API Documentation} for more information. - * @param priority - The priority of the payment method to delete. Can be either 'primary' or 'secondary'. - */ - deletePaymentMethod(priority: Priority): Promise; - /** - * Retrieve all payment methods associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-payment-methods EasyPost API Documentation} for more information. - * @returns {Object} - An object containing the payment methods associated with the current authenticated user. - */ - retrievePaymentMethods(): Promise; - /** - * Get payment info (type of the payment method and ID of the payment method) - * This function is intended for internal use only, please avoid using this function - * @private - * @param {String} priority - The priority of the payment method to retrieve. Can be either 'primary' or 'secondary'. - * @returns {string[]} - An array of two strings, the first being the endpoint of the payment method and the second being the ID of the payment method. - */ - _getPaymentInfo(priority: Priority): Promise; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/carrier_account_service/CarrierAccount.d.ts b/types/services/carrier_account_service/CarrierAccount.d.ts deleted file mode 100644 index 18d31c329..000000000 --- a/types/services/carrier_account_service/CarrierAccount.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { ICarrierAccountFields } from './CarrierAccountFields'; -/** - * A CarrierAccount encapsulates your credentials with the carrier. - * The CarrierAccount object provides CRUD operations for all CarrierAccounts. - * - * Each EasyPost account is automatically provided a USPS account managed by EasyPost. - * - * Other operations, such as Shipment creation, can reference CarrierAccounts to reduce the scope of data returned. - * For instance, you may have multiple warehouses that need to use distinct FedEx SmartPost credentials to request the correct rates. - * Rate objects will include a `carrier_account_id` field which can be used to determine the account used for rating. - * - * @see https://www.easypost.com/docs/api/node#carrier-account-object - */ -export type ICarrierAccount = IObjectWithId<'CarrierAccount'> & - IDatedObject & { - /** - * The name of the carrier type. - */ - type: string; - /** - * Contains "credentials" and/or "test_credentials", or may be empty - */ - fields: ICarrierAccountFields; - /** - * If clone is true, only the reference and description are possible to update - */ - clone?: boolean | null; - /** - * An optional, user-readable field to help distinguish accounts - */ - description?: string | null; - /** - * An optional field that may be used in place of carrier_account_id in other API endpoints - */ - reference?: string | null; - /** - * The name used when displaying a readable value for the type of the account - */ - readable: string; - /** - * Unlike the "credentials" object contained in "fields", this nullable object contains just raw credential pairs for client library consumption - */ - credentials?: object | null; - /** - * Unlike the "test_credentials" object contained in "fields", this nullable object contains just raw test_credential pairs for client library consumption - */ - test_credentials?: object | null; - /** - * Billing type of the carrier account - */ - billing_type: string | null; - }; diff --git a/types/services/carrier_account_service/CarrierAccountCreateParameters.d.ts b/types/services/carrier_account_service/CarrierAccountCreateParameters.d.ts deleted file mode 100644 index c92ebd574..000000000 --- a/types/services/carrier_account_service/CarrierAccountCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { ICarrierAccount } from './CarrierAccount'; -export type ICarrierAccountCreateParameters = Omit; diff --git a/types/services/carrier_account_service/CarrierAccountField.d.ts b/types/services/carrier_account_service/CarrierAccountField.d.ts deleted file mode 100644 index 3d13bf156..000000000 --- a/types/services/carrier_account_service/CarrierAccountField.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @see https://www.easypost.com/docs/api/node#carrier-account-field-object - */ -export type ICarrierAccountField = { - /** - * Each key in the sub-objects of a CarrierAccount's fields is the name of a settable field - */ - key: string; - /** - * The visibility value is used to control form field types, and is discussed in the CarrierType section - */ - visibility: string; - /** - * The label value is used in form rendering to display a more precise field name - */ - label: string; - /** - * Checkbox fields use "0" and "1" as False and True, all other field types present plaintext, partly-masked, or masked credential data for reference - */ - value: string; -}; diff --git a/types/services/carrier_account_service/CarrierAccountFields.d.ts b/types/services/carrier_account_service/CarrierAccountFields.d.ts deleted file mode 100644 index 4371a867f..000000000 --- a/types/services/carrier_account_service/CarrierAccountFields.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ICarrierAccountField } from './CarrierAccountField'; -/** - * @see https://www.easypost.com/docs/api/node#carrier-account-fields-object - */ -export type ICarrierAccountFields = { - /** - * Credentials used in the production environment. - */ - credentials: ICarrierAccountField; - /** - * Credentials used in the test environment. - */ - test_credentials: ICarrierAccountField; - /** - * For USPS this designates that no credentials are required. - */ - auto_link: boolean; - /** - * When present, a separate authentication process will be required through the UI to link this account type. - */ - custom_workflow: boolean; -}; diff --git a/types/services/carrier_account_service/index.d.ts b/types/services/carrier_account_service/index.d.ts deleted file mode 100644 index 8415d712a..000000000 --- a/types/services/carrier_account_service/index.d.ts +++ /dev/null @@ -1,116 +0,0 @@ -import EasyPost from '../..'; -import { ICarrierAccount } from './CarrierAccount'; -import { ICarrierAccountCreateParameters } from './CarrierAccountCreateParameters'; -export * from './CarrierAccount'; -export * from './CarrierAccountCreateParameters'; -export * from './CarrierAccountField'; -export * from './CarrierAccountFields'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link CarrierAccount carrier account}. - * See {@link https://www.easypost.com/docs/api/node#create-a-carrier-account EasyPost API Documentation} for more information. - * @param params - Parameters for the carrier account to be created. - * @returns - The created carrier account. - */ - create( - params: ICarrierAccountCreateParameters, - ): Promise>; - /** - * Update a {@link CarrierAccount carrier account}. - * See {@link https://www.easypost.com/docs/api/node#update-a-carrieraccount EasyPost API Documentation} for more information. - * @param id - The id of the carrier account to be updated. - * @param params - Parameters for the carrier account to be updated. - * @returns - The updated carrier account. - */ - update( - id: string, - params: Partial, - ): Promise>; - /** - * Delete a {@link CarrierAccount carrier account}. - * See {@link https://www.easypost.com/docs/api/node#delete-a-carrier-account EasyPost API Documentation} for more information. - * @param id - The id of the carrier account to be deleted. - * @returns - A promise that resolves when the carrier account has been deleted. - */ - delete(id: string): Promise; - /** - * Returns the correct carrier_account endpoint when creating a record based on the type. - * @private - * @param {string} carrierAccountType - The type of carrier account to be created. - * @returns {string} - The endpoint to be used for the carrier account creation request. - */ - _selectCarrierAccountCreationEndpoint( - carrierAccountType: string, - ): 'carrier_accounts/register' | 'carrier_accounts'; - /** - * Retrieve all {@link CarrierAccount carrier accounts} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#list-all-carrier-accounts EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of carrier accounts. - * @returns - An object containing a list of {@link CarrierAccount carrier accounts} and pagination information. - */ - all(params?: {}): Promise< - import('../../utils/types').IBaseObject<'CarrierAccount'> & { - id: string; - mode: 'test' | 'production'; - object: 'CarrierAccount'; - } & import('../../utils/types').IDatedObject & { - type: string; - fields: import('./CarrierAccountFields').ICarrierAccountFields; - clone?: boolean | null | undefined; - description?: string | null | undefined; - reference?: string | null | undefined; - readable: string; - credentials?: object | null | undefined; - test_credentials?: object | null | undefined; - billing_type: string | null; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link CarrierAccount carrier account} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-carrieraccount EasyPost API Documentation} for more information. - * @param id - The ID of the carrier account to retrieve. - * @returns - The retrieved carrier account. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean - /** - * Retrieve all {@link CarrierAccount carrier accounts} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#list-all-carrier-accounts EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of carrier accounts. - * @returns - An object containing a list of {@link CarrierAccount carrier accounts} and pagination information. - */; - } - >; -}; -export default _default; diff --git a/types/services/carrier_metadata_service/CarrierMetadata.d.ts b/types/services/carrier_metadata_service/CarrierMetadata.d.ts deleted file mode 100644 index 4f76eebc3..000000000 --- a/types/services/carrier_metadata_service/CarrierMetadata.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -/** - * The Carrier Metadata endpoint returns information about all the carriers available on the EasyPost platform. - * This information may include service levels, predefined packages, shipment options, supported features, and - * more that are available per carrier. This metadata can be useful during onboarding and integration or when - * determining the ideal carrier mix for your setup. - * - * @see https://www.easypost.com/docs/api/node#carriermetadata-object - */ -export type ICarrierMetadata = { - /** - * The single-word name of a carrier such as "royalmail" - */ - carrier: string; - /** - * The human-readable name of the carrier - */ - human_readable?: string | null; - /** - * A list of service level objects for this carrier - */ - service_levels?: Array | null; - /** - * A list of predefined package objects for this carrier - */ - predefined_packages?: Array | null; - /** - * A list of supported feature objects for this carrier - */ - supported_features?: Array | null; - /** - * A list of shipment option objects for this carrier - */ - shipment_options?: Array | null; -}; diff --git a/types/services/carrier_metadata_service/index.d.ts b/types/services/carrier_metadata_service/index.d.ts deleted file mode 100644 index 91a1f62e3..000000000 --- a/types/services/carrier_metadata_service/index.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import EasyPost from '../..'; -import { ICarrierMetadata } from './CarrierMetadata'; -export * from './CarrierMetadata'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Retrieve a list of carrier metadata based on the provided parameters. - * @param carriers - List of carrier in string - * @param type - List of types in string - * @returns - List of carrier metadata - */ - retrieve( - carriers?: string[] | null, - types?: string[] | null, - ): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/carrier_type_service/CarrierType.d.ts b/types/services/carrier_type_service/CarrierType.d.ts deleted file mode 100644 index 755c25a0e..000000000 --- a/types/services/carrier_type_service/CarrierType.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { IBaseObject } from '../../utils/types'; -import { ICarrierTypeFields } from './CarrierTypeFields'; -/** - * The CarrierType object provides an export declare interface for determining the valid fields of a CarrierAccount. - * The list of CarrierType objects only changes when a new carrier is added to EasyPost. - * - * The CarrierType objects consist of their top level attributes as well as a fields object that contains credentials and sometimes test_credentials sub-objects, - * which themselves are collections of attributes for CarrierAccount creation as well as metadata about presentation and the naming of said attributes. - * - * There are a couple special case CarrierAccounts, with structures differing somewhat from the norm. - * For instance, instead of credentials for UspsAccount, it has only auto_link: true, which indicates that it is an account that can be added or removed without any carrier-specific fields. - * - * The other custom option in the fields list is custom_workflow: true, which indicates that the EasyPost website export declare interface includes special processing for signups for the associated CarrierType. - * Carriers with a custom workflow will also present their normal credential rules, but it is considered unsafe to directly add a CarrierAccount of this type with these attributes filled out via another source than the EasyPost custom workflow. - * - * @see https://www.easypost.com/docs/api/node#carrier-type-object - */ -export type ICarrierType = IBaseObject<'CarrierType'> & { - /** - * Specifies the CarrierAccount type. - */ - type: string; - /** - * Contains at least one of the following keys: "auto_link", "credentials", "test_credentials", and "custom_workflow" - */ - fields: ICarrierTypeFields; -}; diff --git a/types/services/carrier_type_service/CarrierTypeCredentials.d.ts b/types/services/carrier_type_service/CarrierTypeCredentials.d.ts deleted file mode 100644 index 53653ec07..000000000 --- a/types/services/carrier_type_service/CarrierTypeCredentials.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * @see https://www.easypost.com/docs/api/node#carrier-type-credentials-object - */ -export type ICarrierTypeCredentials = { - /** - * The key for each attribute sub-object within credentials is the name of the attribute for submission on CarrierAccounts - */ - name: string; - /** - * There are five possible values, which encode the security need and storage type for each attribute: "visible", "checkbox", "fake", "password", and "masked" - */ - visibility: 'visible' | 'checkbox' | 'fake' | 'password' | 'masked'; - /** - * Most attributes have generic names, so for clarity a "label" value is provided for clearer representation when rendering forms - */ - label: string; -}; diff --git a/types/services/carrier_type_service/CarrierTypeFields.d.ts b/types/services/carrier_type_service/CarrierTypeFields.d.ts deleted file mode 100644 index 0eea6b8cc..000000000 --- a/types/services/carrier_type_service/CarrierTypeFields.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ICarrierTypeCredentials } from './CarrierTypeCredentials'; -/** - * @see https://www.easypost.com/docs/api/node#carrier-type-fields-object - */ -export type ICarrierTypeFields = { - /** - * If this key is present with the value of true, no other attributes are needed for CarrierAccount creation - */ - auto_link: boolean; - /** - * If this key is present with the value of true, CarrierAccount creation of this type requires extra work not handled by the CarrierAccount standard API - */ - custom_workflow: boolean; - /** - * If this object is present, required attribute names and their metadata are presented inside - */ - credentials: ICarrierTypeCredentials; - /** - * If this object is present, it contains attribute names and metadata just as the credentials object. - * It is not required for CarrierAccount creation if you do not plan on using the carrier account for test mode - */ - test_credentials: ICarrierTypeCredentials; -}; diff --git a/types/services/carrier_type_service/index.d.ts b/types/services/carrier_type_service/index.d.ts deleted file mode 100644 index f220bcf91..000000000 --- a/types/services/carrier_type_service/index.d.ts +++ /dev/null @@ -1,45 +0,0 @@ -import EasyPost from '../..'; -import { ICarrierType } from './CarrierType'; -export * from './CarrierType'; -export * from './CarrierTypeCredentials'; -export * from './CarrierTypeFields'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Retrieve all {@link CarrierType carrier types} available to the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-available-carrier-types EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of carrier types. - * @returns - A list of {@link CarrierType carrier types}. - */ - all(params?: {}): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/customs_info_service/CustomsInfo.d.ts b/types/services/customs_info_service/CustomsInfo.d.ts deleted file mode 100644 index ce91e3287..000000000 --- a/types/services/customs_info_service/CustomsInfo.d.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { ICustomsItem } from '../customs_item_service'; -/** - * CustomsInfo objects contain CustomsItem objects and all necessary information for the generation of customs forms required for international shipping. - * - * Please see the Shipments documentation for examples of including a CustomsInfo object in a shipment. - * - * @see https://www.easypost.com/docs/api/node#customs-info-object - */ -export type ICustomsInfo = IObjectWithId<'CustomsInfo'> & - IDatedObject & { - /** - * "EEL" or "PFC" - * value less than $2500: "NOEEI 30.37(a)" - * value greater than $2500: see [Customs Guide](https://www.easypost.com/customs-guide) - */ - eel_pfc?: string | null; - /** - * "documents", "gift", "merchandise", "returned_goods", "sample", or "other" - */ - contents_type?: string | null; - /** - * (max 255 characters) Human readable description of content. - * Required for certain carriers and always required if contents_type is "other" - */ - contents_explanation?: string | null; - /** - * Electronically certify the information provided - */ - customs_certify?: boolean | null; - /** - * Required if customs_certify is true - */ - customs_signer?: string | null; - /** - * "abandon" or "return", defaults to "return" - */ - non_delivery_option?: 'abandon' | 'return' | null; - /** - * "none", "other", "quarantine", or "sanitary_phytosanitary_inspection" - */ - restriction_type?: 'none' | 'other' | 'quarantine' | 'sanitary_phytosanitary_inspection' | null; - /** - * Required if restriction_type is not "none" - */ - restriction_comments?: string | null; - /** - * Describes the products being shipped - */ - customs_items: ICustomsItem[]; - /** - * A customs declaration message, available for eligible carriers - */ - declaration?: string | null; - }; diff --git a/types/services/customs_info_service/CustomsInfoCreateParameters.d.ts b/types/services/customs_info_service/CustomsInfoCreateParameters.d.ts deleted file mode 100644 index c3a689c41..000000000 --- a/types/services/customs_info_service/CustomsInfoCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { ICustomsInfo } from './CustomsInfo'; -export type ICustomsInfoCreateParameters = Omit; diff --git a/types/services/customs_info_service/index.d.ts b/types/services/customs_info_service/index.d.ts deleted file mode 100644 index 718ff65af..000000000 --- a/types/services/customs_info_service/index.d.ts +++ /dev/null @@ -1,54 +0,0 @@ -import EasyPost from '../..'; -import { ICustomsInfo } from './CustomsInfo'; -import { ICustomsInfoCreateParameters } from './CustomsInfoCreateParameters'; -export * from './CustomsInfo'; -export * from './CustomsInfoCreateParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link CustomsInfo customs info} record. - * See {@link https://www.easypost.com/docs/api/node#create-a-customsinfo EasyPost API Documentation} for more information. - * @param params - Parameters for the customs info to be created. - * @returns - The created customs info. - */ - create( - params: ICustomsInfoCreateParameters, - ): Promise>; - /** - * Retrieve a {@link CustomsInfo customs info} record by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-customsinfo EasyPost API Documentation} for more information. - * @param id - The ID of the customs info to retrieve. - * @returns - The retrieved customs info. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/customs_item_service/CustomsItem.d.ts b/types/services/customs_item_service/CustomsItem.d.ts deleted file mode 100644 index 2852a841b..000000000 --- a/types/services/customs_item_service/CustomsItem.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * A CustomsItem object describes goods for international shipment and should be created then included in a CustomsInfo object. - * - * @see https://www.easypost.com/docs/api/node#customs-item-object - */ -export type ICustomsItem = IObjectWithId<'CustomsItem'> & - IDatedObject & { - /** - * Required, description of item being shipped - */ - description: string; - /** - * Required, greater than zero - * float - */ - quantity: number; - /** - * Required, greater than zero, total value (unit value * quantity) - * float (USD) - */ - value: number; - /** - * Required, greater than zero, total weight (unit weight * quantity) - * float (oz) - */ - weight: number; - /** - * Harmonized Tariff Schedule, e.g. "6109.10.0012" for Men's T-shirts - * - * @see https://hts.usitc.gov/ - */ - hs_tariff_number?: string | null; - /** - * SKU/UPC or other product identifier - */ - code?: string | null; - /** - * Required, 2 char country code - */ - origin_country: string; - /** - * 3 char currency code, default USD - */ - currency?: string | null; - }; diff --git a/types/services/customs_item_service/CustomsItemCreateParameters.d.ts b/types/services/customs_item_service/CustomsItemCreateParameters.d.ts deleted file mode 100644 index 4ac2ff6d7..000000000 --- a/types/services/customs_item_service/CustomsItemCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { ICustomsItem } from './CustomsItem'; -export type ICustomsItemCreateParameters = Omit; diff --git a/types/services/customs_item_service/index.d.ts b/types/services/customs_item_service/index.d.ts deleted file mode 100644 index c8d46b2d2..000000000 --- a/types/services/customs_item_service/index.d.ts +++ /dev/null @@ -1,54 +0,0 @@ -import EasyPost from '../..'; -import { ICustomsItem } from './CustomsItem'; -import { ICustomsItemCreateParameters } from './CustomsItemCreateParameters'; -export * from './CustomsItem'; -export * from './CustomsItemCreateParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link CustomsItem customs item}. - * See {@link https://www.easypost.com/docs/api/node#create-a-customsitem EasyPost API Documentation} for more information. - * @param params - Parameters for the customs item to be created. - * @returns - The created customs item. - */ - create( - params: ICustomsItemCreateParameters, - ): Promise>; - /** - * Retrieve a {@link CustomsItem customs item} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-customsitem EasyPost API Documentation} for more information. - * @param id - The ID of the customs item to retrieve. - * @returns - The retrieved customs item. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/end_shipper_service/EndShipper.d.ts b/types/services/end_shipper_service/EndShipper.d.ts deleted file mode 100644 index 5e5b37489..000000000 --- a/types/services/end_shipper_service/EndShipper.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { IObjectWithId } from '../../utils/types'; -/** - * The EndShipper API is for platforms purchasing postage on behalf of their users, the EndShipper. - * Platforms must assert the EndShipper details, as the EndShipper is ultimately responsible for what is in the box. - * Multiple labels purchased for the same EndShipper must use the same EndShipper identity (API object). - * EndShipper objects must be created prior to buying a Shipment. Once EndShipper objects have been created, - * you must keep track of their public id in order to use them during a label buy. - * - * @see https://www.easypost.com/docs/api/node#endshipper - */ -export type IEndshipper = IObjectWithId<'EndShipper'> & { - /** - * Name of responsible person (conditionally required) - */ - name?: string | null; - /** - * Name of responsible company (conditionally required) - */ - company?: string | null; - /** - * First line of the address - */ - street1?: string | null; - /** - * Second line of the address - */ - street2?: string | null; - /** - * City the address is located in - */ - city?: string | null; - /** - * State or province the address is located in - */ - state?: string | null; - /** - * ZIP or postal code the address is located in - */ - zip: string; - /** - * ISO 3166 country code for the country the address is located in - */ - country?: string; - /** - * Phone number to reach the person or organization - */ - phone?: string | null; - /** - * Email to reach the person or organization - */ - email?: string | null; -}; diff --git a/types/services/end_shipper_service/EndShipperCreateParameters.d.ts b/types/services/end_shipper_service/EndShipperCreateParameters.d.ts deleted file mode 100644 index 11276c69a..000000000 --- a/types/services/end_shipper_service/EndShipperCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { IEndshipper } from './EndShipper'; -export type IEndShipperCreateParameters = Omit; diff --git a/types/services/end_shipper_service/EndShipperListParameters.d.ts b/types/services/end_shipper_service/EndShipperListParameters.d.ts deleted file mode 100644 index c806a475e..000000000 --- a/types/services/end_shipper_service/EndShipperListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api#endshipper - */ -export type IEndShipperListParameters = IAllMethodParameters; diff --git a/types/services/end_shipper_service/index.d.ts b/types/services/end_shipper_service/index.d.ts deleted file mode 100644 index 138577854..000000000 --- a/types/services/end_shipper_service/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -import EasyPost from '../..'; -import { IEndshipper } from './EndShipper'; -import { IEndShipperCreateParameters } from './EndShipperCreateParameters'; -import { IEndShipperListParameters } from './EndShipperListParameters'; -export * from './EndShipper'; -export * from './EndShipperCreateParameters'; -export * from './EndShipperListParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create an {@link EndShipper end shipper}. - * See {@link https://www.easypost.com/docs/api/node#create-an-endshipper EasyPost API Documentation} for more information. - * @param params - Parameters for the end shipper to be created. - * @returns - The created end shipper. - */ - create( - params: IEndShipperCreateParameters, - ): Promise>; - /** - * Update an {@link EndShipper end shipper}. - * See {@link https://www.easypost.com/docs/api/node#update-an-endshipper EasyPost API Documentation} for more information. - * @param id - The ID of the end shipper to update. - * @param params - Parameters for the end shipper to be updated. - * @returns - The updated end shipper. - */ - update( - id: string, - params: Partial, - ): Promise>; - /** - * Retrieve an {@link EndShipper end shipper} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-endshipper EasyPost API Documentation} for more information. - * @param id - The ID of the end shipper to retrieve. - * @returns - The retrieved end shipper. - */ - retrieve(id: string): Promise>; - /** - * Retrieve all {@link EndShipper end shippers} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-endshippers EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of end shippers. - * @returns - An object containing a list of {@link EndShipper end shippers} and pagination information. - */ - all(params?: IEndShipperListParameters): Promise< - { - _params: any; - } & { - has_more: boolean; - } - >; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/event_service/Event.d.ts b/types/services/event_service/Event.d.ts deleted file mode 100644 index 9da8a5e69..000000000 --- a/types/services/event_service/Event.d.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * Webhook Events are triggered by changes in objects you've created via the API. - * Every time an Event related to one of your objects is created, EasyPost guarantees at least one POST request will be sent to each of the webhook URLs set up for your account. - * For this reason, we strongly encourage your webhook handler to be idempotent. - * See the webhooks guide for more information. - * - * @see https://www.easypost.com/docs/api/node#events - */ -export type IEvent = IObjectWithId<'Event'> & - IDatedObject & { - /** - * Result type and event name, see the "Possible Event Types" section for more information - */ - description: string; - /** - * Previous values of relevant result attributes - */ - previous_attributes: any; - /** - * The object associated with the Event. See the "object" attribute on the result to determine its specific type. - * This field will not be returned when retrieving events directly from the API - */ - result: any; - /** - * The current status of the event. Possible values are "completed", "failed", "in_queue", "retrying", or "pending" (deprecated) - * - * @deprecated - */ - status: 'completed' | 'failed' | 'in_queue' | 'retrying' | 'pending'; - /** - * Webhook URLs that have not yet been successfully notified as of the time this webhook event was sent. - * The URL receiving the Event will still be listed in pending_urls, as will any other URLs that receive the Event at the same time - */ - pending_urls: string[]; - /** - * Webhook URLs that have already been successfully notified as of the time this webhook was sent - */ - completed_urls: string[]; - }; diff --git a/types/services/event_service/EventListParameters.d.ts b/types/services/event_service/EventListParameters.d.ts deleted file mode 100644 index 9bdf71607..000000000 --- a/types/services/event_service/EventListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-events - */ -export type IEventListParameters = IAllMethodParameters; diff --git a/types/services/event_service/Payload/Payload.d.ts b/types/services/event_service/Payload/Payload.d.ts deleted file mode 100644 index d52fba6e9..000000000 --- a/types/services/event_service/Payload/Payload.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../../utils/types'; -/** - * A Payload represents an attempt by EasyPost to send an Event to a Webhook. - * An Event can have multiple Payloads. For instance, if there is a failure to deliver a Webhook, - * an Event would have multiple payloads, one for each attempt to deliver the Event to the Webhook. - * Payload can be useful for debugging webhook delivery and when initially setting up EasyPost webhooks. - */ -export type IPayload = IObjectWithId<'Payload'> & - IDatedObject & { - /** - * The body of the Payload response - */ - response_body: string | null; - }; diff --git a/types/services/event_service/Payload/PayloadListParameters.d.ts b/types/services/event_service/Payload/PayloadListParameters.d.ts deleted file mode 100644 index 1286fdbbc..000000000 --- a/types/services/event_service/Payload/PayloadListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads - */ -export type IPayloadListParameters = IAllMethodParameters; diff --git a/types/services/event_service/Payload/index.d.ts b/types/services/event_service/Payload/index.d.ts deleted file mode 100644 index b1fd98702..000000000 --- a/types/services/event_service/Payload/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './Payload'; diff --git a/types/services/event_service/index.d.ts b/types/services/event_service/index.d.ts deleted file mode 100644 index cf8d41b21..000000000 --- a/types/services/event_service/index.d.ts +++ /dev/null @@ -1,96 +0,0 @@ -import EasyPost from '../..'; -import { IEvent } from './Event'; -import { IEventListParameters } from './EventListParameters'; -import { IPayload } from './Payload'; -export * from './Event'; -export * from './EventListParameters'; -export * from './Payload'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Retrieve all {@link Payload payloads} for an {@link Event event}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads EasyPost API Documentation} for more information. - * @param id - The ID of the event to retrieve payloads for. - * @returns - A list of {@link Payload payloads} for the event. - */ - retrieveAllPayloads(id: string): Promise>; - /** - * Retrieve a specific {@link Payload payload} for an {@link Event event}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-payload EasyPost API Documentation} for more information. - * @param id - The ID of the event to retrieve the payload for. - * @param payloadId - The ID of the payload to retrieve. - * @returns - The {@link Payload payload} for the event. - */ - retrievePayload( - id: string, - payloadId: string, - ): Promise>; - /** - * Retrieve all {@link Event events} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-events EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of events. - * @returns - An object containing the list of {@link Event events} and pagination information. - */ - all(params?: IEventListParameters): Promise< - { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of Event collection. - * @param events An object containing a list of {@link Event events} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - events: any, - pageSize?: number | null, - ): Promise< - { - events: IEvent[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve an {@link Event event} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-event EasyPost API Documentation} for more information. - * @param id - The ID of the event to retrieve. - * @returns - The retrieved event. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/index.d.ts b/types/services/index.d.ts deleted file mode 100644 index 229b1e3fa..000000000 --- a/types/services/index.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -export * from './address_service'; -export * from './api_key_service'; -export * from './batch_service'; -export * from './beta_rate_service'; -export * from './beta_referral_customer_service'; -export * from './billing_service'; -export * from './carrier_account_service'; -export * from './carrier_metadata_service'; -export * from './carrier_type_service'; -export * from './customs_info_service'; -export * from './customs_item_service'; -export * from './end_shipper_service'; -export * from './event_service'; -export * from './insurance_service'; -export * from './order_service'; -export * from './parcel_service'; -export * from './pickup_service'; -export * from './rate_service'; -export * from './referral_customer_service'; -export * from './refund_service'; -export * from './report_service'; -export * from './scan_form_service'; -export * from './shipment_service'; -export * from './tracker_service'; -export * from './user_service'; -export * from './webhook_service'; -export * from './base_service'; diff --git a/types/services/insurance_service/Fee.d.ts b/types/services/insurance_service/Fee.d.ts deleted file mode 100644 index 2149b267a..000000000 --- a/types/services/insurance_service/Fee.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { IBaseObject } from '../../utils/types'; -import { TFeeType } from './FeeType'; -/** - * Fee objects are used to represent the breakdown of charges made when purchasing an item on EasyPost. - * Shipments and Trackers both have associations to Fee objects. - * - * Each Shipment object will have a Fee of type "LabelFee" to represent the label fee charged by EasyPost for the service. - * Shipments with postage collected by EasyPost (as opposed to shipments with postage collected directly by the carrier) will have a "PostageFee" according to the postage amount. - * Insurance on a Shipment will add an "InsuranceFee" with the insurance premium (not the covered value) for the amount. - * Tracker objects will have a "TrackerFee" with the price, even when a Tracker is free. - * - * @see https://www.easypost.com/docs/api/node#fee-object - */ -export type IFee = IBaseObject<'Fee'> & { - /** - * The name of the category of fee. Possible types are "LabelFee", "PostageFee", "InsuranceFee", and "TrackerFee" - */ - type: TFeeType; - /** - * USD value with sub-cent precision - */ - amount: string; - /** - * Whether EasyPost has successfully charged your account for the fee - */ - charged: boolean; - /** - * Whether the Fee has been refunded successfully - */ - refunded: boolean; -}; diff --git a/types/services/insurance_service/FeeType.d.ts b/types/services/insurance_service/FeeType.d.ts deleted file mode 100644 index 980a39a05..000000000 --- a/types/services/insurance_service/FeeType.d.ts +++ /dev/null @@ -1 +0,0 @@ -export type TFeeType = 'InsuranceFee' | 'LabelFee' | 'PostageFee' | 'TrackerFee'; diff --git a/types/services/insurance_service/Insurance.d.ts b/types/services/insurance_service/Insurance.d.ts deleted file mode 100644 index af0418285..000000000 --- a/types/services/insurance_service/Insurance.d.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { IAddress } from '../address_service'; -import { ITracker } from '../tracker_service'; -import { IFee } from './Fee'; -import { TInsuranceStatus } from './InsuranceStatus'; -/** - * An Insurance object represents insurance for packages purchased both via the EasyPost API as well as shipments purchased through third parties and later registered with EasyPost. - * An Insurance is created automatically whenever you buy a Shipment through EasyPost and pass insurance options during the Buy call or in a later call to Insure a Shipment. - * - * Insurance purchased through the Shipment Buy or Insure endpoints is immediately insured - there is no possibility of rejection based on tracking information, as the package was just created. - * On the other hand, Insurance purchased on shipments purchased outside of EasyPost requires creation with a tracking code so that EasyPost may confirm the package existence and current shipping status at the time of purchase. - * - * Standalone insurance is created in a pending state to help distinguish it from insurance purchased for an EasyPost Shipment. - * Both kinds of Insurance use the Tracking system to receive periodic updates, and will report those updates to any appropriate Webhooks on file. - * Standalone insurance will cancel itself if the tracking information for the given tracking code shows evidence of having been shipped anytime before the insurance was purchased. - * - * Unlike Shipments within EasyPost, Insurance objects register To and From Address objects according to the destination and ship-from locations of the package. - * This means that a Shipment with "is_return: true" actually ships to the listed From Address. - * Insurance does not have a concept of "is_return", so all insurance records refer to their true package destination as "to_address", regardless of whether or not the shipment is a return. - * - * @see https://www.easypost.com/docs/api/node#insurance-object - */ -export type IInsurance = IObjectWithId<'Insurance'> & - IDatedObject & { - /** - * The unique reference for this Insurance, if any - */ - reference?: string | null; - /** - * USD value of insured goods with sub-cent precision - */ - amount: string; - /** - * The insurance provider used by EasyPost - */ - provider: string; - /** - * An identifying number for some insurance providers used by EasyPost - */ - provider_id: string; - /** - * The ID of the Shipment in EasyPost, if postage was purchased via EasyPost - */ - shipment_id: string; - /** - * The tracking code of either the shipment within EasyPost, or provided by you during creation - */ - tracking_code: string; - /** - * The current status of the insurance, possible values are "new", "pending", "purchased", "failed", or "cancelled" - */ - status: TInsuranceStatus; - /** - * The associated Tracker object - */ - tracker: ITracker; - /** - * The associated Address object for destination - */ - to_address: IAddress; - /** - * The associated Address object for origin - */ - from_address: IAddress; - /** - * The associated InsuranceFee object if any - */ - fee: IFee; - /** - * The list of errors encountered during attempted purchase of the insurance - */ - messages: string[]; - }; diff --git a/types/services/insurance_service/InsuranceCreateParameters.d.ts b/types/services/insurance_service/InsuranceCreateParameters.d.ts deleted file mode 100644 index 537dc6ef8..000000000 --- a/types/services/insurance_service/InsuranceCreateParameters.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { IAddress } from '../address_service'; -export type IInsuranceCreateParameters = { - reference?: string | null; - to_address: IAddress | string; - from_address: IAddress | string; - /** - * The carrier associated with the tracking_code you provided. - * The carrier will get auto-detected if none is provided - */ - carrier?: string | null; - /** - * The tracking code associated with the non-EasyPost-purchased package you'd like to insure. - */ - tracking_code: string; - /** - * The USD value of contents you would like to insure. - * Currently the maximum is $5000 - * - * @example 100.00 - */ - amount: string; -}; diff --git a/types/services/insurance_service/InsuranceStatus.d.ts b/types/services/insurance_service/InsuranceStatus.d.ts deleted file mode 100644 index 139db60a2..000000000 --- a/types/services/insurance_service/InsuranceStatus.d.ts +++ /dev/null @@ -1 +0,0 @@ -export type TInsuranceStatus = 'new' | 'pending' | 'purchased' | 'failed' | 'cancelled'; diff --git a/types/services/insurance_service/index.d.ts b/types/services/insurance_service/index.d.ts deleted file mode 100644 index bb320ba54..000000000 --- a/types/services/insurance_service/index.d.ts +++ /dev/null @@ -1,89 +0,0 @@ -import EasyPost from '../..'; -import { IAllMethodParameters } from '../../utils/types'; -import { IInsurance } from './Insurance'; -import { IInsuranceCreateParameters } from './InsuranceCreateParameters'; -export * from './Fee'; -export * from './FeeType'; -export * from './Insurance'; -export * from './InsuranceCreateParameters'; -export * from './InsuranceStatus'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create an {@link Insurance insurance} record. - * See {@link https://www.easypost.com/docs/api/node#create-an-insurance EasyPost API Documentation} for more information. - * @param params - Parameters for the insurance to be created. - * @returns - The created insurance. - */ - create( - params: IInsuranceCreateParameters, - ): Promise>; - /** - * Retrieve all {@link Insurance} records associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-insurances EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the insurance records. - * @returns - An object containing the list of {@link Insurance insurance} records and pagination information. - */ - all(params?: IAllMethodParameters): Promise< - IInsurance[] & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of Insurance collection. - * @param {Object} insurances An object containing a list of {@link Insurance insurances} and pagination information. - * @param {Number} pageSize The number of records to return on each page - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - insurances: any, - pageSize?: number | null, - ): Promise< - { - insurances: IInsurance[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve an {@link Insurance insurance} record by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-insurance EasyPost API Documentation} for more information. - * @param {string} id - The ID of the insurance to retrieve. - * @returns {Insurance} - The retrieved insurance. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/order_service/Order.d.ts b/types/services/order_service/Order.d.ts deleted file mode 100644 index 0b9a96406..000000000 --- a/types/services/order_service/Order.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { IAddress } from '../address_service'; -import { IRate } from '../rate_service'; -import { IMessage, IShipment } from '../shipment_service'; -/** - * The Order object represents a collection of packages and can be used for Multi-Piece Shipments. - * Like a single Shipment each Order consists of a "to" and "from" Address to be used for each Shipment within the Order. - * These Addresses will be copied to each Shipment so there is no need to specify them multiple times. - * Each Shipment must then specify its Parcel, Options, and CustomsInfo. - * - * An Order created with valid Address Objects and Parcel data nested within the Order's Shipment object will automatically retrieve available shipping Rate options. - * - * @see https://www.easypost.com/docs/api/node#order-object - */ -export type IOrder = IObjectWithId<'Order'> & - IDatedObject & { - /** - * An optional field that may be used in place of id in other API endpoints - */ - reference?: string | null; - /** - * The destination address - */ - to_address: IAddress; - /** - * The origin address - */ - from_address: IAddress; - /** - * The shipper's address, defaults to from_address - */ - return_address?: IAddress | null; - /** - * The buyer's address, defaults to to_address - */ - buyer_address?: IAddress | null; - /** - * All associated Shipment objects. Maximum of 100. - */ - shipments: IShipment[]; - /** - * All associated Rate objects - */ - rates: IRate[]; - /** - * Any carrier errors encountered during rating - */ - messages: IMessage[]; - /** - * Set true to create as a return - */ - is_return?: boolean | null; - }; diff --git a/types/services/order_service/OrderCreateParameters.d.ts b/types/services/order_service/OrderCreateParameters.d.ts deleted file mode 100644 index 8368b1d68..000000000 --- a/types/services/order_service/OrderCreateParameters.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { IAddress } from '../address_service'; -import { IShipment } from '../shipment_service'; -export type IOrderCreateParameters = { - reference?: string | null; - to_address: IAddress | string; - from_address: IAddress | string; - shipments: IShipment[]; - /** - * optional array of ids that begin with "ca_" - */ - carrier_accounts?: string[] | null; -}; diff --git a/types/services/order_service/index.d.ts b/types/services/order_service/index.d.ts deleted file mode 100644 index 4d07b7efe..000000000 --- a/types/services/order_service/index.d.ts +++ /dev/null @@ -1,79 +0,0 @@ -import EasyPost from '../..'; -import { IRate } from '../rate_service'; -import { IOrder } from './Order'; -import { IOrderCreateParameters } from './OrderCreateParameters'; -export * from './Order'; -export * from './OrderCreateParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create an {@link Order order}. - * See {@link https://www.easypost.com/docs/api/node#create-an-order EasyPost API Documentation} for more information. - * @param params - The parameters to create an order with. - * @returns - The created order. - */ - create(params: IOrderCreateParameters): Promise>; - /** - * Purchase an {@link Order order}. - * See {@link https://www.easypost.com/docs/api/node#buy-an-order EasyPost API Documentation} for more information. - * @param id - The ID of the order to buy. - * @param carrier - The carrier to use for the order purchase. - * @param service - The service to use for the order purchase. - * @returns - The purchased order. - */ - buy( - id: string, - carrier: string, - service: string, - ): Promise>; - /** - * Get updated rates for an {@link Order order}. - * See {@link https://www.easypost.com/docs/api/node#orders EasyPost API Documentation} for more information. - * @param id - The ID of the order to get rates for. - * @returns - The order with rates. - */ - getRates(id: string): Promise>; - /** - * Retrieve an {@link Order order} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-order EasyPost API Documentation} for more information. - * @param id - The ID of the order to retrieve. - * @returns - The retrieved order. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - > - /** - * Retrieve an {@link Order order} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-order EasyPost API Documentation} for more information. - * @param id - The ID of the order to retrieve. - * @returns - The retrieved order. - */; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/parcel_service/Parcel.d.ts b/types/services/parcel_service/Parcel.d.ts deleted file mode 100644 index f0c7c6535..000000000 --- a/types/services/parcel_service/Parcel.d.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * Parcel objects represent the physical container being shipped. - * Dimensions can be supplied either as length, width, and height dimensions, or a predefined_package string. - * Only weight is required, but since many carriers charge different rates for packages with large dimensions, we strongly recommend including all dimensions if available. - * - * Weights are in OUNCES (OZ) and go to one decimal point. - * Dimensions are in INCHES (IN) and go to one decimal point. - * - * @see https://www.easypost.com/docs/api/node#parcel-object - */ -export type IParcel = IObjectWithId<'Parcel'> & - IDatedObject & { - /** - * Required if width and/or height are present - * float (inches) - */ - length?: number | null; - /** - * Required if width and/or height are present - * float (inches) - */ - width?: number | null; - /** - * Required if width and/or height are present - * float (inches) - */ - height?: number | null; - /** - * Always required - * float (oz) - */ - weight: number; - /** - * Optional, one of our predefined_packages - */ - predefined_package?: string | null; - }; diff --git a/types/services/parcel_service/ParcelCreateParameters.d.ts b/types/services/parcel_service/ParcelCreateParameters.d.ts deleted file mode 100644 index 35f07b297..000000000 --- a/types/services/parcel_service/ParcelCreateParameters.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { IParcel } from './Parcel'; -export type IParcelCreateParameters = Omit & { - /** - * Required if width and/or height are present - * float (inches) - */ - length?: number | null; - /** - * Required if width and/or height are present - * float (inches) - */ - width?: number | null; - /** - * Required if width and/or height are present - * float (inches) - */ - height?: number | null; - /** - * Always required - * float (oz) - */ - weight: number; -}; diff --git a/types/services/parcel_service/index.d.ts b/types/services/parcel_service/index.d.ts deleted file mode 100644 index cd23ad71e..000000000 --- a/types/services/parcel_service/index.d.ts +++ /dev/null @@ -1,54 +0,0 @@ -import EasyPost from '../..'; -import { IParcel } from './Parcel'; -import { IParcelCreateParameters } from './ParcelCreateParameters'; -export * from './Parcel'; -export * from './ParcelCreateParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Parcel parcel}. - * See {@link https://www.easypost.com/docs/api/node#create-a-parcel EasyPost API Documentation} for more information. - * @param params - The parameters to create a parcel with. - * @returns - The created parcel. - */ - create( - params: IParcelCreateParameters, - ): Promise>; - /** - * Retrieve a {@link Parcel parcel} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-parcel EasyPost API Documentation} for more information. - * @param id - The ID of the parcel to retrieve. - * @returns - The retrieved parcel. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/pickup_service/Pickup.d.ts b/types/services/pickup_service/Pickup.d.ts deleted file mode 100644 index ae6a57f4f..000000000 --- a/types/services/pickup_service/Pickup.d.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { IAddress } from '../address_service'; -import { ICarrierAccount } from '../carrier_account_service'; -import { IMessage, IShipment } from '../shipment_service'; -import { IPickupRate } from './PickupRate'; -/** - * The Pickup object allows you to schedule a pickup from your carrier from your customer's residence or place of business. - * Supported carriers include: - * - Canada Post - * - Canpar - * - DHL Express - * - FedEx - * - Lasership - * - Loomis Express - * - LSO - * - Ontrac - * - UPS - * - USPS - * - Veho - * - * After a Pickup is successfully created, it will automatically fetch PickupRates for each CarrierAccount specified that supports scheduled pickups. - * Then a PickupRate must be selected and purchased before the pickup can be successfully scheduled. - * - * @see https://www.easypost.com/docs/api/node#pickup-object - */ -export type IPickup = IObjectWithId<'Pickup'> & - IDatedObject & { - /** - * An optional field that may be used in place of ID in some API endpoints - */ - reference?: string | null; - /** - * One of: "unknown", "scheduled", or "canceled" - */ - status: 'unknown' | 'scheduled' | 'canceled'; - /** - * The earliest time at which the package is available to pick up - */ - min_datetime: string; - /** - * The latest time at which the package is available to pick up. - * Must be later than the min_datetime - */ - max_datetime: string; - /** - * Is the pickup address the account's address? - */ - is_account_address?: boolean | null; - /** - * Additional text to help the driver successfully obtain the package - */ - instructions?: string | null; - /** - * A list of messages containing carrier errors encountered during pickup rate generation - */ - messages: IMessage[]; - /** - * The confirmation number for a booked pickup from the carrier - */ - confirmation: string; - /** - * The associated Shipment - */ - shipment: IShipment; - /** - * The associated Address - */ - address: IAddress; - /** - * The list of carriers (if empty, all carriers were used) used to generate pickup rates - */ - carrier_accounts?: ICarrierAccount[] | null; - /** - * The list of different pickup rates across valid carrier accounts for the shipment - */ - pickup_rates: IPickupRate[]; - }; diff --git a/types/services/pickup_service/PickupCreateParameters.d.ts b/types/services/pickup_service/PickupCreateParameters.d.ts deleted file mode 100644 index d4c180dcc..000000000 --- a/types/services/pickup_service/PickupCreateParameters.d.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { IAddress } from '../address_service'; -import { IBatch } from '../batch_service'; -import { ICarrierAccount } from '../carrier_account_service'; -import { IShipment } from '../shipment_service'; -import { IPickupRate } from './PickupRate'; -type BasePickupCreateParameters = { - address: IAddress | string; - carrier_accounts?: ICarrierAccount[] | null; - confirmation?: string | null; - instructions?: string | null; - is_account_address?: boolean | null; - max_datetime: string; - min_datetime: string; - pickup_rates: IPickupRate; - reference?: string | null; - status: string; -}; -type ShipmentPickupCreateParameters = BasePickupCreateParameters & { - shipment?: - | IShipment - | { - id: string; - } - | string - | null; -}; -type BatchPickupCreateParameters = BasePickupCreateParameters & { - batch?: - | IBatch - | { - id: string; - } - | string - | null; -}; -export type IPickupCreateParameters = ShipmentPickupCreateParameters | BatchPickupCreateParameters; -export {}; diff --git a/types/services/pickup_service/PickupListParameters.d.ts b/types/services/pickup_service/PickupListParameters.d.ts deleted file mode 100644 index 806edf7f0..000000000 --- a/types/services/pickup_service/PickupListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups - */ -export type IPickupListParameters = IAllMethodParameters; diff --git a/types/services/pickup_service/PickupRate.d.ts b/types/services/pickup_service/PickupRate.d.ts deleted file mode 100644 index 53983d86e..000000000 --- a/types/services/pickup_service/PickupRate.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#pickup-rate-object - */ -export type IPickupRate = IObjectWithId<'PickupRate'> & - IDatedObject & { - /** - * service name - */ - service: string; - /** - * name of carrier - */ - carrier: string; - /** - * the actual rate quote for this service - */ - rate: string; - /** - * currency for the rate - */ - currency: string; - /** - * the ID of the pickup this is a quote for - */ - pickup_id: string; - }; diff --git a/types/services/pickup_service/index.d.ts b/types/services/pickup_service/index.d.ts deleted file mode 100644 index bbab7e5c2..000000000 --- a/types/services/pickup_service/index.d.ts +++ /dev/null @@ -1,110 +0,0 @@ -import EasyPost from '../..'; -import { IPickup } from './Pickup'; -import { IPickupCreateParameters } from './PickupCreateParameters'; -import { IPickupListParameters } from './PickupListParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Pickup pickup}. - * See {@link https://www.easypost.com/docs/api/node#create-a-pickup EasyPost API Documentation} for more information. - * @param params - The parameters to create a pickup with. - * @returns - The created pickup. - */ - create( - params: IPickupCreateParameters, - ): Promise>; - /** - * Purchase a {@link Pickup pickup}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-pickup EasyPost API Documentation} for more information. - * @param id - The ID of the pickup to purchase. - * @param carrier - The carrier to purchase the pickup with. - * @param service - The service to purchase the pickup with. - * @returns - The purchased pickup. - */ - buy( - id: string, - carrier: string, - service: string, - ): Promise>; - /** - * Cancel a {@link Pickup pickup}. - * See {@link https://www.easypost.com/docs/api/node#cancel-a-pickup EasyPost API Documentation} for more information. - * @param id - The ID of the pickup to cancel. - * @returns - The cancelled pickup. - */ - cancel(id: string): Promise>; - /** - * Retrieve all {@link Pickup pickups} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the pickups by. - * @returns - An object containing a list of {@link Pickup pickups} and pagination information. - */ - all(params?: IPickupListParameters): Promise< - IPickup[] & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of Pickup collection. - * @param pickups An object containing a list of {@link Pickup pickups} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - pickups: any, - pageSize?: number | null, - ): Promise< - { - pickups: IPickup[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link Pickup pickup} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-pickup EasyPost API Documentation} for more information. - * @param id - The ID of the pickup to retrieve. - * @returns - The retrieved pickup. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise> - /** - * Retrieve the next page of Pickup collection. - * @param pickups An object containing a list of {@link Pickup pickups} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/rate_service/Rate.d.ts b/types/services/rate_service/Rate.d.ts deleted file mode 100644 index d53e172de..000000000 --- a/types/services/rate_service/Rate.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * The Rate class represents a summary of the price and details of a delivery service quote. - * - * @see https://www.easypost.com/docs/api/node#rates - */ -export type IRate = IObjectWithId<'Rate'> & - IDatedObject & { - /** - * The service level of the rate. - */ - service: string; - /** - * The carrier of the rate. - */ - carrier: string; - /** - * The ID of the carrier account associated with this rate. - */ - carrier_account_id: string; - /** - * The ID of the shipment associated with this rate. - */ - shipment_id: string; - /** - * The quote price of the rate. - */ - rate: string; - /** - * The currency of the rate. - */ - currency: string; - /** - * The in-store retail rate given with no account. - */ - retail_rate: string; - /** - * The currency of the retail rate. - */ - retail_currency: string; - /** - * The non-negotiated rate given for having an account with the carrier. - */ - list_rate: string; - /** - * The currency of the list rate. - */ - list_currency: string; - /** - * The number of days in transit for this rate. - */ - delivery_days: number; - /** - * The delivery date for this rate. - */ - delivery_date: string; - /** - * Whether the delivery window is guaranteed. - */ - delivery_date_guaranteed: boolean; - /** - * The earliest delivery date for this rate. - * This is deprecated and should be ignored. - */ - est_delivery_days: number; - /** - * The billing type of the rate. - */ - billing_type: string; - }; -export type ISmartRate = IRate & { - time_in_transit: { - percentile_50: number; - percentile_75: number; - percentile_85: number; - percentile_90: number; - percentile_95: number; - percentile_97: number; - percentile_99: number; - }; -}; diff --git a/types/services/rate_service/index.d.ts b/types/services/rate_service/index.d.ts deleted file mode 100644 index b51193687..000000000 --- a/types/services/rate_service/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -import EasyPost from '../..'; -import { IRate } from './Rate'; -export * from './Rate'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Retrieve a {@link Rate rate} by its ID. - * See {@link https://www.easypost.com/docs/api/node#rates EasyPost API Documentation} for more information. - * @param {string} id - The ID of the rate to retrieve. - * @returns {Rate} - The retrieved rate. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/referral_customer_service/Referral.d.ts b/types/services/referral_customer_service/Referral.d.ts deleted file mode 100644 index b83dfa0a6..000000000 --- a/types/services/referral_customer_service/Referral.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { IUser } from '../user_service'; -/** - * A Referral represents a sub-user under a Partner or white-label account. - * - * @see https://www.easypost.com/docs/api/node#referral-customers - */ -export declare interface IReferral extends IUser {} diff --git a/types/services/referral_customer_service/ReferralCreateParameters.d.ts b/types/services/referral_customer_service/ReferralCreateParameters.d.ts deleted file mode 100644 index 7035f552d..000000000 --- a/types/services/referral_customer_service/ReferralCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { IReferral } from './Referral'; -export type IReferralCreateParameters = Omit; diff --git a/types/services/referral_customer_service/ReferralListParameters.d.ts b/types/services/referral_customer_service/ReferralListParameters.d.ts deleted file mode 100644 index f26fe30bd..000000000 --- a/types/services/referral_customer_service/ReferralListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers - */ -export type IReferralListParameters = IAllMethodParameters; diff --git a/types/services/referral_customer_service/index.d.ts b/types/services/referral_customer_service/index.d.ts deleted file mode 100644 index 2f4520f4e..000000000 --- a/types/services/referral_customer_service/index.d.ts +++ /dev/null @@ -1,108 +0,0 @@ -import EasyPost from '../..'; -import { IReferralCreateParameters } from './ReferralCreateParameters'; -import { IReferral } from './Referral'; -import { IReferralListParameters } from './ReferralListParameters'; -import { IPaymentMethod } from '../billing_service'; -export * from './Referral'; -export * from './ReferralCreateParameters'; -export * from './ReferralListParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link User referral customer}. - * See {@link https://www.easypost.com/docs/api/node#create-a-referral-customer EasyPost API Documentation} for more information. - * @param params - The referral customer's information. - * @returns - The newly created referral customer. - */ - create( - params: IReferralCreateParameters, - ): Promise>; - /** - * Update a {@link User referral customer's} email address. - * See {@link https://www.easypost.com/docs/api/node#update-a-referral-customer EasyPost API Documentation} for more information. - * @param referralUserId - The ID of the referral customer to update. - * @param email - The new email address. - * @returns - Returns true if the referral was updated successfully, false otherwise. - */ - updateEmail(referralUserId: string, email: string): Promise; - /** - * Add a credit card to a {@link User referral customer's} account. - * See {@link https://www.easypost.com/docs/api/node#create-credit-card EasyPost API Documentation} for more information. - * @param referralApiKey - The referral customer's production API key. - * @param number - The credit card number. - * @param expirationMonth - The credit card expiration month. - * @param expirationYear - The credit card expiration year. - * @param cvc - The credit card CVC. - * @param priority - Whether to add the card as 'primary' or 'secondary' payment method (defaults to 'primary'). - * @returns - An object representing the newly-added credit card. - */ - addCreditCard( - referralApiKey: string, - number: string, - expirationMonth: string, - expirationYear: string, - cvc: string, - priority?: 'primary' | 'secondary', - ): Promise; - /** - * Retrieve all {@link User referral customers} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the referral customers by. - * @returns - An object containing a list of {@link User referral customers} and pagination information. - */ - all(params?: IReferralListParameters): Promise< - IReferral[] & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of Referral Customer collection. - * @param referralCustomers An object containing a list of {@link referral referralCustomers} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - referralCustomers: any, - pageSize?: number | null, - ): Promise< - { - referral_customers: IReferral[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/refund_service/Refund.d.ts b/types/services/refund_service/Refund.d.ts deleted file mode 100644 index 1765f8ccb..000000000 --- a/types/services/refund_service/Refund.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * The Refund object represents a refunded shipment, and includes details about the related Shipment and tracking code. - * USPS shipping labels can be refunded if requested within 30 days of generation. - * The processing time is at least 15 days, after which the funds will return to your EasyPost balance. - * EasyPost fees will also be refunded. To qualify, a shipment must not have been scanned by the USPS. - * UPS and FedEx shipping labels may be refunded within 90 days of creation. - */ -export type IRefund = IObjectWithId<'Refund'> & - IDatedObject & { - /** - * The tracking code of the related Shipment - */ - tracking_code: string; - /** - * The confirmation number for the refund request to the carrier - */ - confirmation_number: string; - /** - * The status of the refund request, reported by the carrier. Possible values are "submitted", "refunded", or "rejected" - */ - status: 'submitted' | 'refunded' | 'rejected'; - /** - * The carrier the refund request was submitted to - */ - carrier: string; - /** - * The ID of the related Shipment being refunded - */ - shipment_id: string; - }; diff --git a/types/services/refund_service/RefundCreateParameters.d.ts b/types/services/refund_service/RefundCreateParameters.d.ts deleted file mode 100644 index 56419c78e..000000000 --- a/types/services/refund_service/RefundCreateParameters.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @see https://www.easypost.com/docs/api/node#create-a-refund - */ -export type IRefundCreateParameters = { - /** - * The carrier to request a refund from - */ - carrier: string; - /** - * A list of tracking codes to request refunds for. Even for a single tracking code, it needs to be submitted as a list. - */ - tracking_codes: string[]; -}; diff --git a/types/services/refund_service/RefundListParameters.d.ts b/types/services/refund_service/RefundListParameters.d.ts deleted file mode 100644 index 5239e02d8..000000000 --- a/types/services/refund_service/RefundListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds - */ -export type IRefundListParameters = IAllMethodParameters; diff --git a/types/services/refund_service/index.d.ts b/types/services/refund_service/index.d.ts deleted file mode 100644 index d476fbfd5..000000000 --- a/types/services/refund_service/index.d.ts +++ /dev/null @@ -1,89 +0,0 @@ -import EasyPost from '../..'; -import { IRefund } from './Refund'; -import { IRefundCreateParameters } from './RefundCreateParameters'; -import { IRefundListParameters } from './RefundListParameters'; -export * from './Refund'; -export * from './RefundCreateParameters'; -export * from './RefundListParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Refund refund}. - * See {@link https://www.easypost.com/docs/api/node#create-a-refund EasyPost API Documentation} for more information. - * @param params - The parameters to create a refund with. - * @returns - The created refund. - */ - create( - params: IRefundCreateParameters, - ): Promise>; - /** - * Retrieve all {@link Refund refunds} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the refunds by. - * @returns - An object containing the list of {@link Refund refunds} and pagination information. - */ - all(params?: IRefundListParameters): Promise< - { - refunds: IRefund[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of Refund collection. - * @param refunds An object containing a list of {@link Refund refunds} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - refunds: any, - pageSize?: number | null, - ): Promise< - { - refunds: IRefund[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link Refund refund} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-refund EasyPost API Documentation} for more information. - * @param id - The ID of the refund to retrieve. - * @returns - The retrieved refund. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/report_service/Report.d.ts b/types/services/report_service/Report.d.ts deleted file mode 100644 index bc01c19c3..000000000 --- a/types/services/report_service/Report.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { TReportObjectType } from './ReportObjectType'; -/** - * A Report contains a csv that is a log of all the objects created within a certain time frame. - * - * Reports can be generated using the Reports Endpoint. - * You can create and view Reports created between any time frame defined between the start_date and end_date. - * - * The Report api can be categorized into several types. - * These types determine which EasyPost Object to produce a Report for, and should be passed as the type in our libraries: - * - cash_flow - * - insurance - * - payment_log - * - refund - * - shipment - * - shipment_invoice - * - tracker - * - * @see https://www.easypost.com/docs/api/node#report-object - */ -export type IReport = IObjectWithId & - IDatedObject & { - /** - * "new", "available", "failed", or null - */ - status: 'new' | 'available' | 'failed' | null; - /** - * A date string in YYYY-MM-DD form eg: "2016-02-02" - */ - start_date: string; - /** - * A date string in YYYY-MM-DD form eg: "2016-02-03" - */ - end_date: string; - /** - * Set true if you would like to include Refunds /Shipments /Trackers created by child users - */ - include_children?: boolean | null; - /** - * A url that contains a link to the Report. - * Expires 30 seconds after retrieving this object - */ - url: string; - /** - * Url expiring time - */ - url_expires_at: string; - /** - * Set true if you would like to send an email containing the Report - */ - send_email?: boolean | null; - }; diff --git a/types/services/report_service/ReportCreateParameters.d.ts b/types/services/report_service/ReportCreateParameters.d.ts deleted file mode 100644 index 909b9d4df..000000000 --- a/types/services/report_service/ReportCreateParameters.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { TReportType } from './ReportObjectType'; -export type IReportCreateParameters = { - type: TReportType; - start_date: string | null; - end_date?: string | null; - include_children?: boolean | null; - send_email?: boolean | null; - columns?: string[] | null; - additional_columns?: string[] | null; -}; diff --git a/types/services/report_service/ReportListParameters.d.ts b/types/services/report_service/ReportListParameters.d.ts deleted file mode 100644 index 2c8e5efe7..000000000 --- a/types/services/report_service/ReportListParameters.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -import { TReportType } from './ReportObjectType'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds - */ -export type IReportListParameters = IAllMethodParameters & { - type: TReportType; -}; diff --git a/types/services/report_service/ReportObjectType.d.ts b/types/services/report_service/ReportObjectType.d.ts deleted file mode 100644 index 918f61516..000000000 --- a/types/services/report_service/ReportObjectType.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -export type TReportObjectType = - | 'CashFlowReport' - | 'PaymentLogReport' - | 'RefundReport' - | 'ShipmentReport' - | 'ShipmentInvoiceReport' - | 'TrackerReport'; -export type TReportType = - | 'cash_flow' - | 'payment_log' - | 'refund' - | 'shipment' - | 'shipment_invoice' - | 'tracker'; diff --git a/types/services/report_service/index.d.ts b/types/services/report_service/index.d.ts deleted file mode 100644 index 998522b84..000000000 --- a/types/services/report_service/index.d.ts +++ /dev/null @@ -1,82 +0,0 @@ -import EasyPost from '../..'; -import { IReport } from './Report'; -import { IReportCreateParameters } from './ReportCreateParameters'; -import { IReportListParameters } from './ReportListParameters'; -export * from './Report'; -export * from './ReportCreateParameters'; -export * from './ReportListParameters'; -export * from './ReportObjectType'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Report report}. - * See {@link https://www.easypost.com/docs/api/node#create-a-report EasyPost API Documentation} for more information. - * @param params - The parameters to create a report with. - * @returns - The created report. - */ - create( - params: IReportCreateParameters, - ): Promise>; - /** - * Retrieve all {@link Report reports} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-reports EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the reports by. - * @returns - An object containing the list of {@link Report reports} and pagination information. - */ - all(params: IReportListParameters): Promise; - /** - * Retrieve the next page of Report collection. - * @param reports An object containing a list of {@link Report reports} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - reports: any, - pageSize?: number | null, - ): Promise< - { - reports: IReport[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link Report report} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-report EasyPost API Documentation} for more information. - * @param id - The ID of the report to retrieve. - * @returns - The retrieved report. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/scan_form_service/ScanForm.d.ts b/types/services/scan_form_service/ScanForm.d.ts deleted file mode 100644 index 9cba95498..000000000 --- a/types/services/scan_form_service/ScanForm.d.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { IAddress } from '../address_service'; -/** - * A ScanForm can be created to speed up and simplify the carrier pickup process. - * The ScanForm is one document that can be scanned to mark all included tracking codes as "Accepted for Shipment" by the carrier. - * The following criteria must met before creation: - * - Refunded Shipments cannot be added - * - Each Shipment must have the same origin address - * - Shipments must all be dated (using the label_date option) on or after the date the form is generated - * - Shipments cannot be added to more than one ScanForm - * - Existing ScanForms may not be updated with additional Shipments. If a ScanForm already exists, and new Shipments need to be added, a new ScanForm must be created. - * - Shipments should be provided in the form of an array - * - * @see https://www.easypost.com/docs/api/node#scan-form-object - */ -export type IScanForm = IObjectWithId<'ScanForm'> & - IDatedObject & { - /** - * Current status. - * Possible values are "creating", "created" and "failed" - */ - status: 'creating' | 'created' | 'failed'; - /** - * Human-readable message explaining any failures - */ - message: string; - /** - * Address that the Shipments will be shipped from - */ - address: IAddress; - /** - * Tracking codes included on the ScanForm - */ - tracking_codes: string[]; - /** - * Url of the document - */ - form_url: string; - /** - * File format of the document - */ - form_file_type: string; - /** - * The id of the associated Batch. Unique, starts with "batch_" - */ - batch_id: string; - }; diff --git a/types/services/scan_form_service/ScanFormCreateParameters.d.ts b/types/services/scan_form_service/ScanFormCreateParameters.d.ts deleted file mode 100644 index 9642f1e8d..000000000 --- a/types/services/scan_form_service/ScanFormCreateParameters.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { DeepPartial } from '../../utils/types'; -import { IShipmentCreateParameters } from '../shipment_service'; -export type IScanFormCreateParameters = { - shipments: - | (DeepPartial & { - id: string; - })[] - | string[]; -}; diff --git a/types/services/scan_form_service/ScanFormListParameters.d.ts b/types/services/scan_form_service/ScanFormListParameters.d.ts deleted file mode 100644 index 655a0094c..000000000 --- a/types/services/scan_form_service/ScanFormListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-scan-forms - */ -export type IScanFormListParameters = IAllMethodParameters; diff --git a/types/services/scan_form_service/index.d.ts b/types/services/scan_form_service/index.d.ts deleted file mode 100644 index 59563b781..000000000 --- a/types/services/scan_form_service/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -import EasyPost from '../..'; -import { IScanForm } from './ScanForm'; -import { IScanFormCreateParameters } from './ScanFormCreateParameters'; -import { IScanFormListParameters } from './ScanFormListParameters'; -export * from './ScanForm'; -export * from './ScanFormCreateParameters'; -export * from './ScanFormListParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link ScanForm scan form}. - * See {@link https://www.easypost.com/docs/api/node#create-a-scanform EasyPost API Documentation} for more information. - * @param params - The parameters to create a scan form with. - * @returns - The created scan form. - */ - create( - params: IScanFormCreateParameters, - ): Promise>; - /** - * Retrieve all {@link ScanForm scan forms} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-scanforms EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the scan forms by. - * @returns - An object containing the list of {@link ScanForm scan forms} and pagination information. - */ - all(params?: IScanFormListParameters): Promise< - { - scan_forms: IScanForm[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of ScanForm collection. - * @param scanForms An object containing a list of {@link ScanForm scanForms} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - scanForms: { - scan_forms: any[]; - }, - pageSize?: number | null, - ): Promise< - { - scan_forms: IScanForm[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link ScanForm scan form} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-scanform EasyPost API Documentation} for more information. - * @param id - The ID of the scan form to retrieve. - * @returns - The retrieved scan form. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/shipment_service/Form.d.ts b/types/services/shipment_service/Form.d.ts deleted file mode 100644 index c7430545a..000000000 --- a/types/services/shipment_service/Form.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#form-object - */ -export type IForm = IObjectWithId<'Form'> & - IDatedObject & { - /** - * The type of form that we returned, can be one of "cn22", "cod_return_label", "commercial_invoice", "high_value_report", "label_qr_code", "nafta_certificate_of_origin", "order_summary", "return_packing_slip", "rma_qr_code" - */ - form_type: - | 'cn22' - | 'cod_return_label' - | 'commercial_invoice' - | 'high_value_report' - | 'label_qr_code' - | 'nafta_certificate_of_origin' - | 'order_summary' - | 'return_packing_slip' - | 'rma_qr_code'; - /** - * The address we return the form back at - */ - form_url: string; - /** - * If we have submitted the form to the carrier on behalf of the customer - */ - submitted_electronically: boolean; - }; diff --git a/types/services/shipment_service/Message.d.ts b/types/services/shipment_service/Message.d.ts deleted file mode 100644 index ff845b655..000000000 --- a/types/services/shipment_service/Message.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -/** - * When rating a Shipment or Pickup, some carriers may fail to generate rates. - * These failures are returned as part of the Shipment or Pickup as part of their messages attribute, and follow a common object structure. - * - * It is important to note that the message value for any member of this list comes directly from the carrier, not from EasyPost. - * This means that if you see an authentication or other non-shipping error here, it is not an issue between you and EasyPost, it is an issue between you and the carrier, or an issue with the given data. - * - * @see https://www.easypost.com/docs/api/node#message-object - */ -export type IMessage = { - /** - * the name of the carrier generating the error, e.g. "UPS" - */ - carrier: string; - /** - * the category of error that occurred. Most frequently "rate_error" - */ - type: string; - /** - * the string from the carrier explaining the problem - */ - message: string; - /** - * the account id of the carrier. Useful if you have multiple accounts with the same carrier - */ - carrier_account_id: string; -}; diff --git a/types/services/shipment_service/Options/LabelFormat.d.ts b/types/services/shipment_service/Options/LabelFormat.d.ts deleted file mode 100644 index cc3a84031..000000000 --- a/types/services/shipment_service/Options/LabelFormat.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare type LabelFormat = 'PNG' | 'PDF' | 'ZPL' | 'EPL2'; diff --git a/types/services/shipment_service/Options/Options.d.ts b/types/services/shipment_service/Options/Options.d.ts deleted file mode 100644 index 52b3a842f..000000000 --- a/types/services/shipment_service/Options/Options.d.ts +++ /dev/null @@ -1,325 +0,0 @@ -import { LabelFormat } from './LabelFormat'; -import { TPrintCustomCode } from './PrintCustomCode'; -/** - * Shipments can have a variety of additional options which you can specify when creating a shipment. - * The Options object can be populated with the keys below. - * - * @see https://www.easypost.com/docs/api/node#options-object - */ -export type IOptions = { - /** - * Setting this option to true, will add an additional handling charge. - * An Additional Handling charge may be applied to the following: - * - Any article that is encased in an outside shipping container made of metal or wood. - * - Any item, such as a barrel, drum, pail or tire, that is not fully encased in a corrugated cardboard shipping container. - * - Any package with the longest side exceeding 60 inches or its second longest side exceeding 30 inches. - * - Any package with an actual weight greater than 70 pounds. - */ - additional_handling?: boolean | null; - /** - * Setting this option to "0", will allow the minimum amount of address information to pass the validation check. - * Only for USPS postage. - */ - address_validation_level?: string | null; - /** - * Set this option to true if your shipment contains alcohol. - * - UPS - only supported for US Domestic shipments - * - FedEx - only supported for US Domestic shipments - * - Canada Post - Requires adult signature 19 years or older. If you want adult signature 18 years or older, instead use delivery_confirmation: ADULT_SIGNATURE - */ - alcohol?: boolean | null; - /** - * Setting this option to true will indicate to the carrier to prefer delivery by drone, if the carrier supports drone delivery. - */ - by_drone?: boolean | null; - /** - * Setting this to true will add a charge to reduce carbon emissions. - */ - carbon_neutral?: boolean | null; - /** - * Adding an amount will have the carrier collect the specified amount from the recipient. - */ - cod_amount?: string | null; - /** - * Method for payment. "CASH", "CHECK", "MONEY_ORDER" - */ - cod_method?: 'CASH' | 'CHECK' | 'MONEY_ORDER' | null; - /** - * The ID of the Address to which the COD payment should be returned. - * Defaults to the origin address. - * Only available on FedEx shipments. - */ - cod_address_id?: string | null; - /** - * A description of the content of the shipment. - */ - content_description?: string | null; - /** - * Which currency this shipment will show for rates if carrier allows. - */ - currency?: string | null; - /** - * If you want to request a signature, you can pass "ADULT_SIGNATURE" or "SIGNATURE". - * You may also request "NO_SIGNATURE" to leave the package at the door. - * - All - some options may be limited for international shipments - * - FedEx - "INDIRECT_SIGNATURE" is also an option - * - USPS - additional options - * - "ADULT_SIGNATURE_RESTRICTED" - * - "SIGNATURE_RESTRICTED" - * - Canada Post - "DO_NOT_SAFE_DROP" - Tells the carrier to not hide the package ("safe drop"). - * - GSO - "STANDARD_SIGNATURE". - * - DHL Express - option mapping - * - "SIGNATURE" - DHL Express Direct Signature - * - "NO_SIGNATURE" - DHL Express Signature Release - */ - delivery_confirmation?: - | 'ADULT_SIGNATURE' - | 'SIGNATURE' - | 'NO_SIGNATURE' - | 'INDIRECT_SIGNATURE' - | 'ADULT_SIGNATURE_RESTRICTED' - | 'SIGNATURE_RESTRICTED' - | null; - /** - * Method the customer will use to transfer the package to the carrier. - * "REGULAR_PICKUP", "SCHEDULED_PICKUP", "RETAIL_LOCATION", "STATION" or "DROP_BOX". - * Supported carriers and their corresponding carrier dropoff codes: - * - FedEx - * - "REGULAR_PICKUP" - "REGULAR_PICKUP" (default) - * - "SCHEDULED_PICKUP" - "REQUEST_COURIER" - * - "RETAIL_LOCATION" - "BUSINESS_SERVICE_CENTER" - * - "STATION" - "STATION" - * - "DROP_BOX" - "DROP_BOX" - */ - dropoff_type?: - | 'REGULAR_PICKUP' - | 'SCHEDULED_PICKUP' - | 'RETAIL_LOCATION' - | 'STATION' - | 'DROP_BOX' - | 'REQUEST_COURIER' - | 'BUSINESS_SERVICE_CENTER' - | null; - /** - * Package contents contain dry ice. - * - UPS - Need dry_ice_weight to be set - * - UPS MailInnovations - Need dry_ice_weight to be set - * - FedEx - Need dry_ice_weight to be set - */ - dry_ice?: boolean | null; - /** - * If the dry ice is for medical use, set this option to true. - * - UPS - Need dry_ice_weight to be set - * - UPS MailInnovations - Need dry_ice_weight to be set - */ - dry_ice_medical?: boolean | null; - /** - * Weight of the dry ice in ounces. - * - UPS - Need dry_ice to be set - * - UPS MailInnovations - Need dry_ice to be set - * - FedEx - Need dry_ice to be set - */ - dry_ice_weight?: string | null; - /** - * Setting duty_payment type to bill the correct account for purchasing postage. - * This option is only available with FedEx and UPS. - * - type - (string) Supported values are "THIRD_PARTY", and "RECEIVER". - * - account - (string) Setting account number. - * - country - (string) Setting country code that the account is based in. - * - postal_code - (string) Setting postal code that the account is based in. - */ - duty_payment?: object | null; - /** - * Possible values "ADDRESS_SERVICE_REQUESTED", "FORWARDING_SERVICE_REQUESTED", "CHANGE_SERVICE_REQUESTED", "RETURN_SERVICE_REQUESTED", "LEAVE_IF_NO_RESPONSE" - */ - endorsement?: - | 'ADDRESS_SERVICE_REQUESTED' - | 'FORWARDING_SERVICE_REQUESTED' - | 'CHANGE_SERVICE_REQUESTED' - | 'RETURN_SERVICE_REQUESTED' - | 'LEAVE_IF_NO_RESPONSE' - | null; - /** - * Specify the responsible EndShipper for the shipment by passing in an EndShipper ID. - */ - end_shipper_id?: string | null; - /** - * Additional cost to be added to the invoice of this shipment. - * Only applies to UPS currently. - */ - freight_charge?: number | null; - /** - * This is to designate special instructions for the carrier like "Do not drop!". - */ - handling_instructions?: string | null; - /** - * Dangerous goods indicator. - * Possible values are "PRIMARY_CONTAINED", "PRIMARY_PACKED", "PRIMARY", "SECONDARY_CONTAINED", "SECONDARY_PACKED", "SECONDARY", "ORMD", "LIMITED_QUANTITY", "LITHIUM". - * Applies to USPS, FedEx and DHL eCommerce. - */ - hazmat?: - | 'PRIMARY_CONTAINED' - | 'PRIMARY_PACKED' - | 'PRIMARY' - | 'SECONDARY_CONTAINED' - | 'SECONDARY_PACKED' - | 'SECONDARY' - | 'ORMD' - | 'LIMITED_QUANTITY' - | 'LITHIUM' - | null; - /** - * Package will wait at carrier facility for pickup. - */ - hold_for_pickup?: boolean | null; - /** - * Incoterm negotiated for shipment. - * Supported values are "EXW", "FCA", "CPT", "CIP", "DAT", "DAP", "DDP", "FAS", "FOB", "CFR", and "CIF". - * Setting this value to anything other than "DDP" will pass the cost and responsibility of duties on to the recipient of the package(s), as specified by Incoterms rules - */ - incoterm?: - | 'EXW' - | 'FCA' - | 'CPT' - | 'CIP' - | 'DAT' - | 'DAP' - | 'DDP' - | 'FAS' - | 'FOB' - | 'CFR' - | 'CIF' - | null; - /** - * This will print an invoice number on the postage label. - */ - invoice_number?: string | null; - /** - * Set the date that will appear on the postage label. - * Accepts ISO 8601 formatted string including time zone offset. - * EasyPost stores all dates as UTC time. - */ - label_date?: string | null; - /** - * Supported label formats include "PNG", "PDF", "ZPL", and "EPL2". - * "PNG" is the only format that allows for conversion. - * - * @see https://www.easypost.com/docs/api#convert-the-label-format-of-a-shipment - */ - label_format?: LabelFormat | null; - /** - * Whether or not the parcel can be processed by the carriers equipment. - */ - machinable?: boolean | null; - /** - * Setting payment type to bill the correct account for purchasing postage. - */ - payment?: { - /** - * Supported values are "SENDER", "THIRD_PARTY", "RECEIVER", "COLLECT". Defaults to SENDER. - */ - type?: 'SENDER' | 'THIRD_PARTY' | 'RECEIVER' | 'COLLECT' | null; - /** - * Setting account number. - * Required for RECEIVER and THIRD_PARTY. - */ - account?: string | null; - /** - * Setting country code that the account is based in. - * Required for THIRD_PARTY. - */ - country?: string | null; - /** - * Setting postal code that the account is based in. - * Required for RECEIVER and THIRD_PARTY. - */ - postal_code?: string | null; - }; - /** - * The earliest a package should be picked up. Supported carriers vary. - */ - pickup_min_datetime?: string | null; - /** - * The latest a package should be picked up. Supported carriers vary. - */ - pickup_man_datetime?: string | null; - /** - * You can optionally print custom messages on labels. - * The locations of these fields show up on different spots on the carrier's labels. - */ - print_custom_1?: string | null; - /** - * An additional message on the label. Same restrictions as print_custom_1 - */ - print_custom_2?: string | null; - /** - * An additional message on the label. Same restrictions as print_custom_1 - */ - print_custom_3?: string | null; - /** - * Create a barcode for this custom reference if supported by carrier. - */ - print_custom_1_barcode?: boolean | null; - /** - * Create a barcode for this custom reference if supported by carrier. - */ - print_custom_2_barcode?: boolean | null; - /** - * Create a barcode for this custom reference if supported by carrier. - */ - print_custom_3_barcode?: boolean | null; - /** - * Specify the type of print_custom_1. - */ - print_custom_1_code?: TPrintCustomCode | null; - /** - * Specify the type of print_custom_2. - */ - print_custom_2_code?: TPrintCustomCode | null; - /** - * Specify the type of print_custom_3. - */ - print_custom_3_code?: TPrintCustomCode | null; - /** - * Set this value to true for delivery on Saturday. - * When setting the saturday_delivery option, you will only get rates for services that are eligible for saturday delivery. - * If no services are available for saturday delivery, then you will not be returned any rates. - * You may need to create 2 shipments, one with the saturday_delivery option set on one without to get all your eligible rates. - */ - saturday_delivery?: boolean | null; - /** - * This option allows you to request restrictive rates from USPS. - * Can set to 'USPS.MEDIAMAIL' or 'USPS.LIBRARYMAIL'. - */ - special_rates_eligibility?: 'USPS.MEDIAMAIL' | 'USPS.LIBRARYMAIL' | null; - /** - * You can use this to override the hub ID you have on your account. - */ - smartpost_hub?: string | null; - /** - * The manifest ID is used to group SmartPost packages onto a manifest for each trailer. - */ - smartpost_manifest?: string | null; - /** - * A reference ID for aggregating DHL eCommerce billing data. - */ - billing_ref?: string | null; - /** - * Certified Mail provides the sender with a mailing receipt and, upon request, electronic verification that an article was delivered or that a delivery attempt was made. - */ - certified_mail?: boolean | null; - /** - * Registered Mail is the most secure service that the USPS offers. - * It incorporates a system of receipts to monitor the movement of the mail from the point of acceptance to delivery - */ - registered_mail?: boolean | null; - /** - * The value of the package contents - */ - registered_mail_amount?: number | null; - /** - * An electronic return receipt may be purchased at the time of mailing and provides a shipper with evidence of delivery (to whom the mail was delivered and date of delivery), and information about the recipient's actual delivery address. - * Only applies to the USPS. - */ - return_receipt?: boolean | null; -}; diff --git a/types/services/shipment_service/Options/PrintCustomCode.d.ts b/types/services/shipment_service/Options/PrintCustomCode.d.ts deleted file mode 100644 index 4933056eb..000000000 --- a/types/services/shipment_service/Options/PrintCustomCode.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -/** - * - FedEx - * - (null) - If print_custom_1_code is not provided it defaults to Customer Reference - * - PO - Purchase Order Number - * - DP - Department Number - * - RMA - Return Merchandise Authorization - * - UPS - * - AJ - Accounts Receivable Customer Account - * - AT - Appropriation Number - * - BM - Bill of Lading Number - * - 9V - Collect on Delivery (COD) Number - * - ON - Dealer Order Number - * - DP - Department Number - * - 3Q - Food and Drug Administration (FDA) Product Code - * - IK - Invoice Number - * - MK - Manifest Key Number - * - MJ - Model Number - * - PM - Part Number - * - PC - Production Code - * - PO - Purchase Order Number - * - RQ - Purchase Request Number - * - RZ - Return Authorization Number - * - SA - Salesperson Number - * - SE - Serial Number - * - ST - Store Number - * - TN - Transaction Reference Number - * - EI - Employer's ID Number - * - TJ - Federal Taxpayer ID No. - */ -export declare type TPrintCustomCode = - | 'PO' - | 'DP' - | 'RMA' - | 'AJ' - | 'AT' - | 'BM' - | '9V' - | 'ON' - | '3Q' - | 'IK' - | 'MK' - | 'MJ' - | 'PM' - | 'PC' - | 'RQ' - | 'RZ' - | 'SA' - | 'SE' - | 'ST' - | 'TN' - | 'EI' - | 'TJ'; diff --git a/types/services/shipment_service/Options/index.d.ts b/types/services/shipment_service/Options/index.d.ts deleted file mode 100644 index 349426b0d..000000000 --- a/types/services/shipment_service/Options/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './LabelFormat'; -export * from './Options'; -export * from './PrintCustomCode'; diff --git a/types/services/shipment_service/PostageLabel.d.ts b/types/services/shipment_service/PostageLabel.d.ts deleted file mode 100644 index 0d0b2fdf6..000000000 --- a/types/services/shipment_service/PostageLabel.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * PostageLabel Object - */ -export type IPostageLabel = IObjectWithId<'PostageLabel'> & - IDatedObject & { - date_advance: number; - integrated_form: string; - label_date: string; - label_resolution: number; - label_size: string; - label_type: string; - label_url: string; - label_file_type: string; - label_pdf_url: string; - label_epl2_url: string; - label_zpl_url: string; - }; diff --git a/types/services/shipment_service/Shipment.d.ts b/types/services/shipment_service/Shipment.d.ts deleted file mode 100644 index 80f7b4292..000000000 --- a/types/services/shipment_service/Shipment.d.ts +++ /dev/null @@ -1,124 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { IAddress } from '../address_service'; -import { TBatchStatus } from '../batch_service'; -import { ICustomsInfo } from '../customs_info_service'; -import { IFee, IInsurance } from '../insurance_service'; -import { IParcel } from '../parcel_service'; -import { IRate } from '../rate_service'; -import { IScanForm } from '../scan_form_service'; -import { ITracker } from '../tracker_service'; -import { IForm } from './Form'; -import { IMessage } from './Message'; -import { IOptions } from './Options'; -import { IPostageLabel } from './PostageLabel'; -/** - * The workhorse of the EasyPost API, a Shipment is made up of a "to" and "from" Address, the Parcel being shipped, and any customs forms required for international deliveries. - * Once created a Shipment object is used to retrieve shipping Rates and purchase a label. - * - * A Shipment created with a valid to_address, from_address, and parcel will automatically populate its rates attribute. - * - * @see https://www.easypost.com/docs/api/node#shipment-object - */ -export type IShipment = IObjectWithId<'Shipment'> & - IDatedObject & { - /** - * An optional field that may be used in place of id in other API endpoints - */ - reference?: string | null; - /** - * The destination address - */ - to_address: IAddress; - /** - * The origin address - */ - from_address: IAddress; - /** - * The shipper's address, defaults to from_address - */ - return_address?: IAddress | null; - /** - * The buyer's address, defaults to to_address - */ - buyer_address?: IAddress | null; - /** - * The dimensions and weight of the package - */ - parcel: IParcel; - /** - * Information for the processing of customs - */ - customs_info?: ICustomsInfo | null; - /** - * Document created to manifest and scan multiple shipments - */ - scan_form: IScanForm; - /** - * All associated Form objects - */ - forms: IForm[]; - /** - * The associated Insurance object - */ - insurance: IInsurance; - /** - * All associated Rate objects - */ - rates: IRate[]; - /** - * The specific rate purchased for the shipment, or null if unpurchased or purchased through another mechanism - */ - selected_rate: IRate; - /** - * The associated PostageLabel object - */ - postage_label: IPostageLabel; - /** - * Any carrier errors encountered during rating, discussed in more depth below - */ - messages: IMessage[]; - /** - * All the options passed to the shipment, discussed in more depth below - */ - options?: IOptions | null; - /** - * Set true to create as a return, discussed in more depth below - */ - is_return?: boolean | null; - /** - * If purchased, the tracking code will appear here as well as within the Tracker object - */ - tracking_code: string; - /** - * The USPS zone of the shipment, if purchased with USPS - */ - usps_zone: string; - /** - * The current tracking status of the shipment - */ - status: string; - /** - * The associated Tracker object - */ - tracker: ITracker; - /** - * The associated Fee objects charged to the billing user account - */ - fees: IFee[]; - /** - * The current status of the shipment refund process. Possible values are "submitted", "refunded", "rejected". - */ - refund_status: 'submitted' | 'refunded' | 'rejected'; - /** - * The ID of the batch that contains this shipment, if any - */ - batch_id: string; - /** - * The current status of the associated BatchShipment - */ - batch_status: TBatchStatus; - /** - * The current message of the associated BatchShipment - */ - batch_message: string; - }; diff --git a/types/services/shipment_service/ShipmentCreateParameters.d.ts b/types/services/shipment_service/ShipmentCreateParameters.d.ts deleted file mode 100644 index 4b690eead..000000000 --- a/types/services/shipment_service/ShipmentCreateParameters.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { DeepPartial } from '../../utils/types'; -import { IAddressCreateParameters } from '../address_service'; -import { ICustomsInfo } from '../customs_info_service'; -import { IParcelCreateParameters } from '../parcel_service'; -import { IOptions } from './Options'; -export type IShipmentCreateParameters = { - reference?: string | null; - to_address: DeepPartial | string; - from_address: DeepPartial | string; - parcel: Partial | string; - /** - * optional array of ids that begin with "ca_" - */ - carrier_accounts?: string[] | null; - customs_info?: DeepPartial | null; - options?: DeepPartial | null; -}; diff --git a/types/services/shipment_service/ShipmentListParameters.d.ts b/types/services/shipment_service/ShipmentListParameters.d.ts deleted file mode 100644 index c875985b8..000000000 --- a/types/services/shipment_service/ShipmentListParameters.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments - */ -export type IShipmentListParameters = IAllMethodParameters & { - /** - * Only include Shipments that have been purchased. - * Default is true - */ - purchased?: boolean; - /** - * Also include Shipments created by Child Users. - * Defaults to false - */ - include_children?: boolean; -}; diff --git a/types/services/shipment_service/index.d.ts b/types/services/shipment_service/index.d.ts deleted file mode 100644 index 0d14ecb05..000000000 --- a/types/services/shipment_service/index.d.ts +++ /dev/null @@ -1,605 +0,0 @@ -import EasyPost from '../..'; -import { IRate, ISmartRate } from '../rate_service'; -import { IOptions, LabelFormat } from './Options'; -import { IShipmentCreateParameters } from './ShipmentCreateParameters'; -import { IShipmentListParameters } from './ShipmentListParameters'; -export * from './Form'; -export * from './Message'; -export * from './PostageLabel'; -export * from './Shipment'; -export * from './ShipmentCreateParameters'; -export * from './ShipmentListParameters'; -export * from './Options'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#create-a-shipment EasyPost API Documentation} for more information. - * @param params - The parameters to create a shipment with. - * @returns - The created shipment. - */ - create(params: IShipmentCreateParameters): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */ - buy( - id: string, - rate: IRate | string, - insuranceAmount?: number | null, - endShipperId?: string | null, - ): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Convert the label format of a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#convert-the-label-format-of-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to convert the label format of. - * @param format - The format to convert the label to. - * @returns - The shipment with the converted label format. - */ - convertLabelFormat( - id: string, - format: LabelFormat, - ): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Regenerate {@link Rate rates} for a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#regenerate-rates-for-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to regenerate rates for. - * @returns - The shipment with regenerated rates. - */ - regenerateRates(id: string): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Get SmartRates for a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-time-in-transit-statistics-across-all-rates-for-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to get SmartRates for. - * @returns - The SmartRates for the shipment. - */ - getSmartRates(id: string): Promise>; - /** - * Insure a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#insure-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to insure. - * @param amount - The amount to insure the shipment for. - * @returns - The insured shipment. - */ - insure( - id: string, - amount: number | string, - ): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Generate a form for a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#create-form EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to generate a form for. - * @param formType - The type of form to generate. - * @param [formOptions] - Options for the form. - * @returns - The shipment with the generated form attached. - */ - generateForm( - id: string, - formType: string, - formOptions?: IOptions, - ): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Refund a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#refund-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to refund. - * @returns - The refunded shipment. - */ - refund(id: string): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Get the lowest SmartRate of a shipment. - * @param id - The ID of the shipment to get the lowest SmartRate of. - * @param deliveryDays - The number of days the shipment will take to deliver. - * @param deliveryAccuracy - The accuracy of the delivery days. - * @returns - The lowest SmartRate of the shipment. - */ - lowestSmartRate( - id: string, - deliveryDays: number, - deliveryAccuracy: keyof ISmartRate['time_in_transit'], - ): Promise; - /** - * Retrieve all {@link Shipment shipments} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the shipments by. - * @returns - An object containing a list of {@link Shipment shipments} and pagination information. - */ - all(params?: IShipmentListParameters): Promise<{ - shipments: (import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - })[]; - _params: any; - has_more: boolean; - }>; - /** - * Retrieve the next page of Shipment collection. - * @param shipments An object containing a list of {@link Shipment shipments} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - shipments: { - shipments: any[]; - }, - pageSize?: null, - ): Promise<{ - shipments: (import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - })[]; - _params: any; - has_more: boolean; - }>; - /** - * Retrieve a {@link Shipment shipment} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to retrieve. - * @returns - The shipment with the given ID. - */ - retrieve(id: string): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Retrieves the estimated delivery date of each Rate via SmartRate. - * @param id - * @param plannedShipDate - * @returns - An array of the estimated delivery date and rates. - */ - retrieveEstimatedDeliveryDate( - id: string, - plannedShipDate: string, - ): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/tracker_service/CarrierDetail.d.ts b/types/services/tracker_service/CarrierDetail.d.ts deleted file mode 100644 index 0cbb6a136..000000000 --- a/types/services/tracker_service/CarrierDetail.d.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { IBaseObject } from '../../utils/types'; -import { ITrackingLocation } from './TrackingLocation'; -/** - * @see https://www.easypost.com/docs/api/node#carrier-detail-object - */ -export type ICarrierDetail = IBaseObject<'CarrierDetail'> & { - /** - * The service level the associated shipment was shipped with (if available) - */ - service: string; - /** - * The type of container the associated shipment was shipped in (if available) - */ - container_type: string; - /** - * The estimated delivery date as provided by the carrier, in the local time zone (if available) - */ - est_delivery_date_local: string; - /** - * The estimated delivery time as provided by the carrier, in the local time zone (if available) - */ - est_delivery_time_local: string; - /** - * The location from which the package originated, stringified for presentation (if available) - */ - origin_location: string; - /** - * The location from which the package originated, broken down by city/state/country/zip (if available) - */ - origin_tracking_location: ITrackingLocation; - /** - * The location to which the package is being sent, stringified for presentation (if available) - */ - destination_location: string; - /** - * The location to which the package is being sent, broken down by city/state/country/zip (if available) - */ - destination_tracking_location: ITrackingLocation; - /** - * The date and time the carrier guarantees the package to be delivered by (if available) - */ - guaranteed_delivery_date: string; - /** - * The alternate identifier for this package as provided by the carrier (if available) - */ - alternate_identifier: string; - /** - * The date and time of the first attempt by the carrier to deliver the package (if available) - */ - initial_delivery_attempt: string; -}; diff --git a/types/services/tracker_service/Tracker.d.ts b/types/services/tracker_service/Tracker.d.ts deleted file mode 100644 index b601dc6c2..000000000 --- a/types/services/tracker_service/Tracker.d.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { IFee } from '../insurance_service'; -import { ICarrierDetail } from './CarrierDetail'; -import { ITrackerStatus } from './TrackerStatus'; -import { ITrackerStatusDetail } from './TrackerStatusDetail'; -import { ITrackingDetail } from './TrackingDetail'; -/** - * A Tracker object contains all the tracking information for a package. - * A Tracker is created automatically whenever you buy a Shipment through EasyPost. - * If you don't use EasyPost to purchase your shipping labels, you can still track packages through our API by creating a Tracker object directly. - * Each Tracker is continually updated in the background as the package moves through its life cycle, regardless of whether or not the label was purchased through EasyPost. - * - * After creation, a Tracker object will be updated periodically based on when the carrier provides EasyPost with new tracking information. - * This information can be consumed by using our webhooks infrastructure. - * Every time a Tracker is updated a webhook Event will be sent. - * - * The Tracker object contains both the current information about the package and previous updates. - * All the previous updates are stored in the tracking_details array. - * Each TrackingDetail object contains the status, the message from the carrier, and a TrackingLocation. - * - * The TrackingLocation contains city, state, country, and zip information about the location where the package was scanned. - * The information each carrier provides is different, so some carriers may not make use of all these fields. - * - * Some Tracker objects may also contain a CarrierDetail, which stores some additional information about the Tracker that the carrier has made available to EasyPost. - * The CarrierDetail object contains the service and container_type of the package. - * Additionally, it also stores the `est_delivery_date_local` and `est_delivery_time_local`, which provide information about the local delivery time. - * - * It's worth noting that tracking_codes are not globally unique. - * Each carrier promises uniqueness for a given `tracking_code` for a certain period of time, but the length of time varies greatly based on the specific carrier and service level. - * The carriers do eventually recycle `tracking_codes`, and for this reason enforcing uniqueness on the `tracking_code` field is not recommended. - * EasyPost does, however, prevent the creation of duplicate Trackers based on tracking_code and carrier; duplicate requests by the same User will simply return the original Tracker. - * - * @see https://www.easypost.com/docs/api/node#tracker-object - */ -export type ITracker = IObjectWithId<'Tracker'> & - IDatedObject & { - /** - * The tracking code provided by the carrier - */ - tracking_code: string; - /** - * The current status of the package, possible values are "unknown", "pre_transit", "in_transit", "out_for_delivery", "delivered", "available_for_pickup", "return_to_sender", "failure", "cancelled" or "error" - */ - status: ITrackerStatus; - /** - * Additional details about the current status, possible values are "unknown", "status_update", "departed_facility", "arrived_at_facility", "out_for_delivery", "arrived_at_destination" - */ - status_detail: ITrackerStatusDetail; - /** - * The name of the person who signed for the package (if available) - */ - signed_by: string; - /** - * The weight of the package as measured by the carrier in ounces (if available) - * float (oz) - */ - weight: number; - /** - * The estimated delivery date provided by the carrier (if available) - */ - est_delivery_date: string; - /** - * The id of the EasyPost Shipment object associated with the Tracker (if any) - */ - shipment_id: string; - /** - * The name of the carrier handling the shipment - */ - carrier: string; - /** - * Array of the associated TrackingDetail objects - */ - tracking_details: ITrackingDetail[]; - /** - * The associated CarrierDetail object (if available) - */ - carrier_detail: ICarrierDetail; - /** - * URL to a publicly-accessible html page that shows tracking details for this tracker - */ - public_url: string; - /** - * Array of the associated Fee objects - */ - fees: IFee[]; - }; diff --git a/types/services/tracker_service/TrackerCreateParameters.d.ts b/types/services/tracker_service/TrackerCreateParameters.d.ts deleted file mode 100644 index 242a3fcec..000000000 --- a/types/services/tracker_service/TrackerCreateParameters.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export type ITrackerCreateParameters = { - /** - * The tracking code associated with the package you'd like to track - */ - tracking_code: string; - /** - * The carrier associated with the tracking_code you provided. - * The carrier will get auto-detected if none is provided - */ - carrier?: string; -}; diff --git a/types/services/tracker_service/TrackerListParameters.d.ts b/types/services/tracker_service/TrackerListParameters.d.ts deleted file mode 100644 index 0a831d83f..000000000 --- a/types/services/tracker_service/TrackerListParameters.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -export type ITrackerListParameters = IAllMethodParameters & { - /** - * Only returns Trackers with the given tracking_code. - * Useful for retrieving an individual Tracker by tracking_code rather than by ID - */ - tracking_code?: string; - /** - * Only returns Trackers with the given carrier value - */ - carrier?: string; -}; diff --git a/types/services/tracker_service/TrackerStatus.d.ts b/types/services/tracker_service/TrackerStatus.d.ts deleted file mode 100644 index 11b490ca1..000000000 --- a/types/services/tracker_service/TrackerStatus.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export type ITrackerStatus = - | 'unknown' - | 'pre_transit' - | 'in_transit' - | 'out_for_delivery' - | 'delivered' - | 'available_for_pickup' - | 'return_to_sender' - | 'failure' - | 'cancelled' - | 'error'; diff --git a/types/services/tracker_service/TrackerStatusDetail.d.ts b/types/services/tracker_service/TrackerStatusDetail.d.ts deleted file mode 100644 index d36c4690c..000000000 --- a/types/services/tracker_service/TrackerStatusDetail.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -export type ITrackerStatusDetail = - | 'address_correction' - | 'arrived_at_destination' - | 'arrived_at_facility' - | 'arrived_at_pickup_location' - | 'awaiting_information' - | 'cancelled' - | 'damaged' - | 'delayed' - | 'delivery_exception' - | 'departed_facility' - | 'departed_origin_facility' - | 'expired' - | 'failure' - | 'held' - | 'in_transit' - | 'label_created' - | 'lost' - | 'missorted' - | 'out_for_delivery' - | 'received_at_destination_facility' - | 'received_at_origin_facility' - | 'refused' - | 'return' - | 'status_update' - | 'transferred_to_destination_carrier' - | 'transit_exception' - | 'unknown' - | 'weather_delay'; diff --git a/types/services/tracker_service/TrackingDetail.d.ts b/types/services/tracker_service/TrackingDetail.d.ts deleted file mode 100644 index c214f1d78..000000000 --- a/types/services/tracker_service/TrackingDetail.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { IBaseObject } from '../../utils/types'; -import { ITrackerStatus } from './TrackerStatus'; -import { ITrackingLocation } from './TrackingLocation'; -/** - * @see https://www.easypost.com/docs/api/node#tracking-detail-object - */ -export type ITrackingDetail = IBaseObject<'TrackingDetail'> & { - /** - * Description of the scan event - */ - message: string; - /** - * Status of the package at the time of the scan event, possible values are "unknown", "pre_transit", "in_transit", "out_for_delivery", "delivered", "available_for_pickup", "return_to_sender", "failure", "cancelled" or "error" - */ - status: ITrackerStatus; - /** - * The timestamp when the tracking scan occurred - */ - datetime: string; - /** - * The original source of the information for this scan event, usually the carrier - */ - source: string; - /** - * The location associated with the scan event - */ - tracking_location: ITrackingLocation; -}; diff --git a/types/services/tracker_service/TrackingLocation.d.ts b/types/services/tracker_service/TrackingLocation.d.ts deleted file mode 100644 index 122522685..000000000 --- a/types/services/tracker_service/TrackingLocation.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { IBaseObject } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#tracking-location-object - */ -export type ITrackingLocation = IBaseObject<'TrackingLocation'> & { - /** - * The city where the scan event occurred (if available) - */ - city: string; - /** - * The state where the scan event occurred (if available) - */ - state: string; - /** - * The country where the scan event occurred (if available) - */ - country: string; - /** - * The postal code where the scan event occurred (if available) - */ - zip: string; -}; diff --git a/types/services/tracker_service/index.d.ts b/types/services/tracker_service/index.d.ts deleted file mode 100644 index 10013907e..000000000 --- a/types/services/tracker_service/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -import EasyPost from '../..'; -import { ITracker } from './Tracker'; -import { ITrackerCreateParameters } from './TrackerCreateParameters'; -import { ITrackerListParameters } from './TrackerListParameters'; -export * from './CarrierDetail'; -export * from './Tracker'; -export * from './TrackerCreateParameters'; -export * from './TrackerListParameters'; -export * from './TrackerStatus'; -export * from './TrackerStatusDetail'; -export * from './TrackingDetail'; -export * from './TrackingLocation'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Tracker tracker}. - * See {@link https://www.easypost.com/docs/api/node#create-a-tracker EasyPost API Documentation} for more information. - * @param params - The parameters to create a tracker with. - * @returns - The created tracker. - */ - create( - params: ITrackerCreateParameters, - ): Promise>; - /** - * Create multiple {@link Tracker trackers} in a single request. - * See {@link https://www.easypost.com/docs/api/node#trackers EasyPost API Documentation} for more information. - * @param [params] - The parameters to create trackers with. - */ - createList(params?: ITrackerCreateParameters[]): Promise; - /** - * Retrieve all {@link Tracker trackers} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-trackers EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the trackers by. - * @returns - An object containing the list of {@link Tracker trackers} and pagination information. - */ - all(params?: ITrackerListParameters): Promise< - { - trackers: ITracker[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of Tracker collection. - * @param trackers An object containing a list of {@link Tracker trackers} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - trackers: { - trackers: any[]; - }, - pageSize?: number | null, - ): Promise< - { - trackers: ITracker[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link Tracker tracker} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-tracker EasyPost API Documentation} for more information. - * @param id - The ID of the tracker to retrieve. - * @returns - The retrieved tracker. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/user_service/Brand.d.ts b/types/services/user_service/Brand.d.ts deleted file mode 100644 index fd0fc15a4..000000000 --- a/types/services/user_service/Brand.d.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { IObjectWithId } from '../../utils/types'; -/** - * The Brand class represents the public-accessible information about a user's brand, including logos, colors and themes. - * - * @see https://www.easypost.com/docs/api/node#brand - */ -export type IBrand = IObjectWithId<'Brand'> & { - /** - * The background color of the brand, as a hex code. - */ - background_color: string; - /** - * The primary color of the brand, as a hex code. - */ - color: string; - /** - * The logo of the brand, as a base64-encoded PNG, GIF, JPEG or SVG. - */ - logo: string; - /** - * The URL of the brand's logo. - */ - logo_href: string; - /** - * The banner ad of the brand, as a base64-encoded PNG, GIF, JPEG or SVG. - */ - ad: string; - /** - * The URL of the brand's banner ad. - */ - ad_href: string; - /** - * The ID of the brand's associated User. - */ - user_id: string; - /** - * The name of the current theme. - */ - theme: 'theme1' | 'theme2'; -}; diff --git a/types/services/user_service/User.d.ts b/types/services/user_service/User.d.ts deleted file mode 100644 index af274970f..000000000 --- a/types/services/user_service/User.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { IObjectWithId } from '../../utils/types'; -/** - * The User object can be used to manage your own account and to create child accounts. - * Only a Production mode API key can be used to make requests against the Users API. - * - * Balance and recharge values on User objects are expressed in higher precision USD. - * - * @see https://www.easypost.com/docs/api/node#user-object - */ -export type IUser = IObjectWithId<'User'> & { - /** - * The ID of the parent user object. - * Top-level users are defined as users with no parent - */ - parent_id: string; - /** - * First and last name required - */ - name: string; - /** - * Required - */ - email: string; - /** - * Optional - */ - phone_number?: string | null; - /** - * Formatted as string "XX.XXXXX" - */ - balance: string; - /** - * Cost per shipment purchase, formatted as string "XX.XXXXX" - */ - price_per_shipment: string; - /** - * USD formatted dollars and cents, delimited by a decimal point - */ - recharge_amount: string; - /** - * USD formatted dollars and cents, delimited by a decimal point - */ - secondary_recharge_amount: string; - /** - * Number of cents USD that when your balance drops below, we automatically recharge your account with your primary payment method. - */ - recharge_threshold: string; - /** - * The fee rate for convenience fees - */ - cc_fee_rate: string; - /** - * The fee rate for insurance purchases - */ - insurance_fee_rate: string; - /** - * The minimum cost for insurance purchases - */ - insurance_fee_minimum: string; - /** - * All associated children - */ - children: IUser[]; -}; diff --git a/types/services/user_service/UserCreateParameters.d.ts b/types/services/user_service/UserCreateParameters.d.ts deleted file mode 100644 index 78113251c..000000000 --- a/types/services/user_service/UserCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { IUser } from './User'; -export type IUserCreateParameters = Omit; diff --git a/types/services/user_service/index.d.ts b/types/services/user_service/index.d.ts deleted file mode 100644 index bd4afc937..000000000 --- a/types/services/user_service/index.d.ts +++ /dev/null @@ -1,126 +0,0 @@ -import EasyPost from '../..'; -import { IBrand } from './Brand'; -import { IUser } from './User'; -import { IUserCreateParameters } from './UserCreateParameters'; -export * from './Brand'; -export * from './User'; -export * from './UserCreateParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link User child user}. - * See {@link https://www.easypost.com/docs/api/node#create-a-child-user EasyPost API Documentation} for more information. - * @param params - The parameters to create a child user with. - * @returns - The created child user. - */ - create(params: IUserCreateParameters): Promise>; - /** - * Update a {@link User user}. - * See {@link https://www.easypost.com/docs/api/node#update-a-user EasyPost API Documentation} for more information. - * @param id - The ID of the user to update (either the current authenticated user or a child user). - * @param params - The parameters to update the user with. - * @returns - The updated user. - */ - update( - id: string, - params: Partial, - ): Promise>; - /** - * Retrieve a {@link User child user}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-user EasyPost API Documentation} for more information. - * @param id - The ID of the child user to retrieve. - * @returns - The retrieved child user. - */ - retrieve(id: string): Promise>; - /** - * Retrieve the {@link User current authenticated user}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-user EasyPost API Documentation} for more information. - * @returns - The retrieved user. - */ - retrieveMe(): Promise>; - /** - * Delete a {@link User child user}. - * See {@link https://www.easypost.com/docs/api/node#delete-a-child-user EasyPost API Documentation} for more information. - * @param id - The ID of the child user to delete. - * @returns - A promise that resolves when the child user is deleted successfully. - */ - delete(id: string): Promise; - /** - * Update the brand of a {@link User user}. - * See {@link https://www.easypost.com/docs/api/node#update-a-brand EasyPost API Documentation} for more information. - * @param id - The ID of the user to update the brand of. - * @param params - The parameters to update the brand with. - * @returns - The updated brand. - */ - updateBrand( - id: string, - params: Partial, - ): Promise>; - /** - * Retrieve a paginated list of children user {@link User user}. - * See {@link https://www.easypost.com/docs/api/node#child-users EasyPost API Documentation} for more information. - * @param params - Parameters to filter the list of children users. - * @returns - An object containing a list of {@link Children User} and pagination information. - */ - allChildren(params: any): Promise< - import('../base_service').EasyPostObject<{ - children: IUser[]; - }> - >; - /** - * Retrieve the next page of children collection. - * @param children An object containing a list of {@link Children children} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - children: { - children: any[]; - }, - pageSize?: number | null, - ): Promise< - { - children: IUser[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise> - /** - * Delete a {@link User child user}. - * See {@link https://www.easypost.com/docs/api/node#delete-a-child-user EasyPost API Documentation} for more information. - * @param id - The ID of the child user to delete. - * @returns - A promise that resolves when the child user is deleted successfully. - */; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/services/webhook_service/Webhook.d.ts b/types/services/webhook_service/Webhook.d.ts deleted file mode 100644 index a7137ee4e..000000000 --- a/types/services/webhook_service/Webhook.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { IObjectWithId } from '../../utils/types'; -/** - * Each Webhook contains the url which EasyPost will notify whenever an object in our system updates. - * Several types of objects are processed asynchronously in the EasyPost system, so whenever an object updates, an Event is sent via HTTP POST to each configured webhook URL. - * The Webhook object provides CRUD operations for all Webhooks. - * - * Currently, our recommended best practice for securing Webhooks involves using basic authentication and HTTPS on your endpoint. - * This will help prevent any altering of any information communicated to you by EasyPost, prevent any third parties from seeing your webhooks in transit, and will prevent any third parties from masquerading as EasyPost and sending fraudulent data. - * EasyPost performs certificate validation and requires any TLS-enabled (HTTPS) webhook recipients to have a certificate signed by a public trusted certification authority. - * We do not support sending webhooks to over SSLv2, SSLv3, or any connection using so-called export-grade ciphers. - * For documentation on how to set up your server with TLS, we recommend Mozilla's guide to Server-Side TLS and Qualys's SSL/TLS deployment best practices guide. - * - * In general, a Webhook's endpoint should return a status code of 2XX. - * A 200 is preferred, but any 2XX status will indicate to our system that the Webhook request was successful. - * Endpoints that return a large volume and rate of failures over a period of time will get automatically disabled by the system; a disabled Webhook can be re-enabled using the Webhook update endpoint. - * - * @see https://www.easypost.com/docs/api/node#webhook-object - */ -export type IWebhook = IObjectWithId<'Webhook'> & { - /** - * http://example.com - */ - url: string; - /** - * the timestamp at which the webhook was most recently disabled (if any) - */ - disabled_at: string; -}; diff --git a/types/services/webhook_service/WebhookCreateParameters.d.ts b/types/services/webhook_service/WebhookCreateParameters.d.ts deleted file mode 100644 index e5eb2aee2..000000000 --- a/types/services/webhook_service/WebhookCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type IWebhookCreateParameters = { - url: string; -}; diff --git a/types/services/webhook_service/WebhookListParameters.d.ts b/types/services/webhook_service/WebhookListParameters.d.ts deleted file mode 100644 index 4660bde6a..000000000 --- a/types/services/webhook_service/WebhookListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#list-a-webhooks - */ -export type IWebhookListParameters = IAllMethodParameters; diff --git a/types/services/webhook_service/index.d.ts b/types/services/webhook_service/index.d.ts deleted file mode 100644 index a1890b6df..000000000 --- a/types/services/webhook_service/index.d.ts +++ /dev/null @@ -1,90 +0,0 @@ -import EasyPost from '../..'; -import { IWebhook } from './Webhook'; -import { IWebhookCreateParameters } from './WebhookCreateParameters'; -import { IWebhookListParameters } from './WebhookListParameters'; -export * from './Webhook'; -export * from './WebhookCreateParameters'; -export * from './WebhookListParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Webhook webhook}. - * See {@link https://www.easypost.com/docs/api/node#create-a-webhook EasyPost API Documentation} for more information. - * @param params - The parameters to create a webhook with. - * @returns - The created webhook. - */ - create( - params: IWebhookCreateParameters, - ): Promise>; - /** - * Update a {@link Webhook webhook}. - * A disabled webhook will be re-enabled if it is updated. - * See {@link https://www.easypost.com/docs/api/node#update-a-webhook EasyPost API Documentation} for more information. - * @param id - The ID of the webhook to update. - * @param params - The parameters to update the webhook with. - * @returns - The updated webhook. - */ - update( - id: string, - params: Partial, - ): Promise>; - /** - * Delete a {@link Webhook webhook}. - * See {@link https://www.easypost.com/docs/api/node#delete-a-webhook EasyPost API Documentation} for more information. - * @param id - The ID of the webhook to delete. - * @returns - A promise that resolves if the webhook was successfully deleted. - */ - delete(id: string): Promise; - /** - * Retrieve all {@link Webhook webhooks} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#list-a-webhooks EasyPost API Documentation} for more information. - * @param [params] - * @returns - */ - all(params?: IWebhookListParameters): Promise< - { - webhooks: IWebhook[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link Webhook webhook} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-webhook EasyPost API Documentation} for more information. - * @param id - The ID of the webhook to retrieve. - * @returns - The retrieved webhook. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/constants.d.ts b/types/src/constants.d.ts deleted file mode 100644 index 2e9caa299..000000000 --- a/types/src/constants.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import Utils from './utils/util'; -/** - * A class containing constants used throughout the EasyPost Node.js client library. - */ -export default class Constants { - static get CARRIER_ACCOUNTS_WITH_CUSTOM_WORKFLOWS(): string[]; - static EXTERNAL_API_CALL_FAILED: string; - static INVALID_API_KEY_TYPE: string; - static INVALID_PARAMETER: string; - static INVALID_PAYMENT: string; - static INVALID_WEBHOOK_SIGNATURE: string; - static MISSING_REQUIRED_PARAMETER: string; - static NO_OBJECT_FOUND: string; - static NO_PAYMENT_METHODS: string; - static API_DID_NOT_RETURN_ERROR_DETAILS: string; - static WEBHOOK_DOES_NOT_MATCH: string; - static END_OF_PAGINATION: string; - static ERROR_DESERIALIZATION: string; - static Utils: Utils; -} diff --git a/types/src/easypost.d.ts b/types/src/easypost.d.ts deleted file mode 100644 index e9b390ae5..000000000 --- a/types/src/easypost.d.ts +++ /dev/null @@ -1,260 +0,0 @@ -import { SuperAgentStatic, Request, Response } from 'superagent'; -import AddressService from './services/address_service'; -import ApiKeyService from './services/api_key_service'; -import BatchService from './services/batch_service'; -import BetaRateService from './services/beta_rate_service'; -import BetaReferralCustomerService from './services/beta_referral_customer_service'; -import BillingService from './services/billing_service'; -import CarrierAccountService from './services/carrier_account_service'; -import CarrierMetadataService from './services/carrier_metadata_service'; -import CarrierTypeService from './services/carrier_type_service'; -import CustomsInfoService from './services/customs_info_service'; -import CustomsItemService from './services/customs_item_service'; -import EndShipperService from './services/end_shipper_service'; -import EventService from './services/event_service'; -import InsuranceService from './services/insurance_service'; -import OrderService from './services/order_service'; -import ParcelService from './services/parcel_service'; -import PickupService from './services/pickup_service'; -import RateService from './services/rate_service'; -import ReferralCustomerService from './services/referral_customer_service'; -import RefundService from './services/refund_service'; -import ReportService from './services/report_service'; -import ScanFormService from './services/scan_form_service'; -import ShipmentService from './services/shipment_service'; -import TrackerService from './services/tracker_service'; -import UserService from './services/user_service'; -import WebhookService from './services/webhook_service'; -import Utils from './utils/util'; -export * from './errors'; -export * from './services'; -export * from './utils/errors'; -export * from './constants'; -/** How many milliseconds in a second. */ -export declare const MS_SECOND = 1000; -/** The default timeout for all EasyPost API requests. */ -export declare const DEFAULT_TIMEOUT: number; -/** The default base URL for all production EasyPost API requests. */ -export declare const DEFAULT_BASE_URL = 'https://api.easypost.com/v2/'; -/** The default headers used for all EasyPost API requests. */ -export declare const DEFAULT_HEADERS: { - Accept: string; - 'Content-Type': string; - 'User-Agent': string; -}; -/** A map of HTTP methods to their corresponding string values (for use with superagent). */ -export declare const METHODS: { - readonly GET: 'get'; - readonly POST: 'post'; - readonly PUT: 'put'; - readonly PATCH: 'patch'; - readonly DELETE: 'del'; -}; -export type EasyPostClientOptions = { - useProxy?: boolean; - timeout?: number; - baseUrl?: string; - superagentMiddleware?: (agent: SuperAgentStatic) => SuperAgentStatic; - requestMiddleware?: (request: Request) => Request; - agent?: SuperAgentStatic; -}; -export type RequestHookData = { - method: (typeof METHODS)[keyof typeof METHODS]; - path: string; - requestBody: any; - headers: Record; - requestTimestamp: number; - requestUUID: string; -}; -export type RequestHook = (data: RequestHookData) => void; -export type ResponseHookData = RequestHookData & { - requestHeaders: Record; - httpStatus: Response['status']; - responseBody: Response['body']; - headers: Response['headers']; - responseTimestamp: number; -}; -export type ResponseHook = (data: ResponseHookData) => void; -/** - * The client used to access services of the EasyPost API. - * This client is configured to use the latest production version of the EasyPost API. - * @param {string} key The API key to use for API requests made by this client. - * @param {EasyPostClientOptions} [options] Additional options to use for the underlying HTTP client (e.g. superagent, middleware, proxy configuration). - */ -export default class EasyPostClient { - useProxy: boolean; - key: string; - timeout: number; - baseUrl: string; - agent: SuperAgentStatic; - requestMiddleware: ((request: Request) => Request) | undefined; - requestHooks: RequestHook[]; - responseHooks: ResponseHook[]; - Utils: Utils; - Address: ReturnType; - ApiKey: ReturnType; - Batch: ReturnType; - BetaRate: ReturnType; - BetaReferralCustomer: ReturnType; - Billing: ReturnType; - CarrierAccount: ReturnType; - CarrierMetadata: ReturnType; - CarrierType: ReturnType; - CustomsInfo: ReturnType; - CustomsItem: ReturnType; - EndShipper: ReturnType; - Event: ReturnType; - Insurance: ReturnType; - Order: ReturnType; - Parcel: ReturnType; - Pickup: ReturnType; - Rate: ReturnType; - ReferralCustomer: ReturnType; - Refund: ReturnType; - Report: ReturnType; - ScanForm: ReturnType; - Shipment: ReturnType; - Tracker: ReturnType; - User: ReturnType; - Webhook: ReturnType; - constructor(key: string, options?: EasyPostClientOptions); - /** - * Add a request hook function. - * @param {(config: object) => void} hook - */ - addRequestHook(hook: RequestHook): void; - /** - * Remove a request hook function. - * @param {(config: object) => void} hook - */ - removeRequestHook(hook: RequestHook): void; - /** - * Clear all request hooks. - */ - clearRequestHooks(): void; - /** - * Add a response hook function. - * @param {(config: object) => void} hook - */ - addResponseHook(hook: ResponseHook): void; - /** - * Remove a response hook function. - * @param {(config: object) => void} hook - */ - removeResponseHook(hook: ResponseHook): void; - /** - * Clear all response hooks. - */ - clearResponseHooks(): void; - /** - * Create a copy of an {@link EasyPostClient} with overridden options. - * @param {EasyPostClient} client The `EasyPostClient` instance to clone. - * @param {Object} [options] The options to override. - * @returns {EasyPostClient} A new `EasyPostClient` instance. - */ - static copyClient( - client: EasyPostClient, - options?: EasyPostClientOptions & { - apiKey?: string; - }, - ): EasyPostClient; - /** - * Build request headers to be sent with each EasyPost API request, combined (or overridden) by any additional headers - * @param {Object} [additionalHeaders] Additional headers to combine or override with the default headers. - * @returns {Object} The headers to use for the request. - */ - static _buildHeaders(additionalHeaders?: {}): { - Accept: string; - 'Content-Type': string; - 'User-Agent': string; - }; - /** - * If the path passed in is a full URI, use it; otherwise, prepend the base url from the api. - * @param {string} path - The path to build. - * @returns {string} The full path to use for the HTTP request. - */ - _buildPath(path?: string): string; - /** - * Create a value to be passed to the responseHooks, based on the requestHooks - * value and the response. - * @param {Object} baseHooksValue - the value being passed the requestHooks - * @param {Object} response - the response from the superagent request - * @returns {Object} - the value to be passed to the responseHooks - */ - _createResponseHooksValue(baseHooksValue: RequestHookData, response: Response): ResponseHookData; - /** - * Make an HTTP request. - * @param [path] - The partial path to append to the base url for the request. - * @param [method] - The HTTP method to use for the request, defaults to GET. - * @param [params] - The parameters to send with the request. - * @param [headers] - Additional headers to send with the request. - * @returns The response from the HTTP request. - * @throws {ApiError} If the request fails. - */ - _request( - path?: string, - method?: (typeof METHODS)[keyof typeof METHODS], - params?: Record, - headers?: Record, - ): Promise; - /** - * Make a GET HTTP request. - * @param path - The partial path to append to the base url for the request. - * @param [params] - The parameters to send with the request. - * @param [headers] - Additional headers to send with the request. - * @returns The response from the HTTP request. - */ - _get( - path: string, - params?: Record, - headers?: Record, - ): Promise; - /** - * Make a POST HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {any} [params] - The parameters to send with the request. - * @param {Record} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - _post( - path: string, - params?: any, - headers?: Record, - ): Promise; - /** - * Make a PUT HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {any} [params] - The parameters to send with the request. - * @param {Record} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - _put( - path: string, - params?: any, - headers?: Record, - ): Promise; - /** - * Make a PATCH HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {any} [params] - The parameters to send with the request. - * @param {Record} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - _patch( - path: string, - params?: any, - headers?: Record, - ): Promise; - /** - * Make a DELETE HTTP request. - * @param {string} path - The partial path to append to the base url for the request. - * @param {any} [params] - The parameters to send with the request. - * @param {Record} [headers] - Additional headers to send with the request. - * @returns {*} The response from the HTTP request. - */ - _delete( - path: string, - params?: any, - headers?: Record, - ): Promise; -} diff --git a/types/src/errors/api/api_error.d.ts b/types/src/errors/api/api_error.d.ts deleted file mode 100644 index 1c0e08efb..000000000 --- a/types/src/errors/api/api_error.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -import EasyPostError from '../easypost_error'; -/** - * The ApiError class is used to represent errors that occurred while communicating with the EasyPost API. - * This class should not be instantiated directly. - * @internal - * @abstract - * @extends EasyPostError - * @property {string} [message] - The message to be displayed when the error is logged. - * @property {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @property {number} [statusCode] - The HTTP status code returned by the HTTP request to the EasyPost API. - * @property {EasyPostError[]} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class ApiError extends EasyPostError { - code: string | undefined; - errors: EasyPostError[] | undefined; - message: string | undefined; - statusCode: number | undefined; - constructor({ - message, - code, - statusCode, - errors, - }?: { - message?: string; - code?: string; - statusCode?: number; - errors?: EasyPostError[]; - }); -} diff --git a/types/src/errors/api/bad_request_error.d.ts b/types/src/errors/api/bad_request_error.d.ts deleted file mode 100644 index a8a3391a5..000000000 --- a/types/src/errors/api/bad_request_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The BadRequestError class is used to represent a 400 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class BadRequestError extends ApiError {} diff --git a/types/src/errors/api/external_api_error.d.ts b/types/src/errors/api/external_api_error.d.ts deleted file mode 100644 index c3bb01401..000000000 --- a/types/src/errors/api/external_api_error.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import ApiError from './api_error'; -/** - * The ExternalApiError class is used to represent errors that occurred while communicating with an external API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - */ -export default class ExternalApiError extends ApiError {} diff --git a/types/src/errors/api/forbidden_error.d.ts b/types/src/errors/api/forbidden_error.d.ts deleted file mode 100644 index f8d9b064e..000000000 --- a/types/src/errors/api/forbidden_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The ForbiddenError class is used to represent a 403 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class ForbiddenError extends ApiError {} diff --git a/types/src/errors/api/gateway_timeout_error.d.ts b/types/src/errors/api/gateway_timeout_error.d.ts deleted file mode 100644 index 1ceec87e7..000000000 --- a/types/src/errors/api/gateway_timeout_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The GatewayTimeoutError class is used to represent a 504 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class GatewayTimeoutError extends ApiError {} diff --git a/types/src/errors/api/http_error.d.ts b/types/src/errors/api/http_error.d.ts deleted file mode 100644 index acaac4c4b..000000000 --- a/types/src/errors/api/http_error.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import ApiError from './api_error'; -/** - * The HttpError class is used to represent a generic HTTP-related error that occurred while communicating with the EasyPost API. - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class HTTPError extends ApiError {} diff --git a/types/src/errors/api/index.d.ts b/types/src/errors/api/index.d.ts deleted file mode 100644 index 6ac9ac6b3..000000000 --- a/types/src/errors/api/index.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -export * from './api_error'; -export * from './bad_request_error'; -export * from './external_api_error'; -export * from './forbidden_error'; -export * from './gateway_timeout_error'; -export * from './http_error'; -export * from './index'; -export * from './internal_server_error'; -export * from './invalid_request_error'; -export * from './method_not_allowed_error'; -export * from './not_found_error'; -export * from './payment_error'; -export * from './rate_limit_error'; -export * from './redirect_error'; -export * from './service_unavailable_error'; -export * from './timeout_error'; -export * from './unauthorized_error'; -export * from './unknown_api_error'; diff --git a/types/src/errors/api/internal_server_error.d.ts b/types/src/errors/api/internal_server_error.d.ts deleted file mode 100644 index 946d7e0fa..000000000 --- a/types/src/errors/api/internal_server_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The InternalServerError class is used to represent a 500 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class InternalServerError extends ApiError {} diff --git a/types/src/errors/api/invalid_request_error.d.ts b/types/src/errors/api/invalid_request_error.d.ts deleted file mode 100644 index 0e87d346d..000000000 --- a/types/src/errors/api/invalid_request_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The InvalidRequestError class is used to represent a 422 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class InvalidRequestError extends ApiError {} diff --git a/types/src/errors/api/method_not_allowed_error.d.ts b/types/src/errors/api/method_not_allowed_error.d.ts deleted file mode 100644 index fd29b3cbc..000000000 --- a/types/src/errors/api/method_not_allowed_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The MethodNotAllowedError class is used to represent a 405 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class MethodNotAllowedError extends ApiError {} diff --git a/types/src/errors/api/not_found_error.d.ts b/types/src/errors/api/not_found_error.d.ts deleted file mode 100644 index 5e2a4262b..000000000 --- a/types/src/errors/api/not_found_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The NotFoundError class is used to represent a 404 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class NotFoundError extends ApiError {} diff --git a/types/src/errors/api/payment_error.d.ts b/types/src/errors/api/payment_error.d.ts deleted file mode 100644 index 081039ad8..000000000 --- a/types/src/errors/api/payment_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The PaymentError class is used to represent a 402 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class PaymentError extends ApiError {} diff --git a/types/src/errors/api/rate_limit_error.d.ts b/types/src/errors/api/rate_limit_error.d.ts deleted file mode 100644 index 3ae7f08f9..000000000 --- a/types/src/errors/api/rate_limit_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The RateLimitError class is used to represent a 429 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class RateLimitError extends ApiError {} diff --git a/types/src/errors/api/redirect_error.d.ts b/types/src/errors/api/redirect_error.d.ts deleted file mode 100644 index 004604f69..000000000 --- a/types/src/errors/api/redirect_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The RedirectError class is used to represent a 3xx error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class RedirectError extends ApiError {} diff --git a/types/src/errors/api/service_unavailable_error.d.ts b/types/src/errors/api/service_unavailable_error.d.ts deleted file mode 100644 index e667d5952..000000000 --- a/types/src/errors/api/service_unavailable_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The ServiceUnavailableError class is used to represent a 503 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class ServiceUnavailableError extends ApiError {} diff --git a/types/src/errors/api/timeout_error.d.ts b/types/src/errors/api/timeout_error.d.ts deleted file mode 100644 index 5775f87ed..000000000 --- a/types/src/errors/api/timeout_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The TimeoutError class is used to represent a 408 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class TimeoutError extends ApiError {} diff --git a/types/src/errors/api/unauthorized_error.d.ts b/types/src/errors/api/unauthorized_error.d.ts deleted file mode 100644 index bad09b743..000000000 --- a/types/src/errors/api/unauthorized_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The UnauthorizedError class is used to represent a 401 error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class UnauthorizedError extends ApiError {} diff --git a/types/src/errors/api/unknown_api_error.d.ts b/types/src/errors/api/unknown_api_error.d.ts deleted file mode 100644 index 8ddc33bbd..000000000 --- a/types/src/errors/api/unknown_api_error.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApiError from './api_error'; -/** - * The UnknownApiError class is used to represent a generic, unexpected error that occurred while communicating with the EasyPost API. - * @sealed - * @extends ApiError - * @param {string} [message] - The message to be displayed when the error is logged. - * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. - * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. - * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. - */ -export default class UnknownApiError extends ApiError {} diff --git a/types/src/errors/easypost_error.d.ts b/types/src/errors/easypost_error.d.ts deleted file mode 100644 index db97aca67..000000000 --- a/types/src/errors/easypost_error.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * The EasyPostError class is the base class for all errors that occur in the EasyPost Node.js client library. - * This class should not be instantiated directly. - * @internal - * @abstract - * @extends Error - * @param {string} [message] - The message to be displayed when the error is logged. - */ -export default class EasyPostError extends Error { - message: string | undefined; - constructor({ message }?: { message?: string }); -} diff --git a/types/src/errors/error_handler.d.ts b/types/src/errors/error_handler.d.ts deleted file mode 100644 index b5aed46ce..000000000 --- a/types/src/errors/error_handler.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -import EasyPostError from './easypost_error'; -export type RawAPIError = { - statusCode: number; - body: { - error: { - code: string; - message: JSONParsableError; - errors: EasyPostError[]; - }; - }; -}; -type JSONParsableError = string | number | JSONObject | JSONArray; -type JSONObject = { - [key: string]: JSONParsableError; -}; -type JSONArray = JSONParsableError[]; -export default class ErrorHandler { - /** - * Recursively traverses a JSON object or array and extracts error messages - * as strings. Adds the extracted messages to the specified messagesList array. - * - * @param {JSONParsableError} errorMessage - The JSON object or array to traverse. - */ - static traverseJsonElement(errorMessage: JSONParsableError): string[]; - static isAPIError(error: any): error is RawAPIError; - /** - * Calculate and generate the appropriate {@link ApiError} based on a received HTTP response error. - * @param {*} error - The errored HTTP response. - * @returns {ApiError} The `ApiError`-based error corresponding to the HTTP status code. - */ - static handleApiError(error: RawAPIError): EasyPostError; -} -export {}; diff --git a/types/src/errors/general/end_of_pagination_error.d.ts b/types/src/errors/general/end_of_pagination_error.d.ts deleted file mode 100644 index 1ae894a77..000000000 --- a/types/src/errors/general/end_of_pagination_error.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import EasyPostError from '../easypost_error'; -/** - * The EndOfPaginationError class is used to represent an error that no more page can be retrieved - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -export default class EndOfPaginationError extends EasyPostError { - constructor(); -} diff --git a/types/src/errors/general/filtering_error.d.ts b/types/src/errors/general/filtering_error.d.ts deleted file mode 100644 index 3f96a1925..000000000 --- a/types/src/errors/general/filtering_error.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import EasyPostError from '../easypost_error'; -/** - * The FilteringError class is used to represent an error that occurred while filtering a list (e.g. a list of rates). - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -export default class FilteringError extends EasyPostError {} diff --git a/types/src/errors/general/index.d.ts b/types/src/errors/general/index.d.ts deleted file mode 100644 index 04c30fdb2..000000000 --- a/types/src/errors/general/index.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from './end_of_pagination_error'; -export * from './filtering_error'; -export * from './invalid_object_error'; -export * from './invalid_parameter_error'; -export * from './missing_parameter_error'; -export * from './signature_verification_error'; diff --git a/types/src/errors/general/invalid_object_error.d.ts b/types/src/errors/general/invalid_object_error.d.ts deleted file mode 100644 index be11f59bd..000000000 --- a/types/src/errors/general/invalid_object_error.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import EasyPostError from '../easypost_error'; -/** - * The InvalidObjectError class is used to represent an error due to an invalid object (e.g. missing an expected property). - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -export default class InvalidObjectError extends EasyPostError {} diff --git a/types/src/errors/general/invalid_parameter_error.d.ts b/types/src/errors/general/invalid_parameter_error.d.ts deleted file mode 100644 index 9931b6a18..000000000 --- a/types/src/errors/general/invalid_parameter_error.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import EasyPostError from '../easypost_error'; -/** - * The InvalidParameterError class is used to represent an error due to an invalid function parameter. - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -export default class InvalidParameterError extends EasyPostError {} diff --git a/types/src/errors/general/missing_parameter_error.d.ts b/types/src/errors/general/missing_parameter_error.d.ts deleted file mode 100644 index 858616524..000000000 --- a/types/src/errors/general/missing_parameter_error.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import EasyPostError from '../easypost_error'; -/** - * The MissingParameterError class is used to represent an error due to a missing expected function parameter. - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -export default class MissingParameterError extends EasyPostError {} diff --git a/types/src/errors/general/signature_verification_error.d.ts b/types/src/errors/general/signature_verification_error.d.ts deleted file mode 100644 index 0d73da0d7..000000000 --- a/types/src/errors/general/signature_verification_error.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import EasyPostError from '../easypost_error'; -/** - * The SignatureVerificationError class is used to represent an error due to a failed signature verification (e.g. a webhook HMAC signature). - * @sealed - * @extends EasyPostError - * @param {string} [message] - The message to be displayed when the error is logged. - */ -export default class SignatureVerificationError extends EasyPostError {} diff --git a/types/src/errors/index.d.ts b/types/src/errors/index.d.ts deleted file mode 100644 index a8d312a93..000000000 --- a/types/src/errors/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './api'; -export * from './general'; -export * from './easypost_error'; -export * from './error_handler'; diff --git a/types/src/index.d.ts b/types/src/index.d.ts deleted file mode 100644 index 310d378d1..000000000 --- a/types/src/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import EasyPost from './easypost'; -export default EasyPost; diff --git a/types/src/services/address_service/Address.d.ts b/types/src/services/address_service/Address.d.ts deleted file mode 100644 index 3de9d7439..000000000 --- a/types/src/services/address_service/Address.d.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { IVerifications } from './Verifications'; -import { IObjectWithId } from '../../utils/types'; -/** - * Address objects are used to represent people, places, and organizations in a number of contexts. - * For example, a Shipment requires a to_address and from_address to accurately calculate rates and generate postage. - * - * Additionally, EasyPost offers several verification tools that can be used to detect deliverability issues, correct minor errors in spelling/formatting, and determine if an Address is residential or not (which has a significant effect on Shipment rating for many carriers). - * - * @see https://www.easypost.com/docs/api/node#address-object - */ -export type IAddress = IObjectWithId<'Address'> & { - /** - * First line of the address - */ - street1?: string | null; - /** - * Second line of the address - */ - street2?: string | null; - /** - * City the address is located in - */ - city?: string | null; - /** - * State or province the address is located in - */ - state?: string | null; - /** - * ZIP or postal code the address is located in - */ - zip: string; - /** - * ISO 3166 country code for the country the address is located in - */ - country: string; - /** - * Whether or not this address would be considered residential - */ - residential?: boolean | null; - /** - * The specific designation for the address (only relevant if the address is a carrier facility) - */ - carrier_facility?: string | null; - /** - * Name of the person. Both name and company can be included - */ - name?: string | null; - /** - * Name of the organization. Both name and company can be included - */ - company?: string | null; - /** - * Phone number to reach the person or organization - */ - phone?: string | null; - /** - * Email to reach the person or organization - */ - email?: string | null; - /** - * Federal tax identifier of the person or organization - */ - federal_tax_id?: string | null; - /** - * State tax identifier of the person or organization - */ - state_tax_id?: string | null; - /** - * The result of any verifications requested - */ - verifications: IVerifications; -}; diff --git a/types/src/services/address_service/AddressCreateParameters.d.ts b/types/src/services/address_service/AddressCreateParameters.d.ts deleted file mode 100644 index 67b6a50ff..000000000 --- a/types/src/services/address_service/AddressCreateParameters.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { IAddress } from './Address'; -/** - * @see https://www.easypost.com/docs/api/node#create-and-verify-addresses - */ -export type IAddressCreateParameters = Omit< - IAddress, - ParametersToOmitOnCreate | 'verifications' -> & { - /** - * The verifications to perform when creating. - * verify_strict takes precedence. - * true will perform both delivery and zip code. - */ - verify?: boolean | null; - /** - * The verifications to perform when creating. - * The failure of any of these verifications causes the whole request to fail. - * true will perform both delivery and zip code. - */ - verify_strict?: boolean | null; -}; diff --git a/types/src/services/address_service/AddressListParameters.d.ts b/types/src/services/address_service/AddressListParameters.d.ts deleted file mode 100644 index cb9b95716..000000000 --- a/types/src/services/address_service/AddressListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api#retrieve-a-list-of-addresses - */ -export type IAddressListParameters = IAllMethodParameters; diff --git a/types/src/services/address_service/Verification.d.ts b/types/src/services/address_service/Verification.d.ts deleted file mode 100644 index 6e547eb54..000000000 --- a/types/src/services/address_service/Verification.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { IFieldError } from '../../utils/errors'; -import { IVerificationDetails } from './VerificationDetails'; -/** - * @see https://www.easypost.com/docs/api/node#verification-object - */ -export type IVerification = { - /** - * The success of the verification - */ - success: boolean; - /** - * All errors that caused the verification to fail - */ - errors: IFieldError[]; - /** - * Extra data related to the verification - */ - details: IVerificationDetails; -}; diff --git a/types/src/services/address_service/VerificationDetails.d.ts b/types/src/services/address_service/VerificationDetails.d.ts deleted file mode 100644 index 6ce352800..000000000 --- a/types/src/services/address_service/VerificationDetails.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * @see https://www.easypost.com/docs/api/node#verification_details-object - */ -export type IVerificationDetails = { - /** - * The latitude of an Address. - */ - latitude: number; - /** - * The longitude of an Address. - */ - longitude: number; - /** - * The time zone the address is located in, IE: America/Los_Angeles - */ - time_zone: string; -}; diff --git a/types/src/services/address_service/Verifications.d.ts b/types/src/services/address_service/Verifications.d.ts deleted file mode 100644 index 85ea98d5b..000000000 --- a/types/src/services/address_service/Verifications.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { IVerification } from './Verification'; -/** - * @see https://www.easypost.com/docs/api/node#verifications-object - */ -export type IVerifications = { - /** - * Only applicable to US addresses - checks and sets the ZIP+4 - */ - zip4: IVerification; - /** - * Checks that the address is deliverable and makes minor corrections to spelling/format. US addresses will also have their "residential" status checked and set. - */ - delivery: IVerification; -}; -declare const _default: {}; -export default _default; diff --git a/types/src/services/address_service/index.d.ts b/types/src/services/address_service/index.d.ts deleted file mode 100644 index ab557c1c7..000000000 --- a/types/src/services/address_service/index.d.ts +++ /dev/null @@ -1,105 +0,0 @@ -import EasyPost from '../..'; -import { IAddress } from './Address'; -import { IAddressCreateParameters } from './AddressCreateParameters'; -import { IAddressListParameters } from './AddressListParameters'; -export * from './Address'; -export * from './AddressCreateParameters'; -export * from './Verification'; -export * from './VerificationDetails'; -export * from './Verifications'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create an {@link Address address}. - * See {@link https://www.easypost.com/docs/api/node#create-an-address EasyPost API Documentation} for more information. - * @param params - Parameters for the address to be created. - * @returns - The created address. - */ - create( - params: IAddressCreateParameters, - ): Promise>; - /** - * Create and verify an {@link Address address} in a single request. - * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. - * @param params - Parameters for the address to be created. - * @returns - The created and verified address. - */ - createAndVerify(params: IAddressCreateParameters): Promise; - /** - * Retrieve all {@link Address addresses} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-addresses EasyPost API Documentation} for more information. - * @param params - Parameters to filter the list of addresses. - * @returns - An object containing a list of {@link Address addresses} and pagination information. - */ - all(params?: IAddressListParameters): Promise< - { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of Address collection. - * @param addresses An object containing a list of {@link Address addresses} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - addresses: { - addresses: IAddress[]; - }, - pageSize?: number | null, - ): Promise< - { - addresses: IAddress[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve an {@link Address address} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-address EasyPost API Documentation} for more information. - * @param id - The ID of the address to retrieve. - * @returns - The retrieved address. - */ - retrieve(id: string): Promise>; - /** - * Verify an {@link Address address} by its ID. - * See {@link https://www.easypost.com/docs/api/node#create-and-verify-addresses EasyPost API Documentation} for more information. - * @param id - The ID of the address to verify. - * @returns - The verified address. - */ - verifyAddress(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/api_key_service/ApiKey.d.ts b/types/src/services/api_key_service/ApiKey.d.ts deleted file mode 100644 index c11cf642e..000000000 --- a/types/src/services/api_key_service/ApiKey.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { IObjectWithId } from '../../utils/types'; -export type IApiKey = IObjectWithId<'ApiKey'> & { - /** - * The actual key value to use for authentication - */ - key: string; - /** - * When the API key was created - */ - created_at: string; - /** - * Whether the API key is active or not - */ - active: boolean; -}; -export type UserAPIKeys = { - id: string; - keys: IApiKey[]; - children: UserAPIKeys[]; -}; diff --git a/types/src/services/api_key_service/index.d.ts b/types/src/services/api_key_service/index.d.ts deleted file mode 100644 index 972a59b27..000000000 --- a/types/src/services/api_key_service/index.d.ts +++ /dev/null @@ -1,71 +0,0 @@ -import EasyPost from '../..'; -import { IApiKey } from './ApiKey'; -export * from './ApiKey'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Retrieve all {@link ApiKey API keys} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. - * @returns - An object containing the API keys associated with the current authenticated user and its child users. - */ - all(params?: {}): Promise< - import('../../utils/types').IBaseObject<'ApiKey'> & { - id: string; - mode: 'test' | 'production'; - object: 'ApiKey'; - } & { - key: string; - created_at: string; - active: boolean; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve API Keys for a specified {@link User user}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. - * @param id - The ID of the user to retrieve keys for. - * @returns - List of associated API Keys. - * @throws {FilteringError} If user or API Keys are not found. - */ - retrieveApiKeysForUser(id: string): Promise; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject - /** - * Retrieve API Keys for a specified {@link User user}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-api-key EasyPost API Documentation} for more information. - * @param id - The ID of the user to retrieve keys for. - * @returns - List of associated API Keys. - * @throws {FilteringError} If user or API Keys are not found. - */; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/base_service.d.ts b/types/src/services/base_service.d.ts deleted file mode 100644 index 51048730a..000000000 --- a/types/src/services/base_service.d.ts +++ /dev/null @@ -1,71 +0,0 @@ -import EasyPostClient from '../easypost'; -export type EasyPostObject = A & { - _params: any; -}; -declare const _default: (easypostClient: EasyPostClient) => { - new (): {}; - /** - * Converts a JSON response and all its nested elements to associated {@link EasyPostObject}-based class instances. - * @internal - * @param {*} response The JSON response to convert (usually a `Map` or `Array`). - * @param {*} params The parameters passed when fetching the response - * @returns {*} An {@link EasyPostObject}-based class instance or an `Array` of {@link EasyPostObject}-based class instances. - */ - _convertToEasyPostObject(response: A, params?: any): EasyPostObject; - /** - * Creates an EasyPost Object via the API. - * @internal - * @param url The URL to send the API request to. - * @param params The parameters to send with the API request. - * @returns The created {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - _create(url: string, params: object): Promise>; - /** - * Retrieve a list of records from the API. - * @internal - * @param url The URL to send the API request to. - * @param params The parameters to send with the API request. - * @returns The retrieved {@link EasyPostObject}-based class instance(s), or a `Promise` that rejects with an error. - */ - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a record from the API. - * @internal - * @param url The URL to send the API request to. - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - _retrieve(url: string): Promise>; - /** - * Retrieve the next page of specific collection of object - * @internal - * @param url The URL to send the API request to. - * @param collection The collection of a specific object. - * @param pageSize The number of records to return on each page. - * @param optionalParams The optional param for additional value in the query string. - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - * TODO: Implement this function in EndShippers and Batches once the API supports them properly. - */ - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/batch_service/Batch.d.ts b/types/src/services/batch_service/Batch.d.ts deleted file mode 100644 index cdd5ee354..000000000 --- a/types/src/services/batch_service/Batch.d.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { IPickup } from '../pickup_service/Pickup'; -import { IScanForm } from '../scan_form_service'; -import { IBatchShipment } from './BatchShipment'; -import { TBatchState } from './BatchState'; -import { TBatchStatuses } from './BatchStatuses'; -/** - * The Batch object allows you to perform operations on multiple Shipments at once. - * This includes scheduling a Pickup, creating a ScanForm and consolidating labels. - * Operations performed on Batches are asynchronous and take advantage of our webhook infrastructure. - * - * @see https://www.easypost.com/docs/api/node#batch-object - */ -export type IBatch = IObjectWithId<'Batch'> & - IDatedObject & { - /** - * An optional field that may be used in place of ID in some API endpoints - */ - reference?: string | null; - /** - * The overall state. Possible values are "creating", "creation_failed", "created", "purchasing", "purchase_failed", "purchased", "label_generating", and "label_generated" - */ - state: TBatchState; - /** - * The number of shipments added - */ - num_shipments: number; - /** - * An array of batch shipments - */ - shipments: IBatchShipment[]; - /** - * A map of BatchShipment statuses to the count of BatchShipments with that status. Valid statuses are "postage_purchased", "postage_purchase_failed", "queued_for_purchase", and "creation_failed" - */ - status: TBatchStatuses; - /** - * The label image url - */ - label_url?: string | null; - /** - * The created ScanForm - */ - scan_form: IScanForm; - /** - * The created Pickup - */ - pickup: IPickup; - }; diff --git a/types/src/services/batch_service/BatchCreateParameters.d.ts b/types/src/services/batch_service/BatchCreateParameters.d.ts deleted file mode 100644 index b778883b5..000000000 --- a/types/src/services/batch_service/BatchCreateParameters.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -export type IBatchCreateParameters = { - shipments?: ( - | { - id: string; - } - | string - )[]; -}; diff --git a/types/src/services/batch_service/BatchListParameters.d.ts b/types/src/services/batch_service/BatchListParameters.d.ts deleted file mode 100644 index 38f453d9f..000000000 --- a/types/src/services/batch_service/BatchListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#list-all-batches - */ -export type IBatchListParameters = IAllMethodParameters; diff --git a/types/src/services/batch_service/BatchShipment.d.ts b/types/src/services/batch_service/BatchShipment.d.ts deleted file mode 100644 index 48c669792..000000000 --- a/types/src/services/batch_service/BatchShipment.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { TBatchStatus } from './BatchStatus'; -/** - * @see https://www.easypost.com/docs/api/node#batch-shipment-object - */ -export type IBatchShipment = { - /** - * The id of the Shipment. Unique, begins with "shp_" - */ - id: string; - /** - * An optional field that may be used in place of ID in some API endpoints - */ - reference?: string | null; - /** - * The current status. Possible values are "postage_purchased", "postage_purchase_failed", "queued_for_purchase", "creation_failed", and "created" - */ - batch_status: TBatchStatus; - /** - * A human readable message for any errors that occurred during the Batch's life cycle - */ - batch_message: string; -}; diff --git a/types/src/services/batch_service/BatchState.d.ts b/types/src/services/batch_service/BatchState.d.ts deleted file mode 100644 index 41fa51e7a..000000000 --- a/types/src/services/batch_service/BatchState.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -export type TBatchState = - | 'creating' - | 'creation_failed' - | 'created' - | 'purchasing' - | 'purchase_failed' - | 'purchased' - | 'label_generating' - | 'label_generated'; diff --git a/types/src/services/batch_service/BatchStatus.d.ts b/types/src/services/batch_service/BatchStatus.d.ts deleted file mode 100644 index c85d419dc..000000000 --- a/types/src/services/batch_service/BatchStatus.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export type TBatchStatus = - | 'postage_purchased' - | 'postage_purchase_failed' - | 'queued_for_purchase' - | 'creation_failed' - | 'created'; diff --git a/types/src/services/batch_service/BatchStatuses.d.ts b/types/src/services/batch_service/BatchStatuses.d.ts deleted file mode 100644 index 7795213f7..000000000 --- a/types/src/services/batch_service/BatchStatuses.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { TBatchStatus } from './BatchStatus'; -export type TBatchStatuses = { - [key in TBatchStatus]: number; -}; diff --git a/types/src/services/batch_service/index.d.ts b/types/src/services/batch_service/index.d.ts deleted file mode 100644 index b815b9db2..000000000 --- a/types/src/services/batch_service/index.d.ts +++ /dev/null @@ -1,132 +0,0 @@ -import EasyPost from '../..'; -import { IBatch } from './Batch'; -import { IBatchCreateParameters } from './BatchCreateParameters'; -import { IBatchListParameters } from './BatchListParameters'; -export * from './Batch'; -export * from './BatchCreateParameters'; -export * from './BatchListParameters'; -export * from './BatchShipment'; -export * from './BatchState'; -export * from './BatchStatus'; -export * from './BatchStatuses'; -export declare const DEFAULT_LABEL_FORMAT = 'pdf'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#create-a-batch EasyPost API Documentation} for more information. - * @param params - Parameters for the batch to be created. - * @returns - The created batch. - */ - create(params: IBatchCreateParameters): Promise>; - /** - * Add {@link Shipment shipments} to a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#add-shipments-to-a-batch EasyPost API Documentation} for more information. - * @param id - The id of the batch to add shipments to. - * @param shipmentIds - The ids of the shipments to add to the batch. - * @returns - The updated batch. - */ - addShipments( - id: string, - shipmentIds: string[], - ): Promise>; - /** - * Removes {@link Shipment shipments} from a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#remove-shipments-from-a-batch EasyPost API Documentation} for more information. - * @param id - The id of the batch to remove shipments from. - * @param shipmentIds - The ids of the shipments to remove from the batch. - * @returns - The updated batch. - */ - removeShipments( - id: string, - shipmentIds: string[], - ): Promise>; - /** - * Generate a label for a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#batch-labels EasyPost API Documentation} for more information. - * @param id - The id of the batch to generate a label for. - * @param fileFormat - The format of the label to generate. Defaults to 'pdf'. - * @returns - The updated batch. - */ - generateLabel( - id: string, - fileFormat?: string, - ): Promise>; - /** - * Create a {@link ScanForm scan form} for a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#manifesting-scan-form EasyPost API Documentation} for more information. - * @param id - The id of the batch to create a scan form for. - * @returns - The updated batch. - */ - createScanForm(id: string): Promise>; - /** - * Purchase a {@link Batch batch}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-batch EasyPost API Documentation} for more information. - * @param id - The id of the batch to purchase. - * @returns - The purchased batch. - */ - buy(id: string): Promise>; - /** - * Retrieve all {@link Batch batches} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#list-all-batches EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of batches. - * @returns - An object containing a list of {@link Batch batches} and pagination information. - */ - all(params?: IBatchListParameters): Promise< - import('../../utils/types').IBaseObject<'Batch'> & { - id: string; - mode: 'test' | 'production'; - object: 'Batch'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - state: import('./BatchState').TBatchState; - num_shipments: number; - shipments: import('./BatchShipment').IBatchShipment[]; - status: import('./BatchStatuses').TBatchStatuses; - label_url?: string | null | undefined; - scan_form: import('..').IScanForm; - pickup: import('../pickup_service/Pickup').IPickup; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link Batch batch} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-batch EasyPost API Documentation} for more information. - * @param id - The ID of the batch to retrieve. - * @returns - The retrieved batch. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/beta_rate_service/index.d.ts b/types/src/services/beta_rate_service/index.d.ts deleted file mode 100644 index bc4eeca1e..000000000 --- a/types/src/services/beta_rate_service/index.d.ts +++ /dev/null @@ -1,44 +0,0 @@ -import EasyPost from '../..'; -import { IRate } from '../rate_service/Rate'; -/** - * @extends baseService - */ -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Retrieve a list of stateless {@link Rate rates} based on the provided parameters. - * @param params - Map of parameters for the API call - * @returns - List of stateless rates - */ - retrieveStatelessRates(params: any): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/beta_referral_customer_service/index.d.ts b/types/src/services/beta_referral_customer_service/index.d.ts deleted file mode 100644 index dd8a712ae..000000000 --- a/types/src/services/beta_referral_customer_service/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -import EasyPost from '../..'; -import { IPaymentMethod } from '../billing_service'; -import { IRefund } from '../refund_service'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Add an existing Stripe payment method to a {@link User referral customer's} account. - * @param stripeCustomerId - The Stripe account's ID. - * @param paymentMethodReference - Reference of Stripe payment method. - * @param [priority] - Which priority to set the payment method to ('primary' or 'secondary'). - * @returns - A JSON object representing the payment method. - */ - addPaymentMethod( - stripeCustomerId: string, - paymentMethodReference: string, - priority?: 'primary' | 'secondary', - ): Promise; - /** - * Refund by amount for a recent payment. - * @param refundAmount - Amount to be refunded by cents. - * @returns - A JSON object representing the refund. - */ - refundByAmount(refundAmount: number): Promise; - /** - * Refund a payment by a payment log ID. - * @param paymentLogId - ID of the payment log. - * @returns - Returns BetaPaymentRefund object. - */ - refundByPaymentLog(paymentLogId: string): Promise; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/billing_service/PaymentMethod.d.ts b/types/src/services/billing_service/PaymentMethod.d.ts deleted file mode 100644 index 5680f3db0..000000000 --- a/types/src/services/billing_service/PaymentMethod.d.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { IObjectWithId } from '../../utils/types'; -/** - * The Payment method object can be either credit card or bank account. - * - * TODO: Add the link to the API doc once its updated - */ -export type IPaymentMethod = IObjectWithId<'PaymentMethod'> & { - /** - * Country of the bank account - */ - country: string; - /** - * Name of the bank - */ - bank_name: string; - /** - * Brand of the credit card - */ - brand: string; - /** - * Whether the payment method(credit card or bank account) is disabled or not - */ - disabled_at: string; - /** - * Expiration month of the credit card - */ - exp_month: number; - /** - * Expiration year of the credit card - */ - exp_year: number; - /** - * Last four of the credit card - */ - last4: string; - /** - * Name of the credit card - */ - name: string; - /** - * Whether the bank account is verified or not - */ - verified: boolean; -}; diff --git a/types/src/services/billing_service/index.d.ts b/types/src/services/billing_service/index.d.ts deleted file mode 100644 index dc097c109..000000000 --- a/types/src/services/billing_service/index.d.ts +++ /dev/null @@ -1,63 +0,0 @@ -import EasyPost from '../..'; -export * from './PaymentMethod'; -export type Priority = 'primary' | 'secondary'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Fund your EasyPost wallet by charging your primary or secondary payment method on file. - * See {@link https://www.easypost.com/docs/api/node#add-funds-to-your-wallet-one-time-charge EasyPost API Documentation} for more information. - * @param amount - The amount to charge to your payment method. - * @param priority - The priority of the payment method to charge. Can be either 'primary' or 'secondary'. - */ - fundWallet(amount: string, priority?: Priority): Promise; - /** - * Delete a payment method from the current authenticated user's account. - * See {@link https://www.easypost.com/docs/api/node#delete-a-payment-method EasyPost API Documentation} for more information. - * @param priority - The priority of the payment method to delete. Can be either 'primary' or 'secondary'. - */ - deletePaymentMethod(priority: Priority): Promise; - /** - * Retrieve all payment methods associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-payment-methods EasyPost API Documentation} for more information. - * @returns {Object} - An object containing the payment methods associated with the current authenticated user. - */ - retrievePaymentMethods(): Promise; - /** - * Get payment info (type of the payment method and ID of the payment method) - * This function is intended for internal use only, please avoid using this function - * @private - * @param {String} priority - The priority of the payment method to retrieve. Can be either 'primary' or 'secondary'. - * @returns {string[]} - An array of two strings, the first being the endpoint of the payment method and the second being the ID of the payment method. - */ - _getPaymentInfo(priority: Priority): Promise; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/carrier_account_service/CarrierAccount.d.ts b/types/src/services/carrier_account_service/CarrierAccount.d.ts deleted file mode 100644 index 18d31c329..000000000 --- a/types/src/services/carrier_account_service/CarrierAccount.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { ICarrierAccountFields } from './CarrierAccountFields'; -/** - * A CarrierAccount encapsulates your credentials with the carrier. - * The CarrierAccount object provides CRUD operations for all CarrierAccounts. - * - * Each EasyPost account is automatically provided a USPS account managed by EasyPost. - * - * Other operations, such as Shipment creation, can reference CarrierAccounts to reduce the scope of data returned. - * For instance, you may have multiple warehouses that need to use distinct FedEx SmartPost credentials to request the correct rates. - * Rate objects will include a `carrier_account_id` field which can be used to determine the account used for rating. - * - * @see https://www.easypost.com/docs/api/node#carrier-account-object - */ -export type ICarrierAccount = IObjectWithId<'CarrierAccount'> & - IDatedObject & { - /** - * The name of the carrier type. - */ - type: string; - /** - * Contains "credentials" and/or "test_credentials", or may be empty - */ - fields: ICarrierAccountFields; - /** - * If clone is true, only the reference and description are possible to update - */ - clone?: boolean | null; - /** - * An optional, user-readable field to help distinguish accounts - */ - description?: string | null; - /** - * An optional field that may be used in place of carrier_account_id in other API endpoints - */ - reference?: string | null; - /** - * The name used when displaying a readable value for the type of the account - */ - readable: string; - /** - * Unlike the "credentials" object contained in "fields", this nullable object contains just raw credential pairs for client library consumption - */ - credentials?: object | null; - /** - * Unlike the "test_credentials" object contained in "fields", this nullable object contains just raw test_credential pairs for client library consumption - */ - test_credentials?: object | null; - /** - * Billing type of the carrier account - */ - billing_type: string | null; - }; diff --git a/types/src/services/carrier_account_service/CarrierAccountCreateParameters.d.ts b/types/src/services/carrier_account_service/CarrierAccountCreateParameters.d.ts deleted file mode 100644 index c92ebd574..000000000 --- a/types/src/services/carrier_account_service/CarrierAccountCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { ICarrierAccount } from './CarrierAccount'; -export type ICarrierAccountCreateParameters = Omit; diff --git a/types/src/services/carrier_account_service/CarrierAccountField.d.ts b/types/src/services/carrier_account_service/CarrierAccountField.d.ts deleted file mode 100644 index 3d13bf156..000000000 --- a/types/src/services/carrier_account_service/CarrierAccountField.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @see https://www.easypost.com/docs/api/node#carrier-account-field-object - */ -export type ICarrierAccountField = { - /** - * Each key in the sub-objects of a CarrierAccount's fields is the name of a settable field - */ - key: string; - /** - * The visibility value is used to control form field types, and is discussed in the CarrierType section - */ - visibility: string; - /** - * The label value is used in form rendering to display a more precise field name - */ - label: string; - /** - * Checkbox fields use "0" and "1" as False and True, all other field types present plaintext, partly-masked, or masked credential data for reference - */ - value: string; -}; diff --git a/types/src/services/carrier_account_service/CarrierAccountFields.d.ts b/types/src/services/carrier_account_service/CarrierAccountFields.d.ts deleted file mode 100644 index 4371a867f..000000000 --- a/types/src/services/carrier_account_service/CarrierAccountFields.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ICarrierAccountField } from './CarrierAccountField'; -/** - * @see https://www.easypost.com/docs/api/node#carrier-account-fields-object - */ -export type ICarrierAccountFields = { - /** - * Credentials used in the production environment. - */ - credentials: ICarrierAccountField; - /** - * Credentials used in the test environment. - */ - test_credentials: ICarrierAccountField; - /** - * For USPS this designates that no credentials are required. - */ - auto_link: boolean; - /** - * When present, a separate authentication process will be required through the UI to link this account type. - */ - custom_workflow: boolean; -}; diff --git a/types/src/services/carrier_account_service/index.d.ts b/types/src/services/carrier_account_service/index.d.ts deleted file mode 100644 index 8415d712a..000000000 --- a/types/src/services/carrier_account_service/index.d.ts +++ /dev/null @@ -1,116 +0,0 @@ -import EasyPost from '../..'; -import { ICarrierAccount } from './CarrierAccount'; -import { ICarrierAccountCreateParameters } from './CarrierAccountCreateParameters'; -export * from './CarrierAccount'; -export * from './CarrierAccountCreateParameters'; -export * from './CarrierAccountField'; -export * from './CarrierAccountFields'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link CarrierAccount carrier account}. - * See {@link https://www.easypost.com/docs/api/node#create-a-carrier-account EasyPost API Documentation} for more information. - * @param params - Parameters for the carrier account to be created. - * @returns - The created carrier account. - */ - create( - params: ICarrierAccountCreateParameters, - ): Promise>; - /** - * Update a {@link CarrierAccount carrier account}. - * See {@link https://www.easypost.com/docs/api/node#update-a-carrieraccount EasyPost API Documentation} for more information. - * @param id - The id of the carrier account to be updated. - * @param params - Parameters for the carrier account to be updated. - * @returns - The updated carrier account. - */ - update( - id: string, - params: Partial, - ): Promise>; - /** - * Delete a {@link CarrierAccount carrier account}. - * See {@link https://www.easypost.com/docs/api/node#delete-a-carrier-account EasyPost API Documentation} for more information. - * @param id - The id of the carrier account to be deleted. - * @returns - A promise that resolves when the carrier account has been deleted. - */ - delete(id: string): Promise; - /** - * Returns the correct carrier_account endpoint when creating a record based on the type. - * @private - * @param {string} carrierAccountType - The type of carrier account to be created. - * @returns {string} - The endpoint to be used for the carrier account creation request. - */ - _selectCarrierAccountCreationEndpoint( - carrierAccountType: string, - ): 'carrier_accounts/register' | 'carrier_accounts'; - /** - * Retrieve all {@link CarrierAccount carrier accounts} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#list-all-carrier-accounts EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of carrier accounts. - * @returns - An object containing a list of {@link CarrierAccount carrier accounts} and pagination information. - */ - all(params?: {}): Promise< - import('../../utils/types').IBaseObject<'CarrierAccount'> & { - id: string; - mode: 'test' | 'production'; - object: 'CarrierAccount'; - } & import('../../utils/types').IDatedObject & { - type: string; - fields: import('./CarrierAccountFields').ICarrierAccountFields; - clone?: boolean | null | undefined; - description?: string | null | undefined; - reference?: string | null | undefined; - readable: string; - credentials?: object | null | undefined; - test_credentials?: object | null | undefined; - billing_type: string | null; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link CarrierAccount carrier account} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-carrieraccount EasyPost API Documentation} for more information. - * @param id - The ID of the carrier account to retrieve. - * @returns - The retrieved carrier account. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean - /** - * Retrieve all {@link CarrierAccount carrier accounts} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#list-all-carrier-accounts EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of carrier accounts. - * @returns - An object containing a list of {@link CarrierAccount carrier accounts} and pagination information. - */; - } - >; -}; -export default _default; diff --git a/types/src/services/carrier_metadata_service/CarrierMetadata.d.ts b/types/src/services/carrier_metadata_service/CarrierMetadata.d.ts deleted file mode 100644 index 4f76eebc3..000000000 --- a/types/src/services/carrier_metadata_service/CarrierMetadata.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -/** - * The Carrier Metadata endpoint returns information about all the carriers available on the EasyPost platform. - * This information may include service levels, predefined packages, shipment options, supported features, and - * more that are available per carrier. This metadata can be useful during onboarding and integration or when - * determining the ideal carrier mix for your setup. - * - * @see https://www.easypost.com/docs/api/node#carriermetadata-object - */ -export type ICarrierMetadata = { - /** - * The single-word name of a carrier such as "royalmail" - */ - carrier: string; - /** - * The human-readable name of the carrier - */ - human_readable?: string | null; - /** - * A list of service level objects for this carrier - */ - service_levels?: Array | null; - /** - * A list of predefined package objects for this carrier - */ - predefined_packages?: Array | null; - /** - * A list of supported feature objects for this carrier - */ - supported_features?: Array | null; - /** - * A list of shipment option objects for this carrier - */ - shipment_options?: Array | null; -}; diff --git a/types/src/services/carrier_metadata_service/index.d.ts b/types/src/services/carrier_metadata_service/index.d.ts deleted file mode 100644 index 91a1f62e3..000000000 --- a/types/src/services/carrier_metadata_service/index.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import EasyPost from '../..'; -import { ICarrierMetadata } from './CarrierMetadata'; -export * from './CarrierMetadata'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Retrieve a list of carrier metadata based on the provided parameters. - * @param carriers - List of carrier in string - * @param type - List of types in string - * @returns - List of carrier metadata - */ - retrieve( - carriers?: string[] | null, - types?: string[] | null, - ): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/carrier_type_service/CarrierType.d.ts b/types/src/services/carrier_type_service/CarrierType.d.ts deleted file mode 100644 index 755c25a0e..000000000 --- a/types/src/services/carrier_type_service/CarrierType.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { IBaseObject } from '../../utils/types'; -import { ICarrierTypeFields } from './CarrierTypeFields'; -/** - * The CarrierType object provides an export declare interface for determining the valid fields of a CarrierAccount. - * The list of CarrierType objects only changes when a new carrier is added to EasyPost. - * - * The CarrierType objects consist of their top level attributes as well as a fields object that contains credentials and sometimes test_credentials sub-objects, - * which themselves are collections of attributes for CarrierAccount creation as well as metadata about presentation and the naming of said attributes. - * - * There are a couple special case CarrierAccounts, with structures differing somewhat from the norm. - * For instance, instead of credentials for UspsAccount, it has only auto_link: true, which indicates that it is an account that can be added or removed without any carrier-specific fields. - * - * The other custom option in the fields list is custom_workflow: true, which indicates that the EasyPost website export declare interface includes special processing for signups for the associated CarrierType. - * Carriers with a custom workflow will also present their normal credential rules, but it is considered unsafe to directly add a CarrierAccount of this type with these attributes filled out via another source than the EasyPost custom workflow. - * - * @see https://www.easypost.com/docs/api/node#carrier-type-object - */ -export type ICarrierType = IBaseObject<'CarrierType'> & { - /** - * Specifies the CarrierAccount type. - */ - type: string; - /** - * Contains at least one of the following keys: "auto_link", "credentials", "test_credentials", and "custom_workflow" - */ - fields: ICarrierTypeFields; -}; diff --git a/types/src/services/carrier_type_service/CarrierTypeCredentials.d.ts b/types/src/services/carrier_type_service/CarrierTypeCredentials.d.ts deleted file mode 100644 index 53653ec07..000000000 --- a/types/src/services/carrier_type_service/CarrierTypeCredentials.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * @see https://www.easypost.com/docs/api/node#carrier-type-credentials-object - */ -export type ICarrierTypeCredentials = { - /** - * The key for each attribute sub-object within credentials is the name of the attribute for submission on CarrierAccounts - */ - name: string; - /** - * There are five possible values, which encode the security need and storage type for each attribute: "visible", "checkbox", "fake", "password", and "masked" - */ - visibility: 'visible' | 'checkbox' | 'fake' | 'password' | 'masked'; - /** - * Most attributes have generic names, so for clarity a "label" value is provided for clearer representation when rendering forms - */ - label: string; -}; diff --git a/types/src/services/carrier_type_service/CarrierTypeFields.d.ts b/types/src/services/carrier_type_service/CarrierTypeFields.d.ts deleted file mode 100644 index 0eea6b8cc..000000000 --- a/types/src/services/carrier_type_service/CarrierTypeFields.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ICarrierTypeCredentials } from './CarrierTypeCredentials'; -/** - * @see https://www.easypost.com/docs/api/node#carrier-type-fields-object - */ -export type ICarrierTypeFields = { - /** - * If this key is present with the value of true, no other attributes are needed for CarrierAccount creation - */ - auto_link: boolean; - /** - * If this key is present with the value of true, CarrierAccount creation of this type requires extra work not handled by the CarrierAccount standard API - */ - custom_workflow: boolean; - /** - * If this object is present, required attribute names and their metadata are presented inside - */ - credentials: ICarrierTypeCredentials; - /** - * If this object is present, it contains attribute names and metadata just as the credentials object. - * It is not required for CarrierAccount creation if you do not plan on using the carrier account for test mode - */ - test_credentials: ICarrierTypeCredentials; -}; diff --git a/types/src/services/carrier_type_service/index.d.ts b/types/src/services/carrier_type_service/index.d.ts deleted file mode 100644 index f220bcf91..000000000 --- a/types/src/services/carrier_type_service/index.d.ts +++ /dev/null @@ -1,45 +0,0 @@ -import EasyPost from '../..'; -import { ICarrierType } from './CarrierType'; -export * from './CarrierType'; -export * from './CarrierTypeCredentials'; -export * from './CarrierTypeFields'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Retrieve all {@link CarrierType carrier types} available to the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-available-carrier-types EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of carrier types. - * @returns - A list of {@link CarrierType carrier types}. - */ - all(params?: {}): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/customs_info_service/CustomsInfo.d.ts b/types/src/services/customs_info_service/CustomsInfo.d.ts deleted file mode 100644 index ce91e3287..000000000 --- a/types/src/services/customs_info_service/CustomsInfo.d.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { ICustomsItem } from '../customs_item_service'; -/** - * CustomsInfo objects contain CustomsItem objects and all necessary information for the generation of customs forms required for international shipping. - * - * Please see the Shipments documentation for examples of including a CustomsInfo object in a shipment. - * - * @see https://www.easypost.com/docs/api/node#customs-info-object - */ -export type ICustomsInfo = IObjectWithId<'CustomsInfo'> & - IDatedObject & { - /** - * "EEL" or "PFC" - * value less than $2500: "NOEEI 30.37(a)" - * value greater than $2500: see [Customs Guide](https://www.easypost.com/customs-guide) - */ - eel_pfc?: string | null; - /** - * "documents", "gift", "merchandise", "returned_goods", "sample", or "other" - */ - contents_type?: string | null; - /** - * (max 255 characters) Human readable description of content. - * Required for certain carriers and always required if contents_type is "other" - */ - contents_explanation?: string | null; - /** - * Electronically certify the information provided - */ - customs_certify?: boolean | null; - /** - * Required if customs_certify is true - */ - customs_signer?: string | null; - /** - * "abandon" or "return", defaults to "return" - */ - non_delivery_option?: 'abandon' | 'return' | null; - /** - * "none", "other", "quarantine", or "sanitary_phytosanitary_inspection" - */ - restriction_type?: 'none' | 'other' | 'quarantine' | 'sanitary_phytosanitary_inspection' | null; - /** - * Required if restriction_type is not "none" - */ - restriction_comments?: string | null; - /** - * Describes the products being shipped - */ - customs_items: ICustomsItem[]; - /** - * A customs declaration message, available for eligible carriers - */ - declaration?: string | null; - }; diff --git a/types/src/services/customs_info_service/CustomsInfoCreateParameters.d.ts b/types/src/services/customs_info_service/CustomsInfoCreateParameters.d.ts deleted file mode 100644 index c3a689c41..000000000 --- a/types/src/services/customs_info_service/CustomsInfoCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { ICustomsInfo } from './CustomsInfo'; -export type ICustomsInfoCreateParameters = Omit; diff --git a/types/src/services/customs_info_service/index.d.ts b/types/src/services/customs_info_service/index.d.ts deleted file mode 100644 index 718ff65af..000000000 --- a/types/src/services/customs_info_service/index.d.ts +++ /dev/null @@ -1,54 +0,0 @@ -import EasyPost from '../..'; -import { ICustomsInfo } from './CustomsInfo'; -import { ICustomsInfoCreateParameters } from './CustomsInfoCreateParameters'; -export * from './CustomsInfo'; -export * from './CustomsInfoCreateParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link CustomsInfo customs info} record. - * See {@link https://www.easypost.com/docs/api/node#create-a-customsinfo EasyPost API Documentation} for more information. - * @param params - Parameters for the customs info to be created. - * @returns - The created customs info. - */ - create( - params: ICustomsInfoCreateParameters, - ): Promise>; - /** - * Retrieve a {@link CustomsInfo customs info} record by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-customsinfo EasyPost API Documentation} for more information. - * @param id - The ID of the customs info to retrieve. - * @returns - The retrieved customs info. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/customs_item_service/CustomsItem.d.ts b/types/src/services/customs_item_service/CustomsItem.d.ts deleted file mode 100644 index 2852a841b..000000000 --- a/types/src/services/customs_item_service/CustomsItem.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * A CustomsItem object describes goods for international shipment and should be created then included in a CustomsInfo object. - * - * @see https://www.easypost.com/docs/api/node#customs-item-object - */ -export type ICustomsItem = IObjectWithId<'CustomsItem'> & - IDatedObject & { - /** - * Required, description of item being shipped - */ - description: string; - /** - * Required, greater than zero - * float - */ - quantity: number; - /** - * Required, greater than zero, total value (unit value * quantity) - * float (USD) - */ - value: number; - /** - * Required, greater than zero, total weight (unit weight * quantity) - * float (oz) - */ - weight: number; - /** - * Harmonized Tariff Schedule, e.g. "6109.10.0012" for Men's T-shirts - * - * @see https://hts.usitc.gov/ - */ - hs_tariff_number?: string | null; - /** - * SKU/UPC or other product identifier - */ - code?: string | null; - /** - * Required, 2 char country code - */ - origin_country: string; - /** - * 3 char currency code, default USD - */ - currency?: string | null; - }; diff --git a/types/src/services/customs_item_service/CustomsItemCreateParameters.d.ts b/types/src/services/customs_item_service/CustomsItemCreateParameters.d.ts deleted file mode 100644 index 4ac2ff6d7..000000000 --- a/types/src/services/customs_item_service/CustomsItemCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { ICustomsItem } from './CustomsItem'; -export type ICustomsItemCreateParameters = Omit; diff --git a/types/src/services/customs_item_service/index.d.ts b/types/src/services/customs_item_service/index.d.ts deleted file mode 100644 index c8d46b2d2..000000000 --- a/types/src/services/customs_item_service/index.d.ts +++ /dev/null @@ -1,54 +0,0 @@ -import EasyPost from '../..'; -import { ICustomsItem } from './CustomsItem'; -import { ICustomsItemCreateParameters } from './CustomsItemCreateParameters'; -export * from './CustomsItem'; -export * from './CustomsItemCreateParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link CustomsItem customs item}. - * See {@link https://www.easypost.com/docs/api/node#create-a-customsitem EasyPost API Documentation} for more information. - * @param params - Parameters for the customs item to be created. - * @returns - The created customs item. - */ - create( - params: ICustomsItemCreateParameters, - ): Promise>; - /** - * Retrieve a {@link CustomsItem customs item} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-customsitem EasyPost API Documentation} for more information. - * @param id - The ID of the customs item to retrieve. - * @returns - The retrieved customs item. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/end_shipper_service/EndShipper.d.ts b/types/src/services/end_shipper_service/EndShipper.d.ts deleted file mode 100644 index 5e5b37489..000000000 --- a/types/src/services/end_shipper_service/EndShipper.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { IObjectWithId } from '../../utils/types'; -/** - * The EndShipper API is for platforms purchasing postage on behalf of their users, the EndShipper. - * Platforms must assert the EndShipper details, as the EndShipper is ultimately responsible for what is in the box. - * Multiple labels purchased for the same EndShipper must use the same EndShipper identity (API object). - * EndShipper objects must be created prior to buying a Shipment. Once EndShipper objects have been created, - * you must keep track of their public id in order to use them during a label buy. - * - * @see https://www.easypost.com/docs/api/node#endshipper - */ -export type IEndshipper = IObjectWithId<'EndShipper'> & { - /** - * Name of responsible person (conditionally required) - */ - name?: string | null; - /** - * Name of responsible company (conditionally required) - */ - company?: string | null; - /** - * First line of the address - */ - street1?: string | null; - /** - * Second line of the address - */ - street2?: string | null; - /** - * City the address is located in - */ - city?: string | null; - /** - * State or province the address is located in - */ - state?: string | null; - /** - * ZIP or postal code the address is located in - */ - zip: string; - /** - * ISO 3166 country code for the country the address is located in - */ - country?: string; - /** - * Phone number to reach the person or organization - */ - phone?: string | null; - /** - * Email to reach the person or organization - */ - email?: string | null; -}; diff --git a/types/src/services/end_shipper_service/EndShipperCreateParameters.d.ts b/types/src/services/end_shipper_service/EndShipperCreateParameters.d.ts deleted file mode 100644 index 11276c69a..000000000 --- a/types/src/services/end_shipper_service/EndShipperCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { IEndshipper } from './EndShipper'; -export type IEndShipperCreateParameters = Omit; diff --git a/types/src/services/end_shipper_service/EndShipperListParameters.d.ts b/types/src/services/end_shipper_service/EndShipperListParameters.d.ts deleted file mode 100644 index c806a475e..000000000 --- a/types/src/services/end_shipper_service/EndShipperListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api#endshipper - */ -export type IEndShipperListParameters = IAllMethodParameters; diff --git a/types/src/services/end_shipper_service/index.d.ts b/types/src/services/end_shipper_service/index.d.ts deleted file mode 100644 index 138577854..000000000 --- a/types/src/services/end_shipper_service/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -import EasyPost from '../..'; -import { IEndshipper } from './EndShipper'; -import { IEndShipperCreateParameters } from './EndShipperCreateParameters'; -import { IEndShipperListParameters } from './EndShipperListParameters'; -export * from './EndShipper'; -export * from './EndShipperCreateParameters'; -export * from './EndShipperListParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create an {@link EndShipper end shipper}. - * See {@link https://www.easypost.com/docs/api/node#create-an-endshipper EasyPost API Documentation} for more information. - * @param params - Parameters for the end shipper to be created. - * @returns - The created end shipper. - */ - create( - params: IEndShipperCreateParameters, - ): Promise>; - /** - * Update an {@link EndShipper end shipper}. - * See {@link https://www.easypost.com/docs/api/node#update-an-endshipper EasyPost API Documentation} for more information. - * @param id - The ID of the end shipper to update. - * @param params - Parameters for the end shipper to be updated. - * @returns - The updated end shipper. - */ - update( - id: string, - params: Partial, - ): Promise>; - /** - * Retrieve an {@link EndShipper end shipper} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-endshipper EasyPost API Documentation} for more information. - * @param id - The ID of the end shipper to retrieve. - * @returns - The retrieved end shipper. - */ - retrieve(id: string): Promise>; - /** - * Retrieve all {@link EndShipper end shippers} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-endshippers EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of end shippers. - * @returns - An object containing a list of {@link EndShipper end shippers} and pagination information. - */ - all(params?: IEndShipperListParameters): Promise< - { - _params: any; - } & { - has_more: boolean; - } - >; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/event_service/Event.d.ts b/types/src/services/event_service/Event.d.ts deleted file mode 100644 index 9da8a5e69..000000000 --- a/types/src/services/event_service/Event.d.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * Webhook Events are triggered by changes in objects you've created via the API. - * Every time an Event related to one of your objects is created, EasyPost guarantees at least one POST request will be sent to each of the webhook URLs set up for your account. - * For this reason, we strongly encourage your webhook handler to be idempotent. - * See the webhooks guide for more information. - * - * @see https://www.easypost.com/docs/api/node#events - */ -export type IEvent = IObjectWithId<'Event'> & - IDatedObject & { - /** - * Result type and event name, see the "Possible Event Types" section for more information - */ - description: string; - /** - * Previous values of relevant result attributes - */ - previous_attributes: any; - /** - * The object associated with the Event. See the "object" attribute on the result to determine its specific type. - * This field will not be returned when retrieving events directly from the API - */ - result: any; - /** - * The current status of the event. Possible values are "completed", "failed", "in_queue", "retrying", or "pending" (deprecated) - * - * @deprecated - */ - status: 'completed' | 'failed' | 'in_queue' | 'retrying' | 'pending'; - /** - * Webhook URLs that have not yet been successfully notified as of the time this webhook event was sent. - * The URL receiving the Event will still be listed in pending_urls, as will any other URLs that receive the Event at the same time - */ - pending_urls: string[]; - /** - * Webhook URLs that have already been successfully notified as of the time this webhook was sent - */ - completed_urls: string[]; - }; diff --git a/types/src/services/event_service/EventListParameters.d.ts b/types/src/services/event_service/EventListParameters.d.ts deleted file mode 100644 index 9bdf71607..000000000 --- a/types/src/services/event_service/EventListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-events - */ -export type IEventListParameters = IAllMethodParameters; diff --git a/types/src/services/event_service/Payload/Payload.d.ts b/types/src/services/event_service/Payload/Payload.d.ts deleted file mode 100644 index d52fba6e9..000000000 --- a/types/src/services/event_service/Payload/Payload.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../../utils/types'; -/** - * A Payload represents an attempt by EasyPost to send an Event to a Webhook. - * An Event can have multiple Payloads. For instance, if there is a failure to deliver a Webhook, - * an Event would have multiple payloads, one for each attempt to deliver the Event to the Webhook. - * Payload can be useful for debugging webhook delivery and when initially setting up EasyPost webhooks. - */ -export type IPayload = IObjectWithId<'Payload'> & - IDatedObject & { - /** - * The body of the Payload response - */ - response_body: string | null; - }; diff --git a/types/src/services/event_service/Payload/PayloadListParameters.d.ts b/types/src/services/event_service/Payload/PayloadListParameters.d.ts deleted file mode 100644 index 1286fdbbc..000000000 --- a/types/src/services/event_service/Payload/PayloadListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads - */ -export type IPayloadListParameters = IAllMethodParameters; diff --git a/types/src/services/event_service/Payload/index.d.ts b/types/src/services/event_service/Payload/index.d.ts deleted file mode 100644 index b1fd98702..000000000 --- a/types/src/services/event_service/Payload/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './Payload'; diff --git a/types/src/services/event_service/index.d.ts b/types/src/services/event_service/index.d.ts deleted file mode 100644 index cf8d41b21..000000000 --- a/types/src/services/event_service/index.d.ts +++ /dev/null @@ -1,96 +0,0 @@ -import EasyPost from '../..'; -import { IEvent } from './Event'; -import { IEventListParameters } from './EventListParameters'; -import { IPayload } from './Payload'; -export * from './Event'; -export * from './EventListParameters'; -export * from './Payload'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Retrieve all {@link Payload payloads} for an {@link Event event}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-payloads EasyPost API Documentation} for more information. - * @param id - The ID of the event to retrieve payloads for. - * @returns - A list of {@link Payload payloads} for the event. - */ - retrieveAllPayloads(id: string): Promise>; - /** - * Retrieve a specific {@link Payload payload} for an {@link Event event}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-payload EasyPost API Documentation} for more information. - * @param id - The ID of the event to retrieve the payload for. - * @param payloadId - The ID of the payload to retrieve. - * @returns - The {@link Payload payload} for the event. - */ - retrievePayload( - id: string, - payloadId: string, - ): Promise>; - /** - * Retrieve all {@link Event events} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-events EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the list of events. - * @returns - An object containing the list of {@link Event events} and pagination information. - */ - all(params?: IEventListParameters): Promise< - { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of Event collection. - * @param events An object containing a list of {@link Event events} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - events: any, - pageSize?: number | null, - ): Promise< - { - events: IEvent[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve an {@link Event event} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-event EasyPost API Documentation} for more information. - * @param id - The ID of the event to retrieve. - * @returns - The retrieved event. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/index.d.ts b/types/src/services/index.d.ts deleted file mode 100644 index 229b1e3fa..000000000 --- a/types/src/services/index.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -export * from './address_service'; -export * from './api_key_service'; -export * from './batch_service'; -export * from './beta_rate_service'; -export * from './beta_referral_customer_service'; -export * from './billing_service'; -export * from './carrier_account_service'; -export * from './carrier_metadata_service'; -export * from './carrier_type_service'; -export * from './customs_info_service'; -export * from './customs_item_service'; -export * from './end_shipper_service'; -export * from './event_service'; -export * from './insurance_service'; -export * from './order_service'; -export * from './parcel_service'; -export * from './pickup_service'; -export * from './rate_service'; -export * from './referral_customer_service'; -export * from './refund_service'; -export * from './report_service'; -export * from './scan_form_service'; -export * from './shipment_service'; -export * from './tracker_service'; -export * from './user_service'; -export * from './webhook_service'; -export * from './base_service'; diff --git a/types/src/services/insurance_service/Fee.d.ts b/types/src/services/insurance_service/Fee.d.ts deleted file mode 100644 index 2149b267a..000000000 --- a/types/src/services/insurance_service/Fee.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { IBaseObject } from '../../utils/types'; -import { TFeeType } from './FeeType'; -/** - * Fee objects are used to represent the breakdown of charges made when purchasing an item on EasyPost. - * Shipments and Trackers both have associations to Fee objects. - * - * Each Shipment object will have a Fee of type "LabelFee" to represent the label fee charged by EasyPost for the service. - * Shipments with postage collected by EasyPost (as opposed to shipments with postage collected directly by the carrier) will have a "PostageFee" according to the postage amount. - * Insurance on a Shipment will add an "InsuranceFee" with the insurance premium (not the covered value) for the amount. - * Tracker objects will have a "TrackerFee" with the price, even when a Tracker is free. - * - * @see https://www.easypost.com/docs/api/node#fee-object - */ -export type IFee = IBaseObject<'Fee'> & { - /** - * The name of the category of fee. Possible types are "LabelFee", "PostageFee", "InsuranceFee", and "TrackerFee" - */ - type: TFeeType; - /** - * USD value with sub-cent precision - */ - amount: string; - /** - * Whether EasyPost has successfully charged your account for the fee - */ - charged: boolean; - /** - * Whether the Fee has been refunded successfully - */ - refunded: boolean; -}; diff --git a/types/src/services/insurance_service/FeeType.d.ts b/types/src/services/insurance_service/FeeType.d.ts deleted file mode 100644 index 980a39a05..000000000 --- a/types/src/services/insurance_service/FeeType.d.ts +++ /dev/null @@ -1 +0,0 @@ -export type TFeeType = 'InsuranceFee' | 'LabelFee' | 'PostageFee' | 'TrackerFee'; diff --git a/types/src/services/insurance_service/Insurance.d.ts b/types/src/services/insurance_service/Insurance.d.ts deleted file mode 100644 index af0418285..000000000 --- a/types/src/services/insurance_service/Insurance.d.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { IAddress } from '../address_service'; -import { ITracker } from '../tracker_service'; -import { IFee } from './Fee'; -import { TInsuranceStatus } from './InsuranceStatus'; -/** - * An Insurance object represents insurance for packages purchased both via the EasyPost API as well as shipments purchased through third parties and later registered with EasyPost. - * An Insurance is created automatically whenever you buy a Shipment through EasyPost and pass insurance options during the Buy call or in a later call to Insure a Shipment. - * - * Insurance purchased through the Shipment Buy or Insure endpoints is immediately insured - there is no possibility of rejection based on tracking information, as the package was just created. - * On the other hand, Insurance purchased on shipments purchased outside of EasyPost requires creation with a tracking code so that EasyPost may confirm the package existence and current shipping status at the time of purchase. - * - * Standalone insurance is created in a pending state to help distinguish it from insurance purchased for an EasyPost Shipment. - * Both kinds of Insurance use the Tracking system to receive periodic updates, and will report those updates to any appropriate Webhooks on file. - * Standalone insurance will cancel itself if the tracking information for the given tracking code shows evidence of having been shipped anytime before the insurance was purchased. - * - * Unlike Shipments within EasyPost, Insurance objects register To and From Address objects according to the destination and ship-from locations of the package. - * This means that a Shipment with "is_return: true" actually ships to the listed From Address. - * Insurance does not have a concept of "is_return", so all insurance records refer to their true package destination as "to_address", regardless of whether or not the shipment is a return. - * - * @see https://www.easypost.com/docs/api/node#insurance-object - */ -export type IInsurance = IObjectWithId<'Insurance'> & - IDatedObject & { - /** - * The unique reference for this Insurance, if any - */ - reference?: string | null; - /** - * USD value of insured goods with sub-cent precision - */ - amount: string; - /** - * The insurance provider used by EasyPost - */ - provider: string; - /** - * An identifying number for some insurance providers used by EasyPost - */ - provider_id: string; - /** - * The ID of the Shipment in EasyPost, if postage was purchased via EasyPost - */ - shipment_id: string; - /** - * The tracking code of either the shipment within EasyPost, or provided by you during creation - */ - tracking_code: string; - /** - * The current status of the insurance, possible values are "new", "pending", "purchased", "failed", or "cancelled" - */ - status: TInsuranceStatus; - /** - * The associated Tracker object - */ - tracker: ITracker; - /** - * The associated Address object for destination - */ - to_address: IAddress; - /** - * The associated Address object for origin - */ - from_address: IAddress; - /** - * The associated InsuranceFee object if any - */ - fee: IFee; - /** - * The list of errors encountered during attempted purchase of the insurance - */ - messages: string[]; - }; diff --git a/types/src/services/insurance_service/InsuranceCreateParameters.d.ts b/types/src/services/insurance_service/InsuranceCreateParameters.d.ts deleted file mode 100644 index 537dc6ef8..000000000 --- a/types/src/services/insurance_service/InsuranceCreateParameters.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { IAddress } from '../address_service'; -export type IInsuranceCreateParameters = { - reference?: string | null; - to_address: IAddress | string; - from_address: IAddress | string; - /** - * The carrier associated with the tracking_code you provided. - * The carrier will get auto-detected if none is provided - */ - carrier?: string | null; - /** - * The tracking code associated with the non-EasyPost-purchased package you'd like to insure. - */ - tracking_code: string; - /** - * The USD value of contents you would like to insure. - * Currently the maximum is $5000 - * - * @example 100.00 - */ - amount: string; -}; diff --git a/types/src/services/insurance_service/InsuranceStatus.d.ts b/types/src/services/insurance_service/InsuranceStatus.d.ts deleted file mode 100644 index 139db60a2..000000000 --- a/types/src/services/insurance_service/InsuranceStatus.d.ts +++ /dev/null @@ -1 +0,0 @@ -export type TInsuranceStatus = 'new' | 'pending' | 'purchased' | 'failed' | 'cancelled'; diff --git a/types/src/services/insurance_service/index.d.ts b/types/src/services/insurance_service/index.d.ts deleted file mode 100644 index bb320ba54..000000000 --- a/types/src/services/insurance_service/index.d.ts +++ /dev/null @@ -1,89 +0,0 @@ -import EasyPost from '../..'; -import { IAllMethodParameters } from '../../utils/types'; -import { IInsurance } from './Insurance'; -import { IInsuranceCreateParameters } from './InsuranceCreateParameters'; -export * from './Fee'; -export * from './FeeType'; -export * from './Insurance'; -export * from './InsuranceCreateParameters'; -export * from './InsuranceStatus'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create an {@link Insurance insurance} record. - * See {@link https://www.easypost.com/docs/api/node#create-an-insurance EasyPost API Documentation} for more information. - * @param params - Parameters for the insurance to be created. - * @returns - The created insurance. - */ - create( - params: IInsuranceCreateParameters, - ): Promise>; - /** - * Retrieve all {@link Insurance} records associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-insurances EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the insurance records. - * @returns - An object containing the list of {@link Insurance insurance} records and pagination information. - */ - all(params?: IAllMethodParameters): Promise< - IInsurance[] & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of Insurance collection. - * @param {Object} insurances An object containing a list of {@link Insurance insurances} and pagination information. - * @param {Number} pageSize The number of records to return on each page - * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - insurances: any, - pageSize?: number | null, - ): Promise< - { - insurances: IInsurance[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve an {@link Insurance insurance} record by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-insurance EasyPost API Documentation} for more information. - * @param {string} id - The ID of the insurance to retrieve. - * @returns {Insurance} - The retrieved insurance. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/order_service/Order.d.ts b/types/src/services/order_service/Order.d.ts deleted file mode 100644 index 0b9a96406..000000000 --- a/types/src/services/order_service/Order.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { IAddress } from '../address_service'; -import { IRate } from '../rate_service'; -import { IMessage, IShipment } from '../shipment_service'; -/** - * The Order object represents a collection of packages and can be used for Multi-Piece Shipments. - * Like a single Shipment each Order consists of a "to" and "from" Address to be used for each Shipment within the Order. - * These Addresses will be copied to each Shipment so there is no need to specify them multiple times. - * Each Shipment must then specify its Parcel, Options, and CustomsInfo. - * - * An Order created with valid Address Objects and Parcel data nested within the Order's Shipment object will automatically retrieve available shipping Rate options. - * - * @see https://www.easypost.com/docs/api/node#order-object - */ -export type IOrder = IObjectWithId<'Order'> & - IDatedObject & { - /** - * An optional field that may be used in place of id in other API endpoints - */ - reference?: string | null; - /** - * The destination address - */ - to_address: IAddress; - /** - * The origin address - */ - from_address: IAddress; - /** - * The shipper's address, defaults to from_address - */ - return_address?: IAddress | null; - /** - * The buyer's address, defaults to to_address - */ - buyer_address?: IAddress | null; - /** - * All associated Shipment objects. Maximum of 100. - */ - shipments: IShipment[]; - /** - * All associated Rate objects - */ - rates: IRate[]; - /** - * Any carrier errors encountered during rating - */ - messages: IMessage[]; - /** - * Set true to create as a return - */ - is_return?: boolean | null; - }; diff --git a/types/src/services/order_service/OrderCreateParameters.d.ts b/types/src/services/order_service/OrderCreateParameters.d.ts deleted file mode 100644 index 8368b1d68..000000000 --- a/types/src/services/order_service/OrderCreateParameters.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { IAddress } from '../address_service'; -import { IShipment } from '../shipment_service'; -export type IOrderCreateParameters = { - reference?: string | null; - to_address: IAddress | string; - from_address: IAddress | string; - shipments: IShipment[]; - /** - * optional array of ids that begin with "ca_" - */ - carrier_accounts?: string[] | null; -}; diff --git a/types/src/services/order_service/index.d.ts b/types/src/services/order_service/index.d.ts deleted file mode 100644 index 4d07b7efe..000000000 --- a/types/src/services/order_service/index.d.ts +++ /dev/null @@ -1,79 +0,0 @@ -import EasyPost from '../..'; -import { IRate } from '../rate_service'; -import { IOrder } from './Order'; -import { IOrderCreateParameters } from './OrderCreateParameters'; -export * from './Order'; -export * from './OrderCreateParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create an {@link Order order}. - * See {@link https://www.easypost.com/docs/api/node#create-an-order EasyPost API Documentation} for more information. - * @param params - The parameters to create an order with. - * @returns - The created order. - */ - create(params: IOrderCreateParameters): Promise>; - /** - * Purchase an {@link Order order}. - * See {@link https://www.easypost.com/docs/api/node#buy-an-order EasyPost API Documentation} for more information. - * @param id - The ID of the order to buy. - * @param carrier - The carrier to use for the order purchase. - * @param service - The service to use for the order purchase. - * @returns - The purchased order. - */ - buy( - id: string, - carrier: string, - service: string, - ): Promise>; - /** - * Get updated rates for an {@link Order order}. - * See {@link https://www.easypost.com/docs/api/node#orders EasyPost API Documentation} for more information. - * @param id - The ID of the order to get rates for. - * @returns - The order with rates. - */ - getRates(id: string): Promise>; - /** - * Retrieve an {@link Order order} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-order EasyPost API Documentation} for more information. - * @param id - The ID of the order to retrieve. - * @returns - The retrieved order. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - > - /** - * Retrieve an {@link Order order} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-an-order EasyPost API Documentation} for more information. - * @param id - The ID of the order to retrieve. - * @returns - The retrieved order. - */; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/parcel_service/Parcel.d.ts b/types/src/services/parcel_service/Parcel.d.ts deleted file mode 100644 index f0c7c6535..000000000 --- a/types/src/services/parcel_service/Parcel.d.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * Parcel objects represent the physical container being shipped. - * Dimensions can be supplied either as length, width, and height dimensions, or a predefined_package string. - * Only weight is required, but since many carriers charge different rates for packages with large dimensions, we strongly recommend including all dimensions if available. - * - * Weights are in OUNCES (OZ) and go to one decimal point. - * Dimensions are in INCHES (IN) and go to one decimal point. - * - * @see https://www.easypost.com/docs/api/node#parcel-object - */ -export type IParcel = IObjectWithId<'Parcel'> & - IDatedObject & { - /** - * Required if width and/or height are present - * float (inches) - */ - length?: number | null; - /** - * Required if width and/or height are present - * float (inches) - */ - width?: number | null; - /** - * Required if width and/or height are present - * float (inches) - */ - height?: number | null; - /** - * Always required - * float (oz) - */ - weight: number; - /** - * Optional, one of our predefined_packages - */ - predefined_package?: string | null; - }; diff --git a/types/src/services/parcel_service/ParcelCreateParameters.d.ts b/types/src/services/parcel_service/ParcelCreateParameters.d.ts deleted file mode 100644 index 35f07b297..000000000 --- a/types/src/services/parcel_service/ParcelCreateParameters.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { IParcel } from './Parcel'; -export type IParcelCreateParameters = Omit & { - /** - * Required if width and/or height are present - * float (inches) - */ - length?: number | null; - /** - * Required if width and/or height are present - * float (inches) - */ - width?: number | null; - /** - * Required if width and/or height are present - * float (inches) - */ - height?: number | null; - /** - * Always required - * float (oz) - */ - weight: number; -}; diff --git a/types/src/services/parcel_service/index.d.ts b/types/src/services/parcel_service/index.d.ts deleted file mode 100644 index cd23ad71e..000000000 --- a/types/src/services/parcel_service/index.d.ts +++ /dev/null @@ -1,54 +0,0 @@ -import EasyPost from '../..'; -import { IParcel } from './Parcel'; -import { IParcelCreateParameters } from './ParcelCreateParameters'; -export * from './Parcel'; -export * from './ParcelCreateParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Parcel parcel}. - * See {@link https://www.easypost.com/docs/api/node#create-a-parcel EasyPost API Documentation} for more information. - * @param params - The parameters to create a parcel with. - * @returns - The created parcel. - */ - create( - params: IParcelCreateParameters, - ): Promise>; - /** - * Retrieve a {@link Parcel parcel} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-parcel EasyPost API Documentation} for more information. - * @param id - The ID of the parcel to retrieve. - * @returns - The retrieved parcel. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/pickup_service/Pickup.d.ts b/types/src/services/pickup_service/Pickup.d.ts deleted file mode 100644 index ae6a57f4f..000000000 --- a/types/src/services/pickup_service/Pickup.d.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { IAddress } from '../address_service'; -import { ICarrierAccount } from '../carrier_account_service'; -import { IMessage, IShipment } from '../shipment_service'; -import { IPickupRate } from './PickupRate'; -/** - * The Pickup object allows you to schedule a pickup from your carrier from your customer's residence or place of business. - * Supported carriers include: - * - Canada Post - * - Canpar - * - DHL Express - * - FedEx - * - Lasership - * - Loomis Express - * - LSO - * - Ontrac - * - UPS - * - USPS - * - Veho - * - * After a Pickup is successfully created, it will automatically fetch PickupRates for each CarrierAccount specified that supports scheduled pickups. - * Then a PickupRate must be selected and purchased before the pickup can be successfully scheduled. - * - * @see https://www.easypost.com/docs/api/node#pickup-object - */ -export type IPickup = IObjectWithId<'Pickup'> & - IDatedObject & { - /** - * An optional field that may be used in place of ID in some API endpoints - */ - reference?: string | null; - /** - * One of: "unknown", "scheduled", or "canceled" - */ - status: 'unknown' | 'scheduled' | 'canceled'; - /** - * The earliest time at which the package is available to pick up - */ - min_datetime: string; - /** - * The latest time at which the package is available to pick up. - * Must be later than the min_datetime - */ - max_datetime: string; - /** - * Is the pickup address the account's address? - */ - is_account_address?: boolean | null; - /** - * Additional text to help the driver successfully obtain the package - */ - instructions?: string | null; - /** - * A list of messages containing carrier errors encountered during pickup rate generation - */ - messages: IMessage[]; - /** - * The confirmation number for a booked pickup from the carrier - */ - confirmation: string; - /** - * The associated Shipment - */ - shipment: IShipment; - /** - * The associated Address - */ - address: IAddress; - /** - * The list of carriers (if empty, all carriers were used) used to generate pickup rates - */ - carrier_accounts?: ICarrierAccount[] | null; - /** - * The list of different pickup rates across valid carrier accounts for the shipment - */ - pickup_rates: IPickupRate[]; - }; diff --git a/types/src/services/pickup_service/PickupCreateParameters.d.ts b/types/src/services/pickup_service/PickupCreateParameters.d.ts deleted file mode 100644 index d4c180dcc..000000000 --- a/types/src/services/pickup_service/PickupCreateParameters.d.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { IAddress } from '../address_service'; -import { IBatch } from '../batch_service'; -import { ICarrierAccount } from '../carrier_account_service'; -import { IShipment } from '../shipment_service'; -import { IPickupRate } from './PickupRate'; -type BasePickupCreateParameters = { - address: IAddress | string; - carrier_accounts?: ICarrierAccount[] | null; - confirmation?: string | null; - instructions?: string | null; - is_account_address?: boolean | null; - max_datetime: string; - min_datetime: string; - pickup_rates: IPickupRate; - reference?: string | null; - status: string; -}; -type ShipmentPickupCreateParameters = BasePickupCreateParameters & { - shipment?: - | IShipment - | { - id: string; - } - | string - | null; -}; -type BatchPickupCreateParameters = BasePickupCreateParameters & { - batch?: - | IBatch - | { - id: string; - } - | string - | null; -}; -export type IPickupCreateParameters = ShipmentPickupCreateParameters | BatchPickupCreateParameters; -export {}; diff --git a/types/src/services/pickup_service/PickupListParameters.d.ts b/types/src/services/pickup_service/PickupListParameters.d.ts deleted file mode 100644 index 806edf7f0..000000000 --- a/types/src/services/pickup_service/PickupListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups - */ -export type IPickupListParameters = IAllMethodParameters; diff --git a/types/src/services/pickup_service/PickupRate.d.ts b/types/src/services/pickup_service/PickupRate.d.ts deleted file mode 100644 index 53983d86e..000000000 --- a/types/src/services/pickup_service/PickupRate.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#pickup-rate-object - */ -export type IPickupRate = IObjectWithId<'PickupRate'> & - IDatedObject & { - /** - * service name - */ - service: string; - /** - * name of carrier - */ - carrier: string; - /** - * the actual rate quote for this service - */ - rate: string; - /** - * currency for the rate - */ - currency: string; - /** - * the ID of the pickup this is a quote for - */ - pickup_id: string; - }; diff --git a/types/src/services/pickup_service/index.d.ts b/types/src/services/pickup_service/index.d.ts deleted file mode 100644 index bbab7e5c2..000000000 --- a/types/src/services/pickup_service/index.d.ts +++ /dev/null @@ -1,110 +0,0 @@ -import EasyPost from '../..'; -import { IPickup } from './Pickup'; -import { IPickupCreateParameters } from './PickupCreateParameters'; -import { IPickupListParameters } from './PickupListParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Pickup pickup}. - * See {@link https://www.easypost.com/docs/api/node#create-a-pickup EasyPost API Documentation} for more information. - * @param params - The parameters to create a pickup with. - * @returns - The created pickup. - */ - create( - params: IPickupCreateParameters, - ): Promise>; - /** - * Purchase a {@link Pickup pickup}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-pickup EasyPost API Documentation} for more information. - * @param id - The ID of the pickup to purchase. - * @param carrier - The carrier to purchase the pickup with. - * @param service - The service to purchase the pickup with. - * @returns - The purchased pickup. - */ - buy( - id: string, - carrier: string, - service: string, - ): Promise>; - /** - * Cancel a {@link Pickup pickup}. - * See {@link https://www.easypost.com/docs/api/node#cancel-a-pickup EasyPost API Documentation} for more information. - * @param id - The ID of the pickup to cancel. - * @returns - The cancelled pickup. - */ - cancel(id: string): Promise>; - /** - * Retrieve all {@link Pickup pickups} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-pickups EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the pickups by. - * @returns - An object containing a list of {@link Pickup pickups} and pagination information. - */ - all(params?: IPickupListParameters): Promise< - IPickup[] & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of Pickup collection. - * @param pickups An object containing a list of {@link Pickup pickups} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - pickups: any, - pageSize?: number | null, - ): Promise< - { - pickups: IPickup[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link Pickup pickup} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-pickup EasyPost API Documentation} for more information. - * @param id - The ID of the pickup to retrieve. - * @returns - The retrieved pickup. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise> - /** - * Retrieve the next page of Pickup collection. - * @param pickups An object containing a list of {@link Pickup pickups} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/rate_service/Rate.d.ts b/types/src/services/rate_service/Rate.d.ts deleted file mode 100644 index d53e172de..000000000 --- a/types/src/services/rate_service/Rate.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * The Rate class represents a summary of the price and details of a delivery service quote. - * - * @see https://www.easypost.com/docs/api/node#rates - */ -export type IRate = IObjectWithId<'Rate'> & - IDatedObject & { - /** - * The service level of the rate. - */ - service: string; - /** - * The carrier of the rate. - */ - carrier: string; - /** - * The ID of the carrier account associated with this rate. - */ - carrier_account_id: string; - /** - * The ID of the shipment associated with this rate. - */ - shipment_id: string; - /** - * The quote price of the rate. - */ - rate: string; - /** - * The currency of the rate. - */ - currency: string; - /** - * The in-store retail rate given with no account. - */ - retail_rate: string; - /** - * The currency of the retail rate. - */ - retail_currency: string; - /** - * The non-negotiated rate given for having an account with the carrier. - */ - list_rate: string; - /** - * The currency of the list rate. - */ - list_currency: string; - /** - * The number of days in transit for this rate. - */ - delivery_days: number; - /** - * The delivery date for this rate. - */ - delivery_date: string; - /** - * Whether the delivery window is guaranteed. - */ - delivery_date_guaranteed: boolean; - /** - * The earliest delivery date for this rate. - * This is deprecated and should be ignored. - */ - est_delivery_days: number; - /** - * The billing type of the rate. - */ - billing_type: string; - }; -export type ISmartRate = IRate & { - time_in_transit: { - percentile_50: number; - percentile_75: number; - percentile_85: number; - percentile_90: number; - percentile_95: number; - percentile_97: number; - percentile_99: number; - }; -}; diff --git a/types/src/services/rate_service/index.d.ts b/types/src/services/rate_service/index.d.ts deleted file mode 100644 index b51193687..000000000 --- a/types/src/services/rate_service/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -import EasyPost from '../..'; -import { IRate } from './Rate'; -export * from './Rate'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Retrieve a {@link Rate rate} by its ID. - * See {@link https://www.easypost.com/docs/api/node#rates EasyPost API Documentation} for more information. - * @param {string} id - The ID of the rate to retrieve. - * @returns {Rate} - The retrieved rate. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/referral_customer_service/Referral.d.ts b/types/src/services/referral_customer_service/Referral.d.ts deleted file mode 100644 index b83dfa0a6..000000000 --- a/types/src/services/referral_customer_service/Referral.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { IUser } from '../user_service'; -/** - * A Referral represents a sub-user under a Partner or white-label account. - * - * @see https://www.easypost.com/docs/api/node#referral-customers - */ -export declare interface IReferral extends IUser {} diff --git a/types/src/services/referral_customer_service/ReferralCreateParameters.d.ts b/types/src/services/referral_customer_service/ReferralCreateParameters.d.ts deleted file mode 100644 index 7035f552d..000000000 --- a/types/src/services/referral_customer_service/ReferralCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { IReferral } from './Referral'; -export type IReferralCreateParameters = Omit; diff --git a/types/src/services/referral_customer_service/ReferralListParameters.d.ts b/types/src/services/referral_customer_service/ReferralListParameters.d.ts deleted file mode 100644 index f26fe30bd..000000000 --- a/types/src/services/referral_customer_service/ReferralListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers - */ -export type IReferralListParameters = IAllMethodParameters; diff --git a/types/src/services/referral_customer_service/index.d.ts b/types/src/services/referral_customer_service/index.d.ts deleted file mode 100644 index 2f4520f4e..000000000 --- a/types/src/services/referral_customer_service/index.d.ts +++ /dev/null @@ -1,108 +0,0 @@ -import EasyPost from '../..'; -import { IReferralCreateParameters } from './ReferralCreateParameters'; -import { IReferral } from './Referral'; -import { IReferralListParameters } from './ReferralListParameters'; -import { IPaymentMethod } from '../billing_service'; -export * from './Referral'; -export * from './ReferralCreateParameters'; -export * from './ReferralListParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link User referral customer}. - * See {@link https://www.easypost.com/docs/api/node#create-a-referral-customer EasyPost API Documentation} for more information. - * @param params - The referral customer's information. - * @returns - The newly created referral customer. - */ - create( - params: IReferralCreateParameters, - ): Promise>; - /** - * Update a {@link User referral customer's} email address. - * See {@link https://www.easypost.com/docs/api/node#update-a-referral-customer EasyPost API Documentation} for more information. - * @param referralUserId - The ID of the referral customer to update. - * @param email - The new email address. - * @returns - Returns true if the referral was updated successfully, false otherwise. - */ - updateEmail(referralUserId: string, email: string): Promise; - /** - * Add a credit card to a {@link User referral customer's} account. - * See {@link https://www.easypost.com/docs/api/node#create-credit-card EasyPost API Documentation} for more information. - * @param referralApiKey - The referral customer's production API key. - * @param number - The credit card number. - * @param expirationMonth - The credit card expiration month. - * @param expirationYear - The credit card expiration year. - * @param cvc - The credit card CVC. - * @param priority - Whether to add the card as 'primary' or 'secondary' payment method (defaults to 'primary'). - * @returns - An object representing the newly-added credit card. - */ - addCreditCard( - referralApiKey: string, - number: string, - expirationMonth: string, - expirationYear: string, - cvc: string, - priority?: 'primary' | 'secondary', - ): Promise; - /** - * Retrieve all {@link User referral customers} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the referral customers by. - * @returns - An object containing a list of {@link User referral customers} and pagination information. - */ - all(params?: IReferralListParameters): Promise< - IReferral[] & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of Referral Customer collection. - * @param referralCustomers An object containing a list of {@link referral referralCustomers} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - referralCustomers: any, - pageSize?: number | null, - ): Promise< - { - referral_customers: IReferral[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/refund_service/Refund.d.ts b/types/src/services/refund_service/Refund.d.ts deleted file mode 100644 index 1765f8ccb..000000000 --- a/types/src/services/refund_service/Refund.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * The Refund object represents a refunded shipment, and includes details about the related Shipment and tracking code. - * USPS shipping labels can be refunded if requested within 30 days of generation. - * The processing time is at least 15 days, after which the funds will return to your EasyPost balance. - * EasyPost fees will also be refunded. To qualify, a shipment must not have been scanned by the USPS. - * UPS and FedEx shipping labels may be refunded within 90 days of creation. - */ -export type IRefund = IObjectWithId<'Refund'> & - IDatedObject & { - /** - * The tracking code of the related Shipment - */ - tracking_code: string; - /** - * The confirmation number for the refund request to the carrier - */ - confirmation_number: string; - /** - * The status of the refund request, reported by the carrier. Possible values are "submitted", "refunded", or "rejected" - */ - status: 'submitted' | 'refunded' | 'rejected'; - /** - * The carrier the refund request was submitted to - */ - carrier: string; - /** - * The ID of the related Shipment being refunded - */ - shipment_id: string; - }; diff --git a/types/src/services/refund_service/RefundCreateParameters.d.ts b/types/src/services/refund_service/RefundCreateParameters.d.ts deleted file mode 100644 index 56419c78e..000000000 --- a/types/src/services/refund_service/RefundCreateParameters.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @see https://www.easypost.com/docs/api/node#create-a-refund - */ -export type IRefundCreateParameters = { - /** - * The carrier to request a refund from - */ - carrier: string; - /** - * A list of tracking codes to request refunds for. Even for a single tracking code, it needs to be submitted as a list. - */ - tracking_codes: string[]; -}; diff --git a/types/src/services/refund_service/RefundListParameters.d.ts b/types/src/services/refund_service/RefundListParameters.d.ts deleted file mode 100644 index 5239e02d8..000000000 --- a/types/src/services/refund_service/RefundListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds - */ -export type IRefundListParameters = IAllMethodParameters; diff --git a/types/src/services/refund_service/index.d.ts b/types/src/services/refund_service/index.d.ts deleted file mode 100644 index d476fbfd5..000000000 --- a/types/src/services/refund_service/index.d.ts +++ /dev/null @@ -1,89 +0,0 @@ -import EasyPost from '../..'; -import { IRefund } from './Refund'; -import { IRefundCreateParameters } from './RefundCreateParameters'; -import { IRefundListParameters } from './RefundListParameters'; -export * from './Refund'; -export * from './RefundCreateParameters'; -export * from './RefundListParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Refund refund}. - * See {@link https://www.easypost.com/docs/api/node#create-a-refund EasyPost API Documentation} for more information. - * @param params - The parameters to create a refund with. - * @returns - The created refund. - */ - create( - params: IRefundCreateParameters, - ): Promise>; - /** - * Retrieve all {@link Refund refunds} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the refunds by. - * @returns - An object containing the list of {@link Refund refunds} and pagination information. - */ - all(params?: IRefundListParameters): Promise< - { - refunds: IRefund[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of Refund collection. - * @param refunds An object containing a list of {@link Refund refunds} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - refunds: any, - pageSize?: number | null, - ): Promise< - { - refunds: IRefund[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link Refund refund} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-refund EasyPost API Documentation} for more information. - * @param id - The ID of the refund to retrieve. - * @returns - The retrieved refund. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/report_service/Report.d.ts b/types/src/services/report_service/Report.d.ts deleted file mode 100644 index bc01c19c3..000000000 --- a/types/src/services/report_service/Report.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { TReportObjectType } from './ReportObjectType'; -/** - * A Report contains a csv that is a log of all the objects created within a certain time frame. - * - * Reports can be generated using the Reports Endpoint. - * You can create and view Reports created between any time frame defined between the start_date and end_date. - * - * The Report api can be categorized into several types. - * These types determine which EasyPost Object to produce a Report for, and should be passed as the type in our libraries: - * - cash_flow - * - insurance - * - payment_log - * - refund - * - shipment - * - shipment_invoice - * - tracker - * - * @see https://www.easypost.com/docs/api/node#report-object - */ -export type IReport = IObjectWithId & - IDatedObject & { - /** - * "new", "available", "failed", or null - */ - status: 'new' | 'available' | 'failed' | null; - /** - * A date string in YYYY-MM-DD form eg: "2016-02-02" - */ - start_date: string; - /** - * A date string in YYYY-MM-DD form eg: "2016-02-03" - */ - end_date: string; - /** - * Set true if you would like to include Refunds /Shipments /Trackers created by child users - */ - include_children?: boolean | null; - /** - * A url that contains a link to the Report. - * Expires 30 seconds after retrieving this object - */ - url: string; - /** - * Url expiring time - */ - url_expires_at: string; - /** - * Set true if you would like to send an email containing the Report - */ - send_email?: boolean | null; - }; diff --git a/types/src/services/report_service/ReportCreateParameters.d.ts b/types/src/services/report_service/ReportCreateParameters.d.ts deleted file mode 100644 index 909b9d4df..000000000 --- a/types/src/services/report_service/ReportCreateParameters.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { TReportType } from './ReportObjectType'; -export type IReportCreateParameters = { - type: TReportType; - start_date: string | null; - end_date?: string | null; - include_children?: boolean | null; - send_email?: boolean | null; - columns?: string[] | null; - additional_columns?: string[] | null; -}; diff --git a/types/src/services/report_service/ReportListParameters.d.ts b/types/src/services/report_service/ReportListParameters.d.ts deleted file mode 100644 index 2c8e5efe7..000000000 --- a/types/src/services/report_service/ReportListParameters.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -import { TReportType } from './ReportObjectType'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-refunds - */ -export type IReportListParameters = IAllMethodParameters & { - type: TReportType; -}; diff --git a/types/src/services/report_service/ReportObjectType.d.ts b/types/src/services/report_service/ReportObjectType.d.ts deleted file mode 100644 index 918f61516..000000000 --- a/types/src/services/report_service/ReportObjectType.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -export type TReportObjectType = - | 'CashFlowReport' - | 'PaymentLogReport' - | 'RefundReport' - | 'ShipmentReport' - | 'ShipmentInvoiceReport' - | 'TrackerReport'; -export type TReportType = - | 'cash_flow' - | 'payment_log' - | 'refund' - | 'shipment' - | 'shipment_invoice' - | 'tracker'; diff --git a/types/src/services/report_service/index.d.ts b/types/src/services/report_service/index.d.ts deleted file mode 100644 index 998522b84..000000000 --- a/types/src/services/report_service/index.d.ts +++ /dev/null @@ -1,82 +0,0 @@ -import EasyPost from '../..'; -import { IReport } from './Report'; -import { IReportCreateParameters } from './ReportCreateParameters'; -import { IReportListParameters } from './ReportListParameters'; -export * from './Report'; -export * from './ReportCreateParameters'; -export * from './ReportListParameters'; -export * from './ReportObjectType'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Report report}. - * See {@link https://www.easypost.com/docs/api/node#create-a-report EasyPost API Documentation} for more information. - * @param params - The parameters to create a report with. - * @returns - The created report. - */ - create( - params: IReportCreateParameters, - ): Promise>; - /** - * Retrieve all {@link Report reports} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-reports EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the reports by. - * @returns - An object containing the list of {@link Report reports} and pagination information. - */ - all(params: IReportListParameters): Promise; - /** - * Retrieve the next page of Report collection. - * @param reports An object containing a list of {@link Report reports} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - reports: any, - pageSize?: number | null, - ): Promise< - { - reports: IReport[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link Report report} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-report EasyPost API Documentation} for more information. - * @param id - The ID of the report to retrieve. - * @returns - The retrieved report. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/scan_form_service/ScanForm.d.ts b/types/src/services/scan_form_service/ScanForm.d.ts deleted file mode 100644 index 9cba95498..000000000 --- a/types/src/services/scan_form_service/ScanForm.d.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { IAddress } from '../address_service'; -/** - * A ScanForm can be created to speed up and simplify the carrier pickup process. - * The ScanForm is one document that can be scanned to mark all included tracking codes as "Accepted for Shipment" by the carrier. - * The following criteria must met before creation: - * - Refunded Shipments cannot be added - * - Each Shipment must have the same origin address - * - Shipments must all be dated (using the label_date option) on or after the date the form is generated - * - Shipments cannot be added to more than one ScanForm - * - Existing ScanForms may not be updated with additional Shipments. If a ScanForm already exists, and new Shipments need to be added, a new ScanForm must be created. - * - Shipments should be provided in the form of an array - * - * @see https://www.easypost.com/docs/api/node#scan-form-object - */ -export type IScanForm = IObjectWithId<'ScanForm'> & - IDatedObject & { - /** - * Current status. - * Possible values are "creating", "created" and "failed" - */ - status: 'creating' | 'created' | 'failed'; - /** - * Human-readable message explaining any failures - */ - message: string; - /** - * Address that the Shipments will be shipped from - */ - address: IAddress; - /** - * Tracking codes included on the ScanForm - */ - tracking_codes: string[]; - /** - * Url of the document - */ - form_url: string; - /** - * File format of the document - */ - form_file_type: string; - /** - * The id of the associated Batch. Unique, starts with "batch_" - */ - batch_id: string; - }; diff --git a/types/src/services/scan_form_service/ScanFormCreateParameters.d.ts b/types/src/services/scan_form_service/ScanFormCreateParameters.d.ts deleted file mode 100644 index 9642f1e8d..000000000 --- a/types/src/services/scan_form_service/ScanFormCreateParameters.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { DeepPartial } from '../../utils/types'; -import { IShipmentCreateParameters } from '../shipment_service'; -export type IScanFormCreateParameters = { - shipments: - | (DeepPartial & { - id: string; - })[] - | string[]; -}; diff --git a/types/src/services/scan_form_service/ScanFormListParameters.d.ts b/types/src/services/scan_form_service/ScanFormListParameters.d.ts deleted file mode 100644 index 655a0094c..000000000 --- a/types/src/services/scan_form_service/ScanFormListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-scan-forms - */ -export type IScanFormListParameters = IAllMethodParameters; diff --git a/types/src/services/scan_form_service/index.d.ts b/types/src/services/scan_form_service/index.d.ts deleted file mode 100644 index 59563b781..000000000 --- a/types/src/services/scan_form_service/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -import EasyPost from '../..'; -import { IScanForm } from './ScanForm'; -import { IScanFormCreateParameters } from './ScanFormCreateParameters'; -import { IScanFormListParameters } from './ScanFormListParameters'; -export * from './ScanForm'; -export * from './ScanFormCreateParameters'; -export * from './ScanFormListParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link ScanForm scan form}. - * See {@link https://www.easypost.com/docs/api/node#create-a-scanform EasyPost API Documentation} for more information. - * @param params - The parameters to create a scan form with. - * @returns - The created scan form. - */ - create( - params: IScanFormCreateParameters, - ): Promise>; - /** - * Retrieve all {@link ScanForm scan forms} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-scanforms EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the scan forms by. - * @returns - An object containing the list of {@link ScanForm scan forms} and pagination information. - */ - all(params?: IScanFormListParameters): Promise< - { - scan_forms: IScanForm[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of ScanForm collection. - * @param scanForms An object containing a list of {@link ScanForm scanForms} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - scanForms: { - scan_forms: any[]; - }, - pageSize?: number | null, - ): Promise< - { - scan_forms: IScanForm[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link ScanForm scan form} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-scanform EasyPost API Documentation} for more information. - * @param id - The ID of the scan form to retrieve. - * @returns - The retrieved scan form. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/shipment_service/Form.d.ts b/types/src/services/shipment_service/Form.d.ts deleted file mode 100644 index c7430545a..000000000 --- a/types/src/services/shipment_service/Form.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#form-object - */ -export type IForm = IObjectWithId<'Form'> & - IDatedObject & { - /** - * The type of form that we returned, can be one of "cn22", "cod_return_label", "commercial_invoice", "high_value_report", "label_qr_code", "nafta_certificate_of_origin", "order_summary", "return_packing_slip", "rma_qr_code" - */ - form_type: - | 'cn22' - | 'cod_return_label' - | 'commercial_invoice' - | 'high_value_report' - | 'label_qr_code' - | 'nafta_certificate_of_origin' - | 'order_summary' - | 'return_packing_slip' - | 'rma_qr_code'; - /** - * The address we return the form back at - */ - form_url: string; - /** - * If we have submitted the form to the carrier on behalf of the customer - */ - submitted_electronically: boolean; - }; diff --git a/types/src/services/shipment_service/Message.d.ts b/types/src/services/shipment_service/Message.d.ts deleted file mode 100644 index ff845b655..000000000 --- a/types/src/services/shipment_service/Message.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -/** - * When rating a Shipment or Pickup, some carriers may fail to generate rates. - * These failures are returned as part of the Shipment or Pickup as part of their messages attribute, and follow a common object structure. - * - * It is important to note that the message value for any member of this list comes directly from the carrier, not from EasyPost. - * This means that if you see an authentication or other non-shipping error here, it is not an issue between you and EasyPost, it is an issue between you and the carrier, or an issue with the given data. - * - * @see https://www.easypost.com/docs/api/node#message-object - */ -export type IMessage = { - /** - * the name of the carrier generating the error, e.g. "UPS" - */ - carrier: string; - /** - * the category of error that occurred. Most frequently "rate_error" - */ - type: string; - /** - * the string from the carrier explaining the problem - */ - message: string; - /** - * the account id of the carrier. Useful if you have multiple accounts with the same carrier - */ - carrier_account_id: string; -}; diff --git a/types/src/services/shipment_service/Options/LabelFormat.d.ts b/types/src/services/shipment_service/Options/LabelFormat.d.ts deleted file mode 100644 index cc3a84031..000000000 --- a/types/src/services/shipment_service/Options/LabelFormat.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare type LabelFormat = 'PNG' | 'PDF' | 'ZPL' | 'EPL2'; diff --git a/types/src/services/shipment_service/Options/Options.d.ts b/types/src/services/shipment_service/Options/Options.d.ts deleted file mode 100644 index 52b3a842f..000000000 --- a/types/src/services/shipment_service/Options/Options.d.ts +++ /dev/null @@ -1,325 +0,0 @@ -import { LabelFormat } from './LabelFormat'; -import { TPrintCustomCode } from './PrintCustomCode'; -/** - * Shipments can have a variety of additional options which you can specify when creating a shipment. - * The Options object can be populated with the keys below. - * - * @see https://www.easypost.com/docs/api/node#options-object - */ -export type IOptions = { - /** - * Setting this option to true, will add an additional handling charge. - * An Additional Handling charge may be applied to the following: - * - Any article that is encased in an outside shipping container made of metal or wood. - * - Any item, such as a barrel, drum, pail or tire, that is not fully encased in a corrugated cardboard shipping container. - * - Any package with the longest side exceeding 60 inches or its second longest side exceeding 30 inches. - * - Any package with an actual weight greater than 70 pounds. - */ - additional_handling?: boolean | null; - /** - * Setting this option to "0", will allow the minimum amount of address information to pass the validation check. - * Only for USPS postage. - */ - address_validation_level?: string | null; - /** - * Set this option to true if your shipment contains alcohol. - * - UPS - only supported for US Domestic shipments - * - FedEx - only supported for US Domestic shipments - * - Canada Post - Requires adult signature 19 years or older. If you want adult signature 18 years or older, instead use delivery_confirmation: ADULT_SIGNATURE - */ - alcohol?: boolean | null; - /** - * Setting this option to true will indicate to the carrier to prefer delivery by drone, if the carrier supports drone delivery. - */ - by_drone?: boolean | null; - /** - * Setting this to true will add a charge to reduce carbon emissions. - */ - carbon_neutral?: boolean | null; - /** - * Adding an amount will have the carrier collect the specified amount from the recipient. - */ - cod_amount?: string | null; - /** - * Method for payment. "CASH", "CHECK", "MONEY_ORDER" - */ - cod_method?: 'CASH' | 'CHECK' | 'MONEY_ORDER' | null; - /** - * The ID of the Address to which the COD payment should be returned. - * Defaults to the origin address. - * Only available on FedEx shipments. - */ - cod_address_id?: string | null; - /** - * A description of the content of the shipment. - */ - content_description?: string | null; - /** - * Which currency this shipment will show for rates if carrier allows. - */ - currency?: string | null; - /** - * If you want to request a signature, you can pass "ADULT_SIGNATURE" or "SIGNATURE". - * You may also request "NO_SIGNATURE" to leave the package at the door. - * - All - some options may be limited for international shipments - * - FedEx - "INDIRECT_SIGNATURE" is also an option - * - USPS - additional options - * - "ADULT_SIGNATURE_RESTRICTED" - * - "SIGNATURE_RESTRICTED" - * - Canada Post - "DO_NOT_SAFE_DROP" - Tells the carrier to not hide the package ("safe drop"). - * - GSO - "STANDARD_SIGNATURE". - * - DHL Express - option mapping - * - "SIGNATURE" - DHL Express Direct Signature - * - "NO_SIGNATURE" - DHL Express Signature Release - */ - delivery_confirmation?: - | 'ADULT_SIGNATURE' - | 'SIGNATURE' - | 'NO_SIGNATURE' - | 'INDIRECT_SIGNATURE' - | 'ADULT_SIGNATURE_RESTRICTED' - | 'SIGNATURE_RESTRICTED' - | null; - /** - * Method the customer will use to transfer the package to the carrier. - * "REGULAR_PICKUP", "SCHEDULED_PICKUP", "RETAIL_LOCATION", "STATION" or "DROP_BOX". - * Supported carriers and their corresponding carrier dropoff codes: - * - FedEx - * - "REGULAR_PICKUP" - "REGULAR_PICKUP" (default) - * - "SCHEDULED_PICKUP" - "REQUEST_COURIER" - * - "RETAIL_LOCATION" - "BUSINESS_SERVICE_CENTER" - * - "STATION" - "STATION" - * - "DROP_BOX" - "DROP_BOX" - */ - dropoff_type?: - | 'REGULAR_PICKUP' - | 'SCHEDULED_PICKUP' - | 'RETAIL_LOCATION' - | 'STATION' - | 'DROP_BOX' - | 'REQUEST_COURIER' - | 'BUSINESS_SERVICE_CENTER' - | null; - /** - * Package contents contain dry ice. - * - UPS - Need dry_ice_weight to be set - * - UPS MailInnovations - Need dry_ice_weight to be set - * - FedEx - Need dry_ice_weight to be set - */ - dry_ice?: boolean | null; - /** - * If the dry ice is for medical use, set this option to true. - * - UPS - Need dry_ice_weight to be set - * - UPS MailInnovations - Need dry_ice_weight to be set - */ - dry_ice_medical?: boolean | null; - /** - * Weight of the dry ice in ounces. - * - UPS - Need dry_ice to be set - * - UPS MailInnovations - Need dry_ice to be set - * - FedEx - Need dry_ice to be set - */ - dry_ice_weight?: string | null; - /** - * Setting duty_payment type to bill the correct account for purchasing postage. - * This option is only available with FedEx and UPS. - * - type - (string) Supported values are "THIRD_PARTY", and "RECEIVER". - * - account - (string) Setting account number. - * - country - (string) Setting country code that the account is based in. - * - postal_code - (string) Setting postal code that the account is based in. - */ - duty_payment?: object | null; - /** - * Possible values "ADDRESS_SERVICE_REQUESTED", "FORWARDING_SERVICE_REQUESTED", "CHANGE_SERVICE_REQUESTED", "RETURN_SERVICE_REQUESTED", "LEAVE_IF_NO_RESPONSE" - */ - endorsement?: - | 'ADDRESS_SERVICE_REQUESTED' - | 'FORWARDING_SERVICE_REQUESTED' - | 'CHANGE_SERVICE_REQUESTED' - | 'RETURN_SERVICE_REQUESTED' - | 'LEAVE_IF_NO_RESPONSE' - | null; - /** - * Specify the responsible EndShipper for the shipment by passing in an EndShipper ID. - */ - end_shipper_id?: string | null; - /** - * Additional cost to be added to the invoice of this shipment. - * Only applies to UPS currently. - */ - freight_charge?: number | null; - /** - * This is to designate special instructions for the carrier like "Do not drop!". - */ - handling_instructions?: string | null; - /** - * Dangerous goods indicator. - * Possible values are "PRIMARY_CONTAINED", "PRIMARY_PACKED", "PRIMARY", "SECONDARY_CONTAINED", "SECONDARY_PACKED", "SECONDARY", "ORMD", "LIMITED_QUANTITY", "LITHIUM". - * Applies to USPS, FedEx and DHL eCommerce. - */ - hazmat?: - | 'PRIMARY_CONTAINED' - | 'PRIMARY_PACKED' - | 'PRIMARY' - | 'SECONDARY_CONTAINED' - | 'SECONDARY_PACKED' - | 'SECONDARY' - | 'ORMD' - | 'LIMITED_QUANTITY' - | 'LITHIUM' - | null; - /** - * Package will wait at carrier facility for pickup. - */ - hold_for_pickup?: boolean | null; - /** - * Incoterm negotiated for shipment. - * Supported values are "EXW", "FCA", "CPT", "CIP", "DAT", "DAP", "DDP", "FAS", "FOB", "CFR", and "CIF". - * Setting this value to anything other than "DDP" will pass the cost and responsibility of duties on to the recipient of the package(s), as specified by Incoterms rules - */ - incoterm?: - | 'EXW' - | 'FCA' - | 'CPT' - | 'CIP' - | 'DAT' - | 'DAP' - | 'DDP' - | 'FAS' - | 'FOB' - | 'CFR' - | 'CIF' - | null; - /** - * This will print an invoice number on the postage label. - */ - invoice_number?: string | null; - /** - * Set the date that will appear on the postage label. - * Accepts ISO 8601 formatted string including time zone offset. - * EasyPost stores all dates as UTC time. - */ - label_date?: string | null; - /** - * Supported label formats include "PNG", "PDF", "ZPL", and "EPL2". - * "PNG" is the only format that allows for conversion. - * - * @see https://www.easypost.com/docs/api#convert-the-label-format-of-a-shipment - */ - label_format?: LabelFormat | null; - /** - * Whether or not the parcel can be processed by the carriers equipment. - */ - machinable?: boolean | null; - /** - * Setting payment type to bill the correct account for purchasing postage. - */ - payment?: { - /** - * Supported values are "SENDER", "THIRD_PARTY", "RECEIVER", "COLLECT". Defaults to SENDER. - */ - type?: 'SENDER' | 'THIRD_PARTY' | 'RECEIVER' | 'COLLECT' | null; - /** - * Setting account number. - * Required for RECEIVER and THIRD_PARTY. - */ - account?: string | null; - /** - * Setting country code that the account is based in. - * Required for THIRD_PARTY. - */ - country?: string | null; - /** - * Setting postal code that the account is based in. - * Required for RECEIVER and THIRD_PARTY. - */ - postal_code?: string | null; - }; - /** - * The earliest a package should be picked up. Supported carriers vary. - */ - pickup_min_datetime?: string | null; - /** - * The latest a package should be picked up. Supported carriers vary. - */ - pickup_man_datetime?: string | null; - /** - * You can optionally print custom messages on labels. - * The locations of these fields show up on different spots on the carrier's labels. - */ - print_custom_1?: string | null; - /** - * An additional message on the label. Same restrictions as print_custom_1 - */ - print_custom_2?: string | null; - /** - * An additional message on the label. Same restrictions as print_custom_1 - */ - print_custom_3?: string | null; - /** - * Create a barcode for this custom reference if supported by carrier. - */ - print_custom_1_barcode?: boolean | null; - /** - * Create a barcode for this custom reference if supported by carrier. - */ - print_custom_2_barcode?: boolean | null; - /** - * Create a barcode for this custom reference if supported by carrier. - */ - print_custom_3_barcode?: boolean | null; - /** - * Specify the type of print_custom_1. - */ - print_custom_1_code?: TPrintCustomCode | null; - /** - * Specify the type of print_custom_2. - */ - print_custom_2_code?: TPrintCustomCode | null; - /** - * Specify the type of print_custom_3. - */ - print_custom_3_code?: TPrintCustomCode | null; - /** - * Set this value to true for delivery on Saturday. - * When setting the saturday_delivery option, you will only get rates for services that are eligible for saturday delivery. - * If no services are available for saturday delivery, then you will not be returned any rates. - * You may need to create 2 shipments, one with the saturday_delivery option set on one without to get all your eligible rates. - */ - saturday_delivery?: boolean | null; - /** - * This option allows you to request restrictive rates from USPS. - * Can set to 'USPS.MEDIAMAIL' or 'USPS.LIBRARYMAIL'. - */ - special_rates_eligibility?: 'USPS.MEDIAMAIL' | 'USPS.LIBRARYMAIL' | null; - /** - * You can use this to override the hub ID you have on your account. - */ - smartpost_hub?: string | null; - /** - * The manifest ID is used to group SmartPost packages onto a manifest for each trailer. - */ - smartpost_manifest?: string | null; - /** - * A reference ID for aggregating DHL eCommerce billing data. - */ - billing_ref?: string | null; - /** - * Certified Mail provides the sender with a mailing receipt and, upon request, electronic verification that an article was delivered or that a delivery attempt was made. - */ - certified_mail?: boolean | null; - /** - * Registered Mail is the most secure service that the USPS offers. - * It incorporates a system of receipts to monitor the movement of the mail from the point of acceptance to delivery - */ - registered_mail?: boolean | null; - /** - * The value of the package contents - */ - registered_mail_amount?: number | null; - /** - * An electronic return receipt may be purchased at the time of mailing and provides a shipper with evidence of delivery (to whom the mail was delivered and date of delivery), and information about the recipient's actual delivery address. - * Only applies to the USPS. - */ - return_receipt?: boolean | null; -}; diff --git a/types/src/services/shipment_service/Options/PrintCustomCode.d.ts b/types/src/services/shipment_service/Options/PrintCustomCode.d.ts deleted file mode 100644 index 4933056eb..000000000 --- a/types/src/services/shipment_service/Options/PrintCustomCode.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -/** - * - FedEx - * - (null) - If print_custom_1_code is not provided it defaults to Customer Reference - * - PO - Purchase Order Number - * - DP - Department Number - * - RMA - Return Merchandise Authorization - * - UPS - * - AJ - Accounts Receivable Customer Account - * - AT - Appropriation Number - * - BM - Bill of Lading Number - * - 9V - Collect on Delivery (COD) Number - * - ON - Dealer Order Number - * - DP - Department Number - * - 3Q - Food and Drug Administration (FDA) Product Code - * - IK - Invoice Number - * - MK - Manifest Key Number - * - MJ - Model Number - * - PM - Part Number - * - PC - Production Code - * - PO - Purchase Order Number - * - RQ - Purchase Request Number - * - RZ - Return Authorization Number - * - SA - Salesperson Number - * - SE - Serial Number - * - ST - Store Number - * - TN - Transaction Reference Number - * - EI - Employer's ID Number - * - TJ - Federal Taxpayer ID No. - */ -export declare type TPrintCustomCode = - | 'PO' - | 'DP' - | 'RMA' - | 'AJ' - | 'AT' - | 'BM' - | '9V' - | 'ON' - | '3Q' - | 'IK' - | 'MK' - | 'MJ' - | 'PM' - | 'PC' - | 'RQ' - | 'RZ' - | 'SA' - | 'SE' - | 'ST' - | 'TN' - | 'EI' - | 'TJ'; diff --git a/types/src/services/shipment_service/Options/index.d.ts b/types/src/services/shipment_service/Options/index.d.ts deleted file mode 100644 index 349426b0d..000000000 --- a/types/src/services/shipment_service/Options/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './LabelFormat'; -export * from './Options'; -export * from './PrintCustomCode'; diff --git a/types/src/services/shipment_service/PostageLabel.d.ts b/types/src/services/shipment_service/PostageLabel.d.ts deleted file mode 100644 index 0d0b2fdf6..000000000 --- a/types/src/services/shipment_service/PostageLabel.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -/** - * PostageLabel Object - */ -export type IPostageLabel = IObjectWithId<'PostageLabel'> & - IDatedObject & { - date_advance: number; - integrated_form: string; - label_date: string; - label_resolution: number; - label_size: string; - label_type: string; - label_url: string; - label_file_type: string; - label_pdf_url: string; - label_epl2_url: string; - label_zpl_url: string; - }; diff --git a/types/src/services/shipment_service/Shipment.d.ts b/types/src/services/shipment_service/Shipment.d.ts deleted file mode 100644 index 80f7b4292..000000000 --- a/types/src/services/shipment_service/Shipment.d.ts +++ /dev/null @@ -1,124 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { IAddress } from '../address_service'; -import { TBatchStatus } from '../batch_service'; -import { ICustomsInfo } from '../customs_info_service'; -import { IFee, IInsurance } from '../insurance_service'; -import { IParcel } from '../parcel_service'; -import { IRate } from '../rate_service'; -import { IScanForm } from '../scan_form_service'; -import { ITracker } from '../tracker_service'; -import { IForm } from './Form'; -import { IMessage } from './Message'; -import { IOptions } from './Options'; -import { IPostageLabel } from './PostageLabel'; -/** - * The workhorse of the EasyPost API, a Shipment is made up of a "to" and "from" Address, the Parcel being shipped, and any customs forms required for international deliveries. - * Once created a Shipment object is used to retrieve shipping Rates and purchase a label. - * - * A Shipment created with a valid to_address, from_address, and parcel will automatically populate its rates attribute. - * - * @see https://www.easypost.com/docs/api/node#shipment-object - */ -export type IShipment = IObjectWithId<'Shipment'> & - IDatedObject & { - /** - * An optional field that may be used in place of id in other API endpoints - */ - reference?: string | null; - /** - * The destination address - */ - to_address: IAddress; - /** - * The origin address - */ - from_address: IAddress; - /** - * The shipper's address, defaults to from_address - */ - return_address?: IAddress | null; - /** - * The buyer's address, defaults to to_address - */ - buyer_address?: IAddress | null; - /** - * The dimensions and weight of the package - */ - parcel: IParcel; - /** - * Information for the processing of customs - */ - customs_info?: ICustomsInfo | null; - /** - * Document created to manifest and scan multiple shipments - */ - scan_form: IScanForm; - /** - * All associated Form objects - */ - forms: IForm[]; - /** - * The associated Insurance object - */ - insurance: IInsurance; - /** - * All associated Rate objects - */ - rates: IRate[]; - /** - * The specific rate purchased for the shipment, or null if unpurchased or purchased through another mechanism - */ - selected_rate: IRate; - /** - * The associated PostageLabel object - */ - postage_label: IPostageLabel; - /** - * Any carrier errors encountered during rating, discussed in more depth below - */ - messages: IMessage[]; - /** - * All the options passed to the shipment, discussed in more depth below - */ - options?: IOptions | null; - /** - * Set true to create as a return, discussed in more depth below - */ - is_return?: boolean | null; - /** - * If purchased, the tracking code will appear here as well as within the Tracker object - */ - tracking_code: string; - /** - * The USPS zone of the shipment, if purchased with USPS - */ - usps_zone: string; - /** - * The current tracking status of the shipment - */ - status: string; - /** - * The associated Tracker object - */ - tracker: ITracker; - /** - * The associated Fee objects charged to the billing user account - */ - fees: IFee[]; - /** - * The current status of the shipment refund process. Possible values are "submitted", "refunded", "rejected". - */ - refund_status: 'submitted' | 'refunded' | 'rejected'; - /** - * The ID of the batch that contains this shipment, if any - */ - batch_id: string; - /** - * The current status of the associated BatchShipment - */ - batch_status: TBatchStatus; - /** - * The current message of the associated BatchShipment - */ - batch_message: string; - }; diff --git a/types/src/services/shipment_service/ShipmentCreateParameters.d.ts b/types/src/services/shipment_service/ShipmentCreateParameters.d.ts deleted file mode 100644 index 4b690eead..000000000 --- a/types/src/services/shipment_service/ShipmentCreateParameters.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { DeepPartial } from '../../utils/types'; -import { IAddressCreateParameters } from '../address_service'; -import { ICustomsInfo } from '../customs_info_service'; -import { IParcelCreateParameters } from '../parcel_service'; -import { IOptions } from './Options'; -export type IShipmentCreateParameters = { - reference?: string | null; - to_address: DeepPartial | string; - from_address: DeepPartial | string; - parcel: Partial | string; - /** - * optional array of ids that begin with "ca_" - */ - carrier_accounts?: string[] | null; - customs_info?: DeepPartial | null; - options?: DeepPartial | null; -}; diff --git a/types/src/services/shipment_service/ShipmentListParameters.d.ts b/types/src/services/shipment_service/ShipmentListParameters.d.ts deleted file mode 100644 index c875985b8..000000000 --- a/types/src/services/shipment_service/ShipmentListParameters.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments - */ -export type IShipmentListParameters = IAllMethodParameters & { - /** - * Only include Shipments that have been purchased. - * Default is true - */ - purchased?: boolean; - /** - * Also include Shipments created by Child Users. - * Defaults to false - */ - include_children?: boolean; -}; diff --git a/types/src/services/shipment_service/index.d.ts b/types/src/services/shipment_service/index.d.ts deleted file mode 100644 index 0d14ecb05..000000000 --- a/types/src/services/shipment_service/index.d.ts +++ /dev/null @@ -1,605 +0,0 @@ -import EasyPost from '../..'; -import { IRate, ISmartRate } from '../rate_service'; -import { IOptions, LabelFormat } from './Options'; -import { IShipmentCreateParameters } from './ShipmentCreateParameters'; -import { IShipmentListParameters } from './ShipmentListParameters'; -export * from './Form'; -export * from './Message'; -export * from './PostageLabel'; -export * from './Shipment'; -export * from './ShipmentCreateParameters'; -export * from './ShipmentListParameters'; -export * from './Options'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#create-a-shipment EasyPost API Documentation} for more information. - * @param params - The parameters to create a shipment with. - * @returns - The created shipment. - */ - create(params: IShipmentCreateParameters): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */ - buy( - id: string, - rate: IRate | string, - insuranceAmount?: number | null, - endShipperId?: string | null, - ): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Convert the label format of a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#convert-the-label-format-of-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to convert the label format of. - * @param format - The format to convert the label to. - * @returns - The shipment with the converted label format. - */ - convertLabelFormat( - id: string, - format: LabelFormat, - ): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Regenerate {@link Rate rates} for a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#regenerate-rates-for-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to regenerate rates for. - * @returns - The shipment with regenerated rates. - */ - regenerateRates(id: string): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Get SmartRates for a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-time-in-transit-statistics-across-all-rates-for-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to get SmartRates for. - * @returns - The SmartRates for the shipment. - */ - getSmartRates(id: string): Promise>; - /** - * Insure a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#insure-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to insure. - * @param amount - The amount to insure the shipment for. - * @returns - The insured shipment. - */ - insure( - id: string, - amount: number | string, - ): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Generate a form for a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#create-form EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to generate a form for. - * @param formType - The type of form to generate. - * @param [formOptions] - Options for the form. - * @returns - The shipment with the generated form attached. - */ - generateForm( - id: string, - formType: string, - formOptions?: IOptions, - ): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Refund a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#refund-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to refund. - * @returns - The refunded shipment. - */ - refund(id: string): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Get the lowest SmartRate of a shipment. - * @param id - The ID of the shipment to get the lowest SmartRate of. - * @param deliveryDays - The number of days the shipment will take to deliver. - * @param deliveryAccuracy - The accuracy of the delivery days. - * @returns - The lowest SmartRate of the shipment. - */ - lowestSmartRate( - id: string, - deliveryDays: number, - deliveryAccuracy: keyof ISmartRate['time_in_transit'], - ): Promise; - /** - * Retrieve all {@link Shipment shipments} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-shipments EasyPost API Documentation} for more information. - * @param [params] - Parameters to filter the shipments by. - * @returns - An object containing a list of {@link Shipment shipments} and pagination information. - */ - all(params?: IShipmentListParameters): Promise<{ - shipments: (import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - })[]; - _params: any; - has_more: boolean; - }>; - /** - * Retrieve the next page of Shipment collection. - * @param shipments An object containing a list of {@link Shipment shipments} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - shipments: { - shipments: any[]; - }, - pageSize?: null, - ): Promise<{ - shipments: (import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - })[]; - _params: any; - has_more: boolean; - }>; - /** - * Retrieve a {@link Shipment shipment} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to retrieve. - * @returns - The shipment with the given ID. - */ - retrieve(id: string): Promise< - import('../../utils/types').IBaseObject<'Shipment'> & { - id: string; - mode: 'test' | 'production'; - object: 'Shipment'; - } & import('../../utils/types').IDatedObject & { - reference?: string | null | undefined; - to_address: import('..').IAddress; - from_address: import('..').IAddress; - return_address?: import('..').IAddress | null | undefined; - buyer_address?: import('..').IAddress | null | undefined; - parcel: import('..').IParcel - /** - * Purchase a {@link Shipment shipment}. - * See {@link https://www.easypost.com/docs/api/node#buy-a-shipment EasyPost API Documentation} for more information. - * @param id - The ID of the shipment to purchase. - * @param rate - The rate to purchase the shipment with. - * @param [insuranceAmount] - The amount of insurance to purchase for the shipment. - * @param [endShipperId] - The ID of the end shipper to purchase the shipment with. - * @returns - The purchased shipment. - */; - customs_info?: import('..').ICustomsInfo | null | undefined; - scan_form: import('..').IScanForm; - forms: import('./Form').IForm[]; - insurance: import('..').IInsurance; - rates: IRate[]; - selected_rate: IRate; - postage_label: import('./PostageLabel').IPostageLabel; - messages: import('./Message').IMessage[]; - options?: IOptions | null | undefined; - is_return?: boolean | null | undefined; - tracking_code: string; - usps_zone: string; - status: string; - tracker: import('..').ITracker; - fees: import('..').IFee[]; - refund_status: 'submitted' | 'refunded' | 'rejected'; - batch_id: string; - batch_status: import('..').TBatchStatus; - batch_message: string; - } & { - lowestRate: (carriers?: string[] | undefined, services?: string[] | undefined) => IRate; - } - >; - /** - * Retrieves the estimated delivery date of each Rate via SmartRate. - * @param id - * @param plannedShipDate - * @returns - An array of the estimated delivery date and rates. - */ - retrieveEstimatedDeliveryDate( - id: string, - plannedShipDate: string, - ): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/tracker_service/CarrierDetail.d.ts b/types/src/services/tracker_service/CarrierDetail.d.ts deleted file mode 100644 index 0cbb6a136..000000000 --- a/types/src/services/tracker_service/CarrierDetail.d.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { IBaseObject } from '../../utils/types'; -import { ITrackingLocation } from './TrackingLocation'; -/** - * @see https://www.easypost.com/docs/api/node#carrier-detail-object - */ -export type ICarrierDetail = IBaseObject<'CarrierDetail'> & { - /** - * The service level the associated shipment was shipped with (if available) - */ - service: string; - /** - * The type of container the associated shipment was shipped in (if available) - */ - container_type: string; - /** - * The estimated delivery date as provided by the carrier, in the local time zone (if available) - */ - est_delivery_date_local: string; - /** - * The estimated delivery time as provided by the carrier, in the local time zone (if available) - */ - est_delivery_time_local: string; - /** - * The location from which the package originated, stringified for presentation (if available) - */ - origin_location: string; - /** - * The location from which the package originated, broken down by city/state/country/zip (if available) - */ - origin_tracking_location: ITrackingLocation; - /** - * The location to which the package is being sent, stringified for presentation (if available) - */ - destination_location: string; - /** - * The location to which the package is being sent, broken down by city/state/country/zip (if available) - */ - destination_tracking_location: ITrackingLocation; - /** - * The date and time the carrier guarantees the package to be delivered by (if available) - */ - guaranteed_delivery_date: string; - /** - * The alternate identifier for this package as provided by the carrier (if available) - */ - alternate_identifier: string; - /** - * The date and time of the first attempt by the carrier to deliver the package (if available) - */ - initial_delivery_attempt: string; -}; diff --git a/types/src/services/tracker_service/Tracker.d.ts b/types/src/services/tracker_service/Tracker.d.ts deleted file mode 100644 index b601dc6c2..000000000 --- a/types/src/services/tracker_service/Tracker.d.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { IDatedObject, IObjectWithId } from '../../utils/types'; -import { IFee } from '../insurance_service'; -import { ICarrierDetail } from './CarrierDetail'; -import { ITrackerStatus } from './TrackerStatus'; -import { ITrackerStatusDetail } from './TrackerStatusDetail'; -import { ITrackingDetail } from './TrackingDetail'; -/** - * A Tracker object contains all the tracking information for a package. - * A Tracker is created automatically whenever you buy a Shipment through EasyPost. - * If you don't use EasyPost to purchase your shipping labels, you can still track packages through our API by creating a Tracker object directly. - * Each Tracker is continually updated in the background as the package moves through its life cycle, regardless of whether or not the label was purchased through EasyPost. - * - * After creation, a Tracker object will be updated periodically based on when the carrier provides EasyPost with new tracking information. - * This information can be consumed by using our webhooks infrastructure. - * Every time a Tracker is updated a webhook Event will be sent. - * - * The Tracker object contains both the current information about the package and previous updates. - * All the previous updates are stored in the tracking_details array. - * Each TrackingDetail object contains the status, the message from the carrier, and a TrackingLocation. - * - * The TrackingLocation contains city, state, country, and zip information about the location where the package was scanned. - * The information each carrier provides is different, so some carriers may not make use of all these fields. - * - * Some Tracker objects may also contain a CarrierDetail, which stores some additional information about the Tracker that the carrier has made available to EasyPost. - * The CarrierDetail object contains the service and container_type of the package. - * Additionally, it also stores the `est_delivery_date_local` and `est_delivery_time_local`, which provide information about the local delivery time. - * - * It's worth noting that tracking_codes are not globally unique. - * Each carrier promises uniqueness for a given `tracking_code` for a certain period of time, but the length of time varies greatly based on the specific carrier and service level. - * The carriers do eventually recycle `tracking_codes`, and for this reason enforcing uniqueness on the `tracking_code` field is not recommended. - * EasyPost does, however, prevent the creation of duplicate Trackers based on tracking_code and carrier; duplicate requests by the same User will simply return the original Tracker. - * - * @see https://www.easypost.com/docs/api/node#tracker-object - */ -export type ITracker = IObjectWithId<'Tracker'> & - IDatedObject & { - /** - * The tracking code provided by the carrier - */ - tracking_code: string; - /** - * The current status of the package, possible values are "unknown", "pre_transit", "in_transit", "out_for_delivery", "delivered", "available_for_pickup", "return_to_sender", "failure", "cancelled" or "error" - */ - status: ITrackerStatus; - /** - * Additional details about the current status, possible values are "unknown", "status_update", "departed_facility", "arrived_at_facility", "out_for_delivery", "arrived_at_destination" - */ - status_detail: ITrackerStatusDetail; - /** - * The name of the person who signed for the package (if available) - */ - signed_by: string; - /** - * The weight of the package as measured by the carrier in ounces (if available) - * float (oz) - */ - weight: number; - /** - * The estimated delivery date provided by the carrier (if available) - */ - est_delivery_date: string; - /** - * The id of the EasyPost Shipment object associated with the Tracker (if any) - */ - shipment_id: string; - /** - * The name of the carrier handling the shipment - */ - carrier: string; - /** - * Array of the associated TrackingDetail objects - */ - tracking_details: ITrackingDetail[]; - /** - * The associated CarrierDetail object (if available) - */ - carrier_detail: ICarrierDetail; - /** - * URL to a publicly-accessible html page that shows tracking details for this tracker - */ - public_url: string; - /** - * Array of the associated Fee objects - */ - fees: IFee[]; - }; diff --git a/types/src/services/tracker_service/TrackerCreateParameters.d.ts b/types/src/services/tracker_service/TrackerCreateParameters.d.ts deleted file mode 100644 index 242a3fcec..000000000 --- a/types/src/services/tracker_service/TrackerCreateParameters.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export type ITrackerCreateParameters = { - /** - * The tracking code associated with the package you'd like to track - */ - tracking_code: string; - /** - * The carrier associated with the tracking_code you provided. - * The carrier will get auto-detected if none is provided - */ - carrier?: string; -}; diff --git a/types/src/services/tracker_service/TrackerListParameters.d.ts b/types/src/services/tracker_service/TrackerListParameters.d.ts deleted file mode 100644 index 0a831d83f..000000000 --- a/types/src/services/tracker_service/TrackerListParameters.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -export type ITrackerListParameters = IAllMethodParameters & { - /** - * Only returns Trackers with the given tracking_code. - * Useful for retrieving an individual Tracker by tracking_code rather than by ID - */ - tracking_code?: string; - /** - * Only returns Trackers with the given carrier value - */ - carrier?: string; -}; diff --git a/types/src/services/tracker_service/TrackerStatus.d.ts b/types/src/services/tracker_service/TrackerStatus.d.ts deleted file mode 100644 index 11b490ca1..000000000 --- a/types/src/services/tracker_service/TrackerStatus.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export type ITrackerStatus = - | 'unknown' - | 'pre_transit' - | 'in_transit' - | 'out_for_delivery' - | 'delivered' - | 'available_for_pickup' - | 'return_to_sender' - | 'failure' - | 'cancelled' - | 'error'; diff --git a/types/src/services/tracker_service/TrackerStatusDetail.d.ts b/types/src/services/tracker_service/TrackerStatusDetail.d.ts deleted file mode 100644 index d36c4690c..000000000 --- a/types/src/services/tracker_service/TrackerStatusDetail.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -export type ITrackerStatusDetail = - | 'address_correction' - | 'arrived_at_destination' - | 'arrived_at_facility' - | 'arrived_at_pickup_location' - | 'awaiting_information' - | 'cancelled' - | 'damaged' - | 'delayed' - | 'delivery_exception' - | 'departed_facility' - | 'departed_origin_facility' - | 'expired' - | 'failure' - | 'held' - | 'in_transit' - | 'label_created' - | 'lost' - | 'missorted' - | 'out_for_delivery' - | 'received_at_destination_facility' - | 'received_at_origin_facility' - | 'refused' - | 'return' - | 'status_update' - | 'transferred_to_destination_carrier' - | 'transit_exception' - | 'unknown' - | 'weather_delay'; diff --git a/types/src/services/tracker_service/TrackingDetail.d.ts b/types/src/services/tracker_service/TrackingDetail.d.ts deleted file mode 100644 index c214f1d78..000000000 --- a/types/src/services/tracker_service/TrackingDetail.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { IBaseObject } from '../../utils/types'; -import { ITrackerStatus } from './TrackerStatus'; -import { ITrackingLocation } from './TrackingLocation'; -/** - * @see https://www.easypost.com/docs/api/node#tracking-detail-object - */ -export type ITrackingDetail = IBaseObject<'TrackingDetail'> & { - /** - * Description of the scan event - */ - message: string; - /** - * Status of the package at the time of the scan event, possible values are "unknown", "pre_transit", "in_transit", "out_for_delivery", "delivered", "available_for_pickup", "return_to_sender", "failure", "cancelled" or "error" - */ - status: ITrackerStatus; - /** - * The timestamp when the tracking scan occurred - */ - datetime: string; - /** - * The original source of the information for this scan event, usually the carrier - */ - source: string; - /** - * The location associated with the scan event - */ - tracking_location: ITrackingLocation; -}; diff --git a/types/src/services/tracker_service/TrackingLocation.d.ts b/types/src/services/tracker_service/TrackingLocation.d.ts deleted file mode 100644 index 122522685..000000000 --- a/types/src/services/tracker_service/TrackingLocation.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { IBaseObject } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#tracking-location-object - */ -export type ITrackingLocation = IBaseObject<'TrackingLocation'> & { - /** - * The city where the scan event occurred (if available) - */ - city: string; - /** - * The state where the scan event occurred (if available) - */ - state: string; - /** - * The country where the scan event occurred (if available) - */ - country: string; - /** - * The postal code where the scan event occurred (if available) - */ - zip: string; -}; diff --git a/types/src/services/tracker_service/index.d.ts b/types/src/services/tracker_service/index.d.ts deleted file mode 100644 index 10013907e..000000000 --- a/types/src/services/tracker_service/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -import EasyPost from '../..'; -import { ITracker } from './Tracker'; -import { ITrackerCreateParameters } from './TrackerCreateParameters'; -import { ITrackerListParameters } from './TrackerListParameters'; -export * from './CarrierDetail'; -export * from './Tracker'; -export * from './TrackerCreateParameters'; -export * from './TrackerListParameters'; -export * from './TrackerStatus'; -export * from './TrackerStatusDetail'; -export * from './TrackingDetail'; -export * from './TrackingLocation'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Tracker tracker}. - * See {@link https://www.easypost.com/docs/api/node#create-a-tracker EasyPost API Documentation} for more information. - * @param params - The parameters to create a tracker with. - * @returns - The created tracker. - */ - create( - params: ITrackerCreateParameters, - ): Promise>; - /** - * Create multiple {@link Tracker trackers} in a single request. - * See {@link https://www.easypost.com/docs/api/node#trackers EasyPost API Documentation} for more information. - * @param [params] - The parameters to create trackers with. - */ - createList(params?: ITrackerCreateParameters[]): Promise; - /** - * Retrieve all {@link Tracker trackers} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-trackers EasyPost API Documentation} for more information. - * @param [params] - The parameters to filter the trackers by. - * @returns - An object containing the list of {@link Tracker trackers} and pagination information. - */ - all(params?: ITrackerListParameters): Promise< - { - trackers: ITracker[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve the next page of Tracker collection. - * @param trackers An object containing a list of {@link Tracker trackers} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - trackers: { - trackers: any[]; - }, - pageSize?: number | null, - ): Promise< - { - trackers: ITracker[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link Tracker tracker} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-tracker EasyPost API Documentation} for more information. - * @param id - The ID of the tracker to retrieve. - * @returns - The retrieved tracker. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/user_service/Brand.d.ts b/types/src/services/user_service/Brand.d.ts deleted file mode 100644 index fd0fc15a4..000000000 --- a/types/src/services/user_service/Brand.d.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { IObjectWithId } from '../../utils/types'; -/** - * The Brand class represents the public-accessible information about a user's brand, including logos, colors and themes. - * - * @see https://www.easypost.com/docs/api/node#brand - */ -export type IBrand = IObjectWithId<'Brand'> & { - /** - * The background color of the brand, as a hex code. - */ - background_color: string; - /** - * The primary color of the brand, as a hex code. - */ - color: string; - /** - * The logo of the brand, as a base64-encoded PNG, GIF, JPEG or SVG. - */ - logo: string; - /** - * The URL of the brand's logo. - */ - logo_href: string; - /** - * The banner ad of the brand, as a base64-encoded PNG, GIF, JPEG or SVG. - */ - ad: string; - /** - * The URL of the brand's banner ad. - */ - ad_href: string; - /** - * The ID of the brand's associated User. - */ - user_id: string; - /** - * The name of the current theme. - */ - theme: 'theme1' | 'theme2'; -}; diff --git a/types/src/services/user_service/User.d.ts b/types/src/services/user_service/User.d.ts deleted file mode 100644 index af274970f..000000000 --- a/types/src/services/user_service/User.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { IObjectWithId } from '../../utils/types'; -/** - * The User object can be used to manage your own account and to create child accounts. - * Only a Production mode API key can be used to make requests against the Users API. - * - * Balance and recharge values on User objects are expressed in higher precision USD. - * - * @see https://www.easypost.com/docs/api/node#user-object - */ -export type IUser = IObjectWithId<'User'> & { - /** - * The ID of the parent user object. - * Top-level users are defined as users with no parent - */ - parent_id: string; - /** - * First and last name required - */ - name: string; - /** - * Required - */ - email: string; - /** - * Optional - */ - phone_number?: string | null; - /** - * Formatted as string "XX.XXXXX" - */ - balance: string; - /** - * Cost per shipment purchase, formatted as string "XX.XXXXX" - */ - price_per_shipment: string; - /** - * USD formatted dollars and cents, delimited by a decimal point - */ - recharge_amount: string; - /** - * USD formatted dollars and cents, delimited by a decimal point - */ - secondary_recharge_amount: string; - /** - * Number of cents USD that when your balance drops below, we automatically recharge your account with your primary payment method. - */ - recharge_threshold: string; - /** - * The fee rate for convenience fees - */ - cc_fee_rate: string; - /** - * The fee rate for insurance purchases - */ - insurance_fee_rate: string; - /** - * The minimum cost for insurance purchases - */ - insurance_fee_minimum: string; - /** - * All associated children - */ - children: IUser[]; -}; diff --git a/types/src/services/user_service/UserCreateParameters.d.ts b/types/src/services/user_service/UserCreateParameters.d.ts deleted file mode 100644 index 78113251c..000000000 --- a/types/src/services/user_service/UserCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ParametersToOmitOnCreate } from '../../utils/types'; -import { IUser } from './User'; -export type IUserCreateParameters = Omit; diff --git a/types/src/services/user_service/index.d.ts b/types/src/services/user_service/index.d.ts deleted file mode 100644 index bd4afc937..000000000 --- a/types/src/services/user_service/index.d.ts +++ /dev/null @@ -1,126 +0,0 @@ -import EasyPost from '../..'; -import { IBrand } from './Brand'; -import { IUser } from './User'; -import { IUserCreateParameters } from './UserCreateParameters'; -export * from './Brand'; -export * from './User'; -export * from './UserCreateParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link User child user}. - * See {@link https://www.easypost.com/docs/api/node#create-a-child-user EasyPost API Documentation} for more information. - * @param params - The parameters to create a child user with. - * @returns - The created child user. - */ - create(params: IUserCreateParameters): Promise>; - /** - * Update a {@link User user}. - * See {@link https://www.easypost.com/docs/api/node#update-a-user EasyPost API Documentation} for more information. - * @param id - The ID of the user to update (either the current authenticated user or a child user). - * @param params - The parameters to update the user with. - * @returns - The updated user. - */ - update( - id: string, - params: Partial, - ): Promise>; - /** - * Retrieve a {@link User child user}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-user EasyPost API Documentation} for more information. - * @param id - The ID of the child user to retrieve. - * @returns - The retrieved child user. - */ - retrieve(id: string): Promise>; - /** - * Retrieve the {@link User current authenticated user}. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-user EasyPost API Documentation} for more information. - * @returns - The retrieved user. - */ - retrieveMe(): Promise>; - /** - * Delete a {@link User child user}. - * See {@link https://www.easypost.com/docs/api/node#delete-a-child-user EasyPost API Documentation} for more information. - * @param id - The ID of the child user to delete. - * @returns - A promise that resolves when the child user is deleted successfully. - */ - delete(id: string): Promise; - /** - * Update the brand of a {@link User user}. - * See {@link https://www.easypost.com/docs/api/node#update-a-brand EasyPost API Documentation} for more information. - * @param id - The ID of the user to update the brand of. - * @param params - The parameters to update the brand with. - * @returns - The updated brand. - */ - updateBrand( - id: string, - params: Partial, - ): Promise>; - /** - * Retrieve a paginated list of children user {@link User user}. - * See {@link https://www.easypost.com/docs/api/node#child-users EasyPost API Documentation} for more information. - * @param params - Parameters to filter the list of children users. - * @returns - An object containing a list of {@link Children User} and pagination information. - */ - allChildren(params: any): Promise< - import('../base_service').EasyPostObject<{ - children: IUser[]; - }> - >; - /** - * Retrieve the next page of children collection. - * @param children An object containing a list of {@link Children children} and pagination information. - * @param pageSize The number of records to return on each page - * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. - */ - getNextPage( - children: { - children: any[]; - }, - pageSize?: number | null, - ): Promise< - { - children: IUser[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise> - /** - * Delete a {@link User child user}. - * See {@link https://www.easypost.com/docs/api/node#delete-a-child-user EasyPost API Documentation} for more information. - * @param id - The ID of the child user to delete. - * @returns - A promise that resolves when the child user is deleted successfully. - */; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/services/webhook_service/Webhook.d.ts b/types/src/services/webhook_service/Webhook.d.ts deleted file mode 100644 index a7137ee4e..000000000 --- a/types/src/services/webhook_service/Webhook.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { IObjectWithId } from '../../utils/types'; -/** - * Each Webhook contains the url which EasyPost will notify whenever an object in our system updates. - * Several types of objects are processed asynchronously in the EasyPost system, so whenever an object updates, an Event is sent via HTTP POST to each configured webhook URL. - * The Webhook object provides CRUD operations for all Webhooks. - * - * Currently, our recommended best practice for securing Webhooks involves using basic authentication and HTTPS on your endpoint. - * This will help prevent any altering of any information communicated to you by EasyPost, prevent any third parties from seeing your webhooks in transit, and will prevent any third parties from masquerading as EasyPost and sending fraudulent data. - * EasyPost performs certificate validation and requires any TLS-enabled (HTTPS) webhook recipients to have a certificate signed by a public trusted certification authority. - * We do not support sending webhooks to over SSLv2, SSLv3, or any connection using so-called export-grade ciphers. - * For documentation on how to set up your server with TLS, we recommend Mozilla's guide to Server-Side TLS and Qualys's SSL/TLS deployment best practices guide. - * - * In general, a Webhook's endpoint should return a status code of 2XX. - * A 200 is preferred, but any 2XX status will indicate to our system that the Webhook request was successful. - * Endpoints that return a large volume and rate of failures over a period of time will get automatically disabled by the system; a disabled Webhook can be re-enabled using the Webhook update endpoint. - * - * @see https://www.easypost.com/docs/api/node#webhook-object - */ -export type IWebhook = IObjectWithId<'Webhook'> & { - /** - * http://example.com - */ - url: string; - /** - * the timestamp at which the webhook was most recently disabled (if any) - */ - disabled_at: string; -}; diff --git a/types/src/services/webhook_service/WebhookCreateParameters.d.ts b/types/src/services/webhook_service/WebhookCreateParameters.d.ts deleted file mode 100644 index e5eb2aee2..000000000 --- a/types/src/services/webhook_service/WebhookCreateParameters.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type IWebhookCreateParameters = { - url: string; -}; diff --git a/types/src/services/webhook_service/WebhookListParameters.d.ts b/types/src/services/webhook_service/WebhookListParameters.d.ts deleted file mode 100644 index 4660bde6a..000000000 --- a/types/src/services/webhook_service/WebhookListParameters.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IAllMethodParameters } from '../../utils/types'; -/** - * @see https://www.easypost.com/docs/api/node#list-a-webhooks - */ -export type IWebhookListParameters = IAllMethodParameters; diff --git a/types/src/services/webhook_service/index.d.ts b/types/src/services/webhook_service/index.d.ts deleted file mode 100644 index a1890b6df..000000000 --- a/types/src/services/webhook_service/index.d.ts +++ /dev/null @@ -1,90 +0,0 @@ -import EasyPost from '../..'; -import { IWebhook } from './Webhook'; -import { IWebhookCreateParameters } from './WebhookCreateParameters'; -import { IWebhookListParameters } from './WebhookListParameters'; -export * from './Webhook'; -export * from './WebhookCreateParameters'; -export * from './WebhookListParameters'; -declare const _default: (easypostClient: EasyPost) => { - new (): {}; - /** - * Create a {@link Webhook webhook}. - * See {@link https://www.easypost.com/docs/api/node#create-a-webhook EasyPost API Documentation} for more information. - * @param params - The parameters to create a webhook with. - * @returns - The created webhook. - */ - create( - params: IWebhookCreateParameters, - ): Promise>; - /** - * Update a {@link Webhook webhook}. - * A disabled webhook will be re-enabled if it is updated. - * See {@link https://www.easypost.com/docs/api/node#update-a-webhook EasyPost API Documentation} for more information. - * @param id - The ID of the webhook to update. - * @param params - The parameters to update the webhook with. - * @returns - The updated webhook. - */ - update( - id: string, - params: Partial, - ): Promise>; - /** - * Delete a {@link Webhook webhook}. - * See {@link https://www.easypost.com/docs/api/node#delete-a-webhook EasyPost API Documentation} for more information. - * @param id - The ID of the webhook to delete. - * @returns - A promise that resolves if the webhook was successfully deleted. - */ - delete(id: string): Promise; - /** - * Retrieve all {@link Webhook webhooks} associated with the current authenticated user. - * See {@link https://www.easypost.com/docs/api/node#list-a-webhooks EasyPost API Documentation} for more information. - * @param [params] - * @returns - */ - all(params?: IWebhookListParameters): Promise< - { - webhooks: IWebhook[]; - } & { - _params: any; - } & { - has_more: boolean; - } - >; - /** - * Retrieve a {@link Webhook webhook} by its ID. - * See {@link https://www.easypost.com/docs/api/node#retrieve-a-webhook EasyPost API Documentation} for more information. - * @param id - The ID of the webhook to retrieve. - * @returns - The retrieved webhook. - */ - retrieve(id: string): Promise>; - _convertToEasyPostObject( - response: A, - params?: any, - ): import('../base_service').EasyPostObject; - _create(url: string, params: object): Promise>; - _all( - url: string, - params?: Record, - ): Promise< - A_2 & { - _params: any; - } & { - has_more: boolean; - } - >; - _retrieve(url: string): Promise>; - _getNextPage>( - url: string, - key: keyof A_4, - collection: A_4, - pageSize?: number | null, - optionalParams?: Record, - ): Promise< - A_4 & { - _params: any; - } & { - has_more: boolean; - } - >; -}; -export default _default; diff --git a/types/src/utils/errors/Error.d.ts b/types/src/utils/errors/Error.d.ts deleted file mode 100644 index d1289c644..000000000 --- a/types/src/utils/errors/Error.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { TErrorCode } from './ErrorCode'; -import { IFieldError } from './FieldError'; -/** - * In the event of a client or server error, the response will contain the standard 4xx or 5xx respectively, accompanied by a well-formed JSON body describing the issue, e.g., a required field was omitted, a purchase failed, etc. - * - * Each client library will encapsulate these errors and raise an exception, in addition to other exceptional cases, such as network failures. - * It is recommended to handle exceptions gracefully and to report any issues to support@easypost.com. - * - * @see https://www.easypost.com/docs/api/node#error-object - */ -export type IError = { - /** - * Machine readable description of the problem - */ - code: TErrorCode; - /** - * Human readable description of the problem - */ - message: string; - /** - * Breakdown of errors for specific fields in the request - */ - errors: IFieldError[]; -}; diff --git a/types/src/utils/errors/ErrorCode.d.ts b/types/src/utils/errors/ErrorCode.d.ts deleted file mode 100644 index 04b10d2d1..000000000 --- a/types/src/utils/errors/ErrorCode.d.ts +++ /dev/null @@ -1,173 +0,0 @@ -export type TErrorCode = - | 'ADDRESS.COUNTRY.INVALID' - | 'ADDRESS.PARAMETERS.INVALID_CHARACTER' - | 'ADDRESS.PARAMETERS.INVALID' - | 'ADDRESS.VERIFICATION.FAILURE' - | 'ADDRESS.VERIFICATION.INVALID' - | 'ADDRESS.VERIFICATION.NOT_FOUND' - | 'ADDRESS.VERIFY.CARRIER_INVALID' - | 'ADDRESS.VERIFY.FAILURE' - | 'ADDRESS.VERIFY.INTL_NOT_ENABLED' - | 'ADDRESS.VERIFY.MISSING_CITY_STATE_ZIP' - | 'ADDRESS.VERIFY.MISSING_STREET' - | 'ADDRESS.VERIFY.ONLY_US' - | 'ADDRESS.VERIFY.UNAVAILABLE' - | 'ADDRESS.VERIFY.UPSTREAM_UNAVAILABLE' - | 'BAD_REQUEST' - | 'BANK_ACCOUNT.CHARGE.FAILURE' - | 'BANK_ACCOUNT.VERIFY.FAILURE' - /** - * The typo "FORAMT" is in both the docs and api error response. - * @link https://github.com/EasyPost/easypost-node/pull/156#discussion_r819811282 - */ - | 'BATCH.FILE_FORAMT.INVALID' - | 'BATCH.PARAMS.INVALID' - | 'BATCH.SHIPMENT.MISSING' - | 'BATCH.SHIPMENT.TOO_LARGE' - | 'BATCH.SHIPMENTS.REQUIRED' - | 'BATCH.STATE.ALREADY_PURCHASED' - | 'BATCH.STATE.CREATING' - | 'BATCH.STATE.CREATION_FAILED' - | 'BATCH.STATE.NOT_PURCHASED' - | 'CARRIER_ACCOUNT.INVALID' - | 'CARRIER_ACCOUNT.PARAMETERS.INVALID' - | 'CARRIER_ACCOUNT.REGISTRATION.FAILED' - | 'CARRIER_ACCOUNT.TYPE.EXISTS' - | 'CARRIER_ACCOUNT.TYPE.UNKNOWN' - | 'CONTAINER.DIMENSION.REQUIRED' - | 'CONTAINER.NAME.REQUIRED' - | 'CONTAINER.TYPE.INVALID' - | 'CREDIT_CARD.CHARGE.FAILURE' - | 'CREDIT_CARD.INVALID' - | 'CUSTOMS_INFO.PARAMETERS.INVALID' - | 'CUSTOMS_ITEM.CURRENCY.ONE_CURRENCY_SUPPORTED' - | 'CUSTOMS_ITEM.ORIGIN_COUNTRY.REQUIRED' - | 'CUSTOMS_ITEM.PARAMETERS.INVALID' - | 'DATE.PARSE.FAILURE' - | 'DHLGM.ACCESS_TOKEN.GENERATION_FAILED' - | 'DHLGM.GIRTH_MAX' - | 'DHLGM.LABEL.FAILURE' - | 'DHLGM.LETTER_NOT_SUPPORTED' - | 'DHLGM.NO_ALCOHOL' - | 'DHLGM.NO_INTERNATIONAL' - | 'DHLGM.RATE_TABLE.NOT_FOUND' - | 'DHLGM.RETURN.AUTHORIZATION_NUMBER_REQUIRED' - | 'DHLGM.SCAN_FORM.GENERATION_FAILED' - | 'DOCUMENT.COMMERCIAL_INVOICE.FAILURE' - | 'DOCUMENT.CONVERSION.FAILURE' - | 'EMAIL_VERIFICATION.EXPIRED' - | 'EMAIL_VERIFICATION.NOT_FOUND' - | 'EMAIL_VERIFICATION.USED' - | 'FORBIDDEN' - | 'IMAGE.CONVERSION.FAILURE' - | 'IMAGE.WIDTH.INVALID' - | 'INSURANCE.AMOUNT.ABOVE_MAXIMUM' - | 'INSURANCE.AMOUNT.BELOW_MINIMUM' - | 'INSURANCE.AMOUNT.REQUIRED' - | 'INSURANCE.CREATE.FAILURE' - | 'INSURANCE.PARAMETERS.INVALID' - | 'INSURANCE.PURCHASE.FAILED' - | 'INSURANCE.PURCHASE.NOT_ALLOWED' - | 'INTERNAL_SERVER_ERROR' - | 'ITEM.HEIGHT.REQUIRED' - | 'ITEM.LENGTH.REQUIRED' - | 'ITEM.NAME.REQUIRED' - | 'ITEM.VALUE.REQUIRED' - | 'ITEM.WEIGHT.REQUIRED' - | 'ITEM.WIDTH.REQUIRED' - | 'MODE.CONFLICT' - | 'MODE.UNAUTHORIZED' - | 'NOT_ACCEPTABLE' - | 'NOT_FOUND' - | 'ORDER.CARRIER_ACCOUNTS.CONFLICT' - | 'ORDER.CARRIER.REQUIRED' - | 'ORDER.FROM_ADDRESS.REQUIRED' - | 'ORDER.INVALID' - | 'ORDER.LABEL_DATE.INVALID' - | 'ORDER.OPTIONS.INVALID' - | 'ORDER.PARAMS.REQUIRED' - | 'ORDER.RATE.UNAVAILABLE' - | 'ORDER.SERVICE.REQUIRED' - | 'ORDER.SHIPMENTS.REQUIRED' - | 'ORDER.TO_ADDRESS.REQUIRED' - | 'PARAMETER.FORBIDDEN' - | 'PARAMETER.REQUIRED' - | 'PARCEL.PARAMETERS.INVALID' - | 'PARCEL.PREDEFINED_PACKAGE.INVALID' - | 'PAYMENT_GATEWAY.ERROR' - | 'PAYMENT_REQUIRED' - | 'PICKUP.ADDRESS.INVALID' - | 'PICKUP.ADDRESS.REQUIRED' - | 'PICKUP.BATCH_CARRIER.INCONSISTENT' - | 'PICKUP.BATCH.INVALID' - | 'PICKUP.BATCH.REQUIRED' - | 'PICKUP.BUY.FAILED' - | 'PICKUP.BUY.FORBIDDEN' - | 'PICKUP.BUY.NO_MATCHING_RATES' - | 'PICKUP.CANCEL.FAILED' - | 'PICKUP.CARRIER.REQUIRED' - | 'PICKUP.IS_ACCOUNT_ADDRESS.REQUIRED' - | 'PICKUP.MAX_DATETIME.REQUIRED' - | 'PICKUP.MIN_DATETIME.REQUIRED' - | 'PICKUP.REQUEST.INVALID' - | 'PICKUP.SERVICE.REQUIRED' - | 'PICKUP.SHIPMENT_COUNTRY.INVALID' - | 'PICKUP.SHIPMENT_SERVICE.INVALID' - | 'PICKUP.STATUS.INVALID' - | 'REFUND.FAILURE' - | 'REFUND.NO_RESPONSE' - | 'REFUND.TRACKING_CODE.NOT_FOUND' - | 'REFUND.TRACKING_CODES.INVALID' - | 'SCAN_FORM.BATCH.MULTIPLE_CARRIERS' - | 'SCAN_FORM.BATCH.NOT_PURCHASED' - | 'SCAN_FORM.CREATE.CARRIER_NOT_SUPPORTED' - | 'SCAN_FORM.CREATE.FAILURE' - | 'SCAN_FORM.FAILURE' - | 'SCAN_FORM.SHIPMENTS.INVALID' - | 'SCAN_FORM.SHIPMENTS.REQUIRED' - | 'SHIPMENT_REPORT.ALREADY_IN_PROGRESS' - | 'SHIPMENT_REPORT.DATE_RANGE.INVALID' - | 'SHIPMENT_REPORT.DATE_RANGE.TOO_LONG' - | 'SHIPMENT.CARRIER_ACCOUNTS.CONFLICT' - | 'SHIPMENT.CUSTOMS_INFO.DESCRIPTION_REQUIRED' - | 'SHIPMENT.CUSTOMS_INFO.REQUIRED' - | 'SHIPMENT.INSURANCE.ALREADY_PURCHASED' - | 'SHIPMENT.INVALID_PARAMS' - | 'SHIPMENT.INVALID' - | 'SHIPMENT.MISSING_INFORMATION' - | 'SHIPMENT.MISSING_RATE' - | 'SHIPMENT.OPTIONS.INVALID' - | 'SHIPMENT.POSTAGE.ASCII' - | 'SHIPMENT.POSTAGE.EXISTS' - | 'SHIPMENT.POSTAGE.FAILURE' - | 'SHIPMENT.POSTAGE.FORMAT_UNAVAILABLE' - | 'SHIPMENT.POSTAGE.INVALID_FORMAT' - | 'SHIPMENT.POSTAGE.NO_RESPONSE' - | 'SHIPMENT.POSTAGE.REQUIRED' - | 'SHIPMENT.PURCHASE.FAILURE' - | 'SHIPMENT.PURCHASE.IN_PROGRESS' - | 'SHIPMENT.RATE.BARCODE_UNAVAILABLE' - | 'SHIPMENT.RATE.CARRIER_ACCOUNT_INVALID' - | 'SHIPMENT.RATE.STAMP_UNAVAILABLE' - | 'SHIPMENT.RATES.UNAVAILABLE' - | 'SHIPMENT.REFUND.FAILURE' - | 'SHIPMENT.REFUND.UNAVAILABLE' - | 'SHIPMENT.TRACKING_CODE.INVALID_CARRIER' - | 'TRACKER.CARRIER_CODE_MISMATCH' - | 'TRACKER.CREATE.ERROR' - | 'TRACKER.INVALID_PARAMS' - | 'TRACKER.INVALID_TEST_CODE' - | 'TRACKER.MULTIPLE_CARRIERS_FOR_CODE' - | 'TRACKER.NO_CARRIER_ACCOUNT' - | 'TRACKER.NO_CARRIER_FOR_CODE' - | 'TRACKER.NOT_FOUND' - | 'TRACKER.RETRIEVE.ERROR' - | 'TRACKER.RUN.ERROR' - | 'TRACKER.UNSUPPORTED_CARRIER' - | 'UNAUTHORIZED' - | 'USER.CHARGE.NOT_ALLOWED' - | 'USER.INVALID' - | 'USER.PARENT.INVALID' - | 'USER.UNAUTHORIZED' - | 'WEBHOOK.EVENT.INVALID' - | 'WEBHOOK.INVALID'; diff --git a/types/src/utils/errors/FieldError.d.ts b/types/src/utils/errors/FieldError.d.ts deleted file mode 100644 index e7ae33219..000000000 --- a/types/src/utils/errors/FieldError.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -export type IFieldError = { - /** - * Field of the request that the error describes - */ - field: string; - /** - * Human readable description of the problem - */ - message: string; -}; diff --git a/types/src/utils/errors/index.d.ts b/types/src/utils/errors/index.d.ts deleted file mode 100644 index d6c2ac5d8..000000000 --- a/types/src/utils/errors/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './Error'; -export * from './ErrorCode'; -export * from './FieldError'; diff --git a/types/src/utils/types.d.ts b/types/src/utils/types.d.ts deleted file mode 100644 index 0dd02ce86..000000000 --- a/types/src/utils/types.d.ts +++ /dev/null @@ -1,62 +0,0 @@ -export type DeepPartial = { - [P in keyof T]?: DeepPartial; -}; -export type ParametersToOmitOnCreate = 'id' | 'object' | 'mode' | 'created_at' | 'updated_at'; -export type IAllMethodParameters = { - /** - * Optional pagination parameter. - * Only records created before the given ID will be included. - * May not be used with after_id - */ - before_id?: string; - /** - * Optional pagination parameter. - * Only records created after the given ID will be included. - * May not be used with before_id - */ - after_id?: string; - /** - * Only return records created after this timestamp. - * Defaults to 1 month ago, or 1 month before a passed end_datetime - */ - start_datetime?: string; - /** - * Only return records created before this timestamp. - * Defaults to end of the current day, or 1 month after a passed start_datetime - */ - end_datetime?: string; - /** - * The number of records to return on each page. - * The maximum value is 100 - */ - page_size?: number; -}; -export type IDatedObject = { - /** - * Date ISO String - */ - created_at: string; - /** - * Date ISO String - */ - updated_at: string; -}; -export type IBaseObject = { - object: ObjectName; -}; -export type IObjectWithId = IBaseObject & { - /** - * Unique identifier, begins with "adr_" / "prcl_" / "ins_" / "trk_" / "batch_" / "cstinfo_" / etc - */ - id: string; - /** - * Set based on which api-key you used, either "test" or "production" - */ - mode: 'test' | 'production'; - /** - * The object name, e.g. "Address", "Rate", "Shipment", etc - */ - object: ObjectName; -}; -declare const _default: {}; -export default _default; diff --git a/types/src/utils/util.d.ts b/types/src/utils/util.d.ts deleted file mode 100644 index 31c07616b..000000000 --- a/types/src/utils/util.d.ts +++ /dev/null @@ -1,47 +0,0 @@ -/// -import { IRate, ISmartRate } from '../services/rate_service'; -/** - * Utility class of various publicly-available helper functions. - * @public - * @type {Utils} - */ -export default class Utils { - /** - * Get the lowest SmartRate from a provided list of SmartRates. - * @public - * @param smartRates - List of SmartRates to filter through - * @param deliveryDays - The maximum number of days allowed for delivery - * @param deliveryAccuracy - The target level of accuracy for the delivery days (e.g. 'percentile_50') - * @returns - The lowest SmartRate - * @throws {FilteringError} - If no applicable rates are found - * @throws {InvalidParameterError} - If the deliveryAccuracy value is invalid - */ - getLowestSmartRate( - smartRates: ISmartRate[], - deliveryDays: number, - deliveryAccuracy: keyof ISmartRate['time_in_transit'], - ): ISmartRate; - /** - * Get the lowest rate from a provided list of rates. - * @public - * @param rates - List of rates to filter through - * @param [carriers] - List of allowed carriers to filter by - * @param [services] - List of allowed services to filter by - * @returns - The lowest rate - * @throws {FilteringError} - If no applicable rates are found - */ - getLowestRate(rates: IRate[], carriers?: string[] | null, services?: string[] | null): IRate; - /** - * Validate a webhook by comparing the HMAC signature header sent from EasyPost to your shared secret. - * If the signatures do not match, an error will be raised signifying the webhook either did not originate - * from EasyPost or the secrets do not match. If the signatures do match, the `event_body` will be returned - * as JSON. - * @public - * @param eventBody - The raw body of the webhook event - * @param headers - The headers of the webhook HTTP request - * @param webhookSecret - The webhook secret shared between EasyPost and your application - * @returns - The JSON-parsed webhook event body if the signature could be verified - * @throws {SignatureVerificationError} - If the signature could not be verified - */ - validateWebhook(eventBody: Buffer, headers: Record, webhookSecret: string): any; -} diff --git a/types/utils/errors/Error.d.ts b/types/utils/errors/Error.d.ts deleted file mode 100644 index d1289c644..000000000 --- a/types/utils/errors/Error.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { TErrorCode } from './ErrorCode'; -import { IFieldError } from './FieldError'; -/** - * In the event of a client or server error, the response will contain the standard 4xx or 5xx respectively, accompanied by a well-formed JSON body describing the issue, e.g., a required field was omitted, a purchase failed, etc. - * - * Each client library will encapsulate these errors and raise an exception, in addition to other exceptional cases, such as network failures. - * It is recommended to handle exceptions gracefully and to report any issues to support@easypost.com. - * - * @see https://www.easypost.com/docs/api/node#error-object - */ -export type IError = { - /** - * Machine readable description of the problem - */ - code: TErrorCode; - /** - * Human readable description of the problem - */ - message: string; - /** - * Breakdown of errors for specific fields in the request - */ - errors: IFieldError[]; -}; diff --git a/types/utils/errors/ErrorCode.d.ts b/types/utils/errors/ErrorCode.d.ts deleted file mode 100644 index 04b10d2d1..000000000 --- a/types/utils/errors/ErrorCode.d.ts +++ /dev/null @@ -1,173 +0,0 @@ -export type TErrorCode = - | 'ADDRESS.COUNTRY.INVALID' - | 'ADDRESS.PARAMETERS.INVALID_CHARACTER' - | 'ADDRESS.PARAMETERS.INVALID' - | 'ADDRESS.VERIFICATION.FAILURE' - | 'ADDRESS.VERIFICATION.INVALID' - | 'ADDRESS.VERIFICATION.NOT_FOUND' - | 'ADDRESS.VERIFY.CARRIER_INVALID' - | 'ADDRESS.VERIFY.FAILURE' - | 'ADDRESS.VERIFY.INTL_NOT_ENABLED' - | 'ADDRESS.VERIFY.MISSING_CITY_STATE_ZIP' - | 'ADDRESS.VERIFY.MISSING_STREET' - | 'ADDRESS.VERIFY.ONLY_US' - | 'ADDRESS.VERIFY.UNAVAILABLE' - | 'ADDRESS.VERIFY.UPSTREAM_UNAVAILABLE' - | 'BAD_REQUEST' - | 'BANK_ACCOUNT.CHARGE.FAILURE' - | 'BANK_ACCOUNT.VERIFY.FAILURE' - /** - * The typo "FORAMT" is in both the docs and api error response. - * @link https://github.com/EasyPost/easypost-node/pull/156#discussion_r819811282 - */ - | 'BATCH.FILE_FORAMT.INVALID' - | 'BATCH.PARAMS.INVALID' - | 'BATCH.SHIPMENT.MISSING' - | 'BATCH.SHIPMENT.TOO_LARGE' - | 'BATCH.SHIPMENTS.REQUIRED' - | 'BATCH.STATE.ALREADY_PURCHASED' - | 'BATCH.STATE.CREATING' - | 'BATCH.STATE.CREATION_FAILED' - | 'BATCH.STATE.NOT_PURCHASED' - | 'CARRIER_ACCOUNT.INVALID' - | 'CARRIER_ACCOUNT.PARAMETERS.INVALID' - | 'CARRIER_ACCOUNT.REGISTRATION.FAILED' - | 'CARRIER_ACCOUNT.TYPE.EXISTS' - | 'CARRIER_ACCOUNT.TYPE.UNKNOWN' - | 'CONTAINER.DIMENSION.REQUIRED' - | 'CONTAINER.NAME.REQUIRED' - | 'CONTAINER.TYPE.INVALID' - | 'CREDIT_CARD.CHARGE.FAILURE' - | 'CREDIT_CARD.INVALID' - | 'CUSTOMS_INFO.PARAMETERS.INVALID' - | 'CUSTOMS_ITEM.CURRENCY.ONE_CURRENCY_SUPPORTED' - | 'CUSTOMS_ITEM.ORIGIN_COUNTRY.REQUIRED' - | 'CUSTOMS_ITEM.PARAMETERS.INVALID' - | 'DATE.PARSE.FAILURE' - | 'DHLGM.ACCESS_TOKEN.GENERATION_FAILED' - | 'DHLGM.GIRTH_MAX' - | 'DHLGM.LABEL.FAILURE' - | 'DHLGM.LETTER_NOT_SUPPORTED' - | 'DHLGM.NO_ALCOHOL' - | 'DHLGM.NO_INTERNATIONAL' - | 'DHLGM.RATE_TABLE.NOT_FOUND' - | 'DHLGM.RETURN.AUTHORIZATION_NUMBER_REQUIRED' - | 'DHLGM.SCAN_FORM.GENERATION_FAILED' - | 'DOCUMENT.COMMERCIAL_INVOICE.FAILURE' - | 'DOCUMENT.CONVERSION.FAILURE' - | 'EMAIL_VERIFICATION.EXPIRED' - | 'EMAIL_VERIFICATION.NOT_FOUND' - | 'EMAIL_VERIFICATION.USED' - | 'FORBIDDEN' - | 'IMAGE.CONVERSION.FAILURE' - | 'IMAGE.WIDTH.INVALID' - | 'INSURANCE.AMOUNT.ABOVE_MAXIMUM' - | 'INSURANCE.AMOUNT.BELOW_MINIMUM' - | 'INSURANCE.AMOUNT.REQUIRED' - | 'INSURANCE.CREATE.FAILURE' - | 'INSURANCE.PARAMETERS.INVALID' - | 'INSURANCE.PURCHASE.FAILED' - | 'INSURANCE.PURCHASE.NOT_ALLOWED' - | 'INTERNAL_SERVER_ERROR' - | 'ITEM.HEIGHT.REQUIRED' - | 'ITEM.LENGTH.REQUIRED' - | 'ITEM.NAME.REQUIRED' - | 'ITEM.VALUE.REQUIRED' - | 'ITEM.WEIGHT.REQUIRED' - | 'ITEM.WIDTH.REQUIRED' - | 'MODE.CONFLICT' - | 'MODE.UNAUTHORIZED' - | 'NOT_ACCEPTABLE' - | 'NOT_FOUND' - | 'ORDER.CARRIER_ACCOUNTS.CONFLICT' - | 'ORDER.CARRIER.REQUIRED' - | 'ORDER.FROM_ADDRESS.REQUIRED' - | 'ORDER.INVALID' - | 'ORDER.LABEL_DATE.INVALID' - | 'ORDER.OPTIONS.INVALID' - | 'ORDER.PARAMS.REQUIRED' - | 'ORDER.RATE.UNAVAILABLE' - | 'ORDER.SERVICE.REQUIRED' - | 'ORDER.SHIPMENTS.REQUIRED' - | 'ORDER.TO_ADDRESS.REQUIRED' - | 'PARAMETER.FORBIDDEN' - | 'PARAMETER.REQUIRED' - | 'PARCEL.PARAMETERS.INVALID' - | 'PARCEL.PREDEFINED_PACKAGE.INVALID' - | 'PAYMENT_GATEWAY.ERROR' - | 'PAYMENT_REQUIRED' - | 'PICKUP.ADDRESS.INVALID' - | 'PICKUP.ADDRESS.REQUIRED' - | 'PICKUP.BATCH_CARRIER.INCONSISTENT' - | 'PICKUP.BATCH.INVALID' - | 'PICKUP.BATCH.REQUIRED' - | 'PICKUP.BUY.FAILED' - | 'PICKUP.BUY.FORBIDDEN' - | 'PICKUP.BUY.NO_MATCHING_RATES' - | 'PICKUP.CANCEL.FAILED' - | 'PICKUP.CARRIER.REQUIRED' - | 'PICKUP.IS_ACCOUNT_ADDRESS.REQUIRED' - | 'PICKUP.MAX_DATETIME.REQUIRED' - | 'PICKUP.MIN_DATETIME.REQUIRED' - | 'PICKUP.REQUEST.INVALID' - | 'PICKUP.SERVICE.REQUIRED' - | 'PICKUP.SHIPMENT_COUNTRY.INVALID' - | 'PICKUP.SHIPMENT_SERVICE.INVALID' - | 'PICKUP.STATUS.INVALID' - | 'REFUND.FAILURE' - | 'REFUND.NO_RESPONSE' - | 'REFUND.TRACKING_CODE.NOT_FOUND' - | 'REFUND.TRACKING_CODES.INVALID' - | 'SCAN_FORM.BATCH.MULTIPLE_CARRIERS' - | 'SCAN_FORM.BATCH.NOT_PURCHASED' - | 'SCAN_FORM.CREATE.CARRIER_NOT_SUPPORTED' - | 'SCAN_FORM.CREATE.FAILURE' - | 'SCAN_FORM.FAILURE' - | 'SCAN_FORM.SHIPMENTS.INVALID' - | 'SCAN_FORM.SHIPMENTS.REQUIRED' - | 'SHIPMENT_REPORT.ALREADY_IN_PROGRESS' - | 'SHIPMENT_REPORT.DATE_RANGE.INVALID' - | 'SHIPMENT_REPORT.DATE_RANGE.TOO_LONG' - | 'SHIPMENT.CARRIER_ACCOUNTS.CONFLICT' - | 'SHIPMENT.CUSTOMS_INFO.DESCRIPTION_REQUIRED' - | 'SHIPMENT.CUSTOMS_INFO.REQUIRED' - | 'SHIPMENT.INSURANCE.ALREADY_PURCHASED' - | 'SHIPMENT.INVALID_PARAMS' - | 'SHIPMENT.INVALID' - | 'SHIPMENT.MISSING_INFORMATION' - | 'SHIPMENT.MISSING_RATE' - | 'SHIPMENT.OPTIONS.INVALID' - | 'SHIPMENT.POSTAGE.ASCII' - | 'SHIPMENT.POSTAGE.EXISTS' - | 'SHIPMENT.POSTAGE.FAILURE' - | 'SHIPMENT.POSTAGE.FORMAT_UNAVAILABLE' - | 'SHIPMENT.POSTAGE.INVALID_FORMAT' - | 'SHIPMENT.POSTAGE.NO_RESPONSE' - | 'SHIPMENT.POSTAGE.REQUIRED' - | 'SHIPMENT.PURCHASE.FAILURE' - | 'SHIPMENT.PURCHASE.IN_PROGRESS' - | 'SHIPMENT.RATE.BARCODE_UNAVAILABLE' - | 'SHIPMENT.RATE.CARRIER_ACCOUNT_INVALID' - | 'SHIPMENT.RATE.STAMP_UNAVAILABLE' - | 'SHIPMENT.RATES.UNAVAILABLE' - | 'SHIPMENT.REFUND.FAILURE' - | 'SHIPMENT.REFUND.UNAVAILABLE' - | 'SHIPMENT.TRACKING_CODE.INVALID_CARRIER' - | 'TRACKER.CARRIER_CODE_MISMATCH' - | 'TRACKER.CREATE.ERROR' - | 'TRACKER.INVALID_PARAMS' - | 'TRACKER.INVALID_TEST_CODE' - | 'TRACKER.MULTIPLE_CARRIERS_FOR_CODE' - | 'TRACKER.NO_CARRIER_ACCOUNT' - | 'TRACKER.NO_CARRIER_FOR_CODE' - | 'TRACKER.NOT_FOUND' - | 'TRACKER.RETRIEVE.ERROR' - | 'TRACKER.RUN.ERROR' - | 'TRACKER.UNSUPPORTED_CARRIER' - | 'UNAUTHORIZED' - | 'USER.CHARGE.NOT_ALLOWED' - | 'USER.INVALID' - | 'USER.PARENT.INVALID' - | 'USER.UNAUTHORIZED' - | 'WEBHOOK.EVENT.INVALID' - | 'WEBHOOK.INVALID'; diff --git a/types/utils/errors/FieldError.d.ts b/types/utils/errors/FieldError.d.ts deleted file mode 100644 index e7ae33219..000000000 --- a/types/utils/errors/FieldError.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -export type IFieldError = { - /** - * Field of the request that the error describes - */ - field: string; - /** - * Human readable description of the problem - */ - message: string; -}; diff --git a/types/utils/errors/index.d.ts b/types/utils/errors/index.d.ts deleted file mode 100644 index d6c2ac5d8..000000000 --- a/types/utils/errors/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './Error'; -export * from './ErrorCode'; -export * from './FieldError'; diff --git a/types/utils/types.d.ts b/types/utils/types.d.ts deleted file mode 100644 index 0dd02ce86..000000000 --- a/types/utils/types.d.ts +++ /dev/null @@ -1,62 +0,0 @@ -export type DeepPartial = { - [P in keyof T]?: DeepPartial; -}; -export type ParametersToOmitOnCreate = 'id' | 'object' | 'mode' | 'created_at' | 'updated_at'; -export type IAllMethodParameters = { - /** - * Optional pagination parameter. - * Only records created before the given ID will be included. - * May not be used with after_id - */ - before_id?: string; - /** - * Optional pagination parameter. - * Only records created after the given ID will be included. - * May not be used with before_id - */ - after_id?: string; - /** - * Only return records created after this timestamp. - * Defaults to 1 month ago, or 1 month before a passed end_datetime - */ - start_datetime?: string; - /** - * Only return records created before this timestamp. - * Defaults to end of the current day, or 1 month after a passed start_datetime - */ - end_datetime?: string; - /** - * The number of records to return on each page. - * The maximum value is 100 - */ - page_size?: number; -}; -export type IDatedObject = { - /** - * Date ISO String - */ - created_at: string; - /** - * Date ISO String - */ - updated_at: string; -}; -export type IBaseObject = { - object: ObjectName; -}; -export type IObjectWithId = IBaseObject & { - /** - * Unique identifier, begins with "adr_" / "prcl_" / "ins_" / "trk_" / "batch_" / "cstinfo_" / etc - */ - id: string; - /** - * Set based on which api-key you used, either "test" or "production" - */ - mode: 'test' | 'production'; - /** - * The object name, e.g. "Address", "Rate", "Shipment", etc - */ - object: ObjectName; -}; -declare const _default: {}; -export default _default; diff --git a/types/utils/util.d.ts b/types/utils/util.d.ts deleted file mode 100644 index 31c07616b..000000000 --- a/types/utils/util.d.ts +++ /dev/null @@ -1,47 +0,0 @@ -/// -import { IRate, ISmartRate } from '../services/rate_service'; -/** - * Utility class of various publicly-available helper functions. - * @public - * @type {Utils} - */ -export default class Utils { - /** - * Get the lowest SmartRate from a provided list of SmartRates. - * @public - * @param smartRates - List of SmartRates to filter through - * @param deliveryDays - The maximum number of days allowed for delivery - * @param deliveryAccuracy - The target level of accuracy for the delivery days (e.g. 'percentile_50') - * @returns - The lowest SmartRate - * @throws {FilteringError} - If no applicable rates are found - * @throws {InvalidParameterError} - If the deliveryAccuracy value is invalid - */ - getLowestSmartRate( - smartRates: ISmartRate[], - deliveryDays: number, - deliveryAccuracy: keyof ISmartRate['time_in_transit'], - ): ISmartRate; - /** - * Get the lowest rate from a provided list of rates. - * @public - * @param rates - List of rates to filter through - * @param [carriers] - List of allowed carriers to filter by - * @param [services] - List of allowed services to filter by - * @returns - The lowest rate - * @throws {FilteringError} - If no applicable rates are found - */ - getLowestRate(rates: IRate[], carriers?: string[] | null, services?: string[] | null): IRate; - /** - * Validate a webhook by comparing the HMAC signature header sent from EasyPost to your shared secret. - * If the signatures do not match, an error will be raised signifying the webhook either did not originate - * from EasyPost or the secrets do not match. If the signatures do match, the `event_body` will be returned - * as JSON. - * @public - * @param eventBody - The raw body of the webhook event - * @param headers - The headers of the webhook HTTP request - * @param webhookSecret - The webhook secret shared between EasyPost and your application - * @returns - The JSON-parsed webhook event body if the signature could be verified - * @throws {SignatureVerificationError} - If the signature could not be verified - */ - validateWebhook(eventBody: Buffer, headers: Record, webhookSecret: string): any; -} From 3f2760bdb8210b41ae933041fab4853e46fce258 Mon Sep 17 00:00:00 2001 From: Alex Matthews Date: Wed, 15 May 2024 15:26:55 -0500 Subject: [PATCH 4/7] Got app building right --- .gitignore | 5 ++++- package.json | 4 +++- src/services/address_service/index.ts | 2 +- src/services/api_key_service/index.ts | 2 +- src/services/batch_service/index.ts | 2 +- src/services/beta_rate_service/index.ts | 2 +- src/services/beta_referral_customer_service/index.ts | 2 +- src/services/billing_service/index.ts | 2 +- src/services/carrier_account_service/index.ts | 2 +- src/services/carrier_metadata_service/index.ts | 2 +- src/services/carrier_type_service/index.ts | 2 +- src/services/customs_info_service/index.ts | 2 +- src/services/customs_item_service/index.ts | 2 +- src/services/end_shipper_service/index.ts | 2 +- src/services/event_service/index.ts | 2 +- src/services/insurance_service/index.ts | 2 +- src/services/order_service/index.ts | 2 +- src/services/parcel_service/index.ts | 2 +- src/services/pickup_service/index.ts | 2 +- src/services/rate_service/index.ts | 2 +- src/services/referral_customer_service/index.ts | 2 +- src/services/refund_service/index.ts | 2 +- src/services/report_service/index.ts | 2 +- src/services/scan_form_service/index.ts | 2 +- src/services/shipment_service/index.ts | 2 +- src/services/tracker_service/index.ts | 2 +- src/services/user_service/index.ts | 2 +- src/services/webhook_service/index.ts | 2 +- test/services/report.test.js | 10 +++++----- tsconfig.json | 8 ++++---- webpack.config.babel.js | 6 +++--- 31 files changed, 45 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 146fab08f..9d6b92bb9 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,10 @@ docs Icon node_modules npm-debug.log - +out +out-tmp +types +types-tmp /.eslintrc /.eslintignore /.prettierrc.yml diff --git a/package.json b/package.json index a020aad19..80069e7aa 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,9 @@ "scripts": { "build": "npm run build:typescript && npm run build:webpack", "build:webpack": "webpack --config webpack.config.babel.js", - "build:typescript": "tsc", + "build:typescript": "npm run build:typescript:pre && tsc && npm run build:typescript:post", + "build:typescript:pre": "rm -rf out out-tmp types types-tmp", + "build:typescript:post": "mv out-tmp/src out && mv types-tmp/src types && rm -rf out-tmp types-tmp", "clean": "rm -rf ./dist ./nyc_output ./node_modules/.cache ./coverage", "coverage": "cross-env NODE_ENV=test nyc npm run test", "docs": "./node_modules/.bin/jsdoc src/models src/services src/errors src/utils -d docs", diff --git a/src/services/address_service/index.ts b/src/services/address_service/index.ts index 5247d8ba2..b6d1bd234 100644 --- a/src/services/address_service/index.ts +++ b/src/services/address_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IAddress } from './Address'; import { IAddressCreateParameters } from './AddressCreateParameters'; diff --git a/src/services/api_key_service/index.ts b/src/services/api_key_service/index.ts index 31cda71ba..04106eb6c 100644 --- a/src/services/api_key_service/index.ts +++ b/src/services/api_key_service/index.ts @@ -2,7 +2,7 @@ import util from 'node:util'; import baseService from '../base_service'; import Constants from '../../constants'; import FilteringError from '../../errors/general/filtering_error'; -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import { IApiKey, UserAPIKeys } from './ApiKey'; export * from './ApiKey'; diff --git a/src/services/batch_service/index.ts b/src/services/batch_service/index.ts index 52423a0e8..1aa6823ac 100644 --- a/src/services/batch_service/index.ts +++ b/src/services/batch_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IBatch } from './Batch'; import { IBatchCreateParameters } from './BatchCreateParameters'; diff --git a/src/services/beta_rate_service/index.ts b/src/services/beta_rate_service/index.ts index 85ab989b0..7149736d6 100644 --- a/src/services/beta_rate_service/index.ts +++ b/src/services/beta_rate_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IRate } from '../rate_service/Rate'; diff --git a/src/services/beta_referral_customer_service/index.ts b/src/services/beta_referral_customer_service/index.ts index afe54ed85..4d188b7b1 100644 --- a/src/services/beta_referral_customer_service/index.ts +++ b/src/services/beta_referral_customer_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IPaymentMethod } from '../billing_service'; import { IRefund } from '../refund_service'; diff --git a/src/services/billing_service/index.ts b/src/services/billing_service/index.ts index a24ca08e2..07fc7b5c8 100644 --- a/src/services/billing_service/index.ts +++ b/src/services/billing_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import Constants from '../../constants'; import InvalidObjectError from '../../errors/general/invalid_object_error'; import baseService from '../base_service'; diff --git a/src/services/carrier_account_service/index.ts b/src/services/carrier_account_service/index.ts index 1679da9cb..7d44676d2 100644 --- a/src/services/carrier_account_service/index.ts +++ b/src/services/carrier_account_service/index.ts @@ -2,7 +2,7 @@ import util from 'node:util'; import baseService from '../base_service'; import Constants from '../../constants'; import InvalidParameterError from '../../errors/general/invalid_parameter_error'; -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import { ICarrierAccount } from './CarrierAccount'; import { ICarrierAccountCreateParameters } from './CarrierAccountCreateParameters'; diff --git a/src/services/carrier_metadata_service/index.ts b/src/services/carrier_metadata_service/index.ts index 16c6b709c..8002fe99e 100644 --- a/src/services/carrier_metadata_service/index.ts +++ b/src/services/carrier_metadata_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { ICarrierMetadata } from './CarrierMetadata'; diff --git a/src/services/carrier_type_service/index.ts b/src/services/carrier_type_service/index.ts index e24efdaba..a39ffe819 100644 --- a/src/services/carrier_type_service/index.ts +++ b/src/services/carrier_type_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { ICarrierType } from './CarrierType'; diff --git a/src/services/customs_info_service/index.ts b/src/services/customs_info_service/index.ts index 94e4a34a7..0626077fd 100644 --- a/src/services/customs_info_service/index.ts +++ b/src/services/customs_info_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { ICustomsInfo } from './CustomsInfo'; import { ICustomsInfoCreateParameters } from './CustomsInfoCreateParameters'; diff --git a/src/services/customs_item_service/index.ts b/src/services/customs_item_service/index.ts index 370efa079..d024ceecc 100644 --- a/src/services/customs_item_service/index.ts +++ b/src/services/customs_item_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { ICustomsItem } from './CustomsItem'; import { ICustomsItemCreateParameters } from './CustomsItemCreateParameters'; diff --git a/src/services/end_shipper_service/index.ts b/src/services/end_shipper_service/index.ts index 3b46fc629..ace6c3fba 100644 --- a/src/services/end_shipper_service/index.ts +++ b/src/services/end_shipper_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IEndshipper } from './EndShipper'; import { IEndShipperCreateParameters } from './EndShipperCreateParameters'; diff --git a/src/services/event_service/index.ts b/src/services/event_service/index.ts index ab150f3af..22fb7b74b 100644 --- a/src/services/event_service/index.ts +++ b/src/services/event_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IEvent } from './Event'; import { IEventListParameters } from './EventListParameters'; diff --git a/src/services/insurance_service/index.ts b/src/services/insurance_service/index.ts index 9e32e40ad..80d8174e9 100644 --- a/src/services/insurance_service/index.ts +++ b/src/services/insurance_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import { IAllMethodParameters } from '../../utils/types'; import baseService from '../base_service'; import { IInsurance } from './Insurance'; diff --git a/src/services/order_service/index.ts b/src/services/order_service/index.ts index ab2a4a067..089d2330a 100644 --- a/src/services/order_service/index.ts +++ b/src/services/order_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IRate } from '../rate_service'; import { IOrder } from './Order'; diff --git a/src/services/parcel_service/index.ts b/src/services/parcel_service/index.ts index 73d3b4644..2a5af0e0b 100644 --- a/src/services/parcel_service/index.ts +++ b/src/services/parcel_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IParcel } from './Parcel'; import { IParcelCreateParameters } from './ParcelCreateParameters'; diff --git a/src/services/pickup_service/index.ts b/src/services/pickup_service/index.ts index 813e6efd8..40b343f21 100644 --- a/src/services/pickup_service/index.ts +++ b/src/services/pickup_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IPickup } from './Pickup'; import { IPickupCreateParameters } from './PickupCreateParameters'; diff --git a/src/services/rate_service/index.ts b/src/services/rate_service/index.ts index ee90f3a68..cd60f847f 100644 --- a/src/services/rate_service/index.ts +++ b/src/services/rate_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IRate } from './Rate'; diff --git a/src/services/referral_customer_service/index.ts b/src/services/referral_customer_service/index.ts index 9daadd9e6..81ad0c357 100644 --- a/src/services/referral_customer_service/index.ts +++ b/src/services/referral_customer_service/index.ts @@ -5,7 +5,7 @@ import Constants from '../../constants'; import EasyPostClient from '../../easypost'; import ExternalApiError from '../../errors/api/external_api_error'; import baseService from '../base_service'; -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import { IReferralCreateParameters } from './ReferralCreateParameters'; import { IReferral } from './Referral'; import { IReferralListParameters } from './ReferralListParameters'; diff --git a/src/services/refund_service/index.ts b/src/services/refund_service/index.ts index a1053aef0..ae4dca3b2 100644 --- a/src/services/refund_service/index.ts +++ b/src/services/refund_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IRefund } from './Refund'; import { IRefundCreateParameters } from './RefundCreateParameters'; diff --git a/src/services/report_service/index.ts b/src/services/report_service/index.ts index f22473d18..d955b87f6 100644 --- a/src/services/report_service/index.ts +++ b/src/services/report_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IReport } from './Report'; import { IReportCreateParameters } from './ReportCreateParameters'; diff --git a/src/services/scan_form_service/index.ts b/src/services/scan_form_service/index.ts index 4c47fbde8..923b2070b 100644 --- a/src/services/scan_form_service/index.ts +++ b/src/services/scan_form_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IScanForm } from './ScanForm'; import { IScanFormCreateParameters } from './ScanFormCreateParameters'; diff --git a/src/services/shipment_service/index.ts b/src/services/shipment_service/index.ts index c550268ee..6024de7a4 100644 --- a/src/services/shipment_service/index.ts +++ b/src/services/shipment_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import Constants from '../../constants'; import baseService from '../base_service'; import { IRate, ISmartRate } from '../rate_service'; diff --git a/src/services/tracker_service/index.ts b/src/services/tracker_service/index.ts index 47cc51fc7..8c57546c2 100644 --- a/src/services/tracker_service/index.ts +++ b/src/services/tracker_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { ITracker } from './Tracker'; import { ITrackerCreateParameters } from './TrackerCreateParameters'; diff --git a/src/services/user_service/index.ts b/src/services/user_service/index.ts index 84e06953a..1e4881e5f 100644 --- a/src/services/user_service/index.ts +++ b/src/services/user_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IBrand } from './Brand'; import { IUser } from './User'; diff --git a/src/services/webhook_service/index.ts b/src/services/webhook_service/index.ts index 64e535c96..022cf53a1 100644 --- a/src/services/webhook_service/index.ts +++ b/src/services/webhook_service/index.ts @@ -1,4 +1,4 @@ -import EasyPost from '../..'; +import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IWebhook } from './Webhook'; import { IWebhookCreateParameters } from './WebhookCreateParameters'; diff --git a/test/services/report.test.js b/test/services/report.test.js index 6c72f2910..3be39f3fd 100644 --- a/test/services/report.test.js +++ b/test/services/report.test.js @@ -25,7 +25,7 @@ describe('Report Service', function () { type: Fixture.reportType(), }); - expect(report.object).to.be.equal('Report'); + expect(report.object).to.be.equal('ShipmentReport'); expect(report.id).to.match(/^shprep_/); }); @@ -39,7 +39,7 @@ describe('Report Service', function () { // Reports are queued, so we can't wait for completion. // Verifying columns would require parsing CSV. Verify correct parameters via URL in cassette - expect(report.object).to.be.equal('Report'); + expect(report.object).to.be.equal('ShipmentReport'); }); it(`creates a report with additional columns`, async function () { @@ -52,7 +52,7 @@ describe('Report Service', function () { // Reports are queued, so we can't wait for completion. // Verifying columns would require parsing CSV. Verify correct parameters via URL in cassette - expect(report.object).to.be.equal('Report'); + expect(report.object).to.be.equal('ShipmentReport'); }); it('retrieves a shipment report', async function () { @@ -64,7 +64,7 @@ describe('Report Service', function () { const retrievedReport = await this.client.Report.retrieve(report.id); - expect(retrievedReport.object).to.be.equal('Report'); + expect(retrievedReport.object).to.be.equal('ShipmentReport'); expect(retrievedReport.start_date).to.equal(report.start_date); expect(retrievedReport.end_date).to.equal(report.end_date); }); @@ -80,7 +80,7 @@ describe('Report Service', function () { expect(reportsArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(reports.has_more).to.exist; reportsArray.forEach((report) => { - expect(report.object).to.be.equal('Report'); + expect(report.object).to.be.equal('ShipmentReport'); }); }); diff --git a/tsconfig.json b/tsconfig.json index aaf2751e8..7c8c9ea00 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,10 +6,10 @@ "resolveJsonModule": true, "strictPropertyInitialization": false, "downlevelIteration": true, - "outDir": "./out", + "outDir": "./out-tmp", "declaration": true, - "declarationDir": "./types", - "rootDir": "./src" + "declarationDir": "./types-tmp" }, - "include": ["./src"] + "include": ["./src"], + "exclude": ["./package.json"] } diff --git a/webpack.config.babel.js b/webpack.config.babel.js index a1fe9c09e..a086afc88 100644 --- a/webpack.config.babel.js +++ b/webpack.config.babel.js @@ -5,7 +5,7 @@ const mode = process.env.NODE_ENV || 'development'; const isDev = mode === 'development'; module.exports = { - entry: path.resolve(__dirname, 'out/src/easypost.js'), + entry: path.resolve(__dirname, 'out/easypost.js'), output: { path: path.resolve(__dirname, 'dist'), filename: 'easypost.js', @@ -13,7 +13,7 @@ module.exports = { type: 'commonjs', }, }, - context: path.resolve(__dirname, 'out/src'), + context: path.resolve(__dirname, 'out'), mode, cache: isDev, devtool: isDev ? 'source-map' : undefined, @@ -32,6 +32,6 @@ module.exports = { }, resolve: { extensions: ['.js'], - modules: [path.resolve(__dirname, 'out/src'), path.resolve(__dirname, './node_modules')], + modules: [path.resolve(__dirname, 'out'), path.resolve(__dirname, './node_modules')], }, }; From e459a8dcfc169c353183f9b0f056508176e91cf4 Mon Sep 17 00:00:00 2001 From: Alex Matthews Date: Wed, 15 May 2024 16:38:28 -0500 Subject: [PATCH 5/7] Gets tests running --- src/errors/error_handler.ts | 36 ++++++++----------- src/services/base_service.ts | 22 ++++++++++-- src/services/billing_service/index.ts | 6 ++-- src/services/insurance_service/index.ts | 17 +++++++-- src/services/order_service/index.ts | 20 +++++++++-- src/services/pickup_service/index.ts | 46 +++++++++++++++++++++---- src/services/report_service/index.ts | 4 +-- src/utils/util.ts | 6 ++-- test/helpers/utils.js | 4 +++ test/services/api_key.test.js | 2 +- test/services/report.test.js | 1 + tsconfig.json | 3 ++ 12 files changed, 122 insertions(+), 45 deletions(-) diff --git a/src/errors/error_handler.ts b/src/errors/error_handler.ts index 5c77e79f2..09951cbff 100644 --- a/src/errors/error_handler.ts +++ b/src/errors/error_handler.ts @@ -21,41 +21,32 @@ export type RawAPIError = { body: { error: { code: string; - message: JSONParsableError; + message: any; errors: EasyPostError[]; }; }; }; -type JSONParsableError = string | number | JSONObject | JSONArray; -type JSONObject = { - [key: string]: JSONParsableError; -}; -type JSONArray = JSONParsableError[]; - export default class ErrorHandler { /** * Recursively traverses a JSON object or array and extracts error messages * as strings. Adds the extracted messages to the specified messagesList array. * - * @param {JSONParsableError} errorMessage - The JSON object or array to traverse. + * @param {object|array|string} errorMessage - The JSON object or array to traverse. + * @param {array} messagesList - The array to which extracted error messages will be added. */ - static traverseJsonElement(errorMessage: JSONParsableError): string[] { - let messages: string[] = []; - - if (errorMessage instanceof Array) { - for (const value of errorMessage) { - messages = messages.concat(this.traverseJsonElement(value)); - } - } else if (errorMessage instanceof Object) { + static traverseJsonElement(errorMessage: any, messagesList: string[]) { + if (errorMessage instanceof Object) { for (const value of Object.values(errorMessage)) { - messages = messages.concat(this.traverseJsonElement(value)); + this.traverseJsonElement(value, messagesList); + } + } else if (errorMessage instanceof Array) { + for (const value of errorMessage) { + this.traverseJsonElement(value, messagesList); } } else { - messages.push(errorMessage.toString()); + messagesList.push(errorMessage.toString()); } - - return messages; } static isAPIError(error: any): error is RawAPIError { @@ -79,14 +70,15 @@ export default class ErrorHandler { const { statusCode } = error; const { code, message, errors } = error.body.error; const errorParams = { - message: '', + message, code, statusCode, errors, }; try { - const messages = this.traverseJsonElement(message); + const messages: string[] = []; + this.traverseJsonElement(errorParams.message, messages); errorParams.message = messages.join(', '); } catch (e) { const errorParams = { diff --git a/src/services/base_service.ts b/src/services/base_service.ts index 16a1f1832..7a0273534 100644 --- a/src/services/base_service.ts +++ b/src/services/base_service.ts @@ -19,10 +19,26 @@ export default (easypostClient: EasyPostClient) => * @returns {*} An {@link EasyPostObject}-based class instance or an `Array` of {@link EasyPostObject}-based class instances. */ static _convertToEasyPostObject(response: A, params?: any): EasyPostObject { - const newResponse = response as EasyPostObject; - newResponse._params = params; + if (Array.isArray(response)) { + return response.map((value) => { + if (typeof value === 'object') { + return this._convertToEasyPostObject(value, params); + } + return value; + }) as EasyPostObject; + } + + if (typeof response === 'object' && response !== null) { + const classObject = {} as EasyPostObject; + Object.entries(response).forEach(([key, value]) => { + classObject[key as keyof A] = this._convertToEasyPostObject(value, params); + }); - return newResponse; + classObject._params = params; + + return classObject; + } + return response as EasyPostObject; } /** diff --git a/src/services/billing_service/index.ts b/src/services/billing_service/index.ts index 07fc7b5c8..d1a957745 100644 --- a/src/services/billing_service/index.ts +++ b/src/services/billing_service/index.ts @@ -77,14 +77,16 @@ export default (easypostClient: EasyPost) => const paymentMethodToUse = paymentMethodMap[priority]; let paymentMethodID; + let paymentMethodObjectType; let endpoint; const errorString = 'The chosen payment method is not valid. Please try again.'; if (paymentMethodToUse !== undefined && paymentMethods[paymentMethodToUse] !== null) { paymentMethodID = paymentMethods[paymentMethodToUse].id; - if (paymentMethodID.startsWith('card_')) { + paymentMethodObjectType = paymentMethods[paymentMethodToUse].object; + if (paymentMethodObjectType === 'CreditCard') { endpoint = 'credit_cards'; - } else if (paymentMethodID.startsWith('bank_')) { + } else if (paymentMethodObjectType === 'BankAccount') { endpoint = 'bank_accounts'; } else { throw new InvalidObjectError({ message: errorString }); diff --git a/src/services/insurance_service/index.ts b/src/services/insurance_service/index.ts index 80d8174e9..1c16834a1 100644 --- a/src/services/insurance_service/index.ts +++ b/src/services/insurance_service/index.ts @@ -63,12 +63,25 @@ export default (easypostClient: EasyPost) => /** * Retrieve an {@link Insurance insurance} record by its ID. * See {@link https://www.easypost.com/docs/api/node#retrieve-an-insurance EasyPost API Documentation} for more information. - * @param {string} id - The ID of the insurance to retrieve. - * @returns {Insurance} - The retrieved insurance. + * @param id - The ID of the insurance to retrieve. + * @returns - The retrieved insurance. */ static async retrieve(id: string) { const url = `insurances/${id}`; return this._retrieve(url); } + + /** + * Refund an {@link Insurance insurance} record by its ID. + * See {@link https://www.easypost.com/docs/api/node#refund-an-insurance EasyPost API Documentation} for more information. + * @param id - The ID of the insurance to be refunded. + * @returns - The refunded insurance. + */ + static async refund(id: string) { + const url = `insurances/${id}/refund`; + const response = await easypostClient._post(url); + + return this._convertToEasyPostObject(response.body); + } }; diff --git a/src/services/order_service/index.ts b/src/services/order_service/index.ts index 089d2330a..2dca683a0 100644 --- a/src/services/order_service/index.ts +++ b/src/services/order_service/index.ts @@ -1,3 +1,4 @@ +import Constants from '../../constants'; import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IRate } from '../rate_service'; @@ -7,6 +8,16 @@ import { IOrderCreateParameters } from './OrderCreateParameters'; export * from './Order'; export * from './OrderCreateParameters'; +export type IOrderWithLowestRate = IOrder & { + lowestRate: (carriers?: string[], services?: string[]) => IRate; +}; + +const addLowestRateToOrder = (order: IOrder): IOrderWithLowestRate => ({ + ...order, + lowestRate: (carriers?: string[], services?: string[]) => + Constants.Utils.getLowestRate(order.rates, carriers, services), +}); + export default (easypostClient: EasyPost) => /** * The OrderService class provides methods for interacting with EasyPost {@link Order} objects. @@ -26,7 +37,8 @@ export default (easypostClient: EasyPost) => order: params, }; - return this._create(url, wrappedParams); + const order = await this._create(url, wrappedParams); + return addLowestRateToOrder(order); } /** @@ -43,7 +55,8 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url, wrappedParams); - return this._convertToEasyPostObject(response.body, wrappedParams); + const order = this._convertToEasyPostObject(response.body, wrappedParams); + return addLowestRateToOrder(order); } catch (e) { return Promise.reject(e); } @@ -76,6 +89,7 @@ export default (easypostClient: EasyPost) => static async retrieve(id: string) { const url = `orders/${id}`; - return this._retrieve(url); + const order = await this._retrieve(url); + return addLowestRateToOrder(order); } }; diff --git a/src/services/pickup_service/index.ts b/src/services/pickup_service/index.ts index 40b343f21..7cf74d932 100644 --- a/src/services/pickup_service/index.ts +++ b/src/services/pickup_service/index.ts @@ -1,8 +1,25 @@ +import Constants from '../../constants'; import EasyPost from '../../easypost'; import baseService from '../base_service'; import { IPickup } from './Pickup'; import { IPickupCreateParameters } from './PickupCreateParameters'; import { IPickupListParameters } from './PickupListParameters'; +import { IPickupRate } from './PickupRate'; + +export * from './Pickup'; +export * from './PickupCreateParameters'; +export * from './PickupListParameters'; +export * from './PickupRate'; + +export type IPickupWithLowestRate = IPickup & { + lowestRate: (carriers?: string[], services?: string[]) => IPickupRate; +}; + +const addLowestRateToPickup = (pickup: IPickup): IPickupWithLowestRate => ({ + ...pickup, + lowestRate: (carriers?: string[], services?: string[]) => + Constants.Utils.getLowestRate(pickup.pickup_rates, carriers, services), +}); export default (easypostClient: EasyPost) => /** @@ -23,7 +40,8 @@ export default (easypostClient: EasyPost) => pickup: params, }; - return this._create(url, wrappedParams); + const pickup = await this._create(url, wrappedParams); + return addLowestRateToPickup(pickup); } /** @@ -40,7 +58,8 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url, wrappedParams); - return this._convertToEasyPostObject(response.body, wrappedParams); + const pickup = this._convertToEasyPostObject(response.body, wrappedParams); + return addLowestRateToPickup(pickup); } catch (e) { return Promise.reject(e); } @@ -57,7 +76,8 @@ export default (easypostClient: EasyPost) => try { const response = await easypostClient._post(url); - return this._convertToEasyPostObject(response.body); + const pickup = this._convertToEasyPostObject(response.body); + return addLowestRateToPickup(pickup); } catch (e) { return Promise.reject(e); } @@ -72,7 +92,11 @@ export default (easypostClient: EasyPost) => static async all(params: IPickupListParameters = {}) { const url = 'pickups'; - return this._all(url, params); + const result = await this._all<{ pickups: IPickup[] }>(url, params); + return { + ...result, + pickups: result.pickups.map(addLowestRateToPickup), + }; } /** @@ -83,7 +107,16 @@ export default (easypostClient: EasyPost) => */ static async getNextPage(pickups: any, pageSize: number | null = null) { const url = 'pickups'; - return this._getNextPage<{ pickups: IPickup[] }>(url, 'pickups', pickups, pageSize); + const result = await this._getNextPage<{ pickups: IPickup[] }>( + url, + 'pickups', + pickups, + pageSize, + ); + return { + ...result, + pickups: result.pickups.map(addLowestRateToPickup), + }; } /** @@ -95,6 +128,7 @@ export default (easypostClient: EasyPost) => static async retrieve(id: string) { const url = `pickups/${id}`; - return this._retrieve(url); + const pickup = await this._retrieve(url); + return addLowestRateToPickup(pickup); } }; diff --git a/src/services/report_service/index.ts b/src/services/report_service/index.ts index d955b87f6..0c4734bf7 100644 --- a/src/services/report_service/index.ts +++ b/src/services/report_service/index.ts @@ -43,9 +43,7 @@ export default (easypostClient: EasyPost) => const response = await easypostClient._get(url, apiParams); - const responseObject = this._convertToEasyPostObject(response.body, params); - - return responseObject; + return this._convertToEasyPostObject(response.body, params); } catch (e) { return Promise.reject(e); } diff --git a/src/utils/util.ts b/src/utils/util.ts index 2b7e35d47..0cb3e947e 100644 --- a/src/utils/util.ts +++ b/src/utils/util.ts @@ -78,11 +78,11 @@ export default class Utils { * @returns - The lowest rate * @throws {FilteringError} - If no applicable rates are found */ - getLowestRate( - rates: IRate[], + getLowestRate( + rates: A[], carriers: string[] | null = null, services: string[] | null = null, - ): IRate { + ): A { if (carriers) { const carriersLower = carriers.map((carrier) => carrier.toLowerCase()); // eslint-disable-next-line no-param-reassign diff --git a/test/helpers/utils.js b/test/helpers/utils.js index 3c0ad3987..57268b1aa 100644 --- a/test/helpers/utils.js +++ b/test/helpers/utils.js @@ -12,6 +12,10 @@ export const withoutParams = (obj) => return null; } + if (key === 'lowestRate') { + return null; + } + if (!value) { return [key, value]; } diff --git a/test/services/api_key.test.js b/test/services/api_key.test.js index 88fd88c93..1ffae1806 100644 --- a/test/services/api_key.test.js +++ b/test/services/api_key.test.js @@ -29,7 +29,7 @@ describe('ApiKey Service', function () { const user = await this.client.User.retrieveMe(); const keys = await this.client.ApiKey.retrieveApiKeysForUser(user.id); - expect(keys.object).to.be.equal('Array'); + expect(keys).to.be.instanceOf(Array); }); it("throws FilteringError when trying to retrieve child user's API keys", async function () { diff --git a/test/services/report.test.js b/test/services/report.test.js index 3be39f3fd..6e8148d07 100644 --- a/test/services/report.test.js +++ b/test/services/report.test.js @@ -98,6 +98,7 @@ describe('Report Service', function () { expect(firstIdOfFirstPage).to.not.equal(firstIdOfSecondPage); } catch (error) { + console.log(error, error instanceof EndOfPaginationError); if (!(error instanceof EndOfPaginationError)) { throw new Error('Test failed intentionally'); } diff --git a/tsconfig.json b/tsconfig.json index 7c8c9ea00..b1e47ee33 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,9 @@ "resolveJsonModule": true, "strictPropertyInitialization": false, "downlevelIteration": true, + "target": "ES6", + "module": "NodeNext", + "moduleResolution": "NodeNext", "outDir": "./out-tmp", "declaration": true, "declarationDir": "./types-tmp" From 212de3b26e4c1e8fad29a03f20872ab4dd970b7d Mon Sep 17 00:00:00 2001 From: Alex Matthews Date: Wed, 15 May 2024 16:49:50 -0500 Subject: [PATCH 6/7] Fixes todos --- src/services/address_service/Address.ts | 127 +++++++++--------- src/services/api_key_service/index.ts | 2 +- src/services/batch_service/index.ts | 2 +- src/services/carrier_account_service/index.ts | 2 +- .../CarrierMetadata.ts | 8 +- src/services/event_service/index.ts | 2 +- src/services/insurance_service/index.ts | 4 +- src/services/pickup_service/index.ts | 2 +- .../referral_customer_service/index.ts | 7 +- src/services/refund_service/index.ts | 2 +- src/services/report_service/index.ts | 2 +- 11 files changed, 82 insertions(+), 78 deletions(-) diff --git a/src/services/address_service/Address.ts b/src/services/address_service/Address.ts index 403c5bc3a..65d8153cd 100644 --- a/src/services/address_service/Address.ts +++ b/src/services/address_service/Address.ts @@ -1,5 +1,5 @@ import { IVerifications } from './Verifications'; -import { IObjectWithId } from '../../utils/types'; +import { IObjectWithId, IDatedObject } from '../../utils/types'; /** * Address objects are used to represent people, places, and organizations in a number of contexts. @@ -9,79 +9,80 @@ import { IObjectWithId } from '../../utils/types'; * * @see https://www.easypost.com/docs/api/node#address-object */ -export type IAddress = IObjectWithId<'Address'> & { - /** - * First line of the address - */ - street1?: string | null; +export type IAddress = IObjectWithId<'Address'> & + IDatedObject & { + /** + * First line of the address + */ + street1?: string | null; - /** - * Second line of the address - */ - street2?: string | null; + /** + * Second line of the address + */ + street2?: string | null; - /** - * City the address is located in - */ - city?: string | null; + /** + * City the address is located in + */ + city?: string | null; - /** - * State or province the address is located in - */ - state?: string | null; + /** + * State or province the address is located in + */ + state?: string | null; - /** - * ZIP or postal code the address is located in - */ - zip: string; + /** + * ZIP or postal code the address is located in + */ + zip: string; - /** - * ISO 3166 country code for the country the address is located in - */ - country: string; + /** + * ISO 3166 country code for the country the address is located in + */ + country: string; - /** - * Whether or not this address would be considered residential - */ - residential?: boolean | null; + /** + * Whether or not this address would be considered residential + */ + residential?: boolean | null; - /** - * The specific designation for the address (only relevant if the address is a carrier facility) - */ - carrier_facility?: string | null; + /** + * The specific designation for the address (only relevant if the address is a carrier facility) + */ + carrier_facility?: string | null; - /** - * Name of the person. Both name and company can be included - */ - name?: string | null; + /** + * Name of the person. Both name and company can be included + */ + name?: string | null; - /** - * Name of the organization. Both name and company can be included - */ - company?: string | null; + /** + * Name of the organization. Both name and company can be included + */ + company?: string | null; - /** - * Phone number to reach the person or organization - */ - phone?: string | null; + /** + * Phone number to reach the person or organization + */ + phone?: string | null; - /** - * Email to reach the person or organization - */ - email?: string | null; + /** + * Email to reach the person or organization + */ + email?: string | null; - /** - * Federal tax identifier of the person or organization - */ - federal_tax_id?: string | null; + /** + * Federal tax identifier of the person or organization + */ + federal_tax_id?: string | null; - /** - * State tax identifier of the person or organization - */ - state_tax_id?: string | null; + /** + * State tax identifier of the person or organization + */ + state_tax_id?: string | null; - /** - * The result of any verifications requested - */ - verifications: IVerifications; -}; + /** + * The result of any verifications requested + */ + verifications: IVerifications; + }; diff --git a/src/services/api_key_service/index.ts b/src/services/api_key_service/index.ts index 04106eb6c..b346bd336 100644 --- a/src/services/api_key_service/index.ts +++ b/src/services/api_key_service/index.ts @@ -21,7 +21,7 @@ export default (easypostClient: EasyPost) => static async all(params = {}) { const url = 'api_keys'; - return this._all(url, params); + return this._all<{ api_keys: IApiKey[] }>(url, params); } /** diff --git a/src/services/batch_service/index.ts b/src/services/batch_service/index.ts index 1aa6823ac..26e4b2c81 100644 --- a/src/services/batch_service/index.ts +++ b/src/services/batch_service/index.ts @@ -144,7 +144,7 @@ export default (easypostClient: EasyPost) => static async all(params: IBatchListParameters = {}) { const url = 'batches'; - return this._all(url, params); + return this._all<{ batches: IBatch[] }>(url, params); } /** diff --git a/src/services/carrier_account_service/index.ts b/src/services/carrier_account_service/index.ts index 7d44676d2..21e98be2d 100644 --- a/src/services/carrier_account_service/index.ts +++ b/src/services/carrier_account_service/index.ts @@ -101,7 +101,7 @@ export default (easypostClient: EasyPost) => static async all(params = {}) { const url = 'carrier_accounts'; - return this._all(url, params); + return this._all<{ carrier_accounts: ICarrierAccount[] }>(url, params); } /** diff --git a/src/services/carrier_metadata_service/CarrierMetadata.ts b/src/services/carrier_metadata_service/CarrierMetadata.ts index 155bad93f..c63215041 100644 --- a/src/services/carrier_metadata_service/CarrierMetadata.ts +++ b/src/services/carrier_metadata_service/CarrierMetadata.ts @@ -20,20 +20,20 @@ export type ICarrierMetadata = { /** * A list of service level objects for this carrier */ - service_levels?: Array | null; + service_levels?: Object[] | null; /** * A list of predefined package objects for this carrier */ - predefined_packages?: Array | null; + predefined_packages?: Object[] | null; /** * A list of supported feature objects for this carrier */ - supported_features?: Array | null; + supported_features?: Object[] | null; /** * A list of shipment option objects for this carrier */ - shipment_options?: Array | null; + shipment_options?: Object[] | null; }; diff --git a/src/services/event_service/index.ts b/src/services/event_service/index.ts index 22fb7b74b..b27b41a2b 100644 --- a/src/services/event_service/index.ts +++ b/src/services/event_service/index.ts @@ -69,7 +69,7 @@ export default (easypostClient: EasyPost) => * @param pageSize The number of records to return on each page * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage(events: any, pageSize: number | null = null) { + static async getNextPage(events: { events: any[] }, pageSize: number | null = null) { const url = 'events'; return this._getNextPage<{ events: IEvent[] }>(url, 'events', events, pageSize); } diff --git a/src/services/insurance_service/index.ts b/src/services/insurance_service/index.ts index 1c16834a1..54a993e2e 100644 --- a/src/services/insurance_service/index.ts +++ b/src/services/insurance_service/index.ts @@ -41,7 +41,7 @@ export default (easypostClient: EasyPost) => static async all(params: IAllMethodParameters = {}) { const url = 'insurances'; - return this._all(url, params); + return this._all<{ insurances: IInsurance[] }>(url, params); } /** @@ -50,7 +50,7 @@ export default (easypostClient: EasyPost) => * @param {Number} pageSize The number of records to return on each page * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage(insurances: any, pageSize: number | null = null) { + static async getNextPage(insurances: { insurances: any[] }, pageSize: number | null = null) { const url = 'insurances'; return this._getNextPage<{ insurances: IInsurance[] }>( url, diff --git a/src/services/pickup_service/index.ts b/src/services/pickup_service/index.ts index 7cf74d932..574098628 100644 --- a/src/services/pickup_service/index.ts +++ b/src/services/pickup_service/index.ts @@ -105,7 +105,7 @@ export default (easypostClient: EasyPost) => * @param pageSize The number of records to return on each page * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage(pickups: any, pageSize: number | null = null) { + static async getNextPage(pickups: { pickups: any[] }, pageSize: number | null = null) { const url = 'pickups'; const result = await this._getNextPage<{ pickups: IPickup[] }>( url, diff --git a/src/services/referral_customer_service/index.ts b/src/services/referral_customer_service/index.ts index 81ad0c357..b5ef36cc8 100644 --- a/src/services/referral_customer_service/index.ts +++ b/src/services/referral_customer_service/index.ts @@ -190,7 +190,7 @@ export default (easypostClient: EasyPost) => static async all(params: IReferralListParameters = {}) { const url = 'referral_customers'; - return this._all(url, params); + return this._all<{ referral_customers: IReferral[] }>(url, params); } /** @@ -199,7 +199,10 @@ export default (easypostClient: EasyPost) => * @param pageSize The number of records to return on each page * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage(referralCustomers: any, pageSize: number | null = null) { + static async getNextPage( + referralCustomers: { referral_customers: any[] }, + pageSize: number | null = null, + ) { const url = 'referral_customers'; return this._getNextPage<{ referral_customers: IReferral[] }>( url, diff --git a/src/services/refund_service/index.ts b/src/services/refund_service/index.ts index ae4dca3b2..11cc29b94 100644 --- a/src/services/refund_service/index.ts +++ b/src/services/refund_service/index.ts @@ -48,7 +48,7 @@ export default (easypostClient: EasyPost) => * @param pageSize The number of records to return on each page * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage(refunds: any, pageSize: number | null = null) { + static async getNextPage(refunds: { refunds: any[] }, pageSize: number | null = null) { const url = 'refunds'; return this._getNextPage<{ refunds: IRefund[] }>(url, 'refunds', refunds, pageSize); } diff --git a/src/services/report_service/index.ts b/src/services/report_service/index.ts index 0c4734bf7..448038298 100644 --- a/src/services/report_service/index.ts +++ b/src/services/report_service/index.ts @@ -55,7 +55,7 @@ export default (easypostClient: EasyPost) => * @param pageSize The number of records to return on each page * @returns The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage(reports: any, pageSize: number | null = null) { + static async getNextPage(reports: { reports: any[] }, pageSize: number | null = null) { const url = `reports/${reports.reports[0]._params.type}`; return this._getNextPage<{ reports: IReport[] }>(url, 'reports', reports, pageSize); } From 8f39633789761b281217580a8251737a72eb0723 Mon Sep 17 00:00:00 2001 From: Alex Matthews Date: Wed, 15 May 2024 17:24:03 -0500 Subject: [PATCH 7/7] Fixes the build for node 12 --- src/easypost.ts | 2 +- src/services/api_key_service/index.ts | 2 +- src/services/carrier_account_service/index.ts | 2 +- src/services/referral_customer_service/index.ts | 2 +- src/utils/util.ts | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/easypost.ts b/src/easypost.ts index b1850f8e8..2fe80b25b 100644 --- a/src/easypost.ts +++ b/src/easypost.ts @@ -34,7 +34,7 @@ import UserService from './services/user_service'; import WebhookService from './services/webhook_service'; import Utils from './utils/util'; -import util from 'node:util'; +import util from 'util'; /** How many milliseconds in a second. */ export const MS_SECOND = 1000; diff --git a/src/services/api_key_service/index.ts b/src/services/api_key_service/index.ts index b346bd336..c85c8dfe8 100644 --- a/src/services/api_key_service/index.ts +++ b/src/services/api_key_service/index.ts @@ -1,4 +1,4 @@ -import util from 'node:util'; +import util from 'util'; import baseService from '../base_service'; import Constants from '../../constants'; import FilteringError from '../../errors/general/filtering_error'; diff --git a/src/services/carrier_account_service/index.ts b/src/services/carrier_account_service/index.ts index 21e98be2d..d66ffae98 100644 --- a/src/services/carrier_account_service/index.ts +++ b/src/services/carrier_account_service/index.ts @@ -1,4 +1,4 @@ -import util from 'node:util'; +import util from 'util'; import baseService from '../base_service'; import Constants from '../../constants'; import InvalidParameterError from '../../errors/general/invalid_parameter_error'; diff --git a/src/services/referral_customer_service/index.ts b/src/services/referral_customer_service/index.ts index b5ef36cc8..02c01f57a 100644 --- a/src/services/referral_customer_service/index.ts +++ b/src/services/referral_customer_service/index.ts @@ -1,4 +1,4 @@ -import util from 'node:util'; +import util from 'util'; import superagent from 'superagent'; import Constants from '../../constants'; diff --git a/src/utils/util.ts b/src/utils/util.ts index 0cb3e947e..735fa376b 100644 --- a/src/utils/util.ts +++ b/src/utils/util.ts @@ -1,10 +1,10 @@ -import crypto from 'node:crypto'; -import util from 'node:util'; +import crypto from 'crypto'; +import util from 'util'; import Constants from '../constants'; import FilteringError from '../errors/general/filtering_error'; import InvalidParameterError from '../errors/general/invalid_parameter_error'; import SignatureVerificationError from '../errors/general/signature_verification_error'; -import { IRate, ISmartRate } from '../services/rate_service'; +import { ISmartRate } from '../services/rate_service'; /** * Utility class of various publicly-available helper functions.