diff --git a/src/easypost.ts b/src/easypost.ts index a4c2c662f..88320135a 100644 --- a/src/easypost.ts +++ b/src/easypost.ts @@ -48,11 +48,11 @@ type HttpClient = typeof fetch; interface CompatibilityRequest { method: string; url: string; - _data: unknown; + _data: Record | undefined; set(headersToSet?: RequestHeaders): CompatibilityRequest; auth(key: string): CompatibilityRequest; query(queryParams?: Record): CompatibilityRequest; - send(body?: unknown): CompatibilityRequest; + send(body?: Record): CompatibilityRequest; } interface HttpMiddleware { @@ -415,7 +415,7 @@ export default class EasyPostClient { const isQueryMethod = normalizedMethod === EasyPostClient.METHODS.GET || normalizedMethod === EasyPostClient.METHODS.DELETE; - let requestBody; + let requestBody: Record | undefined; if (params !== undefined) { if (isQueryMethod) { @@ -427,7 +427,7 @@ export default class EasyPostClient { } } - const compatibilityRequest = { + const compatibilityRequest: CompatibilityRequest = { method: normalizedMethod.toUpperCase(), url: url.toString(), _data: requestBody, @@ -435,7 +435,7 @@ export default class EasyPostClient { Object.assign(requestHeaders, headersToSet); return compatibilityRequest; }, - auth: (key) => { + auth: (key: string) => { requestHeaders.Authorization = `Basic ${EasyPostClient._toBase64(`${key}:`)}`; return compatibilityRequest; }, @@ -446,7 +446,7 @@ export default class EasyPostClient { compatibilityRequest.url = url.toString(); return compatibilityRequest; }, - send: (body = {}) => { + send: (body: Record = {}) => { compatibilityRequest._data = body; return compatibilityRequest; }, @@ -466,7 +466,7 @@ export default class EasyPostClient { } } - let middlewareResponse; + let middlewareResponse: any; if ( this.requestMiddleware && diff --git a/src/services/address_service.ts b/src/services/address_service.ts index 393388f2c..f536f217e 100644 --- a/src/services/address_service.ts +++ b/src/services/address_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; import Address from '../models/address'; +import type EasyPostClient from '../easypost'; type AddressCreateParameters = Record & { name?: string | null; @@ -23,7 +24,7 @@ type AddressCreateParameters = Record & { type PaginationCollection = Record; type AddressCollection = { addresses: Address[]; has_more: boolean }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The AddressService class provides methods for interacting with EasyPost {@link Address} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/api_key_service.ts b/src/services/api_key_service.ts index cd63025f9..2674e1f26 100644 --- a/src/services/api_key_service.ts +++ b/src/services/api_key_service.ts @@ -1,4 +1,5 @@ import util from 'util'; +import type EasyPostClient from '../easypost'; import Constants from '../constants'; import FilteringError from '../errors/general/filtering_error'; @@ -12,7 +13,7 @@ type ApiKeyUser = Record & { }; type ApiKeyAllResponse = Record; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The ApiKeyService class provides methods for interacting with EasyPost {@link ApiKey} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/base_service.ts b/src/services/base_service.ts index aeda360c9..adbbd0f5d 100644 --- a/src/services/base_service.ts +++ b/src/services/base_service.ts @@ -99,7 +99,7 @@ const RESOURCES = { Webhook, }; -export default (easypostClient) => +export default (easypostClient: any) => /** * The base class for all EasyPost client library services. * @param {EasyPostClient} easypostClient The {@link EasyPostClient} instance to use for API calls. @@ -112,13 +112,13 @@ export default (easypostClient) => * @param {*} response The value to serialize. * @returns {*} A plain object/array/scalar. */ - static _toPlainEasyPostObject(response) { + static _toPlainEasyPostObject(response: any): any { if (Array.isArray(response)) { return response.map((value) => this._toPlainEasyPostObject(value)); } if (typeof response === 'object' && response !== null) { - const plainObject = {}; + const plainObject: Record = {}; const prototype = Object.getPrototypeOf(response); if (prototype && prototype !== Object.prototype) { @@ -145,8 +145,10 @@ export default (easypostClient) => }); } - Object.keys(response).forEach((key) => { - plainObject[key] = this._toPlainEasyPostObject(response[key]); + Object.keys(response as Record).forEach((key) => { + plainObject[key] = this._toPlainEasyPostObject( + (response as Record)[key], + ); }); return plainObject; @@ -162,7 +164,7 @@ export default (easypostClient) => * @param {*} params The parameters passed when fetching the response. * @returns {*} An {@link EasyPostObject}-based class instance or an `Array` of {@link EasyPostObject}-based class instances. */ - static _buildEasyPostObject(response, params) { + static _buildEasyPostObject(response: any, params: any): any { if (Array.isArray(response)) { return response.map((value) => { if (typeof value === 'object') { @@ -173,23 +175,26 @@ export default (easypostClient) => } if (typeof response === 'object' && response !== null) { - let classObject; - if (RESOURCES[response.object] !== undefined) { - classObject = new RESOURCES[response.object](); + const responseRecord = response as Record; + let classObject: any; + if ((RESOURCES as Record)[responseRecord.object] !== undefined) { + classObject = new (RESOURCES as Record)[responseRecord.object](); } else if ( - response.id !== undefined && - EASYPOST_OBJECT_ID_PREFIX_TO_CLASS_NAME_MAP[ - response.id.substr(0, response.id.indexOf('_')) + responseRecord.id !== undefined && + (EASYPOST_OBJECT_ID_PREFIX_TO_CLASS_NAME_MAP as Record)[ + responseRecord.id.substr(0, responseRecord.id.indexOf('_')) ] !== undefined ) { - const className = response.id.substr(0, response.id.indexOf('_')); - classObject = new EASYPOST_OBJECT_ID_PREFIX_TO_CLASS_NAME_MAP[className](); + const className = responseRecord.id.substr(0, responseRecord.id.indexOf('_')); + classObject = new (EASYPOST_OBJECT_ID_PREFIX_TO_CLASS_NAME_MAP as Record)[ + className + ](); } else { classObject = new EasyPostObject(); } - Object.keys(response).forEach((key) => { - classObject[key] = this._buildEasyPostObject(response[key], params); + Object.keys(responseRecord).forEach((key) => { + classObject[key] = this._buildEasyPostObject(responseRecord[key], params); }); classObject._params = params; @@ -220,7 +225,7 @@ export default (easypostClient) => * @param {Object} params The parameters to send with the API request. * @returns {EasyPostObject|Promise} The created {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async _create(url, params) { + static async _create(url: string, params: any) { try { const response = await easypostClient._post(url, params); @@ -237,7 +242,7 @@ export default (easypostClient) => * @param {Object} [params] The parameters to send with the API request. * @returns {EasyPostObject|EasyPostObject[]|Promise} The retrieved {@link EasyPostObject}-based class instance(s), or a `Promise` that rejects with an error. */ - static async _all(url, params = {}) { + static async _all(url: string, params: any = {}) { try { // eslint-disable-next-line no-param-reassign const response = await easypostClient._get(url, params); @@ -254,7 +259,7 @@ export default (easypostClient) => * @param {string} url The URL to send the API request to. * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async _retrieve(url) { + static async _retrieve(url: string) { try { const response = await easypostClient._get(url); diff --git a/src/services/batch_service.ts b/src/services/batch_service.ts index f2af3ec3e..9734a61c5 100644 --- a/src/services/batch_service.ts +++ b/src/services/batch_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; import Batch from '../models/batch'; +import type EasyPostClient from '../easypost'; export const DEFAULT_LABEL_FORMAT = 'pdf'; @@ -8,7 +9,7 @@ type BatchCreateParameters = Record & { }; type BatchListResponse = { batches: Batch[]; has_more: boolean }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The BatchService class provides methods for interacting with EasyPost {@link Batch} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/beta_rate_service.ts b/src/services/beta_rate_service.ts index bca4f3bb7..a3ce9c224 100644 --- a/src/services/beta_rate_service.ts +++ b/src/services/beta_rate_service.ts @@ -1,16 +1,17 @@ import baseService from './base_service'; +import type EasyPostClient from '../easypost'; /** * @extends baseService */ -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => class BetaRateService extends baseService(easypostClient) { /** * Retrieve a list of stateless {@link Rate rates} based on the provided parameters. * @param {Object} params - Map of parameters for the API call * @returns {Rate[]} - List of stateless rates */ - static async retrieveStatelessRates(params) { + static async retrieveStatelessRates(params: Record) { const url = 'beta/rates'; const wrappedParams = { shipment: params, diff --git a/src/services/beta_referral_customer_service.ts b/src/services/beta_referral_customer_service.ts index 087e78037..8ea2bc154 100644 --- a/src/services/beta_referral_customer_service.ts +++ b/src/services/beta_referral_customer_service.ts @@ -1,10 +1,11 @@ import baseService from './base_service'; +import type EasyPostClient from '../easypost'; type BetaPaymentMethodResponse = Record; type BetaRefundResponse = Record; type BetaClientSecretResponse = Record; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => class BetaReferralCustomerService extends baseService(easypostClient) { /** * Add an existing Stripe payment method to a {@link User referral customer's} account. @@ -74,7 +75,10 @@ export default (easypostClient) => static async createCreditCardClientSecret(): Promise { const url = 'beta/setup_intents'; - const response = await easypostClient._post(url, null); + // Preserve legacy null payload behavior for cassette matching in tests. + const emptyPayload = null as unknown as Record; + + const response = await easypostClient._post(url, emptyPayload); return response.body; } @@ -86,7 +90,9 @@ export default (easypostClient) => static async createBankAccountClientSecret( returnUrl: string | null, ): Promise { - const params = returnUrl ? { return_url: returnUrl } : null; + const params = returnUrl + ? { return_url: returnUrl } + : (null as unknown as Record); const url = 'beta/financial_connections_sessions'; diff --git a/src/services/billing_service.ts b/src/services/billing_service.ts index 0b480ddb0..4c32e9bbf 100644 --- a/src/services/billing_service.ts +++ b/src/services/billing_service.ts @@ -1,6 +1,7 @@ import Constants from '../constants'; import InvalidObjectError from '../errors/general/invalid_object_error'; import baseService from './base_service'; +import type EasyPostClient from '../easypost'; type PaymentMethodObject = { id: string; @@ -13,7 +14,7 @@ type PaymentMethodsResponse = Record & { secondary_payment_method?: PaymentMethodObject | null; }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The BillingService class provides methods for interacting with EasyPost's billing capabilities. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/carrier_account_service.ts b/src/services/carrier_account_service.ts index a01130645..b250ba829 100644 --- a/src/services/carrier_account_service.ts +++ b/src/services/carrier_account_service.ts @@ -1,4 +1,5 @@ import util from 'util'; +import type EasyPostClient from '../easypost'; import Constants from '../constants'; import InvalidParameterError from '../errors/general/invalid_parameter_error'; @@ -17,7 +18,7 @@ type CarrierAccountCreateParameters = Record & { billing_type?: string | null; }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The CarrierAccountService class provides methods for interacting with EasyPost @{link CarrierAccount} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/carrier_metadata_service.ts b/src/services/carrier_metadata_service.ts index b622e3592..6fd8df1ff 100644 --- a/src/services/carrier_metadata_service.ts +++ b/src/services/carrier_metadata_service.ts @@ -1,11 +1,12 @@ import baseService from './base_service'; +import type EasyPostClient from '../easypost'; type CarrierMetadata = Record; /** * @extends baseService */ -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => class CarrierMetadataService extends baseService(easypostClient) { /** * Retrieve a list of carrier metadata based on the provided parameters. diff --git a/src/services/carrier_type_service.ts b/src/services/carrier_type_service.ts index 9b19adc82..5a3e93280 100644 --- a/src/services/carrier_type_service.ts +++ b/src/services/carrier_type_service.ts @@ -1,7 +1,8 @@ import baseService from './base_service'; import CarrierType from '../models/carrier_type'; +import type EasyPostClient from '../easypost'; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The CarrierTypeService class provides methods for interacting with EasyPost {@link CarrierType} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/claim_service.ts b/src/services/claim_service.ts index 08e49806a..32b0ec320 100644 --- a/src/services/claim_service.ts +++ b/src/services/claim_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; import Claim from '../models/claim'; +import type EasyPostClient from '../easypost'; type ClaimCreateParameters = Record & { tracking_code?: string | null; @@ -16,7 +17,7 @@ type ClaimCreateParameters = Record & { type ClaimCollection = Record; type ClaimListResponse = { claims: Claim[]; has_more: boolean }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The ClaimService class provides methods for interacting with EasyPost {@link Claim} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/customer_portal_service.ts b/src/services/customer_portal_service.ts index da4f1377a..ba30ecd56 100644 --- a/src/services/customer_portal_service.ts +++ b/src/services/customer_portal_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; -import type { ICustomerPortalAccountLink } from '../../types/CustomerPortal/CustomerPortalAccountLink'; +import type EasyPostClient from '../easypost'; +type ICustomerPortalAccountLink = Record; type CustomerPortalAccountLinkCreateParameters = Record & { session_type?: 'account_onboarding' | 'account_management' | null; @@ -9,7 +10,7 @@ type CustomerPortalAccountLinkCreateParameters = Record & { metadata?: Record | null; }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The CustomerPortalService class provides methods for interacting with EasyPost {@link Tracker} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/customs_info_service.ts b/src/services/customs_info_service.ts index c7693e892..14a6ccb60 100644 --- a/src/services/customs_info_service.ts +++ b/src/services/customs_info_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; import CustomsInfo from '../models/customs_info'; +import type EasyPostClient from '../easypost'; type CustomsItemInput = Record; @@ -16,7 +17,7 @@ type CustomsInfoCreateParameters = Record & { declaration?: string | null; }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The CustomsInfoService class provides methods for interacting with EasyPost {@link CustomsInfo} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/customs_item_service.ts b/src/services/customs_item_service.ts index 0b2d0087e..b0337e40a 100644 --- a/src/services/customs_item_service.ts +++ b/src/services/customs_item_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; import CustomsItem from '../models/customs_item'; +import type EasyPostClient from '../easypost'; type CustomsItemCreateParameters = Record & { description?: string | null; @@ -12,7 +13,7 @@ type CustomsItemCreateParameters = Record & { currency?: string | null; }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The CustomsItemService class provides methods for interacting with EasyPost {@link CustomsItem} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/embeddable_service.ts b/src/services/embeddable_service.ts index cf999338d..061d2e9fa 100644 --- a/src/services/embeddable_service.ts +++ b/src/services/embeddable_service.ts @@ -1,12 +1,13 @@ import baseService from './base_service'; -import type { IEmbeddablesSession } from '../../types/Embeddable/EmbeddablesSession'; +import type EasyPostClient from '../easypost'; +type IEmbeddablesSession = Record; type EmbeddablesSessionCreateParameters = Record & { origin_host?: string | null; user_id?: string | null; }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The EmbeddableService class provides methods for interacting with EasyPost {@link Tracker} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/end_shipper_service.ts b/src/services/end_shipper_service.ts index 0831e375b..43afebd9b 100644 --- a/src/services/end_shipper_service.ts +++ b/src/services/end_shipper_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; import EndShipper from '../models/end_shipper'; +import type EasyPostClient from '../easypost'; type EndShipperCreateParameters = Record & { name?: string | null; @@ -15,7 +16,7 @@ type EndShipperCreateParameters = Record & { }; type EndShipperListResponse = { end_shippers: EndShipper[]; has_more: boolean }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The EndShipperService class provides methods for interacting with EasyPost {@link EndShipper} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/event_service.ts b/src/services/event_service.ts index 7b2bdd200..9ac46095c 100644 --- a/src/services/event_service.ts +++ b/src/services/event_service.ts @@ -1,11 +1,12 @@ import baseService from './base_service'; import Event from '../models/event'; import Payload from '../models/payload'; +import type EasyPostClient from '../easypost'; type EventCollection = Record; type EventListResponse = { events: Event[]; has_more: boolean }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The EventService class provides methods for interacting with EasyPost {@link Event} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/fedex_registration_service.ts b/src/services/fedex_registration_service.ts index 5207cfb54..a5d6fa4c9 100644 --- a/src/services/fedex_registration_service.ts +++ b/src/services/fedex_registration_service.ts @@ -1,10 +1,9 @@ import { v4 as uuid } from 'uuid'; - -import type { - IFedExAccountValidationResponse, - IFedExRequestPinResponse, -} from '../../types/FedExRegistration/FedExRegistration'; import baseService from './base_service'; +import type EasyPostClient from '../easypost'; + +type IFedExAccountValidationResponse = Record; +type IFedExRequestPinResponse = Record; type FedExValidationMap = Record & { name?: string | null }; type FedExParams = Record & { @@ -14,7 +13,7 @@ type FedExParams = Record & { easypost_details?: Record; }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The FedExRegistrationService class provides methods for registering FedEx carrier accounts with MFA. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/insurance_service.ts b/src/services/insurance_service.ts index 67385e9c9..68c7c6598 100644 --- a/src/services/insurance_service.ts +++ b/src/services/insurance_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; import Insurance from '../models/insurance'; +import type EasyPostClient from '../easypost'; type InsuranceCreateParameters = Record & { reference?: string | null; @@ -12,7 +13,7 @@ type InsuranceCreateParameters = Record & { type InsuranceCollection = Record; type InsuranceListResponse = { insurances: Insurance[]; has_more: boolean }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The InsuranceService class provides methods for interacting with EasyPost {@link Insurance} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/luma_service.ts b/src/services/luma_service.ts index 526904e51..84fb74cf2 100644 --- a/src/services/luma_service.ts +++ b/src/services/luma_service.ts @@ -1,9 +1,10 @@ import baseService from './base_service'; -import type { ILumaPromise } from '../../types/Luma/Luma'; +import type EasyPostClient from '../easypost'; +type ILumaPromise = Record; type LumaParams = Record; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The LumaService class provides methods for interacting with EasyPost Luma objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/order_service.ts b/src/services/order_service.ts index 1e39089ac..b35b0468c 100644 --- a/src/services/order_service.ts +++ b/src/services/order_service.ts @@ -1,6 +1,7 @@ import baseService from './base_service'; import Order from '../models/order'; import Rate from '../models/rate'; +import type EasyPostClient from '../easypost'; type OrderCreateParameters = Record & { reference?: string | null; @@ -11,7 +12,7 @@ type OrderCreateParameters = Record & { }; type OrderRatesResponse = { rates: Rate[] }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The OrderService class provides methods for interacting with EasyPost {@link Order} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/parcel_service.ts b/src/services/parcel_service.ts index 00a7a9c69..dcf24a676 100644 --- a/src/services/parcel_service.ts +++ b/src/services/parcel_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; import Parcel from '../models/parcel'; +import type EasyPostClient from '../easypost'; type ParcelCreateParameters = Record & { length?: number | null; @@ -9,7 +10,7 @@ type ParcelCreateParameters = Record & { predefined_package?: string | null; }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The ParcelService class provides methods for interacting with EasyPost {@link Parcel} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/pickup_service.ts b/src/services/pickup_service.ts index 0aaf7b8dc..4a9652c8d 100644 --- a/src/services/pickup_service.ts +++ b/src/services/pickup_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; import Pickup from '../models/pickup'; +import type EasyPostClient from '../easypost'; type PickupCreateParameters = Record & { address?: Record | string | null; @@ -18,7 +19,7 @@ type PickupCreateParameters = Record & { type PickupCollection = Record; type PickupListResponse = { pickups: Pickup[]; has_more: boolean }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The PickupService class provides methods for interacting with EasyPost {@link Pickup} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/rate_service.ts b/src/services/rate_service.ts index 2b0184119..2957c848f 100644 --- a/src/services/rate_service.ts +++ b/src/services/rate_service.ts @@ -1,7 +1,8 @@ import baseService from './base_service'; import Rate from '../models/rate'; +import type EasyPostClient from '../easypost'; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The RateService class provides methods for interacting with EasyPost {@link Rate} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/referral_customer_service.ts b/src/services/referral_customer_service.ts index e43e8df9c..8b99f3ae2 100644 --- a/src/services/referral_customer_service.ts +++ b/src/services/referral_customer_service.ts @@ -4,8 +4,8 @@ import Constants from '../constants'; import EasyPostClient from '../easypost'; import ExternalApiError from '../errors/api/external_api_error'; import User from '../models/user'; -import type { IPaymentMethod } from '../../types/PaymentMethod/PaymentMethod'; import baseService from './base_service'; +type IPaymentMethod = Record; type ReferralCreateParameters = Record & { reference?: string | null; @@ -137,7 +137,7 @@ async function _sendCardDetailsToEasyPost( return response.body; } -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The ReferralCustomerService class provides methods for interacting with EasyPost {@link User referral customer} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/refund_service.ts b/src/services/refund_service.ts index 745b7ce04..804162342 100644 --- a/src/services/refund_service.ts +++ b/src/services/refund_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; import Refund from '../models/refund'; +import type EasyPostClient from '../easypost'; type RefundCreateParameters = Record & { carrier?: string | null; @@ -8,7 +9,7 @@ type RefundCreateParameters = Record & { type RefundCollection = Record; type RefundListResponse = { refunds: Refund[]; has_more: boolean }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The RefundService class provides methods for interacting with EasyPost {@link Refund} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/report_service.ts b/src/services/report_service.ts index 7e3830a76..e3b3dac66 100644 --- a/src/services/report_service.ts +++ b/src/services/report_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; import Report from '../models/report'; +import type EasyPostClient from '../easypost'; type ReportCreateParameters = Record & { type: string; @@ -10,11 +11,11 @@ type ReportAllParameters = Record & { }; type ReportCollection = Record & { - reports?: Array>; + reports?: Array>; }; type ReportListResponse = { reports: Report[]; has_more: boolean }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The ReportService class provides methods for interacting with EasyPost {@link Report} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -67,7 +68,8 @@ export default (easypostClient) => reports: ReportCollection, pageSize: number | null = null, ): Promise { - const url = `reports/${reports.reports?.[0]?._params?.type || ''}`; + const firstReport = reports.reports?.[0] as { _params?: { type?: string } } | undefined; + const url = `reports/${firstReport?._params?.type || ''}`; return this._getNextPage(url, 'reports', reports, pageSize); } diff --git a/src/services/scan_form_service.ts b/src/services/scan_form_service.ts index f8c84d5f0..bb0673eae 100644 --- a/src/services/scan_form_service.ts +++ b/src/services/scan_form_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; import ScanForm from '../models/scan_form'; +import type EasyPostClient from '../easypost'; type ScanFormCreateParameters = Record & { shipments?: Array> | null; @@ -7,7 +8,7 @@ type ScanFormCreateParameters = Record & { type ScanFormCollection = Record; type ScanFormListResponse = { scan_forms: ScanForm[]; has_more: boolean }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The ScanFormService class provides methods for interacting with EasyPost {@link ScanForm} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/shipment_service.ts b/src/services/shipment_service.ts index 3cf34fa0a..e30823f07 100644 --- a/src/services/shipment_service.ts +++ b/src/services/shipment_service.ts @@ -2,6 +2,7 @@ import Constants from '../constants'; import baseService from './base_service'; import Rate from '../models/rate'; import Shipment from '../models/shipment'; +import type EasyPostClient from '../easypost'; type AddressCreateInput = Record & { verify?: boolean | string | string[] | null; @@ -44,8 +45,12 @@ type ShipmentRateInput = string | { id: string }; type ShipmentCollection = Record; type ShipmentListResponse = { shipments: Shipment[]; has_more: boolean }; type ShipmentSmartRateResponse = Array>; +type SmartRate = { + rate: string; + time_in_transit: Record; +}; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The ShipmentService class provides methods for interacting with EasyPost {@link Shipment} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. @@ -158,7 +163,7 @@ export default (easypostClient) => * @param {string} id - The ID of the shipment to get SmartRates for. * @returns {Rate[]} - The SmartRates for the shipment. */ - static async getSmartRates(id: string): Promise { + static async getSmartRates(id: string): Promise { const url = `shipments/${id}/smartrate`; try { @@ -250,7 +255,7 @@ export default (easypostClient) => deliveryDays: number, deliveryAccuracy: string, ): Promise { - const smartRates = (await this.getSmartRates(id)) as any[]; + const smartRates = (await this.getSmartRates(id)) as SmartRate[]; return Constants.Utils.getLowestSmartRate( smartRates, deliveryDays, diff --git a/src/services/smart_rate_service.ts b/src/services/smart_rate_service.ts index 9362f7297..e1ad45043 100644 --- a/src/services/smart_rate_service.ts +++ b/src/services/smart_rate_service.ts @@ -1,9 +1,10 @@ import baseService from './base_service'; +import type EasyPostClient from '../easypost'; type SmartRateParams = Record; type SmartRateResult = { results: Array> }; -export default (easypostClient) => +export default (easypostClient: 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. diff --git a/src/services/tracker_service.ts b/src/services/tracker_service.ts index e5fabba33..0c68fe9a0 100644 --- a/src/services/tracker_service.ts +++ b/src/services/tracker_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; import Tracker from '../models/tracker'; +import type EasyPostClient from '../easypost'; type TrackerCreateParameters = Record & { tracking_code?: string | null; @@ -8,7 +9,7 @@ type TrackerCreateParameters = Record & { type TrackerCollection = Record; type TrackerListResponse = { trackers: Tracker[]; has_more: boolean }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The TrackerService class provides methods for interacting with EasyPost {@link Tracker} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/user_service.ts b/src/services/user_service.ts index a52a9ec58..c923496ad 100644 --- a/src/services/user_service.ts +++ b/src/services/user_service.ts @@ -2,6 +2,7 @@ import EndOfPaginationError from '../errors/general/end_of_pagination_error'; import Brand from '../models/brand'; import User from '../models/user'; import baseService from './base_service'; +import type EasyPostClient from '../easypost'; type UserCreateParameters = Record & { reference?: string | null; @@ -26,7 +27,7 @@ type UserCollection = Record & { _params?: Record; }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The UserService class provides methods for interacting with EasyPost {@link User} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/src/services/webhook_service.ts b/src/services/webhook_service.ts index bc665d0d1..32b9de3cb 100644 --- a/src/services/webhook_service.ts +++ b/src/services/webhook_service.ts @@ -1,5 +1,6 @@ import baseService from './base_service'; import Webhook from '../models/webhook'; +import type EasyPostClient from '../easypost'; type WebhookListResponse = { webhooks: Webhook[]; has_more?: boolean }; @@ -9,7 +10,7 @@ type WebhookCreateParameters = Record & { custom_headers?: Array<{ key?: string | null; value?: string | null }> | null; }; -export default (easypostClient) => +export default (easypostClient: EasyPostClient) => /** * The WebhookService class provides methods for interacting with EasyPost {@link Webhook} objects. * @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service. diff --git a/test/services/address.test.ts b/test/services/address.test.ts index 25e5f3521..126234e15 100644 --- a/test/services/address.test.ts +++ b/test/services/address.test.ts @@ -17,7 +17,7 @@ type AddressTestCreateAndVerifyInput = Parameters< /* eslint-disable func-names */ describe('Address Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); @@ -111,7 +111,7 @@ describe('Address Service', function () { expect(addressesArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(addresses.has_more).to.exist; - addressesArray.forEach((address) => { + addressesArray.forEach((address: any) => { expect(address).to.be.an.instanceOf(Address); }); }); @@ -146,7 +146,7 @@ describe('Address Service', function () { const addressData = Fixture.incorrectAddress() as AddressTestCreateAndVerifyInput; // Creates with verify = true behind the scenes, will throw an error if the address cannot be verified - return client.Address.createAndVerify(addressData).catch((err) => + return client.Address.createAndVerify(addressData).catch((err: any) => expect(err).to.be.an.instanceOf(InvalidRequestError), ); }); @@ -163,7 +163,7 @@ describe('Address Service', function () { it('throws an error when we cannot verify an address', async function () { const address = await client.Address.create({ street1: 'invalid' }); - return client.Address.verifyAddress(address.id).catch((err) => + return client.Address.verifyAddress(address.id).catch((err: any) => expect(err).to.be.an.instanceOf(InvalidRequestError), ); }); @@ -186,7 +186,7 @@ describe('Address Service', function () { addressData.verify_carrier = 'UPS'; - return client.Address.createAndVerify(addressData).catch((err) => + return client.Address.createAndVerify(addressData).catch((err: any) => expect(err).to.be.an.instanceOf(InvalidRequestError), ); }); diff --git a/test/services/api_key.test.ts b/test/services/api_key.test.ts index 66a586719..e46b5bd2f 100644 --- a/test/services/api_key.test.ts +++ b/test/services/api_key.test.ts @@ -8,7 +8,7 @@ import * as setupPolly from '../helpers/setup_polly'; describe('ApiKey Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_PROD_API_KEY); @@ -40,7 +40,7 @@ describe('ApiKey Service', function () { it('retrieves all apiKeys', async function () { const apiKeys = await client.ApiKey.all(); - apiKeys.keys.forEach((apiKey) => { + apiKeys.keys.forEach((apiKey: any) => { expect(apiKey).to.be.an.instanceOf(ApiKey); }); }); diff --git a/test/services/base_service.test.ts b/test/services/base_service.test.ts index 8418dc6c8..a606f8ab1 100644 --- a/test/services/base_service.test.ts +++ b/test/services/base_service.test.ts @@ -22,7 +22,7 @@ describe('Base Service', function () { it('getNextPage collects all pages', async function () { const pageSize = 1; // Doesn't matter what this is, we're mocking the response - let allResults = []; + let allResults: any[] = []; let previousPage = null; // Using scanforms as an example, but this should work for any service since it's a base class method @@ -35,7 +35,7 @@ describe('Base Service', function () { ], has_more: true, }; - let middleware = (request) => { + let middleware = (request: any) => { return new MockMiddleware(request, [ new MockRequest( new MockRequestMatchRule('GET', 'v2\\/scan_forms'), @@ -61,7 +61,7 @@ describe('Base Service', function () { ], has_more: true, }; - middleware = (request) => { + middleware = (request: any) => { return new MockMiddleware(request, [ new MockRequest( new MockRequestMatchRule('GET', 'v2\\/scan_forms'), @@ -87,7 +87,7 @@ describe('Base Service', function () { ], has_more: false, }; - middleware = (request) => { + middleware = (request: any) => { return new MockMiddleware(request, [ new MockRequest( new MockRequestMatchRule('GET', 'v2\\/scan_forms'), @@ -132,7 +132,7 @@ describe('Base Service', function () { ], has_more: true, }; - let middleware = (request) => { + let middleware = (request: any) => { return new MockMiddleware(request, [ new MockRequest( new MockRequestMatchRule('GET', 'v2\\/scan_forms'), @@ -157,7 +157,7 @@ describe('Base Service', function () { ], has_more: true, }; - middleware = (request) => { + middleware = (request: any) => { return new MockMiddleware(request, [ new MockRequest( new MockRequestMatchRule('GET', 'v2\\/scan_forms'), diff --git a/test/services/batch.test.ts b/test/services/batch.test.ts index 3742ecfc0..eb6cf8d64 100644 --- a/test/services/batch.test.ts +++ b/test/services/batch.test.ts @@ -15,7 +15,7 @@ type ShipmentTestCreateInput = Parameters { + addressesArray.forEach((batch: any) => { expect(batch).to.be.an.instanceOf(Batch); }); }); diff --git a/test/services/beta_rate.test.ts b/test/services/beta_rate.test.ts index 846ed5a9e..85716a529 100644 --- a/test/services/beta_rate.test.ts +++ b/test/services/beta_rate.test.ts @@ -14,7 +14,7 @@ type BetaRateRetrieveInput = Parameters< /* eslint-disable func-names */ describe('BetaRateService', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); @@ -30,7 +30,7 @@ describe('BetaRateService', function () { Fixture.basicShipment() as BetaRateRetrieveInput, ); - statelessRates.forEach((rate) => { + statelessRates.forEach((rate: any) => { expect(rate).to.be.an.instanceOf(Rate); expect(rate).to.not.have.property('id'); }); diff --git a/test/services/beta_referral_customer.test.ts b/test/services/beta_referral_customer.test.ts index b77899b91..a83bf6ed5 100644 --- a/test/services/beta_referral_customer.test.ts +++ b/test/services/beta_referral_customer.test.ts @@ -5,7 +5,7 @@ import * as setupPolly from '../helpers/setup_polly'; describe('BetaReferralCustomerService', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { const referralCustomerProdApiKey = process.env.REFERRAL_CUSTOMER_PROD_API_KEY || '123'; @@ -18,7 +18,7 @@ describe('BetaReferralCustomerService', function () { }); it('add payment method to a referral customer account', async function () { - await client.BetaReferralCustomer.addPaymentMethod('cus_123', 'ba_123').catch((error) => { + await client.BetaReferralCustomer.addPaymentMethod('cus_123', 'ba_123').catch((error: any) => { expect(error.statusCode).to.equal(422); expect(error.code).to.equal('BILLING.INVALID_PAYMENT_GATEWAY_REFERENCE'); expect(error.message).to.equal('Invalid connect integration.'); @@ -26,7 +26,7 @@ describe('BetaReferralCustomerService', function () { }); it('Refund by amount for a recent payment', async function () { - await client.BetaReferralCustomer.refundByAmount(2000).catch((error) => { + await client.BetaReferralCustomer.refundByAmount(2000).catch((error: any) => { expect(error.statusCode).to.equal(422); expect(error.code).to.equal('TRANSACTION.AMOUNT_INVALID'); expect(error.message).to.equal( @@ -36,7 +36,7 @@ describe('BetaReferralCustomerService', function () { }); it('Refund a payment by a payment log ID', async function () { - await client.BetaReferralCustomer.refundByPaymentLog('paylog_...').catch((error) => { + await client.BetaReferralCustomer.refundByPaymentLog('paylog_...').catch((error: any) => { expect(error.statusCode).to.equal(422); expect(error.code).to.equal('TRANSACTION.DOES_NOT_EXIST'); expect(error.message).to.equal('We could not find a transaction with that id.'); diff --git a/test/services/billing.test.ts b/test/services/billing.test.ts index e50861bfa..4ae5ca116 100644 --- a/test/services/billing.test.ts +++ b/test/services/billing.test.ts @@ -9,7 +9,7 @@ import { MockRequestResponseInfo, } from '../helpers/mocking'; -const middleware = (request) => { +const middleware = (request: any) => { return new MockMiddleware(request, [ new MockRequest( new MockRequestMatchRule('POST', 'v2\\/bank_accounts\\/\\S*\\/charges$'), @@ -47,7 +47,7 @@ const middleware = (request) => { }; describe('Billing Service', function () { - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY, { diff --git a/test/services/carrier_account.test.ts b/test/services/carrier_account.test.ts index 93b6b6a8a..c8974914c 100644 --- a/test/services/carrier_account.test.ts +++ b/test/services/carrier_account.test.ts @@ -15,7 +15,7 @@ type CarrierAccountTestCreateInput = Parameters< /* eslint-disable func-names */ describe('CarrierAccount Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_PROD_API_KEY); @@ -87,7 +87,7 @@ describe('CarrierAccount Service', function () { it('retrieves all carrier accounts', async function () { const carrierAccounts = await client.CarrierAccount.all(); - carrierAccounts.forEach((carrierAccount) => { + carrierAccounts.forEach((carrierAccount: any) => { expect(carrierAccount).to.be.an.instanceOf(CarrierAccount); }); }); @@ -143,7 +143,7 @@ describe('CarrierAccount Service', function () { ); await client.CarrierAccount.delete(carrierAccount.id).then( - expect(function (result) { + expect(function (result: any) { result.not.to.throw(); }), ); diff --git a/test/services/carrier_metadata.test.ts b/test/services/carrier_metadata.test.ts index 41d90eb18..56390ef59 100644 --- a/test/services/carrier_metadata.test.ts +++ b/test/services/carrier_metadata.test.ts @@ -6,7 +6,7 @@ import * as setupPolly from '../helpers/setup_polly'; /* eslint-disable func-names */ describe('CarrierMetadataService', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); @@ -20,8 +20,8 @@ describe('CarrierMetadataService', function () { it('retrieves all carrier metadata', async function () { const carrierMetadata = await client.CarrierMetadata.retrieve(); - expect(carrierMetadata.some((carrier) => carrier.name === 'usps')).to.be.true; - expect(carrierMetadata.some((carrier) => carrier.name === 'fedex')).to.be.true; + expect(carrierMetadata.some((carrier: any) => carrier.name === 'usps')).to.be.true; + expect(carrierMetadata.some((carrier: any) => carrier.name === 'fedex')).to.be.true; }); it('retrieves carrier metadata based on the filters provided', async function () { @@ -30,7 +30,7 @@ describe('CarrierMetadataService', function () { ['service_levels', 'predefined_packages'], ); - expect(carrierMetadata.some((carrier) => carrier.name === 'usps')).to.be.true; + expect(carrierMetadata.some((carrier: any) => carrier.name === 'usps')).to.be.true; expect(carrierMetadata).to.have.lengthOf(1); expect(carrierMetadata[0]).to.have.property('service_levels'); expect(carrierMetadata[0]).to.have.property('predefined_packages'); diff --git a/test/services/carrier_type.test.ts b/test/services/carrier_type.test.ts index b2a578a96..7c51f692d 100644 --- a/test/services/carrier_type.test.ts +++ b/test/services/carrier_type.test.ts @@ -7,7 +7,7 @@ import * as setupPolly from '../helpers/setup_polly'; describe('CarrierType Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_PROD_API_KEY); @@ -21,7 +21,7 @@ describe('CarrierType Service', function () { it('retrieves the carrier account types available', async function () { const carrierTypes = await client.CarrierType.all(); - carrierTypes.forEach((type) => { + carrierTypes.forEach((type: any) => { expect(type).to.be.an.instanceOf(CarrierType); }); }); diff --git a/test/services/claim.test.ts b/test/services/claim.test.ts index 95e060cea..9fd532d69 100644 --- a/test/services/claim.test.ts +++ b/test/services/claim.test.ts @@ -17,7 +17,7 @@ type ShipmentTestCreateInput = Parameters { +const buyTestShipment = async (client: any) => { const shipment = await client.Shipment.create(Fixture.fullShipment() as ShipmentTestCreateInput); const rate = shipment.lowestRate(); @@ -25,7 +25,7 @@ const buyTestShipment = async (client) => { }; /** @param {Client} client */ -const createTestClaim = async (client) => { +const createTestClaim = async (client: any) => { const shipment = await buyTestShipment(client); const claimData = Fixture.basicClaim() as ClaimTestCreateInput; @@ -37,7 +37,7 @@ const createTestClaim = async (client) => { describe('Claim Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); @@ -74,7 +74,7 @@ describe('Claim Service', function () { expect(claimArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(claim.has_more).to.exist; - claimArray.forEach((event) => { + claimArray.forEach((event: any) => { expect(event).to.be.an.instanceOf(Claim); }); }); diff --git a/test/services/customer_portal.test.ts b/test/services/customer_portal.test.ts index 0a17ea80e..b05f62759 100644 --- a/test/services/customer_portal.test.ts +++ b/test/services/customer_portal.test.ts @@ -7,7 +7,7 @@ import * as setupPolly from '../helpers/setup_polly'; describe('CustomerPortal Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_PROD_API_KEY); diff --git a/test/services/customs_info.test.ts b/test/services/customs_info.test.ts index c461a53a8..8d28453a4 100644 --- a/test/services/customs_info.test.ts +++ b/test/services/customs_info.test.ts @@ -14,7 +14,7 @@ type CustomsInfoTestCreateInput = Parameters< describe('CustomsInfo Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); diff --git a/test/services/customs_item.test.ts b/test/services/customs_item.test.ts index 436bb18e4..49f4266fe 100644 --- a/test/services/customs_item.test.ts +++ b/test/services/customs_item.test.ts @@ -2,6 +2,7 @@ import { expect } from 'vitest'; import EasyPost from '../../src/easypost'; +import type EasyPostClient from '../../src/easypost'; import CustomsItem from '../../src/models/customs_item'; import type CustomsItemServiceFactory from '../../src/services/customs_item_service'; import Fixture from '../helpers/fixture'; @@ -14,7 +15,7 @@ type CustomsItemTestCreateInput = Parameters< describe('CustomsItem Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPost(process.env.EASYPOST_TEST_API_KEY); diff --git a/test/services/easypost.test.ts b/test/services/easypost.test.ts index fce583678..239c5ccd0 100644 --- a/test/services/easypost.test.ts +++ b/test/services/easypost.test.ts @@ -11,7 +11,7 @@ type AddressTestCreateInput = Parameters (requestConfig = response); - let responseConfig; - const responseHook = (response) => (responseConfig = response); + let requestConfig: any; + const requestHook = (response: any) => (requestConfig = response); + let responseConfig: any; + const responseHook = (response: any) => (responseConfig = response); client.addRequestHook(requestHook); client.addResponseHook(responseHook); @@ -65,14 +65,14 @@ describe('EasyPost', function () { }); it('will add more than one request and response hook', async function () { - let requestConfig1; - const requestHook1 = (response) => (requestConfig1 = response); - let requestConfig2; - const requestHook2 = (response) => (requestConfig2 = response); - let responseConfig1; - const responseHook1 = (response) => (responseConfig1 = response); - let responseConfig2; - const responseHook2 = (response) => (responseConfig2 = response); + let requestConfig1: any; + const requestHook1 = (response: any) => (requestConfig1 = response); + let requestConfig2: any; + const requestHook2 = (response: any) => (requestConfig2 = response); + let responseConfig1: any; + const responseHook1 = (response: any) => (responseConfig1 = response); + let responseConfig2: any; + const responseHook2 = (response: any) => (responseConfig2 = response); client.addRequestHook(requestHook1); client.addRequestHook(requestHook2); @@ -88,10 +88,10 @@ describe('EasyPost', function () { }); it('will unsubscribe from requests and responses', async function () { - let requestConfig; - const requestHook = (response) => (requestConfig = response); - let responseConfig; - const responseHook = (response) => (responseConfig = response); + let requestConfig: any; + const requestHook = (response: any) => (requestConfig = response); + let responseConfig: any; + const responseHook = (response: any) => (responseConfig = response); client.addRequestHook(requestHook); client.addResponseHook(responseHook); @@ -114,14 +114,14 @@ describe('EasyPost', function () { }); it('will clear all request and response hooks', async function () { - let requestConfig1; - const requestHook1 = (response) => (requestConfig1 = response); - let requestConfig2; - const requestHook2 = (response) => (requestConfig2 = response); - let responseConfig1; - const responseHook1 = (response) => (responseConfig1 = response); - let responseConfig2; - const responseHook2 = (response) => (responseConfig2 = response); + let requestConfig1: any; + const requestHook1 = (response: any) => (requestConfig1 = response); + let requestConfig2: any; + const requestHook2 = (response: any) => (requestConfig2 = response); + let responseConfig1: any; + const responseHook1 = (response: any) => (responseConfig1 = response); + let responseConfig2: any; + const responseHook2 = (response: any) => (responseConfig2 = response); client.addRequestHook(requestHook1); client.addRequestHook(requestHook2); @@ -152,9 +152,9 @@ describe('EasyPost', function () { }); it('makes an API call using the generic makeApiCall method', async function () { - const response = await client.makeApiCall('get', '/addresses', { + const response = (await client.makeApiCall('get', '/addresses', { page_size: 1, - }); + })) as { addresses: Array<{ object: string }> }; expect(response.addresses.length).to.equal(1); expect(response.addresses[0].object).to.equal('Address'); diff --git a/test/services/embeddable.test.ts b/test/services/embeddable.test.ts index 43fe036f7..9e6eb70a3 100644 --- a/test/services/embeddable.test.ts +++ b/test/services/embeddable.test.ts @@ -7,7 +7,7 @@ import * as setupPolly from '../helpers/setup_polly'; describe('Embeddable Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_PROD_API_KEY); diff --git a/test/services/end_shipper.test.ts b/test/services/end_shipper.test.ts index b94154693..d80118ad3 100644 --- a/test/services/end_shipper.test.ts +++ b/test/services/end_shipper.test.ts @@ -11,7 +11,7 @@ type EndShipperUpdateInput = Parameters { + endShippersArray.forEach((endShipper: any) => { expect(endShipper).to.be.an.instanceOf(EndShipper); }); }); diff --git a/test/services/error.test.ts b/test/services/error.test.ts index b44fd550c..2e77c5298 100644 --- a/test/services/error.test.ts +++ b/test/services/error.test.ts @@ -23,7 +23,7 @@ type ClaimTestCreateInput = Parameters['c describe('Error Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); @@ -35,7 +35,7 @@ describe('Error Service', function () { }); it('pulls out error properties of an API error', async function () { - await client.Shipment.create().catch((error) => { + await client.Shipment.create().catch((error: any) => { expect(error.statusCode).to.equal(422); expect(error.code).to.equal('PARAMETER.REQUIRED'); expect(error.message).to.equal('Missing required parameter.'); @@ -46,7 +46,7 @@ describe('Error Service', function () { it('pulls out error properties of an API error when using the alternative format', async function () { const claimData = Fixture.basicClaim() as ClaimTestCreateInput; claimData.tracking_code = '123'; // Intentionally pass a bad tracking code - await client.Claim.create(claimData).catch((error) => { + await client.Claim.create(claimData).catch((error: any) => { expect(error.statusCode).to.equal(404); expect(error.code).to.equal('NOT_FOUND'); expect(error.message).to.equal('The requested resource could not be found.'); @@ -70,7 +70,7 @@ describe('Error Service', function () { throw ErrorHandler.handleApiError(fakeErrorResponse); }) .to.throw(NotFoundError) - .and.satisfy((error) => { + .and.satisfy((error: any) => { expect(error.message).to.be.equal('ERROR_MESSAGE_1, ERROR_MESSAGE_2'); expect(error.code).to.be.equal('NO RESPONSE CODE'); expect(error.errors).to.be.an('array').that.is.empty; @@ -96,7 +96,7 @@ describe('Error Service', function () { throw ErrorHandler.handleApiError(fakeErrorResponse); }) .to.throw(NotFoundError) - .and.satisfy((error) => { + .and.satisfy((error: any) => { expect(error.message).to.be.equal('bad error., second bad error.'); expect(error.code).to.be.equal('NO RESPONSE CODE'); expect(error.errors).to.be.an('array').that.is.empty; @@ -129,7 +129,7 @@ describe('Error Service', function () { throw ErrorHandler.handleApiError(fakeErrorResponse); }) .to.throw(NotFoundError) - .and.satisfy((error) => { + .and.satisfy((error: any) => { expect(error.message).to.be.equal( 'Bad format 1, Bad format 2, Bad format 3, Bad format 4, Bad format 5', ); diff --git a/test/services/event.test.ts b/test/services/event.test.ts index 87191c042..41686ba66 100644 --- a/test/services/event.test.ts +++ b/test/services/event.test.ts @@ -18,7 +18,7 @@ type ShipmentTestCreateInput = Parameters { + eventsArray.forEach((event: any) => { expect(event).to.be.an.instanceOf(Event); }); }); @@ -100,7 +100,7 @@ describe('Event Service', function () { const payloads = await client.Event.retrieveAllPayloads(event.id); - payloads.forEach((payload) => { + payloads.forEach((payload: any) => { expect(payload).to.be.an.instanceOf(Payload); }); diff --git a/test/services/fedex_registration.test.ts b/test/services/fedex_registration.test.ts index 9fe19d186..b2d0b8c96 100644 --- a/test/services/fedex_registration.test.ts +++ b/test/services/fedex_registration.test.ts @@ -36,7 +36,7 @@ describe('FedExRegistrationService', function () { phone_number: '***-***-9721', }; - const middleware = (request) => { + const middleware = (request: any) => { return new MockMiddleware(request, [ new MockRequest( new MockRequestMatchRule( @@ -74,7 +74,7 @@ describe('FedExRegistrationService', function () { message: 'sent secured Pin', }; - const middleware = (request) => { + const middleware = (request: any) => { return new MockMiddleware(request, [ new MockRequest( new MockRequestMatchRule( @@ -121,7 +121,7 @@ describe('FedExRegistrationService', function () { }, }; - const middleware = (request) => { + const middleware = (request: any) => { return new MockMiddleware(request, [ new MockRequest( new MockRequestMatchRule( @@ -175,7 +175,7 @@ describe('FedExRegistrationService', function () { }, }; - const middleware = (request) => { + const middleware = (request: any) => { return new MockMiddleware(request, [ new MockRequest( new MockRequestMatchRule( diff --git a/test/services/insurance.test.ts b/test/services/insurance.test.ts index 843287fbb..b0d72b0e8 100644 --- a/test/services/insurance.test.ts +++ b/test/services/insurance.test.ts @@ -14,7 +14,7 @@ type ShipmentTestCreateInput = Parameters { + insuranceArray.forEach((event: any) => { expect(event).to.be.an.instanceOf(Insurance); }); }); diff --git a/test/services/luma.test.ts b/test/services/luma.test.ts index 89c96e6e6..e321fc23c 100644 --- a/test/services/luma.test.ts +++ b/test/services/luma.test.ts @@ -10,7 +10,7 @@ type LumaTestGetPromiseInput = Parameters[ /* eslint-disable func-names */ describe('Luma Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); diff --git a/test/services/order.test.ts b/test/services/order.test.ts index 31aa51565..12ac039be 100644 --- a/test/services/order.test.ts +++ b/test/services/order.test.ts @@ -13,7 +13,7 @@ type OrderTestCreateInput = Parameters['c describe('Order Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); @@ -49,7 +49,7 @@ describe('Order Service', function () { const ratesArray = rates.rates; expect(ratesArray).to.be.an.instanceOf(Array); - ratesArray.forEach((rate) => { + ratesArray.forEach((rate: any) => { expect(rate).to.be.an.instanceOf(Rate); }); }); @@ -61,7 +61,7 @@ describe('Order Service', function () { const shipmentsArray = boughtOrder.shipments; - shipmentsArray.forEach((shipment) => { + shipmentsArray.forEach((shipment: any) => { expect(shipment.postage_label).to.exist; }); }); diff --git a/test/services/parcel.test.ts b/test/services/parcel.test.ts index a89f20e27..3c9983174 100644 --- a/test/services/parcel.test.ts +++ b/test/services/parcel.test.ts @@ -12,7 +12,7 @@ type ParcelTestCreateInput = Parameters[ describe('Parcel Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); diff --git a/test/services/pickup.test.ts b/test/services/pickup.test.ts index c101b67f1..4205bbfb5 100644 --- a/test/services/pickup.test.ts +++ b/test/services/pickup.test.ts @@ -16,7 +16,7 @@ type ShipmentTestCreateInput = Parameters { + pickupsArray.forEach((pickup: any) => { expect(pickup).to.be.an.instanceOf(Pickup); }); }); diff --git a/test/services/rate.test.ts b/test/services/rate.test.ts index 08be05f26..00da11646 100644 --- a/test/services/rate.test.ts +++ b/test/services/rate.test.ts @@ -11,7 +11,7 @@ type ShipmentTestCreateInput = Parameters { + referralsArray.forEach((referral: any) => { expect(referral).to.be.an.instanceOf(User); }); }); @@ -89,7 +90,7 @@ describe('ReferralCustomer Service', function () { const testEmail = 'me2@email.com'; await client.ReferralCustomer.updateEmail(singleReferral.id, testEmail).then( - expect(function (result) { + expect(function (result: any) { result.not.to.throw(); }), ); @@ -117,7 +118,7 @@ describe('ReferralCustomer Service', function () { referralUserProdApiKey, billing.payment_method_id, billing.priority, - ).catch((error) => { + ).catch((error: any) => { expect(error.message).to.equal( 'Stripe::PaymentMethod does not exist for the specified reference_id', ); @@ -132,7 +133,7 @@ describe('ReferralCustomer Service', function () { billing.financial_connections_id, billing.mandate_data, billing.priority, - ).catch((error) => { + ).catch((error: any) => { expect(error.message).to.equal( 'account_holder_name must be present when creating a Financial Connections payment method', ); diff --git a/test/services/refund.test.ts b/test/services/refund.test.ts index b2a40086c..e41ea7c7d 100644 --- a/test/services/refund.test.ts +++ b/test/services/refund.test.ts @@ -13,7 +13,7 @@ type ShipmentTestCreateInput = Parameters { + refunds.forEach((pickup: any) => { expect(pickup).to.be.an.instanceOf(Refund); }); expect(refunds[0].id).to.match(/^rfnd_/); @@ -53,7 +53,7 @@ describe('Refund Service', function () { expect(refundsArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(refunds.has_more).to.exist; - refundsArray.forEach((refund) => { + refundsArray.forEach((refund: any) => { expect(refund).to.be.an.instanceOf(Refund); }); }); diff --git a/test/services/report.test.ts b/test/services/report.test.ts index 27e018a3d..4c05d320e 100644 --- a/test/services/report.test.ts +++ b/test/services/report.test.ts @@ -9,7 +9,7 @@ import * as setupPolly from '../helpers/setup_polly'; describe('Report Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); @@ -81,14 +81,14 @@ describe('Report Service', function () { expect(reportsArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(reports.has_more).to.exist; - reportsArray.forEach((report) => { + reportsArray.forEach((report: any) => { expect(report).to.be.an.instanceOf(Report); }); }); it('retrieves next page of reports', async function () { - let reports; - let nextPage; + let reports: any; + let nextPage: any; try { const params = { diff --git a/test/services/scan_form.test.ts b/test/services/scan_form.test.ts index bf4b6e59c..736d64861 100644 --- a/test/services/scan_form.test.ts +++ b/test/services/scan_form.test.ts @@ -15,7 +15,7 @@ type ShipmentTestCreateInput = Parameters { + scanformsArray.forEach((scanform: any) => { expect(scanform).to.be.an.instanceOf(ScanForm); }); }); diff --git a/test/services/shipment.test.ts b/test/services/shipment.test.ts index cc4b6a689..3db5b2995 100644 --- a/test/services/shipment.test.ts +++ b/test/services/shipment.test.ts @@ -29,7 +29,7 @@ type ShipmentTestGenerateFormInput = Parameters< /* eslint-disable func-names */ describe('Shipment Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); @@ -120,7 +120,7 @@ describe('Shipment Service', function () { expect(shipmentsArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(shipments.has_more).to.exist; - shipmentsArray.forEach((shipment) => { + shipmentsArray.forEach((shipment: any) => { expect(shipment).to.be.an.instanceOf(Shipment); }); }); @@ -161,7 +161,7 @@ describe('Shipment Service', function () { const ratesArray = rates.rates; expect(ratesArray).to.be.an.instanceOf(Array); - ratesArray.forEach((rate) => { + ratesArray.forEach((rate: any) => { expect(rate).to.be.an.instanceOf(Rate); }); }); @@ -295,7 +295,7 @@ describe('Shipment Service', function () { const smartRates = await client.Shipment.getSmartRates(shipment.id); // Test lowest smartrate with valid filters - const lowestSmartRate = client.Utils.getLowestSmartRate(smartRates, 3, 'percentile_90'); + const lowestSmartRate = client.Utils.getLowestSmartRate(smartRates, 3, 'percentile_90') as any; expect(lowestSmartRate.service).to.equal('GroundAdvantage'); expect(lowestSmartRate.rate).to.equal(6.98); expect(lowestSmartRate.carrier).to.equal('USPS'); diff --git a/test/services/smart_rate.test.ts b/test/services/smart_rate.test.ts index d76103226..408cf1fa2 100644 --- a/test/services/smart_rate.test.ts +++ b/test/services/smart_rate.test.ts @@ -17,7 +17,7 @@ type SmartRateRecommendInput = Parameters< /* eslint-disable func-names */ describe('SmartRate Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); diff --git a/test/services/tracker.test.ts b/test/services/tracker.test.ts index f9214fb98..f6b29d611 100644 --- a/test/services/tracker.test.ts +++ b/test/services/tracker.test.ts @@ -9,7 +9,7 @@ import * as setupPolly from '../helpers/setup_polly'; describe('Tracker Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); @@ -50,7 +50,7 @@ describe('Tracker Service', function () { expect(trackersArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(trackers.has_more).to.exist; - trackersArray.forEach((tracker) => { + trackersArray.forEach((tracker: any) => { expect(tracker).to.be.an.instanceOf(Tracker); }); }); @@ -80,7 +80,7 @@ describe('Tracker Service', function () { tracking_codes: [tracker.tracking_code], }); - trackers.trackers.forEach((tracker) => { + trackers.trackers.forEach((tracker: any) => { expect(tracker).to.be.an.instanceOf(Tracker); }); }); diff --git a/test/services/user.test.ts b/test/services/user.test.ts index a0fdcfbad..806db3360 100644 --- a/test/services/user.test.ts +++ b/test/services/user.test.ts @@ -14,7 +14,7 @@ type UserUpdateInput = Parameters['update' /* eslint-disable func-names */ describe('User Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_PROD_API_KEY); @@ -56,7 +56,7 @@ describe('User Service', function () { it('updates a user', async function () { const testName = 'Test User'; - return client.User.retrieveMe().then(async (user) => { + return client.User.retrieveMe().then(async (user: any) => { const params: UserUpdateInput = {}; params.name = testName; const updatedUser = await client.User.update(user.id, params); @@ -73,7 +73,7 @@ describe('User Service', function () { }); await client.User.delete(user.id).then( - expect(function (result) { + expect(function (result: any) { result.not.to.throw(); }), ); @@ -98,7 +98,7 @@ describe('User Service', function () { expect(childrenArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); expect(response.has_more).to.exist; - childrenArray.forEach((children) => { + childrenArray.forEach((children: any) => { expect(children).to.be.an.instanceOf(User); }); }); diff --git a/test/services/webhook.test.ts b/test/services/webhook.test.ts index c87fba415..6abe4c30f 100644 --- a/test/services/webhook.test.ts +++ b/test/services/webhook.test.ts @@ -11,7 +11,7 @@ import { withoutParams } from '../helpers/utils'; /* eslint-disable func-names */ describe('Webhook Service', function () { const getPolly = setupPolly.setupPollyTests(); - let client; + let client: EasyPostClient; beforeAll(function () { client = new EasyPostClient(process.env.EASYPOST_TEST_API_KEY); @@ -61,7 +61,7 @@ describe('Webhook Service', function () { const webhooksArray = webhooks.webhooks; expect(webhooksArray.length).to.be.lessThanOrEqual(Fixture.pageSize()); - webhooksArray.forEach((webhook) => { + webhooksArray.forEach((webhook: any) => { expect(webhook).to.be.an.instanceOf(Webhook); }); }); @@ -90,7 +90,7 @@ describe('Webhook Service', function () { }); await client.Webhook.delete(webhook.id).then( - expect(function (result) { + expect(function (result: any) { result.not.to.throw(); }), ); @@ -105,7 +105,7 @@ describe('Webhook Service', function () { Fixture.eventBody(), headers, Fixture.webhookSecret(), - ); + ) as { description: string; result: { weight: number } }; expect(webhookBody.description).to.equal('tracker.updated'); expect(webhookBody.result.weight).to.equal(614.4); // Ensure we convert floats properly diff --git a/tsconfig.build.json b/tsconfig.build.json index f46983efb..c0cd3fcad 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -3,7 +3,7 @@ "compilerOptions": { "allowJs": true, "checkJs": false, - "noImplicitAny": false, + "noImplicitAny": true, "declaration": true, "noEmit": true, "types": ["vitest/globals", "node"] diff --git a/tsconfig.json b/tsconfig.json index e2377ec65..1b3262cab 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "compilerOptions": { "allowJs": true, "checkJs": false, - "noImplicitAny": false, + "noImplicitAny": true, "declaration": true, "emitDeclarationOnly": true, "rootDir": "./src", diff --git a/tsconfig.test-services.json b/tsconfig.test-services.json index e95c854fd..befba3e02 100644 --- a/tsconfig.test-services.json +++ b/tsconfig.test-services.json @@ -3,7 +3,7 @@ "compilerOptions": { "allowJs": true, "checkJs": false, - "noImplicitAny": false, + "noImplicitAny": true, "noEmit": true, "skipLibCheck": true, "types": ["vitest/globals", "node"]