├── .gitattributes ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ └── feature_request.yml ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── ci.yml │ └── release.yml ├── .gitignore ├── .gitmodules ├── .npmignore ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── UPGRADE_GUIDE.md ├── audit-ci.jsonc ├── package-lock.json ├── package.json ├── src ├── constants.js ├── easypost.js ├── errors │ ├── api │ │ ├── api_error.js │ │ ├── bad_request_error.js │ │ ├── external_api_error.js │ │ ├── forbidden_error.js │ │ ├── gateway_timeout_error.js │ │ ├── http_error.js │ │ ├── internal_server_error.js │ │ ├── invalid_request_error.js │ │ ├── method_not_allowed_error.js │ │ ├── not_found_error.js │ │ ├── payment_error.js │ │ ├── rate_limit_error.js │ │ ├── redirect_error.js │ │ ├── service_unavailable_error.js │ │ ├── timeout_error.js │ │ ├── unauthorized_error.js │ │ └── unknown_api_error.js │ ├── easypost_error.js │ ├── error_handler.js │ └── general │ │ ├── end_of_pagination_error.js │ │ ├── filtering_error.js │ │ ├── invalid_object_error.js │ │ ├── invalid_parameter_error.js │ │ ├── missing_parameter_error.js │ │ └── signature_verification_error.js ├── models │ ├── address.js │ ├── api_key.js │ ├── batch.js │ ├── brand.js │ ├── carrier_account.js │ ├── carrier_type.js │ ├── claim.js │ ├── customs_info.js │ ├── customs_item.js │ ├── easypost_object.js │ ├── end_shipper.js │ ├── event.js │ ├── form.js │ ├── insurance.js │ ├── order.js │ ├── parcel.js │ ├── payload.js │ ├── pickup.js │ ├── pickup_rate.js │ ├── postage_label.js │ ├── rate.js │ ├── refund.js │ ├── report.js │ ├── scan_form.js │ ├── shipment.js │ ├── tracker.js │ ├── user.js │ └── webhook.js ├── services │ ├── address_service.js │ ├── api_key_service.js │ ├── base_service.js │ ├── batch_service.js │ ├── beta_rate_service.js │ ├── beta_referral_customer_service.js │ ├── billing_service.js │ ├── carrier_account_service.js │ ├── carrier_metadata_service.js │ ├── carrier_type_service.js │ ├── claim_service.js │ ├── customs_info_service.js │ ├── customs_item_service.js │ ├── end_shipper_service.js │ ├── event_service.js │ ├── insurance_service.js │ ├── order_service.js │ ├── parcel_service.js │ ├── pickup_service.js │ ├── rate_service.js │ ├── referral_customer_service.js │ ├── refund_service.js │ ├── report_service.js │ ├── scan_form_service.js │ ├── shipment_service.js │ ├── smart_rate_service.js │ ├── tracker_service.js │ ├── user_service.js │ └── webhook_service.js └── utils │ ├── internal_util.js │ └── util.js ├── test ├── .eslintrc ├── cassettes │ ├── Address-Service_1115845720 │ │ ├── creates-a-verified-address_2691107999 │ │ │ └── recording.har │ │ ├── creates-an-address-with-an-array-verify-param_1154761701 │ │ │ └── recording.har │ │ ├── creates-an-address-with-verify-param_348500273 │ │ │ └── recording.har │ │ ├── creates-an-address-with-verify_strict-param_3337987013 │ │ │ └── recording.har │ │ ├── creates-an-address_3623959033 │ │ │ └── recording.har │ │ ├── retrieves-all-addresses_2336737309 │ │ │ └── recording.har │ │ ├── retrieves-an-address_811685445 │ │ │ └── recording.har │ │ ├── retrieves-next-page-of-addresses_3892775151 │ │ │ └── recording.har │ │ ├── throws-an-error-when-we-cannot-create-and-verify-an-address_2925377245 │ │ │ └── recording.har │ │ ├── throws-an-error-when-we-cannot-verify-an-address_2852976208 │ │ │ └── recording.har │ │ └── verifies-an-address_2951018147 │ │ │ └── recording.har │ ├── ApiKey-Service_1820824481 │ │ ├── retrieves-all-apiKeys_3089762033 │ │ │ └── recording.har │ │ ├── retrieves-parent-user-s-API-keys_3733038849 │ │ │ └── recording.har │ │ └── throws-FilteringError-when-trying-to-retrieve-child-user-s-API-keys_933533041 │ │ │ └── recording.har │ ├── Batch-Service_3950244400 │ │ ├── adds-and-removes-shipments-from-a-batch_444431701 │ │ │ └── recording.har │ │ ├── buys-a-batch_1852613799 │ │ │ └── recording.har │ │ ├── creates-a-batch_594550505 │ │ │ └── recording.har │ │ ├── creates-a-scanform-for-a-batch_397052124 │ │ │ └── recording.har │ │ ├── generates-a-label-for-a-batch_2376202846 │ │ │ └── recording.har │ │ ├── retrieves-a-batch_3567114261 │ │ │ └── recording.har │ │ └── retrieves-all-batches_3594352953 │ │ │ └── recording.har │ ├── BetaRateService_784563276 │ │ ├── retrieve-invalid-lowest-rate_1308734214 │ │ │ └── recording.har │ │ ├── retrieve-the-lowest-rate_1860369698 │ │ │ └── recording.har │ │ └── retrieves-a-list-of-stateless-rates_708839575 │ │ │ └── recording.har │ ├── BetaReferralCustomerService_312890993 │ │ ├── Refund-a-payment-by-a-payment-log-ID_834598297 │ │ │ └── recording.har │ │ ├── Refund-by-amount-for-a-recent-payment_2095459785 │ │ │ └── recording.har │ │ ├── add-payment-method-to-a-referral-customer-account_202490475 │ │ │ └── recording.har │ │ ├── returns-a-client-secret-for-bank-accounts_845792627 │ │ │ └── recording.har │ │ └── returns-a-client-secret-for-credit-cards_1367228089 │ │ │ └── recording.har │ ├── CarrierAccount-Service_2076435725 │ │ ├── creates-a-UPS-carrier-account_3537134608 │ │ │ └── recording.har │ │ ├── creates-a-carrier-account-with-a-custom-workflow_416546097 │ │ │ └── recording.har │ │ ├── creates-a-carrier-account_2088010306 │ │ │ └── recording.har │ │ ├── creates-an-Amazon-carrier-account_772644036 │ │ │ └── recording.har │ │ ├── deletes-a-carrier-account_2969030363 │ │ │ └── recording.har │ │ ├── retrieves-a-carrier-account_39632142 │ │ │ └── recording.har │ │ ├── retrieves-all-carrier-accounts_3697782375 │ │ │ └── recording.har │ │ ├── updates-a-UPS-carrier-account_2425174955 │ │ │ └── recording.har │ │ └── updates-a-carrier-account_2644332837 │ │ │ └── recording.har │ ├── CarrierMetadataService_914849265 │ │ ├── retrieves-all-carrier-metadata_1727273862 │ │ │ └── recording.har │ │ └── retrieves-carrier-metadata-based-on-the-filters-provided_356822124 │ │ │ └── recording.har │ ├── CarrierType-Service_548045692 │ │ └── retrieves-the-carrier-account-types-available_2194398260 │ │ │ └── recording.har │ ├── Claim-Service_1417924316 │ │ ├── cancels-a-standalone-claim_1710270578 │ │ │ └── recording.har │ │ ├── creates-a-claim-object_2101092128 │ │ │ └── recording.har │ │ ├── retrieves-a-claim-object_3414227044 │ │ │ └── recording.har │ │ ├── retrieves-all-claim-objects_2221815381 │ │ │ └── recording.har │ │ └── retrieves-next-page-of-claims_131645032 │ │ │ └── recording.har │ ├── CustomsInfo-Service_3680532552 │ │ ├── creates-a-customs-info_377615867 │ │ │ └── recording.har │ │ └── retrieves-a-customs-info_1122228031 │ │ │ └── recording.har │ ├── CustomsItem-Service_1926184595 │ │ ├── creates-a-customs-item_3109926696 │ │ │ └── recording.har │ │ └── retrieves-a-customs-item_93895516 │ │ │ └── recording.har │ ├── EasyPost_3093958733 │ │ ├── will-add-more-than-one-request-and-response-hook_800203696 │ │ │ └── recording.har │ │ ├── will-clear-all-request-and-response-hooks_2585282550 │ │ │ └── recording.har │ │ ├── will-log-the-appropriate-values-when-a-request-and-response-hooks-are-provided_4257210422 │ │ │ └── recording.har │ │ └── will-unsubscribe-from-requests-and-responses_2536075347 │ │ │ └── recording.har │ ├── EndShipper-Service_2494241140 │ │ ├── creates-an-EndShipper-object_2102997832 │ │ │ └── recording.har │ │ ├── retrieves-all-EndShipper-objects_92306777 │ │ │ └── recording.har │ │ ├── retrieves-an-EndShipper-object_1126490324 │ │ │ └── recording.har │ │ └── updates-an-EndShipper-object_792713925 │ │ │ └── recording.har │ ├── Error-Service_386538342 │ │ ├── pulls-out-error-properties-of-an-API-error-when-using-the-alternative-format_650479431 │ │ │ └── recording.har │ │ └── pulls-out-error-properties-of-an-API-error_2733221812 │ │ │ └── recording.har │ ├── Event-Service_3026743340 │ │ ├── retrieves-a-payload-for-an-event_1410906611 │ │ │ └── recording.har │ │ ├── retrieves-all-events_1562474214 │ │ │ └── recording.har │ │ ├── retrieves-all-payloads-for-an-event_3292460230 │ │ │ └── recording.har │ │ ├── retrieves-an-event_1451703989 │ │ │ └── recording.har │ │ └── retrieves-next-page-of-events_2974553216 │ │ │ └── recording.har │ ├── Insurance-Service_1251316388 │ │ ├── creates-an-insurance-object_4069302148 │ │ │ └── recording.har │ │ ├── refunds-a-standalone-insurance_797329606 │ │ │ └── recording.har │ │ ├── retrieves-all-insurance-objects_1524141757 │ │ │ └── recording.har │ │ ├── retrieves-an-insurance-object_1368608920 │ │ │ └── recording.har │ │ └── retrieves-next-page-of-insurances_2708218560 │ │ │ └── recording.har │ ├── Order-Service_3224466932 │ │ ├── buys-an-order_2645945167 │ │ │ └── recording.har │ │ ├── creates-an-order_965608125 │ │ │ └── recording.har │ │ ├── get-rates-of-an-order_2937298748 │ │ │ └── recording.har │ │ ├── gets-the-lowest-rate_906620131 │ │ │ └── recording.har │ │ └── retrieves-an-order_2815121385 │ │ │ └── recording.har │ ├── Parcel-Service_138173219 │ │ ├── creates-a-parcel_663902114 │ │ │ └── recording.har │ │ └── retrieves-a-parcel_174113886 │ │ │ └── recording.har │ ├── Pickup-Service_2981084322 │ │ ├── buys-a-pickup_1934475561 │ │ │ └── recording.har │ │ ├── cancels-a-pickup_4207662041 │ │ │ └── recording.har │ │ ├── creates-a-pickup_320342919 │ │ │ └── recording.har │ │ ├── gets-the-lowest-rate_906620131 │ │ │ └── recording.har │ │ ├── retrieves-a-pickup_3320623723 │ │ │ └── recording.har │ │ ├── retrieves-all-pickup_1952424459 │ │ │ └── recording.har │ │ └── retrieves-next-page-of-pickups_2715714198 │ │ │ └── recording.har │ ├── Rate-Service_2756950372 │ │ └── retrieves-a-rate_3801249961 │ │ │ └── recording.har │ ├── ReferralCustomer-Service_3380152635 │ │ ├── add-a-referral-user-credit-card_1978527022 │ │ │ └── recording.har │ │ ├── creates-a-referral-user_159009729 │ │ │ └── recording.har │ │ ├── raises-an-error-when-adding-a-bank-account-from-Stripe-fails_3043649864 │ │ │ └── recording.har │ │ ├── raises-an-error-when-adding-a-credit-card-from-Stripe-fails_4230750010 │ │ │ └── recording.har │ │ ├── retrieves-all-referral-users_447651186 │ │ │ └── recording.har │ │ ├── retrieves-next-page-of-referral-customer_33395404 │ │ │ └── recording.har │ │ └── updates-a-referral-user_2206325082 │ │ │ └── recording.har │ ├── Refund-Service_2387004908 │ │ ├── creates-a-refund_2084766157 │ │ │ └── recording.har │ │ ├── retrieves-a-refund_348903105 │ │ │ └── recording.har │ │ ├── retrieves-all-refunds_2266923862 │ │ │ └── recording.har │ │ └── retrieves-next-page-of-refunds_1983981592 │ │ │ └── recording.har │ ├── Report-Service_3431112000 │ │ ├── creates-a-report-by-specifying-columns_1660528128 │ │ │ └── recording.har │ │ ├── creates-a-report-with-additional-columns_3168456315 │ │ │ └── recording.har │ │ ├── creates-a-report_2930610569 │ │ │ └── recording.har │ │ ├── retrieves-a-shipment-report_2373872365 │ │ │ └── recording.har │ │ ├── retrieves-all-reports_3952278090 │ │ │ └── recording.har │ │ └── retrieves-next-page-of-reports_2554341452 │ │ │ └── recording.har │ ├── ScanForm-Service_1241997233 │ │ ├── creates-a-scanform_355573720 │ │ │ └── recording.har │ │ ├── retrieves-a-scanform_3128791796 │ │ │ └── recording.har │ │ ├── retrieves-all-scanforms_428090277 │ │ │ └── recording.har │ │ └── retrieves-next-page-of-scanforms_2978606387 │ │ │ └── recording.har │ ├── Shipment-Service_2987889512 │ │ ├── buys-a-shipment-with-end_shipper_id_3098977158 │ │ │ └── recording.har │ │ ├── buys-a-shipment-with-insuranceAmount_1751540137 │ │ │ └── recording.har │ │ ├── buys-a-shipment_3413405727 │ │ │ └── recording.har │ │ ├── converts-the-label-format-of-a-shipment_4034441427 │ │ │ └── recording.har │ │ ├── creates-a-shipment-when-only-IDs-are-used_3469201880 │ │ │ └── recording.har │ │ ├── creates-a-shipment-with-empty-or-null-objects-and-arrays_3556538065 │ │ │ └── recording.har │ │ ├── creates-a-shipment-with-tax_identifiers_2190110005 │ │ │ └── recording.har │ │ ├── creates-a-shipment_2399399653 │ │ │ └── recording.har │ │ ├── generates-a-form-for-a-shipment_1612844164 │ │ │ └── recording.har │ │ ├── gets-the-lowest-rate_906620131 │ │ │ └── recording.har │ │ ├── gets-the-lowest-smartrate-from-a-list-of-smartRates_633846746 │ │ │ └── recording.har │ │ ├── gets-the-lowest-smartrate_175702804 │ │ │ └── recording.har │ │ ├── insures-a-shipment_1091350575 │ │ │ └── recording.har │ │ ├── raises-an-error-for-getLowestSmartRate-when-no-rates-are-found-due-to-deliveryAccuracy_1334500637 │ │ │ └── recording.har │ │ ├── raises-an-error-for-getLowestSmartRate-when-no-rates-are-found-due-to-deliveryDays_2389038355 │ │ │ └── recording.har │ │ ├── raises-an-error-for-lowestSmartRate-when-no-rates-are-found-due-to-deliveryAccuracy_3569832305 │ │ │ └── recording.har │ │ ├── raises-an-error-for-lowestSmartRate-when-no-rates-are-found-due-to-deliveryDays_4069966983 │ │ │ └── recording.har │ │ ├── refunds-a-shipment_2011747091 │ │ │ └── recording.har │ │ ├── regenerates-rates-for-a-shipment_3874762135 │ │ │ └── recording.har │ │ ├── retrieve-estimated-delivery-dates-for-each-of-the-Rates-of-a-shipment_2875126681 │ │ │ └── recording.har │ │ ├── retrieve-recommended-ship-dates-for-each-of-the-Rates-of-a-shipment_1470819408 │ │ │ └── recording.har │ │ ├── retrieves-a-shipment_1463360065 │ │ │ └── recording.har │ │ ├── retrieves-all-shipments_2577454550 │ │ │ └── recording.har │ │ ├── retrieves-next-page-of-shipments_3501818668 │ │ │ └── recording.har │ │ └── retrieves-smartRates-of-a-shipment_606149918 │ │ │ └── recording.har │ ├── SmartRate-Service_1309568275 │ │ ├── estimate-delivery-date_838626811 │ │ │ └── recording.har │ │ └── recommend-ship-date_3612228667 │ │ │ └── recording.har │ ├── Tracker-Service_4233073632 │ │ ├── creates-a-tracker_1417034065 │ │ │ └── recording.har │ │ ├── retrieves-a-tracker_1615216565 │ │ │ └── recording.har │ │ ├── retrieves-all-trackers_1500382290 │ │ │ └── recording.har │ │ └── retrieves-next-page-of-trackers_2313111836 │ │ │ └── recording.har │ ├── User-Service_2658581389 │ │ ├── creates-a-child-user_3255934642 │ │ │ └── recording.har │ │ ├── deletes-a-user_4172759811 │ │ │ └── recording.har │ │ ├── retrieves-a-paginated-list-of-children_3912335410 │ │ │ └── recording.har │ │ ├── retrieves-a-user_2411570784 │ │ │ └── recording.har │ │ ├── retrieves-next-page-of-children_3033480518 │ │ │ └── recording.har │ │ ├── retrieves-the-authenticated-user_1794683473 │ │ │ └── recording.har │ │ ├── updates-a-user_3226344769 │ │ │ └── recording.har │ │ └── updates-the-authenticated-user-s-brand_879260623 │ │ │ └── recording.har │ └── Webhook-Service_1674309497 │ │ ├── creates-a-webhook_1900246512 │ │ └── recording.har │ │ ├── deletes-a-webhook_2516465233 │ │ └── recording.har │ │ ├── retrieves-a-webhook_2993364388 │ │ └── recording.har │ │ ├── retrieves-all-webhooks_1972539669 │ │ └── recording.har │ │ └── updates-a-webhook_1079406087 │ │ └── recording.har ├── helpers │ ├── cassette_encoding.js │ ├── common.js │ ├── fixture.js │ ├── mocking.js │ ├── setup_polly.js │ └── utils.js ├── node_compatibility │ ├── README.md │ └── index.js └── services │ ├── address.test.js │ ├── api_key.test.js │ ├── base_service.test.js │ ├── batch.test.js │ ├── beta_rate.test.js │ ├── beta_referral_customer.test.js │ ├── billing.test.js │ ├── carrier_account.test.js │ ├── carrier_metadata.test.js │ ├── carrier_type.test.js │ ├── claim.test.js │ ├── customs_info.test.js │ ├── customs_item.test.js │ ├── easypost.test.js │ ├── end_shipper.test.js │ ├── error.test.js │ ├── event.test.js │ ├── insurance.test.js │ ├── order.test.js │ ├── parcel.test.js │ ├── pickup.test.js │ ├── rate.test.js │ ├── referral_customer.test.js │ ├── refund.test.js │ ├── report.test.js │ ├── scan_form.test.js │ ├── shipment.test.js │ ├── smart_rate.test.js │ ├── tracker.test.js │ ├── user.test.js │ └── webhook.test.js ├── types ├── .eslintrc ├── Address │ ├── Address.d.ts │ ├── AddressCreateParameters.d.ts │ ├── AddressListParameters.d.ts │ ├── Verification.d.ts │ ├── VerificationDetails.d.ts │ ├── Verifications.d.ts │ └── index.d.ts ├── ApiKey │ ├── ApiKey.d.ts │ └── index.d.ts ├── Batch │ ├── Batch.d.ts │ ├── BatchCreateParameters.d.ts │ ├── BatchListParameters.d.ts │ ├── BatchShipment.d.ts │ ├── BatchState.d.ts │ ├── BatchStatus.d.ts │ ├── BatchStatuses.d.ts │ └── index.d.ts ├── Billing │ ├── Billing.d.ts │ └── index.d.ts ├── Brand │ ├── Brand.d.ts │ └── index.d.ts ├── Carrier │ ├── CarrierAccount │ │ ├── CarrierAccount.d.ts │ │ ├── CarrierAccountCreateParameters.d.ts │ │ ├── CarrierAccountField.d.ts │ │ ├── CarrierAccountFields.d.ts │ │ └── index.d.ts │ ├── CarrierMetadata │ │ ├── CarrierMetadata.d.ts │ │ └── index.d.ts │ ├── CarrierType │ │ ├── CarrierType.d.ts │ │ ├── CarrierTypeCredentials.d.ts │ │ ├── CarrierTypeFields.d.ts │ │ └── index.d.ts │ └── index.d.ts ├── Claim │ ├── Claim.d.ts │ ├── ClaimCreateParameters.d.ts │ ├── ClaimHistory.d.ts │ ├── ClaimPaymentMethod.d.ts │ ├── ClaimType.d.ts │ └── index.d.ts ├── Customs │ ├── CustomsInfo │ │ ├── CustomsInfo.d.ts │ │ ├── CustomsInfoCreateParameters.d.ts │ │ └── index.d.ts │ ├── CustomsItem │ │ ├── CustomsItem.d.ts │ │ ├── CustomsItemCreateParameters.d.ts │ │ └── index.d.ts │ └── index.d.ts ├── EasyPost.d.ts ├── EndShipper │ ├── EndShipper.d.ts │ ├── EndShipperCreateParameters.d.ts │ ├── EndShipperListParameters.d.ts │ └── index.d.ts ├── Event │ ├── Event.d.ts │ ├── EventListParameters.d.ts │ ├── Payload │ │ ├── Payload.d.ts │ │ ├── PayloadListParameters.d.ts │ │ └── index.d.ts │ └── index.d.ts ├── Fee │ ├── Fee.d.ts │ ├── FeeType.d.ts │ └── index.d.ts ├── Insurance │ ├── Insurance.d.ts │ ├── InsuranceCreateParameters.d.ts │ ├── InsuranceStatus.d.ts │ └── index.d.ts ├── Order │ ├── Order.d.ts │ ├── OrderCreateParameters.d.ts │ └── index.d.ts ├── Parcel │ ├── Parcel.d.ts │ ├── ParcelCreateParameters.d.ts │ └── index.d.ts ├── PaymentMethod │ ├── PaymentMethod.d.ts │ └── index.d.ts ├── Pickup │ ├── Pickup.d.ts │ ├── PickupCreateParameters.d.ts │ ├── PickupListParameters.d.ts │ ├── PickupRate.d.ts │ └── index.d.ts ├── Rate │ ├── Rate.d.ts │ └── index.d.ts ├── Referral │ ├── Referral.d.ts │ ├── ReferralCreateParameters.d.ts │ ├── ReferralListParameters.d.ts │ └── index.d.ts ├── Refund │ ├── Refund.d.ts │ ├── RefundCreateParameters.d.ts │ ├── RefundListParameters.d.ts │ └── index.d.ts ├── Report │ ├── Report.d.ts │ ├── ReportCreateParameters.d.ts │ ├── ReportListParameters.d.ts │ ├── ReportObjectType.d.ts │ └── index.d.ts ├── ScanForm │ ├── ScanForm.d.ts │ ├── ScanFormCreateParameters.d.ts │ ├── ScanFormListParameters.d.ts │ └── index.d.ts ├── Shipment │ ├── Form.d.ts │ ├── Message.d.ts │ ├── Options │ │ ├── LabelFormat.d.ts │ │ ├── Options.d.ts │ │ ├── PrintCustomCode.d.ts │ │ └── index.d.ts │ ├── PostageLabel.d.ts │ ├── Rate.d.ts │ ├── Shipment.d.ts │ ├── ShipmentCreateParameters.d.ts │ ├── ShipmentListParameters.d.ts │ └── index.d.ts ├── SmartRate │ └── SmartRate.d.ts ├── Tracker │ ├── CarrierDetail.d.ts │ ├── Tracker.d.ts │ ├── TrackerCreateParameters.d.ts │ ├── TrackerListParameters.d.ts │ ├── TrackerStatus.d.ts │ ├── TrackerStatusDetail.d.ts │ ├── TrackingDetail.d.ts │ ├── TrackingLocation.d.ts │ └── index.d.ts ├── User │ ├── User.d.ts │ ├── UserCreateParameters.d.ts │ └── index.d.ts ├── Utility │ ├── Utils.d.ts │ └── index.d.ts ├── Webhook │ ├── Webhook.d.ts │ ├── WebhookCreateParameters.d.ts │ ├── WebhookListParameters.d.ts │ └── index.d.ts ├── base.d.ts ├── demo │ ├── README.md │ ├── index.ts │ ├── package-lock.json │ └── package.json ├── errors │ ├── Error.d.ts │ ├── ErrorCode.d.ts │ ├── FieldError.d.ts │ └── index.d.ts ├── index.d.ts └── utils.d.ts ├── vite.config.js └── vitest.config.js /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | # Cassettes 4 | *.har -diff 5 | *.har linguist-generated 6 | 7 | # Docs 8 | docs/**/* -diff 9 | docs/**/* linguist-generated 10 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Ping the Shippers team for reviews on every PR 2 | * @EasyPost/team-shippers 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: File a bug report 3 | title: '[Bug]: ' 4 | labels: ['triage'] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thank you for taking the time to report an issue in this repository. Please fill out the form below. 10 | - type: input 11 | id: software-version 12 | attributes: 13 | label: Software Version 14 | # change this description for the specific repo 15 | description: | 16 | What version of our software are you running? 17 | TIP: [Available versions](https://github.com/EasyPost/easypost-node/releases) 18 | validations: 19 | required: true 20 | - type: input 21 | id: language-version 22 | attributes: 23 | label: Language Version 24 | # change this description for the specific language of the repo 25 | description: | 26 | What language version and/or framework are you using? 27 | TIP: [How to find your Node version](https://flaviocopes.com/node-version-runtime/) 28 | validations: 29 | required: true 30 | - type: input 31 | id: os 32 | attributes: 33 | label: Operating System 34 | description: What operating system are you running the software on? 35 | validations: 36 | required: true 37 | - type: textarea 38 | id: behavior 39 | attributes: 40 | label: What happened? 41 | description: | 42 | Please describe what happened in reproducible steps. 43 | Include how often you see this issue, and any relevant links (i.e. GitHub issue, Stack Overflow, etc.). 44 | value: | 45 | 1. 46 | 2. 47 | 3. 48 | ... 49 | validations: 50 | required: true 51 | - type: textarea 52 | id: expected-behavior 53 | attributes: 54 | label: What was expected? 55 | description: Please describe what was expected to happen instead. 56 | validations: 57 | required: true 58 | - type: textarea 59 | id: sample-code 60 | attributes: 61 | label: Sample Code 62 | description: | 63 | Please provide any sample code that demonstrates the behavior. 64 | This will be automatically formatted into the appropriate language, so no need for backticks. 65 | **Do not include any private information such as API keys or passwords.** 66 | # change this render to the appropriate language: https://github.com/github/linguist/blob/master/lib/linguist/languages.yml 67 | render: node 68 | validations: 69 | required: false 70 | - type: textarea 71 | id: logs 72 | attributes: 73 | label: Relevant logs 74 | description: | 75 | Please copy and paste any relevant log output. 76 | This will be automatically formatted into shell output, so no need for backticks. 77 | If you have screenshots instead, please paste them below. 78 | **Do not include any private information such as API keys or passwords.** 79 | render: sh 80 | validations: 81 | required: false 82 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: Feature Request 2 | description: Request a new feature 3 | title: '[Feat]: ' 4 | labels: ['triage'] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thank you for taking the time to request a new feature. 10 | Please note, all feature requests are subject to review and approval. 11 | We welcome all suggestions and ideas, but we cannot guarantee when or if we will implement them. 12 | 13 | We also welcome pull requests, if you would like to implement the feature yourself. 14 | Doing so will likely accelerate the process of implementing the requested feature. 15 | - type: checkboxes 16 | id: searched 17 | attributes: 18 | label: Feature Request Is New 19 | # change issue link below for the specific repo 20 | description: | 21 | Before we begin, please confirm that the requested feature does not already exist or has not [already been requested](https://github.com/EasyPost/easypost-node/issues). 22 | options: 23 | - label: I have verified that the requested feature does not already exist or has not already been requested. 24 | required: true 25 | - type: textarea 26 | id: description 27 | attributes: 28 | label: Description of the feature 29 | description: | 30 | Please provide a detailed description of the feature, including: 31 | - What the feature is 32 | - What value it adds to the application 33 | - How it should be implemented (i.e. pseudo-code, or a high-level description of the user experience) 34 | - Any other relevant information 35 | validations: 36 | required: true 37 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | 4 | 5 | # Testing 6 | 7 | 14 | 15 | # Pull Request Type 16 | 17 | Please select the option(s) that are relevant to this PR. 18 | 19 | - [ ] Bug fix (non-breaking change which fixes an issue) 20 | - [ ] New feature (non-breaking change which adds functionality) 21 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 22 | - [ ] Improvement (fixing a typo, updating readme, renaming a variable name, etc) 23 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [master] 6 | pull_request: ~ 7 | workflow_dispatch: ~ 8 | 9 | jobs: 10 | # build checks that the app can build and runs tests on the latest node version 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v4 15 | - uses: actions/setup-node@v4 16 | with: 17 | node-version: 22 18 | - run: EASYPOST_TEST_API_KEY=123 EASYPOST_PROD_API_KEY=123 make install install-styleguide build test 19 | # node-compatibility checks that the build version of the app can be imported 20 | # and used on older versions of node 21 | node-compatibility: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | node-version: [16.x, 17.x, 18.x, 19.x, 20.x, 21.x, 22.x] 26 | steps: 27 | - uses: actions/checkout@v4 28 | - uses: actions/setup-node@v4 29 | with: 30 | node-version: 22 31 | - run: EASYPOST_TEST_API_KEY=123 EASYPOST_PROD_API_KEY=123 make install install-styleguide build 32 | - uses: actions/setup-node@v4 33 | with: 34 | node-version: ${{ matrix.node-version }} 35 | - run: EASYPOST_TEST_API_KEY=123 EASYPOST_PROD_API_KEY=123 make test-node-compatibility 36 | lint: 37 | runs-on: ubuntu-latest 38 | steps: 39 | - uses: actions/checkout@v4 40 | - uses: actions/setup-node@v4 41 | with: 42 | node-version: 22 43 | - run: make install install-styleguide build lint 44 | coverage: 45 | runs-on: ubuntu-latest 46 | steps: 47 | - uses: actions/checkout@v4 48 | - uses: actions/setup-node@v4 49 | with: 50 | node-version: 22 51 | - run: make install install-styleguide build 52 | - run: EASYPOST_TEST_API_KEY=123 EASYPOST_PROD_API_KEY=123 make coverage 53 | - name: Coveralls 54 | if: github.ref == 'refs/heads/master' 55 | uses: coverallsapp/github-action@master 56 | with: 57 | github-token: ${{ secrets.GITHUB_TOKEN }} 58 | docs: 59 | if: github.ref == 'refs/heads/master' 60 | runs-on: ubuntu-latest 61 | steps: 62 | - uses: actions/checkout@v4 63 | - uses: actions/setup-node@v4 64 | with: 65 | node-version: 22 66 | - name: Install Dependencies 67 | run: make install 68 | - name: Generate Docs 69 | run: make docs 70 | - name: Deploy docs 71 | uses: peaceiris/actions-gh-pages@v3 72 | with: 73 | github_token: ${{ secrets.GITHUB_TOKEN }} 74 | publish_dir: docs 75 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | release: 5 | types: [published] 6 | workflow_dispatch: ~ 7 | 8 | jobs: 9 | release: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v4 13 | - uses: actions/setup-node@v4 14 | with: 15 | node-version: 22 16 | registry-url: 'https://registry.npmjs.org' 17 | - name: Publish Package 18 | run: EASYPOST_TEST_API_KEY=123 EASYPOST_PROD_API_KEY=123 make install install-styleguide publish 19 | env: 20 | NODE_AUTH_TOKEN: ${{ secrets.NPM_API_KEY }} 21 | - name: Upload assets to release 22 | uses: AButler/upload-release-assets@v3.0 23 | with: 24 | files: 'dist/*' 25 | repo-token: ${{ secrets.GITHUB_TOKEN }} 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ._* 2 | .AppleDouble 3 | .DS_Store 4 | .env 5 | .idea/ 6 | .LSOverride 7 | .nyc_output 8 | .Spotlight-V100 9 | .Trashes 10 | .vscode/ 11 | build.tar.gz 12 | coverage 13 | dist 14 | docs 15 | Icon 16 | node_modules 17 | npm-debug.log 18 | /.eslintrc 19 | /.eslintignore 20 | /.prettierrc.yml 21 | /.prettierignore 22 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "examples"] 2 | path = examples 3 | url = https://github.com/EasyPost/examples 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # This file is written to be an allowlist instead of a disallow. Start by ignoring everything, 2 | # then add back the files we want to be included in the final NPM package: 3 | * 4 | 5 | # These are the files that are allowed: 6 | !/CHANGELOG.md 7 | !/dist/**/* 8 | !/LICENSE 9 | !/package.json 10 | !/prop_types.js 11 | !/README.md 12 | !/src/**/* 13 | !/types/**/* 14 | !/UPGRADE_GUIDE.md 15 | 16 | # Here we exclude files that we pulled in from above that should be removed 17 | .DS_Store 18 | types/.eslintrc 19 | types/demo 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2013 EasyPost (Simpler Postage, Inc) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ## help - Display help about make targets for this Makefile 2 | help: 3 | @cat Makefile | grep '^## ' --color=never | cut -c4- | sed -e "`printf 's/ - /\t- /;'`" | column -s "`printf '\t'`" -t 4 | 5 | ## build - Builds the project 6 | build: 7 | npm run build 8 | 9 | ## clean - Cleans the project 10 | clean: 11 | npm run clean 12 | 13 | ## coverage - Test the project and generate a coverage report 14 | coverage: 15 | npm run coverage 16 | 17 | ## docs - Generate docs for the library 18 | docs: 19 | npm run docs 20 | 21 | ## eslint - Lint the project 22 | eslint: 23 | npm run lint 24 | 25 | ## eslint-fix - Fixes the lint 26 | eslint-fix: 27 | npm run lintFix 28 | 29 | ## init-examples-submodule - Initialize the examples submodule 30 | init-examples-submodule: 31 | git submodule init 32 | git submodule update 33 | 34 | ## install-styleguide - Install the styleguide (Unix only) 35 | install-styleguide: | update-examples-submodule 36 | sh examples/symlink_directory_files.sh examples/style_guides/node . 37 | 38 | ## install - Install project dependencies (Unix only) 39 | install: | init-examples-submodule 40 | npm install 41 | 42 | ## lint - Lint the project 43 | lint: eslint prettier scan 44 | 45 | ## fix - Fix linting errors 46 | lint-fix: eslint-fix prettier-fix 47 | 48 | ## publish - Publish the built assets to NPM 49 | publish: 50 | npm publish 51 | 52 | ## publish-next - Publish the built assets to NPM for a release candidate 53 | publish-next: 54 | npm publish --tag next 55 | 56 | ## prettier - Checks the format with prettier 57 | prettier: 58 | npm run formatCheck 59 | 60 | ## prettier-fix - Fixes the format with prettier 61 | prettier-fix: 62 | npm run format 63 | 64 | ## release - Cuts a release for the project on GitHub (requires GitHub CLI) 65 | # tag = The associated tag title of the release 66 | # target = Target branch or full commit SHA 67 | release: 68 | gh release create ${tag} dist/* --target ${target} 69 | 70 | ## scan - Runs security analysis on the project with Brakeman 71 | scan: 72 | npm run scan 73 | 74 | ## test - Test the project 75 | test: 76 | npm run test 77 | 78 | ## test-node-compatibility - Check the built project works for older versions of Node 79 | test-node-compatibility: 80 | npm run test:node-compatibility 81 | 82 | ## update - Update dependencies (Unix only) 83 | update: | update-examples-submodule 84 | npm update 85 | 86 | ## update-examples-submodule - Update the examples submodule 87 | update-examples-submodule: 88 | git submodule init 89 | git submodule update --remote 90 | 91 | .PHONY: help build clean coverage docs install lint lint-fix publish release scan test update update-examples-submodule 92 | -------------------------------------------------------------------------------- /audit-ci.jsonc: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://github.com/IBM/audit-ci/raw/main/docs/schema.json", 3 | // Only fail the audit if there are critical vulnerabilities. 4 | "critical": true, 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@easypost/api", 3 | "description": "EasyPost Node Client Library", 4 | "version": "8.1.0", 5 | "author": "Easypost Engineering ", 6 | "homepage": "https://easypost.com", 7 | "exports": { 8 | ".": { 9 | "import": "./dist/easypost.mjs", 10 | "require": "./dist/easypost.js", 11 | "types": "./types/index.d.ts" 12 | } 13 | }, 14 | "main": "./dist/easypost.js", 15 | "module": "./dist/easypost.mjs", 16 | "types": "./types/index.d.ts", 17 | "repository": { 18 | "type": "git", 19 | "url": "git://github.com/easypost/easypost-node.git" 20 | }, 21 | "license": "MIT", 22 | "engines": { 23 | "node": ">= 16.0" 24 | }, 25 | "scripts": { 26 | "build": "vite build", 27 | "clean": "rm -rf ./dist ./nyc_output ./node_modules/.cache ./coverage", 28 | "coverage": "cross-env NODE_ENV=test vitest run --coverage", 29 | "docs": "./node_modules/.bin/jsdoc src/models src/services src/errors src/utils -d docs", 30 | "format": "prettier --write .", 31 | "formatCheck": "prettier --check .", 32 | "lint": "eslint --ext .js,.ts .", 33 | "lintFix": "eslint --ext .js,.ts --fix .", 34 | "prepublishOnly": "npm run clean && npm run build && npm run test && npm run lint && npm run formatCheck", 35 | "repl": "./repl.js --local ./dist/easypost.js", 36 | "scan": "npx audit-ci -m --config ./audit-ci.jsonc", 37 | "test": "cross-env NODE_ENV=test vitest run", 38 | "test:node-compatibility": "cross-env NODE_ENV=test node ./test/node_compatibility", 39 | "watch": "vite build --watch" 40 | }, 41 | "dependencies": { 42 | "core-js": "~3.41", 43 | "nodent-runtime": "~3.2.1", 44 | "regenerator-runtime": "~0.14.1", 45 | "source-map-support": "~0.5.21", 46 | "superagent": "~10.1.1", 47 | "uuid": "^11.1.0", 48 | "yargs": "~17.7.2", 49 | "yargs-parser": "~21.1.1" 50 | }, 51 | "devDependencies": { 52 | "@pollyjs/adapter-node-http": "^6.0.6", 53 | "@pollyjs/core": "^6.0.6", 54 | "@pollyjs/persister-fs": "^6.0.6", 55 | "@typescript-eslint/eslint-plugin": "^5.59.5", 56 | "@typescript-eslint/parser": "^5.59.5", 57 | "@vitest/coverage-istanbul": "^3.0.6", 58 | "audit-ci": "^7.1", 59 | "chai": "5.2", 60 | "chai-as-promised": "^8.0.1", 61 | "cross-env": "^7.0.3", 62 | "dotenv": "^16.4.5", 63 | "eslint": "^8.40.0", 64 | "eslint-config-prettier": "^8.8.0", 65 | "eslint-import-resolver-webpack": "^0.13.2", 66 | "eslint-plugin-babel": "^5.3.1", 67 | "eslint-plugin-import": "^2.27.5", 68 | "eslint-plugin-jest": "^27.2.1", 69 | "eslint-plugin-jsx-a11y": "^6.7.1", 70 | "eslint-plugin-react": "^7.32.1", 71 | "eslint-plugin-vitest-globals": "^1.5.0", 72 | "jsdoc": "^4.0.2", 73 | "prettier": "^3.5", 74 | "typescript": "^4.9.5 || ~5.0.0", 75 | "vite": "^6.2", 76 | "vite-plugin-externals": "^0.6.2", 77 | "vitest": "^3.0.6", 78 | "vows": "^0.8.3" 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/constants.js: -------------------------------------------------------------------------------- 1 | import Utils from './utils/util'; 2 | 3 | /** 4 | * A class containing constants used throughout the EasyPost Node.js client library. 5 | */ 6 | export default class Constants { 7 | static get CARRIER_ACCOUNTS_WITH_CUSTOM_CREATE_WORKFLOWS() { 8 | return ['FedexAccount', 'FedexSmartpostAccount']; 9 | } 10 | static get CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH() { 11 | return [ 12 | 'AmazonShippingAccount', 13 | 'UpsAccount', 14 | 'UpsMailInnovationsAccount', 15 | 'UpsSurepostAccount', 16 | ]; 17 | } 18 | static EXTERNAL_API_CALL_FAILED = 'Communication with %s failed, please try again later'; 19 | static INVALID_API_KEY_TYPE = 'Invalid API key type.'; 20 | static INVALID_PARAMETER = 'Invalid parameter: %s.'; 21 | static INVALID_PAYMENT = 'The chosen payment method is not a credit card. Please try again.'; 22 | static INVALID_WEBHOOK_SIGNATURE = 'Webhook does not contain a valid HMAC signature.'; 23 | static MISSING_REQUIRED_PARAMETER = 'Missing required parameter: %s.'; 24 | static NO_OBJECT_FOUND = 'No %s found.'; 25 | static NO_PAYMENT_METHODS = 26 | 'No payment methods are set up. Please add a payment method and try again.'; 27 | static API_DID_NOT_RETURN_ERROR_DETAILS = 'API did not return error details.'; 28 | static WEBHOOK_DOES_NOT_MATCH = 29 | 'Webhook received did not originate from EasyPost or had a webhook secret mismatch.'; 30 | static END_OF_PAGINATION = 'There are no more pages to retrieve.'; 31 | static ERROR_DESERIALIZATION = 'Error deserializing JSON response'; 32 | static Utils = new Utils(); 33 | } 34 | -------------------------------------------------------------------------------- /src/errors/api/api_error.js: -------------------------------------------------------------------------------- 1 | import EasyPostError from '../easypost_error'; 2 | 3 | /** 4 | * The ApiError class is used to represent errors that occurred while communicating with the EasyPost API. 5 | * This class should not be instantiated directly. 6 | * @internal 7 | * @abstract 8 | * @extends EasyPostError 9 | * @property {string} [message] - The message to be displayed when the error is logged. 10 | * @property {string} [code] - The EasyPost-related error code returned by the EasyPost API. 11 | * @property {number} [statusCode] - The HTTP status code returned by the HTTP request to the EasyPost API. 12 | * @property {EasyPostError[]} [errors] - An array of sub-errors returned by the EasyPost API. 13 | */ 14 | export default class ApiError extends EasyPostError { 15 | constructor({ message, code, statusCode, errors } = {}) { 16 | super({ message }); 17 | this.code = code; 18 | this.errors = errors; 19 | this.message = message; 20 | this.statusCode = statusCode; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/errors/api/bad_request_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The BadRequestError class is used to represent a 400 error that occurred while communicating with the EasyPost API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 10 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 11 | */ 12 | export default class BadRequestError extends ApiError {} 13 | -------------------------------------------------------------------------------- /src/errors/api/external_api_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The ExternalApiError class is used to represent errors that occurred while communicating with an external API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | */ 10 | export default class ExternalApiError extends ApiError {} 11 | -------------------------------------------------------------------------------- /src/errors/api/forbidden_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The ForbiddenError class is used to represent a 403 error that occurred while communicating with the EasyPost API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 10 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 11 | */ 12 | export default class ForbiddenError extends ApiError {} 13 | -------------------------------------------------------------------------------- /src/errors/api/gateway_timeout_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The GatewayTimeoutError class is used to represent a 504 error that occurred while communicating with the EasyPost API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 10 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 11 | */ 12 | export default class GatewayTimeoutError extends ApiError {} 13 | -------------------------------------------------------------------------------- /src/errors/api/http_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The HttpError class is used to represent a generic HTTP-related error that occurred while communicating with the EasyPost API. 5 | * @extends ApiError 6 | * @param {string} [message] - The message to be displayed when the error is logged. 7 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 8 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 9 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 10 | */ 11 | export default class HTTPError extends ApiError {} 12 | -------------------------------------------------------------------------------- /src/errors/api/internal_server_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The InternalServerError class is used to represent a 500 error that occurred while communicating with the EasyPost API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 10 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 11 | */ 12 | export default class InternalServerError extends ApiError {} 13 | -------------------------------------------------------------------------------- /src/errors/api/invalid_request_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The InvalidRequestError class is used to represent a 422 error that occurred while communicating with the EasyPost API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 10 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 11 | */ 12 | export default class InvalidRequestError extends ApiError {} 13 | -------------------------------------------------------------------------------- /src/errors/api/method_not_allowed_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The MethodNotAllowedError class is used to represent a 405 error that occurred while communicating with the EasyPost API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 10 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 11 | */ 12 | export default class MethodNotAllowedError extends ApiError {} 13 | -------------------------------------------------------------------------------- /src/errors/api/not_found_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The NotFoundError class is used to represent a 404 error that occurred while communicating with the EasyPost API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 10 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 11 | */ 12 | export default class NotFoundError extends ApiError {} 13 | -------------------------------------------------------------------------------- /src/errors/api/payment_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The PaymentError class is used to represent a 402 error that occurred while communicating with the EasyPost API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 10 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 11 | */ 12 | export default class PaymentError extends ApiError {} 13 | -------------------------------------------------------------------------------- /src/errors/api/rate_limit_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The RateLimitError class is used to represent a 429 error that occurred while communicating with the EasyPost API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 10 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 11 | */ 12 | export default class RateLimitError extends ApiError {} 13 | -------------------------------------------------------------------------------- /src/errors/api/redirect_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The RedirectError class is used to represent a 3xx error that occurred while communicating with the EasyPost API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 10 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 11 | */ 12 | export default class RedirectError extends ApiError {} 13 | -------------------------------------------------------------------------------- /src/errors/api/service_unavailable_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The ServiceUnavailableError class is used to represent a 503 error that occurred while communicating with the EasyPost API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 10 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 11 | */ 12 | export default class ServiceUnavailableError extends ApiError {} 13 | -------------------------------------------------------------------------------- /src/errors/api/timeout_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The TimeoutError class is used to represent a 408 error that occurred while communicating with the EasyPost API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 10 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 11 | */ 12 | export default class TimeoutError extends ApiError {} 13 | -------------------------------------------------------------------------------- /src/errors/api/unauthorized_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The UnauthorizedError class is used to represent a 401 error that occurred while communicating with the EasyPost API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 10 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 11 | */ 12 | export default class UnauthorizedError extends ApiError {} 13 | -------------------------------------------------------------------------------- /src/errors/api/unknown_api_error.js: -------------------------------------------------------------------------------- 1 | import ApiError from './api_error'; 2 | 3 | /** 4 | * The UnknownApiError class is used to represent a generic, unexpected error that occurred while communicating with the EasyPost API. 5 | * @sealed 6 | * @extends ApiError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | * @param {number} [statusCode] - The HTTP status code returned by the HTTP request. 9 | * @param {string} [code] - The EasyPost-related error code returned by the EasyPost API. 10 | * @param {Array} [errors] - An array of sub-errors returned by the EasyPost API. 11 | */ 12 | export default class UnknownApiError extends ApiError {} 13 | -------------------------------------------------------------------------------- /src/errors/easypost_error.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The EasyPostError class is the base class for all errors that occur in the EasyPost Node.js client library. 3 | * This class should not be instantiated directly. 4 | * @internal 5 | * @abstract 6 | * @extends Error 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | */ 9 | export default class EasyPostError extends Error { 10 | constructor({ message } = {}) { 11 | super(message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/errors/general/end_of_pagination_error.js: -------------------------------------------------------------------------------- 1 | import Constants from '../../constants'; 2 | import EasyPostError from '../easypost_error'; 3 | 4 | /** 5 | * The EndOfPaginationError class is used to represent an error that no more page can be retrieved 6 | * @sealed 7 | * @extends EasyPostError 8 | * @param {string} [message] - The message to be displayed when the error is logged. 9 | */ 10 | export default class EndOfPaginationError extends EasyPostError { 11 | constructor() { 12 | super({ message: Constants.END_OF_PAGINATION }); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/errors/general/filtering_error.js: -------------------------------------------------------------------------------- 1 | import EasyPostError from '../easypost_error'; 2 | 3 | /** 4 | * The FilteringError class is used to represent an error that occurred while filtering a list (e.g. a list of rates). 5 | * @sealed 6 | * @extends EasyPostError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | */ 9 | export default class FilteringError extends EasyPostError {} 10 | -------------------------------------------------------------------------------- /src/errors/general/invalid_object_error.js: -------------------------------------------------------------------------------- 1 | import EasyPostError from '../easypost_error'; 2 | 3 | /** 4 | * The InvalidObjectError class is used to represent an error due to an invalid object (e.g. missing an expected property). 5 | * @sealed 6 | * @extends EasyPostError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | */ 9 | export default class InvalidObjectError extends EasyPostError {} 10 | -------------------------------------------------------------------------------- /src/errors/general/invalid_parameter_error.js: -------------------------------------------------------------------------------- 1 | import EasyPostError from '../easypost_error'; 2 | 3 | /** 4 | * The InvalidParameterError class is used to represent an error due to an invalid function parameter. 5 | * @sealed 6 | * @extends EasyPostError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | */ 9 | export default class InvalidParameterError extends EasyPostError {} 10 | -------------------------------------------------------------------------------- /src/errors/general/missing_parameter_error.js: -------------------------------------------------------------------------------- 1 | import EasyPostError from '../easypost_error'; 2 | 3 | /** 4 | * The MissingParameterError class is used to represent an error due to a missing expected function parameter. 5 | * @sealed 6 | * @extends EasyPostError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | */ 9 | export default class MissingParameterError extends EasyPostError {} 10 | -------------------------------------------------------------------------------- /src/errors/general/signature_verification_error.js: -------------------------------------------------------------------------------- 1 | import EasyPostError from '../easypost_error'; 2 | 3 | /** 4 | * The SignatureVerificationError class is used to represent an error due to a failed signature verification (e.g. a webhook HMAC signature). 5 | * @sealed 6 | * @extends EasyPostError 7 | * @param {string} [message] - The message to be displayed when the error is logged. 8 | */ 9 | export default class SignatureVerificationError extends EasyPostError {} 10 | -------------------------------------------------------------------------------- /src/models/address.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * An {@link https://docs.easypost.com/docs/addresses Address} represents people, places, and organizations in a number of contexts. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class Address extends EasyPostObject { 9 | static street1; 10 | static street2; 11 | static city; 12 | static state; 13 | static zip; 14 | static country; 15 | static residential; 16 | static carrier_facility; 17 | static name; 18 | static company; 19 | static phone; 20 | static email; 21 | static federal_tax_id; 22 | static state_tax_id; 23 | static verifications; 24 | } 25 | -------------------------------------------------------------------------------- /src/models/api_key.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * An {@link https://docs.easypost.com/docs/api-keys ApiKey} represents an authentication token that can be used to make requests to the EasyPost API. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class ApiKey extends EasyPostObject { 9 | static active; 10 | static key; 11 | } 12 | -------------------------------------------------------------------------------- /src/models/batch.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/batches Batch} represents a collection of {@link Shipment shipments} that can be processed together. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class Batch extends EasyPostObject { 9 | static label_url; 10 | static num_shipments; 11 | static pickup; 12 | static reference; 13 | static scan_form; 14 | static shipments; 15 | static state; 16 | static status; 17 | } 18 | -------------------------------------------------------------------------------- /src/models/brand.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/users/brand Brand} represents custom branding for an EasyPost user's public-facing tracking details page. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class Brand extends EasyPostObject { 9 | static ad_href; 10 | static ad; 11 | static background_color; 12 | static color; 13 | static logo_href; 14 | static logo; 15 | static name; 16 | static theme; 17 | static user_id; 18 | } 19 | -------------------------------------------------------------------------------- /src/models/carrier_account.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/carrier-accounts CarrierAccount} represents details about a specific enabled carrier, including credentials and other information. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class CarrierAccount extends EasyPostObject { 9 | static billing_type; 10 | static clone; 11 | static credentials; 12 | static description; 13 | static fields; 14 | static readable; 15 | static reference; 16 | static test_credentials; 17 | } 18 | -------------------------------------------------------------------------------- /src/models/carrier_type.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/carrier-types CarrierType} represents the valid fields for a {@link CarrierAccount carrier account}. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class CarrierType extends EasyPostObject { 9 | static fields; 10 | static type; 11 | } 12 | -------------------------------------------------------------------------------- /src/models/claim.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * An {@link https://docs.easypost.com/docs/insurance/claims Claim} object represents claim for a {@link Shipment shipment}. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class Claim extends EasyPostObject { 9 | static id; 10 | static object; 11 | static mode; 12 | static attachments; 13 | static contact_email; 14 | static created_at; 15 | static description; 16 | static history; 17 | static insurance_amount; 18 | static insurance_id; 19 | static payment_method; 20 | static recipient_name; 21 | static reference; 22 | static requested_amount; 23 | static shipment_id; 24 | static status_detail; 25 | static status_timestamp; 26 | static status; 27 | static tracking_code; 28 | static type; 29 | static updated_at; 30 | } 31 | -------------------------------------------------------------------------------- /src/models/customs_info.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/customs-infos CustomsInfo} represents a collection of {@link CustomsItem CustomsItems} and associated information for generating international shipping customs forms. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class CustomsInfo extends EasyPostObject { 9 | static content_explanation; 10 | static contents_type; 11 | static customs_certify; 12 | static customs_items; 13 | static customs_signer; 14 | static declaration; 15 | static eel_pfc; 16 | static non_delivery_option; 17 | static restriction_comments; 18 | static restriction_type; 19 | } 20 | -------------------------------------------------------------------------------- /src/models/customs_item.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/customs-items CustomsItem} represents a single item being shipped internationally. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class CustomsItem extends EasyPostObject { 9 | static code; 10 | static currency; 11 | static description; 12 | static hs_tariff_number; 13 | static origin_country; 14 | static quantity; 15 | static value; 16 | static weight; 17 | } 18 | -------------------------------------------------------------------------------- /src/models/easypost_object.js: -------------------------------------------------------------------------------- 1 | /** 2 | * An EasyPostObject is the base class for all EasyPost API resources. 3 | * @internal 4 | * @abstract 5 | */ 6 | export default class EasyPostObject { 7 | static id; 8 | static object; 9 | static mode; 10 | static created_at; 11 | static updated_at; 12 | static _params; 13 | } 14 | -------------------------------------------------------------------------------- /src/models/end_shipper.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * An {@link https://docs.easypost.com/docs/endshippers 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. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class EndShipper extends EasyPostObject { 9 | static street1; 10 | static street2; 11 | static city; 12 | static state; 13 | static zip; 14 | static country; 15 | static name; 16 | static company; 17 | static phone; 18 | static email; 19 | } 20 | -------------------------------------------------------------------------------- /src/models/event.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * An {@link https://docs.easypost.com/docs/events Event} represents a change in state for elements such as {@link Shipment shipments} and {@link Tracker trackers}, that triggers a {@link Webhook webhook}. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class Event extends EasyPostObject { 9 | static completed_urls; 10 | static description; 11 | static pending_urls; 12 | static previous_attributes; 13 | static result; 14 | static status; 15 | } 16 | -------------------------------------------------------------------------------- /src/models/form.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/shipments/forms Form} represents a printable form for a {@link Shipment shipment}, such as a return packing slip, QR code or international shipping form. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class Form extends EasyPostObject { 9 | static form_type; 10 | static form_url; 11 | static submitted_electronically; 12 | } 13 | -------------------------------------------------------------------------------- /src/models/insurance.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * An {@link https://docs.easypost.com/docs/api-keys Insurance} object represents insurance for a {@link Shipment shipment}. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class Insurance extends EasyPostObject { 9 | static amount; 10 | static fee; 11 | static from_address; 12 | static messages; 13 | static provider_id; 14 | static provider; 15 | static reference; 16 | static shipment_id; 17 | static status; 18 | static to_address; 19 | static tracking_code; 20 | static tracker; 21 | } 22 | -------------------------------------------------------------------------------- /src/models/order.js: -------------------------------------------------------------------------------- 1 | import Constants from '../constants'; 2 | import EasyPostObject from './easypost_object'; 3 | 4 | /** 5 | * An {@link https://docs.easypost.com/docs/orders Order} represents a collection of packages, intended only for multi-parcel shipments. 6 | * @public 7 | * @extends EasyPostObject 8 | */ 9 | export default class Order extends EasyPostObject { 10 | static buyer_address; 11 | static from_address; 12 | static is_return; 13 | static messages; 14 | static rates; 15 | static reference; 16 | static return_address; 17 | static shipments; 18 | static to_address; 19 | 20 | /** 21 | * Get the lowest rate for this {@link Order}. 22 | * @public 23 | * @param {string[]} [carriers] - List of allowed carriers to filter by 24 | * @param {string[]} [services] - List of allowed services to filter by 25 | * @returns {Rate} - The lowest rate 26 | * @throws {FilteringError} - If no applicable rates are found 27 | */ 28 | lowestRate(carriers, services) { 29 | const rates = this.rates || []; 30 | 31 | return Constants.Utils.getLowestRate(rates, carriers, services); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/models/parcel.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/parcels Parcel} represents a physical container being shipped, such as a box or envelope, with corresponding dimensions and weight. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class Parcel extends EasyPostObject { 9 | static height; 10 | static length; 11 | static predefined_package; 12 | static weight; 13 | static width; 14 | } 15 | -------------------------------------------------------------------------------- /src/models/payload.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/events/payloads Payload} represents an attempt by EasyPost to send an {@link Event event} to a {@link Webhook webhook}. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class Payload extends EasyPostObject { 9 | static response_body; 10 | } 11 | -------------------------------------------------------------------------------- /src/models/pickup.js: -------------------------------------------------------------------------------- 1 | import Constants from '../constants'; 2 | import EasyPostObject from './easypost_object'; 3 | 4 | /** 5 | * A {@link https://docs.easypost.com/docs/pickups Pickup} represents a scheduled carrier pickup of packages from an {@link https://docs.easypost.com/docs/addresses Address}. 6 | * @public 7 | * @extends EasyPostObject 8 | */ 9 | export default class Pickup extends EasyPostObject { 10 | static address; 11 | static carrier_accounts; 12 | static confirmation; 13 | static instructions; 14 | static is_account_address; 15 | static max_datetime; 16 | static messages; 17 | static min_datetime; 18 | static pickup_rates; 19 | static reference; 20 | static shipment; 21 | static status; 22 | 23 | /** 24 | * Get the lowest rate for this {@link Pickup}. 25 | * @public 26 | * @param {string[]} [carriers] - List of allowed carriers to filter by 27 | * @param {string[]} [services] - List of allowed services to filter by 28 | * @returns {Rate} - The lowest rate 29 | * @throws {FilteringError} - If no applicable rates are found 30 | */ 31 | lowestRate(carriers, services) { 32 | const rates = this.pickup_rates || []; 33 | 34 | return Constants.Utils.getLowestRate(rates, carriers, services); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/models/pickup_rate.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link PickupRate} represents a {@link Rate rate} for a {@link Pickup pickup}. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class PickupRate extends EasyPostObject { 9 | static carrier; 10 | static currency; 11 | static pickup_id; 12 | static rate; 13 | static service; 14 | } 15 | -------------------------------------------------------------------------------- /src/models/postage_label.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link PostageLabel} represents a physical label to affix to a {@link Parcel parcel} when shipping. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class PostageLabel extends EasyPostObject { 9 | static label_date; 10 | static label_epl2_url; 11 | static label_file_type; 12 | static label_pdf_url; 13 | static label_resolution; 14 | static label_size; 15 | static label_type; 16 | static label_url; 17 | static label_zpl_url; 18 | } 19 | -------------------------------------------------------------------------------- /src/models/rate.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/shipments/rates Rate} represents pricing information for shipping a specific {@link Parcel} with a specific carrier and service level. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class Rate extends EasyPostObject { 9 | static billing_type; 10 | static carrier_account_id; 11 | static carrier; 12 | static currency; 13 | static delivery_date_guaranteed; 14 | static delivery_date; 15 | static delivery_days; 16 | static est_delivery_days; 17 | static list_currency; 18 | static list_rate; 19 | static rate; 20 | static retail_currency; 21 | static retail_rate; 22 | static service; 23 | static shipment_id; 24 | } 25 | -------------------------------------------------------------------------------- /src/models/refund.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/refunds Refund} represents a refunded {@link Shipment}. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class Refund extends EasyPostObject { 9 | static carrier; 10 | static confirmation_number; 11 | static shipment_id; 12 | static status; 13 | static tracking_code; 14 | } 15 | -------------------------------------------------------------------------------- /src/models/report.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/reports Report} represents a CSV file containing a log of all objects within a specific time frame. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class Report extends EasyPostObject { 9 | static end_date; 10 | static include_children; 11 | static send_email; 12 | static start_date; 13 | static status; 14 | static url_expires_at; 15 | static url; 16 | } 17 | -------------------------------------------------------------------------------- /src/models/scan_form.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/scan-form ScanForm} represents a single document that can be scanned to mark all included tracking codes as "Accepted for Shipment" by the carrier. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class ScanForm extends EasyPostObject { 9 | static address; 10 | static batch_id; 11 | static form_file_type; 12 | static form_url; 13 | static message; 14 | static status; 15 | static tracking_codes; 16 | } 17 | -------------------------------------------------------------------------------- /src/models/shipment.js: -------------------------------------------------------------------------------- 1 | import Constants from '../constants'; 2 | import EasyPostObject from './easypost_object'; 3 | 4 | /** 5 | * A {@link https://docs.easypost.com/docs/shipments Shipment} represents a physical {@link Parcel}, the origin and destination {@link Address Addresses}, and any associated {@link CustomsInfo}. 6 | * @public 7 | * @extends EasyPostObject 8 | */ 9 | export default class Shipment extends EasyPostObject { 10 | static batch_id; 11 | static batch_message; 12 | static batch_status; 13 | static buyer_address; 14 | static customs_info; 15 | static fees; 16 | static forms; 17 | static from_address; 18 | static insurance; 19 | static is_return; 20 | static messages; 21 | static options; 22 | static parcel; 23 | static postage_label; 24 | static rates; 25 | static reference; 26 | static refund_status; 27 | static return_address; 28 | static scan_form; 29 | static selected_rate; 30 | static status; 31 | static to_address; 32 | static tracker; 33 | static tracking_code; 34 | static usps_zone; 35 | 36 | /** 37 | * Get the lowest rate for this {@link Shipment}. 38 | * @public 39 | * @param {string[]} [carriers] - List of allowed carriers to filter by 40 | * @param {string[]} [services] - List of allowed services to filter by 41 | * @returns {Rate} - The lowest rate 42 | * @throws {FilteringError} - If no applicable rates are found 43 | */ 44 | lowestRate(carriers, services) { 45 | const rates = this.rates || []; 46 | 47 | return Constants.Utils.getLowestRate(rates, carriers, services); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/models/tracker.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/trackers Tracker} represents the available tracking information for a package. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class Tracker extends EasyPostObject { 9 | static carrier_detail; 10 | static carrier; 11 | static est_delivery_date; 12 | static fees; 13 | static finalized; 14 | static is_return; 15 | static public_url; 16 | static shipment_id; 17 | static signed_by; 18 | static status_detail; 19 | static status; 20 | static tracking_code; 21 | static tracking_details; 22 | static weight; 23 | } 24 | -------------------------------------------------------------------------------- /src/models/user.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/users ApiKey} represents an EasyPost account or child account. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class User extends EasyPostObject { 9 | static api_keys; 10 | static balance; 11 | static cc_fee_rate; 12 | static children; 13 | static email; 14 | static insurance_fee_minimum; 15 | static insurance_fee_rate; 16 | static name; 17 | static parent_id; 18 | static phone_number; 19 | static price_per_shipment; 20 | static recharge_amount; 21 | static secondary_recharge_amount; 22 | } 23 | -------------------------------------------------------------------------------- /src/models/webhook.js: -------------------------------------------------------------------------------- 1 | import EasyPostObject from './easypost_object'; 2 | 3 | /** 4 | * A {@link https://docs.easypost.com/docs/webhooks Webhook} represents a URL that will receive notifications when certain {@link Event} occur. 5 | * @public 6 | * @extends EasyPostObject 7 | */ 8 | export default class Webhook extends EasyPostObject { 9 | static disabled_at; 10 | static url; 11 | } 12 | -------------------------------------------------------------------------------- /src/services/api_key_service.js: -------------------------------------------------------------------------------- 1 | import util from 'util'; 2 | 3 | import Constants from '../constants'; 4 | import FilteringError from '../errors/general/filtering_error'; 5 | import baseService from './base_service'; 6 | 7 | export default (easypostClient) => 8 | /** 9 | * The ApiKeyService class provides methods for interacting with EasyPost {@link ApiKey} objects. 10 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 11 | */ 12 | class ApiKeyService extends baseService(easypostClient) { 13 | /** 14 | * Retrieve all {@link ApiKey API keys} associated with the current authenticated user. 15 | * See {@link https://docs.easypost.com/docs/api-keys#retrieve-an-api-key EasyPost API Documentation} for more information. 16 | * @returns {Object} - An object containing the API keys associated with the current authenticated user and its child users. 17 | */ 18 | static async all(params = {}) { 19 | const url = 'api_keys'; 20 | 21 | return this._all(url, params); 22 | } 23 | 24 | /** 25 | * Retrieve API Keys for a specified {@link User user}. 26 | * See {@link https://docs.easypost.com/docs/api-keys#retrieve-an-api-key EasyPost API Documentation} for more information. 27 | * @param {string} id - The ID of the user to retrieve keys for. 28 | * @returns {Array} - List of associated API Keys. 29 | * @throws {FilteringError} If user or API Keys are not found. 30 | */ 31 | static async retrieveApiKeysForUser(id) { 32 | const url = `api_keys`; 33 | 34 | try { 35 | const response = await easypostClient._get(url); 36 | const user = this._convertToEasyPostObject(response.body); 37 | 38 | if (user.id == id) { 39 | return user.keys; 40 | } 41 | 42 | user.children.forEach((child) => { 43 | if (child.id == id) { 44 | return child.keys; 45 | } 46 | }); 47 | } catch (e) { 48 | return Promise.reject(e); 49 | } 50 | 51 | throw new FilteringError({ message: util.format(Constants.NO_OBJECT_FOUND, 'child') }); 52 | } 53 | }; 54 | -------------------------------------------------------------------------------- /src/services/beta_rate_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | /** 4 | * @extends baseService 5 | */ 6 | export default (easypostClient) => 7 | class BetaRateService extends baseService(easypostClient) { 8 | /** 9 | * Retrieve a list of stateless {@link Rate rates} based on the provided parameters. 10 | * @param {Object} params - Map of parameters for the API call 11 | * @returns {Rate[]} - List of stateless rates 12 | */ 13 | static async retrieveStatelessRates(params) { 14 | const url = 'beta/rates'; 15 | const wrappedParams = { 16 | shipment: params, 17 | }; 18 | 19 | try { 20 | const response = await easypostClient._post(url, wrappedParams); 21 | 22 | return this._convertToEasyPostObject(response.body.rates, wrappedParams); 23 | } catch (e) { 24 | return Promise.reject(e); 25 | } 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /src/services/beta_referral_customer_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | class BetaReferralCustomerService extends baseService(easypostClient) { 5 | /** 6 | * Add an existing Stripe payment method to a {@link User referral customer's} account. 7 | * @param {string} stripeCustomerId - The Stripe account's ID. 8 | * @param {string} paymentMethodReference - Reference of Stripe payment method. 9 | * @param {string} [priority] - Which priority to set the payment method to ('primary' or 'secondary'). 10 | * @returns {Object} - A JSON object representing the payment method. 11 | */ 12 | static async addPaymentMethod(stripeCustomerId, paymentMethodReference, priority = 'primary') { 13 | const params = { 14 | payment_method: { 15 | stripe_customer_id: stripeCustomerId, 16 | payment_method_reference: paymentMethodReference, 17 | priority, 18 | }, 19 | }; 20 | 21 | const url = 'beta/referral_customers/payment_method'; 22 | 23 | const response = await easypostClient._post(url, params); 24 | 25 | return response.body; 26 | } 27 | 28 | /** 29 | * Refund by amount for a recent payment. 30 | * @param {number} refundAmount - Amount to be refunded by cents. 31 | * @returns {Object} - A JSON object representing the refund. 32 | */ 33 | static async refundByAmount(refundAmount) { 34 | const params = { 35 | refund_amount: refundAmount, 36 | }; 37 | 38 | const url = 'beta/referral_customers/refunds'; 39 | 40 | const response = await easypostClient._post(url, params); 41 | 42 | return response.body; 43 | } 44 | 45 | /** 46 | * Refund a payment by a payment log ID. 47 | * @param {string} paymentLogId - ID of the payment log. 48 | * @returns {object} - Returns BetaPaymentRefund object. 49 | */ 50 | static async refundByPaymentLog(paymentLogId) { 51 | const params = { 52 | payment_log_id: paymentLogId, 53 | }; 54 | 55 | const url = 'beta/referral_customers/refunds'; 56 | 57 | const response = await easypostClient._post(url, params); 58 | 59 | return response.body; 60 | } 61 | 62 | /** 63 | * Creates a client secret to use with Stripe when adding a credit card. 64 | * @returns {object} - A JSON object representing the client secret. 65 | */ 66 | static async createCreditCardClientSecret() { 67 | const url = 'beta/setup_intents'; 68 | 69 | const response = await easypostClient._post(url, null); 70 | 71 | return response.body; 72 | } 73 | 74 | /** 75 | * Creates a client secret to use with Stripe when adding a credit card. 76 | * @returns {object} - A JSON object representing the client secret. 77 | */ 78 | static async createBankAccountClientSecret(returnUrl) { 79 | const params = returnUrl ? { return_url: returnUrl } : null; 80 | 81 | const url = 'beta/financial_connections_sessions'; 82 | 83 | const response = await easypostClient._post(url, params); 84 | 85 | return response.body; 86 | } 87 | }; 88 | -------------------------------------------------------------------------------- /src/services/carrier_metadata_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | /** 4 | * @extends baseService 5 | */ 6 | export default (easypostClient) => 7 | class CarrierMetadataService extends baseService(easypostClient) { 8 | /** 9 | * Retrieve a list of carrier metadata based on the provided parameters. 10 | * @param {Array} carriers - List of carrier in string 11 | * @param {Array} type - List of types in string 12 | * @returns {Object[]} - List of carrier metadata 13 | */ 14 | static async retrieve(carriers = null, types = null) { 15 | const url = 'metadata/carriers'; 16 | const params = { 17 | ...(carriers && carriers.length > 0 && { carriers: carriers.join(',') }), 18 | ...(types && types.length > 0 && { types: types.join(',') }), 19 | }; 20 | 21 | try { 22 | const response = await easypostClient._get(url, params); 23 | return this._convertToEasyPostObject(response.body.carriers || [], params); 24 | } catch (e) { 25 | return Promise.reject(e); 26 | } 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /src/services/carrier_type_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | /** 5 | * The CarrierTypeService class provides methods for interacting with EasyPost {@link CarrierType} objects. 6 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 7 | */ 8 | class CarrierTypeService extends baseService(easypostClient) { 9 | /** 10 | * Retrieve all {@link CarrierType carrier types} available to the current authenticated user. 11 | * See {@link https://docs.easypost.com/docs/carrier-types#retrieve-available-carrier-types EasyPost API Documentation} for more information. 12 | * @param {Object} [params] - Parameters to filter the list of carrier types. 13 | * @returns {CarrierType[]} - A list of {@link CarrierType carrier types}. 14 | */ 15 | static async all(params = {}) { 16 | const url = 'carrier_types'; 17 | 18 | try { 19 | const response = await easypostClient._get(url, params); 20 | 21 | return this._convertToEasyPostObject(response.body, params); 22 | } catch (e) { 23 | return Promise.reject(e); 24 | } 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /src/services/claim_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | /** 5 | * The ClaimService class provides methods for interacting with EasyPost {@link Claim} objects. 6 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 7 | */ 8 | class ClaimService extends baseService(easypostClient) { 9 | /** 10 | * Create a {@link Claim claim} record. 11 | * @param {Object} params - Parameters for the claim to be created. 12 | * @returns {Claim} - The created claim. 13 | */ 14 | static async create(params) { 15 | const url = 'claims'; 16 | 17 | return this._create(url, params); 18 | } 19 | 20 | /** 21 | * Retrieve all {@link Claim} records associated with the current authenticated user. 22 | * @param {Object} [params] - Parameters to filter the claim records. 23 | * @returns {Object} - An object containing the list of {@link Claim claim} records and pagination information. 24 | */ 25 | static async all(params = {}) { 26 | const url = 'claims'; 27 | 28 | return this._all(url, params); 29 | } 30 | 31 | /** 32 | * Retrieve the next page of Claim collection. 33 | * @param {Object} claims An object containing a list of {@link Claim claims} and pagination information. 34 | * @param {Number} pageSize The number of records to return on each page 35 | * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. 36 | */ 37 | static async getNextPage(claims, pageSize = null) { 38 | const url = 'claims'; 39 | return this._getNextPage(url, 'claims', claims, pageSize); 40 | } 41 | 42 | /** 43 | * Retrieve a {@link Claim claim} record by its ID. 44 | * @param {string} id - The ID of the claim to retrieve. 45 | * @returns {Claim} - The retrieved claim. 46 | */ 47 | static async retrieve(id) { 48 | const url = `claims/${id}`; 49 | 50 | return this._retrieve(url); 51 | } 52 | 53 | /** 54 | * Cancel a {@link Claim claim} record by its ID. 55 | * @param {string} id - The ID of the claim to be canceled. 56 | * @returns {Claim} - The canceled claim. 57 | */ 58 | static async cancel(id) { 59 | const url = `claims/${id}/cancel`; 60 | return this._create(url); 61 | } 62 | }; 63 | -------------------------------------------------------------------------------- /src/services/customs_info_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | /** 5 | * The CustomsInfoService class provides methods for interacting with EasyPost {@link CustomsInfo} objects. 6 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 7 | */ 8 | class CustomsInfoService extends baseService(easypostClient) { 9 | /** 10 | * Create a {@link CustomsInfo customs info} record. 11 | * See {@link https://docs.easypost.com/docs/customs-infos#create-a-customsinfo EasyPost API Documentation} for more information. 12 | * @param {Object} params - Parameters for the customs info to be created. 13 | * @returns {CustomsInfo} - The created customs info. 14 | */ 15 | static async create(params) { 16 | const url = 'customs_infos'; 17 | 18 | const wrappedParams = { 19 | customs_info: params, 20 | }; 21 | 22 | return this._create(url, wrappedParams); 23 | } 24 | 25 | /** 26 | * Retrieve a {@link CustomsInfo customs info} record by its ID. 27 | * See {@link https://docs.easypost.com/docs/customs-infos#retrieve-a-customsinfo EasyPost API Documentation} for more information. 28 | * @param {string} id - The ID of the customs info to retrieve. 29 | * @returns {CustomsInfo} - The retrieved customs info. 30 | */ 31 | static async retrieve(id) { 32 | const url = `customs_infos/${id}`; 33 | 34 | return this._retrieve(url); 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /src/services/customs_item_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | /** 5 | * The CustomsItemService class provides methods for interacting with EasyPost {@link CustomsItem} objects. 6 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 7 | */ 8 | class CustomsItemService extends baseService(easypostClient) { 9 | /** 10 | * Create a {@link CustomsItem customs item}. 11 | * See {@link https://docs.easypost.com/docs/customs-items#create-a-customsitem EasyPost API Documentation} for more information. 12 | * @param {Object} params - Parameters for the customs item to be created. 13 | * @returns {CustomsItem} - The created customs item. 14 | */ 15 | static async create(params) { 16 | const url = 'customs_items'; 17 | 18 | const wrappedParams = { 19 | customs_item: params, 20 | }; 21 | 22 | return this._create(url, wrappedParams); 23 | } 24 | 25 | /** 26 | * Retrieve a {@link CustomsItem customs item} by its ID. 27 | * See {@link https://docs.easypost.com/docs/customs-items#retrieve-a-customsitem EasyPost API Documentation} for more information. 28 | * @param {string} id - The ID of the customs item to retrieve. 29 | * @returns {CustomsItem} - The retrieved customs item. 30 | */ 31 | static async retrieve(id) { 32 | const url = `customs_items/${id}`; 33 | 34 | return this._retrieve(url); 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /src/services/end_shipper_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | /** 5 | * The EndShipperService class provides methods for interacting with EasyPost {@link EndShipper} objects. 6 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 7 | */ 8 | class EndShipperService extends baseService(easypostClient) { 9 | /** 10 | * Create an {@link EndShipper end shipper}. 11 | * See {@link https://docs.easypost.com/docs/endshippers#create-an-endshipper EasyPost API Documentation} for more information. 12 | * @param {Object} params - Parameters for the end shipper to be created. 13 | * @returns {EndShipper} - The created end shipper. 14 | */ 15 | static async create(params) { 16 | const url = 'end_shippers'; 17 | const wrappedParams = { address: params }; 18 | 19 | return this._create(url, wrappedParams); 20 | } 21 | 22 | /** 23 | * Update an {@link EndShipper end shipper}. 24 | * See {@link https://docs.easypost.com/docs/endshippers#update-an-endshipper EasyPost API Documentation} for more information. 25 | * @param {string} id - The ID of the end shipper to update. 26 | * @param {Object} params - Parameters for the end shipper to be updated. 27 | * @returns {EndShipper} - The updated end shipper. 28 | */ 29 | static async update(id, params) { 30 | const url = `end_shippers/${id}`; 31 | const wrappedParams = { address: params }; 32 | 33 | try { 34 | const response = await easypostClient._put(url, wrappedParams); 35 | 36 | return this._convertToEasyPostObject(response.body, wrappedParams); 37 | } catch (e) { 38 | return Promise.reject(e); 39 | } 40 | } 41 | 42 | /** 43 | * Retrieve an {@link EndShipper end shipper} by its ID. 44 | * See {@link https://docs.easypost.com/docs/endshippers#retrieve-an-endshipper EasyPost API Documentation} for more information. 45 | * @param {string} id - The ID of the end shipper to retrieve. 46 | * @returns {EndShipper} - The retrieved end shipper. 47 | */ 48 | static async retrieve(id) { 49 | const url = `end_shippers/${id}`; 50 | 51 | return this._retrieve(url); 52 | } 53 | 54 | /** 55 | * Retrieve all {@link EndShipper end shippers} associated with the current authenticated user. 56 | * See {@link https://docs.easypost.com/docs/endshippers#retrieve-all-endshippers EasyPost API Documentation} for more information. 57 | * @param {Object} [params] - Parameters to filter the list of end shippers. 58 | * @returns {Object} - An object containing a list of {@link EndShipper end shippers} and pagination information. 59 | */ 60 | static async all(params = {}) { 61 | const url = 'end_shippers'; 62 | 63 | return this._all(url, params); 64 | } 65 | }; 66 | -------------------------------------------------------------------------------- /src/services/insurance_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | /** 5 | * The InsuranceService class provides methods for interacting with EasyPost {@link Insurance} objects. 6 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 7 | */ 8 | class InsuranceService extends baseService(easypostClient) { 9 | /** 10 | * Create an {@link Insurance insurance} record. 11 | * See {@link https://docs.easypost.com/docs/insurance#create-an-insurance EasyPost API Documentation} for more information. 12 | * @param {Object} params - Parameters for the insurance to be created. 13 | * @returns {Insurance} - The created insurance. 14 | */ 15 | static async create(params) { 16 | const url = 'insurances'; 17 | 18 | const wrappedParams = { 19 | insurance: params, 20 | }; 21 | 22 | return this._create(url, wrappedParams); 23 | } 24 | 25 | /** 26 | * Retrieve all {@link Insurance} records associated with the current authenticated user. 27 | * See {@link https://docs.easypost.com/docs/insurance#retrieve-all-insurances EasyPost API Documentation} for more information. 28 | * @param {Object} [params] - Parameters to filter the insurance records. 29 | * @returns {Object} - An object containing the list of {@link Insurance insurance} records and pagination information. 30 | */ 31 | static async all(params = {}) { 32 | const url = 'insurances'; 33 | 34 | return this._all(url, params); 35 | } 36 | 37 | /** 38 | * Retrieve the next page of Insurance collection. 39 | * @param {Object} insurances An object containing a list of {@link Insurance insurances} and pagination information. 40 | * @param {Number} pageSize The number of records to return on each page 41 | * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. 42 | */ 43 | static async getNextPage(insurances, pageSize = null) { 44 | const url = 'insurances'; 45 | return this._getNextPage(url, 'insurances', insurances, pageSize); 46 | } 47 | 48 | /** 49 | * Retrieve an {@link Insurance insurance} record by its ID. 50 | * See {@link https://docs.easypost.com/docs/insurance#retrieve-an-insurance EasyPost API Documentation} for more information. 51 | * @param {string} id - The ID of the insurance to retrieve. 52 | * @returns {Insurance} - The retrieved insurance. 53 | */ 54 | static async retrieve(id) { 55 | const url = `insurances/${id}`; 56 | 57 | return this._retrieve(url); 58 | } 59 | 60 | /** 61 | * Refund an {@link Insurance insurance} record by its ID. 62 | * See {@link https://docs.easypost.com/docs/insurance#refund-an-insurance EasyPost API Documentation} for more information. 63 | * @param {string} id - The ID of the insurance to be refunded. 64 | * @returns {Insurance} - The refunded insurance. 65 | */ 66 | static async refund(id) { 67 | const url = `insurances/${id}/refund`; 68 | const response = await easypostClient._post(url); 69 | 70 | return this._convertToEasyPostObject(response.body); 71 | } 72 | }; 73 | -------------------------------------------------------------------------------- /src/services/order_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | /** 5 | * The OrderService class provides methods for interacting with EasyPost {@link Order} objects. 6 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 7 | */ 8 | class OrderService extends baseService(easypostClient) { 9 | /** 10 | * Create an {@link Order order}. 11 | * See {@link https://docs.easypost.com/docs/orders#create-an-order EasyPost API Documentation} for more information. 12 | * @param {Object} params - The parameters to create an order with. 13 | * @returns {Order} - The created order. 14 | */ 15 | static async create(params) { 16 | const url = 'orders'; 17 | 18 | const wrappedParams = { 19 | order: params, 20 | }; 21 | 22 | return this._create(url, wrappedParams); 23 | } 24 | 25 | /** 26 | * Purchase an {@link Order order}. 27 | * See {@link https://docs.easypost.com/docs/orders#buy-an-order EasyPost API Documentation} for more information. 28 | * @param {string} id - The ID of the order to buy. 29 | * @param {string} carrier - The carrier to use for the order purchase. 30 | * @param {string} service - The service to use for the order purchase. 31 | * @returns {Order} - The purchased order. 32 | */ 33 | static async buy(id, carrier, service) { 34 | const url = `orders/${id}/buy`; 35 | const wrappedParams = { carrier, service }; 36 | try { 37 | const response = await easypostClient._post(url, wrappedParams); 38 | 39 | return this._convertToEasyPostObject(response.body, wrappedParams); 40 | } catch (e) { 41 | return Promise.reject(e); 42 | } 43 | } 44 | 45 | /** 46 | * Get updated rates for an {@link Order order}. 47 | * See {@link https://docs.easypost.com/docs/orders EasyPost API Documentation} for more information. 48 | * @param {string} id - The ID of the order to get rates for. 49 | * @returns {Order} - The order with rates. 50 | */ 51 | static async getRates(id) { 52 | const url = `orders/${id}/rates`; 53 | 54 | try { 55 | const response = await easypostClient._get(url); 56 | 57 | return this._convertToEasyPostObject(response.body); 58 | } catch (e) { 59 | return Promise.reject(e); 60 | } 61 | } 62 | 63 | /** 64 | * Retrieve an {@link Order order} by its ID. 65 | * See {@link https://docs.easypost.com/docs/orders#retrieve-an-order EasyPost API Documentation} for more information. 66 | * @param {string} id - The ID of the order to retrieve. 67 | * @returns {Order} - The retrieved order. 68 | */ 69 | static async retrieve(id) { 70 | const url = `orders/${id}`; 71 | 72 | return this._retrieve(url); 73 | } 74 | }; 75 | -------------------------------------------------------------------------------- /src/services/parcel_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | /** 5 | * The ParcelService class provides methods for interacting with EasyPost {@link Parcel} objects. 6 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 7 | */ 8 | class ParcelService extends baseService(easypostClient) { 9 | /** 10 | * Create a {@link Parcel parcel}. 11 | * See {@link https://docs.easypost.com/docs/parcels#create-a-parcel EasyPost API Documentation} for more information. 12 | * @param {Object} params - The parameters to create a parcel with. 13 | * @returns {Parcel} - The created parcel. 14 | */ 15 | static async create(params) { 16 | const url = 'parcels'; 17 | 18 | const wrappedParams = { 19 | parcel: params, 20 | }; 21 | 22 | return this._create(url, wrappedParams); 23 | } 24 | 25 | /** 26 | * Retrieve a {@link Parcel parcel} by its ID. 27 | * See {@link https://docs.easypost.com/docs/parcels#retrieve-a-parcel EasyPost API Documentation} for more information. 28 | * @param {string} id - The ID of the parcel to retrieve. 29 | * @returns {Parcel} - The retrieved parcel. 30 | */ 31 | static async retrieve(id) { 32 | const url = `parcels/${id}`; 33 | 34 | return this._retrieve(url); 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /src/services/rate_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | /** 5 | * The RateService class provides methods for interacting with EasyPost {@link Rate} objects. 6 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 7 | */ 8 | class RateService extends baseService(easypostClient) { 9 | /** 10 | * Retrieve a {@link Rate rate} by its ID. 11 | * See {@link https://docs.easypost.com/docs/shipments/rates EasyPost API Documentation} for more information. 12 | * @param {string} id - The ID of the rate to retrieve. 13 | * @returns {Rate} - The retrieved rate. 14 | */ 15 | static async retrieve(id) { 16 | const url = `rates/${id}`; 17 | 18 | return this._retrieve(url); 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /src/services/refund_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | /** 5 | * The RefundService class provides methods for interacting with EasyPost {@link Refund} objects. 6 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 7 | */ 8 | class RefundService extends baseService(easypostClient) { 9 | /** 10 | * Create a {@link Refund refund}. 11 | * See {@link https://docs.easypost.com/docs/refunds#create-a-refund EasyPost API Documentation} for more information. 12 | * @param {Object} params - The parameters to create a refund with. 13 | * @returns {Refund} - The created refund. 14 | */ 15 | static async create(params) { 16 | const url = 'refunds'; 17 | 18 | const wrappedParams = { 19 | refund: params, 20 | }; 21 | 22 | return this._create(url, wrappedParams); 23 | } 24 | 25 | /** 26 | * Retrieve all {@link Refund refunds} associated with the current authenticated user. 27 | * See {@link https://docs.easypost.com/docs/refunds#retrieve-all-refunds EasyPost API Documentation} for more information. 28 | * @param {Object} [params] - The parameters to filter the refunds by. 29 | * @returns {Object} - An object containing the list of {@link Refund refunds} and pagination information. 30 | */ 31 | static async all(params = {}) { 32 | const url = 'refunds'; 33 | 34 | return this._all(url, params); 35 | } 36 | 37 | /** 38 | * Retrieve the next page of Refund collection. 39 | * @param {Object} refunds An object containing a list of {@link Refund refunds} and pagination information. 40 | * @param {Number} pageSize The number of records to return on each page 41 | * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. 42 | */ 43 | static async getNextPage(refunds, pageSize = null) { 44 | const url = 'refunds'; 45 | return this._getNextPage(url, 'refunds', refunds, pageSize); 46 | } 47 | 48 | /** 49 | * Retrieve a {@link Refund refund} by its ID. 50 | * See {@link https://docs.easypost.com/docs/refunds#retrieve-a-refund EasyPost API Documentation} for more information. 51 | * @param {string} id - The ID of the refund to retrieve. 52 | * @returns {Refund} - The retrieved refund. 53 | */ 54 | static async retrieve(id) { 55 | const url = `refunds/${id}`; 56 | 57 | return this._retrieve(url); 58 | } 59 | }; 60 | -------------------------------------------------------------------------------- /src/services/report_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | /** 5 | * The ReportService class provides methods for interacting with EasyPost {@link Report} objects. 6 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 7 | */ 8 | class ReportService extends baseService(easypostClient) { 9 | /** 10 | * Create a {@link Report report}. 11 | * See {@link https://docs.easypost.com/docs/reports#create-a-report EasyPost API Documentation} for more information. 12 | * @param {Object} params - The parameters to create a report with. 13 | * @returns {Report} - The created report. 14 | */ 15 | static async create(params) { 16 | const url = `reports/${params.type}`; 17 | return this._create(url, params); 18 | } 19 | 20 | /** 21 | * Retrieve all {@link Report reports} associated with the current authenticated user. 22 | * See {@link https://docs.easypost.com/docs/reports#retrieve-all-reports EasyPost API Documentation} for more information. 23 | * @param {Object} [params] - The parameters to filter the reports by. 24 | * @returns {Object} - An object containing the list of {@link Report reports} and pagination information. 25 | */ 26 | static async all(params = {}) { 27 | const type = params.type; 28 | const url = `reports/${type}`; 29 | 30 | // delete "type" from params, so it doesn't get sent to the API 31 | // eslint-disable-next-line no-param-reassign 32 | delete params.type; 33 | 34 | try { 35 | const response = await easypostClient._get(url, params); 36 | // we want to add it back in here so that it can be used in the 37 | // "getNextPage" call below 38 | const responseObject = this._convertToEasyPostObject(response.body, { ...params, type }); 39 | 40 | return responseObject; 41 | } catch (e) { 42 | return Promise.reject(e); 43 | } 44 | } 45 | 46 | /** 47 | * Retrieve the next page of Report collection. 48 | * @param {Object} reports An object containing a list of {@link Report reports} and pagination information. 49 | * @param {Number} pageSize The number of records to return on each page 50 | * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. 51 | */ 52 | static async getNextPage(reports, pageSize = null) { 53 | const url = `reports/${reports.reports[0]._params.type}`; 54 | return this._getNextPage(url, 'reports', reports, pageSize); 55 | } 56 | 57 | /** 58 | * Retrieve a {@link Report report} by its ID. 59 | * See {@link https://docs.easypost.com/docs/reports#retrieve-a-report EasyPost API Documentation} for more information. 60 | * @param {string} id - The ID of the report to retrieve. 61 | * @returns {Report} - The retrieved report. 62 | */ 63 | static async retrieve(id) { 64 | const url = `reports/${id}`; 65 | 66 | return this._retrieve(url); 67 | } 68 | }; 69 | -------------------------------------------------------------------------------- /src/services/scan_form_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | /** 5 | * The ScanFormService class provides methods for interacting with EasyPost {@link ScanForm} objects. 6 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 7 | */ 8 | class ScanFormService extends baseService(easypostClient) { 9 | /** 10 | * Create a {@link ScanForm scan form}. 11 | * See {@link https://docs.easypost.com/docs/scan-form#create-a-scanform EasyPost API Documentation} for more information. 12 | * @param {Object} params - The parameters to create a scan form with. 13 | * @returns {ScanForm} - The created scan form. 14 | */ 15 | static async create(params) { 16 | const url = 'scan_forms'; 17 | 18 | // wraps up params in `shipments` if the user didn't do it 19 | // turn a list of shipment objects into a map of shipment ids 20 | if (params.shipments) { 21 | // eslint-disable-next-line no-param-reassign 22 | params.shipments = params.shipments.map((s) => { 23 | if (typeof s === 'string') { 24 | return { id: s }; 25 | } 26 | return { id: s.id }; 27 | }); 28 | } 29 | 30 | const wrappedParams = { 31 | scan_form: params, 32 | }; 33 | 34 | return this._create(url, wrappedParams); 35 | } 36 | 37 | /** 38 | * Retrieve all {@link ScanForm scan forms} associated with the current authenticated user. 39 | * See {@link https://docs.easypost.com/docs/scan-form#retrieve-all-scanforms EasyPost API Documentation} for more information. 40 | * @param {Object} [params] - The parameters to filter the scan forms by. 41 | * @returns {Object} - An object containing the list of {@link ScanForm scan forms} and pagination information. 42 | */ 43 | static async all(params = {}) { 44 | const url = 'scan_forms'; 45 | 46 | return this._all(url, params); 47 | } 48 | 49 | /** 50 | * Retrieve the next page of ScanForm collection. 51 | * @param {Object} scanforms An object containing a list of {@link ScanForm scanforms} and pagination information. 52 | * @param {Number} pageSize The number of records to return on each page 53 | * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. 54 | */ 55 | static async getNextPage(scanforms, pageSize = null) { 56 | const url = 'scan_forms'; 57 | return this._getNextPage(url, 'scan_forms', scanforms, pageSize); 58 | } 59 | 60 | /** 61 | * Retrieve a {@link ScanForm scan form} by its ID. 62 | * See {@link https://docs.easypost.com/docs/scan-form#retrieve-a-scanform EasyPost API Documentation} for more information. 63 | * @param {string} id - The ID of the scan form to retrieve. 64 | * @returns {ScanForm} - The retrieved scan form. 65 | */ 66 | static async retrieve(id) { 67 | const url = `scan_forms/${id}`; 68 | 69 | return this._retrieve(url); 70 | } 71 | }; 72 | -------------------------------------------------------------------------------- /src/services/smart_rate_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | /** 5 | * The SmartRateService class provides methods for interacting with EasyPost SmartRate APIs. 6 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 7 | */ 8 | class SmartRateService extends baseService(easypostClient) { 9 | /** 10 | * Retrieve the estimated delivery date of each carrier-service level combination via the Smart Deliver By API, based on a specific ship date and origin-destination postal code pair. 11 | * @param params - The parameters to estimate the delivery date with. 12 | * @returns {Object} - Estimates and related metadata. 13 | */ 14 | static async estimateDeliveryDate(params) { 15 | const url = 'smartrate/deliver_by'; 16 | 17 | try { 18 | const response = await easypostClient._post(url, params); 19 | 20 | return this._convertToEasyPostObject(response.body, params); 21 | } catch (e) { 22 | return Promise.reject(e); 23 | } 24 | } 25 | 26 | /** 27 | * Retrieve a recommended ship date for each carrier-service level combination via the Smart Deliver On API, based on a specific delivery date and origin-destination postal code pair. 28 | * @param params - The parameters to recommend the ship date with. 29 | * @returns {Object} - Recommendation and related metadata. 30 | */ 31 | static async recommendShipDate(params) { 32 | const url = 'smartrate/deliver_on'; 33 | 34 | try { 35 | const response = await easypostClient._post(url, params); 36 | 37 | return this._convertToEasyPostObject(response.body, params); 38 | } catch (e) { 39 | return Promise.reject(e); 40 | } 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /src/services/tracker_service.js: -------------------------------------------------------------------------------- 1 | import baseService from './base_service'; 2 | 3 | export default (easypostClient) => 4 | /** 5 | * The TrackerService class provides methods for interacting with EasyPost {@link Tracker} objects. 6 | * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. 7 | */ 8 | class TrackerService extends baseService(easypostClient) { 9 | /** 10 | * Create a {@link Tracker tracker}. 11 | * See {@link https://docs.easypost.com/docs/trackers#create-a-tracker EasyPost API Documentation} for more information. 12 | * @param {Object} params - The parameters to create a tracker with. 13 | * @returns {Tracker} - The created tracker. 14 | */ 15 | static async create(params) { 16 | const url = 'trackers'; 17 | 18 | const wrappedParams = { 19 | tracker: params, 20 | }; 21 | 22 | return this._create(url, wrappedParams); 23 | } 24 | 25 | /** 26 | * Retrieve all {@link Tracker trackers} associated with the current authenticated user. 27 | * See {@link https://docs.easypost.com/docs/trackers#retrieve-all-trackers EasyPost API Documentation} for more information. 28 | * @param {Object} [params] - The parameters to filter the trackers by. 29 | * @returns {Object} - An object containing the list of {@link Tracker trackers} and pagination information. 30 | */ 31 | static async all(params = {}) { 32 | const url = 'trackers'; 33 | 34 | return this._all(url, params); 35 | } 36 | 37 | /** 38 | * Retrieve the next page of Tracker collection. 39 | * @param {Object} trackers An object containing a list of {@link Tracker trackers} and pagination information. 40 | * @param {Number} pageSize The number of records to return on each page 41 | * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. 42 | */ 43 | static async getNextPage(trackers, pageSize = null) { 44 | const url = 'trackers'; 45 | 46 | return this._getNextPage(url, 'trackers', trackers, pageSize); 47 | } 48 | 49 | /** 50 | * Retrieve a {@link Tracker tracker} by its ID. 51 | * See {@link https://docs.easypost.com/docs/trackers#retrieve-a-tracker EasyPost API Documentation} for more information. 52 | * @param {string} id - The ID of the tracker to retrieve. 53 | * @returns {Tracker} - The retrieved tracker. 54 | */ 55 | static async retrieve(id) { 56 | const url = `trackers/${id}`; 57 | 58 | return this._retrieve(url); 59 | } 60 | }; 61 | -------------------------------------------------------------------------------- /src/utils/internal_util.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Utility class of various internal helper functions. 3 | * This class is not designed to be used directly by consumers of the library. 4 | * @internal 5 | * @type {InternalUtils} 6 | */ 7 | export default class InternalUtils {} 8 | -------------------------------------------------------------------------------- /test/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["eslint:recommended", "prettier", "plugin:vitest-globals/recommended"], 3 | 4 | "env": { 5 | "node": true, 6 | "vitest-globals/env": true 7 | }, 8 | 9 | "rules": { 10 | "import/no-extraneous-dependencies": 0, 11 | 12 | // @easypost/eslint-config-easypost-base assumes all tests are jest. so turn these rules off 13 | "jest/consistent-test-it": 0, 14 | "jest/valid-expect": 0, 15 | "global-require": "off" 16 | }, 17 | 18 | "globals": { 19 | "expect": true 20 | }, 21 | "parserOptions": { 22 | "ecmaVersion": 13 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/helpers/cassette_encoding.js: -------------------------------------------------------------------------------- 1 | import { gunzipSync, gzipSync } from 'zlib'; 2 | import { text } from 'superagent/lib/node/parsers'; 3 | 4 | const charset = 'utf8'; 5 | const encoding = 'base64'; 6 | 7 | const hasHeader = 8 | (headers) => 9 | ([key, value]) => 10 | headers.some((header) => 11 | header.name === key && typeof value === 'function' 12 | ? value(header.value) 13 | : header.value === value, 14 | ); 15 | 16 | const headerValueDelimiter = /,\s*/; 17 | const headerValueContains = (valueToFind) => (headerValue) => 18 | headerValue.split(headerValueDelimiter).includes(valueToFind); 19 | 20 | const isContentChunked = (headers) => 21 | hasHeader(headers)(['transfer-encoding', headerValueContains('chunked')]); 22 | 23 | const isContentGzipped = (headers) => 24 | hasHeader(headers)(['content-encoding', headerValueContains('gzip')]); 25 | 26 | const decodeCassetteResponseBodies = (response) => { 27 | const { content, headers } = response; 28 | if (!isContentGzipped(headers) || content.size === 0) { 29 | return; 30 | } 31 | 32 | const chunks = JSON.parse(content.text); 33 | 34 | if (isContentChunked(headers)) { 35 | const chunkBuffers = []; 36 | 37 | for (let i = 0; i < chunks.length; i += 1) { 38 | const decodedBuffer = Buffer.from(chunks[i], encoding); 39 | chunkBuffers.push(decodedBuffer); 40 | } 41 | 42 | const allBuffers = Buffer.concat(chunkBuffers); 43 | const unzipped = gunzipSync(allBuffers); 44 | 45 | content.text = unzipped.toString(charset); 46 | } else { 47 | throw Error('Unchunked content has no cassette decoding logic and will need to be configured.'); 48 | } 49 | }; 50 | 51 | const encodeCassetteResponseBodies = (response) => { 52 | const { content, headers } = response; 53 | if (!isContentGzipped(headers)) { 54 | return; 55 | } 56 | 57 | const unzipped = Buffer.from(content.text, charset); 58 | const zipped = gzipSync(unzipped); 59 | const base64String = zipped.toString(encoding); 60 | const body = isContentChunked(headers) 61 | ? // re-chunk the content 62 | [base64String.slice(0, 20), base64String.substring(20)] // making the first chunk 20 chars, as it seems to match polly's typical result 63 | : base64String; 64 | content.text = JSON.stringify(body); 65 | 66 | // recalculating the content size in case manual editing of data changes the size 67 | content.size = text.length; 68 | response.bodySize = text.length; 69 | }; 70 | 71 | export { decodeCassetteResponseBodies, encodeCassetteResponseBodies }; 72 | -------------------------------------------------------------------------------- /test/helpers/common.js: -------------------------------------------------------------------------------- 1 | import 'core-js/stable'; 2 | 3 | import chai from 'chai'; 4 | import chaiAsPromised from 'chai-as-promised'; 5 | 6 | /* eslint-disable no-console */ 7 | process.on('unhandledRejection', (err) => { 8 | console.error(err, err.stack); 9 | }); 10 | 11 | chai.should(); 12 | chai.use(chaiAsPromised); 13 | chai.config.truncateThreshold = 0; 14 | 15 | global.expect = chai.expect; 16 | global.AssertionError = chai.AssertionError; 17 | global.Assertion = chai.Assertion; 18 | global.assert = chai.assert; 19 | -------------------------------------------------------------------------------- /test/helpers/mocking.js: -------------------------------------------------------------------------------- 1 | export class MockRequestMatchRule { 2 | constructor(method, urlRegexPattern) { 3 | this.method = method; 4 | this.urlRegexPattern = urlRegexPattern; 5 | } 6 | } 7 | 8 | export class MockRequestResponseInfo { 9 | constructor(statusCode, responseData) { 10 | this.statusCode = statusCode; 11 | this.body = responseData; 12 | } 13 | } 14 | 15 | export class MockRequest { 16 | constructor(matchRule, responseInfo) { 17 | this.matchRule = matchRule; 18 | this.responseInfo = responseInfo; 19 | } 20 | } 21 | 22 | export class MockMiddleware { 23 | constructor(request, mockRequests) { 24 | this.request = request; 25 | this.mockRequests = mockRequests; 26 | this.body = {}; 27 | } 28 | 29 | // eslint-disable-next-line class-methods-use-this,no-unused-vars 30 | auth(key) { 31 | // do nothing 32 | } 33 | 34 | // eslint-disable-next-line class-methods-use-this,no-unused-vars,consistent-return 35 | send(body) { 36 | // we don't need to do anything with the body 37 | const mockRequest = this._findMatchingMockRequest(this.request); 38 | if (mockRequest) { 39 | this.body = mockRequest.responseInfo.body; 40 | return mockRequest.responseInfo; 41 | } 42 | return {}; 43 | } 44 | 45 | // eslint-disable-next-line no-unused-vars 46 | query(params) { 47 | // we don't need to do anything with the params 48 | const mockRequest = this._findMatchingMockRequest(this.request); 49 | if (mockRequest) { 50 | this.body = mockRequest.responseInfo.body; 51 | return mockRequest.responseInfo; 52 | } 53 | return {}; 54 | } 55 | 56 | /** 57 | * @private 58 | */ 59 | _findMatchingMockRequest(request) { 60 | // for each mock request, check if the method and url match 61 | for (let i = 0; i < this.mockRequests.length; i += 1) { 62 | const mockRequest = this.mockRequests[i]; 63 | if ( 64 | mockRequest.matchRule.method === request.method && 65 | request.url.match(mockRequest.matchRule.urlRegexPattern) 66 | ) { 67 | return mockRequest; 68 | } 69 | } 70 | return null; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /test/helpers/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Utils to remove the _params key and all params keys from nested objects from 3 | * an EasyPostObject for sake of comparison in tests 4 | * @param {*} obj an EasyPostObject to remove the params from 5 | * @returns {*} obj without the _params key 6 | */ 7 | export const withoutParams = (obj) => 8 | Object.fromEntries( 9 | Object.entries(obj) 10 | .map(([key, value]) => { 11 | if (key === '_params') { 12 | return null; 13 | } 14 | 15 | if (!value) { 16 | return [key, value]; 17 | } 18 | 19 | if (Array.isArray(value)) { 20 | return [ 21 | key, 22 | value.map((arrValue) => 23 | typeof arrValue === 'object' ? withoutParams(arrValue) : arrValue, 24 | ), 25 | ]; 26 | } 27 | 28 | if (typeof value === 'object') { 29 | return [key, withoutParams(value)]; 30 | } 31 | 32 | return [key, value]; 33 | }) 34 | .filter(Boolean), 35 | ); 36 | -------------------------------------------------------------------------------- /test/node_compatibility/README.md: -------------------------------------------------------------------------------- 1 | # Node Compatibility 2 | 3 | This library supports very old versions of node when importing and using the library. However, we do not support developing this library with very old versions of node. 4 | 5 | Thats where this folder comes in. We will run the full test suite on a modern version of Node, but will check that the library still "works" with older versions of Node using this folder. You can run this file with your API key and if it succeeds, then your version of node is compatible. Otherwise, it is not. 6 | -------------------------------------------------------------------------------- /test/node_compatibility/index.js: -------------------------------------------------------------------------------- 1 | const EasyPostClient = require('../..'); 2 | 3 | const test = async () => { 4 | const client = new EasyPostClient('apiKey'); 5 | 6 | if (!client.baseUrl.match(/^https:\/\/api\.easypost\.com/gm)) { 7 | process.exit(1); 8 | } 9 | }; 10 | 11 | test(); 12 | -------------------------------------------------------------------------------- /test/services/api_key.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable func-names */ 2 | import { expect } from 'chai'; 3 | 4 | import EasyPostClient from '../../src/easypost'; 5 | import ApiKey from '../../src/models/api_key'; 6 | import * as setupPolly from '../helpers/setup_polly'; 7 | import FilteringError from '../../src/errors/general/filtering_error'; 8 | 9 | describe('ApiKey Service', function () { 10 | const getPolly = setupPolly.setupPollyTests(); 11 | let client; 12 | 13 | beforeAll(function () { 14 | client = new EasyPostClient(process.env.EASYPOST_PROD_API_KEY); 15 | }); 16 | 17 | beforeEach(function () { 18 | const { server } = getPolly(); 19 | setupPolly.setupCassette(server); 20 | }); 21 | 22 | it('retrieves all apiKeys', async function () { 23 | const apiKeys = await client.ApiKey.all(); 24 | 25 | apiKeys.keys.forEach((apiKey) => { 26 | expect(apiKey).to.be.an.instanceOf(ApiKey); 27 | }); 28 | }); 29 | 30 | it("retrieves parent user's API keys", async function () { 31 | const user = await client.User.retrieveMe(); 32 | const keys = await client.ApiKey.retrieveApiKeysForUser(user.id); 33 | 34 | expect(keys).to.be.an.instanceOf(Array); 35 | }); 36 | 37 | it("throws FilteringError when trying to retrieve child user's API keys", async function () { 38 | const fakeChildId = 'user_blah'; 39 | 40 | try { 41 | await client.ApiKey.retrieveApiKeysForUser(fakeChildId); 42 | throw new Error('Test did not throw the expected error.'); 43 | } catch (error) { 44 | expect(error).to.be.an.instanceOf(FilteringError, 'No child found.'); 45 | } 46 | }); 47 | }); 48 | -------------------------------------------------------------------------------- /test/services/beta_rate.test.js: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | 3 | import EasyPostClient from '../../src/easypost'; 4 | import FilteringError from '../../src/errors/general/filtering_error'; 5 | import Rate from '../../src/models/rate'; 6 | import Fixture from '../helpers/fixture'; 7 | import * as setupPolly from '../helpers/setup_polly'; 8 | 9 | /* eslint-disable func-names */ 10 | describe('BetaRateService', function () { 11 | const getPolly = setupPolly.setupPollyTests(); 12 | let client; 13 | 14 | beforeAll(function () { 15 | client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); 16 | }); 17 | 18 | beforeEach(function () { 19 | const { server } = getPolly(); 20 | setupPolly.setupCassette(server); 21 | }); 22 | 23 | it('retrieves a list of stateless rates', async function () { 24 | const statelessRates = await client.BetaRate.retrieveStatelessRates(Fixture.basicShipment()); 25 | 26 | statelessRates.forEach((rate) => { 27 | expect(rate).to.be.an.instanceOf(Rate); 28 | expect(rate).to.not.have.property('id'); 29 | }); 30 | }); 31 | 32 | it('retrieve the lowest rate', async function () { 33 | const statelessRates = await client.BetaRate.retrieveStatelessRates(Fixture.basicShipment()); 34 | 35 | const lowestStatelessRate = client.Utils.getLowestRate(statelessRates); 36 | 37 | expect(lowestStatelessRate.service).to.be.equal('GroundAdvantage'); 38 | expect(lowestStatelessRate.rate).to.be.equal('5.93'); 39 | }); 40 | 41 | it('retrieve invalid lowest rate', async function () { 42 | const statelessRates = await client.BetaRate.retrieveStatelessRates(Fixture.basicShipment()); 43 | 44 | expect(() => { 45 | client.Utils.getLowestRate(statelessRates, ['invalid_carrier'], ['invalid_service']); 46 | }).to.throw(FilteringError, 'No rates found.'); 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /test/services/beta_referral_customer.test.js: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | 3 | import EasyPostClient from '../../src/easypost'; 4 | import * as setupPolly from '../helpers/setup_polly'; 5 | 6 | describe('BetaReferralCustomerService', function () { 7 | const getPolly = setupPolly.setupPollyTests(); 8 | let client; 9 | 10 | beforeAll(function () { 11 | const referralCustomerProdApiKey = process.env.REFERRAL_CUSTOMER_PROD_API_KEY || '123'; 12 | client = new EasyPostClient(referralCustomerProdApiKey); 13 | }); 14 | 15 | beforeEach(function () { 16 | const { server } = getPolly(); 17 | setupPolly.setupCassette(server); 18 | }); 19 | 20 | it('add payment method to a referral customer account', async function () { 21 | await client.BetaReferralCustomer.addPaymentMethod('cus_123', 'ba_123').catch((error) => { 22 | expect(error.statusCode).to.equal(422); 23 | expect(error.code).to.equal('BILLING.INVALID_PAYMENT_GATEWAY_REFERENCE'); 24 | expect(error.message).to.equal('Invalid connect integration.'); 25 | }); 26 | }); 27 | 28 | it('Refund by amount for a recent payment', async function () { 29 | await client.BetaReferralCustomer.refundByAmount(2000).catch((error) => { 30 | expect(error.statusCode).to.equal(422); 31 | expect(error.code).to.equal('TRANSACTION.AMOUNT_INVALID'); 32 | expect(error.message).to.equal( 33 | 'Refund amount is invalid. Please use a valid amount or escalate to finance.', 34 | ); 35 | }); 36 | }); 37 | 38 | it('Refund a payment by a payment log ID', async function () { 39 | await client.BetaReferralCustomer.refundByPaymentLog('paylog_...').catch((error) => { 40 | expect(error.statusCode).to.equal(422); 41 | expect(error.code).to.equal('TRANSACTION.DOES_NOT_EXIST'); 42 | expect(error.message).to.equal('We could not find a transaction with that id.'); 43 | }); 44 | }); 45 | 46 | it('returns a client secret for credit cards', async function () { 47 | const response = await client.BetaReferralCustomer.createCreditCardClientSecret(); 48 | 49 | expect(response.client_secret).to.match(/^seti_/); 50 | }); 51 | 52 | it('returns a client secret for bank accounts', async function () { 53 | const response = await client.BetaReferralCustomer.createBankAccountClientSecret(); 54 | 55 | expect(response.client_secret).to.match(/^fcsess_client_secret_/); 56 | }); 57 | }); 58 | -------------------------------------------------------------------------------- /test/services/billing.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable func-names */ 2 | import { expect } from 'chai'; 3 | 4 | import EasyPostClient from '../../src/easypost'; 5 | import { 6 | MockMiddleware, 7 | MockRequest, 8 | MockRequestMatchRule, 9 | MockRequestResponseInfo, 10 | } from '../helpers/mocking'; 11 | 12 | const middleware = (request) => { 13 | return new MockMiddleware(request, [ 14 | new MockRequest( 15 | new MockRequestMatchRule('POST', 'v2\\/bank_accounts\\/\\S*\\/charges$'), 16 | new MockRequestResponseInfo(200, {}), 17 | ), 18 | new MockRequest( 19 | new MockRequestMatchRule('POST', 'v2\\/credit_cards\\/\\S*\\/charges$'), 20 | new MockRequestResponseInfo(200, {}), 21 | ), 22 | new MockRequest( 23 | new MockRequestMatchRule('DELETE', 'v2\\/bank_accounts\\/\\S*$'), 24 | new MockRequestResponseInfo(200, {}), 25 | ), 26 | new MockRequest( 27 | new MockRequestMatchRule('DELETE', 'v2\\/credit_cards\\/\\S*$'), 28 | new MockRequestResponseInfo(200, {}), 29 | ), 30 | new MockRequest( 31 | new MockRequestMatchRule('GET', 'v2\\/payment_methods$'), 32 | new MockRequestResponseInfo(200, { 33 | id: 'summary_123', 34 | primary_payment_method: { 35 | id: 'pm_123', 36 | last4: '1234', 37 | object: 'CreditCard', 38 | }, 39 | secondary_payment_method: { 40 | id: 'pm_123', 41 | bank_name: 'Mock Bank', 42 | object: 'BankAccount', 43 | }, 44 | }), 45 | ), 46 | ]); 47 | }; 48 | 49 | describe('Billing Service', function () { 50 | let client; 51 | 52 | beforeAll(function () { 53 | client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY, { 54 | requestMiddleware: middleware, 55 | }); 56 | }); 57 | 58 | it('fund a wallet', async function () { 59 | expect(async () => { 60 | await client.Billing.fundWallet('2000', 'primary'); 61 | }).not.to.throw(); 62 | }); 63 | 64 | it('delete a payment method', async function () { 65 | expect(async () => { 66 | await client.Billing.deletePaymentMethod('primary'); 67 | }).not.to.throw(); 68 | }); 69 | 70 | it('retrieves all payment methods', async function () { 71 | const paymentMethods = await client.Billing.retrievePaymentMethods(); 72 | 73 | expect(paymentMethods.primary_payment_method).to.exist; 74 | expect(paymentMethods.secondary_payment_method).to.exist; 75 | }); 76 | 77 | it('get payment info', async function () { 78 | const paymentInfo = await client.Billing._getPaymentInfo('primary'); 79 | 80 | expect(paymentInfo).to.deep.equal(['credit_cards', 'pm_123']); 81 | 82 | const paymentInfo2 = await client.Billing._getPaymentInfo('secondary'); 83 | 84 | expect(paymentInfo2).to.deep.equal(['bank_accounts', 'pm_123']); 85 | }); 86 | }); 87 | -------------------------------------------------------------------------------- /test/services/carrier_metadata.test.js: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | 3 | import EasyPostClient from '../../src/easypost'; 4 | import * as setupPolly from '../helpers/setup_polly'; 5 | 6 | /* eslint-disable func-names */ 7 | describe('CarrierMetadataService', function () { 8 | const getPolly = setupPolly.setupPollyTests(); 9 | let client; 10 | 11 | beforeAll(function () { 12 | client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); 13 | }); 14 | 15 | beforeEach(function () { 16 | const { server } = getPolly(); 17 | setupPolly.setupCassette(server); 18 | }); 19 | 20 | it('retrieves all carrier metadata', async function () { 21 | const carrierMetadata = await client.CarrierMetadata.retrieve(); 22 | 23 | expect(carrierMetadata.some((carrier) => carrier.name === 'usps')).to.be.true; 24 | expect(carrierMetadata.some((carrier) => carrier.name === 'fedex')).to.be.true; 25 | }); 26 | 27 | it('retrieves carrier metadata based on the filters provided', async function () { 28 | const carrierMetadata = await client.CarrierMetadata.retrieve( 29 | ['usps'], 30 | ['service_levels', 'predefined_packages'], 31 | ); 32 | 33 | expect(carrierMetadata.some((carrier) => carrier.name === 'usps')).to.be.true; 34 | expect(carrierMetadata).to.have.lengthOf(1); 35 | expect(carrierMetadata[0]).to.have.property('service_levels'); 36 | expect(carrierMetadata[0]).to.have.property('predefined_packages'); 37 | expect(carrierMetadata[0]).to.not.have.property('supported_features'); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /test/services/carrier_type.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable func-names */ 2 | import { expect } from 'chai'; 3 | 4 | import EasyPostClient from '../../src/easypost'; 5 | import CarrierType from '../../src/models/carrier_type'; 6 | import * as setupPolly from '../helpers/setup_polly'; 7 | 8 | describe('CarrierType Service', function () { 9 | const getPolly = setupPolly.setupPollyTests(); 10 | let client; 11 | 12 | beforeAll(function () { 13 | client = new EasyPostClient(process.env.EASYPOST_PROD_API_KEY); 14 | }); 15 | 16 | beforeEach(function () { 17 | const { server } = getPolly(); 18 | setupPolly.setupCassette(server); 19 | }); 20 | 21 | it('retrieves the carrier account types available', async function () { 22 | const carrierTypes = await client.CarrierType.all(); 23 | 24 | carrierTypes.forEach((type) => { 25 | expect(type).to.be.an.instanceOf(CarrierType); 26 | }); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /test/services/customs_info.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable func-names */ 2 | import { expect } from 'chai'; 3 | 4 | import EasyPostClient from '../../src/easypost'; 5 | import CustomsInfo from '../../src/models/customs_info'; 6 | import Fixture from '../helpers/fixture'; 7 | import * as setupPolly from '../helpers/setup_polly'; 8 | import { withoutParams } from '../helpers/utils'; 9 | 10 | describe('CustomsInfo Service', function () { 11 | const getPolly = setupPolly.setupPollyTests(); 12 | let client; 13 | 14 | beforeAll(function () { 15 | client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); 16 | }); 17 | 18 | beforeEach(function () { 19 | const { server } = getPolly(); 20 | setupPolly.setupCassette(server); 21 | }); 22 | 23 | it('creates a customs info', async function () { 24 | const customsInfo = await client.CustomsInfo.create(Fixture.basicCustomsInfo()); 25 | 26 | expect(customsInfo).to.be.an.instanceOf(CustomsInfo); 27 | expect(customsInfo.id).to.match(/^cstinfo_/); 28 | expect(customsInfo.eel_pfc).to.equal('NOEEI 30.37(a)'); 29 | }); 30 | 31 | it('retrieves a customs info', async function () { 32 | const customsInfo = await client.CustomsInfo.create(Fixture.basicCustomsInfo()); 33 | const retrievedCustomsInfo = await client.CustomsInfo.retrieve(customsInfo.id); 34 | 35 | expect(customsInfo).to.be.an.instanceOf(CustomsInfo); 36 | expect(withoutParams(retrievedCustomsInfo)).to.deep.include(withoutParams(customsInfo)); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /test/services/customs_item.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable func-names */ 2 | import { expect } from 'chai'; 3 | 4 | import EasyPost from '../../src/easypost'; 5 | import CustomsItem from '../../src/models/customs_item'; 6 | import Fixture from '../helpers/fixture'; 7 | import * as setupPolly from '../helpers/setup_polly'; 8 | import { withoutParams } from '../helpers/utils'; 9 | 10 | describe('CustomsItem Service', function () { 11 | const getPolly = setupPolly.setupPollyTests(); 12 | let client; 13 | 14 | beforeAll(function () { 15 | client = new EasyPost(process.env.EASYPOST_TEST_API_KEY); 16 | }); 17 | 18 | beforeEach(function () { 19 | const { server } = getPolly(); 20 | setupPolly.setupCassette(server); 21 | }); 22 | 23 | it('creates a customs item', async function () { 24 | const customsItem = await client.CustomsItem.create(Fixture.basicCustomsItem()); 25 | 26 | expect(customsItem).to.be.an.instanceOf(CustomsItem); 27 | expect(customsItem.id).to.match(/^cstitem_/); 28 | expect(customsItem.value).to.equal('23.25'); 29 | }); 30 | 31 | it('retrieves a customs item', async function () { 32 | const customsItem = await client.CustomsItem.create(Fixture.basicCustomsItem()); 33 | const retrievedCustomsInfo = await client.CustomsItem.retrieve(customsItem.id); 34 | 35 | expect(customsItem).to.be.an.instanceOf(CustomsItem); 36 | expect(withoutParams(retrievedCustomsInfo)).to.deep.include(withoutParams(customsItem)); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /test/services/end_shipper.test.js: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | 3 | import EasyPostClient from '../../src/easypost'; 4 | import EndShipper from '../../src/models/end_shipper'; 5 | import Fixture from '../helpers/fixture'; 6 | import * as setupPolly from '../helpers/setup_polly'; 7 | 8 | describe('EndShipper Service', function () { 9 | const getPolly = setupPolly.setupPollyTests(); 10 | let client; 11 | 12 | beforeAll(function () { 13 | client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); 14 | }); 15 | 16 | beforeEach(function () { 17 | const { server } = getPolly(); 18 | setupPolly.setupCassette(server); 19 | }); 20 | 21 | it('creates an EndShipper object', async function () { 22 | const endShipper = await client.EndShipper.create(Fixture.caAddress1()); 23 | 24 | expect(endShipper).to.be.an.instanceOf(EndShipper); 25 | expect(endShipper.id).to.match(/^es_/); 26 | expect(endShipper.street1).to.equal('388 TOWNSEND ST APT 20'); 27 | }); 28 | 29 | it('retrieves an EndShipper object', async function () { 30 | const endShipper = await client.EndShipper.create(Fixture.caAddress2()); 31 | const retrievedEndShipper = await client.EndShipper.retrieve(endShipper.id); 32 | 33 | expect(retrievedEndShipper).to.be.an.instanceOf(EndShipper); 34 | expect(endShipper.street1).to.equal(retrievedEndShipper.street1); 35 | }); 36 | 37 | it('retrieves all EndShipper objects', async function () { 38 | const endShippers = await client.EndShipper.all({ page_size: Fixture.pageSize() }); 39 | 40 | const endShippersArray = endShippers.end_shippers; 41 | 42 | expect(endShippersArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); 43 | expect(endShippers.has_more).to.exist; 44 | endShippersArray.forEach((endShipper) => { 45 | expect(endShipper).to.be.an.instanceOf(EndShipper); 46 | }); 47 | }); 48 | 49 | it('updates an EndShipper object', async function () { 50 | const endShipper = await client.EndShipper.create(Fixture.caAddress2()); 51 | 52 | const params = {}; 53 | const newName = 'Captain Sparrow'; 54 | params.name = newName; 55 | params.company = 'EasyPost'; 56 | params.street1 = '388 Townsend St'; 57 | params.street2 = 'Apt 20'; 58 | params.city = 'San Francisco'; 59 | params.state = 'CA'; 60 | params.zip = '94107'; 61 | params.country = 'US'; 62 | params.phone = '9999999999'; 63 | params.email = 'test@example.com'; 64 | 65 | const updatedEndShipper = await client.EndShipper.update(endShipper.id, params); 66 | 67 | expect(updatedEndShipper).to.be.an.instanceOf(EndShipper); 68 | expect(updatedEndShipper.name).to.equal(newName.toUpperCase()); 69 | }); 70 | }); 71 | -------------------------------------------------------------------------------- /test/services/order.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable func-names */ 2 | import { expect } from 'chai'; 3 | 4 | import EasyPostClient from '../../src/easypost'; 5 | import FilteringError from '../../src/errors/general/filtering_error'; 6 | import Order from '../../src/models/order'; 7 | import Rate from '../../src/models/rate'; 8 | import Fixture from '../helpers/fixture'; 9 | import * as setupPolly from '../helpers/setup_polly'; 10 | 11 | describe('Order Service', function () { 12 | const getPolly = setupPolly.setupPollyTests(); 13 | let client; 14 | 15 | beforeAll(function () { 16 | client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); 17 | }); 18 | 19 | beforeEach(function () { 20 | const { server } = getPolly(); 21 | setupPolly.setupCassette(server); 22 | }); 23 | 24 | it('creates an order', async function () { 25 | const order = await client.Order.create(Fixture.basicOrder()); 26 | 27 | expect(order).to.be.an.instanceOf(Order); 28 | expect(order.id).to.match(/^order_/); 29 | expect(order.rates).to.exist; 30 | }); 31 | 32 | it('retrieves an order', async function () { 33 | const order = await client.Order.create(Fixture.basicOrder()); 34 | 35 | const retrievedOrder = await client.Order.retrieve(order.id); 36 | 37 | expect(retrievedOrder).to.be.an.instanceOf(Order); 38 | expect(retrievedOrder.id).to.equal(order.id); 39 | }); 40 | 41 | it('get rates of an order', async function () { 42 | const order = await client.Order.create(Fixture.basicOrder()); 43 | 44 | const rates = await client.Order.getRates(order.id); 45 | 46 | const ratesArray = rates.rates; 47 | 48 | expect(ratesArray).to.be.an.instanceOf(Array); 49 | ratesArray.forEach((rate) => { 50 | expect(rate).to.be.an.instanceOf(Rate); 51 | }); 52 | }); 53 | 54 | it('buys an order', async function () { 55 | const order = await client.Order.create(Fixture.basicOrder()); 56 | 57 | const boughtOrder = await client.Order.buy(order.id, Fixture.usps(), Fixture.uspsService()); 58 | 59 | const shipmentsArray = boughtOrder.shipments; 60 | 61 | shipmentsArray.forEach((shipment) => { 62 | expect(shipment.postage_label).to.exist; 63 | }); 64 | }); 65 | 66 | it('gets the lowest rate', async function () { 67 | const order = await client.Order.create(Fixture.basicOrder()); 68 | 69 | // Test lowest rate with no filters 70 | const lowestRate = order.lowestRate(); 71 | expect(lowestRate.service).to.equal('GroundAdvantage'); 72 | expect(lowestRate.rate).to.equal('11.40'); 73 | expect(lowestRate.carrier).to.equal('USPS'); 74 | 75 | // Test lowest rate with service filter (this rate is higher than the lowest but should filter) 76 | const lowestRateService = order.lowestRate(null, ['Priority']); 77 | expect(lowestRateService.service).to.equal('Priority'); 78 | expect(lowestRateService.rate).to.equal('14.48'); 79 | expect(lowestRateService.carrier).to.equal('USPS'); 80 | 81 | // Test lowest rate with carrier filter (should error due to bad carrier) 82 | expect(function () { 83 | order.lowestRate(['BAD CARRIER'], null); 84 | }).to.throw(FilteringError, 'No rates found.'); 85 | }); 86 | }); 87 | -------------------------------------------------------------------------------- /test/services/parcel.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable func-names */ 2 | import { expect } from 'chai'; 3 | 4 | import EasyPostClient from '../../src/easypost'; 5 | import Parcel from '../../src/models/parcel'; 6 | import Fixture from '../helpers/fixture'; 7 | import * as setupPolly from '../helpers/setup_polly'; 8 | import { withoutParams } from '../helpers/utils'; 9 | 10 | describe('Parcel Service', function () { 11 | const getPolly = setupPolly.setupPollyTests(); 12 | let client; 13 | 14 | beforeAll(function () { 15 | client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); 16 | }); 17 | 18 | beforeEach(function () { 19 | const { server } = getPolly(); 20 | setupPolly.setupCassette(server); 21 | }); 22 | 23 | it('creates a parcel', async function () { 24 | const parcel = await client.Parcel.create(Fixture.basicParcel()); 25 | 26 | expect(parcel).to.be.an.instanceOf(Parcel); 27 | expect(parcel.id).to.match(/^prcl_/); 28 | expect(parcel.weight).to.equal(15.4); 29 | }); 30 | 31 | it('retrieves a parcel', async function () { 32 | const parcel = await client.Parcel.create(Fixture.basicParcel()); 33 | const retrievedParcel = await client.Parcel.retrieve(parcel.id); 34 | 35 | expect(parcel).to.be.an.instanceOf(Parcel); 36 | expect(withoutParams(retrievedParcel)).to.deep.include(withoutParams(parcel)); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /test/services/rate.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable func-names */ 2 | import { expect } from 'chai'; 3 | 4 | import EasyPostClient from '../../src/easypost'; 5 | import Rate from '../../src/models/rate'; 6 | import Fixture from '../helpers/fixture'; 7 | import * as setupPolly from '../helpers/setup_polly'; 8 | 9 | describe('Rate Service', function () { 10 | const getPolly = setupPolly.setupPollyTests(); 11 | let client; 12 | 13 | beforeAll(function () { 14 | client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); 15 | }); 16 | 17 | beforeEach(function () { 18 | const { server } = getPolly(); 19 | setupPolly.setupCassette(server); 20 | }); 21 | 22 | it('retrieves a rate', async function () { 23 | const shipment = await client.Shipment.create(Fixture.basicShipment()); 24 | 25 | const rate = await client.Rate.retrieve(shipment.rates[0].id); 26 | 27 | expect(rate).to.be.an.instanceOf(Rate); 28 | expect(rate.id).to.match(/^rate_/); 29 | }); 30 | }); 31 | -------------------------------------------------------------------------------- /test/services/refund.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable func-names */ 2 | import { expect } from 'chai'; 3 | 4 | import EasyPostClient from '../../src/easypost'; 5 | import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; 6 | import Refund from '../../src/models/refund'; 7 | import Fixture from '../helpers/fixture'; 8 | import * as setupPolly from '../helpers/setup_polly'; 9 | import { withoutParams } from '../helpers/utils'; 10 | 11 | describe('Refund Service', function () { 12 | const getPolly = setupPolly.setupPollyTests(); 13 | let client; 14 | 15 | beforeAll(function () { 16 | client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); 17 | }); 18 | 19 | beforeEach(function () { 20 | const { server } = getPolly(); 21 | setupPolly.setupCassette(server); 22 | }); 23 | 24 | it('creates a refund', async function () { 25 | const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment()); 26 | 27 | // We need to retrieve the shipment so that the tracking_code has time to populate 28 | const retrievedShipment = await client.Shipment.retrieve(shipment.id); 29 | 30 | const refundData = { 31 | carrier: Fixture.usps(), 32 | tracking_codes: [retrievedShipment.tracking_code], 33 | }; 34 | 35 | const refunds = await client.Refund.create(refundData); 36 | 37 | refunds.forEach((pickup) => { 38 | expect(pickup).to.be.an.instanceOf(Refund); 39 | }); 40 | expect(refunds[0].id).to.match(/^rfnd_/); 41 | expect(refunds[0].status).to.equal('submitted'); 42 | }); 43 | 44 | it('retrieves all refunds', async function () { 45 | const refunds = await client.Refund.all({ page_size: Fixture.pageSize() }); 46 | 47 | const refundsArray = refunds.refunds; 48 | 49 | expect(refundsArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); 50 | expect(refunds.has_more).to.exist; 51 | refundsArray.forEach((refund) => { 52 | expect(refund).to.be.an.instanceOf(Refund); 53 | }); 54 | }); 55 | 56 | it('retrieves next page of refunds', async function () { 57 | try { 58 | const refunds = await client.Refund.all({ page_size: Fixture.pageSize() }); 59 | const nextPage = await client.Refund.getNextPage(refunds, Fixture.pageSize()); 60 | 61 | const firstIdOfFirstPage = refunds.refunds[0].id; 62 | const firstIdOfSecondPage = nextPage.refunds[0].id; 63 | 64 | expect(firstIdOfFirstPage).to.not.equal(firstIdOfSecondPage); 65 | } catch (error) { 66 | if (!(error instanceof EndOfPaginationError)) { 67 | throw new Error('Test failed intentionally'); 68 | } 69 | } 70 | }); 71 | 72 | it('retrieves a refund', async function () { 73 | const refunds = await client.Refund.all({ page_size: Fixture.pageSize() }); 74 | 75 | const retrieveRefund = await client.Refund.retrieve(refunds.refunds[0].id); 76 | 77 | expect(retrieveRefund).to.be.an.instanceOf(Refund); 78 | expect(withoutParams(retrieveRefund)).to.deep.include(withoutParams(refunds.refunds[0])); 79 | }); 80 | }); 81 | -------------------------------------------------------------------------------- /test/services/scan_form.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable func-names */ 2 | import { expect } from 'chai'; 3 | 4 | import EasyPostClient from '../../src/easypost'; 5 | import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; 6 | import ScanForm from '../../src/models/scan_form'; 7 | import Fixture from '../helpers/fixture'; 8 | import * as setupPolly from '../helpers/setup_polly'; 9 | import { withoutParams } from '../helpers/utils'; 10 | 11 | describe('ScanForm Service', function () { 12 | const getPolly = setupPolly.setupPollyTests(); 13 | let client; 14 | 15 | beforeAll(function () { 16 | client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); 17 | }); 18 | 19 | beforeEach(function () { 20 | const { server } = getPolly(); 21 | setupPolly.setupCassette(server); 22 | }); 23 | 24 | it('creates a scanform', async function () { 25 | const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment()); 26 | 27 | const scanform = await client.ScanForm.create({ 28 | shipments: [shipment], 29 | }); 30 | 31 | expect(scanform).to.be.an.instanceOf(ScanForm); 32 | expect(scanform.id).to.match(/^sf_/); 33 | }); 34 | 35 | it('retrieves a scanform', async function () { 36 | const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment()); 37 | 38 | const scanform = await client.ScanForm.create({ 39 | shipments: [shipment], 40 | }); 41 | 42 | const retrievedScanform = await client.ScanForm.retrieve(scanform.id); 43 | 44 | expect(retrievedScanform).to.be.an.instanceOf(ScanForm); 45 | expect(withoutParams(retrievedScanform)).to.deep.include(withoutParams(scanform)); 46 | }); 47 | 48 | it('retrieves all scanforms', async function () { 49 | const scanforms = await client.ScanForm.all({ 50 | page_size: Fixture.pageSize(), 51 | }); 52 | 53 | const scanformsArray = scanforms.scan_forms; 54 | 55 | expect(scanformsArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); 56 | expect(scanforms.has_more).to.exist; 57 | scanformsArray.forEach((scanform) => { 58 | expect(scanform).to.be.an.instanceOf(ScanForm); 59 | }); 60 | }); 61 | 62 | it('retrieves next page of scanforms', async function () { 63 | try { 64 | const scanforms = await client.ScanForm.all({ page_size: Fixture.pageSize() }); 65 | const nextPage = await client.ScanForm.getNextPage(scanforms, Fixture.pageSize()); 66 | 67 | const firstIdOfFirstPage = scanforms.scan_forms[0].id; 68 | const firstIdOfSecondPage = nextPage.scan_forms[0].id; 69 | 70 | expect(firstIdOfFirstPage).to.not.equal(firstIdOfSecondPage); 71 | } catch (error) { 72 | if (!(error instanceof EndOfPaginationError)) { 73 | throw new Error('Test failed intentionally'); 74 | } 75 | } 76 | }); 77 | }); 78 | -------------------------------------------------------------------------------- /test/services/smart_rate.test.js: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | 3 | import EasyPostClient from '../../src/easypost'; 4 | import Fixture from '../helpers/fixture'; 5 | import * as setupPolly from '../helpers/setup_polly'; 6 | 7 | /* eslint-disable func-names */ 8 | describe('SmartRate Service', function () { 9 | const getPolly = setupPolly.setupPollyTests(); 10 | let client; 11 | 12 | beforeAll(function () { 13 | client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); 14 | }); 15 | 16 | beforeEach(function () { 17 | const { server } = getPolly(); 18 | setupPolly.setupCassette(server); 19 | }); 20 | 21 | it('estimate delivery date', async function () { 22 | const carrier = Fixture.usps(); 23 | 24 | const params = { 25 | from_zip: Fixture.caAddress1().zip, 26 | to_zip: Fixture.caAddress2().zip, 27 | planned_ship_date: Fixture.plannedShipDate(), 28 | carriers: [carrier], 29 | }; 30 | 31 | const estimatedDeliveryDates = await client.SmartRate.estimateDeliveryDate(params); 32 | 33 | for (const entry of estimatedDeliveryDates.results) { 34 | expect(entry.carrier).to.equal(carrier); 35 | expect(entry.easypost_time_in_transit_data).to.be.an('object'); 36 | expect(entry.easypost_time_in_transit_data.easypost_estimated_delivery_date).to.not.be.null; 37 | } 38 | }); 39 | 40 | it('recommend ship date', async function () { 41 | const carrier = Fixture.usps(); 42 | 43 | const params = { 44 | from_zip: Fixture.caAddress1().zip, 45 | to_zip: Fixture.caAddress2().zip, 46 | desired_delivery_date: Fixture.plannedDeliveryDate(), 47 | carriers: [carrier], 48 | }; 49 | 50 | const recommendedShipDates = await client.SmartRate.recommendShipDate(params); 51 | 52 | for (const entry of recommendedShipDates.results) { 53 | expect(entry.carrier).to.equal(carrier); 54 | expect(entry.easypost_time_in_transit_data).to.be.an('object'); 55 | expect(entry.easypost_time_in_transit_data.ship_on_date).to.not.be.null; 56 | } 57 | }); 58 | }); 59 | -------------------------------------------------------------------------------- /test/services/tracker.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable func-names */ 2 | import { expect } from 'chai'; 3 | 4 | import EasyPostClient from '../../src/easypost'; 5 | import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; 6 | import Tracker from '../../src/models/tracker'; 7 | import Fixture from '../helpers/fixture'; 8 | import * as setupPolly from '../helpers/setup_polly'; 9 | 10 | describe('Tracker Service', function () { 11 | const getPolly = setupPolly.setupPollyTests(); 12 | let client; 13 | 14 | beforeAll(function () { 15 | client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); 16 | }); 17 | 18 | beforeEach(function () { 19 | const { server } = getPolly(); 20 | setupPolly.setupCassette(server); 21 | }); 22 | 23 | it('creates a tracker', async function () { 24 | const tracker = await client.Tracker.create({ 25 | tracking_code: 'EZ1000000001', 26 | }); 27 | 28 | expect(tracker).to.be.an.instanceOf(Tracker); 29 | expect(tracker.id).to.match(/^trk_/); 30 | expect(tracker.status).to.equal('pre_transit'); 31 | }); 32 | 33 | it('retrieves a tracker', async function () { 34 | const tracker = await client.Tracker.create({ 35 | tracking_code: 'EZ1000000001', 36 | }); 37 | 38 | const retrievedTracker = await client.Tracker.retrieve(tracker.id); 39 | 40 | expect(retrievedTracker).to.be.an.instanceOf(Tracker); 41 | expect(retrievedTracker.id).to.equal(tracker.id); 42 | }); 43 | 44 | it('retrieves all trackers', async function () { 45 | const trackers = await client.Tracker.all({ 46 | page_size: Fixture.pageSize(), 47 | }); 48 | 49 | const trackersArray = trackers.trackers; 50 | 51 | expect(trackersArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); 52 | expect(trackers.has_more).to.exist; 53 | trackersArray.forEach((tracker) => { 54 | expect(tracker).to.be.an.instanceOf(Tracker); 55 | }); 56 | }); 57 | 58 | it('retrieves next page of trackers', async function () { 59 | try { 60 | const trackers = await client.Tracker.all({ page_size: Fixture.pageSize() }); 61 | const nextPage = await client.Tracker.getNextPage(trackers, Fixture.pageSize()); 62 | 63 | const firstIdOfFirstPage = trackers.trackers[0].id; 64 | const firstIdOfSecondPage = nextPage.trackers[0].id; 65 | 66 | expect(firstIdOfFirstPage).to.not.equal(firstIdOfSecondPage); 67 | } catch (error) { 68 | if (!(error instanceof EndOfPaginationError)) { 69 | throw new Error('Test failed intentionally'); 70 | } 71 | } 72 | }); 73 | }); 74 | -------------------------------------------------------------------------------- /types/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "plugins": ["@typescript-eslint"], 5 | "extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended"], 6 | "rules": { 7 | "no-unused-vars": "off" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /types/Address/AddressCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { ParametersToOmitOnCreate } from '../utils'; 2 | import { IAddress } from './Address'; 3 | 4 | /** 5 | * @see https://docs.easypost.com/docs/addresses#verify-an-address 6 | */ 7 | export declare interface IAddressCreateParameters 8 | extends Omit { 9 | /** 10 | * The verifications to perform when creating. 11 | * verify_strict takes precedence. 12 | * true will perform both delivery and zip code. 13 | */ 14 | verify?: boolean | null; 15 | 16 | /** 17 | * The verifications to perform when creating. 18 | * The failure of any of these verifications causes the whole request to fail. 19 | * true will perform both delivery and zip code. 20 | */ 21 | verify_strict?: boolean | null; 22 | } 23 | -------------------------------------------------------------------------------- /types/Address/AddressListParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAllMethodParameters } from '../utils'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/addresses#retrieve-all-addresses 5 | */ 6 | export declare interface IAddressListParameters extends IAllMethodParameters {} 7 | -------------------------------------------------------------------------------- /types/Address/Verification.d.ts: -------------------------------------------------------------------------------- 1 | import { IFieldError } from '../errors'; 2 | import { IVerificationDetails } from './VerificationDetails'; 3 | 4 | /** 5 | * @see https://docs.easypost.com/docs/addresses#verification-object 6 | */ 7 | export declare interface IVerification { 8 | /** 9 | * The success of the verification 10 | */ 11 | success: boolean; 12 | 13 | /** 14 | * All errors that caused the verification to fail 15 | */ 16 | errors: IFieldError[]; 17 | 18 | /** 19 | * Extra data related to the verification 20 | */ 21 | details: IVerificationDetails; 22 | } 23 | -------------------------------------------------------------------------------- /types/Address/VerificationDetails.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @see https://docs.easypost.com/docs/addresses#verificationdetails-object 3 | */ 4 | export declare interface IVerificationDetails { 5 | /** 6 | * The latitude of an Address. 7 | */ 8 | latitude: number; 9 | 10 | /** 11 | * The longitude of an Address. 12 | */ 13 | longitude: number; 14 | 15 | /** 16 | * The time zone the address is located in, IE: America/Los_Angeles 17 | */ 18 | time_zone: string; 19 | } 20 | -------------------------------------------------------------------------------- /types/Address/Verifications.d.ts: -------------------------------------------------------------------------------- 1 | import { IVerification } from './Verification'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/addresses#verification-object 5 | */ 6 | export declare interface IVerifications { 7 | /** 8 | * Only applicable to US addresses - checks and sets the ZIP+4 9 | */ 10 | zip4: IVerification; 11 | /** 12 | * Checks that the address is deliverable and makes minor corrections to spelling/format. US addresses will also have their "residential" status checked and set. 13 | */ 14 | delivery: IVerification; 15 | } 16 | -------------------------------------------------------------------------------- /types/Address/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Address'; 2 | export * from './AddressCreateParameters'; 3 | export * from './Verification'; 4 | export * from './VerificationDetails'; 5 | export * from './Verifications'; 6 | -------------------------------------------------------------------------------- /types/ApiKey/ApiKey.d.ts: -------------------------------------------------------------------------------- 1 | import { IObjectWithId } from '../base'; 2 | 3 | export declare interface IApiKey extends IObjectWithId<'ApiKey'> { 4 | /** 5 | * The actual key value to use for authentication 6 | */ 7 | key: string; 8 | 9 | /** 10 | * When the API key was created 11 | */ 12 | created_at: string; 13 | 14 | /** 15 | * Whether the API key is active or not 16 | */ 17 | active: boolean; 18 | } 19 | 20 | export declare class ApiKey implements IApiKey { 21 | id: string; 22 | mode: 'test' | 'production'; 23 | object: 'ApiKey'; 24 | key: string; 25 | created_at: string; 26 | active: boolean; 27 | 28 | /** 29 | * Both production and test keys will be returned for a User and all of its children. 30 | * If the request is authenticated as a Child, only the API Keys for that Child will be returned. 31 | * 32 | * @see https://docs.easypost.com/docs/api-keys#retrieve-an-api-key 33 | * 34 | * @param apiKeyId Unique, begins with "user_" 35 | * @returns {Promise} The verified {@link ApiKey}. 36 | */ 37 | static retrieve(apiKeyId: string): Promise; 38 | } 39 | -------------------------------------------------------------------------------- /types/ApiKey/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './ApiKey'; 2 | -------------------------------------------------------------------------------- /types/Batch/BatchCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { Shipment } from '../Shipment'; 2 | 3 | export declare interface IBatchCreateParameters { 4 | shipments?: Array; 5 | } 6 | -------------------------------------------------------------------------------- /types/Batch/BatchListParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAllMethodParameters } from '../utils'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/batches#retrieve-all-batches 5 | */ 6 | export declare interface IBatchListParameters extends IAllMethodParameters {} 7 | -------------------------------------------------------------------------------- /types/Batch/BatchShipment.d.ts: -------------------------------------------------------------------------------- 1 | import { TBatchStatus } from './BatchStatus'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/batches#batchshipment-object 5 | */ 6 | export declare interface IBatchShipment { 7 | /** 8 | * The id of the Shipment. Unique, begins with "shp_" 9 | */ 10 | id: string; 11 | 12 | /** 13 | * An optional field that may be used in place of ID in some API endpoints 14 | */ 15 | reference?: string | null; 16 | 17 | /** 18 | * The current status. Possible values are "postage_purchased", "postage_purchase_failed", "queued_for_purchase", "creation_failed", and "created" 19 | */ 20 | batch_status: TBatchStatus; 21 | 22 | /** 23 | * A human readable message for any errors that occurred during the Batch's life cycle 24 | */ 25 | batch_message: string; 26 | } 27 | -------------------------------------------------------------------------------- /types/Batch/BatchState.d.ts: -------------------------------------------------------------------------------- 1 | export declare type TBatchState = 2 | | 'creating' 3 | | 'creation_failed' 4 | | 'created' 5 | | 'purchasing' 6 | | 'purchase_failed' 7 | | 'purchased' 8 | | 'label_generating' 9 | | 'label_generated'; 10 | -------------------------------------------------------------------------------- /types/Batch/BatchStatus.d.ts: -------------------------------------------------------------------------------- 1 | export declare type TBatchStatus = 2 | | 'postage_purchased' 3 | | 'postage_purchase_failed' 4 | | 'queued_for_purchase' 5 | | 'creation_failed' 6 | | 'created'; 7 | -------------------------------------------------------------------------------- /types/Batch/BatchStatuses.d.ts: -------------------------------------------------------------------------------- 1 | import { TBatchStatus } from './BatchStatus'; 2 | 3 | export declare type TBatchStatuses = { [key in TBatchStatus]: number }; 4 | -------------------------------------------------------------------------------- /types/Batch/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Batch'; 2 | export * from './BatchState'; 3 | export * from './BatchStatus'; 4 | export * from './BatchStatuses'; 5 | export * from './BatchShipment'; 6 | export * from './BatchCreateParameters'; 7 | -------------------------------------------------------------------------------- /types/Billing/Billing.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The Billing class allow you to fund wallet by using primary or secondary payment method, 3 | * delete a existing payment method, and retrieve all payment methods associated to the user. 4 | * 5 | * @see https://docs.easypost.com/docs/users/billing 6 | */ 7 | export declare class Billing { 8 | /** 9 | * Fund your EasyPost wallet by charging your primary or secondary payment method on file. 10 | * 11 | * @see https://docs.easypost.com/docs/users/billing#add-funds-to-your-wallet-one-time-charge 12 | * @requires production API Key. 13 | * 14 | * @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. 15 | * @param priority The payment method from your account, either primary or secondary. 16 | */ 17 | static fundWallet(amount: string, priority?: string): void; 18 | 19 | /** 20 | * Delete a payment method from your account. 21 | * @see https://docs.easypost.com/docs/users/billing#delete-a-payment-method 22 | * @requires production API Key. 23 | * 24 | * @param priority The payment method from your account, either primary or secondary. 25 | */ 26 | static deletePaymentMethod(priority: string): void; 27 | 28 | /** 29 | * Retrieve all payment methods. 30 | * 31 | * @see https://docs.easypost.com/docs/users/billing#retrieve-payment-methods 32 | * @requires production API Key. 33 | */ 34 | static retrievePaymentMethods(): object; 35 | } 36 | -------------------------------------------------------------------------------- /types/Billing/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Billing'; 2 | -------------------------------------------------------------------------------- /types/Brand/Brand.d.ts: -------------------------------------------------------------------------------- 1 | import { IObjectWithId } from '../base'; 2 | 3 | /** 4 | * The Brand class represents the public-accessible information about a user's brand, including logos, colors and themes. 5 | * 6 | * @see https://docs.easypost.com/docs/users/brand 7 | */ 8 | export declare interface IBrand extends IObjectWithId<'Brand'> { 9 | /** 10 | * The background color of the brand, as a hex code. 11 | */ 12 | background_color: string; 13 | 14 | /** 15 | * The primary color of the brand, as a hex code. 16 | */ 17 | color: string; 18 | 19 | /** 20 | * The logo of the brand, as a base64-encoded PNG, GIF, JPEG or SVG. 21 | */ 22 | logo: string; 23 | 24 | /** 25 | * The URL of the brand's logo. 26 | */ 27 | logo_href: string; 28 | 29 | /** 30 | * The banner ad of the brand, as a base64-encoded PNG, GIF, JPEG or SVG. 31 | */ 32 | ad: string; 33 | 34 | /** 35 | * The URL of the brand's banner ad. 36 | */ 37 | ad_href: string; 38 | 39 | /** 40 | * The ID of the brand's associated User. 41 | */ 42 | user_id: string; 43 | 44 | /** 45 | * The name of the current theme. 46 | */ 47 | theme: 'theme1' | 'theme2'; 48 | } 49 | 50 | export declare class Brand implements IBrand { 51 | id: string; 52 | mode: 'test' | 'production'; 53 | object: 'Brand'; 54 | reference?: string | null; 55 | ad: string; 56 | ad_href: string; 57 | background_color: string; 58 | color: string; 59 | logo: string; 60 | logo_href: string; 61 | theme: 'theme1' | 'theme2'; 62 | user_id: string; 63 | 64 | /** 65 | * Update the brand of the current authenticated user. 66 | * 67 | * @see https://docs.easypost.com/docs/users/brand#update-a-brand 68 | * 69 | * @param params The parameters to update the {@link Brand} with 70 | * @returns {Promise} The updated Brand. 71 | */ 72 | static updateBrand(params: object): Promise; 73 | } 74 | -------------------------------------------------------------------------------- /types/Brand/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Brand'; 2 | -------------------------------------------------------------------------------- /types/Carrier/CarrierAccount/CarrierAccountCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { ParametersToOmitOnCreate } from '../../utils'; 2 | import { ICarrierAccount } from './CarrierAccount'; 3 | 4 | export declare interface ICarrierAccountCreateParameters 5 | extends Omit {} 6 | -------------------------------------------------------------------------------- /types/Carrier/CarrierAccount/CarrierAccountField.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @see https://docs.easypost.com/docs/carrier-accounts#fields-object 3 | */ 4 | export declare interface ICarrierAccountField { 5 | /** 6 | * Each key in the sub-objects of a CarrierAccount's fields is the name of a settable field 7 | */ 8 | key: string; 9 | 10 | /** 11 | * The visibility value is used to control form field types, and is discussed in the CarrierType section 12 | */ 13 | visibility: string; 14 | 15 | /** 16 | * The label value is used in form rendering to display a more precise field name 17 | */ 18 | label: string; 19 | 20 | /** 21 | * Checkbox fields use "0" and "1" as False and True, all other field types present plaintext, partly-masked, or masked credential data for reference 22 | */ 23 | value: string; 24 | } 25 | -------------------------------------------------------------------------------- /types/Carrier/CarrierAccount/CarrierAccountFields.d.ts: -------------------------------------------------------------------------------- 1 | import { ICarrierAccountField } from './CarrierAccountField'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/carrier-accounts#fields-object 5 | */ 6 | export declare interface ICarrierAccountFields { 7 | /** 8 | * Credentials used in the production environment. 9 | */ 10 | credentials: ICarrierAccountField; 11 | 12 | /** 13 | * Credentials used in the test environment. 14 | */ 15 | test_credentials: ICarrierAccountField; 16 | 17 | /** 18 | * For USPS this designates that no credentials are required. 19 | */ 20 | auto_link: boolean; 21 | 22 | /** 23 | * When present, a separate authentication process will be required through the UI to link this account type. 24 | */ 25 | custom_workflow: boolean; 26 | } 27 | -------------------------------------------------------------------------------- /types/Carrier/CarrierAccount/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './CarrierAccount'; 2 | export * from './CarrierAccountFields'; 3 | export * from './CarrierAccountField'; 4 | export * from './CarrierAccountCreateParameters'; 5 | -------------------------------------------------------------------------------- /types/Carrier/CarrierMetadata/CarrierMetadata.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The Carrier Metadata endpoint returns information about all the carriers available on the EasyPost platform. 3 | * This information may include service levels, predefined packages, shipment options, supported features, and 4 | * more that are available per carrier. This metadata can be useful during onboarding and integration or when 5 | * determining the ideal carrier mix for your setup. 6 | * 7 | * @see https://docs.easypost.com/docs/carrier-metadata#carriermetadata-object 8 | */ 9 | export declare interface ICarrierMetadata { 10 | /** 11 | * The single-word name of a carrier such as "royalmail" 12 | */ 13 | carrier: string; 14 | 15 | /** 16 | * The human-readable name of the carrier 17 | */ 18 | human_readable?: string | null; 19 | 20 | /** 21 | * A list of service level objects for this carrier 22 | */ 23 | service_levels?: Array | null; 24 | 25 | /** 26 | * A list of predefined package objects for this carrier 27 | */ 28 | predefined_packages?: Array | null; 29 | 30 | /** 31 | * A list of supported feature objects for this carrier 32 | */ 33 | supported_features?: Array | null; 34 | 35 | /** 36 | * A list of shipment option objects for this carrier 37 | */ 38 | shipment_options?: Array | null; 39 | } 40 | 41 | export declare class CarrierMetadata implements ICarrierMetadata { 42 | carrier: string; 43 | human_readable?: string | null; 44 | service_levels?: Array | null; 45 | predefined_packages?: Array | null; 46 | supported_features?: Array | null; 47 | shipment_options?: Array | null; 48 | 49 | /** 50 | * Retrieve all Carrier Metadata for all carriers on the EasyPost platform. Optionally, 51 | * filter the response by specifying a list of carriers or metadata types. 52 | * 53 | * @param {Array} carriers A comma-delimited list of single-word carriers you'd like to filter the response by 54 | * @param {Array} types A comma-delimited list of the metadata types you'd like to filter the response by 55 | * 56 | * @see https://docs.easypost.com/docs/carrier-metadata#retrieve-carrier-metadata 57 | * 58 | * @returns {Promise} The {@link CarrierMetadata} object. 59 | */ 60 | static retrieve(carriers: Array, types: Array): Promise; 61 | } 62 | -------------------------------------------------------------------------------- /types/Carrier/CarrierMetadata/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './CarrierMetadata'; 2 | -------------------------------------------------------------------------------- /types/Carrier/CarrierType/CarrierType.d.ts: -------------------------------------------------------------------------------- 1 | import { IBaseObject } from '../../base'; 2 | import { ICarrierTypeFields } from './CarrierTypeFields'; 3 | 4 | /** 5 | * The CarrierType object provides an export declare interface for determining the valid fields of a CarrierAccount. 6 | * The list of CarrierType objects only changes when a new carrier is added to EasyPost. 7 | * 8 | * The CarrierType objects consist of their top level attributes as well as a fields object that contains credentials and sometimes test_credentials sub-objects, 9 | * which themselves are collections of attributes for CarrierAccount creation as well as metadata about presentation and the naming of said attributes. 10 | * 11 | * There are a couple special case CarrierAccounts, with structures differing somewhat from the norm. 12 | * 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. 13 | * 14 | * 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. 15 | * 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. 16 | * 17 | * @see https://docs.easypost.com/docs/carrier-types#carriertype-object 18 | */ 19 | export declare interface ICarrierType extends IBaseObject<'CarrierType'> { 20 | /** 21 | * Specifies the CarrierAccount type. 22 | */ 23 | type: string; 24 | 25 | /** 26 | * Contains at least one of the following keys: "auto_link", "credentials", "test_credentials", and "custom_workflow" 27 | */ 28 | fields: ICarrierTypeFields; 29 | } 30 | 31 | export declare class CarrierType implements ICarrierType { 32 | type: string; 33 | fields: ICarrierTypeFields; 34 | object: 'CarrierType'; 35 | 36 | /** 37 | * The CarrierType list is an unpaginated list of all carrier types available to the account of the given API key. 38 | * 39 | * @see https://docs.easypost.com/docs/carrier-types#retrieve-available-carrier-types 40 | * @requires production API Key. 41 | * 42 | * @returns {Object} - An object containing a list of {@link CarrierType carrier types}. 43 | */ 44 | static all(): Promise; 45 | } 46 | -------------------------------------------------------------------------------- /types/Carrier/CarrierType/CarrierTypeCredentials.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @see https://docs.easypost.com/docs/carrier-types#credentials-object 3 | */ 4 | export declare interface ICarrierTypeCredentials { 5 | /** 6 | * The key for each attribute sub-object within credentials is the name of the attribute for submission on CarrierAccounts 7 | */ 8 | name: string; 9 | 10 | /** 11 | * There are five possible values, which encode the security need and storage type for each attribute: "visible", "checkbox", "fake", "password", and "masked" 12 | */ 13 | visibility: 'visible' | 'checkbox' | 'fake' | 'password' | 'masked'; 14 | 15 | /** 16 | * Most attributes have generic names, so for clarity a "label" value is provided for clearer representation when rendering forms 17 | */ 18 | label: string; 19 | } 20 | -------------------------------------------------------------------------------- /types/Carrier/CarrierType/CarrierTypeFields.d.ts: -------------------------------------------------------------------------------- 1 | import { ICarrierTypeCredentials } from './CarrierTypeCredentials'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/carrier-types#fields-object 5 | */ 6 | export declare interface ICarrierTypeFields { 7 | /** 8 | * If this key is present with the value of true, no other attributes are needed for CarrierAccount creation 9 | */ 10 | auto_link: boolean; 11 | 12 | /** 13 | * 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 14 | */ 15 | custom_workflow: boolean; 16 | 17 | /** 18 | * If this object is present, required attribute names and their metadata are presented inside 19 | */ 20 | credentials: ICarrierTypeCredentials; 21 | 22 | /** 23 | * If this object is present, it contains attribute names and metadata just as the credentials object. 24 | * It is not required for CarrierAccount creation if you do not plan on using the carrier account for test mode 25 | */ 26 | test_credentials: ICarrierTypeCredentials; 27 | } 28 | -------------------------------------------------------------------------------- /types/Carrier/CarrierType/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './CarrierType'; 2 | export * from './CarrierTypeFields'; 3 | export * from './CarrierTypeCredentials'; 4 | -------------------------------------------------------------------------------- /types/Carrier/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './CarrierAccount'; 2 | export * from './CarrierMetadata'; 3 | export * from './CarrierType'; 4 | -------------------------------------------------------------------------------- /types/Claim/ClaimCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { TClaimPaymentMethod } from './ClaimPaymentMethod'; 2 | import { TClaimType } from './ClaimType'; 3 | 4 | export declare interface IClaimCreateParameters { 5 | /** The tracking code of the shipment to file a claim for. */ 6 | tracking_code: string; 7 | 8 | /** The type of claim to file. */ 9 | type: TClaimType; 10 | 11 | /** The amount being claimed for reimbursement. */ 12 | amount: string; 13 | 14 | /** 15 | * Email-based files to attach to the claim for evidence. Each file must be a 16 | * base64-encoded string. 17 | */ 18 | email_evidence_attachments?: string[]; 19 | 20 | /** 21 | * Invoices to attach to the claim for evidence. Each file must be a 22 | * base64-encoded string. 23 | */ 24 | invoice_attachments?: string[]; 25 | 26 | /** 27 | * Additional supporting documents to attach to the claim. Required if the 28 | * type is damage or theft. Each file must be a base64-encoded string. 29 | */ 30 | supporting_documentation_attachments?: string[]; 31 | 32 | /** Detailed description of the claim. */ 33 | description: string; 34 | 35 | /** The name of the recipient of the reimbursement. */ 36 | recipient_name: string; 37 | 38 | /** The email address of the contact for the claim. */ 39 | contact_email: string; 40 | 41 | /** The payment method for the claim reimbursement. */ 42 | payment_method: TClaimPaymentMethod; 43 | } 44 | -------------------------------------------------------------------------------- /types/Claim/ClaimHistory.d.ts: -------------------------------------------------------------------------------- 1 | export declare type TClaimHistory = { 2 | /** The status of the claim at the time of this history entry. */ 3 | status: string; 4 | 5 | /** The reason for the status of the claim at the time of this history entry. */ 6 | status_detail: string; 7 | 8 | /** The date and time of the history entry. */ 9 | timestamp: string; 10 | }; 11 | -------------------------------------------------------------------------------- /types/Claim/ClaimPaymentMethod.d.ts: -------------------------------------------------------------------------------- 1 | export declare type TClaimPaymentMethod = 'mailed_check' | 'easypost_wallet'; 2 | -------------------------------------------------------------------------------- /types/Claim/ClaimType.d.ts: -------------------------------------------------------------------------------- 1 | export declare type TClaimType = 'damage' | 'loss' | 'theft'; 2 | -------------------------------------------------------------------------------- /types/Claim/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Claim'; 2 | export * from './ClaimCreateParameters'; 3 | export * from './ClaimHistory'; 4 | export * from './ClaimType'; 5 | -------------------------------------------------------------------------------- /types/Customs/CustomsInfo/CustomsInfoCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { ParametersToOmitOnCreate } from '../../utils'; 2 | import { ICustomsInfo } from './CustomsInfo'; 3 | 4 | export declare interface ICustomsInfoCreateParameters 5 | extends Omit {} 6 | -------------------------------------------------------------------------------- /types/Customs/CustomsInfo/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './CustomsInfo'; 2 | -------------------------------------------------------------------------------- /types/Customs/CustomsItem/CustomsItem.d.ts: -------------------------------------------------------------------------------- 1 | import { IDatedObject, IObjectWithId } from '../../base'; 2 | import { DeepPartial } from '../../utils'; 3 | import { ICustomsItemCreateParameters } from './CustomsItemCreateParameters'; 4 | 5 | /** 6 | * A CustomsItem object describes goods for international shipment and should be created then included in a CustomsInfo object. 7 | * 8 | * @see https://docs.easypost.com/docs/customs-items-object 9 | */ 10 | export declare interface ICustomsItem extends IObjectWithId<'CustomsItem'>, IDatedObject { 11 | /** 12 | * Required, description of item being shipped 13 | */ 14 | description: string; 15 | 16 | /** 17 | * Required, greater than zero 18 | * float 19 | */ 20 | quantity: number; 21 | 22 | /** 23 | * Required, greater than zero, total value (unit value * quantity) 24 | * float (USD) 25 | */ 26 | value: number; 27 | 28 | /** 29 | * Required, greater than zero, total weight (unit weight * quantity) 30 | * float (oz) 31 | */ 32 | weight: number; 33 | 34 | /** 35 | * Harmonized Tariff Schedule, e.g. "6109.10.0012" for Men's T-shirts 36 | * 37 | * @see https://hts.usitc.gov/ 38 | */ 39 | hs_tariff_number?: string | null; 40 | 41 | /** 42 | * SKU/UPC or other product identifier 43 | */ 44 | code?: string | null; 45 | 46 | /** 47 | * Required, 2 char country code 48 | */ 49 | origin_country: string; 50 | 51 | /** 52 | * 3 char currency code, default USD 53 | */ 54 | currency?: string | null; 55 | } 56 | 57 | export declare class CustomsItem implements ICustomsItem { 58 | public constructor(input: DeepPartial); 59 | 60 | id: string; 61 | mode: 'test' | 'production'; 62 | object: 'CustomsItem'; 63 | description: string; 64 | quantity: number; 65 | value: number; 66 | weight: number; 67 | hs_tariff_number?: string | null; 68 | code?: string | null; 69 | origin_country: string; 70 | currency?: string | null; 71 | created_at: string; 72 | updated_at: string; 73 | 74 | /** 75 | * 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. 76 | * 77 | * @see https://docs.easypost.com/docs/customs-items#create-a-customsitem 78 | * 79 | * @param {Object} params The parameters to create an {@link CustomsItem} with. 80 | * @returns {Promise} The {@link CustomsItem}. 81 | */ 82 | static create(params: Object): Promise; 83 | 84 | /** 85 | * A CustomsItem can be retrieved by its id. 86 | * 87 | * @param CustomsItemId Unique, begins with "cstitem_" 88 | * 89 | * @see https://docs.easypost.com/docs/customs-items#retrieve-a-customsitem 90 | * 91 | * @returns {Promise} The {@link CustomsItem}. 92 | */ 93 | static retrieve(CustomsItemId: string): Promise; 94 | } 95 | -------------------------------------------------------------------------------- /types/Customs/CustomsItem/CustomsItemCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { ParametersToOmitOnCreate } from '../../utils'; 2 | import { ICustomsItem } from './CustomsItem'; 3 | 4 | export declare interface ICustomsItemCreateParameters 5 | extends Omit {} 6 | -------------------------------------------------------------------------------- /types/Customs/CustomsItem/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './CustomsItem'; 2 | -------------------------------------------------------------------------------- /types/Customs/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './CustomsInfo'; 2 | export * from './CustomsItem'; 3 | -------------------------------------------------------------------------------- /types/EndShipper/EndShipperCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { ParametersToOmitOnCreate } from '../utils'; 2 | import { IEndshipper } from './EndShipper'; 3 | 4 | export declare interface IEndShipperCreateParameters 5 | extends Omit {} 6 | -------------------------------------------------------------------------------- /types/EndShipper/EndShipperListParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAllMethodParameters } from '../utils'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/endshippers 5 | */ 6 | export declare interface IEndShipperListParameters extends IAllMethodParameters {} 7 | -------------------------------------------------------------------------------- /types/EndShipper/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './EndShipper'; 2 | export * from './EndShipperCreateParameters'; 3 | -------------------------------------------------------------------------------- /types/Event/EventListParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAllMethodParameters } from '../utils'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/events#retrieve-all-events 5 | */ 6 | export declare interface IEventListParameters extends IAllMethodParameters {} 7 | -------------------------------------------------------------------------------- /types/Event/Payload/Payload.d.ts: -------------------------------------------------------------------------------- 1 | import { IDatedObject, IObjectWithId } from '../../base'; 2 | import { IPayloadListParameters } from './PayloadListParameters'; 3 | 4 | /** 5 | * A Payload represents an attempt by EasyPost to send an Event to a Webhook. 6 | * An Event can have multiple Payloads. For instance, if there is a failure to deliver a Webhook, 7 | * an Event would have multiple payloads, one for each attempt to deliver the Event to the Webhook. 8 | * Payload can be useful for debugging webhook delivery and when initially setting up EasyPost webhooks. 9 | */ 10 | export declare interface IPayload extends IObjectWithId<'Payload'>, IDatedObject { 11 | /** 12 | * The body of the Payload response 13 | */ 14 | response_body: string | null; 15 | } 16 | 17 | export declare class Payload implements IPayload { 18 | id: string; 19 | mode: 'test' | 'production'; 20 | object: 'Payload'; 21 | response_body: string; 22 | created_at: string; 23 | updated_at: string; 24 | 25 | /** 26 | * Payload can be retrieved by their ID. 27 | * 28 | * @see https://docs.easypost.com/docs/events/payloads#retrieve-a-payload 29 | * 30 | * @param eventId the ID of the event object. 31 | * @param payloadId the ID of the payload. 32 | * @returns {Promise} The retrieved {@link Payload payload}. 33 | */ 34 | static retrieve(eventId: string, payloadId: string): Promise; 35 | 36 | /** 37 | * Retrieve all payload objects. 38 | * 39 | * @see https://docs.easypost.com/docs/events/payloads#retrieve-all-payloads 40 | * 41 | * @param params - The parameters to use for the request. 42 | * @returns {Object} - An object containing a list of {@link Payload payloads} and pagination information. 43 | */ 44 | static all(params: IPayloadListParameters): Promise<{ payloads: Payload[] }>; 45 | } 46 | -------------------------------------------------------------------------------- /types/Event/Payload/PayloadListParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAllMethodParameters } from '../../utils'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/events/payloads#retrieve-all-payloads 5 | */ 6 | export declare interface IPayloadListParameters extends IAllMethodParameters {} 7 | -------------------------------------------------------------------------------- /types/Event/Payload/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Payload'; 2 | -------------------------------------------------------------------------------- /types/Event/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Event'; 2 | -------------------------------------------------------------------------------- /types/Fee/Fee.d.ts: -------------------------------------------------------------------------------- 1 | import { IBaseObject } from '../base'; 2 | import { TFeeType } from './FeeType'; 3 | 4 | /** 5 | * Fee objects are used to represent the breakdown of charges made when purchasing an item on EasyPost. 6 | * Shipments and Trackers both have associations to Fee objects. 7 | * 8 | * Each Shipment object will have a Fee of type "LabelFee" to represent the label fee charged by EasyPost for the service. 9 | * 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. 10 | * Insurance on a Shipment will add an "InsuranceFee" with the insurance premium (not the covered value) for the amount. 11 | * Tracker objects will have a "TrackerFee" with the price, even when a Tracker is free. 12 | * 13 | * @see https://docs.easypost.com/docs/fees#fee-object 14 | */ 15 | export declare interface IFee extends IBaseObject<'Fee'> { 16 | /** 17 | * The name of the category of fee. Possible types are "LabelFee", "PostageFee", "InsuranceFee", and "TrackerFee" 18 | */ 19 | type: TFeeType; 20 | 21 | /** 22 | * USD value with sub-cent precision 23 | */ 24 | amount: string; 25 | 26 | /** 27 | * Whether EasyPost has successfully charged your account for the fee 28 | */ 29 | charged: boolean; 30 | 31 | /** 32 | * Whether the Fee has been refunded successfully 33 | */ 34 | refunded: boolean; 35 | } 36 | 37 | export declare class Fee implements IFee { 38 | object: 'Fee'; 39 | type: TFeeType; 40 | amount: string; 41 | charged: boolean; 42 | refunded: boolean; 43 | } 44 | -------------------------------------------------------------------------------- /types/Fee/FeeType.d.ts: -------------------------------------------------------------------------------- 1 | export declare type TFeeType = 'InsuranceFee' | 'LabelFee' | 'PostageFee' | 'TrackerFee'; 2 | -------------------------------------------------------------------------------- /types/Fee/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Fee'; 2 | export * from './FeeType'; 3 | -------------------------------------------------------------------------------- /types/Insurance/InsuranceCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAddress } from '../Address'; 2 | 3 | export declare interface IInsuranceCreateParameters { 4 | reference?: string | null; 5 | to_address: IAddress | string; 6 | from_address: IAddress | string; 7 | 8 | /** 9 | * The carrier associated with the tracking_code you provided. 10 | * The carrier will get auto-detected if none is provided 11 | */ 12 | carrier?: string | null; 13 | 14 | /** 15 | * The tracking code associated with the non-EasyPost-purchased package you'd like to insure. 16 | */ 17 | tracking_code: string; 18 | 19 | /** 20 | * The USD value of contents you would like to insure. 21 | * Currently the maximum is $5000 22 | * 23 | * @example 100.00 24 | */ 25 | amount: string; 26 | } 27 | -------------------------------------------------------------------------------- /types/Insurance/InsuranceStatus.d.ts: -------------------------------------------------------------------------------- 1 | export declare type TInsuranceStatus = 'new' | 'pending' | 'purchased' | 'failed' | 'cancelled'; 2 | -------------------------------------------------------------------------------- /types/Insurance/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Insurance'; 2 | export * from './InsuranceStatus'; 3 | export * from './InsuranceCreateParameters'; 4 | -------------------------------------------------------------------------------- /types/Order/OrderCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAddress } from '../Address'; 2 | import { Shipment } from '../Shipment'; 3 | 4 | export declare interface IOrderCreateParameters { 5 | reference?: string | null; 6 | to_address: IAddress | string; 7 | from_address: IAddress | string; 8 | shipments: Shipment[]; 9 | 10 | /** 11 | * optional array of ids that begin with "ca_" 12 | */ 13 | carrier_accounts?: string[] | null; 14 | } 15 | -------------------------------------------------------------------------------- /types/Order/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Order'; 2 | export * from './OrderCreateParameters'; 3 | -------------------------------------------------------------------------------- /types/Parcel/Parcel.d.ts: -------------------------------------------------------------------------------- 1 | import { IDatedObject, IObjectWithId } from '../base'; 2 | import { DeepPartial } from '../utils'; 3 | import { IParcelCreateParameters } from './ParcelCreateParameters'; 4 | 5 | /** 6 | * Parcel objects represent the physical container being shipped. 7 | * Dimensions can be supplied either as length, width, and height dimensions, or a predefined_package string. 8 | * Only weight is required, but since many carriers charge different rates for packages with large dimensions, we strongly recommend including all dimensions if available. 9 | * 10 | * Weights are in OUNCES (OZ) and go to one decimal point. 11 | * Dimensions are in INCHES (IN) and go to one decimal point. 12 | * 13 | * @see https://docs.easypost.com/docs/parcels#parcel-object 14 | */ 15 | export declare interface IParcel extends IObjectWithId<'Parcel'>, IDatedObject { 16 | /** 17 | * Required if width and/or height are present 18 | * float (inches) 19 | */ 20 | length?: number | null; 21 | 22 | /** 23 | * Required if width and/or height are present 24 | * float (inches) 25 | */ 26 | width?: number | null; 27 | 28 | /** 29 | * Required if width and/or height are present 30 | * float (inches) 31 | */ 32 | height?: number | null; 33 | 34 | /** 35 | * Always required 36 | * float (oz) 37 | */ 38 | weight: number; 39 | 40 | /** 41 | * Optional, one of our predefined_packages 42 | */ 43 | predefined_package?: string | null; 44 | } 45 | 46 | export declare class Parcel implements IParcel { 47 | public constructor(input: DeepPartial); 48 | 49 | id: string; 50 | mode: 'test' | 'production'; 51 | object: 'Parcel'; 52 | length?: number | null; 53 | width?: number | null; 54 | height?: number | null; 55 | predefined_package?: string | null; 56 | weight: number; 57 | created_at: string; 58 | updated_at: string; 59 | 60 | /** 61 | * Include the `weight`, and either a `predefined_package` or `length`, `width` and `height` if applicable. 62 | * 63 | * @see https://docs.easypost.com/docs/parcels#create-a-parcel 64 | * 65 | * @param {Object} params The parameters to create an {@link Parcel} with. 66 | * @returns {Promise} The created and verified {@link Parcel}. 67 | */ 68 | static create(params: Object): Promise; 69 | 70 | /** 71 | * Get a Parcel by its id. 72 | * In general you should not need to use this in your automated solution. 73 | * A Parcel's id can be inlined into the creation call to other objects. 74 | * This allows you to only create one Parcel for each package you will be using. 75 | * 76 | * @see https://docs.easypost.com/docs/parcels#retrieve-a-parcel 77 | * 78 | * @param parcelId Unique, begins with "prcl_" 79 | * @returns {Promise} The retrieved {@link Parcel}. 80 | */ 81 | static retrieve(parcelId: string): Promise; 82 | } 83 | -------------------------------------------------------------------------------- /types/Parcel/ParcelCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { ParametersToOmitOnCreate } from '../utils'; 2 | import { IParcel } from './Parcel'; 3 | 4 | export declare interface IParcelCreateParameters extends Omit { 5 | /** 6 | * Required if width and/or height are present 7 | * float (inches) 8 | */ 9 | length?: number | null; 10 | 11 | /** 12 | * Required if width and/or height are present 13 | * float (inches) 14 | */ 15 | width?: number | null; 16 | 17 | /** 18 | * Required if width and/or height are present 19 | * float (inches) 20 | */ 21 | height?: number | null; 22 | 23 | /** 24 | * Always required 25 | * float (oz) 26 | */ 27 | weight: number; 28 | } 29 | -------------------------------------------------------------------------------- /types/Parcel/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Parcel'; 2 | -------------------------------------------------------------------------------- /types/PaymentMethod/PaymentMethod.d.ts: -------------------------------------------------------------------------------- 1 | import { IObjectWithId } from '../base'; 2 | 3 | /** 4 | * The Payment method object can be either credit card or bank account. 5 | */ 6 | export declare interface IPaymentMethod extends IObjectWithId<'PaymentMethod'> { 7 | /** 8 | * Country of the bank account 9 | */ 10 | country: string; 11 | 12 | /** 13 | * Name of the bank 14 | */ 15 | bank_name: string; 16 | 17 | /** 18 | * Brand of the credit card 19 | */ 20 | brand: string; 21 | 22 | /** 23 | * Whether the payment method(credit card or bank account) is disabled or not 24 | */ 25 | disabled_at: string; 26 | 27 | /** 28 | * Expiration month of the credit card 29 | */ 30 | exp_month: number; 31 | 32 | /** 33 | * Expiration year of the credit card 34 | */ 35 | exp_year: number; 36 | 37 | /** 38 | * Last four of the credit card 39 | */ 40 | last4: string; 41 | 42 | /** 43 | * Name of the credit card 44 | */ 45 | name: string; 46 | 47 | /** 48 | * Whether the bank account is verified or not 49 | */ 50 | verified: boolean; 51 | } 52 | 53 | export declare class PaymentMethod implements IPaymentMethod { 54 | id: string; 55 | mode: 'test' | 'production'; 56 | object: 'PaymentMethod'; 57 | country: string; 58 | bank_name: string; 59 | brand: string; 60 | disabled_at: string; 61 | exp_month: number; 62 | exp_year: number; 63 | last4: string; 64 | name: string; 65 | verified: boolean; 66 | } 67 | -------------------------------------------------------------------------------- /types/PaymentMethod/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './PaymentMethod'; 2 | -------------------------------------------------------------------------------- /types/Pickup/PickupCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IPickupRate } from './PickupRate'; 2 | import { Address } from '../Address'; 3 | import { Batch } from '../Batch'; 4 | import { CarrierAccount } from '../Carrier'; 5 | import { Shipment } from '../Shipment'; 6 | 7 | interface BasePickupCreateParameters { 8 | address: Address | string; 9 | carrier_accounts?: CarrierAccount[] | null; 10 | confirmation?: string | null; 11 | instructions?: string | null; 12 | is_account_address?: boolean | null; 13 | max_datetime: string; 14 | min_datetime: string; 15 | pickup_rates: IPickupRate; 16 | reference?: string | null; 17 | status: string; 18 | } 19 | 20 | interface ShipmentPickupCreateParameters extends BasePickupCreateParameters { 21 | shipment?: Shipment | string | null; 22 | } 23 | 24 | interface BatchPickupCreateParameters extends BasePickupCreateParameters { 25 | batch?: Batch | string | null; 26 | } 27 | 28 | export type IPickupCreateParameters = ShipmentPickupCreateParameters | BatchPickupCreateParameters; 29 | -------------------------------------------------------------------------------- /types/Pickup/PickupListParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAllMethodParameters } from '../utils'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/pickups#retrieve-all-pickups 5 | */ 6 | export declare interface IPickupListParameters extends IAllMethodParameters {} 7 | -------------------------------------------------------------------------------- /types/Pickup/PickupRate.d.ts: -------------------------------------------------------------------------------- 1 | import { IDatedObject, IObjectWithId } from '../base'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/pickups#pickuprate-object 5 | */ 6 | export declare interface IPickupRate extends IObjectWithId<'PickupRate'>, IDatedObject { 7 | /** 8 | * service name 9 | */ 10 | service: string; 11 | 12 | /** 13 | * name of carrier 14 | */ 15 | carrier: string; 16 | 17 | /** 18 | * the actual rate quote for this service 19 | */ 20 | rate: string; 21 | 22 | /** 23 | * currency for the rate 24 | */ 25 | currency: string; 26 | 27 | /** 28 | * the ID of the pickup this is a quote for 29 | */ 30 | pickup_id: string; 31 | } 32 | -------------------------------------------------------------------------------- /types/Pickup/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Pickup'; 2 | export * from './PickupRate'; 3 | export * from './PickupCreateParameters'; 4 | -------------------------------------------------------------------------------- /types/Rate/Rate.d.ts: -------------------------------------------------------------------------------- 1 | import { IDatedObject, IObjectWithId } from '../base'; 2 | 3 | /** 4 | * The Rate class represents a summary of the price and details of a delivery service quote. 5 | * 6 | * @see https://docs.easypost.com/docs/shipments/rates 7 | */ 8 | export declare interface IRate extends IObjectWithId<'Rate'>, IDatedObject { 9 | /** 10 | * The service level of the rate. 11 | */ 12 | service: string; 13 | /** 14 | * The carrier of the rate. 15 | */ 16 | carrier: string; 17 | /** 18 | * The ID of the carrier account associated with this rate. 19 | */ 20 | carrier_account_id: string; 21 | /** 22 | * The ID of the shipment associated with this rate. 23 | */ 24 | shipment_id: string; 25 | /** 26 | * The quote price of the rate. 27 | */ 28 | rate: string; 29 | /** 30 | * The currency of the rate. 31 | */ 32 | currency: string; 33 | /** 34 | * The in-store retail rate given with no account. 35 | */ 36 | retail_rate: string; 37 | /** 38 | * The currency of the retail rate. 39 | */ 40 | retail_currency: string; 41 | /** 42 | * The non-negotiated rate given for having an account with the carrier. 43 | */ 44 | list_rate: string; 45 | /** 46 | * The currency of the list rate. 47 | */ 48 | list_currency: string; 49 | /** 50 | * The number of days in transit for this rate. 51 | */ 52 | delivery_days: number; 53 | /** 54 | * The delivery date for this rate. 55 | */ 56 | delivery_date: string; 57 | /** 58 | * Whether the delivery window is guaranteed. 59 | */ 60 | delivery_date_guaranteed: boolean; 61 | /** 62 | * The earliest delivery date for this rate. 63 | * This is deprecated and should be ignored. 64 | */ 65 | est_delivery_days: number; 66 | /** 67 | * The billing type of the rate. 68 | */ 69 | billing_type: string; 70 | } 71 | 72 | export declare class Rate implements IRate { 73 | billing_type: string; 74 | carrier: string; 75 | carrier_account_id: string; 76 | created_at: string; 77 | currency: string; 78 | delivery_date: string; 79 | delivery_date_guaranteed: boolean; 80 | delivery_days: number; 81 | est_delivery_days: number; 82 | id: string; 83 | list_currency: string; 84 | list_rate: string; 85 | mode: 'test' | 'production'; 86 | object: 'Rate'; 87 | rate: string; 88 | retail_currency: string; 89 | retail_rate: string; 90 | service: string; 91 | shipment_id: string; 92 | updated_at: string; 93 | } 94 | -------------------------------------------------------------------------------- /types/Rate/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Rate'; 2 | -------------------------------------------------------------------------------- /types/Referral/ReferralCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { ParametersToOmitOnCreate } from '../utils'; 2 | import { IReferral } from './Referral'; 3 | 4 | export declare interface IReferralCreateParameters 5 | extends Omit {} 6 | -------------------------------------------------------------------------------- /types/Referral/ReferralListParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAllMethodParameters } from '../utils'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/users/referral-customers#retrieve-all-referralcustomers 5 | */ 6 | export declare interface IReferralListParameters extends IAllMethodParameters {} 7 | -------------------------------------------------------------------------------- /types/Referral/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Referral'; 2 | export * from './ReferralCreateParameters'; 3 | -------------------------------------------------------------------------------- /types/Refund/RefundCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @see https://docs.easypost.com/docs/refunds#create-a-refund 3 | */ 4 | export declare interface IRefundCreateParameters { 5 | /** 6 | * The carrier to request a refund from 7 | */ 8 | carrier: string; 9 | 10 | /** 11 | * A list of tracking codes to request refunds for. Even for a single tracking code, it needs to be submitted as a list. 12 | */ 13 | tracking_codes: string[]; 14 | } 15 | -------------------------------------------------------------------------------- /types/Refund/RefundListParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAllMethodParameters } from '../utils'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/refunds#retrieve-all-refunds 5 | */ 6 | export declare interface IRefundListParameters extends IAllMethodParameters {} 7 | -------------------------------------------------------------------------------- /types/Refund/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Refund'; 2 | export * from './RefundCreateParameters'; 3 | -------------------------------------------------------------------------------- /types/Report/ReportCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | export declare interface IReportCreateParameters { 2 | start_date: string | null; 3 | end_date?: string | null; 4 | include_children?: boolean | null; 5 | send_email?: boolean | null; 6 | columns?: string[] | null; 7 | additional_columns?: string[] | null; 8 | } 9 | -------------------------------------------------------------------------------- /types/Report/ReportListParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAllMethodParameters } from '../utils'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/refunds#retrieve-all-refunds 5 | */ 6 | export declare interface IReportListParameters extends IAllMethodParameters {} 7 | -------------------------------------------------------------------------------- /types/Report/ReportObjectType.d.ts: -------------------------------------------------------------------------------- 1 | export declare type TReportObjectType = 2 | | 'CashFlowReport' 3 | | 'PaymentLogReport' 4 | | 'RefundReport' 5 | | 'ShipmentReport' 6 | | 'ShipmentInvoiceReport' 7 | | 'TrackerReport'; 8 | -------------------------------------------------------------------------------- /types/Report/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Report'; 2 | export * from './ReportObjectType'; 3 | -------------------------------------------------------------------------------- /types/ScanForm/ScanFormCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { DeepPartial } from '../utils'; 2 | import { IShipmentCreateParameters } from '../Shipment'; 3 | 4 | export declare interface IScanFormCreateParameters { 5 | shipments: Array>; 6 | } 7 | -------------------------------------------------------------------------------- /types/ScanForm/ScanFormListParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAllMethodParameters } from '../utils'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/scan-form#retrieve-all-scanforms 5 | */ 6 | export declare interface IScanFormListParameters extends IAllMethodParameters {} 7 | -------------------------------------------------------------------------------- /types/ScanForm/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './ScanForm'; 2 | -------------------------------------------------------------------------------- /types/Shipment/Form.d.ts: -------------------------------------------------------------------------------- 1 | import { IDatedObject, IObjectWithId } from '../base'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/shipments/forms#form-object 5 | */ 6 | export declare interface IForm extends IObjectWithId<'Form'>, IDatedObject { 7 | /** 8 | * 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" 9 | */ 10 | form_type: 11 | | 'cn22' 12 | | 'cod_return_label' 13 | | 'commercial_invoice' 14 | | 'high_value_report' 15 | | 'label_qr_code' 16 | | 'nafta_certificate_of_origin' 17 | | 'order_summary' 18 | | 'return_packing_slip' 19 | | 'rma_qr_code'; 20 | 21 | /** 22 | * The address we return the form back at 23 | */ 24 | form_url: string; 25 | 26 | /** 27 | * If we have submitted the form to the carrier on behalf of the customer 28 | */ 29 | submitted_electronically: boolean; 30 | } 31 | -------------------------------------------------------------------------------- /types/Shipment/Message.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * When rating a Shipment or Pickup, some carriers may fail to generate rates. 3 | * These failures are returned as part of the Shipment or Pickup as part of their messages attribute, and follow a common object structure. 4 | * 5 | * It is important to note that the message value for any member of this list comes directly from the carrier, not from EasyPost. 6 | * 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. 7 | * 8 | * @see https://docs.easypost.com/docs/shipments/messages#message-object 9 | */ 10 | export declare interface IMessage { 11 | /** 12 | * the name of the carrier generating the error, e.g. "UPS" 13 | */ 14 | carrier: string; 15 | 16 | /** 17 | * the category of error that occurred. Most frequently "rate_error" 18 | */ 19 | type: string; 20 | 21 | /** 22 | * the string from the carrier explaining the problem 23 | */ 24 | message: string; 25 | 26 | /** 27 | * the account id of the carrier. Useful if you have multiple accounts with the same carrier 28 | */ 29 | carrier_account_id: string; 30 | } 31 | -------------------------------------------------------------------------------- /types/Shipment/Options/LabelFormat.d.ts: -------------------------------------------------------------------------------- 1 | export declare type LabelFormat = 'PNG' | 'PDF' | 'ZPL' | 'EPL2'; 2 | -------------------------------------------------------------------------------- /types/Shipment/Options/PrintCustomCode.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * - FedEx 3 | * - (null) - If print_custom_1_code is not provided it defaults to Customer Reference 4 | * - PO - Purchase Order Number 5 | * - DP - Department Number 6 | * - RMA - Return Merchandise Authorization 7 | * - UPS 8 | * - AJ - Accounts Receivable Customer Account 9 | * - AT - Appropriation Number 10 | * - BM - Bill of Lading Number 11 | * - 9V - Collect on Delivery (COD) Number 12 | * - ON - Dealer Order Number 13 | * - DP - Department Number 14 | * - 3Q - Food and Drug Administration (FDA) Product Code 15 | * - IK - Invoice Number 16 | * - MK - Manifest Key Number 17 | * - MJ - Model Number 18 | * - PM - Part Number 19 | * - PC - Production Code 20 | * - PO - Purchase Order Number 21 | * - RQ - Purchase Request Number 22 | * - RZ - Return Authorization Number 23 | * - SA - Salesperson Number 24 | * - SE - Serial Number 25 | * - ST - Store Number 26 | * - TN - Transaction Reference Number 27 | * - EI - Employer's ID Number 28 | * - TJ - Federal Taxpayer ID No. 29 | */ 30 | export declare type TPrintCustomCode = 31 | | 'PO' 32 | | 'DP' 33 | | 'RMA' 34 | | 'AJ' 35 | | 'AT' 36 | | 'BM' 37 | | '9V' 38 | | 'ON' 39 | | '3Q' 40 | | 'IK' 41 | | 'MK' 42 | | 'MJ' 43 | | 'PM' 44 | | 'PC' 45 | | 'RQ' 46 | | 'RZ' 47 | | 'SA' 48 | | 'SE' 49 | | 'ST' 50 | | 'TN' 51 | | 'EI' 52 | | 'TJ'; 53 | -------------------------------------------------------------------------------- /types/Shipment/Options/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './LabelFormat'; 2 | export * from './Options'; 3 | export * from './PrintCustomCode'; 4 | -------------------------------------------------------------------------------- /types/Shipment/PostageLabel.d.ts: -------------------------------------------------------------------------------- 1 | import { IDatedObject, IObjectWithId } from '../base'; 2 | 3 | /** 4 | * PostageLabel Object 5 | */ 6 | export declare interface IPostageLabel extends IObjectWithId<'PostageLabel'>, IDatedObject { 7 | date_advance: number; 8 | integrated_form: string; 9 | label_date: string; 10 | label_resolution: number; 11 | label_size: string; 12 | label_type: string; 13 | label_url: string; 14 | label_file_type: string; 15 | label_pdf_url: string; 16 | label_epl2_url: string; 17 | label_zpl_url: string; 18 | } 19 | -------------------------------------------------------------------------------- /types/Shipment/Rate.d.ts: -------------------------------------------------------------------------------- 1 | import { IDatedObject, IObjectWithId } from '../base'; 2 | 3 | /** 4 | * After a Shipment is successfully created, it will automatically fetch Rates. 5 | * You can limit the CarrierAccounts to use for rating by passing the carrier_accounts parameter upon Shipment creation. 6 | * 7 | * 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. 8 | * 9 | * @see https://docs.easypost.com/docs/shipments/rates#rate-object 10 | */ 11 | export declare interface IRate extends IObjectWithId<'Rate'>, IDatedObject { 12 | /** 13 | * service level/name 14 | * @see https://docs.easypost.com/docs/shipments/rates#service-levels 15 | */ 16 | service: string; 17 | 18 | /** 19 | * name of carrier 20 | */ 21 | carrier: string; 22 | 23 | /** 24 | * ID of the CarrierAccount record used to generate this rate 25 | */ 26 | carrier_account_id: string; 27 | 28 | /** 29 | * ID of the Shipment this rate belongs to 30 | */ 31 | shipment_id: string; 32 | 33 | /** 34 | * the actual rate quote for this service 35 | */ 36 | rate: string; 37 | 38 | /** 39 | * currency for the rate 40 | */ 41 | currency: string; 42 | 43 | /** 44 | * the retail rate is the in-store rate given with no account 45 | */ 46 | retail_rate: string; 47 | 48 | /** 49 | * currency for the retail rate 50 | */ 51 | retail_currency: string; 52 | 53 | /** 54 | * the list rate is the non-negotiated rate given for having an account with the carrier 55 | */ 56 | list_rate: string; 57 | 58 | /** 59 | * currency for the list rate 60 | */ 61 | list_currency: string; 62 | 63 | /** 64 | * delivery days for this service 65 | */ 66 | delivery_days: number; 67 | 68 | /** 69 | * date for delivery 70 | */ 71 | delivery_date: string; 72 | 73 | /** 74 | * indicates if delivery window is guaranteed (true) or not (false) 75 | */ 76 | delivery_date_guaranteed: boolean; 77 | } 78 | -------------------------------------------------------------------------------- /types/Shipment/ShipmentCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAddressCreateParameters } from '../Address'; 2 | import { ICustomsInfo } from '../Customs/CustomsInfo/CustomsInfo'; 3 | import { IParcelCreateParameters } from '../Parcel/ParcelCreateParameters'; 4 | import { DeepPartial } from '../utils'; 5 | import { IOptions } from './Options'; 6 | 7 | export declare interface IShipmentCreateParameters { 8 | reference?: string | null; 9 | to_address: DeepPartial | string; 10 | from_address: DeepPartial | string; 11 | parcel: Partial | string; 12 | 13 | /** 14 | * optional array of ids that begin with "ca_" 15 | */ 16 | carrier_accounts?: string[] | null; 17 | 18 | customs_info?: DeepPartial | null; 19 | options?: DeepPartial | null; 20 | } 21 | -------------------------------------------------------------------------------- /types/Shipment/ShipmentListParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAllMethodParameters } from '../utils'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/shipments#retrieve-all-shipments 5 | */ 6 | export declare interface IShipmentListParameters extends IAllMethodParameters { 7 | /** 8 | * Only include Shipments that have been purchased. 9 | * Default is true 10 | */ 11 | purchased?: boolean | null; 12 | 13 | /** 14 | * Also include Shipments created by Child Users. 15 | * Defaults to false 16 | */ 17 | include_children?: boolean | null; 18 | } 19 | -------------------------------------------------------------------------------- /types/Shipment/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Form'; 2 | export * from './Message'; 3 | export * from './Options'; 4 | export * from './PostageLabel'; 5 | export * from './Rate'; 6 | export * from './Shipment'; 7 | export * from './ShipmentCreateParameters'; 8 | export * from './ShipmentListParameters'; 9 | -------------------------------------------------------------------------------- /types/SmartRate/SmartRate.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The SmartRate class interacts with the SmartRate API to provide optimized shipping rates and estimates. 3 | * 4 | * @see https://docs.easypost.com/docs/smartrate 5 | */ 6 | export declare class SmartRate { 7 | /** 8 | * Retrieve the estimated delivery date of each carrier-service level combination via the Smart Deliver By API, based on a specific ship date and origin-destination postal code pair. 9 | * @param params - The parameters to estimate the delivery date with. 10 | * @returns {Object} - Estimates and related metadata. 11 | */ 12 | static estimateDeliveryDate(params: object): object; 13 | 14 | /** 15 | * Retrieve a recommended ship date for each carrier-service level combination via the Smart Deliver On API, based on a specific delivery date and origin-destination postal code pair. 16 | * @param params - The parameters to recommend the ship date with. 17 | * @returns {Object} - Recommendation and related metadata. 18 | */ 19 | static recommendShipDate(params: object): object; 20 | } 21 | -------------------------------------------------------------------------------- /types/Tracker/CarrierDetail.d.ts: -------------------------------------------------------------------------------- 1 | import { IBaseObject } from '../base'; 2 | import { ITrackingLocation } from './TrackingLocation'; 3 | 4 | /** 5 | * @see https://docs.easypost.com/docs/trackers#carrierdetail-object 6 | */ 7 | export declare interface ICarrierDetail extends IBaseObject<'CarrierDetail'> { 8 | /** 9 | * The service level the associated shipment was shipped with (if available) 10 | */ 11 | service: string; 12 | 13 | /** 14 | * The type of container the associated shipment was shipped in (if available) 15 | */ 16 | container_type: string; 17 | 18 | /** 19 | * The estimated delivery date as provided by the carrier, in the local time zone (if available) 20 | */ 21 | est_delivery_date_local: string; 22 | 23 | /** 24 | * The estimated delivery time as provided by the carrier, in the local time zone (if available) 25 | */ 26 | est_delivery_time_local: string; 27 | 28 | /** 29 | * The location from which the package originated, stringified for presentation (if available) 30 | */ 31 | origin_location: string; 32 | 33 | /** 34 | * The location from which the package originated, broken down by city/state/country/zip (if available) 35 | */ 36 | origin_tracking_location: ITrackingLocation; 37 | 38 | /** 39 | * The location to which the package is being sent, stringified for presentation (if available) 40 | */ 41 | destination_location: string; 42 | 43 | /** 44 | * The location to which the package is being sent, broken down by city/state/country/zip (if available) 45 | */ 46 | destination_tracking_location: ITrackingLocation; 47 | 48 | /** 49 | * The date and time the carrier guarantees the package to be delivered by (if available) 50 | */ 51 | guaranteed_delivery_date: string; 52 | 53 | /** 54 | * The alternate identifier for this package as provided by the carrier (if available) 55 | */ 56 | alternate_identifier: string; 57 | 58 | /** 59 | * The date and time of the first attempt by the carrier to deliver the package (if available) 60 | */ 61 | initial_delivery_attempt: string; 62 | } 63 | -------------------------------------------------------------------------------- /types/Tracker/TrackerCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | export declare interface ITrackerCreateParameters { 2 | /** 3 | * The tracking code associated with the package you'd like to track 4 | */ 5 | tracking_code: string; 6 | 7 | /** 8 | * The carrier associated with the tracking_code you provided. 9 | * The carrier will get auto-detected if none is provided 10 | */ 11 | carrier?: string; 12 | } 13 | -------------------------------------------------------------------------------- /types/Tracker/TrackerListParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAllMethodParameters } from '../utils'; 2 | 3 | export declare interface ITrackerListParameters extends IAllMethodParameters { 4 | /** 5 | * Only returns Trackers with the given tracking_code. 6 | * Useful for retrieving an individual Tracker by tracking_code rather than by ID 7 | */ 8 | tracking_code?: string | null; 9 | 10 | /** 11 | * Only returns Trackers with the given carrier value 12 | */ 13 | carrier?: string | null; 14 | } 15 | -------------------------------------------------------------------------------- /types/Tracker/TrackerStatus.d.ts: -------------------------------------------------------------------------------- 1 | export declare type ITrackerStatus = 2 | | 'unknown' 3 | | 'pre_transit' 4 | | 'in_transit' 5 | | 'out_for_delivery' 6 | | 'delivered' 7 | | 'available_for_pickup' 8 | | 'return_to_sender' 9 | | 'failure' 10 | | 'cancelled' 11 | | 'error'; 12 | -------------------------------------------------------------------------------- /types/Tracker/TrackerStatusDetail.d.ts: -------------------------------------------------------------------------------- 1 | export declare type ITrackerStatusDetail = 2 | | 'address_correction' 3 | | 'arrived_at_destination' 4 | | 'arrived_at_facility' 5 | | 'arrived_at_pickup_location' 6 | | 'awaiting_information' 7 | | 'cancelled' 8 | | 'damaged' 9 | | 'delayed' 10 | | 'delivery_exception' 11 | | 'departed_facility' 12 | | 'departed_origin_facility' 13 | | 'expired' 14 | | 'failure' 15 | | 'held' 16 | | 'in_transit' 17 | | 'label_created' 18 | | 'lost' 19 | | 'missorted' 20 | | 'out_for_delivery' 21 | | 'received_at_destination_facility' 22 | | 'received_at_origin_facility' 23 | | 'refused' 24 | | 'return' 25 | | 'status_update' 26 | | 'transferred_to_destination_carrier' 27 | | 'transit_exception' 28 | | 'unknown' 29 | | 'weather_delay'; 30 | -------------------------------------------------------------------------------- /types/Tracker/TrackingDetail.d.ts: -------------------------------------------------------------------------------- 1 | import { IBaseObject } from '../base'; 2 | import { ITrackerStatus } from './TrackerStatus'; 3 | import { ITrackingLocation } from './TrackingLocation'; 4 | 5 | /** 6 | * @see https://docs.easypost.com/docs/trackers#trackingdetail-object 7 | */ 8 | export declare interface ITrackingDetail extends IBaseObject<'TrackingDetail'> { 9 | /** 10 | * Description of the scan event 11 | */ 12 | message: string; 13 | 14 | description: string; 15 | 16 | /** 17 | * 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" 18 | */ 19 | status: ITrackerStatus; 20 | 21 | status_detail: string; 22 | 23 | /** 24 | * The timestamp when the tracking scan occurred 25 | */ 26 | datetime: string; 27 | 28 | /** 29 | * The original source of the information for this scan event, usually the carrier 30 | */ 31 | source: string; 32 | 33 | carrier_code: string; 34 | 35 | /** 36 | * The location associated with the scan event 37 | */ 38 | tracking_location: ITrackingLocation; 39 | } 40 | -------------------------------------------------------------------------------- /types/Tracker/TrackingLocation.d.ts: -------------------------------------------------------------------------------- 1 | import { IBaseObject } from '../base'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/trackers#trackinglocation-object 5 | */ 6 | export declare interface ITrackingLocation extends IBaseObject<'TrackingLocation'> { 7 | /** 8 | * The city where the scan event occurred (if available) 9 | */ 10 | city: string; 11 | 12 | /** 13 | * The state where the scan event occurred (if available) 14 | */ 15 | state: string; 16 | 17 | /** 18 | * The country where the scan event occurred (if available) 19 | */ 20 | country: string; 21 | 22 | /** 23 | * The postal code where the scan event occurred (if available) 24 | */ 25 | zip: string; 26 | } 27 | -------------------------------------------------------------------------------- /types/Tracker/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './CarrierDetail'; 2 | export * from './Tracker'; 3 | export * from './TrackerStatus'; 4 | export * from './TrackingDetail'; 5 | export * from './TrackingLocation'; 6 | export * from './TrackerCreateParameters'; 7 | export * from './TrackerListParameters'; 8 | -------------------------------------------------------------------------------- /types/User/UserCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { ParametersToOmitOnCreate } from '../utils'; 2 | import { IUser } from './User'; 3 | 4 | export declare interface IUserCreateParameters extends Omit {} 5 | -------------------------------------------------------------------------------- /types/User/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './User'; 2 | -------------------------------------------------------------------------------- /types/Utility/Utils.d.ts: -------------------------------------------------------------------------------- 1 | import { Rate } from '../Rate'; 2 | 3 | /** 4 | * The Utils class represents a number of helper methods for the client library. 5 | */ 6 | export declare class Utils { 7 | /** 8 | * Get the lowest SmartRate from a provided list of SmartRates. 9 | * @public 10 | * @param smartrates List of SmartRates to filter through 11 | * @param deliveryDays The maximum number of days allowed for delivery 12 | * @param deliveryAccuracy The target level of accuracy for the delivery days (e.g. 'percentile_95') 13 | * @returns The lowest SmartRate 14 | * @throws FilteringError If no applicable rates are found 15 | * @throws InvalidParameterError If the deliveryAccuracy value is invalid 16 | */ 17 | static getLowestSmartRate( 18 | smartrates: Rate[], 19 | deliveryDays: number, 20 | deliveryAccuracy: string, 21 | ): Rate; 22 | 23 | /** 24 | * Get the lowest rate from a provided list of rates. 25 | * @public 26 | * @param rates List of rates to filter through 27 | * @param carriers List of carriers to filter by 28 | * @param services List of services to filter by 29 | * @returns The lowest rate 30 | * @throws FilteringError If no applicable rates are found 31 | */ 32 | static getLowestRate(rates: Rate[], carriers?: string[], services?: string[]): Rate; 33 | 34 | /** 35 | * Validate a webhook by comparing the HMAC signature header sent from EasyPost to your shared secret. 36 | * If the signatures do not match, an error will be raised signifying the webhook either did not originate 37 | * from EasyPost or the secrets do not match. If the signatures do match, the `event_body` will be returned 38 | * as JSON. 39 | * @public 40 | * @param eventBody The raw body of the webhook event 41 | * @param headers The headers of the webhook HTTP request 42 | * @param webhookSecret The webhook secret shared between EasyPost and your application 43 | * @returns The JSON-parsed webhook event body if the signature could be verified 44 | * @throws SignatureVerificationError If the signature could not be verified 45 | */ 46 | static validateWebhook(eventBody: Buffer, headers: object, webhookSecret: string): object; 47 | } 48 | -------------------------------------------------------------------------------- /types/Utility/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Utils'; 2 | -------------------------------------------------------------------------------- /types/Webhook/WebhookCreateParameters.d.ts: -------------------------------------------------------------------------------- 1 | export declare interface IWebhookCreateParameters { 2 | url: string; 3 | webhook_secret?: string; 4 | custom_headers?: Array<{ key: string; value: string }>; 5 | } 6 | -------------------------------------------------------------------------------- /types/Webhook/WebhookListParameters.d.ts: -------------------------------------------------------------------------------- 1 | import { IAllMethodParameters } from '../utils'; 2 | 3 | /** 4 | * @see https://docs.easypost.com/docs/webhooks#retrieve-all-webhooks 5 | */ 6 | export declare interface IWebhookListParameters extends IAllMethodParameters {} 7 | -------------------------------------------------------------------------------- /types/Webhook/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Webhook'; 2 | export * from './WebhookCreateParameters'; 3 | -------------------------------------------------------------------------------- /types/base.d.ts: -------------------------------------------------------------------------------- 1 | export declare interface IDatedObject { 2 | /** 3 | * Date ISO String 4 | */ 5 | created_at: string; 6 | 7 | /** 8 | * Date ISO String 9 | */ 10 | updated_at: string; 11 | } 12 | 13 | export declare interface IBaseObject { 14 | object: ObjectName; 15 | } 16 | 17 | export declare interface IObjectWithId extends IBaseObject { 18 | /** 19 | * Unique identifier, begins with "adr_" / "prcl_" / "ins_" / "trk_" / "batch_" / "cstinfo_" / etc 20 | */ 21 | id: string; 22 | 23 | /** 24 | * Set based on which api-key you used, either "test" or "production" 25 | */ 26 | mode: 'test' | 'production'; 27 | 28 | /** 29 | * The object name, e.g. "Address", "Rate", "Shipment", etc 30 | */ 31 | object: ObjectName; 32 | } 33 | -------------------------------------------------------------------------------- /types/demo/README.md: -------------------------------------------------------------------------------- 1 | # Typescript Demo 2 | 3 | This is a simple project to demonstrate and test how to use the EasyPost Typescript definitions. 4 | -------------------------------------------------------------------------------- /types/demo/index.ts: -------------------------------------------------------------------------------- 1 | import EasyPostClient from '@easypost/api'; 2 | 3 | // This file is intended to demo how you could use the EasyPost Typescript definitions. 4 | (async () => { 5 | const client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); 6 | 7 | const customsInfo = await client.CustomsInfo.retrieve('cstinfo_...'); 8 | 9 | console.log(customsInfo); 10 | })(); 11 | -------------------------------------------------------------------------------- /types/demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "ts-node src/index.ts" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "@easypost/api": "file:../" 14 | }, 15 | "devDependencies": { 16 | "typescript": "4.6.3", 17 | "ts-node": "10.7.0" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /types/errors/Error.d.ts: -------------------------------------------------------------------------------- 1 | import { TErrorCode } from './ErrorCode'; 2 | import { IFieldError } from './FieldError'; 3 | 4 | /** 5 | * 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. 6 | * 7 | * Each client library will encapsulate these errors and raise an exception, in addition to other exceptional cases, such as network failures. 8 | * It is recommended to handle exceptions gracefully and to report any issues to support@easypost.com. 9 | * 10 | * @see https://docs.easypost.com/docs/errors 11 | */ 12 | export declare interface IError { 13 | /** 14 | * Machine readable description of the problem 15 | */ 16 | code: TErrorCode; 17 | 18 | /** 19 | * Human readable description of the problem 20 | */ 21 | message: string; 22 | 23 | /** 24 | * Breakdown of errors for specific fields in the request 25 | */ 26 | errors: IFieldError[]; 27 | } 28 | -------------------------------------------------------------------------------- /types/errors/FieldError.d.ts: -------------------------------------------------------------------------------- 1 | export declare interface IFieldError { 2 | /** 3 | * Field of the request that the error describes 4 | */ 5 | field: string; 6 | 7 | /** 8 | * Human readable description of the problem 9 | */ 10 | message: string; 11 | } 12 | -------------------------------------------------------------------------------- /types/errors/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Error'; 2 | export * from './ErrorCode'; 3 | export * from './FieldError'; 4 | -------------------------------------------------------------------------------- /types/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Address'; 2 | export * from './Batch'; 3 | export * from './Billing'; 4 | export * from './Brand'; 5 | export * from './Carrier'; 6 | export * from './Customs'; 7 | export * from './EndShipper'; 8 | export * from './errors'; 9 | export * from './Event'; 10 | export * from './Fee'; 11 | export * from './Insurance'; 12 | export * from './Order'; 13 | export * from './Parcel'; 14 | export * from './Parcel'; 15 | export * from './PaymentMethod'; 16 | export * from './Pickup'; 17 | export * from './Refund'; 18 | export * from './Report'; 19 | export * from './ScanForm'; 20 | export * from './Shipment'; 21 | export * from './Tracker'; 22 | export * from './User'; 23 | export * from './utils'; 24 | export * from './Utility'; 25 | export * from './Webhook'; 26 | export { IEasyPostOptions } from './EasyPost'; 27 | 28 | declare const EasyPostClient: typeof import('./EasyPost').default; 29 | export = EasyPostClient; 30 | export as namespace MainClient; 31 | 32 | declare module 'easypost' { 33 | export = EasyPostClient; 34 | } 35 | -------------------------------------------------------------------------------- /types/utils.d.ts: -------------------------------------------------------------------------------- 1 | export type DeepPartial = { 2 | [P in keyof T]?: DeepPartial; 3 | }; 4 | 5 | export type ParametersToOmitOnCreate = 'id' | 'object' | 'mode' | 'created_at' | 'updated_at'; 6 | 7 | export declare interface IAllMethodParameters { 8 | /** 9 | * Optional pagination parameter. 10 | * Only records created before the given ID will be included. 11 | * May not be used with after_id 12 | */ 13 | before_id?: string; 14 | 15 | /** 16 | * Optional pagination parameter. 17 | * Only records created after the given ID will be included. 18 | * May not be used with before_id 19 | */ 20 | after_id?: string; 21 | 22 | /** 23 | * Only return records created after this timestamp. 24 | * Defaults to 1 month ago, or 1 month before a passed end_datetime 25 | */ 26 | start_datetime?: string; 27 | 28 | /** 29 | * Only return records created before this timestamp. 30 | * Defaults to end of the current day, or 1 month after a passed start_datetime 31 | */ 32 | end_datetime?: string; 33 | 34 | /** 35 | * The number of records to return on each page. 36 | * The maximum value is 100 37 | */ 38 | page_size?: number; 39 | } 40 | -------------------------------------------------------------------------------- /vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | import path from 'path'; 3 | 4 | const mode = process.env.NODE_ENV || 'development'; 5 | const isDev = mode === 'development'; 6 | 7 | export default defineConfig({ 8 | build: { 9 | // node 12 is currently the oldest version of node we support. If we want to 10 | // drop node 12 support in the future, change this to the next min version 11 | target: 'node12', 12 | lib: { 13 | entry: path.resolve(__dirname, 'src/easypost.js'), 14 | fileName: 'easypost', 15 | formats: ['cjs', 'es'], 16 | }, 17 | sourcemap: isDev, 18 | rollupOptions: { 19 | external: [/^node:.*/, /^@?[a-zA-Z\-_]+\/?[a-zA-Z\-_]*$/], 20 | output: [ 21 | { 22 | format: 'cjs', 23 | entryFileNames: '[name].js', 24 | dir: 'dist', 25 | }, 26 | { 27 | format: 'esm', 28 | entryFileNames: '[name].mjs', 29 | dir: 'dist', 30 | }, 31 | ], 32 | }, 33 | }, 34 | 35 | resolve: { 36 | extensions: ['.js'], 37 | alias: { 38 | '@': path.resolve(__dirname, 'src'), 39 | }, 40 | }, 41 | 42 | mode, 43 | 44 | optimizeDeps: { 45 | exclude: [], 46 | }, 47 | }); 48 | -------------------------------------------------------------------------------- /vitest.config.js: -------------------------------------------------------------------------------- 1 | import dotenv from 'dotenv'; 2 | import { defineConfig } from 'vitest/config'; 3 | 4 | dotenv.config(); 5 | 6 | export default defineConfig({ 7 | test: { 8 | globals: true, 9 | environment: 'node', 10 | include: ['test/services/**/*.{js,ts}'], 11 | coverage: { 12 | provider: 'istanbul', 13 | reporter: ['lcov', 'html'], 14 | include: ['src/**/*.{js,ts}'], 15 | thresholds: { 16 | lines: 90, 17 | }, 18 | }, 19 | }, 20 | }); 21 | --------------------------------------------------------------------------------