From 0aa400ddbb390d418ed2f7fbbb428cbf5d9c2e99 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Fri, 7 Aug 2026 14:45:39 -0600 Subject: [PATCH] TSM-09: convert Group D services to TypeScript --- .../{claim_service.js => claim_service.ts} | 18 ++++++++++++------ .../{event_service.js => event_service.ts} | 15 ++++++++++----- ...surance_service.js => insurance_service.ts} | 16 +++++++++++----- .../{tracker_service.js => tracker_service.ts} | 18 ++++++++++++------ .../{webhook_service.js => webhook_service.ts} | 12 +++++++----- 5 files changed, 52 insertions(+), 27 deletions(-) rename src/services/{claim_service.js => claim_service.ts} (79%) rename src/services/{event_service.js => event_service.ts} (86%) rename src/services/{insurance_service.js => insurance_service.ts} (85%) rename src/services/{tracker_service.js => tracker_service.ts} (84%) rename src/services/{webhook_service.js => webhook_service.ts} (87%) diff --git a/src/services/claim_service.js b/src/services/claim_service.ts similarity index 79% rename from src/services/claim_service.js rename to src/services/claim_service.ts index 0e92b4472..b6d13f100 100644 --- a/src/services/claim_service.js +++ b/src/services/claim_service.ts @@ -1,5 +1,8 @@ import baseService from './base_service'; +type ClaimParams = Record; +type ClaimCollection = Record; + export default (easypostClient) => /** * The ClaimService class provides methods for interacting with EasyPost {@link Claim} objects. @@ -11,7 +14,7 @@ export default (easypostClient) => * @param {Object} params - Parameters for the claim to be created. * @returns {Claim} - The created claim. */ - static async create(params) { + static async create(params: ClaimParams): Promise { const url = 'claims'; return this._create(url, params); @@ -22,7 +25,7 @@ export default (easypostClient) => * @param {Object} [params] - Parameters to filter the claim records. * @returns {Object} - An object containing the list of {@link Claim claim} records and pagination information. */ - static async all(params = {}) { + static async all(params: Record = {}): Promise { const url = 'claims'; return this._all(url, params); @@ -34,7 +37,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(claims, pageSize = null) { + static async getNextPage( + claims: ClaimCollection, + pageSize: number | null = null, + ): Promise { const url = 'claims'; return this._getNextPage(url, 'claims', claims, pageSize); } @@ -44,7 +50,7 @@ export default (easypostClient) => * @param {string} id - The ID of the claim to retrieve. * @returns {Claim} - The retrieved claim. */ - static async retrieve(id) { + static async retrieve(id: string): Promise { const url = `claims/${id}`; return this._retrieve(url); @@ -55,8 +61,8 @@ export default (easypostClient) => * @param {string} id - The ID of the claim to be canceled. * @returns {Claim} - The canceled claim. */ - static async cancel(id) { + static async cancel(id: string): Promise { const url = `claims/${id}/cancel`; - return this._create(url); + return this._create(url, {}); } }; diff --git a/src/services/event_service.js b/src/services/event_service.ts similarity index 86% rename from src/services/event_service.js rename to src/services/event_service.ts index 3e3f05ae0..f9515e0df 100644 --- a/src/services/event_service.js +++ b/src/services/event_service.ts @@ -1,5 +1,7 @@ import baseService from './base_service'; +type EventCollection = Record; + export default (easypostClient) => /** * The EventService class provides methods for interacting with EasyPost {@link Event} objects. @@ -12,7 +14,7 @@ export default (easypostClient) => * @param {string} id - The ID of the event to retrieve payloads for. * @returns {Payload[]} - A list of {@link Payload payloads} for the event. */ - static async retrieveAllPayloads(id) { + static async retrieveAllPayloads(id: string): Promise { const url = `events/${id}/payloads`; try { @@ -31,7 +33,7 @@ export default (easypostClient) => * @param {string} payloadId - The ID of the payload to retrieve. * @returns {Payload} - The {@link Payload payload} for the event. */ - static async retrievePayload(id, payloadId) { + static async retrievePayload(id: string, payloadId: string): Promise { const url = `events/${id}/payloads/${payloadId}`; try { @@ -49,7 +51,7 @@ export default (easypostClient) => * @param {Object} [params] - Parameters to filter the list of events. * @returns {Object} - An object containing the list of {@link Event events} and pagination information. */ - static async all(params = {}) { + static async all(params: Record = {}): Promise { const url = 'events'; return this._all(url, params); @@ -61,7 +63,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(events, pageSize = null) { + static async getNextPage( + events: EventCollection, + pageSize: number | null = null, + ): Promise { const url = 'events'; return this._getNextPage(url, 'events', events, pageSize); } @@ -72,7 +77,7 @@ export default (easypostClient) => * @param {string} id - The ID of the event to retrieve. * @returns {Event} - The retrieved event. */ - static async retrieve(id) { + static async retrieve(id: string): Promise { const url = `events/${id}`; return this._retrieve(url); diff --git a/src/services/insurance_service.js b/src/services/insurance_service.ts similarity index 85% rename from src/services/insurance_service.js rename to src/services/insurance_service.ts index 4c433a431..0152956cc 100644 --- a/src/services/insurance_service.js +++ b/src/services/insurance_service.ts @@ -1,5 +1,8 @@ import baseService from './base_service'; +type InsuranceParams = Record; +type InsuranceCollection = Record; + export default (easypostClient) => /** * The InsuranceService class provides methods for interacting with EasyPost {@link Insurance} objects. @@ -12,7 +15,7 @@ export default (easypostClient) => * @param {Object} params - Parameters for the insurance to be created. * @returns {Insurance} - The created insurance. */ - static async create(params) { + static async create(params: InsuranceParams): Promise { const url = 'insurances'; const wrappedParams = { @@ -28,7 +31,7 @@ export default (easypostClient) => * @param {Object} [params] - Parameters to filter the insurance records. * @returns {Object} - An object containing the list of {@link Insurance insurance} records and pagination information. */ - static async all(params = {}) { + static async all(params: Record = {}): Promise { const url = 'insurances'; 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(insurances, pageSize = null) { + static async getNextPage( + insurances: InsuranceCollection, + pageSize: number | null = null, + ): Promise { const url = 'insurances'; return this._getNextPage(url, 'insurances', insurances, pageSize); } @@ -51,7 +57,7 @@ export default (easypostClient) => * @param {string} id - The ID of the insurance to retrieve. * @returns {Insurance} - The retrieved insurance. */ - static async retrieve(id) { + static async retrieve(id: string): Promise { const url = `insurances/${id}`; return this._retrieve(url); @@ -63,7 +69,7 @@ export default (easypostClient) => * @param {string} id - The ID of the insurance to be refunded. * @returns {Insurance} - The refunded insurance. */ - static async refund(id) { + static async refund(id: string): Promise { const url = `insurances/${id}/refund`; const response = await easypostClient._post(url); diff --git a/src/services/tracker_service.js b/src/services/tracker_service.ts similarity index 84% rename from src/services/tracker_service.js rename to src/services/tracker_service.ts index 0282416b0..647788326 100644 --- a/src/services/tracker_service.js +++ b/src/services/tracker_service.ts @@ -1,5 +1,8 @@ import baseService from './base_service'; +type TrackerParams = Record; +type TrackerCollection = Record; + export default (easypostClient) => /** * The TrackerService class provides methods for interacting with EasyPost {@link Tracker} objects. @@ -12,7 +15,7 @@ export default (easypostClient) => * @param {Object} params - The parameters to create a tracker with. * @returns {Tracker} - The created tracker. */ - static async create(params) { + static async create(params: TrackerParams): Promise { const url = 'trackers'; const wrappedParams = { @@ -28,7 +31,7 @@ export default (easypostClient) => * @param {Object} [params] - The parameters to filter the trackers by. * @returns {Object} - An object containing the list of {@link Tracker trackers} and pagination information. */ - static async all(params = {}) { + static async all(params: Record = {}): Promise { const url = 'trackers'; 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(trackers, pageSize = null) { + static async getNextPage( + trackers: TrackerCollection, + pageSize: number | null = null, + ): Promise { const url = 'trackers'; return this._getNextPage(url, 'trackers', trackers, pageSize); @@ -52,7 +58,7 @@ export default (easypostClient) => * @param {string} id - The ID of the tracker to retrieve. * @returns {Tracker} - The retrieved tracker. */ - static async retrieve(id) { + static async retrieve(id: string): Promise { const url = `trackers/${id}`; return this._retrieve(url); @@ -63,7 +69,7 @@ export default (easypostClient) => * @param {Object} [params] - The parameters to filter the trackers by. * @returns {Object} - An object containing the list of {@link Tracker trackers}. */ - static async retrieveBatch(params = {}) { + static async retrieveBatch(params: Record = {}): Promise { const url = 'trackers/batch'; try { @@ -81,7 +87,7 @@ export default (easypostClient) => * @param {string} id - The ID of the tracker to delete. * @returns {Promise} */ - static async delete(id) { + static async delete(id: string): Promise { const url = `trackers/${id}`; try { diff --git a/src/services/webhook_service.js b/src/services/webhook_service.ts similarity index 87% rename from src/services/webhook_service.js rename to src/services/webhook_service.ts index aed890d51..7c599abc5 100644 --- a/src/services/webhook_service.js +++ b/src/services/webhook_service.ts @@ -1,5 +1,7 @@ import baseService from './base_service'; +type WebhookParams = Record; + export default (easypostClient) => /** * The WebhookService class provides methods for interacting with EasyPost {@link Webhook} objects. @@ -12,7 +14,7 @@ export default (easypostClient) => * @param {Object} params - The parameters to create a webhook with. * @returns {Webhook} - The created webhook. */ - static async create(params) { + static async create(params: WebhookParams): Promise { const url = 'webhooks'; const wrappedParams = { @@ -30,7 +32,7 @@ export default (easypostClient) => * @param {Object} params - The parameters to update the webhook with. * @returns {Webhook} - The updated webhook. */ - static async update(id, params) { + static async update(id: string, params: Record): Promise { const url = `webhooks/${id}`; try { @@ -48,7 +50,7 @@ export default (easypostClient) => * @param {string} id - The ID of the webhook to delete. * @returns {Promise|Promise} - A promise that resolves if the webhook was successfully deleted. */ - static async delete(id) { + static async delete(id: string): Promise { const url = `webhooks/${id}`; try { @@ -66,7 +68,7 @@ export default (easypostClient) => * @param {Object} [params] * @returns {Webhook[]} */ - static async all(params = {}) { + static async all(params: Record = {}): Promise { const url = 'webhooks'; return this._all(url, params); @@ -78,7 +80,7 @@ export default (easypostClient) => * @param {string} id - The ID of the webhook to retrieve. * @returns {Webhook} - The retrieved webhook. */ - static async retrieve(id) { + static async retrieve(id: string): Promise { const url = `webhooks/${id}`; return this._retrieve(url);