From 28759c9bc1dcd6055f3731dd996e99f3923bf253 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Fri, 7 Aug 2026 14:43:46 -0600 Subject: [PATCH] TSM-07: convert Group B services to TypeScript --- .../{batch_service.js => batch_service.ts} | 21 ++++++++++++------- .../{order_service.js => order_service.ts} | 10 +++++---- .../{pickup_service.js => pickup_service.ts} | 18 ++++++++++------ .../{rate_service.js => rate_service.ts} | 2 +- .../{refund_service.js => refund_service.ts} | 14 +++++++++---- ...n_form_service.js => scan_form_service.ts} | 16 ++++++++++---- ..._rate_service.js => smart_rate_service.ts} | 6 ++++-- 7 files changed, 58 insertions(+), 29 deletions(-) rename src/services/{batch_service.js => batch_service.ts} (88%) rename src/services/{order_service.js => order_service.ts} (88%) rename src/services/{pickup_service.js => pickup_service.ts} (86%) rename src/services/{rate_service.js => rate_service.ts} (92%) rename src/services/{refund_service.js => refund_service.ts} (83%) rename src/services/{scan_form_service.js => scan_form_service.ts} (84%) rename src/services/{smart_rate_service.js => smart_rate_service.ts} (88%) diff --git a/src/services/batch_service.js b/src/services/batch_service.ts similarity index 88% rename from src/services/batch_service.js rename to src/services/batch_service.ts index bbd13f97d..9cd237138 100644 --- a/src/services/batch_service.js +++ b/src/services/batch_service.ts @@ -2,6 +2,8 @@ import baseService from './base_service'; export const DEFAULT_LABEL_FORMAT = 'pdf'; +type BatchParams = Record; + export default (easypostClient) => /** * The BatchService class provides methods for interacting with EasyPost {@link Batch} objects. @@ -14,7 +16,7 @@ export default (easypostClient) => * @param {Object} params - Parameters for the batch to be created. * @returns {Batch} - The created batch. */ - static async create(params) { + static async create(params: BatchParams): Promise { const url = 'batches'; const wrappedParams = { @@ -31,7 +33,7 @@ export default (easypostClient) => * @param {Array} shipmentIds - The ids of the shipments to add to the batch. * @returns {Batch} - The updated batch. */ - static async addShipments(id, shipmentIds) { + static async addShipments(id: string, shipmentIds: string[]): Promise { const url = `batches/${id}/add_shipments`; const wrappedParams = { shipments: shipmentIds.map((s) => ({ id: s })), @@ -52,7 +54,7 @@ export default (easypostClient) => * @param {Array} shipmentIds - The ids of the shipments to remove from the batch. * @returns {Batch} - The updated batch. */ - static async removeShipments(id, shipmentIds) { + static async removeShipments(id: string, shipmentIds: string[]): Promise { const url = `batches/${id}/remove_shipments`; const wrappedParams = { shipments: shipmentIds.map((s) => ({ id: s })), @@ -74,7 +76,10 @@ export default (easypostClient) => * @param {string} fileFormat - The format of the label to generate. Defaults to 'pdf'. * @returns {Batch} - The updated batch. */ - static async generateLabel(id, fileFormat = DEFAULT_LABEL_FORMAT) { + static async generateLabel( + id: string, + fileFormat: string = DEFAULT_LABEL_FORMAT, + ): Promise { const url = `batches/${id}/label`; const wrappedParams = { file_format: fileFormat }; @@ -93,7 +98,7 @@ export default (easypostClient) => * @param {string} id - The id of the batch to create a scan form for. * @returns {Batch} - The updated batch. */ - static async createScanForm(id) { + static async createScanForm(id: string): Promise { const url = `batches/${id}/scan_form`; try { @@ -111,7 +116,7 @@ export default (easypostClient) => * @param {string} id - The id of the batch to purchase. * @returns {Batch} - The purchased batch. */ - static async buy(id) { + static async buy(id: string): Promise { const url = `batches/${id}/buy`; try { @@ -129,7 +134,7 @@ export default (easypostClient) => * @param {Object} [params] - Parameters to filter the list of batches. * @returns {Object} - An object containing a list of {@link Batch batches} and pagination information. */ - static async all(params = {}) { + static async all(params: Record = {}): Promise { const url = 'batches'; return this._all(url, params); @@ -141,7 +146,7 @@ export default (easypostClient) => * @param {string} id - The ID of the batch to retrieve. * @returns {Batch} - The retrieved batch. */ - static async retrieve(id) { + static async retrieve(id: string): Promise { const url = `batches/${id}`; return this._retrieve(url); diff --git a/src/services/order_service.js b/src/services/order_service.ts similarity index 88% rename from src/services/order_service.js rename to src/services/order_service.ts index 01fb6cf3e..20781049d 100644 --- a/src/services/order_service.js +++ b/src/services/order_service.ts @@ -1,5 +1,7 @@ import baseService from './base_service'; +type OrderParams = Record; + export default (easypostClient) => /** * The OrderService class provides methods for interacting with EasyPost {@link Order} objects. @@ -12,7 +14,7 @@ export default (easypostClient) => * @param {Object} params - The parameters to create an order with. * @returns {Order} - The created order. */ - static async create(params) { + static async create(params: OrderParams): Promise { const url = 'orders'; const wrappedParams = { @@ -30,7 +32,7 @@ export default (easypostClient) => * @param {string} service - The service to use for the order purchase. * @returns {Order} - The purchased order. */ - static async buy(id, carrier, service) { + static async buy(id: string, carrier: string, service: string): Promise { const url = `orders/${id}/buy`; const wrappedParams = { carrier, service }; try { @@ -48,7 +50,7 @@ export default (easypostClient) => * @param {string} id - The ID of the order to get rates for. * @returns {Order} - The order with rates. */ - static async getRates(id) { + static async getRates(id: string): Promise { const url = `orders/${id}/rates`; try { @@ -66,7 +68,7 @@ export default (easypostClient) => * @param {string} id - The ID of the order to retrieve. * @returns {Order} - The retrieved order. */ - static async retrieve(id) { + static async retrieve(id: string): Promise { const url = `orders/${id}`; return this._retrieve(url); diff --git a/src/services/pickup_service.js b/src/services/pickup_service.ts similarity index 86% rename from src/services/pickup_service.js rename to src/services/pickup_service.ts index 0968dc8d1..1a5090306 100644 --- a/src/services/pickup_service.js +++ b/src/services/pickup_service.ts @@ -1,5 +1,8 @@ import baseService from './base_service'; +type PickupParams = Record; +type PickupCollection = Record; + export default (easypostClient) => /** * The PickupService class provides methods for interacting with EasyPost {@link Pickup} objects. @@ -12,7 +15,7 @@ export default (easypostClient) => * @param {Object} params - The parameters to create a pickup with. * @returns {Pickup} - The created pickup. */ - static async create(params) { + static async create(params: PickupParams): Promise { const url = 'pickups'; const wrappedParams = { @@ -30,7 +33,7 @@ export default (easypostClient) => * @param {string} service - The service to purchase the pickup with. * @returns {Pickup} - The purchased pickup. */ - static async buy(id, carrier, service) { + static async buy(id: string, carrier: string, service: string): Promise { const url = `pickups/${id}/buy`; const wrappedParams = { carrier, service }; try { @@ -48,7 +51,7 @@ export default (easypostClient) => * @param {string} id - The ID of the pickup to cancel. * @returns {Pickup} - The cancelled pickup. */ - static async cancel(id) { + static async cancel(id: string): Promise { const url = `pickups/${id}/cancel`; try { const response = await easypostClient._post(url); @@ -65,7 +68,7 @@ export default (easypostClient) => * @param {Object} [params] - The parameters to filter the pickups by. * @returns {Object} - An object containing a list of {@link Pickup pickups} and pagination information. */ - static async all(params = {}) { + static async all(params: Record = {}): Promise { const url = 'pickups'; return this._all(url, params); @@ -77,7 +80,10 @@ export default (easypostClient) => * @param {Number} pageSize The number of records to return on each page * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage(pickups, pageSize = null) { + static async getNextPage( + pickups: PickupCollection, + pageSize: number | null = null, + ): Promise { const url = 'pickups'; return this._getNextPage(url, 'pickups', pickups, pageSize); } @@ -88,7 +94,7 @@ export default (easypostClient) => * @param {string} id - The ID of the pickup to retrieve. * @returns {Pickup} - The retrieved pickup. */ - static async retrieve(id) { + static async retrieve(id: string): Promise { const url = `pickups/${id}`; return this._retrieve(url); diff --git a/src/services/rate_service.js b/src/services/rate_service.ts similarity index 92% rename from src/services/rate_service.js rename to src/services/rate_service.ts index 4f65069e3..66bbfaebd 100644 --- a/src/services/rate_service.js +++ b/src/services/rate_service.ts @@ -12,7 +12,7 @@ export default (easypostClient) => * @param {string} id - The ID of the rate to retrieve. * @returns {Rate} - The retrieved rate. */ - static async retrieve(id) { + static async retrieve(id: string): Promise { const url = `rates/${id}`; return this._retrieve(url); diff --git a/src/services/refund_service.js b/src/services/refund_service.ts similarity index 83% rename from src/services/refund_service.js rename to src/services/refund_service.ts index 6012e7d0b..c4a86409b 100644 --- a/src/services/refund_service.js +++ b/src/services/refund_service.ts @@ -1,5 +1,8 @@ import baseService from './base_service'; +type RefundParams = Record; +type RefundCollection = Record; + export default (easypostClient) => /** * The RefundService class provides methods for interacting with EasyPost {@link Refund} objects. @@ -12,7 +15,7 @@ export default (easypostClient) => * @param {Object} params - The parameters to create a refund with. * @returns {Refund} - The created refund. */ - static async create(params) { + static async create(params: RefundParams): Promise { const url = 'refunds'; const wrappedParams = { @@ -28,7 +31,7 @@ export default (easypostClient) => * @param {Object} [params] - The parameters to filter the refunds by. * @returns {Object} - An object containing the list of {@link Refund refunds} and pagination information. */ - static async all(params = {}) { + static async all(params: Record = {}): Promise { const url = 'refunds'; return this._all(url, params); @@ -40,7 +43,10 @@ export default (easypostClient) => * @param {Number} pageSize The number of records to return on each page * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage(refunds, pageSize = null) { + static async getNextPage( + refunds: RefundCollection, + pageSize: number | null = null, + ): Promise { const url = 'refunds'; return this._getNextPage(url, 'refunds', refunds, pageSize); } @@ -51,7 +57,7 @@ export default (easypostClient) => * @param {string} id - The ID of the refund to retrieve. * @returns {Refund} - The retrieved refund. */ - static async retrieve(id) { + static async retrieve(id: string): Promise { const url = `refunds/${id}`; return this._retrieve(url); diff --git a/src/services/scan_form_service.js b/src/services/scan_form_service.ts similarity index 84% rename from src/services/scan_form_service.js rename to src/services/scan_form_service.ts index 75d7de9cc..518dfc9d4 100644 --- a/src/services/scan_form_service.js +++ b/src/services/scan_form_service.ts @@ -1,5 +1,10 @@ import baseService from './base_service'; +type ScanFormParams = Record & { + shipments?: Array; +}; +type ScanFormCollection = Record; + export default (easypostClient) => /** * The ScanFormService class provides methods for interacting with EasyPost {@link ScanForm} objects. @@ -12,7 +17,7 @@ export default (easypostClient) => * @param {Object} params - The parameters to create a scan form with. * @returns {ScanForm} - The created scan form. */ - static async create(params) { + static async create(params: ScanFormParams): Promise { const url = 'scan_forms'; // wraps up params in `shipments` if the user didn't do it @@ -40,7 +45,7 @@ export default (easypostClient) => * @param {Object} [params] - The parameters to filter the scan forms by. * @returns {Object} - An object containing the list of {@link ScanForm scan forms} and pagination information. */ - static async all(params = {}) { + static async all(params: Record = {}): Promise { const url = 'scan_forms'; return this._all(url, params); @@ -52,7 +57,10 @@ export default (easypostClient) => * @param {Number} pageSize The number of records to return on each page * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage(scanforms, pageSize = null) { + static async getNextPage( + scanforms: ScanFormCollection, + pageSize: number | null = null, + ): Promise { const url = 'scan_forms'; return this._getNextPage(url, 'scan_forms', scanforms, pageSize); } @@ -63,7 +71,7 @@ export default (easypostClient) => * @param {string} id - The ID of the scan form to retrieve. * @returns {ScanForm} - The retrieved scan form. */ - static async retrieve(id) { + static async retrieve(id: string): Promise { const url = `scan_forms/${id}`; return this._retrieve(url); diff --git a/src/services/smart_rate_service.js b/src/services/smart_rate_service.ts similarity index 88% rename from src/services/smart_rate_service.js rename to src/services/smart_rate_service.ts index cbb7b1330..ea1909b48 100644 --- a/src/services/smart_rate_service.js +++ b/src/services/smart_rate_service.ts @@ -1,5 +1,7 @@ import baseService from './base_service'; +type SmartRateParams = Record; + export default (easypostClient) => /** * The SmartRateService class provides methods for interacting with EasyPost SmartRate APIs. @@ -11,7 +13,7 @@ export default (easypostClient) => * @param params - The parameters to estimate the delivery date with. * @returns {Object} - Estimates and related metadata. */ - static async estimateDeliveryDate(params) { + static async estimateDeliveryDate(params: SmartRateParams): Promise { const url = 'smartrate/deliver_by'; try { @@ -28,7 +30,7 @@ export default (easypostClient) => * @param params - The parameters to recommend the ship date with. * @returns {Object} - Recommendation and related metadata. */ - static async recommendShipDate(params) { + static async recommendShipDate(params: SmartRateParams): Promise { const url = 'smartrate/deliver_on'; try {