From a4cc22924d559e0d70cfd8ddd11fd5da0192b113 Mon Sep 17 00:00:00 2001 From: Nate Harris Date: Fri, 12 Jul 2024 14:50:09 -0600 Subject: [PATCH] [feat] Add new SmartRate "recommend ship date", "estimate delivery date" functions (#457) - Add new `SmartRate` service - Add `Shipment.recommendShipDate`, `SmartRate.recommendShipDate`, and `SmartRate.estimateDeliveryDate` functions - Update/add unit tests, cassettes as needed - Update TypeScript types for new functions and class --- CHANGELOG.md | 1 + src/easypost.js | 2 + src/services/shipment_service.js | 28 +- src/services/smart_rate_service.js | 42 +++ .../recording.har | 312 ++++++++++++++++++ .../recording.har | 312 ++++++++++++++++++ .../recording.har | 312 ------------------ .../recording.har | 163 +++++++++ .../recording.har | 163 +++++++++ test/helpers/fixture.js | 6 +- test/services/shipment.test.js | 23 +- test/services/smart_rate.test.js | 57 ++++ types/Shipment/Shipment.d.ts | 10 +- types/SmartRate/SmartRate.d.ts | 20 ++ 14 files changed, 1131 insertions(+), 320 deletions(-) create mode 100644 src/services/smart_rate_service.js create mode 100644 test/cassettes/Shipment-Service_2987889512/retrieve-estimated-delivery-dates-for-each-of-the-Rates-of-a-shipment_2875126681/recording.har create mode 100644 test/cassettes/Shipment-Service_2987889512/retrieve-recommended-ship-dates-for-each-of-the-Rates-of-a-shipment_1470819408/recording.har delete mode 100644 test/cassettes/Shipment-Service_2987889512/retrieve-time-in-transit-data-for-each-of-the-Rates-of-a-shipment_2266090777/recording.har create mode 100644 test/cassettes/SmartRate-Service_1309568275/estimate-delivery-date_838626811/recording.har create mode 100644 test/cassettes/SmartRate-Service_1309568275/recommend-ship-date_3612228667/recording.har create mode 100644 test/services/smart_rate.test.js create mode 100644 types/SmartRate/SmartRate.d.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 6abb0e225..22a0302ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Next Release +- Adds new `Shipment.recommendShipDate`, `SmartRate.recommendShipDate`, and `SmartRate.estimateDeliveryDate` functions - Routes `UpsAccount`, `UpsMailInnovationsAccount`, and `UpsSurepostAccount` create/update requests to the new `/ups_oauth_registrations` endpoint - Starting `2024-08-05`, UPS accounts will require a new payload to register or update. See [UPS OAuth 2.0 Update](https://support.easypost.com/hc/en-us/articles/26635027512717-UPS-OAuth-2-0-Update) for more details diff --git a/src/easypost.js b/src/easypost.js index e41be459c..92ad27e8c 100644 --- a/src/easypost.js +++ b/src/easypost.js @@ -29,6 +29,7 @@ import RefundService from './services/refund_service'; import ReportService from './services/report_service'; import ScanFormService from './services/scan_form_service'; import ShipmentService from './services/shipment_service'; +import SmartRateService from './services/smart_rate_service'; import TrackerService from './services/tracker_service'; import UserService from './services/user_service'; import WebhookService from './services/webhook_service'; @@ -106,6 +107,7 @@ export const SERVICES = { Report: ReportService, ScanForm: ScanFormService, Shipment: ShipmentService, + SmartRate: SmartRateService, Tracker: TrackerService, User: UserService, Webhook: WebhookService, diff --git a/src/services/shipment_service.js b/src/services/shipment_service.js index 5dcecddd8..9d17cb5a9 100644 --- a/src/services/shipment_service.js +++ b/src/services/shipment_service.js @@ -238,9 +238,9 @@ export default (easypostClient) => } /** - * Retrieves the estimated delivery date of each Rate via SmartRate. - * @param {string} id - * @param {string} plannedShipDate + * Retrieve the estimated delivery date of each Rate via SmartRate. + * @param {string} id - The ID of the shipment to retrieve the estimated delivery date for. + * @param {string} plannedShipDate - The planned ship date of the shipment. * @returns {Array} - An array of the estimated delivery date and rates. */ static async retrieveEstimatedDeliveryDate(id, plannedShipDate) { @@ -258,4 +258,26 @@ export default (easypostClient) => return Promise.reject(e); } } + + /** + * Retrieve a recommended ship date for a {@link Shipment shipment} via the Precision Shipping API, based on a specific desired delivery date. + * @param id - The ID of the shipment to retrieve the recommended ship date for. + * @param desiredDeliveryDate - The desired delivery date for the shipment. + * @returns {Array} - An array of the recommended ship date and rates. + */ + static async recommendShipDate(id, desiredDeliveryDate) { + const url = `shipments/${id}/smartrate/precision_shipping`; + + const params = { + desired_delivery_date: desiredDeliveryDate, + }; + + try { + const response = await easypostClient._get(url, params); + + return this._convertToEasyPostObject(response.body.rates ?? [], params); + } catch (e) { + return Promise.reject(e); + } + } }; diff --git a/src/services/smart_rate_service.js b/src/services/smart_rate_service.js new file mode 100644 index 000000000..cbb7b1330 --- /dev/null +++ b/src/services/smart_rate_service.js @@ -0,0 +1,42 @@ +import baseService from './base_service'; + +export default (easypostClient) => + /** + * The SmartRateService class provides methods for interacting with EasyPost SmartRate APIs. + * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. + */ + class SmartRateService extends baseService(easypostClient) { + /** + * 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. + * @param params - The parameters to estimate the delivery date with. + * @returns {Object} - Estimates and related metadata. + */ + static async estimateDeliveryDate(params) { + const url = 'smartrate/deliver_by'; + + try { + const response = await easypostClient._post(url, params); + + return this._convertToEasyPostObject(response.body, params); + } catch (e) { + return Promise.reject(e); + } + } + + /** + * 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. + * @param params - The parameters to recommend the ship date with. + * @returns {Object} - Recommendation and related metadata. + */ + static async recommendShipDate(params) { + const url = 'smartrate/deliver_on'; + + try { + const response = await easypostClient._post(url, params); + + return this._convertToEasyPostObject(response.body, params); + } catch (e) { + return Promise.reject(e); + } + } + }; diff --git a/test/cassettes/Shipment-Service_2987889512/retrieve-estimated-delivery-dates-for-each-of-the-Rates-of-a-shipment_2875126681/recording.har b/test/cassettes/Shipment-Service_2987889512/retrieve-estimated-delivery-dates-for-each-of-the-Rates-of-a-shipment_2875126681/recording.har new file mode 100644 index 000000000..8fca18cfa --- /dev/null +++ b/test/cassettes/Shipment-Service_2987889512/retrieve-estimated-delivery-dates-for-each-of-the-Rates-of-a-shipment_2875126681/recording.har @@ -0,0 +1,312 @@ +{ + "log": { + "_recordingName": "Shipment Service/retrieve estimated delivery dates for each of the Rates of a shipment", + "creator": { + "comment": "persister:fs", + "name": "Polly.JS", + "version": "6.0.5" + }, + "entries": [ + { + "_id": "66a1452a15128dd58c4223dd020f429c", + "_order": 0, + "cache": {}, + "request": { + "bodySize": 451, + "cookies": [], + "headers": [ + { + "name": "accept-encoding", + "value": "gzip, deflate" + }, + { + "name": "accept", + "value": "application/json" + }, + { + "name": "content-type", + "value": "application/json" + }, + { + "name": "content-length", + "value": 451 + }, + { + "name": "host", + "value": "api.easypost.com" + } + ], + "headersSize": 390, + "httpVersion": "HTTP/1.1", + "method": "POST", + "postData": { + "mimeType": "application/json", + "params": [], + "text": "{\"shipment\":{\"from_address\":{\"name\":\"Jack Sparrow\",\"street1\":\"388 Townsend St\",\"street2\":\"Apt 20\",\"city\":\"San Francisco\",\"state\":\"CA\",\"zip\":\"94107\",\"country\":\"US\",\"email\":\"test@example.com\",\"phone\":\"5555555555\"},\"to_address\":{\"name\":\"Elizabeth Swan\",\"street1\":\"179 N Harbor Dr\",\"city\":\"Redondo Beach\",\"state\":\"CA\",\"zip\":\"90277\",\"country\":\"US\",\"email\":\"test@example.com\",\"phone\":\"5555555555\"},\"parcel\":{\"length\":10,\"width\":8,\"height\":4,\"weight\":15.4}}}" + }, + "queryString": [], + "url": "https://api.easypost.com/v2/shipments" + }, + "response": { + "bodySize": 1522, + "content": { + "encoding": "base64", + "mimeType": "application/json; charset=utf-8", + "size": 1522, + "text": "{\"created_at\":\"2024-07-11T20:59:01Z\",\"is_return\":false,\"messages\":[],\"mode\":\"test\",\"options\":{\"currency\":\"USD\",\"payment\":{\"type\":\"SENDER\"},\"date_advance\":0},\"reference\":null,\"status\":\"unknown\",\"tracking_code\":null,\"updated_at\":\"2024-07-11T20:59:01Z\",\"batch_id\":null,\"batch_status\":null,\"batch_message\":null,\"customs_info\":null,\"from_address\":{\"id\":\"adr_662e59803fc811efbbc4ac1f6bc53342\",\"object\":\"Address\",\"created_at\":\"2024-07-11T20:59:01+00:00\",\"updated_at\":\"2024-07-11T20:59:01+00:00\",\"name\":\"Jack Sparrow\",\"company\":null,\"street1\":\"388 Townsend St\",\"street2\":\"Apt 20\",\"city\":\"San Francisco\",\"state\":\"CA\",\"zip\":\"94107\",\"country\":\"US\",\"phone\":\"\",\"email\":\"\",\"mode\":\"test\",\"carrier_facility\":null,\"residential\":null,\"federal_tax_id\":null,\"state_tax_id\":null,\"verifications\":{}},\"insurance\":null,\"order_id\":null,\"parcel\":{\"id\":\"prcl_d8e767949225490a8185624cf907c59e\",\"object\":\"Parcel\",\"created_at\":\"2024-07-11T20:59:01Z\",\"updated_at\":\"2024-07-11T20:59:01Z\",\"length\":10,\"width\":8,\"height\":4,\"predefined_package\":null,\"weight\":15.4,\"mode\":\"test\"},\"postage_label\":null,\"rates\":[{\"id\":\"rate_ffd7f2887f2949fb88bec56ea069f876\",\"object\":\"Rate\",\"created_at\":\"2024-07-11T20:59:01Z\",\"updated_at\":\"2024-07-11T20:59:01Z\",\"mode\":\"test\",\"service\":\"Priority\",\"carrier\":\"USPS\",\"rate\":\"6.90\",\"currency\":\"USD\",\"retail_rate\":\"9.80\",\"retail_currency\":\"USD\",\"list_rate\":\"8.25\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":2,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":2,\"shipment_id\":\"shp_77e7f7745bb74ad08e831a16ebc6dc09\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"},{\"id\":\"rate_34a016a74d5e4971a11de5f3ec842975\",\"object\":\"Rate\",\"created_at\":\"2024-07-11T20:59:01Z\",\"updated_at\":\"2024-07-11T20:59:01Z\",\"mode\":\"test\",\"service\":\"GroundAdvantage\",\"carrier\":\"USPS\",\"rate\":\"5.93\",\"currency\":\"USD\",\"retail_rate\":\"8.45\",\"retail_currency\":\"USD\",\"list_rate\":\"6.40\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":3,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":3,\"shipment_id\":\"shp_77e7f7745bb74ad08e831a16ebc6dc09\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"},{\"id\":\"rate_a950183d94304f88bb0033eeb8818907\",\"object\":\"Rate\",\"created_at\":\"2024-07-11T20:59:01Z\",\"updated_at\":\"2024-07-11T20:59:01Z\",\"mode\":\"test\",\"service\":\"First\",\"carrier\":\"USPS\",\"rate\":\"5.93\",\"currency\":\"USD\",\"retail_rate\":\"8.45\",\"retail_currency\":\"USD\",\"list_rate\":\"6.40\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":3,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":3,\"shipment_id\":\"shp_77e7f7745bb74ad08e831a16ebc6dc09\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"},{\"id\":\"rate_9428976bbfde482eb18336516f4d63e8\",\"object\":\"Rate\",\"created_at\":\"2024-07-11T20:59:01Z\",\"updated_at\":\"2024-07-11T20:59:01Z\",\"mode\":\"test\",\"service\":\"ParcelSelect\",\"carrier\":\"USPS\",\"rate\":\"5.93\",\"currency\":\"USD\",\"retail_rate\":\"8.45\",\"retail_currency\":\"USD\",\"list_rate\":\"6.40\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":3,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":3,\"shipment_id\":\"shp_77e7f7745bb74ad08e831a16ebc6dc09\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"},{\"id\":\"rate_cc612db3f99843aabca9d57fb1936934\",\"object\":\"Rate\",\"created_at\":\"2024-07-11T20:59:01Z\",\"updated_at\":\"2024-07-11T20:59:01Z\",\"mode\":\"test\",\"service\":\"Express\",\"carrier\":\"USPS\",\"rate\":\"33.10\",\"currency\":\"USD\",\"retail_rate\":\"37.90\",\"retail_currency\":\"USD\",\"list_rate\":\"33.10\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":2,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":2,\"shipment_id\":\"shp_77e7f7745bb74ad08e831a16ebc6dc09\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"}],\"refund_status\":null,\"scan_form\":null,\"selected_rate\":null,\"tracker\":null,\"to_address\":{\"id\":\"adr_662af8d23fc811efadbaac1f6bc539aa\",\"object\":\"Address\",\"created_at\":\"2024-07-11T20:59:01+00:00\",\"updated_at\":\"2024-07-11T20:59:01+00:00\",\"name\":\"Elizabeth Swan\",\"company\":null,\"street1\":\"179 N Harbor Dr\",\"street2\":null,\"city\":\"Redondo Beach\",\"state\":\"CA\",\"zip\":\"90277\",\"country\":\"US\",\"phone\":\"\",\"email\":\"\",\"mode\":\"test\",\"carrier_facility\":null,\"residential\":null,\"federal_tax_id\":null,\"state_tax_id\":null,\"verifications\":{}},\"usps_zone\":4,\"return_address\":{\"id\":\"adr_662e59803fc811efbbc4ac1f6bc53342\",\"object\":\"Address\",\"created_at\":\"2024-07-11T20:59:01+00:00\",\"updated_at\":\"2024-07-11T20:59:01+00:00\",\"name\":\"Jack Sparrow\",\"company\":null,\"street1\":\"388 Townsend St\",\"street2\":\"Apt 20\",\"city\":\"San Francisco\",\"state\":\"CA\",\"zip\":\"94107\",\"country\":\"US\",\"phone\":\"\",\"email\":\"\",\"mode\":\"test\",\"carrier_facility\":null,\"residential\":null,\"federal_tax_id\":null,\"state_tax_id\":null,\"verifications\":{}},\"buyer_address\":{\"id\":\"adr_662af8d23fc811efadbaac1f6bc539aa\",\"object\":\"Address\",\"created_at\":\"2024-07-11T20:59:01+00:00\",\"updated_at\":\"2024-07-11T20:59:01+00:00\",\"name\":\"Elizabeth Swan\",\"company\":null,\"street1\":\"179 N Harbor Dr\",\"street2\":null,\"city\":\"Redondo Beach\",\"state\":\"CA\",\"zip\":\"90277\",\"country\":\"US\",\"phone\":\"\",\"email\":\"\",\"mode\":\"test\",\"carrier_facility\":null,\"residential\":null,\"federal_tax_id\":null,\"state_tax_id\":null,\"verifications\":{}},\"forms\":[],\"fees\":[],\"id\":\"shp_77e7f7745bb74ad08e831a16ebc6dc09\",\"object\":\"Shipment\"}" + }, + "cookies": [], + "headers": [ + { + "name": "x-frame-options", + "value": "SAMEORIGIN" + }, + { + "name": "x-xss-protection", + "value": "1; mode=block" + }, + { + "name": "x-content-type-options", + "value": "nosniff" + }, + { + "name": "x-download-options", + "value": "noopen" + }, + { + "name": "x-permitted-cross-domain-policies", + "value": "none" + }, + { + "name": "referrer-policy", + "value": "strict-origin-when-cross-origin" + }, + { + "name": "x-ep-request-uuid", + "value": "b8e53c2266904795f419db4a002ec08f" + }, + { + "name": "cache-control", + "value": "private, no-cache, no-store" + }, + { + "name": "pragma", + "value": "no-cache" + }, + { + "name": "expires", + "value": "0" + }, + { + "name": "location", + "value": "/api/v2/shipments/shp_77e7f7745bb74ad08e831a16ebc6dc09" + }, + { + "name": "content-type", + "value": "application/json; charset=utf-8" + }, + { + "name": "x-runtime", + "value": "0.476786" + }, + { + "name": "content-encoding", + "value": "gzip" + }, + { + "name": "transfer-encoding", + "value": "chunked" + }, + { + "name": "x-node", + "value": "bigweb40nuq" + }, + { + "name": "x-version-label", + "value": "easypost-202407111940-3cb16a3462-master" + }, + { + "name": "x-backend", + "value": "easypost" + }, + { + "name": "x-proxied", + "value": "intlb3nuq fa152d4755, extlb2nuq fa152d4755" + }, + { + "name": "strict-transport-security", + "value": "max-age=31536000; includeSubDomains; preload" + }, + { + "name": "connection", + "value": "close" + } + ], + "headersSize": 776, + "httpVersion": "HTTP/1.1", + "redirectURL": "/api/v2/shipments/shp_77e7f7745bb74ad08e831a16ebc6dc09", + "status": 201, + "statusText": "Created" + }, + "startedDateTime": "2024-07-11T20:59:00.759Z", + "time": 751, + "timings": { + "blocked": -1, + "connect": -1, + "dns": -1, + "receive": 0, + "send": 0, + "ssl": -1, + "wait": 751 + } + }, + { + "_id": "48a6709bfc67422d38691cdee502cce6", + "_order": 0, + "cache": {}, + "request": { + "bodySize": 0, + "cookies": [], + "headers": [ + { + "name": "accept-encoding", + "value": "gzip, deflate" + }, + { + "name": "accept", + "value": "application/json" + }, + { + "name": "content-type", + "value": "application/json" + }, + { + "name": "host", + "value": "api.easypost.com" + } + ], + "headersSize": 458, + "httpVersion": "HTTP/1.1", + "method": "GET", + "queryString": [ + { + "name": "planned_ship_date", + "value": "2024-07-14" + } + ], + "url": "https://api.easypost.com/v2/shipments/shp_77e7f7745bb74ad08e831a16ebc6dc09/smartrate/delivery_date?planned_ship_date=2024-07-14" + }, + "response": { + "bodySize": 840, + "content": { + "encoding": "base64", + "mimeType": "application/json; charset=utf-8", + "size": 840, + "text": "{\"rates\":[{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":1,\"percentile_75\":3,\"percentile_85\":3,\"percentile_90\":4,\"percentile_95\":4,\"percentile_97\":5,\"percentile_99\":8},\"easypost_estimated_delivery_date\":\"2024-07-15\",\"planned_ship_date\":\"2024-07-14\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-07-11T20:59:01Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":2,\"est_delivery_days\":2,\"id\":\"rate_ffd7f2887f2949fb88bec56ea069f876\",\"list_currency\":\"USD\",\"list_rate\":8.25,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":6.9,\"retail_currency\":\"USD\",\"retail_rate\":9.8,\"service\":\"Priority\",\"shipment_id\":\"shp_77e7f7745bb74ad08e831a16ebc6dc09\",\"updated_at\":\"2024-07-11T20:59:01Z\"}},{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":1,\"percentile_75\":2,\"percentile_85\":3,\"percentile_90\":4,\"percentile_95\":4,\"percentile_97\":5,\"percentile_99\":8},\"easypost_estimated_delivery_date\":\"2024-07-15\",\"planned_ship_date\":\"2024-07-14\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-07-11T20:59:01Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":3,\"est_delivery_days\":3,\"id\":\"rate_34a016a74d5e4971a11de5f3ec842975\",\"list_currency\":\"USD\",\"list_rate\":6.4,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":5.93,\"retail_currency\":\"USD\",\"retail_rate\":8.45,\"service\":\"GroundAdvantage\",\"shipment_id\":\"shp_77e7f7745bb74ad08e831a16ebc6dc09\",\"updated_at\":\"2024-07-11T20:59:01Z\"}},{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":1,\"percentile_75\":2,\"percentile_85\":3,\"percentile_90\":4,\"percentile_95\":4,\"percentile_97\":5,\"percentile_99\":8},\"easypost_estimated_delivery_date\":\"2024-07-15\",\"planned_ship_date\":\"2024-07-14\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-07-11T20:59:01Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":3,\"est_delivery_days\":3,\"id\":\"rate_a950183d94304f88bb0033eeb8818907\",\"list_currency\":\"USD\",\"list_rate\":6.4,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":5.93,\"retail_currency\":\"USD\",\"retail_rate\":8.45,\"service\":\"First\",\"shipment_id\":\"shp_77e7f7745bb74ad08e831a16ebc6dc09\",\"updated_at\":\"2024-07-11T20:59:01Z\"}},{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":1,\"percentile_75\":2,\"percentile_85\":3,\"percentile_90\":4,\"percentile_95\":4,\"percentile_97\":5,\"percentile_99\":8},\"easypost_estimated_delivery_date\":\"2024-07-15\",\"planned_ship_date\":\"2024-07-14\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-07-11T20:59:01Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":3,\"est_delivery_days\":3,\"id\":\"rate_9428976bbfde482eb18336516f4d63e8\",\"list_currency\":\"USD\",\"list_rate\":6.4,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":5.93,\"retail_currency\":\"USD\",\"retail_rate\":8.45,\"service\":\"ParcelSelect\",\"shipment_id\":\"shp_77e7f7745bb74ad08e831a16ebc6dc09\",\"updated_at\":\"2024-07-11T20:59:01Z\"}},{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":1,\"percentile_75\":2,\"percentile_85\":3,\"percentile_90\":4,\"percentile_95\":4,\"percentile_97\":5,\"percentile_99\":7},\"easypost_estimated_delivery_date\":\"2024-07-15\",\"planned_ship_date\":\"2024-07-14\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-07-11T20:59:01Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":2,\"est_delivery_days\":2,\"id\":\"rate_cc612db3f99843aabca9d57fb1936934\",\"list_currency\":\"USD\",\"list_rate\":33.1,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":33.1,\"retail_currency\":\"USD\",\"retail_rate\":37.9,\"service\":\"Express\",\"shipment_id\":\"shp_77e7f7745bb74ad08e831a16ebc6dc09\",\"updated_at\":\"2024-07-11T20:59:01Z\"}}]}" + }, + "cookies": [], + "headers": [ + { + "name": "x-frame-options", + "value": "SAMEORIGIN" + }, + { + "name": "x-xss-protection", + "value": "1; mode=block" + }, + { + "name": "x-content-type-options", + "value": "nosniff" + }, + { + "name": "x-download-options", + "value": "noopen" + }, + { + "name": "x-permitted-cross-domain-policies", + "value": "none" + }, + { + "name": "referrer-policy", + "value": "strict-origin-when-cross-origin" + }, + { + "name": "x-ep-request-uuid", + "value": "b8e53c2166904795f020ed1b002ec142" + }, + { + "name": "cache-control", + "value": "private, no-cache, no-store" + }, + { + "name": "pragma", + "value": "no-cache" + }, + { + "name": "expires", + "value": "0" + }, + { + "name": "content-type", + "value": "application/json; charset=utf-8" + }, + { + "name": "x-runtime", + "value": "0.239829" + }, + { + "name": "content-encoding", + "value": "gzip" + }, + { + "name": "transfer-encoding", + "value": "chunked" + }, + { + "name": "x-node", + "value": "bigweb40nuq" + }, + { + "name": "x-version-label", + "value": "easypost-202407111940-3cb16a3462-master" + }, + { + "name": "x-backend", + "value": "easypost" + }, + { + "name": "x-proxied", + "value": "intlb4nuq fa152d4755, extlb2nuq fa152d4755" + }, + { + "name": "strict-transport-security", + "value": "max-age=31536000; includeSubDomains; preload" + }, + { + "name": "connection", + "value": "close" + } + ], + "headersSize": 710, + "httpVersion": "HTTP/1.1", + "redirectURL": "", + "status": 200, + "statusText": "OK" + }, + "startedDateTime": "2024-07-11T20:59:01.517Z", + "time": 358, + "timings": { + "blocked": -1, + "connect": -1, + "dns": -1, + "receive": 0, + "send": 0, + "ssl": -1, + "wait": 358 + } + } + ], + "pages": [], + "version": "1.2" + } +} diff --git a/test/cassettes/Shipment-Service_2987889512/retrieve-recommended-ship-dates-for-each-of-the-Rates-of-a-shipment_1470819408/recording.har b/test/cassettes/Shipment-Service_2987889512/retrieve-recommended-ship-dates-for-each-of-the-Rates-of-a-shipment_1470819408/recording.har new file mode 100644 index 000000000..a90bb705a --- /dev/null +++ b/test/cassettes/Shipment-Service_2987889512/retrieve-recommended-ship-dates-for-each-of-the-Rates-of-a-shipment_1470819408/recording.har @@ -0,0 +1,312 @@ +{ + "log": { + "_recordingName": "Shipment Service/retrieve recommended ship dates for each of the Rates of a shipment", + "creator": { + "comment": "persister:fs", + "name": "Polly.JS", + "version": "6.0.5" + }, + "entries": [ + { + "_id": "66a1452a15128dd58c4223dd020f429c", + "_order": 0, + "cache": {}, + "request": { + "bodySize": 451, + "cookies": [], + "headers": [ + { + "name": "accept-encoding", + "value": "gzip, deflate" + }, + { + "name": "accept", + "value": "application/json" + }, + { + "name": "content-type", + "value": "application/json" + }, + { + "name": "content-length", + "value": 451 + }, + { + "name": "host", + "value": "api.easypost.com" + } + ], + "headersSize": 390, + "httpVersion": "HTTP/1.1", + "method": "POST", + "postData": { + "mimeType": "application/json", + "params": [], + "text": "{\"shipment\":{\"from_address\":{\"name\":\"Jack Sparrow\",\"street1\":\"388 Townsend St\",\"street2\":\"Apt 20\",\"city\":\"San Francisco\",\"state\":\"CA\",\"zip\":\"94107\",\"country\":\"US\",\"email\":\"test@example.com\",\"phone\":\"5555555555\"},\"to_address\":{\"name\":\"Elizabeth Swan\",\"street1\":\"179 N Harbor Dr\",\"city\":\"Redondo Beach\",\"state\":\"CA\",\"zip\":\"90277\",\"country\":\"US\",\"email\":\"test@example.com\",\"phone\":\"5555555555\"},\"parcel\":{\"length\":10,\"width\":8,\"height\":4,\"weight\":15.4}}}" + }, + "queryString": [], + "url": "https://api.easypost.com/v2/shipments" + }, + "response": { + "bodySize": 1530, + "content": { + "encoding": "base64", + "mimeType": "application/json; charset=utf-8", + "size": 1530, + "text": "{\"created_at\":\"2024-07-11T20:59:02Z\",\"is_return\":false,\"messages\":[],\"mode\":\"test\",\"options\":{\"currency\":\"USD\",\"payment\":{\"type\":\"SENDER\"},\"date_advance\":0},\"reference\":null,\"status\":\"unknown\",\"tracking_code\":null,\"updated_at\":\"2024-07-11T20:59:02Z\",\"batch_id\":null,\"batch_status\":null,\"batch_message\":null,\"customs_info\":null,\"from_address\":{\"id\":\"adr_66c4fdb03fc811efbbf9ac1f6bc53342\",\"object\":\"Address\",\"created_at\":\"2024-07-11T20:59:02+00:00\",\"updated_at\":\"2024-07-11T20:59:02+00:00\",\"name\":\"Jack Sparrow\",\"company\":null,\"street1\":\"388 Townsend St\",\"street2\":\"Apt 20\",\"city\":\"San Francisco\",\"state\":\"CA\",\"zip\":\"94107\",\"country\":\"US\",\"phone\":\"\",\"email\":\"\",\"mode\":\"test\",\"carrier_facility\":null,\"residential\":null,\"federal_tax_id\":null,\"state_tax_id\":null,\"verifications\":{}},\"insurance\":null,\"order_id\":null,\"parcel\":{\"id\":\"prcl_301f2439e4144dd1b97d0b9934653d13\",\"object\":\"Parcel\",\"created_at\":\"2024-07-11T20:59:02Z\",\"updated_at\":\"2024-07-11T20:59:02Z\",\"length\":10,\"width\":8,\"height\":4,\"predefined_package\":null,\"weight\":15.4,\"mode\":\"test\"},\"postage_label\":null,\"rates\":[{\"id\":\"rate_33b7565038424589a95858d1aba9e5ce\",\"object\":\"Rate\",\"created_at\":\"2024-07-11T20:59:02Z\",\"updated_at\":\"2024-07-11T20:59:02Z\",\"mode\":\"test\",\"service\":\"Priority\",\"carrier\":\"USPS\",\"rate\":\"6.90\",\"currency\":\"USD\",\"retail_rate\":\"9.80\",\"retail_currency\":\"USD\",\"list_rate\":\"8.25\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":2,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":2,\"shipment_id\":\"shp_a228b484015c44bc850cb0cdf6337ee3\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"},{\"id\":\"rate_3724f4f61bd14236ae3708c83dcf7e12\",\"object\":\"Rate\",\"created_at\":\"2024-07-11T20:59:02Z\",\"updated_at\":\"2024-07-11T20:59:02Z\",\"mode\":\"test\",\"service\":\"GroundAdvantage\",\"carrier\":\"USPS\",\"rate\":\"5.93\",\"currency\":\"USD\",\"retail_rate\":\"8.45\",\"retail_currency\":\"USD\",\"list_rate\":\"6.40\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":3,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":3,\"shipment_id\":\"shp_a228b484015c44bc850cb0cdf6337ee3\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"},{\"id\":\"rate_db412e02196d4c82a2058b33d4b65b38\",\"object\":\"Rate\",\"created_at\":\"2024-07-11T20:59:02Z\",\"updated_at\":\"2024-07-11T20:59:02Z\",\"mode\":\"test\",\"service\":\"First\",\"carrier\":\"USPS\",\"rate\":\"5.93\",\"currency\":\"USD\",\"retail_rate\":\"8.45\",\"retail_currency\":\"USD\",\"list_rate\":\"6.40\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":3,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":3,\"shipment_id\":\"shp_a228b484015c44bc850cb0cdf6337ee3\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"},{\"id\":\"rate_6913beda490b42e294f473a4f34e863b\",\"object\":\"Rate\",\"created_at\":\"2024-07-11T20:59:02Z\",\"updated_at\":\"2024-07-11T20:59:02Z\",\"mode\":\"test\",\"service\":\"ParcelSelect\",\"carrier\":\"USPS\",\"rate\":\"5.93\",\"currency\":\"USD\",\"retail_rate\":\"8.45\",\"retail_currency\":\"USD\",\"list_rate\":\"6.40\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":3,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":3,\"shipment_id\":\"shp_a228b484015c44bc850cb0cdf6337ee3\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"},{\"id\":\"rate_05e354d43a6c4cc29d517145bceac76a\",\"object\":\"Rate\",\"created_at\":\"2024-07-11T20:59:02Z\",\"updated_at\":\"2024-07-11T20:59:02Z\",\"mode\":\"test\",\"service\":\"Express\",\"carrier\":\"USPS\",\"rate\":\"33.10\",\"currency\":\"USD\",\"retail_rate\":\"37.90\",\"retail_currency\":\"USD\",\"list_rate\":\"33.10\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":2,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":2,\"shipment_id\":\"shp_a228b484015c44bc850cb0cdf6337ee3\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"}],\"refund_status\":null,\"scan_form\":null,\"selected_rate\":null,\"tracker\":null,\"to_address\":{\"id\":\"adr_66c1f6f43fc811efa6dc3cecef1b359e\",\"object\":\"Address\",\"created_at\":\"2024-07-11T20:59:02+00:00\",\"updated_at\":\"2024-07-11T20:59:02+00:00\",\"name\":\"Elizabeth Swan\",\"company\":null,\"street1\":\"179 N Harbor Dr\",\"street2\":null,\"city\":\"Redondo Beach\",\"state\":\"CA\",\"zip\":\"90277\",\"country\":\"US\",\"phone\":\"\",\"email\":\"\",\"mode\":\"test\",\"carrier_facility\":null,\"residential\":null,\"federal_tax_id\":null,\"state_tax_id\":null,\"verifications\":{}},\"usps_zone\":4,\"return_address\":{\"id\":\"adr_66c4fdb03fc811efbbf9ac1f6bc53342\",\"object\":\"Address\",\"created_at\":\"2024-07-11T20:59:02+00:00\",\"updated_at\":\"2024-07-11T20:59:02+00:00\",\"name\":\"Jack Sparrow\",\"company\":null,\"street1\":\"388 Townsend St\",\"street2\":\"Apt 20\",\"city\":\"San Francisco\",\"state\":\"CA\",\"zip\":\"94107\",\"country\":\"US\",\"phone\":\"\",\"email\":\"\",\"mode\":\"test\",\"carrier_facility\":null,\"residential\":null,\"federal_tax_id\":null,\"state_tax_id\":null,\"verifications\":{}},\"buyer_address\":{\"id\":\"adr_66c1f6f43fc811efa6dc3cecef1b359e\",\"object\":\"Address\",\"created_at\":\"2024-07-11T20:59:02+00:00\",\"updated_at\":\"2024-07-11T20:59:02+00:00\",\"name\":\"Elizabeth Swan\",\"company\":null,\"street1\":\"179 N Harbor Dr\",\"street2\":null,\"city\":\"Redondo Beach\",\"state\":\"CA\",\"zip\":\"90277\",\"country\":\"US\",\"phone\":\"\",\"email\":\"\",\"mode\":\"test\",\"carrier_facility\":null,\"residential\":null,\"federal_tax_id\":null,\"state_tax_id\":null,\"verifications\":{}},\"forms\":[],\"fees\":[],\"id\":\"shp_a228b484015c44bc850cb0cdf6337ee3\",\"object\":\"Shipment\"}" + }, + "cookies": [], + "headers": [ + { + "name": "x-frame-options", + "value": "SAMEORIGIN" + }, + { + "name": "x-xss-protection", + "value": "1; mode=block" + }, + { + "name": "x-content-type-options", + "value": "nosniff" + }, + { + "name": "x-download-options", + "value": "noopen" + }, + { + "name": "x-permitted-cross-domain-policies", + "value": "none" + }, + { + "name": "referrer-policy", + "value": "strict-origin-when-cross-origin" + }, + { + "name": "x-ep-request-uuid", + "value": "b8e53c2366904796f3f857af002ec195" + }, + { + "name": "cache-control", + "value": "private, no-cache, no-store" + }, + { + "name": "pragma", + "value": "no-cache" + }, + { + "name": "expires", + "value": "0" + }, + { + "name": "location", + "value": "/api/v2/shipments/shp_a228b484015c44bc850cb0cdf6337ee3" + }, + { + "name": "content-type", + "value": "application/json; charset=utf-8" + }, + { + "name": "x-runtime", + "value": "0.371167" + }, + { + "name": "content-encoding", + "value": "gzip" + }, + { + "name": "transfer-encoding", + "value": "chunked" + }, + { + "name": "x-node", + "value": "bigweb36nuq" + }, + { + "name": "x-version-label", + "value": "easypost-202407111940-3cb16a3462-master" + }, + { + "name": "x-backend", + "value": "easypost" + }, + { + "name": "x-proxied", + "value": "intlb3nuq fa152d4755, extlb2nuq fa152d4755" + }, + { + "name": "strict-transport-security", + "value": "max-age=31536000; includeSubDomains; preload" + }, + { + "name": "connection", + "value": "close" + } + ], + "headersSize": 776, + "httpVersion": "HTTP/1.1", + "redirectURL": "/api/v2/shipments/shp_a228b484015c44bc850cb0cdf6337ee3", + "status": 201, + "statusText": "Created" + }, + "startedDateTime": "2024-07-11T20:59:01.893Z", + "time": 500, + "timings": { + "blocked": -1, + "connect": -1, + "dns": -1, + "receive": 0, + "send": 0, + "ssl": -1, + "wait": 500 + } + }, + { + "_id": "bac6213f0ae4e3d5246419803bf85e1b", + "_order": 0, + "cache": {}, + "request": { + "bodySize": 0, + "cookies": [], + "headers": [ + { + "name": "accept-encoding", + "value": "gzip, deflate" + }, + { + "name": "accept", + "value": "application/json" + }, + { + "name": "content-type", + "value": "application/json" + }, + { + "name": "host", + "value": "api.easypost.com" + } + ], + "headersSize": 467, + "httpVersion": "HTTP/1.1", + "method": "GET", + "queryString": [ + { + "name": "desired_delivery_date", + "value": "2024-07-14" + } + ], + "url": "https://api.easypost.com/v2/shipments/shp_a228b484015c44bc850cb0cdf6337ee3/smartrate/precision_shipping?desired_delivery_date=2024-07-14" + }, + "response": { + "bodySize": 876, + "content": { + "encoding": "base64", + "mimeType": "application/json; charset=utf-8", + "size": 876, + "text": "{\"rates\":[{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":4,\"percentile_75\":4,\"percentile_85\":4,\"percentile_90\":4,\"percentile_95\":5,\"percentile_97\":5,\"percentile_99\":7},\"delivery_date_confidence\":0,\"desired_delivery_date\":\"2024-07-14\",\"estimated_transit_days\":3,\"ship_on_date\":\"2024-07-11\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-07-11T20:59:02Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":2,\"est_delivery_days\":2,\"id\":\"rate_33b7565038424589a95858d1aba9e5ce\",\"list_currency\":\"USD\",\"list_rate\":8.25,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":6.9,\"retail_currency\":\"USD\",\"retail_rate\":9.8,\"service\":\"Priority\",\"shipment_id\":\"shp_a228b484015c44bc850cb0cdf6337ee3\",\"updated_at\":\"2024-07-11T20:59:02Z\"}},{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":4,\"percentile_75\":4,\"percentile_85\":4,\"percentile_90\":4,\"percentile_95\":5,\"percentile_97\":5,\"percentile_99\":8},\"delivery_date_confidence\":0,\"desired_delivery_date\":\"2024-07-14\",\"estimated_transit_days\":3,\"ship_on_date\":\"2024-07-11\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-07-11T20:59:02Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":3,\"est_delivery_days\":3,\"id\":\"rate_3724f4f61bd14236ae3708c83dcf7e12\",\"list_currency\":\"USD\",\"list_rate\":6.4,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":5.93,\"retail_currency\":\"USD\",\"retail_rate\":8.45,\"service\":\"GroundAdvantage\",\"shipment_id\":\"shp_a228b484015c44bc850cb0cdf6337ee3\",\"updated_at\":\"2024-07-11T20:59:02Z\"}},{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":4,\"percentile_75\":4,\"percentile_85\":4,\"percentile_90\":4,\"percentile_95\":5,\"percentile_97\":5,\"percentile_99\":8},\"delivery_date_confidence\":0,\"desired_delivery_date\":\"2024-07-14\",\"estimated_transit_days\":3,\"ship_on_date\":\"2024-07-11\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-07-11T20:59:02Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":3,\"est_delivery_days\":3,\"id\":\"rate_db412e02196d4c82a2058b33d4b65b38\",\"list_currency\":\"USD\",\"list_rate\":6.4,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":5.93,\"retail_currency\":\"USD\",\"retail_rate\":8.45,\"service\":\"First\",\"shipment_id\":\"shp_a228b484015c44bc850cb0cdf6337ee3\",\"updated_at\":\"2024-07-11T20:59:02Z\"}},{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":4,\"percentile_75\":4,\"percentile_85\":4,\"percentile_90\":4,\"percentile_95\":5,\"percentile_97\":5,\"percentile_99\":8},\"delivery_date_confidence\":0,\"desired_delivery_date\":\"2024-07-14\",\"estimated_transit_days\":3,\"ship_on_date\":\"2024-07-11\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-07-11T20:59:02Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":3,\"est_delivery_days\":3,\"id\":\"rate_6913beda490b42e294f473a4f34e863b\",\"list_currency\":\"USD\",\"list_rate\":6.4,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":5.93,\"retail_currency\":\"USD\",\"retail_rate\":8.45,\"service\":\"ParcelSelect\",\"shipment_id\":\"shp_a228b484015c44bc850cb0cdf6337ee3\",\"updated_at\":\"2024-07-11T20:59:02Z\"}},{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":2,\"percentile_75\":3,\"percentile_85\":4,\"percentile_90\":4,\"percentile_95\":5,\"percentile_97\":5,\"percentile_99\":7},\"delivery_date_confidence\":0.02,\"desired_delivery_date\":\"2024-07-14\",\"estimated_transit_days\":1,\"ship_on_date\":\"2024-07-13\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-07-11T20:59:02Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":2,\"est_delivery_days\":2,\"id\":\"rate_05e354d43a6c4cc29d517145bceac76a\",\"list_currency\":\"USD\",\"list_rate\":33.1,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":33.1,\"retail_currency\":\"USD\",\"retail_rate\":37.9,\"service\":\"Express\",\"shipment_id\":\"shp_a228b484015c44bc850cb0cdf6337ee3\",\"updated_at\":\"2024-07-11T20:59:02Z\"}}]}" + }, + "cookies": [], + "headers": [ + { + "name": "x-frame-options", + "value": "SAMEORIGIN" + }, + { + "name": "x-xss-protection", + "value": "1; mode=block" + }, + { + "name": "x-content-type-options", + "value": "nosniff" + }, + { + "name": "x-download-options", + "value": "noopen" + }, + { + "name": "x-permitted-cross-domain-policies", + "value": "none" + }, + { + "name": "referrer-policy", + "value": "strict-origin-when-cross-origin" + }, + { + "name": "x-ep-request-uuid", + "value": "39ae9bfd66904796f3f621ea003089ef" + }, + { + "name": "cache-control", + "value": "private, no-cache, no-store" + }, + { + "name": "pragma", + "value": "no-cache" + }, + { + "name": "expires", + "value": "0" + }, + { + "name": "content-type", + "value": "application/json; charset=utf-8" + }, + { + "name": "x-runtime", + "value": "0.127551" + }, + { + "name": "content-encoding", + "value": "gzip" + }, + { + "name": "transfer-encoding", + "value": "chunked" + }, + { + "name": "x-node", + "value": "bigweb36nuq" + }, + { + "name": "x-version-label", + "value": "easypost-202407111940-3cb16a3462-master" + }, + { + "name": "x-backend", + "value": "easypost" + }, + { + "name": "x-proxied", + "value": "intlb3nuq fa152d4755, extlb1nuq fa152d4755" + }, + { + "name": "strict-transport-security", + "value": "max-age=31536000; includeSubDomains; preload" + }, + { + "name": "connection", + "value": "close" + } + ], + "headersSize": 710, + "httpVersion": "HTTP/1.1", + "redirectURL": "", + "status": 200, + "statusText": "OK" + }, + "startedDateTime": "2024-07-11T20:59:02.399Z", + "time": 258, + "timings": { + "blocked": -1, + "connect": -1, + "dns": -1, + "receive": 0, + "send": 0, + "ssl": -1, + "wait": 258 + } + } + ], + "pages": [], + "version": "1.2" + } +} diff --git a/test/cassettes/Shipment-Service_2987889512/retrieve-time-in-transit-data-for-each-of-the-Rates-of-a-shipment_2266090777/recording.har b/test/cassettes/Shipment-Service_2987889512/retrieve-time-in-transit-data-for-each-of-the-Rates-of-a-shipment_2266090777/recording.har deleted file mode 100644 index 69b2ead5b..000000000 --- a/test/cassettes/Shipment-Service_2987889512/retrieve-time-in-transit-data-for-each-of-the-Rates-of-a-shipment_2266090777/recording.har +++ /dev/null @@ -1,312 +0,0 @@ -{ - "log": { - "_recordingName": "Shipment Service/retrieve time-in-transit data for each of the Rates of a shipment", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "6.0.5" - }, - "entries": [ - { - "_id": "66a1452a15128dd58c4223dd020f429c", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 451, - "cookies": [], - "headers": [ - { - "name": "accept-encoding", - "value": "gzip, deflate" - }, - { - "name": "accept", - "value": "application/json" - }, - { - "name": "content-type", - "value": "application/json" - }, - { - "name": "content-length", - "value": 451 - }, - { - "name": "host", - "value": "api.easypost.com" - } - ], - "headersSize": 390, - "httpVersion": "HTTP/1.1", - "method": "POST", - "postData": { - "mimeType": "application/json", - "params": [], - "text": "{\"shipment\":{\"from_address\":{\"name\":\"Jack Sparrow\",\"street1\":\"388 Townsend St\",\"street2\":\"Apt 20\",\"city\":\"San Francisco\",\"state\":\"CA\",\"zip\":\"94107\",\"country\":\"US\",\"email\":\"test@example.com\",\"phone\":\"5555555555\"},\"to_address\":{\"name\":\"Elizabeth Swan\",\"street1\":\"179 N Harbor Dr\",\"city\":\"Redondo Beach\",\"state\":\"CA\",\"zip\":\"90277\",\"country\":\"US\",\"email\":\"test@example.com\",\"phone\":\"5555555555\"},\"parcel\":{\"length\":10,\"width\":8,\"height\":4,\"weight\":15.4}}}" - }, - "queryString": [], - "url": "https://api.easypost.com/v2/shipments" - }, - "response": { - "bodySize": 1531, - "content": { - "encoding": "base64", - "mimeType": "application/json; charset=utf-8", - "size": 1531, - "text": "{\"created_at\":\"2024-04-05T20:06:47Z\",\"is_return\":false,\"messages\":[],\"mode\":\"test\",\"options\":{\"currency\":\"USD\",\"payment\":{\"type\":\"SENDER\"},\"date_advance\":0},\"reference\":null,\"status\":\"unknown\",\"tracking_code\":null,\"updated_at\":\"2024-04-05T20:06:47Z\",\"batch_id\":null,\"batch_status\":null,\"batch_message\":null,\"customs_info\":null,\"from_address\":{\"id\":\"adr_081ca2c8f38811ee860fac1f6bc53342\",\"object\":\"Address\",\"created_at\":\"2024-04-05T20:06:47+00:00\",\"updated_at\":\"2024-04-05T20:06:47+00:00\",\"name\":\"Jack Sparrow\",\"company\":null,\"street1\":\"388 Townsend St\",\"street2\":\"Apt 20\",\"city\":\"San Francisco\",\"state\":\"CA\",\"zip\":\"94107\",\"country\":\"US\",\"phone\":\"\",\"email\":\"\",\"mode\":\"test\",\"carrier_facility\":null,\"residential\":null,\"federal_tax_id\":null,\"state_tax_id\":null,\"verifications\":{}},\"insurance\":null,\"order_id\":null,\"parcel\":{\"id\":\"prcl_1b4bea4ffa344d4884469122dab9c546\",\"object\":\"Parcel\",\"created_at\":\"2024-04-05T20:06:47Z\",\"updated_at\":\"2024-04-05T20:06:47Z\",\"length\":10,\"width\":8,\"height\":4,\"predefined_package\":null,\"weight\":15.4,\"mode\":\"test\"},\"postage_label\":null,\"rates\":[{\"id\":\"rate_85b31174b62f4aaca33a333e55a9e407\",\"object\":\"Rate\",\"created_at\":\"2024-04-05T20:06:47Z\",\"updated_at\":\"2024-04-05T20:06:47Z\",\"mode\":\"test\",\"service\":\"GroundAdvantage\",\"carrier\":\"USPS\",\"rate\":\"5.93\",\"currency\":\"USD\",\"retail_rate\":\"8.45\",\"retail_currency\":\"USD\",\"list_rate\":\"6.40\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":3,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":3,\"shipment_id\":\"shp_0e82027eba114d43b5ab061d9f417f96\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"},{\"id\":\"rate_5789e371ff5143648153a02413dda976\",\"object\":\"Rate\",\"created_at\":\"2024-04-05T20:06:47Z\",\"updated_at\":\"2024-04-05T20:06:47Z\",\"mode\":\"test\",\"service\":\"First\",\"carrier\":\"USPS\",\"rate\":\"5.93\",\"currency\":\"USD\",\"retail_rate\":\"8.45\",\"retail_currency\":\"USD\",\"list_rate\":\"6.40\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":3,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":3,\"shipment_id\":\"shp_0e82027eba114d43b5ab061d9f417f96\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"},{\"id\":\"rate_58b4db339c9d41ed85523eabb0378c7e\",\"object\":\"Rate\",\"created_at\":\"2024-04-05T20:06:47Z\",\"updated_at\":\"2024-04-05T20:06:47Z\",\"mode\":\"test\",\"service\":\"ParcelSelect\",\"carrier\":\"USPS\",\"rate\":\"5.93\",\"currency\":\"USD\",\"retail_rate\":\"8.45\",\"retail_currency\":\"USD\",\"list_rate\":\"6.40\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":3,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":3,\"shipment_id\":\"shp_0e82027eba114d43b5ab061d9f417f96\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"},{\"id\":\"rate_832e1c6412ba4774946f5b35b916ff0d\",\"object\":\"Rate\",\"created_at\":\"2024-04-05T20:06:47Z\",\"updated_at\":\"2024-04-05T20:06:47Z\",\"mode\":\"test\",\"service\":\"Express\",\"carrier\":\"USPS\",\"rate\":\"33.10\",\"currency\":\"USD\",\"retail_rate\":\"37.90\",\"retail_currency\":\"USD\",\"list_rate\":\"33.10\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":null,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":null,\"shipment_id\":\"shp_0e82027eba114d43b5ab061d9f417f96\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"},{\"id\":\"rate_de72bb4806c342018606ad01e93197a6\",\"object\":\"Rate\",\"created_at\":\"2024-04-05T20:06:47Z\",\"updated_at\":\"2024-04-05T20:06:47Z\",\"mode\":\"test\",\"service\":\"Priority\",\"carrier\":\"USPS\",\"rate\":\"6.88\",\"currency\":\"USD\",\"retail_rate\":\"9.80\",\"retail_currency\":\"USD\",\"list_rate\":\"8.25\",\"list_currency\":\"USD\",\"billing_type\":\"easypost\",\"delivery_days\":2,\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"est_delivery_days\":2,\"shipment_id\":\"shp_0e82027eba114d43b5ab061d9f417f96\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\"}],\"refund_status\":null,\"scan_form\":null,\"selected_rate\":null,\"tracker\":null,\"to_address\":{\"id\":\"adr_0819def3f38811eea675ac1f6bc539ae\",\"object\":\"Address\",\"created_at\":\"2024-04-05T20:06:47+00:00\",\"updated_at\":\"2024-04-05T20:06:47+00:00\",\"name\":\"Elizabeth Swan\",\"company\":null,\"street1\":\"179 N Harbor Dr\",\"street2\":null,\"city\":\"Redondo Beach\",\"state\":\"CA\",\"zip\":\"90277\",\"country\":\"US\",\"phone\":\"\",\"email\":\"\",\"mode\":\"test\",\"carrier_facility\":null,\"residential\":null,\"federal_tax_id\":null,\"state_tax_id\":null,\"verifications\":{}},\"usps_zone\":4,\"return_address\":{\"id\":\"adr_081ca2c8f38811ee860fac1f6bc53342\",\"object\":\"Address\",\"created_at\":\"2024-04-05T20:06:47+00:00\",\"updated_at\":\"2024-04-05T20:06:47+00:00\",\"name\":\"Jack Sparrow\",\"company\":null,\"street1\":\"388 Townsend St\",\"street2\":\"Apt 20\",\"city\":\"San Francisco\",\"state\":\"CA\",\"zip\":\"94107\",\"country\":\"US\",\"phone\":\"\",\"email\":\"\",\"mode\":\"test\",\"carrier_facility\":null,\"residential\":null,\"federal_tax_id\":null,\"state_tax_id\":null,\"verifications\":{}},\"buyer_address\":{\"id\":\"adr_0819def3f38811eea675ac1f6bc539ae\",\"object\":\"Address\",\"created_at\":\"2024-04-05T20:06:47+00:00\",\"updated_at\":\"2024-04-05T20:06:47+00:00\",\"name\":\"Elizabeth Swan\",\"company\":null,\"street1\":\"179 N Harbor Dr\",\"street2\":null,\"city\":\"Redondo Beach\",\"state\":\"CA\",\"zip\":\"90277\",\"country\":\"US\",\"phone\":\"\",\"email\":\"\",\"mode\":\"test\",\"carrier_facility\":null,\"residential\":null,\"federal_tax_id\":null,\"state_tax_id\":null,\"verifications\":{}},\"forms\":[],\"fees\":[],\"id\":\"shp_0e82027eba114d43b5ab061d9f417f96\",\"object\":\"Shipment\"}" - }, - "cookies": [], - "headers": [ - { - "name": "x-frame-options", - "value": "SAMEORIGIN" - }, - { - "name": "x-xss-protection", - "value": "1; mode=block" - }, - { - "name": "x-content-type-options", - "value": "nosniff" - }, - { - "name": "x-download-options", - "value": "noopen" - }, - { - "name": "x-permitted-cross-domain-policies", - "value": "none" - }, - { - "name": "referrer-policy", - "value": "strict-origin-when-cross-origin" - }, - { - "name": "x-ep-request-uuid", - "value": "1f0ae7a0661059d7f440cef80019e48d" - }, - { - "name": "cache-control", - "value": "private, no-cache, no-store" - }, - { - "name": "pragma", - "value": "no-cache" - }, - { - "name": "expires", - "value": "0" - }, - { - "name": "location", - "value": "/api/v2/shipments/shp_0e82027eba114d43b5ab061d9f417f96" - }, - { - "name": "content-type", - "value": "application/json; charset=utf-8" - }, - { - "name": "x-runtime", - "value": "0.312853" - }, - { - "name": "content-encoding", - "value": "gzip" - }, - { - "name": "transfer-encoding", - "value": "chunked" - }, - { - "name": "x-node", - "value": "bigweb34nuq" - }, - { - "name": "x-version-label", - "value": "easypost-202404051854-b9502cad97-master" - }, - { - "name": "x-backend", - "value": "easypost" - }, - { - "name": "x-proxied", - "value": "intlb3nuq 39c21b8207, extlb2nuq 60566a9ec2" - }, - { - "name": "strict-transport-security", - "value": "max-age=31536000; includeSubDomains; preload" - }, - { - "name": "connection", - "value": "close" - } - ], - "headersSize": 776, - "httpVersion": "HTTP/1.1", - "redirectURL": "/api/v2/shipments/shp_0e82027eba114d43b5ab061d9f417f96", - "status": 201, - "statusText": "Created" - }, - "startedDateTime": "2024-04-05T20:06:46.901Z", - "time": 449, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 449 - } - }, - { - "_id": "bf07f69d70042730263153cc93810c56", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "accept-encoding", - "value": "gzip, deflate" - }, - { - "name": "accept", - "value": "application/json" - }, - { - "name": "content-type", - "value": "application/json" - }, - { - "name": "host", - "value": "api.easypost.com" - } - ], - "headersSize": 458, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [ - { - "name": "planned_ship_date", - "value": "2024-04-08" - } - ], - "url": "https://api.easypost.com/v2/shipments/shp_0e82027eba114d43b5ab061d9f417f96/smartrate/delivery_date?planned_ship_date=2024-04-08" - }, - "response": { - "bodySize": 872, - "content": { - "encoding": "base64", - "mimeType": "application/json; charset=utf-8", - "size": 872, - "text": "{\"rates\":[{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":3,\"percentile_75\":3,\"percentile_85\":3,\"percentile_90\":4,\"percentile_95\":4,\"percentile_97\":5,\"percentile_99\":8},\"easypost_estimated_delivery_date\":\"2024-04-11\",\"planned_ship_date\":\"2024-04-08\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-04-05T20:06:47Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":3,\"est_delivery_days\":3,\"id\":\"rate_85b31174b62f4aaca33a333e55a9e407\",\"list_currency\":\"USD\",\"list_rate\":6.4,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":5.93,\"retail_currency\":\"USD\",\"retail_rate\":8.45,\"service\":\"GroundAdvantage\",\"shipment_id\":\"shp_0e82027eba114d43b5ab061d9f417f96\",\"updated_at\":\"2024-04-05T20:06:47Z\"}},{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":3,\"percentile_75\":3,\"percentile_85\":3,\"percentile_90\":4,\"percentile_95\":4,\"percentile_97\":5,\"percentile_99\":8},\"easypost_estimated_delivery_date\":\"2024-04-11\",\"planned_ship_date\":\"2024-04-08\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-04-05T20:06:47Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":3,\"est_delivery_days\":3,\"id\":\"rate_5789e371ff5143648153a02413dda976\",\"list_currency\":\"USD\",\"list_rate\":6.4,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":5.93,\"retail_currency\":\"USD\",\"retail_rate\":8.45,\"service\":\"First\",\"shipment_id\":\"shp_0e82027eba114d43b5ab061d9f417f96\",\"updated_at\":\"2024-04-05T20:06:47Z\"}},{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":3,\"percentile_75\":3,\"percentile_85\":3,\"percentile_90\":4,\"percentile_95\":4,\"percentile_97\":5,\"percentile_99\":8},\"easypost_estimated_delivery_date\":\"2024-04-11\",\"planned_ship_date\":\"2024-04-08\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-04-05T20:06:47Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":3,\"est_delivery_days\":3,\"id\":\"rate_58b4db339c9d41ed85523eabb0378c7e\",\"list_currency\":\"USD\",\"list_rate\":6.4,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":5.93,\"retail_currency\":\"USD\",\"retail_rate\":8.45,\"service\":\"ParcelSelect\",\"shipment_id\":\"shp_0e82027eba114d43b5ab061d9f417f96\",\"updated_at\":\"2024-04-05T20:06:47Z\"}},{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":1,\"percentile_75\":2,\"percentile_85\":2,\"percentile_90\":3,\"percentile_95\":3,\"percentile_97\":4,\"percentile_99\":7},\"easypost_estimated_delivery_date\":\"2024-04-09\",\"planned_ship_date\":\"2024-04-08\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-04-05T20:06:47Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":null,\"est_delivery_days\":null,\"id\":\"rate_832e1c6412ba4774946f5b35b916ff0d\",\"list_currency\":\"USD\",\"list_rate\":33.1,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":33.1,\"retail_currency\":\"USD\",\"retail_rate\":37.9,\"service\":\"Express\",\"shipment_id\":\"shp_0e82027eba114d43b5ab061d9f417f96\",\"updated_at\":\"2024-04-05T20:06:47Z\"}},{\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":2,\"percentile_75\":3,\"percentile_85\":3,\"percentile_90\":3,\"percentile_95\":4,\"percentile_97\":4,\"percentile_99\":7},\"easypost_estimated_delivery_date\":\"2024-04-10\",\"planned_ship_date\":\"2024-04-08\"},\"rate\":{\"carrier\":\"USPS\",\"carrier_account_id\":\"ca_5ba7ca3632c54adeb17ad4bcac13c890\",\"created_at\":\"2024-04-05T20:06:47Z\",\"currency\":\"USD\",\"delivery_date\":null,\"delivery_date_guaranteed\":false,\"delivery_days\":2,\"est_delivery_days\":2,\"id\":\"rate_de72bb4806c342018606ad01e93197a6\",\"list_currency\":\"USD\",\"list_rate\":8.25,\"mode\":\"test\",\"object\":\"Rate\",\"rate\":6.88,\"retail_currency\":\"USD\",\"retail_rate\":9.8,\"service\":\"Priority\",\"shipment_id\":\"shp_0e82027eba114d43b5ab061d9f417f96\",\"updated_at\":\"2024-04-05T20:06:47Z\"}}]}" - }, - "cookies": [], - "headers": [ - { - "name": "x-frame-options", - "value": "SAMEORIGIN" - }, - { - "name": "x-xss-protection", - "value": "1; mode=block" - }, - { - "name": "x-content-type-options", - "value": "nosniff" - }, - { - "name": "x-download-options", - "value": "noopen" - }, - { - "name": "x-permitted-cross-domain-policies", - "value": "none" - }, - { - "name": "referrer-policy", - "value": "strict-origin-when-cross-origin" - }, - { - "name": "x-ep-request-uuid", - "value": "1f0ae7a0661059d7f42e080a0019e4df" - }, - { - "name": "cache-control", - "value": "private, no-cache, no-store" - }, - { - "name": "pragma", - "value": "no-cache" - }, - { - "name": "expires", - "value": "0" - }, - { - "name": "content-type", - "value": "application/json; charset=utf-8" - }, - { - "name": "x-runtime", - "value": "0.115764" - }, - { - "name": "content-encoding", - "value": "gzip" - }, - { - "name": "transfer-encoding", - "value": "chunked" - }, - { - "name": "x-node", - "value": "bigweb36nuq" - }, - { - "name": "x-version-label", - "value": "easypost-202404051854-b9502cad97-master" - }, - { - "name": "x-backend", - "value": "easypost" - }, - { - "name": "x-proxied", - "value": "intlb3nuq 39c21b8207, extlb2nuq 60566a9ec2" - }, - { - "name": "strict-transport-security", - "value": "max-age=31536000; includeSubDomains; preload" - }, - { - "name": "connection", - "value": "close" - } - ], - "headersSize": 710, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 200, - "statusText": "OK" - }, - "startedDateTime": "2024-04-05T20:06:47.354Z", - "time": 241, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 241 - } - } - ], - "pages": [], - "version": "1.2" - } -} diff --git a/test/cassettes/SmartRate-Service_1309568275/estimate-delivery-date_838626811/recording.har b/test/cassettes/SmartRate-Service_1309568275/estimate-delivery-date_838626811/recording.har new file mode 100644 index 000000000..8c65fadd0 --- /dev/null +++ b/test/cassettes/SmartRate-Service_1309568275/estimate-delivery-date_838626811/recording.har @@ -0,0 +1,163 @@ +{ + "log": { + "_recordingName": "SmartRate Service/estimate delivery date", + "creator": { + "comment": "persister:fs", + "name": "Polly.JS", + "version": "6.0.5" + }, + "entries": [ + { + "_id": "44e77fd9d1aa4a719290c831b29d1c1c", + "_order": 0, + "cache": {}, + "request": { + "bodySize": 90, + "cookies": [], + "headers": [ + { + "name": "accept-encoding", + "value": "gzip, deflate" + }, + { + "name": "accept", + "value": "application/json" + }, + { + "name": "content-type", + "value": "application/json" + }, + { + "name": "content-length", + "value": 90 + }, + { + "name": "host", + "value": "api.easypost.com" + } + ], + "headersSize": 400, + "httpVersion": "HTTP/1.1", + "method": "POST", + "postData": { + "mimeType": "application/json", + "params": [], + "text": "{\"from_zip\":\"94107\",\"to_zip\":\"90277\",\"planned_ship_date\":\"2024-07-14\",\"carriers\":[\"USPS\"]}" + }, + "queryString": [], + "url": "https://api.easypost.com/v2/smartrate/deliver_by" + }, + "response": { + "bodySize": 416, + "content": { + "encoding": "base64", + "mimeType": "application/json; charset=utf-8", + "size": 416, + "text": "{\"carriers_without_tint_estimates\":null,\"from_zip\":\"94107\",\"planned_ship_date\":\"2024-07-14\",\"results\":[{\"carrier\":\"USPS\",\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":1,\"percentile_75\":2,\"percentile_85\":3,\"percentile_90\":4,\"percentile_95\":4,\"percentile_97\":5,\"percentile_99\":7},\"easypost_estimated_delivery_date\":\"2024-07-15\"},\"service\":\"express\"},{\"carrier\":\"USPS\",\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":1,\"percentile_75\":2,\"percentile_85\":3,\"percentile_90\":4,\"percentile_95\":4,\"percentile_97\":5,\"percentile_99\":8},\"easypost_estimated_delivery_date\":\"2024-07-15\"},\"service\":\"groundadvantage\"},{\"carrier\":\"USPS\",\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":1,\"percentile_75\":2,\"percentile_85\":3,\"percentile_90\":3,\"percentile_95\":4,\"percentile_97\":4,\"percentile_99\":8},\"easypost_estimated_delivery_date\":\"2024-07-15\"},\"service\":\"librarymail\"},{\"carrier\":\"USPS\",\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":1,\"percentile_75\":3,\"percentile_85\":3,\"percentile_90\":4,\"percentile_95\":4,\"percentile_97\":5,\"percentile_99\":8},\"easypost_estimated_delivery_date\":\"2024-07-15\"},\"service\":\"mediamail\"},{\"carrier\":\"USPS\",\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":1,\"percentile_75\":3,\"percentile_85\":3,\"percentile_90\":4,\"percentile_95\":4,\"percentile_97\":5,\"percentile_99\":8},\"easypost_estimated_delivery_date\":\"2024-07-15\"},\"service\":\"priority\"}],\"saturday_delivery\":null,\"to_zip\":\"90277\"}" + }, + "cookies": [], + "headers": [ + { + "name": "x-frame-options", + "value": "SAMEORIGIN" + }, + { + "name": "x-xss-protection", + "value": "1; mode=block" + }, + { + "name": "x-content-type-options", + "value": "nosniff" + }, + { + "name": "x-download-options", + "value": "noopen" + }, + { + "name": "x-permitted-cross-domain-policies", + "value": "none" + }, + { + "name": "referrer-policy", + "value": "strict-origin-when-cross-origin" + }, + { + "name": "x-ep-request-uuid", + "value": "39ae9c0066904a3cf3f63b9100345378" + }, + { + "name": "cache-control", + "value": "private, no-cache, no-store" + }, + { + "name": "pragma", + "value": "no-cache" + }, + { + "name": "expires", + "value": "0" + }, + { + "name": "content-type", + "value": "application/json; charset=utf-8" + }, + { + "name": "x-runtime", + "value": "0.054780" + }, + { + "name": "content-encoding", + "value": "gzip" + }, + { + "name": "transfer-encoding", + "value": "chunked" + }, + { + "name": "x-node", + "value": "bigweb41nuq" + }, + { + "name": "x-version-label", + "value": "easypost-202407111940-3cb16a3462-master" + }, + { + "name": "x-backend", + "value": "easypost" + }, + { + "name": "x-proxied", + "value": "intlb3nuq fa152d4755, extlb1nuq fa152d4755" + }, + { + "name": "strict-transport-security", + "value": "max-age=31536000; includeSubDomains; preload" + }, + { + "name": "connection", + "value": "close" + } + ], + "headersSize": 710, + "httpVersion": "HTTP/1.1", + "redirectURL": "", + "status": 200, + "statusText": "OK" + }, + "startedDateTime": "2024-07-11T21:10:20.448Z", + "time": 232, + "timings": { + "blocked": -1, + "connect": -1, + "dns": -1, + "receive": 0, + "send": 0, + "ssl": -1, + "wait": 232 + } + } + ], + "pages": [], + "version": "1.2" + } +} diff --git a/test/cassettes/SmartRate-Service_1309568275/recommend-ship-date_3612228667/recording.har b/test/cassettes/SmartRate-Service_1309568275/recommend-ship-date_3612228667/recording.har new file mode 100644 index 000000000..ce91d6665 --- /dev/null +++ b/test/cassettes/SmartRate-Service_1309568275/recommend-ship-date_3612228667/recording.har @@ -0,0 +1,163 @@ +{ + "log": { + "_recordingName": "SmartRate Service/recommend ship date", + "creator": { + "comment": "persister:fs", + "name": "Polly.JS", + "version": "6.0.5" + }, + "entries": [ + { + "_id": "3892af501b06929c997d6d894396b2d3", + "_order": 0, + "cache": {}, + "request": { + "bodySize": 94, + "cookies": [], + "headers": [ + { + "name": "accept-encoding", + "value": "gzip, deflate" + }, + { + "name": "accept", + "value": "application/json" + }, + { + "name": "content-type", + "value": "application/json" + }, + { + "name": "content-length", + "value": 94 + }, + { + "name": "host", + "value": "api.easypost.com" + } + ], + "headersSize": 400, + "httpVersion": "HTTP/1.1", + "method": "POST", + "postData": { + "mimeType": "application/json", + "params": [], + "text": "{\"from_zip\":\"94107\",\"to_zip\":\"90277\",\"desired_delivery_date\":\"2024-07-14\",\"carriers\":[\"USPS\"]}" + }, + "queryString": [], + "url": "https://api.easypost.com/v2/smartrate/deliver_on" + }, + "response": { + "bodySize": 460, + "content": { + "encoding": "base64", + "mimeType": "application/json; charset=utf-8", + "size": 460, + "text": "{\"carriers_without_tint_estimates\":null,\"desired_delivery_date\":\"2024-07-14\",\"from_zip\":\"94107\",\"results\":[{\"carrier\":\"USPS\",\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":2,\"percentile_75\":3,\"percentile_85\":4,\"percentile_90\":4,\"percentile_95\":5,\"percentile_97\":5,\"percentile_99\":7},\"delivery_date_confidence\":0.02,\"estimated_transit_days\":1,\"ship_on_date\":\"2024-07-13\"},\"service\":\"express\"},{\"carrier\":\"USPS\",\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":4,\"percentile_75\":4,\"percentile_85\":4,\"percentile_90\":4,\"percentile_95\":5,\"percentile_97\":5,\"percentile_99\":8},\"delivery_date_confidence\":0,\"estimated_transit_days\":3,\"ship_on_date\":\"2024-07-11\"},\"service\":\"groundadvantage\"},{\"carrier\":\"USPS\",\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":4,\"percentile_75\":4,\"percentile_85\":4,\"percentile_90\":4,\"percentile_95\":5,\"percentile_97\":5,\"percentile_99\":7},\"delivery_date_confidence\":0,\"estimated_transit_days\":3,\"ship_on_date\":\"2024-07-11\"},\"service\":\"librarymail\"},{\"carrier\":\"USPS\",\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":4,\"percentile_75\":4,\"percentile_85\":4,\"percentile_90\":4,\"percentile_95\":5,\"percentile_97\":5,\"percentile_99\":8},\"delivery_date_confidence\":0,\"estimated_transit_days\":3,\"ship_on_date\":\"2024-07-11\"},\"service\":\"mediamail\"},{\"carrier\":\"USPS\",\"easypost_time_in_transit_data\":{\"days_in_transit\":{\"percentile_50\":4,\"percentile_75\":4,\"percentile_85\":4,\"percentile_90\":4,\"percentile_95\":5,\"percentile_97\":5,\"percentile_99\":7},\"delivery_date_confidence\":0,\"estimated_transit_days\":3,\"ship_on_date\":\"2024-07-11\"},\"service\":\"priority\"}],\"saturday_delivery\":null,\"to_zip\":\"90277\"}" + }, + "cookies": [], + "headers": [ + { + "name": "x-frame-options", + "value": "SAMEORIGIN" + }, + { + "name": "x-xss-protection", + "value": "1; mode=block" + }, + { + "name": "x-content-type-options", + "value": "nosniff" + }, + { + "name": "x-download-options", + "value": "noopen" + }, + { + "name": "x-permitted-cross-domain-policies", + "value": "none" + }, + { + "name": "referrer-policy", + "value": "strict-origin-when-cross-origin" + }, + { + "name": "x-ep-request-uuid", + "value": "b8e53c2066904aa9f40a846c00331f24" + }, + { + "name": "cache-control", + "value": "private, no-cache, no-store" + }, + { + "name": "pragma", + "value": "no-cache" + }, + { + "name": "expires", + "value": "0" + }, + { + "name": "content-type", + "value": "application/json; charset=utf-8" + }, + { + "name": "x-runtime", + "value": "0.048872" + }, + { + "name": "content-encoding", + "value": "gzip" + }, + { + "name": "transfer-encoding", + "value": "chunked" + }, + { + "name": "x-node", + "value": "bigweb35nuq" + }, + { + "name": "x-version-label", + "value": "easypost-202407111940-3cb16a3462-master" + }, + { + "name": "x-backend", + "value": "easypost" + }, + { + "name": "x-proxied", + "value": "intlb3nuq fa152d4755, extlb2nuq fa152d4755" + }, + { + "name": "strict-transport-security", + "value": "max-age=31536000; includeSubDomains; preload" + }, + { + "name": "connection", + "value": "close" + } + ], + "headersSize": 710, + "httpVersion": "HTTP/1.1", + "redirectURL": "", + "status": 200, + "statusText": "OK" + }, + "startedDateTime": "2024-07-11T21:12:09.115Z", + "time": 213, + "timings": { + "blocked": -1, + "connect": -1, + "dns": -1, + "receive": 0, + "send": 0, + "ssl": -1, + "wait": 213 + } + } + ], + "pages": [], + "version": "1.2" + } +} diff --git a/test/helpers/fixture.js b/test/helpers/fixture.js index 929b34575..6aa231a39 100644 --- a/test/helpers/fixture.js +++ b/test/helpers/fixture.js @@ -140,6 +140,10 @@ export default class Fixture { } static plannedShipDate() { - return '2024-04-08'; + return '2024-07-14'; + } + + static plannedDeliveryDate() { + return '2024-07-14'; } } diff --git a/test/services/shipment.test.js b/test/services/shipment.test.js index dc2cc123e..b57e26581 100644 --- a/test/services/shipment.test.js +++ b/test/services/shipment.test.js @@ -321,14 +321,31 @@ describe('Shipment Service', function () { expect(boughtShipment.postage_label).to.exist; }); - it('retrieve time-in-transit data for each of the Rates of a shipment', async function () { + it('retrieve estimated delivery dates for each of the Rates of a shipment', async function () { const shipment = await this.client.Shipment.create(Fixture.basicShipment()); const estimatedDeliveryDates = await this.client.Shipment.retrieveEstimatedDeliveryDate( shipment.id, Fixture.plannedShipDate(), ); - expect(estimatedDeliveryDates.every((entry) => entry.easypost_time_in_transit_data)).to.not.be - .null; + for (const entry of estimatedDeliveryDates) { + expect(entry.rate).to.be.instanceOf(Rate); + expect(entry.easypost_time_in_transit_data).to.be.an('object'); + expect(entry.easypost_time_in_transit_data.easypost_estimated_delivery_date).to.not.be.null; + } + }); + + it('retrieve recommended ship dates for each of the Rates of a shipment', async function () { + const shipment = await this.client.Shipment.create(Fixture.basicShipment()); + const recommendedShipDates = await this.client.Shipment.recommendShipDate( + shipment.id, + Fixture.plannedDeliveryDate(), + ); + + for (const entry of recommendedShipDates) { + expect(entry.rate).to.be.instanceOf(Rate); + expect(entry.easypost_time_in_transit_data).to.be.an('object'); + expect(entry.easypost_time_in_transit_data.ship_on_date).to.not.be.null; + } }); }); diff --git a/test/services/smart_rate.test.js b/test/services/smart_rate.test.js new file mode 100644 index 000000000..494b423a3 --- /dev/null +++ b/test/services/smart_rate.test.js @@ -0,0 +1,57 @@ +import { expect } from 'chai'; + +import EasyPostClient from '../../src/easypost'; +import Fixture from '../helpers/fixture'; +import * as setupPolly from '../helpers/setup_polly'; + +/* eslint-disable func-names */ +describe('SmartRate Service', function () { + setupPolly.startPolly(); + + before(function () { + this.client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); + }); + + beforeEach(function () { + const { server } = this.polly; + setupPolly.setupCassette(server); + }); + + it('estimate delivery date', async function () { + const carrier = Fixture.usps(); + + const params = { + from_zip: Fixture.caAddress1().zip, + to_zip: Fixture.caAddress2().zip, + planned_ship_date: Fixture.plannedShipDate(), + carriers: [carrier], + }; + + const estimatedDeliveryDates = await this.client.SmartRate.estimateDeliveryDate(params); + + for (const entry of estimatedDeliveryDates.results) { + expect(entry.carrier).to.equal(carrier); + expect(entry.easypost_time_in_transit_data).to.be.an('object'); + expect(entry.easypost_time_in_transit_data.easypost_estimated_delivery_date).to.not.be.null; + } + }); + + it('recommend ship date', async function () { + const carrier = Fixture.usps(); + + const params = { + from_zip: Fixture.caAddress1().zip, + to_zip: Fixture.caAddress2().zip, + desired_delivery_date: Fixture.plannedDeliveryDate(), + carriers: [carrier], + }; + + const recommendedShipDates = await this.client.SmartRate.recommendShipDate(params); + + for (const entry of recommendedShipDates.results) { + expect(entry.carrier).to.equal(carrier); + expect(entry.easypost_time_in_transit_data).to.be.an('object'); + expect(entry.easypost_time_in_transit_data.ship_on_date).to.not.be.null; + } + }); +}); diff --git a/types/Shipment/Shipment.d.ts b/types/Shipment/Shipment.d.ts index 9b20d406d..b0470b41b 100644 --- a/types/Shipment/Shipment.d.ts +++ b/types/Shipment/Shipment.d.ts @@ -320,7 +320,7 @@ export declare class Shipment implements IShipment { static generateForm(id: string, formType: string, formOptions?: object): Promise; /** - * Retrieves the estimated delivery date of each Rate via SmartRate. + * Retrieve the estimated delivery date of each Rate via SmartRate. * * @param id shipment id (begins with "shp_"). * @param plannedShipDate The planned ship date in format YYYY-MM-DD @@ -328,6 +328,14 @@ export declare class Shipment implements IShipment { */ static retrieveEstimatedDeliveryDate(id: string, plannedShipDate: string): Promise>; + /** + * Retrieve a recommended ship date for a {@link Shipment shipment} via the Precision Shipping API, based on a specific desired delivery date. + * @param id - The ID of the shipment to retrieve the recommended ship date for. + * @param desiredDeliveryDate - The desired delivery date for the shipment. + * @returns {Array} - An array of the recommended ship date and rates. + */ + static recommendShipDate(id: string, desiredDeliveryDate: string): Promise>; + /** * Retrieve the next page of {@link Shipment shipments}. * diff --git a/types/SmartRate/SmartRate.d.ts b/types/SmartRate/SmartRate.d.ts new file mode 100644 index 000000000..9c2d6399d --- /dev/null +++ b/types/SmartRate/SmartRate.d.ts @@ -0,0 +1,20 @@ +/** + * The SmartRate class interacts with the SmartRate API to provide optimized shipping rates and estimates. + * + * @see https://www.easypost.com/smartrate + */ +export declare class SmartRate { + /** + * 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. + * @param params - The parameters to estimate the delivery date with. + * @returns {Object} - Estimates and related metadata. + */ + static estimateDeliveryDate(params: object): object; + + /** + * 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. + * @param params - The parameters to recommend the ship date with. + * @returns {Object} - Recommendation and related metadata. + */ + static recommendShipDate(params: object): object; +}